Bug 1345690 part.4 Rename JoinNodeTransaction::CheckValidity() to JoinNodeTransaction::CanDoIt() for consistency with other transaction classes r?m_kato
MozReview-Commit-ID: 3a5QXiofEL2
--- a/editor/libeditor/EditorBase.cpp
+++ b/editor/libeditor/EditorBase.cpp
@@ -2737,22 +2737,24 @@ EditorBase::CreateTxnForSplitNode(nsICon
new SplitNodeTransaction(*this, aNode, aOffset);
return transaction.forget();
}
already_AddRefed<JoinNodeTransaction>
EditorBase::CreateTxnForJoinNode(nsINode& aLeftNode,
nsINode& aRightNode)
{
- RefPtr<JoinNodeTransaction> transaction =
+ RefPtr<JoinNodeTransaction> joinNodeTransaction =
new JoinNodeTransaction(*this, aLeftNode, aRightNode);
-
- NS_ENSURE_SUCCESS(transaction->CheckValidity(), nullptr);
-
- return transaction.forget();
+ // 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;
nsCOMPtr<nsINode> mStartNode;
nsCOMPtr<nsINode> mEndNode;
int32_t mStartOffset;
--- a/editor/libeditor/JoinNodeTransaction.cpp
+++ b/editor/libeditor/JoinNodeTransaction.cpp
@@ -31,23 +31,25 @@ JoinNodeTransaction::JoinNodeTransaction
NS_IMPL_CYCLE_COLLECTION_INHERITED(JoinNodeTransaction, EditTransactionBase,
mLeftNode,
mRightNode,
mParent)
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(JoinNodeTransaction)
NS_INTERFACE_MAP_END_INHERITING(EditTransactionBase)
-nsresult
-JoinNodeTransaction::CheckValidity()
+bool
+JoinNodeTransaction::CanDoIt() const
{
- if (!mEditorBase.IsModifiableNode(mLeftNode->GetParentNode())) {
- return NS_ERROR_FAILURE;
+ if (NS_WARN_IF(!mLeftNode) ||
+ NS_WARN_IF(!mRightNode) ||
+ !mLeftNode->GetParentNode()) {
+ return false;
}
- return NS_OK;
+ return mEditorBase.IsModifiableNode(mLeftNode->GetParentNode());
}
// After DoTransaction() and RedoTransaction(), the left node is removed from
// the content tree and right node remains.
NS_IMETHODIMP
JoinNodeTransaction::DoTransaction()
{
// Get the parent node
--- a/editor/libeditor/JoinNodeTransaction.h
+++ b/editor/libeditor/JoinNodeTransaction.h
@@ -31,19 +31,20 @@ public:
* @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);
/**
- * Call this after constructing to ensure the inputs are correct.
+ * CanDoIt() returns true if there are enough members and can join or
+ * restore the nodes. Otherwise, false.
*/
- nsresult CheckValidity();
+ bool CanDoIt() const;
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(JoinNodeTransaction,
EditTransactionBase)
NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr) override;
NS_DECL_EDITTRANSACTIONBASE
protected: