diff options
Diffstat (limited to 'chrome/browser')
-rw-r--r-- | chrome/browser/cocoa/tab_contents_controller.h | 5 | ||||
-rw-r--r-- | chrome/browser/cocoa/tab_contents_controller.mm | 28 | ||||
-rw-r--r-- | chrome/browser/cocoa/tab_strip_controller.mm | 6 |
3 files changed, 33 insertions, 6 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]; } |