Bug 1425412 - part 2: Create InsertNodeTransaction::Create() and remove EditorBase::CreateTxnForInsertNode() r?m_kato draft
authorMasayuki Nakano <masayuki@d-toybox.com>
Fri, 15 Dec 2017 17:34:52 +0900
changeset 712695 9e937b7e951c4aea13db46d7995070b8937db97c
parent 712694 67a745f7ad618507c7aee8b26567aa16cd04598a
child 712696 c4d26f2f8269c16f015dae68f63bf1a6b3404f20
push id93397
push usermasayuki@d-toybox.com
push dateMon, 18 Dec 2017 16:25:33 +0000
reviewersm_kato
bugs1425412
milestone59.0a1
Bug 1425412 - part 2: Create InsertNodeTransaction::Create() and remove EditorBase::CreateTxnForInsertNode() r?m_kato EditorBase::CreateTxnForInsertNode() just hides what it does. Let's create InsertNodeTransaction::Create() and make the caller clearer. MozReview-Commit-ID: 2J2WV73cdsm
editor/libeditor/EditorBase.cpp
editor/libeditor/EditorBase.h
editor/libeditor/InsertNodeTransaction.cpp
editor/libeditor/InsertNodeTransaction.h
--- a/editor/libeditor/EditorBase.cpp
+++ b/editor/libeditor/EditorBase.cpp
@@ -1500,17 +1500,17 @@ EditorBase::InsertNode(nsIContent& aCont
     for (auto& listener : listeners) {
       listener->WillInsertNode(
                   aContentToInsert.AsDOMNode(),
                   GetAsDOMNode(aPointToInsert.GetNextSiblingOfChild()));
     }
   }
 
   RefPtr<InsertNodeTransaction> transaction =
-    CreateTxnForInsertNode(aContentToInsert, aPointToInsert);
+    InsertNodeTransaction::Create(*this, aContentToInsert, aPointToInsert);
   nsresult rv = DoTransaction(transaction);
 
   mRangeUpdater.SelAdjInsertNode(aPointToInsert.GetContainer(),
                                  aPointToInsert.Offset());
 
   {
     AutoActionListenerArray listeners(mActionListeners);
     for (auto& listener : listeners) {
@@ -4643,26 +4643,16 @@ EditorBase::CreateTxnForCreateElement(ns
                                       const EditorRawDOMPoint& aPointToInsert)
 {
   RefPtr<CreateElementTransaction> transaction =
     new CreateElementTransaction(*this, aTag, aPointToInsert);
 
   return transaction.forget();
 }
 
-
-already_AddRefed<InsertNodeTransaction>
-EditorBase::CreateTxnForInsertNode(nsIContent& aNode,
-                                   const EditorRawDOMPoint& aPointToInsert)
-{
-  RefPtr<InsertNodeTransaction> transaction =
-    new InsertNodeTransaction(*this, aNode, aPointToInsert);
-  return transaction.forget();
-}
-
 already_AddRefed<DeleteNodeTransaction>
 EditorBase::CreateTxnForDeleteNode(nsINode* aNode)
 {
   if (NS_WARN_IF(!aNode)) {
     return nullptr;
   }
 
   RefPtr<DeleteNodeTransaction> deleteNodeTransaction =
--- a/editor/libeditor/EditorBase.h
+++ b/editor/libeditor/EditorBase.h
@@ -549,33 +549,16 @@ protected:
    *                        Otherwise, will insert the element before the
    *                        child node referred by this.
    * @return                The created new element node.
    */
   already_AddRefed<Element> CreateNode(nsAtom* aTag,
                                        const EditorRawDOMPoint& aPointToInsert);
 
   /**
-   * Create a transaction for inserting aContentToInsert before the child
-   * at aPointToInsert.
-   *
-   * @param aContentToInsert    The node to be inserted.
-   * @param aPointToInsert      The insertion point of aContentToInsert.
-   *                            If this refers end of the container, the
-   *                            transaction will append the node to the
-   *                            container.  Otherwise, will insert the node
-   *                            before child node referred by this.
-   * @return                    A InsertNodeTranaction which was initialized
-   *                            with the arguments.
-   */
-  already_AddRefed<InsertNodeTransaction>
-    CreateTxnForInsertNode(nsIContent& aContentToInsert,
-                           const EditorRawDOMPoint& aPointToInsert);
-
-  /**
    * Create a transaction for removing aNode from its parent.
    */
   already_AddRefed<DeleteNodeTransaction>
     CreateTxnForDeleteNode(nsINode* aNode);
 
   /**
    * Create an aggregate transaction for delete selection.  The result may
    * include DeleteNodeTransactions and/or DeleteTextTransactions as its
--- a/editor/libeditor/InsertNodeTransaction.cpp
+++ b/editor/libeditor/InsertNodeTransaction.cpp
@@ -17,16 +17,27 @@
 #include "nsMemory.h"                   // for nsMemory
 #include "nsReadableUtils.h"            // for ToNewCString
 #include "nsString.h"                   // for nsString
 
 namespace mozilla {
 
 using namespace dom;
 
+// static
+already_AddRefed<InsertNodeTransaction>
+InsertNodeTransaction::Create(EditorBase& aEditorBase,
+                              nsIContent& aContentToInsert,
+                              const EditorRawDOMPoint& aPointToInsert)
+{
+  RefPtr<InsertNodeTransaction> transaction =
+    new InsertNodeTransaction(aEditorBase, aContentToInsert, aPointToInsert);
+  return transaction.forget();
+}
+
 InsertNodeTransaction::InsertNodeTransaction(
                          EditorBase& aEditorBase,
                          nsIContent& aContentToInsert,
                          const EditorRawDOMPoint& aPointToInsert)
   : mContentToInsert(&aContentToInsert)
   , mPointToInsert(aPointToInsert)
   , mEditorBase(&aEditorBase)
 {
--- a/editor/libeditor/InsertNodeTransaction.h
+++ b/editor/libeditor/InsertNodeTransaction.h
@@ -17,29 +17,42 @@ namespace mozilla {
 
 class EditorBase;
 
 /**
  * A transaction that inserts a single element
  */
 class InsertNodeTransaction final : public EditTransactionBase
 {
-public:
-  /**
-   * Initialize the transaction.
-   *
-   * @param aEditorBase         The editor.
-   * @param aContentToInsert    The node to insert.
-   * @param aPointToInsert      The node to insert into.  I.e., aContentToInsert
-   *                            will be inserted before the child at offset.
-   */
+protected:
   InsertNodeTransaction(EditorBase& aEditorBase,
                         nsIContent& aContentToInsert,
                         const EditorRawDOMPoint& aPointToInsert);
 
+public:
+  /**
+   * Create a transaction for inserting aContentToInsert before the child
+   * at aPointToInsert.
+   *
+   * @param aEditorBase         The editor which manages the transaction.
+   * @param aContentToInsert    The node to be inserted.
+   * @param aPointToInsert      The insertion point of aContentToInsert.
+   *                            If this refers end of the container, the
+   *                            transaction will append the node to the
+   *                            container.  Otherwise, will insert the node
+   *                            before child node referred by this.
+   * @return                    A InsertNodeTranaction which was initialized
+   *                            with the arguments.
+   */
+  static already_AddRefed<InsertNodeTransaction>
+  Create(EditorBase& aEditorBase,
+         nsIContent& aContentToInsert,
+         const EditorRawDOMPoint& aPointToInsert);
+
+
   NS_DECL_ISUPPORTS_INHERITED
   NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(InsertNodeTransaction,
                                            EditTransactionBase)
 
   NS_DECL_EDITTRANSACTIONBASE
 
 protected:
   virtual ~InsertNodeTransaction();