diff options
author | flackr@chromium.org <flackr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-06-05 17:21:36 +0000 |
---|---|---|
committer | flackr@chromium.org <flackr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-06-05 17:21:36 +0000 |
commit | c418d6e9a5a77e23423aad361de4fb94466034cc (patch) | |
tree | 749a2b7e999272cf78db12e723c26399d285f01b /ui/views | |
parent | dd1249f1530308aa5bb6d81ffab6ffdbbc03f8b3 (diff) | |
download | chromium_src-c418d6e9a5a77e23423aad361de4fb94466034cc.zip chromium_src-c418d6e9a5a77e23423aad361de4fb94466034cc.tar.gz chromium_src-c418d6e9a5a77e23423aad361de4fb94466034cc.tar.bz2 |
Add support for touch gestures on views::CustomButtom.
BUG=131184
TEST=Run chrome with --aura-disable-mouse-events-from-touch --enable-touch-events. When you tap down on a button it shows a pressed state and if you release will click the button. Moving your finger off or holding will release the button without clicking it.
Review URL: https://chromiumcodereview.appspot.com/10502018
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@140545 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/views')
-rw-r--r-- | ui/views/controls/button/custom_button.cc | 19 | ||||
-rw-r--r-- | ui/views/controls/button/custom_button.h | 2 |
2 files changed, 21 insertions, 0 deletions
diff --git a/ui/views/controls/button/custom_button.cc b/ui/views/controls/button/custom_button.cc index 8cf2fea..319aaae 100644 --- a/ui/views/controls/button/custom_button.cc +++ b/ui/views/controls/button/custom_button.cc @@ -193,6 +193,25 @@ bool CustomButton::OnKeyReleased(const KeyEvent& event) { return true; } +ui::GestureStatus CustomButton::OnGestureEvent(const GestureEvent& event) { + if (state_ == BS_DISABLED) + return ui::GESTURE_STATUS_UNKNOWN; + + if (event.type() == ui::ET_GESTURE_TAP) { + SetState(BS_NORMAL); + NotifyClick(event); + return ui::GESTURE_STATUS_CONSUMED; + } else if (event.type() == ui::ET_GESTURE_TAP_DOWN) { + SetState(BS_PUSHED); + if (request_focus_on_press_) + RequestFocus(); + return ui::GESTURE_STATUS_CONSUMED; + } else { + SetState(BS_NORMAL); + } + return ui::GESTURE_STATUS_UNKNOWN; +} + bool CustomButton::AcceleratorPressed(const ui::Accelerator& accelerator) { SetState(BS_NORMAL); KeyEvent key_event(ui::ET_KEY_RELEASED, accelerator.key_code(), diff --git a/ui/views/controls/button/custom_button.h b/ui/views/controls/button/custom_button.h index 276aff5..46a99ea 100644 --- a/ui/views/controls/button/custom_button.h +++ b/ui/views/controls/button/custom_button.h @@ -7,6 +7,7 @@ #pragma once #include "ui/base/animation/animation_delegate.h" +#include "ui/base/events.h" #include "ui/views/controls/button/button.h" namespace ui { @@ -87,6 +88,7 @@ class VIEWS_EXPORT CustomButton : public Button, virtual void OnMouseMoved(const MouseEvent& event) OVERRIDE; virtual bool OnKeyPressed(const KeyEvent& event) OVERRIDE; virtual bool OnKeyReleased(const KeyEvent& event) OVERRIDE; + virtual ui::GestureStatus OnGestureEvent(const GestureEvent& event) OVERRIDE; virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) OVERRIDE; virtual void ShowContextMenu(const gfx::Point& p, bool is_mouse_gesture) OVERRIDE; |