Bug 1200194 - Fix AccessibleCaret is out of scrollport in cursor mode. r=roc
authorTing-Yu Lin <tlin@mozilla.com>
Wed, 09 Sep 2015 16:47:20 +0800
changeset 294342 bc60f34e6b6e3e84de94b09ee5b79927c53e9966
parent 294341 8d7e8ebd0de628c8a393e36c392eb3b1ab227bdf
child 294343 9ddf3be46d2ab81dfa86c326c98efb4b7e6317c8
push id5245
push userraliiev@mozilla.com
push dateThu, 29 Oct 2015 11:30:51 +0000
treeherdermozilla-beta@dac831dc1bd0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersroc
bugs1200194
milestone43.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 1200194 - Fix AccessibleCaret is out of scrollport in cursor mode. r=roc The comment reads "No need to consider whether the caret's position is out of scrollport", which is untrue. For example, the position of nsCaret might be shifted by typing and be covered by other elements. So we need to set the appearance of first caret to NormalNotShown when it becomes invisible.
layout/base/AccessibleCaretManager.cpp
--- a/layout/base/AccessibleCaretManager.cpp
+++ b/layout/base/AccessibleCaretManager.cpp
@@ -134,33 +134,45 @@ AccessibleCaretManager::UpdateCaretsForC
   }
 
   Element* editingHost = frame->GetContent()->GetEditingHost();
   if (!editingHost) {
     HideCarets();
     return;
   }
 
-  // No need to consider whether the caret's position is out of scrollport.
-  // According to the spec, we need to explicitly hide it after the scrolling is
-  // ended.
   bool oldSecondCaretVisible = mSecondCaret->IsLogicallyVisible();
-  PositionChangedResult caretResult = mFirstCaret->SetPosition(frame, offset);
+  PositionChangedResult result = mFirstCaret->SetPosition(frame, offset);
+
+  switch (result) {
+    case PositionChangedResult::NotChanged:
+      // Do nothing
+      break;
+
+    case PositionChangedResult::Changed:
+      if (nsContentUtils::HasNonEmptyTextContent(
+            editingHost, nsContentUtils::eRecurseIntoChildren)) {
+        mFirstCaret->SetAppearance(Appearance::Normal);
+      } else {
+        mFirstCaret->SetAppearance(Appearance::NormalNotShown);
+      }
+      break;
+
+    case PositionChangedResult::Invisible:
+      mFirstCaret->SetAppearance(Appearance::NormalNotShown);
+      break;
+  }
+
   mFirstCaret->SetSelectionBarEnabled(false);
-  if (nsContentUtils::HasNonEmptyTextContent(
-        editingHost, nsContentUtils::eRecurseIntoChildren)) {
-    mFirstCaret->SetAppearance(Appearance::Normal);
-  } else {
-    mFirstCaret->SetAppearance(Appearance::NormalNotShown);
-  }
-  LaunchCaretTimeoutTimer();
   mSecondCaret->SetAppearance(Appearance::None);
 
-  if ((caretResult == PositionChangedResult::Changed ||
-      oldSecondCaretVisible) && !mActiveCaret) {
+  LaunchCaretTimeoutTimer();
+
+  if ((result != PositionChangedResult::NotChanged || oldSecondCaretVisible) &&
+      !mActiveCaret) {
     DispatchCaretStateChangedEvent(CaretChangedReason::Updateposition);
   }
 }
 
 void
 AccessibleCaretManager::UpdateCaretsForSelectionMode()
 {
   AC_LOG("%s, selection: %p", __FUNCTION__, GetSelection());