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

version 1.57, 2002/04/09 01:11:32 version 1.67, 2002/04/17 10:30:13
Line 40 Line 40
 #import "IconTabViewItem.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 "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 67  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 90  static NSString *PrintToolbarItemIdentif Line 111  static NSString *PrintToolbarItemIdentif
         mInitialized = NO;          mInitialized = NO;
         mMoveReentrant = NO;          mMoveReentrant = NO;
         mShouldAutosave = YES;          mShouldAutosave = YES;
           mChromeMask = 0;
           mContextMenuFlags = 0;
           mContextMenuEvent = nsnull;
           mContextMenuNode = nsnull;
     }      }
     return self;      return self;
 }  }
Line 135  static NSString *PrintToolbarItemIdentif Line 160  static NSString *PrintToolbarItemIdentif
 {  {
     [super windowDidLoad];      [super windowDidLoad];
   
     [[mURLBar cell] setImage: [NSImage imageNamed:@"smallbookmark"]];
     
     // Get our saved dimensions.      // Get our saved dimensions.
     [[self window] setFrameUsingName: @"NavigatorWindow"];      [[self window] setFrameUsingName: @"NavigatorWindow"];
           
Line 153  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  //  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.  //      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.  //      We now remove the IB tab, then add one of our own.
Line 169  static NSString *PrintToolbarItemIdentif Line 196  static NSString *PrintToolbarItemIdentif
     [mSidebarDrawer setDelegate: self];      [mSidebarDrawer setDelegate: self];
   
     [self setupSidebarTabs];      [self setupSidebarTabs];
   
       [mPersonalToolbar initializeToolbar];
 }  }
   
 - (void)drawerWillOpen: (NSNotification*)aNotification  - (void)drawerWillOpen: (NSNotification*)aNotification
Line 176  static NSString *PrintToolbarItemIdentif Line 205  static NSString *PrintToolbarItemIdentif
   [mSidebarBookmarksDataSource ensureBookmarks];    [mSidebarBookmarksDataSource ensureBookmarks];
   
   // Force the window to shrink and move if necessary in order to accommodate the sidebar.    // Force the window to shrink and move if necessary in order to accommodate the sidebar.
  NSRect screenFrame = [[[self window] screen] frame];  NSRect screenFrame = [[[self window] screen] visibleFrame];
   NSRect windowFrame = [[self window] frame];    NSRect windowFrame = [[self window] frame];
   NSSize drawerSize = [mSidebarDrawer contentSize];    NSSize drawerSize = [mSidebarDrawer contentSize];
   int fudgeFactor = 12; // Not sure how to get the drawer's border info, so we fudge it for now.    int fudgeFactor = 12; // Not sure how to get the drawer's border info, so we fudge it for now.
Line 234  static NSString *PrintToolbarItemIdentif Line 263  static NSString *PrintToolbarItemIdentif
   
 - (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 413  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 423  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 436  static NSString *PrintToolbarItemIdentif Line 503  static NSString *PrintToolbarItemIdentif
     [[mBrowserView getBrowserView] printPreview];      [[mBrowserView getBrowserView] printPreview];
 }  }
   
- (void)findInPage:(NSString*)text- (BOOL)findInPage:(NSString*)text
 {  {
    [[mBrowserView getBrowserView] findInPage:text];    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 543  static NSString *PrintToolbarItemIdentif Line 603  static NSString *PrintToolbarItemIdentif
     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];
         }          }
     }      }
 }  }
Line 595  static NSString *PrintToolbarItemIdentif Line 662  static NSString *PrintToolbarItemIdentif
   [browser loadURL: aURL];    [browser loadURL: aURL];
   if (aLoadInBG)    if (aLoadInBG)
     [[browser window] orderWindow: NSWindowBelow relativeTo: [[self window] windowNumber]];      [[browser window] orderWindow: NSWindowBelow relativeTo: [[self window] windowNumber]];
  else  else {
    [browser showWindow: self];    // Focus the content area and show the window.
    [browser enterModalSession];
  // XXXdwh Focus the content area.    [[[browser getMyBrowserView] getBrowserView] setActive: YES];
   }
 }  }
   
 -(void)openNewTabWithURL: (NSURL*)aURL loadInBackground: (BOOL)aLoadInBG  -(void)openNewTabWithURL: (NSURL*)aURL loadInBackground: (BOOL)aLoadInBG
Line 617  static NSString *PrintToolbarItemIdentif Line 685  static NSString *PrintToolbarItemIdentif
   
     [[newView getBrowserView] loadURI:aURL flags:NSLoadFlagsNone];      [[newView getBrowserView] loadURI:aURL flags:NSLoadFlagsNone];
   
    if (!aLoadInBG)    if (!aLoadInBG) {
        [mTabBrowser selectTabViewItem: newTab];      [mTabBrowser selectTabViewItem: newTab];
              // Focus the content area.
    // XXXdwh Focus the content area.      [[newView getBrowserView] setActive: YES];
     }
 }  }
   
 -(void)setupSidebarTabs  -(void)setupSidebarTabs
Line 631  static NSString *PrintToolbarItemIdentif Line 700  static NSString *PrintToolbarItemIdentif
                                   withTabIcon:[NSImage imageNamed:@"historyicon"]];                                    withTabIcon:[NSImage imageNamed:@"historyicon"]];
     IconTabViewItem *searchItem = [[IconTabViewItem alloc] initWithIdentifier:@"searchSidebarIconTabViewItem"      IconTabViewItem *searchItem = [[IconTabViewItem alloc] initWithIdentifier:@"searchSidebarIconTabViewItem"
                                   withTabIcon:[NSImage imageNamed:@"searchicon"]];                                    withTabIcon:[NSImage imageNamed:@"searchicon"]];
    IconTabViewItem *panelsItem = [[IconTabViewItem alloc] initWithIdentifier:@"myPanelsIconTabViewItem"
                                   withTabIcon:[NSImage imageNamed:@"panel_icon"]];
     
     [bookItem   setView:[[mSidebarSourceTabView tabViewItemAtIndex:0] view]];      [bookItem   setView:[[mSidebarSourceTabView tabViewItemAtIndex:0] view]];
     [histItem   setView:[[mSidebarSourceTabView tabViewItemAtIndex:1] view]];      [histItem   setView:[[mSidebarSourceTabView tabViewItemAtIndex:1] view]];
     [searchItem setView:[[mSidebarSourceTabView tabViewItemAtIndex:2] 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:bookItem   atIndex:0];
     [mSidebarTabView insertTabViewItem:histItem   atIndex:1];      [mSidebarTabView insertTabViewItem:histItem   atIndex:1];
     [mSidebarTabView insertTabViewItem:searchItem atIndex:2];      [mSidebarTabView insertTabViewItem:searchItem atIndex:2];
    [mSidebarTabView insertTabViewItem:panelsItem atIndex:3];
     
     [mSidebarTabView selectFirstTabViewItem:self];      [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.57  
changed lines
  Added in v.1.67


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