Annotation of chimera/BrowserWindowController.mm, revision 1.66
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.61 hyatt 43: #include "nsIDOMElement.h"
1.59 hyatt 44: #include "nsIDOMEvent.h"
1.61 hyatt 45: #include "nsIPrefBranch.h"
1.59 hyatt 46: #include "nsIContextMenuListener.h"
1.64 hyatt 47: #include "nsIDOMWindow.h"
48: #include "nsIScriptGlobalObject.h"
49: #include "nsIDocShell.h"
50: #include "nsIMarkupDocumentViewer.h"
51: #include "nsIContentViewer.h"
1.51 macserv 52: #include "nsCocoaBrowserService.h"
1.61 hyatt 53: #include "nsString.h"
54: #include "GeckoUtils.h"
1.37 hyatt 55:
1.1 hyatt 56: static NSString *BrowserToolbarIdentifier = @"Browser Window Toolbar";
57: static NSString *BackToolbarItemIdentifier = @"Back Toolbar Item";
58: static NSString *ForwardToolbarItemIdentifier = @"Forward Toolbar Item";
59: static NSString *ReloadToolbarItemIdentifier = @"Reload Toolbar Item";
60: static NSString *StopToolbarItemIdentifier = @"Stop Toolbar Item";
61: static NSString *HomeToolbarItemIdentifier = @"Home Toolbar Item";
62: static NSString *LocationToolbarItemIdentifier = @"Location Toolbar Item";
63: static NSString *SidebarToolbarItemIdentifier = @"Sidebar Toolbar Item";
1.11 macserv 64: static NSString *PrintToolbarItemIdentifier = @"Print Toolbar Item";
1.1 hyatt 65:
66: @interface BrowserWindowController(Private)
67: - (void)setupToolbar;
1.52 macserv 68: - (void)setupSidebarTabs;
1.1 hyatt 69: @end
70:
71: @implementation BrowserWindowController
72:
1.39 hyatt 73: -(void)enterModalSession
74: {
75: mModalSession = [NSApp beginModalSessionForWindow: [self window]];
76: [NSApp runModalSession: mModalSession];
77: [NSApp endModalSession: mModalSession];
78: mModalSession = nil;
79: }
80:
1.58 hyatt 81: -(void)windowDidBecomeKey: (NSNotification*)aNotification
82: {
83: // May become necessary later.
84: }
85:
86: -(void)windowDidResignKey: (NSNotification*)aNotification
87: {
88: // May be needed later.
89: }
90:
1.35 hyatt 91: -(void)mouseMoved:(NSEvent*)aEvent
92: {
93: if (mMoveReentrant)
94: return;
95:
96: mMoveReentrant = YES;
97: NSView* view = [[[self window] contentView] hitTest: [aEvent locationInWindow]];
98: [view mouseMoved: aEvent];
99: [super mouseMoved: aEvent];
100: mMoveReentrant = NO;
101: }
102:
1.41 macserv 103: - (id)initWithWindowNibName:(NSString *)windowNibName
1.4 hyatt 104: {
1.41 macserv 105: if ( (self = [super initWithWindowNibName:(NSString *)windowNibName]) ) {
1.51 macserv 106: if ( nsCocoaBrowserService::sNumBrowsers == 0 ) {
107: [self setShouldCascadeWindows:NO];
108: } else {
109: [self setShouldCascadeWindows:YES];
110: }
1.41 macserv 111: mInitialized = NO;
112: mMoveReentrant = NO;
1.48 hyatt 113: mShouldAutosave = YES;
1.58 hyatt 114: mChromeMask = 0;
1.59 hyatt 115: mContextMenuFlags = 0;
116: mContextMenuEvent = nsnull;
117: mContextMenuNode = nsnull;
1.41 macserv 118: }
119: return self;
1.4 hyatt 120: }
121:
1.48 hyatt 122: -(void)autosaveWindowFrame
123: {
124: if (mShouldAutosave)
125: [[self window] saveFrameUsingName: @"NavigatorWindow"];
126: }
127:
128: -(void)disableAutosave
129: {
130: mShouldAutosave = NO;
131: }
132:
1.17 hyatt 133: - (void)windowWillClose:(NSNotification *)notification
134: {
1.49 hyatt 135: printf("Window will close notification.\n");
136: [mSidebarBookmarksDataSource windowClosing];
1.48 hyatt 137:
1.49 hyatt 138: [self autosaveWindowFrame];
139: [self autorelease];
1.17 hyatt 140: }
141:
1.7 hyatt 142: - (void)dealloc
143: {
1.49 hyatt 144: printf("Browser controller died.\n");
1.40 hyatt 145:
1.49 hyatt 146: // Loop over all tabs, and tell them that the window is closed.
147: int numTabs = [mTabBrowser numberOfTabViewItems];
148: for (int i = 0; i < numTabs; i++) {
149: NSTabViewItem* item = [mTabBrowser tabViewItemAtIndex: i];
150: [[item view] windowClosed];
151: }
152: [mSidebarBrowserView windowClosed];
153:
154: [mProgress release];
155:
156: [super dealloc];
1.7 hyatt 157: }
158:
1.1 hyatt 159: - (void)windowDidLoad
160: {
1.35 hyatt 161: [super windowDidLoad];
1.48 hyatt 162:
163: // Get our saved dimensions.
164: [[self window] setFrameUsingName: @"NavigatorWindow"];
1.35 hyatt 165:
1.39 hyatt 166: if (mModalSession)
167: [NSApp stopModal: mModalSession];
168:
1.4 hyatt 169: mInitialized = YES;
1.57 hyatt 170:
171: mDrawerCachedFrame = NO;
1.38 hyatt 172:
173: // Retain with a single extra refcount. This allows the MyBrowserViews
174: // to remove the progress meter from its superview without having to
175: // worry about retaining and releasing it.
176: [mProgress retain];
177:
1.34 hyatt 178: [[self window] setAcceptsMouseMovedEvents: YES];
179:
1.1 hyatt 180: [self setupToolbar];
1.66 ! hyatt 181:
1.41 macserv 182: // 03/03/2002 mlj Changing strategy a bit here. The addTab: method was
183: // duplicating a lot of the code found here. I have moved it to that method.
184: // We now remove the IB tab, then add one of our own.
185:
186: [mTabBrowser removeTabViewItem:[mTabBrowser tabViewItemAtIndex:0]];
187: [self newTab];
1.4 hyatt 188:
189: if (mURL) {
190: [self loadURL: mURL];
191: [mURL release];
192: }
1.18 hyatt 193:
194: [mSidebarDrawer setDelegate: self];
1.50 macserv 195:
1.52 macserv 196: [self setupSidebarTabs];
1.66 ! hyatt 197:
! 198: [mPersonalToolbar initializeToolbar];
1.18 hyatt 199: }
200:
1.22 hyatt 201: - (void)drawerWillOpen: (NSNotification*)aNotification
202: {
1.57 hyatt 203: [mSidebarBookmarksDataSource ensureBookmarks];
204:
205: // Force the window to shrink and move if necessary in order to accommodate the sidebar.
1.65 hyatt 206: NSRect screenFrame = [[[self window] screen] visibleFrame];
1.57 hyatt 207: NSRect windowFrame = [[self window] frame];
208: NSSize drawerSize = [mSidebarDrawer contentSize];
209: int fudgeFactor = 12; // Not sure how to get the drawer's border info, so we fudge it for now.
210: drawerSize.width += fudgeFactor;
211: if (windowFrame.origin.x + windowFrame.size.width + drawerSize.width >
212: screenFrame.size.width) {
213: // We need to adjust the window so that it can fit.
214: int shrinkDelta = (windowFrame.size.width + drawerSize.width) - screenFrame.size.width;
215: if (shrinkDelta < 0) shrinkDelta = 0;
216: int newWidth = (windowFrame.size.width - shrinkDelta);
217: int newPosition = screenFrame.size.width - newWidth - drawerSize.width;
218: if (newPosition < 0) newPosition = 0;
219: mCachedFrameBeforeDrawerOpen = windowFrame;
220: windowFrame.origin.x = newPosition;
221: windowFrame.size.width = newWidth;
222: mCachedFrameAfterDrawerOpen = windowFrame;
223: [[self window] setFrame: windowFrame display: YES];
224: mDrawerCachedFrame = YES;
225: }
1.22 hyatt 226: }
227:
1.18 hyatt 228: - (void)drawerDidOpen:(NSNotification *)aNotification
229: {
1.57 hyatt 230: // XXXdwh This is temporary.
1.56 hyatt 231: // [[mSidebarBrowserView getBrowserView] loadURI: [NSURL URLWithString: @"http://tinderbox.mozilla.org/SeaMonkey/panel.html"] flags:NSLoadFlagsNone];
1.57 hyatt 232:
233: // Toggle the sidebar icon.
234: [mSidebarToolbarItem setImage:[NSImage imageNamed:@"sidebarOpened"]];
1.1 hyatt 235: }
236:
1.19 hyatt 237: - (void)drawerDidClose:(NSNotification *)aNotification
238: {
1.57 hyatt 239: // Unload the Gecko web page in "My Panels" to save memory.
240: [mSidebarToolbarItem setImage:[NSImage imageNamed:@"sidebarClosed"]];
241:
242: // XXXdwh ignore for now.
1.56 hyatt 243: // [[mSidebarBrowserView getBrowserView] loadURI: [NSURL URLWithString: @"about:blank"] flags:NSLoadFlagsNone];
1.57 hyatt 244:
245: if (mDrawerCachedFrame) {
246: printf("Got here.\n");
247: mDrawerCachedFrame = NO;
248: NSRect frame = [[self window] frame];
249: if (frame.origin.x == mCachedFrameAfterDrawerOpen.origin.x &&
250: frame.origin.y == mCachedFrameAfterDrawerOpen.origin.y &&
251: frame.size.width == mCachedFrameAfterDrawerOpen.size.width &&
252: frame.size.height == mCachedFrameAfterDrawerOpen.size.height) {
253: printf("Got here too.\n");
254: printf("Xes are %d %d\n", frame.origin.x, mCachedFrameAfterDrawerOpen.origin.x);
255: printf("Widths are %d %d\n", frame.size.width, mCachedFrameAfterDrawerOpen.size.width);
256: // Restore the original frame.
257: [[self window] setFrame: mCachedFrameBeforeDrawerOpen display: YES];
258: }
259: }
1.19 hyatt 260: }
261:
1.1 hyatt 262: - (void)setupToolbar
263: {
1.58 hyatt 264: if (mChromeMask) {
265: printf("Uh-oh. %d\n", mChromeMask);
266: }
267:
1.1 hyatt 268: NSToolbar *toolbar = [[[NSToolbar alloc] initWithIdentifier:BrowserToolbarIdentifier] autorelease];
269:
270: [toolbar setDisplayMode:NSToolbarDisplayModeDefault];
271: [toolbar setAllowsUserCustomization:YES];
272: [toolbar setAutosavesConfiguration:YES];
273: [toolbar setDelegate:self];
274: [[self window] setToolbar:toolbar];
275: }
276:
277:
278: - (NSArray *)toolbarAllowedItemIdentifiers:(NSToolbar *)toolbar
279: {
280: return [NSArray arrayWithObjects: BackToolbarItemIdentifier,
281: ForwardToolbarItemIdentifier,
282: ReloadToolbarItemIdentifier,
283: StopToolbarItemIdentifier,
284: HomeToolbarItemIdentifier,
285: LocationToolbarItemIdentifier,
286: SidebarToolbarItemIdentifier,
1.11 macserv 287: PrintToolbarItemIdentifier,
1.1 hyatt 288: NSToolbarCustomizeToolbarItemIdentifier,
289: NSToolbarFlexibleSpaceItemIdentifier,
290: NSToolbarSpaceItemIdentifier,
291: NSToolbarSeparatorItemIdentifier,
292: nil];
293: }
294:
295: - (NSArray *)toolbarDefaultItemIdentifiers:(NSToolbar *)toolbar
296: {
297: return [NSArray arrayWithObjects: BackToolbarItemIdentifier,
298: ForwardToolbarItemIdentifier,
299: ReloadToolbarItemIdentifier,
300: StopToolbarItemIdentifier,
301: HomeToolbarItemIdentifier,
302: LocationToolbarItemIdentifier,
303: SidebarToolbarItemIdentifier,
304: nil];
305: }
306:
307: - (NSToolbarItem *) toolbar:(NSToolbar *)toolbar
308: itemForItemIdentifier:(NSString *)itemIdent
309: willBeInsertedIntoToolbar:(BOOL)willBeInserted
310: {
311: NSToolbarItem *toolbarItem = [[[NSToolbarItem alloc] initWithItemIdentifier:itemIdent] autorelease];
312: if ( [itemIdent isEqual:BackToolbarItemIdentifier] ) {
313: [toolbarItem setLabel:@"Back"];
314: [toolbarItem setPaletteLabel:@"Go Back"];
315: [toolbarItem setToolTip:@"Go back one page"];
316: [toolbarItem setImage:[NSImage imageNamed:@"back"]];
317: [toolbarItem setTarget:self];
318: [toolbarItem setAction:@selector(back:)];
319: } else if ( [itemIdent isEqual:ForwardToolbarItemIdentifier] ) {
320: [toolbarItem setLabel:@"Forward"];
321: [toolbarItem setPaletteLabel:@"Go Forward"];
322: [toolbarItem setToolTip:@"Go forward one page"];
323: [toolbarItem setImage:[NSImage imageNamed:@"forward"]];
324: [toolbarItem setTarget:self];
325: [toolbarItem setAction:@selector(forward:)];
326: } else if ( [itemIdent isEqual:ReloadToolbarItemIdentifier] ) {
327: [toolbarItem setLabel:@"Reload"];
328: [toolbarItem setPaletteLabel:@"Reload Page"];
329: [toolbarItem setToolTip:@"Reload current page"];
330: [toolbarItem setImage:[NSImage imageNamed:@"reload"]];
331: [toolbarItem setTarget:self];
332: [toolbarItem setAction:@selector(reload:)];
333: } else if ( [itemIdent isEqual:StopToolbarItemIdentifier] ) {
334: [toolbarItem setLabel:@"Stop"];
335: [toolbarItem setPaletteLabel:@"Stop Loading"];
336: [toolbarItem setToolTip:@"Stop loading this page"];
337: [toolbarItem setImage:[NSImage imageNamed:@"stop"]];
338: [toolbarItem setTarget:self];
339: [toolbarItem setAction:@selector(stop:)];
340: } else if ( [itemIdent isEqual:HomeToolbarItemIdentifier] ) {
341: [toolbarItem setLabel:@"Home"];
342: [toolbarItem setPaletteLabel:@"Go Home"];
343: [toolbarItem setToolTip:@"Go to home page"];
344: [toolbarItem setImage:[NSImage imageNamed:@"home"]];
345: [toolbarItem setTarget:self];
346: [toolbarItem setAction:@selector(home:)];
347: } else if ( [itemIdent isEqual:SidebarToolbarItemIdentifier] ) {
348: [toolbarItem setLabel:@"Sidebar"];
349: [toolbarItem setPaletteLabel:@"Toggle Sidebar"];
350: [toolbarItem setToolTip:@"Show or hide the Sidebar"];
1.54 macserv 351: [toolbarItem setImage:[NSImage imageNamed:@"sidebarClosed"]];
1.1 hyatt 352: [toolbarItem setTarget:self];
353: [toolbarItem setAction:@selector(toggleSidebar:)];
1.54 macserv 354: mSidebarToolbarItem = toolbarItem;
1.1 hyatt 355: } else if ( [itemIdent isEqual:LocationToolbarItemIdentifier] ) {
356:
357: NSMenuItem *menuFormRep = [[[NSMenuItem alloc] init] autorelease];
358:
359: [toolbarItem setLabel:@"Location"];
360: [toolbarItem setPaletteLabel:@"Location"];
361: [toolbarItem setImage:[NSImage imageNamed:@"Enter a web location."]];
362: [toolbarItem setView:mLocationToolbarView];
363: [toolbarItem setMinSize:NSMakeSize(128,32)];
364: [toolbarItem setMaxSize:NSMakeSize(2560,32)];
365:
366: [menuFormRep setTarget:self];
1.5 macserv 367: [menuFormRep setAction:@selector(performAppropriateLocationAction)];
1.1 hyatt 368: [menuFormRep setTitle:[toolbarItem label]];
369:
370: [toolbarItem setMenuFormRepresentation:menuFormRep];
1.5 macserv 371: mLocationToolbarItem = toolbarItem;
1.11 macserv 372:
373: } else if ( [itemIdent isEqual:PrintToolbarItemIdentifier] ) {
374: [toolbarItem setLabel:@"Print"];
375: [toolbarItem setPaletteLabel:@"Print"];
376: [toolbarItem setToolTip:@"Print this page"];
377: [toolbarItem setImage:[NSImage imageNamed:@"print"]];
378: [toolbarItem setTarget:self];
379: [toolbarItem setAction:@selector(printDocument)];
1.1 hyatt 380: } else {
381: toolbarItem = nil;
382: }
383:
384: return toolbarItem;
385: }
386:
387: // This method handles the enabling/disabling of the toolbar buttons.
388: - (BOOL)validateToolbarItem:(NSToolbarItem *)theItem
389: {
390: // Check the action and see if it matches.
391: SEL action = [theItem action];
392: if (action == @selector(back:))
393: return [[mBrowserView getBrowserView] canGoBack];
394: else if (action == @selector(forward:))
395: return [[mBrowserView getBrowserView] canGoForward];
396: else if (action == @selector(reload:))
397: return [mBrowserView isBusy] == NO;
398: else if (action == @selector(stop:))
399: return [mBrowserView isBusy];
400: else
401: return YES;
402: }
403:
1.5 macserv 404: - (void)updateToolbarItems
1.1 hyatt 405: {
406: [[[self window] toolbar] validateVisibleItems];
407: }
408:
1.5 macserv 409: - (void)performAppropriateLocationAction
410: {
411: if ( [[[self window] toolbar] isVisible] ) {
412: if ( ([[[self window] toolbar] displayMode] == NSToolbarDisplayModeIconAndLabel) ||
413: ([[[self window] toolbar] displayMode] == NSToolbarDisplayModeIconOnly) ) {
414: [self focusURLBar];
415: } else {
416: [self beginLocationSheet];
417: }
418: } else {
419: [self beginLocationSheet];
420: }
421: }
422:
423: - (void)focusURLBar
1.3 hyatt 424: {
425: [mURLBar selectText: self];
426: }
427:
1.5 macserv 428: - (void)beginLocationSheet
429: {
430: [NSApp beginSheet: mLocationSheetWindow
431: modalForWindow: [self window]
432: modalDelegate: nil
433: didEndSelector: nil
434: contextInfo: nil];
435: }
436:
437: - (IBAction)endLocationSheet:(id)sender
438: {
439: [mLocationSheetWindow orderOut:self];
440: [NSApp endSheet:mLocationSheetWindow returnCode:1];
441: [self loadURL:[NSURL URLWithString:[mLocationSheetURLField stringValue]]];
1.32 hyatt 442:
443: // Focus and activate our content area.
444: [[mBrowserView getBrowserView] setActive: YES];
1.5 macserv 445: }
446:
1.63 hyatt 447: -(IBAction)cancelAddBookmarkSheet:(id)sender
448: {
449: [mAddBookmarkSheetWindow orderOut:self];
450: [NSApp endSheet:mAddBookmarkSheetWindow returnCode:0];
451: [mCachedBMDS endAddBookmark: 0];
452: }
453:
454: -(IBAction)endAddBookmarkSheet:(id)sender
455: {
456: [mAddBookmarkSheetWindow orderOut:self];
457: [NSApp endSheet:mAddBookmarkSheetWindow returnCode:0];
458: [mCachedBMDS endAddBookmark: 1];
459: }
460:
461: - (void)cacheBookmarkDS: (id)aDS
462: {
463: mCachedBMDS = aDS;
464: }
465:
466: -(IBAction)manageBookmarks: (id)aSender
467: {
468: if (![mSidebarDrawer isOpen])
469: [self toggleSidebar: self];
470:
471: [mSidebarTabView selectFirstTabViewItem:self];
472: }
473:
1.5 macserv 474: - (IBAction)goToLocationFromToolbarURLField:(id)sender
475: {
476: [self loadURL:[NSURL URLWithString:[sender stringValue]]];
1.32 hyatt 477:
478: // Focus and activate our content area.
479: [[mBrowserView getBrowserView] setActive: YES];
1.5 macserv 480: }
481:
1.7 hyatt 482: - (void)saveDocument: (NSView*)aFilterView filterList: (NSPopUpButton*)aFilterList
1.6 hyatt 483: {
1.62 hyatt 484: [[mBrowserView getBrowserView] saveDocument: aFilterView filterList: aFilterList];
485: }
486:
487: - (void)saveURL: (NSView*)aFilterView filterList: (NSPopUpButton*)aFilterList
488: url: (NSURL*)aURL suggestedFilename: (NSString*)aFilename
489: {
490: [[mBrowserView getBrowserView] saveURL: aFilterView filterList: aFilterList
491: url: aURL suggestedFilename: aFilename];
1.6 hyatt 492: }
493:
1.12 hyatt 494: - (void)printDocument
495: {
496: [[mBrowserView getBrowserView] printDocument];
497: }
498:
1.15 hyatt 499: - (void)printPreview
500: {
501: [[mBrowserView getBrowserView] printPreview];
502: }
503:
1.60 pinkerto 504: - (BOOL)findInPage:(NSString*)text
1.16 hyatt 505: {
1.60 pinkerto 506: return [[mBrowserView getBrowserView] findInPage:text];
1.22 hyatt 507: }
508:
1.62 hyatt 509: - (void)addBookmarkExtended: (BOOL)aIsFromMenu
1.22 hyatt 510: {
1.62 hyatt 511: [mSidebarBookmarksDataSource ensureBookmarks];
512: [mSidebarBookmarksDataSource addBookmark: self useSelection: !aIsFromMenu];
1.16 hyatt 513: }
514:
1.5 macserv 515: - (IBAction)back:(id)aSender
1.1 hyatt 516: {
517: [[mBrowserView getBrowserView] goBack];
518: }
519:
1.5 macserv 520: - (IBAction)forward:(id)aSender
1.1 hyatt 521: {
522: [[mBrowserView getBrowserView] goForward];
523: }
524:
1.5 macserv 525: - (IBAction)reload:(id)aSender
1.1 hyatt 526: {
527: [[mBrowserView getBrowserView] reload: 0];
528: }
529:
1.5 macserv 530: - (IBAction)stop:(id)aSender
1.1 hyatt 531: {
1.37 hyatt 532: [[mBrowserView getBrowserView] stop: nsIWebNavigation::STOP_ALL];
1.1 hyatt 533: }
534:
1.5 macserv 535: - (IBAction)home:(id)aSender
1.1 hyatt 536: {
1.5 macserv 537: [[mBrowserView getBrowserView] loadURI:[NSURL URLWithString:@"about:blank"] flags:NSLoadFlagsNone];
1.1 hyatt 538: }
539:
1.5 macserv 540: - (IBAction)toggleSidebar:(id)aSender
1.1 hyatt 541: {
1.36 hyatt 542: NSResponder* resp = [[self window] firstResponder];
543: [[self window] makeFirstResponder: nil];
544:
1.31 hyatt 545: if ( ([mSidebarDrawer state] == NSDrawerClosedState) || ([mSidebarDrawer state] == NSDrawerClosingState) ) {
1.34 hyatt 546: // XXXHack to bypass sidebar crashes.
1.57 hyatt 547: [mSidebarDrawer openOnEdge: NSMaxXEdge];
1.1 hyatt 548: } else {
549: [mSidebarDrawer close];
550: }
1.36 hyatt 551:
552: [[self window] makeFirstResponder: resp];
1.1 hyatt 553: }
1.54 macserv 554:
1.1 hyatt 555:
1.4 hyatt 556: -(void)loadURL:(NSURL*)aURL
1.1 hyatt 557: {
1.32 hyatt 558: if (mInitialized) {
1.4 hyatt 559: [[mBrowserView getBrowserView] loadURI:aURL flags:NSLoadFlagsNone];
1.32 hyatt 560: }
1.4 hyatt 561: else {
562: mURL = aURL;
563: [mURL retain];
564: }
1.1 hyatt 565: }
1.5 macserv 566:
567: - (void)updateLocationFields:(NSString *)locationString
568: {
569: /* //commenting this out because it doesn't work right yet.
570: if ( [locationString length] > 30 ) {
571: [[mLocationToolbarItem menuFormRepresentation] setTitle:
572: [NSString stringWithFormat:@"Location: %@...", [locationString substringToIndex:31]]];
573: } else {
574: [[mLocationToolbarItem menuFormRepresentation] setTitle:
575: [NSString stringWithFormat:@"Location: %@", locationString]];
576: }
577: */
578:
579: [mURLBar setStringValue:locationString];
580: [mLocationSheetURLField setStringValue:locationString];
581:
582: [[self window] update];
583: [[self window] display];
1.8 hyatt 584: }
1.27 hyatt 585:
586: -(void)newTab
587: {
1.28 hyatt 588: NSTabViewItem* newTab = [[[NSTabViewItem alloc] initWithIdentifier: nil] autorelease];
1.47 hyatt 589: MyBrowserView* newView = [[[MyBrowserView alloc] initWithFrame: [mBrowserView frame]] autorelease];
590: [newView setTab: newTab];
1.41 macserv 591:
592: [newTab setLabel: @"Untitled"];
593: [newTab setView: newView];
594:
1.28 hyatt 595: [mTabBrowser addTabViewItem: newTab];
1.42 macserv 596:
1.28 hyatt 597: [[newView getBrowserView] loadURI:[NSURL URLWithString:@"about:blank"] flags:NSLoadFlagsNone];
1.42 macserv 598:
1.28 hyatt 599: [mTabBrowser selectLastTabViewItem: self];
1.42 macserv 600:
1.29 hyatt 601: if ( [[[self window] toolbar] isVisible] ) {
602: if ( ([[[self window] toolbar] displayMode] == NSToolbarDisplayModeIconAndLabel) ||
603: ([[[self window] toolbar] displayMode] == NSToolbarDisplayModeIconOnly) ) {
1.61 hyatt 604: if ([mTabBrowser numberOfTabViewItems] > 1) {
605: [self focusURLBar];
606: [[mBrowserView getBrowserView] setActive: NO];
607: }
608: else if ([[self window] isKeyWindow])
609: [[mBrowserView getBrowserView] setActive: YES];
610: else
611: [[mBrowserView getBrowserView] setActive: NO];
1.42 macserv 612: }
1.29 hyatt 613: }
1.42 macserv 614: }
615:
616: -(void)closeTab
617: {
1.49 hyatt 618: if ( [mTabBrowser numberOfTabViewItems] > 1 ) {
619: [[[mTabBrowser selectedTabViewItem] view] windowClosed];
620: [mTabBrowser removeTabViewItem:[mTabBrowser selectedTabViewItem]];
621: }
1.42 macserv 622: }
623:
624: - (void)previousTab
625: {
626: [mTabBrowser selectPreviousTabViewItem:self];
627: }
628:
629: - (void)nextTab
630: {
631: [mTabBrowser selectNextTabViewItem:self];
1.28 hyatt 632: }
1.27 hyatt 633:
1.28 hyatt 634: - (void)tabView:(NSTabView *)aTabView didSelectTabViewItem:(NSTabViewItem *)aTabViewItem
635: {
1.41 macserv 636: // Disconnect the old view, if one has been designated.
637: // If the window has just been opened, none has been.
638: if ( mBrowserView ) {
639: [mBrowserView disconnectView];
640: }
1.28 hyatt 641: // Connect up the new view
642: mBrowserView = [aTabViewItem view];
1.30 hyatt 643:
1.28 hyatt 644: // Make the new view the primary content area.
1.47 hyatt 645: [mBrowserView makePrimaryBrowserView: mURLBar status: mStatus
1.28 hyatt 646: progress: mProgress windowController: self];
1.27 hyatt 647: }
1.28 hyatt 648:
1.31 hyatt 649: -(MyBrowserView*)getMyBrowserView
650: {
651: return mBrowserView;
652: }
1.45 hyatt 653:
654: -(void)openNewWindowWithURL: (NSURL*)aURL loadInBackground: (BOOL)aLoadInBG
655: {
1.48 hyatt 656: // Autosave our dimensions before we open a new window. That ensures the size ends up matching.
657: [self autosaveWindowFrame];
658:
659: BrowserWindowController* browser = [[BrowserWindowController alloc] initWithWindowNibName: @"BrowserWindow"];
660: [browser loadURL: aURL];
661: if (aLoadInBG)
662: [[browser window] orderWindow: NSWindowBelow relativeTo: [[self window] windowNumber]];
1.62 hyatt 663: else {
1.61 hyatt 664: // Focus the content area and show the window.
1.62 hyatt 665: [browser enterModalSession];
666: [[[browser getMyBrowserView] getBrowserView] setActive: YES];
667: }
1.47 hyatt 668: }
669:
670: -(void)openNewTabWithURL: (NSURL*)aURL loadInBackground: (BOOL)aLoadInBG
671: {
672: NSTabViewItem* newTab = [[[NSTabViewItem alloc] initWithIdentifier: nil] autorelease];
673:
674: NSTabViewItem* selectedTab = [mTabBrowser selectedTabViewItem];
675: int index = [mTabBrowser indexOfTabViewItem: selectedTab];
676: [mTabBrowser insertTabViewItem: newTab atIndex: index+1];
677:
678: MyBrowserView* newView = [[[MyBrowserView alloc] initWithFrame: [mBrowserView frame]] autorelease];
679: [newView setTab: newTab];
680:
681: [newTab setLabel: @"Loading..."];
682: [newTab setView: newView];
683:
684: [[newView getBrowserView] loadURI:aURL flags:NSLoadFlagsNone];
685:
1.61 hyatt 686: if (!aLoadInBG) {
687: [mTabBrowser selectTabViewItem: newTab];
688: // Focus the content area.
689: [[newView getBrowserView] setActive: YES];
690: }
1.45 hyatt 691: }
1.52 macserv 692:
693: -(void)setupSidebarTabs
694: {
695: IconTabViewItem *bookItem = [[IconTabViewItem alloc] initWithIdentifier:@"bookmarkSidebarIconTabViewItem"
696: withTabIcon:[NSImage imageNamed:@"bookicon"]];
697: IconTabViewItem *histItem = [[IconTabViewItem alloc] initWithIdentifier:@"historySidebarIconTabViewItem"
698: withTabIcon:[NSImage imageNamed:@"historyicon"]];
699: IconTabViewItem *searchItem = [[IconTabViewItem alloc] initWithIdentifier:@"searchSidebarIconTabViewItem"
700: withTabIcon:[NSImage imageNamed:@"searchicon"]];
1.63 hyatt 701: IconTabViewItem *panelsItem = [[IconTabViewItem alloc] initWithIdentifier:@"myPanelsIconTabViewItem"
702: withTabIcon:[NSImage imageNamed:@"panel_icon"]];
703:
1.52 macserv 704: [bookItem setView:[[mSidebarSourceTabView tabViewItemAtIndex:0] view]];
705: [histItem setView:[[mSidebarSourceTabView tabViewItemAtIndex:1] view]];
706: [searchItem setView:[[mSidebarSourceTabView tabViewItemAtIndex:2] view]];
1.63 hyatt 707: [panelsItem setView:[[mSidebarSourceTabView tabViewItemAtIndex:3] view]];
1.52 macserv 708:
1.63 hyatt 709: [mSidebarTabView removeTabViewItem:[mSidebarTabView tabViewItemAtIndex:0]];
710:
1.52 macserv 711: [mSidebarTabView insertTabViewItem:bookItem atIndex:0];
712: [mSidebarTabView insertTabViewItem:histItem atIndex:1];
713: [mSidebarTabView insertTabViewItem:searchItem atIndex:2];
1.63 hyatt 714: [mSidebarTabView insertTabViewItem:panelsItem atIndex:3];
715:
1.53 macserv 716: [mSidebarTabView selectFirstTabViewItem:self];
1.52 macserv 717: }
718:
1.58 hyatt 719: -(void)setChromeMask:(int)aMask
720: {
721: mChromeMask = aMask;
1.64 hyatt 722: }
723:
724: -(void) biggerTextSize
725: {
726: nsCOMPtr<nsIDOMWindow> contentWindow = getter_AddRefs([[mBrowserView getBrowserView] getContentWindow]);
727: nsCOMPtr<nsIScriptGlobalObject> global(do_QueryInterface(contentWindow));
728: if (!global)
729: return;
730: nsCOMPtr<nsIDocShell> docShell;
731: global->GetDocShell(getter_AddRefs(docShell));
732: if (!docShell)
733: return;
734: nsCOMPtr<nsIContentViewer> cv;
735: docShell->GetContentViewer(getter_AddRefs(cv));
736: nsCOMPtr<nsIMarkupDocumentViewer> markupViewer(do_QueryInterface(cv));
737: if (!markupViewer)
738: return;
739: float zoom;
740: markupViewer->GetTextZoom(&zoom);
741: if (zoom >= 20)
742: return;
743:
744: zoom += 0.25;
745: if (zoom > 20)
746: zoom = 20;
747:
748: markupViewer->SetTextZoom(zoom);
749: }
750:
751: -(void) smallerTextSize
752: {
753: nsCOMPtr<nsIDOMWindow> contentWindow = getter_AddRefs([[mBrowserView getBrowserView] getContentWindow]);
754: nsCOMPtr<nsIScriptGlobalObject> global(do_QueryInterface(contentWindow));
755: if (!global)
756: return;
757: nsCOMPtr<nsIDocShell> docShell;
758: global->GetDocShell(getter_AddRefs(docShell));
759: if (!docShell)
760: return;
761: nsCOMPtr<nsIContentViewer> cv;
762: docShell->GetContentViewer(getter_AddRefs(cv));
763: nsCOMPtr<nsIMarkupDocumentViewer> markupViewer(do_QueryInterface(cv));
764: if (!markupViewer)
765: return;
766: float zoom;
767: markupViewer->GetTextZoom(&zoom);
768: if (zoom <= 0.01)
769: return;
770:
771: zoom -= 0.25;
772: if (zoom < 0.01)
773: zoom = 0.01;
774:
775: markupViewer->SetTextZoom(zoom);
1.63 hyatt 776: }
777:
778: -(id)getAddBookmarkSheetWindow
779: {
780: return mAddBookmarkSheetWindow;
781: }
782:
783: -(id)getAddBookmarkTitle
784: {
785: return mAddBookmarkTitleField;
786: }
787:
788: -(id)getAddBookmarkFolder
789: {
790: return mAddBookmarkFolderField;
1.59 hyatt 791: }
792:
793: // Called when a context menu should be shown.
794: - (void)onShowContextMenu:(int)flags domEvent:(nsIDOMEvent*)aEvent domNode:(nsIDOMNode*)aNode
795: {
796: mContextMenuFlags = flags;
797: mContextMenuNode = aNode;
798: mContextMenuEvent = aEvent;
799: }
800:
801: - (NSMenu*)getContextMenu
802: {
803: NSMenu* result = nil;
804: if ((mContextMenuFlags & nsIContextMenuListener::CONTEXT_LINK) != 0) {
805: if ((mContextMenuFlags & nsIContextMenuListener::CONTEXT_IMAGE) != 0) {
806: result = mImageLinkMenu;
807: }
808: else
809: result = mLinkMenu;
810: }
811: else if ((mContextMenuFlags & nsIContextMenuListener::CONTEXT_INPUT) != 0 ||
812: (mContextMenuFlags & nsIContextMenuListener::CONTEXT_TEXT) != 0) {
813: result = mInputMenu;
814: }
815: else if ((mContextMenuFlags & nsIContextMenuListener::CONTEXT_IMAGE) != 0) {
816: result = mImageMenu;
817: }
818: else if ((mContextMenuFlags & nsIContextMenuListener::CONTEXT_DOCUMENT) != 0) {
819: result = mPageMenu;
820: }
821:
822: return result;
1.61 hyatt 823: }
824:
825: // Context menu methods
826: - (IBAction)openLinkInNewWindow:(id)aSender
827: {
828: [self openLinkInNewWindowOrTab: YES];
829: }
830:
831: - (IBAction)openLinkInNewTab:(id)aSender
832: {
833: [self openLinkInNewWindowOrTab: NO];
834: }
835:
836: -(void)openLinkInNewWindowOrTab: (BOOL)aUseWindow
837: {
838: nsCOMPtr<nsIDOMElement> linkContent;
839: nsAutoString href;
840: GeckoUtils::GetEnclosingLinkElementAndHref(mContextMenuNode, getter_AddRefs(linkContent), href);
841:
842: // XXXdwh Handle simple XLINKs if we want to be compatible with Mozilla, but who
843: // really uses these anyway? :)
844: if (!linkContent || href.IsEmpty())
845: return;
846:
847: nsCOMPtr<nsIPrefBranch> pref(do_GetService("@mozilla.org/preferences-service;1"));
848: if (!pref)
849: return; // Something bad happened if we can't get prefs.
850:
851: NSString* hrefStr = [NSString stringWithCharacters: href.get() length:nsCRT::strlen(href.get())];
852: NSURL* urlToLoad = [NSURL URLWithString: hrefStr];
853:
854: PRBool loadInBackground;
855: pref->GetBoolPref("browser.tabs.loadInBackground", &loadInBackground);
856:
857: if (aUseWindow)
858: [self openNewWindowWithURL: urlToLoad loadInBackground: loadInBackground];
859: else
860: [self openNewTabWithURL: urlToLoad loadInBackground: loadInBackground];
861: }
862:
1.62 hyatt 863: - (IBAction)savePageAs:(id)aSender
864: {
865: [self saveDocument: nil filterList: nil];
866: }
867:
1.61 hyatt 868: - (IBAction)saveLinkAs:(id)aSender
869: {
1.62 hyatt 870: nsCOMPtr<nsIDOMElement> linkContent;
871: nsAutoString href;
872: GeckoUtils::GetEnclosingLinkElementAndHref(mContextMenuNode, getter_AddRefs(linkContent), href);
873:
874: // XXXdwh Handle simple XLINKs if we want to be compatible with Mozilla, but who
875: // really uses these anyway? :)
876: if (!linkContent || href.IsEmpty())
877: return;
878:
879: NSString* hrefStr = [NSString stringWithCharacters: href.get() length:nsCRT::strlen(href.get())];
880: NSURL* urlToSave = [NSURL URLWithString: hrefStr];
881:
882: // The user wants to save this link.
883: nsAutoString text;
884: GeckoUtils::GatherTextUnder(mContextMenuNode, text);
885:
886: [self saveURL: nil filterList: nil
887: url: urlToSave suggestedFilename: [NSString stringWithCharacters: text.get()
888: length:nsCRT::strlen(text.get())]];
1.61 hyatt 889: }
890:
891: - (IBAction)saveImageAs:(id)aSender
892: {
1.62 hyatt 893: nsCOMPtr<nsIDOMHTMLImageElement> imgElement(do_QueryInterface(mContextMenuNode));
894: if (imgElement) {
895: nsAutoString text;
896: imgElement->GetAttribute(NS_LITERAL_STRING("src"), text);
897: nsAutoString url;
898: imgElement->GetSrc(url);
899:
900: NSString* hrefStr = [NSString stringWithCharacters: url.get() length:nsCRT::strlen(url.get())];
901: NSURL* urlToSave = [NSURL URLWithString: hrefStr];
902:
903: [self saveURL: nil filterList: nil
904: url: urlToSave suggestedFilename: [NSString stringWithCharacters: text.get()
905: length:nsCRT::strlen(text.get())]];
906: }
907: }
908:
909: - (IBAction)viewOnlyThisImage:(id)aSender
910: {
911: nsCOMPtr<nsIDOMHTMLImageElement> imgElement(do_QueryInterface(mContextMenuNode));
912: if (imgElement) {
913: nsAutoString url;
914: imgElement->GetSrc(url);
915:
916: NSString* urlStr = [NSString stringWithCharacters: url.get() length:nsCRT::strlen(url.get())];
917: NSURL* urlToView = [NSURL URLWithString: urlStr];
918:
919: [self loadURL: urlToView];
920:
921: // Focus and activate our content area.
922: [[mBrowserView getBrowserView] setActive: YES];
923: }
1.58 hyatt 924: }
1.52 macserv 925:
1.1 hyatt 926: @end
927:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>