Diff for /chimera/BrowserWindowController.mm between versions 1.39 and 1.67

version 1.39, 2002/02/25 08:44:17 version 1.67, 2002/04/17 10:30:13
Line 1 Line 1
/*/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 *  BrowserWindowController.mm/* ***** 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 "BrowserWindowController.h"  #import "BrowserWindowController.h"
 #import "MyBrowserView.h"  #import "MyBrowserView.h"
   #import "IconTabViewItem.h"
   
 #include "nsIWebNavigation.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 "GeckoUtils.h"
   
 static NSString *BrowserToolbarIdentifier = @"Browser Window Toolbar";  static NSString *BrowserToolbarIdentifier = @"Browser Window Toolbar";
 static NSString *BackToolbarItemIdentifier  = @"Back Toolbar Item";  static NSString *BackToolbarItemIdentifier  = @"Back Toolbar Item";
Line 19  static NSString *PrintToolbarItemIdentif Line 65  static NSString *PrintToolbarItemIdentif
   
 @interface BrowserWindowController(Private)  @interface BrowserWindowController(Private)
 - (void)setupToolbar;  - (void)setupToolbar;
   - (void)setupSidebarTabs;
 @end  @end
   
 @implementation BrowserWindowController  @implementation BrowserWindowController
Line 31  static NSString *PrintToolbarItemIdentif Line 78  static NSString *PrintToolbarItemIdentif
     mModalSession = nil;      mModalSession = nil;
 }  }
   
   -(void)windowDidBecomeKey: (NSNotification*)aNotification
   {
     // May become necessary later.
   }
   
   -(void)windowDidResignKey: (NSNotification*)aNotification
   {
     // May be needed later.
   }
   
 -(void)mouseMoved:(NSEvent*)aEvent  -(void)mouseMoved:(NSEvent*)aEvent
 {  {
     if (mMoveReentrant)      if (mMoveReentrant)
Line 43  static NSString *PrintToolbarItemIdentif Line 100  static NSString *PrintToolbarItemIdentif
     mMoveReentrant = NO;      mMoveReentrant = NO;
 }  }
   
- (id)init - (id)initWithWindowNibName:(NSString *)windowNibName
 {  {
    mInitialized = NO;    if ( (self = [super initWithWindowNibName:(NSString *)windowNibName]) ) {
    mMoveReentrant = NO;        if ( nsCocoaBrowserService::sNumBrowsers == 0 ) {
    return [super init];            [self setShouldCascadeWindows:NO];
         } else {
             [self setShouldCascadeWindows:YES];
         }
         mInitialized = NO;
         mMoveReentrant = NO;
         mShouldAutosave = YES;
         mChromeMask = 0;
         mContextMenuFlags = 0;
         mContextMenuEvent = nsnull;
         mContextMenuNode = nsnull;
     }
     return self;
 }
 
 -(void)autosaveWindowFrame
 {
   if (mShouldAutosave)
     [[self window] saveFrameUsingName: @"NavigatorWindow"];
 }
 
 -(void)disableAutosave
 {
   mShouldAutosave = NO;
 }  }
   
 - (void)windowWillClose:(NSNotification *)notification  - (void)windowWillClose:(NSNotification *)notification
 {  {
    [self autorelease];  printf("Window will close notification.\n");
    [mSidebarBookmarksDataSource windowClosing];  [mSidebarBookmarksDataSource windowClosing];
 
   [self autosaveWindowFrame];
   [self autorelease];
 }  }
   
 - (void)dealloc  - (void)dealloc
 {  {
    printf("Browser controller died.\n");  printf("Browser controller died.\n");
    
    [mBrowserView windowClosed];  // Loop over all tabs, and tell them that the window is closed.
    [mSidebarBrowserView windowClosed];  int numTabs = [mTabBrowser numberOfTabViewItems];
      for (int i = 0; i < numTabs; i++) {
    [mProgress release];    NSTabViewItem* item = [mTabBrowser tabViewItemAtIndex: i];
        [[item view] windowClosed];
    [super dealloc];  }
   [mSidebarBrowserView windowClosed];
 
   [mProgress release];
   
   [super dealloc];
 }  }
   
 - (void)windowDidLoad  - (void)windowDidLoad
 {  {
     [super windowDidLoad];      [super windowDidLoad];
   
     [[mURLBar cell] setImage: [NSImage imageNamed:@"smallbookmark"]];
     
       // Get our saved dimensions.
       [[self window] setFrameUsingName: @"NavigatorWindow"];
           
     if (mModalSession)      if (mModalSession)
       [NSApp stopModal: mModalSession];        [NSApp stopModal: mModalSession];
               
     mInitialized = YES;      mInitialized = YES;
   
       mDrawerCachedFrame = NO;
           
     // Retain with a single extra refcount.  This allows the MyBrowserViews      // Retain with a single extra refcount.  This allows the MyBrowserViews
     // to remove the progress meter from its superview without having to       // to remove the progress meter from its superview without having to 
Line 85  static NSString *PrintToolbarItemIdentif Line 180  static NSString *PrintToolbarItemIdentif
     [[self window] setAcceptsMouseMovedEvents: YES];      [[self window] setAcceptsMouseMovedEvents: YES];
           
     [self setupToolbar];      [self setupToolbar];
       
   //  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.
   
    // Our initial view is our primary view.  Connect it up.    [mTabBrowser removeTabViewItem:[mTabBrowser tabViewItemAtIndex:0]];
    NSTabViewItem* tab = [mTabBrowser tabViewItemAtIndex: 0];    [self newTab];
    NSView* view = [tab view]; 
     
    MyBrowserView* newView = [[[MyBrowserView alloc] initWithFrame: [view frame]] autorelease]; 
    [tab setView: newView]; 
    mBrowserView = newView; 
           
     if (mURL) {      if (mURL) {
       [self loadURL: mURL];        [self loadURL: mURL];
Line 100  static NSString *PrintToolbarItemIdentif Line 194  static NSString *PrintToolbarItemIdentif
     }      }
           
     [mSidebarDrawer setDelegate: self];      [mSidebarDrawer setDelegate: self];
    
    [mBrowserView makePrimaryBrowserView: tab urlbar: mURLBar status: mStatus    [self setupSidebarTabs];
        progress: mProgress windowController: self];
     [mPersonalToolbar initializeToolbar];
 }  }
   
 - (void)drawerWillOpen: (NSNotification*)aNotification  - (void)drawerWillOpen: (NSNotification*)aNotification
 {  {
    [mSidebarBookmarksDataSource ensureBookmarks];  [mSidebarBookmarksDataSource ensureBookmarks];
 
   // 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.size.width) {
     // We need to adjust the window so that it can fit.
     int shrinkDelta = (windowFrame.size.width + drawerSize.width) - screenFrame.size.width;
     if (shrinkDelta < 0) shrinkDelta = 0;
     int newWidth = (windowFrame.size.width - shrinkDelta);
     int 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];
     mDrawerCachedFrame = YES;
   }
 }  }
   
 - (void)drawerDidOpen:(NSNotification *)aNotification  - (void)drawerDidOpen:(NSNotification *)aNotification
 {  {
    // XXXdwh This is temporary.  // XXXdwh This is temporary.
    [[mSidebarBrowserView getBrowserView] loadURI: [NSURL URLWithString: @"http://tinderbox.mozilla.org/SeaMonkey/panel.html"] flags:NSLoadFlagsNone];  //  [[mSidebarBrowserView getBrowserView] loadURI: [NSURL URLWithString: @"http://tinderbox.mozilla.org/SeaMonkey/panel.html"] flags:NSLoadFlagsNone];
 
   // Toggle the sidebar icon.
   [mSidebarToolbarItem setImage:[NSImage imageNamed:@"sidebarOpened"]];
 }  }
   
 - (void)drawerDidClose:(NSNotification *)aNotification  - (void)drawerDidClose:(NSNotification *)aNotification
 {  {
    // Unload the Gecko web page in "My Panels" to save memory.  // Unload the Gecko web page in "My Panels" to save memory.
    [[mSidebarBrowserView getBrowserView] loadURI: [NSURL URLWithString: @"about:blank"] flags:NSLoadFlagsNone];  [mSidebarToolbarItem setImage:[NSImage imageNamed:@"sidebarClosed"]];
 
   // XXXdwh ignore for now.
   //  [[mSidebarBrowserView getBrowserView] loadURI: [NSURL URLWithString: @"about:blank"] flags:NSLoadFlagsNone];
 
   if (mDrawerCachedFrame) {
     printf("Got here.\n");
     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) {
       printf("Got here too.\n");
       printf("Xes are %d %d\n", frame.origin.x, mCachedFrameAfterDrawerOpen.origin.x);
       printf("Widths are %d %d\n", frame.size.width, mCachedFrameAfterDrawerOpen.size.width);
       // Restore the original frame.
       [[self window] setFrame: mCachedFrameBeforeDrawerOpen display: YES];
     }
   }
 }  }
   
 - (void)setupToolbar  - (void)setupToolbar
 {  {
     if (mChromeMask) {
       printf("Uh-oh. %d\n", mChromeMask);
     }
     
     NSToolbar *toolbar = [[[NSToolbar alloc] initWithIdentifier:BrowserToolbarIdentifier] autorelease];      NSToolbar *toolbar = [[[NSToolbar alloc] initWithIdentifier:BrowserToolbarIdentifier] autorelease];
           
     [toolbar setDisplayMode:NSToolbarDisplayModeDefault];      [toolbar setDisplayMode:NSToolbarDisplayModeDefault];
Line 207  static NSString *PrintToolbarItemIdentif Line 350  static NSString *PrintToolbarItemIdentif
         [toolbarItem setLabel:@"Sidebar"];          [toolbarItem setLabel:@"Sidebar"];
         [toolbarItem setPaletteLabel:@"Toggle Sidebar"];          [toolbarItem setPaletteLabel:@"Toggle Sidebar"];
         [toolbarItem setToolTip:@"Show or hide the Sidebar"];          [toolbarItem setToolTip:@"Show or hide the Sidebar"];
        [toolbarItem setImage:[NSImage imageNamed:@"sidebar"]];        [toolbarItem setImage:[NSImage imageNamed:@"sidebarClosed"]];
         [toolbarItem setTarget:self];          [toolbarItem setTarget:self];
         [toolbarItem setAction:@selector(toggleSidebar:)];          [toolbarItem setAction:@selector(toggleSidebar:)];
           mSidebarToolbarItem = toolbarItem;
     } else if ( [itemIdent isEqual:LocationToolbarItemIdentifier] ) {      } else if ( [itemIdent isEqual:LocationToolbarItemIdentifier] ) {
                   
         NSMenuItem *menuFormRep = [[[NSMenuItem alloc] init] autorelease];          NSMenuItem *menuFormRep = [[[NSMenuItem alloc] init] autorelease];
Line 302  static NSString *PrintToolbarItemIdentif Line 446  static NSString *PrintToolbarItemIdentif
     [[mBrowserView getBrowserView] setActive: YES];      [[mBrowserView getBrowserView] setActive: YES];
 }  }
   
   -(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 isOpen])
       [self toggleSidebar: self];
   
     [mSidebarTabView selectFirstTabViewItem:self];
   }
   
 - (IBAction)goToLocationFromToolbarURLField:(id)sender  - (IBAction)goToLocationFromToolbarURLField:(id)sender
 {  {
     [self loadURL:[NSURL URLWithString:[sender stringValue]]];      [self loadURL:[NSURL URLWithString:[sender stringValue]]];
Line 312  static NSString *PrintToolbarItemIdentif Line 483  static NSString *PrintToolbarItemIdentif
   
 - (void)saveDocument: (NSView*)aFilterView filterList: (NSPopUpButton*)aFilterList  - (void)saveDocument: (NSView*)aFilterView filterList: (NSPopUpButton*)aFilterList
 {  {
    [[mBrowserView getBrowserView] saveDocument: aFilterView filterList: aFilterList];  [[mBrowserView getBrowserView] saveDocument: aFilterView filterList: aFilterList];
 }
 
 - (void)saveURL: (NSView*)aFilterView filterList: (NSPopUpButton*)aFilterList
             url: (NSURL*)aURL suggestedFilename: (NSString*)aFilename
 {
   [[mBrowserView getBrowserView] saveURL: aFilterView filterList: aFilterList
                                      url: aURL suggestedFilename: aFilename];
 }  }
   
 - (void)printDocument  - (void)printDocument
Line 325  static NSString *PrintToolbarItemIdentif Line 503  static NSString *PrintToolbarItemIdentif
     [[mBrowserView getBrowserView] printPreview];      [[mBrowserView getBrowserView] printPreview];
 }  }
   
- (void)findInPage- (BOOL)findInPage:(NSString*)text
 {  {
    [[mBrowserView getBrowserView] findInPage];    return [[mBrowserView getBrowserView] findInPage:text];
 }  }
   
- (void)findAgain- (void)addBookmarkExtended: (BOOL)aIsFromMenu
 {  {
    [[mBrowserView getBrowserView] findAgain];  [mSidebarBookmarksDataSource ensureBookmarks];
}  [mSidebarBookmarksDataSource addBookmark: self useSelection: !aIsFromMenu];
 
- (void)addBookmark 
{ 
    // XXXdwh Hack.  Just go to the sidebar for now until we get our 
    // menu data source going. 
    [mSidebarBookmarksDataSource ensureBookmarks]; 
    [mSidebarBookmarksDataSource addBookmark: self]; 
 }  }
   
 - (IBAction)back:(id)aSender  - (IBAction)back:(id)aSender
Line 375  static NSString *PrintToolbarItemIdentif Line 546  static NSString *PrintToolbarItemIdentif
           
     if ( ([mSidebarDrawer state] == NSDrawerClosedState) || ([mSidebarDrawer state] == NSDrawerClosingState) )  {      if ( ([mSidebarDrawer state] == NSDrawerClosedState) || ([mSidebarDrawer state] == NSDrawerClosingState) )  {
         // XXXHack to bypass sidebar crashes.          // XXXHack to bypass sidebar crashes.
        [mSidebarDrawer open];        [mSidebarDrawer openOnEdge: NSMaxXEdge];
     } else {      } else {
         [mSidebarDrawer close];          [mSidebarDrawer close];
     }      }
Line 383  static NSString *PrintToolbarItemIdentif Line 554  static NSString *PrintToolbarItemIdentif
     [[self window] makeFirstResponder: resp];      [[self window] makeFirstResponder: resp];
 }  }
   
   
 -(void)loadURL:(NSURL*)aURL  -(void)loadURL:(NSURL*)aURL
 {  {
     if (mInitialized) {      if (mInitialized) {
Line 416  static NSString *PrintToolbarItemIdentif Line 588  static NSString *PrintToolbarItemIdentif
 -(void)newTab  -(void)newTab
 {  {
     NSTabViewItem* newTab = [[[NSTabViewItem alloc] initWithIdentifier: nil] autorelease];      NSTabViewItem* newTab = [[[NSTabViewItem alloc] initWithIdentifier: nil] autorelease];
     [mTabBrowser addTabViewItem: newTab];  
       
     MyBrowserView* newView = [[[MyBrowserView alloc] initWithFrame: [mBrowserView frame]] autorelease];      MyBrowserView* newView = [[[MyBrowserView alloc] initWithFrame: [mBrowserView frame]] autorelease];
    [newTab setView: newView];    [newView setTab: newTab];
 
     [newTab setLabel: @"Untitled"];      [newTab setLabel: @"Untitled"];
        [newTab setView: newView];
 
     [mTabBrowser addTabViewItem: newTab];
 
     [[newView getBrowserView] loadURI:[NSURL URLWithString:@"about:blank"] flags:NSLoadFlagsNone];      [[newView getBrowserView] loadURI:[NSURL URLWithString:@"about:blank"] flags:NSLoadFlagsNone];
    
     [mTabBrowser selectLastTabViewItem: self];      [mTabBrowser selectLastTabViewItem: self];
    
     if ( [[[self window] toolbar] isVisible] ) {      if ( [[[self window] toolbar] isVisible] ) {
         if ( ([[[self window] toolbar] displayMode] == NSToolbarDisplayModeIconAndLabel) ||          if ( ([[[self window] toolbar] displayMode] == NSToolbarDisplayModeIconAndLabel) ||
              ([[[self window] toolbar] displayMode] == NSToolbarDisplayModeIconOnly) ) {               ([[[self window] toolbar] displayMode] == NSToolbarDisplayModeIconOnly) ) {
             if ([mTabBrowser numberOfTabViewItems] > 1) {
             [self focusURLBar];              [self focusURLBar];
        }             [[mBrowserView getBrowserView] setActive: NO];
           }
           else if ([[self window] isKeyWindow])
             [[mBrowserView getBrowserView] setActive: YES];
           else
             [[mBrowserView getBrowserView] setActive: NO];
         }
     }      }
    }
    //XXXdwh Do this if we ever support auto-hide.
    //if ([mTabBrowser numberOfTabViewItems] == 2)-(void)closeTab
    //    [mTabBrowser setTabViewType: NSTopTabsBezelBorder];{
   if ( [mTabBrowser numberOfTabViewItems] > 1 ) {
     [[[mTabBrowser selectedTabViewItem] view] windowClosed];
     [mTabBrowser removeTabViewItem:[mTabBrowser selectedTabViewItem]];
   }
 }
 
 - (void)previousTab
 {
     [mTabBrowser selectPreviousTabViewItem:self];
 }
 
 - (void)nextTab
 {
     [mTabBrowser selectNextTabViewItem:self];
 }  }
   
 - (void)tabView:(NSTabView *)aTabView didSelectTabViewItem:(NSTabViewItem *)aTabViewItem  - (void)tabView:(NSTabView *)aTabView didSelectTabViewItem:(NSTabViewItem *)aTabViewItem
 {  {
    // Disconnect the old view.    // Disconnect the old view, if one has been designated.
    [mBrowserView disconnectView];    // If the window has just been opened, none has been.
        if ( mBrowserView ) {
         [mBrowserView disconnectView];
     }
     // Connect up the new view      // Connect up the new view
     mBrowserView = [aTabViewItem view];      mBrowserView = [aTabViewItem view];
                 
     // Make the new view the primary content area.      // Make the new view the primary content area.
    [mBrowserView makePrimaryBrowserView: aTabViewItem urlbar: mURLBar status: mStatus    [mBrowserView makePrimaryBrowserView: mURLBar status: mStatus
         progress: mProgress windowController: self];          progress: mProgress windowController: self];
 }  }
   
Line 455  static NSString *PrintToolbarItemIdentif Line 652  static NSString *PrintToolbarItemIdentif
 {  {
     return mBrowserView;      return mBrowserView;
 }  }
   
   -(void)openNewWindowWithURL: (NSURL*)aURL 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: aURL];
     if (aLoadInBG)
       [[browser window] orderWindow: NSWindowBelow relativeTo: [[self window] windowNumber]];
     else {
       // Focus the content area and show the window.
       [browser enterModalSession];
       [[[browser getMyBrowserView] getBrowserView] setActive: YES];
     }
   }
   
   -(void)openNewTabWithURL: (NSURL*)aURL loadInBackground: (BOOL)aLoadInBG
   {
       NSTabViewItem* newTab = [[[NSTabViewItem alloc] initWithIdentifier: nil] autorelease];
       
       NSTabViewItem* selectedTab = [mTabBrowser selectedTabViewItem];
       int index = [mTabBrowser indexOfTabViewItem: selectedTab];
       [mTabBrowser insertTabViewItem: newTab atIndex: index+1];
       
       MyBrowserView* newView = [[[MyBrowserView alloc] initWithFrame: [mBrowserView frame]] autorelease];
       [newView setTab: newTab];
       
       [newTab setLabel: @"Loading..."];
       [newTab setView: newView];
   
       [[newView getBrowserView] loadURI:aURL flags:NSLoadFlagsNone];
   
       if (!aLoadInBG) {
         [mTabBrowser selectTabViewItem: newTab];
         // Focus the content area.
         [[newView getBrowserView] setActive: YES];
       }
   }
   
   -(void)setupSidebarTabs
   {
       IconTabViewItem   *bookItem = [[IconTabViewItem alloc] initWithIdentifier:@"bookmarkSidebarIconTabViewItem"
                                     withTabIcon:[NSImage imageNamed:@"bookicon"]];
       IconTabViewItem   *histItem = [[IconTabViewItem alloc] initWithIdentifier:@"historySidebarIconTabViewItem"
                                     withTabIcon:[NSImage imageNamed:@"historyicon"]];
       IconTabViewItem *searchItem = [[IconTabViewItem alloc] initWithIdentifier:@"searchSidebarIconTabViewItem"
                                     withTabIcon:[NSImage imageNamed:@"searchicon"]];
       IconTabViewItem *panelsItem = [[IconTabViewItem alloc] initWithIdentifier:@"myPanelsIconTabViewItem"
                                     withTabIcon:[NSImage imageNamed:@"panel_icon"]];
       
       [bookItem   setView:[[mSidebarSourceTabView tabViewItemAtIndex:0] view]];
       [histItem   setView:[[mSidebarSourceTabView tabViewItemAtIndex:1] view]];
       [searchItem setView:[[mSidebarSourceTabView tabViewItemAtIndex:2] view]];
       [panelsItem setView:[[mSidebarSourceTabView tabViewItemAtIndex:3] view]];
   
       [mSidebarTabView removeTabViewItem:[mSidebarTabView tabViewItemAtIndex:0]];
       
       [mSidebarTabView insertTabViewItem:bookItem   atIndex:0];
       [mSidebarTabView insertTabViewItem:histItem   atIndex:1];
       [mSidebarTabView insertTabViewItem:searchItem atIndex:2];
       [mSidebarTabView insertTabViewItem:panelsItem atIndex:3];
       
       [mSidebarTabView selectFirstTabViewItem:self];
   }
   
   -(void)setChromeMask:(int)aMask
   {
     mChromeMask = aMask;
   }
   
   -(void) biggerTextSize
   {
     nsCOMPtr<nsIDOMWindow> contentWindow = getter_AddRefs([[mBrowserView getBrowserView] getContentWindow]);
     nsCOMPtr<nsIScriptGlobalObject> global(do_QueryInterface(contentWindow));
     if (!global)
       return;
     nsCOMPtr<nsIDocShell> docShell;
     global->GetDocShell(getter_AddRefs(docShell));
     if (!docShell)
       return;
     nsCOMPtr<nsIContentViewer> cv;
     docShell->GetContentViewer(getter_AddRefs(cv));
     nsCOMPtr<nsIMarkupDocumentViewer> 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<nsIDOMWindow> contentWindow = getter_AddRefs([[mBrowserView getBrowserView] getContentWindow]);
     nsCOMPtr<nsIScriptGlobalObject> global(do_QueryInterface(contentWindow));
     if (!global)
       return;
     nsCOMPtr<nsIDocShell> docShell;
     global->GetDocShell(getter_AddRefs(docShell));
     if (!docShell)
       return;
     nsCOMPtr<nsIContentViewer> cv;
     docShell->GetContentViewer(getter_AddRefs(cv));
     nsCOMPtr<nsIMarkupDocumentViewer> 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);
   }
   
   -(id)getAddBookmarkSheetWindow
   {
     return mAddBookmarkSheetWindow;
   }
   
   -(id)getAddBookmarkTitle
   {
     return mAddBookmarkTitleField;
   }
   
   -(id)getAddBookmarkFolder
   {
     return mAddBookmarkFolderField;
   }
   
   // 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;
     }
     
     return result;
   }
   
   // Context menu methods
   - (IBAction)openLinkInNewWindow:(id)aSender
   {
     [self openLinkInNewWindowOrTab: YES];
   }
   
   - (IBAction)openLinkInNewTab:(id)aSender
   {
     [self openLinkInNewWindowOrTab: NO];
   }
   
   -(void)openLinkInNewWindowOrTab: (BOOL)aUseWindow
   {
     nsCOMPtr<nsIDOMElement> linkContent;
     nsAutoString href;
     GeckoUtils::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<nsIPrefBranch> pref(do_GetService("@mozilla.org/preferences-service;1"));
     if (!pref)
       return; // Something bad happened if we can't get prefs.
   
     NSString* hrefStr = [NSString stringWithCharacters: href.get() length:nsCRT::strlen(href.get())];
     NSURL* urlToLoad = [NSURL URLWithString: hrefStr];
   
     PRBool loadInBackground;
     pref->GetBoolPref("browser.tabs.loadInBackground", &loadInBackground);
   
     if (aUseWindow)
       [self openNewWindowWithURL: urlToLoad loadInBackground: loadInBackground];
     else
       [self openNewTabWithURL: urlToLoad loadInBackground: loadInBackground];
   }
   
   - (IBAction)savePageAs:(id)aSender
   {
     [self saveDocument: nil filterList: nil];
   }
   
   - (IBAction)saveLinkAs:(id)aSender
   {
     nsCOMPtr<nsIDOMElement> linkContent;
     nsAutoString href;
     GeckoUtils::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 stringWithCharacters: href.get() length:nsCRT::strlen(href.get())];
     NSURL* urlToSave = [NSURL URLWithString: hrefStr];
   
     // The user wants to save this link.
     nsAutoString text;
     GeckoUtils::GatherTextUnder(mContextMenuNode, text);
   
     [self saveURL: nil filterList: nil
               url: urlToSave suggestedFilename: [NSString stringWithCharacters: text.get()
                                                                         length:nsCRT::strlen(text.get())]];
   }
   
   - (IBAction)saveImageAs:(id)aSender
   {
     nsCOMPtr<nsIDOMHTMLImageElement> imgElement(do_QueryInterface(mContextMenuNode));
     if (imgElement) {
         nsAutoString text;
         imgElement->GetAttribute(NS_LITERAL_STRING("src"), text);
         nsAutoString url;
         imgElement->GetSrc(url);
   
         NSString* hrefStr = [NSString stringWithCharacters: url.get() length:nsCRT::strlen(url.get())];
         NSURL* urlToSave = [NSURL URLWithString: hrefStr];
   
         [self saveURL: nil filterList: nil
                   url: urlToSave suggestedFilename: [NSString stringWithCharacters: text.get()
                                                                             length:nsCRT::strlen(text.get())]];
     }
   }
   
   - (IBAction)viewOnlyThisImage:(id)aSender
   {
     nsCOMPtr<nsIDOMHTMLImageElement> imgElement(do_QueryInterface(mContextMenuNode));
     if (imgElement) {
       nsAutoString url;
       imgElement->GetSrc(url);
   
       NSString* urlStr = [NSString stringWithCharacters: url.get() length:nsCRT::strlen(url.get())];
       NSURL* urlToView = [NSURL URLWithString: urlStr];
   
       [self loadURL: urlToView];
   
       // Focus and activate our content area.
       [[mBrowserView getBrowserView] setActive: YES];
     }  
   }
   
 @end  @end
   

Removed from v.1.39  
changed lines
  Added in v.1.67


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>