diff options
-rw-r--r-- | views/controls/button/button_dropdown.cc | 30 | ||||
-rw-r--r-- | views/controls/button/button_dropdown.h | 9 | ||||
-rw-r--r-- | views/controls/button/custom_button.cc | 8 | ||||
-rw-r--r-- | views/controls/button/custom_button.h | 5 |
4 files changed, 41 insertions, 11 deletions
diff --git a/views/controls/button/button_dropdown.cc b/views/controls/button/button_dropdown.cc index e59b01c..db40cee 100644 --- a/views/controls/button/button_dropdown.cc +++ b/views/controls/button/button_dropdown.cc @@ -52,12 +52,14 @@ bool ButtonDropDown::OnMousePressed(const MouseEvent& e) { GetWidget()->GetNativeView()), kMenuTimerDelay); } - return ImageButton::OnMousePressed(e); } void ButtonDropDown::OnMouseReleased(const MouseEvent& e, bool canceled) { - ImageButton::OnMouseReleased(e, canceled); + if (e.IsLeftMouseButton() || (e.IsRightMouseButton() && + !HitTest(e.location()))) { + ImageButton::OnMouseReleased(e, canceled); + } if (canceled) return; @@ -67,13 +69,10 @@ void ButtonDropDown::OnMouseReleased(const MouseEvent& e, bool canceled) { if (IsEnabled() && e.IsRightMouseButton() && HitTest(e.location())) { show_menu_factory_.RevokeAll(); - // Make the button look depressed while the menu is open. - // NOTE: SetState() schedules a paint, but it won't occur until after the - // context menu message loop has terminated, so we PaintNow() to - // update the appearance synchronously. - SetState(BS_PUSHED); - PaintNow(); ShowDropDownMenu(GetWidget()->GetNativeView()); + // Set the state back to normal after the drop down menu is closed. + if (state_ != BS_DISABLED) + SetState(BS_NORMAL); } } @@ -93,6 +92,14 @@ bool ButtonDropDown::OnMouseDragged(const MouseEvent& e) { return result; } +void ButtonDropDown::OnMouseExited(const MouseEvent& e) { + // Starting a drag results in a MouseExited, we need to ignore it. + // A right click release triggers an exit event. We want to + // remain in a PUSHED state until the drop down menu closes. + if (state_ != BS_DISABLED && !InDrag() && state_ != BS_PUSHED) + SetState(BS_NORMAL); +} + //////////////////////////////////////////////////////////////////////////////// // // ButtonDropDown - Menu functions @@ -111,6 +118,13 @@ void ButtonDropDown::ShowContextMenu(int x, int y, bool is_mouse_gesture) { SetState(BS_HOT); } +bool ButtonDropDown::ShouldEnterPushedState(const MouseEvent& e) { + // Enter PUSHED state on press with Left or Right mouse button. Remain + // in this state while the context menu is open. + return ((MouseEvent::EF_LEFT_BUTTON_DOWN | + MouseEvent::EF_RIGHT_BUTTON_DOWN) & e.GetFlags()) != 0; +} + void ButtonDropDown::ShowDropDownMenu(gfx::NativeView window) { if (model_) { gfx::Rect lb = GetLocalBounds(true); diff --git a/views/controls/button/button_dropdown.h b/views/controls/button/button_dropdown.h index e0ba3e3..bc1b595 100644 --- a/views/controls/button/button_dropdown.h +++ b/views/controls/button/button_dropdown.h @@ -30,10 +30,11 @@ class ButtonDropDown : public ImageButton { virtual bool GetAccessibleState(AccessibilityTypes::State* state); private: - // Overridden from Button + // Overridden from CustomButton virtual bool OnMousePressed(const MouseEvent& e); virtual void OnMouseReleased(const MouseEvent& e, bool canceled); virtual bool OnMouseDragged(const MouseEvent& e); + virtual void OnMouseExited(const MouseEvent& e); // Overridden from View. Used to display the right-click menu, as triggered // by the keyboard, for instance. Using the member function ShowDropDownMenu @@ -42,6 +43,12 @@ class ButtonDropDown : public ImageButton { int y, bool is_mouse_gesture); + // Overridden from CustomButton. Returns true if the button should become + // pressed when a user holds the mouse down over the button. For this + // implementation, both left and right mouse buttons can trigger a change + // to the PUSHED state. + virtual bool ShouldEnterPushedState(const MouseEvent& e); + // Internal function to show the dropdown menu void ShowDropDownMenu(gfx::NativeView window); diff --git a/views/controls/button/custom_button.cc b/views/controls/button/custom_button.cc index 2b5f43d..45482b8 100644 --- a/views/controls/button/custom_button.cc +++ b/views/controls/button/custom_button.cc @@ -97,7 +97,7 @@ bool CustomButton::AcceleratorPressed(const Accelerator& accelerator) { bool CustomButton::OnMousePressed(const MouseEvent& e) { if (state_ != BS_DISABLED) { - if (IsTriggerableEvent(e) && HitTest(e.location())) + if (ShouldEnterPushedState(e) && HitTest(e.location())) SetState(BS_PUSHED); RequestFocus(); } @@ -108,7 +108,7 @@ bool CustomButton::OnMouseDragged(const MouseEvent& e) { if (state_ != BS_DISABLED) { if (!HitTest(e.location())) SetState(BS_NORMAL); - else if (IsTriggerableEvent(e)) + else if (ShouldEnterPushedState(e)) SetState(BS_PUSHED); else SetState(BS_HOT); @@ -214,6 +214,10 @@ void CustomButton::AnimationProgressed(const Animation* animation) { SchedulePaint(); } +bool CustomButton::ShouldEnterPushedState(const MouseEvent& e) { + return IsTriggerableEvent(e); +} + //////////////////////////////////////////////////////////////////////////////// // CustomButton, private: diff --git a/views/controls/button/custom_button.h b/views/controls/button/custom_button.h index 745c19e..75cb29b 100644 --- a/views/controls/button/custom_button.h +++ b/views/controls/button/custom_button.h @@ -76,6 +76,11 @@ class CustomButton : public Button, // Overridden from AnimationDelegate: virtual void AnimationProgressed(const Animation* animation); + // Returns true if the button should become pressed when the user + // holds the mouse down over the button. For this implementation, + // we simply return IsTriggerableEvent(e). + virtual bool ShouldEnterPushedState(const MouseEvent& e); + // The button state (defined in implementation) ButtonState state_; |