Annotation of chimera/BrowserWindowController.mm, revision 1.59

1.44      hyatt       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 ***** */
1.1       hyatt      37: 
                     38: #import "BrowserWindowController.h"
                     39: #import "MyBrowserView.h"
1.50      macserv    40: #import "IconTabViewItem.h"
1.1       hyatt      41: 
1.37      hyatt      42: #include "nsIWebNavigation.h"
1.59    ! hyatt      43: #include "nsIDOMNode.h"
        !            44: #include "nsIDOMEvent.h"
        !            45: #include "nsIContextMenuListener.h"
1.51      macserv    46: #include "nsCocoaBrowserService.h"
1.37      hyatt      47: 
1.1       hyatt      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";
1.11      macserv    56: static NSString *PrintToolbarItemIdentifier  = @"Print Toolbar Item";
1.1       hyatt      57: 
                     58: @interface BrowserWindowController(Private)
                     59: - (void)setupToolbar;
1.52      macserv    60: - (void)setupSidebarTabs;
1.1       hyatt      61: @end
                     62: 
                     63: @implementation BrowserWindowController
                     64: 
1.39      hyatt      65: -(void)enterModalSession
                     66: {
                     67:     mModalSession = [NSApp beginModalSessionForWindow: [self window]];
                     68:     [NSApp runModalSession: mModalSession];
                     69:     [NSApp endModalSession: mModalSession];
                     70:     mModalSession = nil;
                     71: }
                     72: 
1.58      hyatt      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: 
1.35      hyatt      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: 
1.41      macserv    95: - (id)initWithWindowNibName:(NSString *)windowNibName
1.4       hyatt      96: {
1.41      macserv    97:     if ( (self = [super initWithWindowNibName:(NSString *)windowNibName]) ) {
1.51      macserv    98:         if ( nsCocoaBrowserService::sNumBrowsers == 0 ) {
                     99:             [self setShouldCascadeWindows:NO];
                    100:         } else {
                    101:             [self setShouldCascadeWindows:YES];
                    102:         }
1.41      macserv   103:         mInitialized = NO;
                    104:         mMoveReentrant = NO;
1.48      hyatt     105:         mShouldAutosave = YES;
1.58      hyatt     106:         mChromeMask = 0;
1.59    ! hyatt     107:         mContextMenuFlags = 0;
        !           108:         mContextMenuEvent = nsnull;
        !           109:         mContextMenuNode = nsnull;
1.41      macserv   110:     }
                    111:     return self;
1.4       hyatt     112: }
                    113: 
1.48      hyatt     114: -(void)autosaveWindowFrame
                    115: {
                    116:   if (mShouldAutosave)
                    117:     [[self window] saveFrameUsingName: @"NavigatorWindow"];
                    118: }
                    119: 
                    120: -(void)disableAutosave
                    121: {
                    122:   mShouldAutosave = NO;
                    123: }
                    124: 
1.17      hyatt     125: - (void)windowWillClose:(NSNotification *)notification
                    126: {
1.49      hyatt     127:   printf("Window will close notification.\n");
                    128:   [mSidebarBookmarksDataSource windowClosing];
1.48      hyatt     129: 
1.49      hyatt     130:   [self autosaveWindowFrame];
                    131:   [self autorelease];
1.17      hyatt     132: }
                    133: 
1.7       hyatt     134: - (void)dealloc
                    135: {
1.49      hyatt     136:   printf("Browser controller died.\n");
1.40      hyatt     137: 
1.49      hyatt     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];
1.7       hyatt     149: }
                    150: 
1.1       hyatt     151: - (void)windowDidLoad
                    152: {
1.35      hyatt     153:     [super windowDidLoad];
1.48      hyatt     154: 
                    155:     // Get our saved dimensions.
                    156:     [[self window] setFrameUsingName: @"NavigatorWindow"];
1.35      hyatt     157:     
1.39      hyatt     158:     if (mModalSession)
                    159:       [NSApp stopModal: mModalSession];
                    160:       
1.4       hyatt     161:     mInitialized = YES;
1.57      hyatt     162: 
                    163:     mDrawerCachedFrame = NO;
1.38      hyatt     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:     
1.34      hyatt     170:     [[self window] setAcceptsMouseMovedEvents: YES];
                    171:     
1.1       hyatt     172:     [self setupToolbar];
1.30      hyatt     173: 
1.41      macserv   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];
1.4       hyatt     180:     
                    181:     if (mURL) {
                    182:       [self loadURL: mURL];
                    183:       [mURL release];
                    184:     }
