From 1b78b7e974e754518d60819b69935832cfedf4f5 Mon Sep 17 00:00:00 2001 From: "sky@chromium.org" Date: Thu, 19 May 2011 20:18:33 +0000 Subject: Adds two methods to the MenuDelegate I'm going to need for bookmark menus. Tweaks some wrapping in bookmark_utils.cc and adds an assertion to bookmark_bar_view_test. BUG=81263 TEST=none R=ben@chromium.org Review URL: http://codereview.chromium.org/7029046 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@85960 0039d316-1c4b-4281-b951-d872f2087c98 --- views/controls/menu/menu_controller.cc | 6 ++++-- views/controls/menu/menu_delegate.cc | 8 ++++++-- views/controls/menu/menu_delegate.h | 7 +++++-- 3 files changed, 15 insertions(+), 6 deletions(-) (limited to 'views') diff --git a/views/controls/menu/menu_controller.cc b/views/controls/menu/menu_controller.cc index df88db14..a59caac 100644 --- a/views/controls/menu/menu_controller.cc +++ b/views/controls/menu/menu_controller.cc @@ -544,7 +544,7 @@ void MenuController::OnMouseReleased(SubmenuView* source, SendMouseReleaseToActiveView(source, event); return; } - if (part.menu->GetDelegate()->IsTriggerableEvent(event)) { + if (part.menu->GetDelegate()->IsTriggerableEvent(part.menu, event)) { Accept(part.menu, event.flags()); return; } @@ -1325,6 +1325,8 @@ void MenuController::OpenMenu(MenuItemView* item) { } void MenuController::OpenMenuImpl(MenuItemView* item, bool show) { + if (show) + item->GetDelegate()->WillShowMenu(item); bool prefer_leading = state_.open_leading.empty() ? true : state_.open_leading.back(); bool resulting_direction; @@ -1421,7 +1423,7 @@ gfx::Rect MenuController::CalculateMenuBounds(MenuItemView* item, // Don't let the menu go to wide. pref.set_width(std::min(pref.width(), - item->GetDelegate()->GetMaxWidthForMenu())); + item->GetDelegate()->GetMaxWidthForMenu(item))); if (!state_.monitor_bounds.IsEmpty()) pref.set_width(std::min(pref.width(), state_.monitor_bounds.width())); diff --git a/views/controls/menu/menu_delegate.cc b/views/controls/menu/menu_delegate.cc index 8bd21bf..d4d084d 100644 --- a/views/controls/menu/menu_delegate.cc +++ b/views/controls/menu/menu_delegate.cc @@ -55,7 +55,8 @@ void MenuDelegate::ExecuteCommand(int id, int mouse_event_flags) { ExecuteCommand(id); } -bool MenuDelegate::IsTriggerableEvent(const MouseEvent& e) { +bool MenuDelegate::IsTriggerableEvent(MenuItemView* source, + const MouseEvent& e) { return e.IsLeftMouseButton() || e.IsRightMouseButton(); } @@ -109,10 +110,13 @@ MenuItemView* MenuDelegate::GetSiblingMenu(MenuItemView* menu, return NULL; } -int MenuDelegate::GetMaxWidthForMenu() { +int MenuDelegate::GetMaxWidthForMenu(MenuItemView* menu) { // NOTE: this needs to be large enough to accommodate the wrench menu with // big fonts. return 800; } +void MenuDelegate::WillShowMenu(MenuItemView* menu) { +} + } // namespace views diff --git a/views/controls/menu/menu_delegate.h b/views/controls/menu/menu_delegate.h index 578f679..991d3c5 100644 --- a/views/controls/menu/menu_delegate.h +++ b/views/controls/menu/menu_delegate.h @@ -105,7 +105,7 @@ class MenuDelegate { // Returns true if the specified mouse event is one the user can use // to trigger, or accept, the mouse. Defaults to left or right mouse buttons. - virtual bool IsTriggerableEvent(const MouseEvent& e); + virtual bool IsTriggerableEvent(MenuItemView* view, const MouseEvent& e); // Invoked to determine if drops can be accepted for a submenu. This is // ONLY invoked for menus that have submenus and indicates whether or not @@ -184,7 +184,10 @@ class MenuDelegate { MenuButton** button); // Returns the max width menus can grow to be. - virtual int GetMaxWidthForMenu(); + virtual int GetMaxWidthForMenu(MenuItemView* menu); + + // Invoked prior to a menu being shown. + virtual void WillShowMenu(MenuItemView* menu); }; } // namespace views -- cgit v1.1