mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-11 12:25:53 +00:00
Bug 1385538 - Avoid dynamic memory allocation for EditorBase::mSelState; r=masayuki
This commit is contained in:
parent
f3a8bf3251
commit
30d4df5778
@ -128,7 +128,6 @@ using namespace widget;
|
||||
|
||||
EditorBase::EditorBase()
|
||||
: mPlaceholderName(nullptr)
|
||||
, mSelState(nullptr)
|
||||
, mModCount(0)
|
||||
, mFlags(0)
|
||||
, mUpdateCount(0)
|
||||
@ -974,7 +973,7 @@ EditorBase::BeginPlaceHolderTransaction(nsIAtom* aName)
|
||||
mPlaceholderName = aName;
|
||||
RefPtr<Selection> selection = GetSelection();
|
||||
if (selection) {
|
||||
mSelState = MakeUnique<SelectionState>();
|
||||
mSelState.emplace();
|
||||
mSelState->SaveSelection(selection);
|
||||
// Composition transaction can modify multiple nodes and it merges text
|
||||
// node for ime into single text node.
|
||||
@ -1039,7 +1038,7 @@ EditorBase::EndPlaceHolderTransaction()
|
||||
if (mPlaceholderName == nsGkAtoms::IMETxnName) {
|
||||
mRangeUpdater.DropSelectionState(*mSelState);
|
||||
}
|
||||
mSelState = nullptr;
|
||||
mSelState.reset();
|
||||
}
|
||||
// We might have never made a placeholder if no action took place.
|
||||
if (mPlaceholderTransaction) {
|
||||
|
@ -7,10 +7,10 @@
|
||||
#define mozilla_EditorBase_h
|
||||
|
||||
#include "mozilla/Assertions.h" // for MOZ_ASSERT, etc.
|
||||
#include "mozilla/Maybe.h" // for Maybe
|
||||
#include "mozilla/OwningNonNull.h" // for OwningNonNull
|
||||
#include "mozilla/SelectionState.h" // for RangeUpdater, etc.
|
||||
#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
|
||||
@ -1133,7 +1133,7 @@ protected:
|
||||
// Name of placeholder transaction.
|
||||
nsIAtom* mPlaceholderName;
|
||||
// Saved selection state for placeholder transaction batching.
|
||||
mozilla::UniquePtr<SelectionState> mSelState;
|
||||
mozilla::Maybe<SelectionState> mSelState;
|
||||
// IME composition this is not null between compositionstart and
|
||||
// compositionend.
|
||||
RefPtr<TextComposition> mComposition;
|
||||
|
@ -19,12 +19,12 @@ using namespace dom;
|
||||
PlaceholderTransaction::PlaceholderTransaction(
|
||||
EditorBase& aEditorBase,
|
||||
nsIAtom* aName,
|
||||
UniquePtr<SelectionState> aSelState)
|
||||
Maybe<SelectionState>&& aSelState)
|
||||
: mAbsorb(true)
|
||||
, mForwarding(nullptr)
|
||||
, mCompositionTransaction(nullptr)
|
||||
, mCommitted(false)
|
||||
, mStartSel(Move(aSelState))
|
||||
, mStartSel(Move(*aSelState))
|
||||
, mEditorBase(&aEditorBase)
|
||||
{
|
||||
mName = aName;
|
||||
@ -38,19 +38,15 @@ NS_IMPL_CYCLE_COLLECTION_CLASS(PlaceholderTransaction)
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(PlaceholderTransaction,
|
||||
EditAggregateTransaction)
|
||||
if (tmp->mStartSel) {
|
||||
ImplCycleCollectionUnlink(*tmp->mStartSel);
|
||||
}
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK(mEditorBase);
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK(mStartSel);
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK(mEndSel);
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(PlaceholderTransaction,
|
||||
EditAggregateTransaction)
|
||||
if (tmp->mStartSel) {
|
||||
ImplCycleCollectionTraverse(cb, *tmp->mStartSel, "mStartSel", 0);
|
||||
}
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mEditorBase);
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mStartSel);
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mEndSel);
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
||||
|
||||
@ -78,12 +74,10 @@ PlaceholderTransaction::UndoTransaction()
|
||||
nsresult rv = EditAggregateTransaction::UndoTransaction();
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
NS_ENSURE_TRUE(mStartSel, NS_ERROR_NULL_POINTER);
|
||||
|
||||
// now restore selection
|
||||
RefPtr<Selection> selection = mEditorBase->GetSelection();
|
||||
NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
|
||||
return mStartSel->RestoreSelection(selection);
|
||||
return mStartSel.RestoreSelection(selection);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
@ -222,11 +216,11 @@ PlaceholderTransaction::StartSelectionEquals(SelectionState* aSelState,
|
||||
// determine if starting selection matches the given selection state.
|
||||
// note that we only care about collapsed selections.
|
||||
NS_ENSURE_TRUE(aResult && aSelState, NS_ERROR_NULL_POINTER);
|
||||
if (!mStartSel->IsCollapsed() || !aSelState->IsCollapsed()) {
|
||||
if (!mStartSel.IsCollapsed() || !aSelState->IsCollapsed()) {
|
||||
*aResult = false;
|
||||
return NS_OK;
|
||||
}
|
||||
*aResult = mStartSel->IsEqual(aSelState);
|
||||
*aResult = mStartSel.IsEqual(aSelState);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -8,7 +8,7 @@
|
||||
|
||||
#include "EditAggregateTransaction.h"
|
||||
#include "mozilla/EditorUtils.h"
|
||||
#include "mozilla/UniquePtr.h"
|
||||
#include "mozilla/Maybe.h"
|
||||
#include "nsIAbsorbingTransaction.h"
|
||||
#include "nsIDOMNode.h"
|
||||
#include "nsCOMPtr.h"
|
||||
@ -33,7 +33,7 @@ public:
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
|
||||
PlaceholderTransaction(EditorBase& aEditorBase, nsIAtom* aName,
|
||||
UniquePtr<SelectionState> aSelState);
|
||||
Maybe<SelectionState>&& aSelState);
|
||||
|
||||
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(PlaceholderTransaction,
|
||||
EditAggregateTransaction)
|
||||
@ -81,8 +81,7 @@ protected:
|
||||
// at the end. This is so that UndoTransaction() and RedoTransaction() can
|
||||
// restore the selection properly.
|
||||
|
||||
// Use a pointer because this is constructed before we exist.
|
||||
UniquePtr<SelectionState> mStartSel;
|
||||
SelectionState mStartSel;
|
||||
SelectionState mEndSel;
|
||||
|
||||
// The editor for this transaction.
|
||||
|
Loading…
Reference in New Issue
Block a user