mirror of
https://github.com/roytam1/UXP.git
synced 2026-05-26 13:58:49 +00:00
Bug 1337698 - Use UniquePtr instead of nsAutoPtr in editor
* PlaceholderTransaction should use UniquePtr * HTMLEditor should use UniquePtr * TypeInState should use UniquePtr Tag #1375
This commit is contained in:
@@ -688,13 +688,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 =
|
||||
@@ -944,7 +941,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.
|
||||
@@ -1008,7 +1005,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"
|
||||
@@ -980,7 +981,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.
|
||||
|
||||
@@ -16,12 +16,13 @@
|
||||
#include "mozilla/EditorUtils.h"
|
||||
#include "mozilla/HTMLEditor.h"
|
||||
#include "mozilla/MathAlgorithms.h"
|
||||
#include "mozilla/Move.h"
|
||||
#include "mozilla/Preferences.h"
|
||||
#include "mozilla/UniquePtr.h"
|
||||
#include "mozilla/dom/Selection.h"
|
||||
#include "mozilla/dom/Element.h"
|
||||
#include "mozilla/OwningNonNull.h"
|
||||
#include "mozilla/mozalloc.h"
|
||||
#include "nsAutoPtr.h"
|
||||
#include "nsAString.h"
|
||||
#include "nsAlgorithm.h"
|
||||
#include "nsCRT.h"
|
||||
@@ -4410,20 +4411,21 @@ HTMLEditRules::CreateStyleForInsertText(Selection& aSelection,
|
||||
NS_ENSURE_STATE(rootElement);
|
||||
|
||||
// process clearing any styles first
|
||||
nsAutoPtr<PropItem> item(mHTMLEditor->mTypeInState->TakeClearProperty());
|
||||
UniquePtr<PropItem> item =
|
||||
Move(mHTMLEditor->mTypeInState->TakeClearProperty());
|
||||
while (item && node != rootElement) {
|
||||
NS_ENSURE_STATE(mHTMLEditor);
|
||||
nsresult rv =
|
||||
mHTMLEditor->ClearStyle(address_of(node), &offset,
|
||||
item->tag, &item->attr);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
item = mHTMLEditor->mTypeInState->TakeClearProperty();
|
||||
item = Move(mHTMLEditor->mTypeInState->TakeClearProperty());
|
||||
weDidSomething = true;
|
||||
}
|
||||
|
||||
// then process setting any styles
|
||||
int32_t relFontSize = mHTMLEditor->mTypeInState->TakeRelativeFontSize();
|
||||
item = mHTMLEditor->mTypeInState->TakeSetProperty();
|
||||
item = Move(mHTMLEditor->mTypeInState->TakeSetProperty());
|
||||
|
||||
if (item || relFontSize) {
|
||||
// we have at least one style to add; make a new text node to insert style
|
||||
|
||||
@@ -287,7 +287,7 @@ HTMLEditor::Init(nsIDOMDocument* aDoc,
|
||||
}
|
||||
|
||||
// Init the HTML-CSS utils
|
||||
mCSSEditUtils = new CSSEditUtils(this);
|
||||
mCSSEditUtils = MakeUnique<CSSEditUtils>(this);
|
||||
|
||||
// disable links
|
||||
nsCOMPtr<nsIPresShell> presShell = GetPresShell();
|
||||
|
||||
@@ -10,11 +10,11 @@
|
||||
#include "mozilla/CSSEditUtils.h"
|
||||
#include "mozilla/StyleSheet.h"
|
||||
#include "mozilla/TextEditor.h"
|
||||
#include "mozilla/UniquePtr.h"
|
||||
#include "mozilla/dom/Element.h"
|
||||
#include "mozilla/dom/File.h"
|
||||
|
||||
#include "nsAttrName.h"
|
||||
#include "nsAutoPtr.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIContentFilter.h"
|
||||
#include "nsICSSLoaderObserver.h"
|
||||
@@ -896,7 +896,7 @@ protected:
|
||||
bool mCRInParagraphCreatesParagraph;
|
||||
|
||||
bool mCSSAware;
|
||||
nsAutoPtr<CSSEditUtils> mCSSEditUtils;
|
||||
UniquePtr<CSSEditUtils> mCSSEditUtils;
|
||||
|
||||
// Used by GetFirstSelectedCell and GetNextSelectedCell
|
||||
int32_t mSelectedCellIndex;
|
||||
|
||||
@@ -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()
|
||||
@@ -56,19 +62,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()
|
||||
{
|
||||
|
||||
@@ -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,7 +78,7 @@ 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.
|
||||
|
||||
@@ -193,7 +193,7 @@ TypeInState::ClearProp(nsIAtom* aProp,
|
||||
* TakeClearProperty() hands back next property item on the clear list.
|
||||
* Caller assumes ownership of PropItem and must delete it.
|
||||
*/
|
||||
PropItem*
|
||||
UniquePtr<PropItem>
|
||||
TypeInState::TakeClearProperty()
|
||||
{
|
||||
size_t count = mClearedArray.Length();
|
||||
@@ -204,14 +204,14 @@ TypeInState::TakeClearProperty()
|
||||
--count; // indices are zero based
|
||||
PropItem* propItem = mClearedArray[count];
|
||||
mClearedArray.RemoveElementAt(count);
|
||||
return propItem;
|
||||
return UniquePtr<PropItem>(propItem);
|
||||
}
|
||||
|
||||
/**
|
||||
* TakeSetProperty() hands back next poroperty item on the set list.
|
||||
* Caller assumes ownership of PropItem and must delete it.
|
||||
*/
|
||||
PropItem*
|
||||
UniquePtr<PropItem>
|
||||
TypeInState::TakeSetProperty()
|
||||
{
|
||||
size_t count = mSetArray.Length();
|
||||
@@ -221,7 +221,7 @@ TypeInState::TakeSetProperty()
|
||||
count--; // indices are zero based
|
||||
PropItem* propItem = mSetArray[count];
|
||||
mSetArray.RemoveElementAt(count);
|
||||
return propItem;
|
||||
return UniquePtr<PropItem>(propItem);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#ifndef TypeInState_h
|
||||
#define TypeInState_h
|
||||
|
||||
#include "mozilla/UniquePtr.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsCycleCollectionParticipant.h"
|
||||
#include "nsISelectionListener.h"
|
||||
@@ -63,13 +64,13 @@ public:
|
||||
* TakeClearProperty() hands back next property item on the clear list.
|
||||
* Caller assumes ownership of PropItem and must delete it.
|
||||
*/
|
||||
PropItem* TakeClearProperty();
|
||||
UniquePtr<PropItem> TakeClearProperty();
|
||||
|
||||
/**
|
||||
* TakeSetProperty() hands back next property item on the set list.
|
||||
* Caller assumes ownership of PropItem and must delete it.
|
||||
*/
|
||||
PropItem* TakeSetProperty();
|
||||
UniquePtr<PropItem> TakeSetProperty();
|
||||
|
||||
/**
|
||||
* TakeRelativeFontSize() hands back relative font value, which is then
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user