Bug 1467690 - Make HTMLEditor use MaybeCollapseSelectionAtFirstEditableNode(false) instead of BeginningOfDocument() r?m_kato draft
authorMasayuki Nakano <masayuki@d-toybox.com>
Tue, 05 Jun 2018 21:18:05 +0900
changeset 805642 d387662706750000bcd658dee27d470266182ec5
parent 805551 ea21bf3e665d10066b6dce39873de9b353a12e57
child 805643 96ba8e87cee72a7d01d901ef030ffe7724b6217c
push id112724
push usermasayuki@d-toybox.com
push dateFri, 08 Jun 2018 07:25:52 +0000
reviewersm_kato
bugs1467690
milestone62.0a1
Bug 1467690 - Make HTMLEditor use MaybeCollapseSelectionAtFirstEditableNode(false) instead of BeginningOfDocument() r?m_kato HTMLEditor::BeginningOfDocument() is an XPCOM method and it just calls MaybeCollapseSelectionAtFirstEditableNode(false). So, HTMLEditor can call MaybeCollapseSelectionAtFirstEditableNode(false) directly.
editor/libeditor/HTMLEditor.cpp
--- a/editor/libeditor/HTMLEditor.cpp
+++ b/editor/libeditor/HTMLEditor.cpp
@@ -1440,17 +1440,17 @@ HTMLEditor::RebuildDocumentFromSource(co
 
     RefPtr<Element> divElement =
       CreateElementWithDefaults(NS_LITERAL_STRING("div"));
     if (NS_WARN_IF(!divElement)) {
       return NS_ERROR_FAILURE;
     }
     CloneAttributesWithTransaction(*rootElement, *divElement);
 
-    return BeginningOfDocument();
+    return MaybeCollapseSelectionAtFirstEditableNode(false);
   }
 
   rv = LoadHTML(Substring(beginbody, endtotal));
   NS_ENSURE_SUCCESS(rv, rv);
 
   // Now we must copy attributes user might have edited on the <body> tag
   // because InsertHTML (actually, CreateContextualFragment()) will never
   // return a body node in the DOM fragment
@@ -1480,17 +1480,17 @@ HTMLEditor::RebuildDocumentFromSource(co
 
   nsCOMPtr<nsIContent> child = docfrag->GetFirstChild();
   NS_ENSURE_TRUE(child && child->IsElement(), NS_ERROR_NULL_POINTER);
 
   // Copy all attributes from the div child to current body element
   CloneAttributesWithTransaction(*rootElement, *child->AsElement());
 
   // place selection at first editable content
-  return BeginningOfDocument();
+  return MaybeCollapseSelectionAtFirstEditableNode(false);
 }
 
 EditorRawDOMPoint
 HTMLEditor::GetBetterInsertionPointFor(nsINode& aNodeToInsert,
                                        const EditorRawDOMPoint& aPointToInsert)
 {
   if (NS_WARN_IF(!aPointToInsert.IsSet())) {
     return aPointToInsert;
@@ -4959,17 +4959,17 @@ HTMLEditor::NotifyRootChanged()
     return;
   }
 
   UpdateRootElement();
   if (!mRootElement) {
     return;
   }
 
-  rv = BeginningOfDocument();
+  rv = MaybeCollapseSelectionAtFirstEditableNode(false);
   if (NS_FAILED(rv)) {
     return;
   }
 
   // When this editor has focus, we need to reset the selection limiter to
   // new root.  Otherwise, that is going to be done when this gets focus.
   nsCOMPtr<nsINode> node = GetFocusedNode();
   if (node) {