Bug 1425412 - part 8: Create JoinNodeTransaction::MaybeCreate() and remove EditorBase::CreateTxnForJoinNode() r=m_kato

EditorBase::CreateTxnForJoinNode() just hides what it does.
For making the caller clearer, let's create a factory method,
JoinNodeTransaction::MaybeCreate().

MozReview-Commit-ID: 8vADXdzMeuV

--HG--
extra : rebase_source : 6a281aff11bfa019c292d26cadd0cd29da12753f
This commit is contained in:
Masayuki Nakano 2017-12-15 21:53:08 +09:00
Родитель 2b43d139dd
Коммит f2369df116
4 изменённых файлов: 26 добавлений и 20 удалений

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

@ -1634,11 +1634,13 @@ EditorBase::JoinNodes(nsINode& aLeftNode,
nsresult rv = NS_OK;
RefPtr<JoinNodeTransaction> transaction =
CreateTxnForJoinNode(aLeftNode, aRightNode);
JoinNodeTransaction::MaybeCreate(*this, aLeftNode, aRightNode);
if (transaction) {
rv = DoTransaction(transaction);
}
// XXX Some other transactions manage range updater by themselves.
// Why doesn't JoinNodeTransaction do it?
mRangeUpdater.SelAdjJoinNodes(aLeftNode, aRightNode, *parent, offset,
(int32_t)oldLeftNodeLen);
@ -3045,20 +3047,6 @@ EditorBase::DeleteText(nsGenericDOMDataNode& aCharData,
return rv;
}
already_AddRefed<JoinNodeTransaction>
EditorBase::CreateTxnForJoinNode(nsINode& aLeftNode,
nsINode& aRightNode)
{
RefPtr<JoinNodeTransaction> joinNodeTransaction =
new JoinNodeTransaction(*this, aLeftNode, aRightNode);
// If it's not editable, the transaction shouldn't be recorded since it
// should never be undone/redone.
if (NS_WARN_IF(!joinNodeTransaction->CanDoIt())) {
return nullptr;
}
return joinNodeTransaction.forget();
}
struct SavedRange final
{
RefPtr<Selection> mSelection;

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

@ -590,9 +590,6 @@ protected:
nsresult DeleteText(nsGenericDOMDataNode& aElement,
uint32_t aOffset, uint32_t aLength);
already_AddRefed<JoinNodeTransaction>
CreateTxnForJoinNode(nsINode& aLeftNode, nsINode& aRightNode);
/**
* This method first deletes the selection, if it's not collapsed. Then if
* the selection lies in a CharacterData node, it splits it. If the

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

@ -18,6 +18,20 @@ namespace mozilla {
using namespace dom;
// static
already_AddRefed<JoinNodeTransaction>
JoinNodeTransaction::MaybeCreate(EditorBase& aEditorBase,
nsINode& aLeftNode,
nsINode& aRightNode)
{
RefPtr<JoinNodeTransaction> transaction =
new JoinNodeTransaction(aEditorBase, aLeftNode, aRightNode);
if (NS_WARN_IF(!transaction->CanDoIt())) {
return nullptr;
}
return transaction.forget();
}
JoinNodeTransaction::JoinNodeTransaction(EditorBase& aEditorBase,
nsINode& aLeftNode,
nsINode& aRightNode)

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

@ -26,14 +26,21 @@ class EditorBase;
*/
class JoinNodeTransaction final : public EditTransactionBase
{
protected:
JoinNodeTransaction(EditorBase& aEditorBase,
nsINode& aLeftNode, nsINode& aRightNode);
public:
/**
* Creates a join node transaction. This returns nullptr if cannot join the
* nodes.
*
* @param aEditorBase The provider of core editing operations.
* @param aLeftNode The first of two nodes to join.
* @param aRightNode The second of two nodes to join.
*/
JoinNodeTransaction(EditorBase& aEditorBase,
nsINode& aLeftNode, nsINode& aRightNode);
static already_AddRefed<JoinNodeTransaction>
MaybeCreate(EditorBase& aEditorBase, nsINode& aLeftNode, nsINode& aRightNode);
/**
* CanDoIt() returns true if there are enough members and can join or