summaryrefslogtreecommitdiffstats
path: root/views/controls/button
diff options
context:
space:
mode:
authorsky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-11 22:27:06 +0000
committersky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-11 22:27:06 +0000
commit55b386100e56d244f8cf35d4485d28ab601cbfb2 (patch)
treeee312422a8f9721d50bec8aa761fba216d97038b /views/controls/button
parent6fd279703048008896e8036090d6308605b46202 (diff)
downloadchromium_src-55b386100e56d244f8cf35d4485d28ab601cbfb2.zip
chromium_src-55b386100e56d244f8cf35d4485d28ab601cbfb2.tar.gz
chromium_src-55b386100e56d244f8cf35d4485d28ab601cbfb2.tar.bz2
Lands http://codereview.chromium.org/159838 for Pierre-Antoine. From him:
Right clicking the back and forward buttons is buggy. A single right click opens the drop down menu, however the button does not enter the PUSHED state. If you double right click then click on the tab content area, the button stays in a PUSHED state until you mouseover it. The fix should replicate the intuitive behavior. On a single right click, the button enters the PUSHED state and the drop down appears immediately. As soon as the user clicks on another View, the drop down closes and the button returns to the NORMAL state. Double right click behaves similarly. BUG=9717 TEST=none Review URL: http://codereview.chromium.org/165318 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@23101 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views/controls/button')
-rw-r--r--views/controls/button/button_dropdown.cc30
-rw-r--r--views/controls/button/button_dropdown.h9
-rw-r--r--views/controls/button/custom_button.cc8
-rw-r--r--views/controls/button/custom_button.h5
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_;