From d1a7279479ad1ca4e663c72e33e8ba22db7fea35 Mon Sep 17 00:00:00 2001 From: Ting-Yu Lin Date: Mon, 29 Feb 2016 15:51:44 +0800 Subject: [PATCH] Bug 1251915 - Ignore handling eTouchCancel events. r=roc In my original design, I treat eTouchCancel to be like eTouchEnd for ending a caret dragging procedure. However when pointer events is enabled, it sents an eTouchCancel event after the eTouchStart event whose primary usage is to be converted to pointer events, which then cancels the normal caret dragging procedure. Moreover, when pointer events is disabled, we don't get eTouchCancel during a normal caret dragging scenario, so we don't really need to handle eTouchCancel anyway. MozReview-Commit-ID: GKju2Tp0q3Q --- layout/base/AccessibleCaretEventHub.cpp | 5 +- .../gtest/TestAccessibleCaretEventHub.cpp | 92 ++++++++++++++++--- 2 files changed, 80 insertions(+), 17 deletions(-) diff --git a/layout/base/AccessibleCaretEventHub.cpp b/layout/base/AccessibleCaretEventHub.cpp index 029c4addebf..5044b6d5a5a 100644 --- a/layout/base/AccessibleCaretEventHub.cpp +++ b/layout/base/AccessibleCaretEventHub.cpp @@ -577,9 +577,8 @@ AccessibleCaretEventHub::HandleTouchEvent(WidgetTouchEvent* aEvent) break; case eTouchCancel: - AC_LOGV("Before eTouchCancel, state: %s", mState->Name()); - rv = mState->OnRelease(this); - AC_LOGV("After eTouchCancel, state: %s, consume: %d", mState->Name(), rv); + AC_LOGV("Got eTouchCancel, state: %s", mState->Name()); + // Do nothing since we don't really care eTouchCancel anyway. break; default: diff --git a/layout/base/gtest/TestAccessibleCaretEventHub.cpp b/layout/base/gtest/TestAccessibleCaretEventHub.cpp index 2f230c48fda..7e447992fb3 100644 --- a/layout/base/gtest/TestAccessibleCaretEventHub.cpp +++ b/layout/base/gtest/TestAccessibleCaretEventHub.cpp @@ -168,7 +168,7 @@ public: return Move(event); } - static UniquePtr CreateTouchPressEvent(nscoord aX, nscoord aY) + static UniquePtr CreateTouchStartEvent(nscoord aX, nscoord aY) { return CreateTouchEvent(eTouchStart, aX, aY); } @@ -178,11 +178,16 @@ public: return CreateTouchEvent(eTouchMove, aX, aY); } - static UniquePtr CreateTouchReleaseEvent(nscoord aX, nscoord aY) + static UniquePtr CreateTouchEndEvent(nscoord aX, nscoord aY) { return CreateTouchEvent(eTouchEnd, aX, aY); } + static UniquePtr CreateTouchCancelEvent(nscoord aX, nscoord aY) + { + return CreateTouchEvent(eTouchCancel, aX, aY); + } + static UniquePtr CreateWheelEvent(EventMessage aMessage) { auto event = MakeUnique(true, aMessage, nullptr); @@ -252,7 +257,7 @@ TEST_F(AccessibleCaretEventHubTester, TestMousePressReleaseOnNoCaret) TEST_F(AccessibleCaretEventHubTester, TestTouchPressReleaseOnNoCaret) { - TestPressReleaseOnNoCaret(CreateTouchPressEvent, CreateTouchReleaseEvent); + TestPressReleaseOnNoCaret(CreateTouchStartEvent, CreateTouchEndEvent); } template @@ -284,7 +289,7 @@ TEST_F(AccessibleCaretEventHubTester, TestMousePressReleaseOnCaret) TEST_F(AccessibleCaretEventHubTester, TestTouchPressReleaseOnCaret) { - TestPressReleaseOnCaret(CreateTouchPressEvent, CreateTouchReleaseEvent); + TestPressReleaseOnCaret(CreateTouchStartEvent, CreateTouchEndEvent); } template @@ -327,8 +332,8 @@ TEST_F(AccessibleCaretEventHubTester, TestMousePressMoveReleaseOnNoCaret) TEST_F(AccessibleCaretEventHubTester, TestTouchPressMoveReleaseOnNoCaret) { - TestPressMoveReleaseOnNoCaret(CreateTouchPressEvent, CreateTouchMoveEvent, - CreateTouchReleaseEvent); + TestPressMoveReleaseOnNoCaret(CreateTouchStartEvent, CreateTouchMoveEvent, + CreateTouchEndEvent); } template GetMockAccessibleCaretManager(), PressCaret(_)) + .WillOnce(Return(NS_OK)); + + EXPECT_CALL(*mHub->GetMockAccessibleCaretManager(), DragCaret(_)) + .WillOnce(Return(NS_OK)); + + EXPECT_CALL(*mHub->GetMockAccessibleCaretManager(), ReleaseCaret()) + .WillOnce(Return(NS_OK)); + } + + // All the eTouchCancel events should be ignored in this test. + + HandleEventAndCheckState(CreateTouchStartEvent(x0, y0), + MockAccessibleCaretEventHub::PressCaretState(), + nsEventStatus_eConsumeNoDefault); + + HandleEventAndCheckState(CreateTouchCancelEvent(x0, y0), + MockAccessibleCaretEventHub::PressCaretState(), + nsEventStatus_eIgnore); + + // A small move with the distance between (x0, y0) and (x1, y1) below the + // tolerance value. + HandleEventAndCheckState(CreateTouchMoveEvent(x1, y1), + MockAccessibleCaretEventHub::PressCaretState(), + nsEventStatus_eConsumeNoDefault); + + HandleEventAndCheckState(CreateTouchCancelEvent(x1, y1), + MockAccessibleCaretEventHub::PressCaretState(), + nsEventStatus_eIgnore); + + // A large move forms a valid drag since the distance between (x0, y0) and + // (x2, y2) is above the tolerance value. + HandleEventAndCheckState(CreateTouchMoveEvent(x2, y2), + MockAccessibleCaretEventHub::DragCaretState(), + nsEventStatus_eConsumeNoDefault); + + HandleEventAndCheckState(CreateTouchCancelEvent(x2, y2), + MockAccessibleCaretEventHub::DragCaretState(), + nsEventStatus_eIgnore); + + HandleEventAndCheckState(CreateTouchEndEvent(x3, y3), + MockAccessibleCaretEventHub::NoActionState(), + nsEventStatus_eConsumeNoDefault); + + HandleEventAndCheckState(CreateTouchCancelEvent(x3, y3), + MockAccessibleCaretEventHub::NoActionState(), + nsEventStatus_eIgnore);} + TEST_F(AccessibleCaretEventHubTester, TestMouseLongTapWithSelectWordSuccessful) { TestLongTapWithSelectWordSuccessful(CreateMousePressEvent, @@ -447,8 +511,8 @@ TEST_F(AccessibleCaretEventHubTester, TestMouseLongTapWithSelectWordSuccessful) TEST_F(AccessibleCaretEventHubTester, TestTouchLongTapWithSelectWordSuccessful) { - TestLongTapWithSelectWordSuccessful(CreateTouchPressEvent, - CreateTouchReleaseEvent); + TestLongTapWithSelectWordSuccessful(CreateTouchStartEvent, + CreateTouchEndEvent); } template @@ -531,8 +595,8 @@ TEST_F(AccessibleCaretEventHubTester, TestMouseLongTapWithSelectWordFailed) TEST_F(AccessibleCaretEventHubTester, TestTouchLongTapWithSelectWordFailed) { - TestLongTapWithSelectWordFailed(CreateTouchPressEvent, - CreateTouchReleaseEvent); + TestLongTapWithSelectWordFailed(CreateTouchStartEvent, + CreateTouchEndEvent); } template @@ -566,8 +630,8 @@ AccessibleCaretEventHubTester::TestLongTapWithSelectWordFailed( TEST_F(AccessibleCaretEventHubTester, TestTouchEventDrivenAsyncPanZoomScroll) { - TestEventDrivenAsyncPanZoomScroll(CreateTouchPressEvent, CreateTouchMoveEvent, - CreateTouchReleaseEvent); + TestEventDrivenAsyncPanZoomScroll(CreateTouchStartEvent, CreateTouchMoveEvent, + CreateTouchEndEvent); } TEST_F(AccessibleCaretEventHubTester, TestMouseEventDrivenAsyncPanZoomScroll)