1.18      hyatt     185:     
                    186:     [mSidebarDrawer setDelegate: self];
1.50      macserv   187: 
1.52      macserv   188:     [self setupSidebarTabs];
1.18      hyatt     189: }
                    190: 
1.22      hyatt     191: - (void)drawerWillOpen: (NSNotification*)aNotification
                    192: {
1.57      hyatt     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:   }
1.22      hyatt     216: }
                    217: 
1.18      hyatt     218: - (void)drawerDidOpen:(NSNotification *)aNotification
                    219: {
1.57      hyatt     220:   // XXXdwh This is temporary.
1.56      hyatt     221:   //  [[mSidebarBrowserView getBrowserView] loadURI: [NSURL URLWithString: @"http://tinderbox.mozilla.org/SeaMonkey/panel.html"] flags:NSLoadFlagsNone];
1.57      hyatt     222: 
                    223:   // Toggle the sidebar icon.
                    224:   [mSidebarToolbarItem setImage:[NSImage imageNamed:@"sidebarOpened"]];
1.1       hyatt     225: }
                    226: 
1.19      hyatt     227: - (void)drawerDidClose:(NSNotification *)aNotification
                    228: {
1.57      hyatt     229:   // Unload the Gecko web page in "My Panels" to save memory.
                    230:   [mSidebarToolbarItem setImage:[NSImage imageNamed:@"sidebarClosed"]];
                    231: 
                    232:   // XXXdwh ignore for now.
1.56      hyatt     233:   //  [[mSidebarBrowserView getBrowserView] loadURI: [NSURL URLWithString: @"about:blank"] flags:NSLoadFlagsNone];
1.57      hyatt     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:   }
1.19      hyatt     250: }
                    251: 
1.1       hyatt     252: - (void)setupToolbar
                    253: {
1.58      hyatt     254:   if (mChromeMask) {
                    255:     printf("Uh-oh. %d\n", mChromeMask);
                    256:   }
                    257:   
1.1       hyatt     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,
1.11      macserv   277:                                         PrintToolbarItemIdentifier,
1.1       hyatt     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"];
1.54      macserv   341:         [toolbarItem setImage:[NSImage imageNamed:@"sidebarClosed"]];
1.1       hyatt     342:         [toolbarItem setTarget:self];
                    343:         [toolbarItem setAction:@selector(toggleSidebar:)];
1.54      macserv   344:         mSidebarToolbarItem = toolbarItem;
1.1       hyatt     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];
1.5       macserv   357:         [menuFormRep setAction:@selector(performAppropriateLocationAction)];
1.1       hyatt     358:         [menuFormRep setTitle:[toolbarItem label]];
                    359:         
                    360:         [toolbarItem setMenuFormRepresentation:menuFormRep];
1.5       macserv   361:         mLocationToolbarItem = toolbarItem;
1.11      macserv   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)];
1.1       hyatt     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:    
1.5       macserv   394: - (void)updateToolbarItems
1.1       hyatt     395: {
                    396:   [[[self window] toolbar] validateVisibleItems];
                    397: }
                    398: 
1.5       macserv   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
1.3       hyatt     414: {
                    415:     [mURLBar selectText: self];
                    416: }
                    417: 
1.5       macserv   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]]];
1.32      hyatt     432:     
                    433:     // Focus and activate our content area.
                    434:     [[mBrowserView getBrowserView] setActive: YES];
1.5       macserv   435: }
                    436: 
                    437: - (IBAction)goToLocationFromToolbarURLField:(id)sender
                    438: {
                    439:     [self loadURL:[NSURL URLWithString:[sender stringValue]]];
1.32      hyatt     440:     
                    441:     // Focus and activate our content area.
                    442:     [[mBrowserView getBrowserView] setActive: YES];
1.5       macserv   443: }
                    444: 
1.7       hyatt     445: - (void)saveDocument: (NSView*)aFilterView filterList: (NSPopUpButton*)aFilterList
1.6       hyatt     446: {
1.7       hyatt     447:     [[mBrowserView getBrowserView] saveDocument: aFilterView filterList: aFilterList];
1.6       hyatt     448: }
                    449: 
1.12      hyatt     450: - (void)printDocument
                    451: {
                    452:     [[mBrowserView getBrowserView] printDocument];
                    453: }
                    454: 
1.15      hyatt     455: - (void)printPreview
                    456: {
                    457:     [[mBrowserView getBrowserView] printPreview];
                    458: }
                    459: 
