From 51fbf70b617fa86330795fb87a79f1d6624e9637 Mon Sep 17 00:00:00 2001 From: "smfr%smfr.org" Date: Thu, 24 Feb 2005 06:41:06 +0000 Subject: [PATCH] Fix warning by being explicit about return type of -setDisplaySecureIcon. --- camino/src/browser/AutoCompleteTextField.mm | 4 +- camino/src/browser/BrowserWindowController.h | 8 +- camino/src/browser/BrowserWindowController.mm | 212 ++++++--- camino/src/browser/BrowserWrapper.h | 66 ++- camino/src/browser/BrowserWrapper.mm | 417 +++++++++--------- 5 files changed, 400 insertions(+), 307 deletions(-) diff --git a/camino/src/browser/AutoCompleteTextField.mm b/camino/src/browser/AutoCompleteTextField.mm index 98ffa7e05f6..ff11ca6b1d3 100644 --- a/camino/src/browser/AutoCompleteTextField.mm +++ b/camino/src/browser/AutoCompleteTextField.mm @@ -86,7 +86,7 @@ static NSString* kCorePasteboardFlavorType_url = @"CorePasteboardFlavorType 0x7 { BOOL mDisplaySecureIcon; // YES if currently displaying the security icon } -- setDisplaySecureIcon:(BOOL)inIsVisible; +- (void)setDisplaySecureIcon:(BOOL)inIsVisible; @end @implementation AutoCompleteTextCell @@ -129,7 +129,7 @@ static NSString* kCorePasteboardFlavorType_url = @"CorePasteboardFlavorType 0x7 // Indicates whether or now we need to take away space on the right side for the security // icon. Causes the cell's drawing rect to be recalculated. // -- setDisplaySecureIcon:(BOOL)inIsVisible +- (void)setDisplaySecureIcon:(BOOL)inIsVisible { mDisplaySecureIcon = inIsVisible; [(NSControl*)[self controlView] calcSize]; diff --git a/camino/src/browser/BrowserWindowController.h b/camino/src/browser/BrowserWindowController.h index 3a0f0744afe..a2dc829b6ad 100644 --- a/camino/src/browser/BrowserWindowController.h +++ b/camino/src/browser/BrowserWindowController.h @@ -95,7 +95,7 @@ typedef enum @class AutoCompleteTextField; @class SearchTextField; -@interface BrowserWindowController : NSWindowController +@interface BrowserWindowController : NSWindowController { IBOutlet BrowserTabView* mTabBrowser; IBOutlet NSView* mLocationToolbarView; @@ -111,7 +111,6 @@ typedef enum IBOutlet BrowserContentView* mContentView; IBOutlet BookmarkToolbar* mPersonalToolbar; - IBOutlet HistoryDataSource* mHistoryDataSource; IBOutlet NSWindow* mAddBookmarkSheetWindow; IBOutlet NSTextField* mAddBookmarkTitleField; IBOutlet NSPopUpButton* mAddBookmarkFolderField; @@ -192,10 +191,7 @@ typedef enum - (BrowserWrapper*)getBrowserWrapper; - (void)loadURL:(NSString*)aURLSpec referrer:(NSString*)aReferrer activate:(BOOL)activate allowPopups:(BOOL)inAllowPopups; -- (void)updateLocationFields:(NSString *)locationString; -- (void)updateSiteIcons:(NSImage *)siteIconImage; -- (void)loadingStarted; -- (void)loadingDone; + - (void)focusURLBar; // call to update the image of the lock icon with a value from nsIWebProgressListener diff --git a/camino/src/browser/BrowserWindowController.mm b/camino/src/browser/BrowserWindowController.mm index 6eb2c068f30..9a3209f5bd5 100644 --- a/camino/src/browser/BrowserWindowController.mm +++ b/camino/src/browser/BrowserWindowController.mm @@ -58,6 +58,7 @@ #import "STFPopUpButtonCell.h" #import "MainController.h" #import "DraggableImageAndTextCell.h" +#import "MVPreferencesController.h" #include "nsIWebNavigation.h" #include "nsISHistory.h" @@ -419,11 +420,8 @@ enum BWCOpenDest { [[NSApp delegate] adjustCloseTabMenuItemKeyEquivalent:windowWithMultipleTabs]; [[NSApp delegate] adjustCloseWindowMenuItemKeyEquivalent:windowWithMultipleTabs]; - if ([self isResponderGeckoView:[[self window] firstResponder]]) { - CHBrowserView* browserView = [mBrowserView getBrowserView]; - if (browserView) - [browserView setActive:YES]; - } + if ([self isResponderGeckoView:[[self window] firstResponder]]) + [mBrowserView setBrowserActive:YES]; } - (void)windowDidResignKey:(NSNotification *)notification @@ -433,11 +431,8 @@ enum BWCOpenDest { [[NSApp delegate] adjustCloseTabMenuItemKeyEquivalent:NO]; [[NSApp delegate] adjustCloseWindowMenuItemKeyEquivalent:NO]; - if ([self isResponderGeckoView:[[self window] firstResponder]]) { - CHBrowserView* browserView = [mBrowserView getBrowserView]; - if (browserView) - [browserView setActive:NO]; - } + if ([self isResponderGeckoView:[[self window] firstResponder]]) + [mBrowserView setBrowserActive:NO]; } - (void)windowDidBecomeMain:(NSNotification *)notification @@ -1169,14 +1164,14 @@ enum BWCOpenDest { // we have to handle all the enabling/disabling ourselves because this // toolbar button is a view item. Note the return value is ignored. - [(NSButton*)[theItem view] setEnabled:enable]; + [theItem setEnabled:enable]; return enable; } else if (action == @selector(forward:)) { // we have to handle all the enabling/disabling ourselves because this // toolbar button is a view item. Note the return value is ignored. BOOL enable = [[mBrowserView getBrowserView] canGoForward]; - [(NSButton*)[theItem view] setEnabled:enable]; + [theItem setEnabled:enable]; return enable; } else if (action == @selector(reload:)) @@ -1213,16 +1208,132 @@ enum BWCOpenDest { #pragma mark - +// BrowserUIDelegate methods (called from the frontmost tab's BrowserWrapper) + + - (void)loadingStarted { - [self startThrobber]; + [self ensureBrowserVisible:mBrowserView]; } -- (void)loadingDone +- (void)loadingDone:(BOOL)activateContent { - [self stopThrobber]; + if (activateContent) + { + if ([[self window] isKeyWindow]) + { + if (![self userChangedLocationField]) + [mBrowserView setBrowserActive:YES]; + } + else + [[self window] makeFirstResponder:[mBrowserView getBrowserView]]; + } } +- (void)setLoadingActive:(BOOL)active +{ + if (active) + { + [self startThrobber]; + [mProgress setIndeterminate:YES]; + [self showProgressIndicator]; + [mProgress startAnimation:self]; + } + else + { + [self stopThrobber]; + [mProgress stopAnimation:self]; + [self hideProgressIndicator]; + [mProgress setIndeterminate:YES]; + } +} + +- (void)setLoadingProgress:(float)progress +{ + if (progress > 0.0f) + { + [mProgress setIndeterminate:NO]; + [mProgress setDoubleValue:progress]; + } + else + { + [mProgress setIndeterminate:YES]; + [mProgress startAnimation:self]; + } +} + +- (void)updateWindowTitle:(NSString*)title +{ + [[self window] setTitle:title]; +} + +- (void)updateStatus:(NSString*)status +{ + if (![[mStatus stringValue] isEqualToString:status]) + [mStatus setStringValue:status]; +} + +- (void)updateLocationFields:(NSString*)url ignoreTyping:(BOOL)ignoreTyping +{ + if (!ignoreTyping && [self userChangedLocationField]) + return; + + if ([url isEqual:@"about:blank"]) + url = @""; // return; + + [mURLBar setURI:url]; + [mLocationSheetURLField setStringValue:url]; + + // don't call [window display] here, no matter how much you might want + // to, because it forces a redraw of every view in the window and with a lot + // of tabs, it's dog slow. + // [[self window] display]; +} + +- (void)updateSiteIcons:(NSImage*)icon ignoreTyping:(BOOL)ignoreTyping +{ + if (!ignoreTyping && [self userChangedLocationField]) + return; + + if (icon == nil) + icon = [NSImage imageNamed:@"globe_ico"]; + [mProxyIcon setImage:icon]; +} + +- (void)showPopupBlocked:(BOOL)inBlocked +{ + if (inBlocked && ![mPopupBlocked window]) { // told to show, currently hidden + [mPopupBlockSuperview addSubview:mPopupBlocked]; + } + else if (!inBlocked && [mPopupBlocked window]) { // told to hide, currently visible + [mPopupBlocked removeFromSuperview]; + } +} + +- (void)showSecurityState:(unsigned long)state +{ + [self updateLock:state]; +} + +- (BOOL)userChangedLocationField +{ + return [mURLBar userHasTyped]; +} + +- (void)updateFromFrontmostTab +{ + [[self window] setTitle: [mBrowserView windowTitle]]; + [self setLoadingActive: [mBrowserView isBusy]]; + [self setLoadingProgress: [mBrowserView loadingProgress]]; + [self showPopupBlocked: [mBrowserView popupsBlocked]]; + [self showSecurityState: [mBrowserView securityState]]; + [self updateSiteIcons: [mBrowserView siteIcon] ignoreTyping:NO]; + [self updateStatus: [mBrowserView statusString]]; + [self updateLocationFields:[mBrowserView location] ignoreTyping:NO]; +} + +#pragma mark - + - (void)performAppropriateLocationAction { NSToolbar *toolbar = [[self window] toolbar]; @@ -1249,8 +1360,8 @@ enum BWCOpenDest { - (void)focusURLBar { - [[mBrowserView getBrowserView] setActive:NO]; - [mURLBar selectText: self]; + [mBrowserView setBrowserActive:NO]; + [mURLBar selectText:self]; } - (void)beginLocationSheet @@ -1301,8 +1412,7 @@ enum BWCOpenDest { - (void)focusSearchBar { - [[mBrowserView getBrowserView] setActive:NO]; - + [mBrowserView setBrowserActive:NO]; [mSearchBar selectText:self]; } @@ -2040,27 +2150,6 @@ enum BWCOpenDest { } } -- (void)updateLocationFields:(NSString *)locationString -{ - if ( [locationString isEqual:@"about:blank"] ) - locationString = @""; // return; - - [mURLBar setURI:locationString]; - [mLocationSheetURLField setStringValue:locationString]; - - // don't call [window display] here, no matter how much you might want - // to, because it forces a redraw of every view in the window and with a lot - // of tabs, it's dog slow. - // [[self window] display]; -} - -- (void)updateSiteIcons:(NSImage *)siteIconImage -{ - if (siteIconImage == nil) - siteIconImage = [NSImage imageNamed:@"globe_ico"]; - [mProxyIcon setImage:siteIconImage]; -} - // // closeBrowserWindow: // @@ -2238,15 +2327,23 @@ enum BWCOpenDest { // Disconnect the old view, if one has been designated. // If the window has just been opened, none has been. - if ( mBrowserView ) - [mBrowserView disconnectView]; + if (mBrowserView) + { + [mBrowserView willResignActiveBrowser]; + [mBrowserView setDelegate:nil]; + } // Connect up the new view mBrowserView = [aTabViewItem view]; [mTabBrowser refreshTabBar:YES]; // Make the new view the primary content area. - [mBrowserView makePrimary:mURLBar status:mStatus]; + [mBrowserView setDelegate:self]; + [mBrowserView didBecomeActiveBrowser]; + [self updateFromFrontmostTab]; + + if (![self userChangedLocationField] && [[self window] isKeyWindow]) + [mBrowserView setBrowserActive:YES]; } - (void)tabView:(NSTabView *)aTabView willSelectTabViewItem:(NSTabViewItem *)aTabViewItem @@ -2414,7 +2511,7 @@ enum BWCOpenDest { -(BrowserTabViewItem*)createNewTabItem { BrowserTabViewItem* newTab = [BrowserTabView makeNewTabItem]; - BrowserWrapper* newView = [[BrowserWrapper alloc] initWithTab:newTab windowController:self]; + BrowserWrapper* newView = [[BrowserWrapper alloc] initWithTab:newTab inWindow:[self window]]; // size the new browser view properly up-front, so that if the // page is scrolled to a relative anchor, we don't mess with the @@ -2798,21 +2895,6 @@ enum BWCOpenDest { [mProgress removeFromSuperview]; } -// -// - showPopupBlocked: -// -// Show/hide the image of the blocked-popup indicator -// -- (void)showPopupBlocked:(BOOL)inBlocked -{ - if (inBlocked && ![mPopupBlocked window]) { // told to show, currently hidden - [mPopupBlockSuperview addSubview:mPopupBlocked]; - } - else if (!inBlocked && [mPopupBlocked window]) { // told to hide, currently visible - [mPopupBlocked removeFromSuperview]; - } -} - // // buildPopupBlockerMenu: // @@ -3045,7 +3127,7 @@ enum BWCOpenDest { BOOL newResponderIsGecko = [self isResponderGeckoView:newResponder]; if (oldResponderIsGecko != newResponderIsGecko && [[self window] isKeyWindow]) - [[mBrowserView getBrowserView] setActive:newResponderIsGecko]; + [mBrowserView setBrowserActive:newResponderIsGecko]; } @@ -3105,9 +3187,7 @@ enum BWCOpenDest { if ([self isResponderGeckoView:[[self window] firstResponder]]) { // inform the tab view that it will be hidden so that it can perform any necessary cleanup [mTabBrowser setVisible:NO]; - CHBrowserView* browserView = [mBrowserView getBrowserView]; - if (browserView) - [browserView setActive:NO]; + [mBrowserView setBrowserActive:NO]; } // swap out between content and bookmarks. @@ -3130,9 +3210,7 @@ enum BWCOpenDest { } else { [[self window] setTitle:[self savedTitle]]; - CHBrowserView* browserView = [mBrowserView getBrowserView]; - if (browserView) - [browserView setActive:YES]; + [mBrowserView setBrowserActive:YES]; // inform the tab view that it will be visible, so that it can adjust to any changes that occurred // when it was out of the hierarchy [mTabBrowser setVisible:YES]; @@ -3181,7 +3259,7 @@ enum BWCOpenDest { // kill any autocomplete that was in progress [mURLBar revertText]; // set the text in the URL bar back to the current URL - [self updateLocationFields:[mBrowserView getCurrentURLSpec]]; + [self updateLocationFields:[mBrowserView getCurrentURLSpec] ignoreTyping:YES]; // see if command-return came in the search field } else if ([mSearchBar isFirstResponder]) { diff --git a/camino/src/browser/BrowserWrapper.h b/camino/src/browser/BrowserWrapper.h index dbeb0232640..9c2ada16cbd 100644 --- a/camino/src/browser/BrowserWrapper.h +++ b/camino/src/browser/BrowserWrapper.h @@ -44,11 +44,36 @@ class nsISupportsArray; +// The BrowserWrapper communicates with the UI via this delegate. +// The delegate will be nil for background tabs. +@protocol BrowserUIDelegate + +- (void)loadingStarted; +- (void)loadingDone:(BOOL)activateContent; + +- (void)setLoadingActive:(BOOL)active; +// a progress value of 0.0 will set the meter to its indeterminate state +- (void)setLoadingProgress:(float)progress; + +- (void)updateWindowTitle:(NSString*)title; +- (void)updateStatus:(NSString*)status; + +- (void)updateLocationFields:(NSString*)url ignoreTyping:(BOOL)ignoreTyping; +- (void)updateSiteIcons:(NSImage*)icon ignoreTyping:(BOOL)ignoreTyping; + +- (void)showPopupBlocked:(BOOL)blocked; +- (void)showSecurityState:(unsigned long)state; + +- (BOOL)userChangedLocationField; + +@end + + @interface BrowserWrapper : NSView { - AutoCompleteTextField* mUrlbar; - NSTextField* mStatus; - BrowserWindowController* mWindowController; + NSWindow* mWindow; // the window we are or will be in + + // XXX the BrowserWrapper really shouldn;t know anything about the tab that it's in NSTabViewItem* mTabItem; NSImage* mSiteIconImage; // current proxy icon image, which may be a site icon (favicon). @@ -74,7 +99,8 @@ class nsISupportsArray; double mProgress; - BOOL mIsPrimary; + id mDelegate; // not retained + BOOL mIsBusy; BOOL mOffline; BOOL mListenersAttached; // We hook up our click and context menu listeners lazily. @@ -82,27 +108,43 @@ class nsISupportsArray; BOOL mActivateOnLoad; // If set, activate the browser view when loading starts. } -- (id)initWithTab:(NSTabViewItem*)aTab windowController:(BrowserWindowController*)aWindowController; +- (id)initWithTab:(NSTabViewItem*)aTab inWindow:(NSWindow*)window; +- (id)initWithFrame:(NSRect)frameRect inWindow:(NSWindow*)window; -- (IBAction)load:(id)sender; -- (void)awakeFromNib; +// only the BrowserWrapper in the frontmost tab has a non-null delegate +- (void)setDelegate:(id)delegate; +- (id)delegate; + +- (void)windowClosed; -- (void)setFrame:(NSRect)frameRect; - (void)setFrame:(NSRect)frameRect resizingBrowserViewIfHidden:(BOOL)inResizeBrowser; +- (void)setBrowserActive:(BOOL)inActive; + + +// accessors - (CHBrowserView*)getBrowserView; - (BOOL)isBusy; - (BOOL)isEmpty; // is about:blank loaded? -- (void)windowClosed; + +- (NSString*)windowTitle; +- (NSImage*)siteIcon; +- (NSString*)location; +- (NSString*)statusString; +- (float)loadingProgress; +- (BOOL)popupsBlocked; +- (unsigned long)securityState; - (NSString*)getCurrentURLSpec; - (void)getBlockedSites:(nsISupportsArray**)outSites; - (void)loadURI:(NSString *)urlSpec referrer:(NSString*)referrer flags:(unsigned int)flags activate:(BOOL)activate allowPopups:(BOOL)inAllowPopups; -- (void)makePrimary:(AutoCompleteTextField*)aUrlbar status:(NSTextField*)aStatus; -- (void)disconnectView; -- (void)setTab: (NSTabViewItem*)tab; + +- (void)didBecomeActiveBrowser; +- (void)willResignActiveBrowser; + +- (void)setTab:(NSTabViewItem*)tab; - (NSTabViewItem*) tab; - (IBAction)reloadWithNewCharset:(NSString*)charset; diff --git a/camino/src/browser/BrowserWrapper.mm b/camino/src/browser/BrowserWrapper.mm index 7f2ae205d11..e6e5e44302b 100644 --- a/camino/src/browser/BrowserWrapper.mm +++ b/camino/src/browser/BrowserWrapper.mm @@ -76,6 +76,8 @@ static NSString* const kOfflineNotificationName = @"offlineModeChanged"; @interface BrowserWrapper(Private) +- (void)ensureContentClickListeners; + - (void)setPendingActive:(BOOL)active; - (void)registerNotificationListener; @@ -87,17 +89,21 @@ static NSString* const kOfflineNotificationName = @"offlineModeChanged"; - (void)setTabTitle:(NSString*)tabTitle windowTitle:(NSString*)windowTitle; - (NSString*)displayTitleForPageURL:(NSString*)inURL title:(NSString*)inTitle; +- (void)updateOfflineStatus; + @end #pragma mark - @implementation BrowserWrapper -- (id)initWithTab:(NSTabViewItem*)aTab windowController:(BrowserWindowController*)aWindowController +- (id)initWithTab:(NSTabViewItem*)aTab inWindow:(NSWindow*)window { - mTabItem = aTab; - mWindowController = aWindowController; - return [self initWithFrame: NSZeroRect]; + if (([self initWithFrame:NSZeroRect inWindow:window])) + { + mTabItem = aTab; + } + return self; } // @@ -105,14 +111,21 @@ static NSString* const kOfflineNotificationName = @"offlineModeChanged"; // // Create a Gecko browser view and hook everything up to the UI // -- (id)initWithFrame:(NSRect)frameRect +- (id)initWithFrame:(NSRect)frameRect inWindow:(NSWindow*)window { - if ( (self = [super initWithFrame: frameRect]) ) { - mBrowserView = [[[CHBrowserView alloc] initWithFrame:[self bounds] andWindow: [self getNativeWindow]] autorelease]; - [self addSubview: mBrowserView]; + if ((self = [super initWithFrame: frameRect])) + { + mWindow = window; + + mBrowserView = [[CHBrowserView alloc] initWithFrame:[self bounds] andWindow:window]; + [self addSubview: mBrowserView]; // takes ownership + [mBrowserView release]; + [mBrowserView setContainer:self]; [mBrowserView addListener:self]; + [[KeychainService instance] addListenerToView:mBrowserView]; + mIsBusy = NO; mListenersAttached = NO; mSecureState = nsIWebProgressListener::STATE_IS_INSECURE; @@ -129,9 +142,11 @@ static NSString* const kOfflineNotificationName = @"offlineModeChanged"; //[self setSiteIconImage:[NSImage imageNamed:@"globe_ico"]]; //[self setSiteIconURI: [NSString string]]; - mDefaultStatusString = nil; - mLoadingStatusString = nil; + mDefaultStatusString = @""; + mLoadingStatusString = @""; + mTitle = @""; + [self registerNotificationListener]; } return self; @@ -159,6 +174,10 @@ static NSString* const kOfflineNotificationName = @"offlineModeChanged"; [super dealloc]; } +- (BOOL)isFlipped +{ + return YES; +} -(void)windowClosed { @@ -173,23 +192,18 @@ static NSString* const kOfflineNotificationName = @"offlineModeChanged"; // We don't want site icon notifications when the window has gone away [[NSNotificationCenter defaultCenter] removeObserver:self name:SiteIconLoadNotificationName object:nil]; // We're basically a zombie now. Clear fields which are in an undefined state. - mIsPrimary = NO; - mWindowController = nil; + mDelegate = nil; + mWindow = nil; } -- (IBAction)load:(id)sender +- (void)setDelegate:(id)delegate { - [mBrowserView loadURI:[mUrlbar stringValue] referrer:nil flags:NSLoadFlagsNone allowPopups:NO]; + mDelegate = delegate; } --(void)disconnectView +- (id)delegate { - mUrlbar = nil; - mStatus = nil; - mIsPrimary = NO; - [[NSNotificationCenter defaultCenter] removeObserver:self name:kOfflineNotificationName object:nil]; - - [mBrowserView setActive: NO]; + return mDelegate; } -(void)setTab: (NSTabViewItem*)tab @@ -202,101 +216,11 @@ static NSString* const kOfflineNotificationName = @"offlineModeChanged"; return mTabItem; } -- (void)makePrimary:(AutoCompleteTextField*)aUrlbar status:(NSTextField*)aStatus -{ - mUrlbar = aUrlbar; - mStatus = aStatus; - - if (mIsBusy) - { - [mWindowController startThrobber]; - [mWindowController showProgressIndicator]; - - if (mProgress > 0.0) - { - [[mWindowController progressIndicator] setIndeterminate:NO]; - [[mWindowController progressIndicator] setDoubleValue:mProgress]; - } - else - { - [[mWindowController progressIndicator] setIndeterminate:YES]; - [[mWindowController progressIndicator] startAnimation:self]; - } - } - else - { - [mWindowController stopThrobber]; - [mWindowController hideProgressIndicator]; - - [mDefaultStatusString autorelease]; - mDefaultStatusString = nil; - [mLoadingStatusString autorelease]; - mLoadingStatusString = [NSLocalizedString(@"DocumentDone", @"") retain]; - } - - [mStatus setStringValue:mLoadingStatusString]; - - mIsPrimary = YES; - - // update the global lock icon to the current state of this browser. We need - // to do this after we set |mIsPrimary|. - [self onSecurityStateChange:mSecureState]; - - // update the window's title. - [self setTabTitle:mTabTitle windowTitle:mTitle]; - - if ([[self window] isKeyWindow] && ![mUrlbar userHasTyped]) - [mBrowserView setActive: YES]; - - nsCOMPtr ioService(do_GetService(ioServiceContractID)); - if (!ioService) - return; - PRBool offline = PR_FALSE; - ioService->GetOffline(&offline); - mOffline = offline; - - [[NSNotificationCenter defaultCenter] addObserver:self - selector:@selector(offlineModeChanged:) - name:kOfflineNotificationName - object:nil]; - - // update the blocked popup indicator - [mWindowController showPopupBlocked:(mBlockedSites != nil)]; - - // Update the URL bar, but only if the user hasn't put something of their - // own in there. - if (![mUrlbar userHasTyped]) { - [mWindowController updateLocationFields:[self getCurrentURLSpec]]; - [mWindowController updateSiteIcons:mSiteIconImage]; - } - - if (mWindowController && !mListenersAttached) - { - mListenersAttached = YES; - - // We need to hook up our click and context menu listeners. - ContentClickListener* clickListener = new ContentClickListener(mWindowController); - if (!clickListener) - return; - - nsCOMPtr contentWindow = getter_AddRefs([[self getBrowserView] getContentWindow]); - nsCOMPtr piWindow(do_QueryInterface(contentWindow)); - nsIChromeEventHandler *chromeHandler = piWindow->GetChromeEventHandler(); - nsCOMPtr rec(do_QueryInterface(chromeHandler)); - if ( rec ) - rec->AddEventListenerByIID(clickListener, NS_GET_IID(nsIDOMMouseListener)); - } -} - -(NSString*)getCurrentURLSpec { return [mBrowserView getCurrentURLSpec]; } -- (void)awakeFromNib -{ -} - - (void)setFrame:(NSRect)frameRect { [self setFrame:frameRect resizingBrowserViewIfHidden:NO]; @@ -319,102 +243,187 @@ static NSString* const kOfflineNotificationName = @"offlineModeChanged"; } } +- (void)setBrowserActive:(BOOL)inActive +{ + [mBrowserView setActive:inActive]; +} + -(BOOL)isBusy { return mIsBusy; } +- (NSString*)windowTitle +{ + return mTitle; +} + +- (NSImage*)siteIcon +{ + return mSiteIconImage; +} + +- (NSString*)location +{ + return [mBrowserView getCurrentURLSpec]; +} + +- (NSString*)statusString +{ + // XXX is this right? + return mDefaultStatusString ? mDefaultStatusString : mLoadingStatusString; +} + +- (float)loadingProgress +{ + return mProgress; +} + +- (BOOL)popupsBlocked +{ + if (!mBlockedSites) return NO; + + PRUint32 numBlocked = 0; + mBlockedSites->Count(&numBlocked); + + return (numBlocked > 0); +} + +- (unsigned long)securityState +{ + return mSecureState; +} + + - (void)loadURI:(NSString *)urlSpec referrer:(NSString*)referrer flags:(unsigned int)flags activate:(BOOL)activate allowPopups:(BOOL)inAllowPopups { // blast it into the urlbar immediately so that we know what we're // trying to load, even if it doesn't work - if (mIsPrimary) - [mWindowController updateLocationFields:urlSpec]; + [mDelegate updateLocationFields:urlSpec ignoreTyping:YES]; // if we're not the primary tab, make sure that the browser view is // the correct size when loading a url so that if the url is a relative // anchor, which will cause a scroll to the anchor on load, the scroll // position isn't messed up when we finally display the tab. - if (!mIsPrimary) + if (mDelegate == nil) { - NSRect tabContentRect = [[mWindowController getTabBrowser] contentRect]; + NSRect tabContentRect = [[[mWindow delegate] getTabBrowser] contentRect]; [self setFrame:tabContentRect resizingBrowserViewIfHidden:YES]; } - mActivateOnLoad = activate; + [self setPendingActive:activate]; [mBrowserView loadURI:urlSpec referrer:referrer flags:flags allowPopups:inAllowPopups]; } +- (void)ensureContentClickListeners +{ + if (!mListenersAttached) + { + mListenersAttached = YES; + + // We need to hook up our click and context menu listeners. + // XXX broken + ContentClickListener* clickListener = new ContentClickListener([mWindow delegate]); + if (!clickListener) + return; + + nsCOMPtr contentWindow = getter_AddRefs([[self getBrowserView] getContentWindow]); + nsCOMPtr piWindow(do_QueryInterface(contentWindow)); + nsIChromeEventHandler *chromeHandler = piWindow->GetChromeEventHandler(); + nsCOMPtr rec(do_QueryInterface(chromeHandler)); + if ( rec ) + rec->AddEventListenerByIID(clickListener, NS_GET_IID(nsIDOMMouseListener)); + } +} + +- (void)didBecomeActiveBrowser +{ + { +#if 0 + [mDefaultStatusString autorelease]; + mDefaultStatusString = nil; + [mLoadingStatusString autorelease]; + mLoadingStatusString = [NSLocalizedString(@"DocumentDone", @"") retain]; +#endif + } + + [self ensureContentClickListeners]; + [self updateOfflineStatus]; + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(offlineModeChanged:) + name:kOfflineNotificationName + object:nil]; + +} + +-(void)willResignActiveBrowser +{ + [[NSNotificationCenter defaultCenter] removeObserver:self name:kOfflineNotificationName object:nil]; + [mBrowserView setActive:NO]; +} + + +#pragma mark - + - (void)onLoadingStarted { - if (mDefaultStatusString) { + if (mDefaultStatusString) + { [mDefaultStatusString autorelease]; mDefaultStatusString = nil; } - // it would be much cleaner to wrap up everything that is called - // on the window controller into a delegate protocol, and set - // the delegate of the frontmost wrapper to the BWC - if (mIsPrimary) - { - [mWindowController ensureBrowserVisible:self]; - [mWindowController showProgressIndicator]; - [[mWindowController progressIndicator] setIndeterminate:YES]; - [[mWindowController progressIndicator] startAnimation:self]; - } + mProgress = 0.0; + mIsBusy = YES; + + [mDelegate loadingStarted]; + [mDelegate setLoadingActive:YES]; + [mDelegate setLoadingProgress:mProgress]; [mLoadingStatusString autorelease]; mLoadingStatusString = [NSLocalizedString(@"TabLoading", @"") retain]; - [mStatus setStringValue:mLoadingStatusString]; + [mDelegate updateStatus:mLoadingStatusString]; [(BrowserTabViewItem*)mTabItem startLoadAnimation]; NS_IF_RELEASE(mBlockedSites); - if (mIsPrimary) - [mWindowController showPopupBlocked:NO]; - - mProgress = 0.0; - mIsBusy = YES; + [mDelegate showPopupBlocked:NO]; [mTabTitle autorelease]; mTabTitle = [mLoadingStatusString retain]; [mTabItem setLabel:mTabTitle]; - - if (mIsPrimary) - [mWindowController loadingStarted]; } - (void)onLoadingCompleted:(BOOL)succeeded { - if (mActivateOnLoad) { +#if 0 + if (mActivateOnLoad) + { // if we're the front/key window, focus the content area. If we're not, // set gecko as the first responder so that it will be activated when // the window is focused. If the user is typing in the urlBar, however, // don't mess with the focus at all. - if ( ![mUrlbar userHasTyped] ) { - if ( [[mBrowserView window] isKeyWindow] ) + if (mDelegate) + { + if (![mDelegate userChangedLocationField] && [mWindow isKeyWindow]) [mBrowserView setActive:YES]; else - [[mBrowserView window] makeFirstResponder:mBrowserView]; + [mWindow makeFirstResponder:mBrowserView]; + } mActivateOnLoad = NO; } +#endif - if (mIsPrimary) - { - [[mWindowController progressIndicator] setIndeterminate:YES]; - [[mWindowController progressIndicator] stopAnimation:self]; - [mWindowController hideProgressIndicator]; - } + [mDelegate loadingDone:mActivateOnLoad]; + mActivateOnLoad = NO; + [mDelegate setLoadingActive:NO]; + [mLoadingStatusString autorelease]; mLoadingStatusString = [NSLocalizedString(@"DocumentDone", @"") retain]; - if (mDefaultStatusString) { - [mStatus setStringValue:mDefaultStatusString]; - } - else { - [mStatus setStringValue:mLoadingStatusString]; - } + + [mDelegate updateStatus:mDefaultStatusString ? mDefaultStatusString : mLoadingStatusString]; [(BrowserTabViewItem*)mTabItem stopLoadAnimation]; @@ -430,9 +439,6 @@ static NSString* const kOfflineNotificationName = @"offlineModeChanged"; mProgress = 1.0; mIsBusy = NO; - if (mIsPrimary) - [mWindowController loadingDone]; - // send a little love to the bookmarks if (urlString && ![urlString isEqualToString:@"about:blank"]) { @@ -447,14 +453,7 @@ static NSString* const kOfflineNotificationName = @"offlineModeChanged"; if (maxBytes > 0) { mProgress = ((double)currentBytes / (double)maxBytes) * 100.0; - - if (mIsPrimary) - { - BOOL isIndeterminate = [[mWindowController progressIndicator] isIndeterminate]; - if (isIndeterminate) - [[mWindowController progressIndicator] setIndeterminate:NO]; - [[mWindowController progressIndicator] setDoubleValue:mProgress]; - } + [mDelegate setLoadingProgress:mProgress]; } } @@ -484,18 +483,12 @@ static NSString* const kOfflineNotificationName = @"offlineModeChanged"; if (!siteIconLoadInitiated) [self updateSiteIconImage:nil withURI:faviconURI]; - // if the user has started typing something, don't destroy it - if (mIsPrimary && ![mUrlbar userHasTyped]) - [mWindowController updateLocationFields:urlSpec]; + [mDelegate updateLocationFields:urlSpec ignoreTyping:NO]; } - (void)onStatusChange:(NSString*)aStatusString { - if (![[mStatus stringValue] isEqualToString:aStatusString]) - { - [mStatus setStringValue: aStatusString]; - //[mStatus displayIfNeeded]; // XXX expensive; slows page load - } + [mDelegate updateStatus:aStatusString]; } // @@ -508,8 +501,7 @@ static NSString* const kOfflineNotificationName = @"offlineModeChanged"; - (void)onSecurityStateChange:(unsigned long)newState { mSecureState = newState; - if (mIsPrimary) - [mWindowController updateLock:newState]; + [mDelegate showSecurityState:mSecureState]; } - (void)setStatus:(NSString *)statusString ofType:(NSStatusType)type @@ -519,8 +511,7 @@ static NSString* const kOfflineNotificationName = @"offlineModeChanged"; if (type == NSStatusTypeScriptDefault) { [mDefaultStatusString autorelease]; - mDefaultStatusString = statusString; - [mDefaultStatusString retain]; + mDefaultStatusString = [statusString retain]; } else if (!statusString) { @@ -531,13 +522,8 @@ static NSString* const kOfflineNotificationName = @"offlineModeChanged"; newStatus = statusString; } - if (newStatus && ![[mStatus stringValue] isEqualToString:newStatus]) - { - [mStatus setStringValue:newStatus]; - //[mStatus displayIfNeeded]; // force an immediate display. This works around some issues - // where cocoa unions update rects in the content and chrome, - // causing slow updating (bug 2194819). - } + if (newStatus) + [mDelegate updateStatus:newStatus]; } - (NSString *)title @@ -565,8 +551,7 @@ static NSString* const kOfflineNotificationName = @"offlineModeChanged"; newWindowTitle = [NSString stringWithFormat:NSLocalizedString(@"OfflineTitleFormat", @""), newWindowTitle]; mTitle = [newWindowTitle retain]; - if (mIsPrimary) - [[mWindowController window] setTitle:[mTitle stringByTruncatingTo:80 at:kTruncateAtEnd]]; + [mDelegate updateWindowTitle:[mTitle stringByTruncatingTo:80 at:kTruncateAtEnd]]; // Always set the tab. [mTabItem setLabel:mTabTitle]; // tab titles get truncated when setting them to tabs @@ -592,9 +577,14 @@ static NSString* const kOfflineNotificationName = @"offlineModeChanged"; return NSLocalizedString(@"UntitledPageTitle", @""); } -- (BOOL)isFlipped +- (void)updateOfflineStatus { - return YES; + nsCOMPtr ioService(do_GetService(ioServiceContractID)); + if (!ioService) + return; + PRBool offline = PR_FALSE; + ioService->GetOffline(&offline); + mOffline = offline; } // @@ -631,8 +621,7 @@ static NSString* const kOfflineNotificationName = @"offlineModeChanged"; NS_NewISupportsArray(&mBlockedSites); if ( mBlockedSites ) { mBlockedSites->AppendElement(inSite); - if (mIsPrimary) - [mWindowController showPopupBlocked:YES]; + [mDelegate showPopupBlocked:YES]; } } @@ -640,26 +629,27 @@ static NSString* const kOfflineNotificationName = @"offlineModeChanged"; - (void)onShowContextMenu:(int)flags domEvent:(nsIDOMEvent*)aEvent domNode:(nsIDOMNode*)aNode { // presumably this is only called on the primary tab - [mWindowController onShowContextMenu: flags domEvent: aEvent domNode: aNode]; + [[mWindow delegate] onShowContextMenu:flags domEvent:aEvent domNode:aNode]; } -(NSMenu*)getContextMenu { - return [mWindowController getContextMenu]; + return [[mWindow delegate] getContextMenu]; } -(NSWindow*)getNativeWindow { - NSWindow* window = [self window]; - if (window) - return window; + // use the view's window first + NSWindow* viewsWindow = [self window]; + if (viewsWindow) + return viewsWindow; - return [mWindowController window]; + return mWindow; } - (BOOL)shouldAcceptDragFromSource:(id)dragSource { - if ((dragSource == self) || (dragSource == mTabItem) || (dragSource == [mWindowController proxyIconView])) + if ((dragSource == self) || (dragSource == mTabItem) || (dragSource == [[mWindow delegate] proxyIconView])) return NO; if ([mTabItem isMemberOfClass:[BrowserTabViewItem class]] && (dragSource == [(BrowserTabViewItem*)mTabItem tabItemContentsView])) @@ -677,7 +667,7 @@ static NSString* const kOfflineNotificationName = @"offlineModeChanged"; // - (void)closeBrowserWindow { - [mWindowController closeBrowserWindow:self]; + [[mWindow delegate] closeBrowserWindow:self]; } - (void)getTitle:(NSString **)outTitle andHref:(NSString**)outHrefString @@ -709,29 +699,17 @@ static NSString* const kOfflineNotificationName = @"offlineModeChanged"; *outTitle = [NSString stringWith_nsAString:titleString]; } -- (void)offlineModeChanged: (NSNotification*)aNotification +- (void)offlineModeChanged:(NSNotification*)aNotification { - nsCOMPtr ioService(do_GetService(ioServiceContractID)); - if (!ioService) - return; - PRBool offline = PR_FALSE; - ioService->GetOffline(&offline); - mOffline = offline; - - // XXX localize me - if (mIsPrimary) - { - if (mOffline) - { - NSString* newTitle = [[[mWindowController window] title] stringByAppendingString: @" [Working Offline]"]; - [[mWindowController window] setTitle: newTitle]; - } - else - { - NSArray* titleItems = [[[mWindowController window] title] componentsSeparatedByString:@" [Working Offline]"]; - [[mWindowController window] setTitle: [titleItems objectAtIndex: 0]]; - } - } + [self updateOfflineStatus]; + + // This is pretty broken, and unused. We'd need to do this title futzing + // on every title change, not just now. + // XXX localize me + NSString* titleTrailer = mOffline ? @" [Working Offline]" : @" [Working Offline]"; + NSString* newWindowTitle = [mTitle stringByAppendingString:titleTrailer]; + + [mDelegate updateWindowTitle:newWindowTitle]; } // @@ -847,8 +825,7 @@ static NSString* const kOfflineNotificationName = @"offlineModeChanged"; [self setSiteIconURI: inSiteIconURI]; // update the proxy icon - if (mIsPrimary) - [mWindowController updateSiteIcons:mSiteIconImage]; + [mDelegate updateSiteIcons:mSiteIconImage ignoreTyping:NO]; resetTabIcon = YES; }