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
--- 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