diff options
author | jonross <jonross@chromium.org> | 2014-10-27 16:52:18 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-10-27 23:52:36 +0000 |
commit | c22434d2969cfaad4738219e8fb137613100d3c4 (patch) | |
tree | e9e7df9f505fc04874201154535d944846764c1a /ui/views | |
parent | 26757de92c2d126c705d35056119418d1d03895a (diff) | |
download | chromium_src-c22434d2969cfaad4738219e8fb137613100d3c4.zip chromium_src-c22434d2969cfaad4738219e8fb137613100d3c4.tar.gz chromium_src-c22434d2969cfaad4738219e8fb137613100d3c4.tar.bz2 |
MenuButtons enter Hover state upon Tap Down
MenuButton will now respond to TAP_DOWN gestures, entering the Hover state. It will return to a normal state if the gesture is cancelled. Tap gestures that activate the menu will still cause it to enter a Pressed state.
This experiment is behind the flag switches::kEnableTouchFeedback
TEST=MenuButtonTest.TouchFeedbackDuringTap, MenuButtonTest.TouchFeedbackDuringTapCancel
BUG=398404
Review URL: https://codereview.chromium.org/674163003
Cr-Commit-Position: refs/heads/master@{#301488}
Diffstat (limited to 'ui/views')
-rw-r--r-- | ui/views/controls/button/menu_button.cc | 24 | ||||
-rw-r--r-- | ui/views/controls/button/menu_button_unittest.cc | 38 |
2 files changed, 56 insertions, 6 deletions
diff --git a/ui/views/controls/button/menu_button.cc b/ui/views/controls/button/menu_button.cc index f2b3852..aee3930 100644 --- a/ui/views/controls/button/menu_button.cc +++ b/ui/views/controls/button/menu_button.cc @@ -9,6 +9,7 @@ #include "ui/base/dragdrop/drag_drop_types.h" #include "ui/base/l10n/l10n_util.h" #include "ui/base/resource/resource_bundle.h" +#include "ui/base/ui_base_switches_util.h" #include "ui/events/event.h" #include "ui/events/event_constants.h" #include "ui/gfx/canvas.h" @@ -205,12 +206,23 @@ void MenuButton::OnMouseMoved(const ui::MouseEvent& event) { } void MenuButton::OnGestureEvent(ui::GestureEvent* event) { - if (state() != STATE_DISABLED && ShouldEnterPushedState(*event) && - !Activate()) { - // When |Activate()| returns |false|, it means that a menu is shown and - // has handled the gesture event. So, there is no need to further process - // the gesture event here. - return; + if (state() != STATE_DISABLED) { + if (ShouldEnterPushedState(*event) && !Activate()) { + // When |Activate()| returns |false|, it means that a menu is shown and + // has handled the gesture event. So, there is no need to further process + // the gesture event here. + return; + } + if (switches::IsTouchFeedbackEnabled()) { + if (event->type() == ui::ET_GESTURE_TAP_DOWN) { + event->SetHandled(); + SetState(Button::STATE_HOVERED); + } else if (state() == Button::STATE_HOVERED && + (event->type() == ui::ET_GESTURE_TAP_CANCEL || + event->type() == ui::ET_GESTURE_END)) { + SetState(Button::STATE_NORMAL); + } + } } LabelButton::OnGestureEvent(event); } diff --git a/ui/views/controls/button/menu_button_unittest.cc b/ui/views/controls/button/menu_button_unittest.cc index 21a72a6..a537c1f 100644 --- a/ui/views/controls/button/menu_button_unittest.cc +++ b/ui/views/controls/button/menu_button_unittest.cc @@ -4,9 +4,11 @@ #include "ui/views/controls/button/menu_button.h" +#include "base/command_line.h" #include "base/memory/scoped_ptr.h" #include "base/strings/utf_string_conversions.h" #include "ui/base/dragdrop/drag_drop_types.h" +#include "ui/base/ui_base_switches.h" #include "ui/events/test/event_generator.h" #include "ui/views/controls/button/menu_button_listener.h" #include "ui/views/drag_controller.h" @@ -27,6 +29,12 @@ class MenuButtonTest : public ViewsTestBase { MenuButtonTest() : widget_(nullptr), button_(nullptr) {} ~MenuButtonTest() override {} + void SetUp() override { + CommandLine::ForCurrentProcess()->AppendSwitch( + switches::kEnableTouchFeedback); + ViewsTestBase::SetUp(); + } + void TearDown() override { if (widget_ && !widget_->IsClosed()) widget_->Close(); @@ -390,4 +398,34 @@ TEST_F(MenuButtonTest, DraggableMenuButtonDoesNotActivateOnDrag) { } #endif +// Tests that the button enters a hovered state upon a tap down, before becoming +// pressed at activation. +TEST_F(MenuButtonTest, TouchFeedbackDuringTap) { + TestMenuButtonListener menu_button_listener; + CreateMenuButtonWithMenuButtonListener(&menu_button_listener); + ui::test::EventGenerator generator(GetContext(), widget()->GetNativeWindow()); + generator.set_current_location(gfx::Point(10, 10)); + generator.PressTouch(); + EXPECT_EQ(Button::STATE_HOVERED, button()->state()); + + generator.ReleaseTouch(); + EXPECT_EQ(Button::STATE_PRESSED, menu_button_listener.last_source_state()); +} + +// Tests that a move event that exits the button returns it to the normal state, +// and that the button did not activate the listener. +TEST_F(MenuButtonTest, TouchFeedbackDuringTapCancel) { + TestMenuButtonListener menu_button_listener; + CreateMenuButtonWithMenuButtonListener(&menu_button_listener); + ui::test::EventGenerator generator(GetContext(), widget()->GetNativeWindow()); + generator.set_current_location(gfx::Point(10, 10)); + generator.PressTouch(); + EXPECT_EQ(Button::STATE_HOVERED, button()->state()); + + generator.MoveTouch(gfx::Point(10, 30)); + generator.ReleaseTouch(); + EXPECT_EQ(Button::STATE_NORMAL, button()->state()); + EXPECT_EQ(nullptr, menu_button_listener.last_source()); +} + } // namespace views |