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: - (void)findInPage:(NSString*)text
461: {
462: [[mBrowserView getBrowserView] findInPage:text];
463: }
464:
465: - (void)findAgain
466: {
467: [[mBrowserView getBrowserView] findAgain];
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];
476: }
477:
478: - (IBAction)back:(id)aSender
479: {
480: [[mBrowserView getBrowserView] goBack];
481: }
482:
483: - (IBAction)forward:(id)aSender
484: {
485: [[mBrowserView getBrowserView] goForward];
486: }
487:
488: - (IBAction)reload:(id)aSender
489: {
490: [[mBrowserView getBrowserView] reload: 0];
491: }
492:
493: - (IBAction)stop:(id)aSender
494: {
495: [[mBrowserView getBrowserView] stop: nsIWebNavigation::STOP_ALL];
496: }
497:
498: - (IBAction)home:(id)aSender
499: {
500: [[mBrowserView getBrowserView] loadURI:[NSURL URLWithString:@"about:blank"] flags:NSLoadFlagsNone];
501: }
502:
503: - (IBAction)toggleSidebar:(id)aSender
504: {
505: NSResponder* resp = [[self window] firstResponder];
506: [[self window] makeFirstResponder: nil];
507:
508: if ( ([mSidebarDrawer state] == NSDrawerClosedState) || ([mSidebarDrawer state] == NSDrawerClosingState) ) {
509: // XXXHack to bypass sidebar crashes.
510: [mSidebarDrawer openOnEdge: NSMaxXEdge];
511: } else {
512: [mSidebarDrawer close];
513: }
514:
515: [[self window] makeFirstResponder: resp];
516: }
517:
518:
519: -(void)loadURL:(NSURL*)aURL
520: {
521: if (mInitialized) {
522: [[mBrowserView getBrowserView] loadURI:aURL flags:NSLoadFlagsNone];
523: }
524: else {
525: mURL = aURL;
526: [mURL retain];
527: }
528: }
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];
547: }
548:
549: -(void)newTab
550: {
551: NSTabViewItem* newTab = [[[NSTabViewItem alloc] initWithIdentifier: nil] autorelease];
552: MyBrowserView* newView = [[[MyBrowserView alloc] initWithFrame: [mBrowserView frame]] autorelease];
553: [newView setTab: newTab];
554:
555: [newTab setLabel: @"Untitled"];
556: [newTab setView: newView];
557:
558: [mTabBrowser addTabViewItem: newTab];
559:
560: [[newView getBrowserView] loadURI:[NSURL URLWithString:@"about:blank"] flags:NSLoadFlagsNone];
561:
562: [mTabBrowser selectLastTabViewItem: self];
563:
564: if ( [[[self window] toolbar] isVisible] ) {
565: if ( ([[[self window] toolbar] displayMode] == NSToolbarDisplayModeIconAndLabel) ||
566: ([[[self window] toolbar] displayMode] == NSToolbarDisplayModeIconOnly) ) {
567: [[mBrowserView getBrowserView] setActive: NO];
568: [self focusURLBar];
569: }
570: }
571: }
572:
573: -(void)closeTab
574: {
575: if ( [mTabBrowser numberOfTabViewItems] > 1 ) {
576: [[[mTabBrowser selectedTabViewItem] view] windowClosed];
577: [mTabBrowser removeTabViewItem:[mTabBrowser selectedTabViewItem]];
578: }
579: }
580:
581: - (void)previousTab
582: {
583: [mTabBrowser selectPreviousTabViewItem:self];
584: }
585:
586: - (void)nextTab
587: {
588: [mTabBrowser selectNextTabViewItem:self];
589: }
590:
591: - (void)tabView:(NSTabView *)aTabView didSelectTabViewItem:(NSTabViewItem *)aTabViewItem
592: {
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: }
598: // Connect up the new view
599: mBrowserView = [aTabViewItem view];
600:
601: // Make the new view the primary content area.
602: [mBrowserView makePrimaryBrowserView: mURLBar status: mStatus
603: progress: mProgress windowController: self];
604: }
605:
606: -(MyBrowserView*)getMyBrowserView
607: {
608: return mBrowserView;
609: }
610:
611: -(void)openNewWindowWithURL: (NSURL*)aURL loadInBackground: (BOOL)aLoadInBG
612: {
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.
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.
646: }
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];
664:
665: [mSidebarTabView selectFirstTabViewItem:self];
666: }
667:
668: -(void)setChromeMask:(int)aMask
669: {
670: mChromeMask = aMask;
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;
709: }
710:
711: @end
712:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>