Bug 1251915 - Ignore handling eTouchCancel events. r=roc
authorTing-Yu Lin <tlin@mozilla.com>
Mon, 29 Feb 2016 15:51:44 +0800
changeset 322440 50cb73a3297424c6caa60a128a11843af57becb6
parent 322439 51b5b9c96032fc9f8ea93ed010ce43b6b2442f76
child 322441 788fe2501a34c536caa5d572a9183e4e7304423f
push id5913
push userjlund@mozilla.com
push dateMon, 25 Apr 2016 16:57:49 +0000
treeherdermozilla-beta@dcaf0a6fa115 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersroc
bugs1251915
milestone47.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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
layout/base/gtest/TestAccessibleCaretEventHub.cpp
--- a/layout/base/AccessibleCaretEventHub.cpp
+++ b/layout/base/AccessibleCaretEventHub.cpp
@@ -572,19 +572,18 @@ AccessibleCaretEventHub::HandleTouchEven
 
     case eTouchEnd:
       AC_LOGV("Before eTouchEnd, state: %s", mState->Name());
       rv = mState->OnRelease(this);
       AC_LOGV("After eTouchEnd, state: %s, consume: %d", mState->Name(), rv);
       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:
       break;
   }
 
   return rv;
 }
--- a/layout/base/gtest/TestAccessibleCaretEventHub.cpp
+++ b/layout/base/gtest/TestAccessibleCaretEventHub.cpp
@@ -163,31 +163,36 @@ public:
 
     RefPtr<dom::Touch> touch(
       new dom::Touch(identifier, point, radius, rotationAngle, force));
     event->touches.AppendElement(touch);
 
     return Move(event);
   }
 
-  static UniquePtr<WidgetEvent> CreateTouchPressEvent(nscoord aX, nscoord aY)
+  static UniquePtr<WidgetEvent> CreateTouchStartEvent(nscoord aX, nscoord aY)
   {
     return CreateTouchEvent(eTouchStart, aX, aY);
   }
 
   static UniquePtr<WidgetEvent> CreateTouchMoveEvent(nscoord aX, nscoord aY)
   {
     return CreateTouchEvent(eTouchMove, aX, aY);
   }
 
-  static UniquePtr<WidgetEvent> CreateTouchReleaseEvent(nscoord aX, nscoord aY)
+  static UniquePtr<WidgetEvent> CreateTouchEndEvent(nscoord aX, nscoord aY)
   {
     return CreateTouchEvent(eTouchEnd, aX, aY);
   }
 
+  static UniquePtr<WidgetEvent> CreateTouchCancelEvent(nscoord aX, nscoord aY)
+  {
+    return CreateTouchEvent(eTouchCancel, aX, aY);
+  }
+
   static UniquePtr<WidgetEvent> CreateWheelEvent(EventMessage aMessage)
   {
     auto event = MakeUnique<WidgetWheelEvent>(true, aMessage, nullptr);
 
     return Move(event);
   }
 
   void HandleEventAndCheckState(UniquePtr<WidgetEvent> aEvent,
@@ -247,17 +252,17 @@ public:
 
 TEST_F(AccessibleCaretEventHubTester, TestMousePressReleaseOnNoCaret)
 {
   TestPressReleaseOnNoCaret(CreateMousePressEvent, CreateMouseReleaseEvent);
 }
 
 TEST_F(AccessibleCaretEventHubTester, TestTouchPressReleaseOnNoCaret)
 {
-  TestPressReleaseOnNoCaret(CreateTouchPressEvent, CreateTouchReleaseEvent);
+  TestPressReleaseOnNoCaret(CreateTouchStartEvent, CreateTouchEndEvent);
 }
 
 template <typename PressEventCreator, typename ReleaseEventCreator>
 void
 AccessibleCaretEventHubTester::TestPressReleaseOnNoCaret(
   PressEventCreator aPressEventCreator,
   ReleaseEventCreator aReleaseEventCreator)
 {
@@ -279,17 +284,17 @@ AccessibleCaretEventHubTester::TestPress
 
 TEST_F(AccessibleCaretEventHubTester, TestMousePressReleaseOnCaret)
 {
   TestPressReleaseOnCaret(CreateMousePressEvent, CreateMouseReleaseEvent);
 }
 
 TEST_F(AccessibleCaretEventHubTester, TestTouchPressReleaseOnCaret)
 {
-  TestPressReleaseOnCaret(CreateTouchPressEvent, CreateTouchReleaseEvent);
+  TestPressReleaseOnCaret(CreateTouchStartEvent, CreateTouchEndEvent);
 }
 
 template <typename PressEventCreator, typename ReleaseEventCreator>
 void
 AccessibleCaretEventHubTester::TestPressReleaseOnCaret(
   PressEventCreator aPressEventCreator,
   ReleaseEventCreator aReleaseEventCreator)
 {
@@ -322,18 +327,18 @@ AccessibleCaretEventHubTester::TestPress
 TEST_F(AccessibleCaretEventHubTester, TestMousePressMoveReleaseOnNoCaret)
 {
   TestPressMoveReleaseOnNoCaret(CreateMousePressEvent, CreateMouseMoveEvent,
                                 CreateMouseReleaseEvent);
 }
 
 TEST_F(AccessibleCaretEventHubTester, TestTouchPressMoveReleaseOnNoCaret)
 {
-  TestPressMoveReleaseOnNoCaret(CreateTouchPressEvent, CreateTouchMoveEvent,
-                                CreateTouchReleaseEvent);
+  TestPressMoveReleaseOnNoCaret(CreateTouchStartEvent, CreateTouchMoveEvent,
+                                CreateTouchEndEvent);
 }
 
 template <typename PressEventCreator, typename MoveEventCreator,
           typename ReleaseEventCreator>
 void
 AccessibleCaretEventHubTester::TestPressMoveReleaseOnNoCaret(
   PressEventCreator aPressEventCreator, MoveEventCreator aMoveEventCreator,
   ReleaseEventCreator aReleaseEventCreator)
@@ -376,18 +381,18 @@ AccessibleCaretEventHubTester::TestPress
 TEST_F(AccessibleCaretEventHubTester, TestMousePressMoveReleaseOnCaret)
 {
   TestPressMoveReleaseOnCaret(CreateMousePressEvent, CreateMouseMoveEvent,
                               CreateMouseReleaseEvent);
 }
 
 TEST_F(AccessibleCaretEventHubTester, TestTouchPressMoveReleaseOnCaret)
 {
-  TestPressMoveReleaseOnCaret(CreateTouchPressEvent, CreateTouchMoveEvent,
-                              CreateTouchReleaseEvent);
+  TestPressMoveReleaseOnCaret(CreateTouchStartEvent, CreateTouchMoveEvent,
+                              CreateTouchEndEvent);
 }
 
 template <typename PressEventCreator, typename MoveEventCreator,
           typename ReleaseEventCreator>
 void
 AccessibleCaretEventHubTester::TestPressMoveReleaseOnCaret(
   PressEventCreator aPressEventCreator, MoveEventCreator aMoveEventCreator,
   ReleaseEventCreator aReleaseEventCreator)
@@ -434,26 +439,85 @@ AccessibleCaretEventHubTester::TestPress
                            MockAccessibleCaretEventHub::DragCaretState(),
                            nsEventStatus_eConsumeNoDefault);
 
   HandleEventAndCheckState(aReleaseEventCreator(x3, y3),
                            MockAccessibleCaretEventHub::NoActionState(),
                            nsEventStatus_eConsumeNoDefault);
 }
 
+TEST_F(AccessibleCaretEventHubTester,
+       TestTouchStartMoveEndOnCaretWithTouchCancelIgnored)
+{
+  nscoord x0 = 0, y0 = 0;
+  nscoord x1 = 100, y1 = 100;
+  nscoord x2 = 300, y2 = 300;
+  nscoord x3 = 400, y3 = 400;
+
+  {
+    InSequence dummy;
+
+    EXPECT_CALL(*mHub->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,
                                       CreateMouseReleaseEvent);
 }
 
 TEST_F(AccessibleCaretEventHubTester, TestTouchLongTapWithSelectWordSuccessful)
 {
-  TestLongTapWithSelectWordSuccessful(CreateTouchPressEvent,
-                                      CreateTouchReleaseEvent);
+  TestLongTapWithSelectWordSuccessful(CreateTouchStartEvent,
+                                      CreateTouchEndEvent);
 }
 
 template <typename PressEventCreator, typename ReleaseEventCreator>
 void
 AccessibleCaretEventHubTester::TestLongTapWithSelectWordSuccessful(
   PressEventCreator aPressEventCreator,
   ReleaseEventCreator aReleaseEventCreator)
 {
@@ -526,18 +590,18 @@ AccessibleCaretEventHubTester::TestLongT
 TEST_F(AccessibleCaretEventHubTester, TestMouseLongTapWithSelectWordFailed)
 {
   TestLongTapWithSelectWordFailed(CreateMousePressEvent,
                                   CreateMouseReleaseEvent);
 }
 
 TEST_F(AccessibleCaretEventHubTester, TestTouchLongTapWithSelectWordFailed)
 {
-  TestLongTapWithSelectWordFailed(CreateTouchPressEvent,
-                                  CreateTouchReleaseEvent);
+  TestLongTapWithSelectWordFailed(CreateTouchStartEvent,
+                                  CreateTouchEndEvent);
 }
 
 template <typename PressEventCreator, typename ReleaseEventCreator>
 void
 AccessibleCaretEventHubTester::TestLongTapWithSelectWordFailed(
   PressEventCreator aPressEventCreator,
   ReleaseEventCreator aReleaseEventCreator)
 {
@@ -561,18 +625,18 @@ AccessibleCaretEventHubTester::TestLongT
 
   HandleEventAndCheckState(aReleaseEventCreator(0, 0),
                            MockAccessibleCaretEventHub::NoActionState(),
                            nsEventStatus_eIgnore);
 }
 
 TEST_F(AccessibleCaretEventHubTester, TestTouchEventDrivenAsyncPanZoomScroll)
 {
-  TestEventDrivenAsyncPanZoomScroll(CreateTouchPressEvent, CreateTouchMoveEvent,
-                                    CreateTouchReleaseEvent);
+  TestEventDrivenAsyncPanZoomScroll(CreateTouchStartEvent, CreateTouchMoveEvent,
+                                    CreateTouchEndEvent);
 }
 
 TEST_F(AccessibleCaretEventHubTester, TestMouseEventDrivenAsyncPanZoomScroll)
 {
   TestEventDrivenAsyncPanZoomScroll(CreateMousePressEvent, CreateMouseMoveEvent,
                                     CreateMouseReleaseEvent);
 }