Camino only - Bug 401532: Split miscellaneous utilities out of MainController. r/sr=mento

This commit is contained in:
stuart.morgan%alumni.case.edu 2007-10-31 15:26:58 +00:00
Родитель 820221d3fa
Коммит d9a7d54acb
11 изменённых файлов: 68 добавлений и 253 удалений

Просмотреть файл

@ -199,9 +199,6 @@ typedef enum EBookmarkOpenBehavior
- (NSView*)savePanelView; - (NSView*)savePanelView;
+ (NSImage*)createImageForDragging:(NSImage*)aIcon title:(NSString*)aTitle;
// utility routine to test if a url is "blank" (either empty or about:blank)
+ (BOOL)isBlankURL:(NSString*)inURL;
- (void)closeFindDialog; - (void)closeFindDialog;
@end @end

Просмотреть файл

@ -662,7 +662,7 @@ NSString* const kPreviousSessionTerminatedNormallyKey = @"PreviousSessionTermina
// The process of creating a new tab in this brand new window loads about:blank for us as a // The process of creating a new tab in this brand new window loads about:blank for us as a
// side effect of calling GetDocument(). We don't need to do it again. // side effect of calling GetDocument(). We don't need to do it again.
if ([MainController isBlankURL:aURL]) if (!aURL || [aURL isBlankURL])
[browser disableLoadPage]; [browser disableLoadPage];
else else
[browser loadURL:aURL referrer:aReferrer focusContent:YES allowPopups:inAllowPopups]; [browser loadURL:aURL referrer:aReferrer focusContent:YES allowPopups:inAllowPopups];
@ -866,6 +866,27 @@ NSString* const kPreviousSessionTerminatedNormallyKey = @"PreviousSessionTermina
} }
} }
//
// This takes an NSURL to a local file, and if that file is a file that contains
// a URL we want and isn't the content itself, we return the URL it contains.
// Otherwise, we return the URL we originally got. Right now this supports .url,
// .webloc and .ftploc files.
//
+ (NSURL*)decodeLocalFileURL:(NSURL*)url
{
NSString* urlPathString = [url path];
NSString* ext = [[urlPathString pathExtension] lowercaseString];
OSType fileType = NSHFSTypeCodeFromFileType(NSHFSTypeOfFile(urlPathString));
if ([ext isEqualToString:@"url"] || fileType == 'LINK')
url = [NSURL URLFromIEURLFile:urlPathString];
else if ([ext isEqualToString:@"webloc"] || [ext isEqualToString:@"ftploc"] ||
fileType == 'ilht' || fileType == 'ilft')
url = [NSURL URLFromInetloc:urlPathString];
return url;
}
#pragma mark - #pragma mark -
#pragma mark Delegate/Notification #pragma mark Delegate/Notification
@ -1039,7 +1060,7 @@ NSString* const kPreviousSessionTerminatedNormallyKey = @"PreviousSessionTermina
NSString* homePage = mStartURL ? mStartURL : [[PreferenceManager sharedInstance] homePageUsingStartPage:YES]; NSString* homePage = mStartURL ? mStartURL : [[PreferenceManager sharedInstance] homePageUsingStartPage:YES];
BrowserWindowController* controller = [self openBrowserWindowWithURL:homePage andReferrer:nil behind:nil allowPopups:NO]; BrowserWindowController* controller = [self openBrowserWindowWithURL:homePage andReferrer:nil behind:nil allowPopups:NO];
if ([MainController isBlankURL:homePage]) if (!homePage || [homePage isBlankURL])
[controller focusURLBar]; [controller focusURLBar];
else else
[[[controller browserWrapper] browserView] setActive:YES]; [[[controller browserWrapper] browserView] setActive:YES];
@ -1988,65 +2009,7 @@ static int SortByProtocolAndName(NSDictionary* item1, NSDictionary* item2, void*
} }
#pragma mark - #pragma mark -
#pragma mark Miscellaneous Utilities #pragma mark Find Panel
//which may not belong in MainController at all
//
// This takes an NSURL to a local file, and if that file is a file that contains
// a URL we want and isn't the content itself, we return the URL it contains.
// Otherwise, we return the URL we originally got. Right now this supports .url,
// .webloc and .ftploc files.
//
+ (NSURL*)decodeLocalFileURL:(NSURL*)url
{
NSString* urlPathString = [url path];
NSString* ext = [[urlPathString pathExtension] lowercaseString];
OSType fileType = NSHFSTypeCodeFromFileType(NSHFSTypeOfFile(urlPathString));
if ([ext isEqualToString:@"url"] || fileType == 'LINK')
url = [NSURL URLFromIEURLFile:urlPathString];
else if ([ext isEqualToString:@"webloc"] || [ext isEqualToString:@"ftploc"] || fileType == 'ilht' || fileType == 'ilft')
url = [NSURL URLFromInetloc:urlPathString];
return url;
}
+ (NSImage*)createImageForDragging:(NSImage*)aIcon title:(NSString*)aTitle
{
const float kTitleOffset = 2.0f;
NSDictionary* stringAttrs = [NSDictionary dictionaryWithObjectsAndKeys:
[[NSColor textColor] colorWithAlphaComponent:0.8], NSForegroundColorAttributeName,
[NSFont systemFontOfSize:[NSFont smallSystemFontSize]], NSFontAttributeName,
nil];
// get the size of the new image we are creating
NSSize titleSize = [aTitle sizeWithAttributes:stringAttrs];
NSSize imageSize = NSMakeSize(titleSize.width + [aIcon size].width + kTitleOffset + 2,
titleSize.height > [aIcon size].height ? titleSize.height
: [aIcon size].height);
// create the image and lock drawing focus on it
NSImage* dragImage = [[[NSImage alloc] initWithSize:imageSize] autorelease];
[dragImage lockFocus];
// draw the image and title in image with translucency
NSRect imageRect = NSMakeRect(0, 0, [aIcon size].width, [aIcon size].height);
[aIcon drawAtPoint:NSMakePoint(0, 0) fromRect:imageRect operation:NSCompositeCopy fraction:0.8];
[aTitle drawAtPoint:NSMakePoint([aIcon size].width + kTitleOffset, 0.0) withAttributes:stringAttrs];
[dragImage unlockFocus];
return dragImage;
}
+ (BOOL)isBlankURL:(NSString*)inURL
{
BOOL isBlank = NO;
if (!inURL || [inURL isEqualToString:@"about:blank"] || [inURL isEqualToString:@""])
isBlank = YES;
return isBlank;
}
- (void)closeFindDialog - (void)closeFindDialog
{ {

Просмотреть файл

@ -39,6 +39,7 @@
* ***** END LICENSE BLOCK ***** */ * ***** END LICENSE BLOCK ***** */
#import "BookmarkButton.h" #import "BookmarkButton.h"
#import "ImageAdditions.h"
#import "NSString+Utils.h" #import "NSString+Utils.h"
#import "NSPasteboard+Utils.h" #import "NSPasteboard+Utils.h"
#import "DraggableImageAndTextCell.h" #import "DraggableImageAndTextCell.h"
@ -312,8 +313,8 @@
// deallocated too soon. This occurs with SDK >= 10.3, but not earlier. // deallocated too soon. This occurs with SDK >= 10.3, but not earlier.
// Change in cleanup strategy? Hold on tight. // Change in cleanup strategy? Hold on tight.
[[self retain] autorelease]; [[self retain] autorelease];
[self dragImage:[MainController createImageForDragging:[self image] [self dragImage:[NSImage dragImageWithIcon:[self image]
title:([item isSeparator] ? @"" : title)] title:([item isSeparator] ? @"" : title)]
at:NSMakePoint(0, NSHeight([self bounds])) at:NSMakePoint(0, NSHeight([self bounds]))
offset:NSMakeSize(0, 0) offset:NSMakeSize(0, 0)
event:aEvent event:aEvent

Просмотреть файл

@ -36,6 +36,7 @@
* *
* ***** END LICENSE BLOCK ***** */ * ***** END LICENSE BLOCK ***** */
#import "ImageAdditions.h"
#import "NSString+Utils.h" #import "NSString+Utils.h"
#import "NSBezierPath+Utils.h" #import "NSBezierPath+Utils.h"
#import "NSPasteboard+Utils.h" #import "NSPasteboard+Utils.h"
@ -44,7 +45,6 @@
#import "BrowserTabView.h" #import "BrowserTabView.h"
#import "BrowserWrapper.h" #import "BrowserWrapper.h"
#import "MainController.h"
#import "BrowserWindowController.h" #import "BrowserWindowController.h"
#import "TruncatingTextAndImageCell.h" #import "TruncatingTextAndImageCell.h"
#import "TabButtonCell.h" #import "TabButtonCell.h"
@ -276,9 +276,13 @@ const int kMenuTruncationChars = 60;
NSPoint dragOrigin = [self frame].origin; NSPoint dragOrigin = [self frame].origin;
dragOrigin.y += [self frame].size.height; dragOrigin.y += [self frame].size.height;
[self dragImage: [MainController createImageForDragging:[mLabelCell image] title:title] [self dragImage:[NSImage dragImageWithIcon:[mLabelCell image] title:title]
at:iconRect.origin offset:NSMakeSize(0.0, 0.0) at:iconRect.origin
event:theEvent pasteboard:pboard source:self slideBack:YES]; offset:NSMakeSize(0.0, 0.0)
event:theEvent
pasteboard:pboard
source:self
slideBack:YES];
} }
} }

Просмотреть файл

@ -3353,7 +3353,7 @@ enum BWCOpenDest {
if (loadHomepage) if (loadHomepage)
urlToLoad = [[PreferenceManager sharedInstance] homePageUsingStartPage:NO]; urlToLoad = [[PreferenceManager sharedInstance] homePageUsingStartPage:NO];
focusURLBar = locationBarVisible && [MainController isBlankURL:urlToLoad]; focusURLBar = locationBarVisible && (!urlToLoad || [urlToLoad isBlankURL]);
[newView loadURI:urlToLoad referrer:nil flags:NSLoadFlagsNone focusContent:!focusURLBar allowPopups:NO]; [newView loadURI:urlToLoad referrer:nil flags:NSLoadFlagsNone focusContent:!focusURLBar allowPopups:NO];
} }
@ -3511,7 +3511,7 @@ enum BWCOpenDest {
// this should really be a class method // this should really be a class method
-(BrowserWindowController*)openNewWindowWithURL:(NSString*)aURLSpec referrer:(NSString*)aReferrer loadInBackground:(BOOL)aLoadInBG allowPopups:(BOOL)inAllowPopups -(BrowserWindowController*)openNewWindowWithURL:(NSString*)aURLSpec referrer:(NSString*)aReferrer loadInBackground:(BOOL)aLoadInBG allowPopups:(BOOL)inAllowPopups
{ {
BOOL focusURLBar = [MainController isBlankURL:aURLSpec]; BOOL focusURLBar = !aURLSpec || [aURLSpec isBlankURL];
BrowserWindowController* browser = [self openNewWindow:aLoadInBG]; BrowserWindowController* browser = [self openNewWindow:aLoadInBG];
[browser loadURL:aURLSpec referrer:aReferrer focusContent:!focusURLBar allowPopups:inAllowPopups]; [browser loadURL:aURLSpec referrer:aReferrer focusContent:!focusURLBar allowPopups:inAllowPopups];
return browser; return browser;
@ -3549,7 +3549,7 @@ enum BWCOpenDest {
{ {
BrowserTabViewItem* previouslySelected = (BrowserTabViewItem*)[mTabBrowser selectedTabViewItem]; BrowserTabViewItem* previouslySelected = (BrowserTabViewItem*)[mTabBrowser selectedTabViewItem];
BrowserTabViewItem* newTab = [self openNewTab:aLoadInBG]; BrowserTabViewItem* newTab = [self openNewTab:aLoadInBG];
BOOL focusURLBar = [MainController isBlankURL:aURLSpec]; BOOL focusURLBar = !aURLSpec || [aURLSpec isBlankURL];
// if instructed, tell the tab browser to remember the currently selected tab to // if instructed, tell the tab browser to remember the currently selected tab to
// jump back to if this new one is closed w/out switching to any other tabs. // jump back to if this new one is closed w/out switching to any other tabs.

Просмотреть файл

@ -37,12 +37,12 @@
* *
* ***** END LICENSE BLOCK ***** */ * ***** END LICENSE BLOCK ***** */
#import "PageProxyIcon.h"
#import "ImageAdditions.h"
#import "NSString+Utils.h" #import "NSString+Utils.h"
#import "NSPasteboard+Utils.h" #import "NSPasteboard+Utils.h"
#import "BrowserWindowController.h" #import "BrowserWindowController.h"
#import "PageProxyIcon.h"
#import "MainController.h"
#include "nsCRT.h" #include "nsCRT.h"
#include "nsNetUtil.h" #include "nsNetUtil.h"
@ -104,7 +104,7 @@
} }
// don't allow dragging of proxy icon for empty pages // don't allow dragging of proxy icon for empty pages
if ((!urlString) || [MainController isBlankURL:urlString]) if ((!urlString) || [urlString isBlankURL])
return; return;
NSString *cleanedTitle = [titleString stringByReplacingCharactersInSet:[NSCharacterSet controlCharacterSet] withString:@" "]; NSString *cleanedTitle = [titleString stringByReplacingCharactersInSet:[NSCharacterSet controlCharacterSet] withString:@" "];
@ -114,9 +114,13 @@
[pboard declareURLPasteboardWithAdditionalTypes:[NSArray array] owner:self]; [pboard declareURLPasteboardWithAdditionalTypes:[NSArray array] owner:self];
[pboard setDataForURL:urlString title:cleanedTitle]; [pboard setDataForURL:urlString title:cleanedTitle];
[self dragImage: [MainController createImageForDragging:[self image] title:titleString] [self dragImage:[NSImage dragImageWithIcon:[self image] title:titleString]
at: NSMakePoint(0,0) offset: NSMakeSize(0,0) at:NSMakePoint(0,0)
event: event pasteboard: pboard source: self slideBack: YES]; offset:NSMakeSize(0,0)
event:event
pasteboard:pboard
source:self
slideBack:YES];
} }
@end @end

Просмотреть файл

@ -252,8 +252,9 @@ nsHeaderSniffer::PerformSave(nsIURI* inOriginalURI)
if (url) { if (url) {
nsCAutoString urlFileName; nsCAutoString urlFileName;
url->GetFileName(urlFileName); // (2) For file URLs, use the file name. url->GetFileName(urlFileName); // (2) For file URLs, use the file name.
NSString* unescapedString = [NSString unescapedURLString:[NSString stringWithUTF8String:urlFileName.get()]]; NSString* escapedName = [NSString stringWithUTF8String:urlFileName.get()];
CopyUTF8toUTF16([unescapedString UTF8String], defaultFileName); NSString* unescapedName = [escapedName stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
CopyUTF8toUTF16([unescapedName UTF8String], defaultFileName);
} }
} }

Просмотреть файл

@ -1,50 +0,0 @@
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Chimera code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2002
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#import <AppKit/NSImage.h>
@interface NSImage (ImageAdditions)
- (void) drawFlippedInRect:(NSRect) rect operation:(NSCompositingOperation) op fraction:(float) delta;
- (void) drawFlippedInRect:(NSRect) rect operation:(NSCompositingOperation) op;
// the origin is relative to the bottom, left of the window.
- (void)drawTiledInRect:(NSRect)rect origin:(NSPoint)inOrigin operation:(NSCompositingOperation)inOperation;
- (NSImage*)imageByApplyingBadge:(NSImage*)badge withAlpha:(float)alpha scale:(float)scale;
@end

Просмотреть файл

@ -1,99 +0,0 @@
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Chimera code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2002
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#import "ImageAdditions.h"
#import <Cocoa/Cocoa.h>
@implementation NSImage (ImageAdditions)
- (void) drawFlippedInRect:(NSRect) rect operation:(NSCompositingOperation) op fraction:(float) delta
{
CGContextRef context;
context = [[NSGraphicsContext currentContext] graphicsPort];
CGContextSaveGState( context ); {
CGContextTranslateCTM( context, 0, NSMaxY( rect ) );
CGContextScaleCTM( context, 1, -1 );
rect.origin.y = 0;
[self drawInRect:rect fromRect:NSZeroRect operation:op fraction:delta];
} CGContextRestoreGState( context );
}
- (void) drawFlippedInRect:(NSRect) rect operation:(NSCompositingOperation) op
{
[self drawFlippedInRect:rect operation:op fraction:1.0];
}
- (void)drawTiledInRect:(NSRect)rect origin:(NSPoint)inOrigin operation:(NSCompositingOperation)inOperation
{
NSGraphicsContext* gc = [NSGraphicsContext currentContext];
[gc saveGraphicsState];
[gc setPatternPhase:inOrigin];
NSColor* patternColor = [NSColor colorWithPatternImage:self];
[patternColor set];
NSRectFillUsingOperation(rect, inOperation);
[gc restoreGraphicsState];
}
- (NSImage*)imageByApplyingBadge:(NSImage*)badge withAlpha:(float)alpha scale:(float)scale;
{
if (!badge)
return self;
// bad to actually change badge here
[badge setScalesWhenResized:YES];
[badge setSize:NSMakeSize([self size].width * scale,[self size].height * scale)];
// make a new image, copy over our best rep into it
NSImage* newImage = [[[NSImage alloc] initWithSize:[self size]] autorelease];
NSImageRep* imageRep = [[self bestRepresentationForDevice:nil] copy];
[newImage addRepresentation:imageRep];
[imageRep release];
[newImage lockFocus];
[[NSGraphicsContext currentContext] setImageInterpolation:NSImageInterpolationHigh];
[badge dissolveToPoint:NSMakePoint([self size].width - [badge size].width, 0.0) fraction:alpha];
[newImage unlockFocus];
return newImage;
}
@end

Просмотреть файл

@ -50,8 +50,6 @@ typedef enum
+ (id)ellipsisString; + (id)ellipsisString;
+ (NSString*)stringWithUUID; + (NSString*)stringWithUUID;
+ (id)escapedURLString:(NSString *)unescapedString;
+ (NSString*)unescapedURLString:(NSString*)escapedString;
- (BOOL)isEqualToStringIgnoringCase:(NSString*)inString; - (BOOL)isEqualToStringIgnoringCase:(NSString*)inString;
- (NSString *)stringByRemovingCharactersInSet:(NSCharacterSet*)characterSet; - (NSString *)stringByRemovingCharactersInSet:(NSCharacterSet*)characterSet;
@ -77,3 +75,10 @@ typedef enum
- (NSString*)displayNameOfLastPathComponent; - (NSString*)displayNameOfLastPathComponent;
@end @end
@interface NSString (CaminoURLStringUtils)
// Returns true if the string represents a "blank" URL ("" or "about:blank")
- (BOOL)isBlankURL;
@end

Просмотреть файл

@ -65,26 +65,6 @@
return [uuidString autorelease]; return [uuidString autorelease];
} }
+ (id)escapedURLString:(NSString *)unescapedString
{
NSString *escapedString =
(NSString *)CFURLCreateStringByAddingPercentEscapes(NULL,
(CFStringRef)unescapedString,
NULL,
NULL,
kCFStringEncodingUTF8);
return [escapedString autorelease];
}
+ (NSString*)unescapedURLString:(NSString*)escapedString
{
NSString *unescapedString =
(NSString *)CFURLCreateStringByReplacingPercentEscapes(NULL,
(CFStringRef)escapedString,
CFSTR(""));
return [unescapedString autorelease];
}
- (BOOL)isEqualToStringIgnoringCase:(NSString*)inString - (BOOL)isEqualToStringIgnoringCase:(NSString*)inString
{ {
return ([self compare:inString options:NSCaseInsensitiveSearch] == NSOrderedSame); return ([self compare:inString options:NSCaseInsensitiveSearch] == NSOrderedSame);
@ -327,3 +307,12 @@
} }
@end @end
@implementation NSString (CaminoURLStringUtils)
- (BOOL)isBlankURL
{
return ([self isEqualToString:@"about:blank"] || [self isEqualToString:@""]);
}
@end