diff options
author | jrg@chromium.org <jrg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-23 01:18:13 +0000 |
---|---|---|
committer | jrg@chromium.org <jrg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-23 01:18:13 +0000 |
commit | f6314009810a5ee6c606328c41c8ff4e1dacd05e (patch) | |
tree | 3c530eb3c209f23e369f0a8f35849a94e502cbc8 /chrome/browser/cocoa/browser_window_cocoa.mm | |
parent | ec85e6880806202737a4d32c94817f0ecad4ca8b (diff) | |
download | chromium_src-f6314009810a5ee6c606328c41c8ff4e1dacd05e.zip chromium_src-f6314009810a5ee6c606328c41c8ff4e1dacd05e.tar.gz chromium_src-f6314009810a5ee6c606328c41c8ff4e1dacd05e.tar.bz2 |
Fix problem with bookmark bar introduced by window sharing; pref
change needs to change all open windows with the same preferences,
not just the current one).
Improve unit testing.
Limit bookmark menu size width (1st pass).
Cleanup/delete of code which no longer does much.
Review URL: http://codereview.chromium.org/79068
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@14282 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/cocoa/browser_window_cocoa.mm')
-rw-r--r-- | chrome/browser/cocoa/browser_window_cocoa.mm | 43 |
1 files changed, 34 insertions, 9 deletions
diff --git a/chrome/browser/cocoa/browser_window_cocoa.mm b/chrome/browser/cocoa/browser_window_cocoa.mm index 1ad2e9b..de0f738 100644 --- a/chrome/browser/cocoa/browser_window_cocoa.mm +++ b/chrome/browser/cocoa/browser_window_cocoa.mm @@ -4,17 +4,30 @@ #include "base/gfx/rect.h" #include "base/logging.h" +#include "chrome/browser/bookmarks/bookmark_utils.h" #include "chrome/browser/cocoa/browser_window_cocoa.h" #include "chrome/browser/cocoa/browser_window_controller.h" #include "chrome/browser/browser.h" +#include "chrome/common/notification_service.h" +#include "chrome/common/pref_names.h" +#include "chrome/common/pref_service.h" +#include "chrome/browser/profile.h" BrowserWindowCocoa::BrowserWindowCocoa(Browser* browser, BrowserWindowController* controller, NSWindow* window) : window_(window), browser_(browser), controller_(controller) { + // This pref applies to all windows, so all must watch for it. + NotificationService* ns = NotificationService::current(); + ns->AddObserver(this, NotificationType::BOOKMARK_BAR_VISIBILITY_PREF_CHANGED, + NotificationService::AllSources()); } BrowserWindowCocoa::~BrowserWindowCocoa() { + NotificationService* ns = NotificationService::current(); + ns->RemoveObserver(this, + NotificationType::BOOKMARK_BAR_VISIBILITY_PREF_CHANGED, + NotificationService::AllSources()); } void BrowserWindowCocoa::Show() { @@ -133,18 +146,15 @@ void BrowserWindowCocoa::FocusToolbar() { } bool BrowserWindowCocoa::IsBookmarkBarVisible() const { - // Conversion from ObjC BOOL to C++ bool. - return [controller_ isBookmarkBarVisible] ? true : false; + return browser_->profile()->GetPrefs()->GetBoolean(prefs::kShowBookmarkBar); } -// This is a little awkward. Internal to Chrome, V and C (in the MVC -// sense) tend to smear together. Thus, we have a call chain of -// C(browser_window)--> -// V(me;right here)--> -// C(BrowserWindowController)--> -// C(TabStripController) --> ... +// This is called from Browser, which in turn is called directly from +// a menu option. All we do here is set a preference. The act of +// setting the preference sends notifications to all windows who then +// know what to do. void BrowserWindowCocoa::ToggleBookmarkBar() { - [controller_ toggleBookmarkBar]; + bookmark_utils::ToggleWhenVisible(browser_->profile()); } void BrowserWindowCocoa::AddFindBar( @@ -203,6 +213,21 @@ void BrowserWindowCocoa::ShowHTMLDialog(HtmlDialogUIDelegate* delegate, NOTIMPLEMENTED(); } +void BrowserWindowCocoa::Observe(NotificationType type, + const NotificationSource& source, + const NotificationDetails& details) { + switch (type.value) { + // Only the key window gets a direct toggle from the menu. + // Other windows hear about it from the notification. + case NotificationType::BOOKMARK_BAR_VISIBILITY_PREF_CHANGED: + [controller_ toggleBookmarkBar]; + break; + default: + NOTREACHED(); // we don't ask for anything else! + break; + } +} + void BrowserWindowCocoa::DestroyBrowser() { [controller_ destroyBrowser]; |