diff options
author | wolfbeast <mcwerewolf@gmail.com> | 2018-02-08 12:06:30 +0100 |
---|---|---|
committer | wolfbeast <mcwerewolf@gmail.com> | 2018-02-08 12:06:30 +0100 |
commit | 44cd9f2a915a4879371c5e0b059acc3e5a2378b0 (patch) | |
tree | 8cb1a4758b16d9caae55f525b73f5fca3824b4f7 /editor/libeditor/SplitNodeTransaction.cpp | |
parent | f8d1830b530cd553d788b3579d41725d35c4da7f (diff) | |
parent | b62fce0dc0c77a5788c331db32b3996e4020e2a5 (diff) | |
download | UXP-44cd9f2a915a4879371c5e0b059acc3e5a2378b0.tar UXP-44cd9f2a915a4879371c5e0b059acc3e5a2378b0.tar.gz UXP-44cd9f2a915a4879371c5e0b059acc3e5a2378b0.tar.lz UXP-44cd9f2a915a4879371c5e0b059acc3e5a2378b0.tar.xz UXP-44cd9f2a915a4879371c5e0b059acc3e5a2378b0.zip |
Merge branch 'ported-upstream'
Diffstat (limited to 'editor/libeditor/SplitNodeTransaction.cpp')
-rw-r--r-- | editor/libeditor/SplitNodeTransaction.cpp | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/editor/libeditor/SplitNodeTransaction.cpp b/editor/libeditor/SplitNodeTransaction.cpp index 113ff7a61..8965b5399 100644 --- a/editor/libeditor/SplitNodeTransaction.cpp +++ b/editor/libeditor/SplitNodeTransaction.cpp @@ -19,7 +19,7 @@ using namespace dom; SplitNodeTransaction::SplitNodeTransaction(EditorBase& aEditorBase, nsIContent& aNode, int32_t aOffset) - : mEditorBase(aEditorBase) + : mEditorBase(&aEditorBase) , mExistingRightNode(&aNode) , mOffset(aOffset) { @@ -30,6 +30,7 @@ SplitNodeTransaction::~SplitNodeTransaction() } NS_IMPL_CYCLE_COLLECTION_INHERITED(SplitNodeTransaction, EditTransactionBase, + mEditorBase, mParent, mNewLeftNode) @@ -41,6 +42,10 @@ NS_INTERFACE_MAP_END_INHERITING(EditTransactionBase) NS_IMETHODIMP SplitNodeTransaction::DoTransaction() { + if (NS_WARN_IF(!mEditorBase)) { + return NS_ERROR_NOT_INITIALIZED; + } + // Create a new node ErrorResult rv; // Don't use .downcast directly because AsContent has an assertion we want @@ -48,16 +53,16 @@ SplitNodeTransaction::DoTransaction() NS_ASSERTION(!rv.Failed() && clone, "Could not create clone"); NS_ENSURE_TRUE(!rv.Failed() && clone, rv.StealNSResult()); mNewLeftNode = dont_AddRef(clone.forget().take()->AsContent()); - mEditorBase.MarkNodeDirty(mExistingRightNode->AsDOMNode()); + mEditorBase->MarkNodeDirty(mExistingRightNode->AsDOMNode()); // Get the parent node mParent = mExistingRightNode->GetParentNode(); NS_ENSURE_TRUE(mParent, NS_ERROR_NULL_POINTER); // Insert the new node - rv = mEditorBase.SplitNodeImpl(*mExistingRightNode, mOffset, *mNewLeftNode); - if (mEditorBase.GetShouldTxnSetSelection()) { - RefPtr<Selection> selection = mEditorBase.GetSelection(); + rv = mEditorBase->SplitNodeImpl(*mExistingRightNode, mOffset, *mNewLeftNode); + if (mEditorBase->GetShouldTxnSetSelection()) { + RefPtr<Selection> selection = mEditorBase->GetSelection(); NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER); rv = selection->Collapse(mNewLeftNode, mOffset); } @@ -67,10 +72,14 @@ SplitNodeTransaction::DoTransaction() NS_IMETHODIMP SplitNodeTransaction::UndoTransaction() { - MOZ_ASSERT(mNewLeftNode && mParent); + if (NS_WARN_IF(!mEditorBase) || + NS_WARN_IF(!mNewLeftNode) || + NS_WARN_IF(!mParent)) { + return NS_ERROR_NOT_INITIALIZED; + } // This assumes Do inserted the new node in front of the prior existing node - return mEditorBase.JoinNodesImpl(mExistingRightNode, mNewLeftNode, mParent); + return mEditorBase->JoinNodesImpl(mExistingRightNode, mNewLeftNode, mParent); } /* Redo cannot simply resplit the right node, because subsequent transactions @@ -80,7 +89,10 @@ SplitNodeTransaction::UndoTransaction() NS_IMETHODIMP SplitNodeTransaction::RedoTransaction() { - MOZ_ASSERT(mNewLeftNode && mParent); + if (NS_WARN_IF(!mNewLeftNode) || + NS_WARN_IF(!mParent)) { + return NS_ERROR_NOT_INITIALIZED; + } ErrorResult rv; // First, massage the existing node so it is in its post-split state |