Bug 1425412 - part 3: Create CreateElementTransaction::Create() and remove EditorBase::CreateTxnForCreateElement() r?m_kato draft
authorMasayuki Nakano <masayuki@d-toybox.com>
Fri, 15 Dec 2017 17:54:10 +0900
changeset 712696 c4d26f2f8269c16f015dae68f63bf1a6b3404f20
parent 712695 9e937b7e951c4aea13db46d7995070b8937db97c
child 712697 341eb8b645d535e11303fdf1386a6fbab3f3e3b0
push id93397
push usermasayuki@d-toybox.com
push dateMon, 18 Dec 2017 16:25:33 +0000
reviewersm_kato
bugs1425412
milestone59.0a1
Bug 1425412 - part 3: Create CreateElementTransaction::Create() and remove EditorBase::CreateTxnForCreateElement() r?m_kato EditorBase::CreateTxnForCreateElement() just hides what it does. Let's make the caller what it does with creating CreateElementTransaction::Create(). MozReview-Commit-ID: DYcfQV6KiUZ
editor/libeditor/CreateElementTransaction.cpp
editor/libeditor/CreateElementTransaction.h
editor/libeditor/EditorBase.cpp
editor/libeditor/EditorBase.h
--- a/editor/libeditor/CreateElementTransaction.cpp
+++ b/editor/libeditor/CreateElementTransaction.cpp
@@ -27,16 +27,26 @@
 #include "nsReadableUtils.h"
 #include "nsStringFwd.h"
 #include "nsString.h"
 
 namespace mozilla {
 
 using namespace dom;
 
+already_AddRefed<CreateElementTransaction>
+CreateElementTransaction::Create(EditorBase& aEditorBase,
+                                 nsAtom& aTag,
+                                 const EditorRawDOMPoint& aPointToInsert)
+{
+  RefPtr<CreateElementTransaction> transaction =
+    new CreateElementTransaction(aEditorBase, aTag, aPointToInsert);
+  return transaction.forget();
+}
+
 CreateElementTransaction::CreateElementTransaction(
                             EditorBase& aEditorBase,
                             nsAtom& aTag,
                             const EditorRawDOMPoint& aPointToInsert)
   : EditTransactionBase()
   , mEditorBase(&aEditorBase)
   , mTag(&aTag)
   , mPointToInsert(aPointToInsert)
--- a/editor/libeditor/CreateElementTransaction.h
+++ b/editor/libeditor/CreateElementTransaction.h
@@ -23,29 +23,37 @@ namespace mozilla {
 
 class EditorBase;
 namespace dom {
 class Element;
 } // namespace dom
 
 class CreateElementTransaction final : public EditTransactionBase
 {
+protected:
+  CreateElementTransaction(EditorBase& aEditorBase,
+                           nsAtom& aTag,
+                           const EditorRawDOMPoint& aPointToInsert);
+
 public:
   /**
-   * Initialize the transaction.
-   * @param aEditorBase     The provider of basic editing functionality.
+   * Create a transaction for creating a new child node of the container of
+   * aPointToInsert of type aTag.
+   *
+   * @param aEditorBase     The editor which manages the transaction.
    * @param aTag            The tag (P, HR, TABLE, etc.) for the new element.
    * @param aPointToInsert  The new node will be inserted before the child at
    *                        aPointToInsert.  If this refers end of the container
    *                        or after, the new node will be appended to the
    *                        container.
    */
-  CreateElementTransaction(EditorBase& aEditorBase,
-                           nsAtom& aTag,
-                           const EditorRawDOMPoint& aPointToInsert);
+  static already_AddRefed<CreateElementTransaction>
+  Create(EditorBase& aEditorBase,
+         nsAtom& aTag,
+         const EditorRawDOMPoint& aPointToInsert);
 
   NS_DECL_ISUPPORTS_INHERITED
   NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(CreateElementTransaction,
                                            EditTransactionBase)
 
   NS_DECL_EDITTRANSACTIONBASE
 
   NS_IMETHOD RedoTransaction() override;
--- a/editor/libeditor/EditorBase.cpp
+++ b/editor/libeditor/EditorBase.cpp
@@ -1436,17 +1436,17 @@ EditorBase::CreateNode(nsAtom* aTag,
       listener->WillCreateNode(nsDependentAtomString(aTag),
                                GetAsDOMNode(pointToInsert.GetChild()));
     }
   }
 
   nsCOMPtr<Element> ret;
 
   RefPtr<CreateElementTransaction> transaction =
-    CreateTxnForCreateElement(*aTag, pointToInsert);
+    CreateElementTransaction::Create(*this, *aTag, pointToInsert);
   nsresult rv = DoTransaction(transaction);
   if (NS_SUCCEEDED(rv)) {
     ret = transaction->GetNewNode();
     MOZ_ASSERT(ret);
     // Now, aPointToInsert may be invalid.  I.e., GetChild() keeps
     // referring the next sibling of new node but Offset() refers the
     // new node.  Let's make refer the new node.
     pointToInsert.Set(ret);
@@ -4633,26 +4633,16 @@ EditorBase::CreateTxnForRemoveAttribute(
                                         nsAtom& aAttribute)
 {
   RefPtr<ChangeAttributeTransaction> transaction =
     new ChangeAttributeTransaction(aElement, aAttribute, nullptr);
 
   return transaction.forget();
 }
 
-already_AddRefed<CreateElementTransaction>
-EditorBase::CreateTxnForCreateElement(nsAtom& aTag,
-                                      const EditorRawDOMPoint& aPointToInsert)
-{
-  RefPtr<CreateElementTransaction> transaction =
-    new CreateElementTransaction(*this, aTag, 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
@@ -514,33 +514,16 @@ 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 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 was initialized
-   *                        with the arguments.
-   */
-  already_AddRefed<CreateElementTransaction>
-    CreateTxnForCreateElement(nsAtom& aTag,
-                              const EditorRawDOMPoint& aPointToInsert);
-
-  /**
    * Create an element node whose name is aTag at before aPointToInsert.  When
    * this succeed to create an element node, this sets aPointToInsert to the
    * new element because the relation of child and offset may be broken.
    * If the caller needs to collapse the selection to next to the new element
    * node, it should call |aPointToInsert.AdvanceOffset()| after calling this.
    *
    * @param aTag            The element name to create.
    * @param aPointToInsert  The insertion point of new element.  If this refers