mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-08 19:04:45 +00:00
Bug 1337698 - Part 1. PlaceholderTransaction should use UniquePtr. r=masayuki
MozReview-Commit-ID: 8xqAKRcKCLb --HG-- extra : rebase_source : d0a8d202e973d06c823cd5351d9561b9b5919f43 extra : histedit_source : 696ac1246fbb3691b2f042a0d16e438f37dcf64d%2C446038a833523fed82771c3c177811971679c269
This commit is contained in:
parent
ce8648a50f
commit
b8d5c8b156
@ -674,13 +674,10 @@ EditorBase::DoTransaction(nsITransaction* aTxn)
|
||||
{
|
||||
if (mPlaceHolderBatch && !mPlaceHolderTxn) {
|
||||
nsCOMPtr<nsIAbsorbingTransaction> placeholderTransaction =
|
||||
new PlaceholderTransaction();
|
||||
new PlaceholderTransaction(*this, mPlaceHolderName, Move(mSelState));
|
||||
|
||||
// Save off weak reference to placeholder transaction
|
||||
mPlaceHolderTxn = do_GetWeakReference(placeholderTransaction);
|
||||
placeholderTransaction->Init(mPlaceHolderName, mSelState, this);
|
||||
// placeholder txn took ownership of this pointer
|
||||
mSelState = nullptr;
|
||||
|
||||
// QI to an nsITransaction since that's what DoTransaction() expects
|
||||
nsCOMPtr<nsITransaction> transaction =
|
||||
@ -925,7 +922,7 @@ EditorBase::BeginPlaceHolderTransaction(nsIAtom* aName)
|
||||
mPlaceHolderName = aName;
|
||||
RefPtr<Selection> selection = GetSelection();
|
||||
if (selection) {
|
||||
mSelState = new SelectionState();
|
||||
mSelState = MakeUnique<SelectionState>();
|
||||
mSelState->SaveSelection(selection);
|
||||
// Composition transaction can modify multiple nodes and it merges text
|
||||
// node for ime into single text node.
|
||||
@ -989,7 +986,6 @@ EditorBase::EndPlaceHolderTransaction()
|
||||
if (mPlaceHolderName == nsGkAtoms::IMETxnName) {
|
||||
mRangeUpdater.DropSelectionState(*mSelState);
|
||||
}
|
||||
delete mSelState;
|
||||
mSelState = nullptr;
|
||||
}
|
||||
// We might have never made a placeholder if no action took place.
|
||||
|
@ -11,6 +11,7 @@
|
||||
#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/dom/Text.h"
|
||||
#include "nsCOMPtr.h" // for already_AddRefed, nsCOMPtr
|
||||
#include "nsCycleCollectionParticipant.h"
|
||||
@ -995,7 +996,7 @@ protected:
|
||||
// Name of placeholder transaction.
|
||||
nsIAtom* mPlaceHolderName;
|
||||
// Saved selection state for placeholder transaction batching.
|
||||
SelectionState* mSelState;
|
||||
mozilla::UniquePtr<SelectionState> mSelState;
|
||||
nsString* mPhonetic;
|
||||
// IME composition this is not null between compositionstart and
|
||||
// compositionend.
|
||||
|
@ -8,6 +8,7 @@
|
||||
#include "CompositionTransaction.h"
|
||||
#include "mozilla/EditorBase.h"
|
||||
#include "mozilla/dom/Selection.h"
|
||||
#include "mozilla/Move.h"
|
||||
#include "nsGkAtoms.h"
|
||||
#include "nsQueryObject.h"
|
||||
|
||||
@ -15,13 +16,18 @@ namespace mozilla {
|
||||
|
||||
using namespace dom;
|
||||
|
||||
PlaceholderTransaction::PlaceholderTransaction()
|
||||
PlaceholderTransaction::PlaceholderTransaction(
|
||||
EditorBase& aEditorBase,
|
||||
nsIAtom* aName,
|
||||
UniquePtr<SelectionState> aSelState)
|
||||
: mAbsorb(true)
|
||||
, mForwarding(nullptr)
|
||||
, mCompositionTransaction(nullptr)
|
||||
, mCommitted(false)
|
||||
, mEditorBase(nullptr)
|
||||
, mStartSel(Move(aSelState))
|
||||
, mEditorBase(aEditorBase)
|
||||
{
|
||||
mName = aName;
|
||||
}
|
||||
|
||||
PlaceholderTransaction::~PlaceholderTransaction()
|
||||
@ -54,19 +60,6 @@ NS_INTERFACE_MAP_END_INHERITING(EditAggregateTransaction)
|
||||
NS_IMPL_ADDREF_INHERITED(PlaceholderTransaction, EditAggregateTransaction)
|
||||
NS_IMPL_RELEASE_INHERITED(PlaceholderTransaction, EditAggregateTransaction)
|
||||
|
||||
NS_IMETHODIMP
|
||||
PlaceholderTransaction::Init(nsIAtom* aName,
|
||||
SelectionState* aSelState,
|
||||
EditorBase* aEditorBase)
|
||||
{
|
||||
NS_ENSURE_TRUE(aEditorBase && aSelState, NS_ERROR_NULL_POINTER);
|
||||
|
||||
mName = aName;
|
||||
mStartSel = aSelState;
|
||||
mEditorBase = aEditorBase;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
PlaceholderTransaction::DoTransaction()
|
||||
{
|
||||
@ -83,7 +76,7 @@ PlaceholderTransaction::UndoTransaction()
|
||||
NS_ENSURE_TRUE(mStartSel, NS_ERROR_NULL_POINTER);
|
||||
|
||||
// now restore selection
|
||||
RefPtr<Selection> selection = mEditorBase->GetSelection();
|
||||
RefPtr<Selection> selection = mEditorBase.GetSelection();
|
||||
NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
|
||||
return mStartSel->RestoreSelection(selection);
|
||||
}
|
||||
@ -96,7 +89,7 @@ PlaceholderTransaction::RedoTransaction()
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
// now restore selection
|
||||
RefPtr<Selection> selection = mEditorBase->GetSelection();
|
||||
RefPtr<Selection> selection = mEditorBase.GetSelection();
|
||||
NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
|
||||
return mEndSel.RestoreSelection(selection);
|
||||
}
|
||||
@ -261,7 +254,7 @@ PlaceholderTransaction::Commit()
|
||||
nsresult
|
||||
PlaceholderTransaction::RememberEndingSelection()
|
||||
{
|
||||
RefPtr<Selection> selection = mEditorBase->GetSelection();
|
||||
RefPtr<Selection> selection = mEditorBase.GetSelection();
|
||||
NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
|
||||
mEndSel.SaveSelection(selection);
|
||||
return NS_OK;
|
||||
|
@ -8,12 +8,12 @@
|
||||
|
||||
#include "EditAggregateTransaction.h"
|
||||
#include "mozilla/EditorUtils.h"
|
||||
#include "mozilla/UniquePtr.h"
|
||||
#include "nsIAbsorbingTransaction.h"
|
||||
#include "nsIDOMNode.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsWeakPtr.h"
|
||||
#include "nsWeakReference.h"
|
||||
#include "nsAutoPtr.h"
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
@ -33,7 +33,8 @@ class PlaceholderTransaction final : public EditAggregateTransaction,
|
||||
public:
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
|
||||
PlaceholderTransaction();
|
||||
PlaceholderTransaction(EditorBase& aEditorBase, nsIAtom* aName,
|
||||
UniquePtr<SelectionState> aSelState);
|
||||
|
||||
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(PlaceholderTransaction,
|
||||
EditAggregateTransaction)
|
||||
@ -46,9 +47,6 @@ public:
|
||||
|
||||
// ------------ nsIAbsorbingTransaction -----------------------
|
||||
|
||||
NS_IMETHOD Init(nsIAtom* aName, SelectionState* aSelState,
|
||||
EditorBase* aEditorBase) override;
|
||||
|
||||
NS_IMETHOD GetTxnName(nsIAtom** aName) override;
|
||||
|
||||
NS_IMETHOD StartSelectionEquals(SelectionState* aSelState,
|
||||
@ -80,11 +78,11 @@ protected:
|
||||
// restore the selection properly.
|
||||
|
||||
// Use a pointer because this is constructed before we exist.
|
||||
nsAutoPtr<SelectionState> mStartSel;
|
||||
UniquePtr<SelectionState> mStartSel;
|
||||
SelectionState mEndSel;
|
||||
|
||||
// The editor for this transaction.
|
||||
EditorBase* mEditorBase;
|
||||
EditorBase& mEditorBase;
|
||||
};
|
||||
|
||||
} // namespace mozilla
|
||||
|
@ -35,9 +35,6 @@ public:
|
||||
|
||||
NS_DECLARE_STATIC_IID_ACCESSOR(NS_IABSORBINGTRANSACTION_IID)
|
||||
|
||||
NS_IMETHOD Init(nsIAtom* aName, mozilla::SelectionState* aSelState,
|
||||
mozilla::EditorBase* aEditorBase) = 0;
|
||||
|
||||
NS_IMETHOD EndPlaceHolderBatch()=0;
|
||||
|
||||
NS_IMETHOD GetTxnName(nsIAtom **aName)=0;
|
||||
|
Loading…
Reference in New Issue
Block a user