Diff for /chimera/BrowserWindowController.mm between versions 1.61 and 1.71

version 1.61, 2002/04/14 00:08:17 version 1.71, 2002/04/19 18:04:05
Line 44 Line 44
 #include "nsIDOMEvent.h"  #include "nsIDOMEvent.h"
 #include "nsIPrefBranch.h"  #include "nsIPrefBranch.h"
 #include "nsIContextMenuListener.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 "nsString.h"
 #include "GeckoUtils.h"  #include "GeckoUtils.h"
Line 155  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"];
           
     if (mModalSession)      if (mModalSession)
      [NSApp stopModal: mModalSession];      [NSApp stopModal];
               
     mInitialized = YES;      mInitialized = YES;
   
Line 173  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 189  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 196  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 204  static NSString *PrintToolbarItemIdentif Line 213  static NSString *PrintToolbarItemIdentif
   if (windowFrame.origin.x + windowFrame.size.width + drawerSize.width >    if (windowFrame.origin.x + windowFrame.size.width + drawerSize.width >
       screenFrame.size.width) {        screenFrame.size.width) {
     // We need to adjust the window so that it can fit.      // We need to adjust the window so that it can fit.
    int shrinkDelta = (windowFrame.size.width + drawerSize.width) - screenFrame.size.width;    float shrinkDelta = (windowFrame.size.width + drawerSize.width) - screenFrame.size.width;
     if (shrinkDelta < 0) shrinkDelta = 0;      if (shrinkDelta < 0) shrinkDelta = 0;
    int newWidth = (windowFrame.size.width - shrinkDelta);    float newWidth = (windowFrame.size.width - shrinkDelta);
    int newPosition = screenFrame.size.width - newWidth - drawerSize.width;    float newPosition = screenFrame.size.width - newWidth - drawerSize.width;
     if (newPosition < 0) newPosition = 0;      if (newPosition < 0) newPosition = 0;
     mCachedFrameBeforeDrawerOpen = windowFrame;      mCachedFrameBeforeDrawerOpen = windowFrame;
     windowFrame.origin.x = newPosition;      windowFrame.origin.x = newPosition;
Line 244  static NSString *PrintToolbarItemIdentif Line 253  static NSString *PrintToolbarItemIdentif
         frame.size.width == mCachedFrameAfterDrawerOpen.size.width &&          frame.size.width == mCachedFrameAfterDrawerOpen.size.width &&
         frame.size.height == mCachedFrameAfterDrawerOpen.size.height) {          frame.size.height == mCachedFrameAfterDrawerOpen.size.height) {
       printf("Got here too.\n");        printf("Got here too.\n");
      printf("Xes are %d %d\n", frame.origin.x, mCachedFrameAfterDrawerOpen.origin.x);      printf("Xes are %f %f\n", frame.origin.x, mCachedFrameAfterDrawerOpen.origin.x);
      printf("Widths are %d %d\n", frame.size.width, mCachedFrameAfterDrawerOpen.size.width);      printf("Widths are %f %f\n", frame.size.width, mCachedFrameAfterDrawerOpen.size.width);
       // Restore the original frame.        // Restore the original frame.
       [[self window] setFrame: mCachedFrameBeforeDrawerOpen display: YES];        [[self window] setFrame: mCachedFrameBeforeDrawerOpen display: YES];
     }      }
Line 437  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 state] == NSDrawerClosedState)
       [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 447  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 465  static NSString *PrintToolbarItemIdentif Line 508  static NSString *PrintToolbarItemIdentif
     return [[mBrowserView getBrowserView] findInPage:text];      return [[mBrowserView getBrowserView] findInPage:text];
 }  }
   
- (void)addBookmark- (void)addBookmarkExtended: (BOOL)aIsFromMenu isFolder:(BOOL)aIsFolder
 {  {
    // XXXdwh Hack.  Just go to the sidebar for now until we get our  [mSidebarBookmarksDataSource ensureBookmarks];
    // menu data source going.  [mSidebarBookmarksDataSource addBookmark: self useSelection: !aIsFromMenu isFolder: aIsFolder];
    [mSidebarBookmarksDataSource ensureBookmarks]; 
    [mSidebarBookmarksDataSource addBookmark: self]; 
 }  }
   
 - (IBAction)back:(id)aSender  - (IBAction)back:(id)aSender
Line 607  static NSString *PrintToolbarItemIdentif Line 648  static NSString *PrintToolbarItemIdentif
         progress: mProgress windowController: self];          progress: mProgress windowController: self];
 }  }
   
   -(id)getTabBrowser
   {
     return mTabBrowser;
   }
   
 -(MyBrowserView*)getMyBrowserView  -(MyBrowserView*)getMyBrowserView
 {  {
    return mBrowserView;  return mBrowserView;
 }  }
   
 -(void)openNewWindowWithURL: (NSURL*)aURL loadInBackground: (BOOL)aLoadInBG  -(void)openNewWindowWithURL: (NSURL*)aURL loadInBackground: (BOOL)aLoadInBG
Line 621  static NSString *PrintToolbarItemIdentif Line 667  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 {
     // Focus the content area and show the window.      // Focus the content area and show the window.
    [browser showWindow: self];    [browser enterModalSession];
     [[[browser getMyBrowserView] getBrowserView] setActive: YES];
   }
 }  }
   
 -(void)openNewTabWithURL: (NSURL*)aURL loadInBackground: (BOOL)aLoadInBG  -(void)openNewTabWithURL: (NSURL*)aURL loadInBackground: (BOOL)aLoadInBG
Line 657  static NSString *PrintToolbarItemIdentif Line 705  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];
 }  }
   
Line 674  static NSString *PrintToolbarItemIdentif Line 728  static NSString *PrintToolbarItemIdentif
   mChromeMask = 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.  // Called when a context menu should be shown.
 - (void)onShowContextMenu:(int)flags domEvent:(nsIDOMEvent*)aEvent domNode:(nsIDOMNode*)aNode  - (void)onShowContextMenu:(int)flags domEvent:(nsIDOMEvent*)aEvent domNode:(nsIDOMNode*)aNode
 {  {
Line 744  static NSString *PrintToolbarItemIdentif Line 867  static NSString *PrintToolbarItemIdentif
     [self openNewTabWithURL: urlToLoad loadInBackground: loadInBackground];      [self openNewTabWithURL: urlToLoad loadInBackground: loadInBackground];
 }  }
   
   - (IBAction)savePageAs:(id)aSender
   {
     [self saveDocument: nil filterList: nil];
   }
   
 - (IBAction)saveLinkAs:(id)aSender  - (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  - (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];
     }  
   }
   
   - (NSView*) bookmarksToolbar
   {
     return mPersonalToolbar;
 }  }
   
 @end  @end

Removed from v.1.61  
changed lines
  Added in v.1.71


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