1.55      pinkerto  460: - (void)findInPage:(NSString*)text
1.16      hyatt     461: {
1.55      pinkerto  462:     [[mBrowserView getBrowserView] findInPage:text];
1.16      hyatt     463: }
                    464: 
                    465: - (void)findAgain
                    466: {
                    467:     [[mBrowserView getBrowserView] findAgain];
1.22      hyatt     468: }
                    469: 
                    470: - (void)addBookmark
                    471: {
                    472:     // XXXdwh Hack.  Just go to the sidebar for now until we get our
                    473:     // menu data source going.
                    474:     [mSidebarBookmarksDataSource ensureBookmarks];
                    475:     [mSidebarBookmarksDataSource addBookmark: self];
1.16      hyatt     476: }
                    477: 
1.5       macserv   478: - (IBAction)back:(id)aSender
1.1       hyatt     479: {
                    480:   [[mBrowserView getBrowserView] goBack];
                    481: }
                    482: 
1.5       macserv   483: - (IBAction)forward:(id)aSender
1.1       hyatt     484: {
                    485:   [[mBrowserView getBrowserView] goForward];
                    486: }
                    487: 
1.5       macserv   488: - (IBAction)reload:(id)aSender
1.1       hyatt     489: {
                    490:   [[mBrowserView getBrowserView] reload: 0];
                    491: }
                    492: 
1.5       macserv   493: - (IBAction)stop:(id)aSender
1.1       hyatt     494: {
1.37      hyatt     495:   [[mBrowserView getBrowserView] stop: nsIWebNavigation::STOP_ALL];
1.1       hyatt     496: }
                    497: 
1.5       macserv   498: - (IBAction)home:(id)aSender
1.1       hyatt     499: {
1.5       macserv   500:   [[mBrowserView getBrowserView] loadURI:[NSURL URLWithString:@"about:blank"] flags:NSLoadFlagsNone];
1.1       hyatt     501: }
                    502: 
1.5       macserv   503: - (IBAction)toggleSidebar:(id)aSender
1.1       hyatt     504: {
1.36      hyatt     505:     NSResponder* resp = [[self window] firstResponder];
                    506:     [[self window] makeFirstResponder: nil];
                    507:     
1.31      hyatt     508:     if ( ([mSidebarDrawer state] == NSDrawerClosedState) || ([mSidebarDrawer state] == NSDrawerClosingState) )   {
1.34      hyatt     509:         // XXXHack to bypass sidebar crashes.
1.57      hyatt     510:         [mSidebarDrawer openOnEdge: NSMaxXEdge];
1.1       hyatt     511:     } else {
                    512:         [mSidebarDrawer close];
                    513:     }
1.36      hyatt     514:     
                    515:     [[self window] makeFirstResponder: resp];
1.1       hyatt     516: }
1.54      macserv   517: 
1.1       hyatt     518: 
1.4       hyatt     519: -(void)loadURL:(NSURL*)aURL
1.1       hyatt     520: {
1.32      hyatt     521:     if (mInitialized) {
1.4       hyatt     522:         [[mBrowserView getBrowserView] loadURI:aURL flags:NSLoadFlagsNone];
1.32      hyatt     523:     }
1.4       hyatt     524:     else {
                    525:         mURL = aURL;
                    526:         [mURL retain];
                    527:     }
1.1       hyatt     528: }
1.5       macserv   529: 
                    530: - (void)updateLocationFields:(NSString *)locationString
                    531: {
                    532: /* //commenting this out because it doesn't work right yet.
                    533:     if ( [locationString length] > 30 ) {
                    534:         [[mLocationToolbarItem menuFormRepresentation] setTitle:
                    535:             [NSString stringWithFormat:@"Location: %@...", [locationString substringToIndex:31]]];
                    536:     } else {
                    537:         [[mLocationToolbarItem menuFormRepresentation] setTitle:
                    538:             [NSString stringWithFormat:@"Location: %@", locationString]];
                    539:     }
                    540: */
                    541: 
                    542:     [mURLBar setStringValue:locationString];
                    543:     [mLocationSheetURLField setStringValue:locationString];
                    544: 
                    545:     [[self window] update];
                    546:     [[self window] display];
1.8       hyatt     547: }
1.27      hyatt     548: 
                    549: -(void)newTab
                    550: {
1.28      hyatt     551:     NSTabViewItem* newTab = [[[NSTabViewItem alloc] initWithIdentifier: nil] autorelease];
1.47      hyatt     552:     MyBrowserView* newView = [[[MyBrowserView alloc] initWithFrame: [mBrowserView frame]] autorelease];
                    553:     [newView setTab: newTab];
1.41      macserv   554: 
                    555:     [newTab setLabel: @"Untitled"];
                    556:     [newTab setView: newView];
                    557: 
1.28      hyatt     558:     [mTabBrowser addTabViewItem: newTab];
1.42      macserv   559: 
1.28      hyatt     560:     [[newView getBrowserView] loadURI:[NSURL URLWithString:@"about:blank"] flags:NSLoadFlagsNone];
1.42      macserv   561: 
1.28      hyatt     562:     [mTabBrowser selectLastTabViewItem: self];
1.42      macserv   563: 
1.29      hyatt     564:     if ( [[[self window] toolbar] isVisible] ) {
                    565:         if ( ([[[self window] toolbar] displayMode] == NSToolbarDisplayModeIconAndLabel) ||
                    566:              ([[[self window] toolbar] displayMode] == NSToolbarDisplayModeIconOnly) ) {
1.58      hyatt     567:           [[mBrowserView getBrowserView] setActive: NO];
                    568:           [self focusURLBar];
1.42      macserv   569:         }
1.29      hyatt     570:     }
1.42      macserv   571: }
                    572: 
                    573: -(void)closeTab
                    574: {
1.49      hyatt     575:   if ( [mTabBrowser numberOfTabViewItems] > 1 ) {
                    576:     [[[mTabBrowser selectedTabViewItem] view] windowClosed];
                    577:     [mTabBrowser removeTabViewItem:[mTabBrowser selectedTabViewItem]];
                    578:   }
1.42      macserv   579: }
                    580: 
                    581: - (void)previousTab
                    582: {
                    583:     [mTabBrowser selectPreviousTabViewItem:self];
                    584: }
                    585: 
                    586: - (void)nextTab
                    587: {
                    588:     [mTabBrowser selectNextTabViewItem:self];
1.28      hyatt     589: }
1.27      hyatt     590: 
1.28      hyatt     591: - (void)tabView:(NSTabView *)aTabView didSelectTabViewItem:(NSTabViewItem *)aTabViewItem
                    592: {
1.41      macserv   593:     // Disconnect the old view, if one has been designated.
                    594:     // If the window has just been opened, none has been.
                    595:     if ( mBrowserView ) {
                    596:         [mBrowserView disconnectView];
                    597:     }
1.28      hyatt     598:     // Connect up the new view
                    599:     mBrowserView = [aTabViewItem view];
1.30      hyatt     600:        
1.28      hyatt     601:     // Make the new view the primary content area.
1.47      hyatt     602:     [mBrowserView makePrimaryBrowserView: mURLBar status: mStatus
1.28      hyatt     603:         progress: mProgress windowController: self];
1.27      hyatt     604: }
1.28      hyatt     605: 
1.31      hyatt     606: -(MyBrowserView*)getMyBrowserView
                    607: {
                    608:     return mBrowserView;
                    609: }
