From 983cc0c99803c960174992c0f4217e077565094d Mon Sep 17 00:00:00 2001 From: "pinkerton@chromium.org" Date: Fri, 6 Feb 2009 21:12:59 +0000 Subject: Ensure toolbar buttons are in sync with command updater when tab becomes selected. Remove a NOTIMPLEMENTED that shouldn't be there. Review URL: http://codereview.chromium.org/20138 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@9338 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome/browser/cocoa/tab_contents_controller.h | 5 +++++ chrome/browser/cocoa/tab_contents_controller.mm | 28 +++++++++++++++++++------ chrome/browser/cocoa/tab_strip_controller.mm | 6 ++++++ chrome/common/temp_scaffolding_stubs.h | 5 +---- 4 files changed, 34 insertions(+), 10 deletions(-) diff --git a/chrome/browser/cocoa/tab_contents_controller.h b/chrome/browser/cocoa/tab_contents_controller.h index 51878a1..2d3f110 100644 --- a/chrome/browser/cocoa/tab_contents_controller.h +++ b/chrome/browser/cocoa/tab_contents_controller.h @@ -50,6 +50,11 @@ class TabStripModel; // Get the C++ bridge object representing the location bar for this tab. - (LocationBar*)locationBar; +// Called when the tab contents is about to be put into the view hierarchy as +// the selected tab. Handles things such as ensuring the toolbar is correctly +// enabled. +- (void)willBecomeSelectedTab; + @end #endif // CHROME_BROWSER_COCOA_TAB_COTNENTS_CONTROLLER_H_ diff --git a/chrome/browser/cocoa/tab_contents_controller.mm b/chrome/browser/cocoa/tab_contents_controller.mm index bd1407a..c6d25a7 100644 --- a/chrome/browser/cocoa/tab_contents_controller.mm +++ b/chrome/browser/cocoa/tab_contents_controller.mm @@ -12,6 +12,10 @@ - (void)enabledStateChangedForCommand:(NSInteger)command enabled:(BOOL)enabled; @end +@interface TabContentsController(Private) +- (void)updateToolbarCommandStatus; +@end + // A C++ bridge class that handles listening for updates to commands and // passing them back to the controller. class TabContentsCommandObserver : public CommandUpdater::CommandObserver { @@ -75,12 +79,7 @@ class LocationBarBridge : public LocationBar { - (void)awakeFromNib { // Provide a starting point since we won't get notifications if the state // doesn't change between tabs. - [backButton_ setEnabled:commands_->IsCommandEnabled(IDC_BACK) ? YES : NO]; - [forwardButton_ - setEnabled:commands_->IsCommandEnabled(IDC_FORWARD) ? YES : NO]; - [reloadStopButton_ - setEnabled:commands_->IsCommandEnabled(IDC_RELOAD) ? YES : NO]; - [starButton_ setEnabled:commands_->IsCommandEnabled(IDC_STAR) ? YES : NO]; + [self updateToolbarCommandStatus]; [locationBar_ setStringValue:@"http://dev.chromium.org"]; } @@ -132,6 +131,23 @@ class LocationBarBridge : public LocationBar { } } +// Set the enabled state of the buttons on the toolbar to match the state in +// the controller. We can't only rely on notifications to do this because the +// command model only assumes a single toolbar and won't send notifications if +// the state doesn't change. +- (void)updateToolbarCommandStatus { + [backButton_ setEnabled:commands_->IsCommandEnabled(IDC_BACK) ? YES : NO]; + [forwardButton_ + setEnabled:commands_->IsCommandEnabled(IDC_FORWARD) ? YES : NO]; + [reloadStopButton_ + setEnabled:commands_->IsCommandEnabled(IDC_RELOAD) ? YES : NO]; + [starButton_ setEnabled:commands_->IsCommandEnabled(IDC_STAR) ? YES : NO]; +} + +- (void)willBecomeSelectedTab { + [self updateToolbarCommandStatus]; +} + @end //-------------------------------------------------------------------------- diff --git a/chrome/browser/cocoa/tab_strip_controller.mm b/chrome/browser/cocoa/tab_strip_controller.mm index 926e2b9d..e1b167b 100644 --- a/chrome/browser/cocoa/tab_strip_controller.mm +++ b/chrome/browser/cocoa/tab_strip_controller.mm @@ -242,6 +242,12 @@ class TabStripBridge : public TabStripModelObserver { [current setState:(i == index) ? NSOnState : NSOffState]; } + // Tell the new tab contents it is about to become the selected tab. Here it + // can do things like make sure the toolbar is up to date. + TabContentsController* newController = + [self controllerWithContents:newContents]; + [newController willBecomeSelectedTab]; + // Swap in the contents for the new tab [self swapInTabContents:newContents]; } diff --git a/chrome/common/temp_scaffolding_stubs.h b/chrome/common/temp_scaffolding_stubs.h index 82cfb6d..26a47c6 100644 --- a/chrome/common/temp_scaffolding_stubs.h +++ b/chrome/common/temp_scaffolding_stubs.h @@ -640,10 +640,7 @@ class TabContents : public NotificationObserver { virtual ~TabContents() { } NavigationController* controller() const { return controller_; } void set_controller(NavigationController* c) { controller_ = c; } - virtual WebContents* AsWebContents() const { - NOTIMPLEMENTED(); - return NULL; - } + virtual WebContents* AsWebContents() const { return NULL; } virtual SkBitmap GetFavIcon() const { NOTIMPLEMENTED(); return SkBitmap(); -- cgit v1.1