summaryrefslogtreecommitdiffstats
path: root/chrome/browser/cocoa
diff options
context:
space:
mode:
authorpinkerton@chromium.org <pinkerton@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-02-06 21:12:59 +0000
committerpinkerton@chromium.org <pinkerton@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-02-06 21:12:59 +0000
commit983cc0c99803c960174992c0f4217e077565094d (patch)
treed9fd87db12bfaec401e002732e0ca4b797616876 /chrome/browser/cocoa
parent58adf848df7ad7a724be0526e25196ba6adee0e9 (diff)
downloadchromium_src-983cc0c99803c960174992c0f4217e077565094d.zip
chromium_src-983cc0c99803c960174992c0f4217e077565094d.tar.gz
chromium_src-983cc0c99803c960174992c0f4217e077565094d.tar.bz2
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
Diffstat (limited to 'chrome/browser/cocoa')
-rw-r--r--chrome/browser/cocoa/tab_contents_controller.h5
-rw-r--r--chrome/browser/cocoa/tab_contents_controller.mm28
-rw-r--r--chrome/browser/cocoa/tab_strip_controller.mm6
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];
}