Bug 1438026 - Part 3: Replace nsPresState with the new PresState type, r=baku

This commit is contained in:
Nika Layzell 2018-03-02 13:18:35 -05:00
Родитель 998263091d
Коммит 242c9ce313
21 изменённых файлов: 256 добавлений и 372 удалений

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

@ -28,7 +28,7 @@
#include "mozilla/TextEvents.h"
#include "nsUnicharUtils.h"
#include "nsLayoutUtils.h"
#include "nsPresState.h"
#include "mozilla/PresState.h"
#include "nsError.h"
#include "nsFocusManager.h"
#include "mozilla/dom/HTMLFormElement.h"
@ -448,20 +448,21 @@ HTMLButtonElement::SaveState()
return NS_OK;
}
nsPresState* state = GetPrimaryPresState();
PresState* state = GetPrimaryPresState();
if (state) {
// We do not want to save the real disabled state but the disabled
// attribute.
state->SetDisabled(HasAttr(kNameSpaceID_None, nsGkAtoms::disabled));
state->disabled() = HasAttr(kNameSpaceID_None, nsGkAtoms::disabled);
state->disabledSet() = true;
}
return NS_OK;
}
bool
HTMLButtonElement::RestoreState(nsPresState* aState)
HTMLButtonElement::RestoreState(PresState* aState)
{
if (aState && aState->IsDisabledSet() && !aState->GetDisabled()) {
if (aState && aState->disabledSet() && !aState->disabled()) {
SetDisabled(false, IgnoreErrors());
}

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

@ -45,7 +45,7 @@ public:
NS_IMETHOD Reset() override;
NS_IMETHOD SubmitNamesValues(HTMLFormSubmission* aFormSubmission) override;
NS_IMETHOD SaveState() override;
bool RestoreState(nsPresState* aState) override;
bool RestoreState(PresState* aState) override;
virtual bool IsDisabledForEvents(EventMessage aMessage) override;
virtual void FieldSetDisabledChanged(bool aNotify) override;

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

@ -54,7 +54,7 @@
#include "nsAttrValueOrString.h"
#include "nsDateTimeControlFrame.h"
#include "nsPresState.h"
#include "mozilla/PresState.h"
#include "nsIDOMEvent.h"
#include "nsIDOMNodeList.h"
#include "nsLinebreakConverter.h" //to strip out carriage returns
@ -274,129 +274,6 @@ private:
RefPtr<HTMLInputElement> mInputElement;
};
class HTMLInputElementState final : public nsISupports
{
public:
NS_DECLARE_STATIC_IID_ACCESSOR(NS_INPUT_ELEMENT_STATE_IID)
NS_DECL_ISUPPORTS
bool IsCheckedSet()
{
return mCheckedSet;
}
bool GetChecked()
{
return mChecked;
}
void SetChecked(bool aChecked)
{
mChecked = aChecked;
mCheckedSet = true;
}
const nsString& GetValue()
{
return mValue;
}
void SetValue(const nsAString& aValue)
{
mValue = aValue;
}
void
GetFilesOrDirectories(nsPIDOMWindowInner* aWindow,
nsTArray<OwningFileOrDirectory>& aResult) const
{
for (uint32_t i = 0; i < mBlobImplsOrDirectoryPaths.Length(); ++i) {
if (mBlobImplsOrDirectoryPaths[i].mType == BlobImplOrDirectoryPath::eBlobImpl) {
RefPtr<File> file =
File::Create(aWindow,
mBlobImplsOrDirectoryPaths[i].mBlobImpl);
MOZ_ASSERT(file);
OwningFileOrDirectory* element = aResult.AppendElement();
element->SetAsFile() = file;
} else {
MOZ_ASSERT(mBlobImplsOrDirectoryPaths[i].mType == BlobImplOrDirectoryPath::eDirectoryPath);
nsCOMPtr<nsIFile> file;
nsresult rv =
NS_NewLocalFile(mBlobImplsOrDirectoryPaths[i].mDirectoryPath,
true, getter_AddRefs(file));
if (NS_WARN_IF(NS_FAILED(rv))) {
continue;
}
RefPtr<Directory> directory = Directory::Create(aWindow, file);
MOZ_ASSERT(directory);
OwningFileOrDirectory* element = aResult.AppendElement();
element->SetAsDirectory() = directory;
}
}
}
void SetFilesOrDirectories(const nsTArray<OwningFileOrDirectory>& aArray)
{
mBlobImplsOrDirectoryPaths.Clear();
for (uint32_t i = 0; i < aArray.Length(); ++i) {
if (aArray[i].IsFile()) {
BlobImplOrDirectoryPath* data = mBlobImplsOrDirectoryPaths.AppendElement();
data->mBlobImpl = aArray[i].GetAsFile()->Impl();
data->mType = BlobImplOrDirectoryPath::eBlobImpl;
} else {
MOZ_ASSERT(aArray[i].IsDirectory());
nsAutoString fullPath;
nsresult rv = aArray[i].GetAsDirectory()->GetFullRealPath(fullPath);
if (NS_WARN_IF(NS_FAILED(rv))) {
continue;
}
BlobImplOrDirectoryPath* data =
mBlobImplsOrDirectoryPaths.AppendElement();
data->mDirectoryPath = fullPath;
data->mType = BlobImplOrDirectoryPath::eDirectoryPath;
}
}
}
HTMLInputElementState()
: mValue()
, mChecked(false)
, mCheckedSet(false)
{}
protected:
~HTMLInputElementState() {}
nsString mValue;
struct BlobImplOrDirectoryPath
{
RefPtr<BlobImpl> mBlobImpl;
nsString mDirectoryPath;
enum {
eBlobImpl,
eDirectoryPath
} mType;
};
nsTArray<BlobImplOrDirectoryPath> mBlobImplsOrDirectoryPaths;
bool mChecked;
bool mCheckedSet;
};
NS_DEFINE_STATIC_IID_ACCESSOR(HTMLInputElementState, NS_INPUT_ELEMENT_STATE_IID)
NS_IMPL_ISUPPORTS(HTMLInputElementState, HTMLInputElementState)
struct HTMLInputElement::FileData
{
/**
@ -6366,11 +6243,31 @@ HTMLInputElement::SubmitNamesValues(HTMLFormSubmission* aFormSubmission)
return aFormSubmission->AddNameValuePair(name, value);
}
static nsTArray<FileContentData>
SaveFileContentData(const nsTArray<OwningFileOrDirectory>& aArray)
{
nsTArray<FileContentData> res(aArray.Length());
for (auto& it : aArray) {
if (it.IsFile()) {
RefPtr<BlobImpl> impl = it.GetAsFile()->Impl();
res.AppendElement(Move(impl));
} else {
MOZ_ASSERT(it.IsDirectory());
nsString fullPath;
nsresult rv = it.GetAsDirectory()->GetFullRealPath(fullPath);
if (NS_WARN_IF(NS_FAILED(rv))) {
continue;
}
res.AppendElement(Move(fullPath));
}
}
return res;
}
NS_IMETHODIMP
HTMLInputElement::SaveState()
{
nsPresState* state = nullptr;
PresState* state = nullptr;
switch (GetValueMode()) {
case VALUE_MODE_DEFAULT_ON:
if (mCheckedChanged) {
@ -6379,9 +6276,7 @@ HTMLInputElement::SaveState()
return NS_OK;
}
RefPtr<HTMLInputElementState> inputState = new HTMLInputElementState();
inputState->SetChecked(mChecked);
state->SetStateProperty(inputState);
state->contentData() = CheckedContentData(mChecked);
}
break;
case VALUE_MODE_FILENAME:
@ -6391,9 +6286,8 @@ HTMLInputElement::SaveState()
return NS_OK;
}
RefPtr<HTMLInputElementState> inputState = new HTMLInputElementState();
inputState->SetFilesOrDirectories(mFileData->mFilesOrDirectories);
state->SetStateProperty(inputState);
state->contentData() =
SaveFileContentData(mFileData->mFilesOrDirectories);
}
break;
case VALUE_MODE_VALUE:
@ -6411,7 +6305,6 @@ HTMLInputElement::SaveState()
return NS_OK;
}
RefPtr<HTMLInputElementState> inputState = new HTMLInputElementState();
nsAutoString value;
GetValue(value, CallerType::System);
@ -6427,8 +6320,7 @@ HTMLInputElement::SaveState()
}
}
inputState->SetValue(value);
state->SetStateProperty(inputState);
state->contentData() = Move(value);
break;
}
@ -6439,7 +6331,8 @@ HTMLInputElement::SaveState()
if (state) {
// We do not want to save the real disabled state but the disabled
// attribute.
state->SetDisabled(HasAttr(kNameSpaceID_None, nsGkAtoms::disabled));
state->disabled() = HasAttr(kNameSpaceID_None, nsGkAtoms::disabled);
state->disabledSet() = true;
}
}
@ -6615,50 +6508,85 @@ HTMLInputElement::RemoveStates(EventStates aStates)
nsGenericHTMLFormElementWithState::RemoveStates(aStates);
}
static nsTArray<OwningFileOrDirectory>
RestoreFileContentData(nsPIDOMWindowInner* aWindow,
const nsTArray<FileContentData>& aData)
{
nsTArray<OwningFileOrDirectory> res(aData.Length());
for (auto& it : aData) {
if (it.type() == FileContentData::TBlobImplPtr) {
if (!it.get_BlobImplPtr()) {
// Serialization failed, skip this file.
continue;
}
RefPtr<File> file = File::Create(aWindow, it.get_BlobImplPtr());
MOZ_ASSERT(file);
OwningFileOrDirectory* element = res.AppendElement();
element->SetAsFile() = file;
} else {
MOZ_ASSERT(it.type() == FileContentData::TnsString);
nsCOMPtr<nsIFile> file;
nsresult rv = NS_NewLocalFile(it.get_nsString(), true,
getter_AddRefs(file));
if (NS_WARN_IF(NS_FAILED(rv))) {
continue;
}
RefPtr<Directory> directory = Directory::Create(aWindow, file);
MOZ_ASSERT(directory);
OwningFileOrDirectory* element = res.AppendElement();
element->SetAsDirectory() = directory;
}
}
return res;
}
bool
HTMLInputElement::RestoreState(nsPresState* aState)
HTMLInputElement::RestoreState(PresState* aState)
{
bool restoredCheckedState = false;
nsCOMPtr<HTMLInputElementState> inputState
(do_QueryInterface(aState->GetStateProperty()));
const PresContentData& inputState = aState->contentData();
if (inputState) {
switch (GetValueMode()) {
case VALUE_MODE_DEFAULT_ON:
if (inputState->IsCheckedSet()) {
restoredCheckedState = true;
DoSetChecked(inputState->GetChecked(), true, true);
switch (GetValueMode()) {
case VALUE_MODE_DEFAULT_ON:
if (inputState.type() == PresContentData::TCheckedContentData) {
restoredCheckedState = true;
bool checked = inputState.get_CheckedContentData().checked();
DoSetChecked(checked, true, true);
}
break;
case VALUE_MODE_FILENAME:
if (inputState.type() == PresContentData::TArrayOfFileContentData) {
nsPIDOMWindowInner* window = OwnerDoc()->GetInnerWindow();
if (window) {
nsTArray<OwningFileOrDirectory> array =
RestoreFileContentData(window, inputState);
SetFilesOrDirectories(array, true);
}
}
break;
case VALUE_MODE_VALUE:
case VALUE_MODE_DEFAULT:
if (GetValueMode() == VALUE_MODE_DEFAULT &&
mType != NS_FORM_INPUT_HIDDEN) {
break;
case VALUE_MODE_FILENAME:
{
nsPIDOMWindowInner* window = OwnerDoc()->GetInnerWindow();
if (window) {
nsTArray<OwningFileOrDirectory> array;
inputState->GetFilesOrDirectories(window, array);
SetFilesOrDirectories(array, true);
}
}
break;
case VALUE_MODE_VALUE:
case VALUE_MODE_DEFAULT:
if (GetValueMode() == VALUE_MODE_DEFAULT &&
mType != NS_FORM_INPUT_HIDDEN) {
break;
}
}
if (inputState.type() == PresContentData::TnsString) {
// TODO: What should we do if SetValueInternal fails? (The allocation
// may potentially be big, but most likely we've failed to allocate
// before the type change.)
SetValueInternal(inputState->GetValue(),
SetValueInternal(inputState.get_nsString(),
nsTextEditorState::eSetValue_Notify);
break;
}
}
break;
}
if (aState->IsDisabledSet() && !aState->GetDisabled()) {
if (aState->disabledSet() && !aState->disabled()) {
SetDisabled(false, IgnoreErrors());
}

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

@ -183,7 +183,7 @@ public:
NS_IMETHOD Reset() override;
NS_IMETHOD SubmitNamesValues(HTMLFormSubmission* aFormSubmission) override;
NS_IMETHOD SaveState() override;
virtual bool RestoreState(nsPresState* aState) override;
virtual bool RestoreState(PresState* aState) override;
virtual bool AllowDrop() override;
virtual bool IsDisabledForEvents(EventMessage aMessage) override;

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

@ -32,7 +32,7 @@
#include "nsISelectControlFrame.h"
#include "nsLayoutUtils.h"
#include "nsMappedAttributes.h"
#include "nsPresState.h"
#include "mozilla/PresState.h"
#include "nsServiceManagerUtils.h"
#include "nsStyleConsts.h"
#include "nsTextNode.h"
@ -42,8 +42,6 @@ NS_IMPL_NS_NEW_HTML_ELEMENT_CHECK_PARSER(Select)
namespace mozilla {
namespace dom {
NS_IMPL_ISUPPORTS(SelectState, SelectState)
//----------------------------------------------------------------------
//
// SafeOptionListMutation
@ -1245,7 +1243,7 @@ HTMLSelectElement::DoneAddingChildren(bool aHaveNotified)
// If we foolishly tried to restore before we were done adding
// content, restore the rest of the options proper-like
if (mRestoreState) {
RestoreStateTo(mRestoreState);
RestoreStateTo(*mRestoreState);
mRestoreState = nullptr;
}
@ -1422,12 +1420,12 @@ HTMLSelectElement::IntrinsicState() const
NS_IMETHODIMP
HTMLSelectElement::SaveState()
{
nsPresState* presState = GetPrimaryPresState();
PresState* presState = GetPrimaryPresState();
if (!presState) {
return NS_OK;
}
RefPtr<SelectState> state = new SelectState();
SelectContentData state;
uint32_t len = Length();
@ -1436,37 +1434,40 @@ HTMLSelectElement::SaveState()
if (option && option->Selected()) {
nsAutoString value;
option->GetValue(value);
state->PutOption(optIndex, value);
if (value.IsEmpty()) {
state.indices().AppendElement(optIndex);
} else {
state.values().AppendElement(Move(value));
}
}
}
presState->SetStateProperty(state);
presState->contentData() = Move(state);
if (mDisabledChanged) {
// We do not want to save the real disabled state but the disabled
// attribute.
presState->SetDisabled(HasAttr(kNameSpaceID_None, nsGkAtoms::disabled));
presState->disabled() = HasAttr(kNameSpaceID_None, nsGkAtoms::disabled);
presState->disabledSet() = true;
}
return NS_OK;
}
bool
HTMLSelectElement::RestoreState(nsPresState* aState)
HTMLSelectElement::RestoreState(PresState* aState)
{
// Get the presentation state object to retrieve our stuff out of.
nsCOMPtr<SelectState> state(
do_QueryInterface(aState->GetStateProperty()));
if (state) {
RestoreStateTo(state);
const PresContentData& state = aState->contentData();
if (state.type() == PresContentData::TSelectContentData) {
RestoreStateTo(state.get_SelectContentData());
// Don't flush, if the frame doesn't exist yet it doesn't care if
// we're reset or not.
DispatchContentReset();
}
if (aState->IsDisabledSet() && !aState->GetDisabled()) {
if (aState->disabledSet() && !aState->disabled()) {
SetDisabled(false, IgnoreErrors());
}
@ -1474,10 +1475,11 @@ HTMLSelectElement::RestoreState(nsPresState* aState)
}
void
HTMLSelectElement::RestoreStateTo(SelectState* aNewSelected)
HTMLSelectElement::RestoreStateTo(const SelectContentData& aNewSelected)
{
if (!mIsDoneAddingChildren) {
mRestoreState = aNewSelected;
// Make a copy of the state for us to restore from in the future.
mRestoreState = MakeUnique<SelectContentData>(aNewSelected);
return;
}
@ -1487,13 +1489,20 @@ HTMLSelectElement::RestoreStateTo(SelectState* aNewSelected)
// First clear all
SetOptionsSelectedByIndex(-1, -1, mask);
// Next set the proper ones
for (uint32_t i = 0; i < len; i++) {
// Select by index.
for (uint32_t idx : aNewSelected.indices()) {
if (idx < len) {
SetOptionsSelectedByIndex(idx, idx, IS_SELECTED | SET_DISABLED | NOTIFY);
}
}
// Select by value.
for (uint32_t i = 0; i < len; ++i) {
HTMLOptionElement* option = Item(i);
if (option) {
nsAutoString value;
option->GetValue(value);
if (aNewSelected->ContainsOption(i, value)) {
if (aNewSelected.values().Contains(value)) {
SetOptionsSelectedByIndex(i, i, IS_SELECTED | SET_DISABLED | NOTIFY);
}
}

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

@ -24,64 +24,19 @@ class nsContentList;
class nsIDOMHTMLOptionElement;
class nsIHTMLCollection;
class nsISelectControlFrame;
class nsPresState;
namespace mozilla {
class EventChainPostVisitor;
class EventChainPreVisitor;
class SelectContentData;
class PresState;
namespace dom {
class HTMLFormSubmission;
class HTMLSelectElement;
#define NS_SELECT_STATE_IID \
{ /* 4db54c7c-d159-455f-9d8e-f60ee466dbf3 */ \
0x4db54c7c, \
0xd159, \
0x455f, \
{0x9d, 0x8e, 0xf6, 0x0e, 0xe4, 0x66, 0xdb, 0xf3} \
}
/**
* The restore state used by select
*/
class SelectState : public nsISupports
{
public:
SelectState()
{
}
NS_DECLARE_STATIC_IID_ACCESSOR(NS_SELECT_STATE_IID)
NS_DECL_ISUPPORTS
void PutOption(int32_t aIndex, const nsAString& aValue)
{
// If the option is empty, store the index. If not, store the value.
if (aValue.IsEmpty()) {
mIndices.Put(aIndex);
} else {
mValues.Put(aValue);
}
}
bool ContainsOption(int32_t aIndex, const nsAString& aValue)
{
return mValues.Contains(aValue) || mIndices.Contains(aIndex);
}
private:
virtual ~SelectState()
{
}
nsCheapSet<nsStringHashKey> mValues;
nsCheapSet<nsUint32HashKey> mIndices;
};
NS_DEFINE_STATIC_IID_ACCESSOR(SelectState, NS_SELECT_STATE_IID)
class MOZ_STACK_CLASS SafeOptionListMutation
{
public:
@ -301,7 +256,7 @@ public:
NS_IMETHOD Reset() override;
NS_IMETHOD SubmitNamesValues(HTMLFormSubmission* aFormSubmission) override;
NS_IMETHOD SaveState() override;
virtual bool RestoreState(nsPresState* aState) override;
virtual bool RestoreState(PresState* aState) override;
virtual bool IsDisabledForEvents(EventMessage aMessage) override;
virtual void FieldSetDisabledChanged(bool aNotify) override;
@ -489,7 +444,7 @@ protected:
* Restore state to a particular state string (representing the options)
* @param aNewSelected the state string to restore to
*/
void RestoreStateTo(SelectState* aNewSelected);
void RestoreStateTo(const SelectContentData& aNewSelected);
// Adding options
/**
@ -647,7 +602,7 @@ protected:
* The temporary restore state in case we try to restore before parser is
* done adding options
*/
nsCOMPtr<SelectState> mRestoreState;
UniquePtr<SelectContentData> mRestoreState;
/**
* The live list of selected options.

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

@ -35,7 +35,7 @@
#include "nsMappedAttributes.h"
#include "nsPIDOMWindow.h"
#include "nsPresContext.h"
#include "nsPresState.h"
#include "mozilla/PresState.h"
#include "nsReadableUtils.h"
#include "nsStyleConsts.h"
#include "nsTextEditorState.h"
@ -831,7 +831,7 @@ HTMLTextAreaElement::SaveState()
nsresult rv = NS_OK;
// Only save if value != defaultValue (bug 62713)
nsPresState *state = nullptr;
PresState *state = nullptr;
if (mValueChanged) {
state = GetPrimaryPresState();
if (state) {
@ -848,13 +848,7 @@ HTMLTextAreaElement::SaveState()
return rv;
}
nsCOMPtr<nsISupportsString> pState =
do_CreateInstance(NS_SUPPORTS_STRING_CONTRACTID);
if (!pState) {
return NS_ERROR_OUT_OF_MEMORY;
}
pState->SetData(value);
state->SetStateProperty(pState);
state->contentData() = Move(value);
}
}
@ -866,27 +860,25 @@ HTMLTextAreaElement::SaveState()
if (state) {
// We do not want to save the real disabled state but the disabled
// attribute.
state->SetDisabled(HasAttr(kNameSpaceID_None, nsGkAtoms::disabled));
state->disabled() = HasAttr(kNameSpaceID_None, nsGkAtoms::disabled);
state->disabledSet() = true;
}
}
return rv;
}
bool
HTMLTextAreaElement::RestoreState(nsPresState* aState)
HTMLTextAreaElement::RestoreState(PresState* aState)
{
nsCOMPtr<nsISupportsString> state
(do_QueryInterface(aState->GetStateProperty()));
const PresContentData& state = aState->contentData();
if (state) {
nsAutoString data;
state->GetData(data);
if (state.type() == PresContentData::TnsString) {
ErrorResult rv;
SetValue(data, rv);
SetValue(state.get_nsString(), rv);
ENSURE_SUCCESS(rv, false);
}
if (aState->IsDisabledSet() && !aState->GetDisabled()) {
if (aState->disabledSet() && !aState->disabled()) {
SetDisabled(false, IgnoreErrors());
}

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

@ -25,13 +25,13 @@
class nsIControllers;
class nsIDocument;
class nsPresContext;
class nsPresState;
namespace mozilla {
class EventChainPostVisitor;
class EventChainPreVisitor;
class EventStates;
class PresState;
namespace dom {
@ -75,7 +75,7 @@ public:
NS_IMETHOD Reset() override;
NS_IMETHOD SubmitNamesValues(HTMLFormSubmission* aFormSubmission) override;
NS_IMETHOD SaveState() override;
virtual bool RestoreState(nsPresState* aState) override;
virtual bool RestoreState(PresState* aState) override;
virtual bool IsDisabledForEvents(EventMessage aMessage) override;
virtual void FieldSetDisabledChanged(bool aNotify) override;

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

@ -49,7 +49,7 @@
#include "nsContainerFrame.h"
#include "nsStyleUtil.h"
#include "nsPresState.h"
#include "mozilla/PresState.h"
#include "nsILayoutHistoryState.h"
#include "nsHTMLParts.h"
@ -2756,7 +2756,7 @@ nsGenericHTMLFormElementWithState::GenerateStateKey()
return NS_OK;
}
nsPresState*
PresState*
nsGenericHTMLFormElementWithState::GetPrimaryPresState()
{
if (mStateKey.IsEmpty()) {
@ -2770,10 +2770,11 @@ nsGenericHTMLFormElementWithState::GetPrimaryPresState()
}
// Get the pres state for this key, if it doesn't exist, create one.
nsPresState* result = history->GetState(mStateKey);
PresState* result = history->GetState(mStateKey);
if (!result) {
result = new nsPresState();
history->AddState(mStateKey, result);
UniquePtr<PresState> newState = NewPresState();
result = newState.get();
history->AddState(mStateKey, Move(newState));
}
return result;
@ -2815,9 +2816,8 @@ nsGenericHTMLFormElementWithState::RestoreFormControlState()
return false;
}
nsPresState *state;
// Get the pres state for this key
state = history->GetState(mStateKey);
PresState* state = history->GetState(mStateKey);
if (state) {
bool result = RestoreState(state);
history->RemoveState(mStateKey);

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

@ -25,7 +25,6 @@ class nsIFormControlFrame;
class nsIFrame;
class nsILayoutHistoryState;
class nsIURI;
class nsPresState;
struct nsSize;
namespace mozilla {
@ -35,6 +34,7 @@ class EventChainVisitor;
class EventListenerManager;
class EventStates;
class TextEditor;
class PresState;
namespace dom {
class HTMLFormElement;
class HTMLMenuElement;
@ -1018,7 +1018,7 @@ public:
return NS_OK;
}
virtual bool RestoreState(nsPresState* aState) override
virtual bool RestoreState(mozilla::PresState* aState) override
{
return false;
}
@ -1184,7 +1184,7 @@ public:
* Get the presentation state for a piece of content, or create it if it does
* not exist. Generally used by SaveState().
*/
nsPresState* GetPrimaryPresState();
mozilla::PresState* GetPrimaryPresState();
/**
* Get the layout history object for a particular piece of content.

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

@ -9,9 +9,8 @@
#include "mozilla/EventForwards.h"
#include "nsISupports.h"
class nsPresState;
namespace mozilla {
class PresState;
namespace dom {
class Element;
class HTMLFieldSetElement;
@ -169,7 +168,7 @@ public:
* @return true if the form control was a checkbox and its
* checked state was restored, false otherwise.
*/
virtual bool RestoreState(nsPresState* aState) = 0;
virtual bool RestoreState(mozilla::PresState* aState) = 0;
virtual bool AllowDrop() = 0;

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

@ -15,7 +15,7 @@
#include "nsPlaceholderFrame.h"
#include "nsGkAtoms.h"
#include "nsILayoutHistoryState.h"
#include "nsPresState.h"
#include "mozilla/PresState.h"
#include "mozilla/ComputedStyle.h"
#include "mozilla/dom/Element.h"
#include "mozilla/UndisplayedNode.h"
@ -152,8 +152,7 @@ nsFrameManager::CaptureFrameStateFor(nsIFrame* aFrame,
}
// Capture the state, exit early if we get null (nothing to save)
nsAutoPtr<nsPresState> frameState;
nsresult rv = statefulFrame->SaveState(getter_Transfers(frameState));
UniquePtr<PresState> frameState = statefulFrame->SaveState();
if (!frameState) {
return;
}
@ -163,13 +162,13 @@ nsFrameManager::CaptureFrameStateFor(nsIFrame* aFrame,
nsAutoCString stateKey;
nsIContent* content = aFrame->GetContent();
nsIDocument* doc = content ? content->GetUncomposedDoc() : nullptr;
rv = statefulFrame->GenerateStateKey(content, doc, stateKey);
nsresult rv = statefulFrame->GenerateStateKey(content, doc, stateKey);
if(NS_FAILED(rv) || stateKey.IsEmpty()) {
return;
}
// Store the state. aState owns frameState now.
aState->AddState(stateKey, frameState.forget());
aState->AddState(stateKey, Move(frameState));
}
void
@ -232,7 +231,7 @@ nsFrameManager::RestoreFrameStateFor(nsIFrame* aFrame,
}
// Get the state from the hash
nsPresState* frameState = aState->GetState(stateKey);
PresState* frameState = aState->GetState(stateKey);
if (!frameState) {
return;
}

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

@ -10,9 +10,9 @@
#include "nsISupports.idl"
interface nsPresState;
[ptr] native nsPresStatePtr(nsPresState);
[ptr] native PresStatePtr(mozilla::PresState);
native PresStateUnique(mozilla::UniquePtr<mozilla::PresState>);
[ref] native nsCString(const nsCString);
native constBool(const bool);
@ -52,7 +52,7 @@ interface nsILayoutHistoryState : nsISupports
out float aRes, out boolean aScaleToRes);
/**
* Constructs a new nsPresState object based on the supplied data
* Constructs a new PresState object based on the supplied data
* and adds it to the LayoutHistoryState.
*/
void addNewPresState(in ACString aKey,
@ -68,12 +68,12 @@ interface nsILayoutHistoryState : nsISupports
* It will be freed when RemoveState() is called or when the
* LayoutHistoryState is destroyed.
*/
[noscript, notxpcom, nostdcall] void AddState(in nsCString aKey, in nsPresStatePtr aState);
[noscript, notxpcom, nostdcall] void AddState(in nsCString aKey, in PresStateUnique aState);
/**
* Look up the state object for |aKey|.
*/
[noscript, notxpcom, nostdcall] nsPresStatePtr GetState(in nsCString aKey);
[noscript, notxpcom, nostdcall] PresStatePtr GetState(in nsCString aKey);
/**
* Remove the state object for |aKey|.
@ -92,7 +92,7 @@ interface nsILayoutHistoryState : nsISupports
[noscript, notxpcom, nostdcall] void SetScrollPositionOnly(in constBool aFlag);
/**
* Resets nsPresState::GetScrollState of all nsPresState objects to 0,0.
* Resets PresState::GetScrollState of all PresState objects to 0,0.
*/
[noscript, notxpcom, nostdcall] void ResetScrollState();
};

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

@ -12,8 +12,11 @@
#include "nsILayoutHistoryState.h"
#include "nsWeakReference.h"
#include "nsClassHashtable.h"
#include "nsPresState.h"
#include "mozilla/PresState.h"
#include "mozilla/Attributes.h"
#include "mozilla/UniquePtr.h"
using namespace mozilla;
class nsLayoutHistoryState final : public nsILayoutHistoryState,
public nsSupportsWeakReference
@ -31,7 +34,7 @@ private:
~nsLayoutHistoryState() {}
bool mScrollPositionOnly;
nsClassHashtable<nsCStringHashKey,nsPresState> mStates;
nsDataHashtable<nsCStringHashKey, UniquePtr<PresState>> mStates;
};
@ -79,17 +82,17 @@ nsLayoutHistoryState::GetPresState(const nsACString& aKey,
bool* aAllowScrollOriginDowngrade,
float* aRes, bool* aScaleToRes)
{
nsPresState* state = GetState(nsCString(aKey));
PresState* state = GetState(nsCString(aKey));
if (!state) {
return NS_ERROR_FAILURE;
}
*aScrollX = state->GetScrollPosition().x;
*aScrollY = state->GetScrollPosition().y;
*aAllowScrollOriginDowngrade = state->GetAllowScrollOriginDowngrade();
*aRes = state->GetResolution();
*aScaleToRes = state->GetScaleToResolution();
*aScrollX = state->scrollState().x;
*aScrollY = state->scrollState().y;
*aAllowScrollOriginDowngrade = state->allowScrollOriginDowngrade();
*aRes = state->resolution();
*aScaleToRes = state->scaleToResolution();
return NS_OK;
}
@ -100,32 +103,36 @@ nsLayoutHistoryState::AddNewPresState(const nsACString& aKey,
bool aAllowScrollOriginDowngrade,
float aRes, bool aScaleToRes)
{
nsPresState* newState = new nsPresState();
newState->SetScrollState(nsPoint(aScrollX, aScrollY));
newState->SetAllowScrollOriginDowngrade(aAllowScrollOriginDowngrade);
newState->SetResolution(aRes);
newState->SetScaleToResolution(aScaleToRes);
UniquePtr<PresState> newState = NewPresState();
newState->scrollState() = nsPoint(aScrollX, aScrollY);
newState->allowScrollOriginDowngrade() = aAllowScrollOriginDowngrade;
newState->resolution() = aRes;
newState->scaleToResolution() = aScaleToRes;
mStates.Put(nsCString(aKey), newState);
mStates.Put(nsCString(aKey), Move(newState));
return NS_OK;
}
void
nsLayoutHistoryState::AddState(const nsCString& aStateKey, nsPresState* aState)
nsLayoutHistoryState::AddState(const nsCString& aStateKey, UniquePtr<PresState> aState)
{
mStates.Put(aStateKey, aState);
mStates.Put(aStateKey, Move(aState));
}
nsPresState*
PresState*
nsLayoutHistoryState::GetState(const nsCString& aKey)
{
nsPresState* state = nullptr;
bool entryExists = mStates.Get(aKey, &state);
UniquePtr<PresState>* statePtr = mStates.GetValue(aKey);
if (!statePtr) {
return nullptr;
}
PresState* state = statePtr->get();
if (entryExists && mScrollPositionOnly) {
if (mScrollPositionOnly) {
// Ensure any state that shouldn't be restored is removed
state->ClearNonScrollState();
state->contentData() = void_t();
state->disabledSet() = false;
}
return state;
@ -153,9 +160,9 @@ void
nsLayoutHistoryState::ResetScrollState()
{
for (auto iter = mStates.Iter(); !iter.Done(); iter.Next()) {
nsPresState* state = iter.UserData();
PresState* state = iter.Data().get();
if (state) {
state->SetScrollState(nsPoint(0, 0));
state->scrollState() = nsPoint(0, 0);
}
}
}

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

@ -21,7 +21,7 @@
#include "nsIListControlFrame.h"
#include "nsPIDOMWindow.h"
#include "nsIPresShell.h"
#include "nsPresState.h"
#include "mozilla/PresState.h"
#include "nsView.h"
#include "nsViewManager.h"
#include "nsIContentInlines.h"
@ -50,6 +50,7 @@
#include "mozilla/Unused.h"
#include "gfx2DGlue.h"
#include "mozilla/widget/nsAutoRollup.h"
#include "nsILayoutHistoryState.h"
#ifdef XP_WIN
#define COMBOBOX_ROLLUP_CONSUME_EVENT 0
@ -68,7 +69,6 @@ nsComboboxControlFrame::RedisplayTextEvent::Run()
return NS_OK;
}
class nsPresState;
#define FIX_FOR_BUG_53259
@ -1694,22 +1694,21 @@ nsComboboxControlFrame::OnContentReset()
//--------------------------------------------------------
// nsIStatefulFrame
//--------------------------------------------------------
NS_IMETHODIMP
nsComboboxControlFrame::SaveState(nsPresState** aState)
UniquePtr<PresState>
nsComboboxControlFrame::SaveState()
{
MOZ_ASSERT(!(*aState));
(*aState) = new nsPresState();
(*aState)->SetDroppedDown(mDroppedDown);
return NS_OK;
UniquePtr<PresState> state = NewPresState();
state->droppedDown() = mDroppedDown;
return state;
}
NS_IMETHODIMP
nsComboboxControlFrame::RestoreState(nsPresState* aState)
nsComboboxControlFrame::RestoreState(PresState* aState)
{
if (!aState) {
return NS_ERROR_FAILURE;
}
ShowList(aState->GetDroppedDown()); // might destroy us
ShowList(aState->droppedDown()); // might destroy us
return NS_OK;
}

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

@ -213,8 +213,8 @@ public:
virtual nsIWidget* GetRollupWidget() override;
//nsIStatefulFrame
NS_IMETHOD SaveState(nsPresState** aState) override;
NS_IMETHOD RestoreState(nsPresState* aState) override;
mozilla::UniquePtr<mozilla::PresState> SaveState() override;
NS_IMETHOD RestoreState(mozilla::PresState* aState) override;
NS_IMETHOD GenerateStateKey(nsIContent* aContent,
nsIDocument* aDocument,
nsACString& aKey) override;

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

@ -32,9 +32,10 @@
#include "nsINode.h"
#include "nsPIDOMWindow.h" //needed for notify selection changed to update the menus ect.
#include "nsQueryObject.h"
#include "nsILayoutHistoryState.h"
#include "nsFocusManager.h"
#include "nsPresState.h"
#include "mozilla/PresState.h"
#include "nsAttrValueInlines.h"
#include "mozilla/dom/Selection.h"
#include "mozilla/TextEditRules.h"
@ -1233,9 +1234,9 @@ nsTextControlFrame::SetInitialChildList(ChildListID aListID,
// div, do it here!
nsIStatefulFrame* statefulFrame = do_QueryFrame(first);
NS_ASSERTION(statefulFrame, "unexpected type of frame for the anonymous div");
nsPresState fakePresState;
fakePresState.SetScrollState(*contentScrollPos);
statefulFrame->RestoreState(&fakePresState);
UniquePtr<PresState> fakePresState = NewPresState();
fakePresState->scrollState() = *contentScrollPos;
statefulFrame->RestoreState(fakePresState.get());
RemoveProperty(ContentScrollPos());
delete contentScrollPos;
}
@ -1348,13 +1349,9 @@ nsTextControlFrame::GetOwnedFrameSelection()
return txtCtrl->GetConstFrameSelection();
}
NS_IMETHODIMP
nsTextControlFrame::SaveState(nsPresState** aState)
UniquePtr<PresState>
nsTextControlFrame::SaveState()
{
NS_ENSURE_ARG_POINTER(aState);
*aState = nullptr;
nsCOMPtr<nsITextControlElement> txtCtrl = do_QueryInterface(GetContent());
NS_ASSERTION(txtCtrl, "Content not a text control element");
@ -1363,15 +1360,15 @@ nsTextControlFrame::SaveState(nsPresState** aState)
// Query the nsIStatefulFrame from the HTMLScrollFrame
nsIStatefulFrame* scrollStateFrame = do_QueryFrame(rootNode->GetPrimaryFrame());
if (scrollStateFrame) {
return scrollStateFrame->SaveState(aState);
return scrollStateFrame->SaveState();
}
}
return NS_OK;
return nullptr;
}
NS_IMETHODIMP
nsTextControlFrame::RestoreState(nsPresState* aState)
nsTextControlFrame::RestoreState(PresState* aState)
{
NS_ENSURE_ARG_POINTER(aState);
@ -1390,7 +1387,7 @@ nsTextControlFrame::RestoreState(nsPresState* aState)
// Most likely, we don't have our anonymous content constructed yet, which
// would cause us to end up here. In this case, we'll just store the scroll
// pos ourselves, and forward it to the scroll frame later when it's created.
SetProperty(ContentScrollPos(), new nsPoint(aState->GetScrollPosition()));
SetProperty(ContentScrollPos(), new nsPoint(aState->scrollState()));
return NS_OK;
}

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

@ -158,8 +158,8 @@ public:
//==== NSISTATEFULFRAME
NS_IMETHOD SaveState(nsPresState** aState) override;
NS_IMETHOD RestoreState(nsPresState* aState) override;
UniquePtr<PresState> SaveState() override;
NS_IMETHOD RestoreState(PresState* aState) override;
//=== END NSISTATEFULFRAME

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

@ -29,7 +29,7 @@
#include "nsITextControlFrame.h"
#include "nsNodeInfoManager.h"
#include "nsContentCreatorFunctions.h"
#include "nsPresState.h"
#include "mozilla/PresState.h"
#include "nsIHTMLDocument.h"
#include "nsContentUtils.h"
#include "nsLayoutUtils.h"
@ -58,6 +58,7 @@
#include "nsIScrollPositionListener.h"
#include "StickyScrollContainer.h"
#include "nsIFrameInlines.h"
#include "nsILayoutHistoryState.h"
#include "gfxPlatform.h"
#include "gfxPrefs.h"
#include "ScrollAnimationPhysics.h"
@ -6201,7 +6202,7 @@ ScrollFrameHelper::GetCoordAttribute(nsIFrame* aBox, nsAtom* aAtom,
return aDefaultValue;
}
nsPresState*
UniquePtr<PresState>
ScrollFrameHelper::SaveState() const
{
nsIScrollbarMediator* mediator = do_QueryFrame(GetScrolledFrame());
@ -6217,7 +6218,7 @@ ScrollFrameHelper::SaveState() const
return nullptr;
}
nsPresState* state = new nsPresState();
UniquePtr<PresState> state = NewPresState();
bool allowScrollOriginDowngrade =
!nsLayoutUtils::CanScrollOriginClobberApz(mLastScrollOrigin) ||
mAllowScrollOriginDowngrade;
@ -6238,36 +6239,36 @@ ScrollFrameHelper::SaveState() const
if (mRestorePos.y != -1 && pt == mLastPos) {
pt = mRestorePos;
}
state->SetScrollState(pt);
state->SetAllowScrollOriginDowngrade(allowScrollOriginDowngrade);
state->scrollState() = pt;
state->allowScrollOriginDowngrade() = allowScrollOriginDowngrade;
if (mIsRoot) {
// Only save resolution properties for root scroll frames
nsIPresShell* shell = mOuter->PresShell();
state->SetResolution(shell->GetResolution());
state->SetScaleToResolution(shell->ScaleToResolution());
state->resolution() = shell->GetResolution();
state->scaleToResolution() = shell->ScaleToResolution();
}
return state;
}
void
ScrollFrameHelper::RestoreState(nsPresState* aState)
ScrollFrameHelper::RestoreState(PresState* aState)
{
mRestorePos = aState->GetScrollPosition();
mRestorePos = aState->scrollState();
MOZ_ASSERT(mLastScrollOrigin == nsGkAtoms::other);
mAllowScrollOriginDowngrade = aState->GetAllowScrollOriginDowngrade();
mAllowScrollOriginDowngrade = aState->allowScrollOriginDowngrade();
mDidHistoryRestore = true;
mLastPos = mScrolledFrame ? GetLogicalScrollPosition() : nsPoint(0,0);
// Resolution properties should only exist on root scroll frames.
MOZ_ASSERT(mIsRoot || (!aState->GetScaleToResolution() &&
aState->GetResolution() == 1.0));
MOZ_ASSERT(mIsRoot || (!aState->scaleToResolution() &&
aState->resolution() == 1.0));
if (mIsRoot) {
nsIPresShell* presShell = mOuter->PresShell();
if (aState->GetScaleToResolution()) {
presShell->SetResolutionAndScaleTo(aState->GetResolution());
if (aState->scaleToResolution()) {
presShell->SetResolutionAndScaleTo(aState->resolution());
} else {
presShell->SetResolution(aState->GetResolution());
presShell->SetResolution(aState->resolution());
}
}
}

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

@ -24,12 +24,12 @@
#include "nsExpirationTracker.h"
#include "TextOverflow.h"
#include "ScrollVelocityQueue.h"
#include "mozilla/PresState.h"
class nsPresContext;
class nsIPresShell;
class nsIContent;
class nsAtom;
class nsPresState;
class nsIScrollPositionListener;
namespace mozilla {
@ -297,8 +297,8 @@ public:
nsSize GetLineScrollAmount() const;
nsSize GetPageScrollAmount() const;
nsPresState* SaveState() const;
void RestoreState(nsPresState* aState);
mozilla::UniquePtr<mozilla::PresState> SaveState() const;
void RestoreState(mozilla::PresState* aState);
nsIFrame* GetScrolledFrame() const { return mScrolledFrame; }
nsIFrame* GetScrollbarBox(bool aVertical) const {
@ -1004,12 +1004,10 @@ public:
}
// nsIStatefulFrame
NS_IMETHOD SaveState(nsPresState** aState) override {
NS_ENSURE_ARG_POINTER(aState);
*aState = mHelper.SaveState();
return NS_OK;
mozilla::UniquePtr<mozilla::PresState> SaveState() override {
return mHelper.SaveState();
}
NS_IMETHOD RestoreState(nsPresState* aState) override {
NS_IMETHOD RestoreState(mozilla::PresState* aState) override {
NS_ENSURE_ARG_POINTER(aState);
mHelper.RestoreState(aState);
return NS_OK;
@ -1431,12 +1429,10 @@ public:
}
// nsIStatefulFrame
NS_IMETHOD SaveState(nsPresState** aState) override {
NS_ENSURE_ARG_POINTER(aState);
*aState = mHelper.SaveState();
return NS_OK;
mozilla::UniquePtr<mozilla::PresState> SaveState() override {
return mHelper.SaveState();
}
NS_IMETHOD RestoreState(nsPresState* aState) override {
NS_IMETHOD RestoreState(mozilla::PresState* aState) override {
NS_ENSURE_ARG_POINTER(aState);
mHelper.RestoreState(aState);
return NS_OK;

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

@ -15,19 +15,20 @@
#include "nsContentUtils.h"
#include "nsQueryFrame.h"
class nsPresState;
namespace mozilla {
class PresState;
} // namespace mozilla
class nsIStatefulFrame
{
public:
NS_DECL_QUERYFRAME_TARGET(nsIStatefulFrame)
// Save the state for this frame. If this method succeeds, the caller is
// responsible for deleting the resulting state when done with it.
NS_IMETHOD SaveState(nsPresState** aState) = 0;
// Save the state for this frame.
virtual mozilla::UniquePtr<mozilla::PresState> SaveState() = 0;
// Restore the state for this frame from aState
NS_IMETHOD RestoreState(nsPresState* aState) = 0;
NS_IMETHOD RestoreState(mozilla::PresState* aState) = 0;
// Generate a key for this stateful frame
NS_IMETHOD GenerateStateKey(nsIContent* aContent,