diff --git a/mozilla/camino/AboutBox.nib/classes.nib b/mozilla/camino/AboutBox.nib/classes.nib deleted file mode 100644 index e9180430bcc..00000000000 --- a/mozilla/camino/AboutBox.nib/classes.nib +++ /dev/null @@ -1,17 +0,0 @@ -{ - IBClasses = ( - { - ACTIONS = {showPanel = id; }; - CLASS = AboutBox; - LANGUAGE = ObjC; - OUTLETS = { - buildNumberField = NSTextField; - creditsField = NSTextView; - window = NSWindow; - }; - SUPERCLASS = NSObject; - }, - {CLASS = FirstResponder; LANGUAGE = ObjC; SUPERCLASS = NSObject; } - ); - IBVersion = 1; -} \ No newline at end of file diff --git a/mozilla/camino/AboutBox.nib/info.nib b/mozilla/camino/AboutBox.nib/info.nib deleted file mode 100644 index 4df25655e54..00000000000 --- a/mozilla/camino/AboutBox.nib/info.nib +++ /dev/null @@ -1,18 +0,0 @@ - - - - - IBFramework Version - 248.0 - IBLockedObjects - - 7 - - IBOpenObjects - - 5 - - IBSystem Version - 5S66 - - diff --git a/mozilla/camino/AboutBox.nib/objects.nib b/mozilla/camino/AboutBox.nib/objects.nib deleted file mode 100644 index 8c1c2d1f930..00000000000 Binary files a/mozilla/camino/AboutBox.nib/objects.nib and /dev/null differ diff --git a/mozilla/camino/AppComponents.mm b/mozilla/camino/AppComponents.mm deleted file mode 100644 index d481db2c921..00000000000 --- a/mozilla/camino/AppComponents.mm +++ /dev/null @@ -1,74 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** 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 mozilla.org 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): - * Brian Ryner - * - * 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 -#import "SecurityDialogs.h" -#import "CocoaPromptService.h" -#include "nsIGenericFactory.h" - -// {0ffd3880-7a1a-11d6-a384-975d1d5f86fc} -#define NS_BADCERTHANDLER_CID \ - {0x0ffd3880, 0x7a1a, 0x11d6,{0xa3, 0x84, 0x97, 0x5d, 0x1d, 0x5f, 0x86, 0xfc}} - -#define NS_PROMPTSERVICE_CID \ - {0xa2112d6a, 0x0e28, 0x421f, {0xb4, 0x6a, 0x25, 0xc0, 0xb3, 0x8, 0xcb, 0xd0}} - -NS_GENERIC_FACTORY_CONSTRUCTOR(SecurityDialogs); -NS_GENERIC_FACTORY_CONSTRUCTOR(CocoaPromptService); - -static const nsModuleComponentInfo components[] = { - { - "Bad Cert Handler", - NS_BADCERTHANDLER_CID, - NS_NSSDIALOGS_CONTRACTID, - SecurityDialogsConstructor - }, - { - "Prompt Service", - NS_PROMPTSERVICE_CID, - "@mozilla.org/embedcomp/prompt-service;1", - CocoaPromptServiceConstructor - } -}; - -const nsModuleComponentInfo* GetAppModuleComponentInfo(int* outNumComponents) -{ - *outNumComponents = sizeof(components) / sizeof(components[0]); - return components; -} - diff --git a/mozilla/camino/AppDirServiceProvider.cpp b/mozilla/camino/AppDirServiceProvider.cpp deleted file mode 100644 index 0330560b090..00000000000 --- a/mozilla/camino/AppDirServiceProvider.cpp +++ /dev/null @@ -1,155 +0,0 @@ -/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** 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 mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 2001, 2002 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Conrad Carlen - * - * 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 ***** */ - -#include "AppDirServiceProvider.h" -#include "nsAppDirectoryServiceDefs.h" -#include "nsILocalFileMac.h" - -#include - -// Defines - -#define APP_REGISTRY_NAME NS_LITERAL_CSTRING("Application.regs") -#define PROFILES_ROOT_NAME NS_LITERAL_CSTRING("Profiles") - -//***************************************************************************** -// AppDirServiceProvider::Constructor/Destructor -//***************************************************************************** - -AppDirServiceProvider::AppDirServiceProvider(const nsACString& productDirName) -{ - NS_INIT_ISUPPORTS(); - mProductDirName.Assign(productDirName); -} - -AppDirServiceProvider::~AppDirServiceProvider() -{ -} - -//***************************************************************************** -// AppDirServiceProvider::nsISupports -//***************************************************************************** - -NS_IMPL_ISUPPORTS1(AppDirServiceProvider, nsIDirectoryServiceProvider) - -//***************************************************************************** -// AppDirServiceProvider::nsIDirectoryServiceProvider -//***************************************************************************** - -NS_IMETHODIMP -AppDirServiceProvider::GetFile(const char *prop, PRBool *persistant, nsIFile **_retval) -{ - nsCOMPtr localFile; - nsresult rv = NS_ERROR_FAILURE; - nsCAutoString strBuf; - - *_retval = nsnull; - *persistant = PR_TRUE; - - if (strcmp(prop, NS_APP_APPLICATION_REGISTRY_DIR) == 0) - { - rv = GetProductDirectory(getter_AddRefs(localFile)); - } - else if (strcmp(prop, NS_APP_APPLICATION_REGISTRY_FILE) == 0) - { - rv = GetProductDirectory(getter_AddRefs(localFile)); - if (NS_SUCCEEDED(rv)) - rv = localFile->AppendNative(APP_REGISTRY_NAME); - } - else if (strcmp(prop, NS_APP_USER_PROFILES_ROOT_DIR) == 0) - { - rv = GetProductDirectory(getter_AddRefs(localFile)); - if (NS_FAILED(rv)) - return rv; - rv = localFile->AppendNative(PROFILES_ROOT_NAME); - if (NS_FAILED(rv)) - return rv; - - PRBool exists; - rv = localFile->Exists(&exists); - if (NS_SUCCEEDED(rv) && !exists) - rv = localFile->Create(nsIFile::DIRECTORY_TYPE, 0775); - if (NS_FAILED(rv)) - return rv; - } - - if (localFile && NS_SUCCEEDED(rv)) - return localFile->QueryInterface(NS_GET_IID(nsIFile), (void**)_retval); - - return rv; -} - -//***************************************************************************** -// AppDirServiceProvider::AppDirServiceProvider -//***************************************************************************** - -NS_METHOD -AppDirServiceProvider::GetProductDirectory(nsILocalFile **aLocalFile) -{ - NS_ENSURE_ARG_POINTER(aLocalFile); - *aLocalFile = nsnull; - - nsresult rv; - FSRef foundRef; - - OSErr err = ::FSFindFolder(kUserDomain, kApplicationSupportFolderType, kCreateFolder, &foundRef); - if (err != noErr) - return NS_ERROR_FAILURE; - nsCOMPtr localDir(do_CreateInstance(NS_LOCAL_FILE_CONTRACTID)); - if (!localDir) - return NS_ERROR_FAILURE; - rv = localDir->InitWithFSRef(&foundRef); - if (NS_FAILED(rv)) - return rv; - rv = localDir->AppendNative(mProductDirName); - if (NS_FAILED(rv)) - return rv; - - PRBool exists; - rv = localDir->Exists(&exists); - if (NS_SUCCEEDED(rv) && !exists) - rv = localDir->Create(nsIFile::DIRECTORY_TYPE, 0775); - if (NS_FAILED(rv)) - return rv; - - *aLocalFile = localDir; - NS_ADDREF(*aLocalFile); - - return rv; -} - diff --git a/mozilla/camino/AppDirServiceProvider.h b/mozilla/camino/AppDirServiceProvider.h deleted file mode 100644 index d7b7f4fb116..00000000000 --- a/mozilla/camino/AppDirServiceProvider.h +++ /dev/null @@ -1,70 +0,0 @@ -/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** 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 mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 2001, 2002 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Conrad Carlen - * - * 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 ***** */ - -#ifndef __AppDirServiceProvider_h__ -#define __AppDirServiceProvider_h__ - -#include "nsIDirectoryService.h" -#include "nsILocalFile.h" -#include "nsString.h" - -class nsIFile; - -//***************************************************************************** -// class AppDirServiceProvider -//***************************************************************************** - -class AppDirServiceProvider : public nsIDirectoryServiceProvider -{ -public: - AppDirServiceProvider(const nsACString& productDirName); - - NS_DECL_ISUPPORTS - NS_DECL_NSIDIRECTORYSERVICEPROVIDER - -protected: - virtual ~AppDirServiceProvider(); - - NS_METHOD GetProductDirectory(nsILocalFile **aLocalFile); - NS_METHOD GetDefaultUserProfileRoot(nsILocalFile **aLocalFile); - - nsCString mProductDirName; -}; - -#endif // __AppDirServiceProvider_h__ - diff --git a/mozilla/camino/BookmarkInfoController.h b/mozilla/camino/BookmarkInfoController.h deleted file mode 100644 index ddd1f896443..00000000000 --- a/mozilla/camino/BookmarkInfoController.h +++ /dev/null @@ -1,46 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- -* -* 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 the Mozilla browser. -* -* The Initial Developer of the Original Code is Netscape -* Communications Corporation. Portions created by Netscape are -* Copyright (C) 2002 Netscape Communications Corporation. All -* Rights Reserved. -* -* Contributor(s): -* Ben Goodger (Original Author) -* David Haas -*/ -#import -#import "BookmarksService.h" - -@interface BookmarkInfoController : NSWindowController { - IBOutlet NSTextField* mNameField; - IBOutlet NSTextField* mLocationField; - IBOutlet NSTextField* mKeywordField; - IBOutlet NSTextField* mDescriptionField; - IBOutlet NSTextField* mNameLabel; - IBOutlet NSTextField* mLocationLabel; - IBOutlet NSTextField* mKeywordLabel; - IBOutlet NSTextField* mDescriptionLabel; - - BookmarkItem* mBookmarkItem; - NSTextView* mFieldEditor; -} - -+ (id)sharedBookmarkInfoController; - --(void)setBookmark:(BookmarkItem*)aBookmark; - - -@end diff --git a/mozilla/camino/BookmarkInfoController.mm b/mozilla/camino/BookmarkInfoController.mm deleted file mode 100644 index c04d5b25127..00000000000 --- a/mozilla/camino/BookmarkInfoController.mm +++ /dev/null @@ -1,231 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- -* -* 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 the Mozilla browser. -* -* The Initial Developer of the Original Code is Netscape -* Communications Corporation. Portions created by Netscape are -* Copyright (C) 2002 Netscape Communications Corporation. All -* Rights Reserved. -* -* Contributor(s): -* Ben Goodger (Original Author) -* David Haas -*/ - -#import "NSString+Utils.h" - -#import "BookmarkInfoController.h" -#import "BookmarksDataSource.h" - -#include "nsIContent.h" -#include "nsINamespaceManager.h" - - -@interface BookmarkInfoController(Private) - -- (void)showUIElementPair: (id)aLabel control: (id) aControl; -- (void)hideUIElementPair: (id)aLabel control: (id) aControl; -- (void)commitChanges:(id)sender; -- (void)commitField:(id)textField toProperty:(nsIAtom*)propertyAtom; - -@end; - -@implementation BookmarkInfoController - -/* BookmarkInfoController singelton */ -static BookmarkInfoController *sharedBookmarkInfoController = nil; - -+ (id)sharedBookmarkInfoController -{ - if (!sharedBookmarkInfoController) { - sharedBookmarkInfoController = [[BookmarkInfoController alloc] init]; - } - - return sharedBookmarkInfoController; -} - --(id) init -{ - [super initWithWindowNibName:@"BookmarkInfoPanel"]; - - //custom field editor lets us undo our changes - mFieldEditor = [[NSTextView alloc] init]; - [mFieldEditor setAllowsUndo:YES]; - [mFieldEditor setFieldEditor:YES]; - - return self; -} - --(void)dealloc -{ - if (self == sharedBookmarkInfoController) - sharedBookmarkInfoController = nil; - - [mFieldEditor release]; - [super dealloc]; -} - --(void)controlTextDidEndEditing: (NSNotification*) aNotification -{ - [self commitChanges:[aNotification object]]; - [[mFieldEditor undoManager] removeAllActions]; -} --(void)windowDidBecomeKey:(NSNotification*) aNotification -{ - [[self window] makeFirstResponder:mNameField]; -} - --(void)windowDidResignKey:(NSNotification*) aNotification -{ - [[self window] makeFirstResponder:[self window]]; -} - -- (void)commitChanges:(id)changedField -{ - if (![mBookmarkItem contentNode]) - return; - - // Name - if (changedField == mNameField) - [self commitField:mNameField toProperty:BookmarksService::gNameAtom]; - - // Location - if (changedField == mLocationField) - [self commitField:mLocationField toProperty:BookmarksService::gHrefAtom]; - - // Keyword - if (changedField == mKeywordField) - [self commitField:mKeywordField toProperty:BookmarksService::gKeywordAtom]; - - // Description - if (changedField == mDescriptionField) - [self commitField:mDescriptionField toProperty:BookmarksService::gDescriptionAtom]; - - [[mFieldEditor undoManager] removeAllActions]; - BookmarksService::BookmarkChanged([mBookmarkItem contentNode], TRUE); -} - -- (void)commitField:(id)textField toProperty:(nsIAtom*)propertyAtom -{ - unsigned int len; - PRUnichar* buffer; - nsXPIDLString buf; - - // we really need a category on NSString for this - len = [[textField stringValue] length]; - buffer = new PRUnichar[len + 1]; - if (!buffer) return; - [[textField stringValue] getCharacters:buffer]; - buffer[len] = (PRUnichar)'\0'; - buf.Adopt(buffer); - [mBookmarkItem contentNode]->SetAttr(kNameSpaceID_None, propertyAtom, buf, PR_TRUE); -} - - --(void)setBookmark: (BookmarkItem*) aBookmark -{ - // See bug 154081 - don't show this window if Bookmark doesn't exist - // after fix - this should never happen unless disaster strikes. - if (![aBookmark contentNode]) - return; - - nsAutoString group; - [aBookmark contentNode]->GetAttr(kNameSpaceID_None, BookmarksService::gGroupAtom, group); - BOOL isGroup = !group.IsEmpty(); - BOOL isFolder = !isGroup && [aBookmark isFolder]; - - // First, Show/Hide the appropriate UI - if (isGroup) { - [self showUIElementPair: mNameLabel control: mNameField]; - [mNameField setNextKeyView:mKeywordField]; - [self hideUIElementPair: mLocationLabel control: mLocationField]; - [self showUIElementPair: mKeywordLabel control: mKeywordField]; - [self showUIElementPair: mDescriptionLabel control: mDescriptionField]; - } - else if (isFolder) { - [self showUIElementPair: mNameLabel control: mNameField]; - [mNameField setNextKeyView:mDescriptionField]; - [self hideUIElementPair: mLocationLabel control: mLocationField]; - [self hideUIElementPair: mKeywordLabel control: mKeywordField]; - [self showUIElementPair: mDescriptionLabel control: mDescriptionField]; - } - else { - [self showUIElementPair: mNameLabel control: mNameField]; - [mNameField setNextKeyView:mLocationField]; - [self showUIElementPair: mLocationLabel control: mLocationField]; - [self showUIElementPair: mKeywordLabel control: mKeywordField]; - [self showUIElementPair: mDescriptionLabel control: mDescriptionField]; - } - - // Then, fill with appropriate values from Bookmarks - nsAutoString value; - - [aBookmark contentNode]->GetAttr(kNameSpaceID_None, BookmarksService::gNameAtom, value); - NSString* bookmarkName = [NSString stringWith_nsAString: value]; - [mNameField setStringValue: bookmarkName]; - NSString* infoForString = [NSString stringWithFormat:NSLocalizedString(@"BookmarkInfoTitle",@"Info for "), bookmarkName]; - [[self window] setTitle: infoForString]; - - if (!isGroup && !isFolder) { - [aBookmark contentNode]->GetAttr(kNameSpaceID_None, BookmarksService::gHrefAtom, value); - [mLocationField setStringValue: [NSString stringWith_nsAString: value]]; - } - - if (!isFolder) { - [aBookmark contentNode]->GetAttr(kNameSpaceID_None, BookmarksService::gKeywordAtom, value); - [mKeywordField setStringValue: [NSString stringWith_nsAString: value]]; - } - - [aBookmark contentNode]->GetAttr(kNameSpaceID_None, BookmarksService::gDescriptionAtom, value); - [mDescriptionField setStringValue: [NSString stringWith_nsAString: value]]; - - mBookmarkItem = aBookmark; -} - --(void)showUIElementPair: (id)aLabel control:(id)aControl -{ - if ([aLabel superview] == nil) { - [[[self window] contentView] addSubview: aLabel]; - [aLabel autorelease]; - } - if ([aControl superview] == nil) { - [[[self window] contentView] addSubview: aControl]; - [aControl autorelease]; - } -} - --(void)hideUIElementPair: (id)aLabel control:(id)aControl -{ - if ([aLabel superview] != nil) { - [aLabel removeFromSuperview]; - [aLabel retain]; - } - if ([aControl superview] != nil) { - [aControl removeFromSuperview]; - [aControl retain]; - } -} - --(NSText *)windowWillReturnFieldEditor:(NSWindow *)aPanel toObject:(id)aObject -{ - return mFieldEditor; -} - --(void) close -{ - mBookmarkItem = nil; - [super close]; -} - - -@end diff --git a/mozilla/camino/BookmarkInfoPanel.nib/classes.nib b/mozilla/camino/BookmarkInfoPanel.nib/classes.nib deleted file mode 100644 index 7cb6777f984..00000000000 --- a/mozilla/camino/BookmarkInfoPanel.nib/classes.nib +++ /dev/null @@ -1,22 +0,0 @@ -{ - IBClasses = ( - { - CLASS = BookmarkInfoController; - LANGUAGE = ObjC; - OUTLETS = { - mDescriptionField = NSTextField; - mDescriptionLabel = NSTextField; - mKeywordField = NSTextField; - mKeywordLabel = NSTextField; - mLocationField = NSTextField; - mLocationLabel = NSTextField; - mNameField = NSTextField; - mNameLabel = NSTextField; - }; - SUPERCLASS = NSWindowController; - }, - {CLASS = BookmarkItem; LANGUAGE = ObjC; SUPERCLASS = NSObject; }, - {CLASS = FirstResponder; LANGUAGE = ObjC; SUPERCLASS = NSObject; } - ); - IBVersion = 1; -} \ No newline at end of file diff --git a/mozilla/camino/BookmarkInfoPanel.nib/info.nib b/mozilla/camino/BookmarkInfoPanel.nib/info.nib deleted file mode 100644 index b8cd244ab7f..00000000000 --- a/mozilla/camino/BookmarkInfoPanel.nib/info.nib +++ /dev/null @@ -1,12 +0,0 @@ - - - - - IBDocumentLocation - 144 74 366 258 0 0 1280 1002 - IBFramework Version - 248.0 - IBSystem Version - 5S66 - - diff --git a/mozilla/camino/BookmarkInfoPanel.nib/objects.nib b/mozilla/camino/BookmarkInfoPanel.nib/objects.nib deleted file mode 100644 index 5541b6caeaa..00000000000 Binary files a/mozilla/camino/BookmarkInfoPanel.nib/objects.nib and /dev/null differ diff --git a/mozilla/camino/BookmarksDataSource.h b/mozilla/camino/BookmarksDataSource.h deleted file mode 100644 index 3b0c373041f..00000000000 --- a/mozilla/camino/BookmarksDataSource.h +++ /dev/null @@ -1,123 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape 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/NPL/ - * - * 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 mozilla.org 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): - * Simon Fraser - * - * - * 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 NPL, 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 NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#import -#import - -#import "MainController.h" -#import "CHBookmarksToolbar.h" -#import "CHExtendedOutlineView.h" - -class nsIContent; -class BookmarksService; - -@class BookmarkInfoController; - -// data source for the bookmarks sidebar. We make one per browser window. -@interface BookmarksDataSource : NSObject -{ - BookmarksService* mBookmarks; - - IBOutlet id mOutlineView; - IBOutlet id mBrowserWindowController; - IBOutlet id mEditBookmarkButton; - IBOutlet id mDeleteBookmarkButton; - - NSString* mCachedHref; -} - --(id) init; --(void) windowClosing; - --(void) ensureBookmarks; - --(IBAction)addBookmark:(id)aSender; --(void)endAddBookmark: (int)aCode; - --(IBAction)deleteBookmarks: (id)aSender; --(void)deleteBookmark: (id)aItem; - --(IBAction)addFolder:(id)aSender; - --(void)addBookmark:(id)aSender useSelection:(BOOL)aSel isFolder:(BOOL)aIsFolder URL:(NSString*)aURL title:(NSString*)aTitle; - --(NSString*)resolveKeyword:(NSString*)aKeyword; - -- (IBAction)openBookmarkInNewTab:(id)aSender; -- (IBAction)openBookmarkInNewWindow:(id)aSender; - -- (void)openBookmarkGroup:(id)aTabView groupElement:(nsIDOMElement*)aFolder; -- (IBAction)showBookmarkInfo:(id)aSender; -- (BOOL)haveSelectedRow; - -// Datasource methods. -- (id)outlineView:(NSOutlineView *)outlineView child:(int)index ofItem:(id)item; -- (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item; -- (int)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item; -- (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item; -- (void)outlineView:(NSOutlineView *)outlineView setObjectValue:(id)object forTableColumn:(NSTableColumn *)tableColumn byItem:(id)item; - -- (BOOL)outlineView:(NSOutlineView *)ov writeItems:(NSArray*)items toPasteboard:(NSPasteboard*)pboard; -- (NSDragOperation)outlineView:(NSOutlineView*)ov validateDrop:(id )info proposedItem:(id)item proposedChildIndex:(int)index; -- (BOOL)outlineView:(NSOutlineView*)ov acceptDrop:(id )info item:(id)item childIndex:(int)index; - -- (void)reloadDataForItem:(id)item reloadChildren: (BOOL)aReloadChildren; - -// Delegate methods -- (void)outlineViewItemWillExpand:(NSNotification *)notification; -- (void)outlineViewItemWillCollapse:(NSNotification *)notification; - -@end - -@interface BookmarkItem : NSObject -{ - nsIContent* mContentNode; - NSImage* mSiteIcon; -} - -- (nsIContent*)contentNode; -- (void)setContentNode: (nsIContent*)aContentNode; -- (void)setSiteIcon:(NSImage*)image; -- (NSString*)url; -- (NSImage*)siteIcon; -- (NSNumber*)contentID; -- (id)copyWithZone:(NSZone *)aZone; -- (BOOL)isFolder; - -@end diff --git a/mozilla/camino/BookmarksDataSource.mm b/mozilla/camino/BookmarksDataSource.mm deleted file mode 100644 index 4bf75d761c8..00000000000 --- a/mozilla/camino/BookmarksDataSource.mm +++ /dev/null @@ -1,928 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape 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/NPL/ - * - * 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 mozilla.org 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): - * Simon Fraser - * - * - * 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 NPL, 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 NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#import "NSString+Utils.h" - -#import "BookmarksDataSource.h" -#import "BookmarkInfoController.h" -#import "SiteIconProvider.h" - -#include "nsCOMPtr.h" -#include "nsIContent.h" -#include "nsIDocument.h" -#include "nsIDocumentObserver.h" -#include "nsIDOMDocument.h" -#include "nsIDOMElement.h" -#include "nsINamespaceManager.h" -#include "nsIPrefBranch.h" -#include "nsIServiceManager.h" - -#include "nsVoidArray.h" - -#import "BookmarksService.h" - -@implementation BookmarksDataSource - --(id) init -{ - if ( (self = [super init]) ) { - mBookmarks = nsnull; - mCachedHref = nil; - } - return self; -} - --(void) awakeFromNib -{ - // make sure these are disabled at the start since the outliner - // starts off with no selection. - [mEditBookmarkButton setEnabled:NO]; - [mDeleteBookmarkButton setEnabled:NO]; -} - --(void) windowClosing -{ - if (mBookmarks) { - mBookmarks->RemoveObserver(); - delete mBookmarks; - } -} - --(void) ensureBookmarks -{ - if (mBookmarks) - return; - - mBookmarks = new BookmarksService(self); - mBookmarks->AddObserver(); - - [mOutlineView setTarget: self]; - [mOutlineView setDoubleAction: @selector(openBookmark:)]; - [mOutlineView setDeleteAction: @selector(deleteBookmarks:)]; - [mOutlineView reloadData]; -} - --(IBAction)addBookmark:(id)aSender -{ - [self addBookmark: aSender useSelection: YES isFolder: NO URL:nil title:nil]; -} - --(IBAction)addFolder:(id)aSender -{ - [self addBookmark: aSender useSelection: YES isFolder: YES URL:nil title:nil]; -} - --(void)addBookmark:(id)aSender useSelection:(BOOL)aUseSel isFolder:(BOOL)aIsFolder URL:(NSString*)aURL title:(NSString*)aTitle -{ - if (!mBookmarks) - return; - - // We use the selected item to determine the parent only if aUseSel is YES. - BookmarkItem* item = nil; - if (aUseSel && ([mOutlineView numberOfSelectedRows] == 1)) { - // There is only one selected row. If it is a folder, use it as our parent. - // Otherwise, use our parent, - int index = [mOutlineView selectedRow]; - item = [mOutlineView itemAtRow: index]; - if (![mOutlineView isExpandable: item]) { - // We can't be used as the parent. Try our parent. - nsIContent* content = [item contentNode]; - if (!content) - return; - - nsCOMPtr parentContent; - content->GetParent(*getter_AddRefs(parentContent)); - nsCOMPtr root; - mBookmarks->GetRootContent(getter_AddRefs(root)); - - // The root has no item, so we don't need to do a lookup unless we - // aren't the root. - if (parentContent != root) { - PRUint32 contentID; - parentContent->GetContentID(&contentID); - item = [(BookmarksService::gDictionary) objectForKey: [NSNumber numberWithInt: contentID]]; - } - } - } - - nsCOMPtr domDoc(do_QueryInterface(mBookmarks->gBookmarks)); - - nsAutoString title, href; - if (!aIsFolder) { - - // If no URL and title were specified, get them from the current page. - if (aURL && aTitle) { - [aURL assignTo_nsAString:href]; - [aTitle assignTo_nsAString:title]; - } else { - BookmarksService::GetTitleAndHrefForBrowserView([[mBrowserWindowController getBrowserWrapper] getBrowserView], - title, href); - } - - mCachedHref = [NSString stringWith_nsAString: href]; - [mCachedHref retain]; - - } else { // Folder - mCachedHref = nil; - title = NS_LITERAL_STRING("New Folder"); // XXX localize me - } - - NSTextField* textField = [mBrowserWindowController getAddBookmarkTitle]; - NSString* bookmarkTitle = [NSString stringWith_nsAString: title]; - NSString* cleanedTitle = [bookmarkTitle stringByReplacingCharactersInSet:[NSCharacterSet controlCharacterSet] withString:@" "]; - - [textField setStringValue: cleanedTitle]; - - [mBrowserWindowController cacheBookmarkDS: self]; - - // Show/hide the bookmark all tabs checkbox as appropriate. - NSTabView* tabView = [mBrowserWindowController getTabBrowser]; - id checkbox = [mBrowserWindowController getAddBookmarkCheckbox]; - BOOL hasSuperview = [checkbox superview] != nil; - if (aIsFolder && hasSuperview) { - // Just don't show it at all. - [checkbox removeFromSuperview]; - [checkbox retain]; - } - else if (!aIsFolder && !hasSuperview) { - // Put it back in. - [[[mBrowserWindowController getAddBookmarkSheetWindow] contentView] addSubview: checkbox]; - [checkbox autorelease]; - } - - // Enable the bookmark all tabs checkbox if appropriate. - if (!aIsFolder) - [[mBrowserWindowController getAddBookmarkCheckbox] setEnabled: ([tabView numberOfTabViewItems] > 1)]; - - // Build up the folder list. - NSPopUpButton* popup = [mBrowserWindowController getAddBookmarkFolder]; - BookmarksService::ConstructAddBookmarkFolderList(popup, item); - - [NSApp beginSheet: [mBrowserWindowController getAddBookmarkSheetWindow] - modalForWindow: [mBrowserWindowController window] - modalDelegate: nil //self - didEndSelector: nil //@selector(sheetDidEnd:) - contextInfo: nil]; -} - --(void)endAddBookmark: (int)aCode -{ - if (aCode == 0) - return; - - BOOL isGroup = NO; - id checkbox = [mBrowserWindowController getAddBookmarkCheckbox]; - if (([checkbox superview] != nil) && [checkbox isEnabled] && ([checkbox state] == NSOnState)) { - mCachedHref = nil; - isGroup = YES; - } - - nsAutoString title; - [[[mBrowserWindowController getAddBookmarkTitle] stringValue] assignTo_nsAString:title]; - - nsAutoString tagName; - if (mCachedHref) - tagName = NS_LITERAL_STRING("bookmark"); - else - tagName = NS_LITERAL_STRING("folder"); - - nsCOMPtr domDoc(do_QueryInterface(mBookmarks->gBookmarks)); - nsCOMPtr elt; - domDoc->CreateElementNS(NS_LITERAL_STRING("http://chimera.mozdev.org/bookmarks/"), - tagName, - getter_AddRefs(elt)); - - elt->SetAttribute(NS_LITERAL_STRING("name"), title); - - if (mCachedHref) { - nsAutoString href; - [mCachedHref assignTo_nsAString:href]; - [mCachedHref release]; - elt->SetAttribute(NS_LITERAL_STRING("href"), href); - } - - if (isGroup) { - // We have to iterate over each tab and create content nodes using the - // title/href of all the pages. They are inserted underneath the parent. - elt->SetAttribute(NS_LITERAL_STRING("group"), NS_LITERAL_STRING("true")); - id tabBrowser = [mBrowserWindowController getTabBrowser]; - int count = [tabBrowser numberOfTabViewItems]; - for (int i = 0; i < count; i++) { - id browserView = [[[tabBrowser tabViewItemAtIndex: i] view] getBrowserView]; - nsAutoString title, href; - BookmarksService::GetTitleAndHrefForBrowserView(browserView, title, href); - nsCOMPtr childElt; - domDoc->CreateElementNS(NS_LITERAL_STRING("http://chimera.mozdev.org/bookmarks/"), - NS_LITERAL_STRING("bookmark"), - getter_AddRefs(childElt)); - childElt->SetAttribute(NS_LITERAL_STRING("name"), title); - childElt->SetAttribute(NS_LITERAL_STRING("href"), href); - nsCOMPtr dummy; - elt->AppendChild(childElt, getter_AddRefs(dummy)); - } - } - - // Figure out the parent element. - nsCOMPtr parentElt; - nsCOMPtr parentContent; - NSPopUpButton* popup = [mBrowserWindowController getAddBookmarkFolder]; - NSMenuItem* selectedItem = [popup selectedItem]; - int tag = [selectedItem tag]; - if (tag == -1) { - mBookmarks->GetRootContent(getter_AddRefs(parentContent)); - parentElt = do_QueryInterface(parentContent); - } - else { - BookmarkItem* item = [(BookmarksService::gDictionary) objectForKey: [NSNumber numberWithInt: tag]]; - // Get the content node. - parentContent = [item contentNode]; - parentElt = do_QueryInterface(parentContent); - } - - nsCOMPtr dummy; - parentElt->AppendChild(elt, getter_AddRefs(dummy)); - - nsCOMPtr childContent(do_QueryInterface(elt)); - mBookmarks->BookmarkAdded(parentContent, childContent); -} - --(IBAction)deleteBookmarks: (id)aSender -{ - if (!mBookmarks) - return; - - int index = [mOutlineView selectedRow]; - if (index == -1) - return; - - // first, see how many items are selected - BOOL haveBookmarks = NO; - - NSEnumerator* testSelRows = [mOutlineView selectedRowEnumerator]; - for (NSNumber* currIndex = [testSelRows nextObject]; - currIndex != nil; - currIndex = [testSelRows nextObject]) - { - index = [currIndex intValue]; - BookmarkItem* item = [mOutlineView itemAtRow: index]; - if ([mOutlineView isExpandable: item]) { - // dumb check to see if we're deleting an empty folder. Should really - // recurse down - if ([self outlineView:mOutlineView numberOfChildrenOfItem: item] > 0) - haveBookmarks = YES; - } else - haveBookmarks = YES; - } - - // ideally, we should count the number of doomed bookmarks and tell the user - if (haveBookmarks) { - NSString *alert = NSLocalizedString(@"DeteleBookmarksAlert",@""); - NSString *message = NSLocalizedString(@"DeteleBookmarksMsg",@""); - NSString *okButton = NSLocalizedString(@"DeteleBookmarksOKButton",@""); - NSString *cancelButton = NSLocalizedString(@"DeteleBookmarksCancelButton",@""); - if (NSRunAlertPanel(alert, message, okButton, cancelButton, nil) != NSAlertDefaultReturn) - return; - } - - // The alert panel was the key window. As soon as we dismissed it, Cocoa will - // pick a new one for us. Ideally, it'll be the window we were using when - // we clicked the delete button. However, if by chance the BookmarkInfoController - // is visible, it will become the key window since it's a panel. If we then delete - // the bookmark and try to close the window before we've setup a new bookmark, - // we'll trigger the windowDidResignKey message, which will try to update the bookmark - // we just deleted, and things will crash. So, we'll trigger windowDidResignKey now - // and avoid the unpleasentness of a crash log. - - if (![[mBrowserWindowController window] isKeyWindow]) - [[mBrowserWindowController window] makeKeyWindow]; - - // we'll run into problems if a parent item and one if its children are both selected. - // A cheap way of having to avoid scanning the list to remove children is to have the - // outliner collapse all items that are being deleted. This will cull the selection - // for us and eliminate any children that happened to be selected. - NSEnumerator* selRows = [mOutlineView selectedRowEnumerator]; - for (NSNumber* currIndex = [selRows nextObject]; - currIndex != nil; - currIndex = [selRows nextObject]) { - index = [currIndex intValue]; - BookmarkItem* item = [mOutlineView itemAtRow: index]; - [mOutlineView collapseItem: item]; - } - - // create array of items we need to delete. Deleting items out of of the - // selection array is problematic for some reason. - NSMutableArray* itemsToDelete = [[[NSMutableArray alloc] init] autorelease]; - selRows = [mOutlineView selectedRowEnumerator]; - for (NSNumber* currIndex = [selRows nextObject]; - currIndex != nil; - currIndex = [selRows nextObject]) { - index = [currIndex intValue]; - BookmarkItem* item = [mOutlineView itemAtRow: index]; - [itemsToDelete addObject: item]; - } - - // delete all bookmarks that are in our array - int count = [itemsToDelete count]; - for (int i = 0; i < count; i++) { - BookmarkItem* item = [itemsToDelete objectAtIndex: i]; - [self deleteBookmark: item]; - } - - // restore selection to location near last item deleted or last item - int total = [mOutlineView numberOfRows]; - if (index >= total) - index = total - 1; - [mOutlineView selectRow: index byExtendingSelection: NO]; - // lame, but makes sure we catch all delete events in Info Panel - [[NSNotificationCenter defaultCenter] postNotificationName:@"NSOutlineViewSelectionDidChangeNotification" object:mOutlineView]; - -} - --(void)deleteBookmark:(id)aItem -{ - nsCOMPtr content = [aItem contentNode]; - nsCOMPtr child(do_QueryInterface(content)); - if (!child) - return; - if (child == BookmarksService::gToolbarRoot) - return; // Don't allow the personal toolbar to be deleted. - - nsCOMPtr parent; - child->GetParentNode(getter_AddRefs(parent)); - nsCOMPtr parentContent(do_QueryInterface(parent)); - nsCOMPtr dummy; - if (parent) - parent->RemoveChild(child, getter_AddRefs(dummy)); - mBookmarks->BookmarkRemoved(parentContent, content); -} - --(IBAction)openBookmark: (id)aSender -{ - int index = [mOutlineView selectedRow]; - if (index == -1) - return; - - id item = [mOutlineView itemAtRow: index]; - if (!item) - return; - - nsIContent* content = [item contentNode]; - nsCOMPtr elt(do_QueryInterface(content)); - nsAutoString group; - content->GetAttr(kNameSpaceID_None, BookmarksService::gGroupAtom, group); - if (!group.IsEmpty()) - mBookmarks->OpenBookmarkGroup([mBrowserWindowController getTabBrowser], elt); - else if ([mOutlineView isExpandable: item]) { - if ([mOutlineView isItemExpanded: item]) - [mOutlineView collapseItem: item]; - else - [mOutlineView expandItem: item]; - } - else { - nsAutoString href; - content->GetAttr(kNameSpaceID_None, BookmarksService::gHrefAtom, href); - if (!href.IsEmpty()) { - NSString* url = [NSString stringWith_nsAString: href]; - [[mBrowserWindowController getBrowserWrapper] loadURI: url referrer:nil flags: NSLoadFlagsNone activate:YES]; - } - } -} - --(NSString*) resolveKeyword: (NSString*) aKeyword -{ - return BookmarksService::ResolveKeyword(aKeyword); -} - -#pragma mark - - -// -// outlineView:shouldEditTableColumn:item: (delegate method) -// -// Called by the outliner to determine whether or not we should allow the -// user to edit this item. For now, Cocoa doesn't correctly handle editing -// of attributed strings with icons, so we can't turn this on. :( -// -- (BOOL)outlineView:(NSOutlineView *)outlineView shouldEditTableColumn:(NSTableColumn *)tableColumn item:(id)item -{ - return NO; -} - -- (id)outlineView:(NSOutlineView *)outlineView child:(int)index ofItem:(id)item -{ - if (!mBookmarks) - return nil; - - nsCOMPtr content; - if (!item) - BookmarksService::GetRootContent(getter_AddRefs(content)); - else - content = [item contentNode]; - - nsCOMPtr child; - content->ChildAt(index, *getter_AddRefs(child)); - if ( child ) - return BookmarksService::GetWrapperFor(child); - - return nil; -} - -- (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item -{ - if (!mBookmarks) - return NO; - - if (!item) - return YES; // The root node is always open. - - BOOL isExpandable = [item isFolder]; - -// XXXben - persistence of folder open state -// I'm adding this code, turned off, until I can figure out how to refresh the NSOutlineView's -// row count. Currently the items are expanded, but the outline view continues to believe it had -// the number of rows it had before the item was opened visible, until the view is resized. -#if 0 - if (isExpandable) { - PRBool isOpen = content->HasAttr(kNameSpaceID_None, BookmarksService::gOpenAtom); - if (isOpen) - [mOutlineView expandItem: item]; - else - [mOutlineView collapseItem: item]; - } -#endif - - return isExpandable; -} - -- (int)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item -{ - if (!mBookmarks) - return 0; - - nsCOMPtr content; - if (!item) - mBookmarks->GetRootContent(getter_AddRefs(content)); - else - content = [item contentNode]; - - PRInt32 childCount; - content->ChildCount(childCount); - - return childCount; -} - -- (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item -{ - NSString *columnName = [tableColumn identifier]; - NSMutableAttributedString *cellValue = [[NSMutableAttributedString alloc] init]; - NSFileWrapper *fileWrapper = [[NSFileWrapper alloc] initRegularFileWithContents:nil]; - NSTextAttachment *textAttachment = [[NSTextAttachment alloc] initWithFileWrapper:fileWrapper]; - NSMutableAttributedString *attachmentAttrString = nil; - NSCell *attachmentAttrStringCell; - - if ([columnName isEqualToString: @"name"]) { - nsIContent* content = [item contentNode]; - nsAutoString nameAttr; - content->GetAttr(kNameSpaceID_None, BookmarksService::gNameAtom, nameAttr); - - //Set cell's textual contents - [cellValue replaceCharactersInRange:NSMakeRange(0, [cellValue length]) withString:[NSString stringWith_nsAString: nameAttr]]; - - //Create an attributed string to hold the empty attachment, then release the components. - attachmentAttrString = [[NSMutableAttributedString attributedStringWithAttachment:textAttachment] retain]; - [textAttachment release]; - [fileWrapper release]; - - //Get the cell of the text attachment. - attachmentAttrStringCell = (NSCell *)[(NSTextAttachment *)[attachmentAttrString attribute:NSAttachmentAttributeName atIndex:0 effectiveRange:nil] attachmentCell]; - - nsCOMPtr elt(do_QueryInterface(content)); - NSImage* bookmarkImage = mBookmarks->CreateIconForBookmark(elt); - [attachmentAttrStringCell setImage:bookmarkImage]; - - //Insert the image - [cellValue replaceCharactersInRange:NSMakeRange(0, 0) withAttributedString:attachmentAttrString]; - - //Tweak the baseline to vertically center the text. - [cellValue addAttribute:NSBaselineOffsetAttributeName - value:[NSNumber numberWithFloat:-3.0] - range:NSMakeRange(0, 1)]; - } - return cellValue; -} - -- (void)outlineView:(NSOutlineView *)outlineView setObjectValue:(id)object forTableColumn:(NSTableColumn *)tableColumn byItem:(id)item -{ -#if NOT_USED - // ignore all this. It doesn't work, but i'm leaving it here just in case we ever try to turn - // this code back on. We have to remove the attributes from the string in order to correctly - // set it in the DOM. - - NSString *columnName = [tableColumn identifier]; - if ( [columnName isEqualTo:@"name"] ) { - // remove the attributes - int strLen = [object length]; - NSMutableAttributedString *cellValue = [[NSMutableAttributedString alloc] initWithAttributedString:object]; - [cellValue removeAttribute:NSBaselineOffsetAttributeName range:NSMakeRange(0,1)]; - [cellValue removeAttribute:NSAttachmentAttributeName range:NSMakeRange(0,strLen)]; - - // extract the unicode - strLen = [cellValue length]; - PRUnichar* buffer = new PRUnichar[strLen + 1]; - buffer[strLen] = '\0'; - if ( !buffer ) - return; - [cellValue getCharacters: buffer]; - nsAutoString nameAttr; - nameAttr.Adopt(buffer); - - // stash it into the dom. - nsIContent* content = [item contentNode]; - content->SetAttr(kNameSpaceID_None, BookmarksService::gNameAtom, nameAttr, PR_TRUE); - - [cellValue release]; - } -#endif -} - - -- (BOOL)outlineView:(NSOutlineView *)ov writeItems:(NSArray*)items toPasteboard:(NSPasteboard*)pboard -{ - if (!mBookmarks) - return NO; - -#ifdef FILTER_DESCENDANT_ON_DRAG - NSArray *toDrag = BookmarksService::FilterOutDescendantsForDrag(items); -#else - NSArray *toDrag = items; -#endif - int count = [toDrag count]; - if (count > 0) { - // Create Pasteboard Data - NSMutableArray *draggedID = [NSMutableArray arrayWithCapacity: count]; - - for (int i = 0; i < count; i++) - [draggedID addObject: [[toDrag objectAtIndex: i] contentID]]; - - if (count == 1) { - // if we have just one item, we add some more flavours - [pboard declareTypes: [NSArray arrayWithObjects: - @"MozBookmarkType", NSURLPboardType, NSStringPboardType, nil] owner: self]; - [pboard setPropertyList: draggedID forType: @"MozBookmarkType"]; - - NSString* itemURL = [[toDrag objectAtIndex: 0] url]; - [pboard setString:itemURL forType: NSStringPboardType]; - [[NSURL URLWithString:itemURL] writeToPasteboard: pboard]; - // maybe construct the @"MozURLType" type here also - } - else { - // multiple bookmarks. Array sof strings or NSURLs seem to - // confuse receivers. Not sure what the correct way is. - [pboard declareTypes: [NSArray arrayWithObject: @"MozBookmarkType"] owner: self]; - [pboard setPropertyList: draggedID forType: @"MozBookmarkType"]; - } - - return YES; - } - - return NO; -} - - -- (NSDragOperation)outlineView:(NSOutlineView*)ov validateDrop:(id )info proposedItem:(id)item proposedChildIndex:(int)index -{ - NSArray* types = [[info draggingPasteboard] types]; - - // if the index is -1, deny the drop - if (index == NSOutlineViewDropOnItemIndex) - return NSDragOperationNone; - - if ([types containsObject: @"MozBookmarkType"]) { - NSArray *draggedIDs = [[info draggingPasteboard] propertyListForType: @"MozBookmarkType"]; - BookmarkItem* parent; - parent = (item) ? item : BookmarksService::GetRootItem(); - return (BookmarksService::IsBookmarkDropValid(parent, index, draggedIDs)) ? NSDragOperationGeneric : NSDragOperationNone; - } else if ([types containsObject: @"MozURLType"]) { - return NSDragOperationGeneric; - } else if ([types containsObject: NSStringPboardType]) { - return NSDragOperationGeneric; - } - - return NSDragOperationNone; -} - -- (BOOL)outlineView:(NSOutlineView*)ov acceptDrop:(id )info item:(id)item childIndex:(int)index -{ - NSArray *types = [[info draggingPasteboard] types]; - BookmarkItem* parent = (item) ? item : BookmarksService::GetRootItem(); - - if ([types containsObject: @"MozBookmarkType"]) - { - NSArray *draggedItems = [[info draggingPasteboard] propertyListForType: @"MozBookmarkType"]; - return BookmarksService::PerformBookmarkDrop(parent, index, draggedItems); - } - else if ([types containsObject: @"MozURLType"]) - { - NSDictionary* proxy = [[info draggingPasteboard] propertyListForType: @"MozURLType"]; - BookmarkItem* beforeItem = [self outlineView:ov child:index ofItem:item]; - return BookmarksService::PerformProxyDrop(parent, beforeItem, proxy); - } - else if ([types containsObject: NSStringPboardType]) - { - NSString* draggedText = [[info draggingPasteboard] stringForType:NSStringPboardType]; - BookmarkItem* beforeItem = [self outlineView:ov child:index ofItem:item]; - return BookmarksService::PerformURLDrop(parent, beforeItem, draggedText, draggedText); - } - - return NO; -} - -- (NSString *)outlineView:(NSOutlineView *)outlineView tooltipStringForItem:(id)item -{ - NSString* descStr = nil; - NSString* hrefStr = nil; - nsIContent* content = [item contentNode]; - nsAutoString value; - - content->GetAttr(kNameSpaceID_None, BookmarksService::gDescriptionAtom, value); - if (value.Length()) - descStr = [NSString stringWith_nsAString:value]; - - // Only description for folders - if ([item isFolder]) - return descStr; - - // Extract the URL from the item - content->GetAttr(kNameSpaceID_None, BookmarksService::gHrefAtom, value); - if (value.Length()) - hrefStr = [NSString stringWith_nsAString:value]; - - if (!hrefStr) - return descStr; - else if (!descStr) - return hrefStr; - - // Display both URL and description - return [NSString stringWithFormat:@"%@\n%@", hrefStr, descStr]; -} - -/* -- (NSMenu *)outlineView:(NSOutlineView *)outlineView contextMenuForItem:(id)item -{ - // TODO - return (custom?) context menu for item here. - // Note that according to HIG, there should never be disabled items in - // a context menu - instead, items that do not apply should be removed. - // We could nicely do that here. -} -*/ - -- (void)reloadDataForItem:(id)item reloadChildren: (BOOL)aReloadChildren -{ - if (!item) - [mOutlineView reloadData]; - else - [mOutlineView reloadItem: item reloadChildren: aReloadChildren]; -} - --(IBAction)openBookmarkInNewTab:(id)aSender -{ - int index = [mOutlineView selectedRow]; - if (index == -1) - return; - if ([mOutlineView numberOfSelectedRows] == 1) { - nsCOMPtr pref(do_GetService("@mozilla.org/preferences-service;1")); - if (!pref) - return; // Something bad happened if we can't get prefs. - - BookmarkItem* item = [mOutlineView itemAtRow: index]; - nsAutoString hrefAttr; - [item contentNode]->GetAttr(kNameSpaceID_None, BookmarksService::gHrefAtom, hrefAttr); - - // stuff it into the string - NSString* hrefStr = [NSString stringWith_nsAString:hrefAttr]; - - PRBool loadInBackground; - pref->GetBoolPref("browser.tabs.loadInBackground", &loadInBackground); - - [mBrowserWindowController openNewTabWithURL: hrefStr referrer:nil loadInBackground: loadInBackground]; - } -} - --(IBAction)openBookmarkInNewWindow:(id)aSender -{ - int index = [mOutlineView selectedRow]; - if (index == -1) - return; - if ([mOutlineView numberOfSelectedRows] == 1) { - nsCOMPtr pref(do_GetService("@mozilla.org/preferences-service;1")); - if (!pref) - return; // Something bad happened if we can't get prefs. - - BookmarkItem* item = [mOutlineView itemAtRow: index]; - nsAutoString hrefAttr; - [item contentNode]->GetAttr(kNameSpaceID_None, BookmarksService::gHrefAtom, hrefAttr); - - // stuff it into the string - NSString* hrefStr = [NSString stringWith_nsAString:hrefAttr]; - - PRBool loadInBackground; - pref->GetBoolPref("browser.tabs.loadInBackground", &loadInBackground); - - nsAutoString group; - [item contentNode]->GetAttr(kNameSpaceID_None, BookmarksService::gGroupAtom, group); - if (group.IsEmpty()) - [mBrowserWindowController openNewWindowWithURL: hrefStr referrer: nil loadInBackground: loadInBackground]; - else { - nsCOMPtr elt(do_QueryInterface([item contentNode])); - [mBrowserWindowController openNewWindowWithGroup: elt loadInBackground: loadInBackground]; - } - } -} - --(void)openBookmarkGroup:(id)aTabView groupElement:(nsIDOMElement*)aFolder -{ - mBookmarks->OpenBookmarkGroup(aTabView, aFolder); -} - --(IBAction)showBookmarkInfo:(id)aSender -{ - BookmarkInfoController *bic = [BookmarkInfoController sharedBookmarkInfoController]; - - int index = [mOutlineView selectedRow]; - BookmarkItem* item = [mOutlineView itemAtRow: index]; - [bic setBookmark:item]; - - [bic showWindow:bic]; -} - -- (BOOL)haveSelectedRow -{ - return ([mOutlineView selectedRow] != -1); -} - --(void)outlineViewSelectionDidChange: (NSNotification*) aNotification -{ - BookmarkInfoController *bic = [BookmarkInfoController sharedBookmarkInfoController]; - int index = [mOutlineView selectedRow]; - if (index == -1) { - [mEditBookmarkButton setEnabled:NO]; - [mDeleteBookmarkButton setEnabled:NO]; - [bic close]; - } - else { - [mEditBookmarkButton setEnabled:YES]; - [mDeleteBookmarkButton setEnabled:YES]; - if ([[bic window] isVisible]) - [bic setBookmark:[mOutlineView itemAtRow:index]]; - } -} - --(BOOL)validateMenuItem:(NSMenuItem*)aMenuItem -{ - int index = [mOutlineView selectedRow]; - if (index == -1) - return NO; - - BookmarkItem* item = [mOutlineView itemAtRow: index]; - BOOL isBookmark = [mOutlineView isExpandable:item] == NO; - - nsAutoString group; - [item contentNode]->GetAttr(kNameSpaceID_None, BookmarksService::gGroupAtom, group); - BOOL isGroup = !group.IsEmpty(); - - if (([aMenuItem action] == @selector(openBookmarkInNewWindow:))) { - // Bookmarks and Bookmark Groups can be opened in a new window - return (isBookmark || isGroup); - } - else if (([aMenuItem action] == @selector(openBookmarkInNewTab:))) { - // Only Bookmarks can be opened in new tabs - return isBookmark && [mBrowserWindowController newTabsAllowed]; - } - return YES; -} - -- (void)outlineViewItemWillExpand:(NSNotification *)notification -{ - BookmarkItem* item = [[notification userInfo] objectForKey:[[[notification userInfo] allKeys] objectAtIndex: 0]]; - [item contentNode]->SetAttr(kNameSpaceID_None, BookmarksService::gOpenAtom, NS_LITERAL_STRING("true"), PR_FALSE); -} - -- (void)outlineViewItemWillCollapse:(NSNotification *)notification -{ - BookmarkItem* item = [[notification userInfo] objectForKey:[[[notification userInfo] allKeys] objectAtIndex: 0]]; - [item contentNode]->UnsetAttr(kNameSpaceID_None, BookmarksService::gOpenAtom, PR_FALSE); -} - -@end - -#pragma mark - - -@implementation BookmarkItem - --(void)dealloc -{ - [mSiteIcon release]; - [super dealloc]; -} - --(nsIContent*)contentNode -{ - return mContentNode; -} - -- (NSNumber*)contentID -{ - PRUint32 contentID = 0; - mContentNode->GetContentID(&contentID); - return [NSNumber numberWithInt: contentID]; -} - -- (NSString *)description -{ - nsCOMPtr item = [self contentNode]; - nsCOMPtr element(do_QueryInterface(item)); - nsAutoString href; - element->GetAttribute(NS_LITERAL_STRING("name"), href); - NSString* info = [NSString stringWith_nsAString: href]; - return [NSString stringWithFormat:@"", info]; -} - -- (NSString *)url -{ - nsCOMPtr item = [self contentNode]; - nsCOMPtr element(do_QueryInterface(item)); - nsAutoString href; - element->GetAttribute(NS_LITERAL_STRING("href"), href); - return [NSString stringWith_nsAString: href]; -} - -- (void)setSiteIcon:(NSImage*)image -{ - //NSLog(@"Setting site icon for %@", [self url]); - [mSiteIcon autorelease]; - mSiteIcon = [image retain]; -} - -- (NSImage*)siteIcon -{ - return mSiteIcon; -} - --(void)setContentNode: (nsIContent*)aContentNode -{ - mContentNode = aContentNode; -} - -- (id)copyWithZone:(NSZone *)aZone -{ - BookmarkItem* copy = [[[self class] allocWithZone: aZone] init]; - [copy setContentNode: mContentNode]; - [copy setSiteIcon: mSiteIcon]; - return copy; -} - -- (BOOL)isFolder -{ - nsCOMPtr tagName; - mContentNode->GetTag(*getter_AddRefs(tagName)); - - return (tagName == BookmarksService::gFolderAtom); -} - -@end - diff --git a/mozilla/camino/BookmarksService.h b/mozilla/camino/BookmarksService.h deleted file mode 100644 index 411935e2517..00000000000 --- a/mozilla/camino/BookmarksService.h +++ /dev/null @@ -1,164 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape 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/NPL/ - * - * 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 mozilla.org 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 NPL, 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 NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include -#include - -#include "nsCOMPtr.h" -#include "nsIDocument.h" -#include "nsIDocumentObserver.h" -#include "nsVoidArray.h" - -#import "MainController.h" -#import "CHBookmarksToolbar.h" -#import "CHExtendedOutlineView.h" - -class nsIAtom; -class nsIDOMHTMLDocument; - -@class BookmarksDataSource; -@class BookmarkItem; - -// despite appearances, BookmarksService is not a singleton. We make one for the bookmarks menu, -// one each per BookmarksDataSource, and one per bookmarks toolbar. It relies on a bunch of global -// variables, which is evil. -class BookmarksService -{ -public: - BookmarksService(BookmarksDataSource* aDataSource); - BookmarksService(CHBookmarksToolbar* aToolbar); - virtual ~BookmarksService(); - - void AddObserver(); - void RemoveObserver(); - -public: - static void BookmarkAdded(nsIContent* aContainer, nsIContent* aChild, bool shouldFlush = true); - static void BookmarkChanged(nsIContent* aItem, bool shouldFlush = true); - static void BookmarkRemoved(nsIContent* aContainer, nsIContent* aChild, bool shouldFlush = true); - - static void AddBookmarkToFolder(nsString& aURL, nsString& aTitle, nsIDOMElement* aFolder, nsIDOMElement* aBeforeElt); - static void MoveBookmarkToFolder(nsIDOMElement* aBookmark, nsIDOMElement* aFolder, nsIDOMElement* aBeforeElt); - static void DeleteBookmark(nsIDOMElement* aBookmark); - - static void GetRootContent(nsIContent** aResult); - static BookmarkItem* GetRootItem(); - static BookmarkItem* GetWrapperFor(nsIContent* aItem); - static BookmarkItem* GetWrapperFor(PRUint32 contentID); - - static void ReadBookmarks(); - static void FlushBookmarks(); - - static void ConstructBookmarksMenu(NSMenu* aMenu, nsIContent* aContent); - static void OpenMenuBookmark(BrowserWindowController* aController, id aMenuItem); - static void AddMenuBookmark(NSMenu* aMenu, nsIContent* aParent, nsIContent* aChild, PRInt32 aIndex); - static NSMenu* LocateMenu(nsIContent* aContent); - - static void ConstructAddBookmarkFolderList(NSPopUpButton* aPopup, BookmarkItem* aItem); - - static NSImage* CreateIconForBookmark(nsIDOMElement* aElement); - - static void EnsureToolbarRoot(); - - static void ImportBookmarks(nsIDOMHTMLDocument* aHTMLDoc); - - static void GetTitleAndHrefForBrowserView(id aBrowserView, nsString& aTitle, nsString& aHref); - static void OpenBookmarkGroup(id aTabView, nsIDOMElement* aFolder); - - static NSString* ResolveKeyword(NSString* aKeyword); - - static BOOL DoAncestorsIncludeNode(BookmarkItem* bookmark, BookmarkItem* searchItem); - static bool IsBookmarkDropValid(BookmarkItem* proposedParent, int index, NSArray* draggedIDs); - static bool PerformBookmarkDrop(BookmarkItem* parent, int index, NSArray* draggedIDs); - static bool PerformProxyDrop(BookmarkItem* parentItem, BookmarkItem* beforeItem, NSDictionary* data); - - static bool PerformURLDrop(BookmarkItem* parentItem, BookmarkItem* beforeItem, NSString* title, NSString* url); - -public: - // Global counter and pointers to our singletons. - static PRUint32 gRefCnt; - - // A dictionary that maps from content IDs (which uniquely identify content nodes) - // to Obj-C bookmarkItem objects. These objects are handed back to UI elements like - // the outline view. - static NSMutableDictionary* gDictionary; - static MainController* gMainController; - static NSMenu* gBookmarksMenu; - static nsIDOMElement* gToolbarRoot; - static nsIAtom* gFolderAtom; - static nsIAtom* gNameAtom; - static nsIAtom* gHrefAtom; - static nsIAtom* gKeywordAtom; - static nsIAtom* gDescriptionAtom; - static nsIAtom* gBookmarkAtom; - static nsIAtom* gOpenAtom; - static nsIAtom* gGroupAtom; - static nsIDocument* gBookmarks; - static BOOL gBookmarksFileReadOK; - static nsVoidArray* gInstances; - static int CHInsertNone; - static int CHInsertInto; - static int CHInsertBefore; - static int CHInsertAfter; - -private: - // There are three kinds of bookmarks data sources: - // tree views (mDataSource), the personal toolbar (mToolbar) - // and menus (gBookmarksMenu). - CHBookmarksToolbar* mToolbar; - BookmarksDataSource* mDataSource; -}; - - - -// singleton bookmarks manager object - -@interface BookmarksManager : NSObject -{ - - - -} - -+ (BookmarksManager*)sharedBookmarksManager; - -- (void)loadProxyImageFor:(id)requestor withURI:(NSString*)inURIString; - - -@end - - diff --git a/mozilla/camino/BookmarksService.mm b/mozilla/camino/BookmarksService.mm deleted file mode 100644 index 2f3b7c8d57a..00000000000 --- a/mozilla/camino/BookmarksService.mm +++ /dev/null @@ -1,1434 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape 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/NPL/ - * - * 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 mozilla.org 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 NPL, 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 NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#import "NSString+Utils.h" - -#import "CHPreferenceManager.h" -#import "CHBrowserView.h" -#import "BookmarksService.h" -#import "BookmarksDataSource.h" -#import "BookmarkInfoController.h" -#import "BrowserTabView.h" -#import "SiteIconProvider.h" - -#include "nsCRT.h" -#include "nsString.h" -#include "nsIDocument.h" -#include "nsIContent.h" -#include "nsIAtom.h" -#include "nsITextContent.h" -#include "nsIDOMWindow.h" -#include "nsIDOMHTMLDocument.h" -#include "nsIDOMElement.h" -#include "nsIDOMCharacterData.h" -#include "nsIDOMParser.h" -#include "nsIDOMDocumentFragment.h" -#include "nsIPrefBranch.h" -#include "nsIFile.h" -#include "nsAppDirectoryServiceDefs.h" -#include "nsIXMLHttpRequest.h" -#include "nsIDOMSerializer.h" -#include "nsIDocumentEncoder.h" -#include "nsNetUtil.h" -#include "nsINamespaceManager.h" -#include "nsIXBLService.h" -#include "nsIWebBrowser.h" - - -// Helper for stripping whitespace -static void -StripWhitespaceNodes(nsIContent* aElement) -{ - PRInt32 childCount = 0; - aElement->ChildCount(childCount); - for (PRInt32 i = 0; i < childCount; i++) { - nsCOMPtr child; - aElement->ChildAt(i, *getter_AddRefs(child)); - nsCOMPtr text = do_QueryInterface(child); - if (text) { - PRBool isEmpty = PR_FALSE; - text->IsOnlyWhitespace(&isEmpty); - if (isEmpty) { - // This node contained nothing but whitespace. - // Remove it from the content model. - aElement->RemoveChildAt(i, PR_TRUE); - i--; // Decrement our count, since we just removed this child. - childCount--; // Also decrement our total count. - } - } - else - StripWhitespaceNodes(child); - } -} - -// the tag of the separator after which to insert bookmarks menu items -// this tag must not conflict with content IDs (which are all >=0) -// and match the tab in the .nib -static const int kBookmarksDividerTag = -1; - - -PRUint32 BookmarksService::gRefCnt = 0; -nsIDocument* BookmarksService::gBookmarks = nsnull; -NSMutableDictionary* BookmarksService::gDictionary = nil; -MainController* BookmarksService::gMainController = nil; -NSMenu* BookmarksService::gBookmarksMenu = nil; -nsIDOMElement* BookmarksService::gToolbarRoot = nsnull; - -nsIAtom* BookmarksService::gBookmarkAtom = nsnull; -nsIAtom* BookmarksService::gDescriptionAtom = nsnull; -nsIAtom* BookmarksService::gFolderAtom = nsnull; -nsIAtom* BookmarksService::gGroupAtom = nsnull; -nsIAtom* BookmarksService::gHrefAtom = nsnull; -nsIAtom* BookmarksService::gKeywordAtom = nsnull; -nsIAtom* BookmarksService::gNameAtom = nsnull; -nsIAtom* BookmarksService::gOpenAtom = nsnull; - -nsVoidArray* BookmarksService::gInstances = nsnull; - -BOOL BookmarksService::gBookmarksFileReadOK = NO; - -int BookmarksService::CHInsertNone = 0; -int BookmarksService::CHInsertInto = 1; -int BookmarksService::CHInsertBefore = 2; -int BookmarksService::CHInsertAfter = 3; - -BookmarksService::BookmarksService(BookmarksDataSource* aDataSource) -{ - mDataSource = aDataSource; - mToolbar = nil; -} - -BookmarksService::BookmarksService(CHBookmarksToolbar* aToolbar) -{ - mDataSource = nil; - mToolbar = aToolbar; -} - -BookmarksService::~BookmarksService() -{ -} - -void -BookmarksService::AddObserver() -{ - gRefCnt++; - if (gRefCnt == 1) { - gBookmarkAtom = NS_NewAtom("bookmark"); - gFolderAtom = NS_NewAtom("folder"); - gNameAtom = NS_NewAtom("name"); - gHrefAtom = NS_NewAtom("href"); - gOpenAtom = NS_NewAtom("open"); - gKeywordAtom = NS_NewAtom("id"); - gDescriptionAtom = NS_NewAtom("description"); - gGroupAtom = NS_NewAtom("group"); - gInstances = new nsVoidArray(); - - ReadBookmarks(); - } - - gInstances->AppendElement(this); -} - -void -BookmarksService::RemoveObserver() -{ - if (gRefCnt == 0) - return; - - gInstances->RemoveElement(this); - - gRefCnt--; - if (gRefCnt == 0) { - // Flush Bookmarks before shutting down as some changes are not flushed when - // they are performed (folder open/closed) as writing a whole bookmark file for - // that type of operation seems excessive. - FlushBookmarks(); - - NS_IF_RELEASE(gBookmarks); - NS_RELEASE(gBookmarkAtom); - NS_RELEASE(gFolderAtom); - NS_RELEASE(gNameAtom); - NS_RELEASE(gHrefAtom); - NS_RELEASE(gOpenAtom); - [gDictionary release]; - } -} - -#pragma mark - - -void -BookmarksService::GetRootContent(nsIContent** aResult) -{ - *aResult = nsnull; - if (gBookmarks) { - nsCOMPtr domDoc(do_QueryInterface(gBookmarks)); - if (!domDoc) return; - - nsCOMPtr elt; - domDoc->GetDocumentElement(getter_AddRefs(elt)); - if (elt) - elt->QueryInterface(NS_GET_IID(nsIContent), (void**)aResult); // Addref happens here. - } -} - -BookmarkItem* -BookmarksService::GetRootItem() -{ - nsCOMPtr rootContent; - BookmarksService::GetRootContent(getter_AddRefs(rootContent)); - BookmarkItem* rootItem = BookmarksService::GetWrapperFor(rootContent); - return rootItem; -} - -BookmarkItem* -BookmarksService::GetWrapperFor(nsIContent* aContent) -{ - if ( !aContent ) - return nil; - - if (!gDictionary) - gDictionary = [[NSMutableDictionary alloc] initWithCapacity: 30]; - - PRUint32 contentID = 0; - aContent->GetContentID(&contentID); - - BookmarkItem* item = [gDictionary objectForKey: [NSNumber numberWithInt: contentID]]; - if (item) - return item; - - // Create an item. - item = [[BookmarkItem alloc] init]; // The dictionary retains us. - [item setContentNode: aContent]; - [gDictionary setObject: item forKey: [NSNumber numberWithInt: contentID]]; - [item release]; - return item; -} - -BookmarkItem* -BookmarksService::GetWrapperFor(PRUint32 contentID) -{ - BookmarkItem* item = [gDictionary objectForKey: [NSNumber numberWithUnsignedInt: contentID]]; - return item; -} - -NSMenu* -BookmarksService::LocateMenu(nsIContent* aContent) -{ - nsCOMPtr parent; - aContent->GetParent(*getter_AddRefs(parent)); - if (!parent) { - return BookmarksService::gBookmarksMenu; - } - - NSMenu* parentMenu = LocateMenu(parent); - - PRUint32 contentID; - aContent->GetContentID(&contentID); - - NSMenuItem* childMenu = [parentMenu itemWithTag: contentID]; - return [childMenu submenu]; -} - -void -BookmarksService::BookmarkAdded(nsIContent* aContainer, nsIContent* aChild, bool shouldFlush) -{ - if (!gInstances || !gDictionary) - return; - - PRInt32 count = gInstances->Count(); - for (PRInt32 i = 0; i < count; i++) { - BookmarksService* instance = (BookmarksService*)gInstances->ElementAt(i); - - if (instance->mDataSource) { - // We're a tree view. - nsCOMPtr parent; - aContainer->GetParent(*getter_AddRefs(parent)); - - BookmarkItem* item = nil; - if (parent) - // We're not the root. - item = GetWrapperFor(aContainer); - - [(instance->mDataSource) reloadDataForItem: item reloadChildren: YES]; - } - else if (instance->mToolbar) { - // We're a personal toolbar. - nsCOMPtr parentElt(do_QueryInterface(aContainer)); - if (parentElt == gToolbarRoot) { - // We only care about changes that occur to the personal toolbar's immediate - // children. - PRInt32 index = -1; - aContainer->IndexOf(aChild, index); - nsCOMPtr elt(do_QueryInterface(aChild)); - [(instance->mToolbar) addButton: elt atIndex: index]; - } - } - else { - // We're the menu. - PRInt32 index = -1; - aContainer->IndexOf(aChild, index); - NSMenu* menu = LocateMenu(aContainer); - AddMenuBookmark(menu, aContainer, aChild, index); - } - } - - if (shouldFlush) - FlushBookmarks(); -} - -void -BookmarksService::BookmarkChanged(nsIContent* aItem, bool shouldFlush) -{ - if (!gInstances || !gDictionary) - return; - - PRInt32 count = gInstances->Count(); - for (PRInt32 i = 0; i < count; i++) { - BookmarksService* instance = (BookmarksService*)gInstances->ElementAt(i); - - if (instance->mDataSource) { - // We're a tree view - BookmarkItem* item = GetWrapperFor(aItem); - [(instance->mDataSource) reloadDataForItem: item reloadChildren: NO]; - } - else if (instance->mToolbar) { - // We're a personal toolbar. It'll figure out what to do. - nsCOMPtr elt(do_QueryInterface(aItem)); - [(instance->mToolbar) editButton: elt]; - } - else { - // We're the menu. Reset the title, in case it's changed. - nsCOMPtr parent; - aItem->GetParent(*getter_AddRefs(parent)); - NSMenu* menu = LocateMenu(parent); - PRUint32 contentID = 0; - aItem->GetContentID(&contentID); - NSMenuItem* childItem = [menu itemWithTag: contentID]; - nsAutoString name; - aItem->GetAttr(kNameSpaceID_None, gNameAtom, name); - NSString* bookmarkTitle = [[NSString stringWith_nsAString: name] stringByTruncatingTo:80 at:kTruncateAtMiddle]; - [childItem setTitle: bookmarkTitle]; - - // and reset the image - BookmarkItem* item = GetWrapperFor(aItem); - [childItem setImage: [item siteIcon]]; - } - - } - - if (shouldFlush) - FlushBookmarks(); -} - -void -BookmarksService::BookmarkRemoved(nsIContent* aContainer, nsIContent* aChild, bool shouldFlush) -{ - if (!gInstances) - return; - - PRInt32 count = gInstances->Count(); - for (PRInt32 i = 0; i < count; i++) { - BookmarksService* instance = (BookmarksService*)gInstances->ElementAt(i); - - if (instance->mDataSource) { - // We're a tree view. - nsCOMPtr parent; - aContainer->GetParent(*getter_AddRefs(parent)); - - BookmarkItem* item = nil; - if (parent) - // We're not the root. - item = GetWrapperFor(aContainer); - - [(instance->mDataSource) reloadDataForItem: item reloadChildren: YES]; - } - else if (instance->mToolbar) { - // We're a personal toolbar. - nsCOMPtr parentElt(do_QueryInterface(aContainer)); - if (parentElt == gToolbarRoot) { - // We only care about changes that occur to the personal toolbar's immediate - // children. - nsCOMPtr childElt(do_QueryInterface(aChild)); - [(instance->mToolbar) removeButton: childElt]; - } - } - else { - // We're the menu. - NSMenu* menu = LocateMenu(aContainer); - PRUint32 contentID = 0; - aChild->GetContentID(&contentID); - NSMenuItem* childItem = [menu itemWithTag: contentID]; - [menu removeItem: childItem]; - } - } - - if (shouldFlush) - FlushBookmarks(); -} - - -void -BookmarksService::AddBookmarkToFolder(nsString& aURL, nsString& aTitle, nsIDOMElement* aFolder, nsIDOMElement* aBeforeElt) -{ - // XXX if no folder provided, default to root folder - if (!aFolder) return; - - nsCOMPtr domDoc(do_QueryInterface(gBookmarks)); - nsCOMPtr elt; - domDoc->CreateElementNS(NS_LITERAL_STRING("http://chimera.mozdev.org/bookmarks/"), - NS_LITERAL_STRING("bookmark"), - getter_AddRefs(elt)); - - elt->SetAttribute(NS_LITERAL_STRING("name"), aTitle); - elt->SetAttribute(NS_LITERAL_STRING("href"), aURL); - - MoveBookmarkToFolder(elt, aFolder, aBeforeElt); -} - -void -BookmarksService::MoveBookmarkToFolder(nsIDOMElement* aBookmark, nsIDOMElement* aFolder, nsIDOMElement* aBeforeElt) -{ - if (!aBookmark || !aFolder) return; - - nsCOMPtr oldParent; - aBookmark->GetParentNode(getter_AddRefs(oldParent)); - - nsCOMPtr dummy; - if (oldParent) { - nsCOMPtr bookmarkNode = do_QueryInterface(aBookmark); - oldParent->RemoveChild(bookmarkNode, getter_AddRefs(dummy)); - } - - if (aBeforeElt) { - aFolder->InsertBefore(aBookmark, aBeforeElt, getter_AddRefs(dummy)); - } else { - aFolder->AppendChild(aBookmark, getter_AddRefs(dummy)); - } - - nsCOMPtr childContent(do_QueryInterface(aBookmark)); - nsCOMPtr parentContent(do_QueryInterface(aFolder)); - - if (oldParent) { - nsCOMPtr oldParentContent(do_QueryInterface(oldParent)); - BookmarkRemoved(oldParentContent, childContent); - } - - BookmarkAdded(parentContent, childContent); -} - -void -BookmarksService::DeleteBookmark(nsIDOMElement* aBookmark) -{ - if (!aBookmark || aBookmark == gToolbarRoot) return; - - nsCOMPtr oldParent; - aBookmark->GetParentNode(getter_AddRefs(oldParent)); - - if (oldParent) { - nsCOMPtr dummy; - nsCOMPtr bookmarkNode = do_QueryInterface(aBookmark); - oldParent->RemoveChild(bookmarkNode, getter_AddRefs(dummy)); - - nsCOMPtr childContent(do_QueryInterface(aBookmark)); - nsCOMPtr oldParentContent(do_QueryInterface(oldParent)); - BookmarkRemoved(oldParentContent, childContent); - } -} - -static PRBool -CheckXMLDocumentParseSuccessful(nsIDOMDocument* inDOMDoc) -{ - nsCOMPtr docElement; - inDOMDoc->GetDocumentElement(getter_AddRefs(docElement)); - if (!docElement) - return PR_FALSE; - - nsCOMPtr tagName; - nsCOMPtr docContent = do_QueryInterface(docElement); - docContent->GetTag(*getter_AddRefs(tagName)); - - nsCOMPtr parserErrorAtom = do_GetAtom("parsererror"); - if (parserErrorAtom != tagName) - return PR_TRUE; - - return PR_FALSE; -} - -static PRBool -ValidateXMLDocument(nsIDOMDocument* inDOMDoc) -{ - if (!inDOMDoc) - return PR_FALSE; - - nsCOMPtr elt; - inDOMDoc->GetDocumentElement(getter_AddRefs(elt)); - if (!elt) - return PR_FALSE; - - nsCOMPtr domSerializer = do_CreateInstance(NS_XMLSERIALIZER_CONTRACTID); - if (!domSerializer) - return PR_FALSE; - - nsXPIDLString encodedDocStr; - nsresult rv = domSerializer->SerializeToString(inDOMDoc, getter_Copies(encodedDocStr)); - if (NS_FAILED(rv)) - return PR_FALSE; - - nsCOMPtr domParser = do_CreateInstance(NS_DOMPARSER_CONTRACTID); - if (!domParser) - return PR_FALSE; - - nsCOMPtr newDomDoc; - domParser->ParseFromString(encodedDocStr.get(), "text/xml", getter_AddRefs(newDomDoc)); - if (newDomDoc) - return CheckXMLDocumentParseSuccessful(newDomDoc); - - return PR_FALSE; -} - -void -BookmarksService::ReadBookmarks() -{ - nsCOMPtr profileDirBookmarks; - NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR, getter_AddRefs(profileDirBookmarks)); - profileDirBookmarks->Append(NS_LITERAL_STRING("bookmarks.xml")); - - PRBool fileExists = PR_FALSE; - profileDirBookmarks->Exists(&fileExists); - - // If the bookmarks file does not exist, copy from the defaults so we don't - // crash or anything dumb like that. - if (!fileExists) { - nsCOMPtr defaultBookmarksFile; - NS_GetSpecialDirectory(NS_APP_PROFILE_DEFAULTS_50_DIR, getter_AddRefs(defaultBookmarksFile)); - defaultBookmarksFile->Append(NS_LITERAL_STRING("bookmarks.xml")); - - // XXX for some reason unknown to me, leaving this code in causes the program to crash - // with 'cannot dereference null COMPtr.' -#if I_WANT_TO_CRASH - PRBool defaultFileExists; - defaultBookmarksFile->Exists(&defaultFileExists); - if (defaultFileExists) - return; -#endif - - nsCOMPtr profileDirectory; - NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR, getter_AddRefs(profileDirectory)); - - defaultBookmarksFile->CopyToNative(profileDirectory, NS_LITERAL_CSTRING("bookmarks.xml")); - } - - nsCAutoString bookmarksFileURL; - NS_GetURLSpecFromFile(profileDirBookmarks, bookmarksFileURL); - - nsCOMPtr uri; - NS_NewURI(getter_AddRefs(uri), bookmarksFileURL.get()); - - // XXX this is somewhat lame. we have no way of knowing whether or not the parse succeeded - // or failed. sigh. - // Actually, we do. We check for a root node. This relies on the XMLContentSink - // behaviour. - nsCOMPtr xblService(do_GetService("@mozilla.org/xbl;1")); - xblService->FetchSyncXMLDocument(uri, &gBookmarks); // addref here - - // test for a parser error. The XML parser replaces the document with one - // that has a node as the root. - nsCOMPtr bookmarksDOMDoc = do_QueryInterface(gBookmarks); - BOOL validPrefsFile = CheckXMLDocumentParseSuccessful(bookmarksDOMDoc); - - if (!validPrefsFile) { - // uh oh, parser error. Throw some UI - NSString *alert = NSLocalizedString(@"CorruptedBookmarksAlert",@""); - NSString *message = NSLocalizedString(@"CorruptedBookmarksMsg",@""); - NSString *okButton = NSLocalizedString(@"OKButtonText",@""); - NSRunAlertPanel(alert, message, okButton, nil, nil); - - // maybe we should read the default bookmarks here? - gBookmarksFileReadOK = PR_FALSE; - return; - } - - gBookmarksFileReadOK = PR_TRUE; - - nsCOMPtr rootNode; - GetRootContent(getter_AddRefs(rootNode)); - StripWhitespaceNodes(rootNode); -} - -void -BookmarksService::FlushBookmarks() -{ - // XXX we need to insert a mechanism here to ensure that we don't write corrupt - // bookmarks files (e.g. full disk, program crash, whatever), because our - // error handling in the parse stage is NON-EXISTENT. - // This is now partially handled by looking for a node at read time. - if (!gBookmarksFileReadOK) - return; - - nsCOMPtr bookmarksFile; - NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR, getter_AddRefs(bookmarksFile)); - bookmarksFile->Append(NS_LITERAL_STRING("bookmarks.xml")); - - nsCOMPtr outputStream; - NS_NewLocalFileOutputStream(getter_AddRefs(outputStream), bookmarksFile); - - nsCOMPtr domDoc(do_QueryInterface(gBookmarks)); - - nsCOMPtr domSerializer(do_CreateInstance(NS_XMLSERIALIZER_CONTRACTID)); - if (domSerializer) - domSerializer->SerializeToStream(domDoc, outputStream, nsnull); -} - -NSImage* -BookmarksService::CreateIconForBookmark(nsIDOMElement* aElement) -{ - nsCOMPtr tagName; - nsCOMPtr content = do_QueryInterface(aElement); - content->GetTag(*getter_AddRefs(tagName)); - - nsAutoString group; - content->GetAttr(kNameSpaceID_None, gGroupAtom, group); - if (!group.IsEmpty()) - return [NSImage imageNamed:@"groupbookmark"]; - - if (tagName == BookmarksService::gFolderAtom) - return [NSImage imageNamed:@"folder"]; - - // fire off a proxy icon load - if ([[CHPreferenceManager sharedInstance] getBooleanPref:"browser.chrome.site_icons" withSuccess:NULL]) - { - nsAutoString href; - content->GetAttr(kNameSpaceID_None, gHrefAtom, href); - if (href.Length() > 0) - { - BookmarkItem* contentItem = BookmarksService::GetWrapperFor(content); - if ([contentItem siteIcon]) - return [contentItem siteIcon]; - - if (contentItem && ![contentItem siteIcon]) - [[BookmarksManager sharedBookmarksManager] loadProxyImageFor:contentItem withURI:[NSString stringWith_nsAString:href]]; - } - } - - return [NSImage imageNamed:@"smallbookmark"]; -} - -void BookmarksService::EnsureToolbarRoot() -{ - if (gToolbarRoot) - return; - - nsCOMPtr domDoc(do_QueryInterface(gBookmarks)); - nsCOMPtr rootElt; - domDoc->GetDocumentElement(getter_AddRefs(rootElt)); - - nsCOMPtr child; - rootElt->GetFirstChild(getter_AddRefs(child)); - nsAutoString typeValue; - while (child) { - nsCOMPtr childElt(do_QueryInterface(child)); - if (childElt) { - childElt->GetAttribute(NS_LITERAL_STRING("type"), typeValue); - if (typeValue.Equals(NS_LITERAL_STRING("toolbar"))) - gToolbarRoot = childElt; - } - - nsCOMPtr temp; - child->GetNextSibling(getter_AddRefs(temp)); - child = temp; - } - - if (!gToolbarRoot) { - NSLog(@"Repairing personal toolbar"); - nsCOMPtr elt; - domDoc->CreateElementNS(NS_LITERAL_STRING("http://chimera.mozdev.org/bookmarks/"), - NS_LITERAL_STRING("folder"), - getter_AddRefs(elt)); - - elt->SetAttribute(NS_LITERAL_STRING("name"), NS_LITERAL_STRING("Toolbar Bookmarks")); - elt->SetAttribute(NS_LITERAL_STRING("type"), NS_LITERAL_STRING("toolbar")); - - nsCOMPtr dummy; - rootElt->AppendChild(elt, getter_AddRefs(dummy)); - gToolbarRoot = elt; - } -} - -static -void RecursiveAddBookmarkConstruct(NSPopUpButton* aPopup, NSMenu* aMenu, int aTagToMatch, int depth = 0) -{ - // Get the menu item children. - NSArray* children = [aMenu itemArray]; - int startPosition = 0; - if (aMenu == BookmarksService::gBookmarksMenu) - startPosition = 3; - - int count = [children count]; - for (int i = startPosition; i < count; ++i) { - NSMenuItem* menuItem = [children objectAtIndex: i]; - NSMenu* submenu = [menuItem submenu]; - if (submenu) { - // This is a folder. Add it to our list and then recur. Indent it - // the apropriate depth for readability in the menu. - NSMutableString *title = [NSMutableString stringWithString:[menuItem title]]; - for (int j = 0; j <= depth; ++j) - [title insertString:@" " atIndex: 0]; - - [aPopup addItemWithTitle: title]; - NSMenuItem* lastItem = [aPopup lastItem]; - if ([menuItem tag] == aTagToMatch) - [aPopup selectItem: lastItem]; - - [lastItem setTag: [menuItem tag]]; - RecursiveAddBookmarkConstruct(aPopup, submenu, aTagToMatch, depth+1); - } - } -} - -void -BookmarksService::ConstructAddBookmarkFolderList(NSPopUpButton* aPopup, BookmarkItem* aItem) -{ - [aPopup removeAllItems]; - [aPopup addItemWithTitle: [gBookmarksMenu title]]; - NSMenuItem* lastItem = [aPopup lastItem]; - [lastItem setTag: -1]; - int tag = -1; - if (aItem) { - nsIContent* content = [aItem contentNode]; - PRUint32 utag; - content->GetContentID(&utag); - tag = (int)utag; - } - RecursiveAddBookmarkConstruct(aPopup, gBookmarksMenu, tag); -} - -void -BookmarksService::GetTitleAndHrefForBrowserView(id aBrowserView, nsString& aTitle, nsString& aHref) -{ - nsCOMPtr webBrowser = getter_AddRefs([aBrowserView getWebBrowser]); - nsCOMPtr window; - webBrowser->GetContentDOMWindow(getter_AddRefs(window)); - nsCOMPtr htmlDoc; - window->GetDocument(getter_AddRefs(htmlDoc)); - nsCOMPtr pageDoc(do_QueryInterface(htmlDoc)); - - if (pageDoc) { - nsCOMPtr url; - pageDoc->GetDocumentURL(getter_AddRefs(url)); - nsCAutoString spec; - url->GetSpec(spec); - aHref.AssignWithConversion(spec.get()); - } - - nsCOMPtr htmlDocument(do_QueryInterface(htmlDoc)); - if (htmlDocument) - htmlDocument->GetTitle(aTitle); - if (aTitle.IsEmpty()) - aTitle = aHref; -} - -void -BookmarksService::ConstructBookmarksMenu(NSMenu* aMenu, nsIContent* aContent) -{ - nsCOMPtr content = aContent; - if (!content) { - GetRootContent(getter_AddRefs(content)); - GetWrapperFor(content); - gBookmarksMenu = aMenu; - } - - // Now walk our children, and for folders also recur into them. - PRInt32 childCount; - content->ChildCount(childCount); - - for (PRInt32 i = 0; i < childCount; i++) { - nsCOMPtr child; - content->ChildAt(i, *getter_AddRefs(child)); - AddMenuBookmark(aMenu, content, child, -1); - } -} - -void -BookmarksService::AddMenuBookmark(NSMenu* aMenu, nsIContent* aParent, nsIContent* aChild, PRInt32 aIndex) -{ - nsAutoString name; - aChild->GetAttr(kNameSpaceID_None, gNameAtom, name); - NSString* title = [[NSString stringWith_nsAString: name] stringByTruncatingTo:80 at:kTruncateAtMiddle]; - - // Create a menu or menu item for the child. - NSMenuItem* menuItem = [[[NSMenuItem alloc] initWithTitle: title action: NULL keyEquivalent: @""] autorelease]; - GetWrapperFor(aChild); - - if (aIndex == -1) - [aMenu addItem: menuItem]; - else { - PRInt32 insertIndex = aIndex; - if (aMenu == gBookmarksMenu) // take static menu items into account - insertIndex += [aMenu indexOfItemWithTag:kBookmarksDividerTag] + 1; - - [aMenu insertItem: menuItem atIndex: insertIndex]; - } - - nsCOMPtr tagName; - aChild->GetTag(*getter_AddRefs(tagName)); - - nsAutoString group; - aChild->GetAttr(kNameSpaceID_None, gGroupAtom, group); - - nsCOMPtr elt(do_QueryInterface(aChild)); - NSImage* menuItemImage = BookmarksService::CreateIconForBookmark(elt); - - if (group.IsEmpty() && tagName == gFolderAtom) { - NSMenu* menu = [[[NSMenu alloc] initWithTitle: title] autorelease]; - [aMenu setSubmenu: menu forItem: menuItem]; - [menu setAutoenablesItems: NO]; - [menuItem setImage: menuItemImage]; - ConstructBookmarksMenu(menu, aChild); - } - else { - if (group.IsEmpty()) - [menuItem setImage: menuItemImage]; - else - [menuItem setImage: menuItemImage]; - - [menuItem setTarget: gMainController]; - [menuItem setAction: @selector(openMenuBookmark:)]; - } - - PRUint32 contentID; - aChild->GetContentID(&contentID); - [menuItem setTag: contentID]; -} - -void -BookmarksService::OpenMenuBookmark(BrowserWindowController* aController, id aMenuItem) -{ - // Get the corresponding bookmark item. - BookmarkItem* item = [gDictionary objectForKey: [NSNumber numberWithInt: [aMenuItem tag]]]; - - // Get the content node. - nsIContent* content = [item contentNode]; - nsAutoString group; - content->GetAttr(kNameSpaceID_None, gGroupAtom, group); - if (!group.IsEmpty()) { - nsCOMPtr elt(do_QueryInterface([item contentNode])); - return OpenBookmarkGroup([aController getTabBrowser], elt); - } - - // Get the href attribute. This is the URL we want to load. - nsAutoString href; - content->GetAttr(kNameSpaceID_None, gHrefAtom, href); - if (href.IsEmpty()) - return; - - NSString* url = [NSString stringWith_nsAString: href]; - - // Now load the URL in the window. - [aController loadURL:url referrer:nil activate:YES]; -} - -static void GetImportTitle(nsIDOMElement* aSrc, nsString& aTitle) -{ - aTitle.Truncate(0); - nsCOMPtr curr; - aSrc->GetFirstChild(getter_AddRefs(curr)); - while (curr) { - nsCOMPtr charData(do_QueryInterface(curr)); - if (charData) { - nsAutoString data; - charData->GetData(data); - aTitle += data; - } - else { - // Handle Omniweb's nesting of inside

for its folders. - nsCOMPtr elt(do_QueryInterface(curr)); - if (elt) { - nsAutoString localName; - elt->GetLocalName(localName); - ToLowerCase(localName); - if (localName.Equals(NS_LITERAL_STRING("a"))) { - aTitle = NS_LITERAL_STRING(""); - return GetImportTitle(elt, aTitle); - } - } - } - - nsCOMPtr temp = curr; - temp->GetNextSibling(getter_AddRefs(curr)); - } -} - -// sniff for control chars, which are defined to be in the range U+0000 to U+001F and U+007F to U+009F. -static PRBool ContainsControlChars(const nsString& inString) -{ - PRUint16 *c = (PRUint16*)inString.get(); // be sure to get unsigned - - while (*c) - { - if ((*c <= 0x001F) || (*c >= 0x007F && *c <= 0x009F)) - return PR_TRUE; - c ++; - } - - return PR_FALSE; -} - -static void CleanControlChars(nsString& ioString) -{ - if (ContainsControlChars(ioString)) - { - // strip control chars here. this is inefficient, but does it matter? - NSString* cleanedTitle = [[NSString stringWith_nsAString: ioString] - stringByReplacingCharactersInSet:[NSCharacterSet controlCharacterSet] withString:@""]; - [cleanedTitle assignTo_nsAString:ioString]; - NSLog(@"Removed control characters from bookmark string '%@'", cleanedTitle); - } -} - -static void CreateBookmark(nsIDOMElement* aSrc, nsIDOMElement* aDst, - nsIDOMDocument* aDstDoc, PRBool aIsFolder, - nsIDOMElement** aResult) -{ - nsAutoString tagName(NS_LITERAL_STRING("bookmark")); - if (aIsFolder) - tagName = NS_LITERAL_STRING("folder"); - - aDstDoc->CreateElementNS(NS_LITERAL_STRING("http://chimera.mozdev.org/bookmarks/"), - tagName, - aResult); // Addref happens here. - - nsAutoString title; - GetImportTitle(aSrc, title); - CleanControlChars(title); - - (*aResult)->SetAttribute(NS_LITERAL_STRING("name"), title); - - if (!aIsFolder) { - nsAutoString href; - aSrc->GetAttribute(NS_LITERAL_STRING("href"), href); - CleanControlChars(href); - (*aResult)->SetAttribute(NS_LITERAL_STRING("href"), href); - } - - nsCOMPtr dummy; - aDst->AppendChild(*aResult, getter_AddRefs(dummy)); -} - -static void AddImportedBookmarks(nsIDOMElement* aSrc, nsIDOMElement* aDst, nsIDOMDocument* aDstDoc, - PRInt32& aBookmarksType) -{ - nsAutoString localName; - aSrc->GetLocalName(localName); - ToLowerCase(localName); - nsCOMPtr newBookmark; - if (localName.Equals(NS_LITERAL_STRING("bookmarkinfo"))) - aBookmarksType = 1; // Omniweb. - else if (localName.Equals(NS_LITERAL_STRING("dt"))) { - // We have found either a folder or a leaf. - nsCOMPtr curr; - aSrc->GetFirstChild(getter_AddRefs(curr)); - while (curr) { - nsCOMPtr childElt(do_QueryInterface(curr)); - if (childElt) { - childElt->GetLocalName(localName); - ToLowerCase(localName); - if (localName.Equals(NS_LITERAL_STRING("a"))) { - // Guaranteed to be a bookmark in IE. Could be either in Omniweb. - nsCOMPtr dummy; - CreateBookmark(childElt, aDst, aDstDoc, PR_FALSE, getter_AddRefs(dummy)); - } - // Ignore the H3 we encounter. This will be dealt with later. - } - nsCOMPtr temp = curr; - temp->GetNextSibling(getter_AddRefs(curr)); - } - } - else if (localName.Equals(NS_LITERAL_STRING("dl"))) { - // The children of a folder. Recur inside. - // Locate the parent to create the folder. - nsCOMPtr node; - aSrc->GetPreviousSibling(getter_AddRefs(node)); - nsCOMPtr folderElt(do_QueryInterface(node)); - if (folderElt) { - // Make sure it's an H3 folder in Mozilla and IE. In Mozilla it will probably have an ID. - PRBool hasID; - folderElt->HasAttribute(NS_LITERAL_STRING("ID"), &hasID); - if (aBookmarksType != 1) { - if (hasID) - aBookmarksType = 2; // Mozilla - else - aBookmarksType = 0; // IE - } - nsAutoString localName; - folderElt->GetLocalName(localName); - ToLowerCase(localName); - if (localName.Equals(NS_LITERAL_STRING("h3"))) - CreateBookmark(folderElt, aDst, aDstDoc, PR_TRUE, getter_AddRefs(newBookmark)); - } - if (!newBookmark) - newBookmark = aDst; - // Recur over all our children. - nsCOMPtr curr; - aSrc->GetFirstChild(getter_AddRefs(curr)); - while (curr) { - nsCOMPtr elt(do_QueryInterface(curr)); - if (elt) - AddImportedBookmarks(elt, newBookmark, aDstDoc, aBookmarksType); - nsCOMPtr temp = curr; - temp->GetNextSibling(getter_AddRefs(curr)); - } - } - else { - // Recur over all our children. - nsCOMPtr curr; - aSrc->GetFirstChild(getter_AddRefs(curr)); - while (curr) { - nsCOMPtr elt(do_QueryInterface(curr)); - if (elt) - AddImportedBookmarks(elt, aDst, aDstDoc, aBookmarksType); - nsCOMPtr temp = curr; - temp->GetNextSibling(getter_AddRefs(curr)); - } - } -} - - -void -BookmarksService::ImportBookmarks(nsIDOMHTMLDocument* aHTMLDoc) -{ - nsCOMPtr htmlDocRoot; - aHTMLDoc->GetDocumentElement(getter_AddRefs(htmlDocRoot)); - - nsCOMPtr bookmarksRoot; - nsCOMPtr bookmarksDOMDoc(do_QueryInterface(gBookmarks)); - bookmarksDOMDoc->GetDocumentElement(getter_AddRefs(bookmarksRoot)); - - nsCOMPtr dummy; - - // Create the root of the new bookmarks by hand. - nsCOMPtr importedRootElement; - bookmarksDOMDoc->CreateElementNS( NS_LITERAL_STRING("http://chimera.mozdev.org/bookmarks/"), - NS_LITERAL_STRING("folder"), - getter_AddRefs(importedRootElement)); - - // Now crawl through the file and look for
elements. They signify folders - // or leaves. - PRInt32 bookmarksType = 0; // Assume IE. - AddImportedBookmarks(htmlDocRoot, importedRootElement, bookmarksDOMDoc, bookmarksType); - - if (bookmarksType == 0) - importedRootElement->SetAttribute(NS_LITERAL_STRING("name"), NS_LITERAL_STRING("Internet Explorer Favorites")); - else if (bookmarksType == 1) - importedRootElement->SetAttribute(NS_LITERAL_STRING("name"), NS_LITERAL_STRING("Omniweb Favorites")); - else if (bookmarksType == 2) - importedRootElement->SetAttribute(NS_LITERAL_STRING("name"), NS_LITERAL_STRING("Mozilla/Netscape Favorites")); - - // now put the new child into the doc, and validate it - bookmarksRoot->AppendChild(importedRootElement, getter_AddRefs(dummy)); - - PRBool bookmarksGood = ValidateXMLDocument(bookmarksDOMDoc); - if (!bookmarksGood) { - // uh oh, parser error. Remove the new node, and then throw some UI - bookmarksRoot->RemoveChild(importedRootElement, getter_AddRefs(dummy)); - - NSString *alert = NSLocalizedString(@"ErrorImportingBookmarksAlert",@""); - NSString *message = NSLocalizedString(@"ErrorImportingBookmarksMsg",@""); - NSString *okButton = NSLocalizedString(@"OKButtonText",@""); - NSRunAlertPanel(alert, message, okButton, nil, nil); - return; - } - - // Now do a notification that the root Favorites folder got added. This - // will update all our views. - nsCOMPtr parentContent(do_QueryInterface(bookmarksRoot)); - nsCOMPtr childContent(do_QueryInterface(importedRootElement)); - -#if 0 - // XXX testing - if (gDictionary) - [gDictionary removeAllObjects]; -#endif - - // this will save the file - BookmarkAdded(parentContent, childContent, true /* flush */); -} - -void -BookmarksService::OpenBookmarkGroup(id aTabView, nsIDOMElement* aFolder) -{ - // We might conceivably have to make new tabs in order to load all - // the items in the group. - int currentIndex = 0; - int total = [aTabView numberOfTabViewItems]; - nsCOMPtr child; - aFolder->GetFirstChild(getter_AddRefs(child)); - while (child) { - nsCOMPtr elt(do_QueryInterface(child)); - if (elt) { - nsAutoString href; - elt->GetAttribute(NS_LITERAL_STRING("href"), href); - if (!href.IsEmpty()) { - NSString* url = [NSString stringWith_nsAString: href]; - BrowserTabViewItem* tabViewItem = nil; - if (currentIndex >= total) { - // We need to make a new tab. - // XXX this needs fixing to not max out the number of tabs in a browser window. - // See [BrowserWindowController newTabsAllowed]; - tabViewItem = [BrowserTabView makeNewTabItem]; - CHBrowserWrapper* newView = [[[CHBrowserWrapper alloc] initWithTab: tabViewItem andWindow: [aTabView window]] autorelease]; - [tabViewItem setLabel: NSLocalizedString(@"UntitledPageTitle", @"")]; - [tabViewItem setView: newView]; - [aTabView addTabViewItem: tabViewItem]; - } - else - tabViewItem = [aTabView tabViewItemAtIndex: currentIndex]; - - [[tabViewItem view] loadURI: url referrer:nil - flags: NSLoadFlagsNone activate:(currentIndex == 0)]; - } - } - - nsCOMPtr temp = child; - temp->GetNextSibling(getter_AddRefs(child)); - currentIndex++; - } - - // Select the first tab. - [aTabView selectTabViewItemAtIndex: 0]; -} - -NSString* -BookmarksService::ResolveKeyword(NSString* aKeyword) -{ - nsAutoString keyword; - [aKeyword assignTo_nsAString:keyword]; - - if (keyword.IsEmpty()) - return [NSString string]; - -#if DEBUG - NSLog(@"str = %s", keyword.get()); -#endif - - nsCOMPtr domDoc(do_QueryInterface(gBookmarks)); - nsCOMPtr elt; - domDoc->GetElementById(keyword, getter_AddRefs(elt)); - - nsCOMPtr content(do_QueryInterface(elt)); - nsAutoString url; - if (content) { - content->GetAttr(kNameSpaceID_None, gHrefAtom, url); - return [NSString stringWith_nsAString: url]; - } - return [NSString string]; -} - -// Is searchItem equal to bookmark or bookmark's parent, grandparent, etc? -BOOL -BookmarksService::DoAncestorsIncludeNode(BookmarkItem* bookmark, BookmarkItem* searchItem) -{ - nsCOMPtr search = [searchItem contentNode]; - nsCOMPtr current = [bookmark contentNode]; - nsCOMPtr root; - GetRootContent(getter_AddRefs(root)); - - // If the search item is the root node, return yes immediatly - if (search == root) - return YES; - - // for each ancestor - while (current) { - // If this is the root node we can't search farther, and there was no match - if (current == root) - return NO; - - // If the two nodes match, then the search term is an ancestor of the given bookmark - if (search == current) - return YES; - - // If a match wasn't found, set up the next node to compare - nsCOMPtr oldCurrent = current; - oldCurrent->GetParent(*getter_AddRefs(current)); - } - - return NO; -} - - -#ifdef FILTER_DESCENDANT_ON_DRAG -/* -this has been disabled because it is too slow, and can cause a large -delay when the user is dragging lots of items. this needs to get -fixed someday. - -It should filter out every node whose parent is also being dragged. -*/ - -NSArray* -BookmarksService::FilterOutDescendantsForDrag(NSArray* nodes) -{ - NSMutableArray *toDrag = [NSMutableArray arrayWithArray: nodes]; - unsigned int i = 0; - - while (i < [toDrag count]) { - BookmarkItem* item = [toDrag objectAtIndex: i]; - bool matchFound = false; - - for (unsigned int j = 0; j < [toDrag count] && matchFound == NO; j++) { - if (i != j) // Don't compare to self, will always match - matchFound = BookmarksService::DoAncestorsIncludeNode(item, [toDrag objectAtIndex: j]); - } - - // if a match was found, remove the node from the array - if (matchFound) - [toDrag removeObjectAtIndex: i]; - else - i++; - } - - return toDrag; -} -#endif - -bool -BookmarksService::IsBookmarkDropValid(BookmarkItem* proposedParent, int index, NSArray* draggedIDs) -{ - if ( !draggedIDs ) - return NO; - - NSMutableArray *draggedItems = [NSMutableArray arrayWithCapacity: [draggedIDs count]]; - BOOL toolbarRootMoving = NO; - - for (unsigned int i = 0; i < [draggedIDs count]; i++) { - NSNumber* contentID = [draggedIDs objectAtIndex: i]; - BookmarkItem* bookmarkItem = BookmarksService::GetWrapperFor([contentID unsignedIntValue]); - nsCOMPtr itemContent = [bookmarkItem contentNode]; - nsCOMPtr itemElement(do_QueryInterface(itemContent)); - - if (itemElement == BookmarksService::gToolbarRoot) - toolbarRootMoving = YES; - - if (bookmarkItem) - [draggedItems addObject: bookmarkItem]; - } - - // If we are being dropped into the top level, allow it - if ([proposedParent contentNode] == [BookmarksService::GetRootItem() contentNode]) - return true; - - // If we are not being dropped on the top level, and the toolbar root is being moved, disallow - if (toolbarRootMoving) - return false; - - // Make sure that we are not being dropped into one of our own children - // If the proposed parent, or any of it's ancestors matches one of the nodes being dragged - // then deny the drag. - - for (unsigned int i = 0; i < [draggedItems count]; i++) { - if (BookmarksService::DoAncestorsIncludeNode(proposedParent, [draggedItems objectAtIndex: i])) { - return false; - } - } - - return true; -} - - -bool -BookmarksService::PerformProxyDrop(BookmarkItem* parentItem, BookmarkItem* beforeItem, NSDictionary* data) -{ - if ( !data ) - return NO; - - nsCOMPtr parentElt; - parentElt = do_QueryInterface([parentItem contentNode]); - - nsCOMPtr beforeElt; - beforeElt = do_QueryInterface([beforeItem contentNode]); - - nsAutoString url; [[data objectForKey:@"url"] assignTo_nsAString:url]; - nsAutoString title; [[data objectForKey:@"title"] assignTo_nsAString:title]; - BookmarksService::AddBookmarkToFolder(url, title, parentElt, beforeElt); - return YES; -} - - -bool -BookmarksService::PerformBookmarkDrop(BookmarkItem* parent, int index, NSArray* draggedIDs) -{ - NSEnumerator *enumerator = [draggedIDs reverseObjectEnumerator]; - NSNumber *contentID; - - // for each item being dragged - while ( (contentID = [enumerator nextObject]) ) { - - // get dragged node - nsCOMPtr draggedNode = [GetWrapperFor([contentID unsignedIntValue]) contentNode]; - - // get the dragged nodes parent - nsCOMPtr draggedParent; - if (draggedNode) - draggedNode->GetParent(*getter_AddRefs(draggedParent)); - - // get the proposed parent - nsCOMPtr proposedParent = [parent contentNode]; - - PRInt32 existingIndex = 0; - if (draggedParent) - draggedParent->IndexOf(draggedNode, existingIndex); - - // if the deleted nodes parent and the proposed parents are equal - // and if the deleted point is earlier in the list than the inserted point - if (proposedParent == draggedParent && existingIndex < index) { - index--; // if so, move the inserted point up one to compensate - } - - // remove it from the tree - if (draggedNode != proposedParent) // paranoia. This should never happen - { - if (draggedParent) - draggedParent->RemoveChildAt(existingIndex, PR_TRUE); - BookmarkRemoved(draggedParent, draggedNode, false); - - // insert into new position - if (proposedParent) - proposedParent->InsertChildAt(draggedNode, index, PR_TRUE, PR_TRUE); - BookmarkAdded(proposedParent, draggedNode, false); - } - } - - FlushBookmarks(); - - return true; -} - -bool -BookmarksService::PerformURLDrop(BookmarkItem* parentItem, BookmarkItem* beforeItem, NSString* inTitle, NSString* inUrl) -{ - if ( !inUrl || [inUrl length] == 0 ) - return NO; - - nsCOMPtr parentElt; - parentElt = do_QueryInterface([parentItem contentNode]); - - nsCOMPtr beforeElt; - beforeElt = do_QueryInterface([beforeItem contentNode]); - - nsAutoString url; [inUrl assignTo_nsAString:url]; - nsAutoString title; [inTitle assignTo_nsAString:title]; - if (title.Length() == 0) - [inUrl assignTo_nsAString:title]; - - BookmarksService::AddBookmarkToFolder(url, title, parentElt, beforeElt); - return YES; -} - -#pragma mark - - -@interface BookmarksManager(Private) - -- (void)registerNotificationListener; -- (void)imageLoadedNotification:(NSNotification*)notification; - -@end - - -@implementation BookmarksManager - -+ (BookmarksManager*)sharedBookmarksManager; -{ - static BookmarksManager* sBookmarksManager = nil; - - if (!sBookmarksManager) - sBookmarksManager = [[BookmarksManager alloc] init]; - - return sBookmarksManager; -} - -- (id)init -{ - if ((self = [super init])) - { - [self registerNotificationListener]; - } - return self; -} - -- (void)dealloc -{ - [[NSNotificationCenter defaultCenter] removeObserver:self]; - [super dealloc]; -} - -- (void)loadProxyImageFor:(id)requestor withURI:(NSString*)inURIString -{ - [[SiteIconProvider sharedFavoriteIconProvider] loadFavoriteIcon:self - forURI:inURIString withUserData:requestor allowNetwork:NO]; -} - - -- (void)registerNotificationListener -{ - [[NSNotificationCenter defaultCenter] addObserver: self - selector: @selector(imageLoadedNotification:) - name: SiteIconLoadNotificationName - object: self]; - -} - -// callback for [[SiteIconProvider sharedFavoriteIconProvider] loadFavoriteIcon] -- (void)imageLoadedNotification:(NSNotification*)notification -{ - //NSLog(@"BookmarksManager imageLoadedNotification"); - NSDictionary* userInfo = [notification userInfo]; - if (userInfo) - { - id requestor = [userInfo objectForKey:SiteIconLoadUserDataKey]; // requestor is a BookmarkItem - NSImage* iconImage = [userInfo objectForKey:SiteIconLoadImageKey]; - - if (iconImage && [requestor isMemberOfClass:[BookmarkItem class]]) - { - [requestor setSiteIcon:iconImage]; - BookmarksService::BookmarkChanged([requestor contentNode], FALSE); - } - - } -} - - -@end - diff --git a/mozilla/camino/BrowserTabView.h b/mozilla/camino/BrowserTabView.h deleted file mode 100644 index 044e73999a5..00000000000 --- a/mozilla/camino/BrowserTabView.h +++ /dev/null @@ -1,45 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- -* -* 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 the Mozilla browser. -* -* The Initial Developer of the Original Code is Matt Judy. Portions -* of code @2002 nibfile.com. -*/ - -#import - -#import "BrowserTabViewItem.h" - -@interface BrowserTabView : NSTabView -{ - BOOL autoHides; - BOOL mIsDropTarget; - BOOL mLastClickIsPotentialDrag; - int maxNumberOfTabs; // 0 means 'no max' -} - -+ (BrowserTabViewItem*)makeNewTabItem; - -// Behavior: Autohiding overrides the default tab visibility state. -// To switch back to usual tabView behavior, setAutoHides:NO. -// Initial value is read from defaults. -- (BOOL)autoHides; -- (void)setAutoHides:(BOOL)newSetting; - -- (int)maxNumberOfTabs; -- (void)setMaxNumberOfTabs:(int)maxTabs; -- (BOOL)canMakeNewTabs; - -- (void)addTabForURL:(NSString*)aURL referrer:(NSString*)aReferrer; - -@end diff --git a/mozilla/camino/BrowserTabView.mm b/mozilla/camino/BrowserTabView.mm deleted file mode 100644 index a0993900829..00000000000 --- a/mozilla/camino/BrowserTabView.mm +++ /dev/null @@ -1,406 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** -* Version: NPL 1.1/GPL 2.0/LGPL 2.1 -* -* The contents of this file are subject to the Netscape 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/NPL/ -* -* 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 mozilla.org 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): -* Matt Judy (Original Author) -* David Haas -* -* 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 NPL, 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 NPL, the GPL or the LGPL. -* -* ***** END LICENSE BLOCK ***** */ - -#import "NSString+Utils.h" - -#import "BrowserTabView.h" -#import "BookmarksService.h" -#import "BookmarksDataSource.h" - -#include "nsCOMPtr.h" -#include "nsIDOMElement.h" -#include "nsIContent.h" -#include "nsIAtom.h" -#include "nsString.h" -#include "nsCRT.h" - -////////////////////////// -// NEEDS IMPLEMENTED : Implement drag tracking for moving tabs around. -// Implementation hints : Track drags ;) -// : Change tab controlTint to indicate drag location? -// : Move tab titles around when dragging. -////////////////////////// - -@interface BrowserTabView (Private) - -- (void)showOrHideTabsAsAppropriate; -- (BOOL)handleDropOnTab:(NSTabViewItem*)overTabViewItem overContent:(BOOL)overContentArea withURL:(NSString*)url; -- (BrowserTabViewItem*)getTabViewItemFromWindowPoint:(NSPoint)point; -- (void)showDragDestinationIndicator; -- (void)hideDragDestinationIndicator; - -@end - - -#define kTabDropTargetHeight 18.0 - -@implementation BrowserTabView - -/******************************************/ -/*** Initialization ***/ -/******************************************/ - -- (id)initWithFrame:(NSRect)frameRect -{ - if ( (self = [super initWithFrame:frameRect]) ) { - autoHides = YES; - maxNumberOfTabs = 0; // no max - } - return self; -} - -- (void)awakeFromNib -{ - [self showOrHideTabsAsAppropriate]; - [self registerForDraggedTypes:[NSArray arrayWithObjects: - @"MozURLType", @"MozBookmarkType", NSStringPboardType, NSFilenamesPboardType, nil]]; -} - -/******************************************/ -/*** Overridden Methods ***/ -/******************************************/ - -- (BOOL)isOpaque -{ - if ( ([self tabViewType] == NSNoTabsBezelBorder) && (NSAppKitVersionNumber < 633) ) - return NO; - - return [super isOpaque]; -} - -- (void)drawRect:(NSRect)aRect -{ - if (mIsDropTarget) - { - NSRect hilightRect = aRect; - hilightRect.size.height = kTabDropTargetHeight; // no need to move origin.y; our coords are flipped - NSBezierPath* dropTargetOutline = [NSBezierPath bezierPathWithRect:hilightRect]; - - [[[NSColor colorForControlTint:NSDefaultControlTint] colorWithAlphaComponent:0.5] set]; - [dropTargetOutline fill]; - } - - [super drawRect:aRect]; -} - -- (void)addTabViewItem:(NSTabViewItem *)tabViewItem -{ - [super addTabViewItem:tabViewItem]; - [self showOrHideTabsAsAppropriate]; -} - -- (void)removeTabViewItem:(NSTabViewItem *)tabViewItem -{ - [super removeTabViewItem:tabViewItem]; - [self showOrHideTabsAsAppropriate]; -} - -- (void)insertTabViewItem:(NSTabViewItem *)tabViewItem atIndex:(int)index -{ - [super insertTabViewItem:tabViewItem atIndex:index]; - [self showOrHideTabsAsAppropriate]; -} - -/******************************************/ -/*** Accessor Methods ***/ -/******************************************/ - -- (BOOL)autoHides -{ - return autoHides; -} - -- (void)setAutoHides:(BOOL)newSetting -{ - autoHides = newSetting; -} - -- (int)maxNumberOfTabs -{ - return maxNumberOfTabs; -} - -- (void)setMaxNumberOfTabs:(int)maxTabs -{ - maxNumberOfTabs = maxTabs; -} - -- (BOOL)canMakeNewTabs -{ - return maxNumberOfTabs == 0 || [self numberOfTabViewItems] < maxNumberOfTabs; -} - -/******************************************/ -/*** Instance Methods ***/ -/******************************************/ - -// 03-03-2002 mlj: Modifies tab view size and type appropriately... Fragile. -// Only to be used with the 2 types of tab view which we use in Chimera. -- (void)showOrHideTabsAsAppropriate -{ - //if ( autoHides == YES ) - { - BOOL tabVisibilityChanged = NO; - BOOL tabsVisible = NO; - - if ( [[self tabViewItems] count] < 2) - { - if ( [self tabViewType] != NSNoTabsBezelBorder ) - { - [self setFrameSize:NSMakeSize( NSWidth([self frame]), NSHeight([self frame]) + 10 )]; - [self setTabViewType:NSNoTabsBezelBorder]; - tabVisibilityChanged = YES; - } - tabsVisible = NO; - } - else - { - if ( [self tabViewType] != NSTopTabsBezelBorder ) - { - [self setFrameSize:NSMakeSize( NSWidth([self frame]), NSHeight([self frame]) - 10 )]; - [self setTabViewType:NSTopTabsBezelBorder]; - tabVisibilityChanged = YES; - } - tabsVisible = YES; - } - - // tell the tabs that visibility changed - NSArray* tabViewItems = [self tabViewItems]; - for (unsigned int i = 0; i < [tabViewItems count]; i ++) - { - NSTabViewItem* tabItem = [tabViewItems objectAtIndex:i]; - if ([tabItem isMemberOfClass:[BrowserTabViewItem class]]) - [(BrowserTabViewItem*)tabItem updateTabVisibility:tabsVisible]; - } - - if (tabVisibilityChanged) - [self setNeedsDisplay:YES]; - } -} - - -- (BOOL)handleDropOnTab:(NSTabViewItem*)overTabViewItem overContent:(BOOL)overContentArea withURL:(NSString*)url -{ - if (overTabViewItem) - { - [[overTabViewItem view] loadURI: url referrer:nil flags: NSLoadFlagsNone activate:NO]; - return YES; - } - else if (overContentArea) - { - [[[self selectedTabViewItem] view] loadURI: url referrer:nil flags: NSLoadFlagsNone activate:NO]; - return YES; - } - else if ([self canMakeNewTabs]) - { - [self addTabForURL:url referrer:nil]; - return YES; - } - - return NO; -} - -- (BrowserTabViewItem*)getTabViewItemFromWindowPoint:(NSPoint)point -{ - NSPoint localPoint = [self convertPoint: point fromView: nil]; - NSTabViewItem* overTabViewItem = [self tabViewItemAtPoint: localPoint]; - return (BrowserTabViewItem*)overTabViewItem; -} - -- (void)showDragDestinationIndicator -{ - if (!mIsDropTarget) - { - NSRect invalidRect = [self bounds]; - invalidRect.size.height = kTabDropTargetHeight; - [self setNeedsDisplayInRect:invalidRect]; - mIsDropTarget = YES; - } -} - -- (void)hideDragDestinationIndicator -{ - if (mIsDropTarget) - { - NSRect invalidRect = [self bounds]; - invalidRect.size.height = kTabDropTargetHeight; - [self setNeedsDisplayInRect:invalidRect]; - mIsDropTarget = NO; - } -} - -#pragma mark - - -// NSDraggingDestination /////////// - -- (unsigned int)draggingEntered:(id )sender -{ - NSPoint localPoint = [self convertPoint: [sender draggingLocation] fromView: nil]; - NSTabViewItem* overTabViewItem = [self tabViewItemAtPoint: localPoint]; - BOOL overContentArea = NSPointInRect(localPoint, [self contentRect]); - - if (overTabViewItem) - return NSDragOperationNone; // the tab will handle it - - if (!overContentArea && ![self canMakeNewTabs]) - return NSDragOperationNone; - - [self showDragDestinationIndicator]; // XXX optimize - return NSDragOperationGeneric; -} - -- (unsigned int)draggingUpdated:(id )sender -{ - NSPoint localPoint = [self convertPoint: [sender draggingLocation] fromView: nil]; - NSTabViewItem* overTabViewItem = [self tabViewItemAtPoint: localPoint]; - BOOL overContentArea = NSPointInRect(localPoint, [self contentRect]); - - if (overTabViewItem) - return NSDragOperationNone; // the tab will handle it - - if (!overContentArea && ![self canMakeNewTabs]) - { - [self hideDragDestinationIndicator]; - return NSDragOperationNone; - } - - [self showDragDestinationIndicator]; - return NSDragOperationGeneric; -} - -- (void)draggingExited:(id )sender -{ - [self hideDragDestinationIndicator]; -} - -- (BOOL)prepareForDragOperation:(id )sender -{ - return YES; -} - -- (BOOL)performDragOperation:(id )sender -{ - // determine if we are over a tab or the content area - NSPoint localPoint = [self convertPoint: [sender draggingLocation] fromView: nil]; - NSTabViewItem* overTabViewItem = [self tabViewItemAtPoint: localPoint]; - BOOL overContentArea = NSPointInRect(localPoint, [self contentRect]); - NSArray* pasteBoardTypes = [[sender draggingPasteboard] types]; - - [self hideDragDestinationIndicator]; - - if ([pasteBoardTypes containsObject: @"MozBookmarkType"]) - { - NSArray* contentIds = [[sender draggingPasteboard] propertyListForType: @"MozBookmarkType"]; - if (contentIds) { - // drag type is chimera bookmarks - for (unsigned int i = 0; i < [contentIds count]; ++i) { - BookmarkItem* item = [BookmarksService::gDictionary objectForKey: [contentIds objectAtIndex:i]]; - nsCOMPtr bookmarkElt = do_QueryInterface([item contentNode]); - - nsCOMPtr tagName; - [item contentNode]->GetTag(*getter_AddRefs(tagName)); - - nsAutoString href; - bookmarkElt->GetAttribute(NS_LITERAL_STRING("href"), href); - NSString* url = [NSString stringWith_nsAString: href]; - - nsAutoString group; - bookmarkElt->GetAttribute(NS_LITERAL_STRING("group"), group); - if (!group.IsEmpty()) { - BookmarksService::OpenBookmarkGroup(self, bookmarkElt); - } else { - return [self handleDropOnTab:overTabViewItem overContent:overContentArea withURL:url]; - } - } // for each item - } - } - else if ([pasteBoardTypes containsObject: @"MozURLType"]) - { - // drag type is MozURLType - NSDictionary* data = [[sender draggingPasteboard] propertyListForType: @"MozURLType"]; - if (data) { - NSString* urlString = [data objectForKey:@"url"]; - return [self handleDropOnTab:overTabViewItem overContent:overContentArea withURL:urlString]; - } - } - else if ([pasteBoardTypes containsObject: NSStringPboardType]) - { - NSString* urlString = [[sender draggingPasteboard] stringForType: NSStringPboardType]; - return [self handleDropOnTab:overTabViewItem overContent:overContentArea withURL:urlString]; - } - else if ([pasteBoardTypes containsObject: NSURLPboardType]) - { - NSURL* urlData = [NSURL URLFromPasteboard:[sender draggingPasteboard]]; - return [self handleDropOnTab:overTabViewItem overContent:overContentArea withURL:[urlData absoluteString]]; - } - else if ([pasteBoardTypes containsObject: NSFilenamesPboardType]) - { - NSString* urlString = [[sender draggingPasteboard] stringForType: NSFilenamesPboardType]; - return [self handleDropOnTab:overTabViewItem overContent:overContentArea withURL:urlString]; - } - - return NO; -} - -#pragma mark - - --(void)addTabForURL:(NSString*)aURL referrer:(NSString*)aReferrer -{ - // We need to make a new tab. - BrowserTabViewItem *tabViewItem= [BrowserTabView makeNewTabItem]; - CHBrowserWrapper *newView = [[[CHBrowserWrapper alloc] initWithTab: tabViewItem andWindow: [self window]] autorelease]; - [tabViewItem setLabel: NSLocalizedString(@"UntitledPageTitle", @"")]; - [tabViewItem setView: newView]; - [self addTabViewItem: tabViewItem]; - - [[tabViewItem view] loadURI: aURL referrer:aReferrer flags: NSLoadFlagsNone activate:NO]; -} - -#pragma mark - - -+ (BrowserTabViewItem*)makeNewTabItem -{ - return [[[BrowserTabViewItem alloc] init] autorelease]; -} - -@end - - - - diff --git a/mozilla/camino/BrowserTabViewItem.h b/mozilla/camino/BrowserTabViewItem.h deleted file mode 100644 index ae4787b7ff8..00000000000 --- a/mozilla/camino/BrowserTabViewItem.h +++ /dev/null @@ -1,57 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape 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/NPL/ - * - * 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 mozilla.org 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): - * Simon Fraser - * - * 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 NPL, 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 NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#import - -#import "CHIconTabViewItem.h" - -// a subclass of CHIconTabViewItem that handles dragging of site icons -@class BrowserTabItemContainerView; - -@interface BrowserTabViewItem : CHIconTabViewItem -{ - NSRect mLastDrawRect; // cached draw rect, used for dragging location - BrowserTabItemContainerView* mTabContentsView; - BOOL mDraggable; -} - -- (void)updateTabVisibility:(BOOL)nowVisible; -- (NSView*)tabItemContentsView; -- (void)setTabIcon:(NSImage *)newIcon isDraggable:(BOOL)draggable; - -@end diff --git a/mozilla/camino/BrowserTabViewItem.mm b/mozilla/camino/BrowserTabViewItem.mm deleted file mode 100644 index 9134db8ba5f..00000000000 --- a/mozilla/camino/BrowserTabViewItem.mm +++ /dev/null @@ -1,557 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape 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/NPL/ - * - * 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 mozilla.org 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): - * Simon Fraser - * - * 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 NPL, 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 NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#import "NSString+Utils.h" - -#import "BrowserTabViewItem.h" - -#import "CHBrowserView.h" -#import "MainController.h" -#import "BrowserWindowController.h" - - -@interface BrowserTabViewItem(Private) -- (void)buildTabContents; -- (void)relocateTabContents:(NSRect)inRect; -- (BOOL)draggable; -@end - -#pragma mark - - -@interface NSBezierPath (ChimeraBezierPathUtils) - -+ (NSBezierPath*)bezierPathWithRoundCorneredRect:(NSRect)rect cornerRadius:(float)cornerRadius; - -@end - -@implementation NSBezierPath (ChimeraBezierPathUtils) - -+ (NSBezierPath*)bezierPathWithRoundCorneredRect:(NSRect)rect cornerRadius:(float)cornerRadius -{ - float maxRadius = cornerRadius; - if (NSWidth(rect) / 2.0 < maxRadius) - maxRadius = NSWidth(rect) / 2.0; - - if (NSHeight(rect) / 2.0 < maxRadius) - maxRadius = NSHeight(rect) / 2.0; - - NSBezierPath* newPath = [NSBezierPath bezierPath]; - [newPath moveToPoint:NSMakePoint(NSMinX(rect) + maxRadius, NSMinY(rect))]; - - [newPath appendBezierPathWithArcWithCenter:NSMakePoint(NSMaxX(rect) - maxRadius, NSMinY(rect) + maxRadius) - radius:maxRadius startAngle:270.0 endAngle:0.0]; - - [newPath appendBezierPathWithArcWithCenter:NSMakePoint(NSMaxX(rect) - maxRadius, NSMaxY(rect) - maxRadius) - radius:maxRadius startAngle:0.0 endAngle:90.0]; - - [newPath appendBezierPathWithArcWithCenter:NSMakePoint(NSMinX(rect) + maxRadius, NSMaxY(rect) - maxRadius) - radius:maxRadius startAngle:90.0 endAngle:180.0]; - - [newPath appendBezierPathWithArcWithCenter:NSMakePoint(NSMinX(rect) + maxRadius, NSMinY(rect) + maxRadius) - radius:maxRadius startAngle:180.0 endAngle:270.0]; - - [newPath closePath]; - - return newPath; -} - -@end - -#pragma mark - - -// XXX move this to a new file -@interface NSTruncatingTextAndImageCell : NSCell -{ - NSImage *mImage; - NSMutableString *mTruncLabelString; - int mLabelStringWidth; // -1 if not known - float mImagePadding; - float mImageSpace; - float mImageAlpha; -} - -- (id)initTextCell:(NSString*)aString; -- (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView*)controlView; - -- (void)setImagePadding:(float)padding; -- (void)setImageSpace:(float)space; -- (void)setImageAlpha:(float)alpha; - -- (void)setImage:(NSImage *)anImage; -- (NSImage *)image; - -@end - -@implementation NSTruncatingTextAndImageCell - -- (id)initTextCell:(NSString*)aString -{ - if ((self = [super initTextCell:aString])) - { - mLabelStringWidth = -1; - mImagePadding = 0; - mImageSpace = 2; - } - return self; -} - -- (void)dealloc -{ - [mImage release]; - [mTruncLabelString release]; - [super dealloc]; -} - -- copyWithZone:(NSZone *)zone -{ - NSTruncatingTextAndImageCell *cell = (NSTruncatingTextAndImageCell *)[super copyWithZone:zone]; - cell->mImage = [mImage retain]; - cell->mTruncLabelString = nil; - cell->mLabelStringWidth = -1; - return cell; -} - -- (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView*)controlView -{ - NSRect textRect = cellFrame; - NSRect imageRect; - - // we always reserve space for the image, even if there isn't one - // assume the image rect is always square - float imageWidth = NSHeight(cellFrame) - 2 * mImagePadding; - NSDivideRect(cellFrame, &imageRect, &textRect, imageWidth, NSMinXEdge); - - if (mImage) - { - NSRect imageSrcRect = NSZeroRect; - imageSrcRect.size = [mImage size]; - [mImage drawInRect:NSInsetRect(imageRect, mImagePadding, mImagePadding) - fromRect:imageSrcRect operation:NSCompositeSourceOver fraction:mImageAlpha]; - } - - // remove image space - NSDivideRect(textRect, &imageRect, &textRect, mImageSpace, NSMinXEdge); - - int cellWidth = (int)NSWidth(textRect); - NSDictionary *cellAttributes = [[self attributedStringValue] attributesAtIndex:0 effectiveRange:nil]; - - if (mLabelStringWidth != cellWidth || !mTruncLabelString) - { - [mTruncLabelString release]; - mTruncLabelString = [[NSMutableString alloc] initWithString:[self stringValue]]; - [mTruncLabelString truncateToWidth:cellWidth at:kTruncateAtEnd withAttributes:cellAttributes]; - mLabelStringWidth = cellWidth; - } - - [mTruncLabelString drawInRect:textRect withAttributes:cellAttributes]; -} - -- (void)setStringValue:(NSString *)aString -{ - if (![aString isEqualToString:[self stringValue]]) - { - [mTruncLabelString release]; - mTruncLabelString = nil; - } - [super setStringValue:aString]; -} - -- (void)setAttributedStringValue:(NSAttributedString *)attribStr -{ - if (![attribStr isEqualToAttributedString:[self attributedStringValue]]) - { - [mTruncLabelString release]; - mTruncLabelString = nil; - } - [super setAttributedStringValue:attribStr]; -} - -- (void)setImage:(NSImage *)anImage -{ - if (anImage != mImage) - { - [mImage release]; - mImage = [anImage retain]; - } -} - -- (NSImage *)image -{ - return mImage; -} - -- (void)setImagePadding:(float)padding -{ - mImagePadding = padding; -} - -- (void)setImageSpace:(float)space -{ - mImageSpace = space; -} - -- (void)setImageAlpha:(float)alpha -{ - mImageAlpha = alpha; -} - -@end - -#pragma mark - - -// a container view for the items in the tab view item. We use a subclass of -// NSView to handle drag and drop -@interface BrowserTabItemContainerView : NSView -{ - BrowserTabViewItem* mTabViewItem; - NSTruncatingTextAndImageCell* mLabelCell; - - BOOL mIsDropTarget; - BOOL mSelectTabOnMouseUp; -} - -- (NSTruncatingTextAndImageCell*)labelCell; - -- (void)showDragDestinationIndicator; -- (void)hideDragDestinationIndicator; - -@end - -@implementation BrowserTabItemContainerView - -- (id)initWithFrame:(NSRect)frameRect andTabItem:(NSTabViewItem*)tabViewItem -{ - if ( (self = [super initWithFrame:frameRect]) ) - { - mTabViewItem = tabViewItem; - - mLabelCell = [[NSTruncatingTextAndImageCell alloc] init]; - [mLabelCell setControlSize:NSSmallControlSize]; // doesn't work? - [mLabelCell setImagePadding:0.0]; - [mLabelCell setImageSpace:2.0]; - - [self registerForDraggedTypes:[NSArray arrayWithObjects: - @"MozURLType", @"MozBookmarkType", NSStringPboardType, NSFilenamesPboardType, nil]]; - } - return self; -} - -- (void)dealloc -{ - [mLabelCell release]; - [super dealloc]; -} - -- (NSTruncatingTextAndImageCell*)labelCell -{ - return mLabelCell; -} - -- (void)drawRect:(NSRect)aRect -{ - [mLabelCell drawWithFrame:[self bounds] inView:self]; - - if (mIsDropTarget) - { - NSRect hilightRect = NSOffsetRect(NSInsetRect([self bounds], 1.0, 0), -1.0, 0); - NSBezierPath* dropTargetOutline = [NSBezierPath bezierPathWithRoundCorneredRect:hilightRect cornerRadius:4.0]; - [[NSColor colorWithCalibratedWhite:0.0 alpha:0.15] set]; - [dropTargetOutline fill]; - } -} - -- (void)showDragDestinationIndicator -{ - if (!mIsDropTarget) - { - mIsDropTarget = YES; - [self setNeedsDisplay:YES]; - } -} - -- (void)hideDragDestinationIndicator -{ - if (mIsDropTarget) - { - mIsDropTarget = NO; - [self setNeedsDisplay:YES]; - } -} - -- (BOOL)shouldAcceptDragFrom:(id)sender -{ - if ((sender == self) || (sender == mTabViewItem)) - return NO; - - NSWindowController *windowController = [[[mTabViewItem view] window] windowController]; - if ([windowController isMemberOfClass:[BrowserWindowController class]]) - { - if (sender == [windowController proxyIconView]) - return NO; - } - - return YES; -} - - -#pragma mark - - -// NSDraggingDestination destination methods -- (unsigned int)draggingEntered:(id )sender -{ - if (![self shouldAcceptDragFrom:[sender draggingSource]]) - return NSDragOperationNone; - - [self showDragDestinationIndicator]; - return NSDragOperationGeneric; -} - -- (unsigned int)draggingUpdated:(id )sender -{ - if (![self shouldAcceptDragFrom:[sender draggingSource]]) { - [self hideDragDestinationIndicator]; - return NSDragOperationNone; - } - - [self showDragDestinationIndicator]; - return NSDragOperationGeneric; -} - -- (void)draggingExited:(id )sender -{ - [self hideDragDestinationIndicator]; -} - -- (BOOL)prepareForDragOperation:(id )sender -{ - return YES; -} - -- (BOOL)performDragOperation:(id )sender -{ - [self hideDragDestinationIndicator]; - - if (![self shouldAcceptDragFrom:[sender draggingSource]]) - return NO; - - // let the tab view handle it - return [[mTabViewItem tabView] performDragOperation:sender]; -} - -#pragma mark - - -// NSDraggingSource methods - -- (unsigned int)draggingSourceOperationMaskForLocal:(BOOL)flag -{ - return NSDragOperationGeneric; -} - -// NSResponder methods -- (void)mouseDown:(NSEvent *)theEvent -{ - NSRect iconRect = NSMakeRect(0, 0, 16, 16); - NSPoint localPoint = [self convertPoint: [theEvent locationInWindow] fromView: nil]; - - // this is a bit evil. Because the tab view's mouseDown captures the mouse, we'll - // never get to mouseDragged if we allow the next responder (the tab view) to - // handle the mouseDown. This prevents dragging from background tabs. So we break - // things slightly by intercepting the mouseDown on the icon, so that our mouseDragged - // gets called. If the users didn't drag, we select the tab in the mouse up. - if (NSPointInRect(localPoint, iconRect) && [mTabViewItem draggable]) - { - mSelectTabOnMouseUp = YES; - return; // we want dragging - } - - mSelectTabOnMouseUp = NO; - [[self nextResponder] mouseDown:theEvent]; -} - -- (void)mouseUp:(NSEvent *)theEvent -{ - if (mSelectTabOnMouseUp) - { - [[mTabViewItem tabView] selectTabViewItem:mTabViewItem]; - mSelectTabOnMouseUp = NO; - } - - [[self nextResponder] mouseUp:theEvent]; -} - -- (void)mouseDragged:(NSEvent*)theEvent -{ - NSRect iconRect = NSMakeRect(0, 0, 16, 16); - NSPoint localPoint = [self convertPoint: [theEvent locationInWindow] fromView: nil]; - - if (!NSPointInRect(localPoint, iconRect) || ![mTabViewItem draggable]) - { - [[self nextResponder] mouseDragged:theEvent]; - return; - } - - mSelectTabOnMouseUp = NO; - - CHBrowserView* browserView = (CHBrowserView*)[mTabViewItem view]; - - NSString *url = [browserView getCurrentURLSpec]; - NSString *title = [mLabelCell stringValue]; - - NSString *cleanedTitle = [title stringByReplacingCharactersInSet:[NSCharacterSet controlCharacterSet] withString:@" "]; - - NSArray *dataVals = [NSArray arrayWithObjects: url, cleanedTitle, nil]; - NSArray *dataKeys = [NSArray arrayWithObjects: @"url", @"title", nil]; - NSDictionary *data = [NSDictionary dictionaryWithObjects:dataVals forKeys:dataKeys]; - - NSPasteboard *pboard = [NSPasteboard pasteboardWithName:NSDragPboard]; - [pboard declareTypes:[NSArray arrayWithObjects:@"MozURLType", NSURLPboardType, NSStringPboardType, nil] owner:self]; - - // MozURLType - [pboard setPropertyList:data forType: @"MozURLType"]; - // NSURLPboardType type - [[NSURL URLWithString:url] writeToPasteboard: pboard]; - // NSStringPboardType - [pboard setString:url forType: NSStringPboardType]; - - NSPoint dragOrigin = [self frame].origin; - dragOrigin.y += [self frame].size.height; - - [self dragImage: [MainController createImageForDragging:[mLabelCell image] title:title] - at:NSMakePoint(0, 0) offset:NSMakeSize(0, 0) - event:theEvent pasteboard:pboard source:self slideBack:YES]; -} - -@end - -#pragma mark - - -@implementation BrowserTabViewItem - --(id)initWithIdentifier:(id)identifier withTabIcon:(NSImage *)tabIcon -{ - if ( (self = [super initWithIdentifier:identifier withTabIcon:tabIcon]) ) - { - mTabContentsView = [[BrowserTabItemContainerView alloc] - initWithFrame:NSMakeRect(0, 0, 100, 16) andTabItem:self]; - mDraggable = NO; - } - return self; -} - --(id)initWithIdentifier:(id)identifier -{ - return [self initWithIdentifier:identifier withTabIcon:nil]; -} - --(void)dealloc -{ - // We can either be closing a single tab here, in which case we need to remove our view - // from the superview, or the tab view may be closing, in which case it has already - // removed all its subviews. - [mTabContentsView removeFromSuperview]; // may be noop - [mTabContentsView release]; // balance our init - [super dealloc]; -} - -- (NSView*)tabItemContentsView -{ - return mTabContentsView; -} - -- (void)updateTabVisibility:(BOOL)nowVisible -{ - if (nowVisible) - { - if (![mTabContentsView superview]) - [[self tabView] addSubview:mTabContentsView]; - } - else - { - if ([mTabContentsView superview]) - [mTabContentsView removeFromSuperview]; - } -} - -- (void)relocateTabContents:(NSRect)inRect -{ - [mTabContentsView setFrame:inRect]; -} - -- (BOOL)draggable -{ - return mDraggable; -} - --(void)drawLabel:(BOOL)shouldTruncateLabel inRect:(NSRect)tabRect -{ - [self relocateTabContents:tabRect]; - mLastDrawRect = tabRect; -} - -- (NSSize)sizeOfLabel:(BOOL)shouldTruncateLabel -{ - return [super sizeOfLabel:shouldTruncateLabel]; -} - -- (void)setLabel:(NSString *)label -{ - NSAttributedString* labelString = [[NSAttributedString alloc] initWithString:label attributes:mLabelAttributes]; - [[mTabContentsView labelCell] setAttributedStringValue:labelString]; - - [super setLabel:label]; -} - -- (NSString*)label -{ - return [[mTabContentsView labelCell] stringValue]; -} - --(void)setTabIcon:(NSImage *)newIcon -{ - [super setTabIcon:newIcon]; - [[mTabContentsView labelCell] setImage:mTabIcon]; -} - -- (void)setTabIcon:(NSImage *)newIcon isDraggable:(BOOL)draggable -{ - [self setTabIcon:newIcon]; - mDraggable = draggable; - [[mTabContentsView labelCell] setImageAlpha:(draggable ? 1.0 : 0.6)]; -} - -@end diff --git a/mozilla/camino/BrowserWindow.h b/mozilla/camino/BrowserWindow.h deleted file mode 100644 index edf19f7664b..00000000000 --- a/mozilla/camino/BrowserWindow.h +++ /dev/null @@ -1,46 +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): - * Simon Fraser - * - * 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 - -@interface BrowserWindow : NSWindow -{ - IBOutlet id mAutoCompleteTextField; -} - --(BOOL) makeFirstResponder:(NSResponder*) responder; -@end diff --git a/mozilla/camino/BrowserWindow.mm b/mozilla/camino/BrowserWindow.mm deleted file mode 100644 index 35f409d4ee6..00000000000 --- a/mozilla/camino/BrowserWindow.mm +++ /dev/null @@ -1,66 +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): - * Simon Fraser - * - * 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 "BrowserWindow.h" -#import "BrowserWindowController.h" -#import "CHAutoCompleteTextField.h" - -static const int kEscapeKeyCode = 53; - -@implementation BrowserWindow - -- (BOOL)makeFirstResponder:(NSResponder*)responder -{ - NSResponder* oldResponder = [self firstResponder]; - BOOL madeFirstResponder = [super makeFirstResponder:responder]; - if (madeFirstResponder && oldResponder != [self firstResponder]) - [(BrowserWindowController*)[self delegate] focusChangedFrom:oldResponder to:[self firstResponder]]; - return madeFirstResponder; -} - -- (void)sendEvent:(NSEvent *)theEvent -{ - // We need this hack because NSWindow::sendEvent will eat the escape key - // and won't pass it down to the key handler of responders in the window. - // We have to override sendEvent for all of our escape key needs. - if ([theEvent keyCode] == kEscapeKeyCode && [theEvent type] == NSKeyDown && [self firstResponder] == [mAutoCompleteTextField fieldEditor]) - [mAutoCompleteTextField revertText]; - else - [super sendEvent:theEvent]; -} - -@end diff --git a/mozilla/camino/BrowserWindow.nib/classes.nib b/mozilla/camino/BrowserWindow.nib/classes.nib deleted file mode 100644 index 8802bdedcfd..00000000000 --- a/mozilla/camino/BrowserWindow.nib/classes.nib +++ /dev/null @@ -1,162 +0,0 @@ -{ - IBClasses = ( - {CLASS = BookmarkItem; LANGUAGE = ObjC; SUPERCLASS = NSObject; }, - { - ACTIONS = { - addBookmark = id; - addFolder = id; - deleteBookmarks = id; - openBookmarkInNewTab = id; - openBookmarkInNewWindow = id; - showBookmarkInfo = id; - }; - CLASS = BookmarksDataSource; - LANGUAGE = ObjC; - OUTLETS = { - mBrowserWindowController = id; - mDeleteBookmarkButton = id; - mEditBookmarkButton = id; - mOutlineView = id; - }; - SUPERCLASS = NSObject; - }, - {CLASS = BookmarksToolbar; LANGUAGE = ObjC; SUPERCLASS = NSView; }, - {CLASS = BrowserTabView; LANGUAGE = ObjC; SUPERCLASS = NSTabView; }, - { - CLASS = BrowserWindow; - LANGUAGE = ObjC; - OUTLETS = {mAutoCompleteTextField = id; }; - SUPERCLASS = NSWindow; - }, - { - ACTIONS = { - back = id; - bookmarkLink = id; - bookmarkPage = id; - cancelAddBookmarkSheet = id; - cancelLocationSheet = id; - copyLinkLocation = id; - endAddBookmarkSheet = id; - endLocationSheet = id; - forward = id; - goToLocationFromToolbarURLField = id; - home = id; - manageBookmarks = id; - openLinkInNewTab = id; - openLinkInNewWindow = id; - performSearch = id; - printDocument = id; - reload = id; - saveImageAs = id; - saveLinkAs = id; - savePageAs = id; - stop = id; - toggleSidebar = id; - viewOnlyThisImage = id; - viewSource = id; - }; - CLASS = BrowserWindowController; - LANGUAGE = ObjC; - OUTLETS = { - mAddBookmarkCheckbox = NSButton; - mAddBookmarkFolderField = NSPopUpButton; - mAddBookmarkSheetWindow = NSWindow; - mAddBookmarkTitleField = NSTextField; - mBackItem = NSMenuItem; - mCachedBMDS = id; - mForwardItem = NSMenuItem; - mHistoryDataSource = CHHistoryDataSource; - mImageLinkMenu = NSMenu; - mImageMenu = NSMenu; - mInputMenu = NSMenu; - mLinkMenu = NSMenu; - mLocationSheetURLField = NSTextField; - mLocationSheetWindow = NSWindow; - mLocationToolbarView = NSView; - mLock = NSImageView; - mPageMenu = NSMenu; - mPersonalToolbar = CHBookmarksToolbar; - mProgress = NSProgressIndicator; - mProxyIcon = NSImageView; - mSidebarBookmarksDataSource = BookmarksDataSource; - mSidebarBrowserView = id; - mSidebarDrawer = NSDrawer; - mSidebarSourceTabView = NSTabView; - mSidebarTabView = NSTabView; - mStatus = NSTextField; - mStatusBar = NSView; - mTabBrowser = CHExtendedTabView; - mURLBar = NSTextField; - }; - SUPERCLASS = NSWindowController; - }, - {CLASS = CHAutoCompleteDataSource; LANGUAGE = ObjC; SUPERCLASS = NSObject; }, - { - ACTIONS = {onBlur = id; onResize = id; }; - CLASS = CHAutoCompleteTextField; - LANGUAGE = ObjC; - OUTLETS = {mProxyIcon = CHPageProxyIcon; }; - SUPERCLASS = NSTextField; - }, - { - CLASS = CHBookmarksOutlineView; - LANGUAGE = ObjC; - SUPERCLASS = CHExtendedOutlineView; - }, - {CLASS = CHBookmarksToolbar; LANGUAGE = ObjC; SUPERCLASS = NSView; }, - { - ACTIONS = {load = id; }; - CLASS = CHBrowserWrapper; - LANGUAGE = ObjC; - OUTLETS = { - mLockIcon = id; - mWindowController = id; - progress = id; - progressSuper = id; - status = id; - urlbar = id; - }; - SUPERCLASS = NSView; - }, - {CLASS = CHExtendedOutlineView; LANGUAGE = ObjC; SUPERCLASS = NSOutlineView; }, - { - CLASS = CHHistoryDataSource; - LANGUAGE = ObjC; - OUTLETS = {mBrowserWindowController = id; }; - SUPERCLASS = CHRDFOutlineViewDataSource; - }, - {CLASS = CHLocationBar; LANGUAGE = ObjC; SUPERCLASS = NSView; }, - {CLASS = CHPageProxyIcon; LANGUAGE = ObjC; SUPERCLASS = NSImageView; }, - { - CLASS = CHRDFOutlineViewDataSource; - LANGUAGE = ObjC; - OUTLETS = {mOutlineView = id; }; - SUPERCLASS = NSObject; - }, - {CLASS = ExtendedOutlineView; LANGUAGE = ObjC; SUPERCLASS = NSOutlineView; }, - {CLASS = FirstResponder; LANGUAGE = ObjC; SUPERCLASS = NSObject; }, - {CLASS = LocationBar; LANGUAGE = ObjC; SUPERCLASS = NSView; }, - {CLASS = MainController; LANGUAGE = ObjC; SUPERCLASS = NSObject; }, - { - ACTIONS = {load = id; }; - CLASS = MyBrowserView; - LANGUAGE = ObjC; - OUTLETS = { - mImageLinkMenu = id; - mImageMenu = id; - mInputMenu = id; - mLinkMenu = id; - mPageMenu = id; - mWindowController = id; - progress = id; - progressSuper = id; - status = id; - urlbar = id; - }; - SUPERCLASS = NSView; - }, - {CLASS = RDFOutlineViewItem; LANGUAGE = ObjC; SUPERCLASS = NSObject; }, - {CLASS = ThrobberHandler; LANGUAGE = ObjC; SUPERCLASS = NSObject; } - ); - IBVersion = 1; -} \ No newline at end of file diff --git a/mozilla/camino/BrowserWindow.nib/info.nib b/mozilla/camino/BrowserWindow.nib/info.nib deleted file mode 100644 index 667fcc69e64..00000000000 --- a/mozilla/camino/BrowserWindow.nib/info.nib +++ /dev/null @@ -1,49 +0,0 @@ - - - - - IBDocumentLocation - 176 79 632 495 0 0 1280 1002 - IBEditorPositions - - 124 - 345 803 170 144 0 0 1280 1002 - 160 - 524 326 195 666 0 0 1280 1002 - 28 - 524 439 195 457 0 0 1280 1002 - 297 - 233 646 176 162 0 0 1152 848 - 314 - 418 732 139 66 0 0 1152 848 - 336 - 630 666 200 132 0 0 1152 848 - 365 - 22 587 93 162 0 0 1152 848 - 463 - 22 619 200 180 0 0 1152 848 - 56 - 450 634 343 68 0 0 1280 1002 - - IBFramework Version - 248.0 - IBGroupedObjects - - 3 - - 8 - 9 - - - IBLastGroupID - 4 - IBLockedObjects - - IBOpenObjects - - 10 - - IBSystem Version - 5S60 - - diff --git a/mozilla/camino/BrowserWindow.nib/objects.nib b/mozilla/camino/BrowserWindow.nib/objects.nib deleted file mode 100644 index d775c7ae2db..00000000000 Binary files a/mozilla/camino/BrowserWindow.nib/objects.nib and /dev/null differ diff --git a/mozilla/camino/BrowserWindowController.h b/mozilla/camino/BrowserWindowController.h deleted file mode 100644 index 1a1c3dd4d29..00000000000 --- a/mozilla/camino/BrowserWindowController.h +++ /dev/null @@ -1,285 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape 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/NPL/ - * - * 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 mozilla.org 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 NPL, 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 NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#import -#import "CHBrowserWrapper.h" -#import "CHFind.h" -#import "CHBookmarksToolbar.h" - -class nsIDOMEvent; -class nsIDOMNode; - - -// -// ThrobberHandler -// -// A helper class that handles animating the throbber when it's alive. It starts -// automatically when you init it. To get it to stop, call |stopThrobber|. Calling -// |release| is not enough because the timer used to animate the images holds a strong -// ref back to the handler so it won't go away unless you break that cycle manually with -// |stopThrobber|. -// -// This class must be separate from BrowserWindowController else the -// same thing will happen there and the timer will cause it to stay alive and continue -// loading the webpage even though the window has gone away. -// -@interface ThrobberHandler : NSObject -{ - NSTimer* mTimer; - NSArray* mImages; - unsigned int mFrame; -} - -// public -- (id)initWithToolbarItem:(NSToolbarItem*)inButton images:(NSArray*)inImages; -- (void)stopThrobber; - -// internal -- (void)startThrobber; -- (void)pulseThrobber:(id)aSender; - -@end - - -@class BookmarksDataSource; -@class CHHistoryDataSource; -@class BrowserTabView; -@class CHPageProxyIcon; - -@interface BrowserWindowController : NSWindowController -{ - IBOutlet BrowserTabView* mTabBrowser; - IBOutlet NSDrawer* mSidebarDrawer; - IBOutlet NSTabView* mSidebarTabView; - IBOutlet NSTabView* mSidebarSourceTabView; - IBOutlet NSView* mLocationToolbarView; - IBOutlet NSTextField* mURLBar; - IBOutlet NSTextField* mStatus; - IBOutlet NSProgressIndicator* mProgress; - IBOutlet NSImageView* mLock; - IBOutlet NSWindow* mLocationSheetWindow; - IBOutlet NSTextField* mLocationSheetURLField; - IBOutlet NSView* mStatusBar; // contains the status text, progress bar, and lock - IBOutlet CHPageProxyIcon* mProxyIcon; - - IBOutlet id mSidebarBrowserView; // currently unused - IBOutlet BookmarksDataSource* mSidebarBookmarksDataSource; - IBOutlet CHHistoryDataSource* mHistoryDataSource; - - IBOutlet CHBookmarksToolbar* mPersonalToolbar; - - IBOutlet NSWindow* mAddBookmarkSheetWindow; - IBOutlet NSTextField* mAddBookmarkTitleField; - IBOutlet NSPopUpButton* mAddBookmarkFolderField; - IBOutlet NSButton* mAddBookmarkCheckbox; - - // Context menu outlets. - IBOutlet NSMenu* mPageMenu; - IBOutlet NSMenu* mImageMenu; - IBOutlet NSMenu* mInputMenu; - IBOutlet NSMenu* mLinkMenu; - IBOutlet NSMenu* mImageLinkMenu; - - // Context menu item outlets - IBOutlet NSMenuItem* mBackItem; - IBOutlet NSMenuItem* mForwardItem; - - NSToolbarItem* mSidebarToolbarItem; - - BOOL mInitialized; - NSString* mPendingURL; - NSString* mPendingReferrer; - BOOL mPendingActivate; - - CHBrowserWrapper* mBrowserView; - - BOOL mMoveReentrant; - NSModalSession mModalSession; - - BOOL mShouldAutosave; - BOOL mShouldLoadHomePage; - - BOOL mDrawerCachedFrame; - NSRect mCachedFrameBeforeDrawerOpen; // This is used by the drawer to figure out if the window should - // be returned to its original position when the drawer closes. - NSRect mCachedFrameAfterDrawerOpen; - - unsigned int mChromeMask; // Indicates which parts of the window to show (e.g., don't show toolbars) - - // Context menu members. - int mContextMenuFlags; - nsIDOMEvent* mContextMenuEvent; - nsIDOMNode* mContextMenuNode; - - // Cached bookmark ds used when adding through a sheet - id mCachedBMDS; - - // Throbber state variables. - ThrobberHandler* mThrobberHandler; - NSArray* mThrobberImages; - - // Funky field editor for URL bar - NSTextView *mURLFieldEditor; -} - -- (void)dealloc; - -- (id)getTabBrowser; -- (BOOL)newTabsAllowed; -- (CHBrowserWrapper*)getBrowserWrapper; - -- (void)loadURL:(NSString*)aURLSpec referrer:(NSString*)aReferrer activate:(BOOL)activate; -- (void)updateLocationFields:(NSString *)locationString; -- (void)updateSiteIcons:(NSImage *)siteIconImage; -- (void)updateToolbarItems; -- (void)focusURLBar; - - // call to update the image of the lock icon with a value from nsIWebProgressListener -- (void)updateLock:(unsigned int)securityState; - -- (void)performAppropriateLocationAction; -- (IBAction)goToLocationFromToolbarURLField:(id)sender; -- (void)beginLocationSheet; -- (IBAction)endLocationSheet:(id)sender; -- (IBAction)cancelLocationSheet:(id)sender; - -- (IBAction)cancelAddBookmarkSheet:(id)sender; -- (IBAction)endAddBookmarkSheet:(id)sender; -- (void)cacheBookmarkDS: (id)aDS; - -- (NSSize)windowWillResize:(NSWindow *)sender toSize:(NSSize)proposedFrameSize; - -- (IBAction)viewSource:(id)aSender; - -- (void)saveDocument: (NSView*)aFilterView filterList: (NSPopUpButton*)aFilterList; -- (void)saveURL: (NSView*)aFilterView filterList: (NSPopUpButton*)aFilterList - url: (NSString*)aURLSpec suggestedFilename: (NSString*)aFilename; -- (IBAction)printDocument:(id)aSender; -- (void)printPreview; -- (IBAction)performSearch:(id)aSender; - -- (void)startThrobber; -- (void)stopThrobber; -- (void)clickThrobber:(id)aSender; - -- (void)biggerTextSize; -- (void)smallerTextSize; -- (void)getInfo:(id)sender; - -- (BOOL)canGetInfo; - -- (BOOL)shouldShowBookmarkToolbar; - -- (void)addBookmarkExtended: (BOOL)aIsFromMenu isFolder:(BOOL)aIsFolder URL:(NSString*)aURL title:(NSString*)aTitle; -- (IBAction)manageBookmarks: (id)aSender; -- (void)importBookmarks: (NSString*)aURLSpec; -- (IBAction)toggleSidebar:(id)aSender; -- (BOOL)bookmarksAreVisible:(BOOL)inRequireSelection; - -- (void)newTab:(BOOL)allowHomepage; -- (void)closeTab; -- (void)previousTab; -- (void)nextTab; - -- (IBAction)back:(id)aSender; -- (IBAction)forward:(id)aSender; -- (IBAction)reload:(id)aSender; -- (IBAction)stop:(id)aSender; -- (IBAction)home:(id)aSender; - --(void)enterModalSession; - --(void)openNewWindowWithURL: (NSString*)aURLSpec referrer:(NSString*)aReferrer loadInBackground: (BOOL)aLoadInBG; --(void)openNewWindowWithGroup: (nsIDOMElement*)aFolderElement loadInBackground: (BOOL)aLoadInBG; --(void)openNewTabWithURL: (NSString*)aURLSpec referrer: (NSString*)aReferrer loadInBackground: (BOOL)aLoadInBG; - --(void)autosaveWindowFrame; --(void)disableAutosave; --(void)disableLoadPage; - --(void)setChromeMask:(unsigned int)aMask; --(unsigned int)chromeMask; - --(id)getAddBookmarkSheetWindow; --(id)getAddBookmarkTitle; --(id)getAddBookmarkFolder; --(id)getAddBookmarkCheckbox; - -// Called when a context menu should be shown. -- (void)onShowContextMenu:(int)flags domEvent:(nsIDOMEvent*)aEvent domNode:(nsIDOMNode*)aNode; -- (NSMenu*)getContextMenu; - -// Context menu methods -- (IBAction)openLinkInNewWindow:(id)aSender; -- (IBAction)openLinkInNewTab:(id)aSender; -- (void)openLinkInNewWindowOrTab: (BOOL)aUseWindow; - -- (IBAction)savePageAs:(id)aSender; -- (IBAction)saveLinkAs:(id)aSender; -- (IBAction)saveImageAs:(id)aSender; - -- (IBAction)bookmarkPage: (id)aSender; -- (IBAction)bookmarkLink: (id)aSender; - -- (IBAction)copyLinkLocation:(id)aSender; - -- (IBAction)viewOnlyThisImage:(id)aSender; - -- (CHBookmarksToolbar*) bookmarksToolbar; - -- (BOOL) isResponderGeckoView:(NSResponder*) responder; - -// called when the internal window focus has changed -// this allows us to dispatch activate and deactivate events as necessary -- (void) focusChangedFrom:(NSResponder*) oldResponder to:(NSResponder*) newResponder; - -// Called to get cached versions of our security icons -+ (NSImage*) insecureIcon; -+ (NSImage*) secureIcon; -+ (NSImage*) brokenIcon; - -// cache the toolbar defaults we parse from a plist -+ (NSArray*) toolbarDefaults; - -// Accessor to get the sidebar drawer -- (NSDrawer *)sidebarDrawer; - -// Accessor to get the proxy icon view -- (CHPageProxyIcon *)proxyIconView; - -@end - diff --git a/mozilla/camino/BrowserWindowController.mm b/mozilla/camino/BrowserWindowController.mm deleted file mode 100644 index 2005de8af26..00000000000 --- a/mozilla/camino/BrowserWindowController.mm +++ /dev/null @@ -1,1623 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape 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/NPL/ - * - * 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 mozilla.org 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 NPL, 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 NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#import "NSString+Utils.h" - -#import "BrowserWindowController.h" - -#import "CHBrowserWrapper.h" -#import "CHPreferenceManager.h" -#import "BookmarksDataSource.h" -#import "CHHistoryDataSource.h" -#import "BrowserTabView.h" -#import "CHUserDefaults.h" -#import "CHPageProxyIcon.h" - -#include "nsIWebNavigation.h" -#include "nsIDOMElement.h" -#include "nsIDOMEvent.h" -#include "nsIPrefBranch.h" -#include "nsIContextMenuListener.h" -#include "nsIDOMWindow.h" -#include "nsIScriptGlobalObject.h" -#include "nsIDocShell.h" -#include "nsIMarkupDocumentViewer.h" -#include "nsIContentViewer.h" -#include "nsCocoaBrowserService.h" -#include "nsString.h" -#include "nsCRT.h" -#include "CHGeckoUtils.h" -#include "nsIWebProgressListener.h" -#include "nsIWebBrowserChrome.h" - -#include "nsIClipboardCommands.h" -#include "nsIWebBrowser.h" -#include "nsIInterfaceRequestorUtils.h" -#include "nsIPrefBranch.h" -#include "nsIServiceManagerUtils.h" - -#include - -static NSString *BrowserToolbarIdentifier = @"Browser Window Toolbar"; -static NSString *BackToolbarItemIdentifier = @"Back Toolbar Item"; -static NSString *ForwardToolbarItemIdentifier = @"Forward Toolbar Item"; -static NSString *ReloadToolbarItemIdentifier = @"Reload Toolbar Item"; -static NSString *StopToolbarItemIdentifier = @"Stop Toolbar Item"; -static NSString *HomeToolbarItemIdentifier = @"Home Toolbar Item"; -static NSString *LocationToolbarItemIdentifier = @"Location Toolbar Item"; -static NSString *SidebarToolbarItemIdentifier = @"Sidebar Toolbar Item"; -static NSString *PrintToolbarItemIdentifier = @"Print Toolbar Item"; -static NSString *ThrobberToolbarItemIdentifier = @"Throbber Toolbar Item"; -static NSString *SearchToolbarItemIdentifier = @"Search Toolbar Item"; -static NSString *ViewSourceToolbarItemIdentifier = @"View Source Toolbar Item"; - -static NSString *NavigatorWindowFrameSaveName = @"NavigatorWindow"; - -// Cached toolbar defaults read in from a plist. If null, we'll use -// hardcoded defaults. -static NSArray* sToolbarDefaults = nil; - -#define kMaxBrowserWindowTabs 16 - -@interface BrowserWindowController(Private) -- (void)setupToolbar; -- (void)setupSidebarTabs; -@end - -@implementation BrowserWindowController - -// -// enterModalSession -// -// We have to load the window synchronously so windows coming from a JS -// window.open() can be inspected or modified inline in JS. The way we -// force this is by pretending we're a modal dialog just up to the point -// where we finish creating the window. -// -// This is icky, and there are several bugs that are caused by this hack -// (bugzilla 159410, 159661) -// --(void)enterModalSession -{ - mModalSession = [NSApp beginModalSessionForWindow: [self window]]; - [NSApp runModalSession: mModalSession]; - [NSApp endModalSession: mModalSession]; - mModalSession = nil; -} - -- (BOOL)isResponderGeckoView:(NSResponder*) responder -{ - return ([responder isKindOfClass:[NSView class]] && - [(NSView*)responder isDescendantOf:[mBrowserView getBrowserView]]); -} - -- (void)windowDidBecomeKey:(NSNotification *)notification -{ - BOOL windowWithMultipleTabs = ([mTabBrowser numberOfTabViewItems] > 1); - // When this window gets focus, fix the Close Window modifiers depending - // on whether we have multiple tabs - [[NSApp delegate] adjustCloseTabMenuItemKeyEquivalent:windowWithMultipleTabs]; - [[NSApp delegate] adjustCloseWindowMenuItemKeyEquivalent:windowWithMultipleTabs]; - - if ([self isResponderGeckoView:[[self window] firstResponder]]) { - CHBrowserView* browserView = [mBrowserView getBrowserView]; - if (browserView) - [browserView setActive:YES]; - } -} - -- (void)windowDidResignKey:(NSNotification *)notification -{ - // when we are no longer the key window, set the Close shortcut back - // to Command-W, for other windows. - [[NSApp delegate] adjustCloseTabMenuItemKeyEquivalent:NO]; - [[NSApp delegate] adjustCloseWindowMenuItemKeyEquivalent:NO]; - - if ([self isResponderGeckoView:[[self window] firstResponder]]) { - CHBrowserView* browserView = [mBrowserView getBrowserView]; - if (browserView) - [browserView setActive:NO]; - } -} - -- (void)windowDidBecomeMain:(NSNotification *)notification -{ - // we have to manually enable/disable the bookmarks menu items, because we - // turn autoenabling off for that menu - [[NSApp delegate] adjustBookmarksMenuItemsEnabling:YES]; -} - -- (void)windowDidResignMain:(NSNotification *)notification -{ - // we have to manually enable/disable the bookmarks menu items, because we - // turn autoenabling off for that menu - [[NSApp delegate] adjustBookmarksMenuItemsEnabling:NO]; -} - - --(void)mouseMoved:(NSEvent*)aEvent -{ - if (mMoveReentrant) - return; - - mMoveReentrant = YES; - NSView* view = [[[self window] contentView] hitTest: [aEvent locationInWindow]]; - [view mouseMoved: aEvent]; - [super mouseMoved: aEvent]; - mMoveReentrant = NO; -} - -- (id)initWithWindowNibName:(NSString *)windowNibName -{ - if ( (self = [super initWithWindowNibName:(NSString *)windowNibName]) ) { - // this won't correctly cascade windows on multiple monitors. RADAR bug 2972893 - // filed since it also happens in Terminal.app - if ( nsCocoaBrowserService::sNumBrowsers == 0 ) - [self setShouldCascadeWindows:NO]; - else - [self setShouldCascadeWindows:YES]; - mInitialized = NO; - mMoveReentrant = NO; - mShouldAutosave = YES; - mShouldLoadHomePage = YES; - mChromeMask = 0; - mContextMenuFlags = 0; - mContextMenuEvent = nsnull; - mContextMenuNode = nsnull; - mThrobberImages = nil; - mThrobberHandler = nil; - mURLFieldEditor = nil; - } - return self; -} - --(void)autosaveWindowFrame -{ - if (mShouldAutosave) - [[self window] saveFrameUsingName: NavigatorWindowFrameSaveName]; -} - --(void)disableAutosave -{ - mShouldAutosave = NO; -} - --(void)disableLoadPage -{ - mShouldLoadHomePage = NO; -} - -- (void)windowWillClose:(NSNotification *)notification -{ -#if DEBUG - NSLog(@"Window will close notification."); -#endif - [mSidebarBookmarksDataSource windowClosing]; - - [self autosaveWindowFrame]; - [self autorelease]; -} - -- (void)dealloc -{ -#if DEBUG - NSLog(@"Browser controller died."); -#endif - - // Loop over all tabs, and tell them that the window is closed. - int numTabs = [mTabBrowser numberOfTabViewItems]; - for (int i = 0; i < numTabs; i++) { - NSTabViewItem* item = [mTabBrowser tabViewItemAtIndex: i]; - [[item view] windowClosed]; - } - - //if (mSidebarBrowserView) - // [mSidebarBrowserView windowClosed]; - - [mProgress release]; - - [self stopThrobber]; - [mThrobberImages release]; - [mURLFieldEditor release]; - - [super dealloc]; -} - -- (void)windowDidLoad -{ - [super windowDidLoad]; - - // hide the resize control if specified by the chrome mask - if ( mChromeMask && !(mChromeMask & nsIWebBrowserChrome::CHROME_WINDOW_RESIZE) ) - [[self window] setShowsResizeIndicator:NO]; - - if ( mChromeMask && !(mChromeMask & nsIWebBrowserChrome::CHROME_STATUSBAR) ) { - // remove the status bar at the bottom and adjust the height of the content area. - float height = [mStatusBar frame].size.height; - [mStatusBar removeFromSuperview]; - [mTabBrowser setFrame:NSMakeRect([mTabBrowser frame].origin.x, [mTabBrowser frame].origin.y - height, - [mTabBrowser frame].size.width, [mTabBrowser frame].size.height + height)]; - - // clear out everything in the status bar we were holding on to. This will cause us to - // pass nil for these status items into the CHBrowserwWrapper which is what we want. We'll - // crash if we give them things that have gone away. - mProgress = nil; - mStatus = nil; - mLock = nil; - } - else { - // Retain with a single extra refcount. This allows the CHBrowserWrappers - // to remove the progress meter from its superview without having to - // worry about retaining and releasing it. - [mProgress retain]; - } - - // Get our saved dimensions. - [[self window] setFrameUsingName: NavigatorWindowFrameSaveName]; - - if (mModalSession) - [NSApp stopModal]; - - mInitialized = YES; - - mDrawerCachedFrame = NO; - - [[self window] setAcceptsMouseMovedEvents: YES]; - - [self setupToolbar]; - - // set an upper limit on the number of tabs per window - [mTabBrowser setMaxNumberOfTabs: kMaxBrowserWindowTabs]; - -// 03/03/2002 mlj Changing strategy a bit here. The addTab: method was -// duplicating a lot of the code found here. I have moved it to that method. -// We now remove the IB tab, then add one of our own. - - [mTabBrowser removeTabViewItem:[mTabBrowser tabViewItemAtIndex:0]]; - - // create ourselves a new tab and fill it with the appropriate content. If we - // have a URL pending to be opened here, don't load anything in it, otherwise, - // load the homepage if that's what the user wants (or about:blank). - [self newTab:(!mPendingURL && mShouldLoadHomePage)]; - - // we have a url "pending" from the "open new window with link" command. Deal - // with it now that everything is loaded. - if (mPendingURL) { - if (mShouldLoadHomePage) - [self loadURL: mPendingURL referrer:mPendingReferrer activate:mPendingActivate]; - [mPendingURL release]; - [mPendingReferrer release]; - mPendingURL = mPendingReferrer = nil; - } - - [mSidebarDrawer setDelegate: self]; - - [self setupSidebarTabs]; - - [mPersonalToolbar initializeToolbar]; - if ( mChromeMask && !(mChromeMask & nsIWebBrowserChrome::CHROME_PERSONAL_TOOLBAR) ) { - // remove the personal toolbar and adjust the content area upwards. Removing it - // from the parent view releases it, so we have to clear out the member var. - float height = [mPersonalToolbar frame].size.height; - [mPersonalToolbar removeFromSuperview]; - [mTabBrowser setFrame:NSMakeRect([mTabBrowser frame].origin.x, [mTabBrowser frame].origin.y, - [mTabBrowser frame].size.width, [mTabBrowser frame].size.height + height)]; - mPersonalToolbar = nil; - } - else if (![self shouldShowBookmarkToolbar]) { - [mPersonalToolbar showBookmarksToolbar:NO]; - } -} - -- (NSSize)windowWillResize:(NSWindow *)sender toSize:(NSSize)proposedFrameSize -{ - //if ( mChromeMask && !(mChromeMask & nsIWebBrowserChrome::CHROME_WINDOW_RESIZE) ) - // return [[self window] frame].size; - return proposedFrameSize; -} - - -#define RESIZE_WINDOW_FOR_DRAWER - -- (void)drawerWillOpen: (NSNotification*)aNotification -{ - [mSidebarBookmarksDataSource ensureBookmarks]; - [mHistoryDataSource ensureDataSourceLoaded]; - -#ifdef RESIZE_WINDOW_FOR_DRAWER - // Force the window to shrink and move if necessary in order to accommodate the sidebar. - NSRect screenFrame = [[[self window] screen] visibleFrame]; - NSRect windowFrame = [[self window] frame]; - NSSize drawerSize = [mSidebarDrawer contentSize]; - int fudgeFactor = 12; // Not sure how to get the drawer's border info, so we fudge it for now. - drawerSize.width += fudgeFactor; - if (windowFrame.origin.x + windowFrame.size.width + drawerSize.width > - screenFrame.origin.x + screenFrame.size.width) { - // We need to adjust the window so that it can fit. - float shrinkDelta = (windowFrame.size.width + drawerSize.width) - screenFrame.size.width; - if (shrinkDelta < 0) shrinkDelta = 0; - float newWidth = (windowFrame.size.width - shrinkDelta); - float newPosition = screenFrame.size.width - newWidth - drawerSize.width; - if (newPosition < 0) newPosition = 0; - mCachedFrameBeforeDrawerOpen = windowFrame; - windowFrame.origin.x = newPosition; - windowFrame.size.width = newWidth; - mCachedFrameAfterDrawerOpen = windowFrame; - [[self window] setFrame: windowFrame display: YES animate:NO]; // animation would be nice, but is too slow - mDrawerCachedFrame = YES; - } -#endif - -} - -- (void)drawerDidOpen:(NSNotification *)aNotification -{ - // XXXdwh This is temporary. - // [[mSidebarBrowserView getBrowserView] loadURI: @"http://tinderbox.mozilla.org/SeaMonkey/panel.html" referrer: nil flags:NSLoadFlagsNone]; - - // Toggle the sidebar icon. - if(mSidebarToolbarItem) - [mSidebarToolbarItem setImage:[NSImage imageNamed:@"sidebarOpened"]]; -} - -- (void)drawerDidClose:(NSNotification *)aNotification -{ - // Unload the Gecko web page in "My Panels" to save memory. - if(mSidebarToolbarItem) - [mSidebarToolbarItem setImage:[NSImage imageNamed:@"sidebarClosed"]]; - - // XXXdwh ignore for now. - // [[mSidebarBrowserView getBrowserView] loadURI: @"about:blank" referrer:nil flags:NSLoadFlagsNone]; - -#ifdef RESIZE_WINDOW_FOR_DRAWER - if (mDrawerCachedFrame) { - mDrawerCachedFrame = NO; - NSRect frame = [[self window] frame]; - if (frame.origin.x == mCachedFrameAfterDrawerOpen.origin.x && - frame.origin.y == mCachedFrameAfterDrawerOpen.origin.y && - frame.size.width == mCachedFrameAfterDrawerOpen.size.width && - frame.size.height == mCachedFrameAfterDrawerOpen.size.height) { -#if 0 - printf("Got here too.\n"); - printf("Xes are %f %f\n", frame.origin.x, mCachedFrameAfterDrawerOpen.origin.x); - printf("Widths are %f %f\n", frame.size.width, mCachedFrameAfterDrawerOpen.size.width); -#endif - // Restore the original frame. - [[self window] setFrame: mCachedFrameBeforeDrawerOpen display: YES animate:NO]; // animation would be nice - } - } -#endif - -} - -- (void)setupToolbar -{ - if ( !mChromeMask || (mChromeMask & nsIWebBrowserChrome::CHROME_TOOLBAR) ) { - NSToolbar *toolbar = [[[NSToolbar alloc] initWithIdentifier:BrowserToolbarIdentifier] autorelease]; - - [toolbar setDisplayMode:NSToolbarDisplayModeDefault]; - [toolbar setAllowsUserCustomization:YES]; - [toolbar setAutosavesConfiguration:YES]; - [toolbar setDelegate:self]; - [[self window] setToolbar:toolbar]; - } -} - - -// -// toolbarWillAddItem: (toolbar delegate method) -// -// Called when a button is about to be added to a toolbar. This is where we should -// cache items we may need later. For instance, we want to hold onto the sidebar -// toolbar item so we can change it when the drawer opens and closes. -// -- (void)toolbarWillAddItem:(NSNotification *)notification -{ - NSToolbarItem* item = [[notification userInfo] objectForKey:@"item"]; - if ( [[item itemIdentifier] isEqual:SidebarToolbarItemIdentifier] ) - mSidebarToolbarItem = item; -} - -// -// toolbarDidRemoveItem: (toolbar delegate method) -// -// Called when a button is about to be removed from a toolbar. This is where we should -// uncache items so we don't access them after they're gone. For instance, we want to -// clear our ref to the sidebar toolbar item. -// -- (void)toolbarDidRemoveItem:(NSNotification *)notification -{ - NSToolbarItem* item = [[notification userInfo] objectForKey:@"item"]; - if ( [[item itemIdentifier] isEqual:SidebarToolbarItemIdentifier] ) - mSidebarToolbarItem = nil; - else if ( [[item itemIdentifier] isEqual:ThrobberToolbarItemIdentifier] ) - [self stopThrobber]; -} - -- (NSArray *)toolbarAllowedItemIdentifiers:(NSToolbar *)toolbar -{ - return [NSArray arrayWithObjects: BackToolbarItemIdentifier, - ForwardToolbarItemIdentifier, - ReloadToolbarItemIdentifier, - StopToolbarItemIdentifier, - HomeToolbarItemIdentifier, - LocationToolbarItemIdentifier, - SidebarToolbarItemIdentifier, - ThrobberToolbarItemIdentifier, - SearchToolbarItemIdentifier, - PrintToolbarItemIdentifier, - ViewSourceToolbarItemIdentifier, - NSToolbarCustomizeToolbarItemIdentifier, - NSToolbarFlexibleSpaceItemIdentifier, - NSToolbarSpaceItemIdentifier, - NSToolbarSeparatorItemIdentifier, - nil]; -} - - -// -// + toolbarDefaults -// -// Parse a plist called "ToolbarDefaults.plist" in our Resources subfolder. This -// allows anyone to easily customize the default set w/out having to recompile. We -// hold onto the list for the duration of the app to avoid reparsing it every -// time. -// -+ (NSArray*) toolbarDefaults -{ - if ( !sToolbarDefaults ) { - sToolbarDefaults = [NSArray arrayWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"ToolbarDefaults" ofType:@"plist"]]; - [sToolbarDefaults retain]; - } - return sToolbarDefaults; -} - - -- (NSArray *)toolbarDefaultItemIdentifiers:(NSToolbar *)toolbar -{ - // try to get the defaults from the plist, but if not, hardcode something so - // the user always has a toolbar. - NSArray* defaults = [BrowserWindowController toolbarDefaults]; - NS_ASSERTION(defaults, "Couldn't load toolbar defaults from plist"); - return ( defaults ? defaults : [NSArray arrayWithObjects: BackToolbarItemIdentifier, - ForwardToolbarItemIdentifier, - ReloadToolbarItemIdentifier, - StopToolbarItemIdentifier, - LocationToolbarItemIdentifier, - SidebarToolbarItemIdentifier, - nil] ); -} - -// XXX use a dictionary to speed up the following? - -- (NSToolbarItem *) toolbar:(NSToolbar *)toolbar - itemForItemIdentifier:(NSString *)itemIdent - willBeInsertedIntoToolbar:(BOOL)willBeInserted -{ - NSToolbarItem *toolbarItem = [[[NSToolbarItem alloc] initWithItemIdentifier:itemIdent] autorelease]; - if ( [itemIdent isEqual:BackToolbarItemIdentifier] ) { - [toolbarItem setLabel:@"Back"]; - [toolbarItem setPaletteLabel:@"Go Back"]; - [toolbarItem setToolTip:@"Go back one page"]; - [toolbarItem setImage:[NSImage imageNamed:@"back"]]; - [toolbarItem setTarget:self]; - [toolbarItem setAction:@selector(back:)]; - } else if ( [itemIdent isEqual:ForwardToolbarItemIdentifier] ) { - [toolbarItem setLabel:@"Forward"]; - [toolbarItem setPaletteLabel:@"Go Forward"]; - [toolbarItem setToolTip:@"Go forward one page"]; - [toolbarItem setImage:[NSImage imageNamed:@"forward"]]; - [toolbarItem setTarget:self]; - [toolbarItem setAction:@selector(forward:)]; - } else if ( [itemIdent isEqual:ReloadToolbarItemIdentifier] ) { - [toolbarItem setLabel:@"Reload"]; - [toolbarItem setPaletteLabel:@"Reload Page"]; - [toolbarItem setToolTip:@"Reload current page"]; - [toolbarItem setImage:[NSImage imageNamed:@"reload"]]; - [toolbarItem setTarget:self]; - [toolbarItem setAction:@selector(reload:)]; - } else if ( [itemIdent isEqual:StopToolbarItemIdentifier] ) { - [toolbarItem setLabel:@"Stop"]; - [toolbarItem setPaletteLabel:@"Stop Loading"]; - [toolbarItem setToolTip:@"Stop loading this page"]; - [toolbarItem setImage:[NSImage imageNamed:@"stop"]]; - [toolbarItem setTarget:self]; - [toolbarItem setAction:@selector(stop:)]; - } else if ( [itemIdent isEqual:HomeToolbarItemIdentifier] ) { - [toolbarItem setLabel:@"Home"]; - [toolbarItem setPaletteLabel:@"Go Home"]; - [toolbarItem setToolTip:@"Go to home page"]; - [toolbarItem setImage:[NSImage imageNamed:@"home"]]; - [toolbarItem setTarget:self]; - [toolbarItem setAction:@selector(home:)]; - } else if ( [itemIdent isEqual:SidebarToolbarItemIdentifier] ) { - [toolbarItem setLabel:@"Sidebar"]; - [toolbarItem setPaletteLabel:@"Toggle Sidebar"]; - [toolbarItem setToolTip:@"Show or hide the Sidebar"]; - [toolbarItem setImage:[NSImage imageNamed:@"sidebarClosed"]]; - [toolbarItem setTarget:self]; - [toolbarItem setAction:@selector(toggleSidebar:)]; - } else if ( [itemIdent isEqual:SearchToolbarItemIdentifier] ) { - [toolbarItem setLabel:@"Search"]; - [toolbarItem setPaletteLabel:@"Search"]; - [toolbarItem setToolTip:@"Search the Internet"]; - [toolbarItem setImage:[NSImage imageNamed:@"saveShowFile.tif"]]; - [toolbarItem setTarget:self]; - [toolbarItem setAction:@selector(performSearch:)]; - } else if ( [itemIdent isEqual:ThrobberToolbarItemIdentifier] ) { - [toolbarItem setLabel:@""]; - [toolbarItem setPaletteLabel:@"Progress"]; - [toolbarItem setToolTip:NSLocalizedStringFromTable(@"ThrobberPageDefault", @"WebsiteDefaults", nil)]; - [toolbarItem setImage:[NSImage imageNamed:@"throbber-01"]]; - [toolbarItem setTarget:self]; - [toolbarItem setTag:'Thrb']; - [toolbarItem setAction:@selector(clickThrobber:)]; - } else if ( [itemIdent isEqual:LocationToolbarItemIdentifier] ) { - - NSMenuItem *menuFormRep = [[[NSMenuItem alloc] init] autorelease]; - - [toolbarItem setLabel:@"Location"]; - [toolbarItem setPaletteLabel:@"Location"]; - [toolbarItem setView:mLocationToolbarView]; - [toolbarItem setMinSize:NSMakeSize(128,32)]; - [toolbarItem setMaxSize:NSMakeSize(2560,32)]; - - [menuFormRep setTarget:self]; - [menuFormRep setAction:@selector(performAppropriateLocationAction)]; - [menuFormRep setTitle:[toolbarItem label]]; - - [toolbarItem setMenuFormRepresentation:menuFormRep]; - } else if ( [itemIdent isEqual:PrintToolbarItemIdentifier] ) { - [toolbarItem setLabel:@"Print"]; - [toolbarItem setPaletteLabel:@"Print"]; - [toolbarItem setToolTip:@"Print this page"]; - [toolbarItem setImage:[NSImage imageNamed:@"print"]]; - [toolbarItem setTarget:self]; - [toolbarItem setAction:@selector(printDocument:)]; - } else if ( [itemIdent isEqual:ViewSourceToolbarItemIdentifier] ) { - [toolbarItem setLabel:@"View Source"]; - [toolbarItem setPaletteLabel:@"View Page Source"]; - [toolbarItem setToolTip:@"Display the HTML source of this page"]; - [toolbarItem setImage:[NSImage imageNamed:@"showsource"]]; - [toolbarItem setTarget:self]; - [toolbarItem setAction:@selector(viewSource:)]; - } else { - toolbarItem = nil; - } - - return toolbarItem; -} - -// This method handles the enabling/disabling of the toolbar buttons. -- (BOOL)validateToolbarItem:(NSToolbarItem *)theItem -{ - // Check the action and see if it matches. - SEL action = [theItem action]; - //NSLog(@"Validating toolbar item %@ with selector %s", [theItem label], action); - if (action == @selector(back:)) - return [[mBrowserView getBrowserView] canGoBack]; - else if (action == @selector(forward:)) - return [[mBrowserView getBrowserView] canGoForward]; - else if (action == @selector(reload:)) - return [mBrowserView isBusy] == NO; - else if (action == @selector(stop:)) - return [mBrowserView isBusy]; - else - return YES; -} - -- (void)updateToolbarItems -{ - [[[self window] toolbar] validateVisibleItems]; -} - -- (void)performAppropriateLocationAction -{ - NSToolbar *toolbar = [[self window] toolbar]; - if ( [toolbar isVisible] ) { - if ( ([[[self window] toolbar] displayMode] == NSToolbarDisplayModeIconAndLabel) || - ([[[self window] toolbar] displayMode] == NSToolbarDisplayModeIconOnly) ) { - NSArray *itemsWeCanSee = [toolbar visibleItems]; - - for (unsigned int i=0;i<[itemsWeCanSee count];i++) { - if ([[[itemsWeCanSee objectAtIndex:i] itemIdentifier] isEqual:LocationToolbarItemIdentifier]) { - [self focusURLBar]; - return; - } - } - } - } - - [self beginLocationSheet]; -} - -- (void)focusURLBar -{ - [mURLBar selectText: self]; -} - -- (void)beginLocationSheet -{ - [NSApp beginSheet: mLocationSheetWindow - modalForWindow: [self window] - modalDelegate: nil - didEndSelector: nil - contextInfo: nil]; -} - -- (IBAction)endLocationSheet:(id)sender -{ - [mLocationSheetWindow orderOut:self]; - [NSApp endSheet:mLocationSheetWindow returnCode:1]; - [self loadURL:[mLocationSheetURLField stringValue] referrer:nil activate:YES]; -} - -- (IBAction)cancelLocationSheet:(id)sender -{ - [mLocationSheetWindow orderOut:self]; - [NSApp endSheet:mLocationSheetWindow returnCode:0]; -} - --(IBAction)cancelAddBookmarkSheet:(id)sender -{ - [mAddBookmarkSheetWindow orderOut:self]; - [NSApp endSheet:mAddBookmarkSheetWindow returnCode:0]; - [mCachedBMDS endAddBookmark: 0]; -} - --(IBAction)endAddBookmarkSheet:(id)sender -{ - [mAddBookmarkSheetWindow orderOut:self]; - [NSApp endSheet:mAddBookmarkSheetWindow returnCode:0]; - [mCachedBMDS endAddBookmark: 1]; -} - -- (void)cacheBookmarkDS: (id)aDS -{ - mCachedBMDS = aDS; -} - --(IBAction)manageBookmarks: (id)aSender -{ - if ([mSidebarDrawer state] == NSDrawerClosedState) - [self toggleSidebar: self]; - - [mSidebarTabView selectFirstTabViewItem:self]; -} - -- (void)importBookmarks: (NSString*)aURLSpec -{ - // Open the bookmarks sidebar. - [self manageBookmarks: self]; - - // Now do the importing. - CHBrowserWrapper* newView = [[[CHBrowserWrapper alloc] initWithTab: nil andWindow: [self window]] autorelease]; - [newView setFrame: NSZeroRect]; - [newView setIsBookmarksImport: YES]; - [[[self window] contentView] addSubview: newView]; - [newView loadURI:aURLSpec referrer: nil flags:NSLoadFlagsNone activate:NO]; -} - -- (IBAction)goToLocationFromToolbarURLField:(id)sender -{ - // trim off any whitespace around url - NSMutableString *theURL = [[NSMutableString alloc] initWithString:[sender stringValue]]; - CFStringTrimWhitespace((CFMutableStringRef)theURL); - [self loadURL:theURL referrer:nil activate:YES]; - [theURL release]; -} - -- (void)saveDocument: (NSView*)aFilterView filterList: (NSPopUpButton*)aFilterList -{ - [[mBrowserView getBrowserView] saveDocument: aFilterView filterList: aFilterList]; -} - -- (void)saveURL: (NSView*)aFilterView filterList: (NSPopUpButton*)aFilterList - url: (NSString*)aURLSpec suggestedFilename: (NSString*)aFilename -{ - [[mBrowserView getBrowserView] saveURL: aFilterView filterList: aFilterList - url: aURLSpec suggestedFilename: aFilename]; -} - -- (IBAction)viewSource:(id)aSender -{ - NSString* urlStr = [[mBrowserView getBrowserView] getFocusedURLString]; - NSString* viewSource = [@"view-source:" stringByAppendingString: urlStr]; - - PRBool loadInBackground; - nsCOMPtr pref(do_GetService("@mozilla.org/preferences-service;1")); - pref->GetBoolPref("browser.tabs.loadInBackground", &loadInBackground); - - if (![self newTabsAllowed]) - [self openNewWindowWithURL: viewSource referrer:nil loadInBackground: loadInBackground]; - else - [self openNewTabWithURL: viewSource referrer:nil loadInBackground: loadInBackground]; -} - -- (IBAction)printDocument:(id)aSender -{ - [[mBrowserView getBrowserView] printDocument]; -} - -- (void)printPreview -{ - NS_WARNING("Print Preview stopped in BrowserWindowController, not implemented"); - //XXX there is no printPreview on CHBrowserView...so this isn't implemented - //[[mBrowserView getBrowserView] printPreview]; -} - -- (IBAction)performSearch:(id)aSender -{ - NSString *searchEngine = NSLocalizedStringFromTable(@"SearchPageDefault", @"WebsiteDefaults", nil); - - // Get the users preferred search engine from IC - if (!searchEngine || [searchEngine isEqualToString:@"SearchPageDefault"]) { - searchEngine = [[CHPreferenceManager sharedInstance] getICStringPref:kICWebSearchPagePrefs]; - if (!searchEngine || ([searchEngine length] == 0)) - searchEngine = @"http://dmoz.org/"; - } - - [mBrowserView loadURI:searchEngine referrer: nil flags:NSLoadFlagsNone activate:NO]; -} - - -- (NSToolbarItem*)throbberItem -{ - // find our throbber toolbar item. - NSToolbar* toolbar = [[self window] toolbar]; - NSArray* items = [toolbar visibleItems]; - unsigned count = [items count]; - for (unsigned i = 0; i < count; ++i) { - NSToolbarItem* item = [items objectAtIndex: i]; - if ([item tag] == 'Thrb') { - return item; - } - } - return nil; -} - -- (NSArray*)throbberImages -{ - // Simply load an array of NSImage objects from the files "throbber-NN.tif". I used "Quicktime Player" to - // save all of the frames of the animated gif as individual .tif files for simplicity of implementation. - if (mThrobberImages == nil) { - NSImage* images[64]; - int i; - for (i = 0;; ++i) { - NSString* imageName = [NSString stringWithFormat: @"throbber-%02d", i + 1]; - images[i] = [NSImage imageNamed: imageName]; - if (images[i] == nil) - break; - } - mThrobberImages = [[NSArray alloc] initWithObjects: images count: i]; - } - return mThrobberImages; -} - - -- (void)clickThrobber:(id)aSender -{ - NSString *pageToLoad = NSLocalizedStringFromTable(@"ThrobberPageDefault", @"WebsiteDefaults", nil); - if (![pageToLoad isEqualToString:@"ThrobberPageDefault"]) - [self loadURL:pageToLoad referrer:nil activate:YES]; -} - -- (void)startThrobber -{ - // optimization: only throb if the throbber toolbar item is visible. - NSToolbarItem* throbberItem = [self throbberItem]; - if (throbberItem) { - [self stopThrobber]; - mThrobberHandler = [[ThrobberHandler alloc] initWithToolbarItem:throbberItem - images:[self throbberImages]]; - } -} - -- (void)stopThrobber -{ - [mThrobberHandler stopThrobber]; - [mThrobberHandler release]; - mThrobberHandler = nil; - [[self throbberItem] setImage: [[self throbberImages] objectAtIndex: 0]]; -} - - -- (BOOL)findInPageWithPattern:(NSString*)text caseSensitive:(BOOL)inCaseSensitive - wrap:(BOOL)inWrap backwards:(BOOL)inBackwards -{ - return [[mBrowserView getBrowserView] findInPageWithPattern:text caseSensitive:inCaseSensitive - wrap:inWrap backwards:inBackwards]; -} - -- (void)addBookmarkExtended: (BOOL)aIsFromMenu isFolder:(BOOL)aIsFolder URL:(NSString*)aURL title:(NSString*)aTitle -{ - [mSidebarBookmarksDataSource ensureBookmarks]; - BOOL useSel = aIsFromMenu; - if (aIsFromMenu) { - // Use selection only if the sidebar is open and the bookmarks panel is displaying. - useSel = [self bookmarksAreVisible:NO]; - } - - [mSidebarBookmarksDataSource addBookmark: self useSelection: useSel isFolder: aIsFolder URL:aURL title:aTitle]; -} - -- (BOOL)bookmarksAreVisible:(BOOL)inRequireSelection -{ - // we should really identify the tab by identifier, not index. - BOOL bookmarksShowing = ([mSidebarDrawer state] == NSDrawerOpenState) && - ([mSidebarTabView tabViewItemAtIndex: 0] == [mSidebarTabView selectedTabViewItem]); - - if (inRequireSelection) - bookmarksShowing &= ([mSidebarBookmarksDataSource haveSelectedRow]); - - return bookmarksShowing; -} - -- (IBAction)bookmarkPage: (id)aSender -{ - [self addBookmarkExtended:YES isFolder:NO URL:nil title:nil]; -} - - -- (IBAction)bookmarkLink: (id)aSender -{ - nsCOMPtr linkContent; - nsAutoString href; - CHGeckoUtils::GetEnclosingLinkElementAndHref(mContextMenuNode, getter_AddRefs(linkContent), href); - nsAutoString linkText; - CHGeckoUtils::GatherTextUnder(linkContent, linkText); - NSString* urlStr = [NSString stringWith_nsAString:href]; - NSString* titleStr = [NSString stringWith_nsAString:linkText]; - [self addBookmarkExtended:YES isFolder:NO URL:urlStr title:titleStr]; -} - -- (IBAction)back:(id)aSender -{ - [[mBrowserView getBrowserView] goBack]; -} - -- (IBAction)forward:(id)aSender -{ - [[mBrowserView getBrowserView] goForward]; -} - -- (IBAction)reload:(id)aSender -{ - [[mBrowserView getBrowserView] reload: 0]; -} - -- (IBAction)stop:(id)aSender -{ - [[mBrowserView getBrowserView] stop: nsIWebNavigation::STOP_ALL]; -} - -- (IBAction)home:(id)aSender -{ - [mBrowserView loadURI:[[CHPreferenceManager sharedInstance] homePage:NO] referrer: nil flags:NSLoadFlagsNone activate:NO]; -} - -- (IBAction)toggleSidebar:(id)aSender -{ - if ( ([mSidebarDrawer state] == NSDrawerClosedState) || ([mSidebarDrawer state] == NSDrawerClosingState) ) { - // XXXHack to bypass sidebar crashes. - [mSidebarDrawer openOnEdge: NSMaxXEdge]; - } - else - [mSidebarDrawer close]; -} - --(void)loadURL:(NSString*)aURLSpec referrer:(NSString*)aReferrer activate:(BOOL)activate -{ - if (mInitialized) { - [mBrowserView loadURI:aURLSpec referrer:aReferrer flags:NSLoadFlagsNone activate:activate]; - } - else { - // we haven't yet initialized all the browser machinery, stash the url and referrer - // until we're ready in windowDidLoad: - mPendingURL = aURLSpec; - [mPendingURL retain]; - mPendingReferrer = aReferrer; - [mPendingReferrer retain]; - mPendingActivate = activate; - } -} - -- (void)updateLocationFields:(NSString *)locationString -{ - if ( [locationString isEqual:@"about:blank"] ) // don't show about:blank to users - locationString = @""; - [mURLBar setStringValue:locationString]; - [mLocationSheetURLField setStringValue:locationString]; - - // don't call [window display] here, no matter how much you might want - // to, because it forces a redraw of every view in the window and with a lot - // of tabs, it's dog slow. - // [[self window] display]; -} - -- (void)updateSiteIcons:(NSImage *)siteIconImage -{ - if (siteIconImage == nil) - siteIconImage = [NSImage imageNamed:@"globe_ico"]; - [mProxyIcon setImage:siteIconImage]; -} - --(void)newTab:(BOOL)allowHomepage -{ - BrowserTabViewItem* newTab = [BrowserTabView makeNewTabItem]; - CHBrowserWrapper* newView = [[[CHBrowserWrapper alloc] initWithTab: newTab andWindow: [mTabBrowser window]] autorelease]; - - PRInt32 newTabPage = 0; - if (allowHomepage) { - nsCOMPtr pref(do_GetService("@mozilla.org/preferences-service;1")); - pref->GetIntPref("browser.tabs.startPage", &newTabPage); - } - - [newTab setLabel: ((newTabPage == 1) ? NSLocalizedString(@"TabLoading", @"") : NSLocalizedString(@"UntitledPageTitle", @""))]; - [newTab setView: newView]; - [mTabBrowser addTabViewItem: newTab]; - - // Focus the URL bar if we're opening a blank tab and the URL bar is visible. - NSToolbar* toolbar = [[self window] toolbar]; - BOOL focusURLBar = ([toolbar isVisible] && - ([toolbar displayMode] == NSToolbarDisplayModeIconAndLabel || - [toolbar displayMode] == NSToolbarDisplayModeIconOnly) && - newTabPage != 1 && allowHomepage); - - if (allowHomepage) - [newView loadURI: ((newTabPage == 1) ? [[CHPreferenceManager sharedInstance] homePage: NO] : @"about:blank") referrer:nil flags:NSLoadFlagsNone activate:!focusURLBar]; - - [mTabBrowser selectLastTabViewItem: self]; - - if (focusURLBar) - [self focusURLBar]; -} - --(void)closeTab -{ - if ( [mTabBrowser numberOfTabViewItems] > 1 ) { - [[[mTabBrowser selectedTabViewItem] view] windowClosed]; - [mTabBrowser removeTabViewItem:[mTabBrowser selectedTabViewItem]]; - } -} - -- (void)previousTab -{ - if ([mTabBrowser indexOfTabViewItem:[mTabBrowser selectedTabViewItem]] == 0) - [mTabBrowser selectLastTabViewItem:self]; - else - [mTabBrowser selectPreviousTabViewItem:self]; -} - -- (void)nextTab -{ - if ([mTabBrowser indexOfTabViewItem:[mTabBrowser selectedTabViewItem]] == [mTabBrowser numberOfTabViewItems] - 1) - [mTabBrowser selectFirstTabViewItem:self]; - else - [mTabBrowser selectNextTabViewItem:self]; -} - -- (void)tabView:(NSTabView *)aTabView didSelectTabViewItem:(NSTabViewItem *)aTabViewItem -{ - // Disconnect the old view, if one has been designated. - // If the window has just been opened, none has been. - if ( mBrowserView ) { - [mBrowserView disconnectView]; - } - // Connect up the new view - mBrowserView = [aTabViewItem view]; - - // Make the new view the primary content area. - [mBrowserView makePrimaryBrowserView: mURLBar status: mStatus - progress: mProgress windowController: self]; -} - -- (void)tabViewDidChangeNumberOfTabViewItems:(NSTabView *)aTabView -{ - [[NSApp delegate] fixCloseMenuItemKeyEquivalents]; -} - --(id)getTabBrowser -{ - return mTabBrowser; -} - -- (BOOL)newTabsAllowed -{ - return [mTabBrowser canMakeNewTabs]; -} - --(CHBrowserWrapper*)getBrowserWrapper -{ - return mBrowserView; -} - --(void)openNewWindowWithURL: (NSString*)aURLSpec referrer: (NSString*)aReferrer loadInBackground: (BOOL)aLoadInBG -{ - // Autosave our dimensions before we open a new window. That ensures the size ends up matching. - [self autosaveWindowFrame]; - - BrowserWindowController* browser = [[BrowserWindowController alloc] initWithWindowNibName: @"BrowserWindow"]; - [browser loadURL: aURLSpec referrer:aReferrer activate:!aLoadInBG]; - if (aLoadInBG) - [[browser window] orderWindow: NSWindowBelow relativeTo: [[self window] windowNumber]]; - else - [browser enterModalSession]; -} - --(void)openNewWindowWithGroup: (nsIDOMElement*)aFolderElement loadInBackground: (BOOL)aLoadInBG -{ - // Autosave our dimensions before we open a new window. That ensures the size ends up matching. - [self autosaveWindowFrame]; - - // Tell the Tab Browser in the newly created window to load the group - BrowserWindowController* browser = [[BrowserWindowController alloc] initWithWindowNibName: @"BrowserWindow"]; - if (aLoadInBG) - [[browser window] orderWindow: NSWindowBelow relativeTo: [[self window] windowNumber]]; - else - [browser enterModalSession]; - - id tabBrowser = [browser getTabBrowser]; - [mSidebarBookmarksDataSource openBookmarkGroup: tabBrowser groupElement: aFolderElement]; -} - --(void)openNewTabWithURL: (NSString*)aURLSpec referrer:(NSString*)aReferrer loadInBackground: (BOOL)aLoadInBG -{ - BrowserTabViewItem* newTab = [BrowserTabView makeNewTabItem]; - - // hyatt originally made new tabs open on the far right and tabs opened from a content - // link open to the right of the current tab. The idea was to keep the new tab - // close to the tab that spawned it, since they are related. Users, however, got confused - // as to why tabs appeared in different places, so now all tabs go on the far right. -#ifdef OPEN_TAB_TO_RIGHT_OF_SELECTED - NSTabViewItem* selectedTab = [mTabBrowser selectedTabViewItem]; - int index = [mTabBrowser indexOfTabViewItem: selectedTab]; - [mTabBrowser insertTabViewItem: newTab atIndex: index+1]; -#else - [mTabBrowser addTabViewItem: newTab]; -#endif - - CHBrowserWrapper* newView = [[[CHBrowserWrapper alloc] initWithTab: newTab andWindow: [mTabBrowser window]] autorelease]; - [newView setTab: newTab]; - - [newTab setLabel: NSLocalizedString(@"TabLoading", @"")]; - [newTab setView: newView]; - - [newView loadURI:aURLSpec referrer:aReferrer flags:NSLoadFlagsNone activate:!aLoadInBG]; - - if (!aLoadInBG) - [mTabBrowser selectTabViewItem: newTab]; -} - --(void)setupSidebarTabs -{ - CHIconTabViewItem *bookItem = [[CHIconTabViewItem alloc] initWithIdentifier:@"bookmarkSidebarCHIconTabViewItem" - withTabIcon:[NSImage imageNamed:@"bookicon"]]; - CHIconTabViewItem *histItem = [[CHIconTabViewItem alloc] initWithIdentifier:@"historySidebarCHIconTabViewItem" - withTabIcon:[NSImage imageNamed:@"historyicon"]]; -#if USE_SEARCH_ITEM - CHIconTabViewItem *searchItem = [[CHIconTabViewItem alloc] initWithIdentifier:@"searchSidebarCHIconTabViewItem" - withTabIcon:[NSImage imageNamed:@"searchicon"]]; -#endif -#if USE_PANELS_ITEM - CHIconTabViewItem *panelsItem = [[CHIconTabViewItem alloc] initWithIdentifier:@"myPanelsCHIconTabViewItem" - withTabIcon:[NSImage imageNamed:@"panel_icon"]]; -#endif - - [bookItem setView:[[mSidebarSourceTabView tabViewItemAtIndex:0] view]]; - [histItem setView:[[mSidebarSourceTabView tabViewItemAtIndex:1] view]]; -#if USE_SEARCH_ITEM - [searchItem setView:[[mSidebarSourceTabView tabViewItemAtIndex:2] view]]; -#endif -#if USE_PANELS_ITEM - [panelsItem setView:[[mSidebarSourceTabView tabViewItemAtIndex:3] view]]; -#endif - - // remove default tab from nib - [mSidebarTabView removeTabViewItem:[mSidebarTabView tabViewItemAtIndex:0]]; - - // insert the tabs we want - [mSidebarTabView insertTabViewItem:bookItem atIndex:0]; - [mSidebarTabView insertTabViewItem:histItem atIndex:1]; -#if USE_SEARCH_ITEM - [mSidebarTabView insertTabViewItem:searchItem atIndex:2]; -#endif -#if USE_PANELS_ITEM - [mSidebarTabView insertTabViewItem:panelsItem atIndex:3]; -#endif - - BOOL showHistory = NO; - nsCOMPtr pref(do_GetService("@mozilla.org/preferences-service;1")); - if (pref) { - PRBool historyPref = PR_FALSE; - if (NS_SUCCEEDED(pref->GetBoolPref("chimera.show_history", &historyPref))) - showHistory = historyPref ? YES : NO; - } - - if (!showHistory) - [mSidebarTabView removeTabViewItem:[mSidebarTabView tabViewItemAtIndex:1]]; - - [mSidebarTabView selectFirstTabViewItem:self]; -} - --(void)setChromeMask:(unsigned int)aMask -{ - mChromeMask = aMask; -} - --(unsigned int)chromeMask -{ - return mChromeMask; -} - --(void) biggerTextSize -{ - nsCOMPtr contentWindow = getter_AddRefs([[mBrowserView getBrowserView] getContentWindow]); - nsCOMPtr global(do_QueryInterface(contentWindow)); - if (!global) - return; - nsCOMPtr docShell; - global->GetDocShell(getter_AddRefs(docShell)); - if (!docShell) - return; - nsCOMPtr cv; - docShell->GetContentViewer(getter_AddRefs(cv)); - nsCOMPtr markupViewer(do_QueryInterface(cv)); - if (!markupViewer) - return; - float zoom; - markupViewer->GetTextZoom(&zoom); - if (zoom >= 20) - return; - - zoom += 0.25; - if (zoom > 20) - zoom = 20; - - markupViewer->SetTextZoom(zoom); -} - --(void) smallerTextSize -{ - nsCOMPtr contentWindow = getter_AddRefs([[mBrowserView getBrowserView] getContentWindow]); - nsCOMPtr global(do_QueryInterface(contentWindow)); - if (!global) - return; - nsCOMPtr docShell; - global->GetDocShell(getter_AddRefs(docShell)); - if (!docShell) - return; - nsCOMPtr cv; - docShell->GetContentViewer(getter_AddRefs(cv)); - nsCOMPtr markupViewer(do_QueryInterface(cv)); - if (!markupViewer) - return; - float zoom; - markupViewer->GetTextZoom(&zoom); - if (zoom <= 0.01) - return; - - zoom -= 0.25; - if (zoom < 0.01) - zoom = 0.01; - - markupViewer->SetTextZoom(zoom); -} - -- (void)getInfo:(id)sender -{ - [mSidebarBookmarksDataSource ensureBookmarks]; - [mSidebarBookmarksDataSource showBookmarkInfo:sender]; -} - -- (BOOL)canGetInfo -{ - return [self bookmarksAreVisible:YES]; -} - -- (BOOL)shouldShowBookmarkToolbar -{ - NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults]; - if ([defaults integerForKey:USER_DEFAULTS_HIDE_PERS_TOOLBAR_KEY] == 1) - return NO; - - return YES; -} - --(id)getAddBookmarkSheetWindow -{ - return mAddBookmarkSheetWindow; -} - --(id)getAddBookmarkTitle -{ - return mAddBookmarkTitleField; -} - --(id)getAddBookmarkFolder -{ - return mAddBookmarkFolderField; -} - --(id)getAddBookmarkCheckbox -{ - return mAddBookmarkCheckbox; -} - -// Called when a context menu should be shown. -- (void)onShowContextMenu:(int)flags domEvent:(nsIDOMEvent*)aEvent domNode:(nsIDOMNode*)aNode -{ - mContextMenuFlags = flags; - mContextMenuNode = aNode; - mContextMenuEvent = aEvent; -} - -- (NSMenu*)getContextMenu -{ - NSMenu* result = nil; - if ((mContextMenuFlags & nsIContextMenuListener::CONTEXT_LINK) != 0) { - if ((mContextMenuFlags & nsIContextMenuListener::CONTEXT_IMAGE) != 0) { - result = mImageLinkMenu; - } - else - result = mLinkMenu; - } - else if ((mContextMenuFlags & nsIContextMenuListener::CONTEXT_INPUT) != 0 || - (mContextMenuFlags & nsIContextMenuListener::CONTEXT_TEXT) != 0) { - result = mInputMenu; - } - else if ((mContextMenuFlags & nsIContextMenuListener::CONTEXT_IMAGE) != 0) { - result = mImageMenu; - } - else if ((mContextMenuFlags & nsIContextMenuListener::CONTEXT_DOCUMENT) != 0) { - result = mPageMenu; - [mBackItem setEnabled: [[mBrowserView getBrowserView] canGoBack]]; - [mForwardItem setEnabled: [[mBrowserView getBrowserView] canGoForward]]; - } - - return result; -} - -// Context menu methods -- (IBAction)openLinkInNewWindow:(id)aSender -{ - [self openLinkInNewWindowOrTab: YES]; -} - -- (IBAction)openLinkInNewTab:(id)aSender -{ - [self openLinkInNewWindowOrTab: NO]; -} - --(void)openLinkInNewWindowOrTab: (BOOL)aUseWindow -{ - nsCOMPtr linkContent; - nsAutoString href; - CHGeckoUtils::GetEnclosingLinkElementAndHref(mContextMenuNode, getter_AddRefs(linkContent), href); - - // XXXdwh Handle simple XLINKs if we want to be compatible with Mozilla, but who - // really uses these anyway? :) - if (!linkContent || href.IsEmpty()) - return; - - nsCOMPtr pref(do_GetService("@mozilla.org/preferences-service;1")); - if (!pref) - return; // Something bad happened if we can't get prefs. - - NSString* hrefStr = [NSString stringWith_nsAString:href]; - - PRBool loadInBackground; - pref->GetBoolPref("browser.tabs.loadInBackground", &loadInBackground); - - NSString* referrer = [[mBrowserView getBrowserView] getFocusedURLString]; - - if (aUseWindow || ![self newTabsAllowed]) - [self openNewWindowWithURL: hrefStr referrer:referrer loadInBackground: loadInBackground]; - else - [self openNewTabWithURL: hrefStr referrer:referrer loadInBackground: loadInBackground]; -} - -- (IBAction)savePageAs:(id)aSender -{ - [self saveDocument: nil filterList: nil]; -} - -- (IBAction)saveLinkAs:(id)aSender -{ - nsCOMPtr linkContent; - nsAutoString href; - CHGeckoUtils::GetEnclosingLinkElementAndHref(mContextMenuNode, getter_AddRefs(linkContent), href); - - // XXXdwh Handle simple XLINKs if we want to be compatible with Mozilla, but who - // really uses these anyway? :) - if (!linkContent || href.IsEmpty()) - return; - - NSString* hrefStr = [NSString stringWith_nsAString: href]; - - // The user wants to save this link. - nsAutoString text; - CHGeckoUtils::GatherTextUnder(mContextMenuNode, text); - - [self saveURL: nil filterList: nil - url: hrefStr suggestedFilename: [NSString stringWith_nsAString: text]]; -} - -- (IBAction)saveImageAs:(id)aSender -{ - nsCOMPtr imgElement(do_QueryInterface(mContextMenuNode)); - if (imgElement) { - nsAutoString text; - imgElement->GetAttribute(NS_LITERAL_STRING("src"), text); - nsAutoString url; - imgElement->GetSrc(url); - - NSString* hrefStr = [NSString stringWith_nsAString: url]; - - [self saveURL: nil filterList: nil - url: hrefStr suggestedFilename: [NSString stringWith_nsAString: text]]; - } -} - -- (IBAction)copyLinkLocation:(id)aSender -{ - CHBrowserView* view = [[self getBrowserWrapper] getBrowserView]; - if (!view) return; - - nsCOMPtr webBrowser = getter_AddRefs([view getWebBrowser]); - if (!webBrowser) return; - - nsCOMPtr clipboard(do_GetInterface(webBrowser)); - if (clipboard) - clipboard->CopyLinkLocation(); -} - - - -- (IBAction)viewOnlyThisImage:(id)aSender -{ - nsCOMPtr imgElement(do_QueryInterface(mContextMenuNode)); - if (imgElement) { - nsAutoString url; - imgElement->GetSrc(url); - - NSString* urlStr = [NSString stringWith_nsAString: url]; - NSString* referrer = [[mBrowserView getBrowserView] getFocusedURLString]; - - [self loadURL: urlStr referrer:referrer activate:YES]; - } -} - -- (CHBookmarksToolbar*) bookmarksToolbar -{ - return mPersonalToolbar; -} - - -// -// updateLock: -// -// Sets the lock icon in the status bar to the appropriate image -// -- (void)updateLock:(unsigned int)inSecurityState -{ - switch ( inSecurityState & 0x000000FF ) { - case nsIWebProgressListener::STATE_IS_INSECURE: - [mLock setImage:[BrowserWindowController insecureIcon]]; - break; - case nsIWebProgressListener::STATE_IS_SECURE: - [mLock setImage:[BrowserWindowController secureIcon]]; - break; - case nsIWebProgressListener::STATE_IS_BROKEN: - [mLock setImage:[BrowserWindowController brokenIcon]]; - break; - } -} - -+ (NSImage*) insecureIcon -{ - static NSImage* sInsecureIcon = nil; - if ( !sInsecureIcon ) - sInsecureIcon = [[NSImage imageNamed:@"globe_ico"] retain]; - return sInsecureIcon; -} - -+ (NSImage*) secureIcon; -{ - static NSImage* sSecureIcon = nil; - if ( !sSecureIcon ) - sSecureIcon = [[NSImage imageNamed:@"security_lock"] retain]; - return sSecureIcon; -} - -+ (NSImage*) brokenIcon; -{ - static NSImage* sBrokenIcon = nil; - if ( !sBrokenIcon ) - sBrokenIcon = [[NSImage imageNamed:@"security_broken"] retain]; - return sBrokenIcon; -} - -- (void) focusChangedFrom:(NSResponder*) oldResponder to:(NSResponder*) newResponder -{ - BOOL oldResponderIsGecko = [self isResponderGeckoView:oldResponder]; - BOOL newResponderIsGecko = [self isResponderGeckoView:newResponder]; - - if (oldResponderIsGecko != newResponderIsGecko) - [[mBrowserView getBrowserView] setActive:newResponderIsGecko]; -} - -- (NSDrawer *)sidebarDrawer -{ - return mSidebarDrawer; -} - -- (CHPageProxyIcon *)proxyIconView -{ - return mProxyIcon; -} - -- (id)windowWillReturnFieldEditor:(NSWindow *)aWindow toObject:(id)anObject -{ - if ([anObject isEqual:mURLBar]) { - if (!mURLFieldEditor) { - mURLFieldEditor = [[NSTextView alloc] init]; - [mURLFieldEditor setFieldEditor:YES]; - [mURLFieldEditor setAllowsUndo:YES]; - } - return mURLFieldEditor; - } - return nil; -} - -@end - - -@implementation ThrobberHandler - --(id)initWithToolbarItem:(NSToolbarItem*)inButton images:(NSArray*)inImages -{ - if ( (self = [super init]) ) { - mImages = [inImages retain]; - mTimer = [[NSTimer scheduledTimerWithTimeInterval: 0.2 - target: self selector: @selector(pulseThrobber:) - userInfo: inButton repeats: YES] retain]; - mFrame = 0; - [self startThrobber]; - } - return self; -} - --(void)dealloc -{ - [self stopThrobber]; - [mImages release]; - [super dealloc]; -} - - -// Called by an NSTimer. - -- (void)pulseThrobber:(id)aSender -{ - // advance to next frame. - if (++mFrame >= [mImages count]) - mFrame = 0; - NSToolbarItem* toolbarItem = (NSToolbarItem*) [aSender userInfo]; - [toolbarItem setImage: [mImages objectAtIndex: mFrame]]; -} - -#define QUICKTIME_THROBBER 0 - -#if QUICKTIME_THROBBER -static Boolean movieControllerFilter(MovieController mc, short action, void *params, long refCon) -{ - if (action == mcActionMovieClick || action == mcActionMouseDown) { - EventRecord* event = (EventRecord*) params; - event->what = nullEvent; - return true; - } - return false; -} -#endif - -- (void)startThrobber -{ -#if QUICKTIME_THROBBER - // Use Quicktime to draw the frames from a single Animated GIF. This works fine for the animation, but - // when the frames stop, the poster frame disappears. - NSToolbarItem* throbberItem = [self throbberItem]; - if (throbberItem != nil && [throbberItem view] == nil) { - NSSize minSize = [throbberItem minSize]; - NSLog(@"Origin minSize = %f X %f", minSize.width, minSize.height); - NSSize maxSize = [throbberItem maxSize]; - NSLog(@"Origin maxSize = %f X %f", maxSize.width, maxSize.height); - - NSURL* throbberURL = [NSURL fileURLWithPath: [[NSBundle mainBundle] pathForResource:@"throbber" ofType:@"gif"]]; - NSLog(@"throbberURL = %@", throbberURL); - NSMovie* throbberMovie = [[[NSMovie alloc] initWithURL: throbberURL byReference: YES] autorelease]; - NSLog(@"throbberMovie = %@", throbberMovie); - - if ([throbberMovie QTMovie] != nil) { - NSMovieView* throbberView = [[[NSMovieView alloc] init] autorelease]; - [throbberView setMovie: throbberMovie]; - [throbberView showController: NO adjustingSize: NO]; - [throbberView setLoopMode: NSQTMovieLoopingPlayback]; - [throbberItem setView: throbberView]; - NSSize size = NSMakeSize(32, 32); - [throbberItem setMinSize: size]; - [throbberItem setMaxSize: size]; - [throbberView gotoPosterFrame: self]; - [throbberView start: self]; - - // experiment, veto mouse clicks in the movie controller by using an action filter. - MCSetActionFilterWithRefCon((MovieController) [throbberView movieController], - NewMCActionFilterWithRefConUPP(movieControllerFilter), - 0); - } - } -#else -#endif -} - -- (void)stopThrobber -{ -#if QUICKTIME_THROBBER - // Stop the quicktime animation. - NSToolbarItem* throbberItem = [self throbberItem]; - if (throbberItem != nil) { - NSMovieView* throbberView = [throbberItem view]; - if ([throbberView isPlaying]) { - [throbberView stop: self]; - [throbberView gotoPosterFrame: self]; - } else { - [throbberView start: self]; - } - } -#else - if (mTimer) { - [mTimer invalidate]; - [mTimer release]; - mTimer = nil; - - mFrame = 0; - } -#endif -} - -@end - diff --git a/mozilla/camino/CHAboutBox.h b/mozilla/camino/CHAboutBox.h deleted file mode 100644 index 2068306e703..00000000000 --- a/mozilla/camino/CHAboutBox.h +++ /dev/null @@ -1,56 +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): - * Matt Judy - * Simon Fraser - * - * 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 ***** */ - -#include - -@interface CHAboutBox : NSObject -{ - IBOutlet NSTextView* creditsField; - IBOutlet NSTextField* buildNumberField; - IBOutlet NSWindow* window; - NSTimer *scrollTimer; - float currentPosition; - float maxScrollHeight; - NSTimeInterval startTime; - BOOL restartAtTop; -} - -+ (CHAboutBox *)sharedInstance; -- (IBAction)showPanel:(id)sender; - -@end diff --git a/mozilla/camino/CHAboutBox.m b/mozilla/camino/CHAboutBox.m deleted file mode 100644 index ec983bb4c99..00000000000 --- a/mozilla/camino/CHAboutBox.m +++ /dev/null @@ -1,154 +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): - * Matt Judy - * David Hyatt - * Simon Fraser - * - * 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 "CHAboutBox.h" - -#include "nsBuildID.h" - -@interface CHAboutBox(Private) -- (void)loadWindow; -@end - -@implementation CHAboutBox - -static CHAboutBox *sharedInstance = nil; - -+ (CHAboutBox *)sharedInstance -{ - return sharedInstance ? sharedInstance : [[self alloc] init]; -} - -- (id)init -{ - if (sharedInstance) { - [self dealloc]; - } else { - sharedInstance = [super init]; - } - return sharedInstance; -} - -- (IBAction)showPanel:(id)sender -{ - if (!creditsField) { - [self loadWindow]; - } - - if (![window isVisible]) { - currentPosition = 0; - restartAtTop = NO; - startTime = [NSDate timeIntervalSinceReferenceDate] + 3.0; - [creditsField scrollPoint:NSMakePoint( 0, 0 )]; - } - - [window makeKeyAndOrderFront:nil]; -} - -- (void)windowDidBecomeKey:(NSNotification *)notification -{ - scrollTimer = [NSTimer scheduledTimerWithTimeInterval:0.03 - target:self - selector:@selector(scrollCredits:) - userInfo:nil - repeats:YES]; -} - -- (void)windowDidResignKey:(NSNotification *)notification -{ - [scrollTimer invalidate]; -} - -- (void)scrollCredits:(NSTimer *)timer -{ - if ([NSDate timeIntervalSinceReferenceDate] >= startTime) - { - if (restartAtTop) { - startTime = [NSDate timeIntervalSinceReferenceDate] + 3.0; - restartAtTop = NO; - [creditsField scrollPoint:NSMakePoint( 0, 0 )]; - return; - } - - if (currentPosition >= maxScrollHeight) { - startTime = [NSDate timeIntervalSinceReferenceDate] + 3.0; - currentPosition = 0; - restartAtTop = YES; - } else { - [creditsField scrollPoint:NSMakePoint( 0, currentPosition )]; - currentPosition += 1; - } - } -} - -- (void)loadWindow -{ - NSString *creditsPath; - NSAttributedString *creditsString; - float fieldHeight; - float containerHeight; - - if (![NSBundle loadNibNamed:@"AboutBox" owner:self]) { - NSLog( @"Failed to load AboutBox.nib" ); - NSBeep(); - return; - } - - [window setTitle:[NSString stringWithFormat: @"About %@", NSLocalizedStringFromTable(@"CFBundleName", @"InfoPlist", nil)]]; - - creditsPath = [[NSBundle mainBundle] pathForResource:@"Credits" ofType:@"rtf"]; - creditsString = [[NSAttributedString alloc] initWithPath:creditsPath documentAttributes:nil]; - [creditsField replaceCharactersInRange:NSMakeRange( 0, 0 ) - withRTF:[creditsString RTFFromRange: - NSMakeRange( 0, [creditsString length] ) - documentAttributes:nil]]; - - fieldHeight = [creditsField frame].size.height; - - (void)[[creditsField layoutManager] glyphRangeForTextContainer:[creditsField textContainer]]; - containerHeight = [[creditsField layoutManager] usedRectForTextContainer: - [creditsField textContainer]].size.height; - maxScrollHeight = containerHeight - fieldHeight; - - [buildNumberField setStringValue: [NSString stringWithFormat: NSLocalizedString(@"BuildID", @""), NS_BUILD_ID]]; - [window setExcludedFromWindowsMenu:YES]; - [window setMenu:nil]; - [window center]; -} - -@end diff --git a/mozilla/camino/CHAutoCompleteDataSource.h b/mozilla/camino/CHAutoCompleteDataSource.h deleted file mode 100644 index 539ed560d87..00000000000 --- a/mozilla/camino/CHAutoCompleteDataSource.h +++ /dev/null @@ -1,49 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- -* -* 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 the Mozilla browser. -* -* The Initial Developer of the Original Code is Netscape -* Communications Corporation. Portions created by Netscape are -* Copyright (C) 2002 Netscape Communications Corporation. All -* Rights Reserved. -* -* Contributor(s): -* David Hyatt (Original Author) -*/ - -#import -#import "CHAutoCompleteTextField.h" -#include "nsIAutoCompleteResults.h" - -@class CHAutoCompleteTextField; - -@interface CHAutoCompleteDataSource : NSObject -{ - NSImage *mIconImage; - - NSString* mErrorMessage; - nsIAutoCompleteResults *mResults; -} - -- (id) init; - -- (int) rowCount; -- (id) resultString:(int)aRow column:(NSString *)aColumn; - -- (void) setErrorMessage: (NSString*) error; -- (NSString*) errorMessage; - -- (void) setResults: (nsIAutoCompleteResults*) results; -- (nsIAutoCompleteResults*) results; - -@end diff --git a/mozilla/camino/CHAutoCompleteDataSource.mm b/mozilla/camino/CHAutoCompleteDataSource.mm deleted file mode 100644 index 0071afa0f07..00000000000 --- a/mozilla/camino/CHAutoCompleteDataSource.mm +++ /dev/null @@ -1,127 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- -* -* 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 the Mozilla browser. -* -* The Initial Developer of the Original Code is Netscape -* Communications Corporation. Portions created by Netscape are -* Copyright (C) 2002 Netscape Communications Corporation. All -* Rights Reserved. -* -* Contributor(s): -* David Hyatt (Original Author) -* -*/ - -#import "NSString+Utils.h" - -#import -#import "CHAutoCompleteTextField.h" -#include "nsString.h" -#include "nsCRT.h" - -@implementation CHAutoCompleteDataSource - --(id)init -{ - if ((self = [super init])) { - mResults = nil; - mIconImage = [NSImage imageNamed:@"globe_ico"]; - } - return self; -} - --(void)dealloc -{ - NS_IF_RELEASE(mResults); - [super dealloc]; -} - -- (void) setErrorMessage: (NSString*) error -{ - [self setResults:nsnull]; - mErrorMessage = error; -} - -- (NSString*) errorMessage -{ - return mErrorMessage; -} - -- (void) setResults:(nsIAutoCompleteResults*)aResults -{ - NS_IF_RELEASE(mResults); - - mErrorMessage = nil; - mResults = aResults; - NS_IF_ADDREF(mResults); -} - -- (nsIAutoCompleteResults *) results -{ - return mResults; -} - -- (int) rowCount -{ - if (!mResults) - return 0; - - nsCOMPtr items; - mResults->GetItems(getter_AddRefs(items)); - PRUint32 count; - items->Count(&count); - - return count; -} - -- (id) resultString:(int)aRow column:(NSString *)aColumn -{ - NSString *result = @""; - - if (!mResults) - return result; - - nsCOMPtr items; - mResults->GetItems(getter_AddRefs(items)); - - nsCOMPtr itemSupports = dont_AddRef(items->ElementAt(aRow)); - nsCOMPtr item = do_QueryInterface(itemSupports); - if (!item) - return result; - - if ([aColumn isEqualToString:@"icon"]) { - return mIconImage; - } else if ([aColumn isEqualToString:@"col1"]) { - nsAutoString value; - item->GetValue(value); - result = [NSString stringWith_nsAString:value]; - } else if ([aColumn isEqualToString:@"col2"]) { - nsXPIDLString commentStr; - item->GetComment(getter_Copies(commentStr)); - result = [NSString stringWith_nsAString:commentStr]; - } - - return result; -} - --(int) numberOfRowsInTableView:(NSTableView*)aTableView -{ - return [self rowCount]; -} - --(id)tableView:(NSTableView*)aTableView objectValueForTableColumn:(NSTableColumn*)aTableColumn row:(int)aRowIndex -{ - return [self resultString:aRowIndex column:[aTableColumn identifier]]; -} - -@end diff --git a/mozilla/camino/CHAutoCompleteTextField.h b/mozilla/camino/CHAutoCompleteTextField.h deleted file mode 100644 index 847b86d16a7..00000000000 --- a/mozilla/camino/CHAutoCompleteTextField.h +++ /dev/null @@ -1,93 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- -* -* 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 the Mozilla browser. -* -* The Initial Developer of the Original Code is Netscape -* Communications Corporation. Portions created by Netscape are -* Copyright (C) 2002 Netscape Communications Corporation. All -* Rights Reserved. -* -* Contributor(s): -* Joe Hewitt (Original Author) -* David Haas -*/ - -#import -#import "CHAutoCompleteDataSource.h" -#include "nsIAutoCompleteSession.h" -#include "nsIAutoCompleteResults.h" -#include "nsIAutoCompleteListener.h" - -@class CHAutoCompleteDataSource, CHPageProxyIcon; - -@interface CHAutoCompleteTextField : NSTextField -{ - IBOutlet CHPageProxyIcon *mProxyIcon; - NSWindow *mPopupWin; - NSTableView *mTableView; - - CHAutoCompleteDataSource *mDataSource; - - nsIAutoCompleteSession *mSession; - nsIAutoCompleteResults *mResults; - nsIAutoCompleteListener *mListener; - - NSString *mSearchString; - - // used to remember if backspace was pressed in complete: so we can check this in controlTextDidChange - BOOL mBackspaced; - // determines if the search currently pending should complete the default result when it is ready - BOOL mCompleteResult; - // should the autocomplete fill in the default completion into the text field? The default - // is no, but this can be set with a user default pref. - BOOL mCompleteWhileTyping; - - NSTimer *mOpenTimer; -} - -- (void) setSession:(NSString *)aSession; -- (NSString *) session; -- (void) setPageProxyIcon:(NSImage *)aImage; - -- (NSTableView *) tableView; -- (int) visibleRows; - -- (void) startSearch:(NSString*)aString complete:(BOOL)aComplete; -- (void) performSearch; -- (void) dataReady:(nsIAutoCompleteResults*)aResults status:(AutoCompleteStatus)aStatus; -- (void) searchTimer:(NSTimer *)aTimer; -- (void) clearResults; - -- (void) completeDefaultResult; -- (void) completeSelectedResult; -- (void) completeResult:(int)aRow; -- (void) enterResult:(int)aRow; -- (void) revertText; - -- (void) selectRowAt:(int)aRow; -- (void) selectRowBy:(int)aRows; - -- (void) openPopup; -- (void) closePopup; -- (void) resizePopup; -- (BOOL) isOpen; - -- (void) onRowClicked:(NSNotification *)aNote; -- (void) onBlur:(NSNotification *)aNote; -- (void) onResize:(NSNotification *)aNote; -- (void) onUndoOrRedo:(NSNotification *)aNote; - -- (void) setStringUndoably:(NSString*)aString fromLocation:(unsigned int)aLocation; -- (id) fieldEditor; - -@end diff --git a/mozilla/camino/CHAutoCompleteTextField.mm b/mozilla/camino/CHAutoCompleteTextField.mm deleted file mode 100644 index 9fd20c4a4c4..00000000000 --- a/mozilla/camino/CHAutoCompleteTextField.mm +++ /dev/null @@ -1,588 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- -* -* 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 the Mozilla browser. -* -* The Initial Developer of the Original Code is Netscape -* Communications Corporation. Portions created by Netscape are -* Copyright (C) 2002 Netscape Communications Corporation. All -* Rights Reserved. -* -* Contributor(s): -* Joe Hewitt (Original Author) -* David Haas -*/ - -#import "CHAutoCompleteTextField.h" -#import "BrowserWindowController.h" -#import "CHPageProxyIcon.h" -#include "nsIServiceManager.h" -#include "nsMemory.h" -#include "nsString.h" -#include "CHUserDefaults.h" - -static const int kMaxRows = 6; -static const int kFrameMargin = 1; - -@interface AutoCompleteWindow : NSWindow -- (BOOL)isKeyWindow; -@end - -@implementation AutoCompleteWindow -- (BOOL)isKeyWindow -{ - return YES; -} -@end - -class AutoCompleteListener : public nsIAutoCompleteListener -{ -public: - AutoCompleteListener(CHAutoCompleteTextField* aTextField) - { - NS_INIT_REFCNT(); - mTextField = aTextField; - } - - NS_DECL_ISUPPORTS - - NS_IMETHODIMP OnStatus(const PRUnichar* aText) { return NS_OK; } - NS_IMETHODIMP SetParam(nsISupports *aParam) { return NS_OK; } - NS_IMETHODIMP GetParam(nsISupports **aParam) { return NS_OK; } - - NS_IMETHODIMP OnAutoComplete(nsIAutoCompleteResults *aResults, AutoCompleteStatus aStatus) - { - [mTextField dataReady:aResults status:aStatus]; - return NS_OK; - } - -private: - CHAutoCompleteTextField *mTextField; -}; - -NS_IMPL_ISUPPORTS1(AutoCompleteListener, nsIAutoCompleteListener) - -//////////////////////////////////////////////////////////////////////// - -@implementation CHAutoCompleteTextField - -- (void) awakeFromNib -{ - NSTableColumn *column; - NSScrollView *scrollView; - NSCell *dataCell; - - mSearchString = nil; - mBackspaced = NO; - mCompleteResult = NO; - mOpenTimer = nil; - - mSession = nsnull; - mResults = nsnull; - mListener = (nsIAutoCompleteListener *)new AutoCompleteListener(self); - NS_IF_ADDREF(mListener); - - [self setFont:[NSFont controlContentFontOfSize:0]]; - [self setDelegate: self]; - - // XXX the owner of the textfield should set this - [self setSession:@"history"]; - - // construct and configure the popup window - mPopupWin = [[AutoCompleteWindow alloc] initWithContentRect:NSMakeRect(0,0,0,0) - styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:NO]; - [mPopupWin setReleasedWhenClosed:NO]; - [mPopupWin setLevel:NSFloatingWindowLevel]; - [mPopupWin setHasShadow:YES]; - [mPopupWin setAlphaValue:0.9]; - - // construct and configure the view - mTableView = [[[NSTableView alloc] initWithFrame:NSMakeRect(0,0,0,0)] autorelease]; - [mTableView setIntercellSpacing:NSMakeSize(1, 2)]; - [mTableView setTarget:self]; - [mTableView setAction:@selector(onRowClicked:)]; - - // Create the icon column if we have a proxy icon - if (mProxyIcon) { - column = [[[NSTableColumn alloc] initWithIdentifier:@"icon"] autorelease]; - [column setWidth:[mProxyIcon frame].origin.x + [mProxyIcon frame].size.width]; - dataCell = [[[NSImageCell alloc] initImageCell:nil] autorelease]; - [column setDataCell:dataCell]; - [mTableView addTableColumn: column]; - } - - // create the text columns - column = [[[NSTableColumn alloc] initWithIdentifier:@"col1"] autorelease]; - [mTableView addTableColumn: column]; - column = [[[NSTableColumn alloc] initWithIdentifier:@"col2"] autorelease]; - [[column dataCell] setTextColor:[NSColor darkGrayColor]]; - [mTableView addTableColumn: column]; - - // hide the table header - [mTableView setHeaderView:nil]; - - // construct the scroll view that contains the table view - scrollView = [[[NSScrollView alloc] initWithFrame:NSMakeRect(0,0,0,0)] autorelease]; - [scrollView setHasVerticalScroller:YES]; - [[scrollView verticalScroller] setControlSize:NSSmallControlSize]; - [scrollView setDocumentView: mTableView]; - - // construct the datasource - mDataSource = [[CHAutoCompleteDataSource alloc] init]; - [mTableView setDataSource: mDataSource]; - - [mPopupWin setContentView:scrollView]; - - // listen for when window resigns from key handling - [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onBlur:) - name:NSWindowDidResignKeyNotification object:nil]; - - // listen for when window is about to be moved or resized - [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onBlur:) - name:NSWindowWillMoveNotification object:nil]; - [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onResize:) - name:NSWindowDidResizeNotification object:nil]; - - // listen for Undo/Redo to make sure autocomplete doesn't get horked. - [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onUndoOrRedo:) - name:NSUndoManagerDidRedoChangeNotification - object:[[self fieldEditor] undoManager]]; - [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onUndoOrRedo:) - name:NSUndoManagerDidUndoChangeNotification - object:[[self fieldEditor] undoManager]]; - - // read the user default on if we should auto-complete the text field as the user - // types or make them pick something from a list (a-la mozilla). - mCompleteWhileTyping = [[NSUserDefaults standardUserDefaults] boolForKey:USER_DEFAULTS_AUTOCOMPLETE_WHILE_TYPING]; -} - -- (void) dealloc -{ - [[NSNotificationCenter defaultCenter] removeObserver:self]; - - if (mSearchString) - [mSearchString release]; - - [mPopupWin release]; - [mDataSource release]; - - NS_IF_RELEASE(mSession); - NS_IF_RELEASE(mResults); - NS_IF_RELEASE(mListener); - - [super dealloc]; -} - -- (void) setSession:(NSString *)aSession -{ - NS_IF_RELEASE(mSession); - - // XXX add aSession to contract id - nsCOMPtr session = - do_GetService("@mozilla.org/autocompleteSession;1?type=history"); - mSession = session; - NS_IF_ADDREF(mSession); -} - -- (NSString *) session -{ - // XXX return session name - return @""; -} - -- (NSTableView *) tableView -{ - return mTableView; -} - -- (int) visibleRows -{ - int minRows = [mDataSource rowCount]; - return minRows < kMaxRows ? minRows : kMaxRows; -} - -- (void) setPageProxyIcon:(NSImage *)aImage -{ - [mProxyIcon setImage:aImage]; -} - --(id) fieldEditor -{ - return [[self window] fieldEditor:NO forObject:self]; -} -// searching //////////////////////////// - -- (void) startSearch:(NSString*)aString complete:(BOOL)aComplete -{ - if (mSearchString) - [mSearchString release]; - mSearchString = [aString retain]; - - mCompleteResult = aComplete; - - if ([self isOpen]) { - [self performSearch]; - } else { - // delay the search when the popup is not yet opened so that users - // don't see a jerky flashing popup when they start typing for the first time - if (mOpenTimer) { - [mOpenTimer invalidate]; - [mOpenTimer release]; - } - - mOpenTimer = [[NSTimer scheduledTimerWithTimeInterval:0.2 target:self selector:@selector(searchTimer:) - userInfo:nil repeats:NO] retain]; - } -} - -- (void) performSearch -{ - PRUnichar* chars = nsMemory::Alloc(([mSearchString length]+1) * sizeof(PRUnichar)); - [mSearchString getCharacters:chars]; - chars[[mSearchString length]] = 0; // I shouldn't have to do this - nsresult rv = mSession->OnStartLookup(chars, mResults, mListener); - nsMemory::Free(chars); - - if (NS_FAILED(rv)) - NSLog(@"Unable to perform autocomplete lookup"); -} - -- (void) dataReady:(nsIAutoCompleteResults*)aResults status:(AutoCompleteStatus)aStatus -{ - NS_IF_RELEASE(mResults); - mResults = nsnull; - - if (aStatus == nsIAutoCompleteStatus::failed) { - [mDataSource setErrorMessage:@""]; - } else if (aStatus == nsIAutoCompleteStatus::ignored) { - [mDataSource setErrorMessage:@""]; - } else if (aStatus == nsIAutoCompleteStatus::noMatch) { - [mDataSource setErrorMessage:@""]; - } else if (aStatus == nsIAutoCompleteStatus::matchFound) { - mResults = aResults; - NS_IF_ADDREF(mResults); - [mDataSource setResults:aResults]; - [self completeDefaultResult]; - } - - if ([mDataSource rowCount] > 0) { - [mTableView noteNumberOfRowsChanged]; - [self openPopup]; - } else { - [self closePopup]; - } -} - -- (void) searchTimer:(NSTimer *)aTimer -{ - [mOpenTimer release]; - mOpenTimer = nil; - - [self performSearch]; -} - -- (void) clearResults -{ - // clear out search data - if (mSearchString) - [mSearchString release]; - mSearchString = nil; - NS_IF_RELEASE(mResults); - mResults = nsnull; - - [mDataSource setResults:nil]; - - [self closePopup]; -} - -// handling the popup ///////////////////////////////// - -- (void) openPopup -{ - [self resizePopup]; - - // show the popup - if ([mPopupWin isVisible] == NO) - [mPopupWin orderFront:nil]; -} - -- (void) resizePopup -{ - NSRect locationFrame, winFrame; - NSPoint locationOrigin; - int tableHeight; - - if ([self visibleRows] == 0) { - [self closePopup]; - return; - } - - // get the origin of the location bar in coordinates of the root view - locationFrame = [[self superview] frame]; - locationOrigin = [[[self superview] superview] convertPoint:locationFrame.origin - toView:[[[self window] contentView] superview]]; - - // get the height of the table view - winFrame = [[self window] frame]; - tableHeight = (int)([mTableView rowHeight]+[mTableView intercellSpacing].height)*[self visibleRows]; - - // make the columns split the width of the popup - [[mTableView tableColumnWithIdentifier:@"col1"] setWidth:locationFrame.size.width/2]; - - // position the popup anchored to bottom/left of location bar ( - [mPopupWin setFrame:NSMakeRect(winFrame.origin.x + locationOrigin.x + kFrameMargin, - ((winFrame.origin.y + locationOrigin.y) - tableHeight) - kFrameMargin, - locationFrame.size.width - (2*kFrameMargin), - tableHeight) display:NO]; -} - -- (void) closePopup -{ - [mPopupWin close]; -} - -- (BOOL) isOpen -{ - return [mPopupWin isVisible]; -} - -// url completion //////////////////////////// - -- (void) completeDefaultResult -{ - PRInt32 defaultRow; - mResults->GetDefaultItemIndex(&defaultRow); - - if (mCompleteResult && mCompleteWhileTyping) { - [self selectRowAt:defaultRow]; - [self completeResult:defaultRow]; - } else { - [self selectRowAt:-1]; - } -} - -- (void) completeSelectedResult -{ - [self completeResult:[mTableView selectedRow]]; -} - -- (void) completeResult:(int)aRow -{ - if (aRow < 0 && mSearchString) { - // reset to the original search string with the insertion point at the end. Note - // we have to make our range before we call setStringUndoably: because it calls - // clearResults() which destroys |mSearchString|. - NSRange selectAtEnd = NSMakeRange([mSearchString length],0); - [self setStringUndoably:mSearchString fromLocation:0]; - [[self fieldEditor] setSelectedRange:selectAtEnd]; - } - else { - if ([mDataSource rowCount] <= 0) - return; - - // Fill in the suggestion from the list, but change only the text - // after what is typed and select just that part. This allows the - // user to see what they have typed and what change the autocomplete - // makes while allowing them to continue typing w/out having to - // reset the insertion point. - NSString *result = [mDataSource resultString:aRow column:@"col1"]; - NSRange matchRange = [result rangeOfString:mSearchString]; - if (matchRange.length > 0 && matchRange.location != NSNotFound) { - unsigned int location = matchRange.location + matchRange.length; - result = [result substringWithRange:NSMakeRange(location, [result length]-location)]; - [self setStringUndoably:result fromLocation:[mSearchString length]]; - } - } -} - -- (void) enterResult:(int)aRow -{ - if (aRow >= 0 && [mDataSource rowCount] > 0) { - [self setStringUndoably:[mDataSource resultString:[mTableView selectedRow] column:@"col1"] fromLocation:0]; - [self closePopup]; - } else if (mOpenTimer) { - // if there was a search timer going when we hit enter, cancel it - [mOpenTimer invalidate]; - [mOpenTimer release]; - mOpenTimer = nil; - } -} - -- (void) revertText -{ - BrowserWindowController *controller = (BrowserWindowController *)[[self window] windowController]; - NSString *url = [[controller getBrowserWrapper] getCurrentURLSpec]; - if (url) { - [self clearResults]; - NSTextView *fieldEditor = [self fieldEditor]; - [[fieldEditor undoManager] removeAllActions]; - [fieldEditor setString:url]; - [fieldEditor selectAll:self]; - } -} - -- (void) setStringUndoably:(NSString *)aString fromLocation:(unsigned int)aLocation -{ - NSTextView *fieldEditor = [self fieldEditor]; - NSRange aRange = NSMakeRange(aLocation,[[fieldEditor string] length] - aLocation); - if ([fieldEditor shouldChangeTextInRange:aRange replacementString:aString]) { - [[fieldEditor textStorage] replaceCharactersInRange:aRange withString:aString]; - // Whenever we send [self didChangeText], we trigger the - // textDidChange method, which will begin a new search with - // a new search string (which we just inserted) if the selection - // is at the end of the string. So, we "select" the first character - // to prevent that badness from happening. - [fieldEditor setSelectedRange:NSMakeRange(0,0)]; - [fieldEditor didChangeText]; - } - aRange = NSMakeRange(aLocation,[[fieldEditor string] length] - aLocation); - [fieldEditor setSelectedRange:aRange]; -} - -// selecting rows ///////////////////////////////////////// - -- (void) selectRowAt:(int)aRow -{ - if (aRow >= -1 && [mDataSource rowCount] > 0) { - // show the popup - if ([mPopupWin isVisible] == NO) - [mPopupWin orderFront:nil]; - - [mTableView selectRow:aRow byExtendingSelection:NO]; - [mTableView scrollRowToVisible: aRow]; - } -} - -- (void) selectRowBy:(int)aRows -{ - int row = [mTableView selectedRow]; - - if (row == -1 && aRows < 0) { - // if nothing is selected and you scroll up, go to last row - row = [mTableView numberOfRows]-1; - } else if (row == [mTableView numberOfRows]-1 && aRows == 1) { - // if the last row is selected and you scroll down, go to first row - row = 0; - } else if (aRows+row < 0) { - // if you scroll up beyond first row... - if (row == 0) - row = -1; // ...and first row is selected, select nothing - else - row = 0; // ...else, go to first row - } else if (aRows+row >= [mTableView numberOfRows]) { - // if you scroll down beyond the last row... - if (row == [mTableView numberOfRows]-1) - row = 0; // and last row is selected, select first row - else - row = [mTableView numberOfRows]-1; // else, go to last row - } else { - // no special case, just increment current row - row += aRows; - } - - [self selectRowAt:row]; -} - -// event handlers //////////////////////////////////////////// - -- (void) onRowClicked:(NSNotification *)aNote -{ - [self enterResult:[mTableView clickedRow]]; - [[[self window] windowController] goToLocationFromToolbarURLField:self]; -} - -- (void) onBlur:(NSNotification *)aNote -{ - [self closePopup]; -} - -- (void) onResize:(NSNotification *)aNote -{ - [self resizePopup]; -} - -- (void) onUndoOrRedo:(NSNotification *)aNote -{ - [self clearResults]; -} - -// NSTextField delegate ////////////////////////////////// -- (void)controlTextDidChange:(NSNotification *)aNote -{ - NSTextView *fieldEditor = [[aNote userInfo] objectForKey:@"NSFieldEditor"]; - NSRange range = [fieldEditor selectedRange]; - // make sure we're typing at the end of the string - if (range.location == [[fieldEditor string] length]) { - // when we ask for a NSTextView string, Cocoa returns - // a pointer to the view's backing store. So, the value - // of the string continually changes as we edit the text view. - // Since we'll edit the text view as we add in autocomplete results, - // we've got to make a copy of the string as it currently stands - // to know what we were searching for in the first place. - NSString *searchString = [[fieldEditor string] copyWithZone:nil]; - [self startSearch:searchString complete:!mBackspaced]; - [searchString release]; - } - else if (([mTableView selectedRow] == -1) || mBackspaced) - [self clearResults]; - - mBackspaced = NO; -} - -- (void)controlTextDidEndEditing:(NSNotification *)aNote -{ - [self closePopup]; - [[[[aNote userInfo] objectForKey:@"NSFieldEditor"] undoManager] removeAllActions]; -} - -- (BOOL)control:(NSControl *)control textView:(NSTextView *)textView doCommandBySelector:(SEL)command -{ - if (command == @selector(insertNewline:)) { - [self enterResult:[mTableView selectedRow]]; - } else if (command == @selector(moveUp:)) { - [self selectRowBy:-1]; - [self completeSelectedResult]; - return YES; - } else if (command == @selector(moveDown:)) { - [self selectRowBy:1]; - [self completeSelectedResult]; - return YES; - } else if (command == @selector(scrollPageUp:)) { - [self selectRowBy:-kMaxRows]; - [self completeSelectedResult]; - } else if (command == @selector(scrollPageDown:)) { - [self selectRowBy:kMaxRows]; - [self completeSelectedResult]; - } else if (command == @selector(moveToBeginningOfDocument:)) { - [self selectRowAt:0]; - [self completeSelectedResult]; - } else if (command == @selector(moveToEndOfDocument:)) { - [self selectRowAt:[mTableView numberOfRows]-1]; - [self completeSelectedResult]; - } else if (command == @selector(insertTab:)) { - if ([mPopupWin isVisible]) { - [self selectRowBy:1]; - [self completeSelectedResult]; - return YES; - } - } else if (command == @selector(deleteBackward:) || - command == @selector(deleteForward:)) { - // if the user deletes characters, we need to know so that - // we can prevent autocompletion later when search results come in - if ([[textView string] length] > 1) - mBackspaced = YES; - } - - return NO; -} - -@end diff --git a/mozilla/camino/CHBookmarksButton.h b/mozilla/camino/CHBookmarksButton.h deleted file mode 100644 index 27d5623352e..00000000000 --- a/mozilla/camino/CHBookmarksButton.h +++ /dev/null @@ -1,47 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- -* -* 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 the Mozilla browser. -* -* The Initial Developer of the Original Code is Netscape -* Communications Corporation. Portions created by Netscape are -* Copyright (C) 2002 Netscape Communications Corporation. All -* Rights Reserved. -* -* Contributor(s): -* David Hyatt (Original Author) -*/ - -#import -#import - -class nsIDOMElement; -class BookmarksService; - -@class BookmarkItem; - -@interface CHBookmarksButton : NSButton -{ - nsIDOMElement* mElement; - BookmarkItem* mBookmarkItem; - BookmarksService* mBookmarksService; - BOOL mIsFolder; -} - --(id)initWithFrame:(NSRect)frame element:(nsIDOMElement*)element bookmarksService:(BookmarksService*)bookmarksService; - --(void)setElement: (nsIDOMElement*)aElt; --(nsIDOMElement*)element; - --(IBAction)openBookmark:(id)aSender; - -@end diff --git a/mozilla/camino/CHBookmarksButton.mm b/mozilla/camino/CHBookmarksButton.mm deleted file mode 100644 index abf785435fd..00000000000 --- a/mozilla/camino/CHBookmarksButton.mm +++ /dev/null @@ -1,271 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- -* -* 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 the Mozilla browser. -* -* The Initial Developer of the Original Code is Netscape -* Communications Corporation. Portions created by Netscape are -* Copyright (C) 2002 Netscape Communications Corporation. All -* Rights Reserved. -* -* Contributor(s): -* David Hyatt (Original Author) -*/ - -#import "NSString+Utils.h" -#import "CHBookmarksButton.h" - -#include "nsCOMPtr.h" -#include "nsIContent.h" -#include "nsIDOMElement.h" -#include "nsINamespaceManager.h" -#include "nsIPrefBranch.h" -#include "nsIServiceManager.h" -#include "nsString.h" -#include "nsCRT.h" - -#import "BookmarkInfoController.h" -#import "BookmarksDataSource.h" -#import "BookmarksService.h" - -@implementation CHBookmarksButton - -- (id)initWithFrame:(NSRect)frame -{ - if ( (self = [super initWithFrame:frame]) ) { - [self setBezelStyle: NSRegularSquareBezelStyle]; - [self setButtonType: NSMomentaryChangeButton]; - [self setBordered: NO]; - [self setImagePosition: NSImageLeft]; - [self setRefusesFirstResponder: YES]; - [self setFont: [NSFont labelFontOfSize: 11.0]]; - } - return self; -} - --(id)initWithFrame:(NSRect)frame element:(nsIDOMElement*)element bookmarksService:(BookmarksService*)bookmarksService -{ - if ( (self = [self initWithFrame:frame]) ) { - mBookmarksService = bookmarksService; - [self setElement:element]; - } - return self; -} - --(IBAction)openBookmark:(id)aSender -{ - // See if we're a group. - nsAutoString group; - mElement->GetAttribute(NS_LITERAL_STRING("group"), group); - if (!group.IsEmpty()) { - BookmarksService::OpenBookmarkGroup([[[self window] windowController] getTabBrowser], mElement); - return; - } - - // Get the href attribute. This is the URL we want to load. - nsAutoString href; - mElement->GetAttribute(NS_LITERAL_STRING("href"), href); - if (href.IsEmpty()) - return; - NSString* url = [NSString stringWith_nsAString: href]; - - // Now load the URL in the window. - BrowserWindowController* brController = [[self window] windowController]; - [brController loadURL: url referrer:nil activate:YES]; -} - --(IBAction)openBookmarkInNewTab:(id)aSender -{ - nsCOMPtr pref(do_GetService("@mozilla.org/preferences-service;1")); - if (!pref) - return; // Something bad happened if we can't get prefs. - - // Get the href attribute. This is the URL we want to load. - nsAutoString hrefAttr; - mElement->GetAttribute(NS_LITERAL_STRING("href"), hrefAttr); - NSString* hrefStr = [NSString stringWith_nsAString:hrefAttr]; - - PRBool loadInBackground; - pref->GetBoolPref("browser.tabs.loadInBackground", &loadInBackground); - - BrowserWindowController* brController = [[self window] windowController]; - [brController openNewTabWithURL: hrefStr referrer:nil loadInBackground: loadInBackground]; -} - --(IBAction)openBookmarkInNewWindow:(id)aSender -{ - nsCOMPtr pref(do_GetService("@mozilla.org/preferences-service;1")); - if (!pref) - return; // Something bad happened if we can't get prefs. - - // Get the href attribute. This is the URL we want to load. - nsAutoString hrefAttr; - mElement->GetAttribute(NS_LITERAL_STRING("href"), hrefAttr); - NSString* hrefStr = [NSString stringWith_nsAString:hrefAttr]; - - PRBool loadInBackground; - pref->GetBoolPref("browser.tabs.loadInBackground", &loadInBackground); - - nsAutoString group; - mElement->GetAttribute(NS_LITERAL_STRING("group"), group); - - BrowserWindowController* brController = [[self window] windowController]; - if (group.IsEmpty()) - [brController openNewWindowWithURL: hrefStr referrer: nil loadInBackground: loadInBackground]; - else - [brController openNewWindowWithGroup: mElement loadInBackground: loadInBackground]; -} - --(IBAction)showBookmarkInfo:(id)aSender -{ - BookmarkInfoController *bic = [BookmarkInfoController sharedBookmarkInfoController]; - - [bic showWindow:bic]; - [bic setBookmark:mBookmarkItem]; -} - --(IBAction)deleteBookmarks: (id)aSender -{ - if (mElement == BookmarksService::gToolbarRoot) - return; // Don't allow the personal toolbar to be deleted. - nsCOMPtr content(do_QueryInterface(mElement)); - - nsCOMPtr parent; - mElement->GetParentNode(getter_AddRefs(parent)); - nsCOMPtr parentContent(do_QueryInterface(parent)); - nsCOMPtr dummy; - if (parent) - parent->RemoveChild(mElement, getter_AddRefs(dummy)); - BookmarksService::BookmarkRemoved(parentContent, content); -} - --(IBAction)addFolder:(id)aSender -{ - // TODO -} - --(void)drawRect:(NSRect)aRect -{ - [super drawRect: aRect]; -} - --(NSMenu*)menuForEvent:(NSEvent*)aEvent -{ - // Make a copy of the context menu but change it to target us - // FIXME - this will stop to work as soon as we add items to the context menu - // that have different targets. In that case, we probably should add code to - // CHBookmarksToolbar that manages the context menu for the CHBookmarksButtons. - - NSMenu* myMenu = [[[self superview] menu] copy]; - [[myMenu itemArray] makeObjectsPerformSelector:@selector(setTarget:) withObject: self]; - [myMenu update]; - return [myMenu autorelease]; -} - --(BOOL)validateMenuItem:(NSMenuItem*)aMenuItem -{ - if (!mBookmarkItem) - return NO; - BOOL isBookmark = [mBookmarkItem isFolder] == NO; - - nsAutoString group; - mElement->GetAttribute(NS_LITERAL_STRING("group"), group); - BOOL isGroup = !group.IsEmpty(); - - if (([aMenuItem action] == @selector(openBookmarkInNewWindow:))) { - // Bookmarks and Bookmark Groups can be opened in a new window - return (isBookmark || isGroup); - } - else if (([aMenuItem action] == @selector(openBookmarkInNewTab:))) { - // Only Bookmarks can be opened in new tabs - BrowserWindowController* brController = [[self window] windowController]; - return isBookmark && [brController newTabsAllowed]; - } - return YES; -} - --(void)mouseDown:(NSEvent*)aEvent -{ - // pop up a "context menu" on folders showing their contents. we check - // for single click to fix issues with dblclicks (bug 162367) - if (mIsFolder && [aEvent clickCount] == 1) { - nsCOMPtr content(do_QueryInterface(mElement)); - NSMenu* menu = BookmarksService::LocateMenu(content); - [NSMenu popUpContextMenu: menu withEvent: aEvent forView: self]; - } - else - [super mouseDown:aEvent]; -} - --(void)setElement: (nsIDOMElement*)aElt -{ - mElement = aElt; - nsAutoString tag; - mElement->GetLocalName(tag); - - NSImage* bookmarkImage = mBookmarksService->CreateIconForBookmark(aElt); - - nsAutoString group; - mElement->GetAttribute(NS_LITERAL_STRING("group"), group); - - if (!group.IsEmpty()) { - mIsFolder = NO; - [self setImage: bookmarkImage]; - [self setAction: @selector(openBookmark:)]; - [self setTarget: self]; - } - else if (tag.Equals(NS_LITERAL_STRING("folder"))) { - [self setImage: bookmarkImage]; - mIsFolder = YES; - } - else { - mIsFolder = NO; - [self setImage: bookmarkImage]; - [self setAction: @selector(openBookmark:)]; - [self setTarget: self]; - nsAutoString href; - mElement->GetAttribute(NS_LITERAL_STRING("href"), href); - NSString* helpText = [NSString stringWith_nsAString:href]; - [self setToolTip: helpText]; - } - - nsAutoString name; - mElement->GetAttribute(NS_LITERAL_STRING("name"), name); - [self setTitle: [NSString stringWith_nsAString: name]]; - - nsCOMPtr content(do_QueryInterface(mElement)); - mBookmarkItem = BookmarksService::GetWrapperFor(content); -} - --(nsIDOMElement*)element -{ - return mElement; -} - -- (unsigned int)draggingSourceOperationMaskForLocal:(BOOL)flag -{ - return NSDragOperationGeneric; -} - -- (void) mouseDragged: (NSEvent*) aEvent -{ - // XXX mouseDragged is never called because buttons cancel dragging while you mouse down - // I have to fix this in an ugly way, by doing the "click" stuff myself and never relying - // on the superclass for that. Bah! - - // perhaps you could just implement mouseUp to perform the action (which should be the case - // things shouldn't happen on mouse down) Then does mouseDragged get overridden? - - // BookmarksService::DragBookmark(mElement, self, aEvent); -} - -@end diff --git a/mozilla/camino/CHBookmarksOutlineView.h b/mozilla/camino/CHBookmarksOutlineView.h deleted file mode 100644 index 2c01061c074..00000000000 --- a/mozilla/camino/CHBookmarksOutlineView.h +++ /dev/null @@ -1,31 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- -* -* 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 the Mozilla browser. -* -* The Initial Developer of the Original Code is Netscape -* Communications Corporation. Portions created by Netscape are -* Copyright (C) 2002 Netscape Communications Corporation. All -* Rights Reserved. -* -* Contributor(s): -* Joe Hewitt (Original Author) -*/ - -#import -#import "CHExtendedOutlineView.h" - -@interface CHBookmarksOutlineView : CHExtendedOutlineView { - -} - -@end diff --git a/mozilla/camino/CHBookmarksOutlineView.mm b/mozilla/camino/CHBookmarksOutlineView.mm deleted file mode 100644 index f3a8942e9fe..00000000000 --- a/mozilla/camino/CHBookmarksOutlineView.mm +++ /dev/null @@ -1,64 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- -* -* 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 the Mozilla browser. -* -* The Initial Developer of the Original Code is Netscape -* Communications Corporation. Portions created by Netscape are -* Copyright (C) 2002 Netscape Communications Corporation. All -* Rights Reserved. -* -* Contributor(s): -* Joe Hewitt (Original Author) -*/ - -#import "CHBookmarksOutlineView.h" -#import "BookmarksService.h" -#import "BookmarksDataSource.h" - -#include "nsCOMPtr.h" -#include "nsIDOMElement.h" -#include "nsIContent.h" -#include "nsIDOMNode.h" - -@implementation CHBookmarksOutlineView - -- (void)awakeFromNib -{ - [self registerForDraggedTypes:[NSArray arrayWithObjects:@"MozURLType", @"MozBookmarkType", NSStringPboardType, nil]]; -} - -- (void)draggedImage:(NSImage *)anImage endedAt:(NSPoint)aPoint operation:(NSDragOperation)operation -{ - if (operation == NSDragOperationDelete) { - NSArray* contentIds = nil; - NSPasteboard* pboard = [NSPasteboard pasteboardWithName:NSDragPboard]; - contentIds = [pboard propertyListForType: @"MozBookmarkType"]; - if (contentIds) { - for (unsigned int i = 0; i < [contentIds count]; ++i) { - BookmarkItem* item = [BookmarksService::gDictionary objectForKey: [contentIds objectAtIndex:i]]; - nsCOMPtr bookmarkElt = do_QueryInterface([item contentNode]); - BookmarksService::DeleteBookmark(bookmarkElt); - } - } - } -} - -- (unsigned int)draggingSourceOperationMaskForLocal:(BOOL)flag -{ - unsigned int result = [super draggingSourceOperationMaskForLocal:flag]; - if (flag == NO) - result &= NSDragOperationDelete; - return result; -} - -@end diff --git a/mozilla/camino/CHBookmarksToolbar.h b/mozilla/camino/CHBookmarksToolbar.h deleted file mode 100644 index 8f164fdaf8a..00000000000 --- a/mozilla/camino/CHBookmarksToolbar.h +++ /dev/null @@ -1,58 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- -* -* 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 the Mozilla browser. -* -* The Initial Developer of the Original Code is Netscape -* Communications Corporation. Portions created by Netscape are -* Copyright (C) 2002 Netscape Communications Corporation. All -* Rights Reserved. -* -* Contributor(s): -* David Hyatt (Original Author) -*/ - -#import - -class nsIDOMElement; - -class BookmarksService; -class CHBookmarksButton; - -@interface CHBookmarksToolbar : NSView -{ - BookmarksService* mBookmarks; - NSMutableArray* mButtons; - CHBookmarksButton* mDragInsertionButton; - int mDragInsertionPosition; - BOOL mIsShowing; -} - --(void)initializeToolbar; - -// Called to construct & edit the initial set of personal toolbar buttons. --(void)buildButtonList; --(void)addButton: (nsIDOMElement*)aElt atIndex: (int)aIndex; --(void)editButton: (nsIDOMElement*)aElt; --(void)removeButton: (nsIDOMElement*)aElt; - -// Called to lay out the buttons on the toolbar. --(void)reflowButtons; --(void)reflowButtonsStartingAtIndex: (int)aIndex; - --(BOOL)isShown; --(void)showBookmarksToolbar: (BOOL)aShow; - -- (void) setButtonInsertionPoint:(NSPoint)aPoint; -- (NSRect)insertionRectForButton:(NSView*)aButton position:(int)aPosition; - -@end diff --git a/mozilla/camino/CHBookmarksToolbar.mm b/mozilla/camino/CHBookmarksToolbar.mm deleted file mode 100644 index c65d4d90c18..00000000000 --- a/mozilla/camino/CHBookmarksToolbar.mm +++ /dev/null @@ -1,464 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- -* -* 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 the Mozilla browser. -* -* The Initial Developer of the Original Code is Netscape -* Communications Corporation. Portions created by Netscape are -* Copyright (C) 2002 Netscape Communications Corporation. All -* Rights Reserved. -* -* Contributor(s): -* David Hyatt (Original Author) -* Kathy Brade -* David Haas -*/ - -#import "CHBookmarksButton.h" -#import "CHBookmarksToolbar.h" -#import "BookmarksService.h" -#import "BookmarksDataSource.h" - -#include "nsIDOMElement.h" -#include "nsIContent.h" - -@interface CHBookmarksToolbar(Private) -- (CHBookmarksButton*)makeNewButtonWithElement:(nsIDOMElement*)element; -@end - -@implementation CHBookmarksToolbar - -- (id)initWithFrame:(NSRect)frame -{ - if ( (self = [super initWithFrame:frame]) ) { - mBookmarks = nsnull; - mButtons = [[NSMutableArray alloc] init]; - mDragInsertionButton = nil; - mDragInsertionPosition = BookmarksService::CHInsertNone; - [self registerForDraggedTypes:[NSArray arrayWithObjects:@"MozURLType", @"MozBookmarkType", NSStringPboardType, nil]]; - mIsShowing = YES; - } - return self; -} - --(void)initializeToolbar -{ - // Initialization code here. - mBookmarks = new BookmarksService(self); - mBookmarks->AddObserver(); - mBookmarks->EnsureToolbarRoot(); - [self buildButtonList]; -} - --(void) dealloc -{ - [mButtons autorelease]; - mBookmarks->RemoveObserver(); - delete mBookmarks; - [super dealloc]; -} - -- (void)drawRect:(NSRect)aRect { - // Fill the background with our background color. - //[[NSColor colorWithCalibratedWhite: 0.98 alpha: 1.0] set]; - //NSRectFill(aRect); - - //printf("The rect is: %f %f %f %f\n", aRect.origin.x, aRect.origin.y, aRect.size.width, aRect.size.height); - - if (aRect.origin.y + aRect.size.height == - [self bounds].size.height) { - // The personal toolbar is 21 pixels tall. The bottom two pixels - // are a separator. - [[NSColor colorWithCalibratedWhite: 0.90 alpha: 1.0] set]; - //NSRectFill(NSMakeRect(aRect.origin.x, [self bounds].size.height-2, aRect.size.width, [self bounds].size.height)); - } - - // The buttons will paint themselves. Just call our base class method. - [super drawRect: aRect]; - - // draw a separator at drag n drop insertion point if there is one - if (mDragInsertionPosition) { - [[[NSColor controlShadowColor] colorWithAlphaComponent:0.6] set]; - NSRectFill([self insertionRectForButton:mDragInsertionButton position:mDragInsertionPosition]); - } -} - --(void)buildButtonList -{ - // Build the buttons, and then lay them all out. - nsCOMPtr child; - BookmarksService::gToolbarRoot->GetFirstChild(getter_AddRefs(child)); - while (child) { - nsCOMPtr childElt(do_QueryInterface(child)); - if (childElt) { - CHBookmarksButton* button = [self makeNewButtonWithElement:childElt]; - [self addSubview: button]; - [mButtons addObject: button]; - } - - nsCOMPtr temp = child; - temp->GetNextSibling(getter_AddRefs(child)); - } - - if ([self isShown]) - [self reflowButtons]; -} - --(void)addButton: (nsIDOMElement*)aElt atIndex: (int)aIndex -{ - CHBookmarksButton* button = [self makeNewButtonWithElement:aElt]; - [self addSubview: button]; - [mButtons insertObject: button atIndex: aIndex]; - if ([self isShown]) - [self reflowButtonsStartingAtIndex: aIndex]; -} - --(void)editButton: (nsIDOMElement*)aElt -{ - int count = [mButtons count]; - for (int i = 0; i < count; i++) { - CHBookmarksButton* button = [mButtons objectAtIndex: i]; - if ([button element] == aElt) { - [button setElement: aElt]; - if (count > i && [self isShown]) - [self reflowButtonsStartingAtIndex: i]; - break; - } - } - - [self setNeedsDisplay: [self isShown]]; -} - --(void)removeButton: (nsIDOMElement*)aElt -{ - int count = [mButtons count]; - for (int i = 0; i < count; i++) { - CHBookmarksButton* button = [mButtons objectAtIndex: i]; - if ([button element] == aElt) { - [mButtons removeObjectAtIndex: i]; - [button removeFromSuperview]; - if (count > i && [self isShown]) - [self reflowButtonsStartingAtIndex: i]; - break; - } - } - - [self setNeedsDisplay: [self isShown]]; -} - --(void)reflowButtons -{ - [self reflowButtonsStartingAtIndex: 0]; -} - --(void)reflowButtonsStartingAtIndex: (int)aIndex -{ - float oldHeight = [self frame].size.height; - float computedHeight = 18; - int count = [mButtons count]; - float currY = 1.0; - float prevX = 2.0; - if (aIndex > 0) { - CHBookmarksButton* prevButton = [mButtons objectAtIndex: (aIndex-1)]; - prevX += [prevButton frame].origin.x + [prevButton frame].size.width; - currY = [prevButton frame].origin.y; - } - for (int i = aIndex; i < count; i++) { - CHBookmarksButton* button = [mButtons objectAtIndex: i]; - [button sizeToFit]; - float width = [button frame].size.width; - float height = [button frame].size.height; - if (width > 150) - width = 150; - if (height < 16) - height = 16; // Our folder tiff is only 15 pixels for some reason. - [button setFrame: NSMakeRect(prevX, currY, width, height)]; - - prevX += [button frame].size.width + 2; - - if ([self bounds].size.width < prevX) { - // The previous button didn't fit. We need to make a new row. There's no need to adjust the - // view's frame yet, we'll do that below. - currY += 18; - computedHeight += 18; - - prevX = 2; - [button setFrame: NSMakeRect(prevX, currY, width, height)]; - prevX += [button frame].size.width + 2; - } - - [button setNeedsDisplay: YES]; - } - - // our size has changed, readjust our view's frame and the content area - if (computedHeight != oldHeight) { - [self setFrame: NSMakeRect([self frame].origin.x, [self frame].origin.y + (oldHeight - computedHeight), - [self frame].size.width, computedHeight)]; - [self setNeedsDisplay: [self isShown]]; - - // adjust the content area. - float sizeChange = computedHeight - oldHeight; - NSView* view = [[[self window] windowController] getTabBrowser]; - [view setFrame: NSMakeRect([view frame].origin.x, [view frame].origin.y, - [view frame].size.width, [view frame].size.height - sizeChange)]; - } -} - --(BOOL)isFlipped -{ - return YES; // Use flipped coords, so we can layout out from top row to bottom row. -} - --(void)setFrame:(NSRect)aRect -{ - NSRect oldFrame = [self frame]; - [super setFrame:aRect]; - - if (oldFrame.size.width == aRect.size.width || aRect.size.height == 0) - return; - - int count = [mButtons count]; - if (count <= 2) - return; // We have too few buttons to care. - - // Do some optimizations when we have only one row. - if (aRect.size.height < 25) // We have only one row. - { - if (oldFrame.size.width < aRect.size.width) - // We got bigger. If we already only have one row, just bail. - // This will optimize for a common resizing case. - return; - else { - // We got smaller. Just go to the last button and see if it is outside - // our bounds. - CHBookmarksButton* button = [mButtons objectAtIndex:(count-1)]; - if ([button frame].origin.x + [button frame].size.width > - [self bounds].size.width - 2) { - // The button doesn't fit any more. Reflow starting at this index. - [self reflowButtonsStartingAtIndex:(count-1)]; - } - } - } - else { - // See if we got bigger or smaller. We could gain or lose a row. - [self reflowButtons]; - } -} - --(BOOL)isShown -{ - return mIsShowing; -} - --(void)showBookmarksToolbar: (BOOL)aShow -{ - if (!aShow) { - float height = [self bounds].size.height; - [self setFrame: NSMakeRect([self frame].origin.x, [self frame].origin.y + height, - [self frame].size.width, 0)]; - // We need to adjust the content area. - NSView* view = [[[self window] windowController] getTabBrowser]; - [view setFrame: NSMakeRect([view frame].origin.x, [view frame].origin.y, - [view frame].size.width, [view frame].size.height + height)]; - } - else - // Reflowing the buttons will do the right thing. - [self reflowButtons]; - - mIsShowing = aShow; -} - -- (void)setButtonInsertionPoint:(NSPoint)aPoint -{ - int count = [mButtons count]; - - mDragInsertionButton = nsnull; - mDragInsertionPosition = BookmarksService::CHInsertAfter; - - for (int i = 0; i < count; ++i) { - CHBookmarksButton* button = [mButtons objectAtIndex: i]; - //NSLog(@"check %d - %d,%d %d,%d\n", i, [button frame].origin.x, [button frame].origin.y, aPoint.x, aPoint.y); - // XXX origin.y is coming up zero here! Need that to check the row we're dragging in :( - - nsCOMPtr tagName; - nsCOMPtr contentNode = do_QueryInterface([button element]); - contentNode->GetTag(*getter_AddRefs(tagName)); - - if (tagName == BookmarksService::gFolderAtom) { - if (([button frame].origin.x+([button frame].size.width) > aPoint.x)) { - mDragInsertionButton = button; - mDragInsertionPosition = BookmarksService::CHInsertInto; - return; - } - } else if (([button frame].origin.x+([button frame].size.width/2) > aPoint.x)) { - mDragInsertionButton = button; - mDragInsertionPosition = BookmarksService::CHInsertBefore; - return; - } else if (([button frame].origin.x+([button frame].size.width) > aPoint.x)) { - mDragInsertionButton = button; - mDragInsertionPosition = BookmarksService::CHInsertAfter; - return; - } - } -} - -- (BOOL)dropDestinationValid:(NSPasteboard*)draggingPasteboard -{ - NSArray* types = [draggingPasteboard types]; - - if ([types containsObject: @"MozBookmarkType"]) - { - NSArray *draggedIDs = [draggingPasteboard propertyListForType: @"MozBookmarkType"]; - - nsCOMPtr destinationContent; - int index = 0; - - if (mDragInsertionPosition == BookmarksService::CHInsertInto) // drop onto folder - { - nsCOMPtr parentElt = [mDragInsertionButton element]; - destinationContent = do_QueryInterface(parentElt); - index = 0; - } - else if (mDragInsertionPosition == BookmarksService::CHInsertBefore || - mDragInsertionPosition == BookmarksService::CHInsertAfter) // drop onto toolbar - { - nsCOMPtr toolbarRoot = BookmarksService::gToolbarRoot; - destinationContent = do_QueryInterface(toolbarRoot); - index = [mButtons indexOfObject: mDragInsertionButton]; - } - - BookmarkItem* toolbarFolderItem = BookmarksService::GetWrapperFor(destinationContent); - if (!BookmarksService::IsBookmarkDropValid(toolbarFolderItem, index, draggedIDs)) { - return NO; - } - } - - return YES; -} - -// NSDraggingDestination /////////// - -- (unsigned int)draggingEntered:(id )sender -{ - if (![self dropDestinationValid:[sender draggingPasteboard]]) - return NSDragOperationNone; - - return NSDragOperationGeneric; -} - -- (void)draggingExited:(id )sender -{ - if (mDragInsertionPosition) - [self setNeedsDisplayInRect:[self insertionRectForButton:mDragInsertionButton position:mDragInsertionPosition]]; - - mDragInsertionButton = nil; - mDragInsertionPosition = BookmarksService::CHInsertNone; -} - -- (unsigned int)draggingUpdated:(id )sender -{ - if (mDragInsertionPosition) - [self setNeedsDisplayInRect:[self insertionRectForButton:mDragInsertionButton position:mDragInsertionPosition]]; - - if (![self dropDestinationValid:[sender draggingPasteboard]]) - return NSDragOperationNone; - - [self setButtonInsertionPoint:[sender draggingLocation]]; - - if (mDragInsertionPosition) - [self setNeedsDisplayInRect:[self insertionRectForButton:mDragInsertionButton position:mDragInsertionPosition]]; - - return NSDragOperationGeneric; -} - -- (BOOL)prepareForDragOperation:(id )sender -{ - return YES; -} - -- (BOOL)performDragOperation:(id )sender -{ - BookmarkItem* parent = nsnull; - int index = 0; - - if (mDragInsertionPosition == BookmarksService::CHInsertInto) { // drop onto folder - nsCOMPtr parentElt = [mDragInsertionButton element]; - nsCOMPtr parentContent(do_QueryInterface(parentElt)); - parent = BookmarksService::GetWrapperFor(parentContent); - index = 0; - } - else if (mDragInsertionPosition == BookmarksService::CHInsertBefore || - mDragInsertionPosition == BookmarksService::CHInsertAfter) { // drop onto toolbar - nsCOMPtr rootElt = BookmarksService::gToolbarRoot; - nsCOMPtr rootContent(do_QueryInterface(rootElt)); - parent = BookmarksService::GetWrapperFor(rootContent); - index = [mButtons indexOfObject: mDragInsertionButton]; - if (index == NSNotFound) - rootContent->ChildCount(index); - else if (mDragInsertionPosition == BookmarksService::CHInsertAfter) - index++; - } else { - mDragInsertionButton = nil; - mDragInsertionPosition = BookmarksService::CHInsertNone; - [self setNeedsDisplay:YES]; - return NO; - } - - BOOL dropHandled = NO; - NSArray *draggedTypes = [[sender draggingPasteboard] types]; - if ( [draggedTypes containsObject:@"MozBookmarkType"] ) - { - NSArray *draggedItems = [[sender draggingPasteboard] propertyListForType: @"MozBookmarkType"]; - dropHandled = BookmarksService::PerformBookmarkDrop(parent, index, draggedItems); - } - else if ( [draggedTypes containsObject:@"MozURLType"] ) - { - NSDictionary* proxy = [[sender draggingPasteboard] propertyListForType: @"MozURLType"]; - nsCOMPtr beforeContent; - [parent contentNode]->ChildAt(index, *getter_AddRefs(beforeContent)); - BookmarkItem* beforeItem = mBookmarks->GetWrapperFor(beforeContent); // can handle nil content - dropHandled = BookmarksService::PerformProxyDrop(parent, beforeItem, proxy); - } - else if ( [draggedTypes containsObject:NSStringPboardType] ) - { - NSString* draggedText = [[sender draggingPasteboard] stringForType:NSStringPboardType]; - nsCOMPtr beforeContent; - [parent contentNode]->ChildAt(index, *getter_AddRefs(beforeContent)); - BookmarkItem* beforeItem = mBookmarks->GetWrapperFor(beforeContent); // can handle nil content - // maybe fix URL drags to include the selected text as the title - dropHandled = BookmarksService::PerformURLDrop(parent, beforeItem, draggedText, draggedText); - } - - mDragInsertionButton = nil; - mDragInsertionPosition = BookmarksService::CHInsertNone; - [self setNeedsDisplay: [self isShown]]; - - return dropHandled; -} - -- (NSRect)insertionRectForButton:(NSView*)aButton position:(int) aPosition -{ - if (aPosition == BookmarksService::CHInsertInto) { - return NSMakeRect([aButton frame].origin.x, [aButton frame].origin.y, [aButton frame].size.width, [aButton frame].size.height); - } else if (aPosition == BookmarksService::CHInsertAfter) { - return NSMakeRect([aButton frame].origin.x+[aButton frame].size.width, [aButton frame].origin.y, 2, [aButton frame].size.height); - } else {// if (aPosition == BookmarksService::CHInsertBefore) { - return NSMakeRect([aButton frame].origin.x - 2, [aButton frame].origin.y, 2, [aButton frame].size.height); - } -} - -- (CHBookmarksButton*)makeNewButtonWithElement:(nsIDOMElement*)element -{ - return [[[CHBookmarksButton alloc] initWithFrame: NSMakeRect(2, 1, 100, 17) element:element bookmarksService:mBookmarks] autorelease]; -} - -@end diff --git a/mozilla/camino/CHBrowserView.h b/mozilla/camino/CHBrowserView.h deleted file mode 100644 index ccf88cdd477..00000000000 --- a/mozilla/camino/CHBrowserView.h +++ /dev/null @@ -1,200 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape 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/NPL/ - * - * 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 mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1998 - * 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 NPL, 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 NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef __nsCocoaBrowserView_h__ -#define __nsCocoaBrowserView_h__ - -#undef DARWIN -#import - -@class CHBrowserView; -class nsCocoaBrowserListener; -class nsIDOMWindow; -class nsIWebBrowser; -class nsIDOMNode; -class nsIDOMEvent; -class nsIWebBrowserFind; -class nsIEventSink; -class nsIDragHelperService; - - -// Protocol implemented by anyone interested in progress -// related to a BrowserView. A listener should explicitly -// register itself with the view using the addListener -// method. -@protocol NSBrowserListener - -- (void)onLoadingStarted; -- (void)onLoadingCompleted:(BOOL)succeeded; -// Invoked regularly as data associated with a page streams -// in. If the total number of bytes expected is unknown, -// maxBytes is -1. -- (void)onProgressChange:(int)currentBytes outOf:(int)maxBytes; -- (void)onLocationChange:(NSString*)urlSpec; -- (void)onStatusChange:(NSString*)aMessage; -- (void)onSecurityStateChange:(unsigned long)newState; -// Called when a context menu should be shown. -- (void)onShowContextMenu:(int)flags domEvent:(nsIDOMEvent*)aEvent domNode:(nsIDOMNode*)aNode; -// Called when a tooltip should be shown or hidden -- (void)onShowTooltip:(NSPoint)where withText:(NSString*)text; -- (void)onHideTooltip; - -@end - -typedef enum { - NSStatusTypeScript = 0x0001, - NSStatusTypeScriptDefault = 0x0002, - NSStatusTypeLink = 0x0003, -} NSStatusType; - -@protocol NSBrowserContainer - -- (void)setStatus:(NSString *)statusString ofType:(NSStatusType)type; -- (NSString *)title; -- (void)setTitle:(NSString *)title; -// Set the dimensions of our NSView. The container might need to do -// some adjustment, so the view doesn't do it directly. -- (void)sizeBrowserTo:(NSSize)dimensions; -// Create a new browser container window and return the contained view. -- (CHBrowserView*)createBrowserWindow:(unsigned int)mask; - -- (NSMenu*)getContextMenu; -- (NSWindow*)getNativeWindow; - -// Ask whether the browser should accept a drag from the given source. -// Should return NO if the source is a container for the browser, or -// another item that represents the same entity (e.g. tab or proxy icon) -- (BOOL)shouldAcceptDragFromSource:(id)dragSource; - -@end - -enum { - NSLoadFlagsNone = 0x0000, - NSLoadFlagsDontPutInHistory = 0x0010, - NSLoadFlagsReplaceHistoryEntry = 0x0020, - NSLoadFlagsBypassCacheAndProxy = 0x0040 -}; - -enum { - NSStopLoadNetwork = 0x01, - NSStopLoadContent = 0x02, - NSStopLoadAll = 0x03 -}; - -@interface CHBrowserView : NSView -{ - nsIWebBrowser* _webBrowser; - nsCocoaBrowserListener* _listener; - NSWindow* mWindow; - - nsIDragHelperService* mDragHelper; - NSPoint mLastTrackedLocation; - NSWindow* mLastTrackedWindow; -} - -// NSView overrides -- (id)initWithFrame:(NSRect)frame; -- (id)initWithFrame:(NSRect)frame andWindow:(NSWindow*)aWindow; - -- (void)dealloc; -- (void)setFrame:(NSRect)frameRect; - -// nsIWebBrowser methods -- (void)addListener:(id )listener; -- (void)removeListener:(id )listener; -- (void)setContainer:(id )container; -- (nsIDOMWindow*)getContentWindow; - -// nsIWebNavigation methods -- (void)loadURI:(NSString *)urlSpec referrer:(NSString*)referrer flags:(unsigned int)flags; -- (void)reload:(unsigned int)flags; -- (BOOL)canGoBack; -- (BOOL)canGoForward; -- (void)goBack; -- (void)goForward; -- (void)gotoIndex:(int)index; -- (void)stop:(unsigned int)flags; -- (NSString*)getCurrentURI; - -- (void)saveDocument: (NSView*)aFilterView filterList: (NSPopUpButton*)aFilterList; -- (void)saveURL: (NSView*)aFilterView filterList: (NSPopUpButton*)aFilterList - url: (NSString*)aURLSpec suggestedFilename: (NSString*)aFilename; - -- (void)printDocument; - -- (BOOL)findInPageWithPattern:(NSString*)inText caseSensitive:(BOOL)inCaseSensitive - wrap:(BOOL)inWrap backwards:(BOOL)inBackwards; - --(BOOL)validateMenuItem: (NSMenuItem*)aMenuItem; - --(IBAction)cut:(id)aSender; --(BOOL)canCut; --(IBAction)copy:(id)aSender; --(BOOL)canCopy; --(IBAction)paste:(id)aSender; --(BOOL)canPaste; --(IBAction)delete:(id)aSender; --(BOOL)canDelete; --(IBAction)selectAll:(id)aSender; - --(IBAction)undo:(id)aSender; --(IBAction)redo:(id)aSender; - -- (BOOL)canUndo; -- (BOOL)canRedo; - --(NSString*)getCurrentURLSpec; - -- (void)setActive: (BOOL)aIsActive; - -- (NSMenu*)getContextMenu; -- (NSWindow*)getNativeWindow; - -- (void)destroyWebBrowser; -- (nsIWebBrowser*)getWebBrowser; -- (nsCocoaBrowserListener*)getCocoaBrowserListener; -- (void)setWebBrowser:(nsIWebBrowser*)browser; - -- (NSString*)getFocusedURLString; - - // given a point in window coordinates, find the Gecko event sink of the ChildView the - // point is over. -- (void) findEventSink:(nsIEventSink**)outSink forPoint:(NSPoint)inPoint inWindow:(NSWindow*)inWind; - -@end - -#endif // __nsCocoaBrowserView_h__ diff --git a/mozilla/camino/CHBrowserView.mm b/mozilla/camino/CHBrowserView.mm deleted file mode 100644 index 3006c0304d1..00000000000 --- a/mozilla/camino/CHBrowserView.mm +++ /dev/null @@ -1,870 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape 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/NPL/ - * - * 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 mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1998 - * 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 NPL, 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 NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#import "NSString+Utils.h" - -#include "nsCWebBrowser.h" -#include "nsIBaseWindow.h" -#include "nsIWebNavigation.h" -#include "nsComponentManagerUtils.h" - -#include "nsIURI.h" -#include "nsIDOMWindow.h" -#include "nsIWidget.h" - -// Printing -#include "nsIWebBrowserPrint.h" -//#include "nsIPrintSettings.h" - -// Saving of links/images/docs -#include "nsIWebBrowserFocus.h" -#include "nsIDOMNSDocument.h" -#include "nsIDOMLocation.h" -#include "nsIWebBrowserPersist.h" -#include "nsIProperties.h" -//#include "nsIRequest.h" -//#include "nsIPrefService.h" -#include "nsISHistory.h" -#include "nsIHistoryEntry.h" -#include "nsISHEntry.h" -#include "nsNetUtil.h" -#include "SaveHeaderSniffer.h" - -#import "CHBrowserWrapper.h" -#import "CHBrowserView.h" - -#import "FindDlgController.h" -#import "nsCocoaBrowserService.h" -#import "nsCocoaBrowserListener.h" - -#import "mozView.h" - -typedef unsigned int DragReference; -#include "nsIDragHelperService.h" - -// Cut/copy/paste -#include "nsIClipboardCommands.h" -#include "nsIInterfaceRequestorUtils.h" - -// Undo/redo -#include "nsICommandManager.h" -#include "nsICommandParams.h" - - -const char kPersistContractID[] = "@mozilla.org/embedding/browser/nsWebBrowserPersist;1"; -const char kDirServiceContractID[] = "@mozilla.org/file/directory_service;1"; - -@implementation CHBrowserView - -- (id)initWithFrame:(NSRect)frame andWindow:(NSWindow*)aWindow -{ - mWindow = aWindow; - return [self initWithFrame:frame]; -} - -- (id)initWithFrame:(NSRect)frame -{ - if ( (self = [super initWithFrame:frame]) ) - { - nsresult rv = nsCocoaBrowserService::InitEmbedding(); - if (NS_FAILED(rv)) { -// XXX need to throw - } - - _listener = new nsCocoaBrowserListener(self); - NS_ADDREF(_listener); - -// Create the web browser instance - nsCOMPtr browser = do_CreateInstance(NS_WEBBROWSER_CONTRACTID, &rv); - if (NS_FAILED(rv)) { -// XXX need to throw - } - - _webBrowser = browser; - NS_ADDREF(_webBrowser); - -// Set the container nsIWebBrowserChrome - _webBrowser->SetContainerWindow(NS_STATIC_CAST(nsIWebBrowserChrome *, _listener)); - -// Register as a listener for web progress - nsCOMPtr weak = do_GetWeakReference(NS_STATIC_CAST(nsIWebProgressListener*, _listener)); - _webBrowser->AddWebBrowserListener(weak, NS_GET_IID(nsIWebProgressListener)); - -// Hook up the widget hierarchy with us as the parent - nsCOMPtr baseWin = do_QueryInterface(_webBrowser); - baseWin->InitWindow((NSView*)self, nsnull, 0, 0, - frame.size.width, frame.size.height); - baseWin->Create(); - -// register the view as a drop site for text, files, and urls. - [self registerForDraggedTypes: [NSArray arrayWithObjects: - @"MozURLType", NSStringPboardType, NSURLPboardType, NSFilenamesPboardType, nil]]; - } - return self; -} - -- (void)destroyWebBrowser -{ - nsCOMPtr baseWin = do_QueryInterface(_webBrowser); - baseWin->Destroy(); -} - -- (void)dealloc -{ - NS_RELEASE(_listener); - NS_IF_RELEASE(_webBrowser); - - nsCocoaBrowserService::BrowserClosed(); - -#if DEBUG - NSLog(@"CHBrowserView died."); -#endif - - [super dealloc]; -} - -- (void)setFrame:(NSRect)frameRect -{ - [super setFrame:frameRect]; - if (_webBrowser) { - nsCOMPtr window = do_QueryInterface(_webBrowser); - window->SetSize((PRInt32)frameRect.size.width, - (PRInt32)frameRect.size.height, - PR_TRUE); - } -} - -- (void)addListener:(id )listener -{ - _listener->AddListener(listener); -} - -- (void)removeListener:(id )listener -{ - _listener->RemoveListener(listener); -} - -- (void)setContainer:(id )container -{ - _listener->SetContainer(container); -} - -- (nsIDOMWindow*)getContentWindow -{ - nsIDOMWindow* window; - - _webBrowser->GetContentDOMWindow(&window); - - return window; -} - -- (void)loadURI:(NSString *)urlSpec referrer:(NSString*)referrer flags:(unsigned int)flags -{ - nsCOMPtr nav = do_QueryInterface(_webBrowser); - - int length = [urlSpec length]; - PRUnichar* specStr = nsMemory::Alloc((length+1) * sizeof(PRUnichar)); - [urlSpec getCharacters:specStr]; - specStr[length] = PRUnichar(0); - - nsCOMPtr referrerURI; - if ( referrer ) - NS_NewURI(getter_AddRefs(referrerURI), [referrer UTF8String]); - - PRUint32 navFlags = nsIWebNavigation::LOAD_FLAGS_NONE; - if (flags & NSLoadFlagsDontPutInHistory) { - navFlags |= nsIWebNavigation::LOAD_FLAGS_BYPASS_HISTORY; - } - if (flags & NSLoadFlagsReplaceHistoryEntry) { - navFlags |= nsIWebNavigation::LOAD_FLAGS_REPLACE_HISTORY; - } - if (flags & NSLoadFlagsBypassCacheAndProxy) { - navFlags |= nsIWebNavigation::LOAD_FLAGS_BYPASS_CACHE | - nsIWebNavigation::LOAD_FLAGS_BYPASS_PROXY; - } - - nsresult rv = nav->LoadURI(specStr, navFlags, referrerURI, nsnull, nsnull); - if (NS_FAILED(rv)) { - // XXX need to throw - } - - nsMemory::Free(specStr); -} - -- (void)reload:(unsigned int)flags -{ - nsCOMPtr nav = do_QueryInterface(_webBrowser); - - PRUint32 navFlags = nsIWebNavigation::LOAD_FLAGS_NONE; - if (flags & NSLoadFlagsBypassCacheAndProxy) { - navFlags |= nsIWebNavigation::LOAD_FLAGS_BYPASS_CACHE | - nsIWebNavigation::LOAD_FLAGS_BYPASS_PROXY; - } - - nsresult rv = nav->Reload(navFlags); - if (NS_FAILED(rv)) { - // XXX need to throw - } -} - -- (BOOL)canGoBack -{ - nsCOMPtr nav = do_QueryInterface(_webBrowser); - - PRBool can; - nav->GetCanGoBack(&can); - - return can ? YES : NO; -} - -- (BOOL)canGoForward -{ - nsCOMPtr nav = do_QueryInterface(_webBrowser); - - PRBool can; - nav->GetCanGoForward(&can); - - return can ? YES : NO; -} - -- (void)goBack -{ - nsCOMPtr nav = do_QueryInterface(_webBrowser); - - nsresult rv = nav->GoBack(); - if (NS_FAILED(rv)) { - // XXX need to throw - } -} - -- (void)goForward -{ - nsCOMPtr nav = do_QueryInterface(_webBrowser); - - nsresult rv = nav->GoForward(); - if (NS_FAILED(rv)) { - // XXX need to throw - } -} - -- (void)gotoIndex:(int)index -{ - nsCOMPtr nav = do_QueryInterface(_webBrowser); - - nsresult rv = nav->GotoIndex(index); - if (NS_FAILED(rv)) { - // XXX need to throw - } -} - -- (void)stop:(unsigned int)flags -{ - nsCOMPtr nav = do_QueryInterface(_webBrowser); - - nsresult rv = nav->Stop(flags); - if (NS_FAILED(rv)) { - // XXX need to throw - } -} - -// XXXbryner This isn't used anywhere. how is it different from getCurrentURLSpec? -- (NSString*)getCurrentURI -{ - nsCOMPtr uri; - nsCOMPtr nav = do_QueryInterface(_webBrowser); - - nav->GetCurrentURI(getter_AddRefs(uri)); - if (!uri) { - return nsnull; - } - - nsCAutoString spec; - uri->GetSpec(spec); - - const char* cstr = spec.get(); - NSString* str = [NSString stringWithCString:cstr]; - - return str; -} - -- (nsCocoaBrowserListener*)getCocoaBrowserListener -{ - return _listener; -} - -- (nsIWebBrowser*)getWebBrowser -{ - NS_IF_ADDREF(_webBrowser); - return _webBrowser; -} - -- (void)setWebBrowser:(nsIWebBrowser*)browser -{ - _webBrowser = browser; - - if (_webBrowser) { - // Set the container nsIWebBrowserChrome - _webBrowser->SetContainerWindow(NS_STATIC_CAST(nsIWebBrowserChrome *, - _listener)); - - NSRect frame = [self frame]; - - // Hook up the widget hierarchy with us as the parent - nsCOMPtr baseWin = do_QueryInterface(_webBrowser); - baseWin->InitWindow((NSView*)self, nsnull, 0, 0, - frame.size.width, frame.size.height); - baseWin->Create(); - } - -} - --(void) saveInternal: (nsIURI*)aURI - withDocument: (nsIDOMDocument*)aDocument - suggestedFilename: (const char*)aFilename - bypassCache: (BOOL)aBypassCache - filterView: (NSView*)aFilterView - filterList: (NSPopUpButton*)aFilterList -{ - // Create our web browser persist object. This is the object that knows - // how to actually perform the saving of the page (and of the images - // on the page). - nsCOMPtr webPersist(do_CreateInstance(kPersistContractID)); - if (!webPersist) - return; - - // Make a temporary file object that we can save to. - nsCOMPtr dirService(do_GetService(kDirServiceContractID)); - if (!dirService) - return; - nsCOMPtr tmpFile; - dirService->Get("TmpD", NS_GET_IID(nsIFile), getter_AddRefs(tmpFile)); - static short unsigned int tmpRandom = 0; - nsAutoString tmpNo; tmpNo.AppendInt(tmpRandom++); - nsAutoString saveFile(NS_LITERAL_STRING("-sav")); - saveFile += tmpNo; - saveFile += NS_LITERAL_STRING("tmp"); - tmpFile->Append(saveFile); - - // Get the post data if we're an HTML doc. - nsCOMPtr postData; - if (aDocument) { - nsCOMPtr webNav(do_QueryInterface(_webBrowser)); - nsCOMPtr sessionHistory; - webNav->GetSessionHistory(getter_AddRefs(sessionHistory)); - nsCOMPtr entry; - PRInt32 sindex; - sessionHistory->GetIndex(&sindex); - sessionHistory->GetEntryAtIndex(sindex, PR_FALSE, getter_AddRefs(entry)); - nsCOMPtr shEntry(do_QueryInterface(entry)); - if (shEntry) - shEntry->GetPostData(getter_AddRefs(postData)); - } - - // when saving, we first fire off a save with a nsHeaderSniffer as a progress - // listener. This allows us to look for the content-disposition header, which - // can supply a filename, and maybe has something to do with CGI-generated - // content (?) - nsCAutoString fileName(aFilename); - nsHeaderSniffer* sniffer = new nsHeaderSniffer(webPersist, tmpFile, aURI, - aDocument, postData, fileName, aBypassCache, - aFilterView, aFilterList); - if (!sniffer) - return; - webPersist->SetProgressListener(sniffer); // owned - webPersist->SaveURI(aURI, nsnull, tmpFile); -} - --(void)printDocument -{ - nsCOMPtr domWindow; - _webBrowser->GetContentDOMWindow(getter_AddRefs(domWindow)); - nsCOMPtr ir(do_QueryInterface(domWindow)); - nsCOMPtr print; - ir->GetInterface(NS_GET_IID(nsIWebBrowserPrint), getter_AddRefs(print)); - print->Print(nsnull, nsnull); -} - -- (BOOL)findInPageWithPattern:(NSString*)inText caseSensitive:(BOOL)inCaseSensitive - wrap:(BOOL)inWrap backwards:(BOOL)inBackwards -{ - PRBool found = PR_FALSE; - - nsCOMPtr wbf(do_QueryInterface(_webBrowser)); - nsCOMPtr rootWindow; - nsCOMPtr focusedWindow; - _webBrowser->GetContentDOMWindow(getter_AddRefs(rootWindow)); - wbf->GetFocusedWindow(getter_AddRefs(focusedWindow)); - if (!focusedWindow) - focusedWindow = rootWindow; - nsCOMPtr webFind(do_GetInterface(_webBrowser)); - if ( webFind ) { - nsCOMPtr framesFind(do_QueryInterface(webFind)); - framesFind->SetRootSearchFrame(rootWindow); - framesFind->SetCurrentSearchFrame(focusedWindow); - - webFind->SetMatchCase(inCaseSensitive ? PR_TRUE : PR_FALSE); - webFind->SetWrapFind(inWrap ? PR_TRUE : PR_FALSE); - webFind->SetFindBackwards(inBackwards ? PR_TRUE : PR_FALSE); - - PRUnichar* text = (PRUnichar*)nsMemory::Alloc(([inText length]+1)*sizeof(PRUnichar)); - if ( text ) { - [inText getCharacters:text]; - text[[inText length]] = 0; - webFind->SetSearchString(text); - webFind->FindNext(&found); - nsMemory::Free(text); - } - } - return found; -} - -- (void)saveURL: (NSView*)aFilterView filterList: (NSPopUpButton*)aFilterList - url: (NSString*)aURLSpec suggestedFilename: (NSString*)aFilename -{ - nsCOMPtr url; - nsresult rv = NS_NewURI(getter_AddRefs(url), [aURLSpec UTF8String]); - if (NS_FAILED(rv)) - return; - - [self saveInternal: url.get() - withDocument: nsnull - suggestedFilename: (([aFilename length] > 0) ? [aFilename fileSystemRepresentation] : "") - bypassCache: YES - filterView: aFilterView - filterList: aFilterList]; -} - --(NSString*)getFocusedURLString -{ - nsCOMPtr wbf(do_QueryInterface(_webBrowser)); - nsCOMPtr domWindow; - wbf->GetFocusedWindow(getter_AddRefs(domWindow)); - if (!domWindow) - _webBrowser->GetContentDOMWindow(getter_AddRefs(domWindow)); - if (!domWindow) - return @""; - - nsCOMPtr domDocument; - domWindow->GetDocument(getter_AddRefs(domDocument)); - if (!domDocument) - return @""; - nsCOMPtr nsDoc(do_QueryInterface(domDocument)); - if (!nsDoc) - return @""; - nsCOMPtr location; - nsDoc->GetLocation(getter_AddRefs(location)); - if (!location) - return @""; - nsAutoString urlStr; - location->GetHref(urlStr); - return [NSString stringWith_nsAString: urlStr]; -} - -- (void)saveDocument: (NSView*)aFilterView filterList: (NSPopUpButton*)aFilterList -{ - nsCOMPtr wbf(do_QueryInterface(_webBrowser)); - nsCOMPtr domWindow; - wbf->GetFocusedWindow(getter_AddRefs(domWindow)); - if (!domWindow) - _webBrowser->GetContentDOMWindow(getter_AddRefs(domWindow)); - if (!domWindow) - return; - - nsCOMPtr domDocument; - domWindow->GetDocument(getter_AddRefs(domDocument)); - if (!domDocument) - return; - nsCOMPtr nsDoc(do_QueryInterface(domDocument)); - if (!nsDoc) - return; - nsCOMPtr location; - nsDoc->GetLocation(getter_AddRefs(location)); - if (!location) - return; - nsAutoString urlStr; - location->GetHref(urlStr); - nsCAutoString urlCStr; urlCStr.AssignWithConversion(urlStr); - nsCOMPtr url; - nsresult rv = NS_NewURI(getter_AddRefs(url), urlCStr.get()); - if (NS_FAILED(rv)) - return; - - [self saveInternal: url.get() - withDocument: domDocument - suggestedFilename: "" - bypassCache: NO - filterView: aFilterView - filterList: aFilterList]; -} - --(void)doCommand:(const char*)commandName -{ - nsCOMPtr commandMgr(do_GetInterface(_webBrowser)); - if (commandMgr) { - nsCOMPtr commandParams = do_CreateInstance("@mozilla.org/embedcomp/command-params;1"); - if (commandParams) { - nsresult rv; - - nsAutoString commandNameStr; - commandNameStr.AssignWithConversion(commandName); - - rv = commandParams->SetStringValue(NS_LITERAL_STRING("cmd_name"), commandNameStr); - rv = commandMgr->DoCommand(commandParams); -#if DEBUG - if (NS_FAILED(rv)) - NSLog(@"DoCommand failed"); -#endif - } - else { -#if DEBUG - NSLog(@"Failed to make command params"); -#endif - } - } - else { -#if DEBUG - NSLog(@"No command manager"); -#endif - } -} - --(BOOL)isCommandEnabled:(const char*)commandName -{ - PRBool isEnabled = PR_FALSE; - nsCOMPtr commandMgr(do_GetInterface(_webBrowser)); - if (commandMgr) { - nsAutoString commandNameStr; - commandNameStr.AssignWithConversion(commandName); - nsresult rv = commandMgr->IsCommandEnabled(commandNameStr, &isEnabled); -#if DEBUG - if (NS_FAILED(rv)) - NSLog(@"IsCommandEnabled failed"); -#endif - } - else { -#if DEBUG - NSLog(@"No command manager"); -#endif - } - - return (isEnabled) ? YES : NO; -} - - --(IBAction)cut:(id)aSender -{ - nsCOMPtr clipboard(do_GetInterface(_webBrowser)); - clipboard->CutSelection(); -} - --(BOOL)canCut -{ - PRBool canCut = PR_FALSE; - nsCOMPtr clipboard(do_GetInterface(_webBrowser)); - clipboard->CanCutSelection(&canCut); - return canCut; -} - --(IBAction)copy:(id)aSender -{ - nsCOMPtr clipboard(do_GetInterface(_webBrowser)); - clipboard->CopySelection(); -} - --(BOOL)canCopy -{ - PRBool canCut = PR_FALSE; - nsCOMPtr clipboard(do_GetInterface(_webBrowser)); - clipboard->CanCopySelection(&canCut); - return canCut; -} - --(IBAction)paste:(id)aSender -{ - nsCOMPtr clipboard(do_GetInterface(_webBrowser)); - clipboard->Paste(); -} - --(BOOL)canPaste -{ - PRBool canCut = PR_FALSE; - nsCOMPtr clipboard(do_GetInterface(_webBrowser)); - clipboard->CanPaste(&canCut); - return canCut; -} - --(IBAction)delete:(id)aSender -{ - [self doCommand: "cmd_delete"]; -} - --(BOOL)canDelete -{ - return [self isCommandEnabled: "cmd_delete"]; -} - --(IBAction)selectAll:(id)aSender -{ - nsCOMPtr clipboard(do_GetInterface(_webBrowser)); - clipboard->SelectAll(); -} - --(IBAction)undo:(id)aSender -{ - [self doCommand: "cmd_undo"]; -} - --(IBAction)redo:(id)aSender -{ - [self doCommand: "cmd_redo"]; -} - -- (BOOL)canUndo -{ - return [self isCommandEnabled: "cmd_undo"]; -} - -- (BOOL)canRedo -{ - return [self isCommandEnabled: "cmd_redo"]; -} - --(NSString*)getCurrentURLSpec -{ - NSString* empty = @""; - nsCOMPtr domWindow; - _webBrowser->GetContentDOMWindow(getter_AddRefs(domWindow)); - if (!domWindow) - return empty; - - nsCOMPtr domDocument; - domWindow->GetDocument(getter_AddRefs(domDocument)); - if (!domDocument) - return empty; - nsCOMPtr nsDoc(do_QueryInterface(domDocument)); - if (!nsDoc) - return empty; - nsCOMPtr location; - nsDoc->GetLocation(getter_AddRefs(location)); - if (!location) - return empty; - - nsAutoString urlStr; - location->GetHref(urlStr); - return [NSString stringWith_nsAString: urlStr]; -} - -- (void)setActive: (BOOL)aIsActive -{ - nsCOMPtr wbf(do_QueryInterface(_webBrowser)); - if (aIsActive) - wbf->Activate(); - else - wbf->Deactivate(); -} - --(NSMenu*)getContextMenu -{ - if ([[self superview] conformsToProtocol:@protocol(NSBrowserContainer)]) - { - id browserContainer = [self superview]; - return [browserContainer getContextMenu]; - } - - return nil; -} - --(NSWindow*)getNativeWindow -{ - NSWindow* window = [self window]; - if (window) - return window; // We're visible. Just hand the window back. - - // We're invisible. It's likely that we're in a Cocoa tab view. - // First see if we have a cached window. - if (mWindow) - return mWindow; - - // Finally, see if our parent responds to the getNativeWindow selector, - // and if they do, let them handle it. - if ([[self superview] conformsToProtocol:@protocol(NSBrowserContainer)]) - { - id browserContainer = [self superview]; - return [browserContainer getNativeWindow]; - } - - return nil; -} - - -// -// -findEventSink:forPoint:inWindow: -// -// Given a point in window coordinates, find the Gecko event sink of the ChildView -// the point is over. This involves first converting the point to this view's -// coordinate system and using hitTest: to get the subview. Then we get -// that view's widget and QI it to an event sink -// -- (void) findEventSink:(nsIEventSink**)outSink forPoint:(NSPoint)inPoint inWindow:(NSWindow*)inWind -{ - NSPoint localPoint = [self convertPoint:inPoint fromView:[inWind contentView]]; - NSView* hitView = [self hitTest:localPoint]; - if ( [hitView conformsToProtocol:@protocol(mozView)] ) { - nsCOMPtr sink (do_QueryInterface([hitView widget])); - *outSink = sink.get(); - NS_IF_ADDREF(*outSink); - } -} - -#pragma mark - - -- (BOOL)shouldAcceptDrag:(id )sender -{ - if ([[self superview] conformsToProtocol:@protocol(NSBrowserContainer)]) - { - id browserContainer = [self superview]; - return [browserContainer shouldAcceptDragFromSource:[sender draggingSource]]; - } - return YES; -} - -- (unsigned int)draggingEntered:(id )sender -{ - if (![self shouldAcceptDrag:sender]) - return NSDragOperationNone; - -// NSLog(@"draggingEntered"); - nsCOMPtr helper(do_GetService("@mozilla.org/widget/draghelperservice;1")); - mDragHelper = helper.get(); - NS_IF_ADDREF(mDragHelper); - NS_ASSERTION ( mDragHelper, "Couldn't get a drag service, we're in big trouble" ); - - if ( mDragHelper ) { - mLastTrackedLocation = [sender draggingLocation]; - mLastTrackedWindow = [sender draggingDestinationWindow]; - nsCOMPtr sink; - [self findEventSink:getter_AddRefs(sink) forPoint:mLastTrackedLocation inWindow:mLastTrackedWindow]; - if (sink) - mDragHelper->Enter ( [sender draggingSequenceNumber], sink ); - } - - return NSDragOperationCopy; -} - -- (void)draggingExited:(id )sender -{ -// NSLog(@"draggingExited"); - if ( mDragHelper ) { - nsCOMPtr sink; - - [self findEventSink:getter_AddRefs(sink) - forPoint:mLastTrackedLocation /* [sender draggingLocation] */ - inWindow:mLastTrackedWindow /* [sender draggingDestinationWindow] */ - ]; - if (sink) - mDragHelper->Leave( [sender draggingSequenceNumber], sink ); - NS_RELEASE(mDragHelper); - } -} - -- (unsigned int)draggingUpdated:(id )sender -{ - if (![self shouldAcceptDrag:sender]) - return NSDragOperationNone; - -// NSLog(@"draggingUpdated"); - PRBool dropAllowed = PR_FALSE; - if ( mDragHelper ) { - mLastTrackedLocation = [sender draggingLocation]; - mLastTrackedWindow = [sender draggingDestinationWindow]; - nsCOMPtr sink; - [self findEventSink:getter_AddRefs(sink) forPoint:mLastTrackedLocation inWindow:mLastTrackedWindow]; - if (sink) - mDragHelper->Tracking([sender draggingSequenceNumber], sink, &dropAllowed); - } - - return dropAllowed ? NSDragOperationCopy : NSDragOperationNone; -} - -- (BOOL)prepareForDragOperation:(id )sender -{ - return YES; -} - -- (BOOL)performDragOperation:(id )sender -{ - if (![self shouldAcceptDrag:sender]) - return NO; - - PRBool dragAccepted = PR_FALSE; - - if ( mDragHelper ) { - nsCOMPtr sink; - [self findEventSink:getter_AddRefs(sink) forPoint:[sender draggingLocation] - inWindow:[sender draggingDestinationWindow]]; - if (sink) - mDragHelper->Drop([sender draggingSequenceNumber], sink, &dragAccepted); - } - - return dragAccepted ? YES : NO; -} - -#pragma mark - - --(BOOL)validateMenuItem: (NSMenuItem*)aMenuItem -{ - // update first responder items based on the selection - SEL action = [aMenuItem action]; - if (action == @selector(cut:)) - return [self canCut]; - else if (action == @selector(copy:)) - return [self canCopy]; - else if (action == @selector(paste:)) - return [self canPaste]; - else if (action == @selector(delete:)) - return [self canDelete]; - else if (action == @selector(undo:)) - return [self canUndo]; - else if (action == @selector(redo:)) - return [self canRedo]; - else if (action == @selector(selectAll:)) - return YES; - - return NO; -} - -@end diff --git a/mozilla/camino/CHBrowserWrapper.h b/mozilla/camino/CHBrowserWrapper.h deleted file mode 100644 index c50f9c2a942..00000000000 --- a/mozilla/camino/CHBrowserWrapper.h +++ /dev/null @@ -1,118 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape 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/NPL/ - * - * 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 mozilla.org 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 NPL, 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 NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#import -#import "CHBrowserView.h" - -@class BrowserWindowController; -@class ToolTip; - -@interface CHBrowserWrapper : NSView -{ - NSTextField* mUrlbar; - NSTextField* mStatus; - NSProgressIndicator* mProgress; - NSView* mProgressSuper; - BrowserWindowController* mWindowController; - NSTabViewItem* mTabItem; - NSWindow* mWindow; - - NSImage* mSiteIconImage; // current proxy icon image, which may be a site icon (favicon). - NSString* mSiteIconURI; // uri from which we loaded the site icon - - // the secure state of this browser. We need to hold it so that we can set - // the global lock icon whenever we become the primary. Value is one of - // security enums in nsIWebProgressListener. - unsigned long mSecureState; - // the title associated with this tab's url. We need to hold it so that we - // can set the window title whenever we become the primary. - NSString* mTitle; - - CHBrowserView* mBrowserView; - NSString* mDefaultStatusString; - NSString* mLoadingStatusString; - ToolTip* mToolTip; - - BOOL mIsPrimary; - BOOL mIsBusy; - BOOL mOffline; - BOOL mListenersAttached; // We hook up our click and context menu listeners lazily. - // If we never become the primary view, we don't bother creating the listeners. - BOOL mIsBookmarksImport; // This view was created for the purpose of importing bookmarks. Upon - // completion, we need to do the import and then destroy ourselves. - BOOL mActivateOnLoad; // If set, activate the browser view when loading starts. -} - -- (id)initWithTab:(NSTabViewItem*)aTab andWindow:(NSWindow*)aWindow; - -- (IBAction)load:(id)sender; -- (void)awakeFromNib; -- (void)setFrame:(NSRect)frameRect; -- (CHBrowserView*)getBrowserView; -- (BOOL)isBusy; -- (void)windowClosed; - -- (NSString*)getCurrentURLSpec; - -- (void)loadURI:(NSString *)urlSpec referrer:(NSString*)referrer flags:(unsigned int)flags activate:(BOOL)activate; -- (void)makePrimaryBrowserView: (id)aUrlbar status: (id)aStatus - progress: (id)aProgress windowController: (BrowserWindowController*)aWindowController; -- (void)disconnectView; -- (void)setTab: (NSTabViewItem*)tab; - -- (NSWindow*)getNativeWindow; -- (NSMenu*)getContextMenu; -- (void)setIsBookmarksImport:(BOOL)aIsImport; - -// NSBrowserListener messages -- (void)onLoadingStarted; -- (void)onLoadingCompleted:(BOOL)succeeded; -- (void)onProgressChange:(int)currentBytes outOf:(int)maxBytes; -- (void)onLocationChange:(NSString*)urlSpec; -- (void)onStatusChange:(NSString*)aMessage; -- (void)onSecurityStateChange:(unsigned long)newState; -- (void)onShowTooltip:(NSPoint)where withText:(NSString*)text; -- (void)onHideTooltip; - -// NSBrowserContainer messages -- (void)setStatus:(NSString *)statusString ofType:(NSStatusType)type; -- (NSString *)title; -- (void)setTitle:(NSString *)title; -- (void)sizeBrowserTo:(NSSize)dimensions; -- (CHBrowserView*)createBrowserWindow:(unsigned int)mask; - -@end diff --git a/mozilla/camino/CHBrowserWrapper.mm b/mozilla/camino/CHBrowserWrapper.mm deleted file mode 100644 index e84899836a4..00000000000 --- a/mozilla/camino/CHBrowserWrapper.mm +++ /dev/null @@ -1,692 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape 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/NPL/ - * - * 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 mozilla.org 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 NPL, 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 NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#import "NSString+Utils.h" - -#import "CHPreferenceManager.h" -#import "CHBrowserWrapper.h" -#import "BrowserWindowController.h" -#import "BookmarksService.h" -#import "SiteIconProvider.h" -#import "BrowserTabViewItem.h" -#import "ToolTip.h" -#import "CHPageProxyIcon.h" - -#include "nsCOMPtr.h" -#include "nsIServiceManager.h" -#include "nsIIOService.h" -#include "ContentClickListener.h" -#include "nsIDOMWindow.h" -#include "nsIWebBrowser.h" -#include "nsIDOMDocument.h" -#include "nsIDOMHTMLDocument.h" -#include "nsIChromeEventHandler.h" -#include "nsPIDOMWindow.h" -#include "nsIDOMEventReceiver.h" -#include "nsIPrefBranch.h" -#include "nsIPrefService.h" -#include "nsCocoaBrowserService.h" -#include "nsIWebProgressListener.h" - -#include - -#define DOCUMENT_DONE_STRING @"Document: Done" - -static const char* ioServiceContractID = "@mozilla.org/network/io-service;1"; - -const NSString* kOfflineNotificationName = @"offlineModeChanged"; - -@interface CHBrowserWrapper(Private) - -- (void)setPendingActive:(BOOL)active; -- (void)registerNotificationListener; - -- (void)setSiteIconImage:(NSImage*)inSiteIcon; -- (void)setSiteIconURI:(NSString*)inSiteIconURI; - -- (void)updateSiteIconImage:(NSImage*)inSiteIcon withURI:(NSString *)inSiteIconURI; - -@end - -@implementation CHBrowserWrapper - -- (id)initWithTab:(NSTabViewItem*)aTab andWindow:(NSWindow*)aWindow -{ - mTabItem = aTab; - mWindow = aWindow; - mIsBookmarksImport = NO; - return [self initWithFrame: NSZeroRect]; -} - -// -// initWithFrame: (designated initializer) -// -// Create a Gecko browser view and hook everything up to the UI -// -- (id)initWithFrame:(NSRect)frameRect -{ - if ( (self = [super initWithFrame: frameRect]) ) { - mBrowserView = [[[CHBrowserView alloc] initWithFrame:[self bounds] andWindow: [self getNativeWindow]] autorelease]; - [self addSubview: mBrowserView]; - [mBrowserView setContainer:self]; - [mBrowserView addListener:self]; - mIsBusy = NO; - mListenersAttached = NO; - mSecureState = nsIWebProgressListener::STATE_IS_INSECURE; - - mToolTip = [[ToolTip alloc] init]; - - //[self setSiteIconImage:[NSImage imageNamed:@"globe_ico"]]; - //[self setSiteIconURI: [NSString string]]; - - [self registerNotificationListener]; - } - return self; -} - --(void)dealloc -{ -#if DEBUG - NSLog(@"The browser wrapper died."); -#endif - - [[NSNotificationCenter defaultCenter] removeObserver: self]; - - [mSiteIconImage release]; - [mSiteIconURI release]; - [mDefaultStatusString release]; - [mLoadingStatusString release]; - [mToolTip release]; - - [super dealloc]; -} - - --(void)windowClosed -{ - // Break the cycle. - [mBrowserView destroyWebBrowser]; - [mBrowserView setContainer: nil]; - [mBrowserView removeListener: self]; -} - -- (IBAction)load:(id)sender -{ - [mBrowserView loadURI:[mUrlbar stringValue] referrer:nil flags:NSLoadFlagsNone]; -} - --(void)disconnectView -{ - mUrlbar = nil; - mStatus = nil; - mProgress = nil; - mProgressSuper = nil; - mIsPrimary = NO; - [[NSNotificationCenter defaultCenter] removeObserver:self name:kOfflineNotificationName object:nil]; - - [mBrowserView setActive: NO]; -} - --(void)setTab: (NSTabViewItem*)tab -{ - mTabItem = tab; -} - --(void)makePrimaryBrowserView: (id)aUrlbar status: (id)aStatus - progress: (id)aProgress windowController: (BrowserWindowController*)aWindowController -{ - mUrlbar = aUrlbar; - mStatus = aStatus; - mProgress = aProgress; - mProgressSuper = [aProgress superview]; - mWindowController = aWindowController; - - if (!mIsBusy) - [mProgress removeFromSuperview]; - - mDefaultStatusString = NULL; - mLoadingStatusString = DOCUMENT_DONE_STRING; - [mStatus setStringValue:mLoadingStatusString]; - - mIsPrimary = YES; - - // update the global lock icon to the current state of this browser. We need - // to do this after we set |mIsPrimary|. - [self onSecurityStateChange:mSecureState]; - - // update the window's title. - [self setTitle:mTitle]; - - if ([[self window] isKeyWindow]) - [mBrowserView setActive: YES]; - - nsCOMPtr ioService(do_GetService(ioServiceContractID)); - if (!ioService) - return; - PRBool offline = PR_FALSE; - ioService->GetOffline(&offline); - mOffline = offline; - - if (mWindowController) // Only register if we're the content area. - [[NSNotificationCenter defaultCenter] addObserver:self - selector:@selector(offlineModeChanged:) - name:kOfflineNotificationName - object:nil]; - - // Update the URL bar. - [mWindowController updateLocationFields:[self getCurrentURLSpec]]; - [mWindowController updateSiteIcons:mSiteIconImage]; - - if (mWindowController && !mListenersAttached) { - mListenersAttached = YES; - - // We need to hook up our click and context menu listeners. - ContentClickListener* clickListener = new ContentClickListener(mWindowController); - if (!clickListener) - return; - - nsCOMPtr contentWindow = getter_AddRefs([[self getBrowserView] getContentWindow]); - nsCOMPtr piWindow(do_QueryInterface(contentWindow)); - nsCOMPtr chromeHandler; - piWindow->GetChromeEventHandler(getter_AddRefs(chromeHandler)); - nsCOMPtr rec(do_QueryInterface(chromeHandler)); - rec->AddEventListenerByIID(clickListener, NS_GET_IID(nsIDOMMouseListener)); - } -} - --(NSString*)getCurrentURLSpec -{ - return [mBrowserView getCurrentURLSpec]; -} - -- (void)awakeFromNib -{ -} - -- (void)setFrame:(NSRect)frameRect -{ - [super setFrame:frameRect]; - - // Only resize our browser view if we are visible. If we're hidden, the frame - // will get reset when we get placed back into the view hierarchy anyway. This - // enhancement keeps resizing in a window with many tabs from being slow. - if ([self window]) { - NSRect bounds = [self bounds]; - [mBrowserView setFrame:bounds]; - } -} - --(BOOL)isBusy -{ - return mIsBusy; -} - -- (void)loadURI:(NSString *)urlSpec referrer:(NSString*)referrer flags:(unsigned int)flags activate:(BOOL)activate -{ - mActivateOnLoad = activate; - [mBrowserView loadURI:urlSpec referrer:referrer flags:flags]; -} - -- (void)onLoadingStarted -{ - if (mDefaultStatusString) { - [mDefaultStatusString release]; - mDefaultStatusString = NULL; - } - - [mProgressSuper addSubview:mProgress]; - [mProgress setIndeterminate:YES]; - [mProgress startAnimation:self]; - - mLoadingStatusString = NSLocalizedString(@"TabLoading", @""); - [mStatus setStringValue:mLoadingStatusString]; - - mIsBusy = YES; - [mTabItem setLabel: NSLocalizedString(@"TabLoading", @"")]; - - if (mWindowController) { - [mWindowController updateToolbarItems]; - [mWindowController startThrobber]; - } -} - -- (void)onLoadingCompleted:(BOOL)succeeded -{ - if (mActivateOnLoad) { - [mBrowserView setActive:YES]; - mActivateOnLoad = NO; - } - - [mProgress setIndeterminate:YES]; - [mProgress stopAnimation:self]; - [mProgress removeFromSuperview]; - - mLoadingStatusString = DOCUMENT_DONE_STRING; - if (mDefaultStatusString) { - [mStatus setStringValue:mDefaultStatusString]; - } - else { - [mStatus setStringValue:mLoadingStatusString]; - } - - mIsBusy = NO; - - if (mIsBookmarksImport) { - nsCOMPtr domWindow; - nsCOMPtr webBrowser = getter_AddRefs([mBrowserView getWebBrowser]); - webBrowser->GetContentDOMWindow(getter_AddRefs(domWindow)); - if (domWindow) { - nsCOMPtr domDocument; - domWindow->GetDocument(getter_AddRefs(domDocument)); - nsCOMPtr htmlDoc(do_QueryInterface(domDocument)); - if (htmlDoc) - BookmarksService::ImportBookmarks(htmlDoc); - } - [self windowClosed]; - [self removeFromSuperview]; - } - - if (mWindowController) { - [mWindowController updateToolbarItems]; - [mWindowController stopThrobber]; - } -} - -- (void)onProgressChange:(int)currentBytes outOf:(int)maxBytes -{ - if (maxBytes > 0) { - BOOL isIndeterminate = [mProgress isIndeterminate]; - if (isIndeterminate) { - [mProgress setIndeterminate:NO]; - } - double val = ((double)currentBytes / (double)maxBytes) * 100.0; - [mProgress setDoubleValue:val]; - } -} - -- (void)onLocationChange:(NSString*)urlSpec -{ - BOOL useSiteIcons = [[CHPreferenceManager sharedInstance] getBooleanPref:"browser.chrome.site_icons" withSuccess:NULL]; - BOOL siteIconLoadInitiated = NO; - - SiteIconProvider* faviconProvider = [SiteIconProvider sharedFavoriteIconProvider]; - NSString* faviconURI = [SiteIconProvider faviconLocationStringFromURI:urlSpec]; - - if (useSiteIcons && [faviconURI length] > 0) - { - // if the favicon uri has changed, fire off favicon load. When it completes, our - // imageLoadedNotification selector gets called. - if (![faviconURI isEqualToString:mSiteIconURI]) - siteIconLoadInitiated = [faviconProvider loadFavoriteIcon:self forURI:urlSpec withUserData:nil allowNetwork:YES]; - } - else - { - if ([urlSpec isEqualToString:@"about:blank"]) - faviconURI = urlSpec; - else - faviconURI = @""; - } - - if (!siteIconLoadInitiated) - [self updateSiteIconImage:nil withURI:faviconURI]; - - if (mIsPrimary) - [mWindowController updateLocationFields:urlSpec]; -} - -- (void)onStatusChange:(NSString*)aStatusString -{ - [mStatus setStringValue: aStatusString]; -} - -// -// onSecurityStateChange: -// -// Update the lock to the appropriate icon to match what necko is telling us, but -// only if we own the UI. If we're not the primary browser, we have no business -// mucking with the lock icon. -// -- (void)onSecurityStateChange:(unsigned long)newState -{ - mSecureState = newState; - if ( mIsPrimary ) - [mWindowController updateLock:newState]; -} - -- (void)setStatus:(NSString *)statusString ofType:(NSStatusType)type -{ - if (type == NSStatusTypeScriptDefault) { - if (mDefaultStatusString) { - [mDefaultStatusString release]; - } - mDefaultStatusString = statusString; - if (mDefaultStatusString) { - [mDefaultStatusString retain]; - } - } - else if (!statusString) { - if (mDefaultStatusString) { - [mStatus setStringValue:mDefaultStatusString]; - } - else { - [mStatus setStringValue:mLoadingStatusString]; - } - } - else { - [mStatus setStringValue:statusString]; - } -} - -- (NSString *)title -{ - return mTitle; -} - -- (void)setTitle:(NSString *)title -{ - [mTitle autorelease]; - - // We must be the primary content area to actually set the title, but we - // still want to hold onto the title in case we become the primary later. - NSString* newTitle = nil; - if (mOffline) { - if (title && ![title isEqualToString:@""]) - newTitle = [title stringByAppendingString: @" [Working Offline]"]; // XXX localize me - else - newTitle = [NSString stringWithString:@"Untitled [Working Offline]"]; - mTitle = [newTitle retain]; - } - else { - if (!title || [title isEqualToString:@""]) - title = [NSString stringWithString:NSLocalizedString(@"UntitledPageTitle", @"")]; - mTitle = [title retain]; - } - - if ( mIsPrimary && mWindowController ) - [[mWindowController window] setTitle:[mTitle stringByTruncatingTo:80 at:kTruncateAtEnd]]; - - // Always set the tab. - if (title && ![title isEqualToString:@""]) - [mTabItem setLabel:title]; // tab titles get truncated when setting them to tabs - else - [mTabItem setLabel:NSLocalizedString(@"UntitledPageTitle", @"")]; -} - - - -- (BOOL)isFlipped -{ - return YES; -} - -// -// onShowTooltip:where:withText -// -// Unfortunately, we can't use cocoa's apis here because they rely on setting a region -// and waiting. We already have waited and we just want to display the tooltip, so we -// drop down to the Carbon help manager routines. -// -// |where| is relative to the browser view in QD coordinates (top left is (0,0)) -// and must be converted to global QD coordinates for the carbon help manager. -// -- (void)onShowTooltip:(NSPoint)where withText:(NSString*)text -{ - NSPoint point = [[self window] convertBaseToScreen:[self convertPoint: where toView:nil]]; - [mToolTip showToolTipAtPoint: point withString: text]; -} - -- (void)onHideTooltip -{ - [mToolTip closeToolTip]; -} - -// Called when a context menu should be shown. -- (void)onShowContextMenu:(int)flags domEvent:(nsIDOMEvent*)aEvent domNode:(nsIDOMNode*)aNode -{ - [mWindowController onShowContextMenu: flags domEvent: aEvent domNode: aNode]; -} - --(NSMenu*)getContextMenu -{ - return [mWindowController getContextMenu]; -} - --(NSWindow*)getNativeWindow -{ - NSWindow* window = [self window]; - if (window) - return window; - - if (mWindow) - return mWindow; - - return nil; -} - -- (BOOL)shouldAcceptDragFromSource:(id)dragSource -{ - if ((dragSource == self) || (dragSource == mTabItem) || (dragSource == [mWindowController proxyIconView])) - return NO; - - if ([mTabItem isMemberOfClass:[BrowserTabViewItem class]] && (dragSource == [(BrowserTabViewItem*)mTabItem tabItemContentsView])) - return NO; - - return YES; -} - --(void)setIsBookmarksImport:(BOOL)aIsImport -{ - mIsBookmarksImport = aIsImport; -} - -- (void)offlineModeChanged: (NSNotification*)aNotification -{ - nsCOMPtr ioService(do_GetService(ioServiceContractID)); - if (!ioService) - return; - PRBool offline = PR_FALSE; - ioService->GetOffline(&offline); - mOffline = offline; - - if (mOffline) { - NSString* newTitle = [[[mWindowController window] title] stringByAppendingString: @" [Working Offline]"]; - [[mWindowController window] setTitle: newTitle]; - } - else { - NSArray* titleItems = [[[mWindowController window] title] componentsSeparatedByString:@" [Working Offline]"]; - [[mWindowController window] setTitle: [titleItems objectAtIndex: 0]]; - } -} - -// -// sizeBrowserTo -// -// Sizes window so that browser has dimensions given by |dimensions| -// -- (void)sizeBrowserTo:(NSSize)dimensions -{ - NSRect bounds = [self bounds]; - float dx = dimensions.width - bounds.size.width; - float dy = dimensions.height - bounds.size.height; - - NSRect frame = [[self window] frame]; - NSPoint topLeft = NSMakePoint(NSMinX(frame), NSMaxY(frame)); - frame.size.width += dx; - frame.size.height += dy; - - // if we just call setFrame, it will change the top-left corner of the - // window as it pulls the extra space from the top and right sides of the window, - // which is not at all what the website desired. We must preserve - // topleft of the window and reset it after we resize. - [[self window] setFrame:frame display:YES]; - [[self window] setFrameTopLeftPoint:topLeft]; -} - -- (CHBrowserView*)createBrowserWindow:(unsigned int)aMask -{ - nsCOMPtr pref(do_GetService("@mozilla.org/preferences-service;1")); - if (!pref) - return NS_OK; // Something bad happened if we can't get prefs. - - PRBool showBlocker; - pref->GetBoolPref("browser.popups.showPopupBlocker", &showBlocker); - - if (showBlocker) { - nsCOMPtr domWindow = getter_AddRefs([mBrowserView getContentWindow]); - nsCOMPtr piWindow(do_QueryInterface(domWindow)); - PRBool isUnrequested; - piWindow->IsLoadingOrRunningTimeout(&isUnrequested); - if (isUnrequested) { - // A popup is being opened while the page is currently loading. Offer to block the - // popup. - nsAlertController* controller = nsCocoaBrowserService::GetAlertController(); - BOOL confirm = [controller confirm: [self window] title: @"Unrequested Popup Detected" - text: [NSString stringWithFormat: NSLocalizedString(@"PopupBlockMsg", @""), NSLocalizedStringFromTable(@"CFBundleName", @"InfoPlist", nil)]]; - - // This is a one-time dialog. - pref->SetBoolPref("browser.popups.showPopupBlocker", PR_FALSE); - - if (confirm) { - pref->SetBoolPref("dom.disable_open_during_load", PR_TRUE); - pref->SetIntPref("dom.disable_open_click_delay", 1000); - } - - nsCOMPtr prefService(do_QueryInterface(pref)); - prefService->SavePrefFile(nsnull); - - if (confirm) - return nil; - } - } - - BrowserWindowController* controller = [[BrowserWindowController alloc] initWithWindowNibName: @"BrowserWindow"]; - [controller setChromeMask: aMask]; - [controller disableAutosave]; // The Web page opened this window, so we don't ever use its settings. - [controller disableLoadPage]; // don't load about:blank initially since this is a script-opened window - [controller enterModalSession]; - [[controller getBrowserWrapper] setPendingActive: YES]; - return [[controller getBrowserWrapper] getBrowserView]; -} - -- (CHBrowserView*)getBrowserView -{ - return mBrowserView; -} - -- (void)setPendingActive:(BOOL)active -{ - mActivateOnLoad = active; -} - -- (void)setSiteIconImage:(NSImage*)inSiteIcon -{ - [mSiteIconImage autorelease]; - mSiteIconImage = [inSiteIcon retain]; -} - -- (void)setSiteIconURI:(NSString*)inSiteIconURI -{ - [mSiteIconURI autorelease]; - mSiteIconURI = [inSiteIconURI retain]; -} - -// A nil inSiteIcon image indicates that we should use the default icon -// If inSiteIconURI is "about:blank", we don't show any icon -- (void)updateSiteIconImage:(NSImage*)inSiteIcon withURI:(NSString *)inSiteIconURI -{ - BOOL resetTabIcon = NO; - BOOL tabIconDraggable = YES; - - if (![mSiteIconURI isEqualToString:inSiteIconURI]) - { - if (!inSiteIcon) - { - if ([inSiteIconURI isEqualToString:@"about:blank"]) { - inSiteIcon = [NSImage imageNamed:@"smallDocument"]; - tabIconDraggable = NO; - } else - inSiteIcon = [NSImage imageNamed:@"globe_ico"]; - } - - [self setSiteIconImage: inSiteIcon]; - [self setSiteIconURI: inSiteIconURI]; - - // update the proxy icon - if (mIsPrimary) - [mWindowController updateSiteIcons:mSiteIconImage]; - - resetTabIcon = YES; - } - - // update the tab icon - if ([mTabItem isMemberOfClass:[BrowserTabViewItem class]]) - { - BrowserTabViewItem* tabItem = (BrowserTabViewItem*)mTabItem; - if (resetTabIcon || ![tabItem tabIcon]) - [tabItem setTabIcon:mSiteIconImage isDraggable:tabIconDraggable]; - } - -} - -- (void)registerNotificationListener -{ - [[NSNotificationCenter defaultCenter] addObserver: self - selector: @selector(imageLoadedNotification:) - name: SiteIconLoadNotificationName - object: self]; - -} - -// called when [[SiteIconProvider sharedFavoriteIconProvider] loadFavoriteIcon] completes -- (void)imageLoadedNotification:(NSNotification*)notification -{ - NSDictionary* userInfo = [notification userInfo]; - if (userInfo) - { - NSImage* iconImage = [userInfo objectForKey:SiteIconLoadImageKey]; - NSString* siteIconURI = [userInfo objectForKey:SiteIconLoadURIKey]; - - // NSLog(@"CHBrowserWrapper imageLoadedNotification got image %@ and uri %@", iconImage, proxyImageURI); - if (iconImage == nil) - siteIconURI = @""; // go back to default image - - [self updateSiteIconImage:iconImage withURI:siteIconURI]; - } -} - - -@end diff --git a/mozilla/camino/CHExtendedOutlineView.h b/mozilla/camino/CHExtendedOutlineView.h deleted file mode 100644 index 8b90a2820cf..00000000000 --- a/mozilla/camino/CHExtendedOutlineView.h +++ /dev/null @@ -1,50 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- -* -* 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 the Mozilla browser. -* -* The Initial Developer of the Original Code is Netscape -* Communications Corporation. Portions created by Netscape are -* Copyright (C) 2002 Netscape Communications Corporation. All -* Rights Reserved. -* -* Contributor(s): -* David Hyatt (Original Author) -* Max Horn (Context menu & tooltip code) -*/ - -#import - -@interface CHExtendedOutlineView : NSOutlineView { - SEL mDeleteAction; - - NSRect mOldFrameRect; - int mOldRows; - BOOL mDelegateTooltipStringForItem; -} - --(void)keyDown:(NSEvent*)aEvent; - --(void)setDeleteAction: (SEL)deleteAction; --(SEL)deleteAction; - --(void)setDelegate:(id)anObject; - -@end - -@interface NSObject (CHOutlineViewDataSourceToolTips) -- (NSString *)outlineView:(NSOutlineView *)outlineView tooltipStringForItem:(id)item; -@end - -@interface NSObject (CHOutlineViewContextMenus) -- (NSMenu *)outlineView:(NSOutlineView *)outlineView contextMenuForItem:(id)item; -@end diff --git a/mozilla/camino/CHExtendedOutlineView.mm b/mozilla/camino/CHExtendedOutlineView.mm deleted file mode 100644 index 6d40efb013c..00000000000 --- a/mozilla/camino/CHExtendedOutlineView.mm +++ /dev/null @@ -1,236 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- -* -* 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 the Mozilla browser. -* -* The Initial Developer of the Original Code is Netscape -* Communications Corporation. Portions created by Netscape are -* Copyright (C) 2002 Netscape Communications Corporation. All -* Rights Reserved. -* -* Contributor(s): -* David Hyatt (Original Author) -* Max Horn (Context menu & tooltip code) -*/ - -#import "CHExtendedOutlineView.h" - -@interface CHExtendedOutlineView (Private) -- (void)_updateToolTipRect; -@end - -@implementation CHExtendedOutlineView - -- (id)initWithFrame:(NSRect)frame -{ - if ( (self = [super initWithFrame:frame]) ) { - mDeleteAction = 0; - // FIXME - this method is *never* called for items that are archived in a nib! - // Luckily, object memory is zeroed, so mDeleteAction will be 0 anyway. - // I recommend that this method just be removed. - } - return self; -} - -- (void)awakeFromNib { - // Setup the initial NSToolTipRects - [self _updateToolTipRect]; -} - --(void)setDeleteAction: (SEL)aDeleteAction -{ - mDeleteAction = aDeleteAction; -} - --(SEL)deleteAction -{ - return mDeleteAction; -} - --(void)setDelegate:(id)anObject -{ - [super setDelegate:anObject]; - mDelegateTooltipStringForItem = [anObject respondsToSelector:@selector(outlineView:tooltipStringForItem:)]; -} - - --(void)keyDown:(NSEvent*)aEvent -{ - // check each char in the event array. it should be just 1 char, but - // just in case we use a loop. - int len = [[aEvent characters] length]; - for ( int i = 0; i < len; ++i ) { - unichar c = [[aEvent characters] characterAtIndex:i]; - - // Check for a certain set of special keys. - - if (c == NSDeleteCharacter || c == NSBackspaceCharacter) { - // delete the bookmark - if (mDeleteAction) - [NSApp sendAction: mDeleteAction to: [self target] from: self]; - return; - } - else if (c == NSCarriageReturnCharacter) { - // Start editing - if ([self numberOfSelectedRows] == 1) { - [self editColumn:0 row:[self selectedRow] withEvent:aEvent select:YES]; - return; - } - } - else if (c == NSLeftArrowFunctionKey || c == NSRightArrowFunctionKey) - { - BOOL expand = (c == NSRightArrowFunctionKey); - if ([self numberOfSelectedRows] == 1) { - int index = [self selectedRow]; - if (index == -1) - return; - - id item = [self itemAtRow: index]; - if (!item) - return; - - if (![self isExpandable: item]) - return; - - if (![self isItemExpanded: item] && expand) - [self expandItem: item]; - else if ([self isItemExpanded: item] && !expand) - [self collapseItem: item]; - } - } - } // foreach character - - return [super keyDown: aEvent]; -} - -/* - * Intercept changes to the window frame so we can update our tooltip rects - */ -- (void)setFrameOrigin:(NSPoint)newOrigin; -{ - [super setFrameOrigin:newOrigin]; - [self _updateToolTipRect]; -} - -- (void)setFrameSize:(NSSize)newSize; -{ - [super setFrameSize:newSize]; - [self _updateToolTipRect]; -} - -- (void)setFrame:(NSRect)frameRect -{ - [super setFrame:frameRect]; - [self _updateToolTipRect]; -} - -/* - * Implement the informal NSToolTipOwner protocol to allow tooltips - * on a per-item level. - */ -- (NSString *)view:(NSView *)view stringForToolTip:(NSToolTipTag)tag point:(NSPoint)point userData:(void *)data -{ - NSString *result = nil; - int rowIndex = [self rowAtPoint:point]; - if (rowIndex >= 0) { - id delegate = [self delegate]; - id item = [self itemAtRow:rowIndex]; - - if (item && mDelegateTooltipStringForItem) - result = [delegate outlineView:self tooltipStringForItem:item]; - } - return result; -} - -/* - * Return a context menu depending on which item was clicked. - */ -- (NSMenu *)menuForEvent:(NSEvent *)theEvent -{ - id item; - int rowIndex; - NSPoint point; - - point = [self convertPoint:[theEvent locationInWindow] fromView:nil]; - rowIndex = [self rowAtPoint:point]; - - if (rowIndex >= 0) { - // There seems to be a bug in AppKit; selectRow is supposed to - // abort editing, but it doesn't, thus we do it manually. - [self abortEditing]; - - item = [self itemAtRow:rowIndex]; - if (item) { - id delegate = [self delegate]; - - // If the item was not selected, select it now - if (![self isRowSelected:rowIndex]) { - if (![delegate respondsToSelector:@selector(outlineView:shouldSelectItem:)] - || [delegate outlineView:self shouldSelectItem:item]) - [self selectRow:rowIndex byExtendingSelection:NO]; - } - - if ([delegate respondsToSelector:@selector(outlineView:contextMenuForItem:)]) - return [delegate outlineView:self contextMenuForItem:item]; - } - } - - // Just return the default context menu - return [self menu]; -} - -@end - - -@implementation CHExtendedOutlineView (Private) - -/* - * Set up tooltip rects for every row, but only if the frame size or - * the number of rows changed since the last invocation. - */ -- (void)_updateToolTipRect -{ - static NSRect oldFrameRect; - static int oldRows = 0; - NSRect frameRect; - int rows; - - // Only set tooltip rects if the delegate implements outlineView:tooltipStringForItem: - if (!mDelegateTooltipStringForItem) - return; - - frameRect = [self frame]; - rows = [self numberOfRows]; - - // Check if rows or frame changed - if (rows != oldRows || !NSEqualRects(oldFrameRect, frameRect)) - { - int i; - NSRect rect; - - // Remove all old NSToolTipRects - [self removeAllToolTips]; - - // Add a NSToolTipRect for each row - for (i = 0; i < rows; ++i) - { - rect = [self rectOfRow:i]; - [self addToolTipRect:rect owner:self userData:NULL]; - } - } - - // Save the current values - oldRows = rows; - oldFrameRect = frameRect; -} - -@end diff --git a/mozilla/camino/CHFind.h b/mozilla/camino/CHFind.h deleted file mode 100644 index 588a815c0c5..00000000000 --- a/mozilla/camino/CHFind.h +++ /dev/null @@ -1,38 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- -* -* 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 the Mozilla browser. -* -* The Initial Developer of the Original Code is Netscape -* Communications Corporation. Portions created by Netscape are -* Copyright (C) 2002 Netscape Communications Corporation. All -* Rights Reserved. -* -* Contributor(s): -* Mike Pinkerton (Original Author) -*/ - -#import - -// -// protocol CHFind -// -// Any window who wants to be able to work with the Find dialog should implement -// this protocol. -// - -@protocol CHFind - -- (BOOL)findInPageWithPattern:(NSString*)text caseSensitive:(BOOL)inCaseSensitive - wrap:(BOOL)inWrap backwards:(BOOL)inBackwards; - -@end diff --git a/mozilla/camino/CHGeckoUtils.h b/mozilla/camino/CHGeckoUtils.h deleted file mode 100644 index dfa225a2ff0..00000000000 --- a/mozilla/camino/CHGeckoUtils.h +++ /dev/null @@ -1,179 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape 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/NPL/ - * - * 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 mozilla.org 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 NPL, 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 NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef __GeckoUtils_h__ -#define __GeckoUtils_h__ - -#include "nsIDOMHTMLAnchorElement.h" -#include "nsIDOMHTMLAreaElement.h" -#include "nsIDOMHTMLLinkElement.h" -#include "nsIDOMHTMLImageElement.h" -#include "nsIDOMCharacterData.h" - -class CHGeckoUtils -{ -public: - static void GatherTextUnder(nsIDOMNode* aNode, nsString& aResult) { - nsAutoString text; - nsCOMPtr node; - aNode->GetFirstChild(getter_AddRefs(node)); - PRUint32 depth = 1; - while (node && depth) { - nsCOMPtr charData(do_QueryInterface(node)); - PRUint16 nodeType; - node->GetNodeType(&nodeType); - if (charData && nodeType == nsIDOMNode::TEXT_NODE) { - // Add this text to our collection. - text += NS_LITERAL_STRING(" "); - nsAutoString data; - charData->GetData(data); - text += data; - } - else { - nsCOMPtr img(do_QueryInterface(node)); - if (img) { - nsAutoString altText; - img->GetAlt(altText); - if (!altText.IsEmpty()) { - text = altText; - break; - } - } - } - - // Find the next node to test. - PRBool hasChildNodes; - node->HasChildNodes(&hasChildNodes); - if (hasChildNodes) { - nsCOMPtr temp = node; - temp->GetFirstChild(getter_AddRefs(node)); - depth++; - } - else { - nsCOMPtr nextSibling; - node->GetNextSibling(getter_AddRefs(nextSibling)); - if (nextSibling) - node = nextSibling; - else { - nsCOMPtr parentNode; - node->GetParentNode(getter_AddRefs(parentNode)); - if (!parentNode) - node = nsnull; - else { - nsCOMPtr nextSibling; - parentNode->GetNextSibling(getter_AddRefs(nextSibling)); - node = nextSibling; - depth--; - } - } - } - } - - text.CompressWhitespace(); - aResult = text; - }; - - static void GetEnclosingLinkElementAndHref(nsIDOMNode* aNode, nsIDOMElement** aLinkContent, nsString& aHref) - { - nsCOMPtr content(do_QueryInterface(aNode)); - nsAutoString localName; - if (content) - content->GetLocalName(localName); - - nsCOMPtr linkContent; - ToLowerCase(localName); - nsAutoString href; - if (localName.Equals(NS_LITERAL_STRING("a")) || - localName.Equals(NS_LITERAL_STRING("area")) || - localName.Equals(NS_LITERAL_STRING("link"))) { - PRBool hasAttr; - content->HasAttribute(NS_LITERAL_STRING("href"), &hasAttr); - if (hasAttr) { - linkContent = content; - nsCOMPtr anchor(do_QueryInterface(linkContent)); - if (anchor) - anchor->GetHref(href); - else { - nsCOMPtr area(do_QueryInterface(linkContent)); - if (area) - area->GetHref(href); - else { - nsCOMPtr link(do_QueryInterface(linkContent)); - if (link) - link->GetHref(href); - } - } - } - } - else { - nsCOMPtr curr = aNode; - nsCOMPtr temp = curr; - temp->GetParentNode(getter_AddRefs(curr)); - while (curr) { - content = do_QueryInterface(curr); - if (!content) - break; - content->GetLocalName(localName); - ToLowerCase(localName); - if (localName.Equals(NS_LITERAL_STRING("a"))) { - PRBool hasAttr; - content->HasAttribute(NS_LITERAL_STRING("href"), &hasAttr); - if (hasAttr) { - linkContent = content; - nsCOMPtr anchor(do_QueryInterface(linkContent)); - if (anchor) - anchor->GetHref(href); - } - else - linkContent = nsnull; // Links can't be nested. - break; - } - - temp = curr; - temp->GetParentNode(getter_AddRefs(curr)); - } - } - - *aLinkContent = linkContent; - NS_IF_ADDREF(*aLinkContent); - - aHref = href; - } -}; - - -#endif diff --git a/mozilla/camino/CHGetURLCommand.h b/mozilla/camino/CHGetURLCommand.h deleted file mode 100644 index b5f907bfcb2..00000000000 --- a/mozilla/camino/CHGetURLCommand.h +++ /dev/null @@ -1,30 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- -* -* 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 the Mozilla browser. -* -* The Initial Developer of the Original Code is Netscape -* Communications Corporation. Portions created by Netscape are -* Copyright (C) 2002 Netscape Communications Corporation. All -* Rights Reserved. -* -* Contributor(s): -* David Hyatt (Original Author) -*/ - -#import - -@interface CHGetURLCommand : NSScriptCommand {} - -- (id)performDefaultImplementation; - -@end diff --git a/mozilla/camino/CHGetURLCommand.mm b/mozilla/camino/CHGetURLCommand.mm deleted file mode 100644 index 6c4558ea2fb..00000000000 --- a/mozilla/camino/CHGetURLCommand.mm +++ /dev/null @@ -1,37 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- -* -* 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 the Mozilla browser. -* -* The Initial Developer of the Original Code is Netscape -* Communications Corporation. Portions created by Netscape are -* Copyright (C) 1999 Netscape Communications Corporation. All -* Rights Reserved. -* -* Contributor(s): -* David Hyatt (Original Author) -*/ - -#import "CHGetURLCommand.h" -#import - -#import "MainController.h" - -@implementation CHGetURLCommand - -- (id)performDefaultImplementation -{ - [(MainController*)[NSApp delegate] openNewWindowOrTabWithURL:[self directParameter] andReferrer:nil]; - return nil; -} - -@end diff --git a/mozilla/camino/CHGoMenu.h b/mozilla/camino/CHGoMenu.h deleted file mode 100644 index 17e614302d8..00000000000 --- a/mozilla/camino/CHGoMenu.h +++ /dev/null @@ -1,36 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- -* -* 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 the Mozilla browser. -* -* The Initial Developer of the Original Code is Netscape -* Communications Corporation. Portions created by Netscape are -* Copyright (C) 2002 Netscape Communications Corporation. All -* Rights Reserved. -* -* Contributor(s): -* Joe Hewitt (Original Author) -*/ - -#import - -@interface CHGoMenu : NSMenu { - -} - -- (void) emptyHistoryItems; -- (void) addHistoryItems; - -// NSMenu -- (void) update; - -@end diff --git a/mozilla/camino/CHGoMenu.mm b/mozilla/camino/CHGoMenu.mm deleted file mode 100644 index e160c8dd15e..00000000000 --- a/mozilla/camino/CHGoMenu.mm +++ /dev/null @@ -1,144 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- -* -* 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 the Mozilla browser. -* -* The Initial Developer of the Original Code is Netscape -* Communications Corporation. Portions created by Netscape are -* Copyright (C) 2002 Netscape Communications Corporation. All -* Rights Reserved. -* -* Contributor(s): -* Joe Hewitt (Original Author) -*/ - -#import "NSString+Utils.h" - -#import "CHGoMenu.h" -#import "MainController.h" -#import "BrowserWindowController.h" -#import "CHBrowserWrapper.h" -#import "CHBrowserView.h" -#include "nsCOMPtr.h" -#include "nsString.h" -#include "nsIWebBrowser.h" -#include "nsISHistory.h" -#include "nsIWebNavigation.h" -#include "nsIHistoryEntry.h" -#include "nsCRT.h" - -// the tag of the separator after which to insert history menu items -static const int kDividerTag = 4000; -// the maximum number of history entry menuitems to display -static const int kMaxItems = 15; -// the maximum number of characters in a menu title before cropping it -static const unsigned int kMaxTitleLength = 80; - -@implementation CHGoMenu - -- (void) update -{ - [self emptyHistoryItems]; - [self addHistoryItems]; - - [super update]; -} - -- (nsIWebNavigation*) currentWebNavigation -{ - // get controller for current window - BrowserWindowController *controller = [(MainController *)[NSApp delegate] getMainWindowBrowserController]; - if (!controller) return nsnull; - - // get web navigation for current browser - CHBrowserWrapper* wrapper = [controller getBrowserWrapper]; - if (!wrapper) return nsnull; - CHBrowserView* view = [wrapper getBrowserView]; - if (!view) return nsnull; - nsCOMPtr webBrowser = [view getWebBrowser]; - if (!webBrowser) return nsnull; - nsCOMPtr webNav(do_QueryInterface(webBrowser)); - return webNav.get(); -} - -- (void) historyItemAction:(id)sender -{ - // get web navigation for current browser - nsCOMPtr webNav = [self currentWebNavigation]; - if (!webNav) return; - - // browse to the history entry for the menuitem that was selected - PRInt32 historyIndex = ([sender tag] - 1) - kDividerTag; - webNav->GotoIndex(historyIndex); -} - -- (void) emptyHistoryItems -{ - // remove every history item after the insertion point - int insertionIndex = [self indexOfItemWithTag:kDividerTag]; - for (int i = [self numberOfItems]-1; i > insertionIndex ; --i) { - [self removeItemAtIndex:i]; - } -} - -- (void) addHistoryItems -{ - // get session history for current browser - nsCOMPtr webNav = [self currentWebNavigation]; - if (!webNav) return; - nsCOMPtr sessionHistory; - webNav->GetSessionHistory(getter_AddRefs(sessionHistory)); - - PRInt32 count; - sessionHistory->GetCount(&count); - PRInt32 currentIndex; - sessionHistory->GetIndex(¤tIndex); - - // determine the range of items to display - int rangeStart, rangeEnd; - int above = kMaxItems/2; - int below = (kMaxItems-above)-1; - if (count <= kMaxItems) { - // if the whole history fits within our menu, fit range to show all - rangeStart = count-1; - rangeEnd = 0; - } else { - // if the whole history is too large for menu, try to put current index as close to - // the middle of the list as possible, so the user can see both back and forward in session - rangeStart = currentIndex + above; - rangeEnd = currentIndex - below; - if (rangeStart >= count-1) { - rangeEnd -= (rangeStart-count)+1; // shift overflow to the end - rangeStart = count-1; - } else if (rangeEnd < 0) { - rangeStart -= rangeEnd; // shift overflow to the start - rangeEnd = 0; - } - } - - // create a new menu item for each history entry (up to MAX_MENUITEM entries) - for (PRInt32 i = rangeStart; i >= rangeEnd; --i) { - nsCOMPtr entry; - sessionHistory->GetEntryAtIndex(i, PR_FALSE, getter_AddRefs(entry)); - - nsXPIDLString textStr; - entry->GetTitle(getter_Copies(textStr)); - NSString* title = [[NSString stringWith_nsAString: textStr] stringByTruncatingTo:kMaxTitleLength at:kTruncateAtMiddle]; - NSMenuItem *newItem = [self addItemWithTitle:title action:@selector(historyItemAction:) keyEquivalent:@""]; - [newItem setTarget:self]; - [newItem setTag:kDividerTag+1+i]; - if (currentIndex == i) - [newItem setState:NSOnState]; - } -} - -@end diff --git a/mozilla/camino/CHHistoryDataSource.h b/mozilla/camino/CHHistoryDataSource.h deleted file mode 100644 index cb2259e98bd..00000000000 --- a/mozilla/camino/CHHistoryDataSource.h +++ /dev/null @@ -1,24 +0,0 @@ -// -// CHHistoryDataSource.h -// Chimera -// -// Created by Ben Goodger on Sun Apr 28 2002. -// Copyright (c) 2001 __MyCompanyName__. All rights reserved. -// - -#import - -#import "CHRDFOutlineViewDataSource.h" - -@class BrowserWindowController; - -@interface CHHistoryDataSource : CHRDFOutlineViewDataSource -{ - - IBOutlet BrowserWindowController* mBrowserWindowController; - -} - --(IBAction)openHistoryItem: (id)aSender; - -@end diff --git a/mozilla/camino/CHHistoryDataSource.mm b/mozilla/camino/CHHistoryDataSource.mm deleted file mode 100644 index 932676ef92d..00000000000 --- a/mozilla/camino/CHHistoryDataSource.mm +++ /dev/null @@ -1,160 +0,0 @@ -// -// CHHistoryDataSource.mm -// Chimera -// -// Created by Ben Goodger on Sun Apr 28 2002. -// Copyright (c) 2001 __MyCompanyName__. All rights reserved. -// - -#import "NSString+Utils.h" - -#import "BrowserWindowController.h" -#import "CHHistoryDataSource.h" -#import "CHBrowserView.h" - -#include "nsIRDFService.h" -#include "nsIRDFDataSource.h" -#include "nsIRDFResource.h" - -#include "nsXPIDLString.h" -#include "nsString.h" - -#include "nsComponentManagerUtils.h" - -@implementation CHHistoryDataSource - -- (void) ensureDataSourceLoaded -{ - [super ensureDataSourceLoaded]; - - if (!mDataSource) - { - // Get the Global History DataSource - mRDFService->GetDataSource("rdf:history", &mDataSource); - // Get the Date Folder Root - mRDFService->GetResource("NC:HistoryByDate", &mRootResource); - - [mOutlineView setTarget: self]; - [mOutlineView setDoubleAction: @selector(openHistoryItem:)]; - - [mOutlineView reloadData]; - } -} - -- (id) outlineView: (NSOutlineView*) aOutlineView objectValueForTableColumn: (NSTableColumn*) aTableColumn - byItem: (id) aItem -{ - NSMutableAttributedString *cellValue = [[NSMutableAttributedString alloc] init]; - - if (!mDataSource || !aItem) - return nil; - - // The table column's identifier is the RDF Resource URI of the property being displayed in - // that column, e.g. "http://home.netscape.com/NC-rdf#Name" - NSString* columnPropertyURI = [aTableColumn identifier]; - - nsCOMPtr propertyResource; - mRDFService->GetResource([columnPropertyURI UTF8String], getter_AddRefs(propertyResource)); - - nsCOMPtr resource = dont_AddRef([aItem resource]); - - nsCOMPtr valueNode; - mDataSource->GetTarget(resource, propertyResource, PR_TRUE, getter_AddRefs(valueNode)); - if (!valueNode) { -#if DEBUG - NSLog(@"ValueNode is null in objectValueForTableColumn"); -#endif - return nil; - } - - nsCOMPtr valueLiteral(do_QueryInterface(valueNode)); - if (!valueLiteral) - return nil; - - nsXPIDLString literalValue; - valueLiteral->GetValue(getter_Copies(literalValue)); - - //Set cell's textual contents - [cellValue replaceCharactersInRange:NSMakeRange(0, [cellValue length]) withString:[NSString stringWith_nsAString:literalValue]]; - - if ([columnPropertyURI isEqualToString: @"http://home.netscape.com/NC-rdf#Name"]) - { - NSMutableAttributedString *attachmentAttrString = nil; - NSFileWrapper *fileWrapper = [[NSFileWrapper alloc] initRegularFileWithContents:nil]; - NSTextAttachment *textAttachment = [[NSTextAttachment alloc] initWithFileWrapper:fileWrapper]; - NSCell *attachmentAttrStringCell; - - //Create an attributed string to hold the empty attachment, then release the components. - attachmentAttrString = [[NSMutableAttributedString attributedStringWithAttachment:textAttachment] retain]; - [textAttachment release]; - [fileWrapper release]; - - //Get the cell of the text attachment. - attachmentAttrStringCell = (NSCell *)[(NSTextAttachment *)[attachmentAttrString attribute: - NSAttachmentAttributeName atIndex:0 effectiveRange:nil] attachmentCell]; - - if ([self outlineView:mOutlineView isItemExpandable:aItem]) { - [attachmentAttrStringCell setImage:[NSImage imageNamed:@"folder"]]; - } - else - [attachmentAttrStringCell setImage:[NSImage imageNamed:@"smallbookmark"]]; - - //Insert the image - [cellValue replaceCharactersInRange:NSMakeRange(0, 0) withAttributedString:attachmentAttrString]; - - //Tweak the baseline to vertically center the text. - [cellValue addAttribute:NSBaselineOffsetAttributeName - value:[NSNumber numberWithFloat:-5.0] - range:NSMakeRange(0, 1)]; - } - - return cellValue; -} - --(IBAction)openHistoryItem: (id)aSender -{ - int index = [mOutlineView selectedRow]; - if (index == -1) - return; - - id item = [mOutlineView itemAtRow: index]; - if (!item) - return; - - // expand if collapsed and double click - if ([mOutlineView isExpandable: item]) { - if ([mOutlineView isItemExpanded: item]) - [mOutlineView collapseItem: item]; - else - [mOutlineView expandItem: item]; - - return; - } - - // get uri - nsCOMPtr propertyResource; - mRDFService->GetResource("http://home.netscape.com/NC-rdf#URL", getter_AddRefs(propertyResource)); - - nsCOMPtr resource = dont_AddRef([item resource]); - - nsCOMPtr valueNode; - mDataSource->GetTarget(resource, propertyResource, PR_TRUE, getter_AddRefs(valueNode)); - if (!valueNode) { -#if DEBUG - NSLog(@"ValueNode is null in openHistoryItem"); -#endif - return; - } - - nsCOMPtr valueLiteral(do_QueryInterface(valueNode)); - if (!valueLiteral) - return; - - nsXPIDLString literalValue; - valueLiteral->GetValue(getter_Copies(literalValue)); - - NSString* url = [NSString stringWith_nsAString: literalValue]; - [[mBrowserWindowController getBrowserWrapper] loadURI: url referrer: nil flags: NSLoadFlagsNone activate:YES]; -} - -@end diff --git a/mozilla/camino/CHIconTabViewItem.h b/mozilla/camino/CHIconTabViewItem.h deleted file mode 100644 index f56f0635483..00000000000 --- a/mozilla/camino/CHIconTabViewItem.h +++ /dev/null @@ -1,58 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** -* Version: NPL 1.1/GPL 2.0/LGPL 2.1 -* -* The contents of this file are subject to the Netscape 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/NPL/ -* -* 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 mozilla.org 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. -* Portions are Copyright (C) 2002 nibfile.com -* -* Contributor(s): -* Matt Judy (Original Author) -* David Haas -* -* 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 NPL, 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 NPL, the GPL or the LGPL. -* -* ***** END LICENSE BLOCK ***** */ - -#import - -@interface CHIconTabViewItem : NSTabViewItem -{ - NSImage *mTabIcon; - NSDictionary *mLabelAttributes; - NSString *mLabelString; - NSMutableString *mTruncLabelString; - int mLabelStringWidth; -} - -// The designated initializer --(id)initWithIdentifier:(id)identifier withTabIcon:(NSImage *)tabIcon; - --(NSImage *)tabIcon; --(void)setTabIcon:(NSImage *)newIcon; - -@end diff --git a/mozilla/camino/CHIconTabViewItem.mm b/mozilla/camino/CHIconTabViewItem.mm deleted file mode 100644 index dc58171d306..00000000000 --- a/mozilla/camino/CHIconTabViewItem.mm +++ /dev/null @@ -1,202 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** -* Version: NPL 1.1/GPL 2.0/LGPL 2.1 -* -* The contents of this file are subject to the Netscape 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/NPL/ -* -* 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 mozilla.org 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. -* Portions are Copyright (C) 2002 nibfile.com. -* -* Contributor(s): -* Matt Judy (Original Author) -* David Haas -* Simon Fraser -* -* 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 NPL, 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 NPL, the GPL or the LGPL. -* -* ***** END LICENSE BLOCK ***** */ - -#import "NSString+Utils.h" - -#import "CHIconTabViewItem.h" -#import "NSString+Utils.h" - -// -// NSParagraphStyle has a line break mode which will automatically -// append ellipses to the end of a string. Unfortunately, as of -// OS X 10.1.5, the header says it doesn't work yet. -// -#define BROKEN_NSLineBreakByTruncatingMiddle - -static const int kMinTabsForSpacing = 4; // with 1-4 tabs, each tab is 1/4 the tab view width - -@interface CHIconTabViewItem(Private) -- (void)setupLabelAttributes; -@end; - -@implementation CHIconTabViewItem - --(id)initWithIdentifier:(id)identifier withTabIcon:(NSImage *)tabIcon -{ - if ( (self = [super initWithIdentifier:identifier]) ) { - [self setTabIcon:tabIcon]; - [self setupLabelAttributes]; - mLabelString = @""; - mLabelStringWidth = -1; - } - return self; -} - --(id)initWithIdentifier:(id)identifier -{ - return [self initWithIdentifier:identifier withTabIcon:nil]; -} - --(void)dealloc -{ - [mTabIcon release]; - [mLabelAttributes release]; - [mTruncLabelString release]; - [super dealloc]; -} - - -- (void)setupLabelAttributes -{ - NSMutableParagraphStyle *labelParagraphStyle = [[NSMutableParagraphStyle alloc] init]; - [labelParagraphStyle setParagraphStyle:[NSParagraphStyle defaultParagraphStyle]]; - -#ifdef BROKEN_NSLineBreakByTruncatingMiddle - [labelParagraphStyle setLineBreakMode:NSLineBreakByClipping]; -#else - [labelParagraphStyle setLineBreakMode:NSLineBreakByTruncatingMiddle]; -#endif - - [labelParagraphStyle setAlignment:NSNaturalTextAlignment]; - - NSFont *labelFont = [NSFont systemFontOfSize:[NSFont smallSystemFontSize]]; - mLabelAttributes = [[NSDictionary alloc] initWithObjectsAndKeys: - labelFont, NSFontAttributeName, - labelParagraphStyle, NSParagraphStyleAttributeName, - nil]; - - [labelParagraphStyle release]; -} - - -- (NSSize)sizeOfLabel:(BOOL)shouldTruncateLabel -{ - int numTabs; - float theWidth = 0; - - //if we've got text, size for # of tabs & amount of text. - // Accounts for icon size, if one present. - if ([mLabelString length] > 0) { - numTabs = [[self tabView] numberOfTabViewItems]; - if (numTabs < kMinTabsForSpacing) - numTabs = kMinTabsForSpacing; - theWidth = NSWidth([[self tabView] frame]) / numTabs - 16.0; // 16 works - don't know why. Maybe 8px on each side of the label? - if (shouldTruncateLabel) { - //I have really no clue what this is for. - //it only gets set YES when the tabs have - //reached the edge of the screen area. - //I don't see any difference in behavior between putting - //in -10 or -600 here. But -1 instead of -10 makes the - //tabs go off screen. - theWidth -= 16.0; - } - } - // If we don't have text, but DO have an icon, we'll have size 15. - else if ([self tabIcon]) - theWidth = 15.0; - - return NSMakeSize(theWidth, 15.0); // ugh, hard-coded height. - // This doesn't seem to affect, the height, only the rect pass to - // drawLabel. -} - --(void)drawLabel:(BOOL)shouldTruncateLabel inRect:(NSRect)tabRect -{ - if ([self tabIcon]) { - NSPoint drawPoint = NSMakePoint( (tabRect.origin.x), (tabRect.origin.y + 15.0) ); - [[self tabIcon] compositeToPoint:drawPoint operation:NSCompositeSourceOver]; - tabRect = NSMakeRect(NSMinX(tabRect) + 18.0, - NSMinY(tabRect), - NSWidth(tabRect) - 18.0, - NSHeight(tabRect)); - } - - // Check if we have to rebuild the cached label string - either because the - // size changed, or the label changed, or because we never set the label before. - int width = NSWidth(tabRect); - if (mLabelStringWidth != width || !mTruncLabelString) { - [mTruncLabelString release]; - mTruncLabelString = [[NSMutableString alloc] initWithString:mLabelString]; - mLabelStringWidth = width; - -#ifdef BROKEN_NSLineBreakByTruncatingMiddle - // Do our own truncating until Apple implements LineBreakByTruncatingTail/Middle. - // Then we can remove this code. - [mTruncLabelString truncateToWidth:width at:kTruncateAtEnd withAttributes:mLabelAttributes]; -#endif - } - - [mTruncLabelString drawInRect:tabRect withAttributes:mLabelAttributes]; -} - --(NSImage *)tabIcon -{ - return mTabIcon; -} - --(void)setTabIcon:(NSImage *)newIcon -{ - [mTabIcon autorelease]; - mTabIcon = [newIcon copy]; -} - -- (void)setLabel:(NSString *)label -{ - // We use our complete own label storage, since for some reasons NSTabViewItem - // will start to slow us down a *lot* if the label becomes very long - // (even though we don't use the original drawing/size code at all). - if (![label isEqual:mLabelString]) { - [mLabelString release]; - mLabelString = [label copy]; - mLabelStringWidth = -1; - - // we need to call setLabel on super to make some stuff happen, but the string - // doesn't matter. - [super setLabel:@"foo"]; - } -} - -- (NSString *)label -{ - return mLabelString; -} - -@end diff --git a/mozilla/camino/CHImageAdditions.h b/mozilla/camino/CHImageAdditions.h deleted file mode 100644 index 54c5e8cd1a5..00000000000 --- a/mozilla/camino/CHImageAdditions.h +++ /dev/null @@ -1,7 +0,0 @@ -#import - -@interface NSImage (CHImageAdditions) -- (void) drawFlippedInRect:(NSRect) rect operation:(NSCompositingOperation) op fraction:(float) delta; -- (void) drawFlippedInRect:(NSRect) rect operation:(NSCompositingOperation) op; -- (void)applyBadge:(NSImage*)badge withAlpha:(float)alpha scale:(float)scale; -@end diff --git a/mozilla/camino/CHImageAdditions.m b/mozilla/camino/CHImageAdditions.m deleted file mode 100644 index 81362fda06e..00000000000 --- a/mozilla/camino/CHImageAdditions.m +++ /dev/null @@ -1,36 +0,0 @@ -#import "CHImageAdditions.h" -#import - -@implementation NSImage (CHImageAdditions) -- (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)applyBadge:(NSImage*)badge withAlpha:(float)alpha scale:(float)scale -{ - if (!badge) - return; - - [badge setScalesWhenResized:YES]; - [badge setSize:NSMakeSize([self size].width * scale,[self size].height * scale)]; - - [self lockFocus]; - [[NSGraphicsContext currentContext] setImageInterpolation:NSImageInterpolationHigh]; - [badge dissolveToPoint:NSMakePoint([self size].width - [badge size].width,0) fraction:alpha]; - [self unlockFocus]; -} - -@end diff --git a/mozilla/camino/CHLocationBar.h b/mozilla/camino/CHLocationBar.h deleted file mode 100644 index f2700e473f6..00000000000 --- a/mozilla/camino/CHLocationBar.h +++ /dev/null @@ -1,30 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- -* -* 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 the Mozilla browser. -* -* The Initial Developer of the Original Code is Netscape -* Communications Corporation. Portions created by Netscape are -* Copyright (C) 2002 Netscape Communications Corporation. All -* Rights Reserved. -* -* Contributor(s): -* David Hyatt (Original Author) -*/ - -#import - -@interface CHLocationBar : NSView { - -} - -@end diff --git a/mozilla/camino/CHLocationBar.mm b/mozilla/camino/CHLocationBar.mm deleted file mode 100644 index 6056d1c7977..00000000000 --- a/mozilla/camino/CHLocationBar.mm +++ /dev/null @@ -1,55 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** -* Version: NPL 1.1/GPL 2.0/LGPL 2.1 -* -* The contents of this file are subject to the Netscape 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/NPL/ -* -* 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 mozilla.org 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): -* David Hyatt (Original Author) -* -* 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 NPL, 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 NPL, the GPL or the LGPL. -* -* ***** END LICENSE BLOCK ***** */ - -#import "CHLocationBar.h" - -@implementation CHLocationBar - -- (void)drawRect:(NSRect)aRect { - // Frame the border. - //NSDrawLightBezel([self bounds], aRect); - - [[NSColor colorWithCalibratedWhite: 0.98 alpha: 1.0] set]; - NSRectFill(aRect); - - [[NSColor colorWithCalibratedWhite: 0.90 alpha: 1.0] set]; - NSFrameRectWithWidth([self bounds], 2.0); -} - - -@end diff --git a/mozilla/camino/CHPageProxyIcon.h b/mozilla/camino/CHPageProxyIcon.h deleted file mode 100644 index 4e8b1e17ce8..00000000000 --- a/mozilla/camino/CHPageProxyIcon.h +++ /dev/null @@ -1,31 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- -* -* 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 the Mozilla browser. -* -* The Initial Developer of the Original Code is Netscape -* Communications Corporation. Portions created by Netscape are -* Copyright (C) 2002 Netscape Communications Corporation. All -* Rights Reserved. -* -* Contributor(s): -* Joe Hewitt (Original Author) -*/ - -#import - -@interface CHPageProxyIcon : NSImageView -{ -} - - -@end diff --git a/mozilla/camino/CHPageProxyIcon.mm b/mozilla/camino/CHPageProxyIcon.mm deleted file mode 100644 index 51ab9d59f31..00000000000 --- a/mozilla/camino/CHPageProxyIcon.mm +++ /dev/null @@ -1,93 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- -* -* 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 the Mozilla browser. -* -* The Initial Developer of the Original Code is Netscape -* Communications Corporation. Portions created by Netscape are -* Copyright (C) 2002 Netscape Communications Corporation. All -* Rights Reserved. -* -* Contributor(s): -* Joe Hewitt (Original Author) -*/ - -#import "NSString+Utils.h" - -#import "CHPageProxyIcon.h" - -#import "BookmarksService.h" -#import "MainController.h" - -#include "nsCRT.h" -#include "nsNetUtil.h" -#include "nsString.h" - -@implementation CHPageProxyIcon - -- (void)awakeFromNib -{ -} - -- (void)dealloc -{ - [super dealloc]; -} - -- (void) resetCursorRects -{ - NSCursor* cursor; - - // XXX provide image for drag-hand cursor - cursor = [NSCursor arrowCursor]; - [self addCursorRect:NSMakeRect(0,0,[self frame].size.width,[self frame].size.height) cursor:cursor]; - [cursor setOnMouseEntered:YES]; -} - -- (unsigned int)draggingSourceOperationMaskForLocal:(BOOL)flag -{ - return NSDragOperationGeneric; -} - -- (void)mouseDown:(NSEvent *)theEvent -{ - // need to implement this or else mouseDragged isn't called -} - -- (void) mouseDragged: (NSEvent*) event -{ - nsAutoString hrefStr, titleStr; - BookmarksService::GetTitleAndHrefForBrowserView( - [[[[self window] windowController] getBrowserWrapper] getBrowserView], titleStr, hrefStr); - - NSString *url = [NSString stringWith_nsAString: hrefStr]; - NSString *title = [NSString stringWith_nsAString: titleStr]; - - NSString *cleanedTitle = [title stringByReplacingCharactersInSet:[NSCharacterSet controlCharacterSet] withString:@" "]; - - NSArray *dataVals = [NSArray arrayWithObjects: url, cleanedTitle, nil]; - NSArray *dataKeys = [NSArray arrayWithObjects: @"url", @"title", nil]; - NSDictionary *data = [NSDictionary dictionaryWithObjects:dataVals forKeys:dataKeys]; - - NSPasteboard *pboard = [NSPasteboard pasteboardWithName:NSDragPboard]; - [pboard declareTypes:[NSArray arrayWithObjects:@"MozURLType", NSURLPboardType, NSStringPboardType, nil] owner:self]; - [pboard setPropertyList:data forType: @"MozURLType"]; - [[NSURL URLWithString:url] writeToPasteboard: pboard]; - [pboard setString:url forType: NSStringPboardType]; - - [self dragImage: [MainController createImageForDragging:[self image] title:title] - at: NSMakePoint(0,0) offset: NSMakeSize(0,0) - event: event pasteboard: pboard source: self slideBack: YES]; -} - - -@end diff --git a/mozilla/camino/CHPreferenceManager.h b/mozilla/camino/CHPreferenceManager.h deleted file mode 100644 index a682a4c80e4..00000000000 --- a/mozilla/camino/CHPreferenceManager.h +++ /dev/null @@ -1,66 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape 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/NPL/ - * - * 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 mozilla.org 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 NPL, 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 NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#import -#import - -class nsIPref; - -@interface CHPreferenceManager : NSObject -{ - NSUserDefaults* mDefaults; - ICInstance mInternetConfig; - nsIPref* mPrefs; -} - -+ (CHPreferenceManager *)sharedInstance; - -- (id) init; -- (void) dealloc; -- (BOOL) initInternetConfig; -- (BOOL) initMozillaPrefs; -- (void) syncMozillaPrefs; - -- (NSString *) getICStringPref:(ConstStr255Param) prefKey; -- (NSString *) homePage:(BOOL) checkStartupPagePref; - -- (NSString*)getStringPref: (const char*)prefName withSuccess:(BOOL*)outSuccess; -- (NSColor*)getColorPref: (const char*)prefName withSuccess:(BOOL*)outSuccess; -- (BOOL)getBooleanPref: (const char*)prefName withSuccess:(BOOL*)outSuccess; -- (int)getIntPref: (const char*)prefName withSuccess:(BOOL*)outSuccess; - -@end diff --git a/mozilla/camino/CHPreferenceManager.mm b/mozilla/camino/CHPreferenceManager.mm deleted file mode 100644 index 1fcdece52f9..00000000000 --- a/mozilla/camino/CHPreferenceManager.mm +++ /dev/null @@ -1,481 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape 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/NPL/ - * - * 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 mozilla.org 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 NPL, 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 NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#import -#import - -#import -#import "CHPreferenceManager.h" -#import "CHUserDefaults.h" - -#include "nsIServiceManager.h" -#include "nsIProfile.h" -#include "nsIPref.h" -#include "nsIPrefService.h" -#include "nsIPrefBranch.h" -#include "nsString.h" -#include "nsEmbedAPI.h" -#include "AppDirServiceProvider.h" - - -#ifdef _BUILD_STATIC_BIN -#include "nsStaticComponent.h" -nsresult PR_CALLBACK -app_getModuleInfo(nsStaticModuleInfo **info, PRUint32 *count); -#endif - -@implementation CHPreferenceManager - - -+ (CHPreferenceManager *) sharedInstance { - static CHPreferenceManager *sSharedInstance = nil; - return ( sSharedInstance ? sSharedInstance : (sSharedInstance = [[[CHPreferenceManager alloc] init] autorelease] )); -} - - -- (id) init -{ - if ((self = [super init])) { - if ([self initInternetConfig] == NO) { - // XXXw. throw here - NSLog (@"Failed to initialize Internet Config"); - } - if ([self initMozillaPrefs] == NO) { - // XXXw. throw here too - NSLog (@"Failed to initialize mozilla prefs"); - } - - mDefaults = [NSUserDefaults standardUserDefaults]; - } - return self; -} - -- (void) dealloc -{ - ::ICStop(mInternetConfig); - NS_IF_RELEASE(mPrefs); - - nsresult rv; - nsCOMPtr pref(do_GetService(NS_PREF_CONTRACTID, &rv)); - if (NS_SUCCEEDED(rv)) { - //NSLog(@"Saving prefs file"); - pref->SavePrefFile(nsnull); - } - - [super dealloc]; -} - -- (BOOL) initInternetConfig -{ - OSStatus error; - error = ::ICStart(&mInternetConfig, 'CHIM'); - if (error != noErr) { - // XXX throw here? - NSLog(@"Error initializing IC"); - return NO; - } - return YES; -} - -- (BOOL) initMozillaPrefs -{ - -#ifdef _BUILD_STATIC_BIN - // Initialize XPCOM's module info table - NSGetStaticModuleInfo = app_getModuleInfo; -#endif - - nsresult rv; - - NSString *path = [[[NSBundle mainBundle] executablePath] stringByDeletingLastPathComponent]; - const char *binDirPath = [path fileSystemRepresentation]; - nsCOMPtr binDir; - rv = NS_NewNativeLocalFile(nsDependentCString(binDirPath), PR_TRUE, getter_AddRefs(binDir)); - if (NS_FAILED(rv)) - return NO; - - // This shouldn't be needed since we are initing XPCOM with this - // directory but causes a (harmless) warning if not defined. - setenv("MOZILLA_FIVE_HOME", binDirPath, 1); - - // get the 'mozProfileDirName' key from our Info.plist file - NSString *dirString = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"mozProfileDirName"]; - const char* profileDirName; - if (dirString) - profileDirName = [dirString cString]; - else { - NSLog(@"mozProfileDirName key missing from Info.plist file. Using default profile directory"); - profileDirName = "Chimera"; - } - - // Supply our own directory service provider so we can control where - // the registry and profiles are located. - AppDirServiceProvider *provider = new AppDirServiceProvider(nsDependentCString(profileDirName)); - NS_ASSERTION(provider, "Failed to create AppDirServiceProvider"); - rv = NS_InitEmbedding(binDir, provider); - if (NS_FAILED(rv)) { - NSLog(@"Embedding init failed."); - return NO; - } - - nsCOMPtr profileService(do_GetService(NS_PROFILE_CONTRACTID, &rv)); - if (NS_FAILED(rv)) - return NO; - - nsAutoString newProfileName(NS_LITERAL_STRING("default")); - PRBool profileExists = PR_FALSE; - rv = profileService->ProfileExists(newProfileName.get(), &profileExists); - if (NS_FAILED(rv)) - return NO; - - if (!profileExists) { - rv = profileService->CreateNewProfile(newProfileName.get(), nsnull, nsnull, PR_FALSE); - if (NS_FAILED(rv)) - return NO; - } - - rv = profileService->SetCurrentProfile(newProfileName.get()); - if (NS_FAILED(rv)) { - if (rv == NS_ERROR_FILE_ACCESS_DENIED) { - NSString *alert = [NSString stringWithFormat: NSLocalizedString(@"AlreadyRunningAlert", @""), NSLocalizedStringFromTable(@"CFBundleName", @"InfoPlist", nil)]; - NSString *message = [NSString stringWithFormat: NSLocalizedString(@"AlreadyRunningMsg", @""), NSLocalizedStringFromTable(@"CFBundleName", @"InfoPlist", nil)]; - NSString *quit = NSLocalizedString(@"AlreadyRunningButton",@""); - NSRunAlertPanel(alert,message,quit,nil,nil); - [NSApp terminate:self]; - } - return NO; - } - - nsCOMPtr prefs(do_GetService(NS_PREF_CONTRACTID)); - mPrefs = prefs; - NS_IF_ADDREF(mPrefs); - - [self syncMozillaPrefs]; - return YES; -} - -- (void) syncMozillaPrefs -{ - CFArrayRef cfArray; - CFDictionaryRef cfDictionary; - CFNumberRef cfNumber; - CFStringRef cfString; - char strbuf[1024]; - int numbuf; - - if (!mPrefs) { - NSLog(@"Mozilla prefs not set up successfully"); - return; - } - - // fix up the cookie prefs. If 'p3p' or 'accept foreign cookies' are on, remap them to - // something that chimera can deal with. - PRInt32 acceptCookies = 0; - static const char* kCookieBehaviorPref = "network.cookie.cookieBehavior"; - mPrefs->GetIntPref(kCookieBehaviorPref, &acceptCookies); - if ( acceptCookies == 1 ) { // accept foreign cookies, assume off - acceptCookies = 2; - mPrefs->SetIntPref(kCookieBehaviorPref, acceptCookies); - } - else if ( acceptCookies == 3 ) { // p3p, assume all cookies on - acceptCookies = 0; - mPrefs->SetIntPref(kCookieBehaviorPref, acceptCookies); - } - - // get proxies from SystemConfiguration - mPrefs->SetIntPref("network.proxy.type", 0); // 0 == no proxies - mPrefs->ClearUserPref("network.proxy.http"); - mPrefs->ClearUserPref("network.proxy.http_port"); - mPrefs->ClearUserPref("network.proxy.ssl"); - mPrefs->ClearUserPref("network.proxy.ssl_port"); - mPrefs->ClearUserPref("network.proxy.ftp"); - mPrefs->ClearUserPref("network.proxy.ftp_port"); - mPrefs->ClearUserPref("network.proxy.gopher"); - mPrefs->ClearUserPref("network.proxy.gopher_port"); - mPrefs->ClearUserPref("network.proxy.socks"); - mPrefs->ClearUserPref("network.proxy.socks_port"); - mPrefs->ClearUserPref("network.proxy.no_proxies_on"); - - if ((cfDictionary = SCDynamicStoreCopyProxies (NULL)) != NULL) { - if (CFDictionaryGetValueIfPresent (cfDictionary, kSCPropNetProxiesHTTPEnable, (const void **)&cfNumber) == TRUE) { - if (CFNumberGetValue (cfNumber, kCFNumberIntType, &numbuf) == TRUE && numbuf == 1) { - if (CFDictionaryGetValueIfPresent (cfDictionary, kSCPropNetProxiesHTTPProxy, (const void **)&cfString) == TRUE) { - if (CFStringGetCString (cfString, strbuf, sizeof(strbuf)-1, kCFStringEncodingASCII) == TRUE) { - mPrefs->SetCharPref("network.proxy.http", strbuf); - } - if (CFDictionaryGetValueIfPresent (cfDictionary, kSCPropNetProxiesHTTPPort, (const void **)&cfNumber) == TRUE) { - if (CFNumberGetValue (cfNumber, kCFNumberIntType, &numbuf) == TRUE) { - mPrefs->SetIntPref("network.proxy.http_port", numbuf); - } - mPrefs->SetIntPref("network.proxy.type", 1); - } - } - } - } - if (CFDictionaryGetValueIfPresent (cfDictionary, kSCPropNetProxiesHTTPSEnable, (const void **)&cfNumber) == TRUE) { - if (CFNumberGetValue (cfNumber, kCFNumberIntType, &numbuf) == TRUE && numbuf == 1) { - if (CFDictionaryGetValueIfPresent (cfDictionary, kSCPropNetProxiesHTTPSProxy, (const void **)&cfString) == TRUE) { - if (CFStringGetCString (cfString, strbuf, sizeof(strbuf)-1, kCFStringEncodingASCII) == TRUE) { - mPrefs->SetCharPref("network.proxy.ssl", strbuf); - } - if (CFDictionaryGetValueIfPresent (cfDictionary, kSCPropNetProxiesHTTPSPort, (const void **)&cfNumber) == TRUE) { - if (CFNumberGetValue (cfNumber, kCFNumberIntType, &numbuf) == TRUE) { - mPrefs->SetIntPref("network.proxy.ssl_port", numbuf); - } - mPrefs->SetIntPref("network.proxy.type", 1); - } - } - } - } - if (CFDictionaryGetValueIfPresent (cfDictionary, kSCPropNetProxiesFTPEnable, (const void **)&cfNumber) == TRUE) { - if (CFNumberGetValue (cfNumber, kCFNumberIntType, &numbuf) == TRUE && numbuf == 1) { - if (CFDictionaryGetValueIfPresent (cfDictionary, kSCPropNetProxiesFTPProxy, (const void **)&cfString) == TRUE) { - if (CFStringGetCString (cfString, strbuf, sizeof(strbuf)-1, kCFStringEncodingASCII) == TRUE) { - mPrefs->SetCharPref("network.proxy.ftp", strbuf); - } - if (CFDictionaryGetValueIfPresent (cfDictionary, kSCPropNetProxiesFTPPort, (const void **)&cfNumber) == TRUE) { - if (CFNumberGetValue (cfNumber, kCFNumberIntType, &numbuf) == TRUE) { - mPrefs->SetIntPref("network.proxy.ftp_port", numbuf); - } - mPrefs->SetIntPref("network.proxy.type", 1); - } - } - } - } - if (CFDictionaryGetValueIfPresent (cfDictionary, kSCPropNetProxiesGopherEnable, (const void **)&cfNumber) == TRUE) { - if (CFNumberGetValue (cfNumber, kCFNumberIntType, &numbuf) == TRUE && numbuf == 1) { - if (CFDictionaryGetValueIfPresent (cfDictionary, kSCPropNetProxiesGopherProxy, (const void **)&cfString) == TRUE) { - if (CFStringGetCString (cfString, strbuf, sizeof(strbuf)-1, kCFStringEncodingASCII) == TRUE) { - mPrefs->SetCharPref("network.proxy.gopher", strbuf); - } - if (CFDictionaryGetValueIfPresent (cfDictionary, kSCPropNetProxiesGopherPort, (const void **)&cfNumber) == TRUE) { - if (CFNumberGetValue (cfNumber, kCFNumberIntType, &numbuf) == TRUE) { - mPrefs->SetIntPref("network.proxy.gopher_port", numbuf); - } - mPrefs->SetIntPref("network.proxy.type", 1); - } - } - } - } - if (CFDictionaryGetValueIfPresent (cfDictionary, kSCPropNetProxiesSOCKSEnable, (const void **)&cfNumber) == TRUE) { - if (CFNumberGetValue (cfNumber, kCFNumberIntType, &numbuf) == TRUE && numbuf == 1) { - if (CFDictionaryGetValueIfPresent (cfDictionary, kSCPropNetProxiesSOCKSProxy, (const void **)&cfString) == TRUE) { - if (CFStringGetCString (cfString, strbuf, sizeof(strbuf)-1, kCFStringEncodingASCII) == TRUE) { - mPrefs->SetCharPref("network.proxy.socks", strbuf); - } - if (CFDictionaryGetValueIfPresent (cfDictionary, kSCPropNetProxiesSOCKSPort, (const void **)&cfNumber) == TRUE) { - if (CFNumberGetValue (cfNumber, kCFNumberIntType, &numbuf) == TRUE) { - mPrefs->SetIntPref("network.proxy.socks_port", numbuf); - } - mPrefs->SetIntPref("network.proxy.type", 1); - } - } - } - } - if (CFDictionaryGetValueIfPresent (cfDictionary, kSCPropNetProxiesExceptionsList, (const void **)&cfArray) == TRUE) { - cfString = CFStringCreateByCombiningStrings (NULL, cfArray, CFSTR(", ")); - if (CFStringGetLength (cfString) > 0) { - if (CFStringGetCString (cfString, strbuf, sizeof(strbuf)-1, kCFStringEncodingASCII) == TRUE) { - mPrefs->SetCharPref("network.proxy.no_proxies_on", strbuf); - } - } - } - CFRelease (cfDictionary); - } -} - -- (NSString*)getStringPref: (const char*)prefName withSuccess:(BOOL*)outSuccess -{ - NSString *prefValue = @""; - - char *buf = nsnull; - nsresult rv = NS_ERROR_FAILURE; - if (mPrefs) - rv = mPrefs->GetCharPref(prefName, &buf); - - if (NS_SUCCEEDED(rv) && buf) { - // prefs are UTF-8 - prefValue = [NSString stringWithUTF8String:buf]; - free(buf); - if (outSuccess) *outSuccess = YES; - } else { - if (outSuccess) *outSuccess = NO; - } - - return prefValue; -} - -- (NSColor*)getColorPref: (const char*)prefName withSuccess:(BOOL*)outSuccess -{ - // colors are stored in HTML-like #FFFFFF strings - NSString* colorString = [self getStringPref:prefName withSuccess:outSuccess]; - NSColor* returnColor = [NSColor blackColor]; - - if ([colorString hasPrefix:@"#"] && [colorString length] == 7) - { - unsigned int redInt, greenInt, blueInt; - sscanf([colorString cString], "#%02x%02x%02x", &redInt, &greenInt, &blueInt); - - float redFloat = ((float)redInt / 255.0); - float greenFloat = ((float)greenInt / 255.0); - float blueFloat = ((float)blueInt / 255.0); - - returnColor = [NSColor colorWithCalibratedRed:redFloat green:greenFloat blue:blueFloat alpha:1.0f]; - } - - return returnColor; -} - -- (BOOL)getBooleanPref: (const char*)prefName withSuccess:(BOOL*)outSuccess -{ - PRBool boolPref = PR_FALSE; - nsresult rv = NS_ERROR_FAILURE; - if (mPrefs) - rv = mPrefs->GetBoolPref(prefName, &boolPref); - - if (outSuccess) - *outSuccess = NS_SUCCEEDED(rv); - - return boolPref ? YES : NO; -} - -- (int)getIntPref: (const char*)prefName withSuccess:(BOOL*)outSuccess -{ - PRInt32 intPref = 0; - nsresult rv = NS_ERROR_FAILURE; - if (mPrefs) - mPrefs->GetIntPref(prefName, &intPref); - if (outSuccess) - *outSuccess = NS_SUCCEEDED(rv); - return intPref; -} - - - -//- (BOOL) getICBoolPref:(ConstStr255Param) prefKey; -//{ -// ICAttr dummy; -// OSStatus error; -// SInt32 size; -// Boolean buf; - -// error = ICGetPref (internetConfig, prefKey, &dummy, &buf, &size); -// if (error == noErr && buf) -// return YES; -// else -// return NO; -// } - -- (NSString *) getICStringPref:(ConstStr255Param) prefKey; -{ - NSString *string; - ICAttr dummy; - OSStatus error; - SInt32 size = 256; - char *buf; - - do { - if ((buf = malloc ((unsigned int)size)) == NULL) { - NSLog (@"malloc failed in [PreferenceManager getICStringPref]"); - return nil; - } - error = ICGetPref (mInternetConfig, prefKey, &dummy, buf, &size); - if (error != noErr && error != icTruncatedErr) { - free (buf); - NSLog (@"[IC error %d in [PreferenceManager getICStringPref]", (int) error); - return nil; - } - size *= 2; - } while (error == icTruncatedErr); - if (*buf == 0) { - NSLog (@"ICGetPref returned empty string"); - free (buf); - return nil; - } - CopyPascalStringToC ((ConstStr255Param) buf, buf); - string = [NSString stringWithCString:buf]; - free (buf); - return string; -} - - -- (NSString *) homePage:(BOOL)checkStartupPagePref -{ - if (!mPrefs) - return @"about:blank"; - - PRInt32 mode = 1; - - // In some cases, we need to check browser.startup.page to see if - // we want to use the homepage or if the user wants a blank window. - // mode 0 is blank page, mode 1 is home page. 2 is "last page visited" - // but we don't care about that. Default to 1 unless |checkStartupPagePref| - // is true. - nsresult rv = NS_OK; - if ( checkStartupPagePref ) - rv = mPrefs->GetIntPref("browser.startup.page", &mode); - if (NS_FAILED(rv) || mode == 1) { - // see which home page to use - PRBool boolPref; - if (NS_SUCCEEDED(mPrefs->GetBoolPref("chimera.use_system_home_page", &boolPref)) && boolPref) - return [self getICStringPref:kICWWWHomePage]; - - nsCOMPtr prefBranch = do_QueryInterface(mPrefs); - if (!prefBranch) return @"about:blank"; - - NSString* homepagePref = nil; - PRInt32 haveUserPref; - if (NS_FAILED(prefBranch->PrefHasUserValue("browser.startup.homepage", &haveUserPref)) || !haveUserPref) { - // no home page pref is set in user prefs. - homepagePref = NSLocalizedStringFromTable( @"HomePageDefault", @"WebsiteDefaults", nil); - // and let's copy this into the homepage pref if it's not bad - if (![homepagePref isEqualToString:@"HomePageDefault"]) - mPrefs->SetCharPref("browser.startup.homepage", [homepagePref UTF8String]); - } - else { - homepagePref = [self getStringPref:"browser.startup.homepage" withSuccess:NULL]; - } - - if (homepagePref && [homepagePref length] > 0 && ![homepagePref isEqualToString:@"HomePageDefault"]) - return homepagePref; - } - - return @"about:blank"; -} - -@end - diff --git a/mozilla/camino/CHRDFOutlineViewDataSource.h b/mozilla/camino/CHRDFOutlineViewDataSource.h deleted file mode 100644 index 2d66e0ef490..00000000000 --- a/mozilla/camino/CHRDFOutlineViewDataSource.h +++ /dev/null @@ -1,93 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape 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/NPL/ - * - * 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 mozilla.org 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): - * Ben Goodger (Original Author) - * - * 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 NPL, 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 NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#import -#import - -class nsIRDFDataSource; -class nsIRDFContainer; -class nsIRDFContainerUtils; -class nsIRDFResource; -class nsIRDFService; - -@interface CHRDFOutlineViewDataSource : NSObject { - nsIRDFDataSource* mDataSource; - nsIRDFContainer* mContainer; - nsIRDFContainerUtils* mContainerUtils; - nsIRDFResource* mRootResource; - nsIRDFService* mRDFService; - - IBOutlet id mOutlineView; - - NSMutableDictionary* mDictionary; -} - -// Initialization Methods -- (void) ensureDataSourceLoaded; - -- (nsIRDFDataSource*) dataSource; -- (nsIRDFResource*) rootResource; -- (void) setDataSource: (nsIRDFDataSource*) aDataSource; -- (void) setRootResource: (nsIRDFResource*) aResource; - -// Outline View Data Source methods -- (id)outlineView:(NSOutlineView *)outlineView child:(int)index ofItem:(id)item; -- (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item; -- (int)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item; -- (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item; -- (void)outlineView:(NSOutlineView *)outlineView setObjectValue:(id)object forTableColumn:(NSTableColumn *)tableColumn byItem:(id)item; - -- (void)reloadDataForItem:(id)item reloadChildren: (BOOL)aReloadChildren; - -// Implementation Methods -- (id) MakeWrapperFor: (nsIRDFResource*) aRDFResource; - -@end - -// RDF Resource Wrapper to make the Outline View happy -@interface RDFOutlineViewItem : NSObject -{ - nsIRDFResource* mResource; -} - -- (nsIRDFResource*) resource; -- (void) setResource: (nsIRDFResource*) aResource; - -@end - - diff --git a/mozilla/camino/CHRDFOutlineViewDataSource.mm b/mozilla/camino/CHRDFOutlineViewDataSource.mm deleted file mode 100644 index c39c8263299..00000000000 --- a/mozilla/camino/CHRDFOutlineViewDataSource.mm +++ /dev/null @@ -1,325 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape 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/NPL/ - * - * 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 mozilla.org 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): - * Ben Goodger (Original Author) - * - * 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 NPL, 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 NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#import "NSString+Utils.h" - -#import "CHRDFOutlineViewDataSource.h" - -#include "nsIRDFDataSource.h" -#include "nsIRDFService.h" -#include "nsIRDFLiteral.h" -#include "nsIRDFResource.h" -#include "nsIRDFContainer.h" -#include "nsIRDFContainerUtils.h" -#include "nsRDFCID.h" - -#include "nsComponentManagerUtils.h" -#include "nsIServiceManagerUtils.h" - -#include "nsXPIDLString.h" -#include "nsString.h" - - - -@implementation CHRDFOutlineViewDataSource - -- (void) ensureDataSourceLoaded -{ - if (!mContainer) - { - nsCOMPtr ctr = do_CreateInstance("@mozilla.org/rdf/container;1"); - NS_ADDREF(mContainer = ctr); - - nsCOMPtr ctrUtils = do_GetService("@mozilla.org/rdf/container-utils;1"); - NS_ADDREF(mContainerUtils = ctrUtils); - - nsCOMPtr rdfService = do_GetService("@mozilla.org/rdf/rdf-service;1"); - NS_ADDREF(mRDFService = rdfService); - - mDictionary = [[NSMutableDictionary alloc] initWithCapacity: 30]; - - mDataSource = nsnull; - mRootResource = nsnull; - } -} - -- (void) dealloc -{ - NS_IF_RELEASE(mContainer); - NS_IF_RELEASE(mContainerUtils); - NS_IF_RELEASE(mRDFService); - - NS_IF_RELEASE(mDataSource); - NS_IF_RELEASE(mRootResource); - - [mDictionary release]; - - [super dealloc]; -} - -- (nsIRDFDataSource*) dataSource -{ - NS_IF_ADDREF(mDataSource); - return mDataSource; -} - -- (nsIRDFResource*) rootResource -{ - NS_IF_ADDREF(mRootResource); - return mRootResource; -} - -- (void) setDataSource: (nsIRDFDataSource*) aDataSource -{ - nsIRDFDataSource* oldDataSource = mDataSource; - NS_IF_ADDREF(mDataSource = aDataSource); - NS_IF_RELEASE(oldDataSource); -} - -- (void) setRootResource: (nsIRDFResource*) aResource -{ - nsIRDFResource* oldResource = mRootResource; - NS_IF_ADDREF(mRootResource = aResource); - NS_IF_RELEASE(oldResource); -} - -// -// XXX - For now, we'll just say that none of our items are editable, as we aren't using any -// RDF datasources that are mutable. -// -- (BOOL) outlineView: (NSOutlineView*) aOutlineView shouldEditTableColumn: (NSTableColumn*) aTableColumn - item: (id) aItem -{ - return NO; -} - -- (BOOL) outlineView: (NSOutlineView*) aOutlineView isItemExpandable: (id) aItem -{ - if (!mDataSource) - return NO; - - if (!aItem) - return YES; // The root is always open - - nsCOMPtr itemResource = dont_AddRef([aItem resource]); - - PRBool isSeq = PR_FALSE; - mContainerUtils->IsSeq(mDataSource, itemResource, &isSeq); - if (isSeq) - return YES; - - nsCOMPtr childProperty; - mRDFService->GetResource("http://home.netscape.com/NC-rdf#child", getter_AddRefs(childProperty)); - - nsCOMPtr childNode; - mDataSource->GetTarget(itemResource, childProperty, PR_TRUE, getter_AddRefs(childNode)); - - return childNode != nsnull; -} - -- (id) outlineView: (NSOutlineView*) aOutlineView child: (int) aIndex - ofItem: (id) aItem -{ - if (!mDataSource) - return nil; - - nsCOMPtr resource = !aItem ? dont_AddRef([self rootResource]) : dont_AddRef([aItem resource]); - - nsCOMPtr ordinalResource; - mContainerUtils->IndexToOrdinalResource(aIndex + 1, getter_AddRefs(ordinalResource)); - - nsCOMPtr childNode; - mDataSource->GetTarget(resource, ordinalResource, PR_TRUE, getter_AddRefs(childNode)); - if (childNode) { - // Yay. A regular container. We don't need to count, we can go directly to - // our object. - nsCOMPtr childResource(do_QueryInterface(childNode)); - if (childResource) - return [self MakeWrapperFor:childResource]; - } - else - { - // Oh well, not a regular container. We need to count, dagnabbit. - nsCOMPtr childProperty; - mRDFService->GetResource("http://home.netscape.com/NC-rdf#child", getter_AddRefs(childProperty)); - - nsCOMPtr childNodes; - mDataSource->GetTargets(resource, childProperty, PR_TRUE, getter_AddRefs(childNodes)); - - nsCOMPtr supp; - PRInt32 count = 0; - - PRBool hasMore = PR_FALSE; - while (NS_SUCCEEDED(childNodes->HasMoreElements(&hasMore)) && hasMore) - { - childNodes->GetNext(getter_AddRefs(supp)); - if (count == aIndex) - break; - count ++; - } - - nsCOMPtr childResource(do_QueryInterface(supp)); - if (childResource) { - return [self MakeWrapperFor:childResource]; - } - } - - return nil; -} - -- (int) outlineView: (NSOutlineView*) aOutlineView numberOfChildrenOfItem: (id) aItem; -{ - if (!mDataSource) - return 0; - - nsCOMPtr resource = dont_AddRef(aItem ? [aItem resource] : [self rootResource]); - - // XXX just assume NC:child is the only containment arc for now - nsCOMPtr childProperty; - mRDFService->GetResource("http://home.netscape.com/NC-rdf#child", getter_AddRefs(childProperty)); - - nsCOMPtr childNodes; - mDataSource->GetTargets(resource, childProperty, PR_TRUE, getter_AddRefs(childNodes)); - - PRBool hasMore = PR_FALSE; - PRInt32 count = 0; - - while (NS_SUCCEEDED(childNodes->HasMoreElements(&hasMore)) && hasMore) - { - nsCOMPtr supp; - childNodes->GetNext(getter_AddRefs(supp)); - count ++; - } - - if (count == 0) { - nsresult rv = mContainer->Init(mDataSource, resource); - if (NS_FAILED(rv)) - return 0; - - mContainer->GetCount(&count); - } - - return count; -} - -- (id) outlineView: (NSOutlineView*) aOutlineView objectValueForTableColumn: (NSTableColumn*) aTableColumn - byItem: (id) aItem -{ - if (!mDataSource || !aItem) - return nil; - - // The table column's identifier is the RDF Resource URI of the property being displayed in - // that column, e.g. "http://home.netscape.com/NC-rdf#Name" - NSString* columnPropertyURI = [aTableColumn identifier]; - - nsCOMPtr propertyResource; - mRDFService->GetResource([columnPropertyURI UTF8String], getter_AddRefs(propertyResource)); - - nsCOMPtr resource = dont_AddRef([aItem resource]); - - nsCOMPtr valueNode; - mDataSource->GetTarget(resource, propertyResource, PR_TRUE, getter_AddRefs(valueNode)); - if (!valueNode) { -#if DEBUG - NSLog(@"ValueNode is null in RDF objectValueForTableColumn"); -#endif - return nil; - } - - nsCOMPtr valueLiteral(do_QueryInterface(valueNode)); - if (!valueLiteral) - return nil; - - nsXPIDLString literalValue; - valueLiteral->GetValue(getter_Copies(literalValue)); - - return [NSString stringWith_nsAString: literalValue]; -} - -- (void) outlineView: (NSOutlineView*) aOutlineView setObjectValue: (id) aObject - forTableColumn: (NSTableColumn*) aTableColumn - byItem: (id) aItem -{ - -} - -- (void) reloadDataForItem: (id) aItem reloadChildren: (BOOL) aReloadChildren -{ - if (!aItem) - [mOutlineView reloadData]; - else - [mOutlineView reloadItem: aItem reloadChildren: aReloadChildren]; -} - -- (id) MakeWrapperFor: (nsIRDFResource*) aRDFResource -{ - RDFOutlineViewItem* item = [[[RDFOutlineViewItem alloc] init] autorelease]; - [item setResource: aRDFResource]; - // keep a copy around - const char* resourceValue; - aRDFResource->GetValueConst(&resourceValue); - - [mDictionary setObject:item forKey:[NSString stringWithCString:resourceValue]]; - return item; -} - - -@end - -@implementation RDFOutlineViewItem - -- (void) dealloc -{ - NS_IF_RELEASE(mResource); - [super dealloc]; -} - -- (nsIRDFResource*) resource -{ - NS_IF_ADDREF(mResource); - return mResource; -} - -- (void) setResource: (nsIRDFResource*) aResource -{ - nsIRDFResource* oldResource = mResource; - NS_IF_ADDREF(mResource = aResource); - NS_IF_RELEASE(oldResource); -} - -@end diff --git a/mozilla/camino/CHSplashScreenWindow.h b/mozilla/camino/CHSplashScreenWindow.h deleted file mode 100644 index df82c005af8..00000000000 --- a/mozilla/camino/CHSplashScreenWindow.h +++ /dev/null @@ -1,45 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- -* -* 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 the Mozilla browser. -* -* The Initial Developer of the Original Code is Matt Judy. -*/ - -#import - -@interface CHSplashScreenWindow : NSWindow { - BOOL _fades; - BOOL __didFadeIn; - int _fadeIndex; - NSTimeInterval _fadeDelay; - id _fadeThreadLock; - NSTextField *_statusField; -} - -// This method inits the window and displays it, slightly proud of center, -// and at the size of the image it displays. -// -// The splash method should be used in your main controller's init method -// in this fashion: splashWindow = [[SplashScreenWindow alloc] splashImage:nil withFade:NO withStatusRect:someRect]; -// -// Passing nil to splashImage will attempt to load [NSImage imageNamed:@"splash"] instead. -// If that fails, the app icon will be displayed. -// -// The window will release itself whenever you send it the close message. --(id)splashImage:(NSImage *)splashImage withFade:(BOOL)shouldFade withStatusRect:(NSRect)statusRect; - --(NSString *)statusText; --(void)setStatusText:(NSString *)newText; - - -@end diff --git a/mozilla/camino/CHSplashScreenWindow.m b/mozilla/camino/CHSplashScreenWindow.m deleted file mode 100644 index 0cac643da15..00000000000 --- a/mozilla/camino/CHSplashScreenWindow.m +++ /dev/null @@ -1,186 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- -* -* 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 the Mozilla browser. -* -* The Initial Developer of the Original Code is Matt Judy. -* -*/ - -#import "CHSplashScreenWindow.h" - -@interface CHSplashScreenWindow (Private) --(void)fadeIn; --(void)fadeInThread; --(void)fadeOut; --(void)fadeOutThread; -@end - -@implementation CHSplashScreenWindow - --(id)splashImage:(NSImage *)splashImage withFade:(BOOL)shouldFade withStatusRect:(NSRect)statusRect -{ - NSRect splashRect; - NSRect statusFieldRect; - NSImageView *contentImageView; - - _fadeDelay = (0.5 / 60.0); - - if ( ! splashImage ) { - if ( [NSImage imageNamed:@"splash"] ) { - splashImage = [NSImage imageNamed:@"splash"]; - } else { - splashImage = [NSImage imageNamed:@"NSApplicationIcon"]; - } - } - - splashRect = NSMakeRect(0.0, 0.0, [splashImage size].width, [splashImage size].height); - contentImageView = [[[NSImageView alloc] initWithFrame:splashRect] autorelease]; -#if USE_STATUS_FIELD - statusFieldRect = NSMakeRect(0.0, 170.0, (splashRect.size.width - 5.0), 16.0); - _statusField = [[[NSTextField alloc] initWithFrame:statusFieldRect]; -#endif - - if ( (self = [super initWithContentRect:splashRect - styleMask:NSBorderlessWindowMask - backing:NSBackingStoreBuffered - defer:NO]) ) { - - [contentImageView setImage:splashImage]; - _fadeThreadLock = nil; - -#if USE_STATUS_FIELD - [_statusField setDrawsBackground:NO]; - [_statusField setEditable:NO]; - [_statusField setSelectable:NO]; - [_statusField setBezeled:NO]; - [_statusField setBordered:NO]; - [_statusField setFont:[NSFont fontWithName:@"Monaco" size:10.0]]; - [_statusField setTextColor:[NSColor whiteColor]]; - [_statusField setAlignment:NSRightTextAlignment]; - [_statusField setStringValue:@"Loading..."]; -#endif - - [[self contentView] addSubview:contentImageView]; -#if USE_STATUS_FIELD - [[self contentView] addSubview:_statusField]; -#endif - [self setOpaque:NO]; - [self setHasShadow:YES]; - [self setReleasedWhenClosed:YES]; - [self center]; - - if ( shouldFade ) { - [self fadeIn]; - } else { - [self makeKeyAndOrderFront:self]; - } - __didFadeIn = shouldFade; - } - return self; -} - --(NSString *)statusText -{ - return [_statusField stringValue]; -} - --(void)setStatusText:(NSString *)newText -{ -#if USE_STATUS_FIELD - [_statusField setStringValue:newText]; - [_statusField display]; -#endif -} - --(void)fadeIn -{ - [self setAlphaValue:0.0]; - [self makeKeyAndOrderFront:self]; - - if (_fadeThreadLock == nil) { - _fadeThreadLock = [[NSLock allocWithZone:[self zone]] init]; - } - - [NSThread detachNewThreadSelector:@selector(fadeInThread) toTarget:self withObject:nil]; -} - --(void)fadeInThread -{ - float fadeLevel = 0.0; - NSAutoreleasePool *threadMainPool = [[NSAutoreleasePool alloc] init]; - - [_fadeThreadLock lock]; - - while ( fadeLevel < 1.0 ) { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - fadeLevel += 0.20; - [self setAlphaValue:fadeLevel]; - [self flushWindow]; - [NSThread sleepUntilDate:[NSDate dateWithTimeIntervalSinceNow:_fadeDelay]]; - [pool release]; - } - - [_fadeThreadLock unlock]; - [threadMainPool release]; -} - --(void)fadeOut -{ - if (_fadeThreadLock == nil) { - _fadeThreadLock = [[NSLock allocWithZone:[self zone]] init]; - } - - [NSThread detachNewThreadSelector:@selector(fadeOutThread) toTarget:self withObject:nil]; -} - --(void)fadeOutThread -{ - float fadeLevel = 1.0; - NSAutoreleasePool *threadMainPool = [[NSAutoreleasePool alloc] init]; - - [_fadeThreadLock lock]; - - while ( fadeLevel > 0.0 ) { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - fadeLevel -= 0.1; - [self setAlphaValue:fadeLevel]; - [self flushWindow]; - [NSThread sleepUntilDate:[NSDate dateWithTimeIntervalSinceNow:_fadeDelay]]; - [pool release]; - } - - [_fadeThreadLock unlock]; - [threadMainPool release]; -} - --(void)close -{ -#if USE_STATUS_FIELD - [_statusField release]; -#endif - -// if ( __didFadeIn ) { - if ( NO ) { //Fade out is still problematic... - [self fadeOut]; - } - [super close]; -} - --(void)dealloc -{ - [_fadeThreadLock release]; - - [super dealloc]; -} - -@end diff --git a/mozilla/camino/CHToolbarAdditions.h b/mozilla/camino/CHToolbarAdditions.h deleted file mode 100644 index 0831146aa7b..00000000000 --- a/mozilla/camino/CHToolbarAdditions.h +++ /dev/null @@ -1,12 +0,0 @@ -#import - -@interface NSToolbar (CHToolbarCustomizableAdditions) -- (BOOL) alwaysCustomizableByDrag; -- (void) setAlwaysCustomizableByDrag:(BOOL) flag; - -- (BOOL) showsContextMenu; -- (void) setShowsContextMenu:(BOOL) flag; - -- (unsigned int) indexOfFirstMovableItem; -- (void) setIndexOfFirstMovableItem:(unsigned int) anIndex; -@end diff --git a/mozilla/camino/CHToolbarAdditions.m b/mozilla/camino/CHToolbarAdditions.m deleted file mode 100644 index 62e3c6f1bc8..00000000000 --- a/mozilla/camino/CHToolbarAdditions.m +++ /dev/null @@ -1,28 +0,0 @@ -#import "CHToolbarAdditions.h" -#import - -@implementation NSToolbar (CHToolbarCustomizableAdditions) -- (BOOL) alwaysCustomizableByDrag { - return (BOOL) _tbFlags.clickAndDragPerformsCustomization; -} - -- (void) setAlwaysCustomizableByDrag:(BOOL) flag { - _tbFlags.clickAndDragPerformsCustomization = (unsigned int) flag & 1; -} - -- (BOOL) showsContextMenu { - return (BOOL) ! _tbFlags.showsNoContextMenu; -} - -- (void) setShowsContextMenu:(BOOL) flag { - _tbFlags.showsNoContextMenu = (unsigned int) ! flag & 1; -} - -- (unsigned int) indexOfFirstMovableItem { - return (unsigned int) _tbFlags.firstMoveableItemIndex; -} - -- (void) setIndexOfFirstMovableItem:(unsigned int) anIndex { - _tbFlags.firstMoveableItemIndex = (unsigned int) anIndex & 0x3F; -} -@end diff --git a/mozilla/camino/CHUserDefaults.h b/mozilla/camino/CHUserDefaults.h deleted file mode 100644 index 1c203420f0b..00000000000 --- a/mozilla/camino/CHUserDefaults.h +++ /dev/null @@ -1,55 +0,0 @@ -/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** 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 mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 2001, 2002 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Simon Fraser - * - * 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 ***** */ - - -/* - This file contains a list of #defines for our user default entries. They - are collected here, rather than being scattered throughout the code, for - easier documentation. -*/ - - -#define USER_DEFAULTS_AUTOREGISTER_KEY @"autoRegister" /* Boolean */ -#define USER_DEFAULTS_URL_KEY @"url" /* String */ - -#define USER_DEFAULTS_HIDE_PERS_TOOLBAR_KEY @"Hide Personal Toolbar" /* Integer */ -#define USER_DEFAULTS_HOMEPAGE_KEY @"HomePage" /* String */ - -#define USER_DEFAULTS_AUTOCOMPLETE_WHILE_TYPING @"Autocomplete While Typing" /* Boolean */ - - diff --git a/mozilla/camino/CocoaPromptService.h b/mozilla/camino/CocoaPromptService.h deleted file mode 100644 index 4d8d3375fef..00000000000 --- a/mozilla/camino/CocoaPromptService.h +++ /dev/null @@ -1,64 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** 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 mozilla.org 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): - * Brian Ryner - * - * 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 ***** */ - -#ifndef __CocoaPromptService_h__ -#define __CocoaPromptService_h__ - -#include "nsIStringBundle.h" -#include "nsIPromptService.h" -#import - -class CocoaPromptService : public nsIPromptService -{ -public: - CocoaPromptService(); - virtual ~CocoaPromptService(); - - NS_DECL_ISUPPORTS; - NS_DECL_NSIPROMPTSERVICE; - -private: - NSWindow *GetNSWindowForDOMWindow(nsIDOMWindow* window); - NSString *GetCommonDialogLocaleString(const char *s); - NSString *GetButtonStringFromFlags(PRUint32 btnFlags, PRUint32 btnIDAndShift, - const PRUnichar *btnTitle); - - nsCOMPtr mCommonDialogStringBundle; -}; - -#endif diff --git a/mozilla/camino/CocoaPromptService.mm b/mozilla/camino/CocoaPromptService.mm deleted file mode 100644 index 796762d02b8..00000000000 --- a/mozilla/camino/CocoaPromptService.mm +++ /dev/null @@ -1,453 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** 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 mozilla.org 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): - * Brian Ryner - * - * 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 "NSString+Utils.h" - -#import "nsCocoaBrowserService.h" -#import "CocoaPromptService.h" - -#include "nsCRT.h" -#include "nsIWindowWatcher.h" -#include "nsIWebBrowserChrome.h" -#include "nsIEmbeddingSiteWindow.h" -#include "nsString.h" -#include "nsIServiceManagerUtils.h" - -CocoaPromptService::CocoaPromptService() -{ - NS_INIT_ISUPPORTS(); -} - -CocoaPromptService::~CocoaPromptService() -{ -} - -NS_IMPL_ISUPPORTS1(CocoaPromptService, nsIPromptService); - -/* void alert (in nsIDOMWindow parent, in wstring dialogTitle, in wstring text); */ -NS_IMETHODIMP -CocoaPromptService::Alert(nsIDOMWindow *parent, - const PRUnichar *dialogTitle, - const PRUnichar *text) -{ - nsAlertController* controller = nsCocoaBrowserService::GetAlertController(); - if (!controller) { - return NS_ERROR_FAILURE; - } - - NSString* titleStr = [NSString stringWithPRUnichars:dialogTitle]; - NSString* textStr = [NSString stringWithPRUnichars:text]; - NSWindow* window = GetNSWindowForDOMWindow(parent); - if (!window) - return NS_ERROR_FAILURE; - - [controller alert:window title:titleStr text:textStr]; - - return NS_OK; -} - -/* void alertCheck (in nsIDOMWindow parent, in wstring dialogTitle, in wstring text, in wstring checkMsg, inout boolean checkValue); */ -NS_IMETHODIMP -CocoaPromptService::AlertCheck(nsIDOMWindow *parent, - const PRUnichar *dialogTitle, - const PRUnichar *text, - const PRUnichar *checkMsg, - PRBool *checkValue) -{ - nsAlertController* controller = nsCocoaBrowserService::GetAlertController(); - if (!controller) { - return NS_ERROR_FAILURE; - } - - NSString* titleStr = [NSString stringWithPRUnichars:dialogTitle]; - NSString* textStr = [NSString stringWithPRUnichars:text]; - NSString* msgStr = [NSString stringWithPRUnichars:checkMsg]; - NSWindow* window = GetNSWindowForDOMWindow(parent); - - if (checkValue) { - BOOL valueBool = *checkValue ? YES : NO; - - [controller alertCheck:window title:titleStr text:textStr checkMsg:msgStr checkValue:&valueBool]; - - *checkValue = (valueBool == YES) ? PR_TRUE : PR_FALSE; - } - else { - [controller alert:window title:titleStr text:textStr]; - } - - return NS_OK; -} - -/* boolean confirm (in nsIDOMWindow parent, in wstring dialogTitle, in wstring text); */ -NS_IMETHODIMP -CocoaPromptService::Confirm(nsIDOMWindow *parent, - const PRUnichar *dialogTitle, - const PRUnichar *text, - PRBool *_retval) -{ - nsAlertController* controller = nsCocoaBrowserService::GetAlertController(); - if (!controller) { - return NS_ERROR_FAILURE; - } - - NSString* titleStr = [NSString stringWithPRUnichars:dialogTitle]; - NSString* textStr = [NSString stringWithPRUnichars:text]; - NSWindow* window = GetNSWindowForDOMWindow(parent); - - *_retval = (PRBool)[controller confirm:window title:titleStr text:textStr]; - - return NS_OK; -} - -/* boolean confirmCheck (in nsIDOMWindow parent, in wstring dialogTitle, in wstring text, in wstring checkMsg, inout boolean checkValue); */ -NS_IMETHODIMP -CocoaPromptService::ConfirmCheck(nsIDOMWindow *parent, - const PRUnichar *dialogTitle, - const PRUnichar *text, - const PRUnichar *checkMsg, - PRBool *checkValue, PRBool *_retval) -{ - nsAlertController* controller = nsCocoaBrowserService::GetAlertController(); - if (!controller) { - return NS_ERROR_FAILURE; - } - - NSString* titleStr = [NSString stringWithPRUnichars:dialogTitle]; - NSString* textStr = [NSString stringWithPRUnichars:text]; - NSString* msgStr = [NSString stringWithPRUnichars:checkMsg]; - NSWindow* window = GetNSWindowForDOMWindow(parent); - - if (checkValue) { - BOOL valueBool = *checkValue ? YES : NO; - - *_retval = (PRBool)[controller confirmCheck:window title:titleStr text:textStr checkMsg:msgStr checkValue:&valueBool]; - - *checkValue = (valueBool == YES) ? PR_TRUE : PR_FALSE; - } - else { - *_retval = (PRBool)[controller confirm:window title:titleStr text:textStr]; - } - - return NS_OK; -} - -// these constants are used for identifying the buttons and are intentionally overloaded to -// correspond to the number of bits needed for shifting to obtain the flags for a particular -// button (should be defined in nsIPrompt*.idl instead of here) -const PRUint32 kButton0 = 0; -const PRUint32 kButton1 = 8; -const PRUint32 kButton2 = 16; - -/* void confirmEx (in nsIDOMWindow parent, in wstring dialogTitle, in wstring text, in unsigned long buttonFlags, in wstring button0Title, in wstring button1Title, in wstring button2Title, in wstring checkMsg, inout boolean checkValue, out PRInt32 buttonPressed); */ -NS_IMETHODIMP -CocoaPromptService::ConfirmEx(nsIDOMWindow *parent, - const PRUnichar *dialogTitle, - const PRUnichar *text, - PRUint32 buttonFlags, - const PRUnichar *button0Title, - const PRUnichar *button1Title, - const PRUnichar *button2Title, - const PRUnichar *checkMsg, - PRBool *checkValue, PRInt32 *buttonPressed) -{ - nsAlertController* controller = nsCocoaBrowserService::GetAlertController(); - if (!controller) { - return NS_ERROR_FAILURE; - } - - NSString* titleStr = [NSString stringWithPRUnichars:dialogTitle]; - NSString* textStr = [NSString stringWithPRUnichars:text]; - NSString* msgStr = [NSString stringWithPRUnichars:checkMsg]; - NSWindow* window = GetNSWindowForDOMWindow(parent); - - NSString* btn1Str = GetButtonStringFromFlags(buttonFlags, kButton0, button0Title); - NSString* btn2Str = GetButtonStringFromFlags(buttonFlags, kButton1, button1Title); - NSString* btn3Str = GetButtonStringFromFlags(buttonFlags, kButton2, button2Title); - - if (checkValue) { - BOOL valueBool = *checkValue ? YES : NO; - - *buttonPressed = [controller confirmCheckEx:window title:titleStr text:textStr - button1: btn1Str button2: btn2Str button3: btn3Str - checkMsg:msgStr checkValue:&valueBool]; - - *checkValue = (valueBool == YES) ? PR_TRUE : PR_FALSE; - } - else { - *buttonPressed = [controller confirmEx:window title:titleStr text:textStr - button1: btn1Str button2: btn2Str button3: btn3Str]; - } - - return NS_OK; - -} - - -/* boolean prompt (in nsIDOMWindow parent, in wstring dialogTitle, in wstring text, inout wstring value, in wstring checkMsg, inout boolean checkValue); */ -NS_IMETHODIMP -CocoaPromptService::Prompt(nsIDOMWindow *parent, - const PRUnichar *dialogTitle, - const PRUnichar *text, - PRUnichar **value, - const PRUnichar *checkMsg, - PRBool *checkValue, - PRBool *_retval) -{ - nsAlertController* controller = nsCocoaBrowserService::GetAlertController(); - if (!controller) { - return NS_ERROR_FAILURE; - } - - NSString* titleStr = [NSString stringWithPRUnichars:dialogTitle]; - NSString* textStr = [NSString stringWithPRUnichars:text]; - NSString* msgStr = [NSString stringWithPRUnichars:checkMsg]; - - NSMutableString* valueStr = [NSMutableString stringWithPRUnichars:*value]; - - BOOL valueBool; - if (checkValue) { - valueBool = *checkValue ? YES : NO; - } - NSWindow* window = GetNSWindowForDOMWindow(parent); - - *_retval = (PRBool)[controller prompt:window title:titleStr text:textStr promptText:valueStr checkMsg:msgStr checkValue:&valueBool doCheck:(checkValue != nsnull)]; - - if (checkValue) { - *checkValue = (valueBool == YES) ? PR_TRUE : PR_FALSE; - } - PRUint32 length = [valueStr length]; - PRUnichar* retStr = (PRUnichar*)nsMemory::Alloc((length + 1) * sizeof(PRUnichar)); - [valueStr getCharacters:retStr]; - retStr[length] = PRUnichar(0); - *value = retStr; - - return NS_OK; -} - -/* boolean promptUsernameAndPassword (in nsIDOMWindow parent, in wstring dialogTitle, in wstring text, inout wstring username, inout wstring password, in wstring checkMsg, inout boolean checkValue); */ -NS_IMETHODIMP -CocoaPromptService::PromptUsernameAndPassword(nsIDOMWindow *parent, - const PRUnichar *dialogTitle, - const PRUnichar *text, - PRUnichar **username, - PRUnichar **password, - const PRUnichar *checkMsg, - PRBool *checkValue, - PRBool *_retval) -{ - nsAlertController* controller = nsCocoaBrowserService::GetAlertController(); - if (!controller) { - return NS_ERROR_FAILURE; - } - - NSString* titleStr = [NSString stringWithPRUnichars:dialogTitle]; - NSString* textStr = [NSString stringWithPRUnichars:text]; - NSString* msgStr = [NSString stringWithPRUnichars:checkMsg]; - NSMutableString* userNameStr = [NSMutableString stringWithPRUnichars:*username]; - NSMutableString* passwordStr = [NSMutableString stringWithPRUnichars:*password]; - - BOOL valueBool; - if (checkValue) { - valueBool = *checkValue ? YES : NO; - } - NSWindow* window = GetNSWindowForDOMWindow(parent); - - *_retval = (PRBool)[controller promptUserNameAndPassword:window title:titleStr text:textStr userNameText:userNameStr passwordText:passwordStr checkMsg:msgStr checkValue:&valueBool doCheck:(checkValue != nsnull)]; - - if (checkValue) { - *checkValue = (valueBool == YES) ? PR_TRUE : PR_FALSE; - } - - PRUint32 length = [userNameStr length]; - PRUnichar* retStr = (PRUnichar*)nsMemory::Alloc((length + 1) * sizeof(PRUnichar)); - [userNameStr getCharacters:retStr]; - retStr[length] = PRUnichar(0); - *username = retStr; - - length = [passwordStr length]; - retStr = (PRUnichar*)nsMemory::Alloc((length + 1) * sizeof(PRUnichar)); - [passwordStr getCharacters:retStr]; - retStr[length] = PRUnichar(0); - *password = retStr; - - return NS_OK; -} - -/* boolean promptPassword (in nsIDOMWindow parent, in wstring dialogTitle, in wstring text, inout wstring password, in wstring checkMsg, inout boolean checkValue); */ -NS_IMETHODIMP -CocoaPromptService::PromptPassword(nsIDOMWindow *parent, - const PRUnichar *dialogTitle, - const PRUnichar *text, - PRUnichar **password, - const PRUnichar *checkMsg, - PRBool *checkValue, - PRBool *_retval) -{ - nsAlertController* controller = nsCocoaBrowserService::GetAlertController(); - if (!controller) { - return NS_ERROR_FAILURE; - } - - NSString* titleStr = [NSString stringWithPRUnichars:dialogTitle]; - NSString* textStr = [NSString stringWithPRUnichars:text]; - NSString* msgStr = [NSString stringWithPRUnichars:checkMsg]; - NSMutableString* passwordStr = [NSMutableString stringWithPRUnichars:*password]; - - BOOL valueBool; - if (checkValue) { - valueBool = *checkValue ? YES : NO; - } - NSWindow* window = GetNSWindowForDOMWindow(parent); - - *_retval = (PRBool)[controller promptPassword:window title:titleStr text:textStr passwordText:passwordStr checkMsg:msgStr checkValue:&valueBool doCheck:(checkValue != nsnull)]; - - if (checkValue) { - *checkValue = (valueBool == YES) ? PR_TRUE : PR_FALSE; - } - - PRUint32 length = [passwordStr length]; - PRUnichar* retStr = (PRUnichar*)nsMemory::Alloc((length + 1) * sizeof(PRUnichar)); - [passwordStr getCharacters:retStr]; - retStr[length] = PRUnichar(0); - *password = retStr; - - return NS_OK; -} - -/* boolean select (in nsIDOMWindow parent, in wstring dialogTitle, in wstring text, in PRUint32 count, [array, size_is (count)] in wstring selectList, out long outSelection); */ -NS_IMETHODIMP -CocoaPromptService::Select(nsIDOMWindow *parent, - const PRUnichar *dialogTitle, - const PRUnichar *text, - PRUint32 count, - const PRUnichar **selectList, - PRInt32 *outSelection, - PRBool *_retval) -{ -#if DEBUG - NSLog(@"Uh-oh. Select has not been implemented."); -#endif - return NS_ERROR_NOT_IMPLEMENTED; -} - - -NSWindow* -CocoaPromptService::GetNSWindowForDOMWindow(nsIDOMWindow* window) -{ - nsCOMPtr watcher(do_GetService("@mozilla.org/embedcomp/window-watcher;1")); - if (!watcher) { - return nsnull; - } - - nsCOMPtr chrome; - watcher->GetChromeForWindow(window, getter_AddRefs(chrome)); - if (!chrome) { - return nsnull; - } - - nsCOMPtr siteWindow(do_QueryInterface(chrome)); - if (!siteWindow) { - return nsnull; - } - - NSWindow* nswin; - nsresult rv = siteWindow->GetSiteWindow((void**)&nswin); - if (NS_FAILED(rv)) - return nsnull; - - return nswin; -} - -NSString * -CocoaPromptService::GetCommonDialogLocaleString(const char *key) -{ - NSString *returnValue = @""; - - nsresult rv; - if (!mCommonDialogStringBundle) { -#define kCommonDialogsStrings "chrome://global/locale/commonDialogs.properties" - nsCOMPtr service = do_GetService(NS_STRINGBUNDLE_CONTRACTID); - if ( service ) - rv = service->CreateBundle(kCommonDialogsStrings, getter_AddRefs(mCommonDialogStringBundle)); - else - rv = NS_ERROR_FAILURE; - if (NS_FAILED(rv)) return returnValue; - } - - nsXPIDLString string; - rv = mCommonDialogStringBundle->GetStringFromName(NS_ConvertASCIItoUCS2(key).get(), getter_Copies(string)); - if (NS_FAILED(rv)) return returnValue; - - returnValue = [NSString stringWithPRUnichars:string]; - return returnValue; -} - -NSString * -CocoaPromptService::GetButtonStringFromFlags(PRUint32 btnFlags, - PRUint32 btnIDAndShift, - const PRUnichar *btnTitle) -{ - NSString *btnStr = nsnull; - switch ((btnFlags >> btnIDAndShift) & 0xff) { - case BUTTON_TITLE_OK: - btnStr = GetCommonDialogLocaleString("OK"); - break; - case BUTTON_TITLE_CANCEL: - btnStr = GetCommonDialogLocaleString("Cancel"); - break; - case BUTTON_TITLE_YES: - btnStr = GetCommonDialogLocaleString("Yes"); - break; - case BUTTON_TITLE_NO: - btnStr = GetCommonDialogLocaleString("No"); - break; - case BUTTON_TITLE_SAVE: - btnStr = GetCommonDialogLocaleString("Save"); - break; - case BUTTON_TITLE_DONT_SAVE: - btnStr = GetCommonDialogLocaleString("DontSave"); - break; - case BUTTON_TITLE_REVERT: - btnStr = GetCommonDialogLocaleString("Revert"); - break; - case BUTTON_TITLE_IS_STRING: - btnStr = [NSString stringWithPRUnichars:btnTitle]; - } - - return btnStr; -} diff --git a/mozilla/camino/ContentClickListener.h b/mozilla/camino/ContentClickListener.h deleted file mode 100644 index e7ca6ffa54b..00000000000 --- a/mozilla/camino/ContentClickListener.h +++ /dev/null @@ -1,69 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape 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/NPL/ - * - * 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 mozilla.org 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 NPL, 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 NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef __ContentClickListener_h__ -#define __ContentClickListener_h__ - -#include -#include - -#include "nsIDOMMouseListener.h" -#import "BrowserWindowController.h" - -class ContentClickListener : public nsIDOMMouseListener -{ -public: - ContentClickListener(id aBrowserController); - virtual ~ContentClickListener(); - - NS_DECL_ISUPPORTS - - // The DOM mouse listener interface. We only care about clicks. - NS_IMETHOD HandleEvent(nsIDOMEvent* aEvent) { return NS_OK; }; - NS_IMETHOD MouseDown(nsIDOMEvent* aMouseEvent); - NS_IMETHOD MouseUp(nsIDOMEvent* aMouseEvent) { return NS_OK; }; - NS_IMETHOD MouseClick(nsIDOMEvent* aMouseEvent); - NS_IMETHOD MouseDblClick(nsIDOMEvent* aMouseEvent) { return NS_OK; }; - NS_IMETHOD MouseOver(nsIDOMEvent* aMouseEvent) { return NS_OK; }; - NS_IMETHOD MouseOut(nsIDOMEvent* aMouseEvent) { return NS_OK; }; - -private: - BrowserWindowController* mBrowserController; // Our browser controller (weakly held) -}; - - -#endif diff --git a/mozilla/camino/ContentClickListener.mm b/mozilla/camino/ContentClickListener.mm deleted file mode 100644 index 3e9d997e30c..00000000000 --- a/mozilla/camino/ContentClickListener.mm +++ /dev/null @@ -1,311 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape 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/NPL/ - * - * 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 mozilla.org 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): - * David Hyatt (Original Author) - * - * 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 NPL, 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 NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#import "NSString+Utils.h" - -#include "nsCOMPtr.h" -#include "ContentClickListener.h" -#include "nsIDOMEventTarget.h" -#include "nsIContent.h" -#include "nsIAtom.h" -#include "nsIDOMElement.h" -#include "nsString.h" -#include "nsUnicharUtils.h" -#include "nsIPrefBranch.h" -#include "nsIDOMMouseEvent.h" -#include "nsEmbedAPI.h" -#include "nsIDOMDocument.h" -#include "nsIDOMDocumentEvent.h" -#include "nsIDOMEventTarget.h" -#include "nsIDOMNSHTMLElement.h" -#include "nsIDOMHTMLSelectElement.h" -#include "nsIDOMHTMLOptionElement.h" -#include "nsIDOMHTMLCollection.h" -#include "nsIDOMWindow.h" -#include "nsIScriptGlobalObject.h" -#include "nsIDocument.h" -#include "nsIPresShell.h" -#include "nsIPresContext.h" -#include "nsIFrame.h" -#include "nsIView.h" -#include "nsIWidget.h" -#include "nsIURI.h" -#include "nsIProtocolHandler.h" -#include "nsNetUtil.h" - -// Common helper routines (also used by the context menu code) -#include "CHGeckoUtils.h" - -#import "CHBrowserView.h" - -static void FindOptionWithContentID(nsIDOMHTMLSelectElement* aSel, PRUint32 aID, nsIDOMHTMLOptionElement** aResult) -{ - *aResult = nsnull; - nsCOMPtr options; - aSel->GetOptions(getter_AddRefs(options)); - PRUint32 count; - options->GetLength(&count); - for (PRUint32 i = 0; i < count; i++) { - nsCOMPtr node; - options->Item(i, getter_AddRefs(node)); - PRUint32 contentID; - nsCOMPtr content(do_QueryInterface(node)); - content->GetContentID(&contentID); - if (contentID == aID) { - nsCOMPtr option(do_QueryInterface(node)); - *aResult = option; - NS_ADDREF(*aResult); - break; - } - } -} - -@interface CHOptionSelector : NSObject -{ - nsIDOMHTMLSelectElement* mSelectElt; -} - --(id)initWithSelect:(nsIDOMHTMLSelectElement*)aSel; --(IBAction)selectOption:(id)aSender; - -@end - -@implementation CHOptionSelector - --(id)initWithSelect:(nsIDOMHTMLSelectElement*)aSel -{ - if ( (self = [super init]) ) { - mSelectElt = aSel; - } - return self; -} - --(IBAction)selectOption:(id)aSender -{ - int tag = [aSender tag]; - nsCOMPtr optionElt; - FindOptionWithContentID(mSelectElt, tag, getter_AddRefs(optionElt)); - optionElt->SetSelected(PR_TRUE); - [self autorelease]; // Free up ourselves. - [[aSender menu] autorelease]; // Free up the menu. - - // Fire a DOM event for the title change. - nsCOMPtr event; - nsCOMPtr domDocument; - mSelectElt->GetOwnerDocument(getter_AddRefs(domDocument)); - nsCOMPtr docEvent(do_QueryInterface(domDocument)); - - docEvent->CreateEvent(NS_LITERAL_STRING("Events"), getter_AddRefs(event)); - if (event) { - event->InitEvent(NS_LITERAL_STRING("change"), PR_TRUE, PR_TRUE); - PRBool noDefault; - nsCOMPtr target(do_QueryInterface(mSelectElt)); - target->DispatchEvent(event, &noDefault); - } -} - -@end - -NS_IMPL_ISUPPORTS2(ContentClickListener, nsIDOMMouseListener, nsIDOMEventListener); - -ContentClickListener::ContentClickListener(id aBrowserController) -:mBrowserController(aBrowserController) -{ - NS_INIT_ISUPPORTS(); -} - -ContentClickListener::~ContentClickListener() -{ - -} - -NS_IMETHODIMP -ContentClickListener::MouseDown(nsIDOMEvent* aEvent) -{ - nsCOMPtr target; - aEvent->GetTarget(getter_AddRefs(target)); - if (!target) - return NS_OK; - nsCOMPtr sel(do_QueryInterface(target)); - if (sel) { - NSMenu* menu = [[NSMenu alloc] init]; // Retain the menu. - nsCOMPtr options; - sel->GetOptions(getter_AddRefs(options)); - PRUint32 count; - options->GetLength(&count); - PRInt32 selIndex = 0; - for (PRUint32 i = 0; i < count; i++) { - nsCOMPtr node; - options->Item(i, getter_AddRefs(node)); - PRUint32 contentID; - nsCOMPtr content(do_QueryInterface(node)); - content->GetContentID(&contentID); - nsCOMPtr option(do_QueryInterface(node)); - nsAutoString text; - option->GetLabel(text); - if (text.IsEmpty()) - option->GetText(text); - NSString* title = [[NSString stringWith_nsAString: text] stringByTruncatingTo:75 at:kTruncateAtMiddle]; - NSMenuItem* menuItem = [[[NSMenuItem alloc] initWithTitle: title action: NULL keyEquivalent: @""] autorelease]; - [menu addItem: menuItem]; - [menuItem setTag: contentID]; - PRBool selected; - option->GetSelected(&selected); - if (selected) { - [menuItem setState: NSOnState]; - selIndex = i; - } - CHOptionSelector* optSelector = [[CHOptionSelector alloc] initWithSelect: sel]; - [menuItem setTarget: optSelector]; - [menuItem setAction: @selector(selectOption:)]; - } - - nsCOMPtr nsSel(do_QueryInterface(sel)); - PRInt32 left, top, height; - PRInt32 clientX, clientY; - nsSel->GetOffsetLeft(&left); - nsSel->GetOffsetTop(&top); - nsSel->GetOffsetHeight(&height); - - nsCOMPtr currOffsetParent; - nsSel->GetOffsetParent(getter_AddRefs(currOffsetParent)); - while (currOffsetParent) { - nsCOMPtr currNS(do_QueryInterface(currOffsetParent)); - PRInt32 currLeft, currTop; - currNS->GetOffsetLeft(&currLeft); - currNS->GetOffsetTop(&currTop); - left += currLeft; - top += currTop; - currNS->GetOffsetParent(getter_AddRefs(currOffsetParent)); - } - - nsCOMPtr msEvent(do_QueryInterface(aEvent)); - msEvent->GetClientX(&clientX); - msEvent->GetClientY(&clientY); - - PRInt32 xDelta = clientX - left; - PRInt32 yDelta = top + height - clientY; - - nsCOMPtr window = getter_AddRefs([[[mBrowserController getBrowserWrapper] getBrowserView] getContentWindow]); - PRInt32 scrollX, scrollY; - window->GetScrollX(&scrollX); - window->GetScrollY(&scrollY); - xDelta += scrollX; // Normal direction. - yDelta -= scrollY; // Remember, y is flipped. - -#define XMENUOFFSET 20 -#define MENUHEIGHT 20 - - xDelta += XMENUOFFSET; - yDelta -= MENUHEIGHT*(selIndex+1); - - NSEvent* event = [NSApp currentEvent]; - NSPoint point = [event locationInWindow]; - point.x -= xDelta; - point.y -= yDelta; - - NSEvent* mouseEvent = [NSEvent mouseEventWithType: NSLeftMouseDown location: point - modifierFlags: 0 timestamp: [event timestamp] - windowNumber: [event windowNumber] context: [event context] - eventNumber: [event eventNumber] clickCount: [event clickCount] pressure: [event pressure]]; - - [NSMenu popUpContextMenu: menu withEvent: mouseEvent forView: [[mBrowserController window] contentView]]; - - } - return NS_OK; -} - -NS_IMETHODIMP -ContentClickListener::MouseClick(nsIDOMEvent* aEvent) -{ - nsCOMPtr target; - aEvent->GetTarget(getter_AddRefs(target)); - if (!target) - return NS_OK; - nsCOMPtr content(do_QueryInterface(target)); - - nsCOMPtr linkContent; - nsAutoString href; - CHGeckoUtils::GetEnclosingLinkElementAndHref(content, getter_AddRefs(linkContent), href); - - // XXXdwh Handle simple XLINKs if we want to be compatible with Mozilla, but who - // really uses these anyway? :) - if (!linkContent || href.IsEmpty()) - return NS_OK; - - nsCOMPtr pref(do_GetService("@mozilla.org/preferences-service;1")); - if (!pref) - return NS_OK; // Something bad happened if we can't get prefs. - - PRUint16 button; - nsCOMPtr mouseEvent(do_QueryInterface(aEvent)); - mouseEvent->GetButton(&button); - - PRBool metaKey, shiftKey, altKey; - mouseEvent->GetMetaKey(&metaKey); - mouseEvent->GetShiftKey(&shiftKey); - mouseEvent->GetAltKey(&altKey); - - NSString* hrefStr = [NSString stringWith_nsAString: href]; - - if ((metaKey && button == 0) || button == 1) { - // The command key is down or we got a middle click. Open the link in a new window or tab. - PRBool useTab; - pref->GetBoolPref("browser.tabs.opentabfor.middleclick", &useTab); - PRBool loadInBackground; - pref->GetBoolPref("browser.tabs.loadInBackground", &loadInBackground); - NSString* referrer = [[[mBrowserController getBrowserWrapper] getBrowserView] getFocusedURLString]; - - if (shiftKey) - loadInBackground = !loadInBackground; - if (useTab && [mBrowserController newTabsAllowed]) - [mBrowserController openNewTabWithURL: hrefStr referrer:referrer loadInBackground: loadInBackground]; - else - [mBrowserController openNewWindowWithURL: hrefStr referrer:referrer loadInBackground: loadInBackground]; - } - else if (altKey) { - // The user wants to save this link. - nsAutoString text; - CHGeckoUtils::GatherTextUnder(content, text); - - [mBrowserController saveURL: nil filterList: nil - url: hrefStr suggestedFilename: [NSString stringWith_nsAString: text]]; - } - - return NS_OK; -} diff --git a/mozilla/camino/Credits.rtf b/mozilla/camino/Credits.rtf deleted file mode 100644 index ca73f055b1e..00000000000 --- a/mozilla/camino/Credits.rtf +++ /dev/null @@ -1,74 +0,0 @@ -{\rtf1\mac\ansicpg10000\cocoartf100 -{\fonttbl\f0\fswiss\fcharset77 Optima-BoldItalic;\f1\fswiss\fcharset77 Optima-Italic;\f2\fswiss\fcharset77 Optima-Regular; -\f3\fswiss\fcharset77 Optima-Bold;} -{\colortbl;\red255\green255\blue255;} -\pard\tx1440\tx2880\tx4320\tx5760\tx7200\ql\qnatural - -\f0\i\b\fs18 \cf0 \ - -\fs68 Navigator 0.4.0\ - -\f1\b0\fs24 \ -\ -\ -\ -\ -\ -\ -\ - -\f2\i0 Navigator version 0.4.0\ -http://www.mozilla.org\ -http://chimera.mozdev.org\ - -\fs48 \ - \ - \ - \ -\ - -\f0\i\b\fs28 Contributors:\ - -\f2\i0\b0\fs24 \ - -\f3\b Patrick Beard\ - Kathy Brade\ - Conrad Carlen\ - Ugo Dantas De Santana\ - Simon Fraser\ - Ben Goodger\ - David Haas\ - Joe Hewitt\ - Max Horn -\f2\b0 \ - -\f3\b David Hyatt -\f2\b0 \ - -\f3\b Matt Judy\ - Mike Pinkerton\ - Brian Ryner\ - Richard Schreyer\ - William Dell Wisner\ -\ - Mozilla Contributors:\ - Type \'d2about:credits\'d3 in the Location bar.\ - -\f2\b0 \ -\ -\ -\ - -\fs48 \ - -\f0\i\b\fs28 Special Thanks:\ - -\f2\i0\b0\fs24 \ - -\f3\b Apple Computer Software Engineering\ - The Chimera Mailing List\ - -\f1\i\b0\fs36 \ -\ -\ -} \ No newline at end of file diff --git a/mozilla/camino/DownloadFactories.h b/mozilla/camino/DownloadFactories.h deleted file mode 100644 index 35b5ed5ee8d..00000000000 --- a/mozilla/camino/DownloadFactories.h +++ /dev/null @@ -1,47 +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): - * Simon Fraser - * - * 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 ***** */ - -#include "nscore.h" - -// embedding app's factories for creating instances of interfaces -// related to downloading. - -class nsIFactory; - -nsresult NewDownloadListenerFactory(nsIFactory* *outFactory); - -//nsresult NewHelperAppLauncherDialogFactory(nsIFactory* *outFactory); diff --git a/mozilla/camino/DownloadFactories.mm b/mozilla/camino/DownloadFactories.mm deleted file mode 100644 index e68a8d369a5..00000000000 --- a/mozilla/camino/DownloadFactories.mm +++ /dev/null @@ -1,120 +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): - * Simon Fraser - * - * 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 ***** */ - -// This file contains implementations of factories for various -// downloading-related interfaces. - -#import "DownloadProgressDisplay.h" -#import "ProgressDlgController.h" - -#include "nsCOMPtr.h" -#include "nsIFactory.h" - -#include "nsDownloadListener.h" -#include "DownloadFactories.h" - -// factory for nsIDownload objects -// XXX replace with generic factory stuff -class DownloadListenerFactory : public nsIFactory -{ -public: - DownloadListenerFactory(); - virtual ~DownloadListenerFactory(); - - NS_DECL_ISUPPORTS - NS_DECL_NSIFACTORY - -protected: - - DownloadControllerFactory* mControllerFactory; // factory which creates the Cocoa window controller -}; - - -DownloadListenerFactory::DownloadListenerFactory() -: mControllerFactory(nil) -{ - NS_INIT_ISUPPORTS(); - mControllerFactory = [[ChimeraDownloadControllerFactory alloc] init]; -} - -DownloadListenerFactory::~DownloadListenerFactory() -{ - [mControllerFactory release]; -} - -NS_IMPL_ISUPPORTS1(DownloadListenerFactory, nsIFactory); - -/* void createInstance (in nsISupports aOuter, in nsIIDRef iid, [iid_is (iid), retval] out nsQIResult result); */ -NS_IMETHODIMP -DownloadListenerFactory::CreateInstance(nsISupports *aOuter, const nsIID& aIID, void* *aResult) -{ - nsresult rv; - - if (aIID.Equals(NS_GET_IID(nsIDownload))) - { - nsDownloadListener* downloadListener = new nsDownloadListener(mControllerFactory); - if (!downloadListener) return NS_ERROR_OUT_OF_MEMORY; - - NS_ADDREF(downloadListener); - rv = downloadListener->QueryInterface(aIID, aResult); - NS_RELEASE(downloadListener); - return rv; - } - - return NS_ERROR_NO_INTERFACE; -} - -/* void lockFactory (in PRBool lock); */ -NS_IMETHODIMP -DownloadListenerFactory::LockFactory(PRBool lock) -{ - return NS_OK; -} - -#pragma mark - - -nsresult NewDownloadListenerFactory(nsIFactory* *outFactory) -{ - DownloadListenerFactory* newFactory = new DownloadListenerFactory(); - if (!newFactory) return NS_ERROR_OUT_OF_MEMORY; - - NS_ADDREF(newFactory); - nsresult rv = newFactory->QueryInterface(NS_GET_IID(nsIFactory), (void **)outFactory); - NS_RELEASE(newFactory); - return rv; -} - diff --git a/mozilla/camino/DownloadProgressDisplay.h b/mozilla/camino/DownloadProgressDisplay.h deleted file mode 100644 index fc1fe6ce074..00000000000 --- a/mozilla/camino/DownloadProgressDisplay.h +++ /dev/null @@ -1,167 +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): - * Simon Fraser - * - * 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 ***** */ - -/* - The classes and protocol in this file allow Cocoa applications to easily - reuse the underlying download implementation, which deals with the complexity - of Gecko's downloading callbacks. - - There are three things here: - - 1. The DownloadProgressDisplay protocol. - - This is a formal protocol that needs to be implemented by - a window controller for your progress window. Its methods - will be called by the underlying C++ downloading classes. - - 2. The Obj-C DownloadControllerFactory class. - - This class should be subclassed by an embedder, with an - implementation of 'createDownloadController' that hands back - a new instance of an NSWindowController that implements the - protocol. - - The underlying C++ classes use this factory to create the - progress window controller. - - 3. The CHDownloader C++ class - - This base class exists to hide the complextity of the download - listener classes (which deal with Gecko callbacks) from the - window controller. Embedders don't need to do anything with it. - - How these classes fit together: - - There are 2 ways in which a download is initiated: - - (i) File->Save. - - Chimera does a complex dance here in order to get certain - information about the data being downloaded (it needs to - start the download before it can read some optional MIME headers). - - CBrowserView creates an nsIWebBrowserPersist (WBP), and then a - nsHeaderSniffer, which implements nsIWebProgressListener and is set to - observer the WBP. When nsHeaderSniffer hears about the start of the - download, it decides on a file name, and what format to save the data - in. It then cancels the current WPB, makes another one, and does - a CreateInstance of an nsIDownload (making one of our nsDownloadListener - -- aka nsDownloder -- objects), and sets that as the nsIWebProgressListener. - The full download procedes from there. - - (ii) Click to download (e.g. FTP link) - - This is simpler. The backend (necko) does the CreateInstance of the - nsIDownload, and the download progresses. - - In both cases, creating the nsDownloadListener and calling its Init() method - calls nsDownloder::CreateDownloadDisplay(). The nsDownloder has as a member - variable a DownloadControllerFactory (see above), which got passed to it - via our XPCOM factory for nsIDownload objects. It then uses that DownloadControllerFactory - to get an instance of the download progress window controller, which then - shows the download progress window. - - Simple, eh? - -*/ - -#import - -#include "nsISupports.h" - -class CHDownloader; - -// a formal protocol for something that implements progress display -// Embedders can make a window controller that conforms to this -// protocol, and reuse nsDownloadListener to get download UI. -@protocol DownloadProgressDisplay - -- (void)onStartDownload:(BOOL)isFileSave; -- (void)onEndDownload; - -- (void)setProgressTo:(long)aCurProgress ofMax:(long)aMaxProgress; - -- (void)setDownloadListener:(CHDownloader*)aDownloader; -- (void)setSourceURL:(NSString*)aSourceURL; -- (void)setDestinationPath:(NSString*)aDestPath; - -@end - -// subclass this, and have your subclass instantiate and return your window -// controller in createDownloadController -@interface DownloadControllerFactory : NSObject -{ -} - -- (NSWindowController *)createDownloadController; - -@end - - -// Pure virtual base class for a generic downloader, that the progress UI can talk to. -// It implements nsISupports so that it can be refcounted. This class insulates the -// UI code from having to know too much about the nsIDownloadListener. -// It is responsible for creating the download UI, via the DownloadControllerFactory -// that it owns. -class CHDownloader : public nsISupports -{ -public: - CHDownloader(DownloadControllerFactory* inControllerFactory); - virtual ~CHDownloader(); - - NS_DECL_ISUPPORTS - - virtual void PauseDownload() = 0; - virtual void ResumeDownload() = 0; - virtual void CancelDownload() = 0; - virtual void DownloadDone() = 0; - virtual void DetachDownloadDisplay() = 0; // tell downloader to forget about its display - - virtual void CreateDownloadDisplay(); - -protected: - - PRBool IsFileSave() { return mIsFileSave; } - void SetIsFileSave(PRBool inIsFileSave) { mIsFileSave = inIsFileSave; } - -protected: - - DownloadControllerFactory* mControllerFactory; - id mDownloadDisplay; // something that implements the DownloadProgressDisplay protocol - PRBool mIsFileSave; // true if we're doing a save, rather than a download -}; - diff --git a/mozilla/camino/DownloadProgressDisplay.mm b/mozilla/camino/DownloadProgressDisplay.mm deleted file mode 100644 index 4dac500c85b..00000000000 --- a/mozilla/camino/DownloadProgressDisplay.mm +++ /dev/null @@ -1,76 +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): - * Simon Fraser - * - * 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 "DownloadProgressDisplay.h" - - -@implementation DownloadControllerFactory - -- (NSWindowController *)createDownloadController -{ - // a dummy implementation. You should provide a subclass that - // returns an instance of your progress dialog controller. - return nil; -} - -@end - -#pragma mark - - -// see the header file for comments -CHDownloader::CHDownloader(DownloadControllerFactory* inControllerFactory) -: mControllerFactory(inControllerFactory) -, mDownloadDisplay(nil) -, mIsFileSave(PR_FALSE) -{ - NS_INIT_ISUPPORTS(); - [mControllerFactory retain]; -} - -CHDownloader::~CHDownloader() -{ - [mControllerFactory release]; -} - -NS_IMPL_ISUPPORTS1(CHDownloader, nsISupports); - -void -CHDownloader::CreateDownloadDisplay() -{ - mDownloadDisplay = [mControllerFactory createDownloadController]; - [mDownloadDisplay setDownloadListener:this]; -} diff --git a/mozilla/camino/English.lproj/AboutBox.nib/classes.nib b/mozilla/camino/English.lproj/AboutBox.nib/classes.nib deleted file mode 100644 index e9180430bcc..00000000000 --- a/mozilla/camino/English.lproj/AboutBox.nib/classes.nib +++ /dev/null @@ -1,17 +0,0 @@ -{ - IBClasses = ( - { - ACTIONS = {showPanel = id; }; - CLASS = AboutBox; - LANGUAGE = ObjC; - OUTLETS = { - buildNumberField = NSTextField; - creditsField = NSTextView; - window = NSWindow; - }; - SUPERCLASS = NSObject; - }, - {CLASS = FirstResponder; LANGUAGE = ObjC; SUPERCLASS = NSObject; } - ); - IBVersion = 1; -} \ No newline at end of file diff --git a/mozilla/camino/English.lproj/AboutBox.nib/info.nib b/mozilla/camino/English.lproj/AboutBox.nib/info.nib deleted file mode 100644 index 4df25655e54..00000000000 --- a/mozilla/camino/English.lproj/AboutBox.nib/info.nib +++ /dev/null @@ -1,18 +0,0 @@ - - - - - IBFramework Version - 248.0 - IBLockedObjects - - 7 - - IBOpenObjects - - 5 - - IBSystem Version - 5S66 - - diff --git a/mozilla/camino/English.lproj/AboutBox.nib/objects.nib b/mozilla/camino/English.lproj/AboutBox.nib/objects.nib deleted file mode 100644 index 8c1c2d1f930..00000000000 Binary files a/mozilla/camino/English.lproj/AboutBox.nib/objects.nib and /dev/null differ diff --git a/mozilla/camino/English.lproj/BookmarkInfoPanel.nib/classes.nib b/mozilla/camino/English.lproj/BookmarkInfoPanel.nib/classes.nib deleted file mode 100644 index 7cb6777f984..00000000000 --- a/mozilla/camino/English.lproj/BookmarkInfoPanel.nib/classes.nib +++ /dev/null @@ -1,22 +0,0 @@ -{ - IBClasses = ( - { - CLASS = BookmarkInfoController; - LANGUAGE = ObjC; - OUTLETS = { - mDescriptionField = NSTextField; - mDescriptionLabel = NSTextField; - mKeywordField = NSTextField; - mKeywordLabel = NSTextField; - mLocationField = NSTextField; - mLocationLabel = NSTextField; - mNameField = NSTextField; - mNameLabel = NSTextField; - }; - SUPERCLASS = NSWindowController; - }, - {CLASS = BookmarkItem; LANGUAGE = ObjC; SUPERCLASS = NSObject; }, - {CLASS = FirstResponder; LANGUAGE = ObjC; SUPERCLASS = NSObject; } - ); - IBVersion = 1; -} \ No newline at end of file diff --git a/mozilla/camino/English.lproj/BookmarkInfoPanel.nib/info.nib b/mozilla/camino/English.lproj/BookmarkInfoPanel.nib/info.nib deleted file mode 100644 index b8cd244ab7f..00000000000 --- a/mozilla/camino/English.lproj/BookmarkInfoPanel.nib/info.nib +++ /dev/null @@ -1,12 +0,0 @@ - - - - - IBDocumentLocation - 144 74 366 258 0 0 1280 1002 - IBFramework Version - 248.0 - IBSystem Version - 5S66 - - diff --git a/mozilla/camino/English.lproj/BookmarkInfoPanel.nib/objects.nib b/mozilla/camino/English.lproj/BookmarkInfoPanel.nib/objects.nib deleted file mode 100644 index 5541b6caeaa..00000000000 Binary files a/mozilla/camino/English.lproj/BookmarkInfoPanel.nib/objects.nib and /dev/null differ diff --git a/mozilla/camino/English.lproj/BrowserWindow.nib/classes.nib b/mozilla/camino/English.lproj/BrowserWindow.nib/classes.nib deleted file mode 100644 index 9d9409b58ee..00000000000 --- a/mozilla/camino/English.lproj/BrowserWindow.nib/classes.nib +++ /dev/null @@ -1,141 +0,0 @@ -{ - IBClasses = ( - {CLASS = AutoCompleteDataSource; LANGUAGE = ObjC; SUPERCLASS = NSObject; }, - { - ACTIONS = {onBlur = id; onResize = id; }; - CLASS = AutoCompleteTextField; - LANGUAGE = ObjC; - OUTLETS = {mProxyIcon = PageProxyIcon; }; - SUPERCLASS = NSTextField; - }, - {CLASS = BookmarkItem; LANGUAGE = ObjC; SUPERCLASS = NSObject; }, - { - ACTIONS = { - addBookmark = id; - addFolder = id; - deleteBookmarks = id; - openBookmarkInNewTab = id; - openBookmarkInNewWindow = id; - showBookmarkInfo = id; - }; - CLASS = BookmarksDataSource; - LANGUAGE = ObjC; - OUTLETS = { - mBrowserWindowController = id; - mDeleteBookmarkButton = id; - mEditBookmarkButton = id; - mOutlineView = id; - }; - SUPERCLASS = NSObject; - }, - { - CLASS = BookmarksOutlineView; - LANGUAGE = ObjC; - SUPERCLASS = ExtendedOutlineView; - }, - {CLASS = BookmarksToolbar; LANGUAGE = ObjC; SUPERCLASS = NSView; }, - {CLASS = BrowserTabView; LANGUAGE = ObjC; SUPERCLASS = NSTabView; }, - { - CLASS = BrowserWindow; - LANGUAGE = ObjC; - OUTLETS = {mAutoCompleteTextField = id; }; - SUPERCLASS = NSWindow; - }, - { - ACTIONS = { - back = id; - bookmarkLink = id; - bookmarkPage = id; - cancelAddBookmarkSheet = id; - cancelLocationSheet = id; - copyLinkLocation = id; - endAddBookmarkSheet = id; - endLocationSheet = id; - forward = id; - goToLocationFromToolbarURLField = id; - home = id; - manageBookmarks = id; - openLinkInNewTab = id; - openLinkInNewWindow = id; - performSearch = id; - printDocument = id; - reload = id; - saveImageAs = id; - saveLinkAs = id; - savePageAs = id; - stop = id; - toggleSidebar = id; - viewOnlyThisImage = id; - viewSource = id; - }; - CLASS = BrowserWindowController; - LANGUAGE = ObjC; - OUTLETS = { - mAddBookmarkCheckbox = NSButton; - mAddBookmarkFolderField = NSPopUpButton; - mAddBookmarkSheetWindow = NSWindow; - mAddBookmarkTitleField = NSTextField; - mBackItem = NSMenuItem; - mCachedBMDS = id; - mForwardItem = NSMenuItem; - mHistoryDataSource = HistoryDataSource; - mImageLinkMenu = NSMenu; - mImageMenu = NSMenu; - mInputMenu = NSMenu; - mLinkMenu = NSMenu; - mLocationSheetURLField = NSTextField; - mLocationSheetWindow = NSWindow; - mLocationToolbarView = NSView; - mLock = NSImageView; - mPageMenu = NSMenu; - mPersonalToolbar = BookmarksToolbar; - mProgress = NSProgressIndicator; - mProxyIcon = NSImageView; - mSidebarBookmarksDataSource = BookmarksDataSource; - mSidebarBrowserView = id; - mSidebarDrawer = NSDrawer; - mSidebarSourceTabView = NSTabView; - mSidebarTabView = NSTabView; - mStatus = NSTextField; - mStatusBar = NSView; - mTabBrowser = BrowserTabView; - mURLBar = NSTextField; - }; - SUPERCLASS = NSWindowController; - }, - { - ACTIONS = {load = id; }; - CLASS = BrowserWrapper; - LANGUAGE = ObjC; - OUTLETS = { - mLockIcon = id; - mWindowController = id; - progress = id; - progressSuper = id; - status = id; - urlbar = id; - }; - SUPERCLASS = NSView; - }, - {CLASS = ExtendedOutlineView; LANGUAGE = ObjC; SUPERCLASS = NSOutlineView; }, - {CLASS = FirstResponder; LANGUAGE = ObjC; SUPERCLASS = NSObject; }, - { - CLASS = HistoryDataSource; - LANGUAGE = ObjC; - OUTLETS = {mBrowserWindowController = id; }; - SUPERCLASS = RDFOutlineViewDataSource; - }, - {CLASS = LocationBar; LANGUAGE = ObjC; SUPERCLASS = NSView; }, - {CLASS = MainController; LANGUAGE = ObjC; SUPERCLASS = NSObject; }, - {CLASS = PageProxyIcon; LANGUAGE = ObjC; SUPERCLASS = NSImageView; }, - { - CLASS = RDFOutlineViewDataSource; - LANGUAGE = ObjC; - OUTLETS = {mOutlineView = id; }; - SUPERCLASS = NSObject; - }, - {CLASS = RDFOutlineViewItem; LANGUAGE = ObjC; SUPERCLASS = NSObject; }, - {CLASS = ThrobberHandler; LANGUAGE = ObjC; SUPERCLASS = NSObject; } - ); - IBVersion = 1; -} \ No newline at end of file diff --git a/mozilla/camino/English.lproj/BrowserWindow.nib/info.nib b/mozilla/camino/English.lproj/BrowserWindow.nib/info.nib deleted file mode 100644 index 9fccdc6b397..00000000000 --- a/mozilla/camino/English.lproj/BrowserWindow.nib/info.nib +++ /dev/null @@ -1,45 +0,0 @@ - - - - - IBDocumentLocation - 172 80 630 599 0 0 1280 1002 - IBEditorPositions - - 124 - 345 803 170 144 0 0 1280 1002 - 160 - 165 292 195 666 0 0 1280 1002 - 28 - 524 439 195 457 0 0 1280 1002 - 297 - 233 646 176 162 0 0 1152 848 - 314 - 418 732 139 66 0 0 1152 848 - 336 - 630 666 200 132 0 0 1152 848 - 365 - 22 587 93 162 0 0 1152 848 - 463 - 22 619 200 180 0 0 1152 848 - 56 - 450 634 343 68 0 0 1280 1002 - - IBFramework Version - 248.0 - IBGroupedObjects - - 3 - - 8 - 9 - - - IBLastGroupID - 4 - IBLockedObjects - - IBSystem Version - 5S66 - - diff --git a/mozilla/camino/English.lproj/BrowserWindow.nib/objects.nib b/mozilla/camino/English.lproj/BrowserWindow.nib/objects.nib deleted file mode 100644 index bb73395d197..00000000000 Binary files a/mozilla/camino/English.lproj/BrowserWindow.nib/objects.nib and /dev/null differ diff --git a/mozilla/camino/English.lproj/FindDialog.nib/classes.nib b/mozilla/camino/English.lproj/FindDialog.nib/classes.nib deleted file mode 100644 index b0d20da5dca..00000000000 --- a/mozilla/camino/English.lproj/FindDialog.nib/classes.nib +++ /dev/null @@ -1,19 +0,0 @@ -{ - IBClasses = ( - { - ACTIONS = {find = id; }; - CLASS = FindDlgController; - LANGUAGE = ObjC; - OUTLETS = { - mFindButton = NSButton; - mIgnoreCaseBox = NSButton; - mSearchBackwardsBox = NSButton; - mSearchField = NSTextField; - mWrapAroundBox = NSButton; - }; - SUPERCLASS = NSWindowController; - }, - {CLASS = FirstResponder; LANGUAGE = ObjC; SUPERCLASS = NSObject; } - ); - IBVersion = 1; -} \ No newline at end of file diff --git a/mozilla/camino/English.lproj/FindDialog.nib/info.nib b/mozilla/camino/English.lproj/FindDialog.nib/info.nib deleted file mode 100644 index 681cc6970ac..00000000000 --- a/mozilla/camino/English.lproj/FindDialog.nib/info.nib +++ /dev/null @@ -1,12 +0,0 @@ - - - - - IBDocumentLocation - 180 86 356 240 0 0 1152 746 - IBFramework Version - 248.0 - IBSystem Version - 5S66 - - diff --git a/mozilla/camino/English.lproj/FindDialog.nib/objects.nib b/mozilla/camino/English.lproj/FindDialog.nib/objects.nib deleted file mode 100644 index 27568a170bd..00000000000 Binary files a/mozilla/camino/English.lproj/FindDialog.nib/objects.nib and /dev/null differ diff --git a/mozilla/camino/English.lproj/InfoPlist.strings b/mozilla/camino/English.lproj/InfoPlist.strings deleted file mode 100644 index 7b8529dd570..00000000000 Binary files a/mozilla/camino/English.lproj/InfoPlist.strings and /dev/null differ diff --git a/mozilla/camino/English.lproj/Localizable.strings b/mozilla/camino/English.lproj/Localizable.strings deleted file mode 100644 index 259354c14b9..00000000000 Binary files a/mozilla/camino/English.lproj/Localizable.strings and /dev/null differ diff --git a/mozilla/camino/English.lproj/MVPreferencePaneGroups.strings b/mozilla/camino/English.lproj/MVPreferencePaneGroups.strings deleted file mode 100644 index b410cd0bc55..00000000000 Binary files a/mozilla/camino/English.lproj/MVPreferencePaneGroups.strings and /dev/null differ diff --git a/mozilla/camino/English.lproj/MVPreferences.nib/classes.nib b/mozilla/camino/English.lproj/MVPreferences.nib/classes.nib deleted file mode 100644 index aeac16577ff..00000000000 --- a/mozilla/camino/English.lproj/MVPreferences.nib/classes.nib +++ /dev/null @@ -1,32 +0,0 @@ -{ - IBClasses = ( - {CLASS = FirstResponder; LANGUAGE = ObjC; SUPERCLASS = NSObject; }, - { - ACTIONS = {showAll = id; showPreferences = id; }; - CLASS = MVPreferencesController; - LANGUAGE = ObjC; - OUTLETS = { - groupView = id; - loadingImageView = id; - loadingTextFeld = id; - loadingView = id; - multiView = id; - window = id; - }; - SUPERCLASS = NSObject; - }, - { - CLASS = MVPreferencesGroupedIconView; - LANGUAGE = ObjC; - OUTLETS = {preferencesController = id; }; - SUPERCLASS = NSView; - }, - { - CLASS = MVPreferencesMultipleIconView; - LANGUAGE = ObjC; - OUTLETS = {preferencesController = id; }; - SUPERCLASS = NSView; - } - ); - IBVersion = 1; -} \ No newline at end of file diff --git a/mozilla/camino/English.lproj/MVPreferences.nib/info.nib b/mozilla/camino/English.lproj/MVPreferences.nib/info.nib deleted file mode 100644 index fbed564bb10..00000000000 --- a/mozilla/camino/English.lproj/MVPreferences.nib/info.nib +++ /dev/null @@ -1,16 +0,0 @@ - - - - - IBDocumentLocation - 16 36 356 240 0 0 1024 746 - IBFramework Version - 248.0 - IBOpenObjects - - 7 - - IBSystem Version - 5Q125 - - diff --git a/mozilla/camino/English.lproj/MVPreferences.nib/objects.nib b/mozilla/camino/English.lproj/MVPreferences.nib/objects.nib deleted file mode 100644 index 273ab2bf5c6..00000000000 Binary files a/mozilla/camino/English.lproj/MVPreferences.nib/objects.nib and /dev/null differ diff --git a/mozilla/camino/English.lproj/MainMenu.nib/classes.nib b/mozilla/camino/English.lproj/MainMenu.nib/classes.nib deleted file mode 100644 index f4d1aa2760b..00000000000 --- a/mozilla/camino/English.lproj/MainMenu.nib/classes.nib +++ /dev/null @@ -1,80 +0,0 @@ -{ - IBClasses = ( - { - CLASS = BrowserToolbarController; - LANGUAGE = ObjC; - SUPERCLASS = ToolbarController; - }, - {CLASS = FirstResponder; LANGUAGE = ObjC; SUPERCLASS = NSObject; }, - {CLASS = GoMenu; LANGUAGE = ObjC; SUPERCLASS = NSMenu; }, - { - ACTIONS = { - addBookmark = id; - addFolder = id; - addSeparator = id; - biggerTextSize = id; - closeTab = id; - displayPreferencesWindow = id; - doReload = id; - doSearch = id; - doStop = id; - feedbackLink = id; - findAgain = id; - findInPage = id; - getInfo = id; - goBack = id; - goForward = id; - goHome = id; - importBookmarks = id; - infoLink = id; - manageBookmarks = id; - newTab = id; - newWindow = id; - nextTab = id; - openFile = id; - openLocation = id; - openMenuBookmark = id; - previousTab = id; - printPage = id; - printPreview = id; - savePage = id; - showAboutBox = id; - smallerTextSize = id; - toggleBookmarksToolbar = id; - toggleOfflineMode = id; - toggleSidebar = id; - viewSource = id; - }; - CLASS = MainController; - LANGUAGE = ObjC; - OUTLETS = { - mAddBookmarkMenuItem = NSMenuItem; - mApplication = NSApplication; - mBookmarksMenu = NSMenu; - mBookmarksToolbarMenuItem = NSMenuItem; - mCloseTabMenuItem = NSMenuItem; - mCloseWindowMenuItem = NSMenuItem; - mCreateBookmarksFolderMenuItem = NSMenuItem; - mCreateBookmarksSeparatorMenuItem = NSMenuItem; - mFilterList = NSPopUpButton; - mFilterView = NSView; - mToggleSidebarMenuItem = NSMenuItem; - }; - SUPERCLASS = NSObject; - }, - { - ACTIONS = {load = id; }; - CLASS = MyBrowserView; - LANGUAGE = ObjC; - OUTLETS = {progress = id; progressSuper = id; status = id; urlbar = id; }; - SUPERCLASS = NSView; - }, - { - CLASS = ToolbarController; - LANGUAGE = ObjC; - OUTLETS = {mBrowserView = id; mWindow = id; }; - SUPERCLASS = NSObject; - } - ); - IBVersion = 1; -} \ No newline at end of file diff --git a/mozilla/camino/English.lproj/MainMenu.nib/info.nib b/mozilla/camino/English.lproj/MainMenu.nib/info.nib deleted file mode 100644 index 2a0b9c2b3e9..00000000000 --- a/mozilla/camino/English.lproj/MainMenu.nib/info.nib +++ /dev/null @@ -1,39 +0,0 @@ - - - - - IBDocumentLocation - 108 107 477 485 0 0 1280 1002 - IBEditorPositions - - 266 - 483 623 277 90 0 0 1280 1002 - 29 - 8 957 446 44 0 0 1280 1002 - - IBFramework Version - 248.0 - IBGroupedObjects - - 0 - - 0 - 0 - 0 - - 1 - - 0 - 0 - - - IBLastGroupID - 2 - IBOpenObjects - - 29 - - IBSystem Version - 5S66 - - diff --git a/mozilla/camino/English.lproj/MainMenu.nib/objects.nib b/mozilla/camino/English.lproj/MainMenu.nib/objects.nib deleted file mode 100644 index 2ad295b96c9..00000000000 Binary files a/mozilla/camino/English.lproj/MainMenu.nib/objects.nib and /dev/null differ diff --git a/mozilla/camino/English.lproj/Navigator.scriptTerminology b/mozilla/camino/English.lproj/Navigator.scriptTerminology deleted file mode 100644 index fc11ae62e1f..00000000000 --- a/mozilla/camino/English.lproj/Navigator.scriptTerminology +++ /dev/null @@ -1,27 +0,0 @@ - - - - - Commands - - GetURL - - Description - Load a URL in the frontmost window - Name - Get URL - - OpenURL - - Description - Load a URL in the frontmost window - Name - open url - - - Description - Navigator's scripting suite - Name - Navigator suite - - diff --git a/mozilla/camino/English.lproj/ProgressDialog.nib/classes.nib b/mozilla/camino/English.lproj/ProgressDialog.nib/classes.nib deleted file mode 100644 index fc624beb9c0..00000000000 --- a/mozilla/camino/English.lproj/ProgressDialog.nib/classes.nib +++ /dev/null @@ -1,19 +0,0 @@ -{ - IBClasses = ( - {CLASS = FirstResponder; LANGUAGE = ObjC; SUPERCLASS = NSObject; }, - { - CLASS = ProgressDlgController; - LANGUAGE = ObjC; - OUTLETS = { - mElapsedTimeLabel = NSTextField; - mFromField = NSTextField; - mProgressBar = NSProgressIndicator; - mStatusLabel = NSTextField; - mTimeLeftLabel = NSTextField; - mToField = NSTextField; - }; - SUPERCLASS = NSWindowController; - } - ); - IBVersion = 1; -} \ No newline at end of file diff --git a/mozilla/camino/English.lproj/ProgressDialog.nib/info.nib b/mozilla/camino/English.lproj/ProgressDialog.nib/info.nib deleted file mode 100644 index d128c1fddc6..00000000000 --- a/mozilla/camino/English.lproj/ProgressDialog.nib/info.nib +++ /dev/null @@ -1,12 +0,0 @@ - - - - - IBDocumentLocation - 94 26 404 250 0 0 1152 746 - IBFramework Version - 248.0 - IBSystem Version - 5S66 - - diff --git a/mozilla/camino/English.lproj/ProgressDialog.nib/objects.nib b/mozilla/camino/English.lproj/ProgressDialog.nib/objects.nib deleted file mode 100644 index 53a6f68e67e..00000000000 Binary files a/mozilla/camino/English.lproj/ProgressDialog.nib/objects.nib and /dev/null differ diff --git a/mozilla/camino/English.lproj/alert.nib/classes.nib b/mozilla/camino/English.lproj/alert.nib/classes.nib deleted file mode 100644 index 22720161509..00000000000 --- a/mozilla/camino/English.lproj/alert.nib/classes.nib +++ /dev/null @@ -1,49 +0,0 @@ -{ - IBClasses = ( - {CLASS = FirstResponder; LANGUAGE = ObjC; SUPERCLASS = NSObject; }, - {CLASS = java.lang.Object; LANGUAGE = Java; }, - { - ACTIONS = {hitButton1 = id; hitButton2 = id; hitButton3 = id; }; - CLASS = nsAlertController; - LANGUAGE = ObjC; - OUTLETS = { - alertCheckPanel = id; - alertCheckPanelCheck = id; - alertCheckPanelText = id; - alertPanel = id; - alertPanelText = id; - confirmCheckPanel = id; - confirmCheckPanelButton1 = id; - confirmCheckPanelButton2 = id; - confirmCheckPanelButton3 = id; - confirmCheckPanelCheck = id; - confirmCheckPanelText = id; - confirmPanel = id; - confirmPanelButton1 = id; - confirmPanelButton2 = id; - confirmPanelButton3 = id; - confirmPanelText = id; - expiredCertPanel = id; - owner = id; - passwordPanel = id; - passwordPanelCheck = id; - passwordPanelInput = id; - passwordPanelText = id; - postToInsecureFromSecurePanel = id; - promptPanel = id; - promptPanelCheck = id; - promptPanelInput = id; - promptPanelText = id; - securityMismatchPanel = id; - securityUnknownPanel = id; - usernamePanel = id; - usernamePanelCheck = id; - usernamePanelPassword = id; - usernamePanelText = id; - usernamePanelUserName = id; - }; - SUPERCLASS = NSObject; - } - ); - IBVersion = 1; -} \ No newline at end of file diff --git a/mozilla/camino/English.lproj/alert.nib/info.nib b/mozilla/camino/English.lproj/alert.nib/info.nib deleted file mode 100644 index d2e85852ba9..00000000000 --- a/mozilla/camino/English.lproj/alert.nib/info.nib +++ /dev/null @@ -1,12 +0,0 @@ - - - - - IBDocumentLocation - 285 97 356 301 0 0 1024 746 - IBFramework Version - 248.0 - IBSystem Version - 5S66 - - diff --git a/mozilla/camino/English.lproj/alert.nib/objects.nib b/mozilla/camino/English.lproj/alert.nib/objects.nib deleted file mode 100644 index 114a02c288c..00000000000 Binary files a/mozilla/camino/English.lproj/alert.nib/objects.nib and /dev/null differ diff --git a/mozilla/camino/FindDialog.nib/classes.nib b/mozilla/camino/FindDialog.nib/classes.nib deleted file mode 100644 index b0d20da5dca..00000000000 --- a/mozilla/camino/FindDialog.nib/classes.nib +++ /dev/null @@ -1,19 +0,0 @@ -{ - IBClasses = ( - { - ACTIONS = {find = id; }; - CLASS = FindDlgController; - LANGUAGE = ObjC; - OUTLETS = { - mFindButton = NSButton; - mIgnoreCaseBox = NSButton; - mSearchBackwardsBox = NSButton; - mSearchField = NSTextField; - mWrapAroundBox = NSButton; - }; - SUPERCLASS = NSWindowController; - }, - {CLASS = FirstResponder; LANGUAGE = ObjC; SUPERCLASS = NSObject; } - ); - IBVersion = 1; -} \ No newline at end of file diff --git a/mozilla/camino/FindDialog.nib/info.nib b/mozilla/camino/FindDialog.nib/info.nib deleted file mode 100644 index 681cc6970ac..00000000000 --- a/mozilla/camino/FindDialog.nib/info.nib +++ /dev/null @@ -1,12 +0,0 @@ - - - - - IBDocumentLocation - 180 86 356 240 0 0 1152 746 - IBFramework Version - 248.0 - IBSystem Version - 5S66 - - diff --git a/mozilla/camino/FindDialog.nib/objects.nib b/mozilla/camino/FindDialog.nib/objects.nib deleted file mode 100644 index 27568a170bd..00000000000 Binary files a/mozilla/camino/FindDialog.nib/objects.nib and /dev/null differ diff --git a/mozilla/camino/FindDlgController.h b/mozilla/camino/FindDlgController.h deleted file mode 100644 index 7cd551bfb53..00000000000 --- a/mozilla/camino/FindDlgController.h +++ /dev/null @@ -1,59 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape 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/NPL/ - * - * 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 mozilla.org 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 NPL, 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 NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#import -#include "nsIWebBrowserFind.h" - -@interface FindDlgController : NSWindowController { - IBOutlet NSTextField* mSearchField; - IBOutlet NSButton* mIgnoreCaseBox; - IBOutlet NSButton* mWrapAroundBox; - IBOutlet NSButton* mSearchBackwardsBox; - IBOutlet NSButton* mFindButton; - - NSString* mSearchText; -} - -- (IBAction) find: (id)aSender; -- (IBAction) findAgain: (id)aSender; -- (void) storeSearchText:(NSString*)inText; -- (NSString*)getSearchText; - - // delegates for NSTextView -- (void)controlTextDidChange:(NSNotification *)aNotification; - -@end diff --git a/mozilla/camino/FindDlgController.mm b/mozilla/camino/FindDlgController.mm deleted file mode 100644 index 23de3042d6d..00000000000 --- a/mozilla/camino/FindDlgController.mm +++ /dev/null @@ -1,142 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape 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/NPL/ - * - * 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 mozilla.org 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 NPL, 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 NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#import "FindDlgController.h" -#import "BrowserWindowController.h" -#import "CHFind.h" -#include "nsCOMPtr.h" - - -@implementation FindDlgController - -- (id)initWithWindowNibName:(NSString *)windowNibName -{ - if ( (self = [super initWithWindowNibName:windowNibName]) ) - mSearchText = nil; - return self; -} - -- (void)dealloc -{ - [mSearchText release]; - [super dealloc]; -} - -- (void)windowDidLoad -{ -} - - -// -// -find -// -// User clicked the find button, send the action to the window controller of the -// frontmost browser window. If we found something, hide the window. If not, beep. -// --(IBAction) find: (id)aSender -{ - NSWindowController* controller = [[NSApp mainWindow] windowController]; - if ( [controller conformsToProtocol:@protocol(CHFind)] ) { - id browserController = controller; - BOOL ignoreCase = [mIgnoreCaseBox state]; - BOOL wrapSearch = [mWrapAroundBox state]; - BOOL searchBack = [mSearchBackwardsBox state]; - - [self storeSearchText:[mSearchField stringValue]]; - - BOOL found = [browserController findInPageWithPattern:mSearchText caseSensitive:!ignoreCase - wrap:wrapSearch backwards:searchBack]; - - if (! found ) - NSBeep(); - // we stay open - } - else - NSBeep(); -} - - -// -// -findAgain -// -// Someone hit "find again" in the edit menu, send the action to the window controller of the -// frontmost browser window. Beep if we didn't find something. -// --(IBAction) findAgain: (id)aSender -{ - NSWindowController* controller = [[NSApp mainWindow] windowController]; - if ( [controller conformsToProtocol:@protocol(CHFind)] ) { - id browserController = controller; - BOOL ignoreCase = [mIgnoreCaseBox state]; - BOOL wrapSearch = [mWrapAroundBox state]; - BOOL searchBack = [mSearchBackwardsBox state]; - - BOOL found = [browserController findInPageWithPattern:mSearchText caseSensitive:!ignoreCase - wrap:wrapSearch backwards:searchBack]; - if ( !found ) - NSBeep(); - } - else - NSBeep(); -} - -// -// controlTextDidChange -// -// Check if there is anything in the text field, and if not, disable the find button -// -- (void)controlTextDidChange:(NSNotification *)aNotification -{ - if ( [[mSearchField stringValue] length] ) - [mFindButton setEnabled:PR_TRUE]; - else - [mFindButton setEnabled:PR_FALSE]; -} - -- (void)storeSearchText:(NSString*)inText -{ - [mSearchText autorelease]; - mSearchText = inText; - [mSearchText retain]; -} - -- (NSString*)getSearchText -{ - return mSearchText; -} - -@end diff --git a/mozilla/camino/MainController.h b/mozilla/camino/MainController.h deleted file mode 100644 index a88c3abbfae..00000000000 --- a/mozilla/camino/MainController.h +++ /dev/null @@ -1,158 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape 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/NPL/ - * - * 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 mozilla.org 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 NPL, 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 NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#import -#import "BrowserWindowController.h" -#import "MVPreferencesController.h" -#import "CHSplashScreenWindow.h" -#import "FindDlgController.h" -#import "CHPreferenceManager.h" - -class BookmarksService; - -@interface MainController : NSObject -{ - IBOutlet NSApplication* mApplication; - - // The following two items are used by the filter list when saving files. - IBOutlet NSView* mFilterView; - IBOutlet NSPopUpButton* mFilterList; - - // IBOutlet NSMenuItem* mOfflineMenuItem; - IBOutlet NSMenuItem* mCloseWindowMenuItem; - IBOutlet NSMenuItem* mCloseTabMenuItem; - IBOutlet NSMenuItem* mToggleSidebarMenuItem; - - // The bookmarks menu. - IBOutlet NSMenu* mBookmarksMenu; - - IBOutlet NSMenuItem* mBookmarksToolbarMenuItem; - IBOutlet NSMenuItem* mAddBookmarkMenuItem; - IBOutlet NSMenuItem* mCreateBookmarksFolderMenuItem; - IBOutlet NSMenuItem* mCreateBookmarksSeparatorMenuItem; - - BOOL mOffline; - - CHSplashScreenWindow* mSplashScreen; - - CHPreferenceManager* mPreferenceManager; - - BookmarksService* mMenuBookmarks; - - FindDlgController* mFindDialog; - - MVPreferencesController* mPreferencesController; - - NSString* mStartURL; -} - --(void)dealloc; - -// File menu actions. --(IBAction) newWindow:(id)aSender; --(IBAction) openFile:(id)aSender; --(IBAction) openLocation:(id)aSender; --(IBAction) savePage:(id)aSender; --(IBAction) printPreview:(id)aSender; --(IBAction) printPage:(id)aSender; --(IBAction) toggleOfflineMode:(id)aSender; - -// Edit menu actions. --(IBAction) findInPage:(id)aSender; --(IBAction) findAgain:(id)aSender; --(IBAction) getInfo:(id)aSender; - -// Go menu actions. --(IBAction) goBack:(id)aSender; --(IBAction) goForward:(id)aSender; --(IBAction) goHome:(id)aSender; --(IBAction) doSearch:(id)aSender; --(IBAction) previousTab:(id)aSender; --(IBAction) nextTab:(id)aSender; - -// View menu actions. --(IBAction) toggleSidebar:(id)sender; --(IBAction) toggleBookmarksToolbar:(id)aSender; --(IBAction) doReload:(id)aSender; --(IBAction) doStop:(id)aSender; --(IBAction) biggerTextSize:(id)aSender; --(IBAction) smallerTextSize:(id)aSender; --(IBAction) viewSource:(id)aSender; - -// Bookmarks menu actions. --(IBAction) importBookmarks:(id)aSender; --(IBAction) addBookmark:(id)aSender; --(IBAction) openMenuBookmark:(id)aSender; --(IBAction) manageBookmarks: (id)aSender; --(IBAction) addFolder:(id)aSender; --(IBAction) addSeparator:(id)aSender; - -//Window menu actions --(IBAction) newTab:(id)aSender; --(IBAction) closeTab:(id)aSender; - -//Help menu actions --(IBAction) infoLink:(id)aSender; --(IBAction) feedbackLink:(id)aSender; - --(BrowserWindowController*)openBrowserWindowWithURL: (NSString*)aURL andReferrer: (NSString*)aReferrer; -- (void)openNewWindowOrTabWithURL:(NSString*)inURLString andReferrer:(NSString*)aReferrer; - -- (void)adjustCloseWindowMenuItemKeyEquivalent:(BOOL)inHaveTabs; -- (void)adjustCloseTabMenuItemKeyEquivalent:(BOOL)inHaveTabs; -- (void)fixCloseMenuItemKeyEquivalents; - -- (void)adjustBookmarksMenuItemsEnabling:(BOOL)inBrowserWindowFrontmost; - --(NSWindow*)getFrontmostBrowserWindow; - -- (MVPreferencesController *)preferencesController; -- (void)displayPreferencesWindow:sender; -- (CHPreferenceManager *)preferenceManager; -- (BOOL)isMainWindowABrowserWindow; - -// if the main window is a browser window, return its controller, otherwise nil -- (BrowserWindowController*)getMainWindowBrowserController; - -- (IBAction)showAboutBox:(id)sender; - -+ (NSImage*)createImageForDragging:(NSImage*)aIcon title:(NSString*)aTitle; - -- (void)updatePrebinding; -- (void)prebindFinished:(NSNotification *)aNotification; - -@end diff --git a/mozilla/camino/MainController.mm b/mozilla/camino/MainController.mm deleted file mode 100644 index b30ac343a96..00000000000 --- a/mozilla/camino/MainController.mm +++ /dev/null @@ -1,922 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape 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/NPL/ - * - * 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 mozilla.org 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 NPL, 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 NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include -#include - -#import "MainController.h" -#import "BrowserWindowController.h" -#import "BookmarksService.h" -#import "nsCocoaBrowserService.h" -#import "CHAboutBox.h" -#import "CHUserDefaults.h" - -#include "nsCOMPtr.h" -#include "nsEmbedAPI.h" - -#include "nsIServiceManager.h" -#include "nsIIOService.h" -#include "nsIPref.h" -#include "nsIChromeRegistry.h" - - -#ifdef _BUILD_STATIC_BIN -#include "nsStaticComponent.h" -nsresult PR_CALLBACK -app_getModuleInfo(nsStaticModuleInfo **info, PRUint32 *count); -#endif - -static const char* ioServiceContractID = "@mozilla.org/network/io-service;1"; - -@implementation MainController - --(id)init -{ - if ( (self = [super init]) ) { - NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults]; - if ([defaults boolForKey:USER_DEFAULTS_AUTOREGISTER_KEY]) { - // This option causes us to simply initialize embedding and exit. - NSString *path = [[[NSBundle mainBundle] executablePath] stringByDeletingLastPathComponent]; - setenv("MOZILLA_FIVE_HOME", [path fileSystemRepresentation], 1); - -#ifdef _BUILD_STATIC_BIN - NSGetStaticModuleInfo = app_getModuleInfo; -#endif - - if (NS_SUCCEEDED(NS_InitEmbedding(nsnull, nsnull))) { - // Register new chrome - nsCOMPtr chromeReg = - do_GetService("@mozilla.org/chrome/chrome-registry;1"); - if (chromeReg) { - chromeReg->CheckForNewChrome(); - chromeReg = 0; - } - NS_TermEmbedding(); - } - - [NSApp terminate:self]; - return self; - } - - NSString* url = [defaults stringForKey:USER_DEFAULTS_URL_KEY]; - mStartURL = url ? [url retain] : nil; - mSplashScreen = [[CHSplashScreenWindow alloc] splashImage:nil withFade:NO withStatusRect:NSMakeRect(0,0,0,0)]; - mFindDialog = nil; - mMenuBookmarks = nil; - - [NSApp setServicesProvider:self]; - - } - return self; -} - --(void)dealloc -{ - [mFindDialog release]; - [super dealloc]; -#if DEBUG - NSLog(@"Main controller died"); -#endif -} - --(void)applicationDidFinishLaunching:(NSNotification *)aNotification -{ -#ifdef _BUILD_STATIC_BIN - [self updatePrebinding]; -#endif - // initialize if we haven't already. - [self preferenceManager]; - - // don't open a new browser window if we already have one - // (for example, from an GetURL Apple Event) - NSWindow* browserWindow = [self getFrontmostBrowserWindow]; - if (!browserWindow) - [self newWindow: self]; - - [mSplashScreen close]; - - [mBookmarksMenu setAutoenablesItems: NO]; - mMenuBookmarks = new BookmarksService((BookmarksDataSource*)nil); - mMenuBookmarks->AddObserver(); - BookmarksService::ConstructBookmarksMenu(mBookmarksMenu, nsnull); - BookmarksService::gMainController = self; - - // Initialize offline mode. - mOffline = NO; - nsCOMPtr ioService(do_GetService(ioServiceContractID)); - if (!ioService) - return; - PRBool offline = PR_FALSE; - ioService->GetOffline(&offline); - mOffline = offline; - - // Set the menu item's text to "Go Online" if we're currently - // offline. -/* - if (mOffline) - [mOfflineMenuItem setTitle: @"Go Online"]; // XXX localize me -*/ -} - --(void)applicationWillTerminate: (NSNotification*)aNotification -{ -#if DEBUG - NSLog(@"Termination notification"); -#endif - - // Autosave one of the windows. - [[[mApplication mainWindow] windowController] autosaveWindowFrame]; - - mMenuBookmarks->RemoveObserver(); - delete mMenuBookmarks; - mMenuBookmarks = nsnull; - - // Release before calling TermEmbedding since we need to access XPCOM - // to save preferences - [mPreferencesController release]; - [mPreferenceManager release]; - - nsCocoaBrowserService::TermEmbedding(); - - [self autorelease]; -} - --(IBAction)newWindow:(id)aSender -{ - // If we have a key window, have it autosave its dimensions before - // we open a new window. That ensures the size ends up matching. - NSWindow* mainWindow = [mApplication mainWindow]; - if ( mainWindow && [[mainWindow windowController] respondsToSelector:@selector(autosaveWindowFrame)] ) - [[mainWindow windowController] autosaveWindowFrame]; - - // Now open the new window. - NSString* homePage = mStartURL ? mStartURL : [mPreferenceManager homePage:YES]; - BrowserWindowController* controller = [self openBrowserWindowWithURL:homePage andReferrer:nil]; - - if ([homePage isEqualToString: @"about:blank"]) - [controller focusURLBar]; - else - [[[controller getBrowserWrapper] getBrowserView] setActive: YES]; - - // Only load the command-line specified URL for the first window we open - if (mStartURL) { - [mStartURL release]; - mStartURL = nil; - } -} - --(IBAction)newTab:(id)aSender -{ - BrowserWindowController* browserController = [self getMainWindowBrowserController]; - if (browserController) - [browserController newTab:NO]; -} - --(IBAction)closeTab:(id)aSender -{ - BrowserWindowController* browserController = [self getMainWindowBrowserController]; - if (browserController) - [browserController closeTab]; -} - --(IBAction) previousTab:(id)aSender -{ - BrowserWindowController* browserController = [self getMainWindowBrowserController]; - if (browserController) - [browserController previousTab]; -} - --(IBAction) nextTab:(id)aSender; -{ - BrowserWindowController* browserController = [self getMainWindowBrowserController]; - if (browserController) - [browserController nextTab]; -} - --(IBAction) openFile:(id)aSender -{ - NSOpenPanel* openPanel = [[[NSOpenPanel alloc] init] autorelease]; - [openPanel setCanChooseFiles: YES]; - [openPanel setCanChooseDirectories: NO]; - [openPanel setAllowsMultipleSelection: NO]; - NSArray* array = [NSArray arrayWithObjects: @"htm",@"html",@"shtml",@"xhtml",@"xml", - @"txt",@"text", - @"gif",@"jpg",@"jpeg",@"png",@"bmp", - nil]; - int result = [openPanel runModalForTypes: array]; - if (result == NSOKButton) { - NSArray* urlArray = [openPanel URLs]; - if ([urlArray count] == 0) - return; - NSURL* url = [urlArray objectAtIndex: 0]; - // ---------------------- - [[NSDocumentController sharedDocumentController] noteNewRecentDocumentURL:url]; - // ---------------------- - - BrowserWindowController* browserController = [self getMainWindowBrowserController]; - if (browserController) - [browserController loadURL:[url absoluteString] referrer:nil activate:YES]; - else - [self openBrowserWindowWithURL:[url absoluteString] andReferrer:nil]; - } -} - --(IBAction) openLocation:(id)aSender -{ - NSWindow* browserWindow = [self getFrontmostBrowserWindow]; - if (!browserWindow) { - [self openBrowserWindowWithURL: @"about:blank" andReferrer:nil]; - browserWindow = [mApplication mainWindow]; - } - else if (![browserWindow isMainWindow]) { - [browserWindow makeKeyAndOrderFront:self]; - } - - [[browserWindow windowController] performAppropriateLocationAction]; -} - --(IBAction) savePage:(id)aSender -{ - BrowserWindowController* browserController = [self getMainWindowBrowserController]; - if (browserController) - [browserController saveDocument: mFilterView filterList: mFilterList]; -} - --(IBAction) printPage:(id)aSender -{ - BrowserWindowController* browserController = [self getMainWindowBrowserController]; - if (browserController) - [browserController printDocument:aSender]; -} - --(IBAction) printPreview:(id)aSender -{ - BrowserWindowController* browserController = [self getMainWindowBrowserController]; - if (browserController) - [browserController printPreview]; -} - --(IBAction) toggleOfflineMode:(id)aSender -{ - nsCOMPtr ioService(do_GetService(ioServiceContractID)); - if (!ioService) - return; - PRBool offline = PR_FALSE; - ioService->GetOffline(&offline); - ioService->SetOffline(!offline); - mOffline = !offline; - - // Update the menu item text. - // Set the menu item's text to "Go Online" if we're currently - // offline. -/* - if (mOffline) - [mOfflineMenuItem setTitle: @"Go Online"]; - else - [mOfflineMenuItem setTitle: @"Work Offline"]; -*/ - - // Indicate that we are working offline. - [[NSNotificationCenter defaultCenter] postNotificationName:@"offlineModeChanged" object:nil]; -} - -// Edit menu actions. - - -// -// -findInPage -// -// Called in response to "Find" in edit menu. Opens the find dialog. We only keep -// one around for the whole app to use, showing/hiding as we see fit. -// --(IBAction) findInPage:(id)aSender -{ - if ( !mFindDialog ) - mFindDialog = [[FindDlgController alloc] initWithWindowNibName: @"FindDialog"]; - [mFindDialog showWindow:self]; -} - - -// -// -findAgain -// -// Called in response to "Find Again" in edit menu. Tells the find controller -// to find the next occurrance of what's already been found. -// --(IBAction) findAgain:(id)aSender -{ - if ( mFindDialog ) - [mFindDialog findAgain:aSender]; - else - NSBeep(); -} - --(IBAction) getInfo:(id)aSender -{ - BrowserWindowController* browserController = [self getMainWindowBrowserController]; - if (browserController) - [browserController getInfo: aSender]; -} - --(IBAction) goBack:(id)aSender -{ - BrowserWindowController* browserController = [self getMainWindowBrowserController]; - if (browserController) - [browserController back: aSender]; -} - --(IBAction) goForward:(id)aSender -{ - BrowserWindowController* browserController = [self getMainWindowBrowserController]; - if (browserController) - [browserController forward: aSender]; -} - --(IBAction) doReload:(id)aSender -{ - BrowserWindowController* browserController = [self getMainWindowBrowserController]; - if (browserController) - [browserController reload: aSender]; -} - --(IBAction) doStop:(id)aSender -{ - BrowserWindowController* browserController = [self getMainWindowBrowserController]; - if (browserController) - [browserController stop: aSender]; -} - --(IBAction) goHome:(id)aSender -{ - NSWindow* browserWindow = [self getFrontmostBrowserWindow]; - if (browserWindow) { - if (![browserWindow isMainWindow]) - [browserWindow makeKeyAndOrderFront:self]; - - [[browserWindow windowController] home: aSender]; - } - else { - [self newWindow:self]; - } -} - --(IBAction) doSearch:(id)aSender -{ - NSWindow* browserWindow = [self getFrontmostBrowserWindow]; - if (browserWindow) { - if (![browserWindow isMainWindow]) - [browserWindow makeKeyAndOrderFront:self]; - - [[browserWindow windowController] performSearch: aSender]; - } - else { - [self newWindow:self]; - browserWindow = [self getFrontmostBrowserWindow]; - [[browserWindow windowController] performSearch: aSender]; - } -} - -- (void)adjustBookmarksMenuItemsEnabling:(BOOL)inBrowserWindowFrontmost; -{ - [mAddBookmarkMenuItem setEnabled:inBrowserWindowFrontmost]; - [mCreateBookmarksFolderMenuItem setEnabled:inBrowserWindowFrontmost]; - [mCreateBookmarksSeparatorMenuItem setEnabled:NO]; // separators are not implemented yet -} - --(NSWindow*)getFrontmostBrowserWindow -{ - // for some reason, [NSApp mainWindow] doesn't always work, so we have to - // do this manually - NSArray *windowList = [NSApp orderedWindows]; - NSWindow *foundWindow = NULL; - - for (unsigned int i = 0; i < [windowList count]; i ++) - { - NSWindow* thisWindow = [windowList objectAtIndex:i]; - - if ([[thisWindow windowController] isMemberOfClass:[BrowserWindowController class]] && - ([[thisWindow windowController] chromeMask] == 0)) // only get windows with full chrome - { - foundWindow = thisWindow; - break; - } - } - - return foundWindow; -} - -// open a new URL. This method always makes a new browser window --(BrowserWindowController*)openBrowserWindowWithURL: (NSString*)aURL andReferrer: (NSString*)aReferrer -{ - BrowserWindowController* browser = [[BrowserWindowController alloc] initWithWindowNibName: @"BrowserWindow"]; - - // 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. - if ( [aURL isEqualToString:@"about:blank"] ) - [browser disableLoadPage]; - else - [browser loadURL: aURL referrer:aReferrer activate:YES]; - [browser showWindow: self]; - return browser; -} - -// open a new URL, observing the prefs on how to behave -- (void)openNewWindowOrTabWithURL:(NSString*)inURLString andReferrer: (NSString*)aReferrer -{ - // make sure we're initted - [self preferenceManager]; - - PRBool reuseWindow = PR_FALSE; - PRBool loadInBackground = PR_FALSE; - - nsCOMPtr prefService ( do_GetService(NS_PREF_CONTRACTID) ); - if ( prefService ) { - prefService->GetBoolPref("browser.always_reuse_window", &reuseWindow); - prefService->GetBoolPref("browser.tabs.loadInBackground", &loadInBackground); - } - - // reuse the main window if there is one. The user may have closed all of - // them or we may get this event at startup before we've had time to load - // our window. - BrowserWindowController* controller = [self getMainWindowBrowserController]; - if (reuseWindow && controller && [controller newTabsAllowed]) { - [controller openNewTabWithURL:inURLString referrer:aReferrer loadInBackground:loadInBackground]; - } - else { - // should use BrowserWindowController openNewWindowWithURL, but that method - // really needs to be on the MainController - controller = [self openBrowserWindowWithURL: inURLString andReferrer:aReferrer]; - } - - [[[controller getBrowserWrapper] getBrowserView] setActive: YES]; -} - -// Bookmarks menu actions. --(IBAction) importBookmarks:(id)aSender -{ - // IE favorites: ~/Library/Preferences/Explorer/Favorites.html - // Omniweb favorites: ~/Library/Application Support/Omniweb/Bookmarks.html - // For now, open the panel to IE's favorites. - NSOpenPanel* openPanel = [[[NSOpenPanel alloc] init] autorelease]; - [openPanel setCanChooseFiles: YES]; - [openPanel setCanChooseDirectories: NO]; - [openPanel setAllowsMultipleSelection: NO]; - NSArray* array = [NSArray arrayWithObjects: @"htm",@"html",@"xml", nil]; - int result = [openPanel runModalForDirectory: @"~/Library/Preferences/Explorer/" - file: @"Favorites.html" - types: array]; - if (result == NSOKButton) { - NSArray* urlArray = [openPanel URLs]; - if ([urlArray count] == 0) - return; - NSURL* url = [urlArray objectAtIndex: 0]; - - NSWindow* browserWindow = [self getFrontmostBrowserWindow]; - if (!browserWindow) { - [self newWindow: self]; - browserWindow = [mApplication mainWindow]; - } - - [[browserWindow windowController] importBookmarks: [url absoluteString]]; - } -} - --(IBAction) addBookmark:(id)aSender -{ - BrowserWindowController* browserController = [self getMainWindowBrowserController]; - if (browserController) - [browserController addBookmarkExtended: YES isFolder: NO URL:nil title:nil]; -} - --(IBAction) addFolder:(id)aSender -{ - BrowserWindowController* browserController = [self getMainWindowBrowserController]; - if (browserController) - [browserController addBookmarkExtended: YES isFolder: YES URL:nil title:nil]; -} - --(IBAction) addSeparator:(id)aSender -{ - NSLog(@"Separators not implemented yet"); -} - --(IBAction) openMenuBookmark:(id)aSender -{ - NSWindow* browserWindow = [self getFrontmostBrowserWindow]; - if (!browserWindow) { - [self openBrowserWindowWithURL: @"about:blank" andReferrer:nil]; - browserWindow = [mApplication mainWindow]; - } - - BookmarksService::OpenMenuBookmark([browserWindow windowController], aSender); -} - --(IBAction)manageBookmarks: (id)aSender -{ - NSWindow* browserWindow = [self getFrontmostBrowserWindow]; - if (!browserWindow) { - [self newWindow:self]; - browserWindow = [mApplication mainWindow]; - } - - [[browserWindow windowController] manageBookmarks: aSender]; -} - -- (CHPreferenceManager *)preferenceManager -{ - if (!mPreferenceManager) - mPreferenceManager = [[CHPreferenceManager sharedInstance] retain]; - return mPreferenceManager; -} - -- (MVPreferencesController *)preferencesController -{ - if (!mPreferencesController) { - mPreferencesController = [[MVPreferencesController sharedInstance] retain]; - } - return mPreferencesController; -} - -- (void)displayPreferencesWindow:sender -{ - [[self preferencesController] showPreferences:nil] ; -} - -- (IBAction)showAboutBox:(id)sender -{ - [[CHAboutBox sharedInstance] showPanel:sender]; -} - -- (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename -{ -/* - // On the off chance that we're getting this message off a launch, - // we may not have initialized our embedded mozilla. So check here, - // and if it's not initialized, do it now. - [self preferenceManager]; - - // Make sure it's a browser window b/c "about box" can also become main window. - if ([self isMainWindowABrowserWindow]) { - [[[mApplication mainWindow] windowController] loadURL:[[NSURL fileURLWithPath:filename] absoluteString]]; - } - else { - [self openBrowserWindowWithURL:[[NSURL fileURLWithPath:filename] absoluteString]]; - } -*/ - [self openNewWindowOrTabWithURL:[[NSURL fileURLWithPath:filename] absoluteString] andReferrer:nil]; - - return YES; -} - -- (IBAction)biggerTextSize:(id)aSender -{ - BrowserWindowController* browserController = [self getMainWindowBrowserController]; - if (browserController) - [browserController biggerTextSize]; -} - -- (IBAction)smallerTextSize:(id)aSender -{ - BrowserWindowController* browserController = [self getMainWindowBrowserController]; - if (browserController) - [browserController smallerTextSize]; -} - --(IBAction) viewSource:(id)aSender -{ - BrowserWindowController* browserController = [self getMainWindowBrowserController]; - if (browserController) - [browserController viewSource: aSender]; -} - --(BOOL)isMainWindowABrowserWindow -{ - // see also getFrontmostBrowserWindow - return [[[mApplication mainWindow] windowController] isMemberOfClass:[BrowserWindowController class]]; -} - -- (BrowserWindowController*)getMainWindowBrowserController -{ - NSWindowController* mainWindowController = [[mApplication mainWindow] windowController]; - if (mainWindowController && [mainWindowController isMemberOfClass:[BrowserWindowController class]]) - return (BrowserWindowController*)mainWindowController; - - return nil; -} - -- (void)adjustCloseWindowMenuItemKeyEquivalent:(BOOL)inHaveTabs -{ - // capitalization of the key equivalent affects whether the shift modifer is used. - [mCloseWindowMenuItem setKeyEquivalent: inHaveTabs ? @"W" : @"w"]; -} - -- (void)adjustCloseTabMenuItemKeyEquivalent:(BOOL)inHaveTabs -{ - if (inHaveTabs) { - [mCloseTabMenuItem setKeyEquivalent:@"w"]; - [mCloseTabMenuItem setKeyEquivalentModifierMask:NSCommandKeyMask]; - } - else { - [mCloseTabMenuItem setKeyEquivalent:@""]; - [mCloseTabMenuItem setKeyEquivalentModifierMask:0]; - } -} - -// see if we have a window with tabs open, and adjust the key equivalents for -// Close Tab/Close Window accordingly -- (void)fixCloseMenuItemKeyEquivalents -{ - BrowserWindowController* browserController = [self getMainWindowBrowserController]; - if (browserController) { - BOOL windowWithMultipleTabs = ([[browserController getTabBrowser] numberOfTabViewItems] > 1); - [self adjustCloseWindowMenuItemKeyEquivalent:windowWithMultipleTabs]; - [self adjustCloseTabMenuItemKeyEquivalent:windowWithMultipleTabs]; - } -} - --(BOOL)validateMenuItem: (NSMenuItem*)aMenuItem -{ - BrowserWindowController* browserController = [self getMainWindowBrowserController]; - - // disable items that aren't relevant if there's no main browser window open - SEL action = [aMenuItem action]; - - //NSLog(@"MainController validateMenuItem for %@ (%s)", [aMenuItem title], action); - - if (action == @selector(printPage:) || - /* ... many more items go here ... */ - /* action == @selector(goHome:) || */ // always enabled - /* action == @selector(doSearch:) || */ // always enabled - action == @selector(findInPage:) || - action == @selector(doReload:) || - action == @selector(biggerTextSize:) || - action == @selector(smallerTextSize:) || - action == @selector(viewSource:) || - action == @selector(savePage:)) - { - return (browserController != nil); - } - - if (action == @selector(newTab:)) - return (browserController && [browserController newTabsAllowed]); - - // check if someone has previously done a find before allowing findAgain to be enabled - if (action == @selector(findAgain:)) - return (browserController && mFindDialog && [[mFindDialog getSearchText] length] > 0); - - // check what the state of the personal toolbar should be, but only if there is a browser - // window open. Popup windows that have the personal toolbar removed should always gray - // out this menu. - if (action == @selector(toggleBookmarksToolbar:)) { - if (browserController) { - NSView* bookmarkToolbar = [browserController bookmarksToolbar]; - if ( bookmarkToolbar ) { - float height = [bookmarkToolbar frame].size.height; - BOOL toolbarShowing = (height > 0); - if (toolbarShowing) - [mBookmarksToolbarMenuItem setTitle: NSLocalizedString(@"Hide Bookmarks Toolbar",@"")]; - else - [mBookmarksToolbarMenuItem setTitle: NSLocalizedString(@"Show Bookmarks Toolbar",@"")]; - return YES; - } - else - return NO; - } - else - return NO; - } - - if (action == @selector(toggleSidebar:)) { - if (browserController) { - NSDrawer *sidebar = [browserController sidebarDrawer]; - if (sidebar) { - int sidebarState = [sidebar state]; - if (sidebarState == NSDrawerOpenState) - [mToggleSidebarMenuItem setTitle: NSLocalizedString(@"Hide Sidebar",@"")]; - else - [mToggleSidebarMenuItem setTitle: NSLocalizedString(@"Show Sidebar",@"")]; - return YES; - } - else - return NO; - } - else - return NO; - } - - if ( action == @selector(getInfo:) ) - return (browserController && [browserController canGetInfo]); - - // only activate if we've got multiple tabs open. - if ((action == @selector(closeTab:) || - action == @selector(nextTab:) || - action == @selector(previousTab:))) - { - return (browserController && [[browserController getTabBrowser] numberOfTabViewItems] > 1); - } - - if ( action == @selector(doStop:) ) - return (browserController && [[browserController getBrowserWrapper] isBusy]); - - if ( action == @selector(goBack:) || action == @selector(goForward:) ) { - if (browserController) { - CHBrowserView* browserView = [[browserController getBrowserWrapper] getBrowserView]; - if (action == @selector(goBack:)) - return [browserView canGoBack]; - if (action == @selector(goForward:)) - return [browserView canGoForward]; - } - else - return NO; - } - - // default return - return YES; -} - --(IBAction) toggleSidebar:(id)sender -{ - BrowserWindowController *browserController = [self getMainWindowBrowserController]; - if (!browserController) return; - - [browserController toggleSidebar:sender]; -} - --(IBAction) toggleBookmarksToolbar:(id)aSender -{ - BrowserWindowController* browserController = [self getMainWindowBrowserController]; - if (!browserController) return; - - float height = [[browserController bookmarksToolbar] frame].size.height; - BOOL showToolbar = (BOOL)(!(height > 0)); - - [[browserController bookmarksToolbar] showBookmarksToolbar: showToolbar]; - - // save prefs here - NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults]; - [defaults setInteger: ((showToolbar) ? 0 : 1) forKey: USER_DEFAULTS_HIDE_PERS_TOOLBAR_KEY]; -} - --(IBAction) infoLink:(id)aSender -{ - NSString* pageToLoad = NSLocalizedStringFromTable(@"InfoPageDefault", @"WebsiteDefaults", nil); - if (![pageToLoad isEqualToString:@"InfoPageDefault"]) - [self openNewWindowOrTabWithURL:pageToLoad andReferrer:nil]; -} - --(IBAction) feedbackLink:(id)aSender -{ - NSString *pageToLoad = NSLocalizedStringFromTable(@"FeedbackPageDefault", @"WebsiteDefaults", nil); - if (![pageToLoad isEqualToString:@"FeedbackPageDefault"]) - [self openNewWindowOrTabWithURL:pageToLoad andReferrer:nil]; -} - -+ (NSImage*)createImageForDragging:(NSImage*)aIcon title:(NSString*)aTitle -{ - NSImage* image; - NSSize titleSize, imageSize; - NSRect imageRect; - NSDictionary* stringAttrs; - - // get the size of the new image we are creating - titleSize = [aTitle sizeWithAttributes:nil]; - imageSize = NSMakeSize(titleSize.width + [aIcon size].width, - titleSize.height > [aIcon size].height ? - titleSize.height : [aIcon size].height); - - // create the image and lock drawing focus on it - image = [[[NSImage alloc] initWithSize:imageSize] autorelease]; - [image lockFocus]; - - // draw the image and title in image with translucency - imageRect = NSMakeRect(0,0, [aIcon size].width, [aIcon size].height); - [aIcon drawAtPoint: NSMakePoint(0,0) fromRect: imageRect operation:NSCompositeCopy fraction:0.8]; - - stringAttrs = [NSDictionary dictionaryWithObject: [[NSColor textColor] colorWithAlphaComponent:0.8] - forKey: NSForegroundColorAttributeName]; - [aTitle drawAtPoint: NSMakePoint([aIcon size].width, 0) withAttributes: stringAttrs]; - - [image unlockFocus]; - - return image; -} - -- (BOOL)applicationShouldHandleReopen:(NSApplication *)theApp hasVisibleWindows:(BOOL)flag -{ - // If AppKit knows what to do, let it. - if (flag) - return YES; - - // If window available, wake it up. |mainWindow| should always be null. - NSWindow* mainWindow = [mApplication mainWindow]; - if (!mainWindow) - [self newWindow:self]; - else { // Don't think this will ever happen, but just in case - if ([[mainWindow windowController]respondsToSelector:@selector(showWindow:)]) - [[mainWindow windowController] showWindow:self]; - else - [self newWindow:self]; - } - - return NO; -} - -- (void) applicationDidChangeScreenParameters:(NSNotification *)aNotification -{ - [NSApp makeWindowsPerform:@selector(display) inOrder:YES]; -} - -- (void) updatePrebinding -{ - // Check our prebinding status. If we didn't launch prebound, - // fork the update script. - - if (!_dyld_launched_prebound()) { - NSLog(@"Not prebound, launching update script"); - NSTask* aTask = [[NSTask alloc] init]; - NSArray* args = [NSArray arrayWithObject: @"redo-prebinding.sh"]; - - [aTask setCurrentDirectoryPath:[[[NSBundle mainBundle] executablePath] stringByDeletingLastPathComponent]]; - [aTask setLaunchPath:@"/bin/sh"]; - [aTask setArguments:args]; - - [[NSNotificationCenter defaultCenter] addObserver: self - selector:@selector(prebindFinished:) - name:NSTaskDidTerminateNotification - object: nil]; - - [aTask launch]; - } -} - -- (void)prebindFinished:(NSNotification *)aNotification -{ - [[aNotification object] release]; -} - -// services - -- (void)openURL:(NSPasteboard *) pboard userData:(NSString *) userData error:(NSString **) error -{ - NSMutableString *urlString = [[[NSMutableString alloc] init] autorelease]; - if ( !urlString ) - return; - - NSArray* types = [pboard types]; - if (![types containsObject:NSStringPboardType]) { - *error = NSLocalizedString(@"Error: couldn't open URL.", - @"pboard couldn't give URL string."); - return; - } - NSString* pboardString = [pboard stringForType:NSStringPboardType]; - if (!pboardString) { - *error = NSLocalizedString(@"Error: couldn't open URL.", - @"pboard couldn't give URL string."); - return; - } - NSScanner* scanner = [NSScanner scannerWithString:pboardString]; - [scanner scanCharactersFromSet:[[NSCharacterSet whitespaceAndNewlineCharacterSet] invertedSet] intoString:&urlString]; - while(![scanner isAtEnd]) { - NSString *tmpString; - [scanner scanCharactersFromSet:[[NSCharacterSet whitespaceAndNewlineCharacterSet] invertedSet] intoString:&tmpString]; - [urlString appendString:tmpString]; - } - - [self openNewWindowOrTabWithURL:urlString andReferrer:nil]; -} - -@end diff --git a/mozilla/camino/MainMenu.nib/classes.nib b/mozilla/camino/MainMenu.nib/classes.nib deleted file mode 100644 index fae3aa7579e..00000000000 --- a/mozilla/camino/MainMenu.nib/classes.nib +++ /dev/null @@ -1,80 +0,0 @@ -{ - IBClasses = ( - { - CLASS = BrowserToolbarController; - LANGUAGE = ObjC; - SUPERCLASS = ToolbarController; - }, - {CLASS = CHGoMenu; LANGUAGE = ObjC; SUPERCLASS = NSMenu; }, - {CLASS = FirstResponder; LANGUAGE = ObjC; SUPERCLASS = NSObject; }, - { - ACTIONS = { - addBookmark = id; - addFolder = id; - addSeparator = id; - biggerTextSize = id; - closeTab = id; - displayPreferencesWindow = id; - doReload = id; - doSearch = id; - doStop = id; - feedbackLink = id; - findAgain = id; - findInPage = id; - getInfo = id; - goBack = id; - goForward = id; - goHome = id; - importBookmarks = id; - infoLink = id; - manageBookmarks = id; - newTab = id; - newWindow = id; - nextTab = id; - openFile = id; - openLocation = id; - openMenuBookmark = id; - previousTab = id; - printPage = id; - printPreview = id; - savePage = id; - showAboutBox = id; - smallerTextSize = id; - toggleBookmarksToolbar = id; - toggleOfflineMode = id; - toggleSidebar = id; - viewSource = id; - }; - CLASS = MainController; - LANGUAGE = ObjC; - OUTLETS = { - mAddBookmarkMenuItem = NSMenuItem; - mApplication = NSApplication; - mBookmarksMenu = NSMenu; - mBookmarksToolbarMenuItem = NSMenuItem; - mCloseTabMenuItem = NSMenuItem; - mCloseWindowMenuItem = NSMenuItem; - mCreateBookmarksFolderMenuItem = NSMenuItem; - mCreateBookmarksSeparatorMenuItem = NSMenuItem; - mFilterList = NSPopUpButton; - mFilterView = NSView; - mToggleSidebarMenuItem = NSMenuItem; - }; - SUPERCLASS = NSObject; - }, - { - ACTIONS = {load = id; }; - CLASS = MyBrowserView; - LANGUAGE = ObjC; - OUTLETS = {progress = id; progressSuper = id; status = id; urlbar = id; }; - SUPERCLASS = NSView; - }, - { - CLASS = ToolbarController; - LANGUAGE = ObjC; - OUTLETS = {mBrowserView = id; mWindow = id; }; - SUPERCLASS = NSObject; - } - ); - IBVersion = 1; -} \ No newline at end of file diff --git a/mozilla/camino/MainMenu.nib/info.nib b/mozilla/camino/MainMenu.nib/info.nib deleted file mode 100644 index 2a0b9c2b3e9..00000000000 --- a/mozilla/camino/MainMenu.nib/info.nib +++ /dev/null @@ -1,39 +0,0 @@ - - - - - IBDocumentLocation - 108 107 477 485 0 0 1280 1002 - IBEditorPositions - - 266 - 483 623 277 90 0 0 1280 1002 - 29 - 8 957 446 44 0 0 1280 1002 - - IBFramework Version - 248.0 - IBGroupedObjects - - 0 - - 0 - 0 - 0 - - 1 - - 0 - 0 - - - IBLastGroupID - 2 - IBOpenObjects - - 29 - - IBSystem Version - 5S66 - - diff --git a/mozilla/camino/MainMenu.nib/objects.nib b/mozilla/camino/MainMenu.nib/objects.nib deleted file mode 100644 index 3eb3a4600a8..00000000000 Binary files a/mozilla/camino/MainMenu.nib/objects.nib and /dev/null differ diff --git a/mozilla/camino/NSScreen+Utils.h b/mozilla/camino/NSScreen+Utils.h deleted file mode 100644 index 0c24ec890e9..00000000000 --- a/mozilla/camino/NSScreen+Utils.h +++ /dev/null @@ -1,45 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape 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/NPL/ - * - * 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 mozilla.org 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 NPL, 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 NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#import - - -@interface NSScreen (CHScreenAdditions) - -+ (NSScreen*)screenForPoint:(NSPoint)point; - -@end diff --git a/mozilla/camino/NSScreen+Utils.m b/mozilla/camino/NSScreen+Utils.m deleted file mode 100644 index 290b2c57bed..00000000000 --- a/mozilla/camino/NSScreen+Utils.m +++ /dev/null @@ -1,59 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape 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/NPL/ - * - * 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 mozilla.org 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 NPL, 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 NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - - -#import "NSScreen+Utils.h" - - -@implementation NSScreen (CHScreenAdditions) - -+ (NSScreen*)screenForPoint:(NSPoint)point -{ - NSArray* screens = [NSScreen screens]; - NSEnumerator* screenEnum = [screens objectEnumerator]; - NSScreen* screen; - - while ( (screen = [screenEnum nextObject]) ) { - NSRect frame = [screen frame]; - if (NSPointInRect(point, frame)) - break; - } - - return screen; -} - -@end diff --git a/mozilla/camino/NSString+Utils.h b/mozilla/camino/NSString+Utils.h deleted file mode 100644 index a4d3d6fe3e2..00000000000 --- a/mozilla/camino/NSString+Utils.h +++ /dev/null @@ -1,70 +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): - * Simon Fraser - * - * 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 -#import "nscore.h" - -class nsAString; - -typedef enum -{ - kTruncateAtStart, - kTruncateAtMiddle, - kTruncateAtEnd -} ETruncationType; - - -// a category to extend NSString -@interface NSString (ChimeraStringUtils) - -+ (id)ellipsisString; -+ (id)stringWithPRUnichars:(const PRUnichar*)inString; -+ (id)stringWith_nsAString:(const nsAString&)inString; -- (void)assignTo_nsAString:(nsAString&)ioString; - -- (NSString *)stringByRemovingCharactersInSet:(NSCharacterSet*)characterSet; -- (NSString *)stringByReplacingCharactersInSet:(NSCharacterSet*)characterSet withString:(NSString*)string; -- (NSString *)stringByTruncatingTo:(unsigned int)maxCharacters at:(ETruncationType)truncationType; - -@end - -@interface NSMutableString (ChimeraMutableStringUtils) - -- (void)truncateTo:(unsigned)maxCharacters at:(ETruncationType)truncationType; -- (void)truncateToWidth:(float)maxWidth at:(ETruncationType)truncationType withAttributes:(NSDictionary *)attributes; - -@end diff --git a/mozilla/camino/NSString+Utils.mm b/mozilla/camino/NSString+Utils.mm deleted file mode 100644 index 56b2fbb26e0..00000000000 --- a/mozilla/camino/NSString+Utils.mm +++ /dev/null @@ -1,229 +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): - * Simon Fraser - * - * 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 // for NSStringDrawing.h -#import "NSString+Utils.h" - -#include "nsString.h" -#include "nsPromiseFlatString.h" -#include "nsCRT.h" - - -@implementation NSString (ChimeraStringUtils) - - -+ (id)ellipsisString -{ - static NSString* sEllipsisString = nil; - if (!sEllipsisString) - { - unichar ellipsisChar = 0x2026; - sEllipsisString = [[NSString alloc] initWithCharacters:&ellipsisChar length:1]; - } - - return sEllipsisString; -} - -+ (id)stringWithPRUnichars:(const PRUnichar*)inString -{ - if (inString) - return [self stringWithCharacters:inString length:nsCRT::strlen(inString)]; - else - return [self string]; -} - -+ (id)stringWith_nsAString:(const nsAString&)inString -{ - nsPromiseFlatString flatString = PromiseFlatString(inString); - return [self stringWithCharacters:flatString.get() length:flatString.Length()]; -} - -#define ASSIGN_STACK_BUFFER_CHARACTERS 256 - -- (void)assignTo_nsAString:(nsAString&)ioString -{ - PRUnichar stackBuffer[ASSIGN_STACK_BUFFER_CHARACTERS]; - PRUnichar* buffer = stackBuffer; - - // XXX maybe fix this to use SetLength(0), SetLength(len), and a writing iterator. - unsigned int len = [self length]; - - if (len + 1 > ASSIGN_STACK_BUFFER_CHARACTERS) - { - buffer = (PRUnichar *)malloc(sizeof(PRUnichar) * (len + 1)); - if (!buffer) - return; - } - - [self getCharacters: buffer]; // does not null terminate - ioString.Assign(buffer, len); - - if (buffer != stackBuffer) - free(buffer); -} - -- (NSString *)stringByRemovingCharactersInSet:(NSCharacterSet*)characterSet -{ - NSScanner* cleanerScanner = [NSScanner scannerWithString:self]; - NSMutableString* cleanString = [NSMutableString stringWithCapacity:[self length]]; - - while (![cleanerScanner isAtEnd]) - { - NSString* stringFragment; - if ([cleanerScanner scanUpToCharactersFromSet:characterSet intoString:&stringFragment]) - [cleanString appendString:stringFragment]; - - [cleanerScanner scanCharactersFromSet:characterSet intoString:nil]; - } - - return cleanString; -} - -- (NSString *)stringByReplacingCharactersInSet:(NSCharacterSet*)characterSet withString:(NSString*)string -{ - NSScanner* cleanerScanner = [NSScanner scannerWithString:self]; - NSMutableString* cleanString = [NSMutableString stringWithCapacity:[self length]]; - - while (![cleanerScanner isAtEnd]) - { - NSString* stringFragment; - if ([cleanerScanner scanUpToCharactersFromSet:characterSet intoString:&stringFragment]) - [cleanString appendString:stringFragment]; - - if ([cleanerScanner scanCharactersFromSet:characterSet intoString:nil]) - [cleanString appendString:string]; - } - - return cleanString; -} - -- (NSString*)stringByTruncatingTo:(unsigned in)maxCharacters at:(ETruncationType)truncationType -{ - if ([self length] > maxCharacters) - { - NSMutableString *mutableCopy = [self mutableCopy]; - [mutableCopy truncateTo:maxCharacters at:truncationType]; - return [mutableCopy autorelease]; - } - - return [[self copy] autorelease]; -} - -@end - - -@implementation NSMutableString (ChimeraMutableStringUtils) - -- (void)truncateTo:(unsigned)maxCharacters at:(ETruncationType)truncationType -{ - if ([self length] > maxCharacters) - { - NSRange replaceRange; - replaceRange.length = [self length] - maxCharacters; - - switch (truncationType) - { - case kTruncateAtStart: - replaceRange.location = 0; - break; - - case kTruncateAtMiddle: - replaceRange.location = maxCharacters / 2; - break; - - case kTruncateAtEnd: - replaceRange.location = maxCharacters; - break; - - default: -#if DEBUG - NSLog(@"Unknown truncation type in stringByTruncatingTo::"); -#endif - replaceRange.location = maxCharacters; - break; - } - - [self replaceCharactersInRange:replaceRange withString:[NSString ellipsisString]]; - } -} - - -- (void)truncateToWidth:(float)maxWidth at:(ETruncationType)truncationType withAttributes:(NSDictionary *)attributes -{ - // First check if we have to truncate at all. - if ([self sizeWithAttributes:attributes].width > maxWidth) - { - // Essentially, we perform a binary search on the string length - // which fits best into maxWidth. - - float width; - int lo = 0; - int hi = [self length]; - int mid; - - // Make a backup copy of the string so that we can restore it if we fail low. - NSMutableString *backup = [self mutableCopy]; - - while (hi >= lo) - { - mid = (hi + lo) / 2; - - // Cut to mid chars and calculate the resulting width - [self truncateTo:mid at:truncationType]; - width = [self sizeWithAttributes:attributes].width; - - if (width > maxWidth) { - // Fail high - string is still to wide. For the next cut, we can simply - // work on the already cut string, so we don't restore using the backup. - hi = mid - 1; - } else if (width == maxWidth) { - // Perfect match, abort the search. - break; - } else { - // Fail low - we cut off to much. Restore the string before cutting again. - lo = mid + 1; - [self setString:backup]; - } - } - // Perform the final cut (unless this was already a perfect match). - if (width != maxWidth) - [self truncateTo:hi at:truncationType]; - [backup release]; - } -} - -@end diff --git a/mozilla/camino/Navigator.scriptSuite b/mozilla/camino/Navigator.scriptSuite deleted file mode 100644 index 6d790279fd3..00000000000 --- a/mozilla/camino/Navigator.scriptSuite +++ /dev/null @@ -1,31 +0,0 @@ - - - - - AppleEventCode - CHIM - Commands - - GetURL - - AppleEventClassCode - GURL - AppleEventCode - GURL - CommandClass - CHGetURLCommand - - OpenURL - - AppleEventClassCode - WWW! - AppleEventCode - OURL - CommandClass - CHGetURLCommand - - - Name - Navigator - - diff --git a/mozilla/camino/ProgressDialog.nib/classes.nib b/mozilla/camino/ProgressDialog.nib/classes.nib deleted file mode 100644 index fc624beb9c0..00000000000 --- a/mozilla/camino/ProgressDialog.nib/classes.nib +++ /dev/null @@ -1,19 +0,0 @@ -{ - IBClasses = ( - {CLASS = FirstResponder; LANGUAGE = ObjC; SUPERCLASS = NSObject; }, - { - CLASS = ProgressDlgController; - LANGUAGE = ObjC; - OUTLETS = { - mElapsedTimeLabel = NSTextField; - mFromField = NSTextField; - mProgressBar = NSProgressIndicator; - mStatusLabel = NSTextField; - mTimeLeftLabel = NSTextField; - mToField = NSTextField; - }; - SUPERCLASS = NSWindowController; - } - ); - IBVersion = 1; -} \ No newline at end of file diff --git a/mozilla/camino/ProgressDialog.nib/info.nib b/mozilla/camino/ProgressDialog.nib/info.nib deleted file mode 100644 index d128c1fddc6..00000000000 --- a/mozilla/camino/ProgressDialog.nib/info.nib +++ /dev/null @@ -1,12 +0,0 @@ - - - - - IBDocumentLocation - 94 26 404 250 0 0 1152 746 - IBFramework Version - 248.0 - IBSystem Version - 5S66 - - diff --git a/mozilla/camino/ProgressDialog.nib/objects.nib b/mozilla/camino/ProgressDialog.nib/objects.nib deleted file mode 100644 index 53a6f68e67e..00000000000 Binary files a/mozilla/camino/ProgressDialog.nib/objects.nib and /dev/null differ diff --git a/mozilla/camino/ProgressDlgController.h b/mozilla/camino/ProgressDlgController.h deleted file mode 100644 index 422a3fc70e5..00000000000 --- a/mozilla/camino/ProgressDlgController.h +++ /dev/null @@ -1,83 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape 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/NPL/ - * - * 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 mozilla.org 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 NPL, 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 NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#import - -#import "DownloadProgressDisplay.h" - -#include "nscore.h" - -class nsIWebBrowserPersist; -class nsISupports; -class nsIInputStream; -class nsDownloadListener; - - -@interface ChimeraDownloadControllerFactory : DownloadControllerFactory -@end - - -@interface ProgressDlgController : NSWindowController -{ - IBOutlet NSTextField *mElapsedTimeLabel; - IBOutlet NSTextField *mFromField; - IBOutlet NSTextField *mStatusLabel; - IBOutlet NSTextField *mTimeLeftLabel; - IBOutlet NSTextField *mToField; - IBOutlet NSProgressIndicator *mProgressBar; - - NSToolbarItem *leaveOpenToggleToolbarItem; - - BOOL mSaveFileDialogShouldStayOpen; - BOOL mIsFileSave; - BOOL mDownloadIsComplete; - long mCurrentProgress; // if progress bar is indeterminate, can still calc stats. - - CHDownloader *mDownloader; // we hold a ref to this - NSTimer *mDownloadTimer; -} - --(void)autosaveWindowFrame; - --(void) setupDownloadTimer; --(void) killDownloadTimer; --(void) setDownloadProgress:(NSTimer *)aTimer; --(NSString *) formatTime:(int)aSeconds; --(NSString *) formatFuzzyTime:(int)aSeconds; --(NSString *) formatBytes:(float)aBytes; - -@end diff --git a/mozilla/camino/ProgressDlgController.mm b/mozilla/camino/ProgressDlgController.mm deleted file mode 100644 index 55f5e8897d5..00000000000 --- a/mozilla/camino/ProgressDlgController.mm +++ /dev/null @@ -1,509 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape 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/NPL/ - * - * 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 mozilla.org 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 NPL, 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 NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#import "ProgressDlgController.h" - -#include "nsCOMPtr.h" -#include "nsString.h" -#include "nsCRT.h" -#include "nsIWebBrowserPersist.h" -#include "nsIInputStream.h" -#include "nsIURL.h" -#include "nsILocalFile.h" -#include "nsIDOMHTMLDocument.h" -#include "nsIWebProgressListener.h" -#include "nsIDownload.h" -#include "nsIComponentManager.h" -#include "nsIPref.h" - -static NSString *SaveFileToolbarIdentifier = @"Save File Dialog Toolbar"; -static NSString *CancelToolbarItemIdentifier = @"Cancel Toolbar Item"; -static NSString *ShowFileToolbarItemIdentifier = @"Show File Toolbar Item"; -static NSString *OpenFileToolbarItemIdentifier = @"Open File Toolbar Item"; -static NSString *LeaveOpenToolbarItemIdentifier = @"Leave Open Toggle Toolbar Item"; - -static NSString *ProgressWindowFrameSaveName = @"ProgressWindow"; - -@implementation ChimeraDownloadControllerFactory : DownloadControllerFactory - -- (NSWindowController *)createDownloadController -{ - NSWindowController* progressController = [[ProgressDlgController alloc] initWithWindowNibName: @"ProgressDialog"]; - NSAssert([progressController conformsToProtocol:@protocol(DownloadProgressDisplay)], - @"progressController should conform to DownloadProgressDisplay protocol"); - return progressController; -} - -@end - -#pragma mark - - - -@interface ProgressDlgController(Private) --(void)setupToolbar; -@end - -@implementation ProgressDlgController - -- (void)dealloc -{ - // if we get here because we're quitting, the listener will still be alive - // yet we're going away. As a result, we need to tell the d/l listener to - // forget it ever met us and necko will clean it up on its own. - if ( mDownloader) - mDownloader->DetachDownloadDisplay(); - NS_IF_RELEASE(mDownloader); - [super dealloc]; -} - -- (void)windowDidLoad -{ - [super windowDidLoad]; - - mDownloadIsComplete = NO; - - if (!mIsFileSave) { - nsCOMPtr prefs(do_GetService(NS_PREF_CONTRACTID)); - PRBool save = PR_FALSE; - prefs->GetBoolPref("browser.download.progressDnldDialog.keepAlive", &save); - mSaveFileDialogShouldStayOpen = save; - } - - [self setupToolbar]; - [mProgressBar setUsesThreadedAnimation:YES]; - [mProgressBar startAnimation:self]; // move to onStateChange -} - -- (void)setupToolbar -{ - NSToolbar *toolbar = [[[NSToolbar alloc] initWithIdentifier:SaveFileToolbarIdentifier] autorelease]; - - [toolbar setDisplayMode:NSToolbarDisplayModeDefault]; - [toolbar setAllowsUserCustomization:YES]; - [toolbar setAutosavesConfiguration:YES]; - [toolbar setDelegate:self]; - [[self window] setToolbar:toolbar]; -} - -- (NSArray *)toolbarAllowedItemIdentifiers:(NSToolbar *)toolbar -{ - return [NSArray arrayWithObjects: CancelToolbarItemIdentifier, - ShowFileToolbarItemIdentifier, - OpenFileToolbarItemIdentifier, - LeaveOpenToolbarItemIdentifier, - NSToolbarCustomizeToolbarItemIdentifier, - NSToolbarFlexibleSpaceItemIdentifier, - NSToolbarSpaceItemIdentifier, - NSToolbarSeparatorItemIdentifier, - nil]; -} - -- (NSArray *)toolbarDefaultItemIdentifiers:(NSToolbar *)toolbar -{ - return [NSArray arrayWithObjects: CancelToolbarItemIdentifier, - NSToolbarFlexibleSpaceItemIdentifier, - LeaveOpenToolbarItemIdentifier, - NSToolbarFlexibleSpaceItemIdentifier, - ShowFileToolbarItemIdentifier, - OpenFileToolbarItemIdentifier, - nil]; -} - -- (BOOL)validateToolbarItem:(NSToolbarItem *)toolbarItem -{ - if ([toolbarItem action] == @selector(cancel)) // cancel button - return (!mDownloadIsComplete); - if ([toolbarItem action] == @selector(pauseAndResumeDownload)) // pause/resume button - return (NO); // Hey - it hasn't been hooked up yet. !mDownloadIsComplete when it is. - if ([toolbarItem action] == @selector(showFile)) // show file - return (mDownloadIsComplete); - if ([toolbarItem action] == @selector(openFile)) // open file - return (mDownloadIsComplete); - return YES; // turn it on otherwise. -} - --(void)autosaveWindowFrame -{ - [[self window] saveFrameUsingName: ProgressWindowFrameSaveName]; -} - -- (NSToolbarItem *) toolbar:(NSToolbar *)toolbar - itemForItemIdentifier:(NSString *)itemIdent - willBeInsertedIntoToolbar:(BOOL)willBeInserted -{ - NSToolbarItem *toolbarItem = [[[NSToolbarItem alloc] initWithItemIdentifier:itemIdent] autorelease]; - - if ( [itemIdent isEqual:CancelToolbarItemIdentifier] ) { - [toolbarItem setLabel:NSLocalizedString(@"Cancel",@"Cancel")]; - [toolbarItem setPaletteLabel:NSLocalizedString(@"CancelPaletteLabel",@"Cancel Download")]; - [toolbarItem setToolTip:NSLocalizedString(@"CancelToolTip",@"Cancel this file download")]; - [toolbarItem setImage:[NSImage imageNamed:@"saveCancel"]]; - [toolbarItem setTarget:self]; - [toolbarItem setAction:@selector(cancel)]; - } else if ( [itemIdent isEqual:ShowFileToolbarItemIdentifier] ) { - [toolbarItem setLabel:NSLocalizedString(@"Show File",@"Show File")]; - [toolbarItem setPaletteLabel:NSLocalizedString(@"Show File",@"Show File")]; - [toolbarItem setToolTip:NSLocalizedString(@"ShowToolTip",@"Show the saved file in the Finder")]; - [toolbarItem setImage:[NSImage imageNamed:@"saveShowFile"]]; - [toolbarItem setTarget:self]; - [toolbarItem setAction:@selector(showFile)]; - } else if ( [itemIdent isEqual:OpenFileToolbarItemIdentifier] ) { - [toolbarItem setLabel:NSLocalizedString(@"Open File",@"Open File")]; - [toolbarItem setPaletteLabel:NSLocalizedString(@"Open File",@"Open File")]; - [toolbarItem setToolTip:NSLocalizedString(@"OpenToolTip",@"Open the saved file in its default application.")]; - [toolbarItem setImage:[NSImage imageNamed:@"saveOpenFile"]]; - [toolbarItem setTarget:self]; - [toolbarItem setAction:@selector(openFile)]; - } else if ( [itemIdent isEqual:LeaveOpenToolbarItemIdentifier] ) { - if ( !mIsFileSave ) { - if ( mSaveFileDialogShouldStayOpen ) { - [toolbarItem setLabel:NSLocalizedString(@"Leave Open",@"Leave Open")]; - [toolbarItem setPaletteLabel:NSLocalizedString(@"Toggle Close Behavior",@"Toggle Close Behavior")]; - [toolbarItem setToolTip:NSLocalizedString(@"LeaveOpenToolTip",@"Window will stay open when download finishes.")]; - [toolbarItem setImage:[NSImage imageNamed:@"saveLeaveOpenYES"]]; - [toolbarItem setTarget:self]; - [toolbarItem setAction:@selector(toggleLeaveOpen)]; - } else { - [toolbarItem setLabel:NSLocalizedString(@"Close When Done",@"Close When Done")]; - [toolbarItem setPaletteLabel:NSLocalizedString(@"Toggle Close Behavior",@"Toggle Close Behavior")]; - [toolbarItem setToolTip:NSLocalizedString(@"CloseWhenDoneToolTip",@"Window will close automatically when download finishes.")]; - [toolbarItem setImage:[NSImage imageNamed:@"saveLeaveOpenNO"]]; - [toolbarItem setTarget:self]; - [toolbarItem setAction:@selector(toggleLeaveOpen)]; - } - if ( willBeInserted ) { - leaveOpenToggleToolbarItem = toolbarItem; //establish reference - } - } - } else { - toolbarItem = nil; - } - - return toolbarItem; -} - --(void)cancel -{ - if (mDownloader) // we should always have one - mDownloader->CancelDownload(); - - // clean up downloaded file. - do it here on in CancelDownload? - NSFileManager *fileManager = [NSFileManager defaultManager]; - NSString *thePath = [[mToField stringValue] stringByExpandingTildeInPath]; - if ([fileManager isDeletableFileAtPath:thePath]) - // if we delete it, fantastic. if not, oh well. better to move to trash instead? - [fileManager removeFileAtPath:thePath handler:nil]; - - // we can _not_ set the |mIsDownloadComplete| flag here because the download really - // isn't done yet. We'll probably continue to process more PLEvents that are already - // in the queue until we get a STATE_STOP state change. As a result, we just keep - // going until that comes in (and it will, because we called CancelDownload() above). - // Ensure that the window goes away when we get there by flipping the 'stay alive' - // flag. (bug 154913) - mSaveFileDialogShouldStayOpen = NO; -} - --(void)showFile -{ - NSString *theFile = [[mToField stringValue] stringByExpandingTildeInPath]; - if ([[NSWorkspace sharedWorkspace] selectFile:theFile - inFileViewerRootedAtPath:[theFile stringByDeletingLastPathComponent]]) - return; - // hmmm. it didn't work. that's odd. need localized error messages. for now, just beep. - NSBeep(); -} - --(void)openFile -{ - NSString *theFile = [[mToField stringValue] stringByExpandingTildeInPath]; - if ([[NSWorkspace sharedWorkspace] openFile:theFile]) - return; - // hmmm. it didn't work. that's odd. need localized error message. for now, just beep. - NSBeep(); - -} - --(void)toggleLeaveOpen -{ - if ( ! mSaveFileDialogShouldStayOpen ) { - mSaveFileDialogShouldStayOpen = YES; - [leaveOpenToggleToolbarItem setLabel:NSLocalizedString(@"Leave Open",@"Leave Open")]; - [leaveOpenToggleToolbarItem setPaletteLabel:NSLocalizedString(@"Toggle Close Behavior",@"Toggle Close Behavior")]; - [leaveOpenToggleToolbarItem setToolTip:NSLocalizedString(@"LeaveOpenToolTip",@"Window will stay open when download finishes.")]; - [leaveOpenToggleToolbarItem setImage:[NSImage imageNamed:@"saveLeaveOpenYES"]]; - } else { - mSaveFileDialogShouldStayOpen = NO; - [leaveOpenToggleToolbarItem setLabel:NSLocalizedString(@"Close When Done",@"Close When Done")]; - [leaveOpenToggleToolbarItem setPaletteLabel:NSLocalizedString(@"Toggle Close Behavior",@"Toggle Close Behavior")]; - [leaveOpenToggleToolbarItem setToolTip:NSLocalizedString(@"CloseWhenDoneToolTip",@"Window will close automatically when download finishes.")]; - [leaveOpenToggleToolbarItem setImage:[NSImage imageNamed:@"saveLeaveOpenNO"]]; - } - - nsCOMPtr prefs(do_GetService(NS_PREF_CONTRACTID)); - prefs->SetBoolPref("browser.download.progressDnldDialog.keepAlive", mSaveFileDialogShouldStayOpen); -} - -- (void)windowWillClose:(NSNotification *)notification -{ - [self autosaveWindowFrame]; - [self autorelease]; -} - -- (BOOL)windowShouldClose:(NSNotification *)notification -{ - [self killDownloadTimer]; - if (!mDownloadIsComplete) { //whoops. hard cancel. - [self cancel]; - return NO; // let setDownloadProgress handle the close. - } - return YES; -} - -- (void)killDownloadTimer -{ - if (mDownloadTimer) { - [mDownloadTimer invalidate]; - [mDownloadTimer release]; - mDownloadTimer = nil; - } -} -- (void)setupDownloadTimer -{ - [self killDownloadTimer]; - mDownloadTimer = [[NSTimer scheduledTimerWithTimeInterval:1.0 - target:self - selector:@selector(setDownloadProgress:) - userInfo:nil - repeats:YES] retain]; -} - --(NSString *)formatTime:(int)seconds -{ - NSMutableString *theTime =[[[NSMutableString alloc] initWithCapacity:8] autorelease]; - [theTime setString:@""]; - NSString *padZero = [NSString stringWithString:@"0"]; - //write out new elapsed time - if (seconds >= 3600){ - [theTime appendFormat:@"%d:",(seconds / 3600)]; - seconds = seconds % 3600; - } - NSString *elapsedMin = [NSString stringWithFormat:@"%d:",(seconds / 60)]; - if ([elapsedMin length] == 2) - [theTime appendString:[padZero stringByAppendingString:elapsedMin]]; - else - [theTime appendString:elapsedMin]; - seconds = seconds % 60; - NSString *elapsedSec = [NSString stringWithFormat:@"%d",seconds]; - if ([elapsedSec length] == 2) - [theTime appendString:elapsedSec]; - else - [theTime appendString:[padZero stringByAppendingString:elapsedSec]]; - return theTime; -} -// fuzzy time gives back strings like "about 5 seconds" --(NSString *)formatFuzzyTime:(int)seconds -{ - // check for seconds first - if (seconds < 60) { - if (seconds < 7) - return [[[NSString alloc] initWithFormat:NSLocalizedString(@"UnderSec",@"Under %d seconds"),5] autorelease]; - if (seconds < 13) - return [[[NSString alloc] initWithFormat:NSLocalizedString(@"UnderSec",@"Under %d seconds"),10] autorelease]; - return [[[NSString alloc] initWithString:NSLocalizedString(@"UnderMin",@"Under a minute")] autorelease]; - } - // seconds becomes minutes and we keep checking. - seconds = seconds/60; - if (seconds < 60) { - if (seconds < 2) - return [[[NSString alloc] initWithString:NSLocalizedString(@"AboutMin",@"About a minute")] autorelease]; - // OK, tell the good people how much time we have left. - return [[[NSString alloc] initWithFormat:NSLocalizedString(@"AboutMins",@"About %d minutes"),seconds] autorelease]; - } - //this download will never seemingly never end. now seconds become hours. - seconds = seconds/60; - if (seconds < 2) - return [[[NSString alloc] initWithString:NSLocalizedString(@"AboutHour",@"Over an hour")] autorelease]; - return [[[NSString alloc] initWithFormat:NSLocalizedString(@"AboutHours",@"Over %d hours"),seconds] autorelease]; -} - - --(NSString *)formatBytes:(float)bytes -{ // this is simpler than my first try. I peaked at Omnigroup byte formatting code. - // if bytes are negative, we return question marks. - if (bytes < 0) - return [[[NSString alloc] initWithString:@"???"] autorelease]; - // bytes first. - if (bytes < 1024) - return [[[NSString alloc] initWithFormat:@"%.1f bytes",bytes] autorelease]; - // kb - bytes = bytes/1024; - if (bytes < 1024) - return [[[NSString alloc] initWithFormat:@"%.1f KB",bytes] autorelease]; - // mb - bytes = bytes/1024; - if (bytes < 1024) - return [[[NSString alloc] initWithFormat:@"%.1f MB",bytes] autorelease]; - // gb - bytes = bytes/1024; - return [[[NSString alloc] initWithFormat:@"%.1f GB",bytes] autorelease]; -} - -// this handles lots of things. -- (void)setDownloadProgress:(NSTimer *)downloadTimer; -{ - // XXX this logic needs cleaning up. - - // Ack! we're closing the window with the download still running! - if (mDownloadIsComplete) - { - [[self window] performClose:self]; - return; - } - // get the elapsed time - NSArray *elapsedTimeArray = [[mElapsedTimeLabel stringValue] componentsSeparatedByString:@":"]; - int j = [elapsedTimeArray count]; - int elapsedSec = [[elapsedTimeArray objectAtIndex:(j-1)] intValue] + [[elapsedTimeArray objectAtIndex:(j-2)] intValue]*60; - if (j==3) // this download is taking forever. - elapsedSec += [[elapsedTimeArray objectAtIndex:0] intValue]*3600; - // update elapsed time - [mElapsedTimeLabel setStringValue:[self formatTime:(++elapsedSec)]]; - // for status field & time left - float maxBytes = ([mProgressBar maxValue]); - float byteSec = mCurrentProgress/elapsedSec; - // OK - if downloadTimer is nil, we're done - fix maxBytes value for status report. - if (!downloadTimer) - maxBytes = mCurrentProgress; - // update status field - NSString *labelString = NSLocalizedString(@"LabelString",@"%@ of %@ total (at %@/sec)"); - [mStatusLabel setStringValue: [NSString stringWithFormat:labelString, [self formatBytes:mCurrentProgress], [self formatBytes:maxBytes], [self formatBytes:byteSec]]]; - // updating estimated time left field - // if maxBytes < 0, can't calc time left. - // if !downloadTimer, download is finished. either way, make sure time left is 0. - if ((maxBytes > 0) && (downloadTimer)) - { - int secToGo = (int)ceil((elapsedSec*maxBytes/mCurrentProgress) - elapsedSec); - [mTimeLeftLabel setStringValue:[self formatFuzzyTime:secToGo]]; - } - else if (!downloadTimer) - { // download done. Set remaining time to 0, fix progress bar & cancel button - mDownloadIsComplete = YES; // all done. we got a STATE_STOP - [mTimeLeftLabel setStringValue:@""]; - [self setProgressTo:mCurrentProgress ofMax:mCurrentProgress]; - if (!mSaveFileDialogShouldStayOpen) - [[self window] performClose:self]; // close window - else - [[self window] update]; // redraw window - } - else //maxBytes is undetermined. Set remaining time to question marks. - [mTimeLeftLabel setStringValue:@"???"]; -} - -#pragma mark - - -// DownloadProgressDisplay protocol methods - -- (void)onStartDownload:(BOOL)isFileSave; -{ - mIsFileSave = isFileSave; - - [self window]; // make the window - [[self window] setFrameUsingName: ProgressWindowFrameSaveName]; - - [self showWindow: self]; - [self setupDownloadTimer]; -} - -- (void)onEndDownload -{ - // if we're quitting, our progress window is already gone and we're in the - // process of shutting down gecko and all the d/l listeners. The timer, at - // that point, is the only thing keeping us alive. Killing it will cause - // us to go away immediately, so kung-fu deathgrip it until we're done twiddling - // bits on ourself. - [self retain]; // Enter The Dragon! - [self killDownloadTimer]; - [self setDownloadProgress:nil]; - [self release]; -} - -- (void)setProgressTo:(long)aCurProgress ofMax:(long)aMaxProgress -{ - mCurrentProgress = aCurProgress; // fall back for stat calcs - - if (![mProgressBar isIndeterminate]) //most likely - just update value - { - if (aCurProgress == aMaxProgress) //handles little bug in FTP download size - [mProgressBar setMaxValue:aMaxProgress]; - - [mProgressBar setDoubleValue:aCurProgress]; - } - else if (aMaxProgress > 0) // ok, we're starting up with good max & cur values - { - [mProgressBar setIndeterminate:NO]; - [mProgressBar setMaxValue:aMaxProgress]; - [mProgressBar setDoubleValue:aCurProgress]; - } // if neither case was true, it's barber pole city. -} - --(void) setDownloadListener: (CHDownloader*)aDownloader -{ - if (mDownloader != aDownloader) - NS_IF_RELEASE(mDownloader); - - NS_IF_ADDREF(mDownloader = aDownloader); -} - -- (void)setSourceURL:(NSString*)aSourceURL -{ - [mFromField setStringValue: aSourceURL]; - [mFromField display]; // force an immmeditate update -} - -- (void)setDestinationPath:(NSString*)aDestPath -{ - [mToField setStringValue: [aDestPath stringByAbbreviatingWithTildeInPath]]; - [mToField display]; // force an immmeditate update - - // also set the window title - NSString* downloadFileName = [aDestPath lastPathComponent]; - if ([downloadFileName length] == 0) - downloadFileName = aDestPath; - - [[self window] setTitle:[NSString stringWithFormat:NSLocalizedString(@"DownloadingTitle", @""), downloadFileName]]; -} - -@end diff --git a/mozilla/camino/RemoteDataProvider.h b/mozilla/camino/RemoteDataProvider.h deleted file mode 100644 index 13ff9a3af4a..00000000000 --- a/mozilla/camino/RemoteDataProvider.h +++ /dev/null @@ -1,90 +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): - * Simon Fraser - * - * 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 - - -extern NSString* RemoteDataLoadRequestNotificationName; -extern NSString* RemoteDataLoadRequestURIKey; -extern NSString* RemoteDataLoadRequestDataKey; -extern NSString* RemoteDataLoadRequestUserDataKey; -extern NSString* RemoteDataLoadRequestResultKey; - -// RemoteDataProvider is a class that can be used to do asynchronous loads -// from URIs using necko, and passing back the result of the load to a -// callback in NSData. -// -// Clients can either implement the RemoteLoadListener protocol and call -// loadURI directly, or they can register with the [NSNotification defaultCenter] -// for 'RemoteDataLoadRequestNotificationName' notifications, and catch all loads -// that happen that way. - -@protocol RemoteLoadListener -// called when the load completes, or fails. If the status code is a failure code, -// data may be nil. -- (void)doneRemoteLoad:(NSString*)inURI forTarget:(id)target withUserData:(id)userData data:(NSData*)data status:(nsresult)status; -@end - - -class RemoteURILoadManager; - -@interface RemoteDataProvider : NSObject -{ - RemoteURILoadManager* mLoadManager; -} - -+ (RemoteDataProvider*)sharedRemoteDataProvider; - -// generic method. You can load any URI asynchronously with this selector, -// and the listener will get the contents of the URI in an NSData. -// If allowNetworking is NO, then this method will just check the cache, -// and not go to the network -// This method will return YES if the request was dispatched, or NO otherwise. -- (BOOL)loadURI:(NSString*)inURI forTarget:(id)target withListener:(id)inListener - withUserData:(id)userData allowNetworking:(BOOL)inNetworkOK; - -// specific request to load a remote file. The sender (or any other object), if -// registered with the notification center, will receive a notification when -// the load completes. The 'target' becomes the 'object' of the notification. -// The notification name is given by NSString* RemoteDataLoadRequestNotificationName above. -// If allowNetworking is NO, then this method will just check the cache, -// and not go to the network -// This method will return YES if the request was dispatched, or NO otherwise. -- (BOOL)postURILoadRequest:(NSString*)inURI forTarget:(id)target - withUserData:(id)userData allowNetworking:(BOOL)inNetworkOK; - -@end diff --git a/mozilla/camino/RemoteDataProvider.mm b/mozilla/camino/RemoteDataProvider.mm deleted file mode 100644 index 9bd81c14650..00000000000 --- a/mozilla/camino/RemoteDataProvider.mm +++ /dev/null @@ -1,299 +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): - * Simon Fraser - * - * 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 "NSString+Utils.h" - -#import "RemoteDataProvider.h" - -#include "nsISupports.h" -#include "nsHashtable.h" -#include "nsNetUtil.h" -#include "nsICacheSession.h" -#include "nsICacheService.h" -#include "nsICacheEntryDescriptor.h" - -NSString* RemoteDataLoadRequestNotificationName = @"remoteload_notification_name"; -NSString* RemoteDataLoadRequestURIKey = @"remoteload_uri_key"; -NSString* RemoteDataLoadRequestDataKey = @"remoteload_data_key"; -NSString* RemoteDataLoadRequestUserDataKey = @"remoteload_user_data_key"; -NSString* RemoteDataLoadRequestResultKey = @"remoteload_result_key"; - - -// this has to retain the load listener, to ensure that the listener lives long -// enough to receive notifications. We have to be careful to avoid ref cycles. -class StreamLoaderContext : public nsISupports -{ -public: - StreamLoaderContext(id inLoadListener, id inUserData, id inTarget, const nsAString& inURI) - : mLoadListener(inLoadListener) - , mTarget(inTarget) - , mUserData(inUserData) - , mURI(inURI) - { - NS_INIT_ISUPPORTS(); - [mLoadListener retain]; - } - - virtual ~StreamLoaderContext() - { - [mLoadListener release]; - } - - NS_DECL_ISUPPORTS - - void LoadComplete(nsresult inLoadStatus, const void* inData, unsigned int inDataLength); - const nsAString& GetURI() { return mURI; } - -protected: - - id mLoadListener; // retained - id mTarget; // not retained - id mUserData; // not retained - nsString mURI; - -}; - - -NS_IMPL_ISUPPORTS1(StreamLoaderContext, nsISupports) - -void StreamLoaderContext::LoadComplete(nsresult inLoadStatus, const void* inData, unsigned int inDataLength) -{ - if (mLoadListener) - { - NSData* loadData = nil; - if (NS_SUCCEEDED(inLoadStatus)) - loadData = [NSData dataWithBytes:inData length:inDataLength]; - - [mLoadListener doneRemoteLoad:[NSString stringWith_nsAString:mURI] forTarget:mTarget withUserData:mUserData data:loadData status:inLoadStatus]; - } -} - - -class RemoteURILoadManager : public nsIStreamLoaderObserver -{ -public: - - RemoteURILoadManager(); - virtual ~RemoteURILoadManager(); - - NS_DECL_ISUPPORTS - NS_DECL_NSISTREAMLOADEROBSERVER - - nsresult Init(); - nsresult RequestURILoad(const nsAString& inURI, id loadListener, id userData, id target, PRBool allowNetworking); - -protected: - - nsSupportsHashtable mStreamLoaderHash; // hash of active stream loads, keyed on URI - nsCOMPtr mCacheSession; - -}; - -RemoteURILoadManager::RemoteURILoadManager() -{ - NS_INIT_ISUPPORTS(); -} - -RemoteURILoadManager::~RemoteURILoadManager() -{ -} - -NS_IMPL_ISUPPORTS1(RemoteURILoadManager, nsIStreamLoaderObserver) - -NS_IMETHODIMP RemoteURILoadManager::OnStreamComplete(nsIStreamLoader *loader, nsISupports *ctxt, nsresult status, PRUint32 resultLength, const char *result) -{ - StreamLoaderContext* loaderContext = NS_STATIC_CAST(StreamLoaderContext*, ctxt); - if (loaderContext) - { - loaderContext->LoadComplete(status, (const void*)result, resultLength); - - // remove the stream loader from the hash table - nsStringKey uriKey(loaderContext->GetURI()); - PRBool removed = mStreamLoaderHash.Remove(&uriKey); - } - - return NS_OK; -} - -static NS_DEFINE_CID(kCacheServiceCID, NS_CACHESERVICE_CID); - -nsresult RemoteURILoadManager::Init() -{ - nsresult rv; - nsCOMPtr cacheService = do_GetService(kCacheServiceCID, &rv); - if (NS_FAILED(rv)) - return rv; - - rv = cacheService->CreateSession("HTTP", nsICache::STORE_ANYWHERE, - nsICache::STREAM_BASED, getter_AddRefs(mCacheSession)); - - return rv; -} - -nsresult RemoteURILoadManager::RequestURILoad(const nsAString& inURI, id loadListener, - id userData, id target, PRBool allowNetworking) -{ - nsresult rv; - -#if 0 - // if no networking is allowed, make sure it's in the cache - if (!allowNetworking) - { - if (!mCacheSession) - return NS_ERROR_FAILURE; - - nsCOMPtr entryDesc; - rv = mCacheSession->OpenCacheEntry(NS_ConvertUCS2toUTF8(inURI).get(), nsICache::ACCESS_READ, nsICache::NON_BLOCKING, getter_AddRefs(entryDesc)); - if (NS_FAILED(rv) || !entryDesc) - return NS_ERROR_FAILURE; - } -#endif - - nsStringKey uriKey(inURI); - - // first make sure that there isn't another entry in the hash for this - nsCOMPtr foundStreamSupports = mStreamLoaderHash.Get(&uriKey); - if (foundStreamSupports) - return NS_OK; - - nsCOMPtr uri; - rv = NS_NewURI(getter_AddRefs(uri), inURI); - if (NS_FAILED(rv)) - return rv; - - nsCOMPtr loaderContext = new StreamLoaderContext(loadListener, userData, target, inURI); - - nsLoadFlags loadFlags = (allowNetworking) ? nsIRequest::LOAD_NORMAL : nsIRequest::LOAD_FROM_CACHE; - loadFlags |= nsIRequest::LOAD_BACKGROUND; // don't show progress or cookie dialogs - nsCOMPtr streamLoader; - rv = NS_NewStreamLoader(getter_AddRefs(streamLoader), uri, this, loaderContext, nsnull, nsnull, loadFlags); - if (NS_FAILED(rv)) - { - NSLog(@"NS_NewStreamLoader for favicon failed"); - return rv; - } - -#ifdef DEBUG_smfr - NSLog(@"RequestURILoad called for %@", [NSString stringWith_nsAString: inURI]); -#endif - - // put the stream loader into the hash table - nsCOMPtr streamLoaderAsSupports = do_QueryInterface(streamLoader); - mStreamLoaderHash.Put(&uriKey, streamLoaderAsSupports); - - return NS_OK; -} - - -#pragma mark - - - -@implementation RemoteDataProvider - - -+ (RemoteDataProvider*)sharedRemoteDataProvider -{ - static RemoteDataProvider* sIconProvider = nil; - if (!sIconProvider) - { - sIconProvider = [[RemoteDataProvider alloc] init]; - - // we probably need to register for NSApplicationWillTerminateNotification notifications - // and delete this then. - } - - return sIconProvider; -} - -- (id)init -{ - if ((self = [super init])) - { - mLoadManager = new RemoteURILoadManager; - NS_ADDREF(mLoadManager); - } - - return self; -} - -- (void)dealloc -{ - NS_IF_RELEASE(mLoadManager); - [super dealloc]; -} - -- (BOOL)loadURI:(NSString*)inURI forTarget:(id)target withListener:(id)inListener - withUserData:(id)userData allowNetworking:(BOOL)inNetworkOK -{ - //NSLog(@"loadURI called with %@", inURI); - if (mLoadManager && [inURI length] > 0) - { - nsAutoString uriString; - [inURI assignTo_nsAString:uriString]; - - nsresult rv = mLoadManager->RequestURILoad(uriString, inListener, userData, target, (PRBool)inNetworkOK); - if (NS_FAILED(rv)) - { - NSLog(@"RequestURILoad failed for @%", inURI); - return NO; - } - } - - return YES; -} - -- (BOOL)postURILoadRequest:(NSString*)inURI forTarget:(id)target withUserData:(id)userData allowNetworking:(BOOL)inNetworkOK -{ - return [self loadURI:inURI forTarget:target withListener:self withUserData:userData allowNetworking:inNetworkOK]; -} - -// our own load listener callback -- (void)doneRemoteLoad:(NSString*)inURI forTarget:(id)target withUserData:(id)userData data:(NSData*)data status:(nsresult)status -{ - NSDictionary* notificationData = [NSDictionary dictionaryWithObjectsAndKeys: - inURI, RemoteDataLoadRequestURIKey, - data, RemoteDataLoadRequestDataKey, - userData, RemoteDataLoadRequestUserDataKey, - [NSNumber numberWithInt:status], RemoteDataLoadRequestResultKey, - nil]; - - // NSLog(@"remoteLoadDone with status %d and length %d", status, [data length]); - [[NSNotificationCenter defaultCenter] postNotificationName: RemoteDataLoadRequestNotificationName - object:target userInfo:notificationData]; -} - -@end diff --git a/mozilla/camino/SaveHeaderSniffer.h b/mozilla/camino/SaveHeaderSniffer.h deleted file mode 100644 index 2fcbc55a554..00000000000 --- a/mozilla/camino/SaveHeaderSniffer.h +++ /dev/null @@ -1,84 +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): - * David Hyatt - * Simon Fraser - * - * 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 -#import - -#include "nsString.h" -#include "nsIWebProgressListener.h" -#include "nsIWebBrowserPersist.h" -#include "nsIURI.h" -#include "nsILocalFile.h" -#include "nsIInputStream.h" -#include "nsIDOMDocument.h" - - -// Implementation of a header sniffer class that is used when saving Web pages and images. -class nsHeaderSniffer : public nsIWebProgressListener -{ -public: - nsHeaderSniffer(nsIWebBrowserPersist* aPersist, nsIFile* aFile, nsIURI* aURL, - nsIDOMDocument* aDocument, nsIInputStream* aPostData, - const nsCString& aSuggestedFilename, PRBool aBypassCache, - NSView* aFilterView, NSPopUpButton* aFilterList); - virtual ~nsHeaderSniffer(); - - NS_DECL_ISUPPORTS - NS_DECL_NSIWEBPROGRESSLISTENER - -protected: - - nsresult PerformSave(nsIURI* inOriginalURI); - nsresult InitiateDownload(nsISupports* inSourceData, nsString& inFileName, nsIURI* inOriginalURI); - -private: - - nsIWebBrowserPersist* mPersist; // Weak. It owns us as a listener. - nsCOMPtr mTmpFile; - nsCOMPtr mURL; - nsCOMPtr mDocument; - nsCOMPtr mPostData; - nsCString mDefaultFilename; - PRBool mBypassCache; - nsCString mContentType; - nsCString mContentDisposition; - NSView* mFilterView; - NSPopUpButton* mFilterList; -}; - diff --git a/mozilla/camino/SaveHeaderSniffer.mm b/mozilla/camino/SaveHeaderSniffer.mm deleted file mode 100644 index b4fa380e314..00000000000 --- a/mozilla/camino/SaveHeaderSniffer.mm +++ /dev/null @@ -1,386 +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): - * David Hyatt - * Simon Fraser - * - * 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 ***** */ - -#include "SaveHeaderSniffer.h" - -#include "netCore.h" - -#include "nsIChannel.h" -#include "nsIHttpChannel.h" -#include "nsIURL.h" -#include "nsIPrefService.h" -#include "nsIMIMEService.h" -#include "nsIMIMEInfo.h" -#include "nsIDOMHTMLDocument.h" -#include "nsIDownload.h" - -const char* const persistContractID = "@mozilla.org/embedding/browser/nsWebBrowserPersist;1"; - -nsHeaderSniffer::nsHeaderSniffer(nsIWebBrowserPersist* aPersist, nsIFile* aFile, nsIURI* aURL, - nsIDOMDocument* aDocument, nsIInputStream* aPostData, - const nsCString& aSuggestedFilename, PRBool aBypassCache, - NSView* aFilterView, NSPopUpButton* aFilterList) -: mPersist(aPersist) -, mTmpFile(aFile) -, mURL(aURL) -, mDocument(aDocument) -, mPostData(aPostData) -, mDefaultFilename(aSuggestedFilename) -, mBypassCache(aBypassCache) -, mFilterView(aFilterView) -, mFilterList(aFilterList) -{ - NS_INIT_ISUPPORTS(); -} - -nsHeaderSniffer::~nsHeaderSniffer() -{ -} - -NS_IMPL_ISUPPORTS1(nsHeaderSniffer, nsIWebProgressListener) - -#pragma mark - - -// Implementation of nsIWebProgressListener -/* void onStateChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in long aStateFlags, in unsigned long aStatus); */ -NS_IMETHODIMP -nsHeaderSniffer::OnStateChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, PRUint32 aStateFlags, - PRUint32 aStatus) -{ - if (aStateFlags & nsIWebProgressListener::STATE_START) - { - nsCOMPtr kungFuDeathGrip(mPersist); // be sure to keep it alive while we save - // since it owns us as a listener - nsCOMPtr kungFuSuicideGrip(this); // and keep ourslves alive - - nsresult rv; - nsCOMPtr channel = do_QueryInterface(aRequest, &rv); - if (!channel) return rv; - channel->GetContentType(mContentType); - - nsCOMPtr origURI; - channel->GetOriginalURI(getter_AddRefs(origURI)); - - // Get the content-disposition if we're an HTTP channel. - nsCOMPtr httpChannel(do_QueryInterface(channel)); - if (httpChannel) - httpChannel->GetResponseHeader(nsCAutoString("content-disposition"), mContentDisposition); - - mPersist->CancelSave(); - PRBool exists; - mTmpFile->Exists(&exists); - if (exists) - mTmpFile->Remove(PR_FALSE); - - rv = PerformSave(origURI); - if (NS_FAILED(rv)) - { - // put up some UI - NSLog(@"Error saving web page"); - } - } - return NS_OK; -} - -/* void onProgressChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in long aCurSelfProgress, in long aMaxSelfProgress, in long aCurTotalProgress, in long aMaxTotalProgress); */ -NS_IMETHODIMP -nsHeaderSniffer::OnProgressChange(nsIWebProgress *aWebProgress, - nsIRequest *aRequest, - PRInt32 aCurSelfProgress, - PRInt32 aMaxSelfProgress, - PRInt32 aCurTotalProgress, - PRInt32 aMaxTotalProgress) -{ - return NS_OK; -} - -/* void onLocationChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in nsIURI location); */ -NS_IMETHODIMP -nsHeaderSniffer::OnLocationChange(nsIWebProgress *aWebProgress, - nsIRequest *aRequest, - nsIURI *location) -{ - return NS_OK; -} - -/* void onStatusChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in nsresult aStatus, in wstring aMessage); */ -NS_IMETHODIMP -nsHeaderSniffer::OnStatusChange(nsIWebProgress *aWebProgress, - nsIRequest *aRequest, - nsresult aStatus, - const PRUnichar *aMessage) -{ - return NS_OK; -} - -/* void onSecurityChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in unsigned long state); */ -NS_IMETHODIMP -nsHeaderSniffer::OnSecurityChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, PRUint32 state) -{ - return NS_OK; -} - -#pragma mark - - - -nsresult nsHeaderSniffer::PerformSave(nsIURI* inOriginalURI) -{ - nsresult rv; - // Are we an HTML document? If so, we will want to append an accessory view to - // the save dialog to provide the user with the option of doing a complete - // save vs. a single file save. - PRBool isHTML = (mDocument && mContentType.Equals("text/html") || - mContentType.Equals("text/xml") || - mContentType.Equals("application/xhtml+xml")); - - // Next find out the directory that we should start in. - nsCOMPtr prefs(do_GetService("@mozilla.org/preferences-service;1", &rv)); - if (!prefs) - return rv; - nsCOMPtr dirBranch; - prefs->GetBranch("browser.download.", getter_AddRefs(dirBranch)); - PRInt32 filterIndex = 0; - if (dirBranch) { - nsresult rv = dirBranch->GetIntPref("save_converter_index", &filterIndex); - if (NS_FAILED(rv)) - filterIndex = 0; - } - if (mFilterList) - [mFilterList selectItemAtIndex: filterIndex]; - - // We need to figure out what file name to use. - nsCAutoString defaultFileName; - if (!mContentDisposition.IsEmpty()) { - // (1) Use the HTTP header suggestion. - PRInt32 index = mContentDisposition.Find("filename="); - if (index >= 0) { - // Take the substring following the prefix. - index += 9; - nsCAutoString filename; - mContentDisposition.Right(filename, mContentDisposition.Length() - index); - defaultFileName = filename; - } - } - - if (defaultFileName.IsEmpty()) { - nsCOMPtr url(do_QueryInterface(mURL)); - if (url) - url->GetFileName(defaultFileName); // (2) For file URLs, use the file name. - } - - if (defaultFileName.IsEmpty() && mDocument && isHTML) { - nsCOMPtr htmlDoc(do_QueryInterface(mDocument)); - nsAutoString title; - if (htmlDoc) - htmlDoc->GetTitle(title); // (3) Use the title of the document. - defaultFileName.AssignWithConversion(title); - } - - if (defaultFileName.IsEmpty()) { - // (4) Use the caller provided name. - defaultFileName = mDefaultFilename; - } - - if (defaultFileName.IsEmpty() && mURL) - // (5) Use the host. - mURL->GetHost(defaultFileName); - - // One last case to handle about:blank and other fruity untitled pages. - if (defaultFileName.IsEmpty()) - defaultFileName = "untitled"; - - // Validate the file name to ensure legality. - for (PRUint32 i = 0; i < defaultFileName.Length(); i++) - if (defaultFileName[i] == ':' || defaultFileName[i] == '/') - defaultFileName.SetCharAt(i, ' '); - - // Make sure the appropriate extension is appended to the suggested file name. - nsCOMPtr fileURI(do_CreateInstance("@mozilla.org/network/standard-url;1")); - nsCOMPtr fileURL(do_QueryInterface(fileURI, &rv)); - if (!fileURL) - return rv; - fileURL->SetFilePath(defaultFileName); - - nsCAutoString fileExtension; - fileURL->GetFileExtension(fileExtension); - - PRBool setExtension = PR_FALSE; - if (mContentType.Equals("text/html")) { - if (fileExtension.IsEmpty() || (!fileExtension.Equals("htm") && !fileExtension.Equals("html"))) { - defaultFileName += ".html"; - setExtension = PR_TRUE; - } - } - - if (!setExtension && fileExtension.IsEmpty()) { - nsCOMPtr mimeService(do_GetService("@mozilla.org/mime;1", &rv)); - if (!mimeService) - return rv; - nsCOMPtr mimeInfo; - rv = mimeService->GetFromMIMEType(mContentType.get(), getter_AddRefs(mimeInfo)); - if (!mimeInfo) - return rv; - - PRUint32 extCount = 0; - char** extList = nsnull; - mimeInfo->GetFileExtensions(&extCount, &extList); - if (extCount > 0 && extList) { - defaultFileName += "."; - defaultFileName += extList[0]; - } - } - - // Now it's time to pose the save dialog. - NSSavePanel* savePanel = [NSSavePanel savePanel]; - NSString* file = nil; - if (!defaultFileName.IsEmpty()) - file = [[NSString alloc] initWithCString: defaultFileName.get()]; - - if (isHTML) - [savePanel setAccessoryView: mFilterView]; - - if ([savePanel runModalForDirectory: nil file: file] == NSFileHandlingPanelCancelButton) - return NS_OK; - - // Release the file string. - [file release]; - - // Update the filter index. - if (isHTML && mFilterList) { - filterIndex = [mFilterList indexOfSelectedItem]; - dirBranch->SetIntPref("save_converter_index", filterIndex); - } - - // Convert the content type to text/plain if it was selected in the filter. - if (isHTML && filterIndex == 2) - mContentType = "text/plain"; - - nsCOMPtr sourceData; - if (isHTML && filterIndex != 1) - sourceData = do_QueryInterface(mDocument); - else - sourceData = do_QueryInterface(mURL); - - NSString* destName = [savePanel filename]; - - PRUint32 dstLen = [destName length]; - PRUnichar* tmp = new PRUnichar[dstLen + sizeof(PRUnichar)]; - tmp[dstLen] = (PRUnichar)'\0'; - [destName getCharacters:tmp]; - nsAutoString dstString(tmp); - delete tmp; - - return InitiateDownload(sourceData, dstString, inOriginalURI); -} - -// inOriginalURI is always a URI. inSourceData can be an nsIURI or an nsIDOMDocument, depending -// on what we're saving. It's that way for nsIWebBrowserPersist. -nsresult nsHeaderSniffer::InitiateDownload(nsISupports* inSourceData, nsString& inFileName, nsIURI* inOriginalURI) -{ - nsresult rv = NS_OK; - - nsCOMPtr webPersist = do_CreateInstance(persistContractID, &rv); - if (NS_FAILED(rv)) return rv; - - nsCOMPtr sourceURI = do_QueryInterface(inSourceData); - - nsCOMPtr destFile; - rv = NS_NewLocalFile(inFileName, PR_FALSE, getter_AddRefs(destFile)); - if (NS_FAILED(rv)) return rv; - - PRInt64 timeNow = PR_Now(); - - nsCOMPtr downloader = do_CreateInstance(NS_DOWNLOAD_CONTRACTID); - // dlListener attaches to its progress dialog here, which gains ownership - rv = downloader->Init(inOriginalURI, destFile, inFileName.get(), nsString().get(), timeNow, webPersist); - if (NS_FAILED(rv)) return rv; - - PRInt32 flags = nsIWebBrowserPersist::PERSIST_FLAGS_NO_CONVERSION | - nsIWebBrowserPersist::PERSIST_FLAGS_REPLACE_EXISTING_FILES; - if (mBypassCache) - flags |= nsIWebBrowserPersist::PERSIST_FLAGS_BYPASS_CACHE; - else - flags |= nsIWebBrowserPersist::PERSIST_FLAGS_FROM_CACHE; - - if (sourceURI) - { - rv = webPersist->SaveURI(sourceURI, mPostData, destFile); - } - else - { - nsCOMPtr domDoc = do_QueryInterface(inSourceData, &rv); - if (!domDoc) return rv; // should never happen - - PRInt32 encodingFlags = 0; - nsCOMPtr filesFolder; - - if (!mContentType.Equals("text/plain")) { - // Create a local directory in the same dir as our file. It - // will hold our associated files. - filesFolder = do_CreateInstance("@mozilla.org/file/local;1"); - nsAutoString unicodePath; - destFile->GetPath(unicodePath); - filesFolder->InitWithPath(unicodePath); - - nsAutoString leafName; - filesFolder->GetLeafName(leafName); - nsAutoString nameMinusExt(leafName); - PRInt32 index = nameMinusExt.RFind("."); - if (index >= 0) - nameMinusExt.Left(nameMinusExt, index); - nameMinusExt += NS_LITERAL_STRING(" Files"); // XXXdwh needs to be localizable! - filesFolder->SetLeafName(nameMinusExt); - PRBool exists = PR_FALSE; - filesFolder->Exists(&exists); - if (!exists) { - rv = filesFolder->Create(nsILocalFile::DIRECTORY_TYPE, 0755); - if (NS_FAILED(rv)) - return rv; - } - } - else - { - encodingFlags |= nsIWebBrowserPersist::ENCODE_FLAGS_FORMATTED | - nsIWebBrowserPersist::ENCODE_FLAGS_ABSOLUTE_LINKS | - nsIWebBrowserPersist::ENCODE_FLAGS_NOFRAMES_CONTENT; - } - rv = webPersist->SaveDocument(domDoc, destFile, filesFolder, mContentType.get(), encodingFlags, 80); - } - - return rv; -} diff --git a/mozilla/camino/SecurityDialogs.h b/mozilla/camino/SecurityDialogs.h deleted file mode 100644 index 0b27200ad47..00000000000 --- a/mozilla/camino/SecurityDialogs.h +++ /dev/null @@ -1,70 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** 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 mozilla.org 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): - * Brian Ryner - * - * 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 ***** */ - -#ifndef __SecurityDialogs_h__ -#define __SecurityDialogs_h__ - -#include "nsIBadCertListener.h" -#include "nsISecurityWarningDialogs.h" -#include "nsINSSDialogs.h" -#include "nsIStringBundle.h" - -class SecurityDialogs : public nsIBadCertListener, - public nsISecurityWarningDialogs, - public nsINSSDialogs -{ -public: - SecurityDialogs(); - virtual ~SecurityDialogs(); - - NS_DECL_ISUPPORTS; - NS_DECL_NSIBADCERTLISTENER; - NS_DECL_NSISECURITYWARNINGDIALOGS; - NS_DECL_NSINSSDIALOGS; - -private: - nsresult EnsureSecurityStringBundle(); - - nsresult AlertDialog(nsIInterfaceRequestor* ctx, const char* prefName, - const PRUnichar* messageName, - const PRUnichar* showAgainName); - - nsCOMPtr mSecurityStringBundle; -}; - -#endif diff --git a/mozilla/camino/SecurityDialogs.mm b/mozilla/camino/SecurityDialogs.mm deleted file mode 100644 index a07700a153b..00000000000 --- a/mozilla/camino/SecurityDialogs.mm +++ /dev/null @@ -1,278 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** 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 mozilla.org 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): - * Brian Ryner - * - * 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 "nsAlertController.h" -#import "nsCocoaBrowserService.h" -#import "SecurityDialogs.h" -#import "MainController.h" - -#include "nsString.h" -#include "nsIPrefBranch.h" -#include "nsIPrompt.h" -#include "nsIInterfaceRequestor.h" -#include "nsIInterfaceRequestorUtils.h" -#include "nsIServiceManagerUtils.h" - -SecurityDialogs::SecurityDialogs() -{ - NS_INIT_ISUPPORTS(); -} - -SecurityDialogs::~SecurityDialogs() -{ -} - -NS_IMPL_ISUPPORTS3(SecurityDialogs, nsIBadCertListener, - nsISecurityWarningDialogs, nsINSSDialogs); - -// nsIBadCertListener implementation -/* boolean unknownIssuer (in nsITransportSecurityInfo socketInfo, - in nsIX509Cert cert, out addType); */ -NS_IMETHODIMP -SecurityDialogs::UnknownIssuer(nsITransportSecurityInfo *socketInfo, - nsIX509Cert *cert, PRInt16 *outAddType, - PRBool *_retval) -{ - *_retval = PR_TRUE; - *outAddType = ADD_TRUSTED_FOR_SESSION; - - nsAlertController* controller = nsCocoaBrowserService::GetAlertController(); - if (!controller) - return NS_ERROR_FAILURE; - - // HACK: there is no way to get which window this is for from the API. The - // security team in mozilla just cheats and assumes the frontmost window so - // that's what we'll do. Yes, it's wrong. Yes, it's skanky. Oh well. - *outAddType = (PRBool)[controller unknownCert:[(MainController*)[NSApp delegate] getFrontmostBrowserWindow]]; - switch ( *outAddType ) { - case nsIBadCertListener::ADD_TRUSTED_FOR_SESSION: - case nsIBadCertListener::ADD_TRUSTED_PERMANENTLY: - *_retval = PR_TRUE; - break; - default: - *_retval = PR_FALSE; - } - - return NS_OK; -} - -/* boolean mismatchDomain (in nsITransportSecurityInfo socketInfo, - in wstring targetURL, - in nsIX509Cert cert); */ -NS_IMETHODIMP -SecurityDialogs::MismatchDomain(nsITransportSecurityInfo *socketInfo, - const PRUnichar *targetURL, - nsIX509Cert *cert, PRBool *_retval) -{ - nsAlertController* controller = nsCocoaBrowserService::GetAlertController(); - if (!controller) - return NS_ERROR_FAILURE; - - // HACK: there is no way to get which window this is for from the API. The - // security team in mozilla just cheats and assumes the frontmost window so - // that's what we'll do. Yes, it's wrong. Yes, it's skanky. Oh well. - *_retval = (PRBool)[controller badCert:[(MainController*)[NSApp delegate] getFrontmostBrowserWindow]]; - - return NS_OK; -} - - -/* boolean certExpired (in nsITransportSecurityInfo socketInfo, - in nsIX509Cert cert); */ -NS_IMETHODIMP -SecurityDialogs::CertExpired(nsITransportSecurityInfo *socketInfo, - nsIX509Cert *cert, PRBool *_retval) -{ - nsAlertController* controller = nsCocoaBrowserService::GetAlertController(); - if (!controller) - return NS_ERROR_FAILURE; - - // HACK: there is no way to get which window this is for from the API. The - // security team in mozilla just cheats and assumes the frontmost window so - // that's what we'll do. Yes, it's wrong. Yes, it's skanky. Oh well. - *_retval = (PRBool)[controller expiredCert:[(MainController*)[NSApp delegate] getFrontmostBrowserWindow]]; - - return NS_OK; -} - -NS_IMETHODIMP -SecurityDialogs::CrlNextupdate(nsITransportSecurityInfo *socketInfo, - const PRUnichar * targetURL, nsIX509Cert *cert) -{ - // what does this do!? - return NS_OK; -} - - -// nsISecurityWarningDialogs implementation -#define ENTER_SITE_PREF "security.warn_entering_secure" -#define WEAK_SITE_PREF "security.warn_entering_weak" -#define LEAVE_SITE_PREF "security.warn_leaving_secure" - -#define MIXEDCONTENT_PREF "security.warn_viewing_mixed" -#define INSECURE_SUBMIT_PREF "security.warn_submit_insecure" - -NS_IMETHODIMP -SecurityDialogs::AlertEnteringSecure(nsIInterfaceRequestor *ctx) -{ - // I don't think any user cares they're entering a secure site. - #if 0 - rv = AlertDialog(ctx, ENTER_SITE_PREF, - NS_LITERAL_STRING("EnterSecureMessage").get(), - NS_LITERAL_STRING("EnterSecureShowAgain").get()); - #endif - - return NS_OK; -} - -NS_IMETHODIMP -SecurityDialogs::AlertEnteringWeak(nsIInterfaceRequestor *ctx) -{ - return AlertDialog(ctx, WEAK_SITE_PREF, - NS_LITERAL_STRING("WeakSecureMessage").get(), - NS_LITERAL_STRING("WeakSecureShowAgain").get()); -} - -NS_IMETHODIMP -SecurityDialogs::AlertLeavingSecure(nsIInterfaceRequestor *ctx) -{ - return AlertDialog(ctx, LEAVE_SITE_PREF, - NS_LITERAL_STRING("LeaveSecureMessage").get(), - NS_LITERAL_STRING("LeaveSecureShowAgain").get()); -} - - -NS_IMETHODIMP -SecurityDialogs::AlertMixedMode(nsIInterfaceRequestor *ctx) -{ - return AlertDialog(ctx, MIXEDCONTENT_PREF, - NS_LITERAL_STRING("MixedContentMessage").get(), - NS_LITERAL_STRING("MixedContentShowAgain").get()); -} - - -NS_IMETHODIMP -SecurityDialogs::ConfirmPostToInsecure(nsIInterfaceRequestor *ctx, - PRBool* _result) -{ - // no user cares about this. the first thing they do is turn it off. - *_result = PR_TRUE; - return NS_OK; -} - -NS_IMETHODIMP -SecurityDialogs::ConfirmPostToInsecureFromSecure(nsIInterfaceRequestor *ctx, - PRBool* _result) -{ - nsAlertController* controller = nsCocoaBrowserService::GetAlertController(); - if (!controller) - return NS_ERROR_FAILURE; - - // HACK: there is no way to get which window this is for from the API. The - // security team in mozilla just cheats and assumes the frontmost window so - // that's what we'll do. Yes, it's wrong. Yes, it's skanky. Oh well. - *_result = (PRBool)[controller postToInsecureFromSecure:[(MainController*)[NSApp delegate] getFrontmostBrowserWindow]]; - - return NS_OK; -} - - -// Private helper functions -nsresult -SecurityDialogs::EnsureSecurityStringBundle() -{ - if (!mSecurityStringBundle) { - #define STRING_BUNDLE_URL "chrome://communicator/locale/security.properties" - nsCOMPtr service = do_GetService(NS_STRINGBUNDLE_CONTRACTID); - if ( service ) { - nsresult rv = service->CreateBundle(STRING_BUNDLE_URL, getter_AddRefs(mSecurityStringBundle)); - if (NS_FAILED(rv)) return rv; - } - } - return NS_OK; -} - - -nsresult -SecurityDialogs::AlertDialog(nsIInterfaceRequestor *ctx, const char *prefName, - const PRUnichar *dialogMessageName, - const PRUnichar *showAgainName) -{ - nsresult rv = NS_OK; - - // Get user's preference for this alert - nsCOMPtr pref; - PRBool prefValue = PR_TRUE; - if ( prefName ) { - pref = do_GetService("@mozilla.org/preferences-service;1"); - if ( pref ) - pref->GetBoolPref(prefName, &prefValue); - - // Stop if alert is not requested - if (!prefValue) return NS_OK; - } - - if ( NS_FAILED(rv = EnsureSecurityStringBundle()) ) - return rv; - - // Get Prompt to use - nsCOMPtr prompt = do_GetInterface(ctx); - if (!prompt) return NS_ERROR_FAILURE; - - // Get messages strings from localization file - nsXPIDLString windowTitle, message, dontShowAgain; - mSecurityStringBundle->GetStringFromName(NS_LITERAL_STRING("Title").get(), - getter_Copies(windowTitle)); - mSecurityStringBundle->GetStringFromName(dialogMessageName, - getter_Copies(message)); - if ( prefName ) - mSecurityStringBundle->GetStringFromName(showAgainName, - getter_Copies(dontShowAgain)); - if (!windowTitle.get() || !message.get()) return NS_ERROR_FAILURE; - - if ( prefName ) - rv = prompt->AlertCheck(windowTitle, message, dontShowAgain, &prefValue); - else - rv = prompt->AlertCheck(windowTitle, message, nil, nil); - if (NS_FAILED(rv)) return rv; - - if (prefName && !prefValue) - pref->SetBoolPref(prefName, PR_FALSE); - - return rv; -} diff --git a/mozilla/camino/SiteIconProvider.h b/mozilla/camino/SiteIconProvider.h deleted file mode 100644 index 9cb0209c455..00000000000 --- a/mozilla/camino/SiteIconProvider.h +++ /dev/null @@ -1,69 +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): - * Simon Fraser - * - * 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 - -#import "RemoteDataProvider.h" - -extern NSString* SiteIconLoadNotificationName; -extern NSString* SiteIconLoadImageKey; -extern NSString* SiteIconLoadURIKey; -extern NSString* SiteIconLoadUserDataKey; - -class NeckoCacheHelper; - -@interface SiteIconProvider : NSObject -{ - NeckoCacheHelper* mMissedIconsCacheHelper; -} - -+ (SiteIconProvider*)sharedFavoriteIconProvider; - -+ (NSString*)faviconLocationStringFromURI:(NSString*)inURI; - -// Start a favicon.ico load for the given URI, which can be any URI. -// The caller will get a 'SiteIconLoadNotificationName' notification -// when the load is done, with the image at the 'SiteIconLoadImageKey' key -// in the notifcation userInfo. The caller will have had to register with the -// NSNotifcationCenter in order to receive this notifcation. The notification -// is dispatched with 'sender' as the object. -// This method returns YES if the uri request was dispatched (i.e. if we know -// that we've looked for, and failed to find, this icon before). If it returns -// YES, then the 'SiteIconLoadNotificationName' notification will be sent out. -- (BOOL)loadFavoriteIcon:(id)sender forURI:(NSString *)inURI withUserData:(id)userData allowNetwork:(BOOL)inAllowNetwork; - -@end diff --git a/mozilla/camino/SiteIconProvider.mm b/mozilla/camino/SiteIconProvider.mm deleted file mode 100644 index b791935dcb8..00000000000 --- a/mozilla/camino/SiteIconProvider.mm +++ /dev/null @@ -1,340 +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): - * Simon Fraser - * - * 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 "NSString+Utils.h" - -#import "SiteIconProvider.h" - -#include "prtime.h" -#include "nsString.h" -#include "nsISupports.h" -#include "nsNetUtil.h" -#include "nsICacheSession.h" -#include "nsICacheService.h" -#include "nsICacheEntryDescriptor.h" - - -NSString* SiteIconLoadNotificationName = @"siteicon_load_notification"; -NSString* SiteIconLoadImageKey = @"siteicon_load_image"; -NSString* SiteIconLoadURIKey = @"siteicon_load_uri"; -NSString* SiteIconLoadUserDataKey = @"siteicon_load_user_data"; - - -static inline PRUint32 PRTimeToSeconds(PRTime t_usec) -{ - PRTime usec_per_sec; - PRUint32 t_sec; - LL_I2L(usec_per_sec, PR_USEC_PER_SEC); - LL_DIV(t_usec, t_usec, usec_per_sec); - LL_L2I(t_sec, t_usec); - return t_sec; -} - -class NeckoCacheHelper -{ -public: - - NeckoCacheHelper(const char* inMetaElement, const char* inMetaValue); - ~NeckoCacheHelper() {} - - nsresult Init(const char* inCacheSessionName); - nsresult ExistsInCache(const nsACString& inURI, PRBool* outExists); - nsresult PutInCache(const nsACString& inURI, PRUint32 inExpirationTimeSeconds); - - nsresult ClearCache(); - -protected: - - const char* mMetaElement; - const char* mMetaValue; - nsCOMPtr mCacheSession; - -}; - -static NS_DEFINE_CID(kCacheServiceCID, NS_CACHESERVICE_CID); - -NeckoCacheHelper::NeckoCacheHelper(const char* inMetaElement, const char* inMetaValue) -: mMetaElement(inMetaElement) -, mMetaValue(inMetaValue) -{ -} - -nsresult NeckoCacheHelper::Init(const char* inCacheSessionName) -{ - nsresult rv; - - nsCOMPtr cacheService = do_GetService(kCacheServiceCID, &rv); - if (NS_FAILED(rv)) - return rv; - - rv = cacheService->CreateSession(inCacheSessionName, - nsICache::STORE_ANYWHERE, nsICache::STREAM_BASED, - getter_AddRefs(mCacheSession)); - if (NS_FAILED(rv)) - return rv; - - return NS_OK; -} - - -nsresult NeckoCacheHelper::ExistsInCache(const nsACString& inURI, PRBool* outExists) -{ - NS_ASSERTION(mCacheSession, "No cache session"); - - nsCOMPtr entryDesc; - nsresult rv = mCacheSession->OpenCacheEntry(PromiseFlatCString(inURI).get(), nsICache::ACCESS_READ, nsICache::NON_BLOCKING, getter_AddRefs(entryDesc)); - - *outExists = NS_SUCCEEDED(rv) && (entryDesc != NULL); - return NS_OK; -} - -nsresult NeckoCacheHelper::PutInCache(const nsACString& inURI, PRUint32 inExpirationTimeSeconds) -{ - NS_ASSERTION(mCacheSession, "No cache session"); - - nsCOMPtr entryDesc; - nsresult rv = mCacheSession->OpenCacheEntry(PromiseFlatCString(inURI).get(), nsICache::ACCESS_WRITE, nsICache::NON_BLOCKING, getter_AddRefs(entryDesc)); - if (NS_FAILED(rv) || !entryDesc) return rv; - - nsCacheAccessMode accessMode; - rv = entryDesc->GetAccessGranted(&accessMode); - if (NS_FAILED(rv)) - return rv; - - if (accessMode != nsICache::ACCESS_WRITE) - return NS_ERROR_FAILURE; - - entryDesc->SetMetaDataElement(mMetaElement, mMetaValue); // just set a bit of meta data. - entryDesc->SetExpirationTime(PRTimeToSeconds(PR_Now()) + inExpirationTimeSeconds); - - entryDesc->MarkValid(); - entryDesc->Close(); - - return NS_OK; -} - -nsresult NeckoCacheHelper::ClearCache() -{ - NS_ASSERTION(mCacheSession, "No cache session"); - - return mCacheSession->EvictEntries(); -} - - -#pragma mark - - -static nsresult MakeFaviconURIFromURI(const nsAString& inURIString, nsAString& outFaviconURI) -{ - outFaviconURI.Truncate(0); - - nsCOMPtr uri; - nsresult rv = NS_NewURI(getter_AddRefs(uri), inURIString); - if (NS_FAILED(rv)) - return rv; - - // check for http/https - PRBool isHTTP = PR_FALSE, isHTTPS = PR_FALSE; - uri->SchemeIs("http", &isHTTP); - uri->SchemeIs("https", &isHTTPS); - if (!isHTTP && !isHTTPS) - return NS_OK; - - PRInt32 port; - uri->GetPort(&port); - - nsXPIDLCString scheme; - uri->GetScheme(scheme); - - nsXPIDLCString host; - uri->GetHost(host); - - nsCAutoString faviconURI = scheme; - faviconURI.Append("://"); - faviconURI.Append(host); - if (port != -1) { - faviconURI.Append(':'); - faviconURI.AppendInt(port); - } - faviconURI.Append("/favicon.ico"); - - outFaviconURI.Assign(NS_ConvertUTF8toUCS2(faviconURI)); - return NS_OK; -} - - -@interface SiteIconProvider(Private) - -- (void)addToMissedIconsCache:(const nsAString&)inURI withExpirationSeconds:(unsigned int)inExpSeconds; -- (BOOL)inMissedIconsCache:(const nsAString&)inURI; - -@end - - -@implementation SiteIconProvider - -- (id)init -{ - if ((self = [super init])) - { - mMissedIconsCacheHelper = new NeckoCacheHelper("Favicon", "Missed"); - nsresult rv = mMissedIconsCacheHelper->Init("MissedIconsCache"); - if (NS_FAILED(rv)) { - delete mMissedIconsCacheHelper; - mMissedIconsCacheHelper = NULL; - } - } - - return self; -} - -- (void)dealloc -{ - delete mMissedIconsCacheHelper; - [super dealloc]; -} - -- (void)addToMissedIconsCache:(const nsAString&)inURI withExpirationSeconds:(unsigned int)inExpSeconds -{ - if (mMissedIconsCacheHelper) - { - nsresult rv = mMissedIconsCacheHelper->PutInCache(NS_ConvertUCS2toUTF8(inURI), inExpSeconds); - //NSLog(@"Putting %@ in missed icon cache", [NSString stringWith_nsAString:inURI]); - } - -} - -- (BOOL)inMissedIconsCache:(const nsAString&)inURI -{ - PRBool inCache = PR_FALSE; - - if (mMissedIconsCacheHelper) - mMissedIconsCacheHelper->ExistsInCache(NS_ConvertUCS2toUTF8(inURI), &inCache); - - //NSLog(@"%@ in missed icon cache: %d", [NSString stringWith_nsAString:inURI], inCache); - return inCache; -} - - -- (BOOL)loadFavoriteIcon:(id)sender forURI:(NSString *)inURI withUserData:(id)userData allowNetwork:(BOOL)inAllowNetwork -{ - // look for a favicon - nsAutoString uriString; - [inURI assignTo_nsAString:uriString]; - - nsAutoString faviconURIString; - MakeFaviconURIFromURI(uriString, faviconURIString); - if (faviconURIString.Length() == 0) - return NO; - - NSString* faviconString = [NSString stringWith_nsAString:faviconURIString]; - - // is this uri already in the missing icons cache? - if ([self inMissedIconsCache:faviconURIString]) - return NO; - - RemoteDataProvider* dataProvider = [RemoteDataProvider sharedRemoteDataProvider]; - return [dataProvider loadURI:faviconString forTarget:sender withListener:self withUserData:userData allowNetworking:inAllowNetwork]; -} - -#define SITE_ICON_EXPIRATION_SECONDS (60 * 60 * 24 * 7) // 1 week - -// this is called on the main thread -- (void)doneRemoteLoad:(NSString*)inURI forTarget:(id)target withUserData:(id)userData data:(NSData*)data status:(nsresult)status -{ - nsAutoString uriString; - [inURI assignTo_nsAString:uriString]; - - BOOL loadOK = NS_SUCCEEDED(status) && (data != nil); - - // it's hard to tell if the favicon load succeeded or not. Even if the file - // does not exist, servers will send back a 404 page with a 0 status. - // So we just go ahead and try to make the image; it will return nil on - // failure. - NSImage* faviconImage = nil; - - NS_DURING - faviconImage = [[NSImage alloc] initWithData:data]; - NS_HANDLER - NSLog(@"Exception \"%@ making\" favicon image for %@", localException, inURI); - faviconImage = nil; - NS_ENDHANDLER - - BOOL gotImageData = loadOK && (faviconImage != nil); - if (!gotImageData) - [self addToMissedIconsCache:uriString withExpirationSeconds:SITE_ICON_EXPIRATION_SECONDS]; - - [faviconImage setDataRetained:YES]; - [faviconImage setScalesWhenResized:YES]; - [faviconImage setSize:NSMakeSize(16, 16)]; - - // we always send out the notification, so that clients know - // about failed requests - NSDictionary* notificationData = [NSDictionary dictionaryWithObjectsAndKeys: - inURI, SiteIconLoadURIKey, - faviconImage, SiteIconLoadImageKey, // may be nil - userData, SiteIconLoadUserDataKey, - nil]; - - [[NSNotificationCenter defaultCenter] postNotificationName: SiteIconLoadNotificationName - object:target userInfo:notificationData]; -} - -#pragma mark - - -+ (SiteIconProvider*)sharedFavoriteIconProvider -{ - static SiteIconProvider* sIconProvider = nil; - if (!sIconProvider) - { - sIconProvider = [[SiteIconProvider alloc] init]; - } - - return sIconProvider; -} - - -+ (NSString*)faviconLocationStringFromURI:(NSString*)inURI -{ - nsAutoString uriString; - [inURI assignTo_nsAString:uriString]; - - nsAutoString faviconURIString; - MakeFaviconURIFromURI(uriString, faviconURIString); - return [NSString stringWith_nsAString:faviconURIString]; -} - -@end diff --git a/mozilla/camino/ToolTip.h b/mozilla/camino/ToolTip.h deleted file mode 100644 index 8167dd2e3bb..00000000000 --- a/mozilla/camino/ToolTip.h +++ /dev/null @@ -1,52 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape 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/NPL/ - * - * 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 mozilla.org 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): Richard Schreyer - * - * 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 NPL, 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 NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#import - -@class ToolTipView; - -@interface ToolTip : NSObject -{ - NSPanel* mPanel; - NSTextField* mTextField; -} - -// it expects a point relative to the top left coordinate of the screen -- (void)showToolTipAtPoint:(NSPoint)point withString:(NSString*)string; -- (void)closeToolTip; - -@end diff --git a/mozilla/camino/ToolTip.mm b/mozilla/camino/ToolTip.mm deleted file mode 100644 index 7d46337df28..00000000000 --- a/mozilla/camino/ToolTip.mm +++ /dev/null @@ -1,150 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape 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/NPL/ - * - * 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 mozilla.org 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): Richard Schreyer - * - * 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 NPL, 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 NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#import "ToolTip.h" -#import "NSScreen+Utils.h" - -@interface ToolTip (ToolTipPrivateMethods) - -@end - -const float kBorderPadding = 2.0; - -@implementation ToolTip - -- (id)init -{ - - self = [super init]; - if (self) { - mPanel = [[NSPanel alloc] initWithContentRect: NSMakeRect(0.0, 0.0, 200.0, 200.0) styleMask: NSBorderlessWindowMask backing: NSBackingStoreBuffered defer: YES]; - - // Create a textfield as the content of our new window. Autorelease it because the window will - // hold a ref when we add it as a subview. Field occupies all but the top 2 and bottom - // 2 pixels of the panel (bug 149635) - mTextField = [[[NSTextField alloc] initWithFrame: NSMakeRect(0.0, kBorderPadding, 200.0, 200 - 2*kBorderPadding)] autorelease]; - - [[mPanel contentView] addSubview: mTextField]; - [mPanel setHasShadow: YES]; - [mPanel setBackgroundColor: [NSColor colorWithCalibratedRed: 1.0 green: 1.0 blue: .81 alpha: 1.0]]; - - [mTextField setAutoresizingMask: NSViewWidthSizable | NSViewHeightSizable]; - [mTextField setDrawsBackground: NO]; - [mTextField setEditable: NO]; - [mTextField setSelectable: NO]; - [mTextField setFont: [NSFont toolTipsFontOfSize: [NSFont smallSystemFontSize]]]; - [mTextField setBezeled: NO]; - [mTextField setBordered: NO]; - } - return self; -} - -- (void)dealloc -{ - [mPanel close]; - [mPanel release]; - [super dealloc]; -} - -- (void)showToolTipAtPoint:(NSPoint)point withString:(NSString*)string -{ - if ([string length] == 0) - return; - - NSScreen* screen = [NSScreen screenForPoint: point]; - if (!screen) - screen = [NSScreen mainScreen]; - - if (screen) { - NSRect screenFrame = [screen visibleFrame]; - NSSize screenSize = screenFrame.size; - NSTextView* textView = [[[NSTextView alloc] initWithFrame: screenFrame] autorelease]; - - // find out how large the tooltip needs to be - - [textView setString: string]; - [textView setMinSize: NSMakeSize(0.0, 0.0)]; - [textView setMaxSize: screenSize]; - [textView setVerticallyResizable: YES]; - [textView setHorizontallyResizable: YES]; - [textView setFont: [NSFont toolTipsFontOfSize: [NSFont smallSystemFontSize]]]; - [textView sizeToFit]; - NSSize textSize = NSMakeSize( ceil( NSWidth([textView frame]) ), ceil( NSHeight([textView frame]) ) ); - - // adjust the size of the tooltip by a constant amount, as illustrated in bug 149635 - // specifically, add padding above and below the text, and remove 6 from the right side - // (six!? we're still not sure why it's six pixels too big. ideas are welcome). - - textSize.width -= 6; - textSize.height += kBorderPadding + kBorderPadding; - - // set up the panel - - [mTextField setStringValue: string]; - [mPanel setContentSize: textSize]; - - // the given point is right where the mouse pointer is. We want the tooltip's - // top left corner somewhere below that, but not if that'll put it off the monitor. There - // is no way that we can go off the top of the monitor because cocoa won't let us position a window - // that way - const int kVOffset = 20; - if ( point.y - kVOffset - textSize.height > NSMinY(screenFrame) ) - point.y -= kVOffset; - else - point.y += kVOffset; - [mPanel setFrameTopLeftPoint: point]; - - // if it goes off the edge of the screen, shift around to put it all on the screen - - float amountOffScreenX = NSMaxX(screenFrame) - NSMaxX([mPanel frame]); - if (amountOffScreenX < 0) { - NSRect movedFrame = [mPanel frame]; - movedFrame.origin.x += amountOffScreenX; - [mPanel setFrame: movedFrame display: NO]; - } - - // show the panel - [mPanel orderFront: nil]; - } -} - -- (void)closeToolTip -{ - [mPanel close]; -} - -@end diff --git a/mozilla/camino/ToolbarDefaults.plist b/mozilla/camino/ToolbarDefaults.plist deleted file mode 100644 index 27dce200e4b..00000000000 --- a/mozilla/camino/ToolbarDefaults.plist +++ /dev/null @@ -1,8 +0,0 @@ -( - "Back Toolbar Item", - "Forward Toolbar Item", - "Reload Toolbar Item", - "Stop Toolbar Item", - "Location Toolbar Item", - "Sidebar Toolbar Item" -) diff --git a/mozilla/camino/WebsiteDefaults.strings b/mozilla/camino/WebsiteDefaults.strings deleted file mode 100644 index f80b5d6aae6..00000000000 --- a/mozilla/camino/WebsiteDefaults.strings +++ /dev/null @@ -1,6 +0,0 @@ -HomePageDefault = "http://www.mozilla.org"; -/* SearchPageDefault = "http://www.dmoz.org"; Leave commented out to get search engine from IC */ -StartPageDefault = "about:blank"; -ThrobberPageDefault = "http://www.mozilla.org"; -FeedbackPageDefault = "http://chimera.mozdev.org"; -InfoPageDefault = "http://chimera.mozdev.org/installation.html"; diff --git a/mozilla/camino/about.tif b/mozilla/camino/about.tif deleted file mode 100644 index ab58947d93a..00000000000 Binary files a/mozilla/camino/about.tif and /dev/null differ diff --git a/mozilla/camino/alert.nib/classes.nib b/mozilla/camino/alert.nib/classes.nib deleted file mode 100644 index 22720161509..00000000000 --- a/mozilla/camino/alert.nib/classes.nib +++ /dev/null @@ -1,49 +0,0 @@ -{ - IBClasses = ( - {CLASS = FirstResponder; LANGUAGE = ObjC; SUPERCLASS = NSObject; }, - {CLASS = java.lang.Object; LANGUAGE = Java; }, - { - ACTIONS = {hitButton1 = id; hitButton2 = id; hitButton3 = id; }; - CLASS = nsAlertController; - LANGUAGE = ObjC; - OUTLETS = { - alertCheckPanel = id; - alertCheckPanelCheck = id; - alertCheckPanelText = id; - alertPanel = id; - alertPanelText = id; - confirmCheckPanel = id; - confirmCheckPanelButton1 = id; - confirmCheckPanelButton2 = id; - confirmCheckPanelButton3 = id; - confirmCheckPanelCheck = id; - confirmCheckPanelText = id; - confirmPanel = id; - confirmPanelButton1 = id; - confirmPanelButton2 = id; - confirmPanelButton3 = id; - confirmPanelText = id; - expiredCertPanel = id; - owner = id; - passwordPanel = id; - passwordPanelCheck = id; - passwordPanelInput = id; - passwordPanelText = id; - postToInsecureFromSecurePanel = id; - promptPanel = id; - promptPanelCheck = id; - promptPanelInput = id; - promptPanelText = id; - securityMismatchPanel = id; - securityUnknownPanel = id; - usernamePanel = id; - usernamePanelCheck = id; - usernamePanelPassword = id; - usernamePanelText = id; - usernamePanelUserName = id; - }; - SUPERCLASS = NSObject; - } - ); - IBVersion = 1; -} \ No newline at end of file diff --git a/mozilla/camino/alert.nib/info.nib b/mozilla/camino/alert.nib/info.nib deleted file mode 100644 index d2e85852ba9..00000000000 --- a/mozilla/camino/alert.nib/info.nib +++ /dev/null @@ -1,12 +0,0 @@ - - - - - IBDocumentLocation - 285 97 356 301 0 0 1024 746 - IBFramework Version - 248.0 - IBSystem Version - 5S66 - - diff --git a/mozilla/camino/alert.nib/objects.nib b/mozilla/camino/alert.nib/objects.nib deleted file mode 100644 index 114a02c288c..00000000000 Binary files a/mozilla/camino/alert.nib/objects.nib and /dev/null differ diff --git a/mozilla/camino/appicon.icns b/mozilla/camino/appicon.icns deleted file mode 100644 index 0d686347a4b..00000000000 Binary files a/mozilla/camino/appicon.icns and /dev/null differ diff --git a/mozilla/camino/back.tif b/mozilla/camino/back.tif deleted file mode 100755 index a77d5a50897..00000000000 Binary files a/mozilla/camino/back.tif and /dev/null differ diff --git a/mozilla/camino/bookicon.tif b/mozilla/camino/bookicon.tif deleted file mode 100644 index 5797532ed90..00000000000 Binary files a/mozilla/camino/bookicon.tif and /dev/null differ diff --git a/mozilla/camino/bookmark_on.tif b/mozilla/camino/bookmark_on.tif deleted file mode 100644 index 258b336f5a5..00000000000 Binary files a/mozilla/camino/bookmark_on.tif and /dev/null differ diff --git a/mozilla/camino/bookmarks.xml b/mozilla/camino/bookmarks.xml deleted file mode 100644 index 2c726f11944..00000000000 --- a/mozilla/camino/bookmarks.xml +++ /dev/null @@ -1,23 +0,0 @@ - - - - - - - - - - - - - - - - - - - - diff --git a/mozilla/camino/broken-image.gif b/mozilla/camino/broken-image.gif deleted file mode 100644 index 03f4d14ff64..00000000000 Binary files a/mozilla/camino/broken-image.gif and /dev/null differ diff --git a/mozilla/camino/chimera.js b/mozilla/camino/chimera.js deleted file mode 100644 index eb764501e24..00000000000 --- a/mozilla/camino/chimera.js +++ /dev/null @@ -1,57 +0,0 @@ -/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** 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. - * - * 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): - * Brian Ryner - * - * 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 ***** */ - -// This file contains Chimera-specific default preferences. - -// What to load in a new tab: 0 = blank, 1 = homepage, 2 = last page -pref("browser.tabs.startPage", 0); - -// Disable the print progress dialog -pref("print.show_print_progress", false); - -// Pick some reasonable OS X default fonts -pref("font.name.serif.x-western", "Lucida Grande"); -pref("font.name.sans-serif.x-western", "Lucida Grande"); -pref("font.size.variable.x-western", 15); -pref("font.size.fixed.x-western", 12); -pref("font.size.minimum-size.x-western", 10); - -// Unsuppress painting sooner (XXXbryner, why is this here?) -pref("nglayout.initialpaint.delay", 250); - - diff --git a/mozilla/camino/delete_on.tif b/mozilla/camino/delete_on.tif deleted file mode 100644 index 6672bcd44d1..00000000000 Binary files a/mozilla/camino/delete_on.tif and /dev/null differ diff --git a/mozilla/camino/edit_on.tif b/mozilla/camino/edit_on.tif deleted file mode 100644 index 5c98acf3b93..00000000000 Binary files a/mozilla/camino/edit_on.tif and /dev/null differ diff --git a/mozilla/camino/fileBookmark.icns b/mozilla/camino/fileBookmark.icns deleted file mode 100644 index b89e6e61c98..00000000000 Binary files a/mozilla/camino/fileBookmark.icns and /dev/null differ diff --git a/mozilla/camino/fileHtml.icns b/mozilla/camino/fileHtml.icns deleted file mode 100644 index 3f54c6964d9..00000000000 Binary files a/mozilla/camino/fileHtml.icns and /dev/null differ diff --git a/mozilla/camino/filePreferences.icns b/mozilla/camino/filePreferences.icns deleted file mode 100644 index 724eddf1530..00000000000 Binary files a/mozilla/camino/filePreferences.icns and /dev/null differ diff --git a/mozilla/camino/folder.tiff b/mozilla/camino/folder.tiff deleted file mode 100644 index f5ad95a4f84..00000000000 Binary files a/mozilla/camino/folder.tiff and /dev/null differ diff --git a/mozilla/camino/folder_on.tif b/mozilla/camino/folder_on.tif deleted file mode 100644 index d35e6334c93..00000000000 Binary files a/mozilla/camino/folder_on.tif and /dev/null differ diff --git a/mozilla/camino/forward.tif b/mozilla/camino/forward.tif deleted file mode 100755 index e856613af96..00000000000 Binary files a/mozilla/camino/forward.tif and /dev/null differ diff --git a/mozilla/camino/globe_ico.tif b/mozilla/camino/globe_ico.tif deleted file mode 100644 index c8bb6b6f90e..00000000000 Binary files a/mozilla/camino/globe_ico.tif and /dev/null differ diff --git a/mozilla/camino/groupbookmark.tif b/mozilla/camino/groupbookmark.tif deleted file mode 100644 index 5832357b01e..00000000000 Binary files a/mozilla/camino/groupbookmark.tif and /dev/null differ diff --git a/mozilla/camino/historyicon.tif b/mozilla/camino/historyicon.tif deleted file mode 100644 index ca41c6f85a3..00000000000 Binary files a/mozilla/camino/historyicon.tif and /dev/null differ diff --git a/mozilla/camino/home.tif b/mozilla/camino/home.tif deleted file mode 100755 index d3dd1ee8b0a..00000000000 Binary files a/mozilla/camino/home.tif and /dev/null differ diff --git a/mozilla/camino/loading-image.gif b/mozilla/camino/loading-image.gif deleted file mode 100644 index ba240918423..00000000000 Binary files a/mozilla/camino/loading-image.gif and /dev/null differ diff --git a/mozilla/camino/main.m b/mozilla/camino/main.m deleted file mode 100644 index 7afdacbcaaf..00000000000 --- a/mozilla/camino/main.m +++ /dev/null @@ -1,17 +0,0 @@ -#import - -static void SetupRuntimeOptions(int argc, const char *argv[]) -{ - if (getenv("MOZ_UNBUFFERED_STDIO")) { - printf("stdout and stderr unbuffered\n"); - setbuf(stdout, 0); - setbuf(stderr, 0); - } -} - -int main(int argc, const char *argv[]) -{ - SetupRuntimeOptions(argc, argv); - - return NSApplicationMain(argc, argv); -} diff --git a/mozilla/camino/nsAlertController.h b/mozilla/camino/nsAlertController.h deleted file mode 100644 index 3fbd539d51d..00000000000 --- a/mozilla/camino/nsAlertController.h +++ /dev/null @@ -1,104 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape 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/NPL/ - * - * 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 mozilla.org 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 NPL, 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 NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#import - -@interface nsAlertController : NSObject -{ - IBOutlet id alertCheckPanel; - IBOutlet id alertCheckPanelCheck; - IBOutlet id alertCheckPanelText; - IBOutlet id alertPanel; - IBOutlet id alertPanelText; - IBOutlet id confirmCheckPanel; - IBOutlet id confirmCheckPanelCheck; - IBOutlet id confirmCheckPanelText; - IBOutlet id confirmCheckPanelButton1; - IBOutlet id confirmCheckPanelButton2; - IBOutlet id confirmCheckPanelButton3; - IBOutlet id confirmPanel; - IBOutlet id confirmPanelText; - IBOutlet id confirmPanelButton1; - IBOutlet id confirmPanelButton2; - IBOutlet id confirmPanelButton3; - IBOutlet id promptPanel; - IBOutlet id promptPanelCheck; - IBOutlet id promptPanelText; - IBOutlet id promptPanelInput; - IBOutlet id passwordPanel; - IBOutlet id passwordPanelCheck; - IBOutlet id passwordPanelText; - IBOutlet id passwordPanelInput; - IBOutlet id postToInsecureFromSecurePanel; - IBOutlet id securityMismatchPanel; - IBOutlet id expiredCertPanel; - IBOutlet id securityUnknownPanel; - IBOutlet id usernamePanel; - IBOutlet id usernamePanelCheck; - IBOutlet id usernamePanelText; - IBOutlet id usernamePanelPassword; - IBOutlet id usernamePanelUserName; - IBOutlet id owner; -} -- (IBAction)hitButton1:(id)sender; -- (IBAction)hitButton2:(id)sender; -- (IBAction)hitButton3:(id)sender; - -- (void)awakeFromNib; -- (void)alert:(NSWindow*)parent title:(NSString*)title text:(NSString*)text; -- (void)alertCheck:(NSWindow*)parent title:(NSString*)title text:(NSString*)text checkMsg:(NSString*)checkMsg checkValue:(BOOL*)checkValue; - -- (BOOL)confirm:(NSWindow*)parent title:(NSString*)title text:(NSString*)text; -- (BOOL)confirmCheck:(NSWindow*)parent title:(NSString*)title text:(NSString*)text checkMsg:(NSString*)checkMsg checkValue:(BOOL*)checkValue; - -- (int)confirmEx:(NSWindow*)parent title:(NSString*)title text:(NSString*)text - button1:(NSString*)btn1 button2:(NSString*)btn2 button3:(NSString*)btn3; -- (int)confirmCheckEx:(NSWindow*)parent title:(NSString*)title text:(NSString*)text - button1:(NSString*)btn1 button2:(NSString*)btn2 button3:(NSString*)btn3 - checkMsg:(NSString*)checkMsg checkValue:(BOOL*)checkValue; - -- (BOOL)prompt:(NSWindow*)parent title:(NSString*)title text:(NSString*)text promptText:(NSMutableString*)promptText checkMsg:(NSString*)checkMsg checkValue:(BOOL*)checkValue doCheck:(BOOL)doCheck; -- (BOOL)promptUserNameAndPassword:(NSWindow*)parent title:(NSString*)title text:(NSString*)text userNameText:(NSMutableString*)userNameText passwordText:(NSMutableString*)passwordText checkMsg:(NSString*)checkMsg checkValue:(BOOL*)checkValue doCheck:(BOOL)doCheck; -- (BOOL)promptPassword:(NSWindow*)parent title:(NSString*)title text:(NSString*)text passwordText:(NSMutableString*)passwordText checkMsg:(NSString*)checkMsg checkValue:(BOOL*)checkValue doCheck:(BOOL)doCheck; - -- (BOOL)postToInsecureFromSecure:(NSWindow*)parent; - -- (BOOL)badCert:(NSWindow*)parent; -- (BOOL)expiredCert:(NSWindow*)parent; -- (int)unknownCert:(NSWindow*)parent; - -@end diff --git a/mozilla/camino/nsAlertController.mm b/mozilla/camino/nsAlertController.mm deleted file mode 100644 index 27225a524fc..00000000000 --- a/mozilla/camino/nsAlertController.mm +++ /dev/null @@ -1,309 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape 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/NPL/ - * - * 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 mozilla.org 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 NPL, 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 NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#import "nsAlertController.h" -#import "nsCocoaBrowserService.h" - -#include "nsIBadCertListener.h" - -enum { kOKButton = 0, kCancelButton = 1, kOtherButton = 2 }; - -@implementation nsAlertController - -- (IBAction)hitButton1:(id)sender -{ - [NSApp stopModalWithCode:kOKButton]; -} - -- (IBAction)hitButton2:(id)sender -{ - [NSApp stopModalWithCode:kCancelButton]; -} - -- (IBAction)hitButton3:(id)sender -{ - [NSApp stopModalWithCode:kOtherButton]; -} - - -- (void)awakeFromNib -{ - nsCocoaBrowserService::SetAlertController(self); -} - -- (void)alert:(NSWindow*)parent title:(NSString*)title text:(NSString*)text -{ - [alertPanelText setStringValue:text]; - [alertPanel setTitle:title]; - - [NSApp runModalForWindow:alertPanel relativeToWindow:parent]; - - [alertPanel close]; -} - -- (void)alertCheck:(NSWindow*)parent title:(NSString*)title text:(NSString*)text checkMsg:(NSString*)checkMsg checkValue:(BOOL*)checkValue -{ - [alertCheckPanelText setStringValue:text]; - [alertCheckPanel setTitle:title]; - int state = (*checkValue ? NSOnState : NSOffState); - [alertCheckPanelCheck setState:state]; - [alertCheckPanelCheck setTitle:checkMsg]; - - [NSApp runModalForWindow:alertCheckPanel relativeToWindow:parent]; - - *checkValue = ([alertCheckPanelCheck state] == NSOnState); - [alertCheckPanel close]; -} - -- (BOOL)confirm:(NSWindow*)parent title:(NSString*)title text:(NSString*)text -{ - [confirmPanelText setStringValue:text]; - [confirmPanel setTitle:title]; - - int result = [NSApp runModalForWindow:confirmPanel relativeToWindow:parent]; - - [confirmPanel close]; - - return (result == kOKButton); -} - -- (BOOL)confirmCheck:(NSWindow*)parent title:(NSString*)title text:(NSString*)text checkMsg:(NSString*)checkMsg checkValue:(BOOL*)checkValue -{ - [confirmCheckPanelText setStringValue:text]; - [confirmCheckPanel setTitle:title]; - int state = (*checkValue ? NSOnState : NSOffState); - [confirmCheckPanelCheck setState:state]; - [confirmCheckPanelCheck setTitle:checkMsg]; - - int result = [NSApp runModalForWindow:confirmCheckPanel relativeToWindow:parent]; - - *checkValue = ([confirmCheckPanelCheck state] == NSOnState); - [confirmCheckPanel close]; - - return (result == kOKButton); -} - -- (int)confirmEx:(NSWindow*)parent title:(NSString*)title text:(NSString*)text - button1:(NSString*)btn1 button2:(NSString*)btn2 button3:(NSString*)btn3 -{ - [confirmPanelText setStringValue:text]; - [confirmPanel setTitle:title]; - - [confirmPanelButton1 setTitle:btn1]; - [confirmPanelButton2 setTitle:btn2]; - [confirmPanelButton3 setTitle:btn3]; - - int result = [NSApp runModalForWindow:confirmPanel relativeToWindow:parent]; - - [confirmPanel close]; - - return result; -} - -- (int)confirmCheckEx:(NSWindow*)parent title:(NSString*)title text:(NSString*)text - button1:(NSString*)btn1 button2:(NSString*)btn2 button3:(NSString*)btn3 - checkMsg:(NSString*)checkMsg checkValue:(BOOL*)checkValue -{ - [confirmCheckPanelText setStringValue:text]; - [confirmCheckPanel setTitle:title]; - int state = (*checkValue ? NSOnState : NSOffState); - [confirmCheckPanelCheck setState:state]; - [confirmCheckPanelCheck setTitle:checkMsg]; - - [confirmCheckPanelButton1 setTitle:btn1]; - [confirmCheckPanelButton2 setTitle:btn2]; - [confirmCheckPanelButton3 setTitle:btn3]; - - int result = [NSApp runModalForWindow:confirmCheckPanel relativeToWindow:parent]; - - *checkValue = ([confirmCheckPanelCheck state] == NSOnState); - [confirmCheckPanel close]; - - return result; -} - -- (BOOL)prompt:(NSWindow*)parent title:(NSString*)title text:(NSString*)text promptText:(NSMutableString*)promptText checkMsg:(NSString*)checkMsg checkValue:(BOOL*)checkValue doCheck:(BOOL)doCheck -{ - [promptPanelText setStringValue:text]; - [promptPanel setTitle:title]; - if (doCheck) { - int state = (*checkValue ? NSOnState : NSOffState); - [promptPanelCheck setState:state]; - [promptPanelCheck setTransparent:NO]; - } - else { - [promptPanelCheck setTransparent:YES]; - } - [promptPanelCheck setTitle:checkMsg]; - [promptPanelInput setStringValue:promptText]; - - int result = [NSApp runModalForWindow:promptPanel relativeToWindow:parent]; - - *checkValue = ([promptPanelCheck state] == NSOnState); - - NSString* value = [promptPanelInput stringValue]; - PRUint32 length = [promptText length]; - if (length) { - NSRange all; - all.location = 0; - all.length = [promptText length]; - [promptText deleteCharactersInRange:all]; - } - [promptText appendString:value]; - - [promptPanel close]; - - return (result == kOKButton); -} - -- (BOOL)promptUserNameAndPassword:(NSWindow*)parent title:(NSString*)title text:(NSString*)text userNameText:(NSMutableString*)userNameText passwordText:(NSMutableString*)passwordText checkMsg:(NSString*)checkMsg checkValue:(BOOL*)checkValue doCheck:(BOOL)doCheck -{ - [usernamePanelText setStringValue:text]; - [usernamePanel setTitle:title]; - if (doCheck) { - int state = (*checkValue ? NSOnState : NSOffState); - [usernamePanelCheck setState:state]; - [usernamePanelCheck setTransparent:NO]; - } - else { - [usernamePanelCheck setTransparent:YES]; - } - [usernamePanelCheck setTitle:checkMsg]; - [usernamePanelPassword setStringValue:passwordText]; - [usernamePanelUserName setStringValue:userNameText]; - - int result = [NSApp runModalForWindow:usernamePanel relativeToWindow:parent]; - - *checkValue = ([usernamePanelCheck state] == NSOnState); - - NSString* value = [usernamePanelUserName stringValue]; - PRUint32 length = [userNameText length]; - if (length) { - NSRange all; - all.location = 0; - all.length = [userNameText length]; - [userNameText deleteCharactersInRange:all]; - } - [userNameText appendString:value]; - - value = [usernamePanelPassword stringValue]; - length = [passwordText length]; - if (length) { - NSRange all; - all.location = 0; - all.length = [passwordText length]; - [passwordText deleteCharactersInRange:all]; - } - [passwordText appendString:value]; - - [usernamePanel close]; - - return (result == kOKButton); -} - -- (BOOL)promptPassword:(NSWindow*)parent title:(NSString*)title text:(NSString*)text passwordText:(NSMutableString*)passwordText checkMsg:(NSString*)checkMsg checkValue:(BOOL*)checkValue doCheck:(BOOL)doCheck -{ - [passwordPanelText setStringValue:text]; - [passwordPanel setTitle:title]; - if (doCheck) { - int state = (*checkValue ? NSOnState : NSOffState); - [passwordPanelCheck setState:state]; - [passwordPanelCheck setTransparent:NO]; - } - else { - [passwordPanelCheck setTransparent:YES]; - } - [passwordPanelCheck setTitle:checkMsg]; - [passwordPanelInput setStringValue:passwordText]; - - int result = [NSApp runModalForWindow:passwordPanel relativeToWindow:parent]; - - *checkValue = ([passwordPanelCheck state] == NSOnState); - - NSString* value = [passwordPanelInput stringValue]; - PRUint32 length = [passwordText length]; - if (length) { - NSRange all; - all.location = 0; - all.length = [passwordText length]; - [passwordText deleteCharactersInRange:all]; - } - [passwordText appendString:value]; - - [passwordPanel close]; - - return (result == kOKButton); -} - - -- (BOOL)postToInsecureFromSecure:(NSWindow*)parent -{ - int result = [NSApp runModalForWindow:postToInsecureFromSecurePanel relativeToWindow:parent]; - [postToInsecureFromSecurePanel close]; - - return (result == kOKButton); -} - - -- (BOOL)badCert:(NSWindow*)parent -{ - int result = [NSApp runModalForWindow:securityMismatchPanel relativeToWindow:parent]; - [securityMismatchPanel close]; - - return (result == kOKButton); -} - -- (BOOL)expiredCert:(NSWindow*)parent -{ - int result = [NSApp runModalForWindow:expiredCertPanel relativeToWindow:parent]; - [expiredCertPanel close]; - - return (result == kOKButton); -} - - -- (int)unknownCert:(NSWindow*)parent -{ - // this dialog is a little backward, with "Stop" returning 0, and the default returning - // 1. That's just how nsIBadCertListener defines its constants. *shrug* - int result = [NSApp runModalForWindow:securityUnknownPanel relativeToWindow:parent]; - [securityUnknownPanel close]; - - return result; -} - -@end diff --git a/mozilla/camino/nsCocoaBrowserListener.h b/mozilla/camino/nsCocoaBrowserListener.h deleted file mode 100644 index 0f4880be093..00000000000 --- a/mozilla/camino/nsCocoaBrowserListener.h +++ /dev/null @@ -1,62 +0,0 @@ -// -// nsCocoaBrowserListener.h -// Chimera -// -// Created by Simon Fraser on Sat Aug 17 2002. -// Copyright (c) 2001 __MyCompanyName__. All rights reserved. -// - - -#ifndef __nsCocoaBrowserListener_h__ -#define __nsCocoaBrowserListener_h__ - -#include "nsWeakReference.h" -#include "nsIInterfaceRequestor.h" -#include "nsIWebBrowser.h" -#include "nsIWebBrowserChrome.h" -#include "nsIWebProgressListener.h" -#include "nsIEmbeddingSiteWindow2.h" -#include "nsIWindowCreator.h" - -#include "nsIContextMenuListener.h" -#include "nsITooltipListener.h" - -@class CHBrowserView; - -class nsCocoaBrowserListener : public nsSupportsWeakReference, - public nsIInterfaceRequestor, - public nsIWebBrowserChrome, - public nsIWindowCreator, - public nsIEmbeddingSiteWindow2, - public nsIWebProgressListener, - public nsIContextMenuListener, - public nsITooltipListener -{ -public: - nsCocoaBrowserListener(CHBrowserView* aView); - virtual ~nsCocoaBrowserListener(); - - NS_DECL_ISUPPORTS - NS_DECL_NSIINTERFACEREQUESTOR - NS_DECL_NSIWEBBROWSERCHROME - NS_DECL_NSIWINDOWCREATOR - NS_DECL_NSIEMBEDDINGSITEWINDOW - NS_DECL_NSIEMBEDDINGSITEWINDOW2 - NS_DECL_NSIWEBPROGRESSLISTENER - NS_DECL_NSICONTEXTMENULISTENER - NS_DECL_NSITOOLTIPLISTENER - - void AddListener(id aListener); - void RemoveListener(id aListener); - void SetContainer(id aContainer); - -private: - CHBrowserView* mView; // WEAK - it owns us - NSMutableArray* mListeners; - id mContainer; - PRBool mIsModal; - PRUint32 mChromeFlags; -}; - - -#endif // __nsCocoaBrowserListener_h__ diff --git a/mozilla/camino/nsCocoaBrowserListener.mm b/mozilla/camino/nsCocoaBrowserListener.mm deleted file mode 100644 index d9406ce59ea..00000000000 --- a/mozilla/camino/nsCocoaBrowserListener.mm +++ /dev/null @@ -1,609 +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): - * Simon Fraser - * - * 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 - -#import "NSString+Utils.h" - -// Embedding includes -#include "nsIWebBrowser.h" -#include "nsIWebNavigation.h" -#include "nsIURI.h" -#include "nsIDOMWindow.h" -//#include "nsIWidget.h" - -// XPCOM and String includes -#include "nsCRT.h" -#include "nsString.h" -#include "nsCOMPtr.h" - -#import "CHBrowserView.h" - -#include "nsCocoaBrowserListener.h" - - -nsCocoaBrowserListener::nsCocoaBrowserListener(CHBrowserView* aView) - : mView(aView), mContainer(nsnull), mIsModal(PR_FALSE), mChromeFlags(0) -{ - NS_INIT_ISUPPORTS(); - mListeners = [[NSMutableArray alloc] init]; -} - -nsCocoaBrowserListener::~nsCocoaBrowserListener() -{ - [mListeners release]; - mView = nsnull; - if (mContainer) { - [mContainer release]; - } -} - -NS_IMPL_ISUPPORTS9(nsCocoaBrowserListener, - nsIInterfaceRequestor, - nsIWebBrowserChrome, - nsIWindowCreator, - nsIEmbeddingSiteWindow, - nsIEmbeddingSiteWindow2, - nsIWebProgressListener, - nsISupportsWeakReference, - nsIContextMenuListener, - nsITooltipListener) - -// Implementation of nsIInterfaceRequestor -NS_IMETHODIMP -nsCocoaBrowserListener::GetInterface(const nsIID &aIID, void** aInstancePtr) -{ - if (aIID.Equals(NS_GET_IID(nsIDOMWindow))) { - nsCOMPtr browser = dont_AddRef([mView getWebBrowser]); - if (browser) - return browser->GetContentDOMWindow((nsIDOMWindow **) aInstancePtr); - } - - return QueryInterface(aIID, aInstancePtr); -} - -// Implementation of nsIWindowCreator. The CocoaBrowserService forwards requests -// for a new window that have a parent to us, and we take over from there. -/* nsIWebBrowserChrome createChromeWindow (in nsIWebBrowserChrome parent, in PRUint32 chromeFlags); */ -NS_IMETHODIMP -nsCocoaBrowserListener::CreateChromeWindow(nsIWebBrowserChrome *parent, - PRUint32 chromeFlags, - nsIWebBrowserChrome **_retval) -{ - if (parent != this) { -#if DEBUG - NSLog(@"Mismatch in nsCocoaBrowserListener::CreateChromeWindow. We should be the owning parent."); -#endif - return NS_ERROR_FAILURE; - } - - CHBrowserView* childView = [mContainer createBrowserWindow: chromeFlags]; - if (!childView) { -#if DEBUG - NSLog(@"No CHBrowserView hooked up for a newly created window yet."); -#endif - return NS_ERROR_FAILURE; - } - - nsCocoaBrowserListener* listener = [childView getCocoaBrowserListener]; - if (!listener) { -#if DEBUG - NSLog(@"Uh-oh! No listener yet for a newly created window (nsCocoaBrowserlistener)"); - return NS_ERROR_FAILURE; -#endif - } - -#if DEBUG - NSLog(@"Made a chrome window."); -#endif - - *_retval = listener; - NS_IF_ADDREF(*_retval); - return NS_OK; -} - -// Implementation of nsIContextMenuListener -NS_IMETHODIMP -nsCocoaBrowserListener::OnShowContextMenu(PRUint32 aContextFlags, nsIDOMEvent* aEvent, nsIDOMNode* aNode) -{ - [mContainer onShowContextMenu: aContextFlags domEvent: aEvent domNode: aNode]; - return NS_OK; -} - -// Implementation of nsITooltipListener -NS_IMETHODIMP -nsCocoaBrowserListener::OnShowTooltip(PRInt32 aXCoords, PRInt32 aYCoords, const PRUnichar *aTipText) -{ - NSPoint where; - where.x = aXCoords; where.y = aYCoords; - [mContainer onShowTooltip:where withText:[NSString stringWithPRUnichars:aTipText]]; - return NS_OK; -} - -NS_IMETHODIMP -nsCocoaBrowserListener::OnHideTooltip() -{ - [mContainer onHideTooltip]; - return NS_OK; -} - -// Implementation of nsIWebBrowserChrome -/* void setStatus (in unsigned long statusType, in wstring status); */ -NS_IMETHODIMP -nsCocoaBrowserListener::SetStatus(PRUint32 statusType, const PRUnichar *status) -{ - if (!mContainer) { - return NS_ERROR_FAILURE; - } - - NSString* str = nsnull; - if (status && (*status != PRUnichar(0))) { - str = [NSString stringWithPRUnichars:status]; - } - - [mContainer setStatus:str ofType:(NSStatusType)statusType]; - - return NS_OK; -} - -/* attribute nsIWebBrowser webBrowser; */ -NS_IMETHODIMP -nsCocoaBrowserListener::GetWebBrowser(nsIWebBrowser * *aWebBrowser) -{ - NS_ENSURE_ARG_POINTER(aWebBrowser); - if (!mView) { - return NS_ERROR_FAILURE; - } - *aWebBrowser = [mView getWebBrowser]; - - return NS_OK; -} -NS_IMETHODIMP -nsCocoaBrowserListener::SetWebBrowser(nsIWebBrowser * aWebBrowser) -{ - if (!mView) { - return NS_ERROR_FAILURE; - } - - [mView setWebBrowser:aWebBrowser]; - - return NS_OK; -} - -/* attribute unsigned long chromeFlags; */ -NS_IMETHODIMP -nsCocoaBrowserListener::GetChromeFlags(PRUint32 *aChromeFlags) -{ - NS_ENSURE_ARG_POINTER(aChromeFlags); - *aChromeFlags = mChromeFlags; - return NS_OK; -} -NS_IMETHODIMP -nsCocoaBrowserListener::SetChromeFlags(PRUint32 aChromeFlags) -{ - // XXX Do nothing with them for now - mChromeFlags = aChromeFlags; - return NS_OK; -} - -/* void destroyBrowserWindow (); */ -NS_IMETHODIMP -nsCocoaBrowserListener::DestroyBrowserWindow() -{ - // XXX Could send this up to the container, but for now, - // we just destroy the enclosing window. - NSWindow* window = [mView window]; - - if (window) { - [window close]; - } - - return NS_OK; -} - -/* void sizeBrowserTo (in long aCX, in long aCY); */ -NS_IMETHODIMP -nsCocoaBrowserListener::SizeBrowserTo(PRInt32 aCX, PRInt32 aCY) -{ - if (mContainer) { - NSSize size; - - size.width = (float)aCX; - size.height = (float)aCY; - - [mContainer sizeBrowserTo:size]; - } - - return NS_OK; -} - -/* void showAsModal (); */ -NS_IMETHODIMP -nsCocoaBrowserListener::ShowAsModal() -{ - if (!mView) { - return NS_ERROR_FAILURE; - } - - NSWindow* window = [mView window]; - - if (!window) { - return NS_ERROR_FAILURE; - } - - mIsModal = PR_TRUE; - //int result = [NSApp runModalForWindow:window]; - mIsModal = PR_FALSE; - - return NS_OK; -} - -/* boolean isWindowModal (); */ -NS_IMETHODIMP -nsCocoaBrowserListener::IsWindowModal(PRBool *_retval) -{ - NS_ENSURE_ARG_POINTER(_retval); - - *_retval = mIsModal; - - return NS_OK; -} - -/* void exitModalEventLoop (in nsresult aStatus); */ -NS_IMETHODIMP -nsCocoaBrowserListener::ExitModalEventLoop(nsresult aStatus) -{ -// [NSApp stopModalWithCode:(int)aStatus]; - - return NS_OK; -} - -// Implementation of nsIEmbeddingSiteWindow2 -NS_IMETHODIMP -nsCocoaBrowserListener::Blur() -{ - return NS_OK; -} - -// Implementation of nsIEmbeddingSiteWindow -/* void setDimensions (in unsigned long flags, in long x, in long y, in long cx, in long cy); */ -NS_IMETHODIMP -nsCocoaBrowserListener::SetDimensions(PRUint32 flags, PRInt32 x, PRInt32 y, PRInt32 cx, PRInt32 cy) -{ - if (!mView) - return NS_ERROR_FAILURE; - - NSWindow* window = [mView window]; - if (!window) - return NS_ERROR_FAILURE; - - if (flags & nsIEmbeddingSiteWindow::DIM_FLAGS_POSITION) { - NSPoint origin; - origin.x = (float)x; - origin.y = (float)y; - - // websites assume the origin is the topleft of the window and that the screen origin - // is "topleft" (quickdraw coordinates). As a result, we have to convert it. - GDHandle screenDevice = ::GetMainDevice(); - Rect screenRect = (**screenDevice).gdRect; - short screenHeight = screenRect.bottom - screenRect.top; - origin.y = screenHeight - origin.y; - - [window setFrameTopLeftPoint:origin]; - } - - if (flags & nsIEmbeddingSiteWindow::DIM_FLAGS_SIZE_OUTER) { - NSRect frame = [window frame]; - frame.size.width = (float)cx; - frame.size.height = (float)cy; - [window setFrame:frame display:YES]; - } - else if (flags & nsIEmbeddingSiteWindow::DIM_FLAGS_SIZE_INNER) { - NSSize size; - size.width = (float)cx; - size.height = (float)cy; - [window setContentSize:size]; - } - - return NS_OK; -} - -/* void getDimensions (in unsigned long flags, out long x, out long y, out long cx, out long cy); */ -NS_IMETHODIMP -nsCocoaBrowserListener::GetDimensions(PRUint32 flags, PRInt32 *x, PRInt32 *y, PRInt32 *cx, PRInt32 *cy) -{ - if (!mView) - return NS_ERROR_FAILURE; - - NSWindow* window = [mView window]; - if (!window) - return NS_ERROR_FAILURE; - - NSRect frame = [window frame]; - if (flags & nsIEmbeddingSiteWindow::DIM_FLAGS_POSITION) { - if ( x ) - *x = (PRInt32)frame.origin.x; - if ( y ) - *y = (PRInt32)frame.origin.y; - } - if (flags & nsIEmbeddingSiteWindow::DIM_FLAGS_SIZE_OUTER) { - if ( cx ) - *cx = (PRInt32)frame.size.width; - if ( cy ) - *cy = (PRInt32)frame.size.height; - } - else if (flags & nsIEmbeddingSiteWindow::DIM_FLAGS_SIZE_INNER) { - NSView* contentView = [window contentView]; - NSRect contentFrame = [contentView frame]; - if ( cx ) - *cx = (PRInt32)contentFrame.size.width; - if ( cy ) - *cy = (PRInt32)contentFrame.size.height; - } - - return NS_OK; -} - -/* void setFocus (); */ -NS_IMETHODIMP -nsCocoaBrowserListener::SetFocus() -{ - if (!mView) { - return NS_ERROR_FAILURE; - } - - NSWindow* window = [mView window]; - if (!window) { - return NS_ERROR_FAILURE; - } - - [window makeKeyAndOrderFront:window]; - - return NS_OK; -} - -/* attribute boolean visibility; */ -NS_IMETHODIMP -nsCocoaBrowserListener::GetVisibility(PRBool *aVisibility) -{ - NS_ENSURE_ARG_POINTER(aVisibility); - - if (!mView) { - return NS_ERROR_FAILURE; - } - - NSWindow* window = [mView window]; - if (!window) { - return NS_ERROR_FAILURE; - } - - *aVisibility = [window isMiniaturized]; - - return NS_OK; -} -NS_IMETHODIMP -nsCocoaBrowserListener::SetVisibility(PRBool aVisibility) -{ - if (!mView) { - return NS_ERROR_FAILURE; - } - - NSWindow* window = [mView window]; - if (!window) { - return NS_ERROR_FAILURE; - } - - if (aVisibility) { - [window deminiaturize:window]; - } - else { - [window miniaturize:window]; - } - - return NS_OK; -} - -/* attribute wstring title; */ -NS_IMETHODIMP -nsCocoaBrowserListener::GetTitle(PRUnichar * *aTitle) -{ - NS_ENSURE_ARG_POINTER(aTitle); - - if (!mContainer) { - return NS_ERROR_FAILURE; - } - - NSString* title = [mContainer title]; - unsigned int length = [title length]; - if (length) { - *aTitle = (PRUnichar*)nsMemory::Alloc((length+1)*sizeof(PRUnichar)); - if (!*aTitle) { - return NS_ERROR_OUT_OF_MEMORY; - } - [title getCharacters:*aTitle]; - } - else { - *aTitle = nsnull; - } - - return NS_OK; -} -NS_IMETHODIMP -nsCocoaBrowserListener::SetTitle(const PRUnichar * aTitle) -{ - NS_ENSURE_ARG(aTitle); - - if (!mContainer) { - return NS_ERROR_FAILURE; - } - - NSString* str = [NSString stringWithPRUnichars:aTitle]; - [mContainer setTitle:str]; - - return NS_OK; -} - -/* [noscript] readonly attribute voidPtr siteWindow; */ -NS_IMETHODIMP -nsCocoaBrowserListener::GetSiteWindow(void * *aSiteWindow) -{ - NS_ENSURE_ARG_POINTER(aSiteWindow); - *aSiteWindow = nsnull; - if (!mView) { - return NS_ERROR_FAILURE; - } - - NSWindow* window = [mView window]; - if (!window) { - return NS_ERROR_FAILURE; - } - - *aSiteWindow = (void*)window; - - return NS_OK; -} - - -// -// Implementation of nsIWebProgressListener -// - -/* void onStateChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in unsigned long aStateFlags, in unsigned long aStatus); */ -NS_IMETHODIMP -nsCocoaBrowserListener::OnStateChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, - PRUint32 aStateFlags, PRUint32 aStatus) -{ - NSEnumerator* enumerator = [mListeners objectEnumerator]; - id obj; - - if (aStateFlags & nsIWebProgressListener::STATE_IS_NETWORK) { - if (aStateFlags & nsIWebProgressListener::STATE_START) { - while ((obj = [enumerator nextObject])) - [obj onLoadingStarted]; - } - else if (aStateFlags & nsIWebProgressListener::STATE_STOP) { - while ((obj = [enumerator nextObject])) - [obj onLoadingCompleted:(NS_SUCCEEDED(aStatus))]; - } - } - - return NS_OK; -} - -/* void onProgressChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in long aCurSelfProgress, in long aMaxSelfProgress, in long aCurTotalProgress, in long aMaxTotalProgress); */ -NS_IMETHODIMP -nsCocoaBrowserListener::OnProgressChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, - PRInt32 aCurSelfProgress, PRInt32 aMaxSelfProgress, - PRInt32 aCurTotalProgress, PRInt32 aMaxTotalProgress) -{ - NSEnumerator* enumerator = [mListeners objectEnumerator]; - id obj; - while ((obj = [enumerator nextObject])) - [obj onProgressChange:aCurTotalProgress outOf:aMaxTotalProgress]; - - return NS_OK; -} - -/* void onLocationChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in nsIURI location); */ -NS_IMETHODIMP -nsCocoaBrowserListener::OnLocationChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, - nsIURI *location) -{ - if (!location) - return NS_ERROR_FAILURE; - - nsCAutoString spec; - location->GetSpec(spec); - NSString* str = [NSString stringWithCString:spec.get()]; - - NSEnumerator* enumerator = [mListeners objectEnumerator]; - id obj; - while ((obj = [enumerator nextObject])) - [obj onLocationChange:str]; - - return NS_OK; -} - -/* void onStatusChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in nsresult aStatus, in wstring aMessage); */ -NS_IMETHODIMP -nsCocoaBrowserListener::OnStatusChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, nsresult aStatus, - const PRUnichar *aMessage) -{ - NSString* str = [NSString stringWithPRUnichars:aMessage]; - - NSEnumerator* enumerator = [mListeners objectEnumerator]; - id obj; - while ((obj = [enumerator nextObject])) - [obj onStatusChange: str]; - - return NS_OK; -} - -/* void onSecurityChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in unsigned long state); */ -NS_IMETHODIMP -nsCocoaBrowserListener::OnSecurityChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, PRUint32 state) -{ - NSEnumerator* enumerator = [mListeners objectEnumerator]; - id obj; - while ((obj = [enumerator nextObject])) - [obj onSecurityStateChange: state]; - - return NS_OK; -} - -void -nsCocoaBrowserListener::AddListener(id aListener) -{ - [mListeners addObject:aListener]; -} - -void -nsCocoaBrowserListener::RemoveListener(id aListener) -{ - [mListeners removeObject:aListener]; -} - -void -nsCocoaBrowserListener::SetContainer(id aContainer) -{ - [mContainer autorelease]; - - mContainer = aContainer; - - [mContainer retain]; -} - diff --git a/mozilla/camino/nsCocoaBrowserService.h b/mozilla/camino/nsCocoaBrowserService.h deleted file mode 100644 index e72518cf66e..00000000000 --- a/mozilla/camino/nsCocoaBrowserService.h +++ /dev/null @@ -1,77 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape 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/NPL/ - * - * 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 mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 2001 - * 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 NPL, 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 NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef __nsCocoaBrowserService_h__ -#define __nsCocoaBrowserService_h__ - -#import "nsAlertController.h" -#include "nsCOMPtr.h" -#include "nsIWindowCreator.h" -#include "nsIHelperAppLauncherDialog.h" -#include "nsIFactory.h" - -class nsCocoaBrowserService : public nsIWindowCreator, - public nsIFactory, - public nsIHelperAppLauncherDialog -{ -public: - nsCocoaBrowserService(); - virtual ~nsCocoaBrowserService(); - - NS_DECL_ISUPPORTS - NS_DECL_NSIWINDOWCREATOR - NS_DECL_NSIFACTORY - NS_DECL_NSIHELPERAPPLAUNCHERDIALOG - - static nsresult InitEmbedding(); - static void TermEmbedding(); - static void BrowserClosed(); - - static void SetAlertController(nsAlertController* aController); - static nsAlertController* GetAlertController(); - -public: - static PRUint32 sNumBrowsers; - -private: - static nsCocoaBrowserService* sSingleton; - static nsAlertController* sController; - static PRBool sCanTerminate; -}; - - -#endif diff --git a/mozilla/camino/nsCocoaBrowserService.mm b/mozilla/camino/nsCocoaBrowserService.mm deleted file mode 100644 index b6a20a40415..00000000000 --- a/mozilla/camino/nsCocoaBrowserService.mm +++ /dev/null @@ -1,274 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape 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/NPL/ - * - * 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 mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1998 - * 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 NPL, 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 NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#import "NSString+Utils.h" - -#import "nsCocoaBrowserService.h" -#import "DownloadFactories.h" -#import "CHBrowserView.h" - -#include "nsIWindowWatcher.h" -#include "nsIWebBrowserChrome.h" -#include "nsCRT.h" -#include "nsString.h" -#include "nsIGenericFactory.h" -#include "nsIComponentRegistrar.h" -#include "nsEmbedAPI.h" -#include "nsIDownload.h" -#include "nsIExternalHelperAppService.h" - -nsAlertController* nsCocoaBrowserService::sController = nsnull; -nsCocoaBrowserService* nsCocoaBrowserService::sSingleton = nsnull; -PRUint32 nsCocoaBrowserService::sNumBrowsers = 0; -PRBool nsCocoaBrowserService::sCanTerminate = PR_FALSE; - -// This method should return a nsModuleComponentInfo array of -// application-provided XPCOM components to register. The implementation -// is in AppComponents.mm. -extern const nsModuleComponentInfo* GetAppModuleComponentInfo(int* outNumComponents); - -// nsCocoaBrowserService implementation -nsCocoaBrowserService::nsCocoaBrowserService() -{ - NS_INIT_ISUPPORTS(); -} - -nsCocoaBrowserService::~nsCocoaBrowserService() -{ -} - -NS_IMPL_ISUPPORTS3(nsCocoaBrowserService, - nsIWindowCreator, - nsIFactory, - nsIHelperAppLauncherDialog) - -/* static */ -nsresult -nsCocoaBrowserService::InitEmbedding() -{ - sNumBrowsers++; - - if (sSingleton) - return NS_OK; - - sSingleton = new nsCocoaBrowserService(); - if (!sSingleton) - return NS_ERROR_OUT_OF_MEMORY; - NS_ADDREF(sSingleton); - - nsCOMPtr cr; - NS_GetComponentRegistrar(getter_AddRefs(cr)); - if ( !cr ) - return NS_ERROR_FAILURE; - - // Register as the window creator - nsCOMPtr watcher(do_GetService("@mozilla.org/embedcomp/window-watcher;1")); - if (!watcher) - return NS_ERROR_FAILURE; - watcher->SetWindowCreator(sSingleton); - - // Register application-provided Gecko components. This includes our security dialog implementation. - - int numComponents; - const nsModuleComponentInfo* componentInfo = GetAppModuleComponentInfo(&numComponents); - nsresult rv; - for (int i = 0; i < numComponents; ++i) { - nsCOMPtr componentFactory; - rv = NS_NewGenericFactory(getter_AddRefs(componentFactory), &(componentInfo[i])); - if (NS_FAILED(rv)) { - NS_ASSERTION(PR_FALSE, "Unable to create factory for component"); - continue; - } - - rv = cr->RegisterFactory(componentInfo[i].mCID, - componentInfo[i].mDescription, - componentInfo[i].mContractID, - componentFactory); - NS_ASSERTION(NS_SUCCEEDED(rv), "Unable to register factory for component"); - } - - // replace the external helper app dialog with our own - #define NS_HELPERAPPLAUNCHERDIALOG_CID \ - {0xf68578eb, 0x6ec2, 0x4169, {0xae, 0x19, 0x8c, 0x62, 0x43, 0xf0, 0xab, 0xe1}} - static NS_DEFINE_CID(kHelperDlgCID, NS_HELPERAPPLAUNCHERDIALOG_CID); - rv = cr->RegisterFactory(kHelperDlgCID, NS_IHELPERAPPLAUNCHERDLG_CLASSNAME, NS_IHELPERAPPLAUNCHERDLG_CONTRACTID, - sSingleton); - - // replace the downloader with our own which does not rely on the xpfe downlaod manager - nsCOMPtr downloadFactory; - rv = NewDownloadListenerFactory(getter_AddRefs(downloadFactory)); - if (NS_FAILED(rv)) return rv; - - static NS_DEFINE_CID(kDownloadCID, NS_DOWNLOAD_CID); - rv = cr->RegisterFactory(kDownloadCID, "Download", NS_DOWNLOAD_CONTRACTID, downloadFactory); - - return rv; -} - -/* static */ -void -nsCocoaBrowserService::BrowserClosed() -{ - sNumBrowsers--; - if (sCanTerminate && sNumBrowsers == 0) { - // The app is terminating *and* our count dropped to 0. - NS_IF_RELEASE(sSingleton); - NS_TermEmbedding(); -#if DEBUG - NSLog(@"Shutting down embedding!"); -#endif - } -} - -/* static */ -void -nsCocoaBrowserService::TermEmbedding() -{ - sCanTerminate = PR_TRUE; - if (sNumBrowsers == 0) { - NS_IF_RELEASE(sSingleton); - NS_TermEmbedding(); -#if DEBUG - NSLog(@"Shutting down embedding."); -#endif - } - else { -#if DEBUG - NSLog(@"Cannot yet shut down embedding."); -#endif - // Otherwise we cannot yet terminate. We have to let the death of the browser windows - // induce termination. - } -} - -#define NS_ALERT_NIB_NAME "alert" - -nsAlertController* -nsCocoaBrowserService::GetAlertController() -{ - if (!sController) { - NSBundle* bundle = [NSBundle bundleForClass:[CHBrowserView class]]; - [bundle loadNibFile:@NS_ALERT_NIB_NAME externalNameTable:nsnull withZone:[NSApp zone]]; - } - return sController; -} - -void -nsCocoaBrowserService::SetAlertController(nsAlertController* aController) -{ - // XXX When should the controller be released? - sController = aController; - [sController retain]; -} - -// nsIFactory implementation -NS_IMETHODIMP -nsCocoaBrowserService::CreateInstance(nsISupports *aOuter, - const nsIID & aIID, - void **aResult) -{ - - NS_ENSURE_ARG_POINTER(aResult); - - /* - if (aIID.Equals(NS_GET_IID(nsIHelperAppLauncherDialog))) - { - } - */ - - return sSingleton->QueryInterface(aIID, aResult); -} - -NS_IMETHODIMP -nsCocoaBrowserService::LockFactory(PRBool lock) -{ - return NS_OK; -} - - -// Implementation of nsIWindowCreator -/* nsIWebBrowserChrome createChromeWindow (in nsIWebBrowserChrome parent, in PRUint32 chromeFlags); */ -NS_IMETHODIMP -nsCocoaBrowserService::CreateChromeWindow(nsIWebBrowserChrome *parent, - PRUint32 chromeFlags, - nsIWebBrowserChrome **_retval) -{ - if (!parent) { -#if DEBUG - NSLog(@"Attempt to create a new browser window with a null parent. Should not happen in Chimera."); -#endif - return NS_ERROR_FAILURE; - } - - nsCOMPtr browserChrome(do_QueryInterface(parent)); - return browserChrome->CreateChromeWindow(parent, chromeFlags, _retval); -} - - -// void show( in nsIHelperAppLauncher aLauncher, in nsISupports aContext ); -NS_IMETHODIMP -nsCocoaBrowserService::Show(nsIHelperAppLauncher* inLauncher, nsISupports* inContext) -{ - return inLauncher->SaveToDisk(nsnull, PR_FALSE); -} - -NS_IMETHODIMP -nsCocoaBrowserService::PromptForSaveToFile(nsISupports *aWindowContext, const PRUnichar *aDefaultFile, const PRUnichar *aSuggestedFileExtension, nsILocalFile **_retval) -{ - NSString* filename = [NSString stringWithPRUnichars:aDefaultFile]; - NSSavePanel *thePanel = [NSSavePanel savePanel]; - - // Note: although the docs for NSSavePanel specifically state "path and filename can be empty strings, but - // cannot be nil" if you want the last used directory to persist between calls to display the save panel - // use nil for the path given to runModalForDirectory - int runResult = [thePanel runModalForDirectory: nil file:filename]; - if (runResult == NSOKButton) { - // NSLog(@"Saving to %@", [thePanel filename]); - NSString *theName = [thePanel filename]; - return NS_NewNativeLocalFile(nsDependentCString([theName fileSystemRepresentation]), PR_FALSE, _retval); - } - - return NS_ERROR_FAILURE; -} - -/* void showProgressDialog (in nsIHelperAppLauncher aLauncher, in nsISupports aContext); */ -NS_IMETHODIMP -nsCocoaBrowserService::ShowProgressDialog(nsIHelperAppLauncher *aLauncher, nsISupports *aContext) -{ - NSLog(@"nsCocoaBrowserService::ShowProgressDialog"); - return NS_OK; -} diff --git a/mozilla/camino/nsDownloadListener.h b/mozilla/camino/nsDownloadListener.h deleted file mode 100644 index cd15b3626cd..00000000000 --- a/mozilla/camino/nsDownloadListener.h +++ /dev/null @@ -1,89 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape 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/NPL/ - * - * 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 mozilla.org 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): - * Simon Fraser - * - * 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 NPL, 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 NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - - - -#import -#import - -#import "DownloadProgressDisplay.h" - -#include "nsString.h" -#include "nsIDownload.h" -#include "nsIWebProgressListener.h" -#include "nsIWebBrowserPersist.h" -#include "nsIURI.h" -#include "nsILocalFile.h" - - -// maybe this should replace nsHeaderSniffer too? - -class nsDownloadListener : public CHDownloader, - public nsIDownload, - public nsIWebProgressListener -{ -public: - nsDownloadListener(DownloadControllerFactory* inDownloadControllerFactory); - virtual ~nsDownloadListener(); - - NS_DECL_ISUPPORTS_INHERITED - NS_DECL_NSIDOWNLOAD - NS_DECL_NSIWEBPROGRESSLISTENER - -public: - //void BeginDownload(); - void InitDialog(); - - virtual void PauseDownload(); - virtual void ResumeDownload(); - virtual void CancelDownload(); - virtual void DownloadDone(); - virtual void DetachDownloadDisplay(); - -private: - - nsCOMPtr mWebPersist; // Our web persist object. - nsCOMPtr mURI; // The URI of our source file. Null if we're saving a complete document. - nsCOMPtr mDestination; // Our destination URL. - PRInt64 mStartTime; // When the download started - PRPackedBool mBypassCache; // Whether we should bypass the cache or not. - PRPackedBool mNetworkTransfer; // true if the first OnStateChange has the NETWORK bit set - PRPackedBool mGotFirstStateChange; // true after we've seen the first OnStateChange - PRPackedBool mUserCanceled; // true if the user canceled the download -}; - diff --git a/mozilla/camino/nsDownloadListener.mm b/mozilla/camino/nsDownloadListener.mm deleted file mode 100644 index b0b2e126a3a..00000000000 --- a/mozilla/camino/nsDownloadListener.mm +++ /dev/null @@ -1,325 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape 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/NPL/ - * - * 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 mozilla.org 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): - * Simon Fraser - * - * - * 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 NPL, 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 NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#import "NSString+Utils.h" - -#include "nsDownloadListener.h" - -#include "nsIWebProgress.h" -#include "nsIRequest.h" -#include "nsIURL.h" -#include "netCore.h" - -nsDownloadListener::nsDownloadListener(DownloadControllerFactory* inControllerFactory) -: CHDownloader(inControllerFactory) -, mBypassCache(PR_FALSE) -, mNetworkTransfer(PR_FALSE) -, mGotFirstStateChange(PR_FALSE) -, mUserCanceled(PR_FALSE) -{ -} - -nsDownloadListener::~nsDownloadListener() -{ -} - -NS_IMPL_ISUPPORTS_INHERITED2(nsDownloadListener, CHDownloader, nsIDownload, nsIWebProgressListener) - -#pragma mark - - -/* void init (in nsIURI aSource, in nsILocalFile aTarget, in wstring aDisplayName, in wstring openingWith, in long long startTime, in nsIWebBrowserPersist aPersist); */ -NS_IMETHODIMP -nsDownloadListener::Init(nsIURI *aSource, nsILocalFile *aTarget, const PRUnichar *aDisplayName, - const PRUnichar *openingWith, PRInt64 startTime, nsIWebBrowserPersist *aPersist) -{ - CreateDownloadDisplay(); // call the base class to make the download UI - - if (aPersist) // only true for File->Save As. - { - mWebPersist = aPersist; - mWebPersist->SetProgressListener(this); // we form a cycle here, since we're a listener. - // we'll break this cycle in DownloadDone() - } - - SetIsFileSave(aPersist != NULL); - - mDestination = aTarget; - mURI = aSource; - mStartTime = startTime; - - InitDialog(); - return NS_OK; -} - -/* readonly attribute nsIURI source; */ -NS_IMETHODIMP -nsDownloadListener::GetSource(nsIURI * *aSource) -{ - NS_ENSURE_ARG_POINTER(aSource); - NS_IF_ADDREF(*aSource = mURI); - return NS_OK; -} - -/* readonly attribute nsILocalFile target; */ -NS_IMETHODIMP -nsDownloadListener::GetTarget(nsILocalFile * *aTarget) -{ - NS_ENSURE_ARG_POINTER(aTarget); - NS_IF_ADDREF(*aTarget = mDestination); - return NS_OK; -} - -/* readonly attribute nsIWebBrowserPersist persist; */ -NS_IMETHODIMP -nsDownloadListener::GetPersist(nsIWebBrowserPersist * *aPersist) -{ - NS_ENSURE_ARG_POINTER(aPersist); - NS_IF_ADDREF(*aPersist = mWebPersist); - return NS_OK; -} - -/* readonly attribute PRInt32 percentComplete; */ -NS_IMETHODIMP -nsDownloadListener::GetPercentComplete(PRInt32 *aPercentComplete) -{ - return NS_ERROR_NOT_IMPLEMENTED; -} - -/* attribute wstring displayName; */ -NS_IMETHODIMP -nsDownloadListener::GetDisplayName(PRUnichar * *aDisplayName) -{ - return NS_ERROR_NOT_IMPLEMENTED; -} - -NS_IMETHODIMP -nsDownloadListener::SetDisplayName(const PRUnichar * aDisplayName) -{ - return NS_ERROR_NOT_IMPLEMENTED; -} - -/* readonly attribute long long startTime; */ -NS_IMETHODIMP -nsDownloadListener::GetStartTime(PRInt64 *aStartTime) -{ - NS_ENSURE_ARG(aStartTime); - *aStartTime = mStartTime; - return NS_OK; -} - -/* readonly attribute wstring openingWith; */ -NS_IMETHODIMP -nsDownloadListener::GetOpeningWith(PRUnichar * *aOpeningWith) -{ - return NS_ERROR_NOT_IMPLEMENTED; -} - -/* attribute nsIWebProgressListener listener; */ -NS_IMETHODIMP -nsDownloadListener::GetListener(nsIWebProgressListener * *aListener) -{ - NS_ENSURE_ARG_POINTER(aListener); - NS_IF_ADDREF(*aListener = (nsIWebProgressListener *)this); - return NS_OK; -} - -NS_IMETHODIMP -nsDownloadListener::SetListener(nsIWebProgressListener * aListener) -{ - return NS_ERROR_NOT_IMPLEMENTED; -} - -/* attribute nsIObserver observer; */ -NS_IMETHODIMP -nsDownloadListener::GetObserver(nsIObserver * *aObserver) -{ - return NS_ERROR_NOT_IMPLEMENTED; -} - -NS_IMETHODIMP -nsDownloadListener::SetObserver(nsIObserver * aObserver) -{ - return NS_ERROR_NOT_IMPLEMENTED; -} - -#pragma mark - - -/* void onProgressChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in long aCurSelfProgress, in long aMaxSelfProgress, in long aCurTotalProgress, in long aMaxTotalProgress); */ -NS_IMETHODIMP -nsDownloadListener::OnProgressChange(nsIWebProgress *aWebProgress, - nsIRequest *aRequest, - PRInt32 aCurSelfProgress, - PRInt32 aMaxSelfProgress, - PRInt32 aCurTotalProgress, - PRInt32 aMaxTotalProgress) -{ - if (mUserCanceled) - { - if (aRequest) - aRequest->Cancel(NS_BINDING_ABORTED); - - mUserCanceled = false; - } - - [mDownloadDisplay setProgressTo:aCurTotalProgress ofMax:aMaxTotalProgress]; - return NS_OK; -} - -/* void onLocationChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in nsIURI location); */ -NS_IMETHODIMP -nsDownloadListener::OnLocationChange(nsIWebProgress *aWebProgress, - nsIRequest *aRequest, - nsIURI *location) -{ - return NS_OK; -} - -/* void onStatusChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in nsresult aStatus, in wstring aMessage); */ -NS_IMETHODIMP -nsDownloadListener::OnStatusChange(nsIWebProgress *aWebProgress, - nsIRequest *aRequest, - nsresult aStatus, - const PRUnichar *aMessage) -{ - return NS_OK; -} - -/* void onSecurityChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in unsigned long state); */ -NS_IMETHODIMP -nsDownloadListener::OnSecurityChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, PRUint32 state) -{ - return NS_OK; -} - -// Implementation of nsIWebProgressListener -/* void onStateChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in unsigned long aStateFlags, in unsigned long aStatus); */ -NS_IMETHODIMP -nsDownloadListener::OnStateChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, PRUint32 aStateFlags, - PRUint32 aStatus) -{ - // NSLog(@"State changed: state %u, status %u", aStateFlags, aStatus); - if (!mGotFirstStateChange) { - mNetworkTransfer = ((aStateFlags & STATE_IS_NETWORK) != 0); - mGotFirstStateChange = PR_TRUE; - } - - // when the entire download finishes, stop the progress timer and clean up - // the window and controller. We will get this even in the event of a cancel, - // so this is the only place in the listener where we should kill the download. - if ((aStateFlags & STATE_STOP) && (!mNetworkTransfer || (aStateFlags & STATE_IS_NETWORK))) { - DownloadDone(); - } - return NS_OK; -} - -#pragma mark - - -void -nsDownloadListener::InitDialog() -{ - // dialog has to be shown before the outlets get hooked up - [mDownloadDisplay onStartDownload:(BOOL)IsFileSave()]; - - if (mURI) - { - nsCAutoString spec; - mURI->GetSpec(spec); - [mDownloadDisplay setSourceURL: [NSString stringWithUTF8String:spec.get()]]; - } - - nsAutoString pathStr; - mDestination->GetPath(pathStr); - [mDownloadDisplay setDestinationPath: [NSString stringWith_nsAString:pathStr]]; -} - -void -nsDownloadListener::PauseDownload() -{ - // write me -} - -void -nsDownloadListener::ResumeDownload() -{ - // write me -} - -void -nsDownloadListener::CancelDownload() -{ - mUserCanceled = PR_TRUE; - - if (mWebPersist) - { - mWebPersist->CancelSave(); - mUserCanceled = PR_FALSE; - } - - // delete any files we've created... - - -} - -void -nsDownloadListener::DownloadDone() -{ - // break the reference cycle by removing ourselves as a listener - if (mWebPersist) - { - mWebPersist->SetProgressListener(nsnull); - mWebPersist = nsnull; - } - - [mDownloadDisplay onEndDownload]; -} - -// -// DetachDownloadDisplay -// -// there are times when the download dislpay UI goes away before the -// listener (quit, for example). This alerts us that we should forget all -// about having any UI. -// -void -nsDownloadListener::DetachDownloadDisplay() -{ - mDownloadDisplay = nil; -} - -#pragma mark - diff --git a/mozilla/camino/nsStaticComponents.cpp b/mozilla/camino/nsStaticComponents.cpp deleted file mode 100644 index 1065d7b5ed2..00000000000 --- a/mozilla/camino/nsStaticComponents.cpp +++ /dev/null @@ -1,72 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- - * - * 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 mozilla.org code. - * - * The Initial Developer of the Original Code is Netscape Communications - * Corporation. Portions created by Netscape are - * Copyright (C) 2001 Netscape Communications Corporation. All - * Rights Reserved. - * - * Contributor(s): - * Christopher Seawood - * Chris Waterson - */ - -#line 26 "nsStaticComponents.cpp.in" -#define XPCOM_TRANSLATE_NSGM_ENTRY_POINT 1 - -#include "nsIGenericFactory.h" -#include "nsStaticComponent.h" - -/** - * Construct a unique NSGetModule entry point for a generic module. - */ -#define NSGETMODULE(_name) _name##_NSGetmodule - -/** - * Declare an NSGetModule() routine for a generic module. - */ -#define DECL_NSGETMODULE(_name) \ -extern nsModuleInfo NSMODULEINFO(_name); \ -extern "C" NS_EXPORT nsresult \ -NSGETMODULE(_name) (nsIComponentManager* aCompMgr, \ - nsIFile* aLocation, \ - nsIModule** aResult) \ -{ \ - return NS_NewGenericModule2(&NSMODULEINFO(_name), aResult);\ -} - -// NSGetModule entry points -DECL_NSGETMODULE(UcharUtil) DECL_NSGETMODULE(nsUConvModule) DECL_NSGETMODULE(nsUCvJAModule) DECL_NSGETMODULE(nsUCvCnModule) DECL_NSGETMODULE(nsUCvLatinModule) DECL_NSGETMODULE(nsUCvTWModule) DECL_NSGETMODULE(nsUCvTW2Module) DECL_NSGETMODULE(nsUCvKoModule) DECL_NSGETMODULE(nsLocaleModule) DECL_NSGETMODULE(nsStringBundleModule) DECL_NSGETMODULE(nsLWBrkModule) DECL_NSGETMODULE(nsCharDetModule) DECL_NSGETMODULE(xpconnect) DECL_NSGETMODULE(cacheservice) DECL_NSGETMODULE(necko_core_and_primary_protocols) DECL_NSGETMODULE(necko_secondary_protocols) DECL_NSGETMODULE(nsURILoaderModule) DECL_NSGETMODULE(nsPrefModule) DECL_NSGETMODULE(nsCJVMManagerModule) DECL_NSGETMODULE(nsSecurityManagerModule) DECL_NSGETMODULE(nsChromeModule) DECL_NSGETMODULE(nsRDFModule) DECL_NSGETMODULE(nsParserModule) DECL_NSGETMODULE(nsGfxMacModule) DECL_NSGETMODULE(nsGfx2Module) DECL_NSGETMODULE(nsImageLib2Module) DECL_NSGETMODULE(nsPNGDecoderModule) DECL_NSGETMODULE(nsGIFModule2) DECL_NSGETMODULE(nsJPEGDecoderModule) DECL_NSGETMODULE(nsPluginModule) DECL_NSGETMODULE(javascript__protocol) DECL_NSGETMODULE(DOM_components) DECL_NSGETMODULE(nsViewModule) DECL_NSGETMODULE(nsWidgetMacModule) DECL_NSGETMODULE(nsContentModule) DECL_NSGETMODULE(nsLayoutModule) DECL_NSGETMODULE(nsMorkModule) DECL_NSGETMODULE(docshell_provider) DECL_NSGETMODULE(embedcomponents) DECL_NSGETMODULE(Browser_Embedding_Module) DECL_NSGETMODULE(nsEditorModule) DECL_NSGETMODULE(nsTransactionManagerModule) DECL_NSGETMODULE(nsTextServicesModule) DECL_NSGETMODULE(nsProfileModule) DECL_NSGETMODULE(Session_History_Module) DECL_NSGETMODULE(application) DECL_NSGETMODULE(nsCookieModule) DECL_NSGETMODULE(nsXMLExtrasModule) DECL_NSGETMODULE(nsUniversalCharDetModule) DECL_NSGETMODULE(BOOT) DECL_NSGETMODULE(NSS) -#line 52 "nsStaticComponents.cpp.in" - -/** - * The nsStaticModuleInfo - */ -static nsStaticModuleInfo gStaticModuleInfo[] = { -#define MODULE(_name) { (#_name), NSGETMODULE(_name) } - MODULE(UcharUtil), MODULE(nsUConvModule), MODULE(nsUCvJAModule), MODULE(nsUCvCnModule), MODULE(nsUCvLatinModule), MODULE(nsUCvTWModule), MODULE(nsUCvTW2Module), MODULE(nsUCvKoModule), MODULE(nsLocaleModule), MODULE(nsStringBundleModule), MODULE(nsLWBrkModule), MODULE(nsCharDetModule), MODULE(xpconnect), MODULE(cacheservice), MODULE(necko_core_and_primary_protocols), MODULE(necko_secondary_protocols), MODULE(nsURILoaderModule), MODULE(nsPrefModule), MODULE(nsCJVMManagerModule), MODULE(nsSecurityManagerModule), MODULE(nsChromeModule), MODULE(nsRDFModule), MODULE(nsParserModule), MODULE(nsGfxMacModule), MODULE(nsGfx2Module), MODULE(nsImageLib2Module), MODULE(nsPNGDecoderModule), MODULE(nsGIFModule2), MODULE(nsJPEGDecoderModule), MODULE(nsPluginModule), MODULE(javascript__protocol), MODULE(DOM_components), MODULE(nsViewModule), MODULE(nsWidgetMacModule), MODULE(nsContentModule), MODULE(nsLayoutModule), MODULE(nsMorkModule), MODULE(docshell_provider), MODULE(embedcomponents), MODULE(Browser_Embedding_Module), MODULE(nsEditorModule), MODULE(nsTransactionManagerModule), MODULE(nsTextServicesModule), MODULE(nsProfileModule), MODULE(Session_History_Module), MODULE(application), MODULE(nsCookieModule), MODULE(nsXMLExtrasModule), MODULE(nsUniversalCharDetModule), MODULE(BOOT), MODULE(NSS), -#line 60 "nsStaticComponents.cpp.in" -}; - -/** - * Our NSGetStaticModuleInfoFunc - */ -nsresult -app_getModuleInfo(nsStaticModuleInfo **info, PRUint32 *count) -{ - *info = gStaticModuleInfo; - *count = sizeof(gStaticModuleInfo) / sizeof(gStaticModuleInfo[0]); - return NS_OK; -} - diff --git a/mozilla/camino/panel_icon.tif b/mozilla/camino/panel_icon.tif deleted file mode 100644 index 09059671b1f..00000000000 Binary files a/mozilla/camino/panel_icon.tif and /dev/null differ diff --git a/mozilla/camino/print.tif b/mozilla/camino/print.tif deleted file mode 100755 index 6a7601b0937..00000000000 Binary files a/mozilla/camino/print.tif and /dev/null differ diff --git a/mozilla/camino/projects/redo-prebinding.sh b/mozilla/camino/projects/redo-prebinding.sh deleted file mode 100644 index 303c6125111..00000000000 --- a/mozilla/camino/projects/redo-prebinding.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh -BINARY_DIR=`pwd|sed 's/ /\\\ /g'` -/bin/sh -c "update_prebinding -files $BINARY_DIR/*" diff --git a/mozilla/camino/redo-prebinding.sh b/mozilla/camino/redo-prebinding.sh deleted file mode 100644 index 303c6125111..00000000000 --- a/mozilla/camino/redo-prebinding.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh -BINARY_DIR=`pwd|sed 's/ /\\\ /g'` -/bin/sh -c "update_prebinding -files $BINARY_DIR/*" diff --git a/mozilla/camino/reload.tif b/mozilla/camino/reload.tif deleted file mode 100755 index c67fed929d5..00000000000 Binary files a/mozilla/camino/reload.tif and /dev/null differ diff --git a/mozilla/camino/saveCancel.tif b/mozilla/camino/saveCancel.tif deleted file mode 100644 index b7916fd2919..00000000000 Binary files a/mozilla/camino/saveCancel.tif and /dev/null differ diff --git a/mozilla/camino/saveLeaveOpenNO.tif b/mozilla/camino/saveLeaveOpenNO.tif deleted file mode 100644 index a3f65fcd95e..00000000000 Binary files a/mozilla/camino/saveLeaveOpenNO.tif and /dev/null differ diff --git a/mozilla/camino/saveLeaveOpenYES.tif b/mozilla/camino/saveLeaveOpenYES.tif deleted file mode 100644 index 4032caf3fb1..00000000000 Binary files a/mozilla/camino/saveLeaveOpenYES.tif and /dev/null differ diff --git a/mozilla/camino/saveOpenFile.tif b/mozilla/camino/saveOpenFile.tif deleted file mode 100644 index 3fd7ae0f936..00000000000 Binary files a/mozilla/camino/saveOpenFile.tif and /dev/null differ diff --git a/mozilla/camino/savePause.tif b/mozilla/camino/savePause.tif deleted file mode 100644 index 34092307c32..00000000000 Binary files a/mozilla/camino/savePause.tif and /dev/null differ diff --git a/mozilla/camino/saveResume.tif b/mozilla/camino/saveResume.tif deleted file mode 100644 index 49ab50373ed..00000000000 Binary files a/mozilla/camino/saveResume.tif and /dev/null differ diff --git a/mozilla/camino/saveShowFile.tif b/mozilla/camino/saveShowFile.tif deleted file mode 100644 index 79766ad3e1d..00000000000 Binary files a/mozilla/camino/saveShowFile.tif and /dev/null differ diff --git a/mozilla/camino/searchicon.tif b/mozilla/camino/searchicon.tif deleted file mode 100644 index 31e514b2d68..00000000000 Binary files a/mozilla/camino/searchicon.tif and /dev/null differ diff --git a/mozilla/camino/security_broken.tif b/mozilla/camino/security_broken.tif deleted file mode 100644 index 7cbc1580f39..00000000000 Binary files a/mozilla/camino/security_broken.tif and /dev/null differ diff --git a/mozilla/camino/security_lock.tif b/mozilla/camino/security_lock.tif deleted file mode 100644 index 2b872eff3ba..00000000000 Binary files a/mozilla/camino/security_lock.tif and /dev/null differ diff --git a/mozilla/camino/separator_on.tif b/mozilla/camino/separator_on.tif deleted file mode 100644 index b8d43984ce7..00000000000 Binary files a/mozilla/camino/separator_on.tif and /dev/null differ diff --git a/mozilla/camino/showall.tif b/mozilla/camino/showall.tif deleted file mode 100644 index 9af186d5801..00000000000 Binary files a/mozilla/camino/showall.tif and /dev/null differ diff --git a/mozilla/camino/showsource.tif b/mozilla/camino/showsource.tif deleted file mode 100644 index f32d1546a87..00000000000 Binary files a/mozilla/camino/showsource.tif and /dev/null differ diff --git a/mozilla/camino/sidebar.tif b/mozilla/camino/sidebar.tif deleted file mode 100755 index da3297c8600..00000000000 Binary files a/mozilla/camino/sidebar.tif and /dev/null differ diff --git a/mozilla/camino/sidebarClosed.tif b/mozilla/camino/sidebarClosed.tif deleted file mode 100644 index 11bb8657f82..00000000000 Binary files a/mozilla/camino/sidebarClosed.tif and /dev/null differ diff --git a/mozilla/camino/sidebarOpened.tif b/mozilla/camino/sidebarOpened.tif deleted file mode 100644 index 3c3785926c4..00000000000 Binary files a/mozilla/camino/sidebarOpened.tif and /dev/null differ diff --git a/mozilla/camino/smallDocument.tiff b/mozilla/camino/smallDocument.tiff deleted file mode 100644 index 42a8b6cbcb2..00000000000 Binary files a/mozilla/camino/smallDocument.tiff and /dev/null differ diff --git a/mozilla/camino/smallbookmark.tif b/mozilla/camino/smallbookmark.tif deleted file mode 100644 index 5b7557e1db5..00000000000 Binary files a/mozilla/camino/smallbookmark.tif and /dev/null differ diff --git a/mozilla/camino/splash.tif b/mozilla/camino/splash.tif deleted file mode 100644 index 12a7eb5cb08..00000000000 Binary files a/mozilla/camino/splash.tif and /dev/null differ diff --git a/mozilla/camino/stop.tif b/mozilla/camino/stop.tif deleted file mode 100755 index 0f326815e29..00000000000 Binary files a/mozilla/camino/stop.tif and /dev/null differ diff --git a/mozilla/camino/throbber/throbber-01.gif b/mozilla/camino/throbber/throbber-01.gif deleted file mode 100644 index 3e3a44bb39e..00000000000 Binary files a/mozilla/camino/throbber/throbber-01.gif and /dev/null differ diff --git a/mozilla/camino/throbber/throbber-02.gif b/mozilla/camino/throbber/throbber-02.gif deleted file mode 100644 index 6a872480902..00000000000 Binary files a/mozilla/camino/throbber/throbber-02.gif and /dev/null differ diff --git a/mozilla/camino/throbber/throbber-03.gif b/mozilla/camino/throbber/throbber-03.gif deleted file mode 100644 index ebd56240c80..00000000000 Binary files a/mozilla/camino/throbber/throbber-03.gif and /dev/null differ diff --git a/mozilla/camino/throbber/throbber-04.gif b/mozilla/camino/throbber/throbber-04.gif deleted file mode 100644 index fb040515731..00000000000 Binary files a/mozilla/camino/throbber/throbber-04.gif and /dev/null differ diff --git a/mozilla/camino/throbber/throbber-05.gif b/mozilla/camino/throbber/throbber-05.gif deleted file mode 100644 index 16670e6d932..00000000000 Binary files a/mozilla/camino/throbber/throbber-05.gif and /dev/null differ diff --git a/mozilla/camino/throbber/throbber-06.gif b/mozilla/camino/throbber/throbber-06.gif deleted file mode 100644 index 8f9696037fe..00000000000 Binary files a/mozilla/camino/throbber/throbber-06.gif and /dev/null differ diff --git a/mozilla/camino/throbber/throbber.gif b/mozilla/camino/throbber/throbber.gif deleted file mode 100644 index 1bb813700bc..00000000000 Binary files a/mozilla/camino/throbber/throbber.gif and /dev/null differ diff --git a/mozilla/chimera/AboutBox.nib/classes.nib b/mozilla/chimera/AboutBox.nib/classes.nib deleted file mode 100644 index e9180430bcc..00000000000 --- a/mozilla/chimera/AboutBox.nib/classes.nib +++ /dev/null @@ -1,17 +0,0 @@ -{ - IBClasses = ( - { - ACTIONS = {showPanel = id; }; - CLASS = AboutBox; - LANGUAGE = ObjC; - OUTLETS = { - buildNumberField = NSTextField; - creditsField = NSTextView; - window = NSWindow; - }; - SUPERCLASS = NSObject; - }, - {CLASS = FirstResponder; LANGUAGE = ObjC; SUPERCLASS = NSObject; } - ); - IBVersion = 1; -} \ No newline at end of file diff --git a/mozilla/chimera/AboutBox.nib/info.nib b/mozilla/chimera/AboutBox.nib/info.nib deleted file mode 100644 index 4df25655e54..00000000000 --- a/mozilla/chimera/AboutBox.nib/info.nib +++ /dev/null @@ -1,18 +0,0 @@ - - - - - IBFramework Version - 248.0 - IBLockedObjects - - 7 - - IBOpenObjects - - 5 - - IBSystem Version - 5S66 - - diff --git a/mozilla/chimera/AboutBox.nib/objects.nib b/mozilla/chimera/AboutBox.nib/objects.nib deleted file mode 100644 index 8c1c2d1f930..00000000000 Binary files a/mozilla/chimera/AboutBox.nib/objects.nib and /dev/null differ diff --git a/mozilla/chimera/AppComponents.mm b/mozilla/chimera/AppComponents.mm deleted file mode 100644 index d481db2c921..00000000000 --- a/mozilla/chimera/AppComponents.mm +++ /dev/null @@ -1,74 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** 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 mozilla.org 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): - * Brian Ryner - * - * 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 -#import "SecurityDialogs.h" -#import "CocoaPromptService.h" -#include "nsIGenericFactory.h" - -// {0ffd3880-7a1a-11d6-a384-975d1d5f86fc} -#define NS_BADCERTHANDLER_CID \ - {0x0ffd3880, 0x7a1a, 0x11d6,{0xa3, 0x84, 0x97, 0x5d, 0x1d, 0x5f, 0x86, 0xfc}} - -#define NS_PROMPTSERVICE_CID \ - {0xa2112d6a, 0x0e28, 0x421f, {0xb4, 0x6a, 0x25, 0xc0, 0xb3, 0x8, 0xcb, 0xd0}} - -NS_GENERIC_FACTORY_CONSTRUCTOR(SecurityDialogs); -NS_GENERIC_FACTORY_CONSTRUCTOR(CocoaPromptService); - -static const nsModuleComponentInfo components[] = { - { - "Bad Cert Handler", - NS_BADCERTHANDLER_CID, - NS_NSSDIALOGS_CONTRACTID, - SecurityDialogsConstructor - }, - { - "Prompt Service", - NS_PROMPTSERVICE_CID, - "@mozilla.org/embedcomp/prompt-service;1", - CocoaPromptServiceConstructor - } -}; - -const nsModuleComponentInfo* GetAppModuleComponentInfo(int* outNumComponents) -{ - *outNumComponents = sizeof(components) / sizeof(components[0]); - return components; -} - diff --git a/mozilla/chimera/AppDirServiceProvider.cpp b/mozilla/chimera/AppDirServiceProvider.cpp deleted file mode 100644 index 0330560b090..00000000000 --- a/mozilla/chimera/AppDirServiceProvider.cpp +++ /dev/null @@ -1,155 +0,0 @@ -/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** 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 mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 2001, 2002 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Conrad Carlen - * - * 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 ***** */ - -#include "AppDirServiceProvider.h" -#include "nsAppDirectoryServiceDefs.h" -#include "nsILocalFileMac.h" - -#include - -// Defines - -#define APP_REGISTRY_NAME NS_LITERAL_CSTRING("Application.regs") -#define PROFILES_ROOT_NAME NS_LITERAL_CSTRING("Profiles") - -//***************************************************************************** -// AppDirServiceProvider::Constructor/Destructor -//***************************************************************************** - -AppDirServiceProvider::AppDirServiceProvider(const nsACString& productDirName) -{ - NS_INIT_ISUPPORTS(); - mProductDirName.Assign(productDirName); -} - -AppDirServiceProvider::~AppDirServiceProvider() -{ -} - -//***************************************************************************** -// AppDirServiceProvider::nsISupports -//***************************************************************************** - -NS_IMPL_ISUPPORTS1(AppDirServiceProvider, nsIDirectoryServiceProvider) - -//***************************************************************************** -// AppDirServiceProvider::nsIDirectoryServiceProvider -//***************************************************************************** - -NS_IMETHODIMP -AppDirServiceProvider::GetFile(const char *prop, PRBool *persistant, nsIFile **_retval) -{ - nsCOMPtr localFile; - nsresult rv = NS_ERROR_FAILURE; - nsCAutoString strBuf; - - *_retval = nsnull; - *persistant = PR_TRUE; - - if (strcmp(prop, NS_APP_APPLICATION_REGISTRY_DIR) == 0) - { - rv = GetProductDirectory(getter_AddRefs(localFile)); - } - else if (strcmp(prop, NS_APP_APPLICATION_REGISTRY_FILE) == 0) - { - rv = GetProductDirectory(getter_AddRefs(localFile)); - if (NS_SUCCEEDED(rv)) - rv = localFile->AppendNative(APP_REGISTRY_NAME); - } - else if (strcmp(prop, NS_APP_USER_PROFILES_ROOT_DIR) == 0) - { - rv = GetProductDirectory(getter_AddRefs(localFile)); - if (NS_FAILED(rv)) - return rv; - rv = localFile->AppendNative(PROFILES_ROOT_NAME); - if (NS_FAILED(rv)) - return rv; - - PRBool exists; - rv = localFile->Exists(&exists); - if (NS_SUCCEEDED(rv) && !exists) - rv = localFile->Create(nsIFile::DIRECTORY_TYPE, 0775); - if (NS_FAILED(rv)) - return rv; - } - - if (localFile && NS_SUCCEEDED(rv)) - return localFile->QueryInterface(NS_GET_IID(nsIFile), (void**)_retval); - - return rv; -} - -//***************************************************************************** -// AppDirServiceProvider::AppDirServiceProvider -//***************************************************************************** - -NS_METHOD -AppDirServiceProvider::GetProductDirectory(nsILocalFile **aLocalFile) -{ - NS_ENSURE_ARG_POINTER(aLocalFile); - *aLocalFile = nsnull; - - nsresult rv; - FSRef foundRef; - - OSErr err = ::FSFindFolder(kUserDomain, kApplicationSupportFolderType, kCreateFolder, &foundRef); - if (err != noErr) - return NS_ERROR_FAILURE; - nsCOMPtr localDir(do_CreateInstance(NS_LOCAL_FILE_CONTRACTID)); - if (!localDir) - return NS_ERROR_FAILURE; - rv = localDir->InitWithFSRef(&foundRef); - if (NS_FAILED(rv)) - return rv; - rv = localDir->AppendNative(mProductDirName); - if (NS_FAILED(rv)) - return rv; - - PRBool exists; - rv = localDir->Exists(&exists); - if (NS_SUCCEEDED(rv) && !exists) - rv = localDir->Create(nsIFile::DIRECTORY_TYPE, 0775); - if (NS_FAILED(rv)) - return rv; - - *aLocalFile = localDir; - NS_ADDREF(*aLocalFile); - - return rv; -} - diff --git a/mozilla/chimera/AppDirServiceProvider.h b/mozilla/chimera/AppDirServiceProvider.h deleted file mode 100644 index d7b7f4fb116..00000000000 --- a/mozilla/chimera/AppDirServiceProvider.h +++ /dev/null @@ -1,70 +0,0 @@ -/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** 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 mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 2001, 2002 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Conrad Carlen - * - * 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 ***** */ - -#ifndef __AppDirServiceProvider_h__ -#define __AppDirServiceProvider_h__ - -#include "nsIDirectoryService.h" -#include "nsILocalFile.h" -#include "nsString.h" - -class nsIFile; - -//***************************************************************************** -// class AppDirServiceProvider -//***************************************************************************** - -class AppDirServiceProvider : public nsIDirectoryServiceProvider -{ -public: - AppDirServiceProvider(const nsACString& productDirName); - - NS_DECL_ISUPPORTS - NS_DECL_NSIDIRECTORYSERVICEPROVIDER - -protected: - virtual ~AppDirServiceProvider(); - - NS_METHOD GetProductDirectory(nsILocalFile **aLocalFile); - NS_METHOD GetDefaultUserProfileRoot(nsILocalFile **aLocalFile); - - nsCString mProductDirName; -}; - -#endif // __AppDirServiceProvider_h__ - diff --git a/mozilla/chimera/BookmarkInfoController.h b/mozilla/chimera/BookmarkInfoController.h deleted file mode 100644 index ddd1f896443..00000000000 --- a/mozilla/chimera/BookmarkInfoController.h +++ /dev/null @@ -1,46 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- -* -* 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 the Mozilla browser. -* -* The Initial Developer of the Original Code is Netscape -* Communications Corporation. Portions created by Netscape are -* Copyright (C) 2002 Netscape Communications Corporation. All -* Rights Reserved. -* -* Contributor(s): -* Ben Goodger (Original Author) -* David Haas -*/ -#import -#import "BookmarksService.h" - -@interface BookmarkInfoController : NSWindowController { - IBOutlet NSTextField* mNameField; - IBOutlet NSTextField* mLocationField; - IBOutlet NSTextField* mKeywordField; - IBOutlet NSTextField* mDescriptionField; - IBOutlet NSTextField* mNameLabel; - IBOutlet NSTextField* mLocationLabel; - IBOutlet NSTextField* mKeywordLabel; - IBOutlet NSTextField* mDescriptionLabel; - - BookmarkItem* mBookmarkItem; - NSTextView* mFieldEditor; -} - -+ (id)sharedBookmarkInfoController; - --(void)setBookmark:(BookmarkItem*)aBookmark; - - -@end diff --git a/mozilla/chimera/BookmarkInfoController.mm b/mozilla/chimera/BookmarkInfoController.mm deleted file mode 100644 index c04d5b25127..00000000000 --- a/mozilla/chimera/BookmarkInfoController.mm +++ /dev/null @@ -1,231 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- -* -* 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 the Mozilla browser. -* -* The Initial Developer of the Original Code is Netscape -* Communications Corporation. Portions created by Netscape are -* Copyright (C) 2002 Netscape Communications Corporation. All -* Rights Reserved. -* -* Contributor(s): -* Ben Goodger (Original Author) -* David Haas -*/ - -#import "NSString+Utils.h" - -#import "BookmarkInfoController.h" -#import "BookmarksDataSource.h" - -#include "nsIContent.h" -#include "nsINamespaceManager.h" - - -@interface BookmarkInfoController(Private) - -- (void)showUIElementPair: (id)aLabel control: (id) aControl; -- (void)hideUIElementPair: (id)aLabel control: (id) aControl; -- (void)commitChanges:(id)sender; -- (void)commitField:(id)textField toProperty:(nsIAtom*)propertyAtom; - -@end; - -@implementation BookmarkInfoController - -/* BookmarkInfoController singelton */ -static BookmarkInfoController *sharedBookmarkInfoController = nil; - -+ (id)sharedBookmarkInfoController -{ - if (!sharedBookmarkInfoController) { - sharedBookmarkInfoController = [[BookmarkInfoController alloc] init]; - } - - return sharedBookmarkInfoController; -} - --(id) init -{ - [super initWithWindowNibName:@"BookmarkInfoPanel"]; - - //custom field editor lets us undo our changes - mFieldEditor = [[NSTextView alloc] init]; - [mFieldEditor setAllowsUndo:YES]; - [mFieldEditor setFieldEditor:YES]; - - return self; -} - --(void)dealloc -{ - if (self == sharedBookmarkInfoController) - sharedBookmarkInfoController = nil; - - [mFieldEditor release]; - [super dealloc]; -} - --(void)controlTextDidEndEditing: (NSNotification*) aNotification -{ - [self commitChanges:[aNotification object]]; - [[mFieldEditor undoManager] removeAllActions]; -} --(void)windowDidBecomeKey:(NSNotification*) aNotification -{ - [[self window] makeFirstResponder:mNameField]; -} - --(void)windowDidResignKey:(NSNotification*) aNotification -{ - [[self window] makeFirstResponder:[self window]]; -} - -- (void)commitChanges:(id)changedField -{ - if (![mBookmarkItem contentNode]) - return; - - // Name - if (changedField == mNameField) - [self commitField:mNameField toProperty:BookmarksService::gNameAtom]; - - // Location - if (changedField == mLocationField) - [self commitField:mLocationField toProperty:BookmarksService::gHrefAtom]; - - // Keyword - if (changedField == mKeywordField) - [self commitField:mKeywordField toProperty:BookmarksService::gKeywordAtom]; - - // Description - if (changedField == mDescriptionField) - [self commitField:mDescriptionField toProperty:BookmarksService::gDescriptionAtom]; - - [[mFieldEditor undoManager] removeAllActions]; - BookmarksService::BookmarkChanged([mBookmarkItem contentNode], TRUE); -} - -- (void)commitField:(id)textField toProperty:(nsIAtom*)propertyAtom -{ - unsigned int len; - PRUnichar* buffer; - nsXPIDLString buf; - - // we really need a category on NSString for this - len = [[textField stringValue] length]; - buffer = new PRUnichar[len + 1]; - if (!buffer) return; - [[textField stringValue] getCharacters:buffer]; - buffer[len] = (PRUnichar)'\0'; - buf.Adopt(buffer); - [mBookmarkItem contentNode]->SetAttr(kNameSpaceID_None, propertyAtom, buf, PR_TRUE); -} - - --(void)setBookmark: (BookmarkItem*) aBookmark -{ - // See bug 154081 - don't show this window if Bookmark doesn't exist - // after fix - this should never happen unless disaster strikes. - if (![aBookmark contentNode]) - return; - - nsAutoString group; - [aBookmark contentNode]->GetAttr(kNameSpaceID_None, BookmarksService::gGroupAtom, group); - BOOL isGroup = !group.IsEmpty(); - BOOL isFolder = !isGroup && [aBookmark isFolder]; - - // First, Show/Hide the appropriate UI - if (isGroup) { - [self showUIElementPair: mNameLabel control: mNameField]; - [mNameField setNextKeyView:mKeywordField]; - [self hideUIElementPair: mLocationLabel control: mLocationField]; - [self showUIElementPair: mKeywordLabel control: mKeywordField]; - [self showUIElementPair: mDescriptionLabel control: mDescriptionField]; - } - else if (isFolder) { - [self showUIElementPair: mNameLabel control: mNameField]; - [mNameField setNextKeyView:mDescriptionField]; - [self hideUIElementPair: mLocationLabel control: mLocationField]; - [self hideUIElementPair: mKeywordLabel control: mKeywordField]; - [self showUIElementPair: mDescriptionLabel control: mDescriptionField]; - } - else { - [self showUIElementPair: mNameLabel control: mNameField]; - [mNameField setNextKeyView:mLocationField]; - [self showUIElementPair: mLocationLabel control: mLocationField]; - [self showUIElementPair: mKeywordLabel control: mKeywordField]; - [self showUIElementPair: mDescriptionLabel control: mDescriptionField]; - } - - // Then, fill with appropriate values from Bookmarks - nsAutoString value; - - [aBookmark contentNode]->GetAttr(kNameSpaceID_None, BookmarksService::gNameAtom, value); - NSString* bookmarkName = [NSString stringWith_nsAString: value]; - [mNameField setStringValue: bookmarkName]; - NSString* infoForString = [NSString stringWithFormat:NSLocalizedString(@"BookmarkInfoTitle",@"Info for "), bookmarkName]; - [[self window] setTitle: infoForString]; - - if (!isGroup && !isFolder) { - [aBookmark contentNode]->GetAttr(kNameSpaceID_None, BookmarksService::gHrefAtom, value); - [mLocationField setStringValue: [NSString stringWith_nsAString: value]]; - } - - if (!isFolder) { - [aBookmark contentNode]->GetAttr(kNameSpaceID_None, BookmarksService::gKeywordAtom, value); - [mKeywordField setStringValue: [NSString stringWith_nsAString: value]]; - } - - [aBookmark contentNode]->GetAttr(kNameSpaceID_None, BookmarksService::gDescriptionAtom, value); - [mDescriptionField setStringValue: [NSString stringWith_nsAString: value]]; - - mBookmarkItem = aBookmark; -} - --(void)showUIElementPair: (id)aLabel control:(id)aControl -{ - if ([aLabel superview] == nil) { - [[[self window] contentView] addSubview: aLabel]; - [aLabel autorelease]; - } - if ([aControl superview] == nil) { - [[[self window] contentView] addSubview: aControl]; - [aControl autorelease]; - } -} - --(void)hideUIElementPair: (id)aLabel control:(id)aControl -{ - if ([aLabel superview] != nil) { - [aLabel removeFromSuperview]; - [aLabel retain]; - } - if ([aControl superview] != nil) { - [aControl removeFromSuperview]; - [aControl retain]; - } -} - --(NSText *)windowWillReturnFieldEditor:(NSWindow *)aPanel toObject:(id)aObject -{ - return mFieldEditor; -} - --(void) close -{ - mBookmarkItem = nil; - [super close]; -} - - -@end diff --git a/mozilla/chimera/BookmarkInfoPanel.nib/classes.nib b/mozilla/chimera/BookmarkInfoPanel.nib/classes.nib deleted file mode 100644 index 7cb6777f984..00000000000 --- a/mozilla/chimera/BookmarkInfoPanel.nib/classes.nib +++ /dev/null @@ -1,22 +0,0 @@ -{ - IBClasses = ( - { - CLASS = BookmarkInfoController; - LANGUAGE = ObjC; - OUTLETS = { - mDescriptionField = NSTextField; - mDescriptionLabel = NSTextField; - mKeywordField = NSTextField; - mKeywordLabel = NSTextField; - mLocationField = NSTextField; - mLocationLabel = NSTextField; - mNameField = NSTextField; - mNameLabel = NSTextField; - }; - SUPERCLASS = NSWindowController; - }, - {CLASS = BookmarkItem; LANGUAGE = ObjC; SUPERCLASS = NSObject; }, - {CLASS = FirstResponder; LANGUAGE = ObjC; SUPERCLASS = NSObject; } - ); - IBVersion = 1; -} \ No newline at end of file diff --git a/mozilla/chimera/BookmarkInfoPanel.nib/info.nib b/mozilla/chimera/BookmarkInfoPanel.nib/info.nib deleted file mode 100644 index b8cd244ab7f..00000000000 --- a/mozilla/chimera/BookmarkInfoPanel.nib/info.nib +++ /dev/null @@ -1,12 +0,0 @@ - - - - - IBDocumentLocation - 144 74 366 258 0 0 1280 1002 - IBFramework Version - 248.0 - IBSystem Version - 5S66 - - diff --git a/mozilla/chimera/BookmarkInfoPanel.nib/objects.nib b/mozilla/chimera/BookmarkInfoPanel.nib/objects.nib deleted file mode 100644 index 5541b6caeaa..00000000000 Binary files a/mozilla/chimera/BookmarkInfoPanel.nib/objects.nib and /dev/null differ diff --git a/mozilla/chimera/BookmarksDataSource.h b/mozilla/chimera/BookmarksDataSource.h deleted file mode 100644 index 3b0c373041f..00000000000 --- a/mozilla/chimera/BookmarksDataSource.h +++ /dev/null @@ -1,123 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape 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/NPL/ - * - * 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 mozilla.org 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): - * Simon Fraser - * - * - * 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 NPL, 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 NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#import -#import - -#import "MainController.h" -#import "CHBookmarksToolbar.h" -#import "CHExtendedOutlineView.h" - -class nsIContent; -class BookmarksService; - -@class BookmarkInfoController; - -// data source for the bookmarks sidebar. We make one per browser window. -@interface BookmarksDataSource : NSObject -{ - BookmarksService* mBookmarks; - - IBOutlet id mOutlineView; - IBOutlet id mBrowserWindowController; - IBOutlet id mEditBookmarkButton; - IBOutlet id mDeleteBookmarkButton; - - NSString* mCachedHref; -} - --(id) init; --(void) windowClosing; - --(void) ensureBookmarks; - --(IBAction)addBookmark:(id)aSender; --(void)endAddBookmark: (int)aCode; - --(IBAction)deleteBookmarks: (id)aSender; --(void)deleteBookmark: (id)aItem; - --(IBAction)addFolder:(id)aSender; - --(void)addBookmark:(id)aSender useSelection:(BOOL)aSel isFolder:(BOOL)aIsFolder URL:(NSString*)aURL title:(NSString*)aTitle; - --(NSString*)resolveKeyword:(NSString*)aKeyword; - -- (IBAction)openBookmarkInNewTab:(id)aSender; -- (IBAction)openBookmarkInNewWindow:(id)aSender; - -- (void)openBookmarkGroup:(id)aTabView groupElement:(nsIDOMElement*)aFolder; -- (IBAction)showBookmarkInfo:(id)aSender; -- (BOOL)haveSelectedRow; - -// Datasource methods. -- (id)outlineView:(NSOutlineView *)outlineView child:(int)index ofItem:(id)item; -- (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item; -- (int)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item; -- (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item; -- (void)outlineView:(NSOutlineView *)outlineView setObjectValue:(id)object forTableColumn:(NSTableColumn *)tableColumn byItem:(id)item; - -- (BOOL)outlineView:(NSOutlineView *)ov writeItems:(NSArray*)items toPasteboard:(NSPasteboard*)pboard; -- (NSDragOperation)outlineView:(NSOutlineView*)ov validateDrop:(id )info proposedItem:(id)item proposedChildIndex:(int)index; -- (BOOL)outlineView:(NSOutlineView*)ov acceptDrop:(id )info item:(id)item childIndex:(int)index; - -- (void)reloadDataForItem:(id)item reloadChildren: (BOOL)aReloadChildren; - -// Delegate methods -- (void)outlineViewItemWillExpand:(NSNotification *)notification; -- (void)outlineViewItemWillCollapse:(NSNotification *)notification; - -@end - -@interface BookmarkItem : NSObject -{ - nsIContent* mContentNode; - NSImage* mSiteIcon; -} - -- (nsIContent*)contentNode; -- (void)setContentNode: (nsIContent*)aContentNode; -- (void)setSiteIcon:(NSImage*)image; -- (NSString*)url; -- (NSImage*)siteIcon; -- (NSNumber*)contentID; -- (id)copyWithZone:(NSZone *)aZone; -- (BOOL)isFolder; - -@end diff --git a/mozilla/chimera/BookmarksDataSource.mm b/mozilla/chimera/BookmarksDataSource.mm deleted file mode 100644 index 4bf75d761c8..00000000000 --- a/mozilla/chimera/BookmarksDataSource.mm +++ /dev/null @@ -1,928 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape 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/NPL/ - * - * 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 mozilla.org 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): - * Simon Fraser - * - * - * 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 NPL, 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 NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#import "NSString+Utils.h" - -#import "BookmarksDataSource.h" -#import "BookmarkInfoController.h" -#import "SiteIconProvider.h" - -#include "nsCOMPtr.h" -#include "nsIContent.h" -#include "nsIDocument.h" -#include "nsIDocumentObserver.h" -#include "nsIDOMDocument.h" -#include "nsIDOMElement.h" -#include "nsINamespaceManager.h" -#include "nsIPrefBranch.h" -#include "nsIServiceManager.h" - -#include "nsVoidArray.h" - -#import "BookmarksService.h" - -@implementation BookmarksDataSource - --(id) init -{ - if ( (self = [super init]) ) { - mBookmarks = nsnull; - mCachedHref = nil; - } - return self; -} - --(void) awakeFromNib -{ - // make sure these are disabled at the start since the outliner - // starts off with no selection. - [mEditBookmarkButton setEnabled:NO]; - [mDeleteBookmarkButton setEnabled:NO]; -} - --(void) windowClosing -{ - if (mBookmarks) { - mBookmarks->RemoveObserver(); - delete mBookmarks; - } -} - --(void) ensureBookmarks -{ - if (mBookmarks) - return; - - mBookmarks = new BookmarksService(self); - mBookmarks->AddObserver(); - - [mOutlineView setTarget: self]; - [mOutlineView setDoubleAction: @selector(openBookmark:)]; - [mOutlineView setDeleteAction: @selector(deleteBookmarks:)]; - [mOutlineView reloadData]; -} - --(IBAction)addBookmark:(id)aSender -{ - [self addBookmark: aSender useSelection: YES isFolder: NO URL:nil title:nil]; -} - --(IBAction)addFolder:(id)aSender -{ - [self addBookmark: aSender useSelection: YES isFolder: YES URL:nil title:nil]; -} - --(void)addBookmark:(id)aSender useSelection:(BOOL)aUseSel isFolder:(BOOL)aIsFolder URL:(NSString*)aURL title:(NSString*)aTitle -{ - if (!mBookmarks) - return; - - // We use the selected item to determine the parent only if aUseSel is YES. - BookmarkItem* item = nil; - if (aUseSel && ([mOutlineView numberOfSelectedRows] == 1)) { - // There is only one selected row. If it is a folder, use it as our parent. - // Otherwise, use our parent, - int index = [mOutlineView selectedRow]; - item = [mOutlineView itemAtRow: index]; - if (![mOutlineView isExpandable: item]) { - // We can't be used as the parent. Try our parent. - nsIContent* content = [item contentNode]; - if (!content) - return; - - nsCOMPtr parentContent; - content->GetParent(*getter_AddRefs(parentContent)); - nsCOMPtr root; - mBookmarks->GetRootContent(getter_AddRefs(root)); - - // The root has no item, so we don't need to do a lookup unless we - // aren't the root. - if (parentContent != root) { - PRUint32 contentID; - parentContent->GetContentID(&contentID); - item = [(BookmarksService::gDictionary) objectForKey: [NSNumber numberWithInt: contentID]]; - } - } - } - - nsCOMPtr domDoc(do_QueryInterface(mBookmarks->gBookmarks)); - - nsAutoString title, href; - if (!aIsFolder) { - - // If no URL and title were specified, get them from the current page. - if (aURL && aTitle) { - [aURL assignTo_nsAString:href]; - [aTitle assignTo_nsAString:title]; - } else { - BookmarksService::GetTitleAndHrefForBrowserView([[mBrowserWindowController getBrowserWrapper] getBrowserView], - title, href); - } - - mCachedHref = [NSString stringWith_nsAString: href]; - [mCachedHref retain]; - - } else { // Folder - mCachedHref = nil; - title = NS_LITERAL_STRING("New Folder"); // XXX localize me - } - - NSTextField* textField = [mBrowserWindowController getAddBookmarkTitle]; - NSString* bookmarkTitle = [NSString stringWith_nsAString: title]; - NSString* cleanedTitle = [bookmarkTitle stringByReplacingCharactersInSet:[NSCharacterSet controlCharacterSet] withString:@" "]; - - [textField setStringValue: cleanedTitle]; - - [mBrowserWindowController cacheBookmarkDS: self]; - - // Show/hide the bookmark all tabs checkbox as appropriate. - NSTabView* tabView = [mBrowserWindowController getTabBrowser]; - id checkbox = [mBrowserWindowController getAddBookmarkCheckbox]; - BOOL hasSuperview = [checkbox superview] != nil; - if (aIsFolder && hasSuperview) { - // Just don't show it at all. - [checkbox removeFromSuperview]; - [checkbox retain]; - } - else if (!aIsFolder && !hasSuperview) { - // Put it back in. - [[[mBrowserWindowController getAddBookmarkSheetWindow] contentView] addSubview: checkbox]; - [checkbox autorelease]; - } - - // Enable the bookmark all tabs checkbox if appropriate. - if (!aIsFolder) - [[mBrowserWindowController getAddBookmarkCheckbox] setEnabled: ([tabView numberOfTabViewItems] > 1)]; - - // Build up the folder list. - NSPopUpButton* popup = [mBrowserWindowController getAddBookmarkFolder]; - BookmarksService::ConstructAddBookmarkFolderList(popup, item); - - [NSApp beginSheet: [mBrowserWindowController getAddBookmarkSheetWindow] - modalForWindow: [mBrowserWindowController window] - modalDelegate: nil //self - didEndSelector: nil //@selector(sheetDidEnd:) - contextInfo: nil]; -} - --(void)endAddBookmark: (int)aCode -{ - if (aCode == 0) - return; - - BOOL isGroup = NO; - id checkbox = [mBrowserWindowController getAddBookmarkCheckbox]; - if (([checkbox superview] != nil) && [checkbox isEnabled] && ([checkbox state] == NSOnState)) { - mCachedHref = nil; - isGroup = YES; - } - - nsAutoString title; - [[[mBrowserWindowController getAddBookmarkTitle] stringValue] assignTo_nsAString:title]; - - nsAutoString tagName; - if (mCachedHref) - tagName = NS_LITERAL_STRING("bookmark"); - else - tagName = NS_LITERAL_STRING("folder"); - - nsCOMPtr domDoc(do_QueryInterface(mBookmarks->gBookmarks)); - nsCOMPtr elt; - domDoc->CreateElementNS(NS_LITERAL_STRING("http://chimera.mozdev.org/bookmarks/"), - tagName, - getter_AddRefs(elt)); - - elt->SetAttribute(NS_LITERAL_STRING("name"), title); - - if (mCachedHref) { - nsAutoString href; - [mCachedHref assignTo_nsAString:href]; - [mCachedHref release]; - elt->SetAttribute(NS_LITERAL_STRING("href"), href); - } - - if (isGroup) { - // We have to iterate over each tab and create content nodes using the - // title/href of all the pages. They are inserted underneath the parent. - elt->SetAttribute(NS_LITERAL_STRING("group"), NS_LITERAL_STRING("true")); - id tabBrowser = [mBrowserWindowController getTabBrowser]; - int count = [tabBrowser numberOfTabViewItems]; - for (int i = 0; i < count; i++) { - id browserView = [[[tabBrowser tabViewItemAtIndex: i] view] getBrowserView]; - nsAutoString title, href; - BookmarksService::GetTitleAndHrefForBrowserView(browserView, title, href); - nsCOMPtr childElt; - domDoc->CreateElementNS(NS_LITERAL_STRING("http://chimera.mozdev.org/bookmarks/"), - NS_LITERAL_STRING("bookmark"), - getter_AddRefs(childElt)); - childElt->SetAttribute(NS_LITERAL_STRING("name"), title); - childElt->SetAttribute(NS_LITERAL_STRING("href"), href); - nsCOMPtr dummy; - elt->AppendChild(childElt, getter_AddRefs(dummy)); - } - } - - // Figure out the parent element. - nsCOMPtr parentElt; - nsCOMPtr parentContent; - NSPopUpButton* popup = [mBrowserWindowController getAddBookmarkFolder]; - NSMenuItem* selectedItem = [popup selectedItem]; - int tag = [selectedItem tag]; - if (tag == -1) { - mBookmarks->GetRootContent(getter_AddRefs(parentContent)); - parentElt = do_QueryInterface(parentContent); - } - else { - BookmarkItem* item = [(BookmarksService::gDictionary) objectForKey: [NSNumber numberWithInt: tag]]; - // Get the content node. - parentContent = [item contentNode]; - parentElt = do_QueryInterface(parentContent); - } - - nsCOMPtr dummy; - parentElt->AppendChild(elt, getter_AddRefs(dummy)); - - nsCOMPtr childContent(do_QueryInterface(elt)); - mBookmarks->BookmarkAdded(parentContent, childContent); -} - --(IBAction)deleteBookmarks: (id)aSender -{ - if (!mBookmarks) - return; - - int index = [mOutlineView selectedRow]; - if (index == -1) - return; - - // first, see how many items are selected - BOOL haveBookmarks = NO; - - NSEnumerator* testSelRows = [mOutlineView selectedRowEnumerator]; - for (NSNumber* currIndex = [testSelRows nextObject]; - currIndex != nil; - currIndex = [testSelRows nextObject]) - { - index = [currIndex intValue]; - BookmarkItem* item = [mOutlineView itemAtRow: index]; - if ([mOutlineView isExpandable: item]) { - // dumb check to see if we're deleting an empty folder. Should really - // recurse down - if ([self outlineView:mOutlineView numberOfChildrenOfItem: item] > 0) - haveBookmarks = YES; - } else - haveBookmarks = YES; - } - - // ideally, we should count the number of doomed bookmarks and tell the user - if (haveBookmarks) { - NSString *alert = NSLocalizedString(@"DeteleBookmarksAlert",@""); - NSString *message = NSLocalizedString(@"DeteleBookmarksMsg",@""); - NSString *okButton = NSLocalizedString(@"DeteleBookmarksOKButton",@""); - NSString *cancelButton = NSLocalizedString(@"DeteleBookmarksCancelButton",@""); - if (NSRunAlertPanel(alert, message, okButton, cancelButton, nil) != NSAlertDefaultReturn) - return; - } - - // The alert panel was the key window. As soon as we dismissed it, Cocoa will - // pick a new one for us. Ideally, it'll be the window we were using when - // we clicked the delete button. However, if by chance the BookmarkInfoController - // is visible, it will become the key window since it's a panel. If we then delete - // the bookmark and try to close the window before we've setup a new bookmark, - // we'll trigger the windowDidResignKey message, which will try to update the bookmark - // we just deleted, and things will crash. So, we'll trigger windowDidResignKey now - // and avoid the unpleasentness of a crash log. - - if (![[mBrowserWindowController window] isKeyWindow]) - [[mBrowserWindowController window] makeKeyWindow]; - - // we'll run into problems if a parent item and one if its children are both selected. - // A cheap way of having to avoid scanning the list to remove children is to have the - // outliner collapse all items that are being deleted. This will cull the selection - // for us and eliminate any children that happened to be selected. - NSEnumerator* selRows = [mOutlineView selectedRowEnumerator]; - for (NSNumber* currIndex = [selRows nextObject]; - currIndex != nil; - currIndex = [selRows nextObject]) { - index = [currIndex intValue]; - BookmarkItem* item = [mOutlineView itemAtRow: index]; - [mOutlineView collapseItem: item]; - } - - // create array of items we need to delete. Deleting items out of of the - // selection array is problematic for some reason. - NSMutableArray* itemsToDelete = [[[NSMutableArray alloc] init] autorelease]; - selRows = [mOutlineView selectedRowEnumerator]; - for (NSNumber* currIndex = [selRows nextObject]; - currIndex != nil; - currIndex = [selRows nextObject]) { - index = [currIndex intValue]; - BookmarkItem* item = [mOutlineView itemAtRow: index]; - [itemsToDelete addObject: item]; - } - - // delete all bookmarks that are in our array - int count = [itemsToDelete count]; - for (int i = 0; i < count; i++) { - BookmarkItem* item = [itemsToDelete objectAtIndex: i]; - [self deleteBookmark: item]; - } - - // restore selection to location near last item deleted or last item - int total = [mOutlineView numberOfRows]; - if (index >= total) - index = total - 1; - [mOutlineView selectRow: index byExtendingSelection: NO]; - // lame, but makes sure we catch all delete events in Info Panel - [[NSNotificationCenter defaultCenter] postNotificationName:@"NSOutlineViewSelectionDidChangeNotification" object:mOutlineView]; - -} - --(void)deleteBookmark:(id)aItem -{ - nsCOMPtr content = [aItem contentNode]; - nsCOMPtr child(do_QueryInterface(content)); - if (!child) - return; - if (child == BookmarksService::gToolbarRoot) - return; // Don't allow the personal toolbar to be deleted. - - nsCOMPtr parent; - child->GetParentNode(getter_AddRefs(parent)); - nsCOMPtr parentContent(do_QueryInterface(parent)); - nsCOMPtr dummy; - if (parent) - parent->RemoveChild(child, getter_AddRefs(dummy)); - mBookmarks->BookmarkRemoved(parentContent, content); -} - --(IBAction)openBookmark: (id)aSender -{ - int index = [mOutlineView selectedRow]; - if (index == -1) - return; - - id item = [mOutlineView itemAtRow: index]; - if (!item) - return; - - nsIContent* content = [item contentNode]; - nsCOMPtr elt(do_QueryInterface(content)); - nsAutoString group; - content->GetAttr(kNameSpaceID_None, BookmarksService::gGroupAtom, group); - if (!group.IsEmpty()) - mBookmarks->OpenBookmarkGroup([mBrowserWindowController getTabBrowser], elt); - else if ([mOutlineView isExpandable: item]) { - if ([mOutlineView isItemExpanded: item]) - [mOutlineView collapseItem: item]; - else - [mOutlineView expandItem: item]; - } - else { - nsAutoString href; - content->GetAttr(kNameSpaceID_None, BookmarksService::gHrefAtom, href); - if (!href.IsEmpty()) { - NSString* url = [NSString stringWith_nsAString: href]; - [[mBrowserWindowController getBrowserWrapper] loadURI: url referrer:nil flags: NSLoadFlagsNone activate:YES]; - } - } -} - --(NSString*) resolveKeyword: (NSString*) aKeyword -{ - return BookmarksService::ResolveKeyword(aKeyword); -} - -#pragma mark - - -// -// outlineView:shouldEditTableColumn:item: (delegate method) -// -// Called by the outliner to determine whether or not we should allow the -// user to edit this item. For now, Cocoa doesn't correctly handle editing -// of attributed strings with icons, so we can't turn this on. :( -// -- (BOOL)outlineView:(NSOutlineView *)outlineView shouldEditTableColumn:(NSTableColumn *)tableColumn item:(id)item -{ - return NO; -} - -- (id)outlineView:(NSOutlineView *)outlineView child:(int)index ofItem:(id)item -{ - if (!mBookmarks) - return nil; - - nsCOMPtr content; - if (!item) - BookmarksService::GetRootContent(getter_AddRefs(content)); - else - content = [item contentNode]; - - nsCOMPtr child; - content->ChildAt(index, *getter_AddRefs(child)); - if ( child ) - return BookmarksService::GetWrapperFor(child); - - return nil; -} - -- (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item -{ - if (!mBookmarks) - return NO; - - if (!item) - return YES; // The root node is always open. - - BOOL isExpandable = [item isFolder]; - -// XXXben - persistence of folder open state -// I'm adding this code, turned off, until I can figure out how to refresh the NSOutlineView's -// row count. Currently the items are expanded, but the outline view continues to believe it had -// the number of rows it had before the item was opened visible, until the view is resized. -#if 0 - if (isExpandable) { - PRBool isOpen = content->HasAttr(kNameSpaceID_None, BookmarksService::gOpenAtom); - if (isOpen) - [mOutlineView expandItem: item]; - else - [mOutlineView collapseItem: item]; - } -#endif - - return isExpandable; -} - -- (int)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item -{ - if (!mBookmarks) - return 0; - - nsCOMPtr content; - if (!item) - mBookmarks->GetRootContent(getter_AddRefs(content)); - else - content = [item contentNode]; - - PRInt32 childCount; - content->ChildCount(childCount); - - return childCount; -} - -- (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item -{ - NSString *columnName = [tableColumn identifier]; - NSMutableAttributedString *cellValue = [[NSMutableAttributedString alloc] init]; - NSFileWrapper *fileWrapper = [[NSFileWrapper alloc] initRegularFileWithContents:nil]; - NSTextAttachment *textAttachment = [[NSTextAttachment alloc] initWithFileWrapper:fileWrapper]; - NSMutableAttributedString *attachmentAttrString = nil; - NSCell *attachmentAttrStringCell; - - if ([columnName isEqualToString: @"name"]) { - nsIContent* content = [item contentNode]; - nsAutoString nameAttr; - content->GetAttr(kNameSpaceID_None, BookmarksService::gNameAtom, nameAttr); - - //Set cell's textual contents - [cellValue replaceCharactersInRange:NSMakeRange(0, [cellValue length]) withString:[NSString stringWith_nsAString: nameAttr]]; - - //Create an attributed string to hold the empty attachment, then release the components. - attachmentAttrString = [[NSMutableAttributedString attributedStringWithAttachment:textAttachment] retain]; - [textAttachment release]; - [fileWrapper release]; - - //Get the cell of the text attachment. - attachmentAttrStringCell = (NSCell *)[(NSTextAttachment *)[attachmentAttrString attribute:NSAttachmentAttributeName atIndex:0 effectiveRange:nil] attachmentCell]; - - nsCOMPtr elt(do_QueryInterface(content)); - NSImage* bookmarkImage = mBookmarks->CreateIconForBookmark(elt); - [attachmentAttrStringCell setImage:bookmarkImage]; - - //Insert the image - [cellValue replaceCharactersInRange:NSMakeRange(0, 0) withAttributedString:attachmentAttrString]; - - //Tweak the baseline to vertically center the text. - [cellValue addAttribute:NSBaselineOffsetAttributeName - value:[NSNumber numberWithFloat:-3.0] - range:NSMakeRange(0, 1)]; - } - return cellValue; -} - -- (void)outlineView:(NSOutlineView *)outlineView setObjectValue:(id)object forTableColumn:(NSTableColumn *)tableColumn byItem:(id)item -{ -#if NOT_USED - // ignore all this. It doesn't work, but i'm leaving it here just in case we ever try to turn - // this code back on. We have to remove the attributes from the string in order to correctly - // set it in the DOM. - - NSString *columnName = [tableColumn identifier]; - if ( [columnName isEqualTo:@"name"] ) { - // remove the attributes - int strLen = [object length]; - NSMutableAttributedString *cellValue = [[NSMutableAttributedString alloc] initWithAttributedString:object]; - [cellValue removeAttribute:NSBaselineOffsetAttributeName range:NSMakeRange(0,1)]; - [cellValue removeAttribute:NSAttachmentAttributeName range:NSMakeRange(0,strLen)]; - - // extract the unicode - strLen = [cellValue length]; - PRUnichar* buffer = new PRUnichar[strLen + 1]; - buffer[strLen] = '\0'; - if ( !buffer ) - return; - [cellValue getCharacters: buffer]; - nsAutoString nameAttr; - nameAttr.Adopt(buffer); - - // stash it into the dom. - nsIContent* content = [item contentNode]; - content->SetAttr(kNameSpaceID_None, BookmarksService::gNameAtom, nameAttr, PR_TRUE); - - [cellValue release]; - } -#endif -} - - -- (BOOL)outlineView:(NSOutlineView *)ov writeItems:(NSArray*)items toPasteboard:(NSPasteboard*)pboard -{ - if (!mBookmarks) - return NO; - -#ifdef FILTER_DESCENDANT_ON_DRAG - NSArray *toDrag = BookmarksService::FilterOutDescendantsForDrag(items); -#else - NSArray *toDrag = items; -#endif - int count = [toDrag count]; - if (count > 0) { - // Create Pasteboard Data - NSMutableArray *draggedID = [NSMutableArray arrayWithCapacity: count]; - - for (int i = 0; i < count; i++) - [draggedID addObject: [[toDrag objectAtIndex: i] contentID]]; - - if (count == 1) { - // if we have just one item, we add some more flavours - [pboard declareTypes: [NSArray arrayWithObjects: - @"MozBookmarkType", NSURLPboardType, NSStringPboardType, nil] owner: self]; - [pboard setPropertyList: draggedID forType: @"MozBookmarkType"]; - - NSString* itemURL = [[toDrag objectAtIndex: 0] url]; - [pboard setString:itemURL forType: NSStringPboardType]; - [[NSURL URLWithString:itemURL] writeToPasteboard: pboard]; - // maybe construct the @"MozURLType" type here also - } - else { - // multiple bookmarks. Array sof strings or NSURLs seem to - // confuse receivers. Not sure what the correct way is. - [pboard declareTypes: [NSArray arrayWithObject: @"MozBookmarkType"] owner: self]; - [pboard setPropertyList: draggedID forType: @"MozBookmarkType"]; - } - - return YES; - } - - return NO; -} - - -- (NSDragOperation)outlineView:(NSOutlineView*)ov validateDrop:(id )info proposedItem:(id)item proposedChildIndex:(int)index -{ - NSArray* types = [[info draggingPasteboard] types]; - - // if the index is -1, deny the drop - if (index == NSOutlineViewDropOnItemIndex) - return NSDragOperationNone; - - if ([types containsObject: @"MozBookmarkType"]) { - NSArray *draggedIDs = [[info draggingPasteboard] propertyListForType: @"MozBookmarkType"]; - BookmarkItem* parent; - parent = (item) ? item : BookmarksService::GetRootItem(); - return (BookmarksService::IsBookmarkDropValid(parent, index, draggedIDs)) ? NSDragOperationGeneric : NSDragOperationNone; - } else if ([types containsObject: @"MozURLType"]) { - return NSDragOperationGeneric; - } else if ([types containsObject: NSStringPboardType]) { - return NSDragOperationGeneric; - } - - return NSDragOperationNone; -} - -- (BOOL)outlineView:(NSOutlineView*)ov acceptDrop:(id )info item:(id)item childIndex:(int)index -{ - NSArray *types = [[info draggingPasteboard] types]; - BookmarkItem* parent = (item) ? item : BookmarksService::GetRootItem(); - - if ([types containsObject: @"MozBookmarkType"]) - { - NSArray *draggedItems = [[info draggingPasteboard] propertyListForType: @"MozBookmarkType"]; - return BookmarksService::PerformBookmarkDrop(parent, index, draggedItems); - } - else if ([types containsObject: @"MozURLType"]) - { - NSDictionary* proxy = [[info draggingPasteboard] propertyListForType: @"MozURLType"]; - BookmarkItem* beforeItem = [self outlineView:ov child:index ofItem:item]; - return BookmarksService::PerformProxyDrop(parent, beforeItem, proxy); - } - else if ([types containsObject: NSStringPboardType]) - { - NSString* draggedText = [[info draggingPasteboard] stringForType:NSStringPboardType]; - BookmarkItem* beforeItem = [self outlineView:ov child:index ofItem:item]; - return BookmarksService::PerformURLDrop(parent, beforeItem, draggedText, draggedText); - } - - return NO; -} - -- (NSString *)outlineView:(NSOutlineView *)outlineView tooltipStringForItem:(id)item -{ - NSString* descStr = nil; - NSString* hrefStr = nil; - nsIContent* content = [item contentNode]; - nsAutoString value; - - content->GetAttr(kNameSpaceID_None, BookmarksService::gDescriptionAtom, value); - if (value.Length()) - descStr = [NSString stringWith_nsAString:value]; - - // Only description for folders - if ([item isFolder]) - return descStr; - - // Extract the URL from the item - content->GetAttr(kNameSpaceID_None, BookmarksService::gHrefAtom, value); - if (value.Length()) - hrefStr = [NSString stringWith_nsAString:value]; - - if (!hrefStr) - return descStr; - else if (!descStr) - return hrefStr; - - // Display both URL and description - return [NSString stringWithFormat:@"%@\n%@", hrefStr, descStr]; -} - -/* -- (NSMenu *)outlineView:(NSOutlineView *)outlineView contextMenuForItem:(id)item -{ - // TODO - return (custom?) context menu for item here. - // Note that according to HIG, there should never be disabled items in - // a context menu - instead, items that do not apply should be removed. - // We could nicely do that here. -} -*/ - -- (void)reloadDataForItem:(id)item reloadChildren: (BOOL)aReloadChildren -{ - if (!item) - [mOutlineView reloadData]; - else - [mOutlineView reloadItem: item reloadChildren: aReloadChildren]; -} - --(IBAction)openBookmarkInNewTab:(id)aSender -{ - int index = [mOutlineView selectedRow]; - if (index == -1) - return; - if ([mOutlineView numberOfSelectedRows] == 1) { - nsCOMPtr pref(do_GetService("@mozilla.org/preferences-service;1")); - if (!pref) - return; // Something bad happened if we can't get prefs. - - BookmarkItem* item = [mOutlineView itemAtRow: index]; - nsAutoString hrefAttr; - [item contentNode]->GetAttr(kNameSpaceID_None, BookmarksService::gHrefAtom, hrefAttr); - - // stuff it into the string - NSString* hrefStr = [NSString stringWith_nsAString:hrefAttr]; - - PRBool loadInBackground; - pref->GetBoolPref("browser.tabs.loadInBackground", &loadInBackground); - - [mBrowserWindowController openNewTabWithURL: hrefStr referrer:nil loadInBackground: loadInBackground]; - } -} - --(IBAction)openBookmarkInNewWindow:(id)aSender -{ - int index = [mOutlineView selectedRow]; - if (index == -1) - return; - if ([mOutlineView numberOfSelectedRows] == 1) { - nsCOMPtr pref(do_GetService("@mozilla.org/preferences-service;1")); - if (!pref) - return; // Something bad happened if we can't get prefs. - - BookmarkItem* item = [mOutlineView itemAtRow: index]; - nsAutoString hrefAttr; - [item contentNode]->GetAttr(kNameSpaceID_None, BookmarksService::gHrefAtom, hrefAttr); - - // stuff it into the string - NSString* hrefStr = [NSString stringWith_nsAString:hrefAttr]; - - PRBool loadInBackground; - pref->GetBoolPref("browser.tabs.loadInBackground", &loadInBackground); - - nsAutoString group; - [item contentNode]->GetAttr(kNameSpaceID_None, BookmarksService::gGroupAtom, group); - if (group.IsEmpty()) - [mBrowserWindowController openNewWindowWithURL: hrefStr referrer: nil loadInBackground: loadInBackground]; - else { - nsCOMPtr elt(do_QueryInterface([item contentNode])); - [mBrowserWindowController openNewWindowWithGroup: elt loadInBackground: loadInBackground]; - } - } -} - --(void)openBookmarkGroup:(id)aTabView groupElement:(nsIDOMElement*)aFolder -{ - mBookmarks->OpenBookmarkGroup(aTabView, aFolder); -} - --(IBAction)showBookmarkInfo:(id)aSender -{ - BookmarkInfoController *bic = [BookmarkInfoController sharedBookmarkInfoController]; - - int index = [mOutlineView selectedRow]; - BookmarkItem* item = [mOutlineView itemAtRow: index]; - [bic setBookmark:item]; - - [bic showWindow:bic]; -} - -- (BOOL)haveSelectedRow -{ - return ([mOutlineView selectedRow] != -1); -} - --(void)outlineViewSelectionDidChange: (NSNotification*) aNotification -{ - BookmarkInfoController *bic = [BookmarkInfoController sharedBookmarkInfoController]; - int index = [mOutlineView selectedRow]; - if (index == -1) { - [mEditBookmarkButton setEnabled:NO]; - [mDeleteBookmarkButton setEnabled:NO]; - [bic close]; - } - else { - [mEditBookmarkButton setEnabled:YES]; - [mDeleteBookmarkButton setEnabled:YES]; - if ([[bic window] isVisible]) - [bic setBookmark:[mOutlineView itemAtRow:index]]; - } -} - --(BOOL)validateMenuItem:(NSMenuItem*)aMenuItem -{ - int index = [mOutlineView selectedRow]; - if (index == -1) - return NO; - - BookmarkItem* item = [mOutlineView itemAtRow: index]; - BOOL isBookmark = [mOutlineView isExpandable:item] == NO; - - nsAutoString group; - [item contentNode]->GetAttr(kNameSpaceID_None, BookmarksService::gGroupAtom, group); - BOOL isGroup = !group.IsEmpty(); - - if (([aMenuItem action] == @selector(openBookmarkInNewWindow:))) { - // Bookmarks and Bookmark Groups can be opened in a new window - return (isBookmark || isGroup); - } - else if (([aMenuItem action] == @selector(openBookmarkInNewTab:))) { - // Only Bookmarks can be opened in new tabs - return isBookmark && [mBrowserWindowController newTabsAllowed]; - } - return YES; -} - -- (void)outlineViewItemWillExpand:(NSNotification *)notification -{ - BookmarkItem* item = [[notification userInfo] objectForKey:[[[notification userInfo] allKeys] objectAtIndex: 0]]; - [item contentNode]->SetAttr(kNameSpaceID_None, BookmarksService::gOpenAtom, NS_LITERAL_STRING("true"), PR_FALSE); -} - -- (void)outlineViewItemWillCollapse:(NSNotification *)notification -{ - BookmarkItem* item = [[notification userInfo] objectForKey:[[[notification userInfo] allKeys] objectAtIndex: 0]]; - [item contentNode]->UnsetAttr(kNameSpaceID_None, BookmarksService::gOpenAtom, PR_FALSE); -} - -@end - -#pragma mark - - -@implementation BookmarkItem - --(void)dealloc -{ - [mSiteIcon release]; - [super dealloc]; -} - --(nsIContent*)contentNode -{ - return mContentNode; -} - -- (NSNumber*)contentID -{ - PRUint32 contentID = 0; - mContentNode->GetContentID(&contentID); - return [NSNumber numberWithInt: contentID]; -} - -- (NSString *)description -{ - nsCOMPtr item = [self contentNode]; - nsCOMPtr element(do_QueryInterface(item)); - nsAutoString href; - element->GetAttribute(NS_LITERAL_STRING("name"), href); - NSString* info = [NSString stringWith_nsAString: href]; - return [NSString stringWithFormat:@"", info]; -} - -- (NSString *)url -{ - nsCOMPtr item = [self contentNode]; - nsCOMPtr element(do_QueryInterface(item)); - nsAutoString href; - element->GetAttribute(NS_LITERAL_STRING("href"), href); - return [NSString stringWith_nsAString: href]; -} - -- (void)setSiteIcon:(NSImage*)image -{ - //NSLog(@"Setting site icon for %@", [self url]); - [mSiteIcon autorelease]; - mSiteIcon = [image retain]; -} - -- (NSImage*)siteIcon -{ - return mSiteIcon; -} - --(void)setContentNode: (nsIContent*)aContentNode -{ - mContentNode = aContentNode; -} - -- (id)copyWithZone:(NSZone *)aZone -{ - BookmarkItem* copy = [[[self class] allocWithZone: aZone] init]; - [copy setContentNode: mContentNode]; - [copy setSiteIcon: mSiteIcon]; - return copy; -} - -- (BOOL)isFolder -{ - nsCOMPtr tagName; - mContentNode->GetTag(*getter_AddRefs(tagName)); - - return (tagName == BookmarksService::gFolderAtom); -} - -@end - diff --git a/mozilla/chimera/BookmarksService.h b/mozilla/chimera/BookmarksService.h deleted file mode 100644 index 411935e2517..00000000000 --- a/mozilla/chimera/BookmarksService.h +++ /dev/null @@ -1,164 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape 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/NPL/ - * - * 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 mozilla.org 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 NPL, 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 NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include -#include - -#include "nsCOMPtr.h" -#include "nsIDocument.h" -#include "nsIDocumentObserver.h" -#include "nsVoidArray.h" - -#import "MainController.h" -#import "CHBookmarksToolbar.h" -#import "CHExtendedOutlineView.h" - -class nsIAtom; -class nsIDOMHTMLDocument; - -@class BookmarksDataSource; -@class BookmarkItem; - -// despite appearances, BookmarksService is not a singleton. We make one for the bookmarks menu, -// one each per BookmarksDataSource, and one per bookmarks toolbar. It relies on a bunch of global -// variables, which is evil. -class BookmarksService -{ -public: - BookmarksService(BookmarksDataSource* aDataSource); - BookmarksService(CHBookmarksToolbar* aToolbar); - virtual ~BookmarksService(); - - void AddObserver(); - void RemoveObserver(); - -public: - static void BookmarkAdded(nsIContent* aContainer, nsIContent* aChild, bool shouldFlush = true); - static void BookmarkChanged(nsIContent* aItem, bool shouldFlush = true); - static void BookmarkRemoved(nsIContent* aContainer, nsIContent* aChild, bool shouldFlush = true); - - static void AddBookmarkToFolder(nsString& aURL, nsString& aTitle, nsIDOMElement* aFolder, nsIDOMElement* aBeforeElt); - static void MoveBookmarkToFolder(nsIDOMElement* aBookmark, nsIDOMElement* aFolder, nsIDOMElement* aBeforeElt); - static void DeleteBookmark(nsIDOMElement* aBookmark); - - static void GetRootContent(nsIContent** aResult); - static BookmarkItem* GetRootItem(); - static BookmarkItem* GetWrapperFor(nsIContent* aItem); - static BookmarkItem* GetWrapperFor(PRUint32 contentID); - - static void ReadBookmarks(); - static void FlushBookmarks(); - - static void ConstructBookmarksMenu(NSMenu* aMenu, nsIContent* aContent); - static void OpenMenuBookmark(BrowserWindowController* aController, id aMenuItem); - static void AddMenuBookmark(NSMenu* aMenu, nsIContent* aParent, nsIContent* aChild, PRInt32 aIndex); - static NSMenu* LocateMenu(nsIContent* aContent); - - static void ConstructAddBookmarkFolderList(NSPopUpButton* aPopup, BookmarkItem* aItem); - - static NSImage* CreateIconForBookmark(nsIDOMElement* aElement); - - static void EnsureToolbarRoot(); - - static void ImportBookmarks(nsIDOMHTMLDocument* aHTMLDoc); - - static void GetTitleAndHrefForBrowserView(id aBrowserView, nsString& aTitle, nsString& aHref); - static void OpenBookmarkGroup(id aTabView, nsIDOMElement* aFolder); - - static NSString* ResolveKeyword(NSString* aKeyword); - - static BOOL DoAncestorsIncludeNode(BookmarkItem* bookmark, BookmarkItem* searchItem); - static bool IsBookmarkDropValid(BookmarkItem* proposedParent, int index, NSArray* draggedIDs); - static bool PerformBookmarkDrop(BookmarkItem* parent, int index, NSArray* draggedIDs); - static bool PerformProxyDrop(BookmarkItem* parentItem, BookmarkItem* beforeItem, NSDictionary* data); - - static bool PerformURLDrop(BookmarkItem* parentItem, BookmarkItem* beforeItem, NSString* title, NSString* url); - -public: - // Global counter and pointers to our singletons. - static PRUint32 gRefCnt; - - // A dictionary that maps from content IDs (which uniquely identify content nodes) - // to Obj-C bookmarkItem objects. These objects are handed back to UI elements like - // the outline view. - static NSMutableDictionary* gDictionary; - static MainController* gMainController; - static NSMenu* gBookmarksMenu; - static nsIDOMElement* gToolbarRoot; - static nsIAtom* gFolderAtom; - static nsIAtom* gNameAtom; - static nsIAtom* gHrefAtom; - static nsIAtom* gKeywordAtom; - static nsIAtom* gDescriptionAtom; - static nsIAtom* gBookmarkAtom; - static nsIAtom* gOpenAtom; - static nsIAtom* gGroupAtom; - static nsIDocument* gBookmarks; - static BOOL gBookmarksFileReadOK; - static nsVoidArray* gInstances; - static int CHInsertNone; - static int CHInsertInto; - static int CHInsertBefore; - static int CHInsertAfter; - -private: - // There are three kinds of bookmarks data sources: - // tree views (mDataSource), the personal toolbar (mToolbar) - // and menus (gBookmarksMenu). - CHBookmarksToolbar* mToolbar; - BookmarksDataSource* mDataSource; -}; - - - -// singleton bookmarks manager object - -@interface BookmarksManager : NSObject -{ - - - -} - -+ (BookmarksManager*)sharedBookmarksManager; - -- (void)loadProxyImageFor:(id)requestor withURI:(NSString*)inURIString; - - -@end - - diff --git a/mozilla/chimera/BookmarksService.mm b/mozilla/chimera/BookmarksService.mm deleted file mode 100644 index 2f3b7c8d57a..00000000000 --- a/mozilla/chimera/BookmarksService.mm +++ /dev/null @@ -1,1434 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape 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/NPL/ - * - * 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 mozilla.org 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 NPL, 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 NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#import "NSString+Utils.h" - -#import "CHPreferenceManager.h" -#import "CHBrowserView.h" -#import "BookmarksService.h" -#import "BookmarksDataSource.h" -#import "BookmarkInfoController.h" -#import "BrowserTabView.h" -#import "SiteIconProvider.h" - -#include "nsCRT.h" -#include "nsString.h" -#include "nsIDocument.h" -#include "nsIContent.h" -#include "nsIAtom.h" -#include "nsITextContent.h" -#include "nsIDOMWindow.h" -#include "nsIDOMHTMLDocument.h" -#include "nsIDOMElement.h" -#include "nsIDOMCharacterData.h" -#include "nsIDOMParser.h" -#include "nsIDOMDocumentFragment.h" -#include "nsIPrefBranch.h" -#include "nsIFile.h" -#include "nsAppDirectoryServiceDefs.h" -#include "nsIXMLHttpRequest.h" -#include "nsIDOMSerializer.h" -#include "nsIDocumentEncoder.h" -#include "nsNetUtil.h" -#include "nsINamespaceManager.h" -#include "nsIXBLService.h" -#include "nsIWebBrowser.h" - - -// Helper for stripping whitespace -static void -StripWhitespaceNodes(nsIContent* aElement) -{ - PRInt32 childCount = 0; - aElement->ChildCount(childCount); - for (PRInt32 i = 0; i < childCount; i++) { - nsCOMPtr child; - aElement->ChildAt(i, *getter_AddRefs(child)); - nsCOMPtr text = do_QueryInterface(child); - if (text) { - PRBool isEmpty = PR_FALSE; - text->IsOnlyWhitespace(&isEmpty); - if (isEmpty) { - // This node contained nothing but whitespace. - // Remove it from the content model. - aElement->RemoveChildAt(i, PR_TRUE); - i--; // Decrement our count, since we just removed this child. - childCount--; // Also decrement our total count. - } - } - else - StripWhitespaceNodes(child); - } -} - -// the tag of the separator after which to insert bookmarks menu items -// this tag must not conflict with content IDs (which are all >=0) -// and match the tab in the .nib -static const int kBookmarksDividerTag = -1; - - -PRUint32 BookmarksService::gRefCnt = 0; -nsIDocument* BookmarksService::gBookmarks = nsnull; -NSMutableDictionary* BookmarksService::gDictionary = nil; -MainController* BookmarksService::gMainController = nil; -NSMenu* BookmarksService::gBookmarksMenu = nil; -nsIDOMElement* BookmarksService::gToolbarRoot = nsnull; - -nsIAtom* BookmarksService::gBookmarkAtom = nsnull; -nsIAtom* BookmarksService::gDescriptionAtom = nsnull; -nsIAtom* BookmarksService::gFolderAtom = nsnull; -nsIAtom* BookmarksService::gGroupAtom = nsnull; -nsIAtom* BookmarksService::gHrefAtom = nsnull; -nsIAtom* BookmarksService::gKeywordAtom = nsnull; -nsIAtom* BookmarksService::gNameAtom = nsnull; -nsIAtom* BookmarksService::gOpenAtom = nsnull; - -nsVoidArray* BookmarksService::gInstances = nsnull; - -BOOL BookmarksService::gBookmarksFileReadOK = NO; - -int BookmarksService::CHInsertNone = 0; -int BookmarksService::CHInsertInto = 1; -int BookmarksService::CHInsertBefore = 2; -int BookmarksService::CHInsertAfter = 3; - -BookmarksService::BookmarksService(BookmarksDataSource* aDataSource) -{ - mDataSource = aDataSource; - mToolbar = nil; -} - -BookmarksService::BookmarksService(CHBookmarksToolbar* aToolbar) -{ - mDataSource = nil; - mToolbar = aToolbar; -} - -BookmarksService::~BookmarksService() -{ -} - -void -BookmarksService::AddObserver() -{ - gRefCnt++; - if (gRefCnt == 1) { - gBookmarkAtom = NS_NewAtom("bookmark"); - gFolderAtom = NS_NewAtom("folder"); - gNameAtom = NS_NewAtom("name"); - gHrefAtom = NS_NewAtom("href"); - gOpenAtom = NS_NewAtom("open"); - gKeywordAtom = NS_NewAtom("id"); - gDescriptionAtom = NS_NewAtom("description"); - gGroupAtom = NS_NewAtom("group"); - gInstances = new nsVoidArray(); - - ReadBookmarks(); - } - - gInstances->AppendElement(this); -} - -void -BookmarksService::RemoveObserver() -{ - if (gRefCnt == 0) - return; - - gInstances->RemoveElement(this); - - gRefCnt--; - if (gRefCnt == 0) { - // Flush Bookmarks before shutting down as some changes are not flushed when - // they are performed (folder open/closed) as writing a whole bookmark file for - // that type of operation seems excessive. - FlushBookmarks(); - - NS_IF_RELEASE(gBookmarks); - NS_RELEASE(gBookmarkAtom); - NS_RELEASE(gFolderAtom); - NS_RELEASE(gNameAtom); - NS_RELEASE(gHrefAtom); - NS_RELEASE(gOpenAtom); - [gDictionary release]; - } -} - -#pragma mark - - -void -BookmarksService::GetRootContent(nsIContent** aResult) -{ - *aResult = nsnull; - if (gBookmarks) { - nsCOMPtr domDoc(do_QueryInterface(gBookmarks)); - if (!domDoc) return; - - nsCOMPtr elt; - domDoc->GetDocumentElement(getter_AddRefs(elt)); - if (elt) - elt->QueryInterface(NS_GET_IID(nsIContent), (void**)aResult); // Addref happens here. - } -} - -BookmarkItem* -BookmarksService::GetRootItem() -{ - nsCOMPtr rootContent; - BookmarksService::GetRootContent(getter_AddRefs(rootContent)); - BookmarkItem* rootItem = BookmarksService::GetWrapperFor(rootContent); - return rootItem; -} - -BookmarkItem* -BookmarksService::GetWrapperFor(nsIContent* aContent) -{ - if ( !aContent ) - return nil; - - if (!gDictionary) - gDictionary = [[NSMutableDictionary alloc] initWithCapacity: 30]; - - PRUint32 contentID = 0; - aContent->GetContentID(&contentID); - - BookmarkItem* item = [gDictionary objectForKey: [NSNumber numberWithInt: contentID]]; - if (item) - return item; - - // Create an item. - item = [[BookmarkItem alloc] init]; // The dictionary retains us. - [item setContentNode: aContent]; - [gDictionary setObject: item forKey: [NSNumber numberWithInt: contentID]]; - [item release]; - return item; -} - -BookmarkItem* -BookmarksService::GetWrapperFor(PRUint32 contentID) -{ - BookmarkItem* item = [gDictionary objectForKey: [NSNumber numberWithUnsignedInt: contentID]]; - return item; -} - -NSMenu* -BookmarksService::LocateMenu(nsIContent* aContent) -{ - nsCOMPtr parent; - aContent->GetParent(*getter_AddRefs(parent)); - if (!parent) { - return BookmarksService::gBookmarksMenu; - } - - NSMenu* parentMenu = LocateMenu(parent); - - PRUint32 contentID; - aContent->GetContentID(&contentID); - - NSMenuItem* childMenu = [parentMenu itemWithTag: contentID]; - return [childMenu submenu]; -} - -void -BookmarksService::BookmarkAdded(nsIContent* aContainer, nsIContent* aChild, bool shouldFlush) -{ - if (!gInstances || !gDictionary) - return; - - PRInt32 count = gInstances->Count(); - for (PRInt32 i = 0; i < count; i++) { - BookmarksService* instance = (BookmarksService*)gInstances->ElementAt(i); - - if (instance->mDataSource) { - // We're a tree view. - nsCOMPtr parent; - aContainer->GetParent(*getter_AddRefs(parent)); - - BookmarkItem* item = nil; - if (parent) - // We're not the root. - item = GetWrapperFor(aContainer); - - [(instance->mDataSource) reloadDataForItem: item reloadChildren: YES]; - } - else if (instance->mToolbar) { - // We're a personal toolbar. - nsCOMPtr parentElt(do_QueryInterface(aContainer)); - if (parentElt == gToolbarRoot) { - // We only care about changes that occur to the personal toolbar's immediate - // children. - PRInt32 index = -1; - aContainer->IndexOf(aChild, index); - nsCOMPtr elt(do_QueryInterface(aChild)); - [(instance->mToolbar) addButton: elt atIndex: index]; - } - } - else { - // We're the menu. - PRInt32 index = -1; - aContainer->IndexOf(aChild, index); - NSMenu* menu = LocateMenu(aContainer); - AddMenuBookmark(menu, aContainer, aChild, index); - } - } - - if (shouldFlush) - FlushBookmarks(); -} - -void -BookmarksService::BookmarkChanged(nsIContent* aItem, bool shouldFlush) -{ - if (!gInstances || !gDictionary) - return; - - PRInt32 count = gInstances->Count(); - for (PRInt32 i = 0; i < count; i++) { - BookmarksService* instance = (BookmarksService*)gInstances->ElementAt(i); - - if (instance->mDataSource) { - // We're a tree view - BookmarkItem* item = GetWrapperFor(aItem); - [(instance->mDataSource) reloadDataForItem: item reloadChildren: NO]; - } - else if (instance->mToolbar) { - // We're a personal toolbar. It'll figure out what to do. - nsCOMPtr elt(do_QueryInterface(aItem)); - [(instance->mToolbar) editButton: elt]; - } - else { - // We're the menu. Reset the title, in case it's changed. - nsCOMPtr parent; - aItem->GetParent(*getter_AddRefs(parent)); - NSMenu* menu = LocateMenu(parent); - PRUint32 contentID = 0; - aItem->GetContentID(&contentID); - NSMenuItem* childItem = [menu itemWithTag: contentID]; - nsAutoString name; - aItem->GetAttr(kNameSpaceID_None, gNameAtom, name); - NSString* bookmarkTitle = [[NSString stringWith_nsAString: name] stringByTruncatingTo:80 at:kTruncateAtMiddle]; - [childItem setTitle: bookmarkTitle]; - - // and reset the image - BookmarkItem* item = GetWrapperFor(aItem); - [childItem setImage: [item siteIcon]]; - } - - } - - if (shouldFlush) - FlushBookmarks(); -} - -void -BookmarksService::BookmarkRemoved(nsIContent* aContainer, nsIContent* aChild, bool shouldFlush) -{ - if (!gInstances) - return; - - PRInt32 count = gInstances->Count(); - for (PRInt32 i = 0; i < count; i++) { - BookmarksService* instance = (BookmarksService*)gInstances->ElementAt(i); - - if (instance->mDataSource) { - // We're a tree view. - nsCOMPtr parent; - aContainer->GetParent(*getter_AddRefs(parent)); - - BookmarkItem* item = nil; - if (parent) - // We're not the root. - item = GetWrapperFor(aContainer); - - [(instance->mDataSource) reloadDataForItem: item reloadChildren: YES]; - } - else if (instance->mToolbar) { - // We're a personal toolbar. - nsCOMPtr parentElt(do_QueryInterface(aContainer)); - if (parentElt == gToolbarRoot) { - // We only care about changes that occur to the personal toolbar's immediate - // children. - nsCOMPtr childElt(do_QueryInterface(aChild)); - [(instance->mToolbar) removeButton: childElt]; - } - } - else { - // We're the menu. - NSMenu* menu = LocateMenu(aContainer); - PRUint32 contentID = 0; - aChild->GetContentID(&contentID); - NSMenuItem* childItem = [menu itemWithTag: contentID]; - [menu removeItem: childItem]; - } - } - - if (shouldFlush) - FlushBookmarks(); -} - - -void -BookmarksService::AddBookmarkToFolder(nsString& aURL, nsString& aTitle, nsIDOMElement* aFolder, nsIDOMElement* aBeforeElt) -{ - // XXX if no folder provided, default to root folder - if (!aFolder) return; - - nsCOMPtr domDoc(do_QueryInterface(gBookmarks)); - nsCOMPtr elt; - domDoc->CreateElementNS(NS_LITERAL_STRING("http://chimera.mozdev.org/bookmarks/"), - NS_LITERAL_STRING("bookmark"), - getter_AddRefs(elt)); - - elt->SetAttribute(NS_LITERAL_STRING("name"), aTitle); - elt->SetAttribute(NS_LITERAL_STRING("href"), aURL); - - MoveBookmarkToFolder(elt, aFolder, aBeforeElt); -} - -void -BookmarksService::MoveBookmarkToFolder(nsIDOMElement* aBookmark, nsIDOMElement* aFolder, nsIDOMElement* aBeforeElt) -{ - if (!aBookmark || !aFolder) return; - - nsCOMPtr oldParent; - aBookmark->GetParentNode(getter_AddRefs(oldParent)); - - nsCOMPtr dummy; - if (oldParent) { - nsCOMPtr bookmarkNode = do_QueryInterface(aBookmark); - oldParent->RemoveChild(bookmarkNode, getter_AddRefs(dummy)); - } - - if (aBeforeElt) { - aFolder->InsertBefore(aBookmark, aBeforeElt, getter_AddRefs(dummy)); - } else { - aFolder->AppendChild(aBookmark, getter_AddRefs(dummy)); - } - - nsCOMPtr childContent(do_QueryInterface(aBookmark)); - nsCOMPtr parentContent(do_QueryInterface(aFolder)); - - if (oldParent) { - nsCOMPtr oldParentContent(do_QueryInterface(oldParent)); - BookmarkRemoved(oldParentContent, childContent); - } - - BookmarkAdded(parentContent, childContent); -} - -void -BookmarksService::DeleteBookmark(nsIDOMElement* aBookmark) -{ - if (!aBookmark || aBookmark == gToolbarRoot) return; - - nsCOMPtr oldParent; - aBookmark->GetParentNode(getter_AddRefs(oldParent)); - - if (oldParent) { - nsCOMPtr dummy; - nsCOMPtr bookmarkNode = do_QueryInterface(aBookmark); - oldParent->RemoveChild(bookmarkNode, getter_AddRefs(dummy)); - - nsCOMPtr childContent(do_QueryInterface(aBookmark)); - nsCOMPtr oldParentContent(do_QueryInterface(oldParent)); - BookmarkRemoved(oldParentContent, childContent); - } -} - -static PRBool -CheckXMLDocumentParseSuccessful(nsIDOMDocument* inDOMDoc) -{ - nsCOMPtr docElement; - inDOMDoc->GetDocumentElement(getter_AddRefs(docElement)); - if (!docElement) - return PR_FALSE; - - nsCOMPtr tagName; - nsCOMPtr docContent = do_QueryInterface(docElement); - docContent->GetTag(*getter_AddRefs(tagName)); - - nsCOMPtr parserErrorAtom = do_GetAtom("parsererror"); - if (parserErrorAtom != tagName) - return PR_TRUE; - - return PR_FALSE; -} - -static PRBool -ValidateXMLDocument(nsIDOMDocument* inDOMDoc) -{ - if (!inDOMDoc) - return PR_FALSE; - - nsCOMPtr elt; - inDOMDoc->GetDocumentElement(getter_AddRefs(elt)); - if (!elt) - return PR_FALSE; - - nsCOMPtr domSerializer = do_CreateInstance(NS_XMLSERIALIZER_CONTRACTID); - if (!domSerializer) - return PR_FALSE; - - nsXPIDLString encodedDocStr; - nsresult rv = domSerializer->SerializeToString(inDOMDoc, getter_Copies(encodedDocStr)); - if (NS_FAILED(rv)) - return PR_FALSE; - - nsCOMPtr domParser = do_CreateInstance(NS_DOMPARSER_CONTRACTID); - if (!domParser) - return PR_FALSE; - - nsCOMPtr newDomDoc; - domParser->ParseFromString(encodedDocStr.get(), "text/xml", getter_AddRefs(newDomDoc)); - if (newDomDoc) - return CheckXMLDocumentParseSuccessful(newDomDoc); - - return PR_FALSE; -} - -void -BookmarksService::ReadBookmarks() -{ - nsCOMPtr profileDirBookmarks; - NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR, getter_AddRefs(profileDirBookmarks)); - profileDirBookmarks->Append(NS_LITERAL_STRING("bookmarks.xml")); - - PRBool fileExists = PR_FALSE; - profileDirBookmarks->Exists(&fileExists); - - // If the bookmarks file does not exist, copy from the defaults so we don't - // crash or anything dumb like that. - if (!fileExists) { - nsCOMPtr defaultBookmarksFile; - NS_GetSpecialDirectory(NS_APP_PROFILE_DEFAULTS_50_DIR, getter_AddRefs(defaultBookmarksFile)); - defaultBookmarksFile->Append(NS_LITERAL_STRING("bookmarks.xml")); - - // XXX for some reason unknown to me, leaving this code in causes the program to crash - // with 'cannot dereference null COMPtr.' -#if I_WANT_TO_CRASH - PRBool defaultFileExists; - defaultBookmarksFile->Exists(&defaultFileExists); - if (defaultFileExists) - return; -#endif - - nsCOMPtr profileDirectory; - NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR, getter_AddRefs(profileDirectory)); - - defaultBookmarksFile->CopyToNative(profileDirectory, NS_LITERAL_CSTRING("bookmarks.xml")); - } - - nsCAutoString bookmarksFileURL; - NS_GetURLSpecFromFile(profileDirBookmarks, bookmarksFileURL); - - nsCOMPtr uri; - NS_NewURI(getter_AddRefs(uri), bookmarksFileURL.get()); - - // XXX this is somewhat lame. we have no way of knowing whether or not the parse succeeded - // or failed. sigh. - // Actually, we do. We check for a root node. This relies on the XMLContentSink - // behaviour. - nsCOMPtr xblService(do_GetService("@mozilla.org/xbl;1")); - xblService->FetchSyncXMLDocument(uri, &gBookmarks); // addref here - - // test for a parser error. The XML parser replaces the document with one - // that has a node as the root. - nsCOMPtr bookmarksDOMDoc = do_QueryInterface(gBookmarks); - BOOL validPrefsFile = CheckXMLDocumentParseSuccessful(bookmarksDOMDoc); - - if (!validPrefsFile) { - // uh oh, parser error. Throw some UI - NSString *alert = NSLocalizedString(@"CorruptedBookmarksAlert",@""); - NSString *message = NSLocalizedString(@"CorruptedBookmarksMsg",@""); - NSString *okButton = NSLocalizedString(@"OKButtonText",@""); - NSRunAlertPanel(alert, message, okButton, nil, nil); - - // maybe we should read the default bookmarks here? - gBookmarksFileReadOK = PR_FALSE; - return; - } - - gBookmarksFileReadOK = PR_TRUE; - - nsCOMPtr rootNode; - GetRootContent(getter_AddRefs(rootNode)); - StripWhitespaceNodes(rootNode); -} - -void -BookmarksService::FlushBookmarks() -{ - // XXX we need to insert a mechanism here to ensure that we don't write corrupt - // bookmarks files (e.g. full disk, program crash, whatever), because our - // error handling in the parse stage is NON-EXISTENT. - // This is now partially handled by looking for a node at read time. - if (!gBookmarksFileReadOK) - return; - - nsCOMPtr bookmarksFile; - NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR, getter_AddRefs(bookmarksFile)); - bookmarksFile->Append(NS_LITERAL_STRING("bookmarks.xml")); - - nsCOMPtr outputStream; - NS_NewLocalFileOutputStream(getter_AddRefs(outputStream), bookmarksFile); - - nsCOMPtr domDoc(do_QueryInterface(gBookmarks)); - - nsCOMPtr domSerializer(do_CreateInstance(NS_XMLSERIALIZER_CONTRACTID)); - if (domSerializer) - domSerializer->SerializeToStream(domDoc, outputStream, nsnull); -} - -NSImage* -BookmarksService::CreateIconForBookmark(nsIDOMElement* aElement) -{ - nsCOMPtr tagName; - nsCOMPtr content = do_QueryInterface(aElement); - content->GetTag(*getter_AddRefs(tagName)); - - nsAutoString group; - content->GetAttr(kNameSpaceID_None, gGroupAtom, group); - if (!group.IsEmpty()) - return [NSImage imageNamed:@"groupbookmark"]; - - if (tagName == BookmarksService::gFolderAtom) - return [NSImage imageNamed:@"folder"]; - - // fire off a proxy icon load - if ([[CHPreferenceManager sharedInstance] getBooleanPref:"browser.chrome.site_icons" withSuccess:NULL]) - { - nsAutoString href; - content->GetAttr(kNameSpaceID_None, gHrefAtom, href); - if (href.Length() > 0) - { - BookmarkItem* contentItem = BookmarksService::GetWrapperFor(content); - if ([contentItem siteIcon]) - return [contentItem siteIcon]; - - if (contentItem && ![contentItem siteIcon]) - [[BookmarksManager sharedBookmarksManager] loadProxyImageFor:contentItem withURI:[NSString stringWith_nsAString:href]]; - } - } - - return [NSImage imageNamed:@"smallbookmark"]; -} - -void BookmarksService::EnsureToolbarRoot() -{ - if (gToolbarRoot) - return; - - nsCOMPtr domDoc(do_QueryInterface(gBookmarks)); - nsCOMPtr rootElt; - domDoc->GetDocumentElement(getter_AddRefs(rootElt)); - - nsCOMPtr child; - rootElt->GetFirstChild(getter_AddRefs(child)); - nsAutoString typeValue; - while (child) { - nsCOMPtr childElt(do_QueryInterface(child)); - if (childElt) { - childElt->GetAttribute(NS_LITERAL_STRING("type"), typeValue); - if (typeValue.Equals(NS_LITERAL_STRING("toolbar"))) - gToolbarRoot = childElt; - } - - nsCOMPtr temp; - child->GetNextSibling(getter_AddRefs(temp)); - child = temp; - } - - if (!gToolbarRoot) { - NSLog(@"Repairing personal toolbar"); - nsCOMPtr elt; - domDoc->CreateElementNS(NS_LITERAL_STRING("http://chimera.mozdev.org/bookmarks/"), - NS_LITERAL_STRING("folder"), - getter_AddRefs(elt)); - - elt->SetAttribute(NS_LITERAL_STRING("name"), NS_LITERAL_STRING("Toolbar Bookmarks")); - elt->SetAttribute(NS_LITERAL_STRING("type"), NS_LITERAL_STRING("toolbar")); - - nsCOMPtr dummy; - rootElt->AppendChild(elt, getter_AddRefs(dummy)); - gToolbarRoot = elt; - } -} - -static -void RecursiveAddBookmarkConstruct(NSPopUpButton* aPopup, NSMenu* aMenu, int aTagToMatch, int depth = 0) -{ - // Get the menu item children. - NSArray* children = [aMenu itemArray]; - int startPosition = 0; - if (aMenu == BookmarksService::gBookmarksMenu) - startPosition = 3; - - int count = [children count]; - for (int i = startPosition; i < count; ++i) { - NSMenuItem* menuItem = [children objectAtIndex: i]; - NSMenu* submenu = [menuItem submenu]; - if (submenu) { - // This is a folder. Add it to our list and then recur. Indent it - // the apropriate depth for readability in the menu. - NSMutableString *title = [NSMutableString stringWithString:[menuItem title]]; - for (int j = 0; j <= depth; ++j) - [title insertString:@" " atIndex: 0]; - - [aPopup addItemWithTitle: title]; - NSMenuItem* lastItem = [aPopup lastItem]; - if ([menuItem tag] == aTagToMatch) - [aPopup selectItem: lastItem]; - - [lastItem setTag: [menuItem tag]]; - RecursiveAddBookmarkConstruct(aPopup, submenu, aTagToMatch, depth+1); - } - } -} - -void -BookmarksService::ConstructAddBookmarkFolderList(NSPopUpButton* aPopup, BookmarkItem* aItem) -{ - [aPopup removeAllItems]; - [aPopup addItemWithTitle: [gBookmarksMenu title]]; - NSMenuItem* lastItem = [aPopup lastItem]; - [lastItem setTag: -1]; - int tag = -1; - if (aItem) { - nsIContent* content = [aItem contentNode]; - PRUint32 utag; - content->GetContentID(&utag); - tag = (int)utag; - } - RecursiveAddBookmarkConstruct(aPopup, gBookmarksMenu, tag); -} - -void -BookmarksService::GetTitleAndHrefForBrowserView(id aBrowserView, nsString& aTitle, nsString& aHref) -{ - nsCOMPtr webBrowser = getter_AddRefs([aBrowserView getWebBrowser]); - nsCOMPtr window; - webBrowser->GetContentDOMWindow(getter_AddRefs(window)); - nsCOMPtr htmlDoc; - window->GetDocument(getter_AddRefs(htmlDoc)); - nsCOMPtr pageDoc(do_QueryInterface(htmlDoc)); - - if (pageDoc) { - nsCOMPtr url; - pageDoc->GetDocumentURL(getter_AddRefs(url)); - nsCAutoString spec; - url->GetSpec(spec); - aHref.AssignWithConversion(spec.get()); - } - - nsCOMPtr htmlDocument(do_QueryInterface(htmlDoc)); - if (htmlDocument) - htmlDocument->GetTitle(aTitle); - if (aTitle.IsEmpty()) - aTitle = aHref; -} - -void -BookmarksService::ConstructBookmarksMenu(NSMenu* aMenu, nsIContent* aContent) -{ - nsCOMPtr content = aContent; - if (!content) { - GetRootContent(getter_AddRefs(content)); - GetWrapperFor(content); - gBookmarksMenu = aMenu; - } - - // Now walk our children, and for folders also recur into them. - PRInt32 childCount; - content->ChildCount(childCount); - - for (PRInt32 i = 0; i < childCount; i++) { - nsCOMPtr child; - content->ChildAt(i, *getter_AddRefs(child)); - AddMenuBookmark(aMenu, content, child, -1); - } -} - -void -BookmarksService::AddMenuBookmark(NSMenu* aMenu, nsIContent* aParent, nsIContent* aChild, PRInt32 aIndex) -{ - nsAutoString name; - aChild->GetAttr(kNameSpaceID_None, gNameAtom, name); - NSString* title = [[NSString stringWith_nsAString: name] stringByTruncatingTo:80 at:kTruncateAtMiddle]; - - // Create a menu or menu item for the child. - NSMenuItem* menuItem = [[[NSMenuItem alloc] initWithTitle: title action: NULL keyEquivalent: @""] autorelease]; - GetWrapperFor(aChild); - - if (aIndex == -1) - [aMenu addItem: menuItem]; - else { - PRInt32 insertIndex = aIndex; - if (aMenu == gBookmarksMenu) // take static menu items into account - insertIndex += [aMenu indexOfItemWithTag:kBookmarksDividerTag] + 1; - - [aMenu insertItem: menuItem atIndex: insertIndex]; - } - - nsCOMPtr tagName; - aChild->GetTag(*getter_AddRefs(tagName)); - - nsAutoString group; - aChild->GetAttr(kNameSpaceID_None, gGroupAtom, group); - - nsCOMPtr elt(do_QueryInterface(aChild)); - NSImage* menuItemImage = BookmarksService::CreateIconForBookmark(elt); - - if (group.IsEmpty() && tagName == gFolderAtom) { - NSMenu* menu = [[[NSMenu alloc] initWithTitle: title] autorelease]; - [aMenu setSubmenu: menu forItem: menuItem]; - [menu setAutoenablesItems: NO]; - [menuItem setImage: menuItemImage]; - ConstructBookmarksMenu(menu, aChild); - } - else { - if (group.IsEmpty()) - [menuItem setImage: menuItemImage]; - else - [menuItem setImage: menuItemImage]; - - [menuItem setTarget: gMainController]; - [menuItem setAction: @selector(openMenuBookmark:)]; - } - - PRUint32 contentID; - aChild->GetContentID(&contentID); - [menuItem setTag: contentID]; -} - -void -BookmarksService::OpenMenuBookmark(BrowserWindowController* aController, id aMenuItem) -{ - // Get the corresponding bookmark item. - BookmarkItem* item = [gDictionary objectForKey: [NSNumber numberWithInt: [aMenuItem tag]]]; - - // Get the content node. - nsIContent* content = [item contentNode]; - nsAutoString group; - content->GetAttr(kNameSpaceID_None, gGroupAtom, group); - if (!group.IsEmpty()) { - nsCOMPtr elt(do_QueryInterface([item contentNode])); - return OpenBookmarkGroup([aController getTabBrowser], elt); - } - - // Get the href attribute. This is the URL we want to load. - nsAutoString href; - content->GetAttr(kNameSpaceID_None, gHrefAtom, href); - if (href.IsEmpty()) - return; - - NSString* url = [NSString stringWith_nsAString: href]; - - // Now load the URL in the window. - [aController loadURL:url referrer:nil activate:YES]; -} - -static void GetImportTitle(nsIDOMElement* aSrc, nsString& aTitle) -{ - aTitle.Truncate(0); - nsCOMPtr curr; - aSrc->GetFirstChild(getter_AddRefs(curr)); - while (curr) { - nsCOMPtr charData(do_QueryInterface(curr)); - if (charData) { - nsAutoString data; - charData->GetData(data); - aTitle += data; - } - else { - // Handle Omniweb's nesting of inside

for its folders. - nsCOMPtr elt(do_QueryInterface(curr)); - if (elt) { - nsAutoString localName; - elt->GetLocalName(localName); - ToLowerCase(localName); - if (localName.Equals(NS_LITERAL_STRING("a"))) { - aTitle = NS_LITERAL_STRING(""); - return GetImportTitle(elt, aTitle); - } - } - } - - nsCOMPtr temp = curr; - temp->GetNextSibling(getter_AddRefs(curr)); - } -} - -// sniff for control chars, which are defined to be in the range U+0000 to U+001F and U+007F to U+009F. -static PRBool ContainsControlChars(const nsString& inString) -{ - PRUint16 *c = (PRUint16*)inString.get(); // be sure to get unsigned - - while (*c) - { - if ((*c <= 0x001F) || (*c >= 0x007F && *c <= 0x009F)) - return PR_TRUE; - c ++; - } - - return PR_FALSE; -} - -static void CleanControlChars(nsString& ioString) -{ - if (ContainsControlChars(ioString)) - { - // strip control chars here. this is inefficient, but does it matter? - NSString* cleanedTitle = [[NSString stringWith_nsAString: ioString] - stringByReplacingCharactersInSet:[NSCharacterSet controlCharacterSet] withString:@""]; - [cleanedTitle assignTo_nsAString:ioString]; - NSLog(@"Removed control characters from bookmark string '%@'", cleanedTitle); - } -} - -static void CreateBookmark(nsIDOMElement* aSrc, nsIDOMElement* aDst, - nsIDOMDocument* aDstDoc, PRBool aIsFolder, - nsIDOMElement** aResult) -{ - nsAutoString tagName(NS_LITERAL_STRING("bookmark")); - if (aIsFolder) - tagName = NS_LITERAL_STRING("folder"); - - aDstDoc->CreateElementNS(NS_LITERAL_STRING("http://chimera.mozdev.org/bookmarks/"), - tagName, - aResult); // Addref happens here. - - nsAutoString title; - GetImportTitle(aSrc, title); - CleanControlChars(title); - - (*aResult)->SetAttribute(NS_LITERAL_STRING("name"), title); - - if (!aIsFolder) { - nsAutoString href; - aSrc->GetAttribute(NS_LITERAL_STRING("href"), href); - CleanControlChars(href); - (*aResult)->SetAttribute(NS_LITERAL_STRING("href"), href); - } - - nsCOMPtr dummy; - aDst->AppendChild(*aResult, getter_AddRefs(dummy)); -} - -static void AddImportedBookmarks(nsIDOMElement* aSrc, nsIDOMElement* aDst, nsIDOMDocument* aDstDoc, - PRInt32& aBookmarksType) -{ - nsAutoString localName; - aSrc->GetLocalName(localName); - ToLowerCase(localName); - nsCOMPtr newBookmark; - if (localName.Equals(NS_LITERAL_STRING("bookmarkinfo"))) - aBookmarksType = 1; // Omniweb. - else if (localName.Equals(NS_LITERAL_STRING("dt"))) { - // We have found either a folder or a leaf. - nsCOMPtr curr; - aSrc->GetFirstChild(getter_AddRefs(curr)); - while (curr) { - nsCOMPtr childElt(do_QueryInterface(curr)); - if (childElt) { - childElt->GetLocalName(localName); - ToLowerCase(localName); - if (localName.Equals(NS_LITERAL_STRING("a"))) { - // Guaranteed to be a bookmark in IE. Could be either in Omniweb. - nsCOMPtr dummy; - CreateBookmark(childElt, aDst, aDstDoc, PR_FALSE, getter_AddRefs(dummy)); - } - // Ignore the H3 we encounter. This will be dealt with later. - } - nsCOMPtr temp = curr; - temp->GetNextSibling(getter_AddRefs(curr)); - } - } - else if (localName.Equals(NS_LITERAL_STRING("dl"))) { - // The children of a folder. Recur inside. - // Locate the parent to create the folder. - nsCOMPtr node; - aSrc->GetPreviousSibling(getter_AddRefs(node)); - nsCOMPtr folderElt(do_QueryInterface(node)); - if (folderElt) { - // Make sure it's an H3 folder in Mozilla and IE. In Mozilla it will probably have an ID. - PRBool hasID; - folderElt->HasAttribute(NS_LITERAL_STRING("ID"), &hasID); - if (aBookmarksType != 1) { - if (hasID) - aBookmarksType = 2; // Mozilla - else - aBookmarksType = 0; // IE - } - nsAutoString localName; - folderElt->GetLocalName(localName); - ToLowerCase(localName); - if (localName.Equals(NS_LITERAL_STRING("h3"))) - CreateBookmark(folderElt, aDst, aDstDoc, PR_TRUE, getter_AddRefs(newBookmark)); - } - if (!newBookmark) - newBookmark = aDst; - // Recur over all our children. - nsCOMPtr curr; - aSrc->GetFirstChild(getter_AddRefs(curr)); - while (curr) { - nsCOMPtr elt(do_QueryInterface(curr)); - if (elt) - AddImportedBookmarks(elt, newBookmark, aDstDoc, aBookmarksType); - nsCOMPtr temp = curr; - temp->GetNextSibling(getter_AddRefs(curr)); - } - } - else { - // Recur over all our children. - nsCOMPtr curr; - aSrc->GetFirstChild(getter_AddRefs(curr)); - while (curr) { - nsCOMPtr elt(do_QueryInterface(curr)); - if (elt) - AddImportedBookmarks(elt, aDst, aDstDoc, aBookmarksType); - nsCOMPtr temp = curr; - temp->GetNextSibling(getter_AddRefs(curr)); - } - } -} - - -void -BookmarksService::ImportBookmarks(nsIDOMHTMLDocument* aHTMLDoc) -{ - nsCOMPtr htmlDocRoot; - aHTMLDoc->GetDocumentElement(getter_AddRefs(htmlDocRoot)); - - nsCOMPtr bookmarksRoot; - nsCOMPtr bookmarksDOMDoc(do_QueryInterface(gBookmarks)); - bookmarksDOMDoc->GetDocumentElement(getter_AddRefs(bookmarksRoot)); - - nsCOMPtr dummy; - - // Create the root of the new bookmarks by hand. - nsCOMPtr importedRootElement; - bookmarksDOMDoc->CreateElementNS( NS_LITERAL_STRING("http://chimera.mozdev.org/bookmarks/"), - NS_LITERAL_STRING("folder"), - getter_AddRefs(importedRootElement)); - - // Now crawl through the file and look for
elements. They signify folders - // or leaves. - PRInt32 bookmarksType = 0; // Assume IE. - AddImportedBookmarks(htmlDocRoot, importedRootElement, bookmarksDOMDoc, bookmarksType); - - if (bookmarksType == 0) - importedRootElement->SetAttribute(NS_LITERAL_STRING("name"), NS_LITERAL_STRING("Internet Explorer Favorites")); - else if (bookmarksType == 1) - importedRootElement->SetAttribute(NS_LITERAL_STRING("name"), NS_LITERAL_STRING("Omniweb Favorites")); - else if (bookmarksType == 2) - importedRootElement->SetAttribute(NS_LITERAL_STRING("name"), NS_LITERAL_STRING("Mozilla/Netscape Favorites")); - - // now put the new child into the doc, and validate it - bookmarksRoot->AppendChild(importedRootElement, getter_AddRefs(dummy)); - - PRBool bookmarksGood = ValidateXMLDocument(bookmarksDOMDoc); - if (!bookmarksGood) { - // uh oh, parser error. Remove the new node, and then throw some UI - bookmarksRoot->RemoveChild(importedRootElement, getter_AddRefs(dummy)); - - NSString *alert = NSLocalizedString(@"ErrorImportingBookmarksAlert",@""); - NSString *message = NSLocalizedString(@"ErrorImportingBookmarksMsg",@""); - NSString *okButton = NSLocalizedString(@"OKButtonText",@""); - NSRunAlertPanel(alert, message, okButton, nil, nil); - return; - } - - // Now do a notification that the root Favorites folder got added. This - // will update all our views. - nsCOMPtr parentContent(do_QueryInterface(bookmarksRoot)); - nsCOMPtr childContent(do_QueryInterface(importedRootElement)); - -#if 0 - // XXX testing - if (gDictionary) - [gDictionary removeAllObjects]; -#endif - - // this will save the file - BookmarkAdded(parentContent, childContent, true /* flush */); -} - -void -BookmarksService::OpenBookmarkGroup(id aTabView, nsIDOMElement* aFolder) -{ - // We might conceivably have to make new tabs in order to load all - // the items in the group. - int currentIndex = 0; - int total = [aTabView numberOfTabViewItems]; - nsCOMPtr child; - aFolder->GetFirstChild(getter_AddRefs(child)); - while (child) { - nsCOMPtr elt(do_QueryInterface(child)); - if (elt) { - nsAutoString href; - elt->GetAttribute(NS_LITERAL_STRING("href"), href); - if (!href.IsEmpty()) { - NSString* url = [NSString stringWith_nsAString: href]; - BrowserTabViewItem* tabViewItem = nil; - if (currentIndex >= total) { - // We need to make a new tab. - // XXX this needs fixing to not max out the number of tabs in a browser window. - // See [BrowserWindowController newTabsAllowed]; - tabViewItem = [BrowserTabView makeNewTabItem]; - CHBrowserWrapper* newView = [[[CHBrowserWrapper alloc] initWithTab: tabViewItem andWindow: [aTabView window]] autorelease]; - [tabViewItem setLabel: NSLocalizedString(@"UntitledPageTitle", @"")]; - [tabViewItem setView: newView]; - [aTabView addTabViewItem: tabViewItem]; - } - else - tabViewItem = [aTabView tabViewItemAtIndex: currentIndex]; - - [[tabViewItem view] loadURI: url referrer:nil - flags: NSLoadFlagsNone activate:(currentIndex == 0)]; - } - } - - nsCOMPtr temp = child; - temp->GetNextSibling(getter_AddRefs(child)); - currentIndex++; - } - - // Select the first tab. - [aTabView selectTabViewItemAtIndex: 0]; -} - -NSString* -BookmarksService::ResolveKeyword(NSString* aKeyword) -{ - nsAutoString keyword; - [aKeyword assignTo_nsAString:keyword]; - - if (keyword.IsEmpty()) - return [NSString string]; - -#if DEBUG - NSLog(@"str = %s", keyword.get()); -#endif - - nsCOMPtr domDoc(do_QueryInterface(gBookmarks)); - nsCOMPtr elt; - domDoc->GetElementById(keyword, getter_AddRefs(elt)); - - nsCOMPtr content(do_QueryInterface(elt)); - nsAutoString url; - if (content) { - content->GetAttr(kNameSpaceID_None, gHrefAtom, url); - return [NSString stringWith_nsAString: url]; - } - return [NSString string]; -} - -// Is searchItem equal to bookmark or bookmark's parent, grandparent, etc? -BOOL -BookmarksService::DoAncestorsIncludeNode(BookmarkItem* bookmark, BookmarkItem* searchItem) -{ - nsCOMPtr search = [searchItem contentNode]; - nsCOMPtr current = [bookmark contentNode]; - nsCOMPtr root; - GetRootContent(getter_AddRefs(root)); - - // If the search item is the root node, return yes immediatly - if (search == root) - return YES; - - // for each ancestor - while (current) { - // If this is the root node we can't search farther, and there was no match - if (current == root) - return NO; - - // If the two nodes match, then the search term is an ancestor of the given bookmark - if (search == current) - return YES; - - // If a match wasn't found, set up the next node to compare - nsCOMPtr oldCurrent = current; - oldCurrent->GetParent(*getter_AddRefs(current)); - } - - return NO; -} - - -#ifdef FILTER_DESCENDANT_ON_DRAG -/* -this has been disabled because it is too slow, and can cause a large -delay when the user is dragging lots of items. this needs to get -fixed someday. - -It should filter out every node whose parent is also being dragged. -*/ - -NSArray* -BookmarksService::FilterOutDescendantsForDrag(NSArray* nodes) -{ - NSMutableArray *toDrag = [NSMutableArray arrayWithArray: nodes]; - unsigned int i = 0; - - while (i < [toDrag count]) { - BookmarkItem* item = [toDrag objectAtIndex: i]; - bool matchFound = false; - - for (unsigned int j = 0; j < [toDrag count] && matchFound == NO; j++) { - if (i != j) // Don't compare to self, will always match - matchFound = BookmarksService::DoAncestorsIncludeNode(item, [toDrag objectAtIndex: j]); - } - - // if a match was found, remove the node from the array - if (matchFound) - [toDrag removeObjectAtIndex: i]; - else - i++; - } - - return toDrag; -} -#endif - -bool -BookmarksService::IsBookmarkDropValid(BookmarkItem* proposedParent, int index, NSArray* draggedIDs) -{ - if ( !draggedIDs ) - return NO; - - NSMutableArray *draggedItems = [NSMutableArray arrayWithCapacity: [draggedIDs count]]; - BOOL toolbarRootMoving = NO; - - for (unsigned int i = 0; i < [draggedIDs count]; i++) { - NSNumber* contentID = [draggedIDs objectAtIndex: i]; - BookmarkItem* bookmarkItem = BookmarksService::GetWrapperFor([contentID unsignedIntValue]); - nsCOMPtr itemContent = [bookmarkItem contentNode]; - nsCOMPtr itemElement(do_QueryInterface(itemContent)); - - if (itemElement == BookmarksService::gToolbarRoot) - toolbarRootMoving = YES; - - if (bookmarkItem) - [draggedItems addObject: bookmarkItem]; - } - - // If we are being dropped into the top level, allow it - if ([proposedParent contentNode] == [BookmarksService::GetRootItem() contentNode]) - return true; - - // If we are not being dropped on the top level, and the toolbar root is being moved, disallow - if (toolbarRootMoving) - return false; - - // Make sure that we are not being dropped into one of our own children - // If the proposed parent, or any of it's ancestors matches one of the nodes being dragged - // then deny the drag. - - for (unsigned int i = 0; i < [draggedItems count]; i++) { - if (BookmarksService::DoAncestorsIncludeNode(proposedParent, [draggedItems objectAtIndex: i])) { - return false; - } - } - - return true; -} - - -bool -BookmarksService::PerformProxyDrop(BookmarkItem* parentItem, BookmarkItem* beforeItem, NSDictionary* data) -{ - if ( !data ) - return NO; - - nsCOMPtr parentElt; - parentElt = do_QueryInterface([parentItem contentNode]); - - nsCOMPtr beforeElt; - beforeElt = do_QueryInterface([beforeItem contentNode]); - - nsAutoString url; [[data objectForKey:@"url"] assignTo_nsAString:url]; - nsAutoString title; [[data objectForKey:@"title"] assignTo_nsAString:title]; - BookmarksService::AddBookmarkToFolder(url, title, parentElt, beforeElt); - return YES; -} - - -bool -BookmarksService::PerformBookmarkDrop(BookmarkItem* parent, int index, NSArray* draggedIDs) -{ - NSEnumerator *enumerator = [draggedIDs reverseObjectEnumerator]; - NSNumber *contentID; - - // for each item being dragged - while ( (contentID = [enumerator nextObject]) ) { - - // get dragged node - nsCOMPtr draggedNode = [GetWrapperFor([contentID unsignedIntValue]) contentNode]; - - // get the dragged nodes parent - nsCOMPtr draggedParent; - if (draggedNode) - draggedNode->GetParent(*getter_AddRefs(draggedParent)); - - // get the proposed parent - nsCOMPtr proposedParent = [parent contentNode]; - - PRInt32 existingIndex = 0; - if (draggedParent) - draggedParent->IndexOf(draggedNode, existingIndex); - - // if the deleted nodes parent and the proposed parents are equal - // and if the deleted point is earlier in the list than the inserted point - if (proposedParent == draggedParent && existingIndex < index) { - index--; // if so, move the inserted point up one to compensate - } - - // remove it from the tree - if (draggedNode != proposedParent) // paranoia. This should never happen - { - if (draggedParent) - draggedParent->RemoveChildAt(existingIndex, PR_TRUE); - BookmarkRemoved(draggedParent, draggedNode, false); - - // insert into new position - if (proposedParent) - proposedParent->InsertChildAt(draggedNode, index, PR_TRUE, PR_TRUE); - BookmarkAdded(proposedParent, draggedNode, false); - } - } - - FlushBookmarks(); - - return true; -} - -bool -BookmarksService::PerformURLDrop(BookmarkItem* parentItem, BookmarkItem* beforeItem, NSString* inTitle, NSString* inUrl) -{ - if ( !inUrl || [inUrl length] == 0 ) - return NO; - - nsCOMPtr parentElt; - parentElt = do_QueryInterface([parentItem contentNode]); - - nsCOMPtr beforeElt; - beforeElt = do_QueryInterface([beforeItem contentNode]); - - nsAutoString url; [inUrl assignTo_nsAString:url]; - nsAutoString title; [inTitle assignTo_nsAString:title]; - if (title.Length() == 0) - [inUrl assignTo_nsAString:title]; - - BookmarksService::AddBookmarkToFolder(url, title, parentElt, beforeElt); - return YES; -} - -#pragma mark - - -@interface BookmarksManager(Private) - -- (void)registerNotificationListener; -- (void)imageLoadedNotification:(NSNotification*)notification; - -@end - - -@implementation BookmarksManager - -+ (BookmarksManager*)sharedBookmarksManager; -{ - static BookmarksManager* sBookmarksManager = nil; - - if (!sBookmarksManager) - sBookmarksManager = [[BookmarksManager alloc] init]; - - return sBookmarksManager; -} - -- (id)init -{ - if ((self = [super init])) - { - [self registerNotificationListener]; - } - return self; -} - -- (void)dealloc -{ - [[NSNotificationCenter defaultCenter] removeObserver:self]; - [super dealloc]; -} - -- (void)loadProxyImageFor:(id)requestor withURI:(NSString*)inURIString -{ - [[SiteIconProvider sharedFavoriteIconProvider] loadFavoriteIcon:self - forURI:inURIString withUserData:requestor allowNetwork:NO]; -} - - -- (void)registerNotificationListener -{ - [[NSNotificationCenter defaultCenter] addObserver: self - selector: @selector(imageLoadedNotification:) - name: SiteIconLoadNotificationName - object: self]; - -} - -// callback for [[SiteIconProvider sharedFavoriteIconProvider] loadFavoriteIcon] -- (void)imageLoadedNotification:(NSNotification*)notification -{ - //NSLog(@"BookmarksManager imageLoadedNotification"); - NSDictionary* userInfo = [notification userInfo]; - if (userInfo) - { - id requestor = [userInfo objectForKey:SiteIconLoadUserDataKey]; // requestor is a BookmarkItem - NSImage* iconImage = [userInfo objectForKey:SiteIconLoadImageKey]; - - if (iconImage && [requestor isMemberOfClass:[BookmarkItem class]]) - { - [requestor setSiteIcon:iconImage]; - BookmarksService::BookmarkChanged([requestor contentNode], FALSE); - } - - } -} - - -@end - diff --git a/mozilla/chimera/BrowserTabView.h b/mozilla/chimera/BrowserTabView.h deleted file mode 100644 index 044e73999a5..00000000000 --- a/mozilla/chimera/BrowserTabView.h +++ /dev/null @@ -1,45 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- -* -* 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 the Mozilla browser. -* -* The Initial Developer of the Original Code is Matt Judy. Portions -* of code @2002 nibfile.com. -*/ - -#import - -#import "BrowserTabViewItem.h" - -@interface BrowserTabView : NSTabView -{ - BOOL autoHides; - BOOL mIsDropTarget; - BOOL mLastClickIsPotentialDrag; - int maxNumberOfTabs; // 0 means 'no max' -} - -+ (BrowserTabViewItem*)makeNewTabItem; - -// Behavior: Autohiding overrides the default tab visibility state. -// To switch back to usual tabView behavior, setAutoHides:NO. -// Initial value is read from defaults. -- (BOOL)autoHides; -- (void)setAutoHides:(BOOL)newSetting; - -- (int)maxNumberOfTabs; -- (void)setMaxNumberOfTabs:(int)maxTabs; -- (BOOL)canMakeNewTabs; - -- (void)addTabForURL:(NSString*)aURL referrer:(NSString*)aReferrer; - -@end diff --git a/mozilla/chimera/BrowserTabView.mm b/mozilla/chimera/BrowserTabView.mm deleted file mode 100644 index a0993900829..00000000000 --- a/mozilla/chimera/BrowserTabView.mm +++ /dev/null @@ -1,406 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** -* Version: NPL 1.1/GPL 2.0/LGPL 2.1 -* -* The contents of this file are subject to the Netscape 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/NPL/ -* -* 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 mozilla.org 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): -* Matt Judy (Original Author) -* David Haas -* -* 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 NPL, 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 NPL, the GPL or the LGPL. -* -* ***** END LICENSE BLOCK ***** */ - -#import "NSString+Utils.h" - -#import "BrowserTabView.h" -#import "BookmarksService.h" -#import "BookmarksDataSource.h" - -#include "nsCOMPtr.h" -#include "nsIDOMElement.h" -#include "nsIContent.h" -#include "nsIAtom.h" -#include "nsString.h" -#include "nsCRT.h" - -////////////////////////// -// NEEDS IMPLEMENTED : Implement drag tracking for moving tabs around. -// Implementation hints : Track drags ;) -// : Change tab controlTint to indicate drag location? -// : Move tab titles around when dragging. -////////////////////////// - -@interface BrowserTabView (Private) - -- (void)showOrHideTabsAsAppropriate; -- (BOOL)handleDropOnTab:(NSTabViewItem*)overTabViewItem overContent:(BOOL)overContentArea withURL:(NSString*)url; -- (BrowserTabViewItem*)getTabViewItemFromWindowPoint:(NSPoint)point; -- (void)showDragDestinationIndicator; -- (void)hideDragDestinationIndicator; - -@end - - -#define kTabDropTargetHeight 18.0 - -@implementation BrowserTabView - -/******************************************/ -/*** Initialization ***/ -/******************************************/ - -- (id)initWithFrame:(NSRect)frameRect -{ - if ( (self = [super initWithFrame:frameRect]) ) { - autoHides = YES; - maxNumberOfTabs = 0; // no max - } - return self; -} - -- (void)awakeFromNib -{ - [self showOrHideTabsAsAppropriate]; - [self registerForDraggedTypes:[NSArray arrayWithObjects: - @"MozURLType", @"MozBookmarkType", NSStringPboardType, NSFilenamesPboardType, nil]]; -} - -/******************************************/ -/*** Overridden Methods ***/ -/******************************************/ - -- (BOOL)isOpaque -{ - if ( ([self tabViewType] == NSNoTabsBezelBorder) && (NSAppKitVersionNumber < 633) ) - return NO; - - return [super isOpaque]; -} - -- (void)drawRect:(NSRect)aRect -{ - if (mIsDropTarget) - { - NSRect hilightRect = aRect; - hilightRect.size.height = kTabDropTargetHeight; // no need to move origin.y; our coords are flipped - NSBezierPath* dropTargetOutline = [NSBezierPath bezierPathWithRect:hilightRect]; - - [[[NSColor colorForControlTint:NSDefaultControlTint] colorWithAlphaComponent:0.5] set]; - [dropTargetOutline fill]; - } - - [super drawRect:aRect]; -} - -- (void)addTabViewItem:(NSTabViewItem *)tabViewItem -{ - [super addTabViewItem:tabViewItem]; - [self showOrHideTabsAsAppropriate]; -} - -- (void)removeTabViewItem:(NSTabViewItem *)tabViewItem -{ - [super removeTabViewItem:tabViewItem]; - [self showOrHideTabsAsAppropriate]; -} - -- (void)insertTabViewItem:(NSTabViewItem *)tabViewItem atIndex:(int)index -{ - [super insertTabViewItem:tabViewItem atIndex:index]; - [self showOrHideTabsAsAppropriate]; -} - -/******************************************/ -/*** Accessor Methods ***/ -/******************************************/ - -- (BOOL)autoHides -{ - return autoHides; -} - -- (void)setAutoHides:(BOOL)newSetting -{ - autoHides = newSetting; -} - -- (int)maxNumberOfTabs -{ - return maxNumberOfTabs; -} - -- (void)setMaxNumberOfTabs:(int)maxTabs -{ - maxNumberOfTabs = maxTabs; -} - -- (BOOL)canMakeNewTabs -{ - return maxNumberOfTabs == 0 || [self numberOfTabViewItems] < maxNumberOfTabs; -} - -/******************************************/ -/*** Instance Methods ***/ -/******************************************/ - -// 03-03-2002 mlj: Modifies tab view size and type appropriately... Fragile. -// Only to be used with the 2 types of tab view which we use in Chimera. -- (void)showOrHideTabsAsAppropriate -{ - //if ( autoHides == YES ) - { - BOOL tabVisibilityChanged = NO; - BOOL tabsVisible = NO; - - if ( [[self tabViewItems] count] < 2) - { - if ( [self tabViewType] != NSNoTabsBezelBorder ) - { - [self setFrameSize:NSMakeSize( NSWidth([self frame]), NSHeight([self frame]) + 10 )]; - [self setTabViewType:NSNoTabsBezelBorder]; - tabVisibilityChanged = YES; - } - tabsVisible = NO; - } - else - { - if ( [self tabViewType] != NSTopTabsBezelBorder ) - { - [self setFrameSize:NSMakeSize( NSWidth([self frame]), NSHeight([self frame]) - 10 )]; - [self setTabViewType:NSTopTabsBezelBorder]; - tabVisibilityChanged = YES; - } - tabsVisible = YES; - } - - // tell the tabs that visibility changed - NSArray* tabViewItems = [self tabViewItems]; - for (unsigned int i = 0; i < [tabViewItems count]; i ++) - { - NSTabViewItem* tabItem = [tabViewItems objectAtIndex:i]; - if ([tabItem isMemberOfClass:[BrowserTabViewItem class]]) - [(BrowserTabViewItem*)tabItem updateTabVisibility:tabsVisible]; - } - - if (tabVisibilityChanged) - [self setNeedsDisplay:YES]; - } -} - - -- (BOOL)handleDropOnTab:(NSTabViewItem*)overTabViewItem overContent:(BOOL)overContentArea withURL:(NSString*)url -{ - if (overTabViewItem) - { - [[overTabViewItem view] loadURI: url referrer:nil flags: NSLoadFlagsNone activate:NO]; - return YES; - } - else if (overContentArea) - { - [[[self selectedTabViewItem] view] loadURI: url referrer:nil flags: NSLoadFlagsNone activate:NO]; - return YES; - } - else if ([self canMakeNewTabs]) - { - [self addTabForURL:url referrer:nil]; - return YES; - } - - return NO; -} - -- (BrowserTabViewItem*)getTabViewItemFromWindowPoint:(NSPoint)point -{ - NSPoint localPoint = [self convertPoint: point fromView: nil]; - NSTabViewItem* overTabViewItem = [self tabViewItemAtPoint: localPoint]; - return (BrowserTabViewItem*)overTabViewItem; -} - -- (void)showDragDestinationIndicator -{ - if (!mIsDropTarget) - { - NSRect invalidRect = [self bounds]; - invalidRect.size.height = kTabDropTargetHeight; - [self setNeedsDisplayInRect:invalidRect]; - mIsDropTarget = YES; - } -} - -- (void)hideDragDestinationIndicator -{ - if (mIsDropTarget) - { - NSRect invalidRect = [self bounds]; - invalidRect.size.height = kTabDropTargetHeight; - [self setNeedsDisplayInRect:invalidRect]; - mIsDropTarget = NO; - } -} - -#pragma mark - - -// NSDraggingDestination /////////// - -- (unsigned int)draggingEntered:(id )sender -{ - NSPoint localPoint = [self convertPoint: [sender draggingLocation] fromView: nil]; - NSTabViewItem* overTabViewItem = [self tabViewItemAtPoint: localPoint]; - BOOL overContentArea = NSPointInRect(localPoint, [self contentRect]); - - if (overTabViewItem) - return NSDragOperationNone; // the tab will handle it - - if (!overContentArea && ![self canMakeNewTabs]) - return NSDragOperationNone; - - [self showDragDestinationIndicator]; // XXX optimize - return NSDragOperationGeneric; -} - -- (unsigned int)draggingUpdated:(id )sender -{ - NSPoint localPoint = [self convertPoint: [sender draggingLocation] fromView: nil]; - NSTabViewItem* overTabViewItem = [self tabViewItemAtPoint: localPoint]; - BOOL overContentArea = NSPointInRect(localPoint, [self contentRect]); - - if (overTabViewItem) - return NSDragOperationNone; // the tab will handle it - - if (!overContentArea && ![self canMakeNewTabs]) - { - [self hideDragDestinationIndicator]; - return NSDragOperationNone; - } - - [self showDragDestinationIndicator]; - return NSDragOperationGeneric; -} - -- (void)draggingExited:(id )sender -{ - [self hideDragDestinationIndicator]; -} - -- (BOOL)prepareForDragOperation:(id )sender -{ - return YES; -} - -- (BOOL)performDragOperation:(id )sender -{ - // determine if we are over a tab or the content area - NSPoint localPoint = [self convertPoint: [sender draggingLocation] fromView: nil]; - NSTabViewItem* overTabViewItem = [self tabViewItemAtPoint: localPoint]; - BOOL overContentArea = NSPointInRect(localPoint, [self contentRect]); - NSArray* pasteBoardTypes = [[sender draggingPasteboard] types]; - - [self hideDragDestinationIndicator]; - - if ([pasteBoardTypes containsObject: @"MozBookmarkType"]) - { - NSArray* contentIds = [[sender draggingPasteboard] propertyListForType: @"MozBookmarkType"]; - if (contentIds) { - // drag type is chimera bookmarks - for (unsigned int i = 0; i < [contentIds count]; ++i) { - BookmarkItem* item = [BookmarksService::gDictionary objectForKey: [contentIds objectAtIndex:i]]; - nsCOMPtr bookmarkElt = do_QueryInterface([item contentNode]); - - nsCOMPtr tagName; - [item contentNode]->GetTag(*getter_AddRefs(tagName)); - - nsAutoString href; - bookmarkElt->GetAttribute(NS_LITERAL_STRING("href"), href); - NSString* url = [NSString stringWith_nsAString: href]; - - nsAutoString group; - bookmarkElt->GetAttribute(NS_LITERAL_STRING("group"), group); - if (!group.IsEmpty()) { - BookmarksService::OpenBookmarkGroup(self, bookmarkElt); - } else { - return [self handleDropOnTab:overTabViewItem overContent:overContentArea withURL:url]; - } - } // for each item - } - } - else if ([pasteBoardTypes containsObject: @"MozURLType"]) - { - // drag type is MozURLType - NSDictionary* data = [[sender draggingPasteboard] propertyListForType: @"MozURLType"]; - if (data) { - NSString* urlString = [data objectForKey:@"url"]; - return [self handleDropOnTab:overTabViewItem overContent:overContentArea withURL:urlString]; - } - } - else if ([pasteBoardTypes containsObject: NSStringPboardType]) - { - NSString* urlString = [[sender draggingPasteboard] stringForType: NSStringPboardType]; - return [self handleDropOnTab:overTabViewItem overContent:overContentArea withURL:urlString]; - } - else if ([pasteBoardTypes containsObject: NSURLPboardType]) - { - NSURL* urlData = [NSURL URLFromPasteboard:[sender draggingPasteboard]]; - return [self handleDropOnTab:overTabViewItem overContent:overContentArea withURL:[urlData absoluteString]]; - } - else if ([pasteBoardTypes containsObject: NSFilenamesPboardType]) - { - NSString* urlString = [[sender draggingPasteboard] stringForType: NSFilenamesPboardType]; - return [self handleDropOnTab:overTabViewItem overContent:overContentArea withURL:urlString]; - } - - return NO; -} - -#pragma mark - - --(void)addTabForURL:(NSString*)aURL referrer:(NSString*)aReferrer -{ - // We need to make a new tab. - BrowserTabViewItem *tabViewItem= [BrowserTabView makeNewTabItem]; - CHBrowserWrapper *newView = [[[CHBrowserWrapper alloc] initWithTab: tabViewItem andWindow: [self window]] autorelease]; - [tabViewItem setLabel: NSLocalizedString(@"UntitledPageTitle", @"")]; - [tabViewItem setView: newView]; - [self addTabViewItem: tabViewItem]; - - [[tabViewItem view] loadURI: aURL referrer:aReferrer flags: NSLoadFlagsNone activate:NO]; -} - -#pragma mark - - -+ (BrowserTabViewItem*)makeNewTabItem -{ - return [[[BrowserTabViewItem alloc] init] autorelease]; -} - -@end - - - - diff --git a/mozilla/chimera/BrowserTabViewItem.h b/mozilla/chimera/BrowserTabViewItem.h deleted file mode 100644 index ae4787b7ff8..00000000000 --- a/mozilla/chimera/BrowserTabViewItem.h +++ /dev/null @@ -1,57 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape 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/NPL/ - * - * 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 mozilla.org 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): - * Simon Fraser - * - * 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 NPL, 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 NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#import - -#import "CHIconTabViewItem.h" - -// a subclass of CHIconTabViewItem that handles dragging of site icons -@class BrowserTabItemContainerView; - -@interface BrowserTabViewItem : CHIconTabViewItem -{ - NSRect mLastDrawRect; // cached draw rect, used for dragging location - BrowserTabItemContainerView* mTabContentsView; - BOOL mDraggable; -} - -- (void)updateTabVisibility:(BOOL)nowVisible; -- (NSView*)tabItemContentsView; -- (void)setTabIcon:(NSImage *)newIcon isDraggable:(BOOL)draggable; - -@end diff --git a/mozilla/chimera/BrowserTabViewItem.mm b/mozilla/chimera/BrowserTabViewItem.mm deleted file mode 100644 index 9134db8ba5f..00000000000 --- a/mozilla/chimera/BrowserTabViewItem.mm +++ /dev/null @@ -1,557 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape 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/NPL/ - * - * 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 mozilla.org 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): - * Simon Fraser - * - * 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 NPL, 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 NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#import "NSString+Utils.h" - -#import "BrowserTabViewItem.h" - -#import "CHBrowserView.h" -#import "MainController.h" -#import "BrowserWindowController.h" - - -@interface BrowserTabViewItem(Private) -- (void)buildTabContents; -- (void)relocateTabContents:(NSRect)inRect; -- (BOOL)draggable; -@end - -#pragma mark - - -@interface NSBezierPath (ChimeraBezierPathUtils) - -+ (NSBezierPath*)bezierPathWithRoundCorneredRect:(NSRect)rect cornerRadius:(float)cornerRadius; - -@end - -@implementation NSBezierPath (ChimeraBezierPathUtils) - -+ (NSBezierPath*)bezierPathWithRoundCorneredRect:(NSRect)rect cornerRadius:(float)cornerRadius -{ - float maxRadius = cornerRadius; - if (NSWidth(rect) / 2.0 < maxRadius) - maxRadius = NSWidth(rect) / 2.0; - - if (NSHeight(rect) / 2.0 < maxRadius) - maxRadius = NSHeight(rect) / 2.0; - - NSBezierPath* newPath = [NSBezierPath bezierPath]; - [newPath moveToPoint:NSMakePoint(NSMinX(rect) + maxRadius, NSMinY(rect))]; - - [newPath appendBezierPathWithArcWithCenter:NSMakePoint(NSMaxX(rect) - maxRadius, NSMinY(rect) + maxRadius) - radius:maxRadius startAngle:270.0 endAngle:0.0]; - - [newPath appendBezierPathWithArcWithCenter:NSMakePoint(NSMaxX(rect) - maxRadius, NSMaxY(rect) - maxRadius) - radius:maxRadius startAngle:0.0 endAngle:90.0]; - - [newPath appendBezierPathWithArcWithCenter:NSMakePoint(NSMinX(rect) + maxRadius, NSMaxY(rect) - maxRadius) - radius:maxRadius startAngle:90.0 endAngle:180.0]; - - [newPath appendBezierPathWithArcWithCenter:NSMakePoint(NSMinX(rect) + maxRadius, NSMinY(rect) + maxRadius) - radius:maxRadius startAngle:180.0 endAngle:270.0]; - - [newPath closePath]; - - return newPath; -} - -@end - -#pragma mark - - -// XXX move this to a new file -@interface NSTruncatingTextAndImageCell : NSCell -{ - NSImage *mImage; - NSMutableString *mTruncLabelString; - int mLabelStringWidth; // -1 if not known - float mImagePadding; - float mImageSpace; - float mImageAlpha; -} - -- (id)initTextCell:(NSString*)aString; -- (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView*)controlView; - -- (void)setImagePadding:(float)padding; -- (void)setImageSpace:(float)space; -- (void)setImageAlpha:(float)alpha; - -- (void)setImage:(NSImage *)anImage; -- (NSImage *)image; - -@end - -@implementation NSTruncatingTextAndImageCell - -- (id)initTextCell:(NSString*)aString -{ - if ((self = [super initTextCell:aString])) - { - mLabelStringWidth = -1; - mImagePadding = 0; - mImageSpace = 2; - } - return self; -} - -- (void)dealloc -{ - [mImage release]; - [mTruncLabelString release]; - [super dealloc]; -} - -- copyWithZone:(NSZone *)zone -{ - NSTruncatingTextAndImageCell *cell = (NSTruncatingTextAndImageCell *)[super copyWithZone:zone]; - cell->mImage = [mImage retain]; - cell->mTruncLabelString = nil; - cell->mLabelStringWidth = -1; - return cell; -} - -- (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView*)controlView -{ - NSRect textRect = cellFrame; - NSRect imageRect; - - // we always reserve space for the image, even if there isn't one - // assume the image rect is always square - float imageWidth = NSHeight(cellFrame) - 2 * mImagePadding; - NSDivideRect(cellFrame, &imageRect, &textRect, imageWidth, NSMinXEdge); - - if (mImage) - { - NSRect imageSrcRect = NSZeroRect; - imageSrcRect.size = [mImage size]; - [mImage drawInRect:NSInsetRect(imageRect, mImagePadding, mImagePadding) - fromRect:imageSrcRect operation:NSCompositeSourceOver fraction:mImageAlpha]; - } - - // remove image space - NSDivideRect(textRect, &imageRect, &textRect, mImageSpace, NSMinXEdge); - - int cellWidth = (int)NSWidth(textRect); - NSDictionary *cellAttributes = [[self attributedStringValue] attributesAtIndex:0 effectiveRange:nil]; - - if (mLabelStringWidth != cellWidth || !mTruncLabelString) - { - [mTruncLabelString release]; - mTruncLabelString = [[NSMutableString alloc] initWithString:[self stringValue]]; - [mTruncLabelString truncateToWidth:cellWidth at:kTruncateAtEnd withAttributes:cellAttributes]; - mLabelStringWidth = cellWidth; - } - - [mTruncLabelString drawInRect:textRect withAttributes:cellAttributes]; -} - -- (void)setStringValue:(NSString *)aString -{ - if (![aString isEqualToString:[self stringValue]]) - { - [mTruncLabelString release]; - mTruncLabelString = nil; - } - [super setStringValue:aString]; -} - -- (void)setAttributedStringValue:(NSAttributedString *)attribStr -{ - if (![attribStr isEqualToAttributedString:[self attributedStringValue]]) - { - [mTruncLabelString release]; - mTruncLabelString = nil; - } - [super setAttributedStringValue:attribStr]; -} - -- (void)setImage:(NSImage *)anImage -{ - if (anImage != mImage) - { - [mImage release]; - mImage = [anImage retain]; - } -} - -- (NSImage *)image -{ - return mImage; -} - -- (void)setImagePadding:(float)padding -{ - mImagePadding = padding; -} - -- (void)setImageSpace:(float)space -{ - mImageSpace = space; -} - -- (void)setImageAlpha:(float)alpha -{ - mImageAlpha = alpha; -} - -@end - -#pragma mark - - -// a container view for the items in the tab view item. We use a subclass of -// NSView to handle drag and drop -@interface BrowserTabItemContainerView : NSView -{ - BrowserTabViewItem* mTabViewItem; - NSTruncatingTextAndImageCell* mLabelCell; - - BOOL mIsDropTarget; - BOOL mSelectTabOnMouseUp; -} - -- (NSTruncatingTextAndImageCell*)labelCell; - -- (void)showDragDestinationIndicator; -- (void)hideDragDestinationIndicator; - -@end - -@implementation BrowserTabItemContainerView - -- (id)initWithFrame:(NSRect)frameRect andTabItem:(NSTabViewItem*)tabViewItem -{ - if ( (self = [super initWithFrame:frameRect]) ) - { - mTabViewItem = tabViewItem; - - mLabelCell = [[NSTruncatingTextAndImageCell alloc] init]; - [mLabelCell setControlSize:NSSmallControlSize]; // doesn't work? - [mLabelCell setImagePadding:0.0]; - [mLabelCell setImageSpace:2.0]; - - [self registerForDraggedTypes:[NSArray arrayWithObjects: - @"MozURLType", @"MozBookmarkType", NSStringPboardType, NSFilenamesPboardType, nil]]; - } - return self; -} - -- (void)dealloc -{ - [mLabelCell release]; - [super dealloc]; -} - -- (NSTruncatingTextAndImageCell*)labelCell -{ - return mLabelCell; -} - -- (void)drawRect:(NSRect)aRect -{ - [mLabelCell drawWithFrame:[self bounds] inView:self]; - - if (mIsDropTarget) - { - NSRect hilightRect = NSOffsetRect(NSInsetRect([self bounds], 1.0, 0), -1.0, 0); - NSBezierPath* dropTargetOutline = [NSBezierPath bezierPathWithRoundCorneredRect:hilightRect cornerRadius:4.0]; - [[NSColor colorWithCalibratedWhite:0.0 alpha:0.15] set]; - [dropTargetOutline fill]; - } -} - -- (void)showDragDestinationIndicator -{ - if (!mIsDropTarget) - { - mIsDropTarget = YES; - [self setNeedsDisplay:YES]; - } -} - -- (void)hideDragDestinationIndicator -{ - if (mIsDropTarget) - { - mIsDropTarget = NO; - [self setNeedsDisplay:YES]; - } -} - -- (BOOL)shouldAcceptDragFrom:(id)sender -{ - if ((sender == self) || (sender == mTabViewItem)) - return NO; - - NSWindowController *windowController = [[[mTabViewItem view] window] windowController]; - if ([windowController isMemberOfClass:[BrowserWindowController class]]) - { - if (sender == [windowController proxyIconView]) - return NO; - } - - return YES; -} - - -#pragma mark - - -// NSDraggingDestination destination methods -- (unsigned int)draggingEntered:(id )sender -{ - if (![self shouldAcceptDragFrom:[sender draggingSource]]) - return NSDragOperationNone; - - [self showDragDestinationIndicator]; - return NSDragOperationGeneric; -} - -- (unsigned int)draggingUpdated:(id )sender -{ - if (![self shouldAcceptDragFrom:[sender draggingSource]]) { - [self hideDragDestinationIndicator]; - return NSDragOperationNone; - } - - [self showDragDestinationIndicator]; - return NSDragOperationGeneric; -} - -- (void)draggingExited:(id )sender -{ - [self hideDragDestinationIndicator]; -} - -- (BOOL)prepareForDragOperation:(id )sender -{ - return YES; -} - -- (BOOL)performDragOperation:(id )sender -{ - [self hideDragDestinationIndicator]; - - if (![self shouldAcceptDragFrom:[sender draggingSource]]) - return NO; - - // let the tab view handle it - return [[mTabViewItem tabView] performDragOperation:sender]; -} - -#pragma mark - - -// NSDraggingSource methods - -- (unsigned int)draggingSourceOperationMaskForLocal:(BOOL)flag -{ - return NSDragOperationGeneric; -} - -// NSResponder methods -- (void)mouseDown:(NSEvent *)theEvent -{ - NSRect iconRect = NSMakeRect(0, 0, 16, 16); - NSPoint localPoint = [self convertPoint: [theEvent locationInWindow] fromView: nil]; - - // this is a bit evil. Because the tab view's mouseDown captures the mouse, we'll - // never get to mouseDragged if we allow the next responder (the tab view) to - // handle the mouseDown. This prevents dragging from background tabs. So we break - // things slightly by intercepting the mouseDown on the icon, so that our mouseDragged - // gets called. If the users didn't drag, we select the tab in the mouse up. - if (NSPointInRect(localPoint, iconRect) && [mTabViewItem draggable]) - { - mSelectTabOnMouseUp = YES; - return; // we want dragging - } - - mSelectTabOnMouseUp = NO; - [[self nextResponder] mouseDown:theEvent]; -} - -- (void)mouseUp:(NSEvent *)theEvent -{ - if (mSelectTabOnMouseUp) - { - [[mTabViewItem tabView] selectTabViewItem:mTabViewItem]; - mSelectTabOnMouseUp = NO; - } - - [[self nextResponder] mouseUp:theEvent]; -} - -- (void)mouseDragged:(NSEvent*)theEvent -{ - NSRect iconRect = NSMakeRect(0, 0, 16, 16); - NSPoint localPoint = [self convertPoint: [theEvent locationInWindow] fromView: nil]; - - if (!NSPointInRect(localPoint, iconRect) || ![mTabViewItem draggable]) - { - [[self nextResponder] mouseDragged:theEvent]; - return; - } - - mSelectTabOnMouseUp = NO; - - CHBrowserView* browserView = (CHBrowserView*)[mTabViewItem view]; - - NSString *url = [browserView getCurrentURLSpec]; - NSString *title = [mLabelCell stringValue]; - - NSString *cleanedTitle = [title stringByReplacingCharactersInSet:[NSCharacterSet controlCharacterSet] withString:@" "]; - - NSArray *dataVals = [NSArray arrayWithObjects: url, cleanedTitle, nil]; - NSArray *dataKeys = [NSArray arrayWithObjects: @"url", @"title", nil]; - NSDictionary *data = [NSDictionary dictionaryWithObjects:dataVals forKeys:dataKeys]; - - NSPasteboard *pboard = [NSPasteboard pasteboardWithName:NSDragPboard]; - [pboard declareTypes:[NSArray arrayWithObjects:@"MozURLType", NSURLPboardType, NSStringPboardType, nil] owner:self]; - - // MozURLType - [pboard setPropertyList:data forType: @"MozURLType"]; - // NSURLPboardType type - [[NSURL URLWithString:url] writeToPasteboard: pboard]; - // NSStringPboardType - [pboard setString:url forType: NSStringPboardType]; - - NSPoint dragOrigin = [self frame].origin; - dragOrigin.y += [self frame].size.height; - - [self dragImage: [MainController createImageForDragging:[mLabelCell image] title:title] - at:NSMakePoint(0, 0) offset:NSMakeSize(0, 0) - event:theEvent pasteboard:pboard source:self slideBack:YES]; -} - -@end - -#pragma mark - - -@implementation BrowserTabViewItem - --(id)initWithIdentifier:(id)identifier withTabIcon:(NSImage *)tabIcon -{ - if ( (self = [super initWithIdentifier:identifier withTabIcon:tabIcon]) ) - { - mTabContentsView = [[BrowserTabItemContainerView alloc] - initWithFrame:NSMakeRect(0, 0, 100, 16) andTabItem:self]; - mDraggable = NO; - } - return self; -} - --(id)initWithIdentifier:(id)identifier -{ - return [self initWithIdentifier:identifier withTabIcon:nil]; -} - --(void)dealloc -{ - // We can either be closing a single tab here, in which case we need to remove our view - // from the superview, or the tab view may be closing, in which case it has already - // removed all its subviews. - [mTabContentsView removeFromSuperview]; // may be noop - [mTabContentsView release]; // balance our init - [super dealloc]; -} - -- (NSView*)tabItemContentsView -{ - return mTabContentsView; -} - -- (void)updateTabVisibility:(BOOL)nowVisible -{ - if (nowVisible) - { - if (![mTabContentsView superview]) - [[self tabView] addSubview:mTabContentsView]; - } - else - { - if ([mTabContentsView superview]) - [mTabContentsView removeFromSuperview]; - } -} - -- (void)relocateTabContents:(NSRect)inRect -{ - [mTabContentsView setFrame:inRect]; -} - -- (BOOL)draggable -{ - return mDraggable; -} - --(void)drawLabel:(BOOL)shouldTruncateLabel inRect:(NSRect)tabRect -{ - [self relocateTabContents:tabRect]; - mLastDrawRect = tabRect; -} - -- (NSSize)sizeOfLabel:(BOOL)shouldTruncateLabel -{ - return [super sizeOfLabel:shouldTruncateLabel]; -} - -- (void)setLabel:(NSString *)label -{ - NSAttributedString* labelString = [[NSAttributedString alloc] initWithString:label attributes:mLabelAttributes]; - [[mTabContentsView labelCell] setAttributedStringValue:labelString]; - - [super setLabel:label]; -} - -- (NSString*)label -{ - return [[mTabContentsView labelCell] stringValue]; -} - --(void)setTabIcon:(NSImage *)newIcon -{ - [super setTabIcon:newIcon]; - [[mTabContentsView labelCell] setImage:mTabIcon]; -} - -- (void)setTabIcon:(NSImage *)newIcon isDraggable:(BOOL)draggable -{ - [self setTabIcon:newIcon]; - mDraggable = draggable; - [[mTabContentsView labelCell] setImageAlpha:(draggable ? 1.0 : 0.6)]; -} - -@end diff --git a/mozilla/chimera/BrowserWindow.h b/mozilla/chimera/BrowserWindow.h deleted file mode 100644 index edf19f7664b..00000000000 --- a/mozilla/chimera/BrowserWindow.h +++ /dev/null @@ -1,46 +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): - * Simon Fraser - * - * 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 - -@interface BrowserWindow : NSWindow -{ - IBOutlet id mAutoCompleteTextField; -} - --(BOOL) makeFirstResponder:(NSResponder*) responder; -@end diff --git a/mozilla/chimera/BrowserWindow.mm b/mozilla/chimera/BrowserWindow.mm deleted file mode 100644 index 35f409d4ee6..00000000000 --- a/mozilla/chimera/BrowserWindow.mm +++ /dev/null @@ -1,66 +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): - * Simon Fraser - * - * 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 "BrowserWindow.h" -#import "BrowserWindowController.h" -#import "CHAutoCompleteTextField.h" - -static const int kEscapeKeyCode = 53; - -@implementation BrowserWindow - -- (BOOL)makeFirstResponder:(NSResponder*)responder -{ - NSResponder* oldResponder = [self firstResponder]; - BOOL madeFirstResponder = [super makeFirstResponder:responder]; - if (madeFirstResponder && oldResponder != [self firstResponder]) - [(BrowserWindowController*)[self delegate] focusChangedFrom:oldResponder to:[self firstResponder]]; - return madeFirstResponder; -} - -- (void)sendEvent:(NSEvent *)theEvent -{ - // We need this hack because NSWindow::sendEvent will eat the escape key - // and won't pass it down to the key handler of responders in the window. - // We have to override sendEvent for all of our escape key needs. - if ([theEvent keyCode] == kEscapeKeyCode && [theEvent type] == NSKeyDown && [self firstResponder] == [mAutoCompleteTextField fieldEditor]) - [mAutoCompleteTextField revertText]; - else - [super sendEvent:theEvent]; -} - -@end diff --git a/mozilla/chimera/BrowserWindow.nib/classes.nib b/mozilla/chimera/BrowserWindow.nib/classes.nib deleted file mode 100644 index 8802bdedcfd..00000000000 --- a/mozilla/chimera/BrowserWindow.nib/classes.nib +++ /dev/null @@ -1,162 +0,0 @@ -{ - IBClasses = ( - {CLASS = BookmarkItem; LANGUAGE = ObjC; SUPERCLASS = NSObject; }, - { - ACTIONS = { - addBookmark = id; - addFolder = id; - deleteBookmarks = id; - openBookmarkInNewTab = id; - openBookmarkInNewWindow = id; - showBookmarkInfo = id; - }; - CLASS = BookmarksDataSource; - LANGUAGE = ObjC; - OUTLETS = { - mBrowserWindowController = id; - mDeleteBookmarkButton = id; - mEditBookmarkButton = id; - mOutlineView = id; - }; - SUPERCLASS = NSObject; - }, - {CLASS = BookmarksToolbar; LANGUAGE = ObjC; SUPERCLASS = NSView; }, - {CLASS = BrowserTabView; LANGUAGE = ObjC; SUPERCLASS = NSTabView; }, - { - CLASS = BrowserWindow; - LANGUAGE = ObjC; - OUTLETS = {mAutoCompleteTextField = id; }; - SUPERCLASS = NSWindow; - }, - { - ACTIONS = { - back = id; - bookmarkLink = id; - bookmarkPage = id; - cancelAddBookmarkSheet = id; - cancelLocationSheet = id; - copyLinkLocation = id; - endAddBookmarkSheet = id; - endLocationSheet = id; - forward = id; - goToLocationFromToolbarURLField = id; - home = id; - manageBookmarks = id; - openLinkInNewTab = id; - openLinkInNewWindow = id; - performSearch = id; - printDocument = id; - reload = id; - saveImageAs = id; - saveLinkAs = id; - savePageAs = id; - stop = id; - toggleSidebar = id; - viewOnlyThisImage = id; - viewSource = id; - }; - CLASS = BrowserWindowController; - LANGUAGE = ObjC; - OUTLETS = { - mAddBookmarkCheckbox = NSButton; - mAddBookmarkFolderField = NSPopUpButton; - mAddBookmarkSheetWindow = NSWindow; - mAddBookmarkTitleField = NSTextField; - mBackItem = NSMenuItem; - mCachedBMDS = id; - mForwardItem = NSMenuItem; - mHistoryDataSource = CHHistoryDataSource; - mImageLinkMenu = NSMenu; - mImageMenu = NSMenu; - mInputMenu = NSMenu; - mLinkMenu = NSMenu; - mLocationSheetURLField = NSTextField; - mLocationSheetWindow = NSWindow; - mLocationToolbarView = NSView; - mLock = NSImageView; - mPageMenu = NSMenu; - mPersonalToolbar = CHBookmarksToolbar; - mProgress = NSProgressIndicator; - mProxyIcon = NSImageView; - mSidebarBookmarksDataSource = BookmarksDataSource; - mSidebarBrowserView = id; - mSidebarDrawer = NSDrawer; - mSidebarSourceTabView = NSTabView; - mSidebarTabView = NSTabView; - mStatus = NSTextField; - mStatusBar = NSView; - mTabBrowser = CHExtendedTabView; - mURLBar = NSTextField; - }; - SUPERCLASS = NSWindowController; - }, - {CLASS = CHAutoCompleteDataSource; LANGUAGE = ObjC; SUPERCLASS = NSObject; }, - { - ACTIONS = {onBlur = id; onResize = id; }; - CLASS = CHAutoCompleteTextField; - LANGUAGE = ObjC; - OUTLETS = {mProxyIcon = CHPageProxyIcon; }; - SUPERCLASS = NSTextField; - }, - { - CLASS = CHBookmarksOutlineView; - LANGUAGE = ObjC; - SUPERCLASS = CHExtendedOutlineView; - }, - {CLASS = CHBookmarksToolbar; LANGUAGE = ObjC; SUPERCLASS = NSView; }, - { - ACTIONS = {load = id; }; - CLASS = CHBrowserWrapper; - LANGUAGE = ObjC; - OUTLETS = { - mLockIcon = id; - mWindowController = id; - progress = id; - progressSuper = id; - status = id; - urlbar = id; - }; - SUPERCLASS = NSView; - }, - {CLASS = CHExtendedOutlineView; LANGUAGE = ObjC; SUPERCLASS = NSOutlineView; }, - { - CLASS = CHHistoryDataSource; - LANGUAGE = ObjC; - OUTLETS = {mBrowserWindowController = id; }; - SUPERCLASS = CHRDFOutlineViewDataSource; - }, - {CLASS = CHLocationBar; LANGUAGE = ObjC; SUPERCLASS = NSView; }, - {CLASS = CHPageProxyIcon; LANGUAGE = ObjC; SUPERCLASS = NSImageView; }, - { - CLASS = CHRDFOutlineViewDataSource; - LANGUAGE = ObjC; - OUTLETS = {mOutlineView = id; }; - SUPERCLASS = NSObject; - }, - {CLASS = ExtendedOutlineView; LANGUAGE = ObjC; SUPERCLASS = NSOutlineView; }, - {CLASS = FirstResponder; LANGUAGE = ObjC; SUPERCLASS = NSObject; }, - {CLASS = LocationBar; LANGUAGE = ObjC; SUPERCLASS = NSView; }, - {CLASS = MainController; LANGUAGE = ObjC; SUPERCLASS = NSObject; }, - { - ACTIONS = {load = id; }; - CLASS = MyBrowserView; - LANGUAGE = ObjC; - OUTLETS = { - mImageLinkMenu = id; - mImageMenu = id; - mInputMenu = id; - mLinkMenu = id; - mPageMenu = id; - mWindowController = id; - progress = id; - progressSuper = id; - status = id; - urlbar = id; - }; - SUPERCLASS = NSView; - }, - {CLASS = RDFOutlineViewItem; LANGUAGE = ObjC; SUPERCLASS = NSObject; }, - {CLASS = ThrobberHandler; LANGUAGE = ObjC; SUPERCLASS = NSObject; } - ); - IBVersion = 1; -} \ No newline at end of file diff --git a/mozilla/chimera/BrowserWindow.nib/info.nib b/mozilla/chimera/BrowserWindow.nib/info.nib deleted file mode 100644 index 667fcc69e64..00000000000 --- a/mozilla/chimera/BrowserWindow.nib/info.nib +++ /dev/null @@ -1,49 +0,0 @@ - - - - - IBDocumentLocation - 176 79 632 495 0 0 1280 1002 - IBEditorPositions - - 124 - 345 803 170 144 0 0 1280 1002 - 160 - 524 326 195 666 0 0 1280 1002 - 28 - 524 439 195 457 0 0 1280 1002 - 297 - 233 646 176 162 0 0 1152 848 - 314 - 418 732 139 66 0 0 1152 848 - 336 - 630 666 200 132 0 0 1152 848 - 365 - 22 587 93 162 0 0 1152 848 - 463 - 22 619 200 180 0 0 1152 848 - 56 - 450 634 343 68 0 0 1280 1002 - - IBFramework Version - 248.0 - IBGroupedObjects - - 3 - - 8 - 9 - - - IBLastGroupID - 4 - IBLockedObjects - - IBOpenObjects - - 10 - - IBSystem Version - 5S60 - - diff --git a/mozilla/chimera/BrowserWindow.nib/objects.nib b/mozilla/chimera/BrowserWindow.nib/objects.nib deleted file mode 100644 index d775c7ae2db..00000000000 Binary files a/mozilla/chimera/BrowserWindow.nib/objects.nib and /dev/null differ diff --git a/mozilla/chimera/BrowserWindowController.h b/mozilla/chimera/BrowserWindowController.h deleted file mode 100644 index 1a1c3dd4d29..00000000000 --- a/mozilla/chimera/BrowserWindowController.h +++ /dev/null @@ -1,285 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape 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/NPL/ - * - * 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 mozilla.org 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 NPL, 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 NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#import -#import "CHBrowserWrapper.h" -#import "CHFind.h" -#import "CHBookmarksToolbar.h" - -class nsIDOMEvent; -class nsIDOMNode; - - -// -// ThrobberHandler -// -// A helper class that handles animating the throbber when it's alive. It starts -// automatically when you init it. To get it to stop, call |stopThrobber|. Calling -// |release| is not enough because the timer used to animate the images holds a strong -// ref back to the handler so it won't go away unless you break that cycle manually with -// |stopThrobber|. -// -// This class must be separate from BrowserWindowController else the -// same thing will happen there and the timer will cause it to stay alive and continue -// loading the webpage even though the window has gone away. -// -@interface ThrobberHandler : NSObject -{ - NSTimer* mTimer; - NSArray* mImages; - unsigned int mFrame; -} - -// public -- (id)initWithToolbarItem:(NSToolbarItem*)inButton images:(NSArray*)inImages; -- (void)stopThrobber; - -// internal -- (void)startThrobber; -- (void)pulseThrobber:(id)aSender; - -@end - - -@class BookmarksDataSource; -@class CHHistoryDataSource; -@class BrowserTabView; -@class CHPageProxyIcon; - -@interface BrowserWindowController : NSWindowController -{ - IBOutlet BrowserTabView* mTabBrowser; - IBOutlet NSDrawer* mSidebarDrawer; - IBOutlet NSTabView* mSidebarTabView; - IBOutlet NSTabView* mSidebarSourceTabView; - IBOutlet NSView* mLocationToolbarView; - IBOutlet NSTextField* mURLBar; - IBOutlet NSTextField* mStatus; - IBOutlet NSProgressIndicator* mProgress; - IBOutlet NSImageView* mLock; - IBOutlet NSWindow* mLocationSheetWindow; - IBOutlet NSTextField* mLocationSheetURLField; - IBOutlet NSView* mStatusBar; // contains the status text, progress bar, and lock - IBOutlet CHPageProxyIcon* mProxyIcon; - - IBOutlet id mSidebarBrowserView; // currently unused - IBOutlet BookmarksDataSource* mSidebarBookmarksDataSource; - IBOutlet CHHistoryDataSource* mHistoryDataSource; - - IBOutlet CHBookmarksToolbar* mPersonalToolbar; - - IBOutlet NSWindow* mAddBookmarkSheetWindow; - IBOutlet NSTextField* mAddBookmarkTitleField; - IBOutlet NSPopUpButton* mAddBookmarkFolderField; - IBOutlet NSButton* mAddBookmarkCheckbox; - - // Context menu outlets. - IBOutlet NSMenu* mPageMenu; - IBOutlet NSMenu* mImageMenu; - IBOutlet NSMenu* mInputMenu; - IBOutlet NSMenu* mLinkMenu; - IBOutlet NSMenu* mImageLinkMenu; - - // Context menu item outlets - IBOutlet NSMenuItem* mBackItem; - IBOutlet NSMenuItem* mForwardItem; - - NSToolbarItem* mSidebarToolbarItem; - - BOOL mInitialized; - NSString* mPendingURL; - NSString* mPendingReferrer; - BOOL mPendingActivate; - - CHBrowserWrapper* mBrowserView; - - BOOL mMoveReentrant; - NSModalSession mModalSession; - - BOOL mShouldAutosave; - BOOL mShouldLoadHomePage; - - BOOL mDrawerCachedFrame; - NSRect mCachedFrameBeforeDrawerOpen; // This is used by the drawer to figure out if the window should - // be returned to its original position when the drawer closes. - NSRect mCachedFrameAfterDrawerOpen; - - unsigned int mChromeMask; // Indicates which parts of the window to show (e.g., don't show toolbars) - - // Context menu members. - int mContextMenuFlags; - nsIDOMEvent* mContextMenuEvent; - nsIDOMNode* mContextMenuNode; - - // Cached bookmark ds used when adding through a sheet - id mCachedBMDS; - - // Throbber state variables. - ThrobberHandler* mThrobberHandler; - NSArray* mThrobberImages; - - // Funky field editor for URL bar - NSTextView *mURLFieldEditor; -} - -- (void)dealloc; - -- (id)getTabBrowser; -- (BOOL)newTabsAllowed; -- (CHBrowserWrapper*)getBrowserWrapper; - -- (void)loadURL:(NSString*)aURLSpec referrer:(NSString*)aReferrer activate:(BOOL)activate; -- (void)updateLocationFields:(NSString *)locationString; -- (void)updateSiteIcons:(NSImage *)siteIconImage; -- (void)updateToolbarItems; -- (void)focusURLBar; - - // call to update the image of the lock icon with a value from nsIWebProgressListener -- (void)updateLock:(unsigned int)securityState; - -- (void)performAppropriateLocationAction; -- (IBAction)goToLocationFromToolbarURLField:(id)sender; -- (void)beginLocationSheet; -- (IBAction)endLocationSheet:(id)sender; -- (IBAction)cancelLocationSheet:(id)sender; - -- (IBAction)cancelAddBookmarkSheet:(id)sender; -- (IBAction)endAddBookmarkSheet:(id)sender; -- (void)cacheBookmarkDS: (id)aDS; - -- (NSSize)windowWillResize:(NSWindow *)sender toSize:(NSSize)proposedFrameSize; - -- (IBAction)viewSource:(id)aSender; - -- (void)saveDocument: (NSView*)aFilterView filterList: (NSPopUpButton*)aFilterList; -- (void)saveURL: (NSView*)aFilterView filterList: (NSPopUpButton*)aFilterList - url: (NSString*)aURLSpec suggestedFilename: (NSString*)aFilename; -- (IBAction)printDocument:(id)aSender; -- (void)printPreview; -- (IBAction)performSearch:(id)aSender; - -- (void)startThrobber; -- (void)stopThrobber; -- (void)clickThrobber:(id)aSender; - -- (void)biggerTextSize; -- (void)smallerTextSize; -- (void)getInfo:(id)sender; - -- (BOOL)canGetInfo; - -- (BOOL)shouldShowBookmarkToolbar; - -- (void)addBookmarkExtended: (BOOL)aIsFromMenu isFolder:(BOOL)aIsFolder URL:(NSString*)aURL title:(NSString*)aTitle; -- (IBAction)manageBookmarks: (id)aSender; -- (void)importBookmarks: (NSString*)aURLSpec; -- (IBAction)toggleSidebar:(id)aSender; -- (BOOL)bookmarksAreVisible:(BOOL)inRequireSelection; - -- (void)newTab:(BOOL)allowHomepage; -- (void)closeTab; -- (void)previousTab; -- (void)nextTab; - -- (IBAction)back:(id)aSender; -- (IBAction)forward:(id)aSender; -- (IBAction)reload:(id)aSender; -- (IBAction)stop:(id)aSender; -- (IBAction)home:(id)aSender; - --(void)enterModalSession; - --(void)openNewWindowWithURL: (NSString*)aURLSpec referrer:(NSString*)aReferrer loadInBackground: (BOOL)aLoadInBG; --(void)openNewWindowWithGroup: (nsIDOMElement*)aFolderElement loadInBackground: (BOOL)aLoadInBG; --(void)openNewTabWithURL: (NSString*)aURLSpec referrer: (NSString*)aReferrer loadInBackground: (BOOL)aLoadInBG; - --(void)autosaveWindowFrame; --(void)disableAutosave; --(void)disableLoadPage; - --(void)setChromeMask:(unsigned int)aMask; --(unsigned int)chromeMask; - --(id)getAddBookmarkSheetWindow; --(id)getAddBookmarkTitle; --(id)getAddBookmarkFolder; --(id)getAddBookmarkCheckbox; - -// Called when a context menu should be shown. -- (void)onShowContextMenu:(int)flags domEvent:(nsIDOMEvent*)aEvent domNode:(nsIDOMNode*)aNode; -- (NSMenu*)getContextMenu; - -// Context menu methods -- (IBAction)openLinkInNewWindow:(id)aSender; -- (IBAction)openLinkInNewTab:(id)aSender; -- (void)openLinkInNewWindowOrTab: (BOOL)aUseWindow; - -- (IBAction)savePageAs:(id)aSender; -- (IBAction)saveLinkAs:(id)aSender; -- (IBAction)saveImageAs:(id)aSender; - -- (IBAction)bookmarkPage: (id)aSender; -- (IBAction)bookmarkLink: (id)aSender; - -- (IBAction)copyLinkLocation:(id)aSender; - -- (IBAction)viewOnlyThisImage:(id)aSender; - -- (CHBookmarksToolbar*) bookmarksToolbar; - -- (BOOL) isResponderGeckoView:(NSResponder*) responder; - -// called when the internal window focus has changed -// this allows us to dispatch activate and deactivate events as necessary -- (void) focusChangedFrom:(NSResponder*) oldResponder to:(NSResponder*) newResponder; - -// Called to get cached versions of our security icons -+ (NSImage*) insecureIcon; -+ (NSImage*) secureIcon; -+ (NSImage*) brokenIcon; - -// cache the toolbar defaults we parse from a plist -+ (NSArray*) toolbarDefaults; - -// Accessor to get the sidebar drawer -- (NSDrawer *)sidebarDrawer; - -// Accessor to get the proxy icon view -- (CHPageProxyIcon *)proxyIconView; - -@end - diff --git a/mozilla/chimera/BrowserWindowController.mm b/mozilla/chimera/BrowserWindowController.mm deleted file mode 100644 index 2005de8af26..00000000000 --- a/mozilla/chimera/BrowserWindowController.mm +++ /dev/null @@ -1,1623 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape 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/NPL/ - * - * 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 mozilla.org 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 NPL, 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 NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#import "NSString+Utils.h" - -#import "BrowserWindowController.h" - -#import "CHBrowserWrapper.h" -#import "CHPreferenceManager.h" -#import "BookmarksDataSource.h" -#import "CHHistoryDataSource.h" -#import "BrowserTabView.h" -#import "CHUserDefaults.h" -#import "CHPageProxyIcon.h" - -#include "nsIWebNavigation.h" -#include "nsIDOMElement.h" -#include "nsIDOMEvent.h" -#include "nsIPrefBranch.h" -#include "nsIContextMenuListener.h" -#include "nsIDOMWindow.h" -#include "nsIScriptGlobalObject.h" -#include "nsIDocShell.h" -#include "nsIMarkupDocumentViewer.h" -#include "nsIContentViewer.h" -#include "nsCocoaBrowserService.h" -#include "nsString.h" -#include "nsCRT.h" -#include "CHGeckoUtils.h" -#include "nsIWebProgressListener.h" -#include "nsIWebBrowserChrome.h" - -#include "nsIClipboardCommands.h" -#include "nsIWebBrowser.h" -#include "nsIInterfaceRequestorUtils.h" -#include "nsIPrefBranch.h" -#include "nsIServiceManagerUtils.h" - -#include - -static NSString *BrowserToolbarIdentifier = @"Browser Window Toolbar"; -static NSString *BackToolbarItemIdentifier = @"Back Toolbar Item"; -static NSString *ForwardToolbarItemIdentifier = @"Forward Toolbar Item"; -static NSString *ReloadToolbarItemIdentifier = @"Reload Toolbar Item"; -static NSString *StopToolbarItemIdentifier = @"Stop Toolbar Item"; -static NSString *HomeToolbarItemIdentifier = @"Home Toolbar Item"; -static NSString *LocationToolbarItemIdentifier = @"Location Toolbar Item"; -static NSString *SidebarToolbarItemIdentifier = @"Sidebar Toolbar Item"; -static NSString *PrintToolbarItemIdentifier = @"Print Toolbar Item"; -static NSString *ThrobberToolbarItemIdentifier = @"Throbber Toolbar Item"; -static NSString *SearchToolbarItemIdentifier = @"Search Toolbar Item"; -static NSString *ViewSourceToolbarItemIdentifier = @"View Source Toolbar Item"; - -static NSString *NavigatorWindowFrameSaveName = @"NavigatorWindow"; - -// Cached toolbar defaults read in from a plist. If null, we'll use -// hardcoded defaults. -static NSArray* sToolbarDefaults = nil; - -#define kMaxBrowserWindowTabs 16 - -@interface BrowserWindowController(Private) -- (void)setupToolbar; -- (void)setupSidebarTabs; -@end - -@implementation BrowserWindowController - -// -// enterModalSession -// -// We have to load the window synchronously so windows coming from a JS -// window.open() can be inspected or modified inline in JS. The way we -// force this is by pretending we're a modal dialog just up to the point -// where we finish creating the window. -// -// This is icky, and there are several bugs that are caused by this hack -// (bugzilla 159410, 159661) -// --(void)enterModalSession -{ - mModalSession = [NSApp beginModalSessionForWindow: [self window]]; - [NSApp runModalSession: mModalSession]; - [NSApp endModalSession: mModalSession]; - mModalSession = nil; -} - -- (BOOL)isResponderGeckoView:(NSResponder*) responder -{ - return ([responder isKindOfClass:[NSView class]] && - [(NSView*)responder isDescendantOf:[mBrowserView getBrowserView]]); -} - -- (void)windowDidBecomeKey:(NSNotification *)notification -{ - BOOL windowWithMultipleTabs = ([mTabBrowser numberOfTabViewItems] > 1); - // When this window gets focus, fix the Close Window modifiers depending - // on whether we have multiple tabs - [[NSApp delegate] adjustCloseTabMenuItemKeyEquivalent:windowWithMultipleTabs]; - [[NSApp delegate] adjustCloseWindowMenuItemKeyEquivalent:windowWithMultipleTabs]; - - if ([self isResponderGeckoView:[[self window] firstResponder]]) { - CHBrowserView* browserView = [mBrowserView getBrowserView]; - if (browserView) - [browserView setActive:YES]; - } -} - -- (void)windowDidResignKey:(NSNotification *)notification -{ - // when we are no longer the key window, set the Close shortcut back - // to Command-W, for other windows. - [[NSApp delegate] adjustCloseTabMenuItemKeyEquivalent:NO]; - [[NSApp delegate] adjustCloseWindowMenuItemKeyEquivalent:NO]; - - if ([self isResponderGeckoView:[[self window] firstResponder]]) { - CHBrowserView* browserView = [mBrowserView getBrowserView]; - if (browserView) - [browserView setActive:NO]; - } -} - -- (void)windowDidBecomeMain:(NSNotification *)notification -{ - // we have to manually enable/disable the bookmarks menu items, because we - // turn autoenabling off for that menu - [[NSApp delegate] adjustBookmarksMenuItemsEnabling:YES]; -} - -- (void)windowDidResignMain:(NSNotification *)notification -{ - // we have to manually enable/disable the bookmarks menu items, because we - // turn autoenabling off for that menu - [[NSApp delegate] adjustBookmarksMenuItemsEnabling:NO]; -} - - --(void)mouseMoved:(NSEvent*)aEvent -{ - if (mMoveReentrant) - return; - - mMoveReentrant = YES; - NSView* view = [[[self window] contentView] hitTest: [aEvent locationInWindow]]; - [view mouseMoved: aEvent]; - [super mouseMoved: aEvent]; - mMoveReentrant = NO; -} - -- (id)initWithWindowNibName:(NSString *)windowNibName -{ - if ( (self = [super initWithWindowNibName:(NSString *)windowNibName]) ) { - // this won't correctly cascade windows on multiple monitors. RADAR bug 2972893 - // filed since it also happens in Terminal.app - if ( nsCocoaBrowserService::sNumBrowsers == 0 ) - [self setShouldCascadeWindows:NO]; - else - [self setShouldCascadeWindows:YES]; - mInitialized = NO; - mMoveReentrant = NO; - mShouldAutosave = YES; - mShouldLoadHomePage = YES; - mChromeMask = 0; - mContextMenuFlags = 0; - mContextMenuEvent = nsnull; - mContextMenuNode = nsnull; - mThrobberImages = nil; - mThrobberHandler = nil; - mURLFieldEditor = nil; - } - return self; -} - --(void)autosaveWindowFrame -{ - if (mShouldAutosave) - [[self window] saveFrameUsingName: NavigatorWindowFrameSaveName]; -} - --(void)disableAutosave -{ - mShouldAutosave = NO; -} - --(void)disableLoadPage -{ - mShouldLoadHomePage = NO; -} - -- (void)windowWillClose:(NSNotification *)notification -{ -#if DEBUG - NSLog(@"Window will close notification."); -#endif - [mSidebarBookmarksDataSource windowClosing]; - - [self autosaveWindowFrame]; - [self autorelease]; -} - -- (void)dealloc -{ -#if DEBUG - NSLog(@"Browser controller died."); -#endif - - // Loop over all tabs, and tell them that the window is closed. - int numTabs = [mTabBrowser numberOfTabViewItems]; - for (int i = 0; i < numTabs; i++) { - NSTabViewItem* item = [mTabBrowser tabViewItemAtIndex: i]; - [[item view] windowClosed]; - } - - //if (mSidebarBrowserView) - // [mSidebarBrowserView windowClosed]; - - [mProgress release]; - - [self stopThrobber]; - [mThrobberImages release]; - [mURLFieldEditor release]; - - [super dealloc]; -} - -- (void)windowDidLoad -{ - [super windowDidLoad]; - - // hide the resize control if specified by the chrome mask - if ( mChromeMask && !(mChromeMask & nsIWebBrowserChrome::CHROME_WINDOW_RESIZE) ) - [[self window] setShowsResizeIndicator:NO]; - - if ( mChromeMask && !(mChromeMask & nsIWebBrowserChrome::CHROME_STATUSBAR) ) { - // remove the status bar at the bottom and adjust the height of the content area. - float height = [mStatusBar frame].size.height; - [mStatusBar removeFromSuperview]; - [mTabBrowser setFrame:NSMakeRect([mTabBrowser frame].origin.x, [mTabBrowser frame].origin.y - height, - [mTabBrowser frame].size.width, [mTabBrowser frame].size.height + height)]; - - // clear out everything in the status bar we were holding on to. This will cause us to - // pass nil for these status items into the CHBrowserwWrapper which is what we want. We'll - // crash if we give them things that have gone away. - mProgress = nil; - mStatus = nil; - mLock = nil; - } - else { - // Retain with a single extra refcount. This allows the CHBrowserWrappers - // to remove the progress meter from its superview without having to - // worry about retaining and releasing it. - [mProgress retain]; - } - - // Get our saved dimensions. - [[self window] setFrameUsingName: NavigatorWindowFrameSaveName]; - - if (mModalSession) - [NSApp stopModal]; - - mInitialized = YES; - - mDrawerCachedFrame = NO; - - [[self window] setAcceptsMouseMovedEvents: YES]; - - [self setupToolbar]; - - // set an upper limit on the number of tabs per window - [mTabBrowser setMaxNumberOfTabs: kMaxBrowserWindowTabs]; - -// 03/03/2002 mlj Changing strategy a bit here. The addTab: method was -// duplicating a lot of the code found here. I have moved it to that method. -// We now remove the IB tab, then add one of our own. - - [mTabBrowser removeTabViewItem:[mTabBrowser tabViewItemAtIndex:0]]; - - // create ourselves a new tab and fill it with the appropriate content. If we - // have a URL pending to be opened here, don't load anything in it, otherwise, - // load the homepage if that's what the user wants (or about:blank). - [self newTab:(!mPendingURL && mShouldLoadHomePage)]; - - // we have a url "pending" from the "open new window with link" command. Deal - // with it now that everything is loaded. - if (mPendingURL) { - if (mShouldLoadHomePage) - [self loadURL: mPendingURL referrer:mPendingReferrer activate:mPendingActivate]; - [mPendingURL release]; - [mPendingReferrer release]; - mPendingURL = mPendingReferrer = nil; - } - - [mSidebarDrawer setDelegate: self]; - - [self setupSidebarTabs]; - - [mPersonalToolbar initializeToolbar]; - if ( mChromeMask && !(mChromeMask & nsIWebBrowserChrome::CHROME_PERSONAL_TOOLBAR) ) { - // remove the personal toolbar and adjust the content area upwards. Removing it - // from the parent view releases it, so we have to clear out the member var. - float height = [mPersonalToolbar frame].size.height; - [mPersonalToolbar removeFromSuperview]; - [mTabBrowser setFrame:NSMakeRect([mTabBrowser frame].origin.x, [mTabBrowser frame].origin.y, - [mTabBrowser frame].size.width, [mTabBrowser frame].size.height + height)]; - mPersonalToolbar = nil; - } - else if (![self shouldShowBookmarkToolbar]) { - [mPersonalToolbar showBookmarksToolbar:NO]; - } -} - -- (NSSize)windowWillResize:(NSWindow *)sender toSize:(NSSize)proposedFrameSize -{ - //if ( mChromeMask && !(mChromeMask & nsIWebBrowserChrome::CHROME_WINDOW_RESIZE) ) - // return [[self window] frame].size; - return proposedFrameSize; -} - - -#define RESIZE_WINDOW_FOR_DRAWER - -- (void)drawerWillOpen: (NSNotification*)aNotification -{ - [mSidebarBookmarksDataSource ensureBookmarks]; - [mHistoryDataSource ensureDataSourceLoaded]; - -#ifdef RESIZE_WINDOW_FOR_DRAWER - // Force the window to shrink and move if necessary in order to accommodate the sidebar. - NSRect screenFrame = [[[self window] screen] visibleFrame]; - NSRect windowFrame = [[self window] frame]; - NSSize drawerSize = [mSidebarDrawer contentSize]; - int fudgeFactor = 12; // Not sure how to get the drawer's border info, so we fudge it for now. - drawerSize.width += fudgeFactor; - if (windowFrame.origin.x + windowFrame.size.width + drawerSize.width > - screenFrame.origin.x + screenFrame.size.width) { - // We need to adjust the window so that it can fit. - float shrinkDelta = (windowFrame.size.width + drawerSize.width) - screenFrame.size.width; - if (shrinkDelta < 0) shrinkDelta = 0; - float newWidth = (windowFrame.size.width - shrinkDelta); - float newPosition = screenFrame.size.width - newWidth - drawerSize.width; - if (newPosition < 0) newPosition = 0; - mCachedFrameBeforeDrawerOpen = windowFrame; - windowFrame.origin.x = newPosition; - windowFrame.size.width = newWidth; - mCachedFrameAfterDrawerOpen = windowFrame; - [[self window] setFrame: windowFrame display: YES animate:NO]; // animation would be nice, but is too slow - mDrawerCachedFrame = YES; - } -#endif - -} - -- (void)drawerDidOpen:(NSNotification *)aNotification -{ - // XXXdwh This is temporary. - // [[mSidebarBrowserView getBrowserView] loadURI: @"http://tinderbox.mozilla.org/SeaMonkey/panel.html" referrer: nil flags:NSLoadFlagsNone]; - - // Toggle the sidebar icon. - if(mSidebarToolbarItem) - [mSidebarToolbarItem setImage:[NSImage imageNamed:@"sidebarOpened"]]; -} - -- (void)drawerDidClose:(NSNotification *)aNotification -{ - // Unload the Gecko web page in "My Panels" to save memory. - if(mSidebarToolbarItem) - [mSidebarToolbarItem setImage:[NSImage imageNamed:@"sidebarClosed"]]; - - // XXXdwh ignore for now. - // [[mSidebarBrowserView getBrowserView] loadURI: @"about:blank" referrer:nil flags:NSLoadFlagsNone]; - -#ifdef RESIZE_WINDOW_FOR_DRAWER - if (mDrawerCachedFrame) { - mDrawerCachedFrame = NO; - NSRect frame = [[self window] frame]; - if (frame.origin.x == mCachedFrameAfterDrawerOpen.origin.x && - frame.origin.y == mCachedFrameAfterDrawerOpen.origin.y && - frame.size.width == mCachedFrameAfterDrawerOpen.size.width && - frame.size.height == mCachedFrameAfterDrawerOpen.size.height) { -#if 0 - printf("Got here too.\n"); - printf("Xes are %f %f\n", frame.origin.x, mCachedFrameAfterDrawerOpen.origin.x); - printf("Widths are %f %f\n", frame.size.width, mCachedFrameAfterDrawerOpen.size.width); -#endif - // Restore the original frame. - [[self window] setFrame: mCachedFrameBeforeDrawerOpen display: YES animate:NO]; // animation would be nice - } - } -#endif - -} - -- (void)setupToolbar -{ - if ( !mChromeMask || (mChromeMask & nsIWebBrowserChrome::CHROME_TOOLBAR) ) { - NSToolbar *toolbar = [[[NSToolbar alloc] initWithIdentifier:BrowserToolbarIdentifier] autorelease]; - - [toolbar setDisplayMode:NSToolbarDisplayModeDefault]; - [toolbar setAllowsUserCustomization:YES]; - [toolbar setAutosavesConfiguration:YES]; - [toolbar setDelegate:self]; - [[self window] setToolbar:toolbar]; - } -} - - -// -// toolbarWillAddItem: (toolbar delegate method) -// -// Called when a button is about to be added to a toolbar. This is where we should -// cache items we may need later. For instance, we want to hold onto the sidebar -// toolbar item so we can change it when the drawer opens and closes. -// -- (void)toolbarWillAddItem:(NSNotification *)notification -{ - NSToolbarItem* item = [[notification userInfo] objectForKey:@"item"]; - if ( [[item itemIdentifier] isEqual:SidebarToolbarItemIdentifier] ) - mSidebarToolbarItem = item; -} - -// -// toolbarDidRemoveItem: (toolbar delegate method) -// -// Called when a button is about to be removed from a toolbar. This is where we should -// uncache items so we don't access them after they're gone. For instance, we want to -// clear our ref to the sidebar toolbar item. -// -- (void)toolbarDidRemoveItem:(NSNotification *)notification -{ - NSToolbarItem* item = [[notification userInfo] objectForKey:@"item"]; - if ( [[item itemIdentifier] isEqual:SidebarToolbarItemIdentifier] ) - mSidebarToolbarItem = nil; - else if ( [[item itemIdentifier] isEqual:ThrobberToolbarItemIdentifier] ) - [self stopThrobber]; -} - -- (NSArray *)toolbarAllowedItemIdentifiers:(NSToolbar *)toolbar -{ - return [NSArray arrayWithObjects: BackToolbarItemIdentifier, - ForwardToolbarItemIdentifier, - ReloadToolbarItemIdentifier, - StopToolbarItemIdentifier, - HomeToolbarItemIdentifier, - LocationToolbarItemIdentifier, - SidebarToolbarItemIdentifier, - ThrobberToolbarItemIdentifier, - SearchToolbarItemIdentifier, - PrintToolbarItemIdentifier, - ViewSourceToolbarItemIdentifier, - NSToolbarCustomizeToolbarItemIdentifier, - NSToolbarFlexibleSpaceItemIdentifier, - NSToolbarSpaceItemIdentifier, - NSToolbarSeparatorItemIdentifier, - nil]; -} - - -// -// + toolbarDefaults -// -// Parse a plist called "ToolbarDefaults.plist" in our Resources subfolder. This -// allows anyone to easily customize the default set w/out having to recompile. We -// hold onto the list for the duration of the app to avoid reparsing it every -// time. -// -+ (NSArray*) toolbarDefaults -{ - if ( !sToolbarDefaults ) { - sToolbarDefaults = [NSArray arrayWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"ToolbarDefaults" ofType:@"plist"]]; - [sToolbarDefaults retain]; - } - return sToolbarDefaults; -} - - -- (NSArray *)toolbarDefaultItemIdentifiers:(NSToolbar *)toolbar -{ - // try to get the defaults from the plist, but if not, hardcode something so - // the user always has a toolbar. - NSArray* defaults = [BrowserWindowController toolbarDefaults]; - NS_ASSERTION(defaults, "Couldn't load toolbar defaults from plist"); - return ( defaults ? defaults : [NSArray arrayWithObjects: BackToolbarItemIdentifier, - ForwardToolbarItemIdentifier, - ReloadToolbarItemIdentifier, - StopToolbarItemIdentifier, - LocationToolbarItemIdentifier, - SidebarToolbarItemIdentifier, - nil] ); -} - -// XXX use a dictionary to speed up the following? - -- (NSToolbarItem *) toolbar:(NSToolbar *)toolbar - itemForItemIdentifier:(NSString *)itemIdent - willBeInsertedIntoToolbar:(BOOL)willBeInserted -{ - NSToolbarItem *toolbarItem = [[[NSToolbarItem alloc] initWithItemIdentifier:itemIdent] autorelease]; - if ( [itemIdent isEqual:BackToolbarItemIdentifier] ) { - [toolbarItem setLabel:@"Back"]; - [toolbarItem setPaletteLabel:@"Go Back"]; - [toolbarItem setToolTip:@"Go back one page"]; - [toolbarItem setImage:[NSImage imageNamed:@"back"]]; - [toolbarItem setTarget:self]; - [toolbarItem setAction:@selector(back:)]; - } else if ( [itemIdent isEqual:ForwardToolbarItemIdentifier] ) { - [toolbarItem setLabel:@"Forward"]; - [toolbarItem setPaletteLabel:@"Go Forward"]; - [toolbarItem setToolTip:@"Go forward one page"]; - [toolbarItem setImage:[NSImage imageNamed:@"forward"]]; - [toolbarItem setTarget:self]; - [toolbarItem setAction:@selector(forward:)]; - } else if ( [itemIdent isEqual:ReloadToolbarItemIdentifier] ) { - [toolbarItem setLabel:@"Reload"]; - [toolbarItem setPaletteLabel:@"Reload Page"]; - [toolbarItem setToolTip:@"Reload current page"]; - [toolbarItem setImage:[NSImage imageNamed:@"reload"]]; - [toolbarItem setTarget:self]; - [toolbarItem setAction:@selector(reload:)]; - } else if ( [itemIdent isEqual:StopToolbarItemIdentifier] ) { - [toolbarItem setLabel:@"Stop"]; - [toolbarItem setPaletteLabel:@"Stop Loading"]; - [toolbarItem setToolTip:@"Stop loading this page"]; - [toolbarItem setImage:[NSImage imageNamed:@"stop"]]; - [toolbarItem setTarget:self]; - [toolbarItem setAction:@selector(stop:)]; - } else if ( [itemIdent isEqual:HomeToolbarItemIdentifier] ) { - [toolbarItem setLabel:@"Home"]; - [toolbarItem setPaletteLabel:@"Go Home"]; - [toolbarItem setToolTip:@"Go to home page"]; - [toolbarItem setImage:[NSImage imageNamed:@"home"]]; - [toolbarItem setTarget:self]; - [toolbarItem setAction:@selector(home:)]; - } else if ( [itemIdent isEqual:SidebarToolbarItemIdentifier] ) { - [toolbarItem setLabel:@"Sidebar"]; - [toolbarItem setPaletteLabel:@"Toggle Sidebar"]; - [toolbarItem setToolTip:@"Show or hide the Sidebar"]; - [toolbarItem setImage:[NSImage imageNamed:@"sidebarClosed"]]; - [toolbarItem setTarget:self]; - [toolbarItem setAction:@selector(toggleSidebar:)]; - } else if ( [itemIdent isEqual:SearchToolbarItemIdentifier] ) { - [toolbarItem setLabel:@"Search"]; - [toolbarItem setPaletteLabel:@"Search"]; - [toolbarItem setToolTip:@"Search the Internet"]; - [toolbarItem setImage:[NSImage imageNamed:@"saveShowFile.tif"]]; - [toolbarItem setTarget:self]; - [toolbarItem setAction:@selector(performSearch:)]; - } else if ( [itemIdent isEqual:ThrobberToolbarItemIdentifier] ) { - [toolbarItem setLabel:@""]; - [toolbarItem setPaletteLabel:@"Progress"]; - [toolbarItem setToolTip:NSLocalizedStringFromTable(@"ThrobberPageDefault", @"WebsiteDefaults", nil)]; - [toolbarItem setImage:[NSImage imageNamed:@"throbber-01"]]; - [toolbarItem setTarget:self]; - [toolbarItem setTag:'Thrb']; - [toolbarItem setAction:@selector(clickThrobber:)]; - } else if ( [itemIdent isEqual:LocationToolbarItemIdentifier] ) { - - NSMenuItem *menuFormRep = [[[NSMenuItem alloc] init] autorelease]; - - [toolbarItem setLabel:@"Location"]; - [toolbarItem setPaletteLabel:@"Location"]; - [toolbarItem setView:mLocationToolbarView]; - [toolbarItem setMinSize:NSMakeSize(128,32)]; - [toolbarItem setMaxSize:NSMakeSize(2560,32)]; - - [menuFormRep setTarget:self]; - [menuFormRep setAction:@selector(performAppropriateLocationAction)]; - [menuFormRep setTitle:[toolbarItem label]]; - - [toolbarItem setMenuFormRepresentation:menuFormRep]; - } else if ( [itemIdent isEqual:PrintToolbarItemIdentifier] ) { - [toolbarItem setLabel:@"Print"]; - [toolbarItem setPaletteLabel:@"Print"]; - [toolbarItem setToolTip:@"Print this page"]; - [toolbarItem setImage:[NSImage imageNamed:@"print"]]; - [toolbarItem setTarget:self]; - [toolbarItem setAction:@selector(printDocument:)]; - } else if ( [itemIdent isEqual:ViewSourceToolbarItemIdentifier] ) { - [toolbarItem setLabel:@"View Source"]; - [toolbarItem setPaletteLabel:@"View Page Source"]; - [toolbarItem setToolTip:@"Display the HTML source of this page"]; - [toolbarItem setImage:[NSImage imageNamed:@"showsource"]]; - [toolbarItem setTarget:self]; - [toolbarItem setAction:@selector(viewSource:)]; - } else { - toolbarItem = nil; - } - - return toolbarItem; -} - -// This method handles the enabling/disabling of the toolbar buttons. -- (BOOL)validateToolbarItem:(NSToolbarItem *)theItem -{ - // Check the action and see if it matches. - SEL action = [theItem action]; - //NSLog(@"Validating toolbar item %@ with selector %s", [theItem label], action); - if (action == @selector(back:)) - return [[mBrowserView getBrowserView] canGoBack]; - else if (action == @selector(forward:)) - return [[mBrowserView getBrowserView] canGoForward]; - else if (action == @selector(reload:)) - return [mBrowserView isBusy] == NO; - else if (action == @selector(stop:)) - return [mBrowserView isBusy]; - else - return YES; -} - -- (void)updateToolbarItems -{ - [[[self window] toolbar] validateVisibleItems]; -} - -- (void)performAppropriateLocationAction -{ - NSToolbar *toolbar = [[self window] toolbar]; - if ( [toolbar isVisible] ) { - if ( ([[[self window] toolbar] displayMode] == NSToolbarDisplayModeIconAndLabel) || - ([[[self window] toolbar] displayMode] == NSToolbarDisplayModeIconOnly) ) { - NSArray *itemsWeCanSee = [toolbar visibleItems]; - - for (unsigned int i=0;i<[itemsWeCanSee count];i++) { - if ([[[itemsWeCanSee objectAtIndex:i] itemIdentifier] isEqual:LocationToolbarItemIdentifier]) { - [self focusURLBar]; - return; - } - } - } - } - - [self beginLocationSheet]; -} - -- (void)focusURLBar -{ - [mURLBar selectText: self]; -} - -- (void)beginLocationSheet -{ - [NSApp beginSheet: mLocationSheetWindow - modalForWindow: [self window] - modalDelegate: nil - didEndSelector: nil - contextInfo: nil]; -} - -- (IBAction)endLocationSheet:(id)sender -{ - [mLocationSheetWindow orderOut:self]; - [NSApp endSheet:mLocationSheetWindow returnCode:1]; - [self loadURL:[mLocationSheetURLField stringValue] referrer:nil activate:YES]; -} - -- (IBAction)cancelLocationSheet:(id)sender -{ - [mLocationSheetWindow orderOut:self]; - [NSApp endSheet:mLocationSheetWindow returnCode:0]; -} - --(IBAction)cancelAddBookmarkSheet:(id)sender -{ - [mAddBookmarkSheetWindow orderOut:self]; - [NSApp endSheet:mAddBookmarkSheetWindow returnCode:0]; - [mCachedBMDS endAddBookmark: 0]; -} - --(IBAction)endAddBookmarkSheet:(id)sender -{ - [mAddBookmarkSheetWindow orderOut:self]; - [NSApp endSheet:mAddBookmarkSheetWindow returnCode:0]; - [mCachedBMDS endAddBookmark: 1]; -} - -- (void)cacheBookmarkDS: (id)aDS -{ - mCachedBMDS = aDS; -} - --(IBAction)manageBookmarks: (id)aSender -{ - if ([mSidebarDrawer state] == NSDrawerClosedState) - [self toggleSidebar: self]; - - [mSidebarTabView selectFirstTabViewItem:self]; -} - -- (void)importBookmarks: (NSString*)aURLSpec -{ - // Open the bookmarks sidebar. - [self manageBookmarks: self]; - - // Now do the importing. - CHBrowserWrapper* newView = [[[CHBrowserWrapper alloc] initWithTab: nil andWindow: [self window]] autorelease]; - [newView setFrame: NSZeroRect]; - [newView setIsBookmarksImport: YES]; - [[[self window] contentView] addSubview: newView]; - [newView loadURI:aURLSpec referrer: nil flags:NSLoadFlagsNone activate:NO]; -} - -- (IBAction)goToLocationFromToolbarURLField:(id)sender -{ - // trim off any whitespace around url - NSMutableString *theURL = [[NSMutableString alloc] initWithString:[sender stringValue]]; - CFStringTrimWhitespace((CFMutableStringRef)theURL); - [self loadURL:theURL referrer:nil activate:YES]; - [theURL release]; -} - -- (void)saveDocument: (NSView*)aFilterView filterList: (NSPopUpButton*)aFilterList -{ - [[mBrowserView getBrowserView] saveDocument: aFilterView filterList: aFilterList]; -} - -- (void)saveURL: (NSView*)aFilterView filterList: (NSPopUpButton*)aFilterList - url: (NSString*)aURLSpec suggestedFilename: (NSString*)aFilename -{ - [[mBrowserView getBrowserView] saveURL: aFilterView filterList: aFilterList - url: aURLSpec suggestedFilename: aFilename]; -} - -- (IBAction)viewSource:(id)aSender -{ - NSString* urlStr = [[mBrowserView getBrowserView] getFocusedURLString]; - NSString* viewSource = [@"view-source:" stringByAppendingString: urlStr]; - - PRBool loadInBackground; - nsCOMPtr pref(do_GetService("@mozilla.org/preferences-service;1")); - pref->GetBoolPref("browser.tabs.loadInBackground", &loadInBackground); - - if (![self newTabsAllowed]) - [self openNewWindowWithURL: viewSource referrer:nil loadInBackground: loadInBackground]; - else - [self openNewTabWithURL: viewSource referrer:nil loadInBackground: loadInBackground]; -} - -- (IBAction)printDocument:(id)aSender -{ - [[mBrowserView getBrowserView] printDocument]; -} - -- (void)printPreview -{ - NS_WARNING("Print Preview stopped in BrowserWindowController, not implemented"); - //XXX there is no printPreview on CHBrowserView...so this isn't implemented - //[[mBrowserView getBrowserView] printPreview]; -} - -- (IBAction)performSearch:(id)aSender -{ - NSString *searchEngine = NSLocalizedStringFromTable(@"SearchPageDefault", @"WebsiteDefaults", nil); - - // Get the users preferred search engine from IC - if (!searchEngine || [searchEngine isEqualToString:@"SearchPageDefault"]) { - searchEngine = [[CHPreferenceManager sharedInstance] getICStringPref:kICWebSearchPagePrefs]; - if (!searchEngine || ([searchEngine length] == 0)) - searchEngine = @"http://dmoz.org/"; - } - - [mBrowserView loadURI:searchEngine referrer: nil flags:NSLoadFlagsNone activate:NO]; -} - - -- (NSToolbarItem*)throbberItem -{ - // find our throbber toolbar item. - NSToolbar* toolbar = [[self window] toolbar]; - NSArray* items = [toolbar visibleItems]; - unsigned count = [items count]; - for (unsigned i = 0; i < count; ++i) { - NSToolbarItem* item = [items objectAtIndex: i]; - if ([item tag] == 'Thrb') { - return item; - } - } - return nil; -} - -- (NSArray*)throbberImages -{ - // Simply load an array of NSImage objects from the files "throbber-NN.tif". I used "Quicktime Player" to - // save all of the frames of the animated gif as individual .tif files for simplicity of implementation. - if (mThrobberImages == nil) { - NSImage* images[64]; - int i; - for (i = 0;; ++i) { - NSString* imageName = [NSString stringWithFormat: @"throbber-%02d", i + 1]; - images[i] = [NSImage imageNamed: imageName]; - if (images[i] == nil) - break; - } - mThrobberImages = [[NSArray alloc] initWithObjects: images count: i]; - } - return mThrobberImages; -} - - -- (void)clickThrobber:(id)aSender -{ - NSString *pageToLoad = NSLocalizedStringFromTable(@"ThrobberPageDefault", @"WebsiteDefaults", nil); - if (![pageToLoad isEqualToString:@"ThrobberPageDefault"]) - [self loadURL:pageToLoad referrer:nil activate:YES]; -} - -- (void)startThrobber -{ - // optimization: only throb if the throbber toolbar item is visible. - NSToolbarItem* throbberItem = [self throbberItem]; - if (throbberItem) { - [self stopThrobber]; - mThrobberHandler = [[ThrobberHandler alloc] initWithToolbarItem:throbberItem - images:[self throbberImages]]; - } -} - -- (void)stopThrobber -{ - [mThrobberHandler stopThrobber]; - [mThrobberHandler release]; - mThrobberHandler = nil; - [[self throbberItem] setImage: [[self throbberImages] objectAtIndex: 0]]; -} - - -- (BOOL)findInPageWithPattern:(NSString*)text caseSensitive:(BOOL)inCaseSensitive - wrap:(BOOL)inWrap backwards:(BOOL)inBackwards -{ - return [[mBrowserView getBrowserView] findInPageWithPattern:text caseSensitive:inCaseSensitive - wrap:inWrap backwards:inBackwards]; -} - -- (void)addBookmarkExtended: (BOOL)aIsFromMenu isFolder:(BOOL)aIsFolder URL:(NSString*)aURL title:(NSString*)aTitle -{ - [mSidebarBookmarksDataSource ensureBookmarks]; - BOOL useSel = aIsFromMenu; - if (aIsFromMenu) { - // Use selection only if the sidebar is open and the bookmarks panel is displaying. - useSel = [self bookmarksAreVisible:NO]; - } - - [mSidebarBookmarksDataSource addBookmark: self useSelection: useSel isFolder: aIsFolder URL:aURL title:aTitle]; -} - -- (BOOL)bookmarksAreVisible:(BOOL)inRequireSelection -{ - // we should really identify the tab by identifier, not index. - BOOL bookmarksShowing = ([mSidebarDrawer state] == NSDrawerOpenState) && - ([mSidebarTabView tabViewItemAtIndex: 0] == [mSidebarTabView selectedTabViewItem]); - - if (inRequireSelection) - bookmarksShowing &= ([mSidebarBookmarksDataSource haveSelectedRow]); - - return bookmarksShowing; -} - -- (IBAction)bookmarkPage: (id)aSender -{ - [self addBookmarkExtended:YES isFolder:NO URL:nil title:nil]; -} - - -- (IBAction)bookmarkLink: (id)aSender -{ - nsCOMPtr linkContent; - nsAutoString href; - CHGeckoUtils::GetEnclosingLinkElementAndHref(mContextMenuNode, getter_AddRefs(linkContent), href); - nsAutoString linkText; - CHGeckoUtils::GatherTextUnder(linkContent, linkText); - NSString* urlStr = [NSString stringWith_nsAString:href]; - NSString* titleStr = [NSString stringWith_nsAString:linkText]; - [self addBookmarkExtended:YES isFolder:NO URL:urlStr title:titleStr]; -} - -- (IBAction)back:(id)aSender -{ - [[mBrowserView getBrowserView] goBack]; -} - -- (IBAction)forward:(id)aSender -{ - [[mBrowserView getBrowserView] goForward]; -} - -- (IBAction)reload:(id)aSender -{ - [[mBrowserView getBrowserView] reload: 0]; -} - -- (IBAction)stop:(id)aSender -{ - [[mBrowserView getBrowserView] stop: nsIWebNavigation::STOP_ALL]; -} - -- (IBAction)home:(id)aSender -{ - [mBrowserView loadURI:[[CHPreferenceManager sharedInstance] homePage:NO] referrer: nil flags:NSLoadFlagsNone activate:NO]; -} - -- (IBAction)toggleSidebar:(id)aSender -{ - if ( ([mSidebarDrawer state] == NSDrawerClosedState) || ([mSidebarDrawer state] == NSDrawerClosingState) ) { - // XXXHack to bypass sidebar crashes. - [mSidebarDrawer openOnEdge: NSMaxXEdge]; - } - else - [mSidebarDrawer close]; -} - --(void)loadURL:(NSString*)aURLSpec referrer:(NSString*)aReferrer activate:(BOOL)activate -{ - if (mInitialized) { - [mBrowserView loadURI:aURLSpec referrer:aReferrer flags:NSLoadFlagsNone activate:activate]; - } - else { - // we haven't yet initialized all the browser machinery, stash the url and referrer - // until we're ready in windowDidLoad: - mPendingURL = aURLSpec; - [mPendingURL retain]; - mPendingReferrer = aReferrer; - [mPendingReferrer retain]; - mPendingActivate = activate; - } -} - -- (void)updateLocationFields:(NSString *)locationString -{ - if ( [locationString isEqual:@"about:blank"] ) // don't show about:blank to users - locationString = @""; - [mURLBar setStringValue:locationString]; - [mLocationSheetURLField setStringValue:locationString]; - - // don't call [window display] here, no matter how much you might want - // to, because it forces a redraw of every view in the window and with a lot - // of tabs, it's dog slow. - // [[self window] display]; -} - -- (void)updateSiteIcons:(NSImage *)siteIconImage -{ - if (siteIconImage == nil) - siteIconImage = [NSImage imageNamed:@"globe_ico"]; - [mProxyIcon setImage:siteIconImage]; -} - --(void)newTab:(BOOL)allowHomepage -{ - BrowserTabViewItem* newTab = [BrowserTabView makeNewTabItem]; - CHBrowserWrapper* newView = [[[CHBrowserWrapper alloc] initWithTab: newTab andWindow: [mTabBrowser window]] autorelease]; - - PRInt32 newTabPage = 0; - if (allowHomepage) { - nsCOMPtr pref(do_GetService("@mozilla.org/preferences-service;1")); - pref->GetIntPref("browser.tabs.startPage", &newTabPage); - } - - [newTab setLabel: ((newTabPage == 1) ? NSLocalizedString(@"TabLoading", @"") : NSLocalizedString(@"UntitledPageTitle", @""))]; - [newTab setView: newView]; - [mTabBrowser addTabViewItem: newTab]; - - // Focus the URL bar if we're opening a blank tab and the URL bar is visible. - NSToolbar* toolbar = [[self window] toolbar]; - BOOL focusURLBar = ([toolbar isVisible] && - ([toolbar displayMode] == NSToolbarDisplayModeIconAndLabel || - [toolbar displayMode] == NSToolbarDisplayModeIconOnly) && - newTabPage != 1 && allowHomepage); - - if (allowHomepage) - [newView loadURI: ((newTabPage == 1) ? [[CHPreferenceManager sharedInstance] homePage: NO] : @"about:blank") referrer:nil flags:NSLoadFlagsNone activate:!focusURLBar]; - - [mTabBrowser selectLastTabViewItem: self]; - - if (focusURLBar) - [self focusURLBar]; -} - --(void)closeTab -{ - if ( [mTabBrowser numberOfTabViewItems] > 1 ) { - [[[mTabBrowser selectedTabViewItem] view] windowClosed]; - [mTabBrowser removeTabViewItem:[mTabBrowser selectedTabViewItem]]; - } -} - -- (void)previousTab -{ - if ([mTabBrowser indexOfTabViewItem:[mTabBrowser selectedTabViewItem]] == 0) - [mTabBrowser selectLastTabViewItem:self]; - else - [mTabBrowser selectPreviousTabViewItem:self]; -} - -- (void)nextTab -{ - if ([mTabBrowser indexOfTabViewItem:[mTabBrowser selectedTabViewItem]] == [mTabBrowser numberOfTabViewItems] - 1) - [mTabBrowser selectFirstTabViewItem:self]; - else - [mTabBrowser selectNextTabViewItem:self]; -} - -- (void)tabView:(NSTabView *)aTabView didSelectTabViewItem:(NSTabViewItem *)aTabViewItem -{ - // Disconnect the old view, if one has been designated. - // If the window has just been opened, none has been. - if ( mBrowserView ) { - [mBrowserView disconnectView]; - } - // Connect up the new view - mBrowserView = [aTabViewItem view]; - - // Make the new view the primary content area. - [mBrowserView makePrimaryBrowserView: mURLBar status: mStatus - progress: mProgress windowController: self]; -} - -- (void)tabViewDidChangeNumberOfTabViewItems:(NSTabView *)aTabView -{ - [[NSApp delegate] fixCloseMenuItemKeyEquivalents]; -} - --(id)getTabBrowser -{ - return mTabBrowser; -} - -- (BOOL)newTabsAllowed -{ - return [mTabBrowser canMakeNewTabs]; -} - --(CHBrowserWrapper*)getBrowserWrapper -{ - return mBrowserView; -} - --(void)openNewWindowWithURL: (NSString*)aURLSpec referrer: (NSString*)aReferrer loadInBackground: (BOOL)aLoadInBG -{ - // Autosave our dimensions before we open a new window. That ensures the size ends up matching. - [self autosaveWindowFrame]; - - BrowserWindowController* browser = [[BrowserWindowController alloc] initWithWindowNibName: @"BrowserWindow"]; - [browser loadURL: aURLSpec referrer:aReferrer activate:!aLoadInBG]; - if (aLoadInBG) - [[browser window] orderWindow: NSWindowBelow relativeTo: [[self window] windowNumber]]; - else - [browser enterModalSession]; -} - --(void)openNewWindowWithGroup: (nsIDOMElement*)aFolderElement loadInBackground: (BOOL)aLoadInBG -{ - // Autosave our dimensions before we open a new window. That ensures the size ends up matching. - [self autosaveWindowFrame]; - - // Tell the Tab Browser in the newly created window to load the group - BrowserWindowController* browser = [[BrowserWindowController alloc] initWithWindowNibName: @"BrowserWindow"]; - if (aLoadInBG) - [[browser window] orderWindow: NSWindowBelow relativeTo: [[self window] windowNumber]]; - else - [browser enterModalSession]; - - id tabBrowser = [browser getTabBrowser]; - [mSidebarBookmarksDataSource openBookmarkGroup: tabBrowser groupElement: aFolderElement]; -} - --(void)openNewTabWithURL: (NSString*)aURLSpec referrer:(NSString*)aReferrer loadInBackground: (BOOL)aLoadInBG -{ - BrowserTabViewItem* newTab = [BrowserTabView makeNewTabItem]; - - // hyatt originally made new tabs open on the far right and tabs opened from a content - // link open to the right of the current tab. The idea was to keep the new tab - // close to the tab that spawned it, since they are related. Users, however, got confused - // as to why tabs appeared in different places, so now all tabs go on the far right. -#ifdef OPEN_TAB_TO_RIGHT_OF_SELECTED - NSTabViewItem* selectedTab = [mTabBrowser selectedTabViewItem]; - int index = [mTabBrowser indexOfTabViewItem: selectedTab]; - [mTabBrowser insertTabViewItem: newTab atIndex: index+1]; -#else - [mTabBrowser addTabViewItem: newTab]; -#endif - - CHBrowserWrapper* newView = [[[CHBrowserWrapper alloc] initWithTab: newTab andWindow: [mTabBrowser window]] autorelease]; - [newView setTab: newTab]; - - [newTab setLabel: NSLocalizedString(@"TabLoading", @"")]; - [newTab setView: newView]; - - [newView loadURI:aURLSpec referrer:aReferrer flags:NSLoadFlagsNone activate:!aLoadInBG]; - - if (!aLoadInBG) - [mTabBrowser selectTabViewItem: newTab]; -} - --(void)setupSidebarTabs -{ - CHIconTabViewItem *bookItem = [[CHIconTabViewItem alloc] initWithIdentifier:@"bookmarkSidebarCHIconTabViewItem" - withTabIcon:[NSImage imageNamed:@"bookicon"]]; - CHIconTabViewItem *histItem = [[CHIconTabViewItem alloc] initWithIdentifier:@"historySidebarCHIconTabViewItem" - withTabIcon:[NSImage imageNamed:@"historyicon"]]; -#if USE_SEARCH_ITEM - CHIconTabViewItem *searchItem = [[CHIconTabViewItem alloc] initWithIdentifier:@"searchSidebarCHIconTabViewItem" - withTabIcon:[NSImage imageNamed:@"searchicon"]]; -#endif -#if USE_PANELS_ITEM - CHIconTabViewItem *panelsItem = [[CHIconTabViewItem alloc] initWithIdentifier:@"myPanelsCHIconTabViewItem" - withTabIcon:[NSImage imageNamed:@"panel_icon"]]; -#endif - - [bookItem setView:[[mSidebarSourceTabView tabViewItemAtIndex:0] view]]; - [histItem setView:[[mSidebarSourceTabView tabViewItemAtIndex:1] view]]; -#if USE_SEARCH_ITEM - [searchItem setView:[[mSidebarSourceTabView tabViewItemAtIndex:2] view]]; -#endif -#if USE_PANELS_ITEM - [panelsItem setView:[[mSidebarSourceTabView tabViewItemAtIndex:3] view]]; -#endif - - // remove default tab from nib - [mSidebarTabView removeTabViewItem:[mSidebarTabView tabViewItemAtIndex:0]]; - - // insert the tabs we want - [mSidebarTabView insertTabViewItem:bookItem atIndex:0]; - [mSidebarTabView insertTabViewItem:histItem atIndex:1]; -#if USE_SEARCH_ITEM - [mSidebarTabView insertTabViewItem:searchItem atIndex:2]; -#endif -#if USE_PANELS_ITEM - [mSidebarTabView insertTabViewItem:panelsItem atIndex:3]; -#endif - - BOOL showHistory = NO; - nsCOMPtr pref(do_GetService("@mozilla.org/preferences-service;1")); - if (pref) { - PRBool historyPref = PR_FALSE; - if (NS_SUCCEEDED(pref->GetBoolPref("chimera.show_history", &historyPref))) - showHistory = historyPref ? YES : NO; - } - - if (!showHistory) - [mSidebarTabView removeTabViewItem:[mSidebarTabView tabViewItemAtIndex:1]]; - - [mSidebarTabView selectFirstTabViewItem:self]; -} - --(void)setChromeMask:(unsigned int)aMask -{ - mChromeMask = aMask; -} - --(unsigned int)chromeMask -{ - return mChromeMask; -} - --(void) biggerTextSize -{ - nsCOMPtr contentWindow = getter_AddRefs([[mBrowserView getBrowserView] getContentWindow]); - nsCOMPtr global(do_QueryInterface(contentWindow)); - if (!global) - return; - nsCOMPtr docShell; - global->GetDocShell(getter_AddRefs(docShell)); - if (!docShell) - return; - nsCOMPtr cv; - docShell->GetContentViewer(getter_AddRefs(cv)); - nsCOMPtr markupViewer(do_QueryInterface(cv)); - if (!markupViewer) - return; - float zoom; - markupViewer->GetTextZoom(&zoom); - if (zoom >= 20) - return; - - zoom += 0.25; - if (zoom > 20) - zoom = 20; - - markupViewer->SetTextZoom(zoom); -} - --(void) smallerTextSize -{ - nsCOMPtr contentWindow = getter_AddRefs([[mBrowserView getBrowserView] getContentWindow]); - nsCOMPtr global(do_QueryInterface(contentWindow)); - if (!global) - return; - nsCOMPtr docShell; - global->GetDocShell(getter_AddRefs(docShell)); - if (!docShell) - return; - nsCOMPtr cv; - docShell->GetContentViewer(getter_AddRefs(cv)); - nsCOMPtr markupViewer(do_QueryInterface(cv)); - if (!markupViewer) - return; - float zoom; - markupViewer->GetTextZoom(&zoom); - if (zoom <= 0.01) - return; - - zoom -= 0.25; - if (zoom < 0.01) - zoom = 0.01; - - markupViewer->SetTextZoom(zoom); -} - -- (void)getInfo:(id)sender -{ - [mSidebarBookmarksDataSource ensureBookmarks]; - [mSidebarBookmarksDataSource showBookmarkInfo:sender]; -} - -- (BOOL)canGetInfo -{ - return [self bookmarksAreVisible:YES]; -} - -- (BOOL)shouldShowBookmarkToolbar -{ - NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults]; - if ([defaults integerForKey:USER_DEFAULTS_HIDE_PERS_TOOLBAR_KEY] == 1) - return NO; - - return YES; -} - --(id)getAddBookmarkSheetWindow -{ - return mAddBookmarkSheetWindow; -} - --(id)getAddBookmarkTitle -{ - return mAddBookmarkTitleField; -} - --(id)getAddBookmarkFolder -{ - return mAddBookmarkFolderField; -} - --(id)getAddBookmarkCheckbox -{ - return mAddBookmarkCheckbox; -} - -// Called when a context menu should be shown. -- (void)onShowContextMenu:(int)flags domEvent:(nsIDOMEvent*)aEvent domNode:(nsIDOMNode*)aNode -{ - mContextMenuFlags = flags; - mContextMenuNode = aNode; - mContextMenuEvent = aEvent; -} - -- (NSMenu*)getContextMenu -{ - NSMenu* result = nil; - if ((mContextMenuFlags & nsIContextMenuListener::CONTEXT_LINK) != 0) { - if ((mContextMenuFlags & nsIContextMenuListener::CONTEXT_IMAGE) != 0) { - result = mImageLinkMenu; - } - else - result = mLinkMenu; - } - else if ((mContextMenuFlags & nsIContextMenuListener::CONTEXT_INPUT) != 0 || - (mContextMenuFlags & nsIContextMenuListener::CONTEXT_TEXT) != 0) { - result = mInputMenu; - } - else if ((mContextMenuFlags & nsIContextMenuListener::CONTEXT_IMAGE) != 0) { - result = mImageMenu; - } - else if ((mContextMenuFlags & nsIContextMenuListener::CONTEXT_DOCUMENT) != 0) { - result = mPageMenu; - [mBackItem setEnabled: [[mBrowserView getBrowserView] canGoBack]]; - [mForwardItem setEnabled: [[mBrowserView getBrowserView] canGoForward]]; - } - - return result; -} - -// Context menu methods -- (IBAction)openLinkInNewWindow:(id)aSender -{ - [self openLinkInNewWindowOrTab: YES]; -} - -- (IBAction)openLinkInNewTab:(id)aSender -{ - [self openLinkInNewWindowOrTab: NO]; -} - --(void)openLinkInNewWindowOrTab: (BOOL)aUseWindow -{ - nsCOMPtr linkContent; - nsAutoString href; - CHGeckoUtils::GetEnclosingLinkElementAndHref(mContextMenuNode, getter_AddRefs(linkContent), href); - - // XXXdwh Handle simple XLINKs if we want to be compatible with Mozilla, but who - // really uses these anyway? :) - if (!linkContent || href.IsEmpty()) - return; - - nsCOMPtr pref(do_GetService("@mozilla.org/preferences-service;1")); - if (!pref) - return; // Something bad happened if we can't get prefs. - - NSString* hrefStr = [NSString stringWith_nsAString:href]; - - PRBool loadInBackground; - pref->GetBoolPref("browser.tabs.loadInBackground", &loadInBackground); - - NSString* referrer = [[mBrowserView getBrowserView] getFocusedURLString]; - - if (aUseWindow || ![self newTabsAllowed]) - [self openNewWindowWithURL: hrefStr referrer:referrer loadInBackground: loadInBackground]; - else - [self openNewTabWithURL: hrefStr referrer:referrer loadInBackground: loadInBackground]; -} - -- (IBAction)savePageAs:(id)aSender -{ - [self saveDocument: nil filterList: nil]; -} - -- (IBAction)saveLinkAs:(id)aSender -{ - nsCOMPtr linkContent; - nsAutoString href; - CHGeckoUtils::GetEnclosingLinkElementAndHref(mContextMenuNode, getter_AddRefs(linkContent), href); - - // XXXdwh Handle simple XLINKs if we want to be compatible with Mozilla, but who - // really uses these anyway? :) - if (!linkContent || href.IsEmpty()) - return; - - NSString* hrefStr = [NSString stringWith_nsAString: href]; - - // The user wants to save this link. - nsAutoString text; - CHGeckoUtils::GatherTextUnder(mContextMenuNode, text); - - [self saveURL: nil filterList: nil - url: hrefStr suggestedFilename: [NSString stringWith_nsAString: text]]; -} - -- (IBAction)saveImageAs:(id)aSender -{ - nsCOMPtr imgElement(do_QueryInterface(mContextMenuNode)); - if (imgElement) { - nsAutoString text; - imgElement->GetAttribute(NS_LITERAL_STRING("src"), text); - nsAutoString url; - imgElement->GetSrc(url); - - NSString* hrefStr = [NSString stringWith_nsAString: url]; - - [self saveURL: nil filterList: nil - url: hrefStr suggestedFilename: [NSString stringWith_nsAString: text]]; - } -} - -- (IBAction)copyLinkLocation:(id)aSender -{ - CHBrowserView* view = [[self getBrowserWrapper] getBrowserView]; - if (!view) return; - - nsCOMPtr webBrowser = getter_AddRefs([view getWebBrowser]); - if (!webBrowser) return; - - nsCOMPtr clipboard(do_GetInterface(webBrowser)); - if (clipboard) - clipboard->CopyLinkLocation(); -} - - - -- (IBAction)viewOnlyThisImage:(id)aSender -{ - nsCOMPtr imgElement(do_QueryInterface(mContextMenuNode)); - if (imgElement) { - nsAutoString url; - imgElement->GetSrc(url); - - NSString* urlStr = [NSString stringWith_nsAString: url]; - NSString* referrer = [[mBrowserView getBrowserView] getFocusedURLString]; - - [self loadURL: urlStr referrer:referrer activate:YES]; - } -} - -- (CHBookmarksToolbar*) bookmarksToolbar -{ - return mPersonalToolbar; -} - - -// -// updateLock: -// -// Sets the lock icon in the status bar to the appropriate image -// -- (void)updateLock:(unsigned int)inSecurityState -{ - switch ( inSecurityState & 0x000000FF ) { - case nsIWebProgressListener::STATE_IS_INSECURE: - [mLock setImage:[BrowserWindowController insecureIcon]]; - break; - case nsIWebProgressListener::STATE_IS_SECURE: - [mLock setImage:[BrowserWindowController secureIcon]]; - break; - case nsIWebProgressListener::STATE_IS_BROKEN: - [mLock setImage:[BrowserWindowController brokenIcon]]; - break; - } -} - -+ (NSImage*) insecureIcon -{ - static NSImage* sInsecureIcon = nil; - if ( !sInsecureIcon ) - sInsecureIcon = [[NSImage imageNamed:@"globe_ico"] retain]; - return sInsecureIcon; -} - -+ (NSImage*) secureIcon; -{ - static NSImage* sSecureIcon = nil; - if ( !sSecureIcon ) - sSecureIcon = [[NSImage imageNamed:@"security_lock"] retain]; - return sSecureIcon; -} - -+ (NSImage*) brokenIcon; -{ - static NSImage* sBrokenIcon = nil; - if ( !sBrokenIcon ) - sBrokenIcon = [[NSImage imageNamed:@"security_broken"] retain]; - return sBrokenIcon; -} - -- (void) focusChangedFrom:(NSResponder*) oldResponder to:(NSResponder*) newResponder -{ - BOOL oldResponderIsGecko = [self isResponderGeckoView:oldResponder]; - BOOL newResponderIsGecko = [self isResponderGeckoView:newResponder]; - - if (oldResponderIsGecko != newResponderIsGecko) - [[mBrowserView getBrowserView] setActive:newResponderIsGecko]; -} - -- (NSDrawer *)sidebarDrawer -{ - return mSidebarDrawer; -} - -- (CHPageProxyIcon *)proxyIconView -{ - return mProxyIcon; -} - -- (id)windowWillReturnFieldEditor:(NSWindow *)aWindow toObject:(id)anObject -{ - if ([anObject isEqual:mURLBar]) { - if (!mURLFieldEditor) { - mURLFieldEditor = [[NSTextView alloc] init]; - [mURLFieldEditor setFieldEditor:YES]; - [mURLFieldEditor setAllowsUndo:YES]; - } - return mURLFieldEditor; - } - return nil; -} - -@end - - -@implementation ThrobberHandler - --(id)initWithToolbarItem:(NSToolbarItem*)inButton images:(NSArray*)inImages -{ - if ( (self = [super init]) ) { - mImages = [inImages retain]; - mTimer = [[NSTimer scheduledTimerWithTimeInterval: 0.2 - target: self selector: @selector(pulseThrobber:) - userInfo: inButton repeats: YES] retain]; - mFrame = 0; - [self startThrobber]; - } - return self; -} - --(void)dealloc -{ - [self stopThrobber]; - [mImages release]; - [super dealloc]; -} - - -// Called by an NSTimer. - -- (void)pulseThrobber:(id)aSender -{ - // advance to next frame. - if (++mFrame >= [mImages count]) - mFrame = 0; - NSToolbarItem* toolbarItem = (NSToolbarItem*) [aSender userInfo]; - [toolbarItem setImage: [mImages objectAtIndex: mFrame]]; -} - -#define QUICKTIME_THROBBER 0 - -#if QUICKTIME_THROBBER -static Boolean movieControllerFilter(MovieController mc, short action, void *params, long refCon) -{ - if (action == mcActionMovieClick || action == mcActionMouseDown) { - EventRecord* event = (EventRecord*) params; - event->what = nullEvent; - return true; - } - return false; -} -#endif - -- (void)startThrobber -{ -#if QUICKTIME_THROBBER - // Use Quicktime to draw the frames from a single Animated GIF. This works fine for the animation, but - // when the frames stop, the poster frame disappears. - NSToolbarItem* throbberItem = [self throbberItem]; - if (throbberItem != nil && [throbberItem view] == nil) { - NSSize minSize = [throbberItem minSize]; - NSLog(@"Origin minSize = %f X %f", minSize.width, minSize.height); - NSSize maxSize = [throbberItem maxSize]; - NSLog(@"Origin maxSize = %f X %f", maxSize.width, maxSize.height); - - NSURL* throbberURL = [NSURL fileURLWithPath: [[NSBundle mainBundle] pathForResource:@"throbber" ofType:@"gif"]]; - NSLog(@"throbberURL = %@", throbberURL); - NSMovie* throbberMovie = [[[NSMovie alloc] initWithURL: throbberURL byReference: YES] autorelease]; - NSLog(@"throbberMovie = %@", throbberMovie); - - if ([throbberMovie QTMovie] != nil) { - NSMovieView* throbberView = [[[NSMovieView alloc] init] autorelease]; - [throbberView setMovie: throbberMovie]; - [throbberView showController: NO adjustingSize: NO]; - [throbberView setLoopMode: NSQTMovieLoopingPlayback]; - [throbberItem setView: throbberView]; - NSSize size = NSMakeSize(32, 32); - [throbberItem setMinSize: size]; - [throbberItem setMaxSize: size]; - [throbberView gotoPosterFrame: self]; - [throbberView start: self]; - - // experiment, veto mouse clicks in the movie controller by using an action filter. - MCSetActionFilterWithRefCon((MovieController) [throbberView movieController], - NewMCActionFilterWithRefConUPP(movieControllerFilter), - 0); - } - } -#else -#endif -} - -- (void)stopThrobber -{ -#if QUICKTIME_THROBBER - // Stop the quicktime animation. - NSToolbarItem* throbberItem = [self throbberItem]; - if (throbberItem != nil) { - NSMovieView* throbberView = [throbberItem view]; - if ([throbberView isPlaying]) { - [throbberView stop: self]; - [throbberView gotoPosterFrame: self]; - } else { - [throbberView start: self]; - } - } -#else - if (mTimer) { - [mTimer invalidate]; - [mTimer release]; - mTimer = nil; - - mFrame = 0; - } -#endif -} - -@end - diff --git a/mozilla/chimera/CHAboutBox.h b/mozilla/chimera/CHAboutBox.h deleted file mode 100644 index 2068306e703..00000000000 --- a/mozilla/chimera/CHAboutBox.h +++ /dev/null @@ -1,56 +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): - * Matt Judy - * Simon Fraser - * - * 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 ***** */ - -#include - -@interface CHAboutBox : NSObject -{ - IBOutlet NSTextView* creditsField; - IBOutlet NSTextField* buildNumberField; - IBOutlet NSWindow* window; - NSTimer *scrollTimer; - float currentPosition; - float maxScrollHeight; - NSTimeInterval startTime; - BOOL restartAtTop; -} - -+ (CHAboutBox *)sharedInstance; -- (IBAction)showPanel:(id)sender; - -@end diff --git a/mozilla/chimera/CHAboutBox.m b/mozilla/chimera/CHAboutBox.m deleted file mode 100644 index ec983bb4c99..00000000000 --- a/mozilla/chimera/CHAboutBox.m +++ /dev/null @@ -1,154 +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): - * Matt Judy - * David Hyatt - * Simon Fraser - * - * 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 "CHAboutBox.h" - -#include "nsBuildID.h" - -@interface CHAboutBox(Private) -- (void)loadWindow; -@end - -@implementation CHAboutBox - -static CHAboutBox *sharedInstance = nil; - -+ (CHAboutBox *)sharedInstance -{ - return sharedInstance ? sharedInstance : [[self alloc] init]; -} - -- (id)init -{ - if (sharedInstance) { - [self dealloc]; - } else { - sharedInstance = [super init]; - } - return sharedInstance; -} - -- (IBAction)showPanel:(id)sender -{ - if (!creditsField) { - [self loadWindow]; - } - - if (![window isVisible]) { - currentPosition = 0; - restartAtTop = NO; - startTime = [NSDate timeIntervalSinceReferenceDate] + 3.0; - [creditsField scrollPoint:NSMakePoint( 0, 0 )]; - } - - [window makeKeyAndOrderFront:nil]; -} - -- (void)windowDidBecomeKey:(NSNotification *)notification -{ - scrollTimer = [NSTimer scheduledTimerWithTimeInterval:0.03 - target:self - selector:@selector(scrollCredits:) - userInfo:nil - repeats:YES]; -} - -- (void)windowDidResignKey:(NSNotification *)notification -{ - [scrollTimer invalidate]; -} - -- (void)scrollCredits:(NSTimer *)timer -{ - if ([NSDate timeIntervalSinceReferenceDate] >= startTime) - { - if (restartAtTop) { - startTime = [NSDate timeIntervalSinceReferenceDate] + 3.0; - restartAtTop = NO; - [creditsField scrollPoint:NSMakePoint( 0, 0 )]; - return; - } - - if (currentPosition >= maxScrollHeight) { - startTime = [NSDate timeIntervalSinceReferenceDate] + 3.0; - currentPosition = 0; - restartAtTop = YES; - } else { - [creditsField scrollPoint:NSMakePoint( 0, currentPosition )]; - currentPosition += 1; - } - } -} - -- (void)loadWindow -{ - NSString *creditsPath; - NSAttributedString *creditsString; - float fieldHeight; - float containerHeight; - - if (![NSBundle loadNibNamed:@"AboutBox" owner:self]) { - NSLog( @"Failed to load AboutBox.nib" ); - NSBeep(); - return; - } - - [window setTitle:[NSString stringWithFormat: @"About %@", NSLocalizedStringFromTable(@"CFBundleName", @"InfoPlist", nil)]]; - - creditsPath = [[NSBundle mainBundle] pathForResource:@"Credits" ofType:@"rtf"]; - creditsString = [[NSAttributedString alloc] initWithPath:creditsPath documentAttributes:nil]; - [creditsField replaceCharactersInRange:NSMakeRange( 0, 0 ) - withRTF:[creditsString RTFFromRange: - NSMakeRange( 0, [creditsString length] ) - documentAttributes:nil]]; - - fieldHeight = [creditsField frame].size.height; - - (void)[[creditsField layoutManager] glyphRangeForTextContainer:[creditsField textContainer]]; - containerHeight = [[creditsField layoutManager] usedRectForTextContainer: - [creditsField textContainer]].size.height; - maxScrollHeight = containerHeight - fieldHeight; - - [buildNumberField setStringValue: [NSString stringWithFormat: NSLocalizedString(@"BuildID", @""), NS_BUILD_ID]]; - [window setExcludedFromWindowsMenu:YES]; - [window setMenu:nil]; - [window center]; -} - -@end diff --git a/mozilla/chimera/CHAutoCompleteDataSource.h b/mozilla/chimera/CHAutoCompleteDataSource.h deleted file mode 100644 index 539ed560d87..00000000000 --- a/mozilla/chimera/CHAutoCompleteDataSource.h +++ /dev/null @@ -1,49 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- -* -* 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 the Mozilla browser. -* -* The Initial Developer of the Original Code is Netscape -* Communications Corporation. Portions created by Netscape are -* Copyright (C) 2002 Netscape Communications Corporation. All -* Rights Reserved. -* -* Contributor(s): -* David Hyatt (Original Author) -*/ - -#import -#import "CHAutoCompleteTextField.h" -#include "nsIAutoCompleteResults.h" - -@class CHAutoCompleteTextField; - -@interface CHAutoCompleteDataSource : NSObject -{ - NSImage *mIconImage; - - NSString* mErrorMessage; - nsIAutoCompleteResults *mResults; -} - -- (id) init; - -- (int) rowCount; -- (id) resultString:(int)aRow column:(NSString *)aColumn; - -- (void) setErrorMessage: (NSString*) error; -- (NSString*) errorMessage; - -- (void) setResults: (nsIAutoCompleteResults*) results; -- (nsIAutoCompleteResults*) results; - -@end diff --git a/mozilla/chimera/CHAutoCompleteDataSource.mm b/mozilla/chimera/CHAutoCompleteDataSource.mm deleted file mode 100644 index 0071afa0f07..00000000000 --- a/mozilla/chimera/CHAutoCompleteDataSource.mm +++ /dev/null @@ -1,127 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- -* -* 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 the Mozilla browser. -* -* The Initial Developer of the Original Code is Netscape -* Communications Corporation. Portions created by Netscape are -* Copyright (C) 2002 Netscape Communications Corporation. All -* Rights Reserved. -* -* Contributor(s): -* David Hyatt (Original Author) -* -*/ - -#import "NSString+Utils.h" - -#import -#import "CHAutoCompleteTextField.h" -#include "nsString.h" -#include "nsCRT.h" - -@implementation CHAutoCompleteDataSource - --(id)init -{ - if ((self = [super init])) { - mResults = nil; - mIconImage = [NSImage imageNamed:@"globe_ico"]; - } - return self; -} - --(void)dealloc -{ - NS_IF_RELEASE(mResults); - [super dealloc]; -} - -- (void) setErrorMessage: (NSString*) error -{ - [self setResults:nsnull]; - mErrorMessage = error; -} - -- (NSString*) errorMessage -{ - return mErrorMessage; -} - -- (void) setResults:(nsIAutoCompleteResults*)aResults -{ - NS_IF_RELEASE(mResults); - - mErrorMessage = nil; - mResults = aResults; - NS_IF_ADDREF(mResults); -} - -- (nsIAutoCompleteResults *) results -{ - return mResults; -} - -- (int) rowCount -{ - if (!mResults) - return 0; - - nsCOMPtr items; - mResults->GetItems(getter_AddRefs(items)); - PRUint32 count; - items->Count(&count); - - return count; -} - -- (id) resultString:(int)aRow column:(NSString *)aColumn -{ - NSString *result = @""; - - if (!mResults) - return result; - - nsCOMPtr items; - mResults->GetItems(getter_AddRefs(items)); - - nsCOMPtr itemSupports = dont_AddRef(items->ElementAt(aRow)); - nsCOMPtr item = do_QueryInterface(itemSupports); - if (!item) - return result; - - if ([aColumn isEqualToString:@"icon"]) { - return mIconImage; - } else if ([aColumn isEqualToString:@"col1"]) { - nsAutoString value; - item->GetValue(value); - result = [NSString stringWith_nsAString:value]; - } else if ([aColumn isEqualToString:@"col2"]) { - nsXPIDLString commentStr; - item->GetComment(getter_Copies(commentStr)); - result = [NSString stringWith_nsAString:commentStr]; - } - - return result; -} - --(int) numberOfRowsInTableView:(NSTableView*)aTableView -{ - return [self rowCount]; -} - --(id)tableView:(NSTableView*)aTableView objectValueForTableColumn:(NSTableColumn*)aTableColumn row:(int)aRowIndex -{ - return [self resultString:aRowIndex column:[aTableColumn identifier]]; -} - -@end diff --git a/mozilla/chimera/CHAutoCompleteTextField.h b/mozilla/chimera/CHAutoCompleteTextField.h deleted file mode 100644 index 847b86d16a7..00000000000 --- a/mozilla/chimera/CHAutoCompleteTextField.h +++ /dev/null @@ -1,93 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- -* -* 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 the Mozilla browser. -* -* The Initial Developer of the Original Code is Netscape -* Communications Corporation. Portions created by Netscape are -* Copyright (C) 2002 Netscape Communications Corporation. All -* Rights Reserved. -* -* Contributor(s): -* Joe Hewitt (Original Author) -* David Haas -*/ - -#import -#import "CHAutoCompleteDataSource.h" -#include "nsIAutoCompleteSession.h" -#include "nsIAutoCompleteResults.h" -#include "nsIAutoCompleteListener.h" - -@class CHAutoCompleteDataSource, CHPageProxyIcon; - -@interface CHAutoCompleteTextField : NSTextField -{ - IBOutlet CHPageProxyIcon *mProxyIcon; - NSWindow *mPopupWin; - NSTableView *mTableView; - - CHAutoCompleteDataSource *mDataSource; - - nsIAutoCompleteSession *mSession; - nsIAutoCompleteResults *mResults; - nsIAutoCompleteListener *mListener; - - NSString *mSearchString; - - // used to remember if backspace was pressed in complete: so we can check this in controlTextDidChange - BOOL mBackspaced; - // determines if the search currently pending should complete the default result when it is ready - BOOL mCompleteResult; - // should the autocomplete fill in the default completion into the text field? The default - // is no, but this can be set with a user default pref. - BOOL mCompleteWhileTyping; - - NSTimer *mOpenTimer; -} - -- (void) setSession:(NSString *)aSession; -- (NSString *) session; -- (void) setPageProxyIcon:(NSImage *)aImage; - -- (NSTableView *) tableView; -- (int) visibleRows; - -- (void) startSearch:(NSString*)aString complete:(BOOL)aComplete; -- (void) performSearch; -- (void) dataReady:(nsIAutoCompleteResults*)aResults status:(AutoCompleteStatus)aStatus; -- (void) searchTimer:(NSTimer *)aTimer; -- (void) clearResults; - -- (void) completeDefaultResult; -- (void) completeSelectedResult; -- (void) completeResult:(int)aRow; -- (void) enterResult:(int)aRow; -- (void) revertText; - -- (void) selectRowAt:(int)aRow; -- (void) selectRowBy:(int)aRows; - -- (void) openPopup; -- (void) closePopup; -- (void) resizePopup; -- (BOOL) isOpen; - -- (void) onRowClicked:(NSNotification *)aNote; -- (void) onBlur:(NSNotification *)aNote; -- (void) onResize:(NSNotification *)aNote; -- (void) onUndoOrRedo:(NSNotification *)aNote; - -- (void) setStringUndoably:(NSString*)aString fromLocation:(unsigned int)aLocation; -- (id) fieldEditor; - -@end diff --git a/mozilla/chimera/CHAutoCompleteTextField.mm b/mozilla/chimera/CHAutoCompleteTextField.mm deleted file mode 100644 index 9fd20c4a4c4..00000000000 --- a/mozilla/chimera/CHAutoCompleteTextField.mm +++ /dev/null @@ -1,588 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- -* -* 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 the Mozilla browser. -* -* The Initial Developer of the Original Code is Netscape -* Communications Corporation. Portions created by Netscape are -* Copyright (C) 2002 Netscape Communications Corporation. All -* Rights Reserved. -* -* Contributor(s): -* Joe Hewitt (Original Author) -* David Haas -*/ - -#import "CHAutoCompleteTextField.h" -#import "BrowserWindowController.h" -#import "CHPageProxyIcon.h" -#include "nsIServiceManager.h" -#include "nsMemory.h" -#include "nsString.h" -#include "CHUserDefaults.h" - -static const int kMaxRows = 6; -static const int kFrameMargin = 1; - -@interface AutoCompleteWindow : NSWindow -- (BOOL)isKeyWindow; -@end - -@implementation AutoCompleteWindow -- (BOOL)isKeyWindow -{ - return YES; -} -@end - -class AutoCompleteListener : public nsIAutoCompleteListener -{ -public: - AutoCompleteListener(CHAutoCompleteTextField* aTextField) - { - NS_INIT_REFCNT(); - mTextField = aTextField; - } - - NS_DECL_ISUPPORTS - - NS_IMETHODIMP OnStatus(const PRUnichar* aText) { return NS_OK; } - NS_IMETHODIMP SetParam(nsISupports *aParam) { return NS_OK; } - NS_IMETHODIMP GetParam(nsISupports **aParam) { return NS_OK; } - - NS_IMETHODIMP OnAutoComplete(nsIAutoCompleteResults *aResults, AutoCompleteStatus aStatus) - { - [mTextField dataReady:aResults status:aStatus]; - return NS_OK; - } - -private: - CHAutoCompleteTextField *mTextField; -}; - -NS_IMPL_ISUPPORTS1(AutoCompleteListener, nsIAutoCompleteListener) - -//////////////////////////////////////////////////////////////////////// - -@implementation CHAutoCompleteTextField - -- (void) awakeFromNib -{ - NSTableColumn *column; - NSScrollView *scrollView; - NSCell *dataCell; - - mSearchString = nil; - mBackspaced = NO; - mCompleteResult = NO; - mOpenTimer = nil; - - mSession = nsnull; - mResults = nsnull; - mListener = (nsIAutoCompleteListener *)new AutoCompleteListener(self); - NS_IF_ADDREF(mListener); - - [self setFont:[NSFont controlContentFontOfSize:0]]; - [self setDelegate: self]; - - // XXX the owner of the textfield should set this - [self setSession:@"history"]; - - // construct and configure the popup window - mPopupWin = [[AutoCompleteWindow alloc] initWithContentRect:NSMakeRect(0,0,0,0) - styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:NO]; - [mPopupWin setReleasedWhenClosed:NO]; - [mPopupWin setLevel:NSFloatingWindowLevel]; - [mPopupWin setHasShadow:YES]; - [mPopupWin setAlphaValue:0.9]; - - // construct and configure the view - mTableView = [[[NSTableView alloc] initWithFrame:NSMakeRect(0,0,0,0)] autorelease]; - [mTableView setIntercellSpacing:NSMakeSize(1, 2)]; - [mTableView setTarget:self]; - [mTableView setAction:@selector(onRowClicked:)]; - - // Create the icon column if we have a proxy icon - if (mProxyIcon) { - column = [[[NSTableColumn alloc] initWithIdentifier:@"icon"] autorelease]; - [column setWidth:[mProxyIcon frame].origin.x + [mProxyIcon frame].size.width]; - dataCell = [[[NSImageCell alloc] initImageCell:nil] autorelease]; - [column setDataCell:dataCell]; - [mTableView addTableColumn: column]; - } - - // create the text columns - column = [[[NSTableColumn alloc] initWithIdentifier:@"col1"] autorelease]; - [mTableView addTableColumn: column]; - column = [[[NSTableColumn alloc] initWithIdentifier:@"col2"] autorelease]; - [[column dataCell] setTextColor:[NSColor darkGrayColor]]; - [mTableView addTableColumn: column]; - - // hide the table header - [mTableView setHeaderView:nil]; - - // construct the scroll view that contains the table view - scrollView = [[[NSScrollView alloc] initWithFrame:NSMakeRect(0,0,0,0)] autorelease]; - [scrollView setHasVerticalScroller:YES]; - [[scrollView verticalScroller] setControlSize:NSSmallControlSize]; - [scrollView setDocumentView: mTableView]; - - // construct the datasource - mDataSource = [[CHAutoCompleteDataSource alloc] init]; - [mTableView setDataSource: mDataSource]; - - [mPopupWin setContentView:scrollView]; - - // listen for when window resigns from key handling - [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onBlur:) - name:NSWindowDidResignKeyNotification object:nil]; - - // listen for when window is about to be moved or resized - [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onBlur:) - name:NSWindowWillMoveNotification object:nil]; - [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onResize:) - name:NSWindowDidResizeNotification object:nil]; - - // listen for Undo/Redo to make sure autocomplete doesn't get horked. - [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onUndoOrRedo:) - name:NSUndoManagerDidRedoChangeNotification - object:[[self fieldEditor] undoManager]]; - [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onUndoOrRedo:) - name:NSUndoManagerDidUndoChangeNotification - object:[[self fieldEditor] undoManager]]; - - // read the user default on if we should auto-complete the text field as the user - // types or make them pick something from a list (a-la mozilla). - mCompleteWhileTyping = [[NSUserDefaults standardUserDefaults] boolForKey:USER_DEFAULTS_AUTOCOMPLETE_WHILE_TYPING]; -} - -- (void) dealloc -{ - [[NSNotificationCenter defaultCenter] removeObserver:self]; - - if (mSearchString) - [mSearchString release]; - - [mPopupWin release]; - [mDataSource release]; - - NS_IF_RELEASE(mSession); - NS_IF_RELEASE(mResults); - NS_IF_RELEASE(mListener); - - [super dealloc]; -} - -- (void) setSession:(NSString *)aSession -{ - NS_IF_RELEASE(mSession); - - // XXX add aSession to contract id - nsCOMPtr session = - do_GetService("@mozilla.org/autocompleteSession;1?type=history"); - mSession = session; - NS_IF_ADDREF(mSession); -} - -- (NSString *) session -{ - // XXX return session name - return @""; -} - -- (NSTableView *) tableView -{ - return mTableView; -} - -- (int) visibleRows -{ - int minRows = [mDataSource rowCount]; - return minRows < kMaxRows ? minRows : kMaxRows; -} - -- (void) setPageProxyIcon:(NSImage *)aImage -{ - [mProxyIcon setImage:aImage]; -} - --(id) fieldEditor -{ - return [[self window] fieldEditor:NO forObject:self]; -} -// searching //////////////////////////// - -- (void) startSearch:(NSString*)aString complete:(BOOL)aComplete -{ - if (mSearchString) - [mSearchString release]; - mSearchString = [aString retain]; - - mCompleteResult = aComplete; - - if ([self isOpen]) { - [self performSearch]; - } else { - // delay the search when the popup is not yet opened so that users - // don't see a jerky flashing popup when they start typing for the first time - if (mOpenTimer) { - [mOpenTimer invalidate]; - [mOpenTimer release]; - } - - mOpenTimer = [[NSTimer scheduledTimerWithTimeInterval:0.2 target:self selector:@selector(searchTimer:) - userInfo:nil repeats:NO] retain]; - } -} - -- (void) performSearch -{ - PRUnichar* chars = nsMemory::Alloc(([mSearchString length]+1) * sizeof(PRUnichar)); - [mSearchString getCharacters:chars]; - chars[[mSearchString length]] = 0; // I shouldn't have to do this - nsresult rv = mSession->OnStartLookup(chars, mResults, mListener); - nsMemory::Free(chars); - - if (NS_FAILED(rv)) - NSLog(@"Unable to perform autocomplete lookup"); -} - -- (void) dataReady:(nsIAutoCompleteResults*)aResults status:(AutoCompleteStatus)aStatus -{ - NS_IF_RELEASE(mResults); - mResults = nsnull; - - if (aStatus == nsIAutoCompleteStatus::failed) { - [mDataSource setErrorMessage:@""]; - } else if (aStatus == nsIAutoCompleteStatus::ignored) { - [mDataSource setErrorMessage:@""]; - } else if (aStatus == nsIAutoCompleteStatus::noMatch) { - [mDataSource setErrorMessage:@""]; - } else if (aStatus == nsIAutoCompleteStatus::matchFound) { - mResults = aResults; - NS_IF_ADDREF(mResults); - [mDataSource setResults:aResults]; - [self completeDefaultResult]; - } - - if ([mDataSource rowCount] > 0) { - [mTableView noteNumberOfRowsChanged]; - [self openPopup]; - } else { - [self closePopup]; - } -} - -- (void) searchTimer:(NSTimer *)aTimer -{ - [mOpenTimer release]; - mOpenTimer = nil; - - [self performSearch]; -} - -- (void) clearResults -{ - // clear out search data - if (mSearchString) - [mSearchString release]; - mSearchString = nil; - NS_IF_RELEASE(mResults); - mResults = nsnull; - - [mDataSource setResults:nil]; - - [self closePopup]; -} - -// handling the popup ///////////////////////////////// - -- (void) openPopup -{ - [self resizePopup]; - - // show the popup - if ([mPopupWin isVisible] == NO) - [mPopupWin orderFront:nil]; -} - -- (void) resizePopup -{ - NSRect locationFrame, winFrame; - NSPoint locationOrigin; - int tableHeight; - - if ([self visibleRows] == 0) { - [self closePopup]; - return; - } - - // get the origin of the location bar in coordinates of the root view - locationFrame = [[self superview] frame]; - locationOrigin = [[[self superview] superview] convertPoint:locationFrame.origin - toView:[[[self window] contentView] superview]]; - - // get the height of the table view - winFrame = [[self window] frame]; - tableHeight = (int)([mTableView rowHeight]+[mTableView intercellSpacing].height)*[self visibleRows]; - - // make the columns split the width of the popup - [[mTableView tableColumnWithIdentifier:@"col1"] setWidth:locationFrame.size.width/2]; - - // position the popup anchored to bottom/left of location bar ( - [mPopupWin setFrame:NSMakeRect(winFrame.origin.x + locationOrigin.x + kFrameMargin, - ((winFrame.origin.y + locationOrigin.y) - tableHeight) - kFrameMargin, - locationFrame.size.width - (2*kFrameMargin), - tableHeight) display:NO]; -} - -- (void) closePopup -{ - [mPopupWin close]; -} - -- (BOOL) isOpen -{ - return [mPopupWin isVisible]; -} - -// url completion //////////////////////////// - -- (void) completeDefaultResult -{ - PRInt32 defaultRow; - mResults->GetDefaultItemIndex(&defaultRow); - - if (mCompleteResult && mCompleteWhileTyping) { - [self selectRowAt:defaultRow]; - [self completeResult:defaultRow]; - } else { - [self selectRowAt:-1]; - } -} - -- (void) completeSelectedResult -{ - [self completeResult:[mTableView selectedRow]]; -} - -- (void) completeResult:(int)aRow -{ - if (aRow < 0 && mSearchString) { - // reset to the original search string with the insertion point at the end. Note - // we have to make our range before we call setStringUndoably: because it calls - // clearResults() which destroys |mSearchString|. - NSRange selectAtEnd = NSMakeRange([mSearchString length],0); - [self setStringUndoably:mSearchString fromLocation:0]; - [[self fieldEditor] setSelectedRange:selectAtEnd]; - } - else { - if ([mDataSource rowCount] <= 0) - return; - - // Fill in the suggestion from the list, but change only the text - // after what is typed and select just that part. This allows the - // user to see what they have typed and what change the autocomplete - // makes while allowing them to continue typing w/out having to - // reset the insertion point. - NSString *result = [mDataSource resultString:aRow column:@"col1"]; - NSRange matchRange = [result rangeOfString:mSearchString]; - if (matchRange.length > 0 && matchRange.location != NSNotFound) { - unsigned int location = matchRange.location + matchRange.length; - result = [result substringWithRange:NSMakeRange(location, [result length]-location)]; - [self setStringUndoably:result fromLocation:[mSearchString length]]; - } - } -} - -- (void) enterResult:(int)aRow -{ - if (aRow >= 0 && [mDataSource rowCount] > 0) { - [self setStringUndoably:[mDataSource resultString:[mTableView selectedRow] column:@"col1"] fromLocation:0]; - [self closePopup]; - } else if (mOpenTimer) { - // if there was a search timer going when we hit enter, cancel it - [mOpenTimer invalidate]; - [mOpenTimer release]; - mOpenTimer = nil; - } -} - -- (void) revertText -{ - BrowserWindowController *controller = (BrowserWindowController *)[[self window] windowController]; - NSString *url = [[controller getBrowserWrapper] getCurrentURLSpec]; - if (url) { - [self clearResults]; - NSTextView *fieldEditor = [self fieldEditor]; - [[fieldEditor undoManager] removeAllActions]; - [fieldEditor setString:url]; - [fieldEditor selectAll:self]; - } -} - -- (void) setStringUndoably:(NSString *)aString fromLocation:(unsigned int)aLocation -{ - NSTextView *fieldEditor = [self fieldEditor]; - NSRange aRange = NSMakeRange(aLocation,[[fieldEditor string] length] - aLocation); - if ([fieldEditor shouldChangeTextInRange:aRange replacementString:aString]) { - [[fieldEditor textStorage] replaceCharactersInRange:aRange withString:aString]; - // Whenever we send [self didChangeText], we trigger the - // textDidChange method, which will begin a new search with - // a new search string (which we just inserted) if the selection - // is at the end of the string. So, we "select" the first character - // to prevent that badness from happening. - [fieldEditor setSelectedRange:NSMakeRange(0,0)]; - [fieldEditor didChangeText]; - } - aRange = NSMakeRange(aLocation,[[fieldEditor string] length] - aLocation); - [fieldEditor setSelectedRange:aRange]; -} - -// selecting rows ///////////////////////////////////////// - -- (void) selectRowAt:(int)aRow -{ - if (aRow >= -1 && [mDataSource rowCount] > 0) { - // show the popup - if ([mPopupWin isVisible] == NO) - [mPopupWin orderFront:nil]; - - [mTableView selectRow:aRow byExtendingSelection:NO]; - [mTableView scrollRowToVisible: aRow]; - } -} - -- (void) selectRowBy:(int)aRows -{ - int row = [mTableView selectedRow]; - - if (row == -1 && aRows < 0) { - // if nothing is selected and you scroll up, go to last row - row = [mTableView numberOfRows]-1; - } else if (row == [mTableView numberOfRows]-1 && aRows == 1) { - // if the last row is selected and you scroll down, go to first row - row = 0; - } else if (aRows+row < 0) { - // if you scroll up beyond first row... - if (row == 0) - row = -1; // ...and first row is selected, select nothing - else - row = 0; // ...else, go to first row - } else if (aRows+row >= [mTableView numberOfRows]) { - // if you scroll down beyond the last row... - if (row == [mTableView numberOfRows]-1) - row = 0; // and last row is selected, select first row - else - row = [mTableView numberOfRows]-1; // else, go to last row - } else { - // no special case, just increment current row - row += aRows; - } - - [self selectRowAt:row]; -} - -// event handlers //////////////////////////////////////////// - -- (void) onRowClicked:(NSNotification *)aNote -{ - [self enterResult:[mTableView clickedRow]]; - [[[self window] windowController] goToLocationFromToolbarURLField:self]; -} - -- (void) onBlur:(NSNotification *)aNote -{ - [self closePopup]; -} - -- (void) onResize:(NSNotification *)aNote -{ - [self resizePopup]; -} - -- (void) onUndoOrRedo:(NSNotification *)aNote -{ - [self clearResults]; -} - -// NSTextField delegate ////////////////////////////////// -- (void)controlTextDidChange:(NSNotification *)aNote -{ - NSTextView *fieldEditor = [[aNote userInfo] objectForKey:@"NSFieldEditor"]; - NSRange range = [fieldEditor selectedRange]; - // make sure we're typing at the end of the string - if (range.location == [[fieldEditor string] length]) { - // when we ask for a NSTextView string, Cocoa returns - // a pointer to the view's backing store. So, the value - // of the string continually changes as we edit the text view. - // Since we'll edit the text view as we add in autocomplete results, - // we've got to make a copy of the string as it currently stands - // to know what we were searching for in the first place. - NSString *searchString = [[fieldEditor string] copyWithZone:nil]; - [self startSearch:searchString complete:!mBackspaced]; - [searchString release]; - } - else if (([mTableView selectedRow] == -1) || mBackspaced) - [self clearResults]; - - mBackspaced = NO; -} - -- (void)controlTextDidEndEditing:(NSNotification *)aNote -{ - [self closePopup]; - [[[[aNote userInfo] objectForKey:@"NSFieldEditor"] undoManager] removeAllActions]; -} - -- (BOOL)control:(NSControl *)control textView:(NSTextView *)textView doCommandBySelector:(SEL)command -{ - if (command == @selector(insertNewline:)) { - [self enterResult:[mTableView selectedRow]]; - } else if (command == @selector(moveUp:)) { - [self selectRowBy:-1]; - [self completeSelectedResult]; - return YES; - } else if (command == @selector(moveDown:)) { - [self selectRowBy:1]; - [self completeSelectedResult]; - return YES; - } else if (command == @selector(scrollPageUp:)) { - [self selectRowBy:-kMaxRows]; - [self completeSelectedResult]; - } else if (command == @selector(scrollPageDown:)) { - [self selectRowBy:kMaxRows]; - [self completeSelectedResult]; - } else if (command == @selector(moveToBeginningOfDocument:)) { - [self selectRowAt:0]; - [self completeSelectedResult]; - } else if (command == @selector(moveToEndOfDocument:)) { - [self selectRowAt:[mTableView numberOfRows]-1]; - [self completeSelectedResult]; - } else if (command == @selector(insertTab:)) { - if ([mPopupWin isVisible]) { - [self selectRowBy:1]; - [self completeSelectedResult]; - return YES; - } - } else if (command == @selector(deleteBackward:) || - command == @selector(deleteForward:)) { - // if the user deletes characters, we need to know so that - // we can prevent autocompletion later when search results come in - if ([[textView string] length] > 1) - mBackspaced = YES; - } - - return NO; -} - -@end diff --git a/mozilla/chimera/CHBookmarksButton.h b/mozilla/chimera/CHBookmarksButton.h deleted file mode 100644 index 27d5623352e..00000000000 --- a/mozilla/chimera/CHBookmarksButton.h +++ /dev/null @@ -1,47 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- -* -* 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 the Mozilla browser. -* -* The Initial Developer of the Original Code is Netscape -* Communications Corporation. Portions created by Netscape are -* Copyright (C) 2002 Netscape Communications Corporation. All -* Rights Reserved. -* -* Contributor(s): -* David Hyatt (Original Author) -*/ - -#import -#import - -class nsIDOMElement; -class BookmarksService; - -@class BookmarkItem; - -@interface CHBookmarksButton : NSButton -{ - nsIDOMElement* mElement; - BookmarkItem* mBookmarkItem; - BookmarksService* mBookmarksService; - BOOL mIsFolder; -} - --(id)initWithFrame:(NSRect)frame element:(nsIDOMElement*)element bookmarksService:(BookmarksService*)bookmarksService; - --(void)setElement: (nsIDOMElement*)aElt; --(nsIDOMElement*)element; - --(IBAction)openBookmark:(id)aSender; - -@end diff --git a/mozilla/chimera/CHBookmarksButton.mm b/mozilla/chimera/CHBookmarksButton.mm deleted file mode 100644 index abf785435fd..00000000000 --- a/mozilla/chimera/CHBookmarksButton.mm +++ /dev/null @@ -1,271 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- -* -* 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 the Mozilla browser. -* -* The Initial Developer of the Original Code is Netscape -* Communications Corporation. Portions created by Netscape are -* Copyright (C) 2002 Netscape Communications Corporation. All -* Rights Reserved. -* -* Contributor(s): -* David Hyatt (Original Author) -*/ - -#import "NSString+Utils.h" -#import "CHBookmarksButton.h" - -#include "nsCOMPtr.h" -#include "nsIContent.h" -#include "nsIDOMElement.h" -#include "nsINamespaceManager.h" -#include "nsIPrefBranch.h" -#include "nsIServiceManager.h" -#include "nsString.h" -#include "nsCRT.h" - -#import "BookmarkInfoController.h" -#import "BookmarksDataSource.h" -#import "BookmarksService.h" - -@implementation CHBookmarksButton - -- (id)initWithFrame:(NSRect)frame -{ - if ( (self = [super initWithFrame:frame]) ) { - [self setBezelStyle: NSRegularSquareBezelStyle]; - [self setButtonType: NSMomentaryChangeButton]; - [self setBordered: NO]; - [self setImagePosition: NSImageLeft]; - [self setRefusesFirstResponder: YES]; - [self setFont: [NSFont labelFontOfSize: 11.0]]; - } - return self; -} - --(id)initWithFrame:(NSRect)frame element:(nsIDOMElement*)element bookmarksService:(BookmarksService*)bookmarksService -{ - if ( (self = [self initWithFrame:frame]) ) { - mBookmarksService = bookmarksService; - [self setElement:element]; - } - return self; -} - --(IBAction)openBookmark:(id)aSender -{ - // See if we're a group. - nsAutoString group; - mElement->GetAttribute(NS_LITERAL_STRING("group"), group); - if (!group.IsEmpty()) { - BookmarksService::OpenBookmarkGroup([[[self window] windowController] getTabBrowser], mElement); - return; - } - - // Get the href attribute. This is the URL we want to load. - nsAutoString href; - mElement->GetAttribute(NS_LITERAL_STRING("href"), href); - if (href.IsEmpty()) - return; - NSString* url = [NSString stringWith_nsAString: href]; - - // Now load the URL in the window. - BrowserWindowController* brController = [[self window] windowController]; - [brController loadURL: url referrer:nil activate:YES]; -} - --(IBAction)openBookmarkInNewTab:(id)aSender -{ - nsCOMPtr pref(do_GetService("@mozilla.org/preferences-service;1")); - if (!pref) - return; // Something bad happened if we can't get prefs. - - // Get the href attribute. This is the URL we want to load. - nsAutoString hrefAttr; - mElement->GetAttribute(NS_LITERAL_STRING("href"), hrefAttr); - NSString* hrefStr = [NSString stringWith_nsAString:hrefAttr]; - - PRBool loadInBackground; - pref->GetBoolPref("browser.tabs.loadInBackground", &loadInBackground); - - BrowserWindowController* brController = [[self window] windowController]; - [brController openNewTabWithURL: hrefStr referrer:nil loadInBackground: loadInBackground]; -} - --(IBAction)openBookmarkInNewWindow:(id)aSender -{ - nsCOMPtr pref(do_GetService("@mozilla.org/preferences-service;1")); - if (!pref) - return; // Something bad happened if we can't get prefs. - - // Get the href attribute. This is the URL we want to load. - nsAutoString hrefAttr; - mElement->GetAttribute(NS_LITERAL_STRING("href"), hrefAttr); - NSString* hrefStr = [NSString stringWith_nsAString:hrefAttr]; - - PRBool loadInBackground; - pref->GetBoolPref("browser.tabs.loadInBackground", &loadInBackground); - - nsAutoString group; - mElement->GetAttribute(NS_LITERAL_STRING("group"), group); - - BrowserWindowController* brController = [[self window] windowController]; - if (group.IsEmpty()) - [brController openNewWindowWithURL: hrefStr referrer: nil loadInBackground: loadInBackground]; - else - [brController openNewWindowWithGroup: mElement loadInBackground: loadInBackground]; -} - --(IBAction)showBookmarkInfo:(id)aSender -{ - BookmarkInfoController *bic = [BookmarkInfoController sharedBookmarkInfoController]; - - [bic showWindow:bic]; - [bic setBookmark:mBookmarkItem]; -} - --(IBAction)deleteBookmarks: (id)aSender -{ - if (mElement == BookmarksService::gToolbarRoot) - return; // Don't allow the personal toolbar to be deleted. - nsCOMPtr content(do_QueryInterface(mElement)); - - nsCOMPtr parent; - mElement->GetParentNode(getter_AddRefs(parent)); - nsCOMPtr parentContent(do_QueryInterface(parent)); - nsCOMPtr dummy; - if (parent) - parent->RemoveChild(mElement, getter_AddRefs(dummy)); - BookmarksService::BookmarkRemoved(parentContent, content); -} - --(IBAction)addFolder:(id)aSender -{ - // TODO -} - --(void)drawRect:(NSRect)aRect -{ - [super drawRect: aRect]; -} - --(NSMenu*)menuForEvent:(NSEvent*)aEvent -{ - // Make a copy of the context menu but change it to target us - // FIXME - this will stop to work as soon as we add items to the context menu - // that have different targets. In that case, we probably should add code to - // CHBookmarksToolbar that manages the context menu for the CHBookmarksButtons. - - NSMenu* myMenu = [[[self superview] menu] copy]; - [[myMenu itemArray] makeObjectsPerformSelector:@selector(setTarget:) withObject: self]; - [myMenu update]; - return [myMenu autorelease]; -} - --(BOOL)validateMenuItem:(NSMenuItem*)aMenuItem -{ - if (!mBookmarkItem) - return NO; - BOOL isBookmark = [mBookmarkItem isFolder] == NO; - - nsAutoString group; - mElement->GetAttribute(NS_LITERAL_STRING("group"), group); - BOOL isGroup = !group.IsEmpty(); - - if (([aMenuItem action] == @selector(openBookmarkInNewWindow:))) { - // Bookmarks and Bookmark Groups can be opened in a new window - return (isBookmark || isGroup); - } - else if (([aMenuItem action] == @selector(openBookmarkInNewTab:))) { - // Only Bookmarks can be opened in new tabs - BrowserWindowController* brController = [[self window] windowController]; - return isBookmark && [brController newTabsAllowed]; - } - return YES; -} - --(void)mouseDown:(NSEvent*)aEvent -{ - // pop up a "context menu" on folders showing their contents. we check - // for single click to fix issues with dblclicks (bug 162367) - if (mIsFolder && [aEvent clickCount] == 1) { - nsCOMPtr content(do_QueryInterface(mElement)); - NSMenu* menu = BookmarksService::LocateMenu(content); - [NSMenu popUpContextMenu: menu withEvent: aEvent forView: self]; - } - else - [super mouseDown:aEvent]; -} - --(void)setElement: (nsIDOMElement*)aElt -{ - mElement = aElt; - nsAutoString tag; - mElement->GetLocalName(tag); - - NSImage* bookmarkImage = mBookmarksService->CreateIconForBookmark(aElt); - - nsAutoString group; - mElement->GetAttribute(NS_LITERAL_STRING("group"), group); - - if (!group.IsEmpty()) { - mIsFolder = NO; - [self setImage: bookmarkImage]; - [self setAction: @selector(openBookmark:)]; - [self setTarget: self]; - } - else if (tag.Equals(NS_LITERAL_STRING("folder"))) { - [self setImage: bookmarkImage]; - mIsFolder = YES; - } - else { - mIsFolder = NO; - [self setImage: bookmarkImage]; - [self setAction: @selector(openBookmark:)]; - [self setTarget: self]; - nsAutoString href; - mElement->GetAttribute(NS_LITERAL_STRING("href"), href); - NSString* helpText = [NSString stringWith_nsAString:href]; - [self setToolTip: helpText]; - } - - nsAutoString name; - mElement->GetAttribute(NS_LITERAL_STRING("name"), name); - [self setTitle: [NSString stringWith_nsAString: name]]; - - nsCOMPtr content(do_QueryInterface(mElement)); - mBookmarkItem = BookmarksService::GetWrapperFor(content); -} - --(nsIDOMElement*)element -{ - return mElement; -} - -- (unsigned int)draggingSourceOperationMaskForLocal:(BOOL)flag -{ - return NSDragOperationGeneric; -} - -- (void) mouseDragged: (NSEvent*) aEvent -{ - // XXX mouseDragged is never called because buttons cancel dragging while you mouse down - // I have to fix this in an ugly way, by doing the "click" stuff myself and never relying - // on the superclass for that. Bah! - - // perhaps you could just implement mouseUp to perform the action (which should be the case - // things shouldn't happen on mouse down) Then does mouseDragged get overridden? - - // BookmarksService::DragBookmark(mElement, self, aEvent); -} - -@end diff --git a/mozilla/chimera/CHBookmarksOutlineView.h b/mozilla/chimera/CHBookmarksOutlineView.h deleted file mode 100644 index 2c01061c074..00000000000 --- a/mozilla/chimera/CHBookmarksOutlineView.h +++ /dev/null @@ -1,31 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- -* -* 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 the Mozilla browser. -* -* The Initial Developer of the Original Code is Netscape -* Communications Corporation. Portions created by Netscape are -* Copyright (C) 2002 Netscape Communications Corporation. All -* Rights Reserved. -* -* Contributor(s): -* Joe Hewitt (Original Author) -*/ - -#import -#import "CHExtendedOutlineView.h" - -@interface CHBookmarksOutlineView : CHExtendedOutlineView { - -} - -@end diff --git a/mozilla/chimera/CHBookmarksOutlineView.mm b/mozilla/chimera/CHBookmarksOutlineView.mm deleted file mode 100644 index f3a8942e9fe..00000000000 --- a/mozilla/chimera/CHBookmarksOutlineView.mm +++ /dev/null @@ -1,64 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- -* -* 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 the Mozilla browser. -* -* The Initial Developer of the Original Code is Netscape -* Communications Corporation. Portions created by Netscape are -* Copyright (C) 2002 Netscape Communications Corporation. All -* Rights Reserved. -* -* Contributor(s): -* Joe Hewitt (Original Author) -*/ - -#import "CHBookmarksOutlineView.h" -#import "BookmarksService.h" -#import "BookmarksDataSource.h" - -#include "nsCOMPtr.h" -#include "nsIDOMElement.h" -#include "nsIContent.h" -#include "nsIDOMNode.h" - -@implementation CHBookmarksOutlineView - -- (void)awakeFromNib -{ - [self registerForDraggedTypes:[NSArray arrayWithObjects:@"MozURLType", @"MozBookmarkType", NSStringPboardType, nil]]; -} - -- (void)draggedImage:(NSImage *)anImage endedAt:(NSPoint)aPoint operation:(NSDragOperation)operation -{ - if (operation == NSDragOperationDelete) { - NSArray* contentIds = nil; - NSPasteboard* pboard = [NSPasteboard pasteboardWithName:NSDragPboard]; - contentIds = [pboard propertyListForType: @"MozBookmarkType"]; - if (contentIds) { - for (unsigned int i = 0; i < [contentIds count]; ++i) { - BookmarkItem* item = [BookmarksService::gDictionary objectForKey: [contentIds objectAtIndex:i]]; - nsCOMPtr bookmarkElt = do_QueryInterface([item contentNode]); - BookmarksService::DeleteBookmark(bookmarkElt); - } - } - } -} - -- (unsigned int)draggingSourceOperationMaskForLocal:(BOOL)flag -{ - unsigned int result = [super draggingSourceOperationMaskForLocal:flag]; - if (flag == NO) - result &= NSDragOperationDelete; - return result; -} - -@end diff --git a/mozilla/chimera/CHBookmarksToolbar.h b/mozilla/chimera/CHBookmarksToolbar.h deleted file mode 100644 index 8f164fdaf8a..00000000000 --- a/mozilla/chimera/CHBookmarksToolbar.h +++ /dev/null @@ -1,58 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- -* -* 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 the Mozilla browser. -* -* The Initial Developer of the Original Code is Netscape -* Communications Corporation. Portions created by Netscape are -* Copyright (C) 2002 Netscape Communications Corporation. All -* Rights Reserved. -* -* Contributor(s): -* David Hyatt (Original Author) -*/ - -#import - -class nsIDOMElement; - -class BookmarksService; -class CHBookmarksButton; - -@interface CHBookmarksToolbar : NSView -{ - BookmarksService* mBookmarks; - NSMutableArray* mButtons; - CHBookmarksButton* mDragInsertionButton; - int mDragInsertionPosition; - BOOL mIsShowing; -} - --(void)initializeToolbar; - -// Called to construct & edit the initial set of personal toolbar buttons. --(void)buildButtonList; --(void)addButton: (nsIDOMElement*)aElt atIndex: (int)aIndex; --(void)editButton: (nsIDOMElement*)aElt; --(void)removeButton: (nsIDOMElement*)aElt; - -// Called to lay out the buttons on the toolbar. --(void)reflowButtons; --(void)reflowButtonsStartingAtIndex: (int)aIndex; - --(BOOL)isShown; --(void)showBookmarksToolbar: (BOOL)aShow; - -- (void) setButtonInsertionPoint:(NSPoint)aPoint; -- (NSRect)insertionRectForButton:(NSView*)aButton position:(int)aPosition; - -@end diff --git a/mozilla/chimera/CHBookmarksToolbar.mm b/mozilla/chimera/CHBookmarksToolbar.mm deleted file mode 100644 index c65d4d90c18..00000000000 --- a/mozilla/chimera/CHBookmarksToolbar.mm +++ /dev/null @@ -1,464 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- -* -* 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 the Mozilla browser. -* -* The Initial Developer of the Original Code is Netscape -* Communications Corporation. Portions created by Netscape are -* Copyright (C) 2002 Netscape Communications Corporation. All -* Rights Reserved. -* -* Contributor(s): -* David Hyatt (Original Author) -* Kathy Brade -* David Haas -*/ - -#import "CHBookmarksButton.h" -#import "CHBookmarksToolbar.h" -#import "BookmarksService.h" -#import "BookmarksDataSource.h" - -#include "nsIDOMElement.h" -#include "nsIContent.h" - -@interface CHBookmarksToolbar(Private) -- (CHBookmarksButton*)makeNewButtonWithElement:(nsIDOMElement*)element; -@end - -@implementation CHBookmarksToolbar - -- (id)initWithFrame:(NSRect)frame -{ - if ( (self = [super initWithFrame:frame]) ) { - mBookmarks = nsnull; - mButtons = [[NSMutableArray alloc] init]; - mDragInsertionButton = nil; - mDragInsertionPosition = BookmarksService::CHInsertNone; - [self registerForDraggedTypes:[NSArray arrayWithObjects:@"MozURLType", @"MozBookmarkType", NSStringPboardType, nil]]; - mIsShowing = YES; - } - return self; -} - --(void)initializeToolbar -{ - // Initialization code here. - mBookmarks = new BookmarksService(self); - mBookmarks->AddObserver(); - mBookmarks->EnsureToolbarRoot(); - [self buildButtonList]; -} - --(void) dealloc -{ - [mButtons autorelease]; - mBookmarks->RemoveObserver(); - delete mBookmarks; - [super dealloc]; -} - -- (void)drawRect:(NSRect)aRect { - // Fill the background with our background color. - //[[NSColor colorWithCalibratedWhite: 0.98 alpha: 1.0] set]; - //NSRectFill(aRect); - - //printf("The rect is: %f %f %f %f\n", aRect.origin.x, aRect.origin.y, aRect.size.width, aRect.size.height); - - if (aRect.origin.y + aRect.size.height == - [self bounds].size.height) { - // The personal toolbar is 21 pixels tall. The bottom two pixels - // are a separator. - [[NSColor colorWithCalibratedWhite: 0.90 alpha: 1.0] set]; - //NSRectFill(NSMakeRect(aRect.origin.x, [self bounds].size.height-2, aRect.size.width, [self bounds].size.height)); - } - - // The buttons will paint themselves. Just call our base class method. - [super drawRect: aRect]; - - // draw a separator at drag n drop insertion point if there is one - if (mDragInsertionPosition) { - [[[NSColor controlShadowColor] colorWithAlphaComponent:0.6] set]; - NSRectFill([self insertionRectForButton:mDragInsertionButton position:mDragInsertionPosition]); - } -} - --(void)buildButtonList -{ - // Build the buttons, and then lay them all out. - nsCOMPtr child; - BookmarksService::gToolbarRoot->GetFirstChild(getter_AddRefs(child)); - while (child) { - nsCOMPtr childElt(do_QueryInterface(child)); - if (childElt) { - CHBookmarksButton* button = [self makeNewButtonWithElement:childElt]; - [self addSubview: button]; - [mButtons addObject: button]; - } - - nsCOMPtr temp = child; - temp->GetNextSibling(getter_AddRefs(child)); - } - - if ([self isShown]) - [self reflowButtons]; -} - --(void)addButton: (nsIDOMElement*)aElt atIndex: (int)aIndex -{ - CHBookmarksButton* button = [self makeNewButtonWithElement:aElt]; - [self addSubview: button]; - [mButtons insertObject: button atIndex: aIndex]; - if ([self isShown]) - [self reflowButtonsStartingAtIndex: aIndex]; -} - --(void)editButton: (nsIDOMElement*)aElt -{ - int count = [mButtons count]; - for (int i = 0; i < count; i++) { - CHBookmarksButton* button = [mButtons objectAtIndex: i]; - if ([button element] == aElt) { - [button setElement: aElt]; - if (count > i && [self isShown]) - [self reflowButtonsStartingAtIndex: i]; - break; - } - } - - [self setNeedsDisplay: [self isShown]]; -} - --(void)removeButton: (nsIDOMElement*)aElt -{ - int count = [mButtons count]; - for (int i = 0; i < count; i++) { - CHBookmarksButton* button = [mButtons objectAtIndex: i]; - if ([button element] == aElt) { - [mButtons removeObjectAtIndex: i]; - [button removeFromSuperview]; - if (count > i && [self isShown]) - [self reflowButtonsStartingAtIndex: i]; - break; - } - } - - [self setNeedsDisplay: [self isShown]]; -} - --(void)reflowButtons -{ - [self reflowButtonsStartingAtIndex: 0]; -} - --(void)reflowButtonsStartingAtIndex: (int)aIndex -{ - float oldHeight = [self frame].size.height; - float computedHeight = 18; - int count = [mButtons count]; - float currY = 1.0; - float prevX = 2.0; - if (aIndex > 0) { - CHBookmarksButton* prevButton = [mButtons objectAtIndex: (aIndex-1)]; - prevX += [prevButton frame].origin.x + [prevButton frame].size.width; - currY = [prevButton frame].origin.y; - } - for (int i = aIndex; i < count; i++) { - CHBookmarksButton* button = [mButtons objectAtIndex: i]; - [button sizeToFit]; - float width = [button frame].size.width; - float height = [button frame].size.height; - if (width > 150) - width = 150; - if (height < 16) - height = 16; // Our folder tiff is only 15 pixels for some reason. - [button setFrame: NSMakeRect(prevX, currY, width, height)]; - - prevX += [button frame].size.width + 2; - - if ([self bounds].size.width < prevX) { - // The previous button didn't fit. We need to make a new row. There's no need to adjust the - // view's frame yet, we'll do that below. - currY += 18; - computedHeight += 18; - - prevX = 2; - [button setFrame: NSMakeRect(prevX, currY, width, height)]; - prevX += [button frame].size.width + 2; - } - - [button setNeedsDisplay: YES]; - } - - // our size has changed, readjust our view's frame and the content area - if (computedHeight != oldHeight) { - [self setFrame: NSMakeRect([self frame].origin.x, [self frame].origin.y + (oldHeight - computedHeight), - [self frame].size.width, computedHeight)]; - [self setNeedsDisplay: [self isShown]]; - - // adjust the content area. - float sizeChange = computedHeight - oldHeight; - NSView* view = [[[self window] windowController] getTabBrowser]; - [view setFrame: NSMakeRect([view frame].origin.x, [view frame].origin.y, - [view frame].size.width, [view frame].size.height - sizeChange)]; - } -} - --(BOOL)isFlipped -{ - return YES; // Use flipped coords, so we can layout out from top row to bottom row. -} - --(void)setFrame:(NSRect)aRect -{ - NSRect oldFrame = [self frame]; - [super setFrame:aRect]; - - if (oldFrame.size.width == aRect.size.width || aRect.size.height == 0) - return; - - int count = [mButtons count]; - if (count <= 2) - return; // We have too few buttons to care. - - // Do some optimizations when we have only one row. - if (aRect.size.height < 25) // We have only one row. - { - if (oldFrame.size.width < aRect.size.width) - // We got bigger. If we already only have one row, just bail. - // This will optimize for a common resizing case. - return; - else { - // We got smaller. Just go to the last button and see if it is outside - // our bounds. - CHBookmarksButton* button = [mButtons objectAtIndex:(count-1)]; - if ([button frame].origin.x + [button frame].size.width > - [self bounds].size.width - 2) { - // The button doesn't fit any more. Reflow starting at this index. - [self reflowButtonsStartingAtIndex:(count-1)]; - } - } - } - else { - // See if we got bigger or smaller. We could gain or lose a row. - [self reflowButtons]; - } -} - --(BOOL)isShown -{ - return mIsShowing; -} - --(void)showBookmarksToolbar: (BOOL)aShow -{ - if (!aShow) { - float height = [self bounds].size.height; - [self setFrame: NSMakeRect([self frame].origin.x, [self frame].origin.y + height, - [self frame].size.width, 0)]; - // We need to adjust the content area. - NSView* view = [[[self window] windowController] getTabBrowser]; - [view setFrame: NSMakeRect([view frame].origin.x, [view frame].origin.y, - [view frame].size.width, [view frame].size.height + height)]; - } - else - // Reflowing the buttons will do the right thing. - [self reflowButtons]; - - mIsShowing = aShow; -} - -- (void)setButtonInsertionPoint:(NSPoint)aPoint -{ - int count = [mButtons count]; - - mDragInsertionButton = nsnull; - mDragInsertionPosition = BookmarksService::CHInsertAfter; - - for (int i = 0; i < count; ++i) { - CHBookmarksButton* button = [mButtons objectAtIndex: i]; - //NSLog(@"check %d - %d,%d %d,%d\n", i, [button frame].origin.x, [button frame].origin.y, aPoint.x, aPoint.y); - // XXX origin.y is coming up zero here! Need that to check the row we're dragging in :( - - nsCOMPtr tagName; - nsCOMPtr contentNode = do_QueryInterface([button element]); - contentNode->GetTag(*getter_AddRefs(tagName)); - - if (tagName == BookmarksService::gFolderAtom) { - if (([button frame].origin.x+([button frame].size.width) > aPoint.x)) { - mDragInsertionButton = button; - mDragInsertionPosition = BookmarksService::CHInsertInto; - return; - } - } else if (([button frame].origin.x+([button frame].size.width/2) > aPoint.x)) { - mDragInsertionButton = button; - mDragInsertionPosition = BookmarksService::CHInsertBefore; - return; - } else if (([button frame].origin.x+([button frame].size.width) > aPoint.x)) { - mDragInsertionButton = button; - mDragInsertionPosition = BookmarksService::CHInsertAfter; - return; - } - } -} - -- (BOOL)dropDestinationValid:(NSPasteboard*)draggingPasteboard -{ - NSArray* types = [draggingPasteboard types]; - - if ([types containsObject: @"MozBookmarkType"]) - { - NSArray *draggedIDs = [draggingPasteboard propertyListForType: @"MozBookmarkType"]; - - nsCOMPtr destinationContent; - int index = 0; - - if (mDragInsertionPosition == BookmarksService::CHInsertInto) // drop onto folder - { - nsCOMPtr parentElt = [mDragInsertionButton element]; - destinationContent = do_QueryInterface(parentElt); - index = 0; - } - else if (mDragInsertionPosition == BookmarksService::CHInsertBefore || - mDragInsertionPosition == BookmarksService::CHInsertAfter) // drop onto toolbar - { - nsCOMPtr toolbarRoot = BookmarksService::gToolbarRoot; - destinationContent = do_QueryInterface(toolbarRoot); - index = [mButtons indexOfObject: mDragInsertionButton]; - } - - BookmarkItem* toolbarFolderItem = BookmarksService::GetWrapperFor(destinationContent); - if (!BookmarksService::IsBookmarkDropValid(toolbarFolderItem, index, draggedIDs)) { - return NO; - } - } - - return YES; -} - -// NSDraggingDestination /////////// - -- (unsigned int)draggingEntered:(id )sender -{ - if (![self dropDestinationValid:[sender draggingPasteboard]]) - return NSDragOperationNone; - - return NSDragOperationGeneric; -} - -- (void)draggingExited:(id )sender -{ - if (mDragInsertionPosition) - [self setNeedsDisplayInRect:[self insertionRectForButton:mDragInsertionButton position:mDragInsertionPosition]]; - - mDragInsertionButton = nil; - mDragInsertionPosition = BookmarksService::CHInsertNone; -} - -- (unsigned int)draggingUpdated:(id )sender -{ - if (mDragInsertionPosition) - [self setNeedsDisplayInRect:[self insertionRectForButton:mDragInsertionButton position:mDragInsertionPosition]]; - - if (![self dropDestinationValid:[sender draggingPasteboard]]) - return NSDragOperationNone; - - [self setButtonInsertionPoint:[sender draggingLocation]]; - - if (mDragInsertionPosition) - [self setNeedsDisplayInRect:[self insertionRectForButton:mDragInsertionButton position:mDragInsertionPosition]]; - - return NSDragOperationGeneric; -} - -- (BOOL)prepareForDragOperation:(id )sender -{ - return YES; -} - -- (BOOL)performDragOperation:(id )sender -{ - BookmarkItem* parent = nsnull; - int index = 0; - - if (mDragInsertionPosition == BookmarksService::CHInsertInto) { // drop onto folder - nsCOMPtr parentElt = [mDragInsertionButton element]; - nsCOMPtr parentContent(do_QueryInterface(parentElt)); - parent = BookmarksService::GetWrapperFor(parentContent); - index = 0; - } - else if (mDragInsertionPosition == BookmarksService::CHInsertBefore || - mDragInsertionPosition == BookmarksService::CHInsertAfter) { // drop onto toolbar - nsCOMPtr rootElt = BookmarksService::gToolbarRoot; - nsCOMPtr rootContent(do_QueryInterface(rootElt)); - parent = BookmarksService::GetWrapperFor(rootContent); - index = [mButtons indexOfObject: mDragInsertionButton]; - if (index == NSNotFound) - rootContent->ChildCount(index); - else if (mDragInsertionPosition == BookmarksService::CHInsertAfter) - index++; - } else { - mDragInsertionButton = nil; - mDragInsertionPosition = BookmarksService::CHInsertNone; - [self setNeedsDisplay:YES]; - return NO; - } - - BOOL dropHandled = NO; - NSArray *draggedTypes = [[sender draggingPasteboard] types]; - if ( [draggedTypes containsObject:@"MozBookmarkType"] ) - { - NSArray *draggedItems = [[sender draggingPasteboard] propertyListForType: @"MozBookmarkType"]; - dropHandled = BookmarksService::PerformBookmarkDrop(parent, index, draggedItems); - } - else if ( [draggedTypes containsObject:@"MozURLType"] ) - { - NSDictionary* proxy = [[sender draggingPasteboard] propertyListForType: @"MozURLType"]; - nsCOMPtr beforeContent; - [parent contentNode]->ChildAt(index, *getter_AddRefs(beforeContent)); - BookmarkItem* beforeItem = mBookmarks->GetWrapperFor(beforeContent); // can handle nil content - dropHandled = BookmarksService::PerformProxyDrop(parent, beforeItem, proxy); - } - else if ( [draggedTypes containsObject:NSStringPboardType] ) - { - NSString* draggedText = [[sender draggingPasteboard] stringForType:NSStringPboardType]; - nsCOMPtr beforeContent; - [parent contentNode]->ChildAt(index, *getter_AddRefs(beforeContent)); - BookmarkItem* beforeItem = mBookmarks->GetWrapperFor(beforeContent); // can handle nil content - // maybe fix URL drags to include the selected text as the title - dropHandled = BookmarksService::PerformURLDrop(parent, beforeItem, draggedText, draggedText); - } - - mDragInsertionButton = nil; - mDragInsertionPosition = BookmarksService::CHInsertNone; - [self setNeedsDisplay: [self isShown]]; - - return dropHandled; -} - -- (NSRect)insertionRectForButton:(NSView*)aButton position:(int) aPosition -{ - if (aPosition == BookmarksService::CHInsertInto) { - return NSMakeRect([aButton frame].origin.x, [aButton frame].origin.y, [aButton frame].size.width, [aButton frame].size.height); - } else if (aPosition == BookmarksService::CHInsertAfter) { - return NSMakeRect([aButton frame].origin.x+[aButton frame].size.width, [aButton frame].origin.y, 2, [aButton frame].size.height); - } else {// if (aPosition == BookmarksService::CHInsertBefore) { - return NSMakeRect([aButton frame].origin.x - 2, [aButton frame].origin.y, 2, [aButton frame].size.height); - } -} - -- (CHBookmarksButton*)makeNewButtonWithElement:(nsIDOMElement*)element -{ - return [[[CHBookmarksButton alloc] initWithFrame: NSMakeRect(2, 1, 100, 17) element:element bookmarksService:mBookmarks] autorelease]; -} - -@end diff --git a/mozilla/chimera/CHBrowserView.h b/mozilla/chimera/CHBrowserView.h deleted file mode 100644 index ccf88cdd477..00000000000 --- a/mozilla/chimera/CHBrowserView.h +++ /dev/null @@ -1,200 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape 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/NPL/ - * - * 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 mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1998 - * 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 NPL, 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 NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef __nsCocoaBrowserView_h__ -#define __nsCocoaBrowserView_h__ - -#undef DARWIN -#import - -@class CHBrowserView; -class nsCocoaBrowserListener; -class nsIDOMWindow; -class nsIWebBrowser; -class nsIDOMNode; -class nsIDOMEvent; -class nsIWebBrowserFind; -class nsIEventSink; -class nsIDragHelperService; - - -// Protocol implemented by anyone interested in progress -// related to a BrowserView. A listener should explicitly -// register itself with the view using the addListener -// method. -@protocol NSBrowserListener - -- (void)onLoadingStarted; -- (void)onLoadingCompleted:(BOOL)succeeded; -// Invoked regularly as data associated with a page streams -// in. If the total number of bytes expected is unknown, -// maxBytes is -1. -- (void)onProgressChange:(int)currentBytes outOf:(int)maxBytes; -- (void)onLocationChange:(NSString*)urlSpec; -- (void)onStatusChange:(NSString*)aMessage; -- (void)onSecurityStateChange:(unsigned long)newState; -// Called when a context menu should be shown. -- (void)onShowContextMenu:(int)flags domEvent:(nsIDOMEvent*)aEvent domNode:(nsIDOMNode*)aNode; -// Called when a tooltip should be shown or hidden -- (void)onShowTooltip:(NSPoint)where withText:(NSString*)text; -- (void)onHideTooltip; - -@end - -typedef enum { - NSStatusTypeScript = 0x0001, - NSStatusTypeScriptDefault = 0x0002, - NSStatusTypeLink = 0x0003, -} NSStatusType; - -@protocol NSBrowserContainer - -- (void)setStatus:(NSString *)statusString ofType:(NSStatusType)type; -- (NSString *)title; -- (void)setTitle:(NSString *)title; -// Set the dimensions of our NSView. The container might need to do -// some adjustment, so the view doesn't do it directly. -- (void)sizeBrowserTo:(NSSize)dimensions; -// Create a new browser container window and return the contained view. -- (CHBrowserView*)createBrowserWindow:(unsigned int)mask; - -- (NSMenu*)getContextMenu; -- (NSWindow*)getNativeWindow; - -// Ask whether the browser should accept a drag from the given source. -// Should return NO if the source is a container for the browser, or -// another item that represents the same entity (e.g. tab or proxy icon) -- (BOOL)shouldAcceptDragFromSource:(id)dragSource; - -@end - -enum { - NSLoadFlagsNone = 0x0000, - NSLoadFlagsDontPutInHistory = 0x0010, - NSLoadFlagsReplaceHistoryEntry = 0x0020, - NSLoadFlagsBypassCacheAndProxy = 0x0040 -}; - -enum { - NSStopLoadNetwork = 0x01, - NSStopLoadContent = 0x02, - NSStopLoadAll = 0x03 -}; - -@interface CHBrowserView : NSView -{ - nsIWebBrowser* _webBrowser; - nsCocoaBrowserListener* _listener; - NSWindow* mWindow; - - nsIDragHelperService* mDragHelper; - NSPoint mLastTrackedLocation; - NSWindow* mLastTrackedWindow; -} - -// NSView overrides -- (id)initWithFrame:(NSRect)frame; -- (id)initWithFrame:(NSRect)frame andWindow:(NSWindow*)aWindow; - -- (void)dealloc; -- (void)setFrame:(NSRect)frameRect; - -// nsIWebBrowser methods -- (void)addListener:(id )listener; -- (void)removeListener:(id )listener; -- (void)setContainer:(id )container; -- (nsIDOMWindow*)getContentWindow; - -// nsIWebNavigation methods -- (void)loadURI:(NSString *)urlSpec referrer:(NSString*)referrer flags:(unsigned int)flags; -- (void)reload:(unsigned int)flags; -- (BOOL)canGoBack; -- (BOOL)canGoForward; -- (void)goBack; -- (void)goForward; -- (void)gotoIndex:(int)index; -- (void)stop:(unsigned int)flags; -- (NSString*)getCurrentURI; - -- (void)saveDocument: (NSView*)aFilterView filterList: (NSPopUpButton*)aFilterList; -- (void)saveURL: (NSView*)aFilterView filterList: (NSPopUpButton*)aFilterList - url: (NSString*)aURLSpec suggestedFilename: (NSString*)aFilename; - -- (void)printDocument; - -- (BOOL)findInPageWithPattern:(NSString*)inText caseSensitive:(BOOL)inCaseSensitive - wrap:(BOOL)inWrap backwards:(BOOL)inBackwards; - --(BOOL)validateMenuItem: (NSMenuItem*)aMenuItem; - --(IBAction)cut:(id)aSender; --(BOOL)canCut; --(IBAction)copy:(id)aSender; --(BOOL)canCopy; --(IBAction)paste:(id)aSender; --(BOOL)canPaste; --(IBAction)delete:(id)aSender; --(BOOL)canDelete; --(IBAction)selectAll:(id)aSender; - --(IBAction)undo:(id)aSender; --(IBAction)redo:(id)aSender; - -- (BOOL)canUndo; -- (BOOL)canRedo; - --(NSString*)getCurrentURLSpec; - -- (void)setActive: (BOOL)aIsActive; - -- (NSMenu*)getContextMenu; -- (NSWindow*)getNativeWindow; - -- (void)destroyWebBrowser; -- (nsIWebBrowser*)getWebBrowser; -- (nsCocoaBrowserListener*)getCocoaBrowserListener; -- (void)setWebBrowser:(nsIWebBrowser*)browser; - -- (NSString*)getFocusedURLString; - - // given a point in window coordinates, find the Gecko event sink of the ChildView the - // point is over. -- (void) findEventSink:(nsIEventSink**)outSink forPoint:(NSPoint)inPoint inWindow:(NSWindow*)inWind; - -@end - -#endif // __nsCocoaBrowserView_h__ diff --git a/mozilla/chimera/CHBrowserView.mm b/mozilla/chimera/CHBrowserView.mm deleted file mode 100644 index 3006c0304d1..00000000000 --- a/mozilla/chimera/CHBrowserView.mm +++ /dev/null @@ -1,870 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape 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/NPL/ - * - * 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 mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1998 - * 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 NPL, 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 NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#import "NSString+Utils.h" - -#include "nsCWebBrowser.h" -#include "nsIBaseWindow.h" -#include "nsIWebNavigation.h" -#include "nsComponentManagerUtils.h" - -#include "nsIURI.h" -#include "nsIDOMWindow.h" -#include "nsIWidget.h" - -// Printing -#include "nsIWebBrowserPrint.h" -//#include "nsIPrintSettings.h" - -// Saving of links/images/docs -#include "nsIWebBrowserFocus.h" -#include "nsIDOMNSDocument.h" -#include "nsIDOMLocation.h" -#include "nsIWebBrowserPersist.h" -#include "nsIProperties.h" -//#include "nsIRequest.h" -//#include "nsIPrefService.h" -#include "nsISHistory.h" -#include "nsIHistoryEntry.h" -#include "nsISHEntry.h" -#include "nsNetUtil.h" -#include "SaveHeaderSniffer.h" - -#import "CHBrowserWrapper.h" -#import "CHBrowserView.h" - -#import "FindDlgController.h" -#import "nsCocoaBrowserService.h" -#import "nsCocoaBrowserListener.h" - -#import "mozView.h" - -typedef unsigned int DragReference; -#include "nsIDragHelperService.h" - -// Cut/copy/paste -#include "nsIClipboardCommands.h" -#include "nsIInterfaceRequestorUtils.h" - -// Undo/redo -#include "nsICommandManager.h" -#include "nsICommandParams.h" - - -const char kPersistContractID[] = "@mozilla.org/embedding/browser/nsWebBrowserPersist;1"; -const char kDirServiceContractID[] = "@mozilla.org/file/directory_service;1"; - -@implementation CHBrowserView - -- (id)initWithFrame:(NSRect)frame andWindow:(NSWindow*)aWindow -{ - mWindow = aWindow; - return [self initWithFrame:frame]; -} - -- (id)initWithFrame:(NSRect)frame -{ - if ( (self = [super initWithFrame:frame]) ) - { - nsresult rv = nsCocoaBrowserService::InitEmbedding(); - if (NS_FAILED(rv)) { -// XXX need to throw - } - - _listener = new nsCocoaBrowserListener(self); - NS_ADDREF(_listener); - -// Create the web browser instance - nsCOMPtr browser = do_CreateInstance(NS_WEBBROWSER_CONTRACTID, &rv); - if (NS_FAILED(rv)) { -// XXX need to throw - } - - _webBrowser = browser; - NS_ADDREF(_webBrowser); - -// Set the container nsIWebBrowserChrome - _webBrowser->SetContainerWindow(NS_STATIC_CAST(nsIWebBrowserChrome *, _listener)); - -// Register as a listener for web progress - nsCOMPtr weak = do_GetWeakReference(NS_STATIC_CAST(nsIWebProgressListener*, _listener)); - _webBrowser->AddWebBrowserListener(weak, NS_GET_IID(nsIWebProgressListener)); - -// Hook up the widget hierarchy with us as the parent - nsCOMPtr baseWin = do_QueryInterface(_webBrowser); - baseWin->InitWindow((NSView*)self, nsnull, 0, 0, - frame.size.width, frame.size.height); - baseWin->Create(); - -// register the view as a drop site for text, files, and urls. - [self registerForDraggedTypes: [NSArray arrayWithObjects: - @"MozURLType", NSStringPboardType, NSURLPboardType, NSFilenamesPboardType, nil]]; - } - return self; -} - -- (void)destroyWebBrowser -{ - nsCOMPtr baseWin = do_QueryInterface(_webBrowser); - baseWin->Destroy(); -} - -- (void)dealloc -{ - NS_RELEASE(_listener); - NS_IF_RELEASE(_webBrowser); - - nsCocoaBrowserService::BrowserClosed(); - -#if DEBUG - NSLog(@"CHBrowserView died."); -#endif - - [super dealloc]; -} - -- (void)setFrame:(NSRect)frameRect -{ - [super setFrame:frameRect]; - if (_webBrowser) { - nsCOMPtr window = do_QueryInterface(_webBrowser); - window->SetSize((PRInt32)frameRect.size.width, - (PRInt32)frameRect.size.height, - PR_TRUE); - } -} - -- (void)addListener:(id )listener -{ - _listener->AddListener(listener); -} - -- (void)removeListener:(id )listener -{ - _listener->RemoveListener(listener); -} - -- (void)setContainer:(id )container -{ - _listener->SetContainer(container); -} - -- (nsIDOMWindow*)getContentWindow -{ - nsIDOMWindow* window; - - _webBrowser->GetContentDOMWindow(&window); - - return window; -} - -- (void)loadURI:(NSString *)urlSpec referrer:(NSString*)referrer flags:(unsigned int)flags -{ - nsCOMPtr nav = do_QueryInterface(_webBrowser); - - int length = [urlSpec length]; - PRUnichar* specStr = nsMemory::Alloc((length+1) * sizeof(PRUnichar)); - [urlSpec getCharacters:specStr]; - specStr[length] = PRUnichar(0); - - nsCOMPtr referrerURI; - if ( referrer ) - NS_NewURI(getter_AddRefs(referrerURI), [referrer UTF8String]); - - PRUint32 navFlags = nsIWebNavigation::LOAD_FLAGS_NONE; - if (flags & NSLoadFlagsDontPutInHistory) { - navFlags |= nsIWebNavigation::LOAD_FLAGS_BYPASS_HISTORY; - } - if (flags & NSLoadFlagsReplaceHistoryEntry) { - navFlags |= nsIWebNavigation::LOAD_FLAGS_REPLACE_HISTORY; - } - if (flags & NSLoadFlagsBypassCacheAndProxy) { - navFlags |= nsIWebNavigation::LOAD_FLAGS_BYPASS_CACHE | - nsIWebNavigation::LOAD_FLAGS_BYPASS_PROXY; - } - - nsresult rv = nav->LoadURI(specStr, navFlags, referrerURI, nsnull, nsnull); - if (NS_FAILED(rv)) { - // XXX need to throw - } - - nsMemory::Free(specStr); -} - -- (void)reload:(unsigned int)flags -{ - nsCOMPtr nav = do_QueryInterface(_webBrowser); - - PRUint32 navFlags = nsIWebNavigation::LOAD_FLAGS_NONE; - if (flags & NSLoadFlagsBypassCacheAndProxy) { - navFlags |= nsIWebNavigation::LOAD_FLAGS_BYPASS_CACHE | - nsIWebNavigation::LOAD_FLAGS_BYPASS_PROXY; - } - - nsresult rv = nav->Reload(navFlags); - if (NS_FAILED(rv)) { - // XXX need to throw - } -} - -- (BOOL)canGoBack -{ - nsCOMPtr nav = do_QueryInterface(_webBrowser); - - PRBool can; - nav->GetCanGoBack(&can); - - return can ? YES : NO; -} - -- (BOOL)canGoForward -{ - nsCOMPtr nav = do_QueryInterface(_webBrowser); - - PRBool can; - nav->GetCanGoForward(&can); - - return can ? YES : NO; -} - -- (void)goBack -{ - nsCOMPtr nav = do_QueryInterface(_webBrowser); - - nsresult rv = nav->GoBack(); - if (NS_FAILED(rv)) { - // XXX need to throw - } -} - -- (void)goForward -{ - nsCOMPtr nav = do_QueryInterface(_webBrowser); - - nsresult rv = nav->GoForward(); - if (NS_FAILED(rv)) { - // XXX need to throw - } -} - -- (void)gotoIndex:(int)index -{ - nsCOMPtr nav = do_QueryInterface(_webBrowser); - - nsresult rv = nav->GotoIndex(index); - if (NS_FAILED(rv)) { - // XXX need to throw - } -} - -- (void)stop:(unsigned int)flags -{ - nsCOMPtr nav = do_QueryInterface(_webBrowser); - - nsresult rv = nav->Stop(flags); - if (NS_FAILED(rv)) { - // XXX need to throw - } -} - -// XXXbryner This isn't used anywhere. how is it different from getCurrentURLSpec? -- (NSString*)getCurrentURI -{ - nsCOMPtr uri; - nsCOMPtr nav = do_QueryInterface(_webBrowser); - - nav->GetCurrentURI(getter_AddRefs(uri)); - if (!uri) { - return nsnull; - } - - nsCAutoString spec; - uri->GetSpec(spec); - - const char* cstr = spec.get(); - NSString* str = [NSString stringWithCString:cstr]; - - return str; -} - -- (nsCocoaBrowserListener*)getCocoaBrowserListener -{ - return _listener; -} - -- (nsIWebBrowser*)getWebBrowser -{ - NS_IF_ADDREF(_webBrowser); - return _webBrowser; -} - -- (void)setWebBrowser:(nsIWebBrowser*)browser -{ - _webBrowser = browser; - - if (_webBrowser) { - // Set the container nsIWebBrowserChrome - _webBrowser->SetContainerWindow(NS_STATIC_CAST(nsIWebBrowserChrome *, - _listener)); - - NSRect frame = [self frame]; - - // Hook up the widget hierarchy with us as the parent - nsCOMPtr baseWin = do_QueryInterface(_webBrowser); - baseWin->InitWindow((NSView*)self, nsnull, 0, 0, - frame.size.width, frame.size.height); - baseWin->Create(); - } - -} - --(void) saveInternal: (nsIURI*)aURI - withDocument: (nsIDOMDocument*)aDocument - suggestedFilename: (const char*)aFilename - bypassCache: (BOOL)aBypassCache - filterView: (NSView*)aFilterView - filterList: (NSPopUpButton*)aFilterList -{ - // Create our web browser persist object. This is the object that knows - // how to actually perform the saving of the page (and of the images - // on the page). - nsCOMPtr webPersist(do_CreateInstance(kPersistContractID)); - if (!webPersist) - return; - - // Make a temporary file object that we can save to. - nsCOMPtr dirService(do_GetService(kDirServiceContractID)); - if (!dirService) - return; - nsCOMPtr tmpFile; - dirService->Get("TmpD", NS_GET_IID(nsIFile), getter_AddRefs(tmpFile)); - static short unsigned int tmpRandom = 0; - nsAutoString tmpNo; tmpNo.AppendInt(tmpRandom++); - nsAutoString saveFile(NS_LITERAL_STRING("-sav")); - saveFile += tmpNo; - saveFile += NS_LITERAL_STRING("tmp"); - tmpFile->Append(saveFile); - - // Get the post data if we're an HTML doc. - nsCOMPtr postData; - if (aDocument) { - nsCOMPtr webNav(do_QueryInterface(_webBrowser)); - nsCOMPtr sessionHistory; - webNav->GetSessionHistory(getter_AddRefs(sessionHistory)); - nsCOMPtr entry; - PRInt32 sindex; - sessionHistory->GetIndex(&sindex); - sessionHistory->GetEntryAtIndex(sindex, PR_FALSE, getter_AddRefs(entry)); - nsCOMPtr shEntry(do_QueryInterface(entry)); - if (shEntry) - shEntry->GetPostData(getter_AddRefs(postData)); - } - - // when saving, we first fire off a save with a nsHeaderSniffer as a progress - // listener. This allows us to look for the content-disposition header, which - // can supply a filename, and maybe has something to do with CGI-generated - // content (?) - nsCAutoString fileName(aFilename); - nsHeaderSniffer* sniffer = new nsHeaderSniffer(webPersist, tmpFile, aURI, - aDocument, postData, fileName, aBypassCache, - aFilterView, aFilterList); - if (!sniffer) - return; - webPersist->SetProgressListener(sniffer); // owned - webPersist->SaveURI(aURI, nsnull, tmpFile); -} - --(void)printDocument -{ - nsCOMPtr domWindow; - _webBrowser->GetContentDOMWindow(getter_AddRefs(domWindow)); - nsCOMPtr ir(do_QueryInterface(domWindow)); - nsCOMPtr print; - ir->GetInterface(NS_GET_IID(nsIWebBrowserPrint), getter_AddRefs(print)); - print->Print(nsnull, nsnull); -} - -- (BOOL)findInPageWithPattern:(NSString*)inText caseSensitive:(BOOL)inCaseSensitive - wrap:(BOOL)inWrap backwards:(BOOL)inBackwards -{ - PRBool found = PR_FALSE; - - nsCOMPtr wbf(do_QueryInterface(_webBrowser)); - nsCOMPtr rootWindow; - nsCOMPtr focusedWindow; - _webBrowser->GetContentDOMWindow(getter_AddRefs(rootWindow)); - wbf->GetFocusedWindow(getter_AddRefs(focusedWindow)); - if (!focusedWindow) - focusedWindow = rootWindow; - nsCOMPtr webFind(do_GetInterface(_webBrowser)); - if ( webFind ) { - nsCOMPtr framesFind(do_QueryInterface(webFind)); - framesFind->SetRootSearchFrame(rootWindow); - framesFind->SetCurrentSearchFrame(focusedWindow); - - webFind->SetMatchCase(inCaseSensitive ? PR_TRUE : PR_FALSE); - webFind->SetWrapFind(inWrap ? PR_TRUE : PR_FALSE); - webFind->SetFindBackwards(inBackwards ? PR_TRUE : PR_FALSE); - - PRUnichar* text = (PRUnichar*)nsMemory::Alloc(([inText length]+1)*sizeof(PRUnichar)); - if ( text ) { - [inText getCharacters:text]; - text[[inText length]] = 0; - webFind->SetSearchString(text); - webFind->FindNext(&found); - nsMemory::Free(text); - } - } - return found; -} - -- (void)saveURL: (NSView*)aFilterView filterList: (NSPopUpButton*)aFilterList - url: (NSString*)aURLSpec suggestedFilename: (NSString*)aFilename -{ - nsCOMPtr url; - nsresult rv = NS_NewURI(getter_AddRefs(url), [aURLSpec UTF8String]); - if (NS_FAILED(rv)) - return; - - [self saveInternal: url.get() - withDocument: nsnull - suggestedFilename: (([aFilename length] > 0) ? [aFilename fileSystemRepresentation] : "") - bypassCache: YES - filterView: aFilterView - filterList: aFilterList]; -} - --(NSString*)getFocusedURLString -{ - nsCOMPtr wbf(do_QueryInterface(_webBrowser)); - nsCOMPtr domWindow; - wbf->GetFocusedWindow(getter_AddRefs(domWindow)); - if (!domWindow) - _webBrowser->GetContentDOMWindow(getter_AddRefs(domWindow)); - if (!domWindow) - return @""; - - nsCOMPtr domDocument; - domWindow->GetDocument(getter_AddRefs(domDocument)); - if (!domDocument) - return @""; - nsCOMPtr nsDoc(do_QueryInterface(domDocument)); - if (!nsDoc) - return @""; - nsCOMPtr location; - nsDoc->GetLocation(getter_AddRefs(location)); - if (!location) - return @""; - nsAutoString urlStr; - location->GetHref(urlStr); - return [NSString stringWith_nsAString: urlStr]; -} - -- (void)saveDocument: (NSView*)aFilterView filterList: (NSPopUpButton*)aFilterList -{ - nsCOMPtr wbf(do_QueryInterface(_webBrowser)); - nsCOMPtr domWindow; - wbf->GetFocusedWindow(getter_AddRefs(domWindow)); - if (!domWindow) - _webBrowser->GetContentDOMWindow(getter_AddRefs(domWindow)); - if (!domWindow) - return; - - nsCOMPtr domDocument; - domWindow->GetDocument(getter_AddRefs(domDocument)); - if (!domDocument) - return; - nsCOMPtr nsDoc(do_QueryInterface(domDocument)); - if (!nsDoc) - return; - nsCOMPtr location; - nsDoc->GetLocation(getter_AddRefs(location)); - if (!location) - return; - nsAutoString urlStr; - location->GetHref(urlStr); - nsCAutoString urlCStr; urlCStr.AssignWithConversion(urlStr); - nsCOMPtr url; - nsresult rv = NS_NewURI(getter_AddRefs(url), urlCStr.get()); - if (NS_FAILED(rv)) - return; - - [self saveInternal: url.get() - withDocument: domDocument - suggestedFilename: "" - bypassCache: NO - filterView: aFilterView - filterList: aFilterList]; -} - --(void)doCommand:(const char*)commandName -{ - nsCOMPtr commandMgr(do_GetInterface(_webBrowser)); - if (commandMgr) { - nsCOMPtr commandParams = do_CreateInstance("@mozilla.org/embedcomp/command-params;1"); - if (commandParams) { - nsresult rv; - - nsAutoString commandNameStr; - commandNameStr.AssignWithConversion(commandName); - - rv = commandParams->SetStringValue(NS_LITERAL_STRING("cmd_name"), commandNameStr); - rv = commandMgr->DoCommand(commandParams); -#if DEBUG - if (NS_FAILED(rv)) - NSLog(@"DoCommand failed"); -#endif - } - else { -#if DEBUG - NSLog(@"Failed to make command params"); -#endif - } - } - else { -#if DEBUG - NSLog(@"No command manager"); -#endif - } -} - --(BOOL)isCommandEnabled:(const char*)commandName -{ - PRBool isEnabled = PR_FALSE; - nsCOMPtr commandMgr(do_GetInterface(_webBrowser)); - if (commandMgr) { - nsAutoString commandNameStr; - commandNameStr.AssignWithConversion(commandName); - nsresult rv = commandMgr->IsCommandEnabled(commandNameStr, &isEnabled); -#if DEBUG - if (NS_FAILED(rv)) - NSLog(@"IsCommandEnabled failed"); -#endif - } - else { -#if DEBUG - NSLog(@"No command manager"); -#endif - } - - return (isEnabled) ? YES : NO; -} - - --(IBAction)cut:(id)aSender -{ - nsCOMPtr clipboard(do_GetInterface(_webBrowser)); - clipboard->CutSelection(); -} - --(BOOL)canCut -{ - PRBool canCut = PR_FALSE; - nsCOMPtr clipboard(do_GetInterface(_webBrowser)); - clipboard->CanCutSelection(&canCut); - return canCut; -} - --(IBAction)copy:(id)aSender -{ - nsCOMPtr clipboard(do_GetInterface(_webBrowser)); - clipboard->CopySelection(); -} - --(BOOL)canCopy -{ - PRBool canCut = PR_FALSE; - nsCOMPtr clipboard(do_GetInterface(_webBrowser)); - clipboard->CanCopySelection(&canCut); - return canCut; -} - --(IBAction)paste:(id)aSender -{ - nsCOMPtr clipboard(do_GetInterface(_webBrowser)); - clipboard->Paste(); -} - --(BOOL)canPaste -{ - PRBool canCut = PR_FALSE; - nsCOMPtr clipboard(do_GetInterface(_webBrowser)); - clipboard->CanPaste(&canCut); - return canCut; -} - --(IBAction)delete:(id)aSender -{ - [self doCommand: "cmd_delete"]; -} - --(BOOL)canDelete -{ - return [self isCommandEnabled: "cmd_delete"]; -} - --(IBAction)selectAll:(id)aSender -{ - nsCOMPtr clipboard(do_GetInterface(_webBrowser)); - clipboard->SelectAll(); -} - --(IBAction)undo:(id)aSender -{ - [self doCommand: "cmd_undo"]; -} - --(IBAction)redo:(id)aSender -{ - [self doCommand: "cmd_redo"]; -} - -- (BOOL)canUndo -{ - return [self isCommandEnabled: "cmd_undo"]; -} - -- (BOOL)canRedo -{ - return [self isCommandEnabled: "cmd_redo"]; -} - --(NSString*)getCurrentURLSpec -{ - NSString* empty = @""; - nsCOMPtr domWindow; - _webBrowser->GetContentDOMWindow(getter_AddRefs(domWindow)); - if (!domWindow) - return empty; - - nsCOMPtr domDocument; - domWindow->GetDocument(getter_AddRefs(domDocument)); - if (!domDocument) - return empty; - nsCOMPtr nsDoc(do_QueryInterface(domDocument)); - if (!nsDoc) - return empty; - nsCOMPtr location; - nsDoc->GetLocation(getter_AddRefs(location)); - if (!location) - return empty; - - nsAutoString urlStr; - location->GetHref(urlStr); - return [NSString stringWith_nsAString: urlStr]; -} - -- (void)setActive: (BOOL)aIsActive -{ - nsCOMPtr wbf(do_QueryInterface(_webBrowser)); - if (aIsActive) - wbf->Activate(); - else - wbf->Deactivate(); -} - --(NSMenu*)getContextMenu -{ - if ([[self superview] conformsToProtocol:@protocol(NSBrowserContainer)]) - { - id browserContainer = [self superview]; - return [browserContainer getContextMenu]; - } - - return nil; -} - --(NSWindow*)getNativeWindow -{ - NSWindow* window = [self window]; - if (window) - return window; // We're visible. Just hand the window back. - - // We're invisible. It's likely that we're in a Cocoa tab view. - // First see if we have a cached window. - if (mWindow) - return mWindow; - - // Finally, see if our parent responds to the getNativeWindow selector, - // and if they do, let them handle it. - if ([[self superview] conformsToProtocol:@protocol(NSBrowserContainer)]) - { - id browserContainer = [self superview]; - return [browserContainer getNativeWindow]; - } - - return nil; -} - - -// -// -findEventSink:forPoint:inWindow: -// -// Given a point in window coordinates, find the Gecko event sink of the ChildView -// the point is over. This involves first converting the point to this view's -// coordinate system and using hitTest: to get the subview. Then we get -// that view's widget and QI it to an event sink -// -- (void) findEventSink:(nsIEventSink**)outSink forPoint:(NSPoint)inPoint inWindow:(NSWindow*)inWind -{ - NSPoint localPoint = [self convertPoint:inPoint fromView:[inWind contentView]]; - NSView* hitView = [self hitTest:localPoint]; - if ( [hitView conformsToProtocol:@protocol(mozView)] ) { - nsCOMPtr sink (do_QueryInterface([hitView widget])); - *outSink = sink.get(); - NS_IF_ADDREF(*outSink); - } -} - -#pragma mark - - -- (BOOL)shouldAcceptDrag:(id )sender -{ - if ([[self superview] conformsToProtocol:@protocol(NSBrowserContainer)]) - { - id browserContainer = [self superview]; - return [browserContainer shouldAcceptDragFromSource:[sender draggingSource]]; - } - return YES; -} - -- (unsigned int)draggingEntered:(id )sender -{ - if (![self shouldAcceptDrag:sender]) - return NSDragOperationNone; - -// NSLog(@"draggingEntered"); - nsCOMPtr helper(do_GetService("@mozilla.org/widget/draghelperservice;1")); - mDragHelper = helper.get(); - NS_IF_ADDREF(mDragHelper); - NS_ASSERTION ( mDragHelper, "Couldn't get a drag service, we're in big trouble" ); - - if ( mDragHelper ) { - mLastTrackedLocation = [sender draggingLocation]; - mLastTrackedWindow = [sender draggingDestinationWindow]; - nsCOMPtr sink; - [self findEventSink:getter_AddRefs(sink) forPoint:mLastTrackedLocation inWindow:mLastTrackedWindow]; - if (sink) - mDragHelper->Enter ( [sender draggingSequenceNumber], sink ); - } - - return NSDragOperationCopy; -} - -- (void)draggingExited:(id )sender -{ -// NSLog(@"draggingExited"); - if ( mDragHelper ) { - nsCOMPtr sink; - - [self findEventSink:getter_AddRefs(sink) - forPoint:mLastTrackedLocation /* [sender draggingLocation] */ - inWindow:mLastTrackedWindow /* [sender draggingDestinationWindow] */ - ]; - if (sink) - mDragHelper->Leave( [sender draggingSequenceNumber], sink ); - NS_RELEASE(mDragHelper); - } -} - -- (unsigned int)draggingUpdated:(id )sender -{ - if (![self shouldAcceptDrag:sender]) - return NSDragOperationNone; - -// NSLog(@"draggingUpdated"); - PRBool dropAllowed = PR_FALSE; - if ( mDragHelper ) { - mLastTrackedLocation = [sender draggingLocation]; - mLastTrackedWindow = [sender draggingDestinationWindow]; - nsCOMPtr sink; - [self findEventSink:getter_AddRefs(sink) forPoint:mLastTrackedLocation inWindow:mLastTrackedWindow]; - if (sink) - mDragHelper->Tracking([sender draggingSequenceNumber], sink, &dropAllowed); - } - - return dropAllowed ? NSDragOperationCopy : NSDragOperationNone; -} - -- (BOOL)prepareForDragOperation:(id )sender -{ - return YES; -} - -- (BOOL)performDragOperation:(id )sender -{ - if (![self shouldAcceptDrag:sender]) - return NO; - - PRBool dragAccepted = PR_FALSE; - - if ( mDragHelper ) { - nsCOMPtr sink; - [self findEventSink:getter_AddRefs(sink) forPoint:[sender draggingLocation] - inWindow:[sender draggingDestinationWindow]]; - if (sink) - mDragHelper->Drop([sender draggingSequenceNumber], sink, &dragAccepted); - } - - return dragAccepted ? YES : NO; -} - -#pragma mark - - --(BOOL)validateMenuItem: (NSMenuItem*)aMenuItem -{ - // update first responder items based on the selection - SEL action = [aMenuItem action]; - if (action == @selector(cut:)) - return [self canCut]; - else if (action == @selector(copy:)) - return [self canCopy]; - else if (action == @selector(paste:)) - return [self canPaste]; - else if (action == @selector(delete:)) - return [self canDelete]; - else if (action == @selector(undo:)) - return [self canUndo]; - else if (action == @selector(redo:)) - return [self canRedo]; - else if (action == @selector(selectAll:)) - return YES; - - return NO; -} - -@end diff --git a/mozilla/chimera/CHBrowserWrapper.h b/mozilla/chimera/CHBrowserWrapper.h deleted file mode 100644 index c50f9c2a942..00000000000 --- a/mozilla/chimera/CHBrowserWrapper.h +++ /dev/null @@ -1,118 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape 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/NPL/ - * - * 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 mozilla.org 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 NPL, 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 NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#import -#import "CHBrowserView.h" - -@class BrowserWindowController; -@class ToolTip; - -@interface CHBrowserWrapper : NSView -{ - NSTextField* mUrlbar; - NSTextField* mStatus; - NSProgressIndicator* mProgress; - NSView* mProgressSuper; - BrowserWindowController* mWindowController; - NSTabViewItem* mTabItem; - NSWindow* mWindow; - - NSImage* mSiteIconImage; // current proxy icon image, which may be a site icon (favicon). - NSString* mSiteIconURI; // uri from which we loaded the site icon - - // the secure state of this browser. We need to hold it so that we can set - // the global lock icon whenever we become the primary. Value is one of - // security enums in nsIWebProgressListener. - unsigned long mSecureState; - // the title associated with this tab's url. We need to hold it so that we - // can set the window title whenever we become the primary. - NSString* mTitle; - - CHBrowserView* mBrowserView; - NSString* mDefaultStatusString; - NSString* mLoadingStatusString; - ToolTip* mToolTip; - - BOOL mIsPrimary; - BOOL mIsBusy; - BOOL mOffline; - BOOL mListenersAttached; // We hook up our click and context menu listeners lazily. - // If we never become the primary view, we don't bother creating the listeners. - BOOL mIsBookmarksImport; // This view was created for the purpose of importing bookmarks. Upon - // completion, we need to do the import and then destroy ourselves. - BOOL mActivateOnLoad; // If set, activate the browser view when loading starts. -} - -- (id)initWithTab:(NSTabViewItem*)aTab andWindow:(NSWindow*)aWindow; - -- (IBAction)load:(id)sender; -- (void)awakeFromNib; -- (void)setFrame:(NSRect)frameRect; -- (CHBrowserView*)getBrowserView; -- (BOOL)isBusy; -- (void)windowClosed; - -- (NSString*)getCurrentURLSpec; - -- (void)loadURI:(NSString *)urlSpec referrer:(NSString*)referrer flags:(unsigned int)flags activate:(BOOL)activate; -- (void)makePrimaryBrowserView: (id)aUrlbar status: (id)aStatus - progress: (id)aProgress windowController: (BrowserWindowController*)aWindowController; -- (void)disconnectView; -- (void)setTab: (NSTabViewItem*)tab; - -- (NSWindow*)getNativeWindow; -- (NSMenu*)getContextMenu; -- (void)setIsBookmarksImport:(BOOL)aIsImport; - -// NSBrowserListener messages -- (void)onLoadingStarted; -- (void)onLoadingCompleted:(BOOL)succeeded; -- (void)onProgressChange:(int)currentBytes outOf:(int)maxBytes; -- (void)onLocationChange:(NSString*)urlSpec; -- (void)onStatusChange:(NSString*)aMessage; -- (void)onSecurityStateChange:(unsigned long)newState; -- (void)onShowTooltip:(NSPoint)where withText:(NSString*)text; -- (void)onHideTooltip; - -// NSBrowserContainer messages -- (void)setStatus:(NSString *)statusString ofType:(NSStatusType)type; -- (NSString *)title; -- (void)setTitle:(NSString *)title; -- (void)sizeBrowserTo:(NSSize)dimensions; -- (CHBrowserView*)createBrowserWindow:(unsigned int)mask; - -@end diff --git a/mozilla/chimera/CHBrowserWrapper.mm b/mozilla/chimera/CHBrowserWrapper.mm deleted file mode 100644 index e84899836a4..00000000000 --- a/mozilla/chimera/CHBrowserWrapper.mm +++ /dev/null @@ -1,692 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape 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/NPL/ - * - * 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 mozilla.org 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 NPL, 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 NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#import "NSString+Utils.h" - -#import "CHPreferenceManager.h" -#import "CHBrowserWrapper.h" -#import "BrowserWindowController.h" -#import "BookmarksService.h" -#import "SiteIconProvider.h" -#import "BrowserTabViewItem.h" -#import "ToolTip.h" -#import "CHPageProxyIcon.h" - -#include "nsCOMPtr.h" -#include "nsIServiceManager.h" -#include "nsIIOService.h" -#include "ContentClickListener.h" -#include "nsIDOMWindow.h" -#include "nsIWebBrowser.h" -#include "nsIDOMDocument.h" -#include "nsIDOMHTMLDocument.h" -#include "nsIChromeEventHandler.h" -#include "nsPIDOMWindow.h" -#include "nsIDOMEventReceiver.h" -#include "nsIPrefBranch.h" -#include "nsIPrefService.h" -#include "nsCocoaBrowserService.h" -#include "nsIWebProgressListener.h" - -#include - -#define DOCUMENT_DONE_STRING @"Document: Done" - -static const char* ioServiceContractID = "@mozilla.org/network/io-service;1"; - -const NSString* kOfflineNotificationName = @"offlineModeChanged"; - -@interface CHBrowserWrapper(Private) - -- (void)setPendingActive:(BOOL)active; -- (void)registerNotificationListener; - -- (void)setSiteIconImage:(NSImage*)inSiteIcon; -- (void)setSiteIconURI:(NSString*)inSiteIconURI; - -- (void)updateSiteIconImage:(NSImage*)inSiteIcon withURI:(NSString *)inSiteIconURI; - -@end - -@implementation CHBrowserWrapper - -- (id)initWithTab:(NSTabViewItem*)aTab andWindow:(NSWindow*)aWindow -{ - mTabItem = aTab; - mWindow = aWindow; - mIsBookmarksImport = NO; - return [self initWithFrame: NSZeroRect]; -} - -// -// initWithFrame: (designated initializer) -// -// Create a Gecko browser view and hook everything up to the UI -// -- (id)initWithFrame:(NSRect)frameRect -{ - if ( (self = [super initWithFrame: frameRect]) ) { - mBrowserView = [[[CHBrowserView alloc] initWithFrame:[self bounds] andWindow: [self getNativeWindow]] autorelease]; - [self addSubview: mBrowserView]; - [mBrowserView setContainer:self]; - [mBrowserView addListener:self]; - mIsBusy = NO; - mListenersAttached = NO; - mSecureState = nsIWebProgressListener::STATE_IS_INSECURE; - - mToolTip = [[ToolTip alloc] init]; - - //[self setSiteIconImage:[NSImage imageNamed:@"globe_ico"]]; - //[self setSiteIconURI: [NSString string]]; - - [self registerNotificationListener]; - } - return self; -} - --(void)dealloc -{ -#if DEBUG - NSLog(@"The browser wrapper died."); -#endif - - [[NSNotificationCenter defaultCenter] removeObserver: self]; - - [mSiteIconImage release]; - [mSiteIconURI release]; - [mDefaultStatusString release]; - [mLoadingStatusString release]; - [mToolTip release]; - - [super dealloc]; -} - - --(void)windowClosed -{ - // Break the cycle. - [mBrowserView destroyWebBrowser]; - [mBrowserView setContainer: nil]; - [mBrowserView removeListener: self]; -} - -- (IBAction)load:(id)sender -{ - [mBrowserView loadURI:[mUrlbar stringValue] referrer:nil flags:NSLoadFlagsNone]; -} - --(void)disconnectView -{ - mUrlbar = nil; - mStatus = nil; - mProgress = nil; - mProgressSuper = nil; - mIsPrimary = NO; - [[NSNotificationCenter defaultCenter] removeObserver:self name:kOfflineNotificationName object:nil]; - - [mBrowserView setActive: NO]; -} - --(void)setTab: (NSTabViewItem*)tab -{ - mTabItem = tab; -} - --(void)makePrimaryBrowserView: (id)aUrlbar status: (id)aStatus - progress: (id)aProgress windowController: (BrowserWindowController*)aWindowController -{ - mUrlbar = aUrlbar; - mStatus = aStatus; - mProgress = aProgress; - mProgressSuper = [aProgress superview]; - mWindowController = aWindowController; - - if (!mIsBusy) - [mProgress removeFromSuperview]; - - mDefaultStatusString = NULL; - mLoadingStatusString = DOCUMENT_DONE_STRING; - [mStatus setStringValue:mLoadingStatusString]; - - mIsPrimary = YES; - - // update the global lock icon to the current state of this browser. We need - // to do this after we set |mIsPrimary|. - [self onSecurityStateChange:mSecureState]; - - // update the window's title. - [self setTitle:mTitle]; - - if ([[self window] isKeyWindow]) - [mBrowserView setActive: YES]; - - nsCOMPtr ioService(do_GetService(ioServiceContractID)); - if (!ioService) - return; - PRBool offline = PR_FALSE; - ioService->GetOffline(&offline); - mOffline = offline; - - if (mWindowController) // Only register if we're the content area. - [[NSNotificationCenter defaultCenter] addObserver:self - selector:@selector(offlineModeChanged:) - name:kOfflineNotificationName - object:nil]; - - // Update the URL bar. - [mWindowController updateLocationFields:[self getCurrentURLSpec]]; - [mWindowController updateSiteIcons:mSiteIconImage]; - - if (mWindowController && !mListenersAttached) { - mListenersAttached = YES; - - // We need to hook up our click and context menu listeners. - ContentClickListener* clickListener = new ContentClickListener(mWindowController); - if (!clickListener) - return; - - nsCOMPtr contentWindow = getter_AddRefs([[self getBrowserView] getContentWindow]); - nsCOMPtr piWindow(do_QueryInterface(contentWindow)); - nsCOMPtr chromeHandler; - piWindow->GetChromeEventHandler(getter_AddRefs(chromeHandler)); - nsCOMPtr rec(do_QueryInterface(chromeHandler)); - rec->AddEventListenerByIID(clickListener, NS_GET_IID(nsIDOMMouseListener)); - } -} - --(NSString*)getCurrentURLSpec -{ - return [mBrowserView getCurrentURLSpec]; -} - -- (void)awakeFromNib -{ -} - -- (void)setFrame:(NSRect)frameRect -{ - [super setFrame:frameRect]; - - // Only resize our browser view if we are visible. If we're hidden, the frame - // will get reset when we get placed back into the view hierarchy anyway. This - // enhancement keeps resizing in a window with many tabs from being slow. - if ([self window]) { - NSRect bounds = [self bounds]; - [mBrowserView setFrame:bounds]; - } -} - --(BOOL)isBusy -{ - return mIsBusy; -} - -- (void)loadURI:(NSString *)urlSpec referrer:(NSString*)referrer flags:(unsigned int)flags activate:(BOOL)activate -{ - mActivateOnLoad = activate; - [mBrowserView loadURI:urlSpec referrer:referrer flags:flags]; -} - -- (void)onLoadingStarted -{ - if (mDefaultStatusString) { - [mDefaultStatusString release]; - mDefaultStatusString = NULL; - } - - [mProgressSuper addSubview:mProgress]; - [mProgress setIndeterminate:YES]; - [mProgress startAnimation:self]; - - mLoadingStatusString = NSLocalizedString(@"TabLoading", @""); - [mStatus setStringValue:mLoadingStatusString]; - - mIsBusy = YES; - [mTabItem setLabel: NSLocalizedString(@"TabLoading", @"")]; - - if (mWindowController) { - [mWindowController updateToolbarItems]; - [mWindowController startThrobber]; - } -} - -- (void)onLoadingCompleted:(BOOL)succeeded -{ - if (mActivateOnLoad) { - [mBrowserView setActive:YES]; - mActivateOnLoad = NO; - } - - [mProgress setIndeterminate:YES]; - [mProgress stopAnimation:self]; - [mProgress removeFromSuperview]; - - mLoadingStatusString = DOCUMENT_DONE_STRING; - if (mDefaultStatusString) { - [mStatus setStringValue:mDefaultStatusString]; - } - else { - [mStatus setStringValue:mLoadingStatusString]; - } - - mIsBusy = NO; - - if (mIsBookmarksImport) { - nsCOMPtr domWindow; - nsCOMPtr webBrowser = getter_AddRefs([mBrowserView getWebBrowser]); - webBrowser->GetContentDOMWindow(getter_AddRefs(domWindow)); - if (domWindow) { - nsCOMPtr domDocument; - domWindow->GetDocument(getter_AddRefs(domDocument)); - nsCOMPtr htmlDoc(do_QueryInterface(domDocument)); - if (htmlDoc) - BookmarksService::ImportBookmarks(htmlDoc); - } - [self windowClosed]; - [self removeFromSuperview]; - } - - if (mWindowController) { - [mWindowController updateToolbarItems]; - [mWindowController stopThrobber]; - } -} - -- (void)onProgressChange:(int)currentBytes outOf:(int)maxBytes -{ - if (maxBytes > 0) { - BOOL isIndeterminate = [mProgress isIndeterminate]; - if (isIndeterminate) { - [mProgress setIndeterminate:NO]; - } - double val = ((double)currentBytes / (double)maxBytes) * 100.0; - [mProgress setDoubleValue:val]; - } -} - -- (void)onLocationChange:(NSString*)urlSpec -{ - BOOL useSiteIcons = [[CHPreferenceManager sharedInstance] getBooleanPref:"browser.chrome.site_icons" withSuccess:NULL]; - BOOL siteIconLoadInitiated = NO; - - SiteIconProvider* faviconProvider = [SiteIconProvider sharedFavoriteIconProvider]; - NSString* faviconURI = [SiteIconProvider faviconLocationStringFromURI:urlSpec]; - - if (useSiteIcons && [faviconURI length] > 0) - { - // if the favicon uri has changed, fire off favicon load. When it completes, our - // imageLoadedNotification selector gets called. - if (![faviconURI isEqualToString:mSiteIconURI]) - siteIconLoadInitiated = [faviconProvider loadFavoriteIcon:self forURI:urlSpec withUserData:nil allowNetwork:YES]; - } - else - { - if ([urlSpec isEqualToString:@"about:blank"]) - faviconURI = urlSpec; - else - faviconURI = @""; - } - - if (!siteIconLoadInitiated) - [self updateSiteIconImage:nil withURI:faviconURI]; - - if (mIsPrimary) - [mWindowController updateLocationFields:urlSpec]; -} - -- (void)onStatusChange:(NSString*)aStatusString -{ - [mStatus setStringValue: aStatusString]; -} - -// -// onSecurityStateChange: -// -// Update the lock to the appropriate icon to match what necko is telling us, but -// only if we own the UI. If we're not the primary browser, we have no business -// mucking with the lock icon. -// -- (void)onSecurityStateChange:(unsigned long)newState -{ - mSecureState = newState; - if ( mIsPrimary ) - [mWindowController updateLock:newState]; -} - -- (void)setStatus:(NSString *)statusString ofType:(NSStatusType)type -{ - if (type == NSStatusTypeScriptDefault) { - if (mDefaultStatusString) { - [mDefaultStatusString release]; - } - mDefaultStatusString = statusString; - if (mDefaultStatusString) { - [mDefaultStatusString retain]; - } - } - else if (!statusString) { - if (mDefaultStatusString) { - [mStatus setStringValue:mDefaultStatusString]; - } - else { - [mStatus setStringValue:mLoadingStatusString]; - } - } - else { - [mStatus setStringValue:statusString]; - } -} - -- (NSString *)title -{ - return mTitle; -} - -- (void)setTitle:(NSString *)title -{ - [mTitle autorelease]; - - // We must be the primary content area to actually set the title, but we - // still want to hold onto the title in case we become the primary later. - NSString* newTitle = nil; - if (mOffline) { - if (title && ![title isEqualToString:@""]) - newTitle = [title stringByAppendingString: @" [Working Offline]"]; // XXX localize me - else - newTitle = [NSString stringWithString:@"Untitled [Working Offline]"]; - mTitle = [newTitle retain]; - } - else { - if (!title || [title isEqualToString:@""]) - title = [NSString stringWithString:NSLocalizedString(@"UntitledPageTitle", @"")]; - mTitle = [title retain]; - } - - if ( mIsPrimary && mWindowController ) - [[mWindowController window] setTitle:[mTitle stringByTruncatingTo:80 at:kTruncateAtEnd]]; - - // Always set the tab. - if (title && ![title isEqualToString:@""]) - [mTabItem setLabel:title]; // tab titles get truncated when setting them to tabs - else - [mTabItem setLabel:NSLocalizedString(@"UntitledPageTitle", @"")]; -} - - - -- (BOOL)isFlipped -{ - return YES; -} - -// -// onShowTooltip:where:withText -// -// Unfortunately, we can't use cocoa's apis here because they rely on setting a region -// and waiting. We already have waited and we just want to display the tooltip, so we -// drop down to the Carbon help manager routines. -// -// |where| is relative to the browser view in QD coordinates (top left is (0,0)) -// and must be converted to global QD coordinates for the carbon help manager. -// -- (void)onShowTooltip:(NSPoint)where withText:(NSString*)text -{ - NSPoint point = [[self window] convertBaseToScreen:[self convertPoint: where toView:nil]]; - [mToolTip showToolTipAtPoint: point withString: text]; -} - -- (void)onHideTooltip -{ - [mToolTip closeToolTip]; -} - -// Called when a context menu should be shown. -- (void)onShowContextMenu:(int)flags domEvent:(nsIDOMEvent*)aEvent domNode:(nsIDOMNode*)aNode -{ - [mWindowController onShowContextMenu: flags domEvent: aEvent domNode: aNode]; -} - --(NSMenu*)getContextMenu -{ - return [mWindowController getContextMenu]; -} - --(NSWindow*)getNativeWindow -{ - NSWindow* window = [self window]; - if (window) - return window; - - if (mWindow) - return mWindow; - - return nil; -} - -- (BOOL)shouldAcceptDragFromSource:(id)dragSource -{ - if ((dragSource == self) || (dragSource == mTabItem) || (dragSource == [mWindowController proxyIconView])) - return NO; - - if ([mTabItem isMemberOfClass:[BrowserTabViewItem class]] && (dragSource == [(BrowserTabViewItem*)mTabItem tabItemContentsView])) - return NO; - - return YES; -} - --(void)setIsBookmarksImport:(BOOL)aIsImport -{ - mIsBookmarksImport = aIsImport; -} - -- (void)offlineModeChanged: (NSNotification*)aNotification -{ - nsCOMPtr ioService(do_GetService(ioServiceContractID)); - if (!ioService) - return; - PRBool offline = PR_FALSE; - ioService->GetOffline(&offline); - mOffline = offline; - - if (mOffline) { - NSString* newTitle = [[[mWindowController window] title] stringByAppendingString: @" [Working Offline]"]; - [[mWindowController window] setTitle: newTitle]; - } - else { - NSArray* titleItems = [[[mWindowController window] title] componentsSeparatedByString:@" [Working Offline]"]; - [[mWindowController window] setTitle: [titleItems objectAtIndex: 0]]; - } -} - -// -// sizeBrowserTo -// -// Sizes window so that browser has dimensions given by |dimensions| -// -- (void)sizeBrowserTo:(NSSize)dimensions -{ - NSRect bounds = [self bounds]; - float dx = dimensions.width - bounds.size.width; - float dy = dimensions.height - bounds.size.height; - - NSRect frame = [[self window] frame]; - NSPoint topLeft = NSMakePoint(NSMinX(frame), NSMaxY(frame)); - frame.size.width += dx; - frame.size.height += dy; - - // if we just call setFrame, it will change the top-left corner of the - // window as it pulls the extra space from the top and right sides of the window, - // which is not at all what the website desired. We must preserve - // topleft of the window and reset it after we resize. - [[self window] setFrame:frame display:YES]; - [[self window] setFrameTopLeftPoint:topLeft]; -} - -- (CHBrowserView*)createBrowserWindow:(unsigned int)aMask -{ - nsCOMPtr pref(do_GetService("@mozilla.org/preferences-service;1")); - if (!pref) - return NS_OK; // Something bad happened if we can't get prefs. - - PRBool showBlocker; - pref->GetBoolPref("browser.popups.showPopupBlocker", &showBlocker); - - if (showBlocker) { - nsCOMPtr domWindow = getter_AddRefs([mBrowserView getContentWindow]); - nsCOMPtr piWindow(do_QueryInterface(domWindow)); - PRBool isUnrequested; - piWindow->IsLoadingOrRunningTimeout(&isUnrequested); - if (isUnrequested) { - // A popup is being opened while the page is currently loading. Offer to block the - // popup. - nsAlertController* controller = nsCocoaBrowserService::GetAlertController(); - BOOL confirm = [controller confirm: [self window] title: @"Unrequested Popup Detected" - text: [NSString stringWithFormat: NSLocalizedString(@"PopupBlockMsg", @""), NSLocalizedStringFromTable(@"CFBundleName", @"InfoPlist", nil)]]; - - // This is a one-time dialog. - pref->SetBoolPref("browser.popups.showPopupBlocker", PR_FALSE); - - if (confirm) { - pref->SetBoolPref("dom.disable_open_during_load", PR_TRUE); - pref->SetIntPref("dom.disable_open_click_delay", 1000); - } - - nsCOMPtr prefService(do_QueryInterface(pref)); - prefService->SavePrefFile(nsnull); - - if (confirm) - return nil; - } - } - - BrowserWindowController* controller = [[BrowserWindowController alloc] initWithWindowNibName: @"BrowserWindow"]; - [controller setChromeMask: aMask]; - [controller disableAutosave]; // The Web page opened this window, so we don't ever use its settings. - [controller disableLoadPage]; // don't load about:blank initially since this is a script-opened window - [controller enterModalSession]; - [[controller getBrowserWrapper] setPendingActive: YES]; - return [[controller getBrowserWrapper] getBrowserView]; -} - -- (CHBrowserView*)getBrowserView -{ - return mBrowserView; -} - -- (void)setPendingActive:(BOOL)active -{ - mActivateOnLoad = active; -} - -- (void)setSiteIconImage:(NSImage*)inSiteIcon -{ - [mSiteIconImage autorelease]; - mSiteIconImage = [inSiteIcon retain]; -} - -- (void)setSiteIconURI:(NSString*)inSiteIconURI -{ - [mSiteIconURI autorelease]; - mSiteIconURI = [inSiteIconURI retain]; -} - -// A nil inSiteIcon image indicates that we should use the default icon -// If inSiteIconURI is "about:blank", we don't show any icon -- (void)updateSiteIconImage:(NSImage*)inSiteIcon withURI:(NSString *)inSiteIconURI -{ - BOOL resetTabIcon = NO; - BOOL tabIconDraggable = YES; - - if (![mSiteIconURI isEqualToString:inSiteIconURI]) - { - if (!inSiteIcon) - { - if ([inSiteIconURI isEqualToString:@"about:blank"]) { - inSiteIcon = [NSImage imageNamed:@"smallDocument"]; - tabIconDraggable = NO; - } else - inSiteIcon = [NSImage imageNamed:@"globe_ico"]; - } - - [self setSiteIconImage: inSiteIcon]; - [self setSiteIconURI: inSiteIconURI]; - - // update the proxy icon - if (mIsPrimary) - [mWindowController updateSiteIcons:mSiteIconImage]; - - resetTabIcon = YES; - } - - // update the tab icon - if ([mTabItem isMemberOfClass:[BrowserTabViewItem class]]) - { - BrowserTabViewItem* tabItem = (BrowserTabViewItem*)mTabItem; - if (resetTabIcon || ![tabItem tabIcon]) - [tabItem setTabIcon:mSiteIconImage isDraggable:tabIconDraggable]; - } - -} - -- (void)registerNotificationListener -{ - [[NSNotificationCenter defaultCenter] addObserver: self - selector: @selector(imageLoadedNotification:) - name: SiteIconLoadNotificationName - object: self]; - -} - -// called when [[SiteIconProvider sharedFavoriteIconProvider] loadFavoriteIcon] completes -- (void)imageLoadedNotification:(NSNotification*)notification -{ - NSDictionary* userInfo = [notification userInfo]; - if (userInfo) - { - NSImage* iconImage = [userInfo objectForKey:SiteIconLoadImageKey]; - NSString* siteIconURI = [userInfo objectForKey:SiteIconLoadURIKey]; - - // NSLog(@"CHBrowserWrapper imageLoadedNotification got image %@ and uri %@", iconImage, proxyImageURI); - if (iconImage == nil) - siteIconURI = @""; // go back to default image - - [self updateSiteIconImage:iconImage withURI:siteIconURI]; - } -} - - -@end diff --git a/mozilla/chimera/CHExtendedOutlineView.h b/mozilla/chimera/CHExtendedOutlineView.h deleted file mode 100644 index 8b90a2820cf..00000000000 --- a/mozilla/chimera/CHExtendedOutlineView.h +++ /dev/null @@ -1,50 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- -* -* 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 the Mozilla browser. -* -* The Initial Developer of the Original Code is Netscape -* Communications Corporation. Portions created by Netscape are -* Copyright (C) 2002 Netscape Communications Corporation. All -* Rights Reserved. -* -* Contributor(s): -* David Hyatt (Original Author) -* Max Horn (Context menu & tooltip code) -*/ - -#import - -@interface CHExtendedOutlineView : NSOutlineView { - SEL mDeleteAction; - - NSRect mOldFrameRect; - int mOldRows; - BOOL mDelegateTooltipStringForItem; -} - --(void)keyDown:(NSEvent*)aEvent; - --(void)setDeleteAction: (SEL)deleteAction; --(SEL)deleteAction; - --(void)setDelegate:(id)anObject; - -@end - -@interface NSObject (CHOutlineViewDataSourceToolTips) -- (NSString *)outlineView:(NSOutlineView *)outlineView tooltipStringForItem:(id)item; -@end - -@interface NSObject (CHOutlineViewContextMenus) -- (NSMenu *)outlineView:(NSOutlineView *)outlineView contextMenuForItem:(id)item; -@end diff --git a/mozilla/chimera/CHExtendedOutlineView.mm b/mozilla/chimera/CHExtendedOutlineView.mm deleted file mode 100644 index 6d40efb013c..00000000000 --- a/mozilla/chimera/CHExtendedOutlineView.mm +++ /dev/null @@ -1,236 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- -* -* 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 the Mozilla browser. -* -* The Initial Developer of the Original Code is Netscape -* Communications Corporation. Portions created by Netscape are -* Copyright (C) 2002 Netscape Communications Corporation. All -* Rights Reserved. -* -* Contributor(s): -* David Hyatt (Original Author) -* Max Horn (Context menu & tooltip code) -*/ - -#import "CHExtendedOutlineView.h" - -@interface CHExtendedOutlineView (Private) -- (void)_updateToolTipRect; -@end - -@implementation CHExtendedOutlineView - -- (id)initWithFrame:(NSRect)frame -{ - if ( (self = [super initWithFrame:frame]) ) { - mDeleteAction = 0; - // FIXME - this method is *never* called for items that are archived in a nib! - // Luckily, object memory is zeroed, so mDeleteAction will be 0 anyway. - // I recommend that this method just be removed. - } - return self; -} - -- (void)awakeFromNib { - // Setup the initial NSToolTipRects - [self _updateToolTipRect]; -} - --(void)setDeleteAction: (SEL)aDeleteAction -{ - mDeleteAction = aDeleteAction; -} - --(SEL)deleteAction -{ - return mDeleteAction; -} - --(void)setDelegate:(id)anObject -{ - [super setDelegate:anObject]; - mDelegateTooltipStringForItem = [anObject respondsToSelector:@selector(outlineView:tooltipStringForItem:)]; -} - - --(void)keyDown:(NSEvent*)aEvent -{ - // check each char in the event array. it should be just 1 char, but - // just in case we use a loop. - int len = [[aEvent characters] length]; - for ( int i = 0; i < len; ++i ) { - unichar c = [[aEvent characters] characterAtIndex:i]; - - // Check for a certain set of special keys. - - if (c == NSDeleteCharacter || c == NSBackspaceCharacter) { - // delete the bookmark - if (mDeleteAction) - [NSApp sendAction: mDeleteAction to: [self target] from: self]; - return; - } - else if (c == NSCarriageReturnCharacter) { - // Start editing - if ([self numberOfSelectedRows] == 1) { - [self editColumn:0 row:[self selectedRow] withEvent:aEvent select:YES]; - return; - } - } - else if (c == NSLeftArrowFunctionKey || c == NSRightArrowFunctionKey) - { - BOOL expand = (c == NSRightArrowFunctionKey); - if ([self numberOfSelectedRows] == 1) { - int index = [self selectedRow]; - if (index == -1) - return; - - id item = [self itemAtRow: index]; - if (!item) - return; - - if (![self isExpandable: item]) - return; - - if (![self isItemExpanded: item] && expand) - [self expandItem: item]; - else if ([self isItemExpanded: item] && !expand) - [self collapseItem: item]; - } - } - } // foreach character - - return [super keyDown: aEvent]; -} - -/* - * Intercept changes to the window frame so we can update our tooltip rects - */ -- (void)setFrameOrigin:(NSPoint)newOrigin; -{ - [super setFrameOrigin:newOrigin]; - [self _updateToolTipRect]; -} - -- (void)setFrameSize:(NSSize)newSize; -{ - [super setFrameSize:newSize]; - [self _updateToolTipRect]; -} - -- (void)setFrame:(NSRect)frameRect -{ - [super setFrame:frameRect]; - [self _updateToolTipRect]; -} - -/* - * Implement the informal NSToolTipOwner protocol to allow tooltips - * on a per-item level. - */ -- (NSString *)view:(NSView *)view stringForToolTip:(NSToolTipTag)tag point:(NSPoint)point userData:(void *)data -{ - NSString *result = nil; - int rowIndex = [self rowAtPoint:point]; - if (rowIndex >= 0) { - id delegate = [self delegate]; - id item = [self itemAtRow:rowIndex]; - - if (item && mDelegateTooltipStringForItem) - result = [delegate outlineView:self tooltipStringForItem:item]; - } - return result; -} - -/* - * Return a context menu depending on which item was clicked. - */ -- (NSMenu *)menuForEvent:(NSEvent *)theEvent -{ - id item; - int rowIndex; - NSPoint point; - - point = [self convertPoint:[theEvent locationInWindow] fromView:nil]; - rowIndex = [self rowAtPoint:point]; - - if (rowIndex >= 0) { - // There seems to be a bug in AppKit; selectRow is supposed to - // abort editing, but it doesn't, thus we do it manually. - [self abortEditing]; - - item = [self itemAtRow:rowIndex]; - if (item) { - id delegate = [self delegate]; - - // If the item was not selected, select it now - if (![self isRowSelected:rowIndex]) { - if (![delegate respondsToSelector:@selector(outlineView:shouldSelectItem:)] - || [delegate outlineView:self shouldSelectItem:item]) - [self selectRow:rowIndex byExtendingSelection:NO]; - } - - if ([delegate respondsToSelector:@selector(outlineView:contextMenuForItem:)]) - return [delegate outlineView:self contextMenuForItem:item]; - } - } - - // Just return the default context menu - return [self menu]; -} - -@end - - -@implementation CHExtendedOutlineView (Private) - -/* - * Set up tooltip rects for every row, but only if the frame size or - * the number of rows changed since the last invocation. - */ -- (void)_updateToolTipRect -{ - static NSRect oldFrameRect; - static int oldRows = 0; - NSRect frameRect; - int rows; - - // Only set tooltip rects if the delegate implements outlineView:tooltipStringForItem: - if (!mDelegateTooltipStringForItem) - return; - - frameRect = [self frame]; - rows = [self numberOfRows]; - - // Check if rows or frame changed - if (rows != oldRows || !NSEqualRects(oldFrameRect, frameRect)) - { - int i; - NSRect rect; - - // Remove all old NSToolTipRects - [self removeAllToolTips]; - - // Add a NSToolTipRect for each row - for (i = 0; i < rows; ++i) - { - rect = [self rectOfRow:i]; - [self addToolTipRect:rect owner:self userData:NULL]; - } - } - - // Save the current values - oldRows = rows; - oldFrameRect = frameRect; -} - -@end diff --git a/mozilla/chimera/CHFind.h b/mozilla/chimera/CHFind.h deleted file mode 100644 index 588a815c0c5..00000000000 --- a/mozilla/chimera/CHFind.h +++ /dev/null @@ -1,38 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- -* -* 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 the Mozilla browser. -* -* The Initial Developer of the Original Code is Netscape -* Communications Corporation. Portions created by Netscape are -* Copyright (C) 2002 Netscape Communications Corporation. All -* Rights Reserved. -* -* Contributor(s): -* Mike Pinkerton (Original Author) -*/ - -#import - -// -// protocol CHFind -// -// Any window who wants to be able to work with the Find dialog should implement -// this protocol. -// - -@protocol CHFind - -- (BOOL)findInPageWithPattern:(NSString*)text caseSensitive:(BOOL)inCaseSensitive - wrap:(BOOL)inWrap backwards:(BOOL)inBackwards; - -@end diff --git a/mozilla/chimera/CHGeckoUtils.h b/mozilla/chimera/CHGeckoUtils.h deleted file mode 100644 index dfa225a2ff0..00000000000 --- a/mozilla/chimera/CHGeckoUtils.h +++ /dev/null @@ -1,179 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape 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/NPL/ - * - * 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 mozilla.org 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 NPL, 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 NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef __GeckoUtils_h__ -#define __GeckoUtils_h__ - -#include "nsIDOMHTMLAnchorElement.h" -#include "nsIDOMHTMLAreaElement.h" -#include "nsIDOMHTMLLinkElement.h" -#include "nsIDOMHTMLImageElement.h" -#include "nsIDOMCharacterData.h" - -class CHGeckoUtils -{ -public: - static void GatherTextUnder(nsIDOMNode* aNode, nsString& aResult) { - nsAutoString text; - nsCOMPtr node; - aNode->GetFirstChild(getter_AddRefs(node)); - PRUint32 depth = 1; - while (node && depth) { - nsCOMPtr charData(do_QueryInterface(node)); - PRUint16 nodeType; - node->GetNodeType(&nodeType); - if (charData && nodeType == nsIDOMNode::TEXT_NODE) { - // Add this text to our collection. - text += NS_LITERAL_STRING(" "); - nsAutoString data; - charData->GetData(data); - text += data; - } - else { - nsCOMPtr img(do_QueryInterface(node)); - if (img) { - nsAutoString altText; - img->GetAlt(altText); - if (!altText.IsEmpty()) { - text = altText; - break; - } - } - } - - // Find the next node to test. - PRBool hasChildNodes; - node->HasChildNodes(&hasChildNodes); - if (hasChildNodes) { - nsCOMPtr temp = node; - temp->GetFirstChild(getter_AddRefs(node)); - depth++; - } - else { - nsCOMPtr nextSibling; - node->GetNextSibling(getter_AddRefs(nextSibling)); - if (nextSibling) - node = nextSibling; - else { - nsCOMPtr parentNode; - node->GetParentNode(getter_AddRefs(parentNode)); - if (!parentNode) - node = nsnull; - else { - nsCOMPtr nextSibling; - parentNode->GetNextSibling(getter_AddRefs(nextSibling)); - node = nextSibling; - depth--; - } - } - } - } - - text.CompressWhitespace(); - aResult = text; - }; - - static void GetEnclosingLinkElementAndHref(nsIDOMNode* aNode, nsIDOMElement** aLinkContent, nsString& aHref) - { - nsCOMPtr content(do_QueryInterface(aNode)); - nsAutoString localName; - if (content) - content->GetLocalName(localName); - - nsCOMPtr linkContent; - ToLowerCase(localName); - nsAutoString href; - if (localName.Equals(NS_LITERAL_STRING("a")) || - localName.Equals(NS_LITERAL_STRING("area")) || - localName.Equals(NS_LITERAL_STRING("link"))) { - PRBool hasAttr; - content->HasAttribute(NS_LITERAL_STRING("href"), &hasAttr); - if (hasAttr) { - linkContent = content; - nsCOMPtr anchor(do_QueryInterface(linkContent)); - if (anchor) - anchor->GetHref(href); - else { - nsCOMPtr area(do_QueryInterface(linkContent)); - if (area) - area->GetHref(href); - else { - nsCOMPtr link(do_QueryInterface(linkContent)); - if (link) - link->GetHref(href); - } - } - } - } - else { - nsCOMPtr curr = aNode; - nsCOMPtr temp = curr; - temp->GetParentNode(getter_AddRefs(curr)); - while (curr) { - content = do_QueryInterface(curr); - if (!content) - break; - content->GetLocalName(localName); - ToLowerCase(localName); - if (localName.Equals(NS_LITERAL_STRING("a"))) { - PRBool hasAttr; - content->HasAttribute(NS_LITERAL_STRING("href"), &hasAttr); - if (hasAttr) { - linkContent = content; - nsCOMPtr anchor(do_QueryInterface(linkContent)); - if (anchor) - anchor->GetHref(href); - } - else - linkContent = nsnull; // Links can't be nested. - break; - } - - temp = curr; - temp->GetParentNode(getter_AddRefs(curr)); - } - } - - *aLinkContent = linkContent; - NS_IF_ADDREF(*aLinkContent); - - aHref = href; - } -}; - - -#endif diff --git a/mozilla/chimera/CHGetURLCommand.h b/mozilla/chimera/CHGetURLCommand.h deleted file mode 100644 index b5f907bfcb2..00000000000 --- a/mozilla/chimera/CHGetURLCommand.h +++ /dev/null @@ -1,30 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- -* -* 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 the Mozilla browser. -* -* The Initial Developer of the Original Code is Netscape -* Communications Corporation. Portions created by Netscape are -* Copyright (C) 2002 Netscape Communications Corporation. All -* Rights Reserved. -* -* Contributor(s): -* David Hyatt (Original Author) -*/ - -#import - -@interface CHGetURLCommand : NSScriptCommand {} - -- (id)performDefaultImplementation; - -@end diff --git a/mozilla/chimera/CHGetURLCommand.mm b/mozilla/chimera/CHGetURLCommand.mm deleted file mode 100644 index 6c4558ea2fb..00000000000 --- a/mozilla/chimera/CHGetURLCommand.mm +++ /dev/null @@ -1,37 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- -* -* 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 the Mozilla browser. -* -* The Initial Developer of the Original Code is Netscape -* Communications Corporation. Portions created by Netscape are -* Copyright (C) 1999 Netscape Communications Corporation. All -* Rights Reserved. -* -* Contributor(s): -* David Hyatt (Original Author) -*/ - -#import "CHGetURLCommand.h" -#import - -#import "MainController.h" - -@implementation CHGetURLCommand - -- (id)performDefaultImplementation -{ - [(MainController*)[NSApp delegate] openNewWindowOrTabWithURL:[self directParameter] andReferrer:nil]; - return nil; -} - -@end diff --git a/mozilla/chimera/CHGoMenu.h b/mozilla/chimera/CHGoMenu.h deleted file mode 100644 index 17e614302d8..00000000000 --- a/mozilla/chimera/CHGoMenu.h +++ /dev/null @@ -1,36 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- -* -* 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 the Mozilla browser. -* -* The Initial Developer of the Original Code is Netscape -* Communications Corporation. Portions created by Netscape are -* Copyright (C) 2002 Netscape Communications Corporation. All -* Rights Reserved. -* -* Contributor(s): -* Joe Hewitt (Original Author) -*/ - -#import - -@interface CHGoMenu : NSMenu { - -} - -- (void) emptyHistoryItems; -- (void) addHistoryItems; - -// NSMenu -- (void) update; - -@end diff --git a/mozilla/chimera/CHGoMenu.mm b/mozilla/chimera/CHGoMenu.mm deleted file mode 100644 index e160c8dd15e..00000000000 --- a/mozilla/chimera/CHGoMenu.mm +++ /dev/null @@ -1,144 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- -* -* 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 the Mozilla browser. -* -* The Initial Developer of the Original Code is Netscape -* Communications Corporation. Portions created by Netscape are -* Copyright (C) 2002 Netscape Communications Corporation. All -* Rights Reserved. -* -* Contributor(s): -* Joe Hewitt (Original Author) -*/ - -#import "NSString+Utils.h" - -#import "CHGoMenu.h" -#import "MainController.h" -#import "BrowserWindowController.h" -#import "CHBrowserWrapper.h" -#import "CHBrowserView.h" -#include "nsCOMPtr.h" -#include "nsString.h" -#include "nsIWebBrowser.h" -#include "nsISHistory.h" -#include "nsIWebNavigation.h" -#include "nsIHistoryEntry.h" -#include "nsCRT.h" - -// the tag of the separator after which to insert history menu items -static const int kDividerTag = 4000; -// the maximum number of history entry menuitems to display -static const int kMaxItems = 15; -// the maximum number of characters in a menu title before cropping it -static const unsigned int kMaxTitleLength = 80; - -@implementation CHGoMenu - -- (void) update -{ - [self emptyHistoryItems]; - [self addHistoryItems]; - - [super update]; -} - -- (nsIWebNavigation*) currentWebNavigation -{ - // get controller for current window - BrowserWindowController *controller = [(MainController *)[NSApp delegate] getMainWindowBrowserController]; - if (!controller) return nsnull; - - // get web navigation for current browser - CHBrowserWrapper* wrapper = [controller getBrowserWrapper]; - if (!wrapper) return nsnull; - CHBrowserView* view = [wrapper getBrowserView]; - if (!view) return nsnull; - nsCOMPtr webBrowser = [view getWebBrowser]; - if (!webBrowser) return nsnull; - nsCOMPtr webNav(do_QueryInterface(webBrowser)); - return webNav.get(); -} - -- (void) historyItemAction:(id)sender -{ - // get web navigation for current browser - nsCOMPtr webNav = [self currentWebNavigation]; - if (!webNav) return; - - // browse to the history entry for the menuitem that was selected - PRInt32 historyIndex = ([sender tag] - 1) - kDividerTag; - webNav->GotoIndex(historyIndex); -} - -- (void) emptyHistoryItems -{ - // remove every history item after the insertion point - int insertionIndex = [self indexOfItemWithTag:kDividerTag]; - for (int i = [self numberOfItems]-1; i > insertionIndex ; --i) { - [self removeItemAtIndex:i]; - } -} - -- (void) addHistoryItems -{ - // get session history for current browser - nsCOMPtr webNav = [self currentWebNavigation]; - if (!webNav) return; - nsCOMPtr sessionHistory; - webNav->GetSessionHistory(getter_AddRefs(sessionHistory)); - - PRInt32 count; - sessionHistory->GetCount(&count); - PRInt32 currentIndex; - sessionHistory->GetIndex(¤tIndex); - - // determine the range of items to display - int rangeStart, rangeEnd; - int above = kMaxItems/2; - int below = (kMaxItems-above)-1; - if (count <= kMaxItems) { - // if the whole history fits within our menu, fit range to show all - rangeStart = count-1; - rangeEnd = 0; - } else { - // if the whole history is too large for menu, try to put current index as close to - // the middle of the list as possible, so the user can see both back and forward in session - rangeStart = currentIndex + above; - rangeEnd = currentIndex - below; - if (rangeStart >= count-1) { - rangeEnd -= (rangeStart-count)+1; // shift overflow to the end - rangeStart = count-1; - } else if (rangeEnd < 0) { - rangeStart -= rangeEnd; // shift overflow to the start - rangeEnd = 0; - } - } - - // create a new menu item for each history entry (up to MAX_MENUITEM entries) - for (PRInt32 i = rangeStart; i >= rangeEnd; --i) { - nsCOMPtr entry; - sessionHistory->GetEntryAtIndex(i, PR_FALSE, getter_AddRefs(entry)); - - nsXPIDLString textStr; - entry->GetTitle(getter_Copies(textStr)); - NSString* title = [[NSString stringWith_nsAString: textStr] stringByTruncatingTo:kMaxTitleLength at:kTruncateAtMiddle]; - NSMenuItem *newItem = [self addItemWithTitle:title action:@selector(historyItemAction:) keyEquivalent:@""]; - [newItem setTarget:self]; - [newItem setTag:kDividerTag+1+i]; - if (currentIndex == i) - [newItem setState:NSOnState]; - } -} - -@end diff --git a/mozilla/chimera/CHHistoryDataSource.h b/mozilla/chimera/CHHistoryDataSource.h deleted file mode 100644 index cb2259e98bd..00000000000 --- a/mozilla/chimera/CHHistoryDataSource.h +++ /dev/null @@ -1,24 +0,0 @@ -// -// CHHistoryDataSource.h -// Chimera -// -// Created by Ben Goodger on Sun Apr 28 2002. -// Copyright (c) 2001 __MyCompanyName__. All rights reserved. -// - -#import - -#import "CHRDFOutlineViewDataSource.h" - -@class BrowserWindowController; - -@interface CHHistoryDataSource : CHRDFOutlineViewDataSource -{ - - IBOutlet BrowserWindowController* mBrowserWindowController; - -} - --(IBAction)openHistoryItem: (id)aSender; - -@end diff --git a/mozilla/chimera/CHHistoryDataSource.mm b/mozilla/chimera/CHHistoryDataSource.mm deleted file mode 100644 index 932676ef92d..00000000000 --- a/mozilla/chimera/CHHistoryDataSource.mm +++ /dev/null @@ -1,160 +0,0 @@ -// -// CHHistoryDataSource.mm -// Chimera -// -// Created by Ben Goodger on Sun Apr 28 2002. -// Copyright (c) 2001 __MyCompanyName__. All rights reserved. -// - -#import "NSString+Utils.h" - -#import "BrowserWindowController.h" -#import "CHHistoryDataSource.h" -#import "CHBrowserView.h" - -#include "nsIRDFService.h" -#include "nsIRDFDataSource.h" -#include "nsIRDFResource.h" - -#include "nsXPIDLString.h" -#include "nsString.h" - -#include "nsComponentManagerUtils.h" - -@implementation CHHistoryDataSource - -- (void) ensureDataSourceLoaded -{ - [super ensureDataSourceLoaded]; - - if (!mDataSource) - { - // Get the Global History DataSource - mRDFService->GetDataSource("rdf:history", &mDataSource); - // Get the Date Folder Root - mRDFService->GetResource("NC:HistoryByDate", &mRootResource); - - [mOutlineView setTarget: self]; - [mOutlineView setDoubleAction: @selector(openHistoryItem:)]; - - [mOutlineView reloadData]; - } -} - -- (id) outlineView: (NSOutlineView*) aOutlineView objectValueForTableColumn: (NSTableColumn*) aTableColumn - byItem: (id) aItem -{ - NSMutableAttributedString *cellValue = [[NSMutableAttributedString alloc] init]; - - if (!mDataSource || !aItem) - return nil; - - // The table column's identifier is the RDF Resource URI of the property being displayed in - // that column, e.g. "http://home.netscape.com/NC-rdf#Name" - NSString* columnPropertyURI = [aTableColumn identifier]; - - nsCOMPtr propertyResource; - mRDFService->GetResource([columnPropertyURI UTF8String], getter_AddRefs(propertyResource)); - - nsCOMPtr resource = dont_AddRef([aItem resource]); - - nsCOMPtr valueNode; - mDataSource->GetTarget(resource, propertyResource, PR_TRUE, getter_AddRefs(valueNode)); - if (!valueNode) { -#if DEBUG - NSLog(@"ValueNode is null in objectValueForTableColumn"); -#endif - return nil; - } - - nsCOMPtr valueLiteral(do_QueryInterface(valueNode)); - if (!valueLiteral) - return nil; - - nsXPIDLString literalValue; - valueLiteral->GetValue(getter_Copies(literalValue)); - - //Set cell's textual contents - [cellValue replaceCharactersInRange:NSMakeRange(0, [cellValue length]) withString:[NSString stringWith_nsAString:literalValue]]; - - if ([columnPropertyURI isEqualToString: @"http://home.netscape.com/NC-rdf#Name"]) - { - NSMutableAttributedString *attachmentAttrString = nil; - NSFileWrapper *fileWrapper = [[NSFileWrapper alloc] initRegularFileWithContents:nil]; - NSTextAttachment *textAttachment = [[NSTextAttachment alloc] initWithFileWrapper:fileWrapper]; - NSCell *attachmentAttrStringCell; - - //Create an attributed string to hold the empty attachment, then release the components. - attachmentAttrString = [[NSMutableAttributedString attributedStringWithAttachment:textAttachment] retain]; - [textAttachment release]; - [fileWrapper release]; - - //Get the cell of the text attachment. - attachmentAttrStringCell = (NSCell *)[(NSTextAttachment *)[attachmentAttrString attribute: - NSAttachmentAttributeName atIndex:0 effectiveRange:nil] attachmentCell]; - - if ([self outlineView:mOutlineView isItemExpandable:aItem]) { - [attachmentAttrStringCell setImage:[NSImage imageNamed:@"folder"]]; - } - else - [attachmentAttrStringCell setImage:[NSImage imageNamed:@"smallbookmark"]]; - - //Insert the image - [cellValue replaceCharactersInRange:NSMakeRange(0, 0) withAttributedString:attachmentAttrString]; - - //Tweak the baseline to vertically center the text. - [cellValue addAttribute:NSBaselineOffsetAttributeName - value:[NSNumber numberWithFloat:-5.0] - range:NSMakeRange(0, 1)]; - } - - return cellValue; -} - --(IBAction)openHistoryItem: (id)aSender -{ - int index = [mOutlineView selectedRow]; - if (index == -1) - return; - - id item = [mOutlineView itemAtRow: index]; - if (!item) - return; - - // expand if collapsed and double click - if ([mOutlineView isExpandable: item]) { - if ([mOutlineView isItemExpanded: item]) - [mOutlineView collapseItem: item]; - else - [mOutlineView expandItem: item]; - - return; - } - - // get uri - nsCOMPtr propertyResource; - mRDFService->GetResource("http://home.netscape.com/NC-rdf#URL", getter_AddRefs(propertyResource)); - - nsCOMPtr resource = dont_AddRef([item resource]); - - nsCOMPtr valueNode; - mDataSource->GetTarget(resource, propertyResource, PR_TRUE, getter_AddRefs(valueNode)); - if (!valueNode) { -#if DEBUG - NSLog(@"ValueNode is null in openHistoryItem"); -#endif - return; - } - - nsCOMPtr valueLiteral(do_QueryInterface(valueNode)); - if (!valueLiteral) - return; - - nsXPIDLString literalValue; - valueLiteral->GetValue(getter_Copies(literalValue)); - - NSString* url = [NSString stringWith_nsAString: literalValue]; - [[mBrowserWindowController getBrowserWrapper] loadURI: url referrer: nil flags: NSLoadFlagsNone activate:YES]; -} - -@end diff --git a/mozilla/chimera/CHIconTabViewItem.h b/mozilla/chimera/CHIconTabViewItem.h deleted file mode 100644 index f56f0635483..00000000000 --- a/mozilla/chimera/CHIconTabViewItem.h +++ /dev/null @@ -1,58 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** -* Version: NPL 1.1/GPL 2.0/LGPL 2.1 -* -* The contents of this file are subject to the Netscape 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/NPL/ -* -* 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 mozilla.org 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. -* Portions are Copyright (C) 2002 nibfile.com -* -* Contributor(s): -* Matt Judy (Original Author) -* David Haas -* -* 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 NPL, 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 NPL, the GPL or the LGPL. -* -* ***** END LICENSE BLOCK ***** */ - -#import - -@interface CHIconTabViewItem : NSTabViewItem -{ - NSImage *mTabIcon; - NSDictionary *mLabelAttributes; - NSString *mLabelString; - NSMutableString *mTruncLabelString; - int mLabelStringWidth; -} - -// The designated initializer --(id)initWithIdentifier:(id)identifier withTabIcon:(NSImage *)tabIcon; - --(NSImage *)tabIcon; --(void)setTabIcon:(NSImage *)newIcon; - -@end diff --git a/mozilla/chimera/CHIconTabViewItem.mm b/mozilla/chimera/CHIconTabViewItem.mm deleted file mode 100644 index dc58171d306..00000000000 --- a/mozilla/chimera/CHIconTabViewItem.mm +++ /dev/null @@ -1,202 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** -* Version: NPL 1.1/GPL 2.0/LGPL 2.1 -* -* The contents of this file are subject to the Netscape 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/NPL/ -* -* 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 mozilla.org 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. -* Portions are Copyright (C) 2002 nibfile.com. -* -* Contributor(s): -* Matt Judy (Original Author) -* David Haas -* Simon Fraser -* -* 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 NPL, 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 NPL, the GPL or the LGPL. -* -* ***** END LICENSE BLOCK ***** */ - -#import "NSString+Utils.h" - -#import "CHIconTabViewItem.h" -#import "NSString+Utils.h" - -// -// NSParagraphStyle has a line break mode which will automatically -// append ellipses to the end of a string. Unfortunately, as of -// OS X 10.1.5, the header says it doesn't work yet. -// -#define BROKEN_NSLineBreakByTruncatingMiddle - -static const int kMinTabsForSpacing = 4; // with 1-4 tabs, each tab is 1/4 the tab view width - -@interface CHIconTabViewItem(Private) -- (void)setupLabelAttributes; -@end; - -@implementation CHIconTabViewItem - --(id)initWithIdentifier:(id)identifier withTabIcon:(NSImage *)tabIcon -{ - if ( (self = [super initWithIdentifier:identifier]) ) { - [self setTabIcon:tabIcon]; - [self setupLabelAttributes]; - mLabelString = @""; - mLabelStringWidth = -1; - } - return self; -} - --(id)initWithIdentifier:(id)identifier -{ - return [self initWithIdentifier:identifier withTabIcon:nil]; -} - --(void)dealloc -{ - [mTabIcon release]; - [mLabelAttributes release]; - [mTruncLabelString release]; - [super dealloc]; -} - - -- (void)setupLabelAttributes -{ - NSMutableParagraphStyle *labelParagraphStyle = [[NSMutableParagraphStyle alloc] init]; - [labelParagraphStyle setParagraphStyle:[NSParagraphStyle defaultParagraphStyle]]; - -#ifdef BROKEN_NSLineBreakByTruncatingMiddle - [labelParagraphStyle setLineBreakMode:NSLineBreakByClipping]; -#else - [labelParagraphStyle setLineBreakMode:NSLineBreakByTruncatingMiddle]; -#endif - - [labelParagraphStyle setAlignment:NSNaturalTextAlignment]; - - NSFont *labelFont = [NSFont systemFontOfSize:[NSFont smallSystemFontSize]]; - mLabelAttributes = [[NSDictionary alloc] initWithObjectsAndKeys: - labelFont, NSFontAttributeName, - labelParagraphStyle, NSParagraphStyleAttributeName, - nil]; - - [labelParagraphStyle release]; -} - - -- (NSSize)sizeOfLabel:(BOOL)shouldTruncateLabel -{ - int numTabs; - float theWidth = 0; - - //if we've got text, size for # of tabs & amount of text. - // Accounts for icon size, if one present. - if ([mLabelString length] > 0) { - numTabs = [[self tabView] numberOfTabViewItems]; - if (numTabs < kMinTabsForSpacing) - numTabs = kMinTabsForSpacing; - theWidth = NSWidth([[self tabView] frame]) / numTabs - 16.0; // 16 works - don't know why. Maybe 8px on each side of the label? - if (shouldTruncateLabel) { - //I have really no clue what this is for. - //it only gets set YES when the tabs have - //reached the edge of the screen area. - //I don't see any difference in behavior between putting - //in -10 or -600 here. But -1 instead of -10 makes the - //tabs go off screen. - theWidth -= 16.0; - } - } - // If we don't have text, but DO have an icon, we'll have size 15. - else if ([self tabIcon]) - theWidth = 15.0; - - return NSMakeSize(theWidth, 15.0); // ugh, hard-coded height. - // This doesn't seem to affect, the height, only the rect pass to - // drawLabel. -} - --(void)drawLabel:(BOOL)shouldTruncateLabel inRect:(NSRect)tabRect -{ - if ([self tabIcon]) { - NSPoint drawPoint = NSMakePoint( (tabRect.origin.x), (tabRect.origin.y + 15.0) ); - [[self tabIcon] compositeToPoint:drawPoint operation:NSCompositeSourceOver]; - tabRect = NSMakeRect(NSMinX(tabRect) + 18.0, - NSMinY(tabRect), - NSWidth(tabRect) - 18.0, - NSHeight(tabRect)); - } - - // Check if we have to rebuild the cached label string - either because the - // size changed, or the label changed, or because we never set the label before. - int width = NSWidth(tabRect); - if (mLabelStringWidth != width || !mTruncLabelString) { - [mTruncLabelString release]; - mTruncLabelString = [[NSMutableString alloc] initWithString:mLabelString]; - mLabelStringWidth = width; - -#ifdef BROKEN_NSLineBreakByTruncatingMiddle - // Do our own truncating until Apple implements LineBreakByTruncatingTail/Middle. - // Then we can remove this code. - [mTruncLabelString truncateToWidth:width at:kTruncateAtEnd withAttributes:mLabelAttributes]; -#endif - } - - [mTruncLabelString drawInRect:tabRect withAttributes:mLabelAttributes]; -} - --(NSImage *)tabIcon -{ - return mTabIcon; -} - --(void)setTabIcon:(NSImage *)newIcon -{ - [mTabIcon autorelease]; - mTabIcon = [newIcon copy]; -} - -- (void)setLabel:(NSString *)label -{ - // We use our complete own label storage, since for some reasons NSTabViewItem - // will start to slow us down a *lot* if the label becomes very long - // (even though we don't use the original drawing/size code at all). - if (![label isEqual:mLabelString]) { - [mLabelString release]; - mLabelString = [label copy]; - mLabelStringWidth = -1; - - // we need to call setLabel on super to make some stuff happen, but the string - // doesn't matter. - [super setLabel:@"foo"]; - } -} - -- (NSString *)label -{ - return mLabelString; -} - -@end diff --git a/mozilla/chimera/CHImageAdditions.h b/mozilla/chimera/CHImageAdditions.h deleted file mode 100644 index 54c5e8cd1a5..00000000000 --- a/mozilla/chimera/CHImageAdditions.h +++ /dev/null @@ -1,7 +0,0 @@ -#import - -@interface NSImage (CHImageAdditions) -- (void) drawFlippedInRect:(NSRect) rect operation:(NSCompositingOperation) op fraction:(float) delta; -- (void) drawFlippedInRect:(NSRect) rect operation:(NSCompositingOperation) op; -- (void)applyBadge:(NSImage*)badge withAlpha:(float)alpha scale:(float)scale; -@end diff --git a/mozilla/chimera/CHImageAdditions.m b/mozilla/chimera/CHImageAdditions.m deleted file mode 100644 index 81362fda06e..00000000000 --- a/mozilla/chimera/CHImageAdditions.m +++ /dev/null @@ -1,36 +0,0 @@ -#import "CHImageAdditions.h" -#import - -@implementation NSImage (CHImageAdditions) -- (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)applyBadge:(NSImage*)badge withAlpha:(float)alpha scale:(float)scale -{ - if (!badge) - return; - - [badge setScalesWhenResized:YES]; - [badge setSize:NSMakeSize([self size].width * scale,[self size].height * scale)]; - - [self lockFocus]; - [[NSGraphicsContext currentContext] setImageInterpolation:NSImageInterpolationHigh]; - [badge dissolveToPoint:NSMakePoint([self size].width - [badge size].width,0) fraction:alpha]; - [self unlockFocus]; -} - -@end diff --git a/mozilla/chimera/CHLocationBar.h b/mozilla/chimera/CHLocationBar.h deleted file mode 100644 index f2700e473f6..00000000000 --- a/mozilla/chimera/CHLocationBar.h +++ /dev/null @@ -1,30 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- -* -* 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 the Mozilla browser. -* -* The Initial Developer of the Original Code is Netscape -* Communications Corporation. Portions created by Netscape are -* Copyright (C) 2002 Netscape Communications Corporation. All -* Rights Reserved. -* -* Contributor(s): -* David Hyatt (Original Author) -*/ - -#import - -@interface CHLocationBar : NSView { - -} - -@end diff --git a/mozilla/chimera/CHLocationBar.mm b/mozilla/chimera/CHLocationBar.mm deleted file mode 100644 index 6056d1c7977..00000000000 --- a/mozilla/chimera/CHLocationBar.mm +++ /dev/null @@ -1,55 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** -* Version: NPL 1.1/GPL 2.0/LGPL 2.1 -* -* The contents of this file are subject to the Netscape 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/NPL/ -* -* 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 mozilla.org 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): -* David Hyatt (Original Author) -* -* 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 NPL, 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 NPL, the GPL or the LGPL. -* -* ***** END LICENSE BLOCK ***** */ - -#import "CHLocationBar.h" - -@implementation CHLocationBar - -- (void)drawRect:(NSRect)aRect { - // Frame the border. - //NSDrawLightBezel([self bounds], aRect); - - [[NSColor colorWithCalibratedWhite: 0.98 alpha: 1.0] set]; - NSRectFill(aRect); - - [[NSColor colorWithCalibratedWhite: 0.90 alpha: 1.0] set]; - NSFrameRectWithWidth([self bounds], 2.0); -} - - -@end diff --git a/mozilla/chimera/CHPageProxyIcon.h b/mozilla/chimera/CHPageProxyIcon.h deleted file mode 100644 index 4e8b1e17ce8..00000000000 --- a/mozilla/chimera/CHPageProxyIcon.h +++ /dev/null @@ -1,31 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- -* -* 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 the Mozilla browser. -* -* The Initial Developer of the Original Code is Netscape -* Communications Corporation. Portions created by Netscape are -* Copyright (C) 2002 Netscape Communications Corporation. All -* Rights Reserved. -* -* Contributor(s): -* Joe Hewitt (Original Author) -*/ - -#import - -@interface CHPageProxyIcon : NSImageView -{ -} - - -@end diff --git a/mozilla/chimera/CHPageProxyIcon.mm b/mozilla/chimera/CHPageProxyIcon.mm deleted file mode 100644 index 51ab9d59f31..00000000000 --- a/mozilla/chimera/CHPageProxyIcon.mm +++ /dev/null @@ -1,93 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- -* -* 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 the Mozilla browser. -* -* The Initial Developer of the Original Code is Netscape -* Communications Corporation. Portions created by Netscape are -* Copyright (C) 2002 Netscape Communications Corporation. All -* Rights Reserved. -* -* Contributor(s): -* Joe Hewitt (Original Author) -*/ - -#import "NSString+Utils.h" - -#import "CHPageProxyIcon.h" - -#import "BookmarksService.h" -#import "MainController.h" - -#include "nsCRT.h" -#include "nsNetUtil.h" -#include "nsString.h" - -@implementation CHPageProxyIcon - -- (void)awakeFromNib -{ -} - -- (void)dealloc -{ - [super dealloc]; -} - -- (void) resetCursorRects -{ - NSCursor* cursor; - - // XXX provide image for drag-hand cursor - cursor = [NSCursor arrowCursor]; - [self addCursorRect:NSMakeRect(0,0,[self frame].size.width,[self frame].size.height) cursor:cursor]; - [cursor setOnMouseEntered:YES]; -} - -- (unsigned int)draggingSourceOperationMaskForLocal:(BOOL)flag -{ - return NSDragOperationGeneric; -} - -- (void)mouseDown:(NSEvent *)theEvent -{ - // need to implement this or else mouseDragged isn't called -} - -- (void) mouseDragged: (NSEvent*) event -{ - nsAutoString hrefStr, titleStr; - BookmarksService::GetTitleAndHrefForBrowserView( - [[[[self window] windowController] getBrowserWrapper] getBrowserView], titleStr, hrefStr); - - NSString *url = [NSString stringWith_nsAString: hrefStr]; - NSString *title = [NSString stringWith_nsAString: titleStr]; - - NSString *cleanedTitle = [title stringByReplacingCharactersInSet:[NSCharacterSet controlCharacterSet] withString:@" "]; - - NSArray *dataVals = [NSArray arrayWithObjects: url, cleanedTitle, nil]; - NSArray *dataKeys = [NSArray arrayWithObjects: @"url", @"title", nil]; - NSDictionary *data = [NSDictionary dictionaryWithObjects:dataVals forKeys:dataKeys]; - - NSPasteboard *pboard = [NSPasteboard pasteboardWithName:NSDragPboard]; - [pboard declareTypes:[NSArray arrayWithObjects:@"MozURLType", NSURLPboardType, NSStringPboardType, nil] owner:self]; - [pboard setPropertyList:data forType: @"MozURLType"]; - [[NSURL URLWithString:url] writeToPasteboard: pboard]; - [pboard setString:url forType: NSStringPboardType]; - - [self dragImage: [MainController createImageForDragging:[self image] title:title] - at: NSMakePoint(0,0) offset: NSMakeSize(0,0) - event: event pasteboard: pboard source: self slideBack: YES]; -} - - -@end diff --git a/mozilla/chimera/CHPreferenceManager.h b/mozilla/chimera/CHPreferenceManager.h deleted file mode 100644 index a682a4c80e4..00000000000 --- a/mozilla/chimera/CHPreferenceManager.h +++ /dev/null @@ -1,66 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape 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/NPL/ - * - * 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 mozilla.org 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 NPL, 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 NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#import -#import - -class nsIPref; - -@interface CHPreferenceManager : NSObject -{ - NSUserDefaults* mDefaults; - ICInstance mInternetConfig; - nsIPref* mPrefs; -} - -+ (CHPreferenceManager *)sharedInstance; - -- (id) init; -- (void) dealloc; -- (BOOL) initInternetConfig; -- (BOOL) initMozillaPrefs; -- (void) syncMozillaPrefs; - -- (NSString *) getICStringPref:(ConstStr255Param) prefKey; -- (NSString *) homePage:(BOOL) checkStartupPagePref; - -- (NSString*)getStringPref: (const char*)prefName withSuccess:(BOOL*)outSuccess; -- (NSColor*)getColorPref: (const char*)prefName withSuccess:(BOOL*)outSuccess; -- (BOOL)getBooleanPref: (const char*)prefName withSuccess:(BOOL*)outSuccess; -- (int)getIntPref: (const char*)prefName withSuccess:(BOOL*)outSuccess; - -@end diff --git a/mozilla/chimera/CHPreferenceManager.mm b/mozilla/chimera/CHPreferenceManager.mm deleted file mode 100644 index 1fcdece52f9..00000000000 --- a/mozilla/chimera/CHPreferenceManager.mm +++ /dev/null @@ -1,481 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape 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/NPL/ - * - * 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 mozilla.org 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 NPL, 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 NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#import -#import - -#import -#import "CHPreferenceManager.h" -#import "CHUserDefaults.h" - -#include "nsIServiceManager.h" -#include "nsIProfile.h" -#include "nsIPref.h" -#include "nsIPrefService.h" -#include "nsIPrefBranch.h" -#include "nsString.h" -#include "nsEmbedAPI.h" -#include "AppDirServiceProvider.h" - - -#ifdef _BUILD_STATIC_BIN -#include "nsStaticComponent.h" -nsresult PR_CALLBACK -app_getModuleInfo(nsStaticModuleInfo **info, PRUint32 *count); -#endif - -@implementation CHPreferenceManager - - -+ (CHPreferenceManager *) sharedInstance { - static CHPreferenceManager *sSharedInstance = nil; - return ( sSharedInstance ? sSharedInstance : (sSharedInstance = [[[CHPreferenceManager alloc] init] autorelease] )); -} - - -- (id) init -{ - if ((self = [super init])) { - if ([self initInternetConfig] == NO) { - // XXXw. throw here - NSLog (@"Failed to initialize Internet Config"); - } - if ([self initMozillaPrefs] == NO) { - // XXXw. throw here too - NSLog (@"Failed to initialize mozilla prefs"); - } - - mDefaults = [NSUserDefaults standardUserDefaults]; - } - return self; -} - -- (void) dealloc -{ - ::ICStop(mInternetConfig); - NS_IF_RELEASE(mPrefs); - - nsresult rv; - nsCOMPtr pref(do_GetService(NS_PREF_CONTRACTID, &rv)); - if (NS_SUCCEEDED(rv)) { - //NSLog(@"Saving prefs file"); - pref->SavePrefFile(nsnull); - } - - [super dealloc]; -} - -- (BOOL) initInternetConfig -{ - OSStatus error; - error = ::ICStart(&mInternetConfig, 'CHIM'); - if (error != noErr) { - // XXX throw here? - NSLog(@"Error initializing IC"); - return NO; - } - return YES; -} - -- (BOOL) initMozillaPrefs -{ - -#ifdef _BUILD_STATIC_BIN - // Initialize XPCOM's module info table - NSGetStaticModuleInfo = app_getModuleInfo; -#endif - - nsresult rv; - - NSString *path = [[[NSBundle mainBundle] executablePath] stringByDeletingLastPathComponent]; - const char *binDirPath = [path fileSystemRepresentation]; - nsCOMPtr binDir; - rv = NS_NewNativeLocalFile(nsDependentCString(binDirPath), PR_TRUE, getter_AddRefs(binDir)); - if (NS_FAILED(rv)) - return NO; - - // This shouldn't be needed since we are initing XPCOM with this - // directory but causes a (harmless) warning if not defined. - setenv("MOZILLA_FIVE_HOME", binDirPath, 1); - - // get the 'mozProfileDirName' key from our Info.plist file - NSString *dirString = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"mozProfileDirName"]; - const char* profileDirName; - if (dirString) - profileDirName = [dirString cString]; - else { - NSLog(@"mozProfileDirName key missing from Info.plist file. Using default profile directory"); - profileDirName = "Chimera"; - } - - // Supply our own directory service provider so we can control where - // the registry and profiles are located. - AppDirServiceProvider *provider = new AppDirServiceProvider(nsDependentCString(profileDirName)); - NS_ASSERTION(provider, "Failed to create AppDirServiceProvider"); - rv = NS_InitEmbedding(binDir, provider); - if (NS_FAILED(rv)) { - NSLog(@"Embedding init failed."); - return NO; - } - - nsCOMPtr profileService(do_GetService(NS_PROFILE_CONTRACTID, &rv)); - if (NS_FAILED(rv)) - return NO; - - nsAutoString newProfileName(NS_LITERAL_STRING("default")); - PRBool profileExists = PR_FALSE; - rv = profileService->ProfileExists(newProfileName.get(), &profileExists); - if (NS_FAILED(rv)) - return NO; - - if (!profileExists) { - rv = profileService->CreateNewProfile(newProfileName.get(), nsnull, nsnull, PR_FALSE); - if (NS_FAILED(rv)) - return NO; - } - - rv = profileService->SetCurrentProfile(newProfileName.get()); - if (NS_FAILED(rv)) { - if (rv == NS_ERROR_FILE_ACCESS_DENIED) { - NSString *alert = [NSString stringWithFormat: NSLocalizedString(@"AlreadyRunningAlert", @""), NSLocalizedStringFromTable(@"CFBundleName", @"InfoPlist", nil)]; - NSString *message = [NSString stringWithFormat: NSLocalizedString(@"AlreadyRunningMsg", @""), NSLocalizedStringFromTable(@"CFBundleName", @"InfoPlist", nil)]; - NSString *quit = NSLocalizedString(@"AlreadyRunningButton",@""); - NSRunAlertPanel(alert,message,quit,nil,nil); - [NSApp terminate:self]; - } - return NO; - } - - nsCOMPtr prefs(do_GetService(NS_PREF_CONTRACTID)); - mPrefs = prefs; - NS_IF_ADDREF(mPrefs); - - [self syncMozillaPrefs]; - return YES; -} - -- (void) syncMozillaPrefs -{ - CFArrayRef cfArray; - CFDictionaryRef cfDictionary; - CFNumberRef cfNumber; - CFStringRef cfString; - char strbuf[1024]; - int numbuf; - - if (!mPrefs) { - NSLog(@"Mozilla prefs not set up successfully"); - return; - } - - // fix up the cookie prefs. If 'p3p' or 'accept foreign cookies' are on, remap them to - // something that chimera can deal with. - PRInt32 acceptCookies = 0; - static const char* kCookieBehaviorPref = "network.cookie.cookieBehavior"; - mPrefs->GetIntPref(kCookieBehaviorPref, &acceptCookies); - if ( acceptCookies == 1 ) { // accept foreign cookies, assume off - acceptCookies = 2; - mPrefs->SetIntPref(kCookieBehaviorPref, acceptCookies); - } - else if ( acceptCookies == 3 ) { // p3p, assume all cookies on - acceptCookies = 0; - mPrefs->SetIntPref(kCookieBehaviorPref, acceptCookies); - } - - // get proxies from SystemConfiguration - mPrefs->SetIntPref("network.proxy.type", 0); // 0 == no proxies - mPrefs->ClearUserPref("network.proxy.http"); - mPrefs->ClearUserPref("network.proxy.http_port"); - mPrefs->ClearUserPref("network.proxy.ssl"); - mPrefs->ClearUserPref("network.proxy.ssl_port"); - mPrefs->ClearUserPref("network.proxy.ftp"); - mPrefs->ClearUserPref("network.proxy.ftp_port"); - mPrefs->ClearUserPref("network.proxy.gopher"); - mPrefs->ClearUserPref("network.proxy.gopher_port"); - mPrefs->ClearUserPref("network.proxy.socks"); - mPrefs->ClearUserPref("network.proxy.socks_port"); - mPrefs->ClearUserPref("network.proxy.no_proxies_on"); - - if ((cfDictionary = SCDynamicStoreCopyProxies (NULL)) != NULL) { - if (CFDictionaryGetValueIfPresent (cfDictionary, kSCPropNetProxiesHTTPEnable, (const void **)&cfNumber) == TRUE) { - if (CFNumberGetValue (cfNumber, kCFNumberIntType, &numbuf) == TRUE && numbuf == 1) { - if (CFDictionaryGetValueIfPresent (cfDictionary, kSCPropNetProxiesHTTPProxy, (const void **)&cfString) == TRUE) { - if (CFStringGetCString (cfString, strbuf, sizeof(strbuf)-1, kCFStringEncodingASCII) == TRUE) { - mPrefs->SetCharPref("network.proxy.http", strbuf); - } - if (CFDictionaryGetValueIfPresent (cfDictionary, kSCPropNetProxiesHTTPPort, (const void **)&cfNumber) == TRUE) { - if (CFNumberGetValue (cfNumber, kCFNumberIntType, &numbuf) == TRUE) { - mPrefs->SetIntPref("network.proxy.http_port", numbuf); - } - mPrefs->SetIntPref("network.proxy.type", 1); - } - } - } - } - if (CFDictionaryGetValueIfPresent (cfDictionary, kSCPropNetProxiesHTTPSEnable, (const void **)&cfNumber) == TRUE) { - if (CFNumberGetValue (cfNumber, kCFNumberIntType, &numbuf) == TRUE && numbuf == 1) { - if (CFDictionaryGetValueIfPresent (cfDictionary, kSCPropNetProxiesHTTPSProxy, (const void **)&cfString) == TRUE) { - if (CFStringGetCString (cfString, strbuf, sizeof(strbuf)-1, kCFStringEncodingASCII) == TRUE) { - mPrefs->SetCharPref("network.proxy.ssl", strbuf); - } - if (CFDictionaryGetValueIfPresent (cfDictionary, kSCPropNetProxiesHTTPSPort, (const void **)&cfNumber) == TRUE) { - if (CFNumberGetValue (cfNumber, kCFNumberIntType, &numbuf) == TRUE) { - mPrefs->SetIntPref("network.proxy.ssl_port", numbuf); - } - mPrefs->SetIntPref("network.proxy.type", 1); - } - } - } - } - if (CFDictionaryGetValueIfPresent (cfDictionary, kSCPropNetProxiesFTPEnable, (const void **)&cfNumber) == TRUE) { - if (CFNumberGetValue (cfNumber, kCFNumberIntType, &numbuf) == TRUE && numbuf == 1) { - if (CFDictionaryGetValueIfPresent (cfDictionary, kSCPropNetProxiesFTPProxy, (const void **)&cfString) == TRUE) { - if (CFStringGetCString (cfString, strbuf, sizeof(strbuf)-1, kCFStringEncodingASCII) == TRUE) { - mPrefs->SetCharPref("network.proxy.ftp", strbuf); - } - if (CFDictionaryGetValueIfPresent (cfDictionary, kSCPropNetProxiesFTPPort, (const void **)&cfNumber) == TRUE) { - if (CFNumberGetValue (cfNumber, kCFNumberIntType, &numbuf) == TRUE) { - mPrefs->SetIntPref("network.proxy.ftp_port", numbuf); - } - mPrefs->SetIntPref("network.proxy.type", 1); - } - } - } - } - if (CFDictionaryGetValueIfPresent (cfDictionary, kSCPropNetProxiesGopherEnable, (const void **)&cfNumber) == TRUE) { - if (CFNumberGetValue (cfNumber, kCFNumberIntType, &numbuf) == TRUE && numbuf == 1) { - if (CFDictionaryGetValueIfPresent (cfDictionary, kSCPropNetProxiesGopherProxy, (const void **)&cfString) == TRUE) { - if (CFStringGetCString (cfString, strbuf, sizeof(strbuf)-1, kCFStringEncodingASCII) == TRUE) { - mPrefs->SetCharPref("network.proxy.gopher", strbuf); - } - if (CFDictionaryGetValueIfPresent (cfDictionary, kSCPropNetProxiesGopherPort, (const void **)&cfNumber) == TRUE) { - if (CFNumberGetValue (cfNumber, kCFNumberIntType, &numbuf) == TRUE) { - mPrefs->SetIntPref("network.proxy.gopher_port", numbuf); - } - mPrefs->SetIntPref("network.proxy.type", 1); - } - } - } - } - if (CFDictionaryGetValueIfPresent (cfDictionary, kSCPropNetProxiesSOCKSEnable, (const void **)&cfNumber) == TRUE) { - if (CFNumberGetValue (cfNumber, kCFNumberIntType, &numbuf) == TRUE && numbuf == 1) { - if (CFDictionaryGetValueIfPresent (cfDictionary, kSCPropNetProxiesSOCKSProxy, (const void **)&cfString) == TRUE) { - if (CFStringGetCString (cfString, strbuf, sizeof(strbuf)-1, kCFStringEncodingASCII) == TRUE) { - mPrefs->SetCharPref("network.proxy.socks", strbuf); - } - if (CFDictionaryGetValueIfPresent (cfDictionary, kSCPropNetProxiesSOCKSPort, (const void **)&cfNumber) == TRUE) { - if (CFNumberGetValue (cfNumber, kCFNumberIntType, &numbuf) == TRUE) { - mPrefs->SetIntPref("network.proxy.socks_port", numbuf); - } - mPrefs->SetIntPref("network.proxy.type", 1); - } - } - } - } - if (CFDictionaryGetValueIfPresent (cfDictionary, kSCPropNetProxiesExceptionsList, (const void **)&cfArray) == TRUE) { - cfString = CFStringCreateByCombiningStrings (NULL, cfArray, CFSTR(", ")); - if (CFStringGetLength (cfString) > 0) { - if (CFStringGetCString (cfString, strbuf, sizeof(strbuf)-1, kCFStringEncodingASCII) == TRUE) { - mPrefs->SetCharPref("network.proxy.no_proxies_on", strbuf); - } - } - } - CFRelease (cfDictionary); - } -} - -- (NSString*)getStringPref: (const char*)prefName withSuccess:(BOOL*)outSuccess -{ - NSString *prefValue = @""; - - char *buf = nsnull; - nsresult rv = NS_ERROR_FAILURE; - if (mPrefs) - rv = mPrefs->GetCharPref(prefName, &buf); - - if (NS_SUCCEEDED(rv) && buf) { - // prefs are UTF-8 - prefValue = [NSString stringWithUTF8String:buf]; - free(buf); - if (outSuccess) *outSuccess = YES; - } else { - if (outSuccess) *outSuccess = NO; - } - - return prefValue; -} - -- (NSColor*)getColorPref: (const char*)prefName withSuccess:(BOOL*)outSuccess -{ - // colors are stored in HTML-like #FFFFFF strings - NSString* colorString = [self getStringPref:prefName withSuccess:outSuccess]; - NSColor* returnColor = [NSColor blackColor]; - - if ([colorString hasPrefix:@"#"] && [colorString length] == 7) - { - unsigned int redInt, greenInt, blueInt; - sscanf([colorString cString], "#%02x%02x%02x", &redInt, &greenInt, &blueInt); - - float redFloat = ((float)redInt / 255.0); - float greenFloat = ((float)greenInt / 255.0); - float blueFloat = ((float)blueInt / 255.0); - - returnColor = [NSColor colorWithCalibratedRed:redFloat green:greenFloat blue:blueFloat alpha:1.0f]; - } - - return returnColor; -} - -- (BOOL)getBooleanPref: (const char*)prefName withSuccess:(BOOL*)outSuccess -{ - PRBool boolPref = PR_FALSE; - nsresult rv = NS_ERROR_FAILURE; - if (mPrefs) - rv = mPrefs->GetBoolPref(prefName, &boolPref); - - if (outSuccess) - *outSuccess = NS_SUCCEEDED(rv); - - return boolPref ? YES : NO; -} - -- (int)getIntPref: (const char*)prefName withSuccess:(BOOL*)outSuccess -{ - PRInt32 intPref = 0; - nsresult rv = NS_ERROR_FAILURE; - if (mPrefs) - mPrefs->GetIntPref(prefName, &intPref); - if (outSuccess) - *outSuccess = NS_SUCCEEDED(rv); - return intPref; -} - - - -//- (BOOL) getICBoolPref:(ConstStr255Param) prefKey; -//{ -// ICAttr dummy; -// OSStatus error; -// SInt32 size; -// Boolean buf; - -// error = ICGetPref (internetConfig, prefKey, &dummy, &buf, &size); -// if (error == noErr && buf) -// return YES; -// else -// return NO; -// } - -- (NSString *) getICStringPref:(ConstStr255Param) prefKey; -{ - NSString *string; - ICAttr dummy; - OSStatus error; - SInt32 size = 256; - char *buf; - - do { - if ((buf = malloc ((unsigned int)size)) == NULL) { - NSLog (@"malloc failed in [PreferenceManager getICStringPref]"); - return nil; - } - error = ICGetPref (mInternetConfig, prefKey, &dummy, buf, &size); - if (error != noErr && error != icTruncatedErr) { - free (buf); - NSLog (@"[IC error %d in [PreferenceManager getICStringPref]", (int) error); - return nil; - } - size *= 2; - } while (error == icTruncatedErr); - if (*buf == 0) { - NSLog (@"ICGetPref returned empty string"); - free (buf); - return nil; - } - CopyPascalStringToC ((ConstStr255Param) buf, buf); - string = [NSString stringWithCString:buf]; - free (buf); - return string; -} - - -- (NSString *) homePage:(BOOL)checkStartupPagePref -{ - if (!mPrefs) - return @"about:blank"; - - PRInt32 mode = 1; - - // In some cases, we need to check browser.startup.page to see if - // we want to use the homepage or if the user wants a blank window. - // mode 0 is blank page, mode 1 is home page. 2 is "last page visited" - // but we don't care about that. Default to 1 unless |checkStartupPagePref| - // is true. - nsresult rv = NS_OK; - if ( checkStartupPagePref ) - rv = mPrefs->GetIntPref("browser.startup.page", &mode); - if (NS_FAILED(rv) || mode == 1) { - // see which home page to use - PRBool boolPref; - if (NS_SUCCEEDED(mPrefs->GetBoolPref("chimera.use_system_home_page", &boolPref)) && boolPref) - return [self getICStringPref:kICWWWHomePage]; - - nsCOMPtr prefBranch = do_QueryInterface(mPrefs); - if (!prefBranch) return @"about:blank"; - - NSString* homepagePref = nil; - PRInt32 haveUserPref; - if (NS_FAILED(prefBranch->PrefHasUserValue("browser.startup.homepage", &haveUserPref)) || !haveUserPref) { - // no home page pref is set in user prefs. - homepagePref = NSLocalizedStringFromTable( @"HomePageDefault", @"WebsiteDefaults", nil); - // and let's copy this into the homepage pref if it's not bad - if (![homepagePref isEqualToString:@"HomePageDefault"]) - mPrefs->SetCharPref("browser.startup.homepage", [homepagePref UTF8String]); - } - else { - homepagePref = [self getStringPref:"browser.startup.homepage" withSuccess:NULL]; - } - - if (homepagePref && [homepagePref length] > 0 && ![homepagePref isEqualToString:@"HomePageDefault"]) - return homepagePref; - } - - return @"about:blank"; -} - -@end - diff --git a/mozilla/chimera/CHRDFOutlineViewDataSource.h b/mozilla/chimera/CHRDFOutlineViewDataSource.h deleted file mode 100644 index 2d66e0ef490..00000000000 --- a/mozilla/chimera/CHRDFOutlineViewDataSource.h +++ /dev/null @@ -1,93 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape 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/NPL/ - * - * 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 mozilla.org 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): - * Ben Goodger (Original Author) - * - * 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 NPL, 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 NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#import -#import - -class nsIRDFDataSource; -class nsIRDFContainer; -class nsIRDFContainerUtils; -class nsIRDFResource; -class nsIRDFService; - -@interface CHRDFOutlineViewDataSource : NSObject { - nsIRDFDataSource* mDataSource; - nsIRDFContainer* mContainer; - nsIRDFContainerUtils* mContainerUtils; - nsIRDFResource* mRootResource; - nsIRDFService* mRDFService; - - IBOutlet id mOutlineView; - - NSMutableDictionary* mDictionary; -} - -// Initialization Methods -- (void) ensureDataSourceLoaded; - -- (nsIRDFDataSource*) dataSource; -- (nsIRDFResource*) rootResource; -- (void) setDataSource: (nsIRDFDataSource*) aDataSource; -- (void) setRootResource: (nsIRDFResource*) aResource; - -// Outline View Data Source methods -- (id)outlineView:(NSOutlineView *)outlineView child:(int)index ofItem:(id)item; -- (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item; -- (int)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item; -- (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item; -- (void)outlineView:(NSOutlineView *)outlineView setObjectValue:(id)object forTableColumn:(NSTableColumn *)tableColumn byItem:(id)item; - -- (void)reloadDataForItem:(id)item reloadChildren: (BOOL)aReloadChildren; - -// Implementation Methods -- (id) MakeWrapperFor: (nsIRDFResource*) aRDFResource; - -@end - -// RDF Resource Wrapper to make the Outline View happy -@interface RDFOutlineViewItem : NSObject -{ - nsIRDFResource* mResource; -} - -- (nsIRDFResource*) resource; -- (void) setResource: (nsIRDFResource*) aResource; - -@end - - diff --git a/mozilla/chimera/CHRDFOutlineViewDataSource.mm b/mozilla/chimera/CHRDFOutlineViewDataSource.mm deleted file mode 100644 index c39c8263299..00000000000 --- a/mozilla/chimera/CHRDFOutlineViewDataSource.mm +++ /dev/null @@ -1,325 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape 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/NPL/ - * - * 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 mozilla.org 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): - * Ben Goodger (Original Author) - * - * 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 NPL, 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 NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#import "NSString+Utils.h" - -#import "CHRDFOutlineViewDataSource.h" - -#include "nsIRDFDataSource.h" -#include "nsIRDFService.h" -#include "nsIRDFLiteral.h" -#include "nsIRDFResource.h" -#include "nsIRDFContainer.h" -#include "nsIRDFContainerUtils.h" -#include "nsRDFCID.h" - -#include "nsComponentManagerUtils.h" -#include "nsIServiceManagerUtils.h" - -#include "nsXPIDLString.h" -#include "nsString.h" - - - -@implementation CHRDFOutlineViewDataSource - -- (void) ensureDataSourceLoaded -{ - if (!mContainer) - { - nsCOMPtr ctr = do_CreateInstance("@mozilla.org/rdf/container;1"); - NS_ADDREF(mContainer = ctr); - - nsCOMPtr ctrUtils = do_GetService("@mozilla.org/rdf/container-utils;1"); - NS_ADDREF(mContainerUtils = ctrUtils); - - nsCOMPtr rdfService = do_GetService("@mozilla.org/rdf/rdf-service;1"); - NS_ADDREF(mRDFService = rdfService); - - mDictionary = [[NSMutableDictionary alloc] initWithCapacity: 30]; - - mDataSource = nsnull; - mRootResource = nsnull; - } -} - -- (void) dealloc -{ - NS_IF_RELEASE(mContainer); - NS_IF_RELEASE(mContainerUtils); - NS_IF_RELEASE(mRDFService); - - NS_IF_RELEASE(mDataSource); - NS_IF_RELEASE(mRootResource); - - [mDictionary release]; - - [super dealloc]; -} - -- (nsIRDFDataSource*) dataSource -{ - NS_IF_ADDREF(mDataSource); - return mDataSource; -} - -- (nsIRDFResource*) rootResource -{ - NS_IF_ADDREF(mRootResource); - return mRootResource; -} - -- (void) setDataSource: (nsIRDFDataSource*) aDataSource -{ - nsIRDFDataSource* oldDataSource = mDataSource; - NS_IF_ADDREF(mDataSource = aDataSource); - NS_IF_RELEASE(oldDataSource); -} - -- (void) setRootResource: (nsIRDFResource*) aResource -{ - nsIRDFResource* oldResource = mRootResource; - NS_IF_ADDREF(mRootResource = aResource); - NS_IF_RELEASE(oldResource); -} - -// -// XXX - For now, we'll just say that none of our items are editable, as we aren't using any -// RDF datasources that are mutable. -// -- (BOOL) outlineView: (NSOutlineView*) aOutlineView shouldEditTableColumn: (NSTableColumn*) aTableColumn - item: (id) aItem -{ - return NO; -} - -- (BOOL) outlineView: (NSOutlineView*) aOutlineView isItemExpandable: (id) aItem -{ - if (!mDataSource) - return NO; - - if (!aItem) - return YES; // The root is always open - - nsCOMPtr itemResource = dont_AddRef([aItem resource]); - - PRBool isSeq = PR_FALSE; - mContainerUtils->IsSeq(mDataSource, itemResource, &isSeq); - if (isSeq) - return YES; - - nsCOMPtr childProperty; - mRDFService->GetResource("http://home.netscape.com/NC-rdf#child", getter_AddRefs(childProperty)); - - nsCOMPtr childNode; - mDataSource->GetTarget(itemResource, childProperty, PR_TRUE, getter_AddRefs(childNode)); - - return childNode != nsnull; -} - -- (id) outlineView: (NSOutlineView*) aOutlineView child: (int) aIndex - ofItem: (id) aItem -{ - if (!mDataSource) - return nil; - - nsCOMPtr resource = !aItem ? dont_AddRef([self rootResource]) : dont_AddRef([aItem resource]); - - nsCOMPtr ordinalResource; - mContainerUtils->IndexToOrdinalResource(aIndex + 1, getter_AddRefs(ordinalResource)); - - nsCOMPtr childNode; - mDataSource->GetTarget(resource, ordinalResource, PR_TRUE, getter_AddRefs(childNode)); - if (childNode) { - // Yay. A regular container. We don't need to count, we can go directly to - // our object. - nsCOMPtr childResource(do_QueryInterface(childNode)); - if (childResource) - return [self MakeWrapperFor:childResource]; - } - else - { - // Oh well, not a regular container. We need to count, dagnabbit. - nsCOMPtr childProperty; - mRDFService->GetResource("http://home.netscape.com/NC-rdf#child", getter_AddRefs(childProperty)); - - nsCOMPtr childNodes; - mDataSource->GetTargets(resource, childProperty, PR_TRUE, getter_AddRefs(childNodes)); - - nsCOMPtr supp; - PRInt32 count = 0; - - PRBool hasMore = PR_FALSE; - while (NS_SUCCEEDED(childNodes->HasMoreElements(&hasMore)) && hasMore) - { - childNodes->GetNext(getter_AddRefs(supp)); - if (count == aIndex) - break; - count ++; - } - - nsCOMPtr childResource(do_QueryInterface(supp)); - if (childResource) { - return [self MakeWrapperFor:childResource]; - } - } - - return nil; -} - -- (int) outlineView: (NSOutlineView*) aOutlineView numberOfChildrenOfItem: (id) aItem; -{ - if (!mDataSource) - return 0; - - nsCOMPtr resource = dont_AddRef(aItem ? [aItem resource] : [self rootResource]); - - // XXX just assume NC:child is the only containment arc for now - nsCOMPtr childProperty; - mRDFService->GetResource("http://home.netscape.com/NC-rdf#child", getter_AddRefs(childProperty)); - - nsCOMPtr childNodes; - mDataSource->GetTargets(resource, childProperty, PR_TRUE, getter_AddRefs(childNodes)); - - PRBool hasMore = PR_FALSE; - PRInt32 count = 0; - - while (NS_SUCCEEDED(childNodes->HasMoreElements(&hasMore)) && hasMore) - { - nsCOMPtr supp; - childNodes->GetNext(getter_AddRefs(supp)); - count ++; - } - - if (count == 0) { - nsresult rv = mContainer->Init(mDataSource, resource); - if (NS_FAILED(rv)) - return 0; - - mContainer->GetCount(&count); - } - - return count; -} - -- (id) outlineView: (NSOutlineView*) aOutlineView objectValueForTableColumn: (NSTableColumn*) aTableColumn - byItem: (id) aItem -{ - if (!mDataSource || !aItem) - return nil; - - // The table column's identifier is the RDF Resource URI of the property being displayed in - // that column, e.g. "http://home.netscape.com/NC-rdf#Name" - NSString* columnPropertyURI = [aTableColumn identifier]; - - nsCOMPtr propertyResource; - mRDFService->GetResource([columnPropertyURI UTF8String], getter_AddRefs(propertyResource)); - - nsCOMPtr resource = dont_AddRef([aItem resource]); - - nsCOMPtr valueNode; - mDataSource->GetTarget(resource, propertyResource, PR_TRUE, getter_AddRefs(valueNode)); - if (!valueNode) { -#if DEBUG - NSLog(@"ValueNode is null in RDF objectValueForTableColumn"); -#endif - return nil; - } - - nsCOMPtr valueLiteral(do_QueryInterface(valueNode)); - if (!valueLiteral) - return nil; - - nsXPIDLString literalValue; - valueLiteral->GetValue(getter_Copies(literalValue)); - - return [NSString stringWith_nsAString: literalValue]; -} - -- (void) outlineView: (NSOutlineView*) aOutlineView setObjectValue: (id) aObject - forTableColumn: (NSTableColumn*) aTableColumn - byItem: (id) aItem -{ - -} - -- (void) reloadDataForItem: (id) aItem reloadChildren: (BOOL) aReloadChildren -{ - if (!aItem) - [mOutlineView reloadData]; - else - [mOutlineView reloadItem: aItem reloadChildren: aReloadChildren]; -} - -- (id) MakeWrapperFor: (nsIRDFResource*) aRDFResource -{ - RDFOutlineViewItem* item = [[[RDFOutlineViewItem alloc] init] autorelease]; - [item setResource: aRDFResource]; - // keep a copy around - const char* resourceValue; - aRDFResource->GetValueConst(&resourceValue); - - [mDictionary setObject:item forKey:[NSString stringWithCString:resourceValue]]; - return item; -} - - -@end - -@implementation RDFOutlineViewItem - -- (void) dealloc -{ - NS_IF_RELEASE(mResource); - [super dealloc]; -} - -- (nsIRDFResource*) resource -{ - NS_IF_ADDREF(mResource); - return mResource; -} - -- (void) setResource: (nsIRDFResource*) aResource -{ - nsIRDFResource* oldResource = mResource; - NS_IF_ADDREF(mResource = aResource); - NS_IF_RELEASE(oldResource); -} - -@end diff --git a/mozilla/chimera/CHSplashScreenWindow.h b/mozilla/chimera/CHSplashScreenWindow.h deleted file mode 100644 index df82c005af8..00000000000 --- a/mozilla/chimera/CHSplashScreenWindow.h +++ /dev/null @@ -1,45 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- -* -* 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 the Mozilla browser. -* -* The Initial Developer of the Original Code is Matt Judy. -*/ - -#import - -@interface CHSplashScreenWindow : NSWindow { - BOOL _fades; - BOOL __didFadeIn; - int _fadeIndex; - NSTimeInterval _fadeDelay; - id _fadeThreadLock; - NSTextField *_statusField; -} - -// This method inits the window and displays it, slightly proud of center, -// and at the size of the image it displays. -// -// The splash method should be used in your main controller's init method -// in this fashion: splashWindow = [[SplashScreenWindow alloc] splashImage:nil withFade:NO withStatusRect:someRect]; -// -// Passing nil to splashImage will attempt to load [NSImage imageNamed:@"splash"] instead. -// If that fails, the app icon will be displayed. -// -// The window will release itself whenever you send it the close message. --(id)splashImage:(NSImage *)splashImage withFade:(BOOL)shouldFade withStatusRect:(NSRect)statusRect; - --(NSString *)statusText; --(void)setStatusText:(NSString *)newText; - - -@end diff --git a/mozilla/chimera/CHSplashScreenWindow.m b/mozilla/chimera/CHSplashScreenWindow.m deleted file mode 100644 index 0cac643da15..00000000000 --- a/mozilla/chimera/CHSplashScreenWindow.m +++ /dev/null @@ -1,186 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- -* -* 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 the Mozilla browser. -* -* The Initial Developer of the Original Code is Matt Judy. -* -*/ - -#import "CHSplashScreenWindow.h" - -@interface CHSplashScreenWindow (Private) --(void)fadeIn; --(void)fadeInThread; --(void)fadeOut; --(void)fadeOutThread; -@end - -@implementation CHSplashScreenWindow - --(id)splashImage:(NSImage *)splashImage withFade:(BOOL)shouldFade withStatusRect:(NSRect)statusRect -{ - NSRect splashRect; - NSRect statusFieldRect; - NSImageView *contentImageView; - - _fadeDelay = (0.5 / 60.0); - - if ( ! splashImage ) { - if ( [NSImage imageNamed:@"splash"] ) { - splashImage = [NSImage imageNamed:@"splash"]; - } else { - splashImage = [NSImage imageNamed:@"NSApplicationIcon"]; - } - } - - splashRect = NSMakeRect(0.0, 0.0, [splashImage size].width, [splashImage size].height); - contentImageView = [[[NSImageView alloc] initWithFrame:splashRect] autorelease]; -#if USE_STATUS_FIELD - statusFieldRect = NSMakeRect(0.0, 170.0, (splashRect.size.width - 5.0), 16.0); - _statusField = [[[NSTextField alloc] initWithFrame:statusFieldRect]; -#endif - - if ( (self = [super initWithContentRect:splashRect - styleMask:NSBorderlessWindowMask - backing:NSBackingStoreBuffered - defer:NO]) ) { - - [contentImageView setImage:splashImage]; - _fadeThreadLock = nil; - -#if USE_STATUS_FIELD - [_statusField setDrawsBackground:NO]; - [_statusField setEditable:NO]; - [_statusField setSelectable:NO]; - [_statusField setBezeled:NO]; - [_statusField setBordered:NO]; - [_statusField setFont:[NSFont fontWithName:@"Monaco" size:10.0]]; - [_statusField setTextColor:[NSColor whiteColor]]; - [_statusField setAlignment:NSRightTextAlignment]; - [_statusField setStringValue:@"Loading..."]; -#endif - - [[self contentView] addSubview:contentImageView]; -#if USE_STATUS_FIELD - [[self contentView] addSubview:_statusField]; -#endif - [self setOpaque:NO]; - [self setHasShadow:YES]; - [self setReleasedWhenClosed:YES]; - [self center]; - - if ( shouldFade ) { - [self fadeIn]; - } else { - [self makeKeyAndOrderFront:self]; - } - __didFadeIn = shouldFade; - } - return self; -} - --(NSString *)statusText -{ - return [_statusField stringValue]; -} - --(void)setStatusText:(NSString *)newText -{ -#if USE_STATUS_FIELD - [_statusField setStringValue:newText]; - [_statusField display]; -#endif -} - --(void)fadeIn -{ - [self setAlphaValue:0.0]; - [self makeKeyAndOrderFront:self]; - - if (_fadeThreadLock == nil) { - _fadeThreadLock = [[NSLock allocWithZone:[self zone]] init]; - } - - [NSThread detachNewThreadSelector:@selector(fadeInThread) toTarget:self withObject:nil]; -} - --(void)fadeInThread -{ - float fadeLevel = 0.0; - NSAutoreleasePool *threadMainPool = [[NSAutoreleasePool alloc] init]; - - [_fadeThreadLock lock]; - - while ( fadeLevel < 1.0 ) { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - fadeLevel += 0.20; - [self setAlphaValue:fadeLevel]; - [self flushWindow]; - [NSThread sleepUntilDate:[NSDate dateWithTimeIntervalSinceNow:_fadeDelay]]; - [pool release]; - } - - [_fadeThreadLock unlock]; - [threadMainPool release]; -} - --(void)fadeOut -{ - if (_fadeThreadLock == nil) { - _fadeThreadLock = [[NSLock allocWithZone:[self zone]] init]; - } - - [NSThread detachNewThreadSelector:@selector(fadeOutThread) toTarget:self withObject:nil]; -} - --(void)fadeOutThread -{ - float fadeLevel = 1.0; - NSAutoreleasePool *threadMainPool = [[NSAutoreleasePool alloc] init]; - - [_fadeThreadLock lock]; - - while ( fadeLevel > 0.0 ) { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - fadeLevel -= 0.1; - [self setAlphaValue:fadeLevel]; - [self flushWindow]; - [NSThread sleepUntilDate:[NSDate dateWithTimeIntervalSinceNow:_fadeDelay]]; - [pool release]; - } - - [_fadeThreadLock unlock]; - [threadMainPool release]; -} - --(void)close -{ -#if USE_STATUS_FIELD - [_statusField release]; -#endif - -// if ( __didFadeIn ) { - if ( NO ) { //Fade out is still problematic... - [self fadeOut]; - } - [super close]; -} - --(void)dealloc -{ - [_fadeThreadLock release]; - - [super dealloc]; -} - -@end diff --git a/mozilla/chimera/CHToolbarAdditions.h b/mozilla/chimera/CHToolbarAdditions.h deleted file mode 100644 index 0831146aa7b..00000000000 --- a/mozilla/chimera/CHToolbarAdditions.h +++ /dev/null @@ -1,12 +0,0 @@ -#import - -@interface NSToolbar (CHToolbarCustomizableAdditions) -- (BOOL) alwaysCustomizableByDrag; -- (void) setAlwaysCustomizableByDrag:(BOOL) flag; - -- (BOOL) showsContextMenu; -- (void) setShowsContextMenu:(BOOL) flag; - -- (unsigned int) indexOfFirstMovableItem; -- (void) setIndexOfFirstMovableItem:(unsigned int) anIndex; -@end diff --git a/mozilla/chimera/CHToolbarAdditions.m b/mozilla/chimera/CHToolbarAdditions.m deleted file mode 100644 index 62e3c6f1bc8..00000000000 --- a/mozilla/chimera/CHToolbarAdditions.m +++ /dev/null @@ -1,28 +0,0 @@ -#import "CHToolbarAdditions.h" -#import - -@implementation NSToolbar (CHToolbarCustomizableAdditions) -- (BOOL) alwaysCustomizableByDrag { - return (BOOL) _tbFlags.clickAndDragPerformsCustomization; -} - -- (void) setAlwaysCustomizableByDrag:(BOOL) flag { - _tbFlags.clickAndDragPerformsCustomization = (unsigned int) flag & 1; -} - -- (BOOL) showsContextMenu { - return (BOOL) ! _tbFlags.showsNoContextMenu; -} - -- (void) setShowsContextMenu:(BOOL) flag { - _tbFlags.showsNoContextMenu = (unsigned int) ! flag & 1; -} - -- (unsigned int) indexOfFirstMovableItem { - return (unsigned int) _tbFlags.firstMoveableItemIndex; -} - -- (void) setIndexOfFirstMovableItem:(unsigned int) anIndex { - _tbFlags.firstMoveableItemIndex = (unsigned int) anIndex & 0x3F; -} -@end diff --git a/mozilla/chimera/CHUserDefaults.h b/mozilla/chimera/CHUserDefaults.h deleted file mode 100644 index 1c203420f0b..00000000000 --- a/mozilla/chimera/CHUserDefaults.h +++ /dev/null @@ -1,55 +0,0 @@ -/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** 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 mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 2001, 2002 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Simon Fraser - * - * 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 ***** */ - - -/* - This file contains a list of #defines for our user default entries. They - are collected here, rather than being scattered throughout the code, for - easier documentation. -*/ - - -#define USER_DEFAULTS_AUTOREGISTER_KEY @"autoRegister" /* Boolean */ -#define USER_DEFAULTS_URL_KEY @"url" /* String */ - -#define USER_DEFAULTS_HIDE_PERS_TOOLBAR_KEY @"Hide Personal Toolbar" /* Integer */ -#define USER_DEFAULTS_HOMEPAGE_KEY @"HomePage" /* String */ - -#define USER_DEFAULTS_AUTOCOMPLETE_WHILE_TYPING @"Autocomplete While Typing" /* Boolean */ - - diff --git a/mozilla/chimera/CocoaPromptService.h b/mozilla/chimera/CocoaPromptService.h deleted file mode 100644 index 4d8d3375fef..00000000000 --- a/mozilla/chimera/CocoaPromptService.h +++ /dev/null @@ -1,64 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** 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 mozilla.org 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): - * Brian Ryner - * - * 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 ***** */ - -#ifndef __CocoaPromptService_h__ -#define __CocoaPromptService_h__ - -#include "nsIStringBundle.h" -#include "nsIPromptService.h" -#import - -class CocoaPromptService : public nsIPromptService -{ -public: - CocoaPromptService(); - virtual ~CocoaPromptService(); - - NS_DECL_ISUPPORTS; - NS_DECL_NSIPROMPTSERVICE; - -private: - NSWindow *GetNSWindowForDOMWindow(nsIDOMWindow* window); - NSString *GetCommonDialogLocaleString(const char *s); - NSString *GetButtonStringFromFlags(PRUint32 btnFlags, PRUint32 btnIDAndShift, - const PRUnichar *btnTitle); - - nsCOMPtr mCommonDialogStringBundle; -}; - -#endif diff --git a/mozilla/chimera/CocoaPromptService.mm b/mozilla/chimera/CocoaPromptService.mm deleted file mode 100644 index 796762d02b8..00000000000 --- a/mozilla/chimera/CocoaPromptService.mm +++ /dev/null @@ -1,453 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** 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 mozilla.org 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): - * Brian Ryner - * - * 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 "NSString+Utils.h" - -#import "nsCocoaBrowserService.h" -#import "CocoaPromptService.h" - -#include "nsCRT.h" -#include "nsIWindowWatcher.h" -#include "nsIWebBrowserChrome.h" -#include "nsIEmbeddingSiteWindow.h" -#include "nsString.h" -#include "nsIServiceManagerUtils.h" - -CocoaPromptService::CocoaPromptService() -{ - NS_INIT_ISUPPORTS(); -} - -CocoaPromptService::~CocoaPromptService() -{ -} - -NS_IMPL_ISUPPORTS1(CocoaPromptService, nsIPromptService); - -/* void alert (in nsIDOMWindow parent, in wstring dialogTitle, in wstring text); */ -NS_IMETHODIMP -CocoaPromptService::Alert(nsIDOMWindow *parent, - const PRUnichar *dialogTitle, - const PRUnichar *text) -{ - nsAlertController* controller = nsCocoaBrowserService::GetAlertController(); - if (!controller) { - return NS_ERROR_FAILURE; - } - - NSString* titleStr = [NSString stringWithPRUnichars:dialogTitle]; - NSString* textStr = [NSString stringWithPRUnichars:text]; - NSWindow* window = GetNSWindowForDOMWindow(parent); - if (!window) - return NS_ERROR_FAILURE; - - [controller alert:window title:titleStr text:textStr]; - - return NS_OK; -} - -/* void alertCheck (in nsIDOMWindow parent, in wstring dialogTitle, in wstring text, in wstring checkMsg, inout boolean checkValue); */ -NS_IMETHODIMP -CocoaPromptService::AlertCheck(nsIDOMWindow *parent, - const PRUnichar *dialogTitle, - const PRUnichar *text, - const PRUnichar *checkMsg, - PRBool *checkValue) -{ - nsAlertController* controller = nsCocoaBrowserService::GetAlertController(); - if (!controller) { - return NS_ERROR_FAILURE; - } - - NSString* titleStr = [NSString stringWithPRUnichars:dialogTitle]; - NSString* textStr = [NSString stringWithPRUnichars:text]; - NSString* msgStr = [NSString stringWithPRUnichars:checkMsg]; - NSWindow* window = GetNSWindowForDOMWindow(parent); - - if (checkValue) { - BOOL valueBool = *checkValue ? YES : NO; - - [controller alertCheck:window title:titleStr text:textStr checkMsg:msgStr checkValue:&valueBool]; - - *checkValue = (valueBool == YES) ? PR_TRUE : PR_FALSE; - } - else { - [controller alert:window title:titleStr text:textStr]; - } - - return NS_OK; -} - -/* boolean confirm (in nsIDOMWindow parent, in wstring dialogTitle, in wstring text); */ -NS_IMETHODIMP -CocoaPromptService::Confirm(nsIDOMWindow *parent, - const PRUnichar *dialogTitle, - const PRUnichar *text, - PRBool *_retval) -{ - nsAlertController* controller = nsCocoaBrowserService::GetAlertController(); - if (!controller) { - return NS_ERROR_FAILURE; - } - - NSString* titleStr = [NSString stringWithPRUnichars:dialogTitle]; - NSString* textStr = [NSString stringWithPRUnichars:text]; - NSWindow* window = GetNSWindowForDOMWindow(parent); - - *_retval = (PRBool)[controller confirm:window title:titleStr text:textStr]; - - return NS_OK; -} - -/* boolean confirmCheck (in nsIDOMWindow parent, in wstring dialogTitle, in wstring text, in wstring checkMsg, inout boolean checkValue); */ -NS_IMETHODIMP -CocoaPromptService::ConfirmCheck(nsIDOMWindow *parent, - const PRUnichar *dialogTitle, - const PRUnichar *text, - const PRUnichar *checkMsg, - PRBool *checkValue, PRBool *_retval) -{ - nsAlertController* controller = nsCocoaBrowserService::GetAlertController(); - if (!controller) { - return NS_ERROR_FAILURE; - } - - NSString* titleStr = [NSString stringWithPRUnichars:dialogTitle]; - NSString* textStr = [NSString stringWithPRUnichars:text]; - NSString* msgStr = [NSString stringWithPRUnichars:checkMsg]; - NSWindow* window = GetNSWindowForDOMWindow(parent); - - if (checkValue) { - BOOL valueBool = *checkValue ? YES : NO; - - *_retval = (PRBool)[controller confirmCheck:window title:titleStr text:textStr checkMsg:msgStr checkValue:&valueBool]; - - *checkValue = (valueBool == YES) ? PR_TRUE : PR_FALSE; - } - else { - *_retval = (PRBool)[controller confirm:window title:titleStr text:textStr]; - } - - return NS_OK; -} - -// these constants are used for identifying the buttons and are intentionally overloaded to -// correspond to the number of bits needed for shifting to obtain the flags for a particular -// button (should be defined in nsIPrompt*.idl instead of here) -const PRUint32 kButton0 = 0; -const PRUint32 kButton1 = 8; -const PRUint32 kButton2 = 16; - -/* void confirmEx (in nsIDOMWindow parent, in wstring dialogTitle, in wstring text, in unsigned long buttonFlags, in wstring button0Title, in wstring button1Title, in wstring button2Title, in wstring checkMsg, inout boolean checkValue, out PRInt32 buttonPressed); */ -NS_IMETHODIMP -CocoaPromptService::ConfirmEx(nsIDOMWindow *parent, - const PRUnichar *dialogTitle, - const PRUnichar *text, - PRUint32 buttonFlags, - const PRUnichar *button0Title, - const PRUnichar *button1Title, - const PRUnichar *button2Title, - const PRUnichar *checkMsg, - PRBool *checkValue, PRInt32 *buttonPressed) -{ - nsAlertController* controller = nsCocoaBrowserService::GetAlertController(); - if (!controller) { - return NS_ERROR_FAILURE; - } - - NSString* titleStr = [NSString stringWithPRUnichars:dialogTitle]; - NSString* textStr = [NSString stringWithPRUnichars:text]; - NSString* msgStr = [NSString stringWithPRUnichars:checkMsg]; - NSWindow* window = GetNSWindowForDOMWindow(parent); - - NSString* btn1Str = GetButtonStringFromFlags(buttonFlags, kButton0, button0Title); - NSString* btn2Str = GetButtonStringFromFlags(buttonFlags, kButton1, button1Title); - NSString* btn3Str = GetButtonStringFromFlags(buttonFlags, kButton2, button2Title); - - if (checkValue) { - BOOL valueBool = *checkValue ? YES : NO; - - *buttonPressed = [controller confirmCheckEx:window title:titleStr text:textStr - button1: btn1Str button2: btn2Str button3: btn3Str - checkMsg:msgStr checkValue:&valueBool]; - - *checkValue = (valueBool == YES) ? PR_TRUE : PR_FALSE; - } - else { - *buttonPressed = [controller confirmEx:window title:titleStr text:textStr - button1: btn1Str button2: btn2Str button3: btn3Str]; - } - - return NS_OK; - -} - - -/* boolean prompt (in nsIDOMWindow parent, in wstring dialogTitle, in wstring text, inout wstring value, in wstring checkMsg, inout boolean checkValue); */ -NS_IMETHODIMP -CocoaPromptService::Prompt(nsIDOMWindow *parent, - const PRUnichar *dialogTitle, - const PRUnichar *text, - PRUnichar **value, - const PRUnichar *checkMsg, - PRBool *checkValue, - PRBool *_retval) -{ - nsAlertController* controller = nsCocoaBrowserService::GetAlertController(); - if (!controller) { - return NS_ERROR_FAILURE; - } - - NSString* titleStr = [NSString stringWithPRUnichars:dialogTitle]; - NSString* textStr = [NSString stringWithPRUnichars:text]; - NSString* msgStr = [NSString stringWithPRUnichars:checkMsg]; - - NSMutableString* valueStr = [NSMutableString stringWithPRUnichars:*value]; - - BOOL valueBool; - if (checkValue) { - valueBool = *checkValue ? YES : NO; - } - NSWindow* window = GetNSWindowForDOMWindow(parent); - - *_retval = (PRBool)[controller prompt:window title:titleStr text:textStr promptText:valueStr checkMsg:msgStr checkValue:&valueBool doCheck:(checkValue != nsnull)]; - - if (checkValue) { - *checkValue = (valueBool == YES) ? PR_TRUE : PR_FALSE; - } - PRUint32 length = [valueStr length]; - PRUnichar* retStr = (PRUnichar*)nsMemory::Alloc((length + 1) * sizeof(PRUnichar)); - [valueStr getCharacters:retStr]; - retStr[length] = PRUnichar(0); - *value = retStr; - - return NS_OK; -} - -/* boolean promptUsernameAndPassword (in nsIDOMWindow parent, in wstring dialogTitle, in wstring text, inout wstring username, inout wstring password, in wstring checkMsg, inout boolean checkValue); */ -NS_IMETHODIMP -CocoaPromptService::PromptUsernameAndPassword(nsIDOMWindow *parent, - const PRUnichar *dialogTitle, - const PRUnichar *text, - PRUnichar **username, - PRUnichar **password, - const PRUnichar *checkMsg, - PRBool *checkValue, - PRBool *_retval) -{ - nsAlertController* controller = nsCocoaBrowserService::GetAlertController(); - if (!controller) { - return NS_ERROR_FAILURE; - } - - NSString* titleStr = [NSString stringWithPRUnichars:dialogTitle]; - NSString* textStr = [NSString stringWithPRUnichars:text]; - NSString* msgStr = [NSString stringWithPRUnichars:checkMsg]; - NSMutableString* userNameStr = [NSMutableString stringWithPRUnichars:*username]; - NSMutableString* passwordStr = [NSMutableString stringWithPRUnichars:*password]; - - BOOL valueBool; - if (checkValue) { - valueBool = *checkValue ? YES : NO; - } - NSWindow* window = GetNSWindowForDOMWindow(parent); - - *_retval = (PRBool)[controller promptUserNameAndPassword:window title:titleStr text:textStr userNameText:userNameStr passwordText:passwordStr checkMsg:msgStr checkValue:&valueBool doCheck:(checkValue != nsnull)]; - - if (checkValue) { - *checkValue = (valueBool == YES) ? PR_TRUE : PR_FALSE; - } - - PRUint32 length = [userNameStr length]; - PRUnichar* retStr = (PRUnichar*)nsMemory::Alloc((length + 1) * sizeof(PRUnichar)); - [userNameStr getCharacters:retStr]; - retStr[length] = PRUnichar(0); - *username = retStr; - - length = [passwordStr length]; - retStr = (PRUnichar*)nsMemory::Alloc((length + 1) * sizeof(PRUnichar)); - [passwordStr getCharacters:retStr]; - retStr[length] = PRUnichar(0); - *password = retStr; - - return NS_OK; -} - -/* boolean promptPassword (in nsIDOMWindow parent, in wstring dialogTitle, in wstring text, inout wstring password, in wstring checkMsg, inout boolean checkValue); */ -NS_IMETHODIMP -CocoaPromptService::PromptPassword(nsIDOMWindow *parent, - const PRUnichar *dialogTitle, - const PRUnichar *text, - PRUnichar **password, - const PRUnichar *checkMsg, - PRBool *checkValue, - PRBool *_retval) -{ - nsAlertController* controller = nsCocoaBrowserService::GetAlertController(); - if (!controller) { - return NS_ERROR_FAILURE; - } - - NSString* titleStr = [NSString stringWithPRUnichars:dialogTitle]; - NSString* textStr = [NSString stringWithPRUnichars:text]; - NSString* msgStr = [NSString stringWithPRUnichars:checkMsg]; - NSMutableString* passwordStr = [NSMutableString stringWithPRUnichars:*password]; - - BOOL valueBool; - if (checkValue) { - valueBool = *checkValue ? YES : NO; - } - NSWindow* window = GetNSWindowForDOMWindow(parent); - - *_retval = (PRBool)[controller promptPassword:window title:titleStr text:textStr passwordText:passwordStr checkMsg:msgStr checkValue:&valueBool doCheck:(checkValue != nsnull)]; - - if (checkValue) { - *checkValue = (valueBool == YES) ? PR_TRUE : PR_FALSE; - } - - PRUint32 length = [passwordStr length]; - PRUnichar* retStr = (PRUnichar*)nsMemory::Alloc((length + 1) * sizeof(PRUnichar)); - [passwordStr getCharacters:retStr]; - retStr[length] = PRUnichar(0); - *password = retStr; - - return NS_OK; -} - -/* boolean select (in nsIDOMWindow parent, in wstring dialogTitle, in wstring text, in PRUint32 count, [array, size_is (count)] in wstring selectList, out long outSelection); */ -NS_IMETHODIMP -CocoaPromptService::Select(nsIDOMWindow *parent, - const PRUnichar *dialogTitle, - const PRUnichar *text, - PRUint32 count, - const PRUnichar **selectList, - PRInt32 *outSelection, - PRBool *_retval) -{ -#if DEBUG - NSLog(@"Uh-oh. Select has not been implemented."); -#endif - return NS_ERROR_NOT_IMPLEMENTED; -} - - -NSWindow* -CocoaPromptService::GetNSWindowForDOMWindow(nsIDOMWindow* window) -{ - nsCOMPtr watcher(do_GetService("@mozilla.org/embedcomp/window-watcher;1")); - if (!watcher) { - return nsnull; - } - - nsCOMPtr chrome; - watcher->GetChromeForWindow(window, getter_AddRefs(chrome)); - if (!chrome) { - return nsnull; - } - - nsCOMPtr siteWindow(do_QueryInterface(chrome)); - if (!siteWindow) { - return nsnull; - } - - NSWindow* nswin; - nsresult rv = siteWindow->GetSiteWindow((void**)&nswin); - if (NS_FAILED(rv)) - return nsnull; - - return nswin; -} - -NSString * -CocoaPromptService::GetCommonDialogLocaleString(const char *key) -{ - NSString *returnValue = @""; - - nsresult rv; - if (!mCommonDialogStringBundle) { -#define kCommonDialogsStrings "chrome://global/locale/commonDialogs.properties" - nsCOMPtr service = do_GetService(NS_STRINGBUNDLE_CONTRACTID); - if ( service ) - rv = service->CreateBundle(kCommonDialogsStrings, getter_AddRefs(mCommonDialogStringBundle)); - else - rv = NS_ERROR_FAILURE; - if (NS_FAILED(rv)) return returnValue; - } - - nsXPIDLString string; - rv = mCommonDialogStringBundle->GetStringFromName(NS_ConvertASCIItoUCS2(key).get(), getter_Copies(string)); - if (NS_FAILED(rv)) return returnValue; - - returnValue = [NSString stringWithPRUnichars:string]; - return returnValue; -} - -NSString * -CocoaPromptService::GetButtonStringFromFlags(PRUint32 btnFlags, - PRUint32 btnIDAndShift, - const PRUnichar *btnTitle) -{ - NSString *btnStr = nsnull; - switch ((btnFlags >> btnIDAndShift) & 0xff) { - case BUTTON_TITLE_OK: - btnStr = GetCommonDialogLocaleString("OK"); - break; - case BUTTON_TITLE_CANCEL: - btnStr = GetCommonDialogLocaleString("Cancel"); - break; - case BUTTON_TITLE_YES: - btnStr = GetCommonDialogLocaleString("Yes"); - break; - case BUTTON_TITLE_NO: - btnStr = GetCommonDialogLocaleString("No"); - break; - case BUTTON_TITLE_SAVE: - btnStr = GetCommonDialogLocaleString("Save"); - break; - case BUTTON_TITLE_DONT_SAVE: - btnStr = GetCommonDialogLocaleString("DontSave"); - break; - case BUTTON_TITLE_REVERT: - btnStr = GetCommonDialogLocaleString("Revert"); - break; - case BUTTON_TITLE_IS_STRING: - btnStr = [NSString stringWithPRUnichars:btnTitle]; - } - - return btnStr; -} diff --git a/mozilla/chimera/ContentClickListener.h b/mozilla/chimera/ContentClickListener.h deleted file mode 100644 index e7ca6ffa54b..00000000000 --- a/mozilla/chimera/ContentClickListener.h +++ /dev/null @@ -1,69 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape 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/NPL/ - * - * 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 mozilla.org 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 NPL, 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 NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef __ContentClickListener_h__ -#define __ContentClickListener_h__ - -#include -#include - -#include "nsIDOMMouseListener.h" -#import "BrowserWindowController.h" - -class ContentClickListener : public nsIDOMMouseListener -{ -public: - ContentClickListener(id aBrowserController); - virtual ~ContentClickListener(); - - NS_DECL_ISUPPORTS - - // The DOM mouse listener interface. We only care about clicks. - NS_IMETHOD HandleEvent(nsIDOMEvent* aEvent) { return NS_OK; }; - NS_IMETHOD MouseDown(nsIDOMEvent* aMouseEvent); - NS_IMETHOD MouseUp(nsIDOMEvent* aMouseEvent) { return NS_OK; }; - NS_IMETHOD MouseClick(nsIDOMEvent* aMouseEvent); - NS_IMETHOD MouseDblClick(nsIDOMEvent* aMouseEvent) { return NS_OK; }; - NS_IMETHOD MouseOver(nsIDOMEvent* aMouseEvent) { return NS_OK; }; - NS_IMETHOD MouseOut(nsIDOMEvent* aMouseEvent) { return NS_OK; }; - -private: - BrowserWindowController* mBrowserController; // Our browser controller (weakly held) -}; - - -#endif diff --git a/mozilla/chimera/ContentClickListener.mm b/mozilla/chimera/ContentClickListener.mm deleted file mode 100644 index 3e9d997e30c..00000000000 --- a/mozilla/chimera/ContentClickListener.mm +++ /dev/null @@ -1,311 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape 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/NPL/ - * - * 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 mozilla.org 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): - * David Hyatt (Original Author) - * - * 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 NPL, 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 NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#import "NSString+Utils.h" - -#include "nsCOMPtr.h" -#include "ContentClickListener.h" -#include "nsIDOMEventTarget.h" -#include "nsIContent.h" -#include "nsIAtom.h" -#include "nsIDOMElement.h" -#include "nsString.h" -#include "nsUnicharUtils.h" -#include "nsIPrefBranch.h" -#include "nsIDOMMouseEvent.h" -#include "nsEmbedAPI.h" -#include "nsIDOMDocument.h" -#include "nsIDOMDocumentEvent.h" -#include "nsIDOMEventTarget.h" -#include "nsIDOMNSHTMLElement.h" -#include "nsIDOMHTMLSelectElement.h" -#include "nsIDOMHTMLOptionElement.h" -#include "nsIDOMHTMLCollection.h" -#include "nsIDOMWindow.h" -#include "nsIScriptGlobalObject.h" -#include "nsIDocument.h" -#include "nsIPresShell.h" -#include "nsIPresContext.h" -#include "nsIFrame.h" -#include "nsIView.h" -#include "nsIWidget.h" -#include "nsIURI.h" -#include "nsIProtocolHandler.h" -#include "nsNetUtil.h" - -// Common helper routines (also used by the context menu code) -#include "CHGeckoUtils.h" - -#import "CHBrowserView.h" - -static void FindOptionWithContentID(nsIDOMHTMLSelectElement* aSel, PRUint32 aID, nsIDOMHTMLOptionElement** aResult) -{ - *aResult = nsnull; - nsCOMPtr options; - aSel->GetOptions(getter_AddRefs(options)); - PRUint32 count; - options->GetLength(&count); - for (PRUint32 i = 0; i < count; i++) { - nsCOMPtr node; - options->Item(i, getter_AddRefs(node)); - PRUint32 contentID; - nsCOMPtr content(do_QueryInterface(node)); - content->GetContentID(&contentID); - if (contentID == aID) { - nsCOMPtr option(do_QueryInterface(node)); - *aResult = option; - NS_ADDREF(*aResult); - break; - } - } -} - -@interface CHOptionSelector : NSObject -{ - nsIDOMHTMLSelectElement* mSelectElt; -} - --(id)initWithSelect:(nsIDOMHTMLSelectElement*)aSel; --(IBAction)selectOption:(id)aSender; - -@end - -@implementation CHOptionSelector - --(id)initWithSelect:(nsIDOMHTMLSelectElement*)aSel -{ - if ( (self = [super init]) ) { - mSelectElt = aSel; - } - return self; -} - --(IBAction)selectOption:(id)aSender -{ - int tag = [aSender tag]; - nsCOMPtr optionElt; - FindOptionWithContentID(mSelectElt, tag, getter_AddRefs(optionElt)); - optionElt->SetSelected(PR_TRUE); - [self autorelease]; // Free up ourselves. - [[aSender menu] autorelease]; // Free up the menu. - - // Fire a DOM event for the title change. - nsCOMPtr event; - nsCOMPtr domDocument; - mSelectElt->GetOwnerDocument(getter_AddRefs(domDocument)); - nsCOMPtr docEvent(do_QueryInterface(domDocument)); - - docEvent->CreateEvent(NS_LITERAL_STRING("Events"), getter_AddRefs(event)); - if (event) { - event->InitEvent(NS_LITERAL_STRING("change"), PR_TRUE, PR_TRUE); - PRBool noDefault; - nsCOMPtr target(do_QueryInterface(mSelectElt)); - target->DispatchEvent(event, &noDefault); - } -} - -@end - -NS_IMPL_ISUPPORTS2(ContentClickListener, nsIDOMMouseListener, nsIDOMEventListener); - -ContentClickListener::ContentClickListener(id aBrowserController) -:mBrowserController(aBrowserController) -{ - NS_INIT_ISUPPORTS(); -} - -ContentClickListener::~ContentClickListener() -{ - -} - -NS_IMETHODIMP -ContentClickListener::MouseDown(nsIDOMEvent* aEvent) -{ - nsCOMPtr target; - aEvent->GetTarget(getter_AddRefs(target)); - if (!target) - return NS_OK; - nsCOMPtr sel(do_QueryInterface(target)); - if (sel) { - NSMenu* menu = [[NSMenu alloc] init]; // Retain the menu. - nsCOMPtr options; - sel->GetOptions(getter_AddRefs(options)); - PRUint32 count; - options->GetLength(&count); - PRInt32 selIndex = 0; - for (PRUint32 i = 0; i < count; i++) { - nsCOMPtr node; - options->Item(i, getter_AddRefs(node)); - PRUint32 contentID; - nsCOMPtr content(do_QueryInterface(node)); - content->GetContentID(&contentID); - nsCOMPtr option(do_QueryInterface(node)); - nsAutoString text; - option->GetLabel(text); - if (text.IsEmpty()) - option->GetText(text); - NSString* title = [[NSString stringWith_nsAString: text] stringByTruncatingTo:75 at:kTruncateAtMiddle]; - NSMenuItem* menuItem = [[[NSMenuItem alloc] initWithTitle: title action: NULL keyEquivalent: @""] autorelease]; - [menu addItem: menuItem]; - [menuItem setTag: contentID]; - PRBool selected; - option->GetSelected(&selected); - if (selected) { - [menuItem setState: NSOnState]; - selIndex = i; - } - CHOptionSelector* optSelector = [[CHOptionSelector alloc] initWithSelect: sel]; - [menuItem setTarget: optSelector]; - [menuItem setAction: @selector(selectOption:)]; - } - - nsCOMPtr nsSel(do_QueryInterface(sel)); - PRInt32 left, top, height; - PRInt32 clientX, clientY; - nsSel->GetOffsetLeft(&left); - nsSel->GetOffsetTop(&top); - nsSel->GetOffsetHeight(&height); - - nsCOMPtr currOffsetParent; - nsSel->GetOffsetParent(getter_AddRefs(currOffsetParent)); - while (currOffsetParent) { - nsCOMPtr currNS(do_QueryInterface(currOffsetParent)); - PRInt32 currLeft, currTop; - currNS->GetOffsetLeft(&currLeft); - currNS->GetOffsetTop(&currTop); - left += currLeft; - top += currTop; - currNS->GetOffsetParent(getter_AddRefs(currOffsetParent)); - } - - nsCOMPtr msEvent(do_QueryInterface(aEvent)); - msEvent->GetClientX(&clientX); - msEvent->GetClientY(&clientY); - - PRInt32 xDelta = clientX - left; - PRInt32 yDelta = top + height - clientY; - - nsCOMPtr window = getter_AddRefs([[[mBrowserController getBrowserWrapper] getBrowserView] getContentWindow]); - PRInt32 scrollX, scrollY; - window->GetScrollX(&scrollX); - window->GetScrollY(&scrollY); - xDelta += scrollX; // Normal direction. - yDelta -= scrollY; // Remember, y is flipped. - -#define XMENUOFFSET 20 -#define MENUHEIGHT 20 - - xDelta += XMENUOFFSET; - yDelta -= MENUHEIGHT*(selIndex+1); - - NSEvent* event = [NSApp currentEvent]; - NSPoint point = [event locationInWindow]; - point.x -= xDelta; - point.y -= yDelta; - - NSEvent* mouseEvent = [NSEvent mouseEventWithType: NSLeftMouseDown location: point - modifierFlags: 0 timestamp: [event timestamp] - windowNumber: [event windowNumber] context: [event context] - eventNumber: [event eventNumber] clickCount: [event clickCount] pressure: [event pressure]]; - - [NSMenu popUpContextMenu: menu withEvent: mouseEvent forView: [[mBrowserController window] contentView]]; - - } - return NS_OK; -} - -NS_IMETHODIMP -ContentClickListener::MouseClick(nsIDOMEvent* aEvent) -{ - nsCOMPtr target; - aEvent->GetTarget(getter_AddRefs(target)); - if (!target) - return NS_OK; - nsCOMPtr content(do_QueryInterface(target)); - - nsCOMPtr linkContent; - nsAutoString href; - CHGeckoUtils::GetEnclosingLinkElementAndHref(content, getter_AddRefs(linkContent), href); - - // XXXdwh Handle simple XLINKs if we want to be compatible with Mozilla, but who - // really uses these anyway? :) - if (!linkContent || href.IsEmpty()) - return NS_OK; - - nsCOMPtr pref(do_GetService("@mozilla.org/preferences-service;1")); - if (!pref) - return NS_OK; // Something bad happened if we can't get prefs. - - PRUint16 button; - nsCOMPtr mouseEvent(do_QueryInterface(aEvent)); - mouseEvent->GetButton(&button); - - PRBool metaKey, shiftKey, altKey; - mouseEvent->GetMetaKey(&metaKey); - mouseEvent->GetShiftKey(&shiftKey); - mouseEvent->GetAltKey(&altKey); - - NSString* hrefStr = [NSString stringWith_nsAString: href]; - - if ((metaKey && button == 0) || button == 1) { - // The command key is down or we got a middle click. Open the link in a new window or tab. - PRBool useTab; - pref->GetBoolPref("browser.tabs.opentabfor.middleclick", &useTab); - PRBool loadInBackground; - pref->GetBoolPref("browser.tabs.loadInBackground", &loadInBackground); - NSString* referrer = [[[mBrowserController getBrowserWrapper] getBrowserView] getFocusedURLString]; - - if (shiftKey) - loadInBackground = !loadInBackground; - if (useTab && [mBrowserController newTabsAllowed]) - [mBrowserController openNewTabWithURL: hrefStr referrer:referrer loadInBackground: loadInBackground]; - else - [mBrowserController openNewWindowWithURL: hrefStr referrer:referrer loadInBackground: loadInBackground]; - } - else if (altKey) { - // The user wants to save this link. - nsAutoString text; - CHGeckoUtils::GatherTextUnder(content, text); - - [mBrowserController saveURL: nil filterList: nil - url: hrefStr suggestedFilename: [NSString stringWith_nsAString: text]]; - } - - return NS_OK; -} diff --git a/mozilla/chimera/Credits.rtf b/mozilla/chimera/Credits.rtf deleted file mode 100644 index ca73f055b1e..00000000000 --- a/mozilla/chimera/Credits.rtf +++ /dev/null @@ -1,74 +0,0 @@ -{\rtf1\mac\ansicpg10000\cocoartf100 -{\fonttbl\f0\fswiss\fcharset77 Optima-BoldItalic;\f1\fswiss\fcharset77 Optima-Italic;\f2\fswiss\fcharset77 Optima-Regular; -\f3\fswiss\fcharset77 Optima-Bold;} -{\colortbl;\red255\green255\blue255;} -\pard\tx1440\tx2880\tx4320\tx5760\tx7200\ql\qnatural - -\f0\i\b\fs18 \cf0 \ - -\fs68 Navigator 0.4.0\ - -\f1\b0\fs24 \ -\ -\ -\ -\ -\ -\ -\ - -\f2\i0 Navigator version 0.4.0\ -http://www.mozilla.org\ -http://chimera.mozdev.org\ - -\fs48 \ - \ - \ - \ -\ - -\f0\i\b\fs28 Contributors:\ - -\f2\i0\b0\fs24 \ - -\f3\b Patrick Beard\ - Kathy Brade\ - Conrad Carlen\ - Ugo Dantas De Santana\ - Simon Fraser\ - Ben Goodger\ - David Haas\ - Joe Hewitt\ - Max Horn -\f2\b0 \ - -\f3\b David Hyatt -\f2\b0 \ - -\f3\b Matt Judy\ - Mike Pinkerton\ - Brian Ryner\ - Richard Schreyer\ - William Dell Wisner\ -\ - Mozilla Contributors:\ - Type \'d2about:credits\'d3 in the Location bar.\ - -\f2\b0 \ -\ -\ -\ - -\fs48 \ - -\f0\i\b\fs28 Special Thanks:\ - -\f2\i0\b0\fs24 \ - -\f3\b Apple Computer Software Engineering\ - The Chimera Mailing List\ - -\f1\i\b0\fs36 \ -\ -\ -} \ No newline at end of file diff --git a/mozilla/chimera/DownloadFactories.h b/mozilla/chimera/DownloadFactories.h deleted file mode 100644 index 35b5ed5ee8d..00000000000 --- a/mozilla/chimera/DownloadFactories.h +++ /dev/null @@ -1,47 +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): - * Simon Fraser - * - * 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 ***** */ - -#include "nscore.h" - -// embedding app's factories for creating instances of interfaces -// related to downloading. - -class nsIFactory; - -nsresult NewDownloadListenerFactory(nsIFactory* *outFactory); - -//nsresult NewHelperAppLauncherDialogFactory(nsIFactory* *outFactory); diff --git a/mozilla/chimera/DownloadFactories.mm b/mozilla/chimera/DownloadFactories.mm deleted file mode 100644 index e68a8d369a5..00000000000 --- a/mozilla/chimera/DownloadFactories.mm +++ /dev/null @@ -1,120 +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): - * Simon Fraser - * - * 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 ***** */ - -// This file contains implementations of factories for various -// downloading-related interfaces. - -#import "DownloadProgressDisplay.h" -#import "ProgressDlgController.h" - -#include "nsCOMPtr.h" -#include "nsIFactory.h" - -#include "nsDownloadListener.h" -#include "DownloadFactories.h" - -// factory for nsIDownload objects -// XXX replace with generic factory stuff -class DownloadListenerFactory : public nsIFactory -{ -public: - DownloadListenerFactory(); - virtual ~DownloadListenerFactory(); - - NS_DECL_ISUPPORTS - NS_DECL_NSIFACTORY - -protected: - - DownloadControllerFactory* mControllerFactory; // factory which creates the Cocoa window controller -}; - - -DownloadListenerFactory::DownloadListenerFactory() -: mControllerFactory(nil) -{ - NS_INIT_ISUPPORTS(); - mControllerFactory = [[ChimeraDownloadControllerFactory alloc] init]; -} - -DownloadListenerFactory::~DownloadListenerFactory() -{ - [mControllerFactory release]; -} - -NS_IMPL_ISUPPORTS1(DownloadListenerFactory, nsIFactory); - -/* void createInstance (in nsISupports aOuter, in nsIIDRef iid, [iid_is (iid), retval] out nsQIResult result); */ -NS_IMETHODIMP -DownloadListenerFactory::CreateInstance(nsISupports *aOuter, const nsIID& aIID, void* *aResult) -{ - nsresult rv; - - if (aIID.Equals(NS_GET_IID(nsIDownload))) - { - nsDownloadListener* downloadListener = new nsDownloadListener(mControllerFactory); - if (!downloadListener) return NS_ERROR_OUT_OF_MEMORY; - - NS_ADDREF(downloadListener); - rv = downloadListener->QueryInterface(aIID, aResult); - NS_RELEASE(downloadListener); - return rv; - } - - return NS_ERROR_NO_INTERFACE; -} - -/* void lockFactory (in PRBool lock); */ -NS_IMETHODIMP -DownloadListenerFactory::LockFactory(PRBool lock) -{ - return NS_OK; -} - -#pragma mark - - -nsresult NewDownloadListenerFactory(nsIFactory* *outFactory) -{ - DownloadListenerFactory* newFactory = new DownloadListenerFactory(); - if (!newFactory) return NS_ERROR_OUT_OF_MEMORY; - - NS_ADDREF(newFactory); - nsresult rv = newFactory->QueryInterface(NS_GET_IID(nsIFactory), (void **)outFactory); - NS_RELEASE(newFactory); - return rv; -} - diff --git a/mozilla/chimera/DownloadProgressDisplay.h b/mozilla/chimera/DownloadProgressDisplay.h deleted file mode 100644 index fc1fe6ce074..00000000000 --- a/mozilla/chimera/DownloadProgressDisplay.h +++ /dev/null @@ -1,167 +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): - * Simon Fraser - * - * 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 ***** */ - -/* - The classes and protocol in this file allow Cocoa applications to easily - reuse the underlying download implementation, which deals with the complexity - of Gecko's downloading callbacks. - - There are three things here: - - 1. The DownloadProgressDisplay protocol. - - This is a formal protocol that needs to be implemented by - a window controller for your progress window. Its methods - will be called by the underlying C++ downloading classes. - - 2. The Obj-C DownloadControllerFactory class. - - This class should be subclassed by an embedder, with an - implementation of 'createDownloadController' that hands back - a new instance of an NSWindowController that implements the - protocol. - - The underlying C++ classes use this factory to create the - progress window controller. - - 3. The CHDownloader C++ class - - This base class exists to hide the complextity of the download - listener classes (which deal with Gecko callbacks) from the - window controller. Embedders don't need to do anything with it. - - How these classes fit together: - - There are 2 ways in which a download is initiated: - - (i) File->Save. - - Chimera does a complex dance here in order to get certain - information about the data being downloaded (it needs to - start the download before it can read some optional MIME headers). - - CBrowserView creates an nsIWebBrowserPersist (WBP), and then a - nsHeaderSniffer, which implements nsIWebProgressListener and is set to - observer the WBP. When nsHeaderSniffer hears about the start of the - download, it decides on a file name, and what format to save the data - in. It then cancels the current WPB, makes another one, and does - a CreateInstance of an nsIDownload (making one of our nsDownloadListener - -- aka nsDownloder -- objects), and sets that as the nsIWebProgressListener. - The full download procedes from there. - - (ii) Click to download (e.g. FTP link) - - This is simpler. The backend (necko) does the CreateInstance of the - nsIDownload, and the download progresses. - - In both cases, creating the nsDownloadListener and calling its Init() method - calls nsDownloder::CreateDownloadDisplay(). The nsDownloder has as a member - variable a DownloadControllerFactory (see above), which got passed to it - via our XPCOM factory for nsIDownload objects. It then uses that DownloadControllerFactory - to get an instance of the download progress window controller, which then - shows the download progress window. - - Simple, eh? - -*/ - -#import - -#include "nsISupports.h" - -class CHDownloader; - -// a formal protocol for something that implements progress display -// Embedders can make a window controller that conforms to this -// protocol, and reuse nsDownloadListener to get download UI. -@protocol DownloadProgressDisplay - -- (void)onStartDownload:(BOOL)isFileSave; -- (void)onEndDownload; - -- (void)setProgressTo:(long)aCurProgress ofMax:(long)aMaxProgress; - -- (void)setDownloadListener:(CHDownloader*)aDownloader; -- (void)setSourceURL:(NSString*)aSourceURL; -- (void)setDestinationPath:(NSString*)aDestPath; - -@end - -// subclass this, and have your subclass instantiate and return your window -// controller in createDownloadController -@interface DownloadControllerFactory : NSObject -{ -} - -- (NSWindowController *)createDownloadController; - -@end - - -// Pure virtual base class for a generic downloader, that the progress UI can talk to. -// It implements nsISupports so that it can be refcounted. This class insulates the -// UI code from having to know too much about the nsIDownloadListener. -// It is responsible for creating the download UI, via the DownloadControllerFactory -// that it owns. -class CHDownloader : public nsISupports -{ -public: - CHDownloader(DownloadControllerFactory* inControllerFactory); - virtual ~CHDownloader(); - - NS_DECL_ISUPPORTS - - virtual void PauseDownload() = 0; - virtual void ResumeDownload() = 0; - virtual void CancelDownload() = 0; - virtual void DownloadDone() = 0; - virtual void DetachDownloadDisplay() = 0; // tell downloader to forget about its display - - virtual void CreateDownloadDisplay(); - -protected: - - PRBool IsFileSave() { return mIsFileSave; } - void SetIsFileSave(PRBool inIsFileSave) { mIsFileSave = inIsFileSave; } - -protected: - - DownloadControllerFactory* mControllerFactory; - id mDownloadDisplay; // something that implements the DownloadProgressDisplay protocol - PRBool mIsFileSave; // true if we're doing a save, rather than a download -}; - diff --git a/mozilla/chimera/DownloadProgressDisplay.mm b/mozilla/chimera/DownloadProgressDisplay.mm deleted file mode 100644 index 4dac500c85b..00000000000 --- a/mozilla/chimera/DownloadProgressDisplay.mm +++ /dev/null @@ -1,76 +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): - * Simon Fraser - * - * 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 "DownloadProgressDisplay.h" - - -@implementation DownloadControllerFactory - -- (NSWindowController *)createDownloadController -{ - // a dummy implementation. You should provide a subclass that - // returns an instance of your progress dialog controller. - return nil; -} - -@end - -#pragma mark - - -// see the header file for comments -CHDownloader::CHDownloader(DownloadControllerFactory* inControllerFactory) -: mControllerFactory(inControllerFactory) -, mDownloadDisplay(nil) -, mIsFileSave(PR_FALSE) -{ - NS_INIT_ISUPPORTS(); - [mControllerFactory retain]; -} - -CHDownloader::~CHDownloader() -{ - [mControllerFactory release]; -} - -NS_IMPL_ISUPPORTS1(CHDownloader, nsISupports); - -void -CHDownloader::CreateDownloadDisplay() -{ - mDownloadDisplay = [mControllerFactory createDownloadController]; - [mDownloadDisplay setDownloadListener:this]; -} diff --git a/mozilla/chimera/English.lproj/AboutBox.nib/classes.nib b/mozilla/chimera/English.lproj/AboutBox.nib/classes.nib deleted file mode 100644 index e9180430bcc..00000000000 --- a/mozilla/chimera/English.lproj/AboutBox.nib/classes.nib +++ /dev/null @@ -1,17 +0,0 @@ -{ - IBClasses = ( - { - ACTIONS = {showPanel = id; }; - CLASS = AboutBox; - LANGUAGE = ObjC; - OUTLETS = { - buildNumberField = NSTextField; - creditsField = NSTextView; - window = NSWindow; - }; - SUPERCLASS = NSObject; - }, - {CLASS = FirstResponder; LANGUAGE = ObjC; SUPERCLASS = NSObject; } - ); - IBVersion = 1; -} \ No newline at end of file diff --git a/mozilla/chimera/English.lproj/AboutBox.nib/info.nib b/mozilla/chimera/English.lproj/AboutBox.nib/info.nib deleted file mode 100644 index 4df25655e54..00000000000 --- a/mozilla/chimera/English.lproj/AboutBox.nib/info.nib +++ /dev/null @@ -1,18 +0,0 @@ - - - - - IBFramework Version - 248.0 - IBLockedObjects - - 7 - - IBOpenObjects - - 5 - - IBSystem Version - 5S66 - - diff --git a/mozilla/chimera/English.lproj/AboutBox.nib/objects.nib b/mozilla/chimera/English.lproj/AboutBox.nib/objects.nib deleted file mode 100644 index 8c1c2d1f930..00000000000 Binary files a/mozilla/chimera/English.lproj/AboutBox.nib/objects.nib and /dev/null differ diff --git a/mozilla/chimera/English.lproj/BookmarkInfoPanel.nib/classes.nib b/mozilla/chimera/English.lproj/BookmarkInfoPanel.nib/classes.nib deleted file mode 100644 index 7cb6777f984..00000000000 --- a/mozilla/chimera/English.lproj/BookmarkInfoPanel.nib/classes.nib +++ /dev/null @@ -1,22 +0,0 @@ -{ - IBClasses = ( - { - CLASS = BookmarkInfoController; - LANGUAGE = ObjC; - OUTLETS = { - mDescriptionField = NSTextField; - mDescriptionLabel = NSTextField; - mKeywordField = NSTextField; - mKeywordLabel = NSTextField; - mLocationField = NSTextField; - mLocationLabel = NSTextField; - mNameField = NSTextField; - mNameLabel = NSTextField; - }; - SUPERCLASS = NSWindowController; - }, - {CLASS = BookmarkItem; LANGUAGE = ObjC; SUPERCLASS = NSObject; }, - {CLASS = FirstResponder; LANGUAGE = ObjC; SUPERCLASS = NSObject; } - ); - IBVersion = 1; -} \ No newline at end of file diff --git a/mozilla/chimera/English.lproj/BookmarkInfoPanel.nib/info.nib b/mozilla/chimera/English.lproj/BookmarkInfoPanel.nib/info.nib deleted file mode 100644 index b8cd244ab7f..00000000000 --- a/mozilla/chimera/English.lproj/BookmarkInfoPanel.nib/info.nib +++ /dev/null @@ -1,12 +0,0 @@ - - - - - IBDocumentLocation - 144 74 366 258 0 0 1280 1002 - IBFramework Version - 248.0 - IBSystem Version - 5S66 - - diff --git a/mozilla/chimera/English.lproj/BookmarkInfoPanel.nib/objects.nib b/mozilla/chimera/English.lproj/BookmarkInfoPanel.nib/objects.nib deleted file mode 100644 index 5541b6caeaa..00000000000 Binary files a/mozilla/chimera/English.lproj/BookmarkInfoPanel.nib/objects.nib and /dev/null differ diff --git a/mozilla/chimera/English.lproj/BrowserWindow.nib/classes.nib b/mozilla/chimera/English.lproj/BrowserWindow.nib/classes.nib deleted file mode 100644 index 9d9409b58ee..00000000000 --- a/mozilla/chimera/English.lproj/BrowserWindow.nib/classes.nib +++ /dev/null @@ -1,141 +0,0 @@ -{ - IBClasses = ( - {CLASS = AutoCompleteDataSource; LANGUAGE = ObjC; SUPERCLASS = NSObject; }, - { - ACTIONS = {onBlur = id; onResize = id; }; - CLASS = AutoCompleteTextField; - LANGUAGE = ObjC; - OUTLETS = {mProxyIcon = PageProxyIcon; }; - SUPERCLASS = NSTextField; - }, - {CLASS = BookmarkItem; LANGUAGE = ObjC; SUPERCLASS = NSObject; }, - { - ACTIONS = { - addBookmark = id; - addFolder = id; - deleteBookmarks = id; - openBookmarkInNewTab = id; - openBookmarkInNewWindow = id; - showBookmarkInfo = id; - }; - CLASS = BookmarksDataSource; - LANGUAGE = ObjC; - OUTLETS = { - mBrowserWindowController = id; - mDeleteBookmarkButton = id; - mEditBookmarkButton = id; - mOutlineView = id; - }; - SUPERCLASS = NSObject; - }, - { - CLASS = BookmarksOutlineView; - LANGUAGE = ObjC; - SUPERCLASS = ExtendedOutlineView; - }, - {CLASS = BookmarksToolbar; LANGUAGE = ObjC; SUPERCLASS = NSView; }, - {CLASS = BrowserTabView; LANGUAGE = ObjC; SUPERCLASS = NSTabView; }, - { - CLASS = BrowserWindow; - LANGUAGE = ObjC; - OUTLETS = {mAutoCompleteTextField = id; }; - SUPERCLASS = NSWindow; - }, - { - ACTIONS = { - back = id; - bookmarkLink = id; - bookmarkPage = id; - cancelAddBookmarkSheet = id; - cancelLocationSheet = id; - copyLinkLocation = id; - endAddBookmarkSheet = id; - endLocationSheet = id; - forward = id; - goToLocationFromToolbarURLField = id; - home = id; - manageBookmarks = id; - openLinkInNewTab = id; - openLinkInNewWindow = id; - performSearch = id; - printDocument = id; - reload = id; - saveImageAs = id; - saveLinkAs = id; - savePageAs = id; - stop = id; - toggleSidebar = id; - viewOnlyThisImage = id; - viewSource = id; - }; - CLASS = BrowserWindowController; - LANGUAGE = ObjC; - OUTLETS = { - mAddBookmarkCheckbox = NSButton; - mAddBookmarkFolderField = NSPopUpButton; - mAddBookmarkSheetWindow = NSWindow; - mAddBookmarkTitleField = NSTextField; - mBackItem = NSMenuItem; - mCachedBMDS = id; - mForwardItem = NSMenuItem; - mHistoryDataSource = HistoryDataSource; - mImageLinkMenu = NSMenu; - mImageMenu = NSMenu; - mInputMenu = NSMenu; - mLinkMenu = NSMenu; - mLocationSheetURLField = NSTextField; - mLocationSheetWindow = NSWindow; - mLocationToolbarView = NSView; - mLock = NSImageView; - mPageMenu = NSMenu; - mPersonalToolbar = BookmarksToolbar; - mProgress = NSProgressIndicator; - mProxyIcon = NSImageView; - mSidebarBookmarksDataSource = BookmarksDataSource; - mSidebarBrowserView = id; - mSidebarDrawer = NSDrawer; - mSidebarSourceTabView = NSTabView; - mSidebarTabView = NSTabView; - mStatus = NSTextField; - mStatusBar = NSView; - mTabBrowser = BrowserTabView; - mURLBar = NSTextField; - }; - SUPERCLASS = NSWindowController; - }, - { - ACTIONS = {load = id; }; - CLASS = BrowserWrapper; - LANGUAGE = ObjC; - OUTLETS = { - mLockIcon = id; - mWindowController = id; - progress = id; - progressSuper = id; - status = id; - urlbar = id; - }; - SUPERCLASS = NSView; - }, - {CLASS = ExtendedOutlineView; LANGUAGE = ObjC; SUPERCLASS = NSOutlineView; }, - {CLASS = FirstResponder; LANGUAGE = ObjC; SUPERCLASS = NSObject; }, - { - CLASS = HistoryDataSource; - LANGUAGE = ObjC; - OUTLETS = {mBrowserWindowController = id; }; - SUPERCLASS = RDFOutlineViewDataSource; - }, - {CLASS = LocationBar; LANGUAGE = ObjC; SUPERCLASS = NSView; }, - {CLASS = MainController; LANGUAGE = ObjC; SUPERCLASS = NSObject; }, - {CLASS = PageProxyIcon; LANGUAGE = ObjC; SUPERCLASS = NSImageView; }, - { - CLASS = RDFOutlineViewDataSource; - LANGUAGE = ObjC; - OUTLETS = {mOutlineView = id; }; - SUPERCLASS = NSObject; - }, - {CLASS = RDFOutlineViewItem; LANGUAGE = ObjC; SUPERCLASS = NSObject; }, - {CLASS = ThrobberHandler; LANGUAGE = ObjC; SUPERCLASS = NSObject; } - ); - IBVersion = 1; -} \ No newline at end of file diff --git a/mozilla/chimera/English.lproj/BrowserWindow.nib/info.nib b/mozilla/chimera/English.lproj/BrowserWindow.nib/info.nib deleted file mode 100644 index 9fccdc6b397..00000000000 --- a/mozilla/chimera/English.lproj/BrowserWindow.nib/info.nib +++ /dev/null @@ -1,45 +0,0 @@ - - - - - IBDocumentLocation - 172 80 630 599 0 0 1280 1002 - IBEditorPositions - - 124 - 345 803 170 144 0 0 1280 1002 - 160 - 165 292 195 666 0 0 1280 1002 - 28 - 524 439 195 457 0 0 1280 1002 - 297 - 233 646 176 162 0 0 1152 848 - 314 - 418 732 139 66 0 0 1152 848 - 336 - 630 666 200 132 0 0 1152 848 - 365 - 22 587 93 162 0 0 1152 848 - 463 - 22 619 200 180 0 0 1152 848 - 56 - 450 634 343 68 0 0 1280 1002 - - IBFramework Version - 248.0 - IBGroupedObjects - - 3 - - 8 - 9 - - - IBLastGroupID - 4 - IBLockedObjects - - IBSystem Version - 5S66 - - diff --git a/mozilla/chimera/English.lproj/BrowserWindow.nib/objects.nib b/mozilla/chimera/English.lproj/BrowserWindow.nib/objects.nib deleted file mode 100644 index bb73395d197..00000000000 Binary files a/mozilla/chimera/English.lproj/BrowserWindow.nib/objects.nib and /dev/null differ diff --git a/mozilla/chimera/English.lproj/FindDialog.nib/classes.nib b/mozilla/chimera/English.lproj/FindDialog.nib/classes.nib deleted file mode 100644 index b0d20da5dca..00000000000 --- a/mozilla/chimera/English.lproj/FindDialog.nib/classes.nib +++ /dev/null @@ -1,19 +0,0 @@ -{ - IBClasses = ( - { - ACTIONS = {find = id; }; - CLASS = FindDlgController; - LANGUAGE = ObjC; - OUTLETS = { - mFindButton = NSButton; - mIgnoreCaseBox = NSButton; - mSearchBackwardsBox = NSButton; - mSearchField = NSTextField; - mWrapAroundBox = NSButton; - }; - SUPERCLASS = NSWindowController; - }, - {CLASS = FirstResponder; LANGUAGE = ObjC; SUPERCLASS = NSObject; } - ); - IBVersion = 1; -} \ No newline at end of file diff --git a/mozilla/chimera/English.lproj/FindDialog.nib/info.nib b/mozilla/chimera/English.lproj/FindDialog.nib/info.nib deleted file mode 100644 index 681cc6970ac..00000000000 --- a/mozilla/chimera/English.lproj/FindDialog.nib/info.nib +++ /dev/null @@ -1,12 +0,0 @@ - - - - - IBDocumentLocation - 180 86 356 240 0 0 1152 746 - IBFramework Version - 248.0 - IBSystem Version - 5S66 - - diff --git a/mozilla/chimera/English.lproj/FindDialog.nib/objects.nib b/mozilla/chimera/English.lproj/FindDialog.nib/objects.nib deleted file mode 100644 index 27568a170bd..00000000000 Binary files a/mozilla/chimera/English.lproj/FindDialog.nib/objects.nib and /dev/null differ diff --git a/mozilla/chimera/English.lproj/InfoPlist.strings b/mozilla/chimera/English.lproj/InfoPlist.strings deleted file mode 100644 index 7b8529dd570..00000000000 Binary files a/mozilla/chimera/English.lproj/InfoPlist.strings and /dev/null differ diff --git a/mozilla/chimera/English.lproj/Localizable.strings b/mozilla/chimera/English.lproj/Localizable.strings deleted file mode 100644 index 259354c14b9..00000000000 Binary files a/mozilla/chimera/English.lproj/Localizable.strings and /dev/null differ diff --git a/mozilla/chimera/English.lproj/MVPreferencePaneGroups.strings b/mozilla/chimera/English.lproj/MVPreferencePaneGroups.strings deleted file mode 100644 index b410cd0bc55..00000000000 Binary files a/mozilla/chimera/English.lproj/MVPreferencePaneGroups.strings and /dev/null differ diff --git a/mozilla/chimera/English.lproj/MVPreferences.nib/classes.nib b/mozilla/chimera/English.lproj/MVPreferences.nib/classes.nib deleted file mode 100644 index aeac16577ff..00000000000 --- a/mozilla/chimera/English.lproj/MVPreferences.nib/classes.nib +++ /dev/null @@ -1,32 +0,0 @@ -{ - IBClasses = ( - {CLASS = FirstResponder; LANGUAGE = ObjC; SUPERCLASS = NSObject; }, - { - ACTIONS = {showAll = id; showPreferences = id; }; - CLASS = MVPreferencesController; - LANGUAGE = ObjC; - OUTLETS = { - groupView = id; - loadingImageView = id; - loadingTextFeld = id; - loadingView = id; - multiView = id; - window = id; - }; - SUPERCLASS = NSObject; - }, - { - CLASS = MVPreferencesGroupedIconView; - LANGUAGE = ObjC; - OUTLETS = {preferencesController = id; }; - SUPERCLASS = NSView; - }, - { - CLASS = MVPreferencesMultipleIconView; - LANGUAGE = ObjC; - OUTLETS = {preferencesController = id; }; - SUPERCLASS = NSView; - } - ); - IBVersion = 1; -} \ No newline at end of file diff --git a/mozilla/chimera/English.lproj/MVPreferences.nib/info.nib b/mozilla/chimera/English.lproj/MVPreferences.nib/info.nib deleted file mode 100644 index fbed564bb10..00000000000 --- a/mozilla/chimera/English.lproj/MVPreferences.nib/info.nib +++ /dev/null @@ -1,16 +0,0 @@ - - - - - IBDocumentLocation - 16 36 356 240 0 0 1024 746 - IBFramework Version - 248.0 - IBOpenObjects - - 7 - - IBSystem Version - 5Q125 - - diff --git a/mozilla/chimera/English.lproj/MVPreferences.nib/objects.nib b/mozilla/chimera/English.lproj/MVPreferences.nib/objects.nib deleted file mode 100644 index 273ab2bf5c6..00000000000 Binary files a/mozilla/chimera/English.lproj/MVPreferences.nib/objects.nib and /dev/null differ diff --git a/mozilla/chimera/English.lproj/MainMenu.nib/classes.nib b/mozilla/chimera/English.lproj/MainMenu.nib/classes.nib deleted file mode 100644 index f4d1aa2760b..00000000000 --- a/mozilla/chimera/English.lproj/MainMenu.nib/classes.nib +++ /dev/null @@ -1,80 +0,0 @@ -{ - IBClasses = ( - { - CLASS = BrowserToolbarController; - LANGUAGE = ObjC; - SUPERCLASS = ToolbarController; - }, - {CLASS = FirstResponder; LANGUAGE = ObjC; SUPERCLASS = NSObject; }, - {CLASS = GoMenu; LANGUAGE = ObjC; SUPERCLASS = NSMenu; }, - { - ACTIONS = { - addBookmark = id; - addFolder = id; - addSeparator = id; - biggerTextSize = id; - closeTab = id; - displayPreferencesWindow = id; - doReload = id; - doSearch = id; - doStop = id; - feedbackLink = id; - findAgain = id; - findInPage = id; - getInfo = id; - goBack = id; - goForward = id; - goHome = id; - importBookmarks = id; - infoLink = id; - manageBookmarks = id; - newTab = id; - newWindow = id; - nextTab = id; - openFile = id; - openLocation = id; - openMenuBookmark = id; - previousTab = id; - printPage = id; - printPreview = id; - savePage = id; - showAboutBox = id; - smallerTextSize = id; - toggleBookmarksToolbar = id; - toggleOfflineMode = id; - toggleSidebar = id; - viewSource = id; - }; - CLASS = MainController; - LANGUAGE = ObjC; - OUTLETS = { - mAddBookmarkMenuItem = NSMenuItem; - mApplication = NSApplication; - mBookmarksMenu = NSMenu; - mBookmarksToolbarMenuItem = NSMenuItem; - mCloseTabMenuItem = NSMenuItem; - mCloseWindowMenuItem = NSMenuItem; - mCreateBookmarksFolderMenuItem = NSMenuItem; - mCreateBookmarksSeparatorMenuItem = NSMenuItem; - mFilterList = NSPopUpButton; - mFilterView = NSView; - mToggleSidebarMenuItem = NSMenuItem; - }; - SUPERCLASS = NSObject; - }, - { - ACTIONS = {load = id; }; - CLASS = MyBrowserView; - LANGUAGE = ObjC; - OUTLETS = {progress = id; progressSuper = id; status = id; urlbar = id; }; - SUPERCLASS = NSView; - }, - { - CLASS = ToolbarController; - LANGUAGE = ObjC; - OUTLETS = {mBrowserView = id; mWindow = id; }; - SUPERCLASS = NSObject; - } - ); - IBVersion = 1; -} \ No newline at end of file diff --git a/mozilla/chimera/English.lproj/MainMenu.nib/info.nib b/mozilla/chimera/English.lproj/MainMenu.nib/info.nib deleted file mode 100644 index 2a0b9c2b3e9..00000000000 --- a/mozilla/chimera/English.lproj/MainMenu.nib/info.nib +++ /dev/null @@ -1,39 +0,0 @@ - - - - - IBDocumentLocation - 108 107 477 485 0 0 1280 1002 - IBEditorPositions - - 266 - 483 623 277 90 0 0 1280 1002 - 29 - 8 957 446 44 0 0 1280 1002 - - IBFramework Version - 248.0 - IBGroupedObjects - - 0 - - 0 - 0 - 0 - - 1 - - 0 - 0 - - - IBLastGroupID - 2 - IBOpenObjects - - 29 - - IBSystem Version - 5S66 - - diff --git a/mozilla/chimera/English.lproj/MainMenu.nib/objects.nib b/mozilla/chimera/English.lproj/MainMenu.nib/objects.nib deleted file mode 100644 index 2ad295b96c9..00000000000 Binary files a/mozilla/chimera/English.lproj/MainMenu.nib/objects.nib and /dev/null differ diff --git a/mozilla/chimera/English.lproj/Navigator.scriptTerminology b/mozilla/chimera/English.lproj/Navigator.scriptTerminology deleted file mode 100644 index fc11ae62e1f..00000000000 --- a/mozilla/chimera/English.lproj/Navigator.scriptTerminology +++ /dev/null @@ -1,27 +0,0 @@ - - - - - Commands - - GetURL - - Description - Load a URL in the frontmost window - Name - Get URL - - OpenURL - - Description - Load a URL in the frontmost window - Name - open url - - - Description - Navigator's scripting suite - Name - Navigator suite - - diff --git a/mozilla/chimera/English.lproj/ProgressDialog.nib/classes.nib b/mozilla/chimera/English.lproj/ProgressDialog.nib/classes.nib deleted file mode 100644 index fc624beb9c0..00000000000 --- a/mozilla/chimera/English.lproj/ProgressDialog.nib/classes.nib +++ /dev/null @@ -1,19 +0,0 @@ -{ - IBClasses = ( - {CLASS = FirstResponder; LANGUAGE = ObjC; SUPERCLASS = NSObject; }, - { - CLASS = ProgressDlgController; - LANGUAGE = ObjC; - OUTLETS = { - mElapsedTimeLabel = NSTextField; - mFromField = NSTextField; - mProgressBar = NSProgressIndicator; - mStatusLabel = NSTextField; - mTimeLeftLabel = NSTextField; - mToField = NSTextField; - }; - SUPERCLASS = NSWindowController; - } - ); - IBVersion = 1; -} \ No newline at end of file diff --git a/mozilla/chimera/English.lproj/ProgressDialog.nib/info.nib b/mozilla/chimera/English.lproj/ProgressDialog.nib/info.nib deleted file mode 100644 index d128c1fddc6..00000000000 --- a/mozilla/chimera/English.lproj/ProgressDialog.nib/info.nib +++ /dev/null @@ -1,12 +0,0 @@ - - - - - IBDocumentLocation - 94 26 404 250 0 0 1152 746 - IBFramework Version - 248.0 - IBSystem Version - 5S66 - - diff --git a/mozilla/chimera/English.lproj/ProgressDialog.nib/objects.nib b/mozilla/chimera/English.lproj/ProgressDialog.nib/objects.nib deleted file mode 100644 index 53a6f68e67e..00000000000 Binary files a/mozilla/chimera/English.lproj/ProgressDialog.nib/objects.nib and /dev/null differ diff --git a/mozilla/chimera/English.lproj/alert.nib/classes.nib b/mozilla/chimera/English.lproj/alert.nib/classes.nib deleted file mode 100644 index 22720161509..00000000000 --- a/mozilla/chimera/English.lproj/alert.nib/classes.nib +++ /dev/null @@ -1,49 +0,0 @@ -{ - IBClasses = ( - {CLASS = FirstResponder; LANGUAGE = ObjC; SUPERCLASS = NSObject; }, - {CLASS = java.lang.Object; LANGUAGE = Java; }, - { - ACTIONS = {hitButton1 = id; hitButton2 = id; hitButton3 = id; }; - CLASS = nsAlertController; - LANGUAGE = ObjC; - OUTLETS = { - alertCheckPanel = id; - alertCheckPanelCheck = id; - alertCheckPanelText = id; - alertPanel = id; - alertPanelText = id; - confirmCheckPanel = id; - confirmCheckPanelButton1 = id; - confirmCheckPanelButton2 = id; - confirmCheckPanelButton3 = id; - confirmCheckPanelCheck = id; - confirmCheckPanelText = id; - confirmPanel = id; - confirmPanelButton1 = id; - confirmPanelButton2 = id; - confirmPanelButton3 = id; - confirmPanelText = id; - expiredCertPanel = id; - owner = id; - passwordPanel = id; - passwordPanelCheck = id; - passwordPanelInput = id; - passwordPanelText = id; - postToInsecureFromSecurePanel = id; - promptPanel = id; - promptPanelCheck = id; - promptPanelInput = id; - promptPanelText = id; - securityMismatchPanel = id; - securityUnknownPanel = id; - usernamePanel = id; - usernamePanelCheck = id; - usernamePanelPassword = id; - usernamePanelText = id; - usernamePanelUserName = id; - }; - SUPERCLASS = NSObject; - } - ); - IBVersion = 1; -} \ No newline at end of file diff --git a/mozilla/chimera/English.lproj/alert.nib/info.nib b/mozilla/chimera/English.lproj/alert.nib/info.nib deleted file mode 100644 index d2e85852ba9..00000000000 --- a/mozilla/chimera/English.lproj/alert.nib/info.nib +++ /dev/null @@ -1,12 +0,0 @@ - - - - - IBDocumentLocation - 285 97 356 301 0 0 1024 746 - IBFramework Version - 248.0 - IBSystem Version - 5S66 - - diff --git a/mozilla/chimera/English.lproj/alert.nib/objects.nib b/mozilla/chimera/English.lproj/alert.nib/objects.nib deleted file mode 100644 index 114a02c288c..00000000000 Binary files a/mozilla/chimera/English.lproj/alert.nib/objects.nib and /dev/null differ diff --git a/mozilla/chimera/FindDialog.nib/classes.nib b/mozilla/chimera/FindDialog.nib/classes.nib deleted file mode 100644 index b0d20da5dca..00000000000 --- a/mozilla/chimera/FindDialog.nib/classes.nib +++ /dev/null @@ -1,19 +0,0 @@ -{ - IBClasses = ( - { - ACTIONS = {find = id; }; - CLASS = FindDlgController; - LANGUAGE = ObjC; - OUTLETS = { - mFindButton = NSButton; - mIgnoreCaseBox = NSButton; - mSearchBackwardsBox = NSButton; - mSearchField = NSTextField; - mWrapAroundBox = NSButton; - }; - SUPERCLASS = NSWindowController; - }, - {CLASS = FirstResponder; LANGUAGE = ObjC; SUPERCLASS = NSObject; } - ); - IBVersion = 1; -} \ No newline at end of file diff --git a/mozilla/chimera/FindDialog.nib/info.nib b/mozilla/chimera/FindDialog.nib/info.nib deleted file mode 100644 index 681cc6970ac..00000000000 --- a/mozilla/chimera/FindDialog.nib/info.nib +++ /dev/null @@ -1,12 +0,0 @@ - - - - - IBDocumentLocation - 180 86 356 240 0 0 1152 746 - IBFramework Version - 248.0 - IBSystem Version - 5S66 - - diff --git a/mozilla/chimera/FindDialog.nib/objects.nib b/mozilla/chimera/FindDialog.nib/objects.nib deleted file mode 100644 index 27568a170bd..00000000000 Binary files a/mozilla/chimera/FindDialog.nib/objects.nib and /dev/null differ diff --git a/mozilla/chimera/FindDlgController.h b/mozilla/chimera/FindDlgController.h deleted file mode 100644 index 7cd551bfb53..00000000000 --- a/mozilla/chimera/FindDlgController.h +++ /dev/null @@ -1,59 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape 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/NPL/ - * - * 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 mozilla.org 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 NPL, 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 NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#import -#include "nsIWebBrowserFind.h" - -@interface FindDlgController : NSWindowController { - IBOutlet NSTextField* mSearchField; - IBOutlet NSButton* mIgnoreCaseBox; - IBOutlet NSButton* mWrapAroundBox; - IBOutlet NSButton* mSearchBackwardsBox; - IBOutlet NSButton* mFindButton; - - NSString* mSearchText; -} - -- (IBAction) find: (id)aSender; -- (IBAction) findAgain: (id)aSender; -- (void) storeSearchText:(NSString*)inText; -- (NSString*)getSearchText; - - // delegates for NSTextView -- (void)controlTextDidChange:(NSNotification *)aNotification; - -@end diff --git a/mozilla/chimera/FindDlgController.mm b/mozilla/chimera/FindDlgController.mm deleted file mode 100644 index 23de3042d6d..00000000000 --- a/mozilla/chimera/FindDlgController.mm +++ /dev/null @@ -1,142 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape 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/NPL/ - * - * 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 mozilla.org 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 NPL, 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 NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#import "FindDlgController.h" -#import "BrowserWindowController.h" -#import "CHFind.h" -#include "nsCOMPtr.h" - - -@implementation FindDlgController - -- (id)initWithWindowNibName:(NSString *)windowNibName -{ - if ( (self = [super initWithWindowNibName:windowNibName]) ) - mSearchText = nil; - return self; -} - -- (void)dealloc -{ - [mSearchText release]; - [super dealloc]; -} - -- (void)windowDidLoad -{ -} - - -// -// -find -// -// User clicked the find button, send the action to the window controller of the -// frontmost browser window. If we found something, hide the window. If not, beep. -// --(IBAction) find: (id)aSender -{ - NSWindowController* controller = [[NSApp mainWindow] windowController]; - if ( [controller conformsToProtocol:@protocol(CHFind)] ) { - id browserController = controller; - BOOL ignoreCase = [mIgnoreCaseBox state]; - BOOL wrapSearch = [mWrapAroundBox state]; - BOOL searchBack = [mSearchBackwardsBox state]; - - [self storeSearchText:[mSearchField stringValue]]; - - BOOL found = [browserController findInPageWithPattern:mSearchText caseSensitive:!ignoreCase - wrap:wrapSearch backwards:searchBack]; - - if (! found ) - NSBeep(); - // we stay open - } - else - NSBeep(); -} - - -// -// -findAgain -// -// Someone hit "find again" in the edit menu, send the action to the window controller of the -// frontmost browser window. Beep if we didn't find something. -// --(IBAction) findAgain: (id)aSender -{ - NSWindowController* controller = [[NSApp mainWindow] windowController]; - if ( [controller conformsToProtocol:@protocol(CHFind)] ) { - id browserController = controller; - BOOL ignoreCase = [mIgnoreCaseBox state]; - BOOL wrapSearch = [mWrapAroundBox state]; - BOOL searchBack = [mSearchBackwardsBox state]; - - BOOL found = [browserController findInPageWithPattern:mSearchText caseSensitive:!ignoreCase - wrap:wrapSearch backwards:searchBack]; - if ( !found ) - NSBeep(); - } - else - NSBeep(); -} - -// -// controlTextDidChange -// -// Check if there is anything in the text field, and if not, disable the find button -// -- (void)controlTextDidChange:(NSNotification *)aNotification -{ - if ( [[mSearchField stringValue] length] ) - [mFindButton setEnabled:PR_TRUE]; - else - [mFindButton setEnabled:PR_FALSE]; -} - -- (void)storeSearchText:(NSString*)inText -{ - [mSearchText autorelease]; - mSearchText = inText; - [mSearchText retain]; -} - -- (NSString*)getSearchText -{ - return mSearchText; -} - -@end diff --git a/mozilla/chimera/MainController.h b/mozilla/chimera/MainController.h deleted file mode 100644 index a88c3abbfae..00000000000 --- a/mozilla/chimera/MainController.h +++ /dev/null @@ -1,158 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape 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/NPL/ - * - * 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 mozilla.org 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 NPL, 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 NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#import -#import "BrowserWindowController.h" -#import "MVPreferencesController.h" -#import "CHSplashScreenWindow.h" -#import "FindDlgController.h" -#import "CHPreferenceManager.h" - -class BookmarksService; - -@interface MainController : NSObject -{ - IBOutlet NSApplication* mApplication; - - // The following two items are used by the filter list when saving files. - IBOutlet NSView* mFilterView; - IBOutlet NSPopUpButton* mFilterList; - - // IBOutlet NSMenuItem* mOfflineMenuItem; - IBOutlet NSMenuItem* mCloseWindowMenuItem; - IBOutlet NSMenuItem* mCloseTabMenuItem; - IBOutlet NSMenuItem* mToggleSidebarMenuItem; - - // The bookmarks menu. - IBOutlet NSMenu* mBookmarksMenu; - - IBOutlet NSMenuItem* mBookmarksToolbarMenuItem; - IBOutlet NSMenuItem* mAddBookmarkMenuItem; - IBOutlet NSMenuItem* mCreateBookmarksFolderMenuItem; - IBOutlet NSMenuItem* mCreateBookmarksSeparatorMenuItem; - - BOOL mOffline; - - CHSplashScreenWindow* mSplashScreen; - - CHPreferenceManager* mPreferenceManager; - - BookmarksService* mMenuBookmarks; - - FindDlgController* mFindDialog; - - MVPreferencesController* mPreferencesController; - - NSString* mStartURL; -} - --(void)dealloc; - -// File menu actions. --(IBAction) newWindow:(id)aSender; --(IBAction) openFile:(id)aSender; --(IBAction) openLocation:(id)aSender; --(IBAction) savePage:(id)aSender; --(IBAction) printPreview:(id)aSender; --(IBAction) printPage:(id)aSender; --(IBAction) toggleOfflineMode:(id)aSender; - -// Edit menu actions. --(IBAction) findInPage:(id)aSender; --(IBAction) findAgain:(id)aSender; --(IBAction) getInfo:(id)aSender; - -// Go menu actions. --(IBAction) goBack:(id)aSender; --(IBAction) goForward:(id)aSender; --(IBAction) goHome:(id)aSender; --(IBAction) doSearch:(id)aSender; --(IBAction) previousTab:(id)aSender; --(IBAction) nextTab:(id)aSender; - -// View menu actions. --(IBAction) toggleSidebar:(id)sender; --(IBAction) toggleBookmarksToolbar:(id)aSender; --(IBAction) doReload:(id)aSender; --(IBAction) doStop:(id)aSender; --(IBAction) biggerTextSize:(id)aSender; --(IBAction) smallerTextSize:(id)aSender; --(IBAction) viewSource:(id)aSender; - -// Bookmarks menu actions. --(IBAction) importBookmarks:(id)aSender; --(IBAction) addBookmark:(id)aSender; --(IBAction) openMenuBookmark:(id)aSender; --(IBAction) manageBookmarks: (id)aSender; --(IBAction) addFolder:(id)aSender; --(IBAction) addSeparator:(id)aSender; - -//Window menu actions --(IBAction) newTab:(id)aSender; --(IBAction) closeTab:(id)aSender; - -//Help menu actions --(IBAction) infoLink:(id)aSender; --(IBAction) feedbackLink:(id)aSender; - --(BrowserWindowController*)openBrowserWindowWithURL: (NSString*)aURL andReferrer: (NSString*)aReferrer; -- (void)openNewWindowOrTabWithURL:(NSString*)inURLString andReferrer:(NSString*)aReferrer; - -- (void)adjustCloseWindowMenuItemKeyEquivalent:(BOOL)inHaveTabs; -- (void)adjustCloseTabMenuItemKeyEquivalent:(BOOL)inHaveTabs; -- (void)fixCloseMenuItemKeyEquivalents; - -- (void)adjustBookmarksMenuItemsEnabling:(BOOL)inBrowserWindowFrontmost; - --(NSWindow*)getFrontmostBrowserWindow; - -- (MVPreferencesController *)preferencesController; -- (void)displayPreferencesWindow:sender; -- (CHPreferenceManager *)preferenceManager; -- (BOOL)isMainWindowABrowserWindow; - -// if the main window is a browser window, return its controller, otherwise nil -- (BrowserWindowController*)getMainWindowBrowserController; - -- (IBAction)showAboutBox:(id)sender; - -+ (NSImage*)createImageForDragging:(NSImage*)aIcon title:(NSString*)aTitle; - -- (void)updatePrebinding; -- (void)prebindFinished:(NSNotification *)aNotification; - -@end diff --git a/mozilla/chimera/MainController.mm b/mozilla/chimera/MainController.mm deleted file mode 100644 index b30ac343a96..00000000000 --- a/mozilla/chimera/MainController.mm +++ /dev/null @@ -1,922 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape 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/NPL/ - * - * 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 mozilla.org 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 NPL, 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 NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include -#include - -#import "MainController.h" -#import "BrowserWindowController.h" -#import "BookmarksService.h" -#import "nsCocoaBrowserService.h" -#import "CHAboutBox.h" -#import "CHUserDefaults.h" - -#include "nsCOMPtr.h" -#include "nsEmbedAPI.h" - -#include "nsIServiceManager.h" -#include "nsIIOService.h" -#include "nsIPref.h" -#include "nsIChromeRegistry.h" - - -#ifdef _BUILD_STATIC_BIN -#include "nsStaticComponent.h" -nsresult PR_CALLBACK -app_getModuleInfo(nsStaticModuleInfo **info, PRUint32 *count); -#endif - -static const char* ioServiceContractID = "@mozilla.org/network/io-service;1"; - -@implementation MainController - --(id)init -{ - if ( (self = [super init]) ) { - NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults]; - if ([defaults boolForKey:USER_DEFAULTS_AUTOREGISTER_KEY]) { - // This option causes us to simply initialize embedding and exit. - NSString *path = [[[NSBundle mainBundle] executablePath] stringByDeletingLastPathComponent]; - setenv("MOZILLA_FIVE_HOME", [path fileSystemRepresentation], 1); - -#ifdef _BUILD_STATIC_BIN - NSGetStaticModuleInfo = app_getModuleInfo; -#endif - - if (NS_SUCCEEDED(NS_InitEmbedding(nsnull, nsnull))) { - // Register new chrome - nsCOMPtr chromeReg = - do_GetService("@mozilla.org/chrome/chrome-registry;1"); - if (chromeReg) { - chromeReg->CheckForNewChrome(); - chromeReg = 0; - } - NS_TermEmbedding(); - } - - [NSApp terminate:self]; - return self; - } - - NSString* url = [defaults stringForKey:USER_DEFAULTS_URL_KEY]; - mStartURL = url ? [url retain] : nil; - mSplashScreen = [[CHSplashScreenWindow alloc] splashImage:nil withFade:NO withStatusRect:NSMakeRect(0,0,0,0)]; - mFindDialog = nil; - mMenuBookmarks = nil; - - [NSApp setServicesProvider:self]; - - } - return self; -} - --(void)dealloc -{ - [mFindDialog release]; - [super dealloc]; -#if DEBUG - NSLog(@"Main controller died"); -#endif -} - --(void)applicationDidFinishLaunching:(NSNotification *)aNotification -{ -#ifdef _BUILD_STATIC_BIN - [self updatePrebinding]; -#endif - // initialize if we haven't already. - [self preferenceManager]; - - // don't open a new browser window if we already have one - // (for example, from an GetURL Apple Event) - NSWindow* browserWindow = [self getFrontmostBrowserWindow]; - if (!browserWindow) - [self newWindow: self]; - - [mSplashScreen close]; - - [mBookmarksMenu setAutoenablesItems: NO]; - mMenuBookmarks = new BookmarksService((BookmarksDataSource*)nil); - mMenuBookmarks->AddObserver(); - BookmarksService::ConstructBookmarksMenu(mBookmarksMenu, nsnull); - BookmarksService::gMainController = self; - - // Initialize offline mode. - mOffline = NO; - nsCOMPtr ioService(do_GetService(ioServiceContractID)); - if (!ioService) - return; - PRBool offline = PR_FALSE; - ioService->GetOffline(&offline); - mOffline = offline; - - // Set the menu item's text to "Go Online" if we're currently - // offline. -/* - if (mOffline) - [mOfflineMenuItem setTitle: @"Go Online"]; // XXX localize me -*/ -} - --(void)applicationWillTerminate: (NSNotification*)aNotification -{ -#if DEBUG - NSLog(@"Termination notification"); -#endif - - // Autosave one of the windows. - [[[mApplication mainWindow] windowController] autosaveWindowFrame]; - - mMenuBookmarks->RemoveObserver(); - delete mMenuBookmarks; - mMenuBookmarks = nsnull; - - // Release before calling TermEmbedding since we need to access XPCOM - // to save preferences - [mPreferencesController release]; - [mPreferenceManager release]; - - nsCocoaBrowserService::TermEmbedding(); - - [self autorelease]; -} - --(IBAction)newWindow:(id)aSender -{ - // If we have a key window, have it autosave its dimensions before - // we open a new window. That ensures the size ends up matching. - NSWindow* mainWindow = [mApplication mainWindow]; - if ( mainWindow && [[mainWindow windowController] respondsToSelector:@selector(autosaveWindowFrame)] ) - [[mainWindow windowController] autosaveWindowFrame]; - - // Now open the new window. - NSString* homePage = mStartURL ? mStartURL : [mPreferenceManager homePage:YES]; - BrowserWindowController* controller = [self openBrowserWindowWithURL:homePage andReferrer:nil]; - - if ([homePage isEqualToString: @"about:blank"]) - [controller focusURLBar]; - else - [[[controller getBrowserWrapper] getBrowserView] setActive: YES]; - - // Only load the command-line specified URL for the first window we open - if (mStartURL) { - [mStartURL release]; - mStartURL = nil; - } -} - --(IBAction)newTab:(id)aSender -{ - BrowserWindowController* browserController = [self getMainWindowBrowserController]; - if (browserController) - [browserController newTab:NO]; -} - --(IBAction)closeTab:(id)aSender -{ - BrowserWindowController* browserController = [self getMainWindowBrowserController]; - if (browserController) - [browserController closeTab]; -} - --(IBAction) previousTab:(id)aSender -{ - BrowserWindowController* browserController = [self getMainWindowBrowserController]; - if (browserController) - [browserController previousTab]; -} - --(IBAction) nextTab:(id)aSender; -{ - BrowserWindowController* browserController = [self getMainWindowBrowserController]; - if (browserController) - [browserController nextTab]; -} - --(IBAction) openFile:(id)aSender -{ - NSOpenPanel* openPanel = [[[NSOpenPanel alloc] init] autorelease]; - [openPanel setCanChooseFiles: YES]; - [openPanel setCanChooseDirectories: NO]; - [openPanel setAllowsMultipleSelection: NO]; - NSArray* array = [NSArray arrayWithObjects: @"htm",@"html",@"shtml",@"xhtml",@"xml", - @"txt",@"text", - @"gif",@"jpg",@"jpeg",@"png",@"bmp", - nil]; - int result = [openPanel runModalForTypes: array]; - if (result == NSOKButton) { - NSArray* urlArray = [openPanel URLs]; - if ([urlArray count] == 0) - return; - NSURL* url = [urlArray objectAtIndex: 0]; - // ---------------------- - [[NSDocumentController sharedDocumentController] noteNewRecentDocumentURL:url]; - // ---------------------- - - BrowserWindowController* browserController = [self getMainWindowBrowserController]; - if (browserController) - [browserController loadURL:[url absoluteString] referrer:nil activate:YES]; - else - [self openBrowserWindowWithURL:[url absoluteString] andReferrer:nil]; - } -} - --(IBAction) openLocation:(id)aSender -{ - NSWindow* browserWindow = [self getFrontmostBrowserWindow]; - if (!browserWindow) { - [self openBrowserWindowWithURL: @"about:blank" andReferrer:nil]; - browserWindow = [mApplication mainWindow]; - } - else if (![browserWindow isMainWindow]) { - [browserWindow makeKeyAndOrderFront:self]; - } - - [[browserWindow windowController] performAppropriateLocationAction]; -} - --(IBAction) savePage:(id)aSender -{ - BrowserWindowController* browserController = [self getMainWindowBrowserController]; - if (browserController) - [browserController saveDocument: mFilterView filterList: mFilterList]; -} - --(IBAction) printPage:(id)aSender -{ - BrowserWindowController* browserController = [self getMainWindowBrowserController]; - if (browserController) - [browserController printDocument:aSender]; -} - --(IBAction) printPreview:(id)aSender -{ - BrowserWindowController* browserController = [self getMainWindowBrowserController]; - if (browserController) - [browserController printPreview]; -} - --(IBAction) toggleOfflineMode:(id)aSender -{ - nsCOMPtr ioService(do_GetService(ioServiceContractID)); - if (!ioService) - return; - PRBool offline = PR_FALSE; - ioService->GetOffline(&offline); - ioService->SetOffline(!offline); - mOffline = !offline; - - // Update the menu item text. - // Set the menu item's text to "Go Online" if we're currently - // offline. -/* - if (mOffline) - [mOfflineMenuItem setTitle: @"Go Online"]; - else - [mOfflineMenuItem setTitle: @"Work Offline"]; -*/ - - // Indicate that we are working offline. - [[NSNotificationCenter defaultCenter] postNotificationName:@"offlineModeChanged" object:nil]; -} - -// Edit menu actions. - - -// -// -findInPage -// -// Called in response to "Find" in edit menu. Opens the find dialog. We only keep -// one around for the whole app to use, showing/hiding as we see fit. -// --(IBAction) findInPage:(id)aSender -{ - if ( !mFindDialog ) - mFindDialog = [[FindDlgController alloc] initWithWindowNibName: @"FindDialog"]; - [mFindDialog showWindow:self]; -} - - -// -// -findAgain -// -// Called in response to "Find Again" in edit menu. Tells the find controller -// to find the next occurrance of what's already been found. -// --(IBAction) findAgain:(id)aSender -{ - if ( mFindDialog ) - [mFindDialog findAgain:aSender]; - else - NSBeep(); -} - --(IBAction) getInfo:(id)aSender -{ - BrowserWindowController* browserController = [self getMainWindowBrowserController]; - if (browserController) - [browserController getInfo: aSender]; -} - --(IBAction) goBack:(id)aSender -{ - BrowserWindowController* browserController = [self getMainWindowBrowserController]; - if (browserController) - [browserController back: aSender]; -} - --(IBAction) goForward:(id)aSender -{ - BrowserWindowController* browserController = [self getMainWindowBrowserController]; - if (browserController) - [browserController forward: aSender]; -} - --(IBAction) doReload:(id)aSender -{ - BrowserWindowController* browserController = [self getMainWindowBrowserController]; - if (browserController) - [browserController reload: aSender]; -} - --(IBAction) doStop:(id)aSender -{ - BrowserWindowController* browserController = [self getMainWindowBrowserController]; - if (browserController) - [browserController stop: aSender]; -} - --(IBAction) goHome:(id)aSender -{ - NSWindow* browserWindow = [self getFrontmostBrowserWindow]; - if (browserWindow) { - if (![browserWindow isMainWindow]) - [browserWindow makeKeyAndOrderFront:self]; - - [[browserWindow windowController] home: aSender]; - } - else { - [self newWindow:self]; - } -} - --(IBAction) doSearch:(id)aSender -{ - NSWindow* browserWindow = [self getFrontmostBrowserWindow]; - if (browserWindow) { - if (![browserWindow isMainWindow]) - [browserWindow makeKeyAndOrderFront:self]; - - [[browserWindow windowController] performSearch: aSender]; - } - else { - [self newWindow:self]; - browserWindow = [self getFrontmostBrowserWindow]; - [[browserWindow windowController] performSearch: aSender]; - } -} - -- (void)adjustBookmarksMenuItemsEnabling:(BOOL)inBrowserWindowFrontmost; -{ - [mAddBookmarkMenuItem setEnabled:inBrowserWindowFrontmost]; - [mCreateBookmarksFolderMenuItem setEnabled:inBrowserWindowFrontmost]; - [mCreateBookmarksSeparatorMenuItem setEnabled:NO]; // separators are not implemented yet -} - --(NSWindow*)getFrontmostBrowserWindow -{ - // for some reason, [NSApp mainWindow] doesn't always work, so we have to - // do this manually - NSArray *windowList = [NSApp orderedWindows]; - NSWindow *foundWindow = NULL; - - for (unsigned int i = 0; i < [windowList count]; i ++) - { - NSWindow* thisWindow = [windowList objectAtIndex:i]; - - if ([[thisWindow windowController] isMemberOfClass:[BrowserWindowController class]] && - ([[thisWindow windowController] chromeMask] == 0)) // only get windows with full chrome - { - foundWindow = thisWindow; - break; - } - } - - return foundWindow; -} - -// open a new URL. This method always makes a new browser window --(BrowserWindowController*)openBrowserWindowWithURL: (NSString*)aURL andReferrer: (NSString*)aReferrer -{ - BrowserWindowController* browser = [[BrowserWindowController alloc] initWithWindowNibName: @"BrowserWindow"]; - - // 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. - if ( [aURL isEqualToString:@"about:blank"] ) - [browser disableLoadPage]; - else - [browser loadURL: aURL referrer:aReferrer activate:YES]; - [browser showWindow: self]; - return browser; -} - -// open a new URL, observing the prefs on how to behave -- (void)openNewWindowOrTabWithURL:(NSString*)inURLString andReferrer: (NSString*)aReferrer -{ - // make sure we're initted - [self preferenceManager]; - - PRBool reuseWindow = PR_FALSE; - PRBool loadInBackground = PR_FALSE; - - nsCOMPtr prefService ( do_GetService(NS_PREF_CONTRACTID) ); - if ( prefService ) { - prefService->GetBoolPref("browser.always_reuse_window", &reuseWindow); - prefService->GetBoolPref("browser.tabs.loadInBackground", &loadInBackground); - } - - // reuse the main window if there is one. The user may have closed all of - // them or we may get this event at startup before we've had time to load - // our window. - BrowserWindowController* controller = [self getMainWindowBrowserController]; - if (reuseWindow && controller && [controller newTabsAllowed]) { - [controller openNewTabWithURL:inURLString referrer:aReferrer loadInBackground:loadInBackground]; - } - else { - // should use BrowserWindowController openNewWindowWithURL, but that method - // really needs to be on the MainController - controller = [self openBrowserWindowWithURL: inURLString andReferrer:aReferrer]; - } - - [[[controller getBrowserWrapper] getBrowserView] setActive: YES]; -} - -// Bookmarks menu actions. --(IBAction) importBookmarks:(id)aSender -{ - // IE favorites: ~/Library/Preferences/Explorer/Favorites.html - // Omniweb favorites: ~/Library/Application Support/Omniweb/Bookmarks.html - // For now, open the panel to IE's favorites. - NSOpenPanel* openPanel = [[[NSOpenPanel alloc] init] autorelease]; - [openPanel setCanChooseFiles: YES]; - [openPanel setCanChooseDirectories: NO]; - [openPanel setAllowsMultipleSelection: NO]; - NSArray* array = [NSArray arrayWithObjects: @"htm",@"html",@"xml", nil]; - int result = [openPanel runModalForDirectory: @"~/Library/Preferences/Explorer/" - file: @"Favorites.html" - types: array]; - if (result == NSOKButton) { - NSArray* urlArray = [openPanel URLs]; - if ([urlArray count] == 0) - return; - NSURL* url = [urlArray objectAtIndex: 0]; - - NSWindow* browserWindow = [self getFrontmostBrowserWindow]; - if (!browserWindow) { - [self newWindow: self]; - browserWindow = [mApplication mainWindow]; - } - - [[browserWindow windowController] importBookmarks: [url absoluteString]]; - } -} - --(IBAction) addBookmark:(id)aSender -{ - BrowserWindowController* browserController = [self getMainWindowBrowserController]; - if (browserController) - [browserController addBookmarkExtended: YES isFolder: NO URL:nil title:nil]; -} - --(IBAction) addFolder:(id)aSender -{ - BrowserWindowController* browserController = [self getMainWindowBrowserController]; - if (browserController) - [browserController addBookmarkExtended: YES isFolder: YES URL:nil title:nil]; -} - --(IBAction) addSeparator:(id)aSender -{ - NSLog(@"Separators not implemented yet"); -} - --(IBAction) openMenuBookmark:(id)aSender -{ - NSWindow* browserWindow = [self getFrontmostBrowserWindow]; - if (!browserWindow) { - [self openBrowserWindowWithURL: @"about:blank" andReferrer:nil]; - browserWindow = [mApplication mainWindow]; - } - - BookmarksService::OpenMenuBookmark([browserWindow windowController], aSender); -} - --(IBAction)manageBookmarks: (id)aSender -{ - NSWindow* browserWindow = [self getFrontmostBrowserWindow]; - if (!browserWindow) { - [self newWindow:self]; - browserWindow = [mApplication mainWindow]; - } - - [[browserWindow windowController] manageBookmarks: aSender]; -} - -- (CHPreferenceManager *)preferenceManager -{ - if (!mPreferenceManager) - mPreferenceManager = [[CHPreferenceManager sharedInstance] retain]; - return mPreferenceManager; -} - -- (MVPreferencesController *)preferencesController -{ - if (!mPreferencesController) { - mPreferencesController = [[MVPreferencesController sharedInstance] retain]; - } - return mPreferencesController; -} - -- (void)displayPreferencesWindow:sender -{ - [[self preferencesController] showPreferences:nil] ; -} - -- (IBAction)showAboutBox:(id)sender -{ - [[CHAboutBox sharedInstance] showPanel:sender]; -} - -- (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename -{ -/* - // On the off chance that we're getting this message off a launch, - // we may not have initialized our embedded mozilla. So check here, - // and if it's not initialized, do it now. - [self preferenceManager]; - - // Make sure it's a browser window b/c "about box" can also become main window. - if ([self isMainWindowABrowserWindow]) { - [[[mApplication mainWindow] windowController] loadURL:[[NSURL fileURLWithPath:filename] absoluteString]]; - } - else { - [self openBrowserWindowWithURL:[[NSURL fileURLWithPath:filename] absoluteString]]; - } -*/ - [self openNewWindowOrTabWithURL:[[NSURL fileURLWithPath:filename] absoluteString] andReferrer:nil]; - - return YES; -} - -- (IBAction)biggerTextSize:(id)aSender -{ - BrowserWindowController* browserController = [self getMainWindowBrowserController]; - if (browserController) - [browserController biggerTextSize]; -} - -- (IBAction)smallerTextSize:(id)aSender -{ - BrowserWindowController* browserController = [self getMainWindowBrowserController]; - if (browserController) - [browserController smallerTextSize]; -} - --(IBAction) viewSource:(id)aSender -{ - BrowserWindowController* browserController = [self getMainWindowBrowserController]; - if (browserController) - [browserController viewSource: aSender]; -} - --(BOOL)isMainWindowABrowserWindow -{ - // see also getFrontmostBrowserWindow - return [[[mApplication mainWindow] windowController] isMemberOfClass:[BrowserWindowController class]]; -} - -- (BrowserWindowController*)getMainWindowBrowserController -{ - NSWindowController* mainWindowController = [[mApplication mainWindow] windowController]; - if (mainWindowController && [mainWindowController isMemberOfClass:[BrowserWindowController class]]) - return (BrowserWindowController*)mainWindowController; - - return nil; -} - -- (void)adjustCloseWindowMenuItemKeyEquivalent:(BOOL)inHaveTabs -{ - // capitalization of the key equivalent affects whether the shift modifer is used. - [mCloseWindowMenuItem setKeyEquivalent: inHaveTabs ? @"W" : @"w"]; -} - -- (void)adjustCloseTabMenuItemKeyEquivalent:(BOOL)inHaveTabs -{ - if (inHaveTabs) { - [mCloseTabMenuItem setKeyEquivalent:@"w"]; - [mCloseTabMenuItem setKeyEquivalentModifierMask:NSCommandKeyMask]; - } - else { - [mCloseTabMenuItem setKeyEquivalent:@""]; - [mCloseTabMenuItem setKeyEquivalentModifierMask:0]; - } -} - -// see if we have a window with tabs open, and adjust the key equivalents for -// Close Tab/Close Window accordingly -- (void)fixCloseMenuItemKeyEquivalents -{ - BrowserWindowController* browserController = [self getMainWindowBrowserController]; - if (browserController) { - BOOL windowWithMultipleTabs = ([[browserController getTabBrowser] numberOfTabViewItems] > 1); - [self adjustCloseWindowMenuItemKeyEquivalent:windowWithMultipleTabs]; - [self adjustCloseTabMenuItemKeyEquivalent:windowWithMultipleTabs]; - } -} - --(BOOL)validateMenuItem: (NSMenuItem*)aMenuItem -{ - BrowserWindowController* browserController = [self getMainWindowBrowserController]; - - // disable items that aren't relevant if there's no main browser window open - SEL action = [aMenuItem action]; - - //NSLog(@"MainController validateMenuItem for %@ (%s)", [aMenuItem title], action); - - if (action == @selector(printPage:) || - /* ... many more items go here ... */ - /* action == @selector(goHome:) || */ // always enabled - /* action == @selector(doSearch:) || */ // always enabled - action == @selector(findInPage:) || - action == @selector(doReload:) || - action == @selector(biggerTextSize:) || - action == @selector(smallerTextSize:) || - action == @selector(viewSource:) || - action == @selector(savePage:)) - { - return (browserController != nil); - } - - if (action == @selector(newTab:)) - return (browserController && [browserController newTabsAllowed]); - - // check if someone has previously done a find before allowing findAgain to be enabled - if (action == @selector(findAgain:)) - return (browserController && mFindDialog && [[mFindDialog getSearchText] length] > 0); - - // check what the state of the personal toolbar should be, but only if there is a browser - // window open. Popup windows that have the personal toolbar removed should always gray - // out this menu. - if (action == @selector(toggleBookmarksToolbar:)) { - if (browserController) { - NSView* bookmarkToolbar = [browserController bookmarksToolbar]; - if ( bookmarkToolbar ) { - float height = [bookmarkToolbar frame].size.height; - BOOL toolbarShowing = (height > 0); - if (toolbarShowing) - [mBookmarksToolbarMenuItem setTitle: NSLocalizedString(@"Hide Bookmarks Toolbar",@"")]; - else - [mBookmarksToolbarMenuItem setTitle: NSLocalizedString(@"Show Bookmarks Toolbar",@"")]; - return YES; - } - else - return NO; - } - else - return NO; - } - - if (action == @selector(toggleSidebar:)) { - if (browserController) { - NSDrawer *sidebar = [browserController sidebarDrawer]; - if (sidebar) { - int sidebarState = [sidebar state]; - if (sidebarState == NSDrawerOpenState) - [mToggleSidebarMenuItem setTitle: NSLocalizedString(@"Hide Sidebar",@"")]; - else - [mToggleSidebarMenuItem setTitle: NSLocalizedString(@"Show Sidebar",@"")]; - return YES; - } - else - return NO; - } - else - return NO; - } - - if ( action == @selector(getInfo:) ) - return (browserController && [browserController canGetInfo]); - - // only activate if we've got multiple tabs open. - if ((action == @selector(closeTab:) || - action == @selector(nextTab:) || - action == @selector(previousTab:))) - { - return (browserController && [[browserController getTabBrowser] numberOfTabViewItems] > 1); - } - - if ( action == @selector(doStop:) ) - return (browserController && [[browserController getBrowserWrapper] isBusy]); - - if ( action == @selector(goBack:) || action == @selector(goForward:) ) { - if (browserController) { - CHBrowserView* browserView = [[browserController getBrowserWrapper] getBrowserView]; - if (action == @selector(goBack:)) - return [browserView canGoBack]; - if (action == @selector(goForward:)) - return [browserView canGoForward]; - } - else - return NO; - } - - // default return - return YES; -} - --(IBAction) toggleSidebar:(id)sender -{ - BrowserWindowController *browserController = [self getMainWindowBrowserController]; - if (!browserController) return; - - [browserController toggleSidebar:sender]; -} - --(IBAction) toggleBookmarksToolbar:(id)aSender -{ - BrowserWindowController* browserController = [self getMainWindowBrowserController]; - if (!browserController) return; - - float height = [[browserController bookmarksToolbar] frame].size.height; - BOOL showToolbar = (BOOL)(!(height > 0)); - - [[browserController bookmarksToolbar] showBookmarksToolbar: showToolbar]; - - // save prefs here - NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults]; - [defaults setInteger: ((showToolbar) ? 0 : 1) forKey: USER_DEFAULTS_HIDE_PERS_TOOLBAR_KEY]; -} - --(IBAction) infoLink:(id)aSender -{ - NSString* pageToLoad = NSLocalizedStringFromTable(@"InfoPageDefault", @"WebsiteDefaults", nil); - if (![pageToLoad isEqualToString:@"InfoPageDefault"]) - [self openNewWindowOrTabWithURL:pageToLoad andReferrer:nil]; -} - --(IBAction) feedbackLink:(id)aSender -{ - NSString *pageToLoad = NSLocalizedStringFromTable(@"FeedbackPageDefault", @"WebsiteDefaults", nil); - if (![pageToLoad isEqualToString:@"FeedbackPageDefault"]) - [self openNewWindowOrTabWithURL:pageToLoad andReferrer:nil]; -} - -+ (NSImage*)createImageForDragging:(NSImage*)aIcon title:(NSString*)aTitle -{ - NSImage* image; - NSSize titleSize, imageSize; - NSRect imageRect; - NSDictionary* stringAttrs; - - // get the size of the new image we are creating - titleSize = [aTitle sizeWithAttributes:nil]; - imageSize = NSMakeSize(titleSize.width + [aIcon size].width, - titleSize.height > [aIcon size].height ? - titleSize.height : [aIcon size].height); - - // create the image and lock drawing focus on it - image = [[[NSImage alloc] initWithSize:imageSize] autorelease]; - [image lockFocus]; - - // draw the image and title in image with translucency - imageRect = NSMakeRect(0,0, [aIcon size].width, [aIcon size].height); - [aIcon drawAtPoint: NSMakePoint(0,0) fromRect: imageRect operation:NSCompositeCopy fraction:0.8]; - - stringAttrs = [NSDictionary dictionaryWithObject: [[NSColor textColor] colorWithAlphaComponent:0.8] - forKey: NSForegroundColorAttributeName]; - [aTitle drawAtPoint: NSMakePoint([aIcon size].width, 0) withAttributes: stringAttrs]; - - [image unlockFocus]; - - return image; -} - -- (BOOL)applicationShouldHandleReopen:(NSApplication *)theApp hasVisibleWindows:(BOOL)flag -{ - // If AppKit knows what to do, let it. - if (flag) - return YES; - - // If window available, wake it up. |mainWindow| should always be null. - NSWindow* mainWindow = [mApplication mainWindow]; - if (!mainWindow) - [self newWindow:self]; - else { // Don't think this will ever happen, but just in case - if ([[mainWindow windowController]respondsToSelector:@selector(showWindow:)]) - [[mainWindow windowController] showWindow:self]; - else - [self newWindow:self]; - } - - return NO; -} - -- (void) applicationDidChangeScreenParameters:(NSNotification *)aNotification -{ - [NSApp makeWindowsPerform:@selector(display) inOrder:YES]; -} - -- (void) updatePrebinding -{ - // Check our prebinding status. If we didn't launch prebound, - // fork the update script. - - if (!_dyld_launched_prebound()) { - NSLog(@"Not prebound, launching update script"); - NSTask* aTask = [[NSTask alloc] init]; - NSArray* args = [NSArray arrayWithObject: @"redo-prebinding.sh"]; - - [aTask setCurrentDirectoryPath:[[[NSBundle mainBundle] executablePath] stringByDeletingLastPathComponent]]; - [aTask setLaunchPath:@"/bin/sh"]; - [aTask setArguments:args]; - - [[NSNotificationCenter defaultCenter] addObserver: self - selector:@selector(prebindFinished:) - name:NSTaskDidTerminateNotification - object: nil]; - - [aTask launch]; - } -} - -- (void)prebindFinished:(NSNotification *)aNotification -{ - [[aNotification object] release]; -} - -// services - -- (void)openURL:(NSPasteboard *) pboard userData:(NSString *) userData error:(NSString **) error -{ - NSMutableString *urlString = [[[NSMutableString alloc] init] autorelease]; - if ( !urlString ) - return; - - NSArray* types = [pboard types]; - if (![types containsObject:NSStringPboardType]) { - *error = NSLocalizedString(@"Error: couldn't open URL.", - @"pboard couldn't give URL string."); - return; - } - NSString* pboardString = [pboard stringForType:NSStringPboardType]; - if (!pboardString) { - *error = NSLocalizedString(@"Error: couldn't open URL.", - @"pboard couldn't give URL string."); - return; - } - NSScanner* scanner = [NSScanner scannerWithString:pboardString]; - [scanner scanCharactersFromSet:[[NSCharacterSet whitespaceAndNewlineCharacterSet] invertedSet] intoString:&urlString]; - while(![scanner isAtEnd]) { - NSString *tmpString; - [scanner scanCharactersFromSet:[[NSCharacterSet whitespaceAndNewlineCharacterSet] invertedSet] intoString:&tmpString]; - [urlString appendString:tmpString]; - } - - [self openNewWindowOrTabWithURL:urlString andReferrer:nil]; -} - -@end diff --git a/mozilla/chimera/MainMenu.nib/classes.nib b/mozilla/chimera/MainMenu.nib/classes.nib deleted file mode 100644 index fae3aa7579e..00000000000 --- a/mozilla/chimera/MainMenu.nib/classes.nib +++ /dev/null @@ -1,80 +0,0 @@ -{ - IBClasses = ( - { - CLASS = BrowserToolbarController; - LANGUAGE = ObjC; - SUPERCLASS = ToolbarController; - }, - {CLASS = CHGoMenu; LANGUAGE = ObjC; SUPERCLASS = NSMenu; }, - {CLASS = FirstResponder; LANGUAGE = ObjC; SUPERCLASS = NSObject; }, - { - ACTIONS = { - addBookmark = id; - addFolder = id; - addSeparator = id; - biggerTextSize = id; - closeTab = id; - displayPreferencesWindow = id; - doReload = id; - doSearch = id; - doStop = id; - feedbackLink = id; - findAgain = id; - findInPage = id; - getInfo = id; - goBack = id; - goForward = id; - goHome = id; - importBookmarks = id; - infoLink = id; - manageBookmarks = id; - newTab = id; - newWindow = id; - nextTab = id; - openFile = id; - openLocation = id; - openMenuBookmark = id; - previousTab = id; - printPage = id; - printPreview = id; - savePage = id; - showAboutBox = id; - smallerTextSize = id; - toggleBookmarksToolbar = id; - toggleOfflineMode = id; - toggleSidebar = id; - viewSource = id; - }; - CLASS = MainController; - LANGUAGE = ObjC; - OUTLETS = { - mAddBookmarkMenuItem = NSMenuItem; - mApplication = NSApplication; - mBookmarksMenu = NSMenu; - mBookmarksToolbarMenuItem = NSMenuItem; - mCloseTabMenuItem = NSMenuItem; - mCloseWindowMenuItem = NSMenuItem; - mCreateBookmarksFolderMenuItem = NSMenuItem; - mCreateBookmarksSeparatorMenuItem = NSMenuItem; - mFilterList = NSPopUpButton; - mFilterView = NSView; - mToggleSidebarMenuItem = NSMenuItem; - }; - SUPERCLASS = NSObject; - }, - { - ACTIONS = {load = id; }; - CLASS = MyBrowserView; - LANGUAGE = ObjC; - OUTLETS = {progress = id; progressSuper = id; status = id; urlbar = id; }; - SUPERCLASS = NSView; - }, - { - CLASS = ToolbarController; - LANGUAGE = ObjC; - OUTLETS = {mBrowserView = id; mWindow = id; }; - SUPERCLASS = NSObject; - } - ); - IBVersion = 1; -} \ No newline at end of file diff --git a/mozilla/chimera/MainMenu.nib/info.nib b/mozilla/chimera/MainMenu.nib/info.nib deleted file mode 100644 index 2a0b9c2b3e9..00000000000 --- a/mozilla/chimera/MainMenu.nib/info.nib +++ /dev/null @@ -1,39 +0,0 @@ - - - - - IBDocumentLocation - 108 107 477 485 0 0 1280 1002 - IBEditorPositions - - 266 - 483 623 277 90 0 0 1280 1002 - 29 - 8 957 446 44 0 0 1280 1002 - - IBFramework Version - 248.0 - IBGroupedObjects - - 0 - - 0 - 0 - 0 - - 1 - - 0 - 0 - - - IBLastGroupID - 2 - IBOpenObjects - - 29 - - IBSystem Version - 5S66 - - diff --git a/mozilla/chimera/MainMenu.nib/objects.nib b/mozilla/chimera/MainMenu.nib/objects.nib deleted file mode 100644 index 3eb3a4600a8..00000000000 Binary files a/mozilla/chimera/MainMenu.nib/objects.nib and /dev/null differ diff --git a/mozilla/chimera/NSScreen+Utils.h b/mozilla/chimera/NSScreen+Utils.h deleted file mode 100644 index 0c24ec890e9..00000000000 --- a/mozilla/chimera/NSScreen+Utils.h +++ /dev/null @@ -1,45 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape 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/NPL/ - * - * 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 mozilla.org 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 NPL, 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 NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#import - - -@interface NSScreen (CHScreenAdditions) - -+ (NSScreen*)screenForPoint:(NSPoint)point; - -@end diff --git a/mozilla/chimera/NSScreen+Utils.m b/mozilla/chimera/NSScreen+Utils.m deleted file mode 100644 index 290b2c57bed..00000000000 --- a/mozilla/chimera/NSScreen+Utils.m +++ /dev/null @@ -1,59 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape 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/NPL/ - * - * 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 mozilla.org 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 NPL, 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 NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - - -#import "NSScreen+Utils.h" - - -@implementation NSScreen (CHScreenAdditions) - -+ (NSScreen*)screenForPoint:(NSPoint)point -{ - NSArray* screens = [NSScreen screens]; - NSEnumerator* screenEnum = [screens objectEnumerator]; - NSScreen* screen; - - while ( (screen = [screenEnum nextObject]) ) { - NSRect frame = [screen frame]; - if (NSPointInRect(point, frame)) - break; - } - - return screen; -} - -@end diff --git a/mozilla/chimera/NSString+Utils.h b/mozilla/chimera/NSString+Utils.h deleted file mode 100644 index a4d3d6fe3e2..00000000000 --- a/mozilla/chimera/NSString+Utils.h +++ /dev/null @@ -1,70 +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): - * Simon Fraser - * - * 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 -#import "nscore.h" - -class nsAString; - -typedef enum -{ - kTruncateAtStart, - kTruncateAtMiddle, - kTruncateAtEnd -} ETruncationType; - - -// a category to extend NSString -@interface NSString (ChimeraStringUtils) - -+ (id)ellipsisString; -+ (id)stringWithPRUnichars:(const PRUnichar*)inString; -+ (id)stringWith_nsAString:(const nsAString&)inString; -- (void)assignTo_nsAString:(nsAString&)ioString; - -- (NSString *)stringByRemovingCharactersInSet:(NSCharacterSet*)characterSet; -- (NSString *)stringByReplacingCharactersInSet:(NSCharacterSet*)characterSet withString:(NSString*)string; -- (NSString *)stringByTruncatingTo:(unsigned int)maxCharacters at:(ETruncationType)truncationType; - -@end - -@interface NSMutableString (ChimeraMutableStringUtils) - -- (void)truncateTo:(unsigned)maxCharacters at:(ETruncationType)truncationType; -- (void)truncateToWidth:(float)maxWidth at:(ETruncationType)truncationType withAttributes:(NSDictionary *)attributes; - -@end diff --git a/mozilla/chimera/NSString+Utils.mm b/mozilla/chimera/NSString+Utils.mm deleted file mode 100644 index 56b2fbb26e0..00000000000 --- a/mozilla/chimera/NSString+Utils.mm +++ /dev/null @@ -1,229 +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): - * Simon Fraser - * - * 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 // for NSStringDrawing.h -#import "NSString+Utils.h" - -#include "nsString.h" -#include "nsPromiseFlatString.h" -#include "nsCRT.h" - - -@implementation NSString (ChimeraStringUtils) - - -+ (id)ellipsisString -{ - static NSString* sEllipsisString = nil; - if (!sEllipsisString) - { - unichar ellipsisChar = 0x2026; - sEllipsisString = [[NSString alloc] initWithCharacters:&ellipsisChar length:1]; - } - - return sEllipsisString; -} - -+ (id)stringWithPRUnichars:(const PRUnichar*)inString -{ - if (inString) - return [self stringWithCharacters:inString length:nsCRT::strlen(inString)]; - else - return [self string]; -} - -+ (id)stringWith_nsAString:(const nsAString&)inString -{ - nsPromiseFlatString flatString = PromiseFlatString(inString); - return [self stringWithCharacters:flatString.get() length:flatString.Length()]; -} - -#define ASSIGN_STACK_BUFFER_CHARACTERS 256 - -- (void)assignTo_nsAString:(nsAString&)ioString -{ - PRUnichar stackBuffer[ASSIGN_STACK_BUFFER_CHARACTERS]; - PRUnichar* buffer = stackBuffer; - - // XXX maybe fix this to use SetLength(0), SetLength(len), and a writing iterator. - unsigned int len = [self length]; - - if (len + 1 > ASSIGN_STACK_BUFFER_CHARACTERS) - { - buffer = (PRUnichar *)malloc(sizeof(PRUnichar) * (len + 1)); - if (!buffer) - return; - } - - [self getCharacters: buffer]; // does not null terminate - ioString.Assign(buffer, len); - - if (buffer != stackBuffer) - free(buffer); -} - -- (NSString *)stringByRemovingCharactersInSet:(NSCharacterSet*)characterSet -{ - NSScanner* cleanerScanner = [NSScanner scannerWithString:self]; - NSMutableString* cleanString = [NSMutableString stringWithCapacity:[self length]]; - - while (![cleanerScanner isAtEnd]) - { - NSString* stringFragment; - if ([cleanerScanner scanUpToCharactersFromSet:characterSet intoString:&stringFragment]) - [cleanString appendString:stringFragment]; - - [cleanerScanner scanCharactersFromSet:characterSet intoString:nil]; - } - - return cleanString; -} - -- (NSString *)stringByReplacingCharactersInSet:(NSCharacterSet*)characterSet withString:(NSString*)string -{ - NSScanner* cleanerScanner = [NSScanner scannerWithString:self]; - NSMutableString* cleanString = [NSMutableString stringWithCapacity:[self length]]; - - while (![cleanerScanner isAtEnd]) - { - NSString* stringFragment; - if ([cleanerScanner scanUpToCharactersFromSet:characterSet intoString:&stringFragment]) - [cleanString appendString:stringFragment]; - - if ([cleanerScanner scanCharactersFromSet:characterSet intoString:nil]) - [cleanString appendString:string]; - } - - return cleanString; -} - -- (NSString*)stringByTruncatingTo:(unsigned in)maxCharacters at:(ETruncationType)truncationType -{ - if ([self length] > maxCharacters) - { - NSMutableString *mutableCopy = [self mutableCopy]; - [mutableCopy truncateTo:maxCharacters at:truncationType]; - return [mutableCopy autorelease]; - } - - return [[self copy] autorelease]; -} - -@end - - -@implementation NSMutableString (ChimeraMutableStringUtils) - -- (void)truncateTo:(unsigned)maxCharacters at:(ETruncationType)truncationType -{ - if ([self length] > maxCharacters) - { - NSRange replaceRange; - replaceRange.length = [self length] - maxCharacters; - - switch (truncationType) - { - case kTruncateAtStart: - replaceRange.location = 0; - break; - - case kTruncateAtMiddle: - replaceRange.location = maxCharacters / 2; - break; - - case kTruncateAtEnd: - replaceRange.location = maxCharacters; - break; - - default: -#if DEBUG - NSLog(@"Unknown truncation type in stringByTruncatingTo::"); -#endif - replaceRange.location = maxCharacters; - break; - } - - [self replaceCharactersInRange:replaceRange withString:[NSString ellipsisString]]; - } -} - - -- (void)truncateToWidth:(float)maxWidth at:(ETruncationType)truncationType withAttributes:(NSDictionary *)attributes -{ - // First check if we have to truncate at all. - if ([self sizeWithAttributes:attributes].width > maxWidth) - { - // Essentially, we perform a binary search on the string length - // which fits best into maxWidth. - - float width; - int lo = 0; - int hi = [self length]; - int mid; - - // Make a backup copy of the string so that we can restore it if we fail low. - NSMutableString *backup = [self mutableCopy]; - - while (hi >= lo) - { - mid = (hi + lo) / 2; - - // Cut to mid chars and calculate the resulting width - [self truncateTo:mid at:truncationType]; - width = [self sizeWithAttributes:attributes].width; - - if (width > maxWidth) { - // Fail high - string is still to wide. For the next cut, we can simply - // work on the already cut string, so we don't restore using the backup. - hi = mid - 1; - } else if (width == maxWidth) { - // Perfect match, abort the search. - break; - } else { - // Fail low - we cut off to much. Restore the string before cutting again. - lo = mid + 1; - [self setString:backup]; - } - } - // Perform the final cut (unless this was already a perfect match). - if (width != maxWidth) - [self truncateTo:hi at:truncationType]; - [backup release]; - } -} - -@end diff --git a/mozilla/chimera/Navigator.scriptSuite b/mozilla/chimera/Navigator.scriptSuite deleted file mode 100644 index 6d790279fd3..00000000000 --- a/mozilla/chimera/Navigator.scriptSuite +++ /dev/null @@ -1,31 +0,0 @@ - - - - - AppleEventCode - CHIM - Commands - - GetURL - - AppleEventClassCode - GURL - AppleEventCode - GURL - CommandClass - CHGetURLCommand - - OpenURL - - AppleEventClassCode - WWW! - AppleEventCode - OURL - CommandClass - CHGetURLCommand - - - Name - Navigator - - diff --git a/mozilla/chimera/ProgressDialog.nib/classes.nib b/mozilla/chimera/ProgressDialog.nib/classes.nib deleted file mode 100644 index fc624beb9c0..00000000000 --- a/mozilla/chimera/ProgressDialog.nib/classes.nib +++ /dev/null @@ -1,19 +0,0 @@ -{ - IBClasses = ( - {CLASS = FirstResponder; LANGUAGE = ObjC; SUPERCLASS = NSObject; }, - { - CLASS = ProgressDlgController; - LANGUAGE = ObjC; - OUTLETS = { - mElapsedTimeLabel = NSTextField; - mFromField = NSTextField; - mProgressBar = NSProgressIndicator; - mStatusLabel = NSTextField; - mTimeLeftLabel = NSTextField; - mToField = NSTextField; - }; - SUPERCLASS = NSWindowController; - } - ); - IBVersion = 1; -} \ No newline at end of file diff --git a/mozilla/chimera/ProgressDialog.nib/info.nib b/mozilla/chimera/ProgressDialog.nib/info.nib deleted file mode 100644 index d128c1fddc6..00000000000 --- a/mozilla/chimera/ProgressDialog.nib/info.nib +++ /dev/null @@ -1,12 +0,0 @@ - - - - - IBDocumentLocation - 94 26 404 250 0 0 1152 746 - IBFramework Version - 248.0 - IBSystem Version - 5S66 - - diff --git a/mozilla/chimera/ProgressDialog.nib/objects.nib b/mozilla/chimera/ProgressDialog.nib/objects.nib deleted file mode 100644 index 53a6f68e67e..00000000000 Binary files a/mozilla/chimera/ProgressDialog.nib/objects.nib and /dev/null differ diff --git a/mozilla/chimera/ProgressDlgController.h b/mozilla/chimera/ProgressDlgController.h deleted file mode 100644 index 422a3fc70e5..00000000000 --- a/mozilla/chimera/ProgressDlgController.h +++ /dev/null @@ -1,83 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape 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/NPL/ - * - * 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 mozilla.org 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 NPL, 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 NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#import - -#import "DownloadProgressDisplay.h" - -#include "nscore.h" - -class nsIWebBrowserPersist; -class nsISupports; -class nsIInputStream; -class nsDownloadListener; - - -@interface ChimeraDownloadControllerFactory : DownloadControllerFactory -@end - - -@interface ProgressDlgController : NSWindowController -{ - IBOutlet NSTextField *mElapsedTimeLabel; - IBOutlet NSTextField *mFromField; - IBOutlet NSTextField *mStatusLabel; - IBOutlet NSTextField *mTimeLeftLabel; - IBOutlet NSTextField *mToField; - IBOutlet NSProgressIndicator *mProgressBar; - - NSToolbarItem *leaveOpenToggleToolbarItem; - - BOOL mSaveFileDialogShouldStayOpen; - BOOL mIsFileSave; - BOOL mDownloadIsComplete; - long mCurrentProgress; // if progress bar is indeterminate, can still calc stats. - - CHDownloader *mDownloader; // we hold a ref to this - NSTimer *mDownloadTimer; -} - --(void)autosaveWindowFrame; - --(void) setupDownloadTimer; --(void) killDownloadTimer; --(void) setDownloadProgress:(NSTimer *)aTimer; --(NSString *) formatTime:(int)aSeconds; --(NSString *) formatFuzzyTime:(int)aSeconds; --(NSString *) formatBytes:(float)aBytes; - -@end diff --git a/mozilla/chimera/ProgressDlgController.mm b/mozilla/chimera/ProgressDlgController.mm deleted file mode 100644 index 55f5e8897d5..00000000000 --- a/mozilla/chimera/ProgressDlgController.mm +++ /dev/null @@ -1,509 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape 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/NPL/ - * - * 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 mozilla.org 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 NPL, 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 NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#import "ProgressDlgController.h" - -#include "nsCOMPtr.h" -#include "nsString.h" -#include "nsCRT.h" -#include "nsIWebBrowserPersist.h" -#include "nsIInputStream.h" -#include "nsIURL.h" -#include "nsILocalFile.h" -#include "nsIDOMHTMLDocument.h" -#include "nsIWebProgressListener.h" -#include "nsIDownload.h" -#include "nsIComponentManager.h" -#include "nsIPref.h" - -static NSString *SaveFileToolbarIdentifier = @"Save File Dialog Toolbar"; -static NSString *CancelToolbarItemIdentifier = @"Cancel Toolbar Item"; -static NSString *ShowFileToolbarItemIdentifier = @"Show File Toolbar Item"; -static NSString *OpenFileToolbarItemIdentifier = @"Open File Toolbar Item"; -static NSString *LeaveOpenToolbarItemIdentifier = @"Leave Open Toggle Toolbar Item"; - -static NSString *ProgressWindowFrameSaveName = @"ProgressWindow"; - -@implementation ChimeraDownloadControllerFactory : DownloadControllerFactory - -- (NSWindowController *)createDownloadController -{ - NSWindowController* progressController = [[ProgressDlgController alloc] initWithWindowNibName: @"ProgressDialog"]; - NSAssert([progressController conformsToProtocol:@protocol(DownloadProgressDisplay)], - @"progressController should conform to DownloadProgressDisplay protocol"); - return progressController; -} - -@end - -#pragma mark - - - -@interface ProgressDlgController(Private) --(void)setupToolbar; -@end - -@implementation ProgressDlgController - -- (void)dealloc -{ - // if we get here because we're quitting, the listener will still be alive - // yet we're going away. As a result, we need to tell the d/l listener to - // forget it ever met us and necko will clean it up on its own. - if ( mDownloader) - mDownloader->DetachDownloadDisplay(); - NS_IF_RELEASE(mDownloader); - [super dealloc]; -} - -- (void)windowDidLoad -{ - [super windowDidLoad]; - - mDownloadIsComplete = NO; - - if (!mIsFileSave) { - nsCOMPtr prefs(do_GetService(NS_PREF_CONTRACTID)); - PRBool save = PR_FALSE; - prefs->GetBoolPref("browser.download.progressDnldDialog.keepAlive", &save); - mSaveFileDialogShouldStayOpen = save; - } - - [self setupToolbar]; - [mProgressBar setUsesThreadedAnimation:YES]; - [mProgressBar startAnimation:self]; // move to onStateChange -} - -- (void)setupToolbar -{ - NSToolbar *toolbar = [[[NSToolbar alloc] initWithIdentifier:SaveFileToolbarIdentifier] autorelease]; - - [toolbar setDisplayMode:NSToolbarDisplayModeDefault]; - [toolbar setAllowsUserCustomization:YES]; - [toolbar setAutosavesConfiguration:YES]; - [toolbar setDelegate:self]; - [[self window] setToolbar:toolbar]; -} - -- (NSArray *)toolbarAllowedItemIdentifiers:(NSToolbar *)toolbar -{ - return [NSArray arrayWithObjects: CancelToolbarItemIdentifier, - ShowFileToolbarItemIdentifier, - OpenFileToolbarItemIdentifier, - LeaveOpenToolbarItemIdentifier, - NSToolbarCustomizeToolbarItemIdentifier, - NSToolbarFlexibleSpaceItemIdentifier, - NSToolbarSpaceItemIdentifier, - NSToolbarSeparatorItemIdentifier, - nil]; -} - -- (NSArray *)toolbarDefaultItemIdentifiers:(NSToolbar *)toolbar -{ - return [NSArray arrayWithObjects: CancelToolbarItemIdentifier, - NSToolbarFlexibleSpaceItemIdentifier, - LeaveOpenToolbarItemIdentifier, - NSToolbarFlexibleSpaceItemIdentifier, - ShowFileToolbarItemIdentifier, - OpenFileToolbarItemIdentifier, - nil]; -} - -- (BOOL)validateToolbarItem:(NSToolbarItem *)toolbarItem -{ - if ([toolbarItem action] == @selector(cancel)) // cancel button - return (!mDownloadIsComplete); - if ([toolbarItem action] == @selector(pauseAndResumeDownload)) // pause/resume button - return (NO); // Hey - it hasn't been hooked up yet. !mDownloadIsComplete when it is. - if ([toolbarItem action] == @selector(showFile)) // show file - return (mDownloadIsComplete); - if ([toolbarItem action] == @selector(openFile)) // open file - return (mDownloadIsComplete); - return YES; // turn it on otherwise. -} - --(void)autosaveWindowFrame -{ - [[self window] saveFrameUsingName: ProgressWindowFrameSaveName]; -} - -- (NSToolbarItem *) toolbar:(NSToolbar *)toolbar - itemForItemIdentifier:(NSString *)itemIdent - willBeInsertedIntoToolbar:(BOOL)willBeInserted -{ - NSToolbarItem *toolbarItem = [[[NSToolbarItem alloc] initWithItemIdentifier:itemIdent] autorelease]; - - if ( [itemIdent isEqual:CancelToolbarItemIdentifier] ) { - [toolbarItem setLabel:NSLocalizedString(@"Cancel",@"Cancel")]; - [toolbarItem setPaletteLabel:NSLocalizedString(@"CancelPaletteLabel",@"Cancel Download")]; - [toolbarItem setToolTip:NSLocalizedString(@"CancelToolTip",@"Cancel this file download")]; - [toolbarItem setImage:[NSImage imageNamed:@"saveCancel"]]; - [toolbarItem setTarget:self]; - [toolbarItem setAction:@selector(cancel)]; - } else if ( [itemIdent isEqual:ShowFileToolbarItemIdentifier] ) { - [toolbarItem setLabel:NSLocalizedString(@"Show File",@"Show File")]; - [toolbarItem setPaletteLabel:NSLocalizedString(@"Show File",@"Show File")]; - [toolbarItem setToolTip:NSLocalizedString(@"ShowToolTip",@"Show the saved file in the Finder")]; - [toolbarItem setImage:[NSImage imageNamed:@"saveShowFile"]]; - [toolbarItem setTarget:self]; - [toolbarItem setAction:@selector(showFile)]; - } else if ( [itemIdent isEqual:OpenFileToolbarItemIdentifier] ) { - [toolbarItem setLabel:NSLocalizedString(@"Open File",@"Open File")]; - [toolbarItem setPaletteLabel:NSLocalizedString(@"Open File",@"Open File")]; - [toolbarItem setToolTip:NSLocalizedString(@"OpenToolTip",@"Open the saved file in its default application.")]; - [toolbarItem setImage:[NSImage imageNamed:@"saveOpenFile"]]; - [toolbarItem setTarget:self]; - [toolbarItem setAction:@selector(openFile)]; - } else if ( [itemIdent isEqual:LeaveOpenToolbarItemIdentifier] ) { - if ( !mIsFileSave ) { - if ( mSaveFileDialogShouldStayOpen ) { - [toolbarItem setLabel:NSLocalizedString(@"Leave Open",@"Leave Open")]; - [toolbarItem setPaletteLabel:NSLocalizedString(@"Toggle Close Behavior",@"Toggle Close Behavior")]; - [toolbarItem setToolTip:NSLocalizedString(@"LeaveOpenToolTip",@"Window will stay open when download finishes.")]; - [toolbarItem setImage:[NSImage imageNamed:@"saveLeaveOpenYES"]]; - [toolbarItem setTarget:self]; - [toolbarItem setAction:@selector(toggleLeaveOpen)]; - } else { - [toolbarItem setLabel:NSLocalizedString(@"Close When Done",@"Close When Done")]; - [toolbarItem setPaletteLabel:NSLocalizedString(@"Toggle Close Behavior",@"Toggle Close Behavior")]; - [toolbarItem setToolTip:NSLocalizedString(@"CloseWhenDoneToolTip",@"Window will close automatically when download finishes.")]; - [toolbarItem setImage:[NSImage imageNamed:@"saveLeaveOpenNO"]]; - [toolbarItem setTarget:self]; - [toolbarItem setAction:@selector(toggleLeaveOpen)]; - } - if ( willBeInserted ) { - leaveOpenToggleToolbarItem = toolbarItem; //establish reference - } - } - } else { - toolbarItem = nil; - } - - return toolbarItem; -} - --(void)cancel -{ - if (mDownloader) // we should always have one - mDownloader->CancelDownload(); - - // clean up downloaded file. - do it here on in CancelDownload? - NSFileManager *fileManager = [NSFileManager defaultManager]; - NSString *thePath = [[mToField stringValue] stringByExpandingTildeInPath]; - if ([fileManager isDeletableFileAtPath:thePath]) - // if we delete it, fantastic. if not, oh well. better to move to trash instead? - [fileManager removeFileAtPath:thePath handler:nil]; - - // we can _not_ set the |mIsDownloadComplete| flag here because the download really - // isn't done yet. We'll probably continue to process more PLEvents that are already - // in the queue until we get a STATE_STOP state change. As a result, we just keep - // going until that comes in (and it will, because we called CancelDownload() above). - // Ensure that the window goes away when we get there by flipping the 'stay alive' - // flag. (bug 154913) - mSaveFileDialogShouldStayOpen = NO; -} - --(void)showFile -{ - NSString *theFile = [[mToField stringValue] stringByExpandingTildeInPath]; - if ([[NSWorkspace sharedWorkspace] selectFile:theFile - inFileViewerRootedAtPath:[theFile stringByDeletingLastPathComponent]]) - return; - // hmmm. it didn't work. that's odd. need localized error messages. for now, just beep. - NSBeep(); -} - --(void)openFile -{ - NSString *theFile = [[mToField stringValue] stringByExpandingTildeInPath]; - if ([[NSWorkspace sharedWorkspace] openFile:theFile]) - return; - // hmmm. it didn't work. that's odd. need localized error message. for now, just beep. - NSBeep(); - -} - --(void)toggleLeaveOpen -{ - if ( ! mSaveFileDialogShouldStayOpen ) { - mSaveFileDialogShouldStayOpen = YES; - [leaveOpenToggleToolbarItem setLabel:NSLocalizedString(@"Leave Open",@"Leave Open")]; - [leaveOpenToggleToolbarItem setPaletteLabel:NSLocalizedString(@"Toggle Close Behavior",@"Toggle Close Behavior")]; - [leaveOpenToggleToolbarItem setToolTip:NSLocalizedString(@"LeaveOpenToolTip",@"Window will stay open when download finishes.")]; - [leaveOpenToggleToolbarItem setImage:[NSImage imageNamed:@"saveLeaveOpenYES"]]; - } else { - mSaveFileDialogShouldStayOpen = NO; - [leaveOpenToggleToolbarItem setLabel:NSLocalizedString(@"Close When Done",@"Close When Done")]; - [leaveOpenToggleToolbarItem setPaletteLabel:NSLocalizedString(@"Toggle Close Behavior",@"Toggle Close Behavior")]; - [leaveOpenToggleToolbarItem setToolTip:NSLocalizedString(@"CloseWhenDoneToolTip",@"Window will close automatically when download finishes.")]; - [leaveOpenToggleToolbarItem setImage:[NSImage imageNamed:@"saveLeaveOpenNO"]]; - } - - nsCOMPtr prefs(do_GetService(NS_PREF_CONTRACTID)); - prefs->SetBoolPref("browser.download.progressDnldDialog.keepAlive", mSaveFileDialogShouldStayOpen); -} - -- (void)windowWillClose:(NSNotification *)notification -{ - [self autosaveWindowFrame]; - [self autorelease]; -} - -- (BOOL)windowShouldClose:(NSNotification *)notification -{ - [self killDownloadTimer]; - if (!mDownloadIsComplete) { //whoops. hard cancel. - [self cancel]; - return NO; // let setDownloadProgress handle the close. - } - return YES; -} - -- (void)killDownloadTimer -{ - if (mDownloadTimer) { - [mDownloadTimer invalidate]; - [mDownloadTimer release]; - mDownloadTimer = nil; - } -} -- (void)setupDownloadTimer -{ - [self killDownloadTimer]; - mDownloadTimer = [[NSTimer scheduledTimerWithTimeInterval:1.0 - target:self - selector:@selector(setDownloadProgress:) - userInfo:nil - repeats:YES] retain]; -} - --(NSString *)formatTime:(int)seconds -{ - NSMutableString *theTime =[[[NSMutableString alloc] initWithCapacity:8] autorelease]; - [theTime setString:@""]; - NSString *padZero = [NSString stringWithString:@"0"]; - //write out new elapsed time - if (seconds >= 3600){ - [theTime appendFormat:@"%d:",(seconds / 3600)]; - seconds = seconds % 3600; - } - NSString *elapsedMin = [NSString stringWithFormat:@"%d:",(seconds / 60)]; - if ([elapsedMin length] == 2) - [theTime appendString:[padZero stringByAppendingString:elapsedMin]]; - else - [theTime appendString:elapsedMin]; - seconds = seconds % 60; - NSString *elapsedSec = [NSString stringWithFormat:@"%d",seconds]; - if ([elapsedSec length] == 2) - [theTime appendString:elapsedSec]; - else - [theTime appendString:[padZero stringByAppendingString:elapsedSec]]; - return theTime; -} -// fuzzy time gives back strings like "about 5 seconds" --(NSString *)formatFuzzyTime:(int)seconds -{ - // check for seconds first - if (seconds < 60) { - if (seconds < 7) - return [[[NSString alloc] initWithFormat:NSLocalizedString(@"UnderSec",@"Under %d seconds"),5] autorelease]; - if (seconds < 13) - return [[[NSString alloc] initWithFormat:NSLocalizedString(@"UnderSec",@"Under %d seconds"),10] autorelease]; - return [[[NSString alloc] initWithString:NSLocalizedString(@"UnderMin",@"Under a minute")] autorelease]; - } - // seconds becomes minutes and we keep checking. - seconds = seconds/60; - if (seconds < 60) { - if (seconds < 2) - return [[[NSString alloc] initWithString:NSLocalizedString(@"AboutMin",@"About a minute")] autorelease]; - // OK, tell the good people how much time we have left. - return [[[NSString alloc] initWithFormat:NSLocalizedString(@"AboutMins",@"About %d minutes"),seconds] autorelease]; - } - //this download will never seemingly never end. now seconds become hours. - seconds = seconds/60; - if (seconds < 2) - return [[[NSString alloc] initWithString:NSLocalizedString(@"AboutHour",@"Over an hour")] autorelease]; - return [[[NSString alloc] initWithFormat:NSLocalizedString(@"AboutHours",@"Over %d hours"),seconds] autorelease]; -} - - --(NSString *)formatBytes:(float)bytes -{ // this is simpler than my first try. I peaked at Omnigroup byte formatting code. - // if bytes are negative, we return question marks. - if (bytes < 0) - return [[[NSString alloc] initWithString:@"???"] autorelease]; - // bytes first. - if (bytes < 1024) - return [[[NSString alloc] initWithFormat:@"%.1f bytes",bytes] autorelease]; - // kb - bytes = bytes/1024; - if (bytes < 1024) - return [[[NSString alloc] initWithFormat:@"%.1f KB",bytes] autorelease]; - // mb - bytes = bytes/1024; - if (bytes < 1024) - return [[[NSString alloc] initWithFormat:@"%.1f MB",bytes] autorelease]; - // gb - bytes = bytes/1024; - return [[[NSString alloc] initWithFormat:@"%.1f GB",bytes] autorelease]; -} - -// this handles lots of things. -- (void)setDownloadProgress:(NSTimer *)downloadTimer; -{ - // XXX this logic needs cleaning up. - - // Ack! we're closing the window with the download still running! - if (mDownloadIsComplete) - { - [[self window] performClose:self]; - return; - } - // get the elapsed time - NSArray *elapsedTimeArray = [[mElapsedTimeLabel stringValue] componentsSeparatedByString:@":"]; - int j = [elapsedTimeArray count]; - int elapsedSec = [[elapsedTimeArray objectAtIndex:(j-1)] intValue] + [[elapsedTimeArray objectAtIndex:(j-2)] intValue]*60; - if (j==3) // this download is taking forever. - elapsedSec += [[elapsedTimeArray objectAtIndex:0] intValue]*3600; - // update elapsed time - [mElapsedTimeLabel setStringValue:[self formatTime:(++elapsedSec)]]; - // for status field & time left - float maxBytes = ([mProgressBar maxValue]); - float byteSec = mCurrentProgress/elapsedSec; - // OK - if downloadTimer is nil, we're done - fix maxBytes value for status report. - if (!downloadTimer) - maxBytes = mCurrentProgress; - // update status field - NSString *labelString = NSLocalizedString(@"LabelString",@"%@ of %@ total (at %@/sec)"); - [mStatusLabel setStringValue: [NSString stringWithFormat:labelString, [self formatBytes:mCurrentProgress], [self formatBytes:maxBytes], [self formatBytes:byteSec]]]; - // updating estimated time left field - // if maxBytes < 0, can't calc time left. - // if !downloadTimer, download is finished. either way, make sure time left is 0. - if ((maxBytes > 0) && (downloadTimer)) - { - int secToGo = (int)ceil((elapsedSec*maxBytes/mCurrentProgress) - elapsedSec); - [mTimeLeftLabel setStringValue:[self formatFuzzyTime:secToGo]]; - } - else if (!downloadTimer) - { // download done. Set remaining time to 0, fix progress bar & cancel button - mDownloadIsComplete = YES; // all done. we got a STATE_STOP - [mTimeLeftLabel setStringValue:@""]; - [self setProgressTo:mCurrentProgress ofMax:mCurrentProgress]; - if (!mSaveFileDialogShouldStayOpen) - [[self window] performClose:self]; // close window - else - [[self window] update]; // redraw window - } - else //maxBytes is undetermined. Set remaining time to question marks. - [mTimeLeftLabel setStringValue:@"???"]; -} - -#pragma mark - - -// DownloadProgressDisplay protocol methods - -- (void)onStartDownload:(BOOL)isFileSave; -{ - mIsFileSave = isFileSave; - - [self window]; // make the window - [[self window] setFrameUsingName: ProgressWindowFrameSaveName]; - - [self showWindow: self]; - [self setupDownloadTimer]; -} - -- (void)onEndDownload -{ - // if we're quitting, our progress window is already gone and we're in the - // process of shutting down gecko and all the d/l listeners. The timer, at - // that point, is the only thing keeping us alive. Killing it will cause - // us to go away immediately, so kung-fu deathgrip it until we're done twiddling - // bits on ourself. - [self retain]; // Enter The Dragon! - [self killDownloadTimer]; - [self setDownloadProgress:nil]; - [self release]; -} - -- (void)setProgressTo:(long)aCurProgress ofMax:(long)aMaxProgress -{ - mCurrentProgress = aCurProgress; // fall back for stat calcs - - if (![mProgressBar isIndeterminate]) //most likely - just update value - { - if (aCurProgress == aMaxProgress) //handles little bug in FTP download size - [mProgressBar setMaxValue:aMaxProgress]; - - [mProgressBar setDoubleValue:aCurProgress]; - } - else if (aMaxProgress > 0) // ok, we're starting up with good max & cur values - { - [mProgressBar setIndeterminate:NO]; - [mProgressBar setMaxValue:aMaxProgress]; - [mProgressBar setDoubleValue:aCurProgress]; - } // if neither case was true, it's barber pole city. -} - --(void) setDownloadListener: (CHDownloader*)aDownloader -{ - if (mDownloader != aDownloader) - NS_IF_RELEASE(mDownloader); - - NS_IF_ADDREF(mDownloader = aDownloader); -} - -- (void)setSourceURL:(NSString*)aSourceURL -{ - [mFromField setStringValue: aSourceURL]; - [mFromField display]; // force an immmeditate update -} - -- (void)setDestinationPath:(NSString*)aDestPath -{ - [mToField setStringValue: [aDestPath stringByAbbreviatingWithTildeInPath]]; - [mToField display]; // force an immmeditate update - - // also set the window title - NSString* downloadFileName = [aDestPath lastPathComponent]; - if ([downloadFileName length] == 0) - downloadFileName = aDestPath; - - [[self window] setTitle:[NSString stringWithFormat:NSLocalizedString(@"DownloadingTitle", @""), downloadFileName]]; -} - -@end diff --git a/mozilla/chimera/RemoteDataProvider.h b/mozilla/chimera/RemoteDataProvider.h deleted file mode 100644 index 13ff9a3af4a..00000000000 --- a/mozilla/chimera/RemoteDataProvider.h +++ /dev/null @@ -1,90 +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): - * Simon Fraser - * - * 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 - - -extern NSString* RemoteDataLoadRequestNotificationName; -extern NSString* RemoteDataLoadRequestURIKey; -extern NSString* RemoteDataLoadRequestDataKey; -extern NSString* RemoteDataLoadRequestUserDataKey; -extern NSString* RemoteDataLoadRequestResultKey; - -// RemoteDataProvider is a class that can be used to do asynchronous loads -// from URIs using necko, and passing back the result of the load to a -// callback in NSData. -// -// Clients can either implement the RemoteLoadListener protocol and call -// loadURI directly, or they can register with the [NSNotification defaultCenter] -// for 'RemoteDataLoadRequestNotificationName' notifications, and catch all loads -// that happen that way. - -@protocol RemoteLoadListener -// called when the load completes, or fails. If the status code is a failure code, -// data may be nil. -- (void)doneRemoteLoad:(NSString*)inURI forTarget:(id)target withUserData:(id)userData data:(NSData*)data status:(nsresult)status; -@end - - -class RemoteURILoadManager; - -@interface RemoteDataProvider : NSObject -{ - RemoteURILoadManager* mLoadManager; -} - -+ (RemoteDataProvider*)sharedRemoteDataProvider; - -// generic method. You can load any URI asynchronously with this selector, -// and the listener will get the contents of the URI in an NSData. -// If allowNetworking is NO, then this method will just check the cache, -// and not go to the network -// This method will return YES if the request was dispatched, or NO otherwise. -- (BOOL)loadURI:(NSString*)inURI forTarget:(id)target withListener:(id)inListener - withUserData:(id)userData allowNetworking:(BOOL)inNetworkOK; - -// specific request to load a remote file. The sender (or any other object), if -// registered with the notification center, will receive a notification when -// the load completes. The 'target' becomes the 'object' of the notification. -// The notification name is given by NSString* RemoteDataLoadRequestNotificationName above. -// If allowNetworking is NO, then this method will just check the cache, -// and not go to the network -// This method will return YES if the request was dispatched, or NO otherwise. -- (BOOL)postURILoadRequest:(NSString*)inURI forTarget:(id)target - withUserData:(id)userData allowNetworking:(BOOL)inNetworkOK; - -@end diff --git a/mozilla/chimera/RemoteDataProvider.mm b/mozilla/chimera/RemoteDataProvider.mm deleted file mode 100644 index 9bd81c14650..00000000000 --- a/mozilla/chimera/RemoteDataProvider.mm +++ /dev/null @@ -1,299 +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): - * Simon Fraser - * - * 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 "NSString+Utils.h" - -#import "RemoteDataProvider.h" - -#include "nsISupports.h" -#include "nsHashtable.h" -#include "nsNetUtil.h" -#include "nsICacheSession.h" -#include "nsICacheService.h" -#include "nsICacheEntryDescriptor.h" - -NSString* RemoteDataLoadRequestNotificationName = @"remoteload_notification_name"; -NSString* RemoteDataLoadRequestURIKey = @"remoteload_uri_key"; -NSString* RemoteDataLoadRequestDataKey = @"remoteload_data_key"; -NSString* RemoteDataLoadRequestUserDataKey = @"remoteload_user_data_key"; -NSString* RemoteDataLoadRequestResultKey = @"remoteload_result_key"; - - -// this has to retain the load listener, to ensure that the listener lives long -// enough to receive notifications. We have to be careful to avoid ref cycles. -class StreamLoaderContext : public nsISupports -{ -public: - StreamLoaderContext(id inLoadListener, id inUserData, id inTarget, const nsAString& inURI) - : mLoadListener(inLoadListener) - , mTarget(inTarget) - , mUserData(inUserData) - , mURI(inURI) - { - NS_INIT_ISUPPORTS(); - [mLoadListener retain]; - } - - virtual ~StreamLoaderContext() - { - [mLoadListener release]; - } - - NS_DECL_ISUPPORTS - - void LoadComplete(nsresult inLoadStatus, const void* inData, unsigned int inDataLength); - const nsAString& GetURI() { return mURI; } - -protected: - - id mLoadListener; // retained - id mTarget; // not retained - id mUserData; // not retained - nsString mURI; - -}; - - -NS_IMPL_ISUPPORTS1(StreamLoaderContext, nsISupports) - -void StreamLoaderContext::LoadComplete(nsresult inLoadStatus, const void* inData, unsigned int inDataLength) -{ - if (mLoadListener) - { - NSData* loadData = nil; - if (NS_SUCCEEDED(inLoadStatus)) - loadData = [NSData dataWithBytes:inData length:inDataLength]; - - [mLoadListener doneRemoteLoad:[NSString stringWith_nsAString:mURI] forTarget:mTarget withUserData:mUserData data:loadData status:inLoadStatus]; - } -} - - -class RemoteURILoadManager : public nsIStreamLoaderObserver -{ -public: - - RemoteURILoadManager(); - virtual ~RemoteURILoadManager(); - - NS_DECL_ISUPPORTS - NS_DECL_NSISTREAMLOADEROBSERVER - - nsresult Init(); - nsresult RequestURILoad(const nsAString& inURI, id loadListener, id userData, id target, PRBool allowNetworking); - -protected: - - nsSupportsHashtable mStreamLoaderHash; // hash of active stream loads, keyed on URI - nsCOMPtr mCacheSession; - -}; - -RemoteURILoadManager::RemoteURILoadManager() -{ - NS_INIT_ISUPPORTS(); -} - -RemoteURILoadManager::~RemoteURILoadManager() -{ -} - -NS_IMPL_ISUPPORTS1(RemoteURILoadManager, nsIStreamLoaderObserver) - -NS_IMETHODIMP RemoteURILoadManager::OnStreamComplete(nsIStreamLoader *loader, nsISupports *ctxt, nsresult status, PRUint32 resultLength, const char *result) -{ - StreamLoaderContext* loaderContext = NS_STATIC_CAST(StreamLoaderContext*, ctxt); - if (loaderContext) - { - loaderContext->LoadComplete(status, (const void*)result, resultLength); - - // remove the stream loader from the hash table - nsStringKey uriKey(loaderContext->GetURI()); - PRBool removed = mStreamLoaderHash.Remove(&uriKey); - } - - return NS_OK; -} - -static NS_DEFINE_CID(kCacheServiceCID, NS_CACHESERVICE_CID); - -nsresult RemoteURILoadManager::Init() -{ - nsresult rv; - nsCOMPtr cacheService = do_GetService(kCacheServiceCID, &rv); - if (NS_FAILED(rv)) - return rv; - - rv = cacheService->CreateSession("HTTP", nsICache::STORE_ANYWHERE, - nsICache::STREAM_BASED, getter_AddRefs(mCacheSession)); - - return rv; -} - -nsresult RemoteURILoadManager::RequestURILoad(const nsAString& inURI, id loadListener, - id userData, id target, PRBool allowNetworking) -{ - nsresult rv; - -#if 0 - // if no networking is allowed, make sure it's in the cache - if (!allowNetworking) - { - if (!mCacheSession) - return NS_ERROR_FAILURE; - - nsCOMPtr entryDesc; - rv = mCacheSession->OpenCacheEntry(NS_ConvertUCS2toUTF8(inURI).get(), nsICache::ACCESS_READ, nsICache::NON_BLOCKING, getter_AddRefs(entryDesc)); - if (NS_FAILED(rv) || !entryDesc) - return NS_ERROR_FAILURE; - } -#endif - - nsStringKey uriKey(inURI); - - // first make sure that there isn't another entry in the hash for this - nsCOMPtr foundStreamSupports = mStreamLoaderHash.Get(&uriKey); - if (foundStreamSupports) - return NS_OK; - - nsCOMPtr uri; - rv = NS_NewURI(getter_AddRefs(uri), inURI); - if (NS_FAILED(rv)) - return rv; - - nsCOMPtr loaderContext = new StreamLoaderContext(loadListener, userData, target, inURI); - - nsLoadFlags loadFlags = (allowNetworking) ? nsIRequest::LOAD_NORMAL : nsIRequest::LOAD_FROM_CACHE; - loadFlags |= nsIRequest::LOAD_BACKGROUND; // don't show progress or cookie dialogs - nsCOMPtr streamLoader; - rv = NS_NewStreamLoader(getter_AddRefs(streamLoader), uri, this, loaderContext, nsnull, nsnull, loadFlags); - if (NS_FAILED(rv)) - { - NSLog(@"NS_NewStreamLoader for favicon failed"); - return rv; - } - -#ifdef DEBUG_smfr - NSLog(@"RequestURILoad called for %@", [NSString stringWith_nsAString: inURI]); -#endif - - // put the stream loader into the hash table - nsCOMPtr streamLoaderAsSupports = do_QueryInterface(streamLoader); - mStreamLoaderHash.Put(&uriKey, streamLoaderAsSupports); - - return NS_OK; -} - - -#pragma mark - - - -@implementation RemoteDataProvider - - -+ (RemoteDataProvider*)sharedRemoteDataProvider -{ - static RemoteDataProvider* sIconProvider = nil; - if (!sIconProvider) - { - sIconProvider = [[RemoteDataProvider alloc] init]; - - // we probably need to register for NSApplicationWillTerminateNotification notifications - // and delete this then. - } - - return sIconProvider; -} - -- (id)init -{ - if ((self = [super init])) - { - mLoadManager = new RemoteURILoadManager; - NS_ADDREF(mLoadManager); - } - - return self; -} - -- (void)dealloc -{ - NS_IF_RELEASE(mLoadManager); - [super dealloc]; -} - -- (BOOL)loadURI:(NSString*)inURI forTarget:(id)target withListener:(id)inListener - withUserData:(id)userData allowNetworking:(BOOL)inNetworkOK -{ - //NSLog(@"loadURI called with %@", inURI); - if (mLoadManager && [inURI length] > 0) - { - nsAutoString uriString; - [inURI assignTo_nsAString:uriString]; - - nsresult rv = mLoadManager->RequestURILoad(uriString, inListener, userData, target, (PRBool)inNetworkOK); - if (NS_FAILED(rv)) - { - NSLog(@"RequestURILoad failed for @%", inURI); - return NO; - } - } - - return YES; -} - -- (BOOL)postURILoadRequest:(NSString*)inURI forTarget:(id)target withUserData:(id)userData allowNetworking:(BOOL)inNetworkOK -{ - return [self loadURI:inURI forTarget:target withListener:self withUserData:userData allowNetworking:inNetworkOK]; -} - -// our own load listener callback -- (void)doneRemoteLoad:(NSString*)inURI forTarget:(id)target withUserData:(id)userData data:(NSData*)data status:(nsresult)status -{ - NSDictionary* notificationData = [NSDictionary dictionaryWithObjectsAndKeys: - inURI, RemoteDataLoadRequestURIKey, - data, RemoteDataLoadRequestDataKey, - userData, RemoteDataLoadRequestUserDataKey, - [NSNumber numberWithInt:status], RemoteDataLoadRequestResultKey, - nil]; - - // NSLog(@"remoteLoadDone with status %d and length %d", status, [data length]); - [[NSNotificationCenter defaultCenter] postNotificationName: RemoteDataLoadRequestNotificationName - object:target userInfo:notificationData]; -} - -@end diff --git a/mozilla/chimera/SaveHeaderSniffer.h b/mozilla/chimera/SaveHeaderSniffer.h deleted file mode 100644 index 2fcbc55a554..00000000000 --- a/mozilla/chimera/SaveHeaderSniffer.h +++ /dev/null @@ -1,84 +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): - * David Hyatt - * Simon Fraser - * - * 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 -#import - -#include "nsString.h" -#include "nsIWebProgressListener.h" -#include "nsIWebBrowserPersist.h" -#include "nsIURI.h" -#include "nsILocalFile.h" -#include "nsIInputStream.h" -#include "nsIDOMDocument.h" - - -// Implementation of a header sniffer class that is used when saving Web pages and images. -class nsHeaderSniffer : public nsIWebProgressListener -{ -public: - nsHeaderSniffer(nsIWebBrowserPersist* aPersist, nsIFile* aFile, nsIURI* aURL, - nsIDOMDocument* aDocument, nsIInputStream* aPostData, - const nsCString& aSuggestedFilename, PRBool aBypassCache, - NSView* aFilterView, NSPopUpButton* aFilterList); - virtual ~nsHeaderSniffer(); - - NS_DECL_ISUPPORTS - NS_DECL_NSIWEBPROGRESSLISTENER - -protected: - - nsresult PerformSave(nsIURI* inOriginalURI); - nsresult InitiateDownload(nsISupports* inSourceData, nsString& inFileName, nsIURI* inOriginalURI); - -private: - - nsIWebBrowserPersist* mPersist; // Weak. It owns us as a listener. - nsCOMPtr mTmpFile; - nsCOMPtr mURL; - nsCOMPtr mDocument; - nsCOMPtr mPostData; - nsCString mDefaultFilename; - PRBool mBypassCache; - nsCString mContentType; - nsCString mContentDisposition; - NSView* mFilterView; - NSPopUpButton* mFilterList; -}; - diff --git a/mozilla/chimera/SaveHeaderSniffer.mm b/mozilla/chimera/SaveHeaderSniffer.mm deleted file mode 100644 index b4fa380e314..00000000000 --- a/mozilla/chimera/SaveHeaderSniffer.mm +++ /dev/null @@ -1,386 +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): - * David Hyatt - * Simon Fraser - * - * 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 ***** */ - -#include "SaveHeaderSniffer.h" - -#include "netCore.h" - -#include "nsIChannel.h" -#include "nsIHttpChannel.h" -#include "nsIURL.h" -#include "nsIPrefService.h" -#include "nsIMIMEService.h" -#include "nsIMIMEInfo.h" -#include "nsIDOMHTMLDocument.h" -#include "nsIDownload.h" - -const char* const persistContractID = "@mozilla.org/embedding/browser/nsWebBrowserPersist;1"; - -nsHeaderSniffer::nsHeaderSniffer(nsIWebBrowserPersist* aPersist, nsIFile* aFile, nsIURI* aURL, - nsIDOMDocument* aDocument, nsIInputStream* aPostData, - const nsCString& aSuggestedFilename, PRBool aBypassCache, - NSView* aFilterView, NSPopUpButton* aFilterList) -: mPersist(aPersist) -, mTmpFile(aFile) -, mURL(aURL) -, mDocument(aDocument) -, mPostData(aPostData) -, mDefaultFilename(aSuggestedFilename) -, mBypassCache(aBypassCache) -, mFilterView(aFilterView) -, mFilterList(aFilterList) -{ - NS_INIT_ISUPPORTS(); -} - -nsHeaderSniffer::~nsHeaderSniffer() -{ -} - -NS_IMPL_ISUPPORTS1(nsHeaderSniffer, nsIWebProgressListener) - -#pragma mark - - -// Implementation of nsIWebProgressListener -/* void onStateChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in long aStateFlags, in unsigned long aStatus); */ -NS_IMETHODIMP -nsHeaderSniffer::OnStateChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, PRUint32 aStateFlags, - PRUint32 aStatus) -{ - if (aStateFlags & nsIWebProgressListener::STATE_START) - { - nsCOMPtr kungFuDeathGrip(mPersist); // be sure to keep it alive while we save - // since it owns us as a listener - nsCOMPtr kungFuSuicideGrip(this); // and keep ourslves alive - - nsresult rv; - nsCOMPtr channel = do_QueryInterface(aRequest, &rv); - if (!channel) return rv; - channel->GetContentType(mContentType); - - nsCOMPtr origURI; - channel->GetOriginalURI(getter_AddRefs(origURI)); - - // Get the content-disposition if we're an HTTP channel. - nsCOMPtr httpChannel(do_QueryInterface(channel)); - if (httpChannel) - httpChannel->GetResponseHeader(nsCAutoString("content-disposition"), mContentDisposition); - - mPersist->CancelSave(); - PRBool exists; - mTmpFile->Exists(&exists); - if (exists) - mTmpFile->Remove(PR_FALSE); - - rv = PerformSave(origURI); - if (NS_FAILED(rv)) - { - // put up some UI - NSLog(@"Error saving web page"); - } - } - return NS_OK; -} - -/* void onProgressChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in long aCurSelfProgress, in long aMaxSelfProgress, in long aCurTotalProgress, in long aMaxTotalProgress); */ -NS_IMETHODIMP -nsHeaderSniffer::OnProgressChange(nsIWebProgress *aWebProgress, - nsIRequest *aRequest, - PRInt32 aCurSelfProgress, - PRInt32 aMaxSelfProgress, - PRInt32 aCurTotalProgress, - PRInt32 aMaxTotalProgress) -{ - return NS_OK; -} - -/* void onLocationChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in nsIURI location); */ -NS_IMETHODIMP -nsHeaderSniffer::OnLocationChange(nsIWebProgress *aWebProgress, - nsIRequest *aRequest, - nsIURI *location) -{ - return NS_OK; -} - -/* void onStatusChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in nsresult aStatus, in wstring aMessage); */ -NS_IMETHODIMP -nsHeaderSniffer::OnStatusChange(nsIWebProgress *aWebProgress, - nsIRequest *aRequest, - nsresult aStatus, - const PRUnichar *aMessage) -{ - return NS_OK; -} - -/* void onSecurityChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in unsigned long state); */ -NS_IMETHODIMP -nsHeaderSniffer::OnSecurityChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, PRUint32 state) -{ - return NS_OK; -} - -#pragma mark - - - -nsresult nsHeaderSniffer::PerformSave(nsIURI* inOriginalURI) -{ - nsresult rv; - // Are we an HTML document? If so, we will want to append an accessory view to - // the save dialog to provide the user with the option of doing a complete - // save vs. a single file save. - PRBool isHTML = (mDocument && mContentType.Equals("text/html") || - mContentType.Equals("text/xml") || - mContentType.Equals("application/xhtml+xml")); - - // Next find out the directory that we should start in. - nsCOMPtr prefs(do_GetService("@mozilla.org/preferences-service;1", &rv)); - if (!prefs) - return rv; - nsCOMPtr dirBranch; - prefs->GetBranch("browser.download.", getter_AddRefs(dirBranch)); - PRInt32 filterIndex = 0; - if (dirBranch) { - nsresult rv = dirBranch->GetIntPref("save_converter_index", &filterIndex); - if (NS_FAILED(rv)) - filterIndex = 0; - } - if (mFilterList) - [mFilterList selectItemAtIndex: filterIndex]; - - // We need to figure out what file name to use. - nsCAutoString defaultFileName; - if (!mContentDisposition.IsEmpty()) { - // (1) Use the HTTP header suggestion. - PRInt32 index = mContentDisposition.Find("filename="); - if (index >= 0) { - // Take the substring following the prefix. - index += 9; - nsCAutoString filename; - mContentDisposition.Right(filename, mContentDisposition.Length() - index); - defaultFileName = filename; - } - } - - if (defaultFileName.IsEmpty()) { - nsCOMPtr url(do_QueryInterface(mURL)); - if (url) - url->GetFileName(defaultFileName); // (2) For file URLs, use the file name. - } - - if (defaultFileName.IsEmpty() && mDocument && isHTML) { - nsCOMPtr htmlDoc(do_QueryInterface(mDocument)); - nsAutoString title; - if (htmlDoc) - htmlDoc->GetTitle(title); // (3) Use the title of the document. - defaultFileName.AssignWithConversion(title); - } - - if (defaultFileName.IsEmpty()) { - // (4) Use the caller provided name. - defaultFileName = mDefaultFilename; - } - - if (defaultFileName.IsEmpty() && mURL) - // (5) Use the host. - mURL->GetHost(defaultFileName); - - // One last case to handle about:blank and other fruity untitled pages. - if (defaultFileName.IsEmpty()) - defaultFileName = "untitled"; - - // Validate the file name to ensure legality. - for (PRUint32 i = 0; i < defaultFileName.Length(); i++) - if (defaultFileName[i] == ':' || defaultFileName[i] == '/') - defaultFileName.SetCharAt(i, ' '); - - // Make sure the appropriate extension is appended to the suggested file name. - nsCOMPtr fileURI(do_CreateInstance("@mozilla.org/network/standard-url;1")); - nsCOMPtr fileURL(do_QueryInterface(fileURI, &rv)); - if (!fileURL) - return rv; - fileURL->SetFilePath(defaultFileName); - - nsCAutoString fileExtension; - fileURL->GetFileExtension(fileExtension); - - PRBool setExtension = PR_FALSE; - if (mContentType.Equals("text/html")) { - if (fileExtension.IsEmpty() || (!fileExtension.Equals("htm") && !fileExtension.Equals("html"))) { - defaultFileName += ".html"; - setExtension = PR_TRUE; - } - } - - if (!setExtension && fileExtension.IsEmpty()) { - nsCOMPtr mimeService(do_GetService("@mozilla.org/mime;1", &rv)); - if (!mimeService) - return rv; - nsCOMPtr mimeInfo; - rv = mimeService->GetFromMIMEType(mContentType.get(), getter_AddRefs(mimeInfo)); - if (!mimeInfo) - return rv; - - PRUint32 extCount = 0; - char** extList = nsnull; - mimeInfo->GetFileExtensions(&extCount, &extList); - if (extCount > 0 && extList) { - defaultFileName += "."; - defaultFileName += extList[0]; - } - } - - // Now it's time to pose the save dialog. - NSSavePanel* savePanel = [NSSavePanel savePanel]; - NSString* file = nil; - if (!defaultFileName.IsEmpty()) - file = [[NSString alloc] initWithCString: defaultFileName.get()]; - - if (isHTML) - [savePanel setAccessoryView: mFilterView]; - - if ([savePanel runModalForDirectory: nil file: file] == NSFileHandlingPanelCancelButton) - return NS_OK; - - // Release the file string. - [file release]; - - // Update the filter index. - if (isHTML && mFilterList) { - filterIndex = [mFilterList indexOfSelectedItem]; - dirBranch->SetIntPref("save_converter_index", filterIndex); - } - - // Convert the content type to text/plain if it was selected in the filter. - if (isHTML && filterIndex == 2) - mContentType = "text/plain"; - - nsCOMPtr sourceData; - if (isHTML && filterIndex != 1) - sourceData = do_QueryInterface(mDocument); - else - sourceData = do_QueryInterface(mURL); - - NSString* destName = [savePanel filename]; - - PRUint32 dstLen = [destName length]; - PRUnichar* tmp = new PRUnichar[dstLen + sizeof(PRUnichar)]; - tmp[dstLen] = (PRUnichar)'\0'; - [destName getCharacters:tmp]; - nsAutoString dstString(tmp); - delete tmp; - - return InitiateDownload(sourceData, dstString, inOriginalURI); -} - -// inOriginalURI is always a URI. inSourceData can be an nsIURI or an nsIDOMDocument, depending -// on what we're saving. It's that way for nsIWebBrowserPersist. -nsresult nsHeaderSniffer::InitiateDownload(nsISupports* inSourceData, nsString& inFileName, nsIURI* inOriginalURI) -{ - nsresult rv = NS_OK; - - nsCOMPtr webPersist = do_CreateInstance(persistContractID, &rv); - if (NS_FAILED(rv)) return rv; - - nsCOMPtr sourceURI = do_QueryInterface(inSourceData); - - nsCOMPtr destFile; - rv = NS_NewLocalFile(inFileName, PR_FALSE, getter_AddRefs(destFile)); - if (NS_FAILED(rv)) return rv; - - PRInt64 timeNow = PR_Now(); - - nsCOMPtr downloader = do_CreateInstance(NS_DOWNLOAD_CONTRACTID); - // dlListener attaches to its progress dialog here, which gains ownership - rv = downloader->Init(inOriginalURI, destFile, inFileName.get(), nsString().get(), timeNow, webPersist); - if (NS_FAILED(rv)) return rv; - - PRInt32 flags = nsIWebBrowserPersist::PERSIST_FLAGS_NO_CONVERSION | - nsIWebBrowserPersist::PERSIST_FLAGS_REPLACE_EXISTING_FILES; - if (mBypassCache) - flags |= nsIWebBrowserPersist::PERSIST_FLAGS_BYPASS_CACHE; - else - flags |= nsIWebBrowserPersist::PERSIST_FLAGS_FROM_CACHE; - - if (sourceURI) - { - rv = webPersist->SaveURI(sourceURI, mPostData, destFile); - } - else - { - nsCOMPtr domDoc = do_QueryInterface(inSourceData, &rv); - if (!domDoc) return rv; // should never happen - - PRInt32 encodingFlags = 0; - nsCOMPtr filesFolder; - - if (!mContentType.Equals("text/plain")) { - // Create a local directory in the same dir as our file. It - // will hold our associated files. - filesFolder = do_CreateInstance("@mozilla.org/file/local;1"); - nsAutoString unicodePath; - destFile->GetPath(unicodePath); - filesFolder->InitWithPath(unicodePath); - - nsAutoString leafName; - filesFolder->GetLeafName(leafName); - nsAutoString nameMinusExt(leafName); - PRInt32 index = nameMinusExt.RFind("."); - if (index >= 0) - nameMinusExt.Left(nameMinusExt, index); - nameMinusExt += NS_LITERAL_STRING(" Files"); // XXXdwh needs to be localizable! - filesFolder->SetLeafName(nameMinusExt); - PRBool exists = PR_FALSE; - filesFolder->Exists(&exists); - if (!exists) { - rv = filesFolder->Create(nsILocalFile::DIRECTORY_TYPE, 0755); - if (NS_FAILED(rv)) - return rv; - } - } - else - { - encodingFlags |= nsIWebBrowserPersist::ENCODE_FLAGS_FORMATTED | - nsIWebBrowserPersist::ENCODE_FLAGS_ABSOLUTE_LINKS | - nsIWebBrowserPersist::ENCODE_FLAGS_NOFRAMES_CONTENT; - } - rv = webPersist->SaveDocument(domDoc, destFile, filesFolder, mContentType.get(), encodingFlags, 80); - } - - return rv; -} diff --git a/mozilla/chimera/SecurityDialogs.h b/mozilla/chimera/SecurityDialogs.h deleted file mode 100644 index 0b27200ad47..00000000000 --- a/mozilla/chimera/SecurityDialogs.h +++ /dev/null @@ -1,70 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** 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 mozilla.org 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): - * Brian Ryner - * - * 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 ***** */ - -#ifndef __SecurityDialogs_h__ -#define __SecurityDialogs_h__ - -#include "nsIBadCertListener.h" -#include "nsISecurityWarningDialogs.h" -#include "nsINSSDialogs.h" -#include "nsIStringBundle.h" - -class SecurityDialogs : public nsIBadCertListener, - public nsISecurityWarningDialogs, - public nsINSSDialogs -{ -public: - SecurityDialogs(); - virtual ~SecurityDialogs(); - - NS_DECL_ISUPPORTS; - NS_DECL_NSIBADCERTLISTENER; - NS_DECL_NSISECURITYWARNINGDIALOGS; - NS_DECL_NSINSSDIALOGS; - -private: - nsresult EnsureSecurityStringBundle(); - - nsresult AlertDialog(nsIInterfaceRequestor* ctx, const char* prefName, - const PRUnichar* messageName, - const PRUnichar* showAgainName); - - nsCOMPtr mSecurityStringBundle; -}; - -#endif diff --git a/mozilla/chimera/SecurityDialogs.mm b/mozilla/chimera/SecurityDialogs.mm deleted file mode 100644 index a07700a153b..00000000000 --- a/mozilla/chimera/SecurityDialogs.mm +++ /dev/null @@ -1,278 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** 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 mozilla.org 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): - * Brian Ryner - * - * 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 "nsAlertController.h" -#import "nsCocoaBrowserService.h" -#import "SecurityDialogs.h" -#import "MainController.h" - -#include "nsString.h" -#include "nsIPrefBranch.h" -#include "nsIPrompt.h" -#include "nsIInterfaceRequestor.h" -#include "nsIInterfaceRequestorUtils.h" -#include "nsIServiceManagerUtils.h" - -SecurityDialogs::SecurityDialogs() -{ - NS_INIT_ISUPPORTS(); -} - -SecurityDialogs::~SecurityDialogs() -{ -} - -NS_IMPL_ISUPPORTS3(SecurityDialogs, nsIBadCertListener, - nsISecurityWarningDialogs, nsINSSDialogs); - -// nsIBadCertListener implementation -/* boolean unknownIssuer (in nsITransportSecurityInfo socketInfo, - in nsIX509Cert cert, out addType); */ -NS_IMETHODIMP -SecurityDialogs::UnknownIssuer(nsITransportSecurityInfo *socketInfo, - nsIX509Cert *cert, PRInt16 *outAddType, - PRBool *_retval) -{ - *_retval = PR_TRUE; - *outAddType = ADD_TRUSTED_FOR_SESSION; - - nsAlertController* controller = nsCocoaBrowserService::GetAlertController(); - if (!controller) - return NS_ERROR_FAILURE; - - // HACK: there is no way to get which window this is for from the API. The - // security team in mozilla just cheats and assumes the frontmost window so - // that's what we'll do. Yes, it's wrong. Yes, it's skanky. Oh well. - *outAddType = (PRBool)[controller unknownCert:[(MainController*)[NSApp delegate] getFrontmostBrowserWindow]]; - switch ( *outAddType ) { - case nsIBadCertListener::ADD_TRUSTED_FOR_SESSION: - case nsIBadCertListener::ADD_TRUSTED_PERMANENTLY: - *_retval = PR_TRUE; - break; - default: - *_retval = PR_FALSE; - } - - return NS_OK; -} - -/* boolean mismatchDomain (in nsITransportSecurityInfo socketInfo, - in wstring targetURL, - in nsIX509Cert cert); */ -NS_IMETHODIMP -SecurityDialogs::MismatchDomain(nsITransportSecurityInfo *socketInfo, - const PRUnichar *targetURL, - nsIX509Cert *cert, PRBool *_retval) -{ - nsAlertController* controller = nsCocoaBrowserService::GetAlertController(); - if (!controller) - return NS_ERROR_FAILURE; - - // HACK: there is no way to get which window this is for from the API. The - // security team in mozilla just cheats and assumes the frontmost window so - // that's what we'll do. Yes, it's wrong. Yes, it's skanky. Oh well. - *_retval = (PRBool)[controller badCert:[(MainController*)[NSApp delegate] getFrontmostBrowserWindow]]; - - return NS_OK; -} - - -/* boolean certExpired (in nsITransportSecurityInfo socketInfo, - in nsIX509Cert cert); */ -NS_IMETHODIMP -SecurityDialogs::CertExpired(nsITransportSecurityInfo *socketInfo, - nsIX509Cert *cert, PRBool *_retval) -{ - nsAlertController* controller = nsCocoaBrowserService::GetAlertController(); - if (!controller) - return NS_ERROR_FAILURE; - - // HACK: there is no way to get which window this is for from the API. The - // security team in mozilla just cheats and assumes the frontmost window so - // that's what we'll do. Yes, it's wrong. Yes, it's skanky. Oh well. - *_retval = (PRBool)[controller expiredCert:[(MainController*)[NSApp delegate] getFrontmostBrowserWindow]]; - - return NS_OK; -} - -NS_IMETHODIMP -SecurityDialogs::CrlNextupdate(nsITransportSecurityInfo *socketInfo, - const PRUnichar * targetURL, nsIX509Cert *cert) -{ - // what does this do!? - return NS_OK; -} - - -// nsISecurityWarningDialogs implementation -#define ENTER_SITE_PREF "security.warn_entering_secure" -#define WEAK_SITE_PREF "security.warn_entering_weak" -#define LEAVE_SITE_PREF "security.warn_leaving_secure" - -#define MIXEDCONTENT_PREF "security.warn_viewing_mixed" -#define INSECURE_SUBMIT_PREF "security.warn_submit_insecure" - -NS_IMETHODIMP -SecurityDialogs::AlertEnteringSecure(nsIInterfaceRequestor *ctx) -{ - // I don't think any user cares they're entering a secure site. - #if 0 - rv = AlertDialog(ctx, ENTER_SITE_PREF, - NS_LITERAL_STRING("EnterSecureMessage").get(), - NS_LITERAL_STRING("EnterSecureShowAgain").get()); - #endif - - return NS_OK; -} - -NS_IMETHODIMP -SecurityDialogs::AlertEnteringWeak(nsIInterfaceRequestor *ctx) -{ - return AlertDialog(ctx, WEAK_SITE_PREF, - NS_LITERAL_STRING("WeakSecureMessage").get(), - NS_LITERAL_STRING("WeakSecureShowAgain").get()); -} - -NS_IMETHODIMP -SecurityDialogs::AlertLeavingSecure(nsIInterfaceRequestor *ctx) -{ - return AlertDialog(ctx, LEAVE_SITE_PREF, - NS_LITERAL_STRING("LeaveSecureMessage").get(), - NS_LITERAL_STRING("LeaveSecureShowAgain").get()); -} - - -NS_IMETHODIMP -SecurityDialogs::AlertMixedMode(nsIInterfaceRequestor *ctx) -{ - return AlertDialog(ctx, MIXEDCONTENT_PREF, - NS_LITERAL_STRING("MixedContentMessage").get(), - NS_LITERAL_STRING("MixedContentShowAgain").get()); -} - - -NS_IMETHODIMP -SecurityDialogs::ConfirmPostToInsecure(nsIInterfaceRequestor *ctx, - PRBool* _result) -{ - // no user cares about this. the first thing they do is turn it off. - *_result = PR_TRUE; - return NS_OK; -} - -NS_IMETHODIMP -SecurityDialogs::ConfirmPostToInsecureFromSecure(nsIInterfaceRequestor *ctx, - PRBool* _result) -{ - nsAlertController* controller = nsCocoaBrowserService::GetAlertController(); - if (!controller) - return NS_ERROR_FAILURE; - - // HACK: there is no way to get which window this is for from the API. The - // security team in mozilla just cheats and assumes the frontmost window so - // that's what we'll do. Yes, it's wrong. Yes, it's skanky. Oh well. - *_result = (PRBool)[controller postToInsecureFromSecure:[(MainController*)[NSApp delegate] getFrontmostBrowserWindow]]; - - return NS_OK; -} - - -// Private helper functions -nsresult -SecurityDialogs::EnsureSecurityStringBundle() -{ - if (!mSecurityStringBundle) { - #define STRING_BUNDLE_URL "chrome://communicator/locale/security.properties" - nsCOMPtr service = do_GetService(NS_STRINGBUNDLE_CONTRACTID); - if ( service ) { - nsresult rv = service->CreateBundle(STRING_BUNDLE_URL, getter_AddRefs(mSecurityStringBundle)); - if (NS_FAILED(rv)) return rv; - } - } - return NS_OK; -} - - -nsresult -SecurityDialogs::AlertDialog(nsIInterfaceRequestor *ctx, const char *prefName, - const PRUnichar *dialogMessageName, - const PRUnichar *showAgainName) -{ - nsresult rv = NS_OK; - - // Get user's preference for this alert - nsCOMPtr pref; - PRBool prefValue = PR_TRUE; - if ( prefName ) { - pref = do_GetService("@mozilla.org/preferences-service;1"); - if ( pref ) - pref->GetBoolPref(prefName, &prefValue); - - // Stop if alert is not requested - if (!prefValue) return NS_OK; - } - - if ( NS_FAILED(rv = EnsureSecurityStringBundle()) ) - return rv; - - // Get Prompt to use - nsCOMPtr prompt = do_GetInterface(ctx); - if (!prompt) return NS_ERROR_FAILURE; - - // Get messages strings from localization file - nsXPIDLString windowTitle, message, dontShowAgain; - mSecurityStringBundle->GetStringFromName(NS_LITERAL_STRING("Title").get(), - getter_Copies(windowTitle)); - mSecurityStringBundle->GetStringFromName(dialogMessageName, - getter_Copies(message)); - if ( prefName ) - mSecurityStringBundle->GetStringFromName(showAgainName, - getter_Copies(dontShowAgain)); - if (!windowTitle.get() || !message.get()) return NS_ERROR_FAILURE; - - if ( prefName ) - rv = prompt->AlertCheck(windowTitle, message, dontShowAgain, &prefValue); - else - rv = prompt->AlertCheck(windowTitle, message, nil, nil); - if (NS_FAILED(rv)) return rv; - - if (prefName && !prefValue) - pref->SetBoolPref(prefName, PR_FALSE); - - return rv; -} diff --git a/mozilla/chimera/SiteIconProvider.h b/mozilla/chimera/SiteIconProvider.h deleted file mode 100644 index 9cb0209c455..00000000000 --- a/mozilla/chimera/SiteIconProvider.h +++ /dev/null @@ -1,69 +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): - * Simon Fraser - * - * 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 - -#import "RemoteDataProvider.h" - -extern NSString* SiteIconLoadNotificationName; -extern NSString* SiteIconLoadImageKey; -extern NSString* SiteIconLoadURIKey; -extern NSString* SiteIconLoadUserDataKey; - -class NeckoCacheHelper; - -@interface SiteIconProvider : NSObject -{ - NeckoCacheHelper* mMissedIconsCacheHelper; -} - -+ (SiteIconProvider*)sharedFavoriteIconProvider; - -+ (NSString*)faviconLocationStringFromURI:(NSString*)inURI; - -// Start a favicon.ico load for the given URI, which can be any URI. -// The caller will get a 'SiteIconLoadNotificationName' notification -// when the load is done, with the image at the 'SiteIconLoadImageKey' key -// in the notifcation userInfo. The caller will have had to register with the -// NSNotifcationCenter in order to receive this notifcation. The notification -// is dispatched with 'sender' as the object. -// This method returns YES if the uri request was dispatched (i.e. if we know -// that we've looked for, and failed to find, this icon before). If it returns -// YES, then the 'SiteIconLoadNotificationName' notification will be sent out. -- (BOOL)loadFavoriteIcon:(id)sender forURI:(NSString *)inURI withUserData:(id)userData allowNetwork:(BOOL)inAllowNetwork; - -@end diff --git a/mozilla/chimera/SiteIconProvider.mm b/mozilla/chimera/SiteIconProvider.mm deleted file mode 100644 index b791935dcb8..00000000000 --- a/mozilla/chimera/SiteIconProvider.mm +++ /dev/null @@ -1,340 +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): - * Simon Fraser - * - * 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 "NSString+Utils.h" - -#import "SiteIconProvider.h" - -#include "prtime.h" -#include "nsString.h" -#include "nsISupports.h" -#include "nsNetUtil.h" -#include "nsICacheSession.h" -#include "nsICacheService.h" -#include "nsICacheEntryDescriptor.h" - - -NSString* SiteIconLoadNotificationName = @"siteicon_load_notification"; -NSString* SiteIconLoadImageKey = @"siteicon_load_image"; -NSString* SiteIconLoadURIKey = @"siteicon_load_uri"; -NSString* SiteIconLoadUserDataKey = @"siteicon_load_user_data"; - - -static inline PRUint32 PRTimeToSeconds(PRTime t_usec) -{ - PRTime usec_per_sec; - PRUint32 t_sec; - LL_I2L(usec_per_sec, PR_USEC_PER_SEC); - LL_DIV(t_usec, t_usec, usec_per_sec); - LL_L2I(t_sec, t_usec); - return t_sec; -} - -class NeckoCacheHelper -{ -public: - - NeckoCacheHelper(const char* inMetaElement, const char* inMetaValue); - ~NeckoCacheHelper() {} - - nsresult Init(const char* inCacheSessionName); - nsresult ExistsInCache(const nsACString& inURI, PRBool* outExists); - nsresult PutInCache(const nsACString& inURI, PRUint32 inExpirationTimeSeconds); - - nsresult ClearCache(); - -protected: - - const char* mMetaElement; - const char* mMetaValue; - nsCOMPtr mCacheSession; - -}; - -static NS_DEFINE_CID(kCacheServiceCID, NS_CACHESERVICE_CID); - -NeckoCacheHelper::NeckoCacheHelper(const char* inMetaElement, const char* inMetaValue) -: mMetaElement(inMetaElement) -, mMetaValue(inMetaValue) -{ -} - -nsresult NeckoCacheHelper::Init(const char* inCacheSessionName) -{ - nsresult rv; - - nsCOMPtr cacheService = do_GetService(kCacheServiceCID, &rv); - if (NS_FAILED(rv)) - return rv; - - rv = cacheService->CreateSession(inCacheSessionName, - nsICache::STORE_ANYWHERE, nsICache::STREAM_BASED, - getter_AddRefs(mCacheSession)); - if (NS_FAILED(rv)) - return rv; - - return NS_OK; -} - - -nsresult NeckoCacheHelper::ExistsInCache(const nsACString& inURI, PRBool* outExists) -{ - NS_ASSERTION(mCacheSession, "No cache session"); - - nsCOMPtr entryDesc; - nsresult rv = mCacheSession->OpenCacheEntry(PromiseFlatCString(inURI).get(), nsICache::ACCESS_READ, nsICache::NON_BLOCKING, getter_AddRefs(entryDesc)); - - *outExists = NS_SUCCEEDED(rv) && (entryDesc != NULL); - return NS_OK; -} - -nsresult NeckoCacheHelper::PutInCache(const nsACString& inURI, PRUint32 inExpirationTimeSeconds) -{ - NS_ASSERTION(mCacheSession, "No cache session"); - - nsCOMPtr entryDesc; - nsresult rv = mCacheSession->OpenCacheEntry(PromiseFlatCString(inURI).get(), nsICache::ACCESS_WRITE, nsICache::NON_BLOCKING, getter_AddRefs(entryDesc)); - if (NS_FAILED(rv) || !entryDesc) return rv; - - nsCacheAccessMode accessMode; - rv = entryDesc->GetAccessGranted(&accessMode); - if (NS_FAILED(rv)) - return rv; - - if (accessMode != nsICache::ACCESS_WRITE) - return NS_ERROR_FAILURE; - - entryDesc->SetMetaDataElement(mMetaElement, mMetaValue); // just set a bit of meta data. - entryDesc->SetExpirationTime(PRTimeToSeconds(PR_Now()) + inExpirationTimeSeconds); - - entryDesc->MarkValid(); - entryDesc->Close(); - - return NS_OK; -} - -nsresult NeckoCacheHelper::ClearCache() -{ - NS_ASSERTION(mCacheSession, "No cache session"); - - return mCacheSession->EvictEntries(); -} - - -#pragma mark - - -static nsresult MakeFaviconURIFromURI(const nsAString& inURIString, nsAString& outFaviconURI) -{ - outFaviconURI.Truncate(0); - - nsCOMPtr uri; - nsresult rv = NS_NewURI(getter_AddRefs(uri), inURIString); - if (NS_FAILED(rv)) - return rv; - - // check for http/https - PRBool isHTTP = PR_FALSE, isHTTPS = PR_FALSE; - uri->SchemeIs("http", &isHTTP); - uri->SchemeIs("https", &isHTTPS); - if (!isHTTP && !isHTTPS) - return NS_OK; - - PRInt32 port; - uri->GetPort(&port); - - nsXPIDLCString scheme; - uri->GetScheme(scheme); - - nsXPIDLCString host; - uri->GetHost(host); - - nsCAutoString faviconURI = scheme; - faviconURI.Append("://"); - faviconURI.Append(host); - if (port != -1) { - faviconURI.Append(':'); - faviconURI.AppendInt(port); - } - faviconURI.Append("/favicon.ico"); - - outFaviconURI.Assign(NS_ConvertUTF8toUCS2(faviconURI)); - return NS_OK; -} - - -@interface SiteIconProvider(Private) - -- (void)addToMissedIconsCache:(const nsAString&)inURI withExpirationSeconds:(unsigned int)inExpSeconds; -- (BOOL)inMissedIconsCache:(const nsAString&)inURI; - -@end - - -@implementation SiteIconProvider - -- (id)init -{ - if ((self = [super init])) - { - mMissedIconsCacheHelper = new NeckoCacheHelper("Favicon", "Missed"); - nsresult rv = mMissedIconsCacheHelper->Init("MissedIconsCache"); - if (NS_FAILED(rv)) { - delete mMissedIconsCacheHelper; - mMissedIconsCacheHelper = NULL; - } - } - - return self; -} - -- (void)dealloc -{ - delete mMissedIconsCacheHelper; - [super dealloc]; -} - -- (void)addToMissedIconsCache:(const nsAString&)inURI withExpirationSeconds:(unsigned int)inExpSeconds -{ - if (mMissedIconsCacheHelper) - { - nsresult rv = mMissedIconsCacheHelper->PutInCache(NS_ConvertUCS2toUTF8(inURI), inExpSeconds); - //NSLog(@"Putting %@ in missed icon cache", [NSString stringWith_nsAString:inURI]); - } - -} - -- (BOOL)inMissedIconsCache:(const nsAString&)inURI -{ - PRBool inCache = PR_FALSE; - - if (mMissedIconsCacheHelper) - mMissedIconsCacheHelper->ExistsInCache(NS_ConvertUCS2toUTF8(inURI), &inCache); - - //NSLog(@"%@ in missed icon cache: %d", [NSString stringWith_nsAString:inURI], inCache); - return inCache; -} - - -- (BOOL)loadFavoriteIcon:(id)sender forURI:(NSString *)inURI withUserData:(id)userData allowNetwork:(BOOL)inAllowNetwork -{ - // look for a favicon - nsAutoString uriString; - [inURI assignTo_nsAString:uriString]; - - nsAutoString faviconURIString; - MakeFaviconURIFromURI(uriString, faviconURIString); - if (faviconURIString.Length() == 0) - return NO; - - NSString* faviconString = [NSString stringWith_nsAString:faviconURIString]; - - // is this uri already in the missing icons cache? - if ([self inMissedIconsCache:faviconURIString]) - return NO; - - RemoteDataProvider* dataProvider = [RemoteDataProvider sharedRemoteDataProvider]; - return [dataProvider loadURI:faviconString forTarget:sender withListener:self withUserData:userData allowNetworking:inAllowNetwork]; -} - -#define SITE_ICON_EXPIRATION_SECONDS (60 * 60 * 24 * 7) // 1 week - -// this is called on the main thread -- (void)doneRemoteLoad:(NSString*)inURI forTarget:(id)target withUserData:(id)userData data:(NSData*)data status:(nsresult)status -{ - nsAutoString uriString; - [inURI assignTo_nsAString:uriString]; - - BOOL loadOK = NS_SUCCEEDED(status) && (data != nil); - - // it's hard to tell if the favicon load succeeded or not. Even if the file - // does not exist, servers will send back a 404 page with a 0 status. - // So we just go ahead and try to make the image; it will return nil on - // failure. - NSImage* faviconImage = nil; - - NS_DURING - faviconImage = [[NSImage alloc] initWithData:data]; - NS_HANDLER - NSLog(@"Exception \"%@ making\" favicon image for %@", localException, inURI); - faviconImage = nil; - NS_ENDHANDLER - - BOOL gotImageData = loadOK && (faviconImage != nil); - if (!gotImageData) - [self addToMissedIconsCache:uriString withExpirationSeconds:SITE_ICON_EXPIRATION_SECONDS]; - - [faviconImage setDataRetained:YES]; - [faviconImage setScalesWhenResized:YES]; - [faviconImage setSize:NSMakeSize(16, 16)]; - - // we always send out the notification, so that clients know - // about failed requests - NSDictionary* notificationData = [NSDictionary dictionaryWithObjectsAndKeys: - inURI, SiteIconLoadURIKey, - faviconImage, SiteIconLoadImageKey, // may be nil - userData, SiteIconLoadUserDataKey, - nil]; - - [[NSNotificationCenter defaultCenter] postNotificationName: SiteIconLoadNotificationName - object:target userInfo:notificationData]; -} - -#pragma mark - - -+ (SiteIconProvider*)sharedFavoriteIconProvider -{ - static SiteIconProvider* sIconProvider = nil; - if (!sIconProvider) - { - sIconProvider = [[SiteIconProvider alloc] init]; - } - - return sIconProvider; -} - - -+ (NSString*)faviconLocationStringFromURI:(NSString*)inURI -{ - nsAutoString uriString; - [inURI assignTo_nsAString:uriString]; - - nsAutoString faviconURIString; - MakeFaviconURIFromURI(uriString, faviconURIString); - return [NSString stringWith_nsAString:faviconURIString]; -} - -@end diff --git a/mozilla/chimera/ToolTip.h b/mozilla/chimera/ToolTip.h deleted file mode 100644 index 8167dd2e3bb..00000000000 --- a/mozilla/chimera/ToolTip.h +++ /dev/null @@ -1,52 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape 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/NPL/ - * - * 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 mozilla.org 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): Richard Schreyer - * - * 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 NPL, 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 NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#import - -@class ToolTipView; - -@interface ToolTip : NSObject -{ - NSPanel* mPanel; - NSTextField* mTextField; -} - -// it expects a point relative to the top left coordinate of the screen -- (void)showToolTipAtPoint:(NSPoint)point withString:(NSString*)string; -- (void)closeToolTip; - -@end diff --git a/mozilla/chimera/ToolTip.mm b/mozilla/chimera/ToolTip.mm deleted file mode 100644 index 7d46337df28..00000000000 --- a/mozilla/chimera/ToolTip.mm +++ /dev/null @@ -1,150 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape 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/NPL/ - * - * 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 mozilla.org 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): Richard Schreyer - * - * 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 NPL, 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 NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#import "ToolTip.h" -#import "NSScreen+Utils.h" - -@interface ToolTip (ToolTipPrivateMethods) - -@end - -const float kBorderPadding = 2.0; - -@implementation ToolTip - -- (id)init -{ - - self = [super init]; - if (self) { - mPanel = [[NSPanel alloc] initWithContentRect: NSMakeRect(0.0, 0.0, 200.0, 200.0) styleMask: NSBorderlessWindowMask backing: NSBackingStoreBuffered defer: YES]; - - // Create a textfield as the content of our new window. Autorelease it because the window will - // hold a ref when we add it as a subview. Field occupies all but the top 2 and bottom - // 2 pixels of the panel (bug 149635) - mTextField = [[[NSTextField alloc] initWithFrame: NSMakeRect(0.0, kBorderPadding, 200.0, 200 - 2*kBorderPadding)] autorelease]; - - [[mPanel contentView] addSubview: mTextField]; - [mPanel setHasShadow: YES]; - [mPanel setBackgroundColor: [NSColor colorWithCalibratedRed: 1.0 green: 1.0 blue: .81 alpha: 1.0]]; - - [mTextField setAutoresizingMask: NSViewWidthSizable | NSViewHeightSizable]; - [mTextField setDrawsBackground: NO]; - [mTextField setEditable: NO]; - [mTextField setSelectable: NO]; - [mTextField setFont: [NSFont toolTipsFontOfSize: [NSFont smallSystemFontSize]]]; - [mTextField setBezeled: NO]; - [mTextField setBordered: NO]; - } - return self; -} - -- (void)dealloc -{ - [mPanel close]; - [mPanel release]; - [super dealloc]; -} - -- (void)showToolTipAtPoint:(NSPoint)point withString:(NSString*)string -{ - if ([string length] == 0) - return; - - NSScreen* screen = [NSScreen screenForPoint: point]; - if (!screen) - screen = [NSScreen mainScreen]; - - if (screen) { - NSRect screenFrame = [screen visibleFrame]; - NSSize screenSize = screenFrame.size; - NSTextView* textView = [[[NSTextView alloc] initWithFrame: screenFrame] autorelease]; - - // find out how large the tooltip needs to be - - [textView setString: string]; - [textView setMinSize: NSMakeSize(0.0, 0.0)]; - [textView setMaxSize: screenSize]; - [textView setVerticallyResizable: YES]; - [textView setHorizontallyResizable: YES]; - [textView setFont: [NSFont toolTipsFontOfSize: [NSFont smallSystemFontSize]]]; - [textView sizeToFit]; - NSSize textSize = NSMakeSize( ceil( NSWidth([textView frame]) ), ceil( NSHeight([textView frame]) ) ); - - // adjust the size of the tooltip by a constant amount, as illustrated in bug 149635 - // specifically, add padding above and below the text, and remove 6 from the right side - // (six!? we're still not sure why it's six pixels too big. ideas are welcome). - - textSize.width -= 6; - textSize.height += kBorderPadding + kBorderPadding; - - // set up the panel - - [mTextField setStringValue: string]; - [mPanel setContentSize: textSize]; - - // the given point is right where the mouse pointer is. We want the tooltip's - // top left corner somewhere below that, but not if that'll put it off the monitor. There - // is no way that we can go off the top of the monitor because cocoa won't let us position a window - // that way - const int kVOffset = 20; - if ( point.y - kVOffset - textSize.height > NSMinY(screenFrame) ) - point.y -= kVOffset; - else - point.y += kVOffset; - [mPanel setFrameTopLeftPoint: point]; - - // if it goes off the edge of the screen, shift around to put it all on the screen - - float amountOffScreenX = NSMaxX(screenFrame) - NSMaxX([mPanel frame]); - if (amountOffScreenX < 0) { - NSRect movedFrame = [mPanel frame]; - movedFrame.origin.x += amountOffScreenX; - [mPanel setFrame: movedFrame display: NO]; - } - - // show the panel - [mPanel orderFront: nil]; - } -} - -- (void)closeToolTip -{ - [mPanel close]; -} - -@end diff --git a/mozilla/chimera/ToolbarDefaults.plist b/mozilla/chimera/ToolbarDefaults.plist deleted file mode 100644 index 27dce200e4b..00000000000 --- a/mozilla/chimera/ToolbarDefaults.plist +++ /dev/null @@ -1,8 +0,0 @@ -( - "Back Toolbar Item", - "Forward Toolbar Item", - "Reload Toolbar Item", - "Stop Toolbar Item", - "Location Toolbar Item", - "Sidebar Toolbar Item" -) diff --git a/mozilla/chimera/WebsiteDefaults.strings b/mozilla/chimera/WebsiteDefaults.strings deleted file mode 100644 index f80b5d6aae6..00000000000 --- a/mozilla/chimera/WebsiteDefaults.strings +++ /dev/null @@ -1,6 +0,0 @@ -HomePageDefault = "http://www.mozilla.org"; -/* SearchPageDefault = "http://www.dmoz.org"; Leave commented out to get search engine from IC */ -StartPageDefault = "about:blank"; -ThrobberPageDefault = "http://www.mozilla.org"; -FeedbackPageDefault = "http://chimera.mozdev.org"; -InfoPageDefault = "http://chimera.mozdev.org/installation.html"; diff --git a/mozilla/chimera/about.tif b/mozilla/chimera/about.tif deleted file mode 100644 index ab58947d93a..00000000000 Binary files a/mozilla/chimera/about.tif and /dev/null differ diff --git a/mozilla/chimera/alert.nib/classes.nib b/mozilla/chimera/alert.nib/classes.nib deleted file mode 100644 index 22720161509..00000000000 --- a/mozilla/chimera/alert.nib/classes.nib +++ /dev/null @@ -1,49 +0,0 @@ -{ - IBClasses = ( - {CLASS = FirstResponder; LANGUAGE = ObjC; SUPERCLASS = NSObject; }, - {CLASS = java.lang.Object; LANGUAGE = Java; }, - { - ACTIONS = {hitButton1 = id; hitButton2 = id; hitButton3 = id; }; - CLASS = nsAlertController; - LANGUAGE = ObjC; - OUTLETS = { - alertCheckPanel = id; - alertCheckPanelCheck = id; - alertCheckPanelText = id; - alertPanel = id; - alertPanelText = id; - confirmCheckPanel = id; - confirmCheckPanelButton1 = id; - confirmCheckPanelButton2 = id; - confirmCheckPanelButton3 = id; - confirmCheckPanelCheck = id; - confirmCheckPanelText = id; - confirmPanel = id; - confirmPanelButton1 = id; - confirmPanelButton2 = id; - confirmPanelButton3 = id; - confirmPanelText = id; - expiredCertPanel = id; - owner = id; - passwordPanel = id; - passwordPanelCheck = id; - passwordPanelInput = id; - passwordPanelText = id; - postToInsecureFromSecurePanel = id; - promptPanel = id; - promptPanelCheck = id; - promptPanelInput = id; - promptPanelText = id; - securityMismatchPanel = id; - securityUnknownPanel = id; - usernamePanel = id; - usernamePanelCheck = id; - usernamePanelPassword = id; - usernamePanelText = id; - usernamePanelUserName = id; - }; - SUPERCLASS = NSObject; - } - ); - IBVersion = 1; -} \ No newline at end of file diff --git a/mozilla/chimera/alert.nib/info.nib b/mozilla/chimera/alert.nib/info.nib deleted file mode 100644 index d2e85852ba9..00000000000 --- a/mozilla/chimera/alert.nib/info.nib +++ /dev/null @@ -1,12 +0,0 @@ - - - - - IBDocumentLocation - 285 97 356 301 0 0 1024 746 - IBFramework Version - 248.0 - IBSystem Version - 5S66 - - diff --git a/mozilla/chimera/alert.nib/objects.nib b/mozilla/chimera/alert.nib/objects.nib deleted file mode 100644 index 114a02c288c..00000000000 Binary files a/mozilla/chimera/alert.nib/objects.nib and /dev/null differ diff --git a/mozilla/chimera/appicon.icns b/mozilla/chimera/appicon.icns deleted file mode 100644 index 0d686347a4b..00000000000 Binary files a/mozilla/chimera/appicon.icns and /dev/null differ diff --git a/mozilla/chimera/back.tif b/mozilla/chimera/back.tif deleted file mode 100755 index a77d5a50897..00000000000 Binary files a/mozilla/chimera/back.tif and /dev/null differ diff --git a/mozilla/chimera/bookicon.tif b/mozilla/chimera/bookicon.tif deleted file mode 100644 index 5797532ed90..00000000000 Binary files a/mozilla/chimera/bookicon.tif and /dev/null differ diff --git a/mozilla/chimera/bookmark_on.tif b/mozilla/chimera/bookmark_on.tif deleted file mode 100644 index 258b336f5a5..00000000000 Binary files a/mozilla/chimera/bookmark_on.tif and /dev/null differ diff --git a/mozilla/chimera/bookmarks.xml b/mozilla/chimera/bookmarks.xml deleted file mode 100644 index 2c726f11944..00000000000 --- a/mozilla/chimera/bookmarks.xml +++ /dev/null @@ -1,23 +0,0 @@ - - - - - - - - - - - - - - - - - - - - diff --git a/mozilla/chimera/broken-image.gif b/mozilla/chimera/broken-image.gif deleted file mode 100644 index 03f4d14ff64..00000000000 Binary files a/mozilla/chimera/broken-image.gif and /dev/null differ diff --git a/mozilla/chimera/chimera.js b/mozilla/chimera/chimera.js deleted file mode 100644 index eb764501e24..00000000000 --- a/mozilla/chimera/chimera.js +++ /dev/null @@ -1,57 +0,0 @@ -/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** 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. - * - * 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): - * Brian Ryner - * - * 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 ***** */ - -// This file contains Chimera-specific default preferences. - -// What to load in a new tab: 0 = blank, 1 = homepage, 2 = last page -pref("browser.tabs.startPage", 0); - -// Disable the print progress dialog -pref("print.show_print_progress", false); - -// Pick some reasonable OS X default fonts -pref("font.name.serif.x-western", "Lucida Grande"); -pref("font.name.sans-serif.x-western", "Lucida Grande"); -pref("font.size.variable.x-western", 15); -pref("font.size.fixed.x-western", 12); -pref("font.size.minimum-size.x-western", 10); - -// Unsuppress painting sooner (XXXbryner, why is this here?) -pref("nglayout.initialpaint.delay", 250); - - diff --git a/mozilla/chimera/delete_on.tif b/mozilla/chimera/delete_on.tif deleted file mode 100644 index 6672bcd44d1..00000000000 Binary files a/mozilla/chimera/delete_on.tif and /dev/null differ diff --git a/mozilla/chimera/edit_on.tif b/mozilla/chimera/edit_on.tif deleted file mode 100644 index 5c98acf3b93..00000000000 Binary files a/mozilla/chimera/edit_on.tif and /dev/null differ diff --git a/mozilla/chimera/fileBookmark.icns b/mozilla/chimera/fileBookmark.icns deleted file mode 100644 index b89e6e61c98..00000000000 Binary files a/mozilla/chimera/fileBookmark.icns and /dev/null differ diff --git a/mozilla/chimera/fileHtml.icns b/mozilla/chimera/fileHtml.icns deleted file mode 100644 index 3f54c6964d9..00000000000 Binary files a/mozilla/chimera/fileHtml.icns and /dev/null differ diff --git a/mozilla/chimera/filePreferences.icns b/mozilla/chimera/filePreferences.icns deleted file mode 100644 index 724eddf1530..00000000000 Binary files a/mozilla/chimera/filePreferences.icns and /dev/null differ diff --git a/mozilla/chimera/folder.tiff b/mozilla/chimera/folder.tiff deleted file mode 100644 index f5ad95a4f84..00000000000 Binary files a/mozilla/chimera/folder.tiff and /dev/null differ diff --git a/mozilla/chimera/folder_on.tif b/mozilla/chimera/folder_on.tif deleted file mode 100644 index d35e6334c93..00000000000 Binary files a/mozilla/chimera/folder_on.tif and /dev/null differ diff --git a/mozilla/chimera/forward.tif b/mozilla/chimera/forward.tif deleted file mode 100755 index e856613af96..00000000000 Binary files a/mozilla/chimera/forward.tif and /dev/null differ diff --git a/mozilla/chimera/globe_ico.tif b/mozilla/chimera/globe_ico.tif deleted file mode 100644 index c8bb6b6f90e..00000000000 Binary files a/mozilla/chimera/globe_ico.tif and /dev/null differ diff --git a/mozilla/chimera/groupbookmark.tif b/mozilla/chimera/groupbookmark.tif deleted file mode 100644 index 5832357b01e..00000000000 Binary files a/mozilla/chimera/groupbookmark.tif and /dev/null differ diff --git a/mozilla/chimera/historyicon.tif b/mozilla/chimera/historyicon.tif deleted file mode 100644 index ca41c6f85a3..00000000000 Binary files a/mozilla/chimera/historyicon.tif and /dev/null differ diff --git a/mozilla/chimera/home.tif b/mozilla/chimera/home.tif deleted file mode 100755 index d3dd1ee8b0a..00000000000 Binary files a/mozilla/chimera/home.tif and /dev/null differ diff --git a/mozilla/chimera/loading-image.gif b/mozilla/chimera/loading-image.gif deleted file mode 100644 index ba240918423..00000000000 Binary files a/mozilla/chimera/loading-image.gif and /dev/null differ diff --git a/mozilla/chimera/main.m b/mozilla/chimera/main.m deleted file mode 100644 index 7afdacbcaaf..00000000000 --- a/mozilla/chimera/main.m +++ /dev/null @@ -1,17 +0,0 @@ -#import - -static void SetupRuntimeOptions(int argc, const char *argv[]) -{ - if (getenv("MOZ_UNBUFFERED_STDIO")) { - printf("stdout and stderr unbuffered\n"); - setbuf(stdout, 0); - setbuf(stderr, 0); - } -} - -int main(int argc, const char *argv[]) -{ - SetupRuntimeOptions(argc, argv); - - return NSApplicationMain(argc, argv); -} diff --git a/mozilla/chimera/nsAlertController.h b/mozilla/chimera/nsAlertController.h deleted file mode 100644 index 3fbd539d51d..00000000000 --- a/mozilla/chimera/nsAlertController.h +++ /dev/null @@ -1,104 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape 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/NPL/ - * - * 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 mozilla.org 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 NPL, 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 NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#import - -@interface nsAlertController : NSObject -{ - IBOutlet id alertCheckPanel; - IBOutlet id alertCheckPanelCheck; - IBOutlet id alertCheckPanelText; - IBOutlet id alertPanel; - IBOutlet id alertPanelText; - IBOutlet id confirmCheckPanel; - IBOutlet id confirmCheckPanelCheck; - IBOutlet id confirmCheckPanelText; - IBOutlet id confirmCheckPanelButton1; - IBOutlet id confirmCheckPanelButton2; - IBOutlet id confirmCheckPanelButton3; - IBOutlet id confirmPanel; - IBOutlet id confirmPanelText; - IBOutlet id confirmPanelButton1; - IBOutlet id confirmPanelButton2; - IBOutlet id confirmPanelButton3; - IBOutlet id promptPanel; - IBOutlet id promptPanelCheck; - IBOutlet id promptPanelText; - IBOutlet id promptPanelInput; - IBOutlet id passwordPanel; - IBOutlet id passwordPanelCheck; - IBOutlet id passwordPanelText; - IBOutlet id passwordPanelInput; - IBOutlet id postToInsecureFromSecurePanel; - IBOutlet id securityMismatchPanel; - IBOutlet id expiredCertPanel; - IBOutlet id securityUnknownPanel; - IBOutlet id usernamePanel; - IBOutlet id usernamePanelCheck; - IBOutlet id usernamePanelText; - IBOutlet id usernamePanelPassword; - IBOutlet id usernamePanelUserName; - IBOutlet id owner; -} -- (IBAction)hitButton1:(id)sender; -- (IBAction)hitButton2:(id)sender; -- (IBAction)hitButton3:(id)sender; - -- (void)awakeFromNib; -- (void)alert:(NSWindow*)parent title:(NSString*)title text:(NSString*)text; -- (void)alertCheck:(NSWindow*)parent title:(NSString*)title text:(NSString*)text checkMsg:(NSString*)checkMsg checkValue:(BOOL*)checkValue; - -- (BOOL)confirm:(NSWindow*)parent title:(NSString*)title text:(NSString*)text; -- (BOOL)confirmCheck:(NSWindow*)parent title:(NSString*)title text:(NSString*)text checkMsg:(NSString*)checkMsg checkValue:(BOOL*)checkValue; - -- (int)confirmEx:(NSWindow*)parent title:(NSString*)title text:(NSString*)text - button1:(NSString*)btn1 button2:(NSString*)btn2 button3:(NSString*)btn3; -- (int)confirmCheckEx:(NSWindow*)parent title:(NSString*)title text:(NSString*)text - button1:(NSString*)btn1 button2:(NSString*)btn2 button3:(NSString*)btn3 - checkMsg:(NSString*)checkMsg checkValue:(BOOL*)checkValue; - -- (BOOL)prompt:(NSWindow*)parent title:(NSString*)title text:(NSString*)text promptText:(NSMutableString*)promptText checkMsg:(NSString*)checkMsg checkValue:(BOOL*)checkValue doCheck:(BOOL)doCheck; -- (BOOL)promptUserNameAndPassword:(NSWindow*)parent title:(NSString*)title text:(NSString*)text userNameText:(NSMutableString*)userNameText passwordText:(NSMutableString*)passwordText checkMsg:(NSString*)checkMsg checkValue:(BOOL*)checkValue doCheck:(BOOL)doCheck; -- (BOOL)promptPassword:(NSWindow*)parent title:(NSString*)title text:(NSString*)text passwordText:(NSMutableString*)passwordText checkMsg:(NSString*)checkMsg checkValue:(BOOL*)checkValue doCheck:(BOOL)doCheck; - -- (BOOL)postToInsecureFromSecure:(NSWindow*)parent; - -- (BOOL)badCert:(NSWindow*)parent; -- (BOOL)expiredCert:(NSWindow*)parent; -- (int)unknownCert:(NSWindow*)parent; - -@end diff --git a/mozilla/chimera/nsAlertController.mm b/mozilla/chimera/nsAlertController.mm deleted file mode 100644 index 27225a524fc..00000000000 --- a/mozilla/chimera/nsAlertController.mm +++ /dev/null @@ -1,309 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape 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/NPL/ - * - * 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 mozilla.org 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 NPL, 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 NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#import "nsAlertController.h" -#import "nsCocoaBrowserService.h" - -#include "nsIBadCertListener.h" - -enum { kOKButton = 0, kCancelButton = 1, kOtherButton = 2 }; - -@implementation nsAlertController - -- (IBAction)hitButton1:(id)sender -{ - [NSApp stopModalWithCode:kOKButton]; -} - -- (IBAction)hitButton2:(id)sender -{ - [NSApp stopModalWithCode:kCancelButton]; -} - -- (IBAction)hitButton3:(id)sender -{ - [NSApp stopModalWithCode:kOtherButton]; -} - - -- (void)awakeFromNib -{ - nsCocoaBrowserService::SetAlertController(self); -} - -- (void)alert:(NSWindow*)parent title:(NSString*)title text:(NSString*)text -{ - [alertPanelText setStringValue:text]; - [alertPanel setTitle:title]; - - [NSApp runModalForWindow:alertPanel relativeToWindow:parent]; - - [alertPanel close]; -} - -- (void)alertCheck:(NSWindow*)parent title:(NSString*)title text:(NSString*)text checkMsg:(NSString*)checkMsg checkValue:(BOOL*)checkValue -{ - [alertCheckPanelText setStringValue:text]; - [alertCheckPanel setTitle:title]; - int state = (*checkValue ? NSOnState : NSOffState); - [alertCheckPanelCheck setState:state]; - [alertCheckPanelCheck setTitle:checkMsg]; - - [NSApp runModalForWindow:alertCheckPanel relativeToWindow:parent]; - - *checkValue = ([alertCheckPanelCheck state] == NSOnState); - [alertCheckPanel close]; -} - -- (BOOL)confirm:(NSWindow*)parent title:(NSString*)title text:(NSString*)text -{ - [confirmPanelText setStringValue:text]; - [confirmPanel setTitle:title]; - - int result = [NSApp runModalForWindow:confirmPanel relativeToWindow:parent]; - - [confirmPanel close]; - - return (result == kOKButton); -} - -- (BOOL)confirmCheck:(NSWindow*)parent title:(NSString*)title text:(NSString*)text checkMsg:(NSString*)checkMsg checkValue:(BOOL*)checkValue -{ - [confirmCheckPanelText setStringValue:text]; - [confirmCheckPanel setTitle:title]; - int state = (*checkValue ? NSOnState : NSOffState); - [confirmCheckPanelCheck setState:state]; - [confirmCheckPanelCheck setTitle:checkMsg]; - - int result = [NSApp runModalForWindow:confirmCheckPanel relativeToWindow:parent]; - - *checkValue = ([confirmCheckPanelCheck state] == NSOnState); - [confirmCheckPanel close]; - - return (result == kOKButton); -} - -- (int)confirmEx:(NSWindow*)parent title:(NSString*)title text:(NSString*)text - button1:(NSString*)btn1 button2:(NSString*)btn2 button3:(NSString*)btn3 -{ - [confirmPanelText setStringValue:text]; - [confirmPanel setTitle:title]; - - [confirmPanelButton1 setTitle:btn1]; - [confirmPanelButton2 setTitle:btn2]; - [confirmPanelButton3 setTitle:btn3]; - - int result = [NSApp runModalForWindow:confirmPanel relativeToWindow:parent]; - - [confirmPanel close]; - - return result; -} - -- (int)confirmCheckEx:(NSWindow*)parent title:(NSString*)title text:(NSString*)text - button1:(NSString*)btn1 button2:(NSString*)btn2 button3:(NSString*)btn3 - checkMsg:(NSString*)checkMsg checkValue:(BOOL*)checkValue -{ - [confirmCheckPanelText setStringValue:text]; - [confirmCheckPanel setTitle:title]; - int state = (*checkValue ? NSOnState : NSOffState); - [confirmCheckPanelCheck setState:state]; - [confirmCheckPanelCheck setTitle:checkMsg]; - - [confirmCheckPanelButton1 setTitle:btn1]; - [confirmCheckPanelButton2 setTitle:btn2]; - [confirmCheckPanelButton3 setTitle:btn3]; - - int result = [NSApp runModalForWindow:confirmCheckPanel relativeToWindow:parent]; - - *checkValue = ([confirmCheckPanelCheck state] == NSOnState); - [confirmCheckPanel close]; - - return result; -} - -- (BOOL)prompt:(NSWindow*)parent title:(NSString*)title text:(NSString*)text promptText:(NSMutableString*)promptText checkMsg:(NSString*)checkMsg checkValue:(BOOL*)checkValue doCheck:(BOOL)doCheck -{ - [promptPanelText setStringValue:text]; - [promptPanel setTitle:title]; - if (doCheck) { - int state = (*checkValue ? NSOnState : NSOffState); - [promptPanelCheck setState:state]; - [promptPanelCheck setTransparent:NO]; - } - else { - [promptPanelCheck setTransparent:YES]; - } - [promptPanelCheck setTitle:checkMsg]; - [promptPanelInput setStringValue:promptText]; - - int result = [NSApp runModalForWindow:promptPanel relativeToWindow:parent]; - - *checkValue = ([promptPanelCheck state] == NSOnState); - - NSString* value = [promptPanelInput stringValue]; - PRUint32 length = [promptText length]; - if (length) { - NSRange all; - all.location = 0; - all.length = [promptText length]; - [promptText deleteCharactersInRange:all]; - } - [promptText appendString:value]; - - [promptPanel close]; - - return (result == kOKButton); -} - -- (BOOL)promptUserNameAndPassword:(NSWindow*)parent title:(NSString*)title text:(NSString*)text userNameText:(NSMutableString*)userNameText passwordText:(NSMutableString*)passwordText checkMsg:(NSString*)checkMsg checkValue:(BOOL*)checkValue doCheck:(BOOL)doCheck -{ - [usernamePanelText setStringValue:text]; - [usernamePanel setTitle:title]; - if (doCheck) { - int state = (*checkValue ? NSOnState : NSOffState); - [usernamePanelCheck setState:state]; - [usernamePanelCheck setTransparent:NO]; - } - else { - [usernamePanelCheck setTransparent:YES]; - } - [usernamePanelCheck setTitle:checkMsg]; - [usernamePanelPassword setStringValue:passwordText]; - [usernamePanelUserName setStringValue:userNameText]; - - int result = [NSApp runModalForWindow:usernamePanel relativeToWindow:parent]; - - *checkValue = ([usernamePanelCheck state] == NSOnState); - - NSString* value = [usernamePanelUserName stringValue]; - PRUint32 length = [userNameText length]; - if (length) { - NSRange all; - all.location = 0; - all.length = [userNameText length]; - [userNameText deleteCharactersInRange:all]; - } - [userNameText appendString:value]; - - value = [usernamePanelPassword stringValue]; - length = [passwordText length]; - if (length) { - NSRange all; - all.location = 0; - all.length = [passwordText length]; - [passwordText deleteCharactersInRange:all]; - } - [passwordText appendString:value]; - - [usernamePanel close]; - - return (result == kOKButton); -} - -- (BOOL)promptPassword:(NSWindow*)parent title:(NSString*)title text:(NSString*)text passwordText:(NSMutableString*)passwordText checkMsg:(NSString*)checkMsg checkValue:(BOOL*)checkValue doCheck:(BOOL)doCheck -{ - [passwordPanelText setStringValue:text]; - [passwordPanel setTitle:title]; - if (doCheck) { - int state = (*checkValue ? NSOnState : NSOffState); - [passwordPanelCheck setState:state]; - [passwordPanelCheck setTransparent:NO]; - } - else { - [passwordPanelCheck setTransparent:YES]; - } - [passwordPanelCheck setTitle:checkMsg]; - [passwordPanelInput setStringValue:passwordText]; - - int result = [NSApp runModalForWindow:passwordPanel relativeToWindow:parent]; - - *checkValue = ([passwordPanelCheck state] == NSOnState); - - NSString* value = [passwordPanelInput stringValue]; - PRUint32 length = [passwordText length]; - if (length) { - NSRange all; - all.location = 0; - all.length = [passwordText length]; - [passwordText deleteCharactersInRange:all]; - } - [passwordText appendString:value]; - - [passwordPanel close]; - - return (result == kOKButton); -} - - -- (BOOL)postToInsecureFromSecure:(NSWindow*)parent -{ - int result = [NSApp runModalForWindow:postToInsecureFromSecurePanel relativeToWindow:parent]; - [postToInsecureFromSecurePanel close]; - - return (result == kOKButton); -} - - -- (BOOL)badCert:(NSWindow*)parent -{ - int result = [NSApp runModalForWindow:securityMismatchPanel relativeToWindow:parent]; - [securityMismatchPanel close]; - - return (result == kOKButton); -} - -- (BOOL)expiredCert:(NSWindow*)parent -{ - int result = [NSApp runModalForWindow:expiredCertPanel relativeToWindow:parent]; - [expiredCertPanel close]; - - return (result == kOKButton); -} - - -- (int)unknownCert:(NSWindow*)parent -{ - // this dialog is a little backward, with "Stop" returning 0, and the default returning - // 1. That's just how nsIBadCertListener defines its constants. *shrug* - int result = [NSApp runModalForWindow:securityUnknownPanel relativeToWindow:parent]; - [securityUnknownPanel close]; - - return result; -} - -@end diff --git a/mozilla/chimera/nsCocoaBrowserListener.h b/mozilla/chimera/nsCocoaBrowserListener.h deleted file mode 100644 index 0f4880be093..00000000000 --- a/mozilla/chimera/nsCocoaBrowserListener.h +++ /dev/null @@ -1,62 +0,0 @@ -// -// nsCocoaBrowserListener.h -// Chimera -// -// Created by Simon Fraser on Sat Aug 17 2002. -// Copyright (c) 2001 __MyCompanyName__. All rights reserved. -// - - -#ifndef __nsCocoaBrowserListener_h__ -#define __nsCocoaBrowserListener_h__ - -#include "nsWeakReference.h" -#include "nsIInterfaceRequestor.h" -#include "nsIWebBrowser.h" -#include "nsIWebBrowserChrome.h" -#include "nsIWebProgressListener.h" -#include "nsIEmbeddingSiteWindow2.h" -#include "nsIWindowCreator.h" - -#include "nsIContextMenuListener.h" -#include "nsITooltipListener.h" - -@class CHBrowserView; - -class nsCocoaBrowserListener : public nsSupportsWeakReference, - public nsIInterfaceRequestor, - public nsIWebBrowserChrome, - public nsIWindowCreator, - public nsIEmbeddingSiteWindow2, - public nsIWebProgressListener, - public nsIContextMenuListener, - public nsITooltipListener -{ -public: - nsCocoaBrowserListener(CHBrowserView* aView); - virtual ~nsCocoaBrowserListener(); - - NS_DECL_ISUPPORTS - NS_DECL_NSIINTERFACEREQUESTOR - NS_DECL_NSIWEBBROWSERCHROME - NS_DECL_NSIWINDOWCREATOR - NS_DECL_NSIEMBEDDINGSITEWINDOW - NS_DECL_NSIEMBEDDINGSITEWINDOW2 - NS_DECL_NSIWEBPROGRESSLISTENER - NS_DECL_NSICONTEXTMENULISTENER - NS_DECL_NSITOOLTIPLISTENER - - void AddListener(id aListener); - void RemoveListener(id aListener); - void SetContainer(id aContainer); - -private: - CHBrowserView* mView; // WEAK - it owns us - NSMutableArray* mListeners; - id mContainer; - PRBool mIsModal; - PRUint32 mChromeFlags; -}; - - -#endif // __nsCocoaBrowserListener_h__ diff --git a/mozilla/chimera/nsCocoaBrowserListener.mm b/mozilla/chimera/nsCocoaBrowserListener.mm deleted file mode 100644 index d9406ce59ea..00000000000 --- a/mozilla/chimera/nsCocoaBrowserListener.mm +++ /dev/null @@ -1,609 +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): - * Simon Fraser - * - * 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 - -#import "NSString+Utils.h" - -// Embedding includes -#include "nsIWebBrowser.h" -#include "nsIWebNavigation.h" -#include "nsIURI.h" -#include "nsIDOMWindow.h" -//#include "nsIWidget.h" - -// XPCOM and String includes -#include "nsCRT.h" -#include "nsString.h" -#include "nsCOMPtr.h" - -#import "CHBrowserView.h" - -#include "nsCocoaBrowserListener.h" - - -nsCocoaBrowserListener::nsCocoaBrowserListener(CHBrowserView* aView) - : mView(aView), mContainer(nsnull), mIsModal(PR_FALSE), mChromeFlags(0) -{ - NS_INIT_ISUPPORTS(); - mListeners = [[NSMutableArray alloc] init]; -} - -nsCocoaBrowserListener::~nsCocoaBrowserListener() -{ - [mListeners release]; - mView = nsnull; - if (mContainer) { - [mContainer release]; - } -} - -NS_IMPL_ISUPPORTS9(nsCocoaBrowserListener, - nsIInterfaceRequestor, - nsIWebBrowserChrome, - nsIWindowCreator, - nsIEmbeddingSiteWindow, - nsIEmbeddingSiteWindow2, - nsIWebProgressListener, - nsISupportsWeakReference, - nsIContextMenuListener, - nsITooltipListener) - -// Implementation of nsIInterfaceRequestor -NS_IMETHODIMP -nsCocoaBrowserListener::GetInterface(const nsIID &aIID, void** aInstancePtr) -{ - if (aIID.Equals(NS_GET_IID(nsIDOMWindow))) { - nsCOMPtr browser = dont_AddRef([mView getWebBrowser]); - if (browser) - return browser->GetContentDOMWindow((nsIDOMWindow **) aInstancePtr); - } - - return QueryInterface(aIID, aInstancePtr); -} - -// Implementation of nsIWindowCreator. The CocoaBrowserService forwards requests -// for a new window that have a parent to us, and we take over from there. -/* nsIWebBrowserChrome createChromeWindow (in nsIWebBrowserChrome parent, in PRUint32 chromeFlags); */ -NS_IMETHODIMP -nsCocoaBrowserListener::CreateChromeWindow(nsIWebBrowserChrome *parent, - PRUint32 chromeFlags, - nsIWebBrowserChrome **_retval) -{ - if (parent != this) { -#if DEBUG - NSLog(@"Mismatch in nsCocoaBrowserListener::CreateChromeWindow. We should be the owning parent."); -#endif - return NS_ERROR_FAILURE; - } - - CHBrowserView* childView = [mContainer createBrowserWindow: chromeFlags]; - if (!childView) { -#if DEBUG - NSLog(@"No CHBrowserView hooked up for a newly created window yet."); -#endif - return NS_ERROR_FAILURE; - } - - nsCocoaBrowserListener* listener = [childView getCocoaBrowserListener]; - if (!listener) { -#if DEBUG - NSLog(@"Uh-oh! No listener yet for a newly created window (nsCocoaBrowserlistener)"); - return NS_ERROR_FAILURE; -#endif - } - -#if DEBUG - NSLog(@"Made a chrome window."); -#endif - - *_retval = listener; - NS_IF_ADDREF(*_retval); - return NS_OK; -} - -// Implementation of nsIContextMenuListener -NS_IMETHODIMP -nsCocoaBrowserListener::OnShowContextMenu(PRUint32 aContextFlags, nsIDOMEvent* aEvent, nsIDOMNode* aNode) -{ - [mContainer onShowContextMenu: aContextFlags domEvent: aEvent domNode: aNode]; - return NS_OK; -} - -// Implementation of nsITooltipListener -NS_IMETHODIMP -nsCocoaBrowserListener::OnShowTooltip(PRInt32 aXCoords, PRInt32 aYCoords, const PRUnichar *aTipText) -{ - NSPoint where; - where.x = aXCoords; where.y = aYCoords; - [mContainer onShowTooltip:where withText:[NSString stringWithPRUnichars:aTipText]]; - return NS_OK; -} - -NS_IMETHODIMP -nsCocoaBrowserListener::OnHideTooltip() -{ - [mContainer onHideTooltip]; - return NS_OK; -} - -// Implementation of nsIWebBrowserChrome -/* void setStatus (in unsigned long statusType, in wstring status); */ -NS_IMETHODIMP -nsCocoaBrowserListener::SetStatus(PRUint32 statusType, const PRUnichar *status) -{ - if (!mContainer) { - return NS_ERROR_FAILURE; - } - - NSString* str = nsnull; - if (status && (*status != PRUnichar(0))) { - str = [NSString stringWithPRUnichars:status]; - } - - [mContainer setStatus:str ofType:(NSStatusType)statusType]; - - return NS_OK; -} - -/* attribute nsIWebBrowser webBrowser; */ -NS_IMETHODIMP -nsCocoaBrowserListener::GetWebBrowser(nsIWebBrowser * *aWebBrowser) -{ - NS_ENSURE_ARG_POINTER(aWebBrowser); - if (!mView) { - return NS_ERROR_FAILURE; - } - *aWebBrowser = [mView getWebBrowser]; - - return NS_OK; -} -NS_IMETHODIMP -nsCocoaBrowserListener::SetWebBrowser(nsIWebBrowser * aWebBrowser) -{ - if (!mView) { - return NS_ERROR_FAILURE; - } - - [mView setWebBrowser:aWebBrowser]; - - return NS_OK; -} - -/* attribute unsigned long chromeFlags; */ -NS_IMETHODIMP -nsCocoaBrowserListener::GetChromeFlags(PRUint32 *aChromeFlags) -{ - NS_ENSURE_ARG_POINTER(aChromeFlags); - *aChromeFlags = mChromeFlags; - return NS_OK; -} -NS_IMETHODIMP -nsCocoaBrowserListener::SetChromeFlags(PRUint32 aChromeFlags) -{ - // XXX Do nothing with them for now - mChromeFlags = aChromeFlags; - return NS_OK; -} - -/* void destroyBrowserWindow (); */ -NS_IMETHODIMP -nsCocoaBrowserListener::DestroyBrowserWindow() -{ - // XXX Could send this up to the container, but for now, - // we just destroy the enclosing window. - NSWindow* window = [mView window]; - - if (window) { - [window close]; - } - - return NS_OK; -} - -/* void sizeBrowserTo (in long aCX, in long aCY); */ -NS_IMETHODIMP -nsCocoaBrowserListener::SizeBrowserTo(PRInt32 aCX, PRInt32 aCY) -{ - if (mContainer) { - NSSize size; - - size.width = (float)aCX; - size.height = (float)aCY; - - [mContainer sizeBrowserTo:size]; - } - - return NS_OK; -} - -/* void showAsModal (); */ -NS_IMETHODIMP -nsCocoaBrowserListener::ShowAsModal() -{ - if (!mView) { - return NS_ERROR_FAILURE; - } - - NSWindow* window = [mView window]; - - if (!window) { - return NS_ERROR_FAILURE; - } - - mIsModal = PR_TRUE; - //int result = [NSApp runModalForWindow:window]; - mIsModal = PR_FALSE; - - return NS_OK; -} - -/* boolean isWindowModal (); */ -NS_IMETHODIMP -nsCocoaBrowserListener::IsWindowModal(PRBool *_retval) -{ - NS_ENSURE_ARG_POINTER(_retval); - - *_retval = mIsModal; - - return NS_OK; -} - -/* void exitModalEventLoop (in nsresult aStatus); */ -NS_IMETHODIMP -nsCocoaBrowserListener::ExitModalEventLoop(nsresult aStatus) -{ -// [NSApp stopModalWithCode:(int)aStatus]; - - return NS_OK; -} - -// Implementation of nsIEmbeddingSiteWindow2 -NS_IMETHODIMP -nsCocoaBrowserListener::Blur() -{ - return NS_OK; -} - -// Implementation of nsIEmbeddingSiteWindow -/* void setDimensions (in unsigned long flags, in long x, in long y, in long cx, in long cy); */ -NS_IMETHODIMP -nsCocoaBrowserListener::SetDimensions(PRUint32 flags, PRInt32 x, PRInt32 y, PRInt32 cx, PRInt32 cy) -{ - if (!mView) - return NS_ERROR_FAILURE; - - NSWindow* window = [mView window]; - if (!window) - return NS_ERROR_FAILURE; - - if (flags & nsIEmbeddingSiteWindow::DIM_FLAGS_POSITION) { - NSPoint origin; - origin.x = (float)x; - origin.y = (float)y; - - // websites assume the origin is the topleft of the window and that the screen origin - // is "topleft" (quickdraw coordinates). As a result, we have to convert it. - GDHandle screenDevice = ::GetMainDevice(); - Rect screenRect = (**screenDevice).gdRect; - short screenHeight = screenRect.bottom - screenRect.top; - origin.y = screenHeight - origin.y; - - [window setFrameTopLeftPoint:origin]; - } - - if (flags & nsIEmbeddingSiteWindow::DIM_FLAGS_SIZE_OUTER) { - NSRect frame = [window frame]; - frame.size.width = (float)cx; - frame.size.height = (float)cy; - [window setFrame:frame display:YES]; - } - else if (flags & nsIEmbeddingSiteWindow::DIM_FLAGS_SIZE_INNER) { - NSSize size; - size.width = (float)cx; - size.height = (float)cy; - [window setContentSize:size]; - } - - return NS_OK; -} - -/* void getDimensions (in unsigned long flags, out long x, out long y, out long cx, out long cy); */ -NS_IMETHODIMP -nsCocoaBrowserListener::GetDimensions(PRUint32 flags, PRInt32 *x, PRInt32 *y, PRInt32 *cx, PRInt32 *cy) -{ - if (!mView) - return NS_ERROR_FAILURE; - - NSWindow* window = [mView window]; - if (!window) - return NS_ERROR_FAILURE; - - NSRect frame = [window frame]; - if (flags & nsIEmbeddingSiteWindow::DIM_FLAGS_POSITION) { - if ( x ) - *x = (PRInt32)frame.origin.x; - if ( y ) - *y = (PRInt32)frame.origin.y; - } - if (flags & nsIEmbeddingSiteWindow::DIM_FLAGS_SIZE_OUTER) { - if ( cx ) - *cx = (PRInt32)frame.size.width; - if ( cy ) - *cy = (PRInt32)frame.size.height; - } - else if (flags & nsIEmbeddingSiteWindow::DIM_FLAGS_SIZE_INNER) { - NSView* contentView = [window contentView]; - NSRect contentFrame = [contentView frame]; - if ( cx ) - *cx = (PRInt32)contentFrame.size.width; - if ( cy ) - *cy = (PRInt32)contentFrame.size.height; - } - - return NS_OK; -} - -/* void setFocus (); */ -NS_IMETHODIMP -nsCocoaBrowserListener::SetFocus() -{ - if (!mView) { - return NS_ERROR_FAILURE; - } - - NSWindow* window = [mView window]; - if (!window) { - return NS_ERROR_FAILURE; - } - - [window makeKeyAndOrderFront:window]; - - return NS_OK; -} - -/* attribute boolean visibility; */ -NS_IMETHODIMP -nsCocoaBrowserListener::GetVisibility(PRBool *aVisibility) -{ - NS_ENSURE_ARG_POINTER(aVisibility); - - if (!mView) { - return NS_ERROR_FAILURE; - } - - NSWindow* window = [mView window]; - if (!window) { - return NS_ERROR_FAILURE; - } - - *aVisibility = [window isMiniaturized]; - - return NS_OK; -} -NS_IMETHODIMP -nsCocoaBrowserListener::SetVisibility(PRBool aVisibility) -{ - if (!mView) { - return NS_ERROR_FAILURE; - } - - NSWindow* window = [mView window]; - if (!window) { - return NS_ERROR_FAILURE; - } - - if (aVisibility) { - [window deminiaturize:window]; - } - else { - [window miniaturize:window]; - } - - return NS_OK; -} - -/* attribute wstring title; */ -NS_IMETHODIMP -nsCocoaBrowserListener::GetTitle(PRUnichar * *aTitle) -{ - NS_ENSURE_ARG_POINTER(aTitle); - - if (!mContainer) { - return NS_ERROR_FAILURE; - } - - NSString* title = [mContainer title]; - unsigned int length = [title length]; - if (length) { - *aTitle = (PRUnichar*)nsMemory::Alloc((length+1)*sizeof(PRUnichar)); - if (!*aTitle) { - return NS_ERROR_OUT_OF_MEMORY; - } - [title getCharacters:*aTitle]; - } - else { - *aTitle = nsnull; - } - - return NS_OK; -} -NS_IMETHODIMP -nsCocoaBrowserListener::SetTitle(const PRUnichar * aTitle) -{ - NS_ENSURE_ARG(aTitle); - - if (!mContainer) { - return NS_ERROR_FAILURE; - } - - NSString* str = [NSString stringWithPRUnichars:aTitle]; - [mContainer setTitle:str]; - - return NS_OK; -} - -/* [noscript] readonly attribute voidPtr siteWindow; */ -NS_IMETHODIMP -nsCocoaBrowserListener::GetSiteWindow(void * *aSiteWindow) -{ - NS_ENSURE_ARG_POINTER(aSiteWindow); - *aSiteWindow = nsnull; - if (!mView) { - return NS_ERROR_FAILURE; - } - - NSWindow* window = [mView window]; - if (!window) { - return NS_ERROR_FAILURE; - } - - *aSiteWindow = (void*)window; - - return NS_OK; -} - - -// -// Implementation of nsIWebProgressListener -// - -/* void onStateChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in unsigned long aStateFlags, in unsigned long aStatus); */ -NS_IMETHODIMP -nsCocoaBrowserListener::OnStateChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, - PRUint32 aStateFlags, PRUint32 aStatus) -{ - NSEnumerator* enumerator = [mListeners objectEnumerator]; - id obj; - - if (aStateFlags & nsIWebProgressListener::STATE_IS_NETWORK) { - if (aStateFlags & nsIWebProgressListener::STATE_START) { - while ((obj = [enumerator nextObject])) - [obj onLoadingStarted]; - } - else if (aStateFlags & nsIWebProgressListener::STATE_STOP) { - while ((obj = [enumerator nextObject])) - [obj onLoadingCompleted:(NS_SUCCEEDED(aStatus))]; - } - } - - return NS_OK; -} - -/* void onProgressChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in long aCurSelfProgress, in long aMaxSelfProgress, in long aCurTotalProgress, in long aMaxTotalProgress); */ -NS_IMETHODIMP -nsCocoaBrowserListener::OnProgressChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, - PRInt32 aCurSelfProgress, PRInt32 aMaxSelfProgress, - PRInt32 aCurTotalProgress, PRInt32 aMaxTotalProgress) -{ - NSEnumerator* enumerator = [mListeners objectEnumerator]; - id obj; - while ((obj = [enumerator nextObject])) - [obj onProgressChange:aCurTotalProgress outOf:aMaxTotalProgress]; - - return NS_OK; -} - -/* void onLocationChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in nsIURI location); */ -NS_IMETHODIMP -nsCocoaBrowserListener::OnLocationChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, - nsIURI *location) -{ - if (!location) - return NS_ERROR_FAILURE; - - nsCAutoString spec; - location->GetSpec(spec); - NSString* str = [NSString stringWithCString:spec.get()]; - - NSEnumerator* enumerator = [mListeners objectEnumerator]; - id obj; - while ((obj = [enumerator nextObject])) - [obj onLocationChange:str]; - - return NS_OK; -} - -/* void onStatusChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in nsresult aStatus, in wstring aMessage); */ -NS_IMETHODIMP -nsCocoaBrowserListener::OnStatusChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, nsresult aStatus, - const PRUnichar *aMessage) -{ - NSString* str = [NSString stringWithPRUnichars:aMessage]; - - NSEnumerator* enumerator = [mListeners objectEnumerator]; - id obj; - while ((obj = [enumerator nextObject])) - [obj onStatusChange: str]; - - return NS_OK; -} - -/* void onSecurityChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in unsigned long state); */ -NS_IMETHODIMP -nsCocoaBrowserListener::OnSecurityChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, PRUint32 state) -{ - NSEnumerator* enumerator = [mListeners objectEnumerator]; - id obj; - while ((obj = [enumerator nextObject])) - [obj onSecurityStateChange: state]; - - return NS_OK; -} - -void -nsCocoaBrowserListener::AddListener(id aListener) -{ - [mListeners addObject:aListener]; -} - -void -nsCocoaBrowserListener::RemoveListener(id aListener) -{ - [mListeners removeObject:aListener]; -} - -void -nsCocoaBrowserListener::SetContainer(id aContainer) -{ - [mContainer autorelease]; - - mContainer = aContainer; - - [mContainer retain]; -} - diff --git a/mozilla/chimera/nsCocoaBrowserService.h b/mozilla/chimera/nsCocoaBrowserService.h deleted file mode 100644 index e72518cf66e..00000000000 --- a/mozilla/chimera/nsCocoaBrowserService.h +++ /dev/null @@ -1,77 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape 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/NPL/ - * - * 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 mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 2001 - * 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 NPL, 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 NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef __nsCocoaBrowserService_h__ -#define __nsCocoaBrowserService_h__ - -#import "nsAlertController.h" -#include "nsCOMPtr.h" -#include "nsIWindowCreator.h" -#include "nsIHelperAppLauncherDialog.h" -#include "nsIFactory.h" - -class nsCocoaBrowserService : public nsIWindowCreator, - public nsIFactory, - public nsIHelperAppLauncherDialog -{ -public: - nsCocoaBrowserService(); - virtual ~nsCocoaBrowserService(); - - NS_DECL_ISUPPORTS - NS_DECL_NSIWINDOWCREATOR - NS_DECL_NSIFACTORY - NS_DECL_NSIHELPERAPPLAUNCHERDIALOG - - static nsresult InitEmbedding(); - static void TermEmbedding(); - static void BrowserClosed(); - - static void SetAlertController(nsAlertController* aController); - static nsAlertController* GetAlertController(); - -public: - static PRUint32 sNumBrowsers; - -private: - static nsCocoaBrowserService* sSingleton; - static nsAlertController* sController; - static PRBool sCanTerminate; -}; - - -#endif diff --git a/mozilla/chimera/nsCocoaBrowserService.mm b/mozilla/chimera/nsCocoaBrowserService.mm deleted file mode 100644 index b6a20a40415..00000000000 --- a/mozilla/chimera/nsCocoaBrowserService.mm +++ /dev/null @@ -1,274 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape 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/NPL/ - * - * 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 mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1998 - * 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 NPL, 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 NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#import "NSString+Utils.h" - -#import "nsCocoaBrowserService.h" -#import "DownloadFactories.h" -#import "CHBrowserView.h" - -#include "nsIWindowWatcher.h" -#include "nsIWebBrowserChrome.h" -#include "nsCRT.h" -#include "nsString.h" -#include "nsIGenericFactory.h" -#include "nsIComponentRegistrar.h" -#include "nsEmbedAPI.h" -#include "nsIDownload.h" -#include "nsIExternalHelperAppService.h" - -nsAlertController* nsCocoaBrowserService::sController = nsnull; -nsCocoaBrowserService* nsCocoaBrowserService::sSingleton = nsnull; -PRUint32 nsCocoaBrowserService::sNumBrowsers = 0; -PRBool nsCocoaBrowserService::sCanTerminate = PR_FALSE; - -// This method should return a nsModuleComponentInfo array of -// application-provided XPCOM components to register. The implementation -// is in AppComponents.mm. -extern const nsModuleComponentInfo* GetAppModuleComponentInfo(int* outNumComponents); - -// nsCocoaBrowserService implementation -nsCocoaBrowserService::nsCocoaBrowserService() -{ - NS_INIT_ISUPPORTS(); -} - -nsCocoaBrowserService::~nsCocoaBrowserService() -{ -} - -NS_IMPL_ISUPPORTS3(nsCocoaBrowserService, - nsIWindowCreator, - nsIFactory, - nsIHelperAppLauncherDialog) - -/* static */ -nsresult -nsCocoaBrowserService::InitEmbedding() -{ - sNumBrowsers++; - - if (sSingleton) - return NS_OK; - - sSingleton = new nsCocoaBrowserService(); - if (!sSingleton) - return NS_ERROR_OUT_OF_MEMORY; - NS_ADDREF(sSingleton); - - nsCOMPtr cr; - NS_GetComponentRegistrar(getter_AddRefs(cr)); - if ( !cr ) - return NS_ERROR_FAILURE; - - // Register as the window creator - nsCOMPtr watcher(do_GetService("@mozilla.org/embedcomp/window-watcher;1")); - if (!watcher) - return NS_ERROR_FAILURE; - watcher->SetWindowCreator(sSingleton); - - // Register application-provided Gecko components. This includes our security dialog implementation. - - int numComponents; - const nsModuleComponentInfo* componentInfo = GetAppModuleComponentInfo(&numComponents); - nsresult rv; - for (int i = 0; i < numComponents; ++i) { - nsCOMPtr componentFactory; - rv = NS_NewGenericFactory(getter_AddRefs(componentFactory), &(componentInfo[i])); - if (NS_FAILED(rv)) { - NS_ASSERTION(PR_FALSE, "Unable to create factory for component"); - continue; - } - - rv = cr->RegisterFactory(componentInfo[i].mCID, - componentInfo[i].mDescription, - componentInfo[i].mContractID, - componentFactory); - NS_ASSERTION(NS_SUCCEEDED(rv), "Unable to register factory for component"); - } - - // replace the external helper app dialog with our own - #define NS_HELPERAPPLAUNCHERDIALOG_CID \ - {0xf68578eb, 0x6ec2, 0x4169, {0xae, 0x19, 0x8c, 0x62, 0x43, 0xf0, 0xab, 0xe1}} - static NS_DEFINE_CID(kHelperDlgCID, NS_HELPERAPPLAUNCHERDIALOG_CID); - rv = cr->RegisterFactory(kHelperDlgCID, NS_IHELPERAPPLAUNCHERDLG_CLASSNAME, NS_IHELPERAPPLAUNCHERDLG_CONTRACTID, - sSingleton); - - // replace the downloader with our own which does not rely on the xpfe downlaod manager - nsCOMPtr downloadFactory; - rv = NewDownloadListenerFactory(getter_AddRefs(downloadFactory)); - if (NS_FAILED(rv)) return rv; - - static NS_DEFINE_CID(kDownloadCID, NS_DOWNLOAD_CID); - rv = cr->RegisterFactory(kDownloadCID, "Download", NS_DOWNLOAD_CONTRACTID, downloadFactory); - - return rv; -} - -/* static */ -void -nsCocoaBrowserService::BrowserClosed() -{ - sNumBrowsers--; - if (sCanTerminate && sNumBrowsers == 0) { - // The app is terminating *and* our count dropped to 0. - NS_IF_RELEASE(sSingleton); - NS_TermEmbedding(); -#if DEBUG - NSLog(@"Shutting down embedding!"); -#endif - } -} - -/* static */ -void -nsCocoaBrowserService::TermEmbedding() -{ - sCanTerminate = PR_TRUE; - if (sNumBrowsers == 0) { - NS_IF_RELEASE(sSingleton); - NS_TermEmbedding(); -#if DEBUG - NSLog(@"Shutting down embedding."); -#endif - } - else { -#if DEBUG - NSLog(@"Cannot yet shut down embedding."); -#endif - // Otherwise we cannot yet terminate. We have to let the death of the browser windows - // induce termination. - } -} - -#define NS_ALERT_NIB_NAME "alert" - -nsAlertController* -nsCocoaBrowserService::GetAlertController() -{ - if (!sController) { - NSBundle* bundle = [NSBundle bundleForClass:[CHBrowserView class]]; - [bundle loadNibFile:@NS_ALERT_NIB_NAME externalNameTable:nsnull withZone:[NSApp zone]]; - } - return sController; -} - -void -nsCocoaBrowserService::SetAlertController(nsAlertController* aController) -{ - // XXX When should the controller be released? - sController = aController; - [sController retain]; -} - -// nsIFactory implementation -NS_IMETHODIMP -nsCocoaBrowserService::CreateInstance(nsISupports *aOuter, - const nsIID & aIID, - void **aResult) -{ - - NS_ENSURE_ARG_POINTER(aResult); - - /* - if (aIID.Equals(NS_GET_IID(nsIHelperAppLauncherDialog))) - { - } - */ - - return sSingleton->QueryInterface(aIID, aResult); -} - -NS_IMETHODIMP -nsCocoaBrowserService::LockFactory(PRBool lock) -{ - return NS_OK; -} - - -// Implementation of nsIWindowCreator -/* nsIWebBrowserChrome createChromeWindow (in nsIWebBrowserChrome parent, in PRUint32 chromeFlags); */ -NS_IMETHODIMP -nsCocoaBrowserService::CreateChromeWindow(nsIWebBrowserChrome *parent, - PRUint32 chromeFlags, - nsIWebBrowserChrome **_retval) -{ - if (!parent) { -#if DEBUG - NSLog(@"Attempt to create a new browser window with a null parent. Should not happen in Chimera."); -#endif - return NS_ERROR_FAILURE; - } - - nsCOMPtr browserChrome(do_QueryInterface(parent)); - return browserChrome->CreateChromeWindow(parent, chromeFlags, _retval); -} - - -// void show( in nsIHelperAppLauncher aLauncher, in nsISupports aContext ); -NS_IMETHODIMP -nsCocoaBrowserService::Show(nsIHelperAppLauncher* inLauncher, nsISupports* inContext) -{ - return inLauncher->SaveToDisk(nsnull, PR_FALSE); -} - -NS_IMETHODIMP -nsCocoaBrowserService::PromptForSaveToFile(nsISupports *aWindowContext, const PRUnichar *aDefaultFile, const PRUnichar *aSuggestedFileExtension, nsILocalFile **_retval) -{ - NSString* filename = [NSString stringWithPRUnichars:aDefaultFile]; - NSSavePanel *thePanel = [NSSavePanel savePanel]; - - // Note: although the docs for NSSavePanel specifically state "path and filename can be empty strings, but - // cannot be nil" if you want the last used directory to persist between calls to display the save panel - // use nil for the path given to runModalForDirectory - int runResult = [thePanel runModalForDirectory: nil file:filename]; - if (runResult == NSOKButton) { - // NSLog(@"Saving to %@", [thePanel filename]); - NSString *theName = [thePanel filename]; - return NS_NewNativeLocalFile(nsDependentCString([theName fileSystemRepresentation]), PR_FALSE, _retval); - } - - return NS_ERROR_FAILURE; -} - -/* void showProgressDialog (in nsIHelperAppLauncher aLauncher, in nsISupports aContext); */ -NS_IMETHODIMP -nsCocoaBrowserService::ShowProgressDialog(nsIHelperAppLauncher *aLauncher, nsISupports *aContext) -{ - NSLog(@"nsCocoaBrowserService::ShowProgressDialog"); - return NS_OK; -} diff --git a/mozilla/chimera/nsDownloadListener.h b/mozilla/chimera/nsDownloadListener.h deleted file mode 100644 index cd15b3626cd..00000000000 --- a/mozilla/chimera/nsDownloadListener.h +++ /dev/null @@ -1,89 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape 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/NPL/ - * - * 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 mozilla.org 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): - * Simon Fraser - * - * 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 NPL, 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 NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - - - -#import -#import - -#import "DownloadProgressDisplay.h" - -#include "nsString.h" -#include "nsIDownload.h" -#include "nsIWebProgressListener.h" -#include "nsIWebBrowserPersist.h" -#include "nsIURI.h" -#include "nsILocalFile.h" - - -// maybe this should replace nsHeaderSniffer too? - -class nsDownloadListener : public CHDownloader, - public nsIDownload, - public nsIWebProgressListener -{ -public: - nsDownloadListener(DownloadControllerFactory* inDownloadControllerFactory); - virtual ~nsDownloadListener(); - - NS_DECL_ISUPPORTS_INHERITED - NS_DECL_NSIDOWNLOAD - NS_DECL_NSIWEBPROGRESSLISTENER - -public: - //void BeginDownload(); - void InitDialog(); - - virtual void PauseDownload(); - virtual void ResumeDownload(); - virtual void CancelDownload(); - virtual void DownloadDone(); - virtual void DetachDownloadDisplay(); - -private: - - nsCOMPtr mWebPersist; // Our web persist object. - nsCOMPtr mURI; // The URI of our source file. Null if we're saving a complete document. - nsCOMPtr mDestination; // Our destination URL. - PRInt64 mStartTime; // When the download started - PRPackedBool mBypassCache; // Whether we should bypass the cache or not. - PRPackedBool mNetworkTransfer; // true if the first OnStateChange has the NETWORK bit set - PRPackedBool mGotFirstStateChange; // true after we've seen the first OnStateChange - PRPackedBool mUserCanceled; // true if the user canceled the download -}; - diff --git a/mozilla/chimera/nsDownloadListener.mm b/mozilla/chimera/nsDownloadListener.mm deleted file mode 100644 index b0b2e126a3a..00000000000 --- a/mozilla/chimera/nsDownloadListener.mm +++ /dev/null @@ -1,325 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape 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/NPL/ - * - * 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 mozilla.org 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): - * Simon Fraser - * - * - * 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 NPL, 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 NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#import "NSString+Utils.h" - -#include "nsDownloadListener.h" - -#include "nsIWebProgress.h" -#include "nsIRequest.h" -#include "nsIURL.h" -#include "netCore.h" - -nsDownloadListener::nsDownloadListener(DownloadControllerFactory* inControllerFactory) -: CHDownloader(inControllerFactory) -, mBypassCache(PR_FALSE) -, mNetworkTransfer(PR_FALSE) -, mGotFirstStateChange(PR_FALSE) -, mUserCanceled(PR_FALSE) -{ -} - -nsDownloadListener::~nsDownloadListener() -{ -} - -NS_IMPL_ISUPPORTS_INHERITED2(nsDownloadListener, CHDownloader, nsIDownload, nsIWebProgressListener) - -#pragma mark - - -/* void init (in nsIURI aSource, in nsILocalFile aTarget, in wstring aDisplayName, in wstring openingWith, in long long startTime, in nsIWebBrowserPersist aPersist); */ -NS_IMETHODIMP -nsDownloadListener::Init(nsIURI *aSource, nsILocalFile *aTarget, const PRUnichar *aDisplayName, - const PRUnichar *openingWith, PRInt64 startTime, nsIWebBrowserPersist *aPersist) -{ - CreateDownloadDisplay(); // call the base class to make the download UI - - if (aPersist) // only true for File->Save As. - { - mWebPersist = aPersist; - mWebPersist->SetProgressListener(this); // we form a cycle here, since we're a listener. - // we'll break this cycle in DownloadDone() - } - - SetIsFileSave(aPersist != NULL); - - mDestination = aTarget; - mURI = aSource; - mStartTime = startTime; - - InitDialog(); - return NS_OK; -} - -/* readonly attribute nsIURI source; */ -NS_IMETHODIMP -nsDownloadListener::GetSource(nsIURI * *aSource) -{ - NS_ENSURE_ARG_POINTER(aSource); - NS_IF_ADDREF(*aSource = mURI); - return NS_OK; -} - -/* readonly attribute nsILocalFile target; */ -NS_IMETHODIMP -nsDownloadListener::GetTarget(nsILocalFile * *aTarget) -{ - NS_ENSURE_ARG_POINTER(aTarget); - NS_IF_ADDREF(*aTarget = mDestination); - return NS_OK; -} - -/* readonly attribute nsIWebBrowserPersist persist; */ -NS_IMETHODIMP -nsDownloadListener::GetPersist(nsIWebBrowserPersist * *aPersist) -{ - NS_ENSURE_ARG_POINTER(aPersist); - NS_IF_ADDREF(*aPersist = mWebPersist); - return NS_OK; -} - -/* readonly attribute PRInt32 percentComplete; */ -NS_IMETHODIMP -nsDownloadListener::GetPercentComplete(PRInt32 *aPercentComplete) -{ - return NS_ERROR_NOT_IMPLEMENTED; -} - -/* attribute wstring displayName; */ -NS_IMETHODIMP -nsDownloadListener::GetDisplayName(PRUnichar * *aDisplayName) -{ - return NS_ERROR_NOT_IMPLEMENTED; -} - -NS_IMETHODIMP -nsDownloadListener::SetDisplayName(const PRUnichar * aDisplayName) -{ - return NS_ERROR_NOT_IMPLEMENTED; -} - -/* readonly attribute long long startTime; */ -NS_IMETHODIMP -nsDownloadListener::GetStartTime(PRInt64 *aStartTime) -{ - NS_ENSURE_ARG(aStartTime); - *aStartTime = mStartTime; - return NS_OK; -} - -/* readonly attribute wstring openingWith; */ -NS_IMETHODIMP -nsDownloadListener::GetOpeningWith(PRUnichar * *aOpeningWith) -{ - return NS_ERROR_NOT_IMPLEMENTED; -} - -/* attribute nsIWebProgressListener listener; */ -NS_IMETHODIMP -nsDownloadListener::GetListener(nsIWebProgressListener * *aListener) -{ - NS_ENSURE_ARG_POINTER(aListener); - NS_IF_ADDREF(*aListener = (nsIWebProgressListener *)this); - return NS_OK; -} - -NS_IMETHODIMP -nsDownloadListener::SetListener(nsIWebProgressListener * aListener) -{ - return NS_ERROR_NOT_IMPLEMENTED; -} - -/* attribute nsIObserver observer; */ -NS_IMETHODIMP -nsDownloadListener::GetObserver(nsIObserver * *aObserver) -{ - return NS_ERROR_NOT_IMPLEMENTED; -} - -NS_IMETHODIMP -nsDownloadListener::SetObserver(nsIObserver * aObserver) -{ - return NS_ERROR_NOT_IMPLEMENTED; -} - -#pragma mark - - -/* void onProgressChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in long aCurSelfProgress, in long aMaxSelfProgress, in long aCurTotalProgress, in long aMaxTotalProgress); */ -NS_IMETHODIMP -nsDownloadListener::OnProgressChange(nsIWebProgress *aWebProgress, - nsIRequest *aRequest, - PRInt32 aCurSelfProgress, - PRInt32 aMaxSelfProgress, - PRInt32 aCurTotalProgress, - PRInt32 aMaxTotalProgress) -{ - if (mUserCanceled) - { - if (aRequest) - aRequest->Cancel(NS_BINDING_ABORTED); - - mUserCanceled = false; - } - - [mDownloadDisplay setProgressTo:aCurTotalProgress ofMax:aMaxTotalProgress]; - return NS_OK; -} - -/* void onLocationChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in nsIURI location); */ -NS_IMETHODIMP -nsDownloadListener::OnLocationChange(nsIWebProgress *aWebProgress, - nsIRequest *aRequest, - nsIURI *location) -{ - return NS_OK; -} - -/* void onStatusChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in nsresult aStatus, in wstring aMessage); */ -NS_IMETHODIMP -nsDownloadListener::OnStatusChange(nsIWebProgress *aWebProgress, - nsIRequest *aRequest, - nsresult aStatus, - const PRUnichar *aMessage) -{ - return NS_OK; -} - -/* void onSecurityChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in unsigned long state); */ -NS_IMETHODIMP -nsDownloadListener::OnSecurityChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, PRUint32 state) -{ - return NS_OK; -} - -// Implementation of nsIWebProgressListener -/* void onStateChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in unsigned long aStateFlags, in unsigned long aStatus); */ -NS_IMETHODIMP -nsDownloadListener::OnStateChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, PRUint32 aStateFlags, - PRUint32 aStatus) -{ - // NSLog(@"State changed: state %u, status %u", aStateFlags, aStatus); - if (!mGotFirstStateChange) { - mNetworkTransfer = ((aStateFlags & STATE_IS_NETWORK) != 0); - mGotFirstStateChange = PR_TRUE; - } - - // when the entire download finishes, stop the progress timer and clean up - // the window and controller. We will get this even in the event of a cancel, - // so this is the only place in the listener where we should kill the download. - if ((aStateFlags & STATE_STOP) && (!mNetworkTransfer || (aStateFlags & STATE_IS_NETWORK))) { - DownloadDone(); - } - return NS_OK; -} - -#pragma mark - - -void -nsDownloadListener::InitDialog() -{ - // dialog has to be shown before the outlets get hooked up - [mDownloadDisplay onStartDownload:(BOOL)IsFileSave()]; - - if (mURI) - { - nsCAutoString spec; - mURI->GetSpec(spec); - [mDownloadDisplay setSourceURL: [NSString stringWithUTF8String:spec.get()]]; - } - - nsAutoString pathStr; - mDestination->GetPath(pathStr); - [mDownloadDisplay setDestinationPath: [NSString stringWith_nsAString:pathStr]]; -} - -void -nsDownloadListener::PauseDownload() -{ - // write me -} - -void -nsDownloadListener::ResumeDownload() -{ - // write me -} - -void -nsDownloadListener::CancelDownload() -{ - mUserCanceled = PR_TRUE; - - if (mWebPersist) - { - mWebPersist->CancelSave(); - mUserCanceled = PR_FALSE; - } - - // delete any files we've created... - - -} - -void -nsDownloadListener::DownloadDone() -{ - // break the reference cycle by removing ourselves as a listener - if (mWebPersist) - { - mWebPersist->SetProgressListener(nsnull); - mWebPersist = nsnull; - } - - [mDownloadDisplay onEndDownload]; -} - -// -// DetachDownloadDisplay -// -// there are times when the download dislpay UI goes away before the -// listener (quit, for example). This alerts us that we should forget all -// about having any UI. -// -void -nsDownloadListener::DetachDownloadDisplay() -{ - mDownloadDisplay = nil; -} - -#pragma mark - diff --git a/mozilla/chimera/nsStaticComponents.cpp b/mozilla/chimera/nsStaticComponents.cpp deleted file mode 100644 index 1065d7b5ed2..00000000000 --- a/mozilla/chimera/nsStaticComponents.cpp +++ /dev/null @@ -1,72 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- - * - * 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 mozilla.org code. - * - * The Initial Developer of the Original Code is Netscape Communications - * Corporation. Portions created by Netscape are - * Copyright (C) 2001 Netscape Communications Corporation. All - * Rights Reserved. - * - * Contributor(s): - * Christopher Seawood - * Chris Waterson - */ - -#line 26 "nsStaticComponents.cpp.in" -#define XPCOM_TRANSLATE_NSGM_ENTRY_POINT 1 - -#include "nsIGenericFactory.h" -#include "nsStaticComponent.h" - -/** - * Construct a unique NSGetModule entry point for a generic module. - */ -#define NSGETMODULE(_name) _name##_NSGetmodule - -/** - * Declare an NSGetModule() routine for a generic module. - */ -#define DECL_NSGETMODULE(_name) \ -extern nsModuleInfo NSMODULEINFO(_name); \ -extern "C" NS_EXPORT nsresult \ -NSGETMODULE(_name) (nsIComponentManager* aCompMgr, \ - nsIFile* aLocation, \ - nsIModule** aResult) \ -{ \ - return NS_NewGenericModule2(&NSMODULEINFO(_name), aResult);\ -} - -// NSGetModule entry points -DECL_NSGETMODULE(UcharUtil) DECL_NSGETMODULE(nsUConvModule) DECL_NSGETMODULE(nsUCvJAModule) DECL_NSGETMODULE(nsUCvCnModule) DECL_NSGETMODULE(nsUCvLatinModule) DECL_NSGETMODULE(nsUCvTWModule) DECL_NSGETMODULE(nsUCvTW2Module) DECL_NSGETMODULE(nsUCvKoModule) DECL_NSGETMODULE(nsLocaleModule) DECL_NSGETMODULE(nsStringBundleModule) DECL_NSGETMODULE(nsLWBrkModule) DECL_NSGETMODULE(nsCharDetModule) DECL_NSGETMODULE(xpconnect) DECL_NSGETMODULE(cacheservice) DECL_NSGETMODULE(necko_core_and_primary_protocols) DECL_NSGETMODULE(necko_secondary_protocols) DECL_NSGETMODULE(nsURILoaderModule) DECL_NSGETMODULE(nsPrefModule) DECL_NSGETMODULE(nsCJVMManagerModule) DECL_NSGETMODULE(nsSecurityManagerModule) DECL_NSGETMODULE(nsChromeModule) DECL_NSGETMODULE(nsRDFModule) DECL_NSGETMODULE(nsParserModule) DECL_NSGETMODULE(nsGfxMacModule) DECL_NSGETMODULE(nsGfx2Module) DECL_NSGETMODULE(nsImageLib2Module) DECL_NSGETMODULE(nsPNGDecoderModule) DECL_NSGETMODULE(nsGIFModule2) DECL_NSGETMODULE(nsJPEGDecoderModule) DECL_NSGETMODULE(nsPluginModule) DECL_NSGETMODULE(javascript__protocol) DECL_NSGETMODULE(DOM_components) DECL_NSGETMODULE(nsViewModule) DECL_NSGETMODULE(nsWidgetMacModule) DECL_NSGETMODULE(nsContentModule) DECL_NSGETMODULE(nsLayoutModule) DECL_NSGETMODULE(nsMorkModule) DECL_NSGETMODULE(docshell_provider) DECL_NSGETMODULE(embedcomponents) DECL_NSGETMODULE(Browser_Embedding_Module) DECL_NSGETMODULE(nsEditorModule) DECL_NSGETMODULE(nsTransactionManagerModule) DECL_NSGETMODULE(nsTextServicesModule) DECL_NSGETMODULE(nsProfileModule) DECL_NSGETMODULE(Session_History_Module) DECL_NSGETMODULE(application) DECL_NSGETMODULE(nsCookieModule) DECL_NSGETMODULE(nsXMLExtrasModule) DECL_NSGETMODULE(nsUniversalCharDetModule) DECL_NSGETMODULE(BOOT) DECL_NSGETMODULE(NSS) -#line 52 "nsStaticComponents.cpp.in" - -/** - * The nsStaticModuleInfo - */ -static nsStaticModuleInfo gStaticModuleInfo[] = { -#define MODULE(_name) { (#_name), NSGETMODULE(_name) } - MODULE(UcharUtil), MODULE(nsUConvModule), MODULE(nsUCvJAModule), MODULE(nsUCvCnModule), MODULE(nsUCvLatinModule), MODULE(nsUCvTWModule), MODULE(nsUCvTW2Module), MODULE(nsUCvKoModule), MODULE(nsLocaleModule), MODULE(nsStringBundleModule), MODULE(nsLWBrkModule), MODULE(nsCharDetModule), MODULE(xpconnect), MODULE(cacheservice), MODULE(necko_core_and_primary_protocols), MODULE(necko_secondary_protocols), MODULE(nsURILoaderModule), MODULE(nsPrefModule), MODULE(nsCJVMManagerModule), MODULE(nsSecurityManagerModule), MODULE(nsChromeModule), MODULE(nsRDFModule), MODULE(nsParserModule), MODULE(nsGfxMacModule), MODULE(nsGfx2Module), MODULE(nsImageLib2Module), MODULE(nsPNGDecoderModule), MODULE(nsGIFModule2), MODULE(nsJPEGDecoderModule), MODULE(nsPluginModule), MODULE(javascript__protocol), MODULE(DOM_components), MODULE(nsViewModule), MODULE(nsWidgetMacModule), MODULE(nsContentModule), MODULE(nsLayoutModule), MODULE(nsMorkModule), MODULE(docshell_provider), MODULE(embedcomponents), MODULE(Browser_Embedding_Module), MODULE(nsEditorModule), MODULE(nsTransactionManagerModule), MODULE(nsTextServicesModule), MODULE(nsProfileModule), MODULE(Session_History_Module), MODULE(application), MODULE(nsCookieModule), MODULE(nsXMLExtrasModule), MODULE(nsUniversalCharDetModule), MODULE(BOOT), MODULE(NSS), -#line 60 "nsStaticComponents.cpp.in" -}; - -/** - * Our NSGetStaticModuleInfoFunc - */ -nsresult -app_getModuleInfo(nsStaticModuleInfo **info, PRUint32 *count) -{ - *info = gStaticModuleInfo; - *count = sizeof(gStaticModuleInfo) / sizeof(gStaticModuleInfo[0]); - return NS_OK; -} - diff --git a/mozilla/chimera/panel_icon.tif b/mozilla/chimera/panel_icon.tif deleted file mode 100644 index 09059671b1f..00000000000 Binary files a/mozilla/chimera/panel_icon.tif and /dev/null differ diff --git a/mozilla/chimera/print.tif b/mozilla/chimera/print.tif deleted file mode 100755 index 6a7601b0937..00000000000 Binary files a/mozilla/chimera/print.tif and /dev/null differ diff --git a/mozilla/chimera/projects/redo-prebinding.sh b/mozilla/chimera/projects/redo-prebinding.sh deleted file mode 100644 index 303c6125111..00000000000 --- a/mozilla/chimera/projects/redo-prebinding.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh -BINARY_DIR=`pwd|sed 's/ /\\\ /g'` -/bin/sh -c "update_prebinding -files $BINARY_DIR/*" diff --git a/mozilla/chimera/redo-prebinding.sh b/mozilla/chimera/redo-prebinding.sh deleted file mode 100644 index 303c6125111..00000000000 --- a/mozilla/chimera/redo-prebinding.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh -BINARY_DIR=`pwd|sed 's/ /\\\ /g'` -/bin/sh -c "update_prebinding -files $BINARY_DIR/*" diff --git a/mozilla/chimera/reload.tif b/mozilla/chimera/reload.tif deleted file mode 100755 index c67fed929d5..00000000000 Binary files a/mozilla/chimera/reload.tif and /dev/null differ diff --git a/mozilla/chimera/saveCancel.tif b/mozilla/chimera/saveCancel.tif deleted file mode 100644 index b7916fd2919..00000000000 Binary files a/mozilla/chimera/saveCancel.tif and /dev/null differ diff --git a/mozilla/chimera/saveLeaveOpenNO.tif b/mozilla/chimera/saveLeaveOpenNO.tif deleted file mode 100644 index a3f65fcd95e..00000000000 Binary files a/mozilla/chimera/saveLeaveOpenNO.tif and /dev/null differ diff --git a/mozilla/chimera/saveLeaveOpenYES.tif b/mozilla/chimera/saveLeaveOpenYES.tif deleted file mode 100644 index 4032caf3fb1..00000000000 Binary files a/mozilla/chimera/saveLeaveOpenYES.tif and /dev/null differ diff --git a/mozilla/chimera/saveOpenFile.tif b/mozilla/chimera/saveOpenFile.tif deleted file mode 100644 index 3fd7ae0f936..00000000000 Binary files a/mozilla/chimera/saveOpenFile.tif and /dev/null differ diff --git a/mozilla/chimera/savePause.tif b/mozilla/chimera/savePause.tif deleted file mode 100644 index 34092307c32..00000000000 Binary files a/mozilla/chimera/savePause.tif and /dev/null differ diff --git a/mozilla/chimera/saveResume.tif b/mozilla/chimera/saveResume.tif deleted file mode 100644 index 49ab50373ed..00000000000 Binary files a/mozilla/chimera/saveResume.tif and /dev/null differ diff --git a/mozilla/chimera/saveShowFile.tif b/mozilla/chimera/saveShowFile.tif deleted file mode 100644 index 79766ad3e1d..00000000000 Binary files a/mozilla/chimera/saveShowFile.tif and /dev/null differ diff --git a/mozilla/chimera/searchicon.tif b/mozilla/chimera/searchicon.tif deleted file mode 100644 index 31e514b2d68..00000000000 Binary files a/mozilla/chimera/searchicon.tif and /dev/null differ diff --git a/mozilla/chimera/security_broken.tif b/mozilla/chimera/security_broken.tif deleted file mode 100644 index 7cbc1580f39..00000000000 Binary files a/mozilla/chimera/security_broken.tif and /dev/null differ diff --git a/mozilla/chimera/security_lock.tif b/mozilla/chimera/security_lock.tif deleted file mode 100644 index 2b872eff3ba..00000000000 Binary files a/mozilla/chimera/security_lock.tif and /dev/null differ diff --git a/mozilla/chimera/separator_on.tif b/mozilla/chimera/separator_on.tif deleted file mode 100644 index b8d43984ce7..00000000000 Binary files a/mozilla/chimera/separator_on.tif and /dev/null differ diff --git a/mozilla/chimera/showall.tif b/mozilla/chimera/showall.tif deleted file mode 100644 index 9af186d5801..00000000000 Binary files a/mozilla/chimera/showall.tif and /dev/null differ diff --git a/mozilla/chimera/showsource.tif b/mozilla/chimera/showsource.tif deleted file mode 100644 index f32d1546a87..00000000000 Binary files a/mozilla/chimera/showsource.tif and /dev/null differ diff --git a/mozilla/chimera/sidebar.tif b/mozilla/chimera/sidebar.tif deleted file mode 100755 index da3297c8600..00000000000 Binary files a/mozilla/chimera/sidebar.tif and /dev/null differ diff --git a/mozilla/chimera/sidebarClosed.tif b/mozilla/chimera/sidebarClosed.tif deleted file mode 100644 index 11bb8657f82..00000000000 Binary files a/mozilla/chimera/sidebarClosed.tif and /dev/null differ diff --git a/mozilla/chimera/sidebarOpened.tif b/mozilla/chimera/sidebarOpened.tif deleted file mode 100644 index 3c3785926c4..00000000000 Binary files a/mozilla/chimera/sidebarOpened.tif and /dev/null differ diff --git a/mozilla/chimera/smallDocument.tiff b/mozilla/chimera/smallDocument.tiff deleted file mode 100644 index 42a8b6cbcb2..00000000000 Binary files a/mozilla/chimera/smallDocument.tiff and /dev/null differ diff --git a/mozilla/chimera/smallbookmark.tif b/mozilla/chimera/smallbookmark.tif deleted file mode 100644 index 5b7557e1db5..00000000000 Binary files a/mozilla/chimera/smallbookmark.tif and /dev/null differ diff --git a/mozilla/chimera/splash.tif b/mozilla/chimera/splash.tif deleted file mode 100644 index 12a7eb5cb08..00000000000 Binary files a/mozilla/chimera/splash.tif and /dev/null differ diff --git a/mozilla/chimera/stop.tif b/mozilla/chimera/stop.tif deleted file mode 100755 index 0f326815e29..00000000000 Binary files a/mozilla/chimera/stop.tif and /dev/null differ diff --git a/mozilla/chimera/throbber/throbber-01.gif b/mozilla/chimera/throbber/throbber-01.gif deleted file mode 100644 index 3e3a44bb39e..00000000000 Binary files a/mozilla/chimera/throbber/throbber-01.gif and /dev/null differ diff --git a/mozilla/chimera/throbber/throbber-02.gif b/mozilla/chimera/throbber/throbber-02.gif deleted file mode 100644 index 6a872480902..00000000000 Binary files a/mozilla/chimera/throbber/throbber-02.gif and /dev/null differ diff --git a/mozilla/chimera/throbber/throbber-03.gif b/mozilla/chimera/throbber/throbber-03.gif deleted file mode 100644 index ebd56240c80..00000000000 Binary files a/mozilla/chimera/throbber/throbber-03.gif and /dev/null differ diff --git a/mozilla/chimera/throbber/throbber-04.gif b/mozilla/chimera/throbber/throbber-04.gif deleted file mode 100644 index fb040515731..00000000000 Binary files a/mozilla/chimera/throbber/throbber-04.gif and /dev/null differ diff --git a/mozilla/chimera/throbber/throbber-05.gif b/mozilla/chimera/throbber/throbber-05.gif deleted file mode 100644 index 16670e6d932..00000000000 Binary files a/mozilla/chimera/throbber/throbber-05.gif and /dev/null differ diff --git a/mozilla/chimera/throbber/throbber-06.gif b/mozilla/chimera/throbber/throbber-06.gif deleted file mode 100644 index 8f9696037fe..00000000000 Binary files a/mozilla/chimera/throbber/throbber-06.gif and /dev/null differ diff --git a/mozilla/chimera/throbber/throbber.gif b/mozilla/chimera/throbber/throbber.gif deleted file mode 100644 index 1bb813700bc..00000000000 Binary files a/mozilla/chimera/throbber/throbber.gif and /dev/null differ