diff options
Diffstat (limited to 'chrome/browser/ui')
-rw-r--r-- | chrome/browser/ui/views/toolbar_view.cc | 4 | ||||
-rw-r--r-- | chrome/browser/ui/views/toolbar_view.h | 3 | ||||
-rw-r--r-- | chrome/browser/ui/views/wrench_menu.cc | 18 | ||||
-rw-r--r-- | chrome/browser/ui/views/wrench_menu.h | 12 |
4 files changed, 31 insertions, 6 deletions
diff --git a/chrome/browser/ui/views/toolbar_view.cc b/chrome/browser/ui/views/toolbar_view.cc index a22bccf..fc45d50 100644 --- a/chrome/browser/ui/views/toolbar_view.cc +++ b/chrome/browser/ui/views/toolbar_view.cc @@ -133,7 +133,6 @@ void ToolbarView::Init() { browser_, BackForwardMenuModel::BACKWARD_MENU)); forward_menu_model_.reset(new BackForwardMenuModel( browser_, BackForwardMenuModel::FORWARD_MENU)); - wrench_menu_model_.reset(new WrenchMenuModel(this, browser_)); back_ = new views::ButtonDropDown(this, back_menu_model_.get()); back_->set_triggerable_event_flags(ui::EF_LEFT_BUTTON_DOWN | ui::EF_MIDDLE_BUTTON_DOWN); @@ -337,7 +336,8 @@ void ToolbarView::RunMenu(views::View* source, const gfx::Point& /* pt */) { DCHECK_EQ(VIEW_ID_APP_MENU, source->id()); wrench_menu_.reset(new WrenchMenu(browser_)); - wrench_menu_->Init(wrench_menu_model_.get()); + WrenchMenuModel model(this, browser_); + wrench_menu_->Init(&model); FOR_EACH_OBSERVER(views::MenuListener, menu_listeners_, OnMenuOpened()); diff --git a/chrome/browser/ui/views/toolbar_view.h b/chrome/browser/ui/views/toolbar_view.h index 2fa54b5..59dfbdc 100644 --- a/chrome/browser/ui/views/toolbar_view.h +++ b/chrome/browser/ui/views/toolbar_view.h @@ -199,9 +199,6 @@ class ToolbarView : public AccessiblePaneView, // The display mode used when laying out the toolbar. DisplayMode display_mode_; - // The contents of the wrench menu. - scoped_ptr<ui::SimpleMenuModel> wrench_menu_model_; - // Wrench menu. scoped_ptr<WrenchMenu> wrench_menu_; diff --git a/chrome/browser/ui/views/wrench_menu.cc b/chrome/browser/ui/views/wrench_menu.cc index 5d546d96..55d8986 100644 --- a/chrome/browser/ui/views/wrench_menu.cc +++ b/chrome/browser/ui/views/wrench_menu.cc @@ -16,6 +16,7 @@ #include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser_window.h" #include "chrome/browser/ui/views/bookmarks/bookmark_menu_delegate.h" +#include "chrome/common/chrome_notification_types.h" #include "content/browser/tab_contents/tab_contents.h" #include "content/browser/user_metrics.h" #include "content/common/content_notification_types.h" @@ -569,6 +570,8 @@ WrenchMenu::WrenchMenu(Browser* browser) selected_index_(0), bookmark_menu_(NULL), first_bookmark_command_id_(0) { + registrar_.Add(this, chrome::NOTIFICATION_GLOBAL_ERRORS_CHANGED, + Source<Profile>(browser_->profile())); } WrenchMenu::~WrenchMenu() { @@ -770,6 +773,21 @@ void WrenchMenu::BookmarkModelChanged() { root_->Cancel(); } + +void WrenchMenu::Observe(int type, + const NotificationSource& source, + const NotificationDetails& details) { + switch (type) { + case chrome::NOTIFICATION_GLOBAL_ERRORS_CHANGED: + // A change in the global errors list can add or remove items from the + // menu. Close the menu to avoid have a stale menu on-screen. + root_->Cancel(); + break; + default: + NOTREACHED(); + } +} + void WrenchMenu::PopulateMenu(MenuItemView* parent, MenuModel* model, int* next_id) { diff --git a/chrome/browser/ui/views/wrench_menu.h b/chrome/browser/ui/views/wrench_menu.h index 231f379..469c67f 100644 --- a/chrome/browser/ui/views/wrench_menu.h +++ b/chrome/browser/ui/views/wrench_menu.h @@ -11,6 +11,8 @@ #include "base/memory/scoped_ptr.h" #include "chrome/browser/bookmarks/base_bookmark_model_observer.h" +#include "content/common/notification_observer.h" +#include "content/common/notification_registrar.h" #include "ui/base/models/menu_model.h" #include "views/controls/menu/menu_delegate.h" @@ -26,7 +28,8 @@ class View; // WrenchMenu adapts the WrenchMenuModel to view's menu related classes. class WrenchMenu : public views::MenuDelegate, - public BaseBookmarkModelObserver { + public BaseBookmarkModelObserver, + public NotificationObserver { public: explicit WrenchMenu(Browser* browser); virtual ~WrenchMenu(); @@ -71,6 +74,11 @@ class WrenchMenu : public views::MenuDelegate, // BaseBookmarkModelObserver overrides: virtual void BookmarkModelChanged() OVERRIDE; + // NotificationObserver overrides: + virtual void Observe(int type, + const NotificationSource& source, + const NotificationDetails& details) OVERRIDE; + private: class CutCopyPasteView; class ZoomView; @@ -134,6 +142,8 @@ class WrenchMenu : public views::MenuDelegate, // ID to use for the items representing bookmarks in the bookmark menu. int first_bookmark_command_id_; + NotificationRegistrar registrar_; + DISALLOW_COPY_AND_ASSIGN(WrenchMenu); }; |