Bug 1314790 - Part 1. GetGoodSelPointForNode doesn't work with ePrevousWord action. r=masayuki, a=gchang
authorMakoto Kato <m_kato@ga2.so-net.ne.jp>
Sat, 12 Nov 2016 21:59:04 +0900
changeset 352646 86def315a57917729644cd22f6c78e900145e49a
parent 352645 287a87843f93f402f1bf4292ad4d28be98fe930a
child 352647 7b4599e0220c20eb60f3431916b89cb874d65990
push id6795
push userjlund@mozilla.com
push dateMon, 23 Jan 2017 14:19:46 +0000
treeherdermozilla-esr52@76101b503191 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmasayuki, gchang
bugs1314790
milestone52.0a2
Bug 1314790 - Part 1. GetGoodSelPointForNode doesn't work with ePrevousWord action. r=masayuki, a=gchang Although GetGoodSelPointForNode only supports ePrevious or eNext as action, we use other action. So we should add aseetion for it. MozReview-Commit-ID: 3gLFFTAdNxU
editor/libeditor/HTMLEditRules.cpp
--- a/editor/libeditor/HTMLEditRules.cpp
+++ b/editor/libeditor/HTMLEditRules.cpp
@@ -2506,37 +2506,47 @@ HTMLEditRules::InsertBRIfNeeded(Selectio
 }
 
 /**
  * GetGoodSelPointForNode() finds where at a node you would want to set the
  * selection if you were trying to have a caret next to it.  Always returns a
  * valid value (unless mHTMLEditor has gone away).
  *
  * @param aNode         The node
- * @param aAction       Which edge to find: eNext indicates beginning,
- *                      ePrevious ending.
+ * @param aAction       Which edge to find:
+ *                        eNext/eNextWord/eToEndOfLine indicates beginning,
+ *                        ePrevious/PreviousWord/eToBeginningOfLine ending.
  */
 EditorDOMPoint
 HTMLEditRules::GetGoodSelPointForNode(nsINode& aNode,
                                       nsIEditor::EDirection aAction)
 {
+  MOZ_ASSERT(aAction == nsIEditor::eNext ||
+             aAction == nsIEditor::eNextWord ||
+             aAction == nsIEditor::ePrevious ||
+             aAction == nsIEditor::ePreviousWord ||
+             aAction == nsIEditor::eToBeginningOfLine ||
+             aAction == nsIEditor::eToEndOfLine);
+
+  bool isPreviousAction = (aAction == nsIEditor::ePrevious ||
+                           aAction == nsIEditor::ePreviousWord ||
+                           aAction == nsIEditor::eToBeginningOfLine);
+
   NS_ENSURE_TRUE(mHTMLEditor, EditorDOMPoint());
   if (aNode.GetAsText() || mHTMLEditor->IsContainer(&aNode) ||
       NS_WARN_IF(!aNode.GetParentNode())) {
-    return EditorDOMPoint(&aNode,
-                          aAction == nsIEditor::ePrevious ? aNode.Length() : 0);
+    return EditorDOMPoint(&aNode, isPreviousAction ? aNode.Length() : 0);
   }
 
   EditorDOMPoint ret;
   ret.node = aNode.GetParentNode();
   ret.offset = ret.node ? ret.node->IndexOf(&aNode) : -1;
   NS_ENSURE_TRUE(mHTMLEditor, EditorDOMPoint());
   if ((!aNode.IsHTMLElement(nsGkAtoms::br) ||
-       mHTMLEditor->IsVisBreak(&aNode)) &&
-      aAction == nsIEditor::ePrevious) {
+       mHTMLEditor->IsVisBreak(&aNode)) && isPreviousAction) {
     ret.offset++;
   }
   return ret;
 }
 
 
 /**
  * This method is used to join two block elements.  The right element is always
@@ -4837,42 +4847,47 @@ HTMLEditRules::CheckForEmptyBlock(nsINod
           // Adjust selection to be right before it
           rv = aSelection->Collapse(listParent, listOffset);
           NS_ENSURE_SUCCESS(rv, rv);
         }
         // Else just let selection percolate up.  We'll adjust it in
         // AfterEdit()
       }
     } else {
-      if (aAction == nsIEditor::eNext) {
+      if (aAction == nsIEditor::eNext || aAction == nsIEditor::eNextWord ||
+          aAction == nsIEditor::eToEndOfLine) {
         // Move to the start of the next node, if any
         nsCOMPtr<nsIContent> nextNode = htmlEditor->GetNextNode(blockParent,
                                                                 offset + 1, true);
         if (nextNode) {
           EditorDOMPoint pt = GetGoodSelPointForNode(*nextNode, aAction);
           nsresult rv = aSelection->Collapse(pt.node, pt.offset);
           NS_ENSURE_SUCCESS(rv, rv);
         } else {
           // Adjust selection to be right after it.
           nsresult rv = aSelection->Collapse(blockParent, offset + 1);
           NS_ENSURE_SUCCESS(rv, rv);
         }
-      } else {
+      } else if (aAction == nsIEditor::ePrevious ||
+                 aAction == nsIEditor::ePreviousWord ||
+                 aAction == nsIEditor::eToBeginningOfLine) {
         // Move to the end of the previous node
         nsCOMPtr<nsIContent> priorNode = htmlEditor->GetPriorNode(blockParent,
                                                                   offset,
                                                                   true);
         if (priorNode) {
           EditorDOMPoint pt = GetGoodSelPointForNode(*priorNode, aAction);
           nsresult rv = aSelection->Collapse(pt.node, pt.offset);
           NS_ENSURE_SUCCESS(rv, rv);
         } else {
           nsresult rv = aSelection->Collapse(blockParent, offset + 1);
           NS_ENSURE_SUCCESS(rv, rv);
         }
+      } else {
+        NS_RUNTIMEABORT("CheckForEmptyBlock doesn't support this action yet");
       }
     }
     NS_ENSURE_STATE(htmlEditor);
     *aHandled = true;
     nsresult rv = htmlEditor->DeleteNode(emptyBlock);
     NS_ENSURE_SUCCESS(rv, rv);
   }
   return NS_OK;