Bug 1121468 - Show carets when long-pressing on selection highlight. r?roc draft
authorTing-Yu Lin <tlin@mozilla.com>
Mon, 25 Jan 2016 15:50:28 +0800
changeset 324963 320486797e9042131e321f4ae52d4410242361ec
parent 324962 32e35c161859990b3ef463d04792616f4f899d23
child 324964 cda6c30b61dd517b5ff901a39a03c398215de366
push id9958
push usertlin@mozilla.com
push dateMon, 25 Jan 2016 09:46:52 +0000
reviewersroc
bugs1121468
milestone46.0a1
Bug 1121468 - Show carets when long-pressing on selection highlight. r?roc The blur event will hide the carets and produces a standalone selection highlight without carets. When a user long-pressing on the highlight, we should show carets for the original selection highlight instead of select a new word. The helper UpdateCaretsWithHapticFeedback() should only be needed when long-pressing. It should suffice to live within SelectWordOrShortcut() instead of being a member function.
layout/base/AccessibleCaretManager.cpp
--- a/layout/base/AccessibleCaretManager.cpp
+++ b/layout/base/AccessibleCaretManager.cpp
@@ -451,16 +451,21 @@ AccessibleCaretManager::TapCaret(const n
   }
 
   return rv;
 }
 
 nsresult
 AccessibleCaretManager::SelectWordOrShortcut(const nsPoint& aPoint)
 {
+  auto UpdateCaretsWithHapticFeedback = [this] {
+    UpdateCarets();
+    ProvideHapticFeedback();
+  };
+
   if (!mPresShell) {
     return NS_ERROR_UNEXPECTED;
   }
 
   nsIFrame* rootFrame = mPresShell->GetRootFrame();
   if (!rootFrame) {
     return NS_ERROR_NOT_AVAILABLE;
   }
@@ -483,18 +488,17 @@ AccessibleCaretManager::SelectWordOrShor
 
   // Firstly check long press on an empty editable content.
   Element* newFocusEditingHost = GetEditingHostForFrame(ptFrame);
   if (focusableFrame && newFocusEditingHost &&
       !HasNonEmptyTextContent(newFocusEditingHost)) {
     ChangeFocusToOrClearOldFocus(focusableFrame);
     // We need to update carets to get correct information before dispatching
     // CaretStateChangedEvent.
-    UpdateCarets();
-    ProvideHapticFeedback();
+    UpdateCaretsWithHapticFeedback();
     DispatchCaretStateChangedEvent(CaretChangedReason::Longpressonemptycontent);
     return NS_OK;
   }
 
   bool selectable = false;
   ptFrame->IsSelectable(&selectable, nullptr);
 
 #ifdef DEBUG_FRAME_DUMP
@@ -509,23 +513,32 @@ AccessibleCaretManager::SelectWordOrShor
   // Commit the composition string of the old editable focus element (if there
   // is any) before changing the focus.
   IMEStateManager::NotifyIME(widget::REQUEST_TO_COMMIT_COMPOSITION,
                              mPresShell->GetPresContext());
 
   // ptFrame is selectable. Now change the focus.
   ChangeFocusToOrClearOldFocus(focusableFrame);
 
+  if (GetCaretMode() == CaretMode::Selection &&
+      !mFirstCaret->IsLogicallyVisible() && !mSecondCaret->IsLogicallyVisible()) {
+    // We have a selection while both carets have Appearance::None because of
+    // previous operations like blur event. Just update carets on the selection
+    // without selecting a new word.
+    AC_LOG("%s: UpdateCarets() for current selection", __FUNCTION__);
+    UpdateCaretsWithHapticFeedback();
+    return NS_OK;
+  }
+
   // Then try select a word under point.
   nsPoint ptInFrame = aPoint;
   nsLayoutUtils::TransformPoint(rootFrame, ptFrame, ptInFrame);
 
   nsresult rv = SelectWord(ptFrame, ptInFrame);
-  UpdateCarets();
-  ProvideHapticFeedback();
+  UpdateCaretsWithHapticFeedback();
 
   return rv;
 }
 
 void
 AccessibleCaretManager::OnScrollStart()
 {
   AC_LOG("%s", __FUNCTION__);