diff options
author | gene@chromium.org <gene@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-08-06 20:19:57 +0000 |
---|---|---|
committer | gene@chromium.org <gene@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-08-06 20:19:57 +0000 |
commit | 58e290357865595f32e30560af71608e2b2384ae (patch) | |
tree | 583be02c0b92d83416150638d10423dc6412673f /ui | |
parent | 0f7bee56fbd084edd893558ceef8890f49a3bd69 (diff) | |
download | chromium_src-58e290357865595f32e30560af71608e2b2384ae.zip chromium_src-58e290357865595f32e30560af71608e2b2384ae.tar.gz chromium_src-58e290357865595f32e30560af71608e2b2384ae.tar.bz2 |
Added Reload drop-down menu for when in Dev mode for Windows.
(Already added for Linux in previous CL).
BUG=none
TEST=Run browser on Windows, switch to Dev mode, verify drop-down menu from Reload.
Review URL: https://chromiumcodereview.appspot.com/10779019
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@150138 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui')
-rw-r--r-- | ui/views/controls/button/button_dropdown.cc | 58 | ||||
-rw-r--r-- | ui/views/controls/button/button_dropdown.h | 23 |
2 files changed, 61 insertions, 20 deletions
diff --git a/ui/views/controls/button/button_dropdown.cc b/ui/views/controls/button/button_dropdown.cc index 3a0e866..5ee98b3 100644 --- a/ui/views/controls/button/button_dropdown.cc +++ b/ui/views/controls/button/button_dropdown.cc @@ -35,6 +35,7 @@ const int kMenuTimerDelay = 500; ButtonDropDown::ButtonDropDown(ButtonListener* listener, ui::MenuModel* model) : ImageButton(listener), model_(model), + menu_showing_(false), y_position_on_lbuttondown_(0), ALLOW_THIS_IN_INITIALIZER_LIST(show_menu_factory_(this)) { } @@ -42,6 +43,14 @@ ButtonDropDown::ButtonDropDown(ButtonListener* listener, ui::MenuModel* model) ButtonDropDown::~ButtonDropDown() { } +void ButtonDropDown::ClearPendingMenu() { + show_menu_factory_.InvalidateWeakPtrs(); +} + +bool ButtonDropDown::IsMenuShowing() const { + return menu_showing_; +} + //////////////////////////////////////////////////////////////////////////////// // // ButtonDropDown - Events @@ -49,7 +58,8 @@ ButtonDropDown::~ButtonDropDown() { //////////////////////////////////////////////////////////////////////////////// bool ButtonDropDown::OnMousePressed(const MouseEvent& event) { - if (enabled() && IsTriggerableEvent(event) && HitTest(event.location())) { + if (enabled() && ShouldShowMenu() && + IsTriggerableEvent(event) && HitTest(event.location())) { // Store the y pos of the mouse coordinates so we can use them later to // determine if the user dragged the mouse down (which should pop up the // drag down menu immediately, instead of waiting for the timer) @@ -59,8 +69,7 @@ bool ButtonDropDown::OnMousePressed(const MouseEvent& event) { MessageLoop::current()->PostDelayedTask( FROM_HERE, base::Bind(&ButtonDropDown::ShowDropDownMenu, - show_menu_factory_.GetWeakPtr(), - GetWidget()->GetNativeView()), + show_menu_factory_.GetWeakPtr()), base::TimeDelta::FromMilliseconds(kMenuTimerDelay)); } return ImageButton::OnMousePressed(event); @@ -75,7 +84,7 @@ bool ButtonDropDown::OnMouseDragged(const MouseEvent& event) { // it immediately. if (event.y() > y_position_on_lbuttondown_ + GetHorizontalDragThreshold()) { show_menu_factory_.InvalidateWeakPtrs(); - ShowDropDownMenu(GetWidget()->GetNativeView()); + ShowDropDownMenu(); } } @@ -93,7 +102,7 @@ void ButtonDropDown::OnMouseReleased(const MouseEvent& event) { if (enabled() && event.IsRightMouseButton() && HitTest(event.location())) { show_menu_factory_.InvalidateWeakPtrs(); - ShowDropDownMenu(GetWidget()->GetNativeView()); + ShowDropDownMenu(); } } @@ -112,7 +121,7 @@ void ButtonDropDown::OnMouseExited(const MouseEvent& event) { void ButtonDropDown::ShowContextMenu(const gfx::Point& p, bool is_mouse_gesture) { show_menu_factory_.InvalidateWeakPtrs(); - ShowDropDownMenu(GetWidget()->GetNativeView()); + ShowDropDownMenu(); SetState(BS_HOT); } @@ -132,7 +141,14 @@ bool ButtonDropDown::ShouldEnterPushedState(const Event& event) { ui::EF_RIGHT_MOUSE_BUTTON) & event.flags()) != 0); } -void ButtonDropDown::ShowDropDownMenu(gfx::NativeView window) { +bool ButtonDropDown::ShouldShowMenu() { + return true; +} + +void ButtonDropDown::ShowDropDownMenu() { + if (!ShouldShowMenu()) + return; + gfx::Rect lb = GetLocalBounds(); // Both the menu position and the menu anchor type change if the UI layout @@ -156,27 +172,35 @@ void ButtonDropDown::ShowDropDownMenu(gfx::NativeView window) { // Make the button look depressed while the menu is open. SetState(BS_PUSHED); + menu_showing_ = true; + // Create and run menu. Display an empty menu if model is NULL. if (model_) { MenuModelAdapter menu_delegate(model_); menu_delegate.set_triggerable_event_flags(triggerable_event_flags()); - MenuRunner runner(menu_delegate.CreateMenu()); - if (runner.RunMenuAt(GetWidget(), NULL, - gfx::Rect(menu_position, gfx::Size(0, 0)), - MenuItemView::TOPLEFT, - MenuRunner::HAS_MNEMONICS) == MenuRunner::MENU_DELETED) + menu_runner_.reset(new MenuRunner(menu_delegate.CreateMenu())); + MenuRunner::RunResult result = + menu_runner_->RunMenuAt(GetWidget(), NULL, + gfx::Rect(menu_position, gfx::Size(0, 0)), + MenuItemView::TOPLEFT, + MenuRunner::HAS_MNEMONICS); + if (result == MenuRunner::MENU_DELETED) return; } else { MenuDelegate menu_delegate; MenuItemView* menu = new MenuItemView(&menu_delegate); - MenuRunner runner(menu); - if (runner.RunMenuAt(GetWidget(), NULL, - gfx::Rect(menu_position, gfx::Size(0, 0)), - views::MenuItemView::TOPLEFT, - MenuRunner::HAS_MNEMONICS) == MenuRunner::MENU_DELETED) + menu_runner_.reset(new MenuRunner(menu)); + MenuRunner::RunResult result = + menu_runner_->RunMenuAt(GetWidget(), NULL, + gfx::Rect(menu_position, gfx::Size(0, 0)), + MenuItemView::TOPLEFT, + MenuRunner::HAS_MNEMONICS); + if (result == MenuRunner::MENU_DELETED) return; } + menu_showing_ = false; + // Need to explicitly clear mouse handler so that events get sent // properly after the menu finishes running. If we don't do this, then // the first click to other parts of the UI is eaten. diff --git a/ui/views/controls/button/button_dropdown.h b/ui/views/controls/button/button_dropdown.h index b117a69..d58e640 100644 --- a/ui/views/controls/button/button_dropdown.h +++ b/ui/views/controls/button/button_dropdown.h @@ -14,6 +14,8 @@ class MenuModel; namespace views { +class MenuRunner; + //////////////////////////////////////////////////////////////////////////////// // // ButtonDropDown @@ -30,6 +32,12 @@ class VIEWS_EXPORT ButtonDropDown : public ImageButton { ButtonDropDown(ButtonListener* listener, ui::MenuModel* model); virtual ~ButtonDropDown(); + // If menu is currently pending for long press - stop it. + void ClearPendingMenu(); + + // Indicates if menu is currently showing. + bool IsMenuShowing() const; + // Overridden from views::View virtual bool OnMousePressed(const MouseEvent& event) OVERRIDE; virtual bool OnMouseDragged(const MouseEvent& event) OVERRIDE; @@ -51,16 +59,25 @@ class VIEWS_EXPORT ButtonDropDown : public ImageButton { // to the PUSHED state. virtual bool ShouldEnterPushedState(const Event& event) OVERRIDE; - private: - // Internal function to show the dropdown menu - void ShowDropDownMenu(gfx::NativeView window); + // Returns if menu should be shown. Override this to change default behavior. + virtual bool ShouldShowMenu(); + // Function to show the dropdown menu. + virtual void ShowDropDownMenu(); + + private: // The model that populates the attached menu. ui::MenuModel* model_; + // Indicates if menu is currently showing. + bool menu_showing_; + // Y position of mouse when left mouse button is pressed int y_position_on_lbuttondown_; + // Menu runner to display drop down menu. + scoped_ptr<MenuRunner> menu_runner_; + // A factory for tasks that show the dropdown context menu for the button. base::WeakPtrFactory<ButtonDropDown> show_menu_factory_; |