summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--editor/libeditor/EditorBase.cpp64
-rw-r--r--editor/libeditor/EditorBase.h10
-rw-r--r--editor/libeditor/PlaceholderTransaction.cpp1
-rw-r--r--editor/libeditor/PlaceholderTransaction.h15
-rw-r--r--editor/libeditor/TextEditor.cpp2
-rw-r--r--editor/libeditor/nsIAbsorbingTransaction.h4
6 files changed, 53 insertions, 43 deletions
diff --git a/editor/libeditor/EditorBase.cpp b/editor/libeditor/EditorBase.cpp
index d37070849..f068e9179 100644
--- a/editor/libeditor/EditorBase.cpp
+++ b/editor/libeditor/EditorBase.cpp
@@ -127,13 +127,13 @@ using namespace widget;
*****************************************************************************/
EditorBase::EditorBase()
- : mPlaceHolderName(nullptr)
+ : mPlaceholderName(nullptr)
, mSelState(nullptr)
, mPhonetic(nullptr)
, mModCount(0)
, mFlags(0)
, mUpdateCount(0)
- , mPlaceHolderBatch(0)
+ , mPlaceholderBatch(0)
, mAction(EditAction::none)
, mIMETextOffset(0)
, mIMETextLength(0)
@@ -692,29 +692,29 @@ EditorBase::GetSelection(SelectionType aSelectionType)
NS_IMETHODIMP
EditorBase::DoTransaction(nsITransaction* aTxn)
{
- if (mPlaceHolderBatch && !mPlaceHolderTxn) {
- nsCOMPtr<nsIAbsorbingTransaction> placeholderTransaction =
- new PlaceholderTransaction(*this, mPlaceHolderName, Move(mSelState));
+ if (mPlaceholderBatch && !mPlaceholderTransactionWeak) {
+ RefPtr<PlaceholderTransaction> placeholderTransaction =
+ new PlaceholderTransaction(*this, mPlaceholderName, Move(mSelState));
// Save off weak reference to placeholder transaction
- mPlaceHolderTxn = do_GetWeakReference(placeholderTransaction);
+ mPlaceholderTransactionWeak = placeholderTransaction;
- // QI to an nsITransaction since that's what DoTransaction() expects
- nsCOMPtr<nsITransaction> transaction =
- do_QueryInterface(placeholderTransaction);
// We will recurse, but will not hit this case in the nested call
- DoTransaction(transaction);
+ DoTransaction(placeholderTransaction);
if (mTxnMgr) {
- nsCOMPtr<nsITransaction> topTxn = mTxnMgr->PeekUndoStack();
- if (topTxn) {
- placeholderTransaction = do_QueryInterface(topTxn);
- if (placeholderTransaction) {
+ nsCOMPtr<nsITransaction> topTransaction = mTxnMgr->PeekUndoStack();
+ nsCOMPtr<nsIAbsorbingTransaction> topAbsorbingTransaction =
+ do_QueryInterface(topTransaction);
+ if (topAbsorbingTransaction) {
+ RefPtr<PlaceholderTransaction> topPlaceholderTransaction =
+ topAbsorbingTransaction->AsPlaceholderTransaction();
+ if (topPlaceholderTransaction) {
// there is a placeholder transaction on top of the undo stack. It
// is either the one we just created, or an earlier one that we are
// now merging into. From here on out remember this placeholder
// instead of the one we just created.
- mPlaceHolderTxn = do_GetWeakReference(placeholderTransaction);
+ mPlaceholderTransactionWeak = topPlaceholderTransaction;
}
}
}
@@ -938,13 +938,13 @@ EditorBase::EndTransaction()
NS_IMETHODIMP
EditorBase::BeginPlaceHolderTransaction(nsIAtom* aName)
{
- NS_PRECONDITION(mPlaceHolderBatch >= 0, "negative placeholder batch count!");
- if (!mPlaceHolderBatch) {
+ MOZ_ASSERT(mPlaceholderBatch >= 0, "negative placeholder batch count!");
+ if (!mPlaceholderBatch) {
NotifyEditorObservers(eNotifyEditorObserversOfBefore);
// time to turn on the batch
BeginUpdateViewBatch();
- mPlaceHolderTxn = nullptr;
- mPlaceHolderName = aName;
+ mPlaceholderTransactionWeak = nullptr;
+ mPlaceholderName = aName;
RefPtr<Selection> selection = GetSelection();
if (selection) {
mSelState = MakeUnique<SelectionState>();
@@ -954,12 +954,12 @@ EditorBase::BeginPlaceHolderTransaction(nsIAtom* aName)
// So if current selection is into IME text node, it might be failed
// to restore selection by UndoTransaction.
// So we need update selection by range updater.
- if (mPlaceHolderName == nsGkAtoms::IMETxnName) {
+ if (mPlaceholderName == nsGkAtoms::IMETxnName) {
mRangeUpdater.RegisterSelectionState(*mSelState);
}
}
}
- mPlaceHolderBatch++;
+ mPlaceholderBatch++;
return NS_OK;
}
@@ -967,8 +967,9 @@ EditorBase::BeginPlaceHolderTransaction(nsIAtom* aName)
NS_IMETHODIMP
EditorBase::EndPlaceHolderTransaction()
{
- NS_PRECONDITION(mPlaceHolderBatch > 0, "zero or negative placeholder batch count when ending batch!");
- if (mPlaceHolderBatch == 1) {
+ MOZ_ASSERT(mPlaceholderBatch > 0,
+ "zero or negative placeholder batch count when ending batch!");
+ if (mPlaceholderBatch == 1) {
RefPtr<Selection> selection = GetSelection();
// By making the assumption that no reflow happens during the calls
@@ -1008,21 +1009,16 @@ EditorBase::EndPlaceHolderTransaction()
if (mSelState) {
// we saved the selection state, but never got to hand it to placeholder
// (else we ould have nulled out this pointer), so destroy it to prevent leaks.
- if (mPlaceHolderName == nsGkAtoms::IMETxnName) {
+ if (mPlaceholderName == nsGkAtoms::IMETxnName) {
mRangeUpdater.DropSelectionState(*mSelState);
}
mSelState = nullptr;
}
// We might have never made a placeholder if no action took place.
- if (mPlaceHolderTxn) {
- nsCOMPtr<nsIAbsorbingTransaction> plcTxn = do_QueryReferent(mPlaceHolderTxn);
- if (plcTxn) {
- plcTxn->EndPlaceHolderBatch();
- } else {
- // in the future we will check to make sure undo is off here,
- // since that is the only known case where the placeholdertxn would disappear on us.
- // For now just removing the assert.
- }
+ if (mPlaceholderTransactionWeak) {
+ RefPtr<PlaceholderTransaction> placeholderTransaction =
+ mPlaceholderTransactionWeak.get();
+ placeholderTransaction->EndPlaceHolderBatch();
// notify editor observers of action but if composing, it's done by
// compositionchange event handler.
if (!mComposition) {
@@ -1032,7 +1028,7 @@ EditorBase::EndPlaceHolderTransaction()
NotifyEditorObservers(eNotifyEditorObserversOfCancel);
}
}
- mPlaceHolderBatch--;
+ mPlaceholderBatch--;
return NS_OK;
}
diff --git a/editor/libeditor/EditorBase.h b/editor/libeditor/EditorBase.h
index 83917c150..7ea0f4dab 100644
--- a/editor/libeditor/EditorBase.h
+++ b/editor/libeditor/EditorBase.h
@@ -10,8 +10,9 @@
#include "mozFlushType.h" // for mozFlushType enum
#include "mozilla/OwningNonNull.h" // for OwningNonNull
#include "mozilla/SelectionState.h" // for RangeUpdater, etc.
-#include "mozilla/StyleSheet.h" // for StyleSheet
+#include "mozilla/StyleSheet.h" // for StyleSheet
#include "mozilla/UniquePtr.h"
+#include "mozilla/WeakPtr.h" // for WeakPtr
#include "mozilla/dom/Text.h"
#include "nsCOMPtr.h" // for already_AddRefed, nsCOMPtr
#include "nsCycleCollectionParticipant.h"
@@ -116,6 +117,7 @@ class ErrorResult;
class InsertNodeTransaction;
class InsertTextTransaction;
class JoinNodeTransaction;
+class PlaceholderTransaction;
class RemoveStyleSheetTransaction;
class SplitNodeTransaction;
class TextComposition;
@@ -976,11 +978,11 @@ protected:
// Weak reference to the nsISelectionController.
nsWeakPtr mSelConWeak;
// Weak reference to placeholder for begin/end batch purposes.
- nsWeakPtr mPlaceHolderTxn;
+ WeakPtr<PlaceholderTransaction> mPlaceholderTransactionWeak;
// Weak reference to the nsIDOMDocument.
nsWeakPtr mDocWeak;
// Name of placeholder transaction.
- nsIAtom* mPlaceHolderName;
+ nsIAtom* mPlaceholderName;
// Saved selection state for placeholder transaction batching.
mozilla::UniquePtr<SelectionState> mSelState;
nsString* mPhonetic;
@@ -1014,7 +1016,7 @@ protected:
int32_t mUpdateCount;
// Nesting count for batching.
- int32_t mPlaceHolderBatch;
+ int32_t mPlaceholderBatch;
// The current editor action.
EditAction mAction;
diff --git a/editor/libeditor/PlaceholderTransaction.cpp b/editor/libeditor/PlaceholderTransaction.cpp
index 5a76e391a..142a85075 100644
--- a/editor/libeditor/PlaceholderTransaction.cpp
+++ b/editor/libeditor/PlaceholderTransaction.cpp
@@ -56,7 +56,6 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(PlaceholderTransaction)
NS_INTERFACE_MAP_ENTRY(nsIAbsorbingTransaction)
- NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
NS_INTERFACE_MAP_END_INHERITING(EditAggregateTransaction)
NS_IMPL_ADDREF_INHERITED(PlaceholderTransaction, EditAggregateTransaction)
diff --git a/editor/libeditor/PlaceholderTransaction.h b/editor/libeditor/PlaceholderTransaction.h
index 7e592cc03..5fa58a1e9 100644
--- a/editor/libeditor/PlaceholderTransaction.h
+++ b/editor/libeditor/PlaceholderTransaction.h
@@ -9,6 +9,7 @@
#include "EditAggregateTransaction.h"
#include "mozilla/EditorUtils.h"
#include "mozilla/UniquePtr.h"
+#include "mozilla/WeakPtr.h"
#include "nsIAbsorbingTransaction.h"
#include "nsIDOMNode.h"
#include "nsCOMPtr.h"
@@ -26,11 +27,14 @@ class CompositionTransaction;
* transactions it has absorbed.
*/
-class PlaceholderTransaction final : public EditAggregateTransaction,
- public nsIAbsorbingTransaction,
- public nsSupportsWeakReference
+class PlaceholderTransaction final
+ : public EditAggregateTransaction
+ , public nsIAbsorbingTransaction
+ , public SupportsWeakPtr<PlaceholderTransaction>
{
public:
+ MOZ_DECLARE_WEAKREFERENCE_TYPENAME(PlaceholderTransaction)
+
NS_DECL_ISUPPORTS_INHERITED
PlaceholderTransaction(EditorBase& aEditorBase, nsIAtom* aName,
@@ -59,6 +63,11 @@ public:
NS_IMETHOD Commit() override;
+ NS_IMETHOD_(PlaceholderTransaction*) AsPlaceholderTransaction() override
+ {
+ return this;
+ }
+
nsresult RememberEndingSelection();
protected:
diff --git a/editor/libeditor/TextEditor.cpp b/editor/libeditor/TextEditor.cpp
index 1e855d769..35ea5da83 100644
--- a/editor/libeditor/TextEditor.cpp
+++ b/editor/libeditor/TextEditor.cpp
@@ -864,7 +864,7 @@ TextEditor::UpdateIMEComposition(WidgetCompositionEvent* aCompositionChangeEvent
// of NotifiyEditorObservers(eNotifyEditorObserversOfEnd) or
// NotifiyEditorObservers(eNotifyEditorObserversOfCancel) which notifies
// TextComposition of a selection change.
- MOZ_ASSERT(!mPlaceHolderBatch,
+ MOZ_ASSERT(!mPlaceholderBatch,
"UpdateIMEComposition() must be called without place holder batch");
TextComposition::CompositionChangeEventHandlingMarker
compositionChangeEventHandlingMarker(mComposition, aCompositionChangeEvent);
diff --git a/editor/libeditor/nsIAbsorbingTransaction.h b/editor/libeditor/nsIAbsorbingTransaction.h
index b2d7b2c79..06329f3d4 100644
--- a/editor/libeditor/nsIAbsorbingTransaction.h
+++ b/editor/libeditor/nsIAbsorbingTransaction.h
@@ -23,6 +23,7 @@ class nsIAtom;
namespace mozilla {
class EditorBase;
+class PlaceholderTransaction;
class SelectionState;
} // namespace mozilla
@@ -45,6 +46,9 @@ public:
NS_IMETHOD ForwardEndBatchTo(nsIAbsorbingTransaction *aForwardingAddress)=0;
NS_IMETHOD Commit()=0;
+
+ NS_IMETHOD_(mozilla::PlaceholderTransaction*)
+ AsPlaceholderTransaction() = 0;
};
NS_DEFINE_STATIC_IID_ACCESSOR(nsIAbsorbingTransaction,