Commit 3914c250 authored by lanwei's avatar lanwei Committed by Commit bot

Always send the ET_GESTURE_END event as the last one for every touch

event.

Occasionally we synthesize scroll or tap cancel events when a touch
sequence has been canceled or terminated, we want to make sure that
ET_GESTURE_END always happens after them.

BUG=379772

Review URL: https://codereview.chromium.org/549333002

Cr-Commit-Position: refs/heads/master@{#294010}
parent 4dad341e
......@@ -219,7 +219,7 @@ void TouchDispositionGestureFilter::FilterAndSendPacket(
} else if (packet.gesture_source() == GestureEventDataPacket::TOUCH_START) {
CancelTapIfNecessary(packet);
}
int gesture_end_index = -1;
for (size_t i = 0; i < packet.gesture_count(); ++i) {
const GestureEventData& gesture = packet.gesture(i);
DCHECK_GE(gesture.details.type(), ET_GESTURE_TYPE_START);
......@@ -232,9 +232,20 @@ void TouchDispositionGestureFilter::FilterAndSendPacket(
// Sending a timed gesture could delete |this|, so we need to return
// directly after the |SendGesture| call.
SendGesture(gesture, packet);
// We should not have a timeout gesture and other gestures in the same
// packet.
DCHECK_EQ(1U, packet.gesture_count());
return;
}
// Occasionally scroll or tap cancel events are synthesized when a touch
// sequence has been canceled or terminated, we want to make sure that
// ET_GESTURE_END always happens after them.
if (gesture.type() == ET_GESTURE_END) {
// Make sure there is at most one ET_GESTURE_END event in each packet.
DCHECK_EQ(-1, gesture_end_index);
gesture_end_index = static_cast<int>(i);
continue;
}
SendGesture(gesture, packet);
}
......@@ -246,6 +257,9 @@ void TouchDispositionGestureFilter::FilterAndSendPacket(
GestureEventDataPacket::TOUCH_SEQUENCE_END) {
EndScrollIfNecessary(packet);
}
// Always send the ET_GESTURE_END event as the last one for every touch event.
if (gesture_end_index >= 0)
SendGesture(packet.gesture(gesture_end_index), packet);
}
void TouchDispositionGestureFilter::SendGesture(
......
......@@ -988,7 +988,7 @@ TEST_F(TouchDispositionGestureFilterTest,
PushGesture(ET_GESTURE_END);
ReleaseTouchPoint();
SendTouchNotConsumedAck();
EXPECT_TRUE(GesturesMatch(Gestures(ET_GESTURE_END, ET_GESTURE_SCROLL_END),
EXPECT_TRUE(GesturesMatch(Gestures(ET_GESTURE_SCROLL_END, ET_GESTURE_END),
GetAndResetSentGestures()));
EXPECT_EQ(LastSentGestureLocation(), gfx::PointF(2, 2));
......@@ -1101,4 +1101,25 @@ TEST_F(TouchDispositionGestureFilterTest, ShowPressBoundingBox) {
EXPECT_EQ(gfx::RectF(5, 5, 10, 10), ShowPressBoundingBox());
}
TEST_F(TouchDispositionGestureFilterTest, TapCancelledBeforeGestureEnd) {
PushGesture(ET_GESTURE_BEGIN);
PushGesture(ET_GESTURE_TAP_DOWN);
PressTouchPoint(1, 1);
SendTouchNotConsumedAck();
EXPECT_TRUE(GesturesMatch(Gestures(ET_GESTURE_BEGIN, ET_GESTURE_TAP_DOWN),
GetAndResetSentGestures()));
SendTimeoutGesture(ET_GESTURE_SHOW_PRESS);
EXPECT_TRUE(GesturesMatch(Gestures(ET_GESTURE_SHOW_PRESS),
GetAndResetSentGestures()));
SendTimeoutGesture(ET_GESTURE_LONG_PRESS);
EXPECT_TRUE(GesturesMatch(Gestures(ET_GESTURE_LONG_PRESS),
GetAndResetSentGestures()));
PushGesture(ET_GESTURE_END);
CancelTouchPoint();
SendTouchNotConsumedAck();
EXPECT_TRUE(GesturesMatch(Gestures(ET_GESTURE_TAP_CANCEL, ET_GESTURE_END),
GetAndResetSentGestures()));
}
} // namespace ui
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment