summaryrefslogtreecommitdiffstats
path: root/editor/libeditor
diff options
context:
space:
mode:
authorMatt A. Tobin <email@mattatobin.com>2020-04-17 05:43:18 -0400
committerMatt A. Tobin <email@mattatobin.com>2020-04-17 05:43:18 -0400
commit516fd67d506b8dd3c2721dfd1aa1bbef4a2eda6f (patch)
treeaea649009c0ef563041ded0cb0c5d397568eab07 /editor/libeditor
parent17f7e1c8c6fca351174bdbd73981aa8e44d0f9da (diff)
downloadUXP-516fd67d506b8dd3c2721dfd1aa1bbef4a2eda6f.tar
UXP-516fd67d506b8dd3c2721dfd1aa1bbef4a2eda6f.tar.gz
UXP-516fd67d506b8dd3c2721dfd1aa1bbef4a2eda6f.tar.lz
UXP-516fd67d506b8dd3c2721dfd1aa1bbef4a2eda6f.tar.xz
UXP-516fd67d506b8dd3c2721dfd1aa1bbef4a2eda6f.zip
Bug 1337698 - Use UniquePtr instead of nsAutoPtr in editor
* PlaceholderTransaction should use UniquePtr * HTMLEditor should use UniquePtr * TypeInState should use UniquePtr Tag #1375
Diffstat (limited to 'editor/libeditor')
-rw-r--r--editor/libeditor/EditorBase.cpp8
-rw-r--r--editor/libeditor/EditorBase.h3
-rw-r--r--editor/libeditor/HTMLEditRules.cpp10
-rw-r--r--editor/libeditor/HTMLEditor.cpp2
-rw-r--r--editor/libeditor/HTMLEditor.h4
-rw-r--r--editor/libeditor/PlaceholderTransaction.cpp23
-rw-r--r--editor/libeditor/PlaceholderTransaction.h10
-rw-r--r--editor/libeditor/TypeInState.cpp8
-rw-r--r--editor/libeditor/TypeInState.h5
-rw-r--r--editor/libeditor/nsIAbsorbingTransaction.h3
10 files changed, 32 insertions, 44 deletions
diff --git a/editor/libeditor/EditorBase.cpp b/editor/libeditor/EditorBase.cpp
index f0f3095d6..9bae5dfa0 100644
--- a/editor/libeditor/EditorBase.cpp
+++ b/editor/libeditor/EditorBase.cpp
@@ -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.
diff --git a/editor/libeditor/EditorBase.h b/editor/libeditor/EditorBase.h
index 8680b57ae..157623287 100644
--- a/editor/libeditor/EditorBase.h
+++ b/editor/libeditor/EditorBase.h
@@ -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.
diff --git a/editor/libeditor/HTMLEditRules.cpp b/editor/libeditor/HTMLEditRules.cpp
index 0aa2bde8c..c97ebf27f 100644
--- a/editor/libeditor/HTMLEditRules.cpp
+++ b/editor/libeditor/HTMLEditRules.cpp
@@ -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
diff --git a/editor/libeditor/HTMLEditor.cpp b/editor/libeditor/HTMLEditor.cpp
index 73dd1673b..56e607200 100644
--- a/editor/libeditor/HTMLEditor.cpp
+++ b/editor/libeditor/HTMLEditor.cpp
@@ -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();
diff --git a/editor/libeditor/HTMLEditor.h b/editor/libeditor/HTMLEditor.h
index dfcdd8d6b..dc1a41b70 100644
--- a/editor/libeditor/HTMLEditor.h
+++ b/editor/libeditor/HTMLEditor.h
@@ -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;
diff --git a/editor/libeditor/PlaceholderTransaction.cpp b/editor/libeditor/PlaceholderTransaction.cpp
index fa808afad..5a76e391a 100644
--- a/editor/libeditor/PlaceholderTransaction.cpp
+++ b/editor/libeditor/PlaceholderTransaction.cpp
@@ -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()
@@ -57,19 +63,6 @@ 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()
{
return NS_OK;
diff --git a/editor/libeditor/PlaceholderTransaction.h b/editor/libeditor/PlaceholderTransaction.h
index 8193239be..7e592cc03 100644
--- a/editor/libeditor/PlaceholderTransaction.h
+++ b/editor/libeditor/PlaceholderTransaction.h
@@ -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.
diff --git a/editor/libeditor/TypeInState.cpp b/editor/libeditor/TypeInState.cpp
index ce43e5e4d..840139fee 100644
--- a/editor/libeditor/TypeInState.cpp
+++ b/editor/libeditor/TypeInState.cpp
@@ -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);
}
/**
diff --git a/editor/libeditor/TypeInState.h b/editor/libeditor/TypeInState.h
index 540b2d9c1..e1b949508 100644
--- a/editor/libeditor/TypeInState.h
+++ b/editor/libeditor/TypeInState.h
@@ -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
diff --git a/editor/libeditor/nsIAbsorbingTransaction.h b/editor/libeditor/nsIAbsorbingTransaction.h
index e22caed4a..b2d7b2c79 100644
--- a/editor/libeditor/nsIAbsorbingTransaction.h
+++ b/editor/libeditor/nsIAbsorbingTransaction.h
@@ -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;