summaryrefslogtreecommitdiffstats
path: root/ui/aura
diff options
context:
space:
mode:
authorsadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-06-12 19:56:53 +0000
committersadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-06-12 19:56:53 +0000
commitf1e904954feb4595c5c9ba37827336014277f83a (patch)
tree0ed0de3afde766888775b0a3a025656ea8aee663 /ui/aura
parent31e0749c08bce6b03835890c2462f0165b40d192 (diff)
downloadchromium_src-f1e904954feb4595c5c9ba37827336014277f83a.zip
chromium_src-f1e904954feb4595c5c9ba37827336014277f83a.tar.gz
chromium_src-f1e904954feb4595c5c9ba37827336014277f83a.tar.bz2
aura: Allow held touch-events to contribute to gesture events.
When a touch-move event is 'held', i.e. it is not dispatched, the event does produce any gesture events. However, once this 'held' event is dispatched (either because a touch-release event was encountered, or because ReleasePointerMoves() was called on the dispatcher), it should be used to generate the appropriate gesture events. BUG=none R=sky@chromium.org Review URL: https://codereview.chromium.org/332703003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@276781 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/aura')
-rw-r--r--ui/aura/window_event_dispatcher.cc6
-rw-r--r--ui/aura/window_event_dispatcher_unittest.cc66
2 files changed, 58 insertions, 14 deletions
diff --git a/ui/aura/window_event_dispatcher.cc b/ui/aura/window_event_dispatcher.cc
index 3dc7432..0f47150 100644
--- a/ui/aura/window_event_dispatcher.cc
+++ b/ui/aura/window_event_dispatcher.cc
@@ -470,8 +470,10 @@ ui::EventDispatchDetails WindowEventDispatcher::PostDispatchEvent(
#endif
if (event.IsTouchEvent() && !details.target_destroyed) {
- // Do not let 'held' touch events contribute to any gestures.
- if (!held_move_event_ || !held_move_event_->IsTouchEvent()) {
+ // Do not let 'held' touch events contribute to any gestures unless it is
+ // being dispatched.
+ if (dispatching_held_event_ || !held_move_event_ ||
+ !held_move_event_->IsTouchEvent()) {
ui::TouchEvent orig_event(static_cast<const ui::TouchEvent&>(event),
static_cast<Window*>(event.target()), window());
// Get the list of GestureEvents from GestureRecognizer.
diff --git a/ui/aura/window_event_dispatcher_unittest.cc b/ui/aura/window_event_dispatcher_unittest.cc
index 86b6046..716bcc9 100644
--- a/ui/aura/window_event_dispatcher_unittest.cc
+++ b/ui/aura/window_event_dispatcher_unittest.cc
@@ -588,7 +588,7 @@ std::string EventTypeToString(ui::EventType type) {
default:
// We should explicitly require each event type.
- NOTREACHED();
+ NOTREACHED() << "Received unexpected event: " << type;
break;
}
return "";
@@ -744,12 +744,15 @@ TEST_F(WindowEventDispatcherTest, TouchMovesHeld) {
// Check that we don't immediately dispatch the TOUCH_MOVED event.
ui::TouchEvent touch_moved_event(
ui::ET_TOUCH_MOVED, touch_location, 0, ui::EventTimeForNow());
+ ui::TouchEvent touch_moved_event2 = touch_moved_event;
+ ui::TouchEvent touch_moved_event3 = touch_moved_event;
+
DispatchEventUsingWindowDispatcher(&touch_moved_event);
EXPECT_TRUE(recorder.events().empty());
// Check that on ReleasePointerMoves, held events are not dispatched
// immediately, but posted instead.
- DispatchEventUsingWindowDispatcher(&touch_moved_event);
+ DispatchEventUsingWindowDispatcher(&touch_moved_event2);
host()->dispatcher()->ReleasePointerMoves();
EXPECT_TRUE(recorder.events().empty());
@@ -763,7 +766,7 @@ TEST_F(WindowEventDispatcherTest, TouchMovesHeld) {
ui::ET_TOUCH_RELEASED, touch_location, 0, ui::EventTimeForNow());
recorder.Reset();
host()->dispatcher()->HoldPointerMoves();
- DispatchEventUsingWindowDispatcher(&touch_moved_event);
+ DispatchEventUsingWindowDispatcher(&touch_moved_event3);
DispatchEventUsingWindowDispatcher(&touch_released_event);
EXPECT_EQ("TOUCH_MOVED TOUCH_RELEASED GESTURE_TAP GESTURE_END",
EventTypesToString(recorder.events()));
@@ -773,20 +776,21 @@ TEST_F(WindowEventDispatcherTest, TouchMovesHeld) {
EXPECT_TRUE(recorder.events().empty());
}
+// This event handler requests the dispatcher to start holding pointer-move
+// events when it receives the first scroll-update gesture.
class HoldPointerOnScrollHandler : public ui::test::TestEventHandler {
public:
HoldPointerOnScrollHandler(WindowEventDispatcher* dispatcher,
- EventFilterRecorder* filter)
+ EventFilterRecorder* filter)
: dispatcher_(dispatcher),
filter_(filter),
- holding_moves_(false) {
- }
+ holding_moves_(false) {}
virtual ~HoldPointerOnScrollHandler() {}
private:
+ // ui::test::TestEventHandler:
virtual void OnGestureEvent(ui::GestureEvent* gesture) OVERRIDE {
- if (gesture->type() == ui::ET_GESTURE_SCROLL_UPDATE) {
- CHECK(!holding_moves_);
+ if (!holding_moves_ && gesture->type() == ui::ET_GESTURE_SCROLL_UPDATE) {
holding_moves_ = true;
dispatcher_->HoldPointerMoves();
filter_->Reset();
@@ -825,8 +829,10 @@ TEST_F(WindowEventDispatcherTest, TouchMovesHeldOnScroll) {
// along with the subsequent events (i.e. touch-release, scroll-end, and
// gesture-end).
const EventFilterRecorder::Events& events = recorder.events();
- EXPECT_EQ("TOUCH_MOVED TOUCH_RELEASED GESTURE_SCROLL_END GESTURE_END",
- EventTypesToString(events));
+ EXPECT_EQ(
+ "TOUCH_MOVED GESTURE_SCROLL_UPDATE TOUCH_RELEASED "
+ "GESTURE_SCROLL_END GESTURE_END",
+ EventTypesToString(events));
ASSERT_EQ(2u, recorder.touch_locations().size());
EXPECT_EQ(gfx::Point(-40, 10).ToString(),
recorder.touch_locations()[0].ToString());
@@ -834,6 +840,40 @@ TEST_F(WindowEventDispatcherTest, TouchMovesHeldOnScroll) {
recorder.touch_locations()[1].ToString());
}
+// Tests that a 'held' touch-event does contribute to gesture event when it is
+// dispatched.
+TEST_F(WindowEventDispatcherTest, HeldTouchMoveContributesToGesture) {
+ EventFilterRecorder recorder;
+ root_window()->AddPreTargetHandler(&recorder);
+
+ const gfx::Point location(20, 20);
+ ui::TouchEvent press(
+ ui::ET_TOUCH_PRESSED, location, 0, ui::EventTimeForNow());
+ DispatchEventUsingWindowDispatcher(&press);
+ EXPECT_TRUE(recorder.HasReceivedEvent(ui::ET_TOUCH_PRESSED));
+ recorder.Reset();
+
+ host()->dispatcher()->HoldPointerMoves();
+
+ ui::TouchEvent move(ui::ET_TOUCH_MOVED,
+ location + gfx::Vector2d(100, 100),
+ 0,
+ ui::EventTimeForNow());
+ DispatchEventUsingWindowDispatcher(&move);
+ EXPECT_FALSE(recorder.HasReceivedEvent(ui::ET_TOUCH_MOVED));
+ EXPECT_FALSE(recorder.HasReceivedEvent(ui::ET_GESTURE_SCROLL_BEGIN));
+ recorder.Reset();
+
+ host()->dispatcher()->ReleasePointerMoves();
+ EXPECT_FALSE(recorder.HasReceivedEvent(ui::ET_TOUCH_MOVED));
+ RunAllPendingInMessageLoop();
+ EXPECT_TRUE(recorder.HasReceivedEvent(ui::ET_TOUCH_MOVED));
+ EXPECT_TRUE(recorder.HasReceivedEvent(ui::ET_GESTURE_SCROLL_BEGIN));
+ EXPECT_TRUE(recorder.HasReceivedEvent(ui::ET_GESTURE_SCROLL_UPDATE));
+
+ root_window()->RemovePreTargetHandler(&recorder);
+}
+
// Tests that synthetic mouse events are ignored when mouse
// events are disabled.
TEST_F(WindowEventDispatcherTest, DispatchSyntheticMouseEvents) {
@@ -1895,8 +1935,10 @@ TEST_F(WindowEventDispatcherTestInHighDPI, TouchMovesHeldOnScroll) {
// along with the subsequent events (i.e. touch-release, scroll-end, and
// gesture-end).
const EventFilterRecorder::Events& events = recorder.events();
- EXPECT_EQ("TOUCH_MOVED TOUCH_RELEASED GESTURE_SCROLL_END GESTURE_END",
- EventTypesToString(events));
+ EXPECT_EQ(
+ "TOUCH_MOVED GESTURE_SCROLL_UPDATE TOUCH_RELEASED "
+ "GESTURE_SCROLL_END GESTURE_END",
+ EventTypesToString(events));
ASSERT_EQ(2u, recorder.touch_locations().size());
EXPECT_EQ(gfx::Point(-40, 10).ToString(),
recorder.touch_locations()[0].ToString());