Skip to content
This repository has been archived by the owner on Apr 3, 2020. It is now read-only.

Commit

Permalink
Invalid press events don't create multiple pointers with the same id.
Browse files Browse the repository at this point in the history
Previously if we got an invalid event stream such as

Press id 0
Press id 0

MotionEventAura would happily add the second pointer. Now we replace
the first pointer with the second pointer.

This work around is required due to crbug.com/373125.

BUG=450880

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

Cr-Commit-Position: refs/heads/master@{#313116}
(cherry picked from commit b88d572)

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

Cr-Commit-Position: refs/branch-heads/2272@{#185}
Cr-Branched-From: 827a380-refs/heads/master@{#310958}
  • Loading branch information
tdresser committed Feb 2, 2015
1 parent 6318233 commit 6b8b695
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
2 changes: 1 addition & 1 deletion ui/aura/gestures/gesture_recognizer_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2554,7 +2554,7 @@ TEST_F(GestureRecognizerTest, PressDoesNotCrash) {
// there is at least one case where we need to allow a touch press
// from a currently used touch id. See crbug.com/373125 for details.
EXPECT_TRUE(delegate->begin());
EXPECT_FALSE(delegate->tap_down());
EXPECT_TRUE(delegate->tap_down());
EXPECT_TRUE(delegate->tap_cancel());
EXPECT_FALSE(delegate->scroll_begin());
}
Expand Down
15 changes: 10 additions & 5 deletions ui/events/gestures/motion_event_aura.cc
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,17 @@ bool MotionEventAura::OnTouch(const TouchEvent& touch) {
bool pointer_id_is_active = index != -1;

if (touch.type() == ET_TOUCH_PRESSED && pointer_id_is_active) {
// Ignore touch press events if we already believe the pointer is down.

// TODO(tdresser): this should return false (or NOTREACHED());
// however, there is at least one case where we need to allow a
// touch press from a currently used touch id. See
// TODO(tdresser): This should return false (or NOTREACHED()), and
// ignore the touch; however, there is at least one case where we
// need to allow a touch press from a currently used touch id. See
// crbug.com/446852 for details.

// Cancel the existing touch, before handling the touch press.
TouchEvent cancel(ET_TOUCH_CANCELLED, touch.location(), touch.touch_id(),
touch.time_stamp());
OnTouch(cancel);
CleanupRemovedTouchPoints(cancel);
DCHECK_EQ(-1, FindPointerIndexOfId(touch.touch_id()));
} else if (touch.type() != ET_TOUCH_PRESSED && !pointer_id_is_active) {
// We could have an active touch stream transfered to us, resulting in touch
// move or touch up events without associated touch down events. Ignore
Expand Down
16 changes: 13 additions & 3 deletions ui/events/gestures/motion_event_aura_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -426,10 +426,20 @@ TEST(MotionEventAuraTest, Flags) {

// Once crbug.com/446852 is fixed, we should ignore redundant presses.
TEST(MotionEventAuraTest, DoesntIgnoreRedundantPresses) {
int id = 7;
const int id = 7;
const int position_1 = 10;
const int position_2 = 23;

MotionEventAura event;
EXPECT_TRUE(event.OnTouch(TouchWithType(ET_TOUCH_PRESSED, id)));
EXPECT_TRUE(event.OnTouch(TouchWithType(ET_TOUCH_PRESSED, id)));
TouchEvent press1 = TouchWithPosition(ET_TOUCH_PRESSED, id, position_1,
position_1, position_1, position_1);
EXPECT_TRUE(event.OnTouch(press1));
TouchEvent press2 = TouchWithPosition(ET_TOUCH_PRESSED, id, position_2,
position_2, position_2, position_2);
EXPECT_TRUE(event.OnTouch(press2));

EXPECT_EQ(1U, event.GetPointerCount());
EXPECT_FLOAT_EQ(position_2, event.GetX(0));
}

TEST(MotionEventAuraTest, IgnoresEventsWithoutPress) {
Expand Down

0 comments on commit 6b8b695

Please sign in to comment.