Bug 1425412 - part 7: Create SplitNodeTransaction::Create() and remove EditorBase::CreateTxnForSplitNode() r=m_kato

SplitNodeTransaction::Create() just hides what it does.  For making its caller
clearer, let's create a factory method, SplitNodeTransaction::Create().

MozReview-Commit-ID: KDiC8dDrLuQ

--HG--
extra : rebase_source : ac04544e10644b8a73375fb2b786e0bc86eb56ae
This commit is contained in:
Masayuki Nakano 2017-12-15 21:37:23 +09:00
parent 015555162f
commit 2b43d139dd
4 changed files with 24 additions and 27 deletions

View File

@ -1571,12 +1571,14 @@ EditorBase::SplitNode(const EditorRawDOMPoint& aStartOfRightNode,
}
RefPtr<SplitNodeTransaction> transaction =
CreateTxnForSplitNode(aStartOfRightNode);
SplitNodeTransaction::Create(*this, aStartOfRightNode);
aError = DoTransaction(transaction);
nsCOMPtr<nsIContent> newNode = transaction->GetNewNode();
NS_WARNING_ASSERTION(newNode, "Failed to create a new left node");
// XXX Some other transactions manage range updater by themselves.
// Why doesn't SplitNodeTransaction do it?
mRangeUpdater.SelAdjSplitNode(*aStartOfRightNode.GetContainerAsContent(),
newNode);
@ -3043,15 +3045,6 @@ EditorBase::DeleteText(nsGenericDOMDataNode& aCharData,
return rv;
}
already_AddRefed<SplitNodeTransaction>
EditorBase::CreateTxnForSplitNode(const EditorRawDOMPoint& aStartOfRightNode)
{
MOZ_ASSERT(aStartOfRightNode.IsSetAndValid());
RefPtr<SplitNodeTransaction> transaction =
new SplitNodeTransaction(*this, aStartOfRightNode);
return transaction.forget();
}
already_AddRefed<JoinNodeTransaction>
EditorBase::CreateTxnForJoinNode(nsINode& aLeftNode,
nsINode& aRightNode)

View File

@ -590,21 +590,6 @@ protected:
nsresult DeleteText(nsGenericDOMDataNode& aElement,
uint32_t aOffset, uint32_t aLength);
/**
* CreateTxnForSplitNode() creates a transaction to create a new node
* (left node) identical to an existing node (right node), and split the
* contents between the same point in both nodes.
*
* @param aStartOfRightNode The point to split. Its container will be
* the right node, i.e., become the new node's
* next sibling. And the point will be start
* of the right node.
* @return The new transaction to split the container of
* aStartOfRightNode.
*/
already_AddRefed<SplitNodeTransaction>
CreateTxnForSplitNode(const EditorRawDOMPoint& aStartOfRightNode);
already_AddRefed<JoinNodeTransaction>
CreateTxnForJoinNode(nsINode& aLeftNode, nsINode& aRightNode);

View File

@ -17,6 +17,16 @@ namespace mozilla {
using namespace dom;
// static
already_AddRefed<SplitNodeTransaction>
SplitNodeTransaction::Create(EditorBase& aEditorBase,
const EditorRawDOMPoint& aStartOfRightNode)
{
RefPtr<SplitNodeTransaction> transaction =
new SplitNodeTransaction(aEditorBase, aStartOfRightNode);
return transaction.forget();
}
SplitNodeTransaction::SplitNodeTransaction(
EditorBase& aEditorBase,
const EditorRawDOMPoint& aStartOfRightNode)

View File

@ -26,16 +26,25 @@ class EditorBase;
*/
class SplitNodeTransaction final : public EditTransactionBase
{
private:
SplitNodeTransaction(EditorBase& aEditorBase,
const EditorRawDOMPoint& aStartOfRightNode);
public:
/**
* Creates a transaction to create a new node (left node) identical to an
* existing node (right node), and split the contents between the same point
* in both nodes.
*
* @param aEditorBase The provider of core editing operations.
* @param aStartOfRightNode The point to split. Its container will be
* the right node, i.e., become the new node's
* next sibling. And the point will be start
* of the right node.
*/
SplitNodeTransaction(EditorBase& aEditorBase,
const EditorRawDOMPoint& aStartOfRightNode);
static already_AddRefed<SplitNodeTransaction>
Create(EditorBase& aEditorBase,
const EditorRawDOMPoint& aStartOfRightNode);
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(SplitNodeTransaction,