1.45      hyatt     610: 
                    611: -(void)openNewWindowWithURL: (NSURL*)aURL loadInBackground: (BOOL)aLoadInBG
                    612: {
1.48      hyatt     613:   // Autosave our dimensions before we open a new window.  That ensures the size ends up matching.
                    614:   [self autosaveWindowFrame];
                    615: 
                    616:   BrowserWindowController* browser = [[BrowserWindowController alloc] initWithWindowNibName: @"BrowserWindow"];
                    617:   [browser loadURL: aURL];
                    618:   if (aLoadInBG)
                    619:     [[browser window] orderWindow: NSWindowBelow relativeTo: [[self window] windowNumber]];
                    620:   else
                    621:     [browser showWindow: self];
                    622: 
                    623:   // XXXdwh Focus the content area.
1.47      hyatt     624: }
                    625: 
                    626: -(void)openNewTabWithURL: (NSURL*)aURL loadInBackground: (BOOL)aLoadInBG
                    627: {
                    628:     NSTabViewItem* newTab = [[[NSTabViewItem alloc] initWithIdentifier: nil] autorelease];
                    629:     
                    630:     NSTabViewItem* selectedTab = [mTabBrowser selectedTabViewItem];
                    631:     int index = [mTabBrowser indexOfTabViewItem: selectedTab];
                    632:     [mTabBrowser insertTabViewItem: newTab atIndex: index+1];
                    633:     
                    634:     MyBrowserView* newView = [[[MyBrowserView alloc] initWithFrame: [mBrowserView frame]] autorelease];
                    635:     [newView setTab: newTab];
                    636:     
                    637:     [newTab setLabel: @"Loading..."];
                    638:     [newTab setView: newView];
                    639: 
                    640:     [[newView getBrowserView] loadURI:aURL flags:NSLoadFlagsNone];
                    641: 
                    642:     if (!aLoadInBG)
                    643:         [mTabBrowser selectTabViewItem: newTab];
                    644:         
                    645:     // XXXdwh Focus the content area.
1.45      hyatt     646: }
1.52      macserv   647: 
                    648: -(void)setupSidebarTabs
                    649: {
                    650:     IconTabViewItem   *bookItem = [[IconTabViewItem alloc] initWithIdentifier:@"bookmarkSidebarIconTabViewItem"
                    651:                                   withTabIcon:[NSImage imageNamed:@"bookicon"]];
                    652:     IconTabViewItem   *histItem = [[IconTabViewItem alloc] initWithIdentifier:@"historySidebarIconTabViewItem"
                    653:                                   withTabIcon:[NSImage imageNamed:@"historyicon"]];
                    654:     IconTabViewItem *searchItem = [[IconTabViewItem alloc] initWithIdentifier:@"searchSidebarIconTabViewItem"
                    655:                                   withTabIcon:[NSImage imageNamed:@"searchicon"]];
                    656: 
                    657:     [bookItem   setView:[[mSidebarSourceTabView tabViewItemAtIndex:0] view]];
                    658:     [histItem   setView:[[mSidebarSourceTabView tabViewItemAtIndex:1] view]];
                    659:     [searchItem setView:[[mSidebarSourceTabView tabViewItemAtIndex:2] view]];
                    660: 
                    661:     [mSidebarTabView insertTabViewItem:bookItem   atIndex:0];
                    662:     [mSidebarTabView insertTabViewItem:histItem   atIndex:1];
                    663:     [mSidebarTabView insertTabViewItem:searchItem atIndex:2];
1.53      macserv   664: 
                    665:     [mSidebarTabView selectFirstTabViewItem:self];
1.52      macserv   666: }
                    667: 
1.58      hyatt     668: -(void)setChromeMask:(int)aMask
                    669: {
                    670:   mChromeMask = aMask;
1.59    ! hyatt     671: }
        !           672: 
        !           673: // Called when a context menu should be shown.
        !           674: - (void)onShowContextMenu:(int)flags domEvent:(nsIDOMEvent*)aEvent domNode:(nsIDOMNode*)aNode
        !           675: {
        !           676:   mContextMenuFlags = flags;
        !           677:   mContextMenuNode = aNode;
        !           678:   NS_IF_ADDREF(aNode);
        !           679:   mContextMenuEvent = aEvent;
        !           680:   NS_IF_ADDREF(aEvent);
        !           681: }
        !           682: 
        !           683: - (NSMenu*)getContextMenu
        !           684: {
        !           685:   NSMenu* result = nil;
        !           686:   if ((mContextMenuFlags & nsIContextMenuListener::CONTEXT_LINK) != 0) {
        !           687:     if ((mContextMenuFlags & nsIContextMenuListener::CONTEXT_IMAGE) != 0) {
        !           688:       result = mImageLinkMenu;
        !           689:     }
        !           690:     else
        !           691:       result = mLinkMenu;
        !           692:   }
        !           693:   else if ((mContextMenuFlags & nsIContextMenuListener::CONTEXT_INPUT) != 0 ||
        !           694:            (mContextMenuFlags & nsIContextMenuListener::CONTEXT_TEXT) != 0) {
        !           695:     result = mInputMenu;
        !           696:   }
        !           697:   else if ((mContextMenuFlags & nsIContextMenuListener::CONTEXT_IMAGE) != 0) {
        !           698:     result = mImageMenu;
        !           699:   }
        !           700:   else if ((mContextMenuFlags & nsIContextMenuListener::CONTEXT_DOCUMENT) != 0) {
        !           701:     result = mPageMenu;
        !           702:   }
        !           703:   
        !           704:   NS_IF_RELEASE(mContextMenuNode);
        !           705:   mContextMenuNode = nsnull;
        !           706:   NS_IF_RELEASE(mContextMenuEvent);
        !           707:   mContextMenuEvent = nsnull;
        !           708:   return result;
1.58      hyatt     709: }
1.52      macserv   710: 
1.1       hyatt     711: @end
                    712: 

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