summaryrefslogtreecommitdiffstats
path: root/editor/libeditor/CompositionTransaction.cpp
diff options
context:
space:
mode:
authorwolfbeast <mcwerewolf@gmail.com>2018-02-07 21:36:37 +0100
committerwolfbeast <mcwerewolf@gmail.com>2018-02-07 21:36:37 +0100
commitd773eca3316f2c99db9a1dd77929bcbd157eeacb (patch)
treebe0efc8413575e2db60480a9ba5991261929b144 /editor/libeditor/CompositionTransaction.cpp
parent1e55a5d9188b87da8632e217b238838effb1cdeb (diff)
downloadUXP-d773eca3316f2c99db9a1dd77929bcbd157eeacb.tar
UXP-d773eca3316f2c99db9a1dd77929bcbd157eeacb.tar.gz
UXP-d773eca3316f2c99db9a1dd77929bcbd157eeacb.tar.lz
UXP-d773eca3316f2c99db9a1dd77929bcbd157eeacb.tar.xz
UXP-d773eca3316f2c99db9a1dd77929bcbd157eeacb.zip
Edit transactions should store their editor instance with strong reference
Edit transactions should store their editor instance with a strong reference, and they should be released when the editor is destroyed.
Diffstat (limited to 'editor/libeditor/CompositionTransaction.cpp')
-rw-r--r--editor/libeditor/CompositionTransaction.cpp20
1 files changed, 16 insertions, 4 deletions
diff --git a/editor/libeditor/CompositionTransaction.cpp b/editor/libeditor/CompositionTransaction.cpp
index 25938fa60..bde53d2e5 100644
--- a/editor/libeditor/CompositionTransaction.cpp
+++ b/editor/libeditor/CompositionTransaction.cpp
@@ -33,7 +33,7 @@ CompositionTransaction::CompositionTransaction(
, mReplaceLength(aReplaceLength)
, mRanges(aTextRangeArray)
, mStringToInsert(aStringToInsert)
- , mEditorBase(aEditorBase)
+ , mEditorBase(&aEditorBase)
, mRangeUpdater(aRangeUpdater)
, mFixed(false)
{
@@ -45,6 +45,7 @@ CompositionTransaction::~CompositionTransaction()
}
NS_IMPL_CYCLE_COLLECTION_INHERITED(CompositionTransaction, EditTransactionBase,
+ mEditorBase,
mTextNode)
// mRangeList can't lead to cycles
@@ -60,9 +61,13 @@ NS_IMPL_RELEASE_INHERITED(CompositionTransaction, EditTransactionBase)
NS_IMETHODIMP
CompositionTransaction::DoTransaction()
{
+ if (NS_WARN_IF(!mEditorBase)) {
+ return NS_ERROR_NOT_INITIALIZED;
+ }
+
// Fail before making any changes if there's no selection controller
nsCOMPtr<nsISelectionController> selCon;
- mEditorBase.GetSelectionController(getter_AddRefs(selCon));
+ mEditorBase->GetSelectionController(getter_AddRefs(selCon));
NS_ENSURE_TRUE(selCon, NS_ERROR_NOT_INITIALIZED);
// Advance caret: This requires the presentation shell to get the selection.
@@ -108,9 +113,13 @@ CompositionTransaction::DoTransaction()
NS_IMETHODIMP
CompositionTransaction::UndoTransaction()
{
+ if (NS_WARN_IF(!mEditorBase)) {
+ return NS_ERROR_NOT_INITIALIZED;
+ }
+
// Get the selection first so we'll fail before making any changes if we
// can't get it
- RefPtr<Selection> selection = mEditorBase.GetSelection();
+ RefPtr<Selection> selection = mEditorBase->GetSelection();
NS_ENSURE_TRUE(selection, NS_ERROR_NOT_INITIALIZED);
nsresult rv = mTextNode->DeleteData(mOffset, mStringToInsert.Length());
@@ -171,7 +180,10 @@ CompositionTransaction::GetTxnDescription(nsAString& aString)
nsresult
CompositionTransaction::SetSelectionForRanges()
{
- return SetIMESelection(mEditorBase, mTextNode, mOffset,
+ if (NS_WARN_IF(!mEditorBase)) {
+ return NS_ERROR_NOT_INITIALIZED;
+ }
+ return SetIMESelection(*mEditorBase, mTextNode, mOffset,
mStringToInsert.Length(), mRanges);
}