Bug 1196176 - Hide carets for mouse down reason. r=mtseng
authorTing-Yu Lin <tlin@mozilla.com>
Tue, 22 Sep 2015 17:39:36 +0800
changeset 264054 1c27eb1ea593d33e648508cfeae1a9b8c40794a5
parent 264053 cd3d36c8fdae2a9d3e8c9d3531d7cf009664603f
child 264055 bd5678610d2ae9b86a06e31b34c5fb6e7b2585f5
push id29427
push usercbook@mozilla.com
push dateThu, 24 Sep 2015 09:59:50 +0000
treeherdermozilla-central@0f498d5adbf9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmtseng
bugs1196176
milestone44.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 1196176 - Hide carets for mouse down reason. r=mtseng SelectionCaret had been hiding carets upon receiving mouse down reason. In this way, text selection dialog won't show, hide, and show again.
layout/base/AccessibleCaretManager.cpp
layout/base/gtest/TestAccessibleCaretManager.cpp
--- a/layout/base/AccessibleCaretManager.cpp
+++ b/layout/base/AccessibleCaretManager.cpp
@@ -75,18 +75,18 @@ AccessibleCaretManager::~AccessibleCaret
 {
   CancelCaretTimeoutTimer();
 }
 
 nsresult
 AccessibleCaretManager::OnSelectionChanged(nsIDOMDocument* aDoc,
                                            nsISelection* aSel, int16_t aReason)
 {
-  AC_LOG("aSel: %p, GetSelection(): %p, aReason: %d", aSel, GetSelection(),
-         aReason);
+  AC_LOG("%s: aSel: %p, GetSelection(): %p, aReason: %d", __FUNCTION__,
+         aSel, GetSelection(), aReason);
 
   if (aSel != GetSelection()) {
     return NS_OK;
   }
 
   // Move the cursor by Javascript.
   if (aReason == nsISelectionListener::NO_REASON) {
     HideCarets();
@@ -94,16 +94,23 @@ AccessibleCaretManager::OnSelectionChang
   }
 
   // Move cursor by keyboard.
   if (aReason & nsISelectionListener::KEYPRESS_REASON) {
     HideCarets();
     return NS_OK;
   }
 
+  // OnBlur() might be called between mouse down and mouse up, so we hide carets
+  // upon mouse down anyway, and update carets upon mouse up.
+  if (aReason & nsISelectionListener::MOUSEDOWN_REASON) {
+    HideCarets();
+    return NS_OK;
+  }
+
   // Range will collapse after cutting or copying text.
   if (aReason & (nsISelectionListener::COLLAPSETOSTART_REASON |
                  nsISelectionListener::COLLAPSETOEND_REASON)) {
     HideCarets();
     return NS_OK;
   }
 
   UpdateCarets();
--- a/layout/base/gtest/TestAccessibleCaretManager.cpp
+++ b/layout/base/gtest/TestAccessibleCaretManager.cpp
@@ -143,65 +143,79 @@ TEST_F(AccessibleCaretManagerTester, Tes
   EXPECT_EQ(FirstCaretAppearance(), Appearance::Normal);
   EXPECT_EQ(SecondCaretAppearance(), Appearance::Normal);
 
   mManager.OnScrollPositionChanged();
   EXPECT_EQ(FirstCaretAppearance(), Appearance::Normal);
   EXPECT_EQ(SecondCaretAppearance(), Appearance::Normal);
 }
 
-TEST_F(AccessibleCaretManagerTester, TestUpdatesInCursorModeOnNonEmptyContent)
+TEST_F(AccessibleCaretManagerTester, TestSingleTapOnNonEmptyInput)
 {
   EXPECT_CALL(mManager, GetCaretMode())
     .WillRepeatedly(Return(CaretMode::Cursor));
 
   EXPECT_CALL(mManager, HasNonEmptyTextContent(_))
     .WillRepeatedly(Return(true));
 
   MockFunction<void(std::string aCheckPointName)> check;
   {
     InSequence dummy;
 
     EXPECT_CALL(mManager, DispatchCaretStateChangedEvent(
                   CaretChangedReason::Updateposition)).Times(1);
-    EXPECT_CALL(check, Call("mouse down"));
-
-    EXPECT_CALL(mManager, DispatchCaretStateChangedEvent(
-                  CaretChangedReason::Updateposition)).Times(1);
-    EXPECT_CALL(check, Call("reflow"));
+    EXPECT_CALL(check, Call("update"));
 
     EXPECT_CALL(mManager, DispatchCaretStateChangedEvent(
                   CaretChangedReason::Visibilitychange)).Times(1);
+    EXPECT_CALL(check, Call("mouse down"));
+
+    EXPECT_CALL(mManager, DispatchCaretStateChangedEvent(_)).Times(0);
+    EXPECT_CALL(check, Call("reflow"));
+
+    EXPECT_CALL(mManager, DispatchCaretStateChangedEvent(_)).Times(0);
     EXPECT_CALL(check, Call("blur"));
 
     EXPECT_CALL(mManager, DispatchCaretStateChangedEvent(
                   CaretChangedReason::Updateposition)).Times(1);
     EXPECT_CALL(check, Call("mouse up"));
 
     EXPECT_CALL(mManager, DispatchCaretStateChangedEvent(
                   CaretChangedReason::Updateposition)).Times(1);
+    EXPECT_CALL(check, Call("reflow2"));
+
+    EXPECT_CALL(mManager, DispatchCaretStateChangedEvent(
+                  CaretChangedReason::Updateposition)).Times(1);
   }
 
   // Simulate a single tap on a non-empty input.
+  mManager.UpdateCarets();
+  EXPECT_EQ(FirstCaretAppearance(), Appearance::Normal);
+  check.Call("update");
+
   mManager.OnSelectionChanged(nullptr, nullptr,
                               nsISelectionListener::DRAG_REASON |
                               nsISelectionListener::MOUSEDOWN_REASON);
-  EXPECT_EQ(FirstCaretAppearance(), Appearance::Normal);
+  EXPECT_EQ(FirstCaretAppearance(), Appearance::None);
   check.Call("mouse down");
 
   mManager.OnReflow();
-  EXPECT_EQ(FirstCaretAppearance(), Appearance::Normal);
+  EXPECT_EQ(FirstCaretAppearance(), Appearance::None);
   check.Call("reflow");
 
   mManager.OnBlur();
   EXPECT_EQ(FirstCaretAppearance(), Appearance::None);
   check.Call("blur");
 
   mManager.OnSelectionChanged(nullptr, nullptr,
                               nsISelectionListener::MOUSEUP_REASON);
   EXPECT_EQ(FirstCaretAppearance(), Appearance::Normal);
   check.Call("mouse up");
 
+  mManager.OnReflow();
+  EXPECT_EQ(FirstCaretAppearance(), Appearance::Normal);
+  check.Call("reflow2");
+
   mManager.OnScrollPositionChanged();
   EXPECT_EQ(FirstCaretAppearance(), Appearance::Normal);
 }
 
 } // namespace mozilla