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