File:  [mozdev] / chimera / BrowserWindowController.mm
Revision 1.60: download - view: text, annotated - select for diffs - revision graph
Fri Apr 12 19:45:37 2002 UTC (17 years, 1 month ago) by pinkerton
Branches: MAIN
CVS tags: HEAD
make "find again" work, as well as across multiple windows. uses a new "Find" protocol and puts all the logic in the find controller.

    1: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
    2: /* ***** BEGIN LICENSE BLOCK *****
    3:  * Version: NPL 1.1/GPL 2.0/LGPL 2.1
    4:  *
    5:  * The contents of this file are subject to the Netscape Public License
    6:  * Version 1.1 (the "License"); you may not use this file except in
    7:  * compliance with the License. You may obtain a copy of the License at
    8:  * http://www.mozilla.org/NPL/
    9:  *
   10:  * Software distributed under the License is distributed on an "AS IS" basis,
   11:  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
   12:  * for the specific language governing rights and limitations under the
   13:  * License.
   14:  *
   15:  * The Original Code is mozilla.org code.
   16:  *
   17:  * The Initial Developer of the Original Code is 
   18:  * Netscape Communications Corporation.
   19:  * Portions created by the Initial Developer are Copyright (C) 2002
   20:  * the Initial Developer. All Rights Reserved.
   21:  *
   22:  * Contributor(s):
   23:  *
   24:  * Alternatively, the contents of this file may be used under the terms of
   25:  * either the GNU General Public License Version 2 or later (the "GPL"), or 
   26:  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
   27:  * in which case the provisions of the GPL or the LGPL are applicable instead
   28:  * of those above. If you wish to allow use of your version of this file only
   29:  * under the terms of either the GPL or the LGPL, and not to allow others to
   30:  * use your version of this file under the terms of the NPL, indicate your
   31:  * decision by deleting the provisions above and replace them with the notice
   32:  * and other provisions required by the GPL or the LGPL. If you do not delete
   33:  * the provisions above, a recipient may use your version of this file under
   34:  * the terms of any one of the NPL, the GPL or the LGPL.
   35:  *
   36:  * ***** END LICENSE BLOCK ***** */
   37: 
   38: #import "BrowserWindowController.h"
   39: #import "MyBrowserView.h"
   40: #import "IconTabViewItem.h"
   41: 
   42: #include "nsIWebNavigation.h"
   43: #include "nsIDOMNode.h"
   44: #include "nsIDOMEvent.h"
   45: #include "nsIContextMenuListener.h"
   46: #include "nsCocoaBrowserService.h"
   47: 
   48: static NSString *BrowserToolbarIdentifier	= @"Browser Window Toolbar";
   49: static NSString *BackToolbarItemIdentifier	= @"Back Toolbar Item";
   50: static NSString *ForwardToolbarItemIdentifier	= @"Forward Toolbar Item";
   51: static NSString *ReloadToolbarItemIdentifier	= @"Reload Toolbar Item";
   52: static NSString *StopToolbarItemIdentifier	= @"Stop Toolbar Item";
   53: static NSString *HomeToolbarItemIdentifier	= @"Home Toolbar Item";
   54: static NSString *LocationToolbarItemIdentifier	= @"Location Toolbar Item";
   55: static NSString *SidebarToolbarItemIdentifier	= @"Sidebar Toolbar Item";
   56: static NSString *PrintToolbarItemIdentifier	= @"Print Toolbar Item";
   57: 
   58: @interface BrowserWindowController(Private)
   59: - (void)setupToolbar;
   60: - (void)setupSidebarTabs;
   61: @end
   62: 
   63: @implementation BrowserWindowController
   64: 
   65: -(void)enterModalSession
   66: {
   67:     mModalSession = [NSApp beginModalSessionForWindow: [self window]];
   68:     [NSApp runModalSession: mModalSession];
   69:     [NSApp endModalSession: mModalSession];
   70:     mModalSession = nil;
   71: }
   72: 
   73: -(void)windowDidBecomeKey: (NSNotification*)aNotification
   74: {
   75:   // May become necessary later.
   76: }
   77: 
   78: -(void)windowDidResignKey: (NSNotification*)aNotification
   79: {
   80:   // May be needed later.
   81: }
   82: 
   83: -(void)mouseMoved:(NSEvent*)aEvent
   84: {
   85:     if (mMoveReentrant)
   86:         return;
   87:         
   88:     mMoveReentrant = YES;
   89:     NSView* view = [[[self window] contentView] hitTest: [aEvent locationInWindow]];
   90:     [view mouseMoved: aEvent];
   91:     [super mouseMoved: aEvent];
   92:     mMoveReentrant = NO;
   93: }
   94: 
   95: - (id)initWithWindowNibName:(NSString *)windowNibName
   96: {
   97:     if ( (self = [super initWithWindowNibName:(NSString *)windowNibName]) ) {
   98:         if ( nsCocoaBrowserService::sNumBrowsers == 0 ) {
   99:             [self setShouldCascadeWindows:NO];
  100:         } else {
  101:             [self setShouldCascadeWindows:YES];
  102:         }
  103:         mInitialized = NO;
  104:         mMoveReentrant = NO;
  105:         mShouldAutosave = YES;
  106:         mChromeMask = 0;
  107:         mContextMenuFlags = 0;
  108:         mContextMenuEvent = nsnull;
  109:         mContextMenuNode = nsnull;
  110:     }
  111:     return self;
  112: }
  113: 
  114: -(void)autosaveWindowFrame
  115: {
  116:   if (mShouldAutosave)
  117:     [[self window] saveFrameUsingName: @"NavigatorWindow"];
  118: }
  119: 
  120: -(void)disableAutosave
  121: {
  122:   mShouldAutosave = NO;
  123: }
  124: 
  125: - (void)windowWillClose:(NSNotification *)notification
  126: {
  127:   printf("Window will close notification.\n");
  128:   [mSidebarBookmarksDataSource windowClosing];
  129: 
  130:   [self autosaveWindowFrame];
  131:   [self autorelease];
  132: }
  133: 
  134: - (void)dealloc
  135: {
  136:   printf("Browser controller died.\n");
  137: 
  138:   // Loop over all tabs, and tell them that the window is closed.
  139:   int numTabs = [mTabBrowser numberOfTabViewItems];
  140:   for (int i = 0; i < numTabs; i++) {
  141:     NSTabViewItem* item = [mTabBrowser tabViewItemAtIndex: i];
  142:     [[item view] windowClosed];
  143:   }
  144:   [mSidebarBrowserView windowClosed];
  145: 
  146:   [mProgress release];
  147:   
  148:   [super dealloc];
  149: }
  150: 
  151: - (void)windowDidLoad
  152: {
  153:     [super windowDidLoad];
  154: 
  155:     // Get our saved dimensions.
  156:     [[self window] setFrameUsingName: @"NavigatorWindow"];
  157:     
  158:     if (mModalSession)
  159:       [NSApp stopModal: mModalSession];
  160:       
  161:     mInitialized = YES;
  162: 
  163:     mDrawerCachedFrame = NO;
  164:     
  165:     // Retain with a single extra refcount.  This allows the MyBrowserViews
  166:     // to remove the progress meter from its superview without having to 
  167:     // worry about retaining and releasing it.
  168:     [mProgress retain];
  169:     
  170:     [[self window] setAcceptsMouseMovedEvents: YES];
  171:     
  172:     [self setupToolbar];
  173: 
  174: //  03/03/2002 mlj Changing strategy a bit here.  The addTab: method was
  175: //	duplicating a lot of the code found here.  I have moved it to that method.
  176: //	We now remove the IB tab, then add one of our own.
  177: 
  178:     [mTabBrowser removeTabViewItem:[mTabBrowser tabViewItemAtIndex:0]];
  179:     [self newTab];
  180:     
  181:     if (mURL) {
  182:       [self loadURL: mURL];
  183:       [mURL release];
  184:     }
  185:     
  186:     [mSidebarDrawer setDelegate: self];
  187: 
  188:     [self setupSidebarTabs];
  189: }
  190: 
  191: - (void)drawerWillOpen: (NSNotification*)aNotification
  192: {
  193:   [mSidebarBookmarksDataSource ensureBookmarks];
  194: 
  195:   // Force the window to shrink and move if necessary in order to accommodate the sidebar.
  196:   NSRect screenFrame = [[[self window] screen] frame];
  197:   NSRect windowFrame = [[self window] frame];
  198:   NSSize drawerSize = [mSidebarDrawer contentSize];
  199:   int fudgeFactor = 12; // Not sure how to get the drawer's border info, so we fudge it for now.
  200:   drawerSize.width += fudgeFactor;
  201:   if (windowFrame.origin.x + windowFrame.size.width + drawerSize.width >
  202:       screenFrame.size.width) {
  203:     // We need to adjust the window so that it can fit.
  204:     int shrinkDelta = (windowFrame.size.width + drawerSize.width) - screenFrame.size.width;
  205:     if (shrinkDelta < 0) shrinkDelta = 0;
  206:     int newWidth = (windowFrame.size.width - shrinkDelta);
  207:     int newPosition = screenFrame.size.width - newWidth - drawerSize.width;
  208:     if (newPosition < 0) newPosition = 0;
  209:     mCachedFrameBeforeDrawerOpen = windowFrame;
  210:     windowFrame.origin.x = newPosition;
  211:     windowFrame.size.width = newWidth;
  212:     mCachedFrameAfterDrawerOpen = windowFrame;
  213:     [[self window] setFrame: windowFrame display: YES];
  214:     mDrawerCachedFrame = YES;
  215:   }
  216: }
  217: 
  218: - (void)drawerDidOpen:(NSNotification *)aNotification
  219: {
  220:   // XXXdwh This is temporary.
  221:   //  [[mSidebarBrowserView getBrowserView] loadURI: [NSURL URLWithString: @"http://tinderbox.mozilla.org/SeaMonkey/panel.html"] flags:NSLoadFlagsNone];
  222: 
  223:   // Toggle the sidebar icon.
  224:   [mSidebarToolbarItem setImage:[NSImage imageNamed:@"sidebarOpened"]];
  225: }
  226: 
  227: - (void)drawerDidClose:(NSNotification *)aNotification
  228: {
  229:   // Unload the Gecko web page in "My Panels" to save memory.
  230:   [mSidebarToolbarItem setImage:[NSImage imageNamed:@"sidebarClosed"]];
  231: 
  232:   // XXXdwh ignore for now.
  233:   //  [[mSidebarBrowserView getBrowserView] loadURI: [NSURL URLWithString: @"about:blank"] flags:NSLoadFlagsNone];
  234: 
  235:   if (mDrawerCachedFrame) {
  236:     printf("Got here.\n");
  237:     mDrawerCachedFrame = NO;
  238:     NSRect frame = [[self window] frame];
  239:     if (frame.origin.x == mCachedFrameAfterDrawerOpen.origin.x &&
  240:         frame.origin.y == mCachedFrameAfterDrawerOpen.origin.y &&
  241:         frame.size.width == mCachedFrameAfterDrawerOpen.size.width &&
  242:         frame.size.height == mCachedFrameAfterDrawerOpen.size.height) {
  243:       printf("Got here too.\n");
  244:       printf("Xes are %d %d\n", frame.origin.x, mCachedFrameAfterDrawerOpen.origin.x);
  245:       printf("Widths are %d %d\n", frame.size.width, mCachedFrameAfterDrawerOpen.size.width);
  246:       // Restore the original frame.
  247:       [[self window] setFrame: mCachedFrameBeforeDrawerOpen display: YES];
  248:     }
  249:   }
  250: }
  251: 
  252: - (void)setupToolbar
  253: {
  254:   if (mChromeMask) {
  255:     printf("Uh-oh. %d\n", mChromeMask);
  256:   }
  257:   
  258:     NSToolbar *toolbar = [[[NSToolbar alloc] initWithIdentifier:BrowserToolbarIdentifier] autorelease];
  259:     
  260:     [toolbar setDisplayMode:NSToolbarDisplayModeDefault];
  261:     [toolbar setAllowsUserCustomization:YES];
  262:     [toolbar setAutosavesConfiguration:YES];
  263:     [toolbar setDelegate:self];
  264:     [[self window] setToolbar:toolbar];
  265: }
  266: 
  267: 
  268: - (NSArray *)toolbarAllowedItemIdentifiers:(NSToolbar *)toolbar
  269: {
  270:     return [NSArray arrayWithObjects:	BackToolbarItemIdentifier,
  271:                                         ForwardToolbarItemIdentifier,
  272:                                         ReloadToolbarItemIdentifier,
  273:                                         StopToolbarItemIdentifier,
  274:                                         HomeToolbarItemIdentifier,
  275:                                         LocationToolbarItemIdentifier,
  276:                                         SidebarToolbarItemIdentifier,
  277:                                         PrintToolbarItemIdentifier,
  278:                                         NSToolbarCustomizeToolbarItemIdentifier,
  279:                                         NSToolbarFlexibleSpaceItemIdentifier,
  280:                                         NSToolbarSpaceItemIdentifier,
  281:                                         NSToolbarSeparatorItemIdentifier,
  282:                                         nil];
  283: }
  284: 
  285: - (NSArray *)toolbarDefaultItemIdentifiers:(NSToolbar *)toolbar
  286: {
  287:     return [NSArray arrayWithObjects:	BackToolbarItemIdentifier,
  288:                                         ForwardToolbarItemIdentifier,
  289:                                         ReloadToolbarItemIdentifier,
  290:                                         StopToolbarItemIdentifier,
  291:                                         HomeToolbarItemIdentifier,
  292:                                         LocationToolbarItemIdentifier,
  293:                                         SidebarToolbarItemIdentifier,
  294:                                         nil];
  295: }
  296: 
  297: - (NSToolbarItem *) toolbar:(NSToolbar *)toolbar
  298:       itemForItemIdentifier:(NSString *)itemIdent
  299:   willBeInsertedIntoToolbar:(BOOL)willBeInserted
  300: {
  301:     NSToolbarItem *toolbarItem = [[[NSToolbarItem alloc] initWithItemIdentifier:itemIdent] autorelease];
  302:     if ( [itemIdent isEqual:BackToolbarItemIdentifier] ) {
  303:         [toolbarItem setLabel:@"Back"];
  304:         [toolbarItem setPaletteLabel:@"Go Back"];
  305:         [toolbarItem setToolTip:@"Go back one page"];
  306:         [toolbarItem setImage:[NSImage imageNamed:@"back"]];
  307:         [toolbarItem setTarget:self];
  308:         [toolbarItem setAction:@selector(back:)];
  309:     } else if ( [itemIdent isEqual:ForwardToolbarItemIdentifier] ) {
  310:         [toolbarItem setLabel:@"Forward"];
  311:         [toolbarItem setPaletteLabel:@"Go Forward"];
  312:         [toolbarItem setToolTip:@"Go forward one page"];
  313:         [toolbarItem setImage:[NSImage imageNamed:@"forward"]];
  314:         [toolbarItem setTarget:self];
  315:         [toolbarItem setAction:@selector(forward:)];
  316:     } else if ( [itemIdent isEqual:ReloadToolbarItemIdentifier] ) {
  317:         [toolbarItem setLabel:@"Reload"];
  318:         [toolbarItem setPaletteLabel:@"Reload Page"];
  319:         [toolbarItem setToolTip:@"Reload current page"];
  320:         [toolbarItem setImage:[NSImage imageNamed:@"reload"]];
  321:         [toolbarItem setTarget:self];
  322:         [toolbarItem setAction:@selector(reload:)];
  323:     } else if ( [itemIdent isEqual:StopToolbarItemIdentifier] ) {
  324:         [toolbarItem setLabel:@"Stop"];
  325:         [toolbarItem setPaletteLabel:@"Stop Loading"];
  326:         [toolbarItem setToolTip:@"Stop loading this page"];
  327:         [toolbarItem setImage:[NSImage imageNamed:@"stop"]];
  328:         [toolbarItem setTarget:self];
  329:         [toolbarItem setAction:@selector(stop:)];
  330:     } else if ( [itemIdent isEqual:HomeToolbarItemIdentifier] ) {
  331:         [toolbarItem setLabel:@"Home"];
  332:         [toolbarItem setPaletteLabel:@"Go Home"];
  333:         [toolbarItem setToolTip:@"Go to home page"];
  334:         [toolbarItem setImage:[NSImage imageNamed:@"home"]];
  335:         [toolbarItem setTarget:self];
  336:         [toolbarItem setAction:@selector(home:)];
  337:     } else if ( [itemIdent isEqual:SidebarToolbarItemIdentifier] ) {
  338:         [toolbarItem setLabel:@"Sidebar"];
  339:         [toolbarItem setPaletteLabel:@"Toggle Sidebar"];
  340:         [toolbarItem setToolTip:@"Show or hide the Sidebar"];
  341:         [toolbarItem setImage:[NSImage imageNamed:@"sidebarClosed"]];
  342:         [toolbarItem setTarget:self];
  343:         [toolbarItem setAction:@selector(toggleSidebar:)];
  344:         mSidebarToolbarItem = toolbarItem;
  345:     } else if ( [itemIdent isEqual:LocationToolbarItemIdentifier] ) {
  346:         
  347:         NSMenuItem *menuFormRep = [[[NSMenuItem alloc] init] autorelease];
  348:         
  349:         [toolbarItem setLabel:@"Location"];
  350:         [toolbarItem setPaletteLabel:@"Location"];
  351:         [toolbarItem setImage:[NSImage imageNamed:@"Enter a web location."]];
  352:         [toolbarItem setView:mLocationToolbarView];
  353:         [toolbarItem setMinSize:NSMakeSize(128,32)];
  354:         [toolbarItem setMaxSize:NSMakeSize(2560,32)];
  355:         
  356:         [menuFormRep setTarget:self];
  357:         [menuFormRep setAction:@selector(performAppropriateLocationAction)];
  358:         [menuFormRep setTitle:[toolbarItem label]];
  359:         
  360:         [toolbarItem setMenuFormRepresentation:menuFormRep];
  361:         mLocationToolbarItem = toolbarItem;
  362: 
  363:     } else if ( [itemIdent isEqual:PrintToolbarItemIdentifier] ) {
  364:         [toolbarItem setLabel:@"Print"];
  365:         [toolbarItem setPaletteLabel:@"Print"];
  366:         [toolbarItem setToolTip:@"Print this page"];
  367:         [toolbarItem setImage:[NSImage imageNamed:@"print"]];
  368:         [toolbarItem setTarget:self];
  369:         [toolbarItem setAction:@selector(printDocument)];
  370:     } else {
  371:         toolbarItem = nil;
  372:     }
  373:         
  374:     return toolbarItem;
  375: }
  376: 
  377: // This method handles the enabling/disabling of the toolbar buttons.
  378: - (BOOL)validateToolbarItem:(NSToolbarItem *)theItem
  379: {
  380:   // Check the action and see if it matches.
  381:   SEL action = [theItem action];
  382:   if (action == @selector(back:))
  383:     return [[mBrowserView getBrowserView] canGoBack];
  384:   else if (action == @selector(forward:))
  385:     return [[mBrowserView getBrowserView] canGoForward];
  386:   else if (action == @selector(reload:))
  387:     return [mBrowserView isBusy] == NO;
  388:   else if (action == @selector(stop:))
  389:     return [mBrowserView isBusy];
  390:   else
  391:     return YES;
  392: }
  393:    
  394: - (void)updateToolbarItems
  395: {
  396:   [[[self window] toolbar] validateVisibleItems];
  397: }
  398: 
  399: - (void)performAppropriateLocationAction
  400: {
  401:     if ( [[[self window] toolbar] isVisible] ) {
  402:         if ( ([[[self window] toolbar] displayMode] == NSToolbarDisplayModeIconAndLabel) ||
  403:              ([[[self window] toolbar] displayMode] == NSToolbarDisplayModeIconOnly) ) {
  404:             [self focusURLBar];
  405:         } else {
  406:             [self beginLocationSheet];
  407:         }
  408:     } else {
  409:         [self beginLocationSheet];
  410:     }
  411: }
  412: 
  413: - (void)focusURLBar
  414: {
  415:     [mURLBar selectText: self];
  416: }
  417: 
  418: - (void)beginLocationSheet
  419: {
  420:     [NSApp beginSheet:	mLocationSheetWindow
  421:        modalForWindow:	[self window]
  422:         modalDelegate:	nil
  423:        didEndSelector:	nil
  424:           contextInfo:	nil];
  425: }
  426: 
  427: - (IBAction)endLocationSheet:(id)sender
  428: {
  429:     [mLocationSheetWindow orderOut:self];
  430:     [NSApp endSheet:mLocationSheetWindow returnCode:1];
  431:     [self loadURL:[NSURL URLWithString:[mLocationSheetURLField stringValue]]];
  432:     
  433:     // Focus and activate our content area.
  434:     [[mBrowserView getBrowserView] setActive: YES];
  435: }
  436: 
  437: - (IBAction)goToLocationFromToolbarURLField:(id)sender
  438: {
  439:     [self loadURL:[NSURL URLWithString:[sender stringValue]]];
  440:     
  441:     // Focus and activate our content area.
  442:     [[mBrowserView getBrowserView] setActive: YES];
  443: }
  444: 
  445: - (void)saveDocument: (NSView*)aFilterView filterList: (NSPopUpButton*)aFilterList
  446: {
  447:     [[mBrowserView getBrowserView] saveDocument: aFilterView filterList: aFilterList];
  448: }
  449: 
  450: - (void)printDocument
  451: {
  452:     [[mBrowserView getBrowserView] printDocument];
  453: }
  454: 
  455: - (void)printPreview
  456: {
  457:     [[mBrowserView getBrowserView] printPreview];
  458: }
  459: 
  460: - (BOOL)findInPage:(NSString*)text
  461: {
  462:     return [[mBrowserView getBrowserView] findInPage:text];
  463: }
  464: 
  465: - (void)addBookmark
  466: {
  467:     // XXXdwh Hack.  Just go to the sidebar for now until we get our
  468:     // menu data source going.
  469:     [mSidebarBookmarksDataSource ensureBookmarks];
  470:     [mSidebarBookmarksDataSource addBookmark: self];
  471: }
  472: 
  473: - (IBAction)back:(id)aSender
  474: {
  475:   [[mBrowserView getBrowserView] goBack];
  476: }
  477: 
  478: - (IBAction)forward:(id)aSender
  479: {
  480:   [[mBrowserView getBrowserView] goForward];
  481: }
  482: 
  483: - (IBAction)reload:(id)aSender
  484: {
  485:   [[mBrowserView getBrowserView] reload: 0];
  486: }
  487: 
  488: - (IBAction)stop:(id)aSender
  489: {
  490:   [[mBrowserView getBrowserView] stop: nsIWebNavigation::STOP_ALL];
  491: }
  492: 
  493: - (IBAction)home:(id)aSender
  494: {
  495:   [[mBrowserView getBrowserView] loadURI:[NSURL URLWithString:@"about:blank"] flags:NSLoadFlagsNone];
  496: }
  497: 
  498: - (IBAction)toggleSidebar:(id)aSender
  499: {
  500:     NSResponder* resp = [[self window] firstResponder];
  501:     [[self window] makeFirstResponder: nil];
  502:     
  503:     if ( ([mSidebarDrawer state] == NSDrawerClosedState) || ([mSidebarDrawer state] == NSDrawerClosingState) ) 	{
  504:         // XXXHack to bypass sidebar crashes.
  505:         [mSidebarDrawer openOnEdge: NSMaxXEdge];
  506:     } else {
  507:         [mSidebarDrawer close];
  508:     }
  509:     
  510:     [[self window] makeFirstResponder: resp];
  511: }
  512: 
  513: 
  514: -(void)loadURL:(NSURL*)aURL
  515: {
  516:     if (mInitialized) {
  517:         [[mBrowserView getBrowserView] loadURI:aURL flags:NSLoadFlagsNone];
  518:     }
  519:     else {
  520:         mURL = aURL;
  521:         [mURL retain];
  522:     }
  523: }
  524: 
  525: - (void)updateLocationFields:(NSString *)locationString
  526: {
  527: /* //commenting this out because it doesn't work right yet.
  528:     if ( [locationString length] > 30 ) {
  529:         [[mLocationToolbarItem menuFormRepresentation] setTitle:
  530:             [NSString stringWithFormat:@"Location: %@...", [locationString substringToIndex:31]]];
  531:     } else {
  532:         [[mLocationToolbarItem menuFormRepresentation] setTitle:
  533:             [NSString stringWithFormat:@"Location: %@", locationString]];
  534:     }
  535: */
  536: 
  537:     [mURLBar setStringValue:locationString];
  538:     [mLocationSheetURLField setStringValue:locationString];
  539: 
  540:     [[self window] update];
  541:     [[self window] display];
  542: }
  543: 
  544: -(void)newTab
  545: {
  546:     NSTabViewItem* newTab = [[[NSTabViewItem alloc] initWithIdentifier: nil] autorelease];
  547:     MyBrowserView* newView = [[[MyBrowserView alloc] initWithFrame: [mBrowserView frame]] autorelease];
  548:     [newView setTab: newTab];
  549: 
  550:     [newTab setLabel: @"Untitled"];
  551:     [newTab setView: newView];
  552: 
  553:     [mTabBrowser addTabViewItem: newTab];
  554: 
  555:     [[newView getBrowserView] loadURI:[NSURL URLWithString:@"about:blank"] flags:NSLoadFlagsNone];
  556: 
  557:     [mTabBrowser selectLastTabViewItem: self];
  558: 
  559:     if ( [[[self window] toolbar] isVisible] ) {
  560:         if ( ([[[self window] toolbar] displayMode] == NSToolbarDisplayModeIconAndLabel) ||
  561:              ([[[self window] toolbar] displayMode] == NSToolbarDisplayModeIconOnly) ) {
  562:           [[mBrowserView getBrowserView] setActive: NO];
  563:           [self focusURLBar];
  564:         }
  565:     }
  566: }
  567: 
  568: -(void)closeTab
  569: {
  570:   if ( [mTabBrowser numberOfTabViewItems] > 1 ) {
  571:     [[[mTabBrowser selectedTabViewItem] view] windowClosed];
  572:     [mTabBrowser removeTabViewItem:[mTabBrowser selectedTabViewItem]];
  573:   }
  574: }
  575: 
  576: - (void)previousTab
  577: {
  578:     [mTabBrowser selectPreviousTabViewItem:self];
  579: }
  580: 
  581: - (void)nextTab
  582: {
  583:     [mTabBrowser selectNextTabViewItem:self];
  584: }
  585: 
  586: - (void)tabView:(NSTabView *)aTabView didSelectTabViewItem:(NSTabViewItem *)aTabViewItem
  587: {
  588:     // Disconnect the old view, if one has been designated.
  589:     // If the window has just been opened, none has been.
  590:     if ( mBrowserView ) {
  591:         [mBrowserView disconnectView];
  592:     }
  593:     // Connect up the new view
  594:     mBrowserView = [aTabViewItem view];
  595:        
  596:     // Make the new view the primary content area.
  597:     [mBrowserView makePrimaryBrowserView: mURLBar status: mStatus
  598:         progress: mProgress windowController: self];
  599: }
  600: 
  601: -(MyBrowserView*)getMyBrowserView
  602: {
  603:     return mBrowserView;
  604: }
  605: 
  606: -(void)openNewWindowWithURL: (NSURL*)aURL loadInBackground: (BOOL)aLoadInBG
  607: {
  608:   // Autosave our dimensions before we open a new window.  That ensures the size ends up matching.
  609:   [self autosaveWindowFrame];
  610: 
  611:   BrowserWindowController* browser = [[BrowserWindowController alloc] initWithWindowNibName: @"BrowserWindow"];
  612:   [browser loadURL: aURL];
  613:   if (aLoadInBG)
  614:     [[browser window] orderWindow: NSWindowBelow relativeTo: [[self window] windowNumber]];
  615:   else
  616:     [browser showWindow: self];
  617: 
  618:   // XXXdwh Focus the content area.
  619: }
  620: 
  621: -(void)openNewTabWithURL: (NSURL*)aURL loadInBackground: (BOOL)aLoadInBG
  622: {
  623:     NSTabViewItem* newTab = [[[NSTabViewItem alloc] initWithIdentifier: nil] autorelease];
  624:     
  625:     NSTabViewItem* selectedTab = [mTabBrowser selectedTabViewItem];
  626:     int index = [mTabBrowser indexOfTabViewItem: selectedTab];
  627:     [mTabBrowser insertTabViewItem: newTab atIndex: index+1];
  628:     
  629:     MyBrowserView* newView = [[[MyBrowserView alloc] initWithFrame: [mBrowserView frame]] autorelease];
  630:     [newView setTab: newTab];
  631:     
  632:     [newTab setLabel: @"Loading..."];
  633:     [newTab setView: newView];
  634: 
  635:     [[newView getBrowserView] loadURI:aURL flags:NSLoadFlagsNone];
  636: 
  637:     if (!aLoadInBG)
  638:         [mTabBrowser selectTabViewItem: newTab];
  639:         
  640:     // XXXdwh Focus the content area.
  641: }
  642: 
  643: -(void)setupSidebarTabs
  644: {
  645:     IconTabViewItem   *bookItem = [[IconTabViewItem alloc] initWithIdentifier:@"bookmarkSidebarIconTabViewItem"
  646:                                   withTabIcon:[NSImage imageNamed:@"bookicon"]];
  647:     IconTabViewItem   *histItem = [[IconTabViewItem alloc] initWithIdentifier:@"historySidebarIconTabViewItem"
  648:                                   withTabIcon:[NSImage imageNamed:@"historyicon"]];
  649:     IconTabViewItem *searchItem = [[IconTabViewItem alloc] initWithIdentifier:@"searchSidebarIconTabViewItem"
  650:                                   withTabIcon:[NSImage imageNamed:@"searchicon"]];
  651: 
  652:     [bookItem   setView:[[mSidebarSourceTabView tabViewItemAtIndex:0] view]];
  653:     [histItem   setView:[[mSidebarSourceTabView tabViewItemAtIndex:1] view]];
  654:     [searchItem setView:[[mSidebarSourceTabView tabViewItemAtIndex:2] view]];
  655: 
  656:     [mSidebarTabView insertTabViewItem:bookItem   atIndex:0];
  657:     [mSidebarTabView insertTabViewItem:histItem   atIndex:1];
  658:     [mSidebarTabView insertTabViewItem:searchItem atIndex:2];
  659: 
  660:     [mSidebarTabView selectFirstTabViewItem:self];
  661: }
  662: 
  663: -(void)setChromeMask:(int)aMask
  664: {
  665:   mChromeMask = aMask;
  666: }
  667: 
  668: // Called when a context menu should be shown.
  669: - (void)onShowContextMenu:(int)flags domEvent:(nsIDOMEvent*)aEvent domNode:(nsIDOMNode*)aNode
  670: {
  671:   mContextMenuFlags = flags;
  672:   mContextMenuNode = aNode;
  673:   NS_IF_ADDREF(aNode);
  674:   mContextMenuEvent = aEvent;
  675:   NS_IF_ADDREF(aEvent);
  676: }
  677: 
  678: - (NSMenu*)getContextMenu
  679: {
  680:   NSMenu* result = nil;
  681:   if ((mContextMenuFlags & nsIContextMenuListener::CONTEXT_LINK) != 0) {
  682:     if ((mContextMenuFlags & nsIContextMenuListener::CONTEXT_IMAGE) != 0) {
  683:       result = mImageLinkMenu;
  684:     }
  685:     else
  686:       result = mLinkMenu;
  687:   }
  688:   else if ((mContextMenuFlags & nsIContextMenuListener::CONTEXT_INPUT) != 0 ||
  689:            (mContextMenuFlags & nsIContextMenuListener::CONTEXT_TEXT) != 0) {
  690:     result = mInputMenu;
  691:   }
  692:   else if ((mContextMenuFlags & nsIContextMenuListener::CONTEXT_IMAGE) != 0) {
  693:     result = mImageMenu;
  694:   }
  695:   else if ((mContextMenuFlags & nsIContextMenuListener::CONTEXT_DOCUMENT) != 0) {
  696:     result = mPageMenu;
  697:   }
  698:   
  699:   NS_IF_RELEASE(mContextMenuNode);
  700:   mContextMenuNode = nsnull;
  701:   NS_IF_RELEASE(mContextMenuEvent);
  702:   mContextMenuEvent = nsnull;
  703:   return result;
  704: }
  705: 
  706: @end
  707: 

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