Bug 1337698 - Part 3. TypeInState should use UniquePtr. r=masayuki

MozReview-Commit-ID: K9UY83Nx1v3

--HG--
extra : rebase_source : e9177c1c31805288e04270b589300c8e49d59940
extra : amend_source : 91bea4e023031b1c1594799b8dbe70dc3fb5b6ed
extra : histedit_source : 2ee5b839c0f8019d18586a1b07e06e122e7780ee
This commit is contained in:
Makoto Kato 2017-02-08 18:14:53 +09:00
Родитель d84f1fef72
Коммит 894130bddc
3 изменённых файлов: 13 добавлений и 10 удалений

Просмотреть файл

@ -16,13 +16,14 @@
#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/Unused.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"
@ -4499,20 +4500,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

Просмотреть файл

@ -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