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
Родитель 015555162f
Коммит 2b43d139dd
4 изменённых файлов: 24 добавлений и 27 удалений

Просмотреть файл

@ -1571,12 +1571,14 @@ EditorBase::SplitNode(const EditorRawDOMPoint& aStartOfRightNode,
} }
RefPtr<SplitNodeTransaction> transaction = RefPtr<SplitNodeTransaction> transaction =
CreateTxnForSplitNode(aStartOfRightNode); SplitNodeTransaction::Create(*this, aStartOfRightNode);
aError = DoTransaction(transaction); aError = DoTransaction(transaction);
nsCOMPtr<nsIContent> newNode = transaction->GetNewNode(); nsCOMPtr<nsIContent> newNode = transaction->GetNewNode();
NS_WARNING_ASSERTION(newNode, "Failed to create a new left node"); 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(), mRangeUpdater.SelAdjSplitNode(*aStartOfRightNode.GetContainerAsContent(),
newNode); newNode);
@ -3043,15 +3045,6 @@ EditorBase::DeleteText(nsGenericDOMDataNode& aCharData,
return rv; 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> already_AddRefed<JoinNodeTransaction>
EditorBase::CreateTxnForJoinNode(nsINode& aLeftNode, EditorBase::CreateTxnForJoinNode(nsINode& aLeftNode,
nsINode& aRightNode) nsINode& aRightNode)

Просмотреть файл

@ -590,21 +590,6 @@ protected:
nsresult DeleteText(nsGenericDOMDataNode& aElement, nsresult DeleteText(nsGenericDOMDataNode& aElement,
uint32_t aOffset, uint32_t aLength); 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> already_AddRefed<JoinNodeTransaction>
CreateTxnForJoinNode(nsINode& aLeftNode, nsINode& aRightNode); CreateTxnForJoinNode(nsINode& aLeftNode, nsINode& aRightNode);

Просмотреть файл

@ -17,6 +17,16 @@ namespace mozilla {
using namespace dom; 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( SplitNodeTransaction::SplitNodeTransaction(
EditorBase& aEditorBase, EditorBase& aEditorBase,
const EditorRawDOMPoint& aStartOfRightNode) const EditorRawDOMPoint& aStartOfRightNode)

Просмотреть файл

@ -26,16 +26,25 @@ class EditorBase;
*/ */
class SplitNodeTransaction final : public EditTransactionBase class SplitNodeTransaction final : public EditTransactionBase
{ {
private:
SplitNodeTransaction(EditorBase& aEditorBase,
const EditorRawDOMPoint& aStartOfRightNode);
public: 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 aEditorBase The provider of core editing operations.
* @param aStartOfRightNode The point to split. Its container will be * @param aStartOfRightNode The point to split. Its container will be
* the right node, i.e., become the new node's * the right node, i.e., become the new node's
* next sibling. And the point will be start * next sibling. And the point will be start
* of the right node. * of the right node.
*/ */
SplitNodeTransaction(EditorBase& aEditorBase, static already_AddRefed<SplitNodeTransaction>
const EditorRawDOMPoint& aStartOfRightNode); Create(EditorBase& aEditorBase,
const EditorRawDOMPoint& aStartOfRightNode);
NS_DECL_ISUPPORTS_INHERITED NS_DECL_ISUPPORTS_INHERITED
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(SplitNodeTransaction, NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(SplitNodeTransaction,