Bug 1415445 - part 2: EditorBase::CreateTxnForCreateElement() should take EditorRawDOMPoint for insertion point r=m_kato
authorMasayuki Nakano <masayuki@d-toybox.com>
Wed, 08 Nov 2017 17:23:28 +0900
changeset 444323 80b30e8921626614049932ad55b456829eb38828
parent 444322 ff1aff2fa5b6beb672dd91ac475cba5e627add12
child 444324 57ed7f0422124ea09e45dd8df7c14d4a0bc689f6
push id1618
push userCallek@gmail.com
push dateThu, 11 Jan 2018 17:45:48 +0000
treeherdermozilla-release@882ca853e05a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersm_kato
bugs1415445
milestone58.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 1415445 - part 2: EditorBase::CreateTxnForCreateElement() should take EditorRawDOMPoint for insertion point r=m_kato The constructor of CreateElementTransaction now takes EditorRawDOMPoint instead of a set of container node and offset in it. So, its only user, EditorBase::CreateTxnForCreateElement(), should take EditorRawDOMPoint too. MozReview-Commit-ID: A8QfPM3LRii
editor/libeditor/EditorBase.cpp
editor/libeditor/EditorBase.h
--- a/editor/libeditor/EditorBase.cpp
+++ b/editor/libeditor/EditorBase.cpp
@@ -1420,44 +1420,58 @@ EditorBase::SetSpellcheckUserOverride(bo
 already_AddRefed<Element>
 EditorBase::CreateNode(nsAtom* aTag,
                        nsINode* aParent,
                        int32_t aPosition,
                        nsIContent* aChildAtPosition)
 {
   MOZ_ASSERT(aTag && aParent);
 
+  EditorRawDOMPoint pointToInsert;
+  if (aPosition == -1) {
+    pointToInsert.Set(aParent, aParent->Length());
+  } else if (aChildAtPosition) {
+    pointToInsert.Set(aChildAtPosition);
+    // Ensure pointToInsert has offset for sending same offset for both
+    // WillCreateNode() and DidCreateNode().
+    Unused << pointToInsert.Offset();
+  } else {
+    pointToInsert.Set(aParent, aPosition);
+  }
+
   AutoRules beginRulesSniffing(this, EditAction::createNode, nsIEditor::eNext);
 
   {
     AutoActionListenerArray listeners(mActionListeners);
     for (auto& listener : listeners) {
       listener->WillCreateNode(nsDependentAtomString(aTag),
-                               GetAsDOMNode(aParent), aPosition);
+                               GetAsDOMNode(pointToInsert.Container()),
+                               pointToInsert.Offset());
     }
   }
 
   nsCOMPtr<Element> ret;
 
   RefPtr<CreateElementTransaction> transaction =
-    CreateTxnForCreateElement(*aTag, *aParent, aPosition,
-                              aChildAtPosition);
+    CreateTxnForCreateElement(*aTag, pointToInsert);
   nsresult rv = DoTransaction(transaction);
   if (NS_SUCCEEDED(rv)) {
     ret = transaction->GetNewNode();
     MOZ_ASSERT(ret);
   }
 
-  mRangeUpdater.SelAdjCreateNode(aParent, aPosition);
+  mRangeUpdater.SelAdjCreateNode(pointToInsert.Container(),
+                                 pointToInsert.Offset());
 
   {
     AutoActionListenerArray listeners(mActionListeners);
     for (auto& listener : listeners) {
       listener->DidCreateNode(nsDependentAtomString(aTag), GetAsDOMNode(ret),
-                              GetAsDOMNode(aParent), aPosition, rv);
+                              GetAsDOMNode(pointToInsert.Container()),
+                              pointToInsert.Offset(), rv);
     }
   }
 
   return ret.forget();
 }
 
 NS_IMETHODIMP
 EditorBase::InsertNode(nsIDOMNode* aNode,
@@ -4363,30 +4377,20 @@ EditorBase::CreateTxnForRemoveAttribute(
   RefPtr<ChangeAttributeTransaction> transaction =
     new ChangeAttributeTransaction(aElement, aAttribute, nullptr);
 
   return transaction.forget();
 }
 
 already_AddRefed<CreateElementTransaction>
 EditorBase::CreateTxnForCreateElement(nsAtom& aTag,
-                                      nsINode& aParent,
-                                      int32_t aPosition,
-                                      nsIContent* aChildAtPosition)
-{
-  EditorRawDOMPoint pointToInsert;
-  if (aPosition == -1) {
-    pointToInsert.Set(&aParent, aParent.Length());
-  } else if (aChildAtPosition) {
-    pointToInsert.Set(aChildAtPosition);
-  } else {
-    pointToInsert.Set(&aParent, aPosition);
-  }
+                                      const EditorRawDOMPoint& aPointToInsert)
+{
   RefPtr<CreateElementTransaction> transaction =
-    new CreateElementTransaction(*this, aTag, pointToInsert);
+    new CreateElementTransaction(*this, aTag, aPointToInsert);
 
   return transaction.forget();
 }
 
 
 already_AddRefed<InsertNodeTransaction>
 EditorBase::CreateTxnForInsertNode(nsIContent& aNode,
                                    nsINode& aParent,
--- a/editor/libeditor/EditorBase.h
+++ b/editor/libeditor/EditorBase.h
@@ -389,23 +389,31 @@ protected:
   /**
    * Create a transaction for removing aAttribute on aElement.  Never returns
    * null.
    */
   already_AddRefed<ChangeAttributeTransaction>
     CreateTxnForRemoveAttribute(Element& aElement, nsAtom& aAttribute);
 
   /**
-   * Create a transaction for creating a new child node of aParent of type aTag.
+   * Create a transaction for creating a new child node of the container of
+   * aPointToInsert of type aTag.
+   *
+   * @param aTag            The element name to create.
+   * @param aPointToInsert  The insertion point of new element.  If this refers
+   *                        end of the container or after, the transaction
+   *                        will append the element to the container.
+   *                        Otherwise, will insert the element before the
+   *                        child node referred by this.
+   * @return                A CreateElementTransaction which are initialized
+   *                        with the arguments.
    */
   already_AddRefed<CreateElementTransaction>
     CreateTxnForCreateElement(nsAtom& aTag,
-                              nsINode& aParent,
-                              int32_t aPosition,
-                              nsIContent* aChildAtPosition);
+                              const EditorRawDOMPoint& aPointToInsert);
 
   already_AddRefed<Element> CreateNode(nsAtom* aTag, nsINode* aParent,
                                        int32_t aPosition,
                                        nsIContent* aChildAtPosition = nullptr);
 
   /**
    * Create a transaction for inserting aNode as a child of aParent.
    */