Remove nsIPresState (bug 279699). r+sr=roc.

This commit is contained in:
bryner%brianryner.com 2005-01-27 22:52:53 +00:00
Родитель 3e616c3709
Коммит 5b8aeed3b1
40 изменённых файлов: 308 добавлений и 313 удалений

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

@ -40,7 +40,7 @@
#include "nsISupports.h"
class nsIDOMHTMLFormElement;
class nsPresContext;
class nsIPresState;
class nsPresState;
class nsIContent;
class nsString;
class nsIFormProcessor;
@ -69,8 +69,8 @@ class nsIFormSubmission;
#define NS_FORM_OBJECT 21
#define NS_IFORMCONTROL_IID \
{ 0x282ff440, 0xcd7e, 0x11d1, \
{0x89, 0xad, 0x00, 0x60, 0x08, 0x91, 0x1b, 0x81} }
{ 0xfcf27549, 0xbd77, 0x455a, \
{0x8c, 0x3e, 0xbb, 0x20, 0xc5, 0xaf, 0x7b, 0x86} }
/**
@ -138,7 +138,7 @@ public:
* @return PR_TRUE if the form control was a checkbox and its
* checked state was restored, PR_FALSE otherwise.
*/
virtual PRBool RestoreState(nsIPresState* aState) = 0;
virtual PRBool RestoreState(nsPresState* aState) = 0;
virtual PRBool AllowDrop() = 0;
};

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

@ -40,7 +40,6 @@
interface nsIContent;
interface nsIDOMHTMLOptionElement;
interface nsPresContext;
interface nsIPresState;
/**
* This interface is used to notify a SELECT when OPTION

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

@ -88,7 +88,7 @@
#include "nsIScriptContext.h"
#include "nsRuleData.h"
#include "nsIPresState.h"
#include "nsPresState.h"
#include "nsILayoutHistoryState.h"
#include "nsHTMLParts.h"
@ -139,7 +139,6 @@
#include "nsCOMArray.h"
#include "nsNodeInfoManager.h"
static NS_DEFINE_CID(kPresStateCID, NS_PRESSTATE_CID);
// XXX todo: add in missing out-of-memory checks
//----------------------------------------------------------------------
@ -2253,9 +2252,9 @@ nsGenericHTMLElement::GetFormControlFrameFor(nsIContent* aContent,
return nsnull;
}
nsresult
/* static */ nsresult
nsGenericHTMLElement::GetPrimaryPresState(nsGenericHTMLElement* aContent,
nsIPresState** aPresState)
nsPresState** aPresState)
{
NS_ENSURE_ARG_POINTER(aPresState);
*aPresState = nsnull;
@ -2270,7 +2269,7 @@ nsGenericHTMLElement::GetPrimaryPresState(nsGenericHTMLElement* aContent,
// Get the pres state for this key, if it doesn't exist, create one
result = history->GetState(key, aPresState);
if (!*aPresState) {
result = CallCreateInstance(kPresStateCID, aPresState);
result = NS_NewPresState(aPresState);
if (NS_SUCCEEDED(result)) {
result = history->AddState(key, *aPresState);
}
@ -2338,12 +2337,13 @@ nsGenericHTMLElement::RestoreFormControlState(nsGenericHTMLElement* aContent,
return PR_FALSE;
}
nsCOMPtr<nsIPresState> state;
nsPresState *state;
// Get the pres state for this key
rv = history->GetState(key, getter_AddRefs(state));
rv = history->GetState(key, &state);
if (state) {
PRBool result = aControl->RestoreState(state);
history->RemoveState(key);
return aControl->RestoreState(state);
return result;
}
return PR_FALSE;

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

@ -59,7 +59,7 @@ class nsIDOMCSSStyleDeclaration;
class nsIURI;
class nsIFormControlFrame;
class nsIForm;
class nsIPresState;
class nsPresState;
class nsIScrollableView;
class nsILayoutHistoryState;
struct nsRect;
@ -545,7 +545,7 @@ public:
* @param aPresState the presentation state (out param)
*/
static nsresult GetPrimaryPresState(nsGenericHTMLElement* aContent,
nsIPresState** aPresState);
nsPresState** aPresState);
/**
* Get the layout history object *and* generate the key for a particular
* piece of content.
@ -818,7 +818,7 @@ public:
{
return NS_OK;
}
virtual PRBool RestoreState(nsIPresState* aState)
virtual PRBool RestoreState(nsPresState* aState)
{
return PR_FALSE;
}

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

@ -73,7 +73,7 @@
#include "nsIEditor.h"
#include "nsGUIEvent.h"
#include "nsIPresState.h"
#include "nsPresState.h"
#include "nsLayoutErrors.h"
#include "nsIDOMEvent.h"
#include "nsIDOMNSEvent.h"
@ -169,7 +169,7 @@ public:
NS_IMETHOD SubmitNamesValues(nsIFormSubmission* aFormSubmission,
nsIContent* aSubmitElement);
NS_IMETHOD SaveState();
virtual PRBool RestoreState(nsIPresState* aState);
virtual PRBool RestoreState(nsPresState* aState);
virtual PRBool AllowDrop();
// nsIContent
@ -2338,7 +2338,7 @@ nsHTMLInputElement::SaveState()
{
nsresult rv = NS_OK;
nsCOMPtr<nsIPresState> state;
nsPresState *state = nsnull;
switch (mType) {
case NS_FORM_INPUT_CHECKBOX:
case NS_FORM_INPUT_RADIO:
@ -2351,7 +2351,7 @@ nsHTMLInputElement::SaveState()
// (always save if it's a radio button so that the checked
// state of all radio buttons is restored)
if (mType == NS_FORM_INPUT_RADIO || checked != defaultChecked) {
rv = GetPrimaryPresState(this, getter_AddRefs(state));
rv = GetPrimaryPresState(this, &state);
if (state) {
if (checked) {
rv = state->SetStateProperty(NS_LITERAL_STRING("checked"),
@ -2374,7 +2374,7 @@ nsHTMLInputElement::SaveState()
case NS_FORM_INPUT_HIDDEN:
{
if (GET_BOOLBIT(mBitField, BF_VALUE_CHANGED)) {
rv = GetPrimaryPresState(this, getter_AddRefs(state));
rv = GetPrimaryPresState(this, &state);
if (state) {
nsAutoString value;
GetValue(value);
@ -2392,7 +2392,7 @@ nsHTMLInputElement::SaveState()
}
if (GET_BOOLBIT(mBitField, BF_DISABLED_CHANGED)) {
rv |= GetPrimaryPresState(this, getter_AddRefs(state));
rv |= GetPrimaryPresState(this, &state);
if (state) {
PRBool disabled;
GetDisabled(&disabled);
@ -2452,7 +2452,7 @@ nsHTMLInputElement::DoneCreatingElement()
}
PRBool
nsHTMLInputElement::RestoreState(nsIPresState* aState)
nsHTMLInputElement::RestoreState(nsPresState* aState)
{
PRBool restoredCheckedState = PR_FALSE;

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

@ -79,7 +79,7 @@ public:
NS_IMETHOD SubmitNamesValues(nsIFormSubmission* aFormSubmission,
nsIContent* aSubmitElement);
NS_IMETHOD SaveState();
virtual PRBool RestoreState(nsIPresState* aState);
virtual PRBool RestoreState(nsPresState* aState);
virtual void DoneAddingChildren();
virtual PRBool IsDoneAddingChildren();
@ -180,7 +180,7 @@ nsHTMLObjectElement::SaveState()
}
PRBool
nsHTMLObjectElement::RestoreState(nsIPresState* aState)
nsHTMLObjectElement::RestoreState(nsPresState* aState)
{
return PR_FALSE;
}

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

@ -67,7 +67,7 @@
// PresState
#include "nsXPCOM.h"
#include "nsIPresState.h"
#include "nsPresState.h"
#include "nsIComponentManager.h"
#include "nsCheapSets.h"
@ -237,7 +237,7 @@ public:
NS_IMETHOD SubmitNamesValues(nsIFormSubmission* aFormSubmission,
nsIContent* aSubmitElement);
NS_IMETHOD SaveState();
virtual PRBool RestoreState(nsIPresState* aState);
virtual PRBool RestoreState(nsPresState* aState);
// nsISelectElement
NS_DECL_NSISELECTELEMENT
@ -1783,8 +1783,8 @@ nsHTMLSelectElement::SaveState()
}
}
nsCOMPtr<nsIPresState> presState;
nsresult rv = GetPrimaryPresState(this, getter_AddRefs(presState));
nsPresState *presState = nsnull;
nsresult rv = GetPrimaryPresState(this, &presState);
if (presState) {
rv = presState->SetStatePropertyAsSupports(NS_LITERAL_STRING("selecteditems"),
state);
@ -1797,7 +1797,7 @@ nsHTMLSelectElement::SaveState()
}
PRBool
nsHTMLSelectElement::RestoreState(nsIPresState* aState)
nsHTMLSelectElement::RestoreState(nsPresState* aState)
{
// Get the presentation state object to retrieve our stuff out of.
nsCOMPtr<nsISupports> state;

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

@ -80,7 +80,7 @@ public:
NS_IMETHOD SubmitNamesValues(nsIFormSubmission* aFormSubmission,
nsIContent* aSubmitElement);
NS_IMETHOD SaveState();
virtual PRBool RestoreState(nsIPresState* aState);
virtual PRBool RestoreState(nsPresState* aState);
virtual PRBool ParseAttribute(nsIAtom* aAttribute,
const nsAString& aValue,
@ -149,7 +149,7 @@ nsHTMLObjectElement::SaveState()
}
PRBool
nsHTMLObjectElement::RestoreState(nsIPresState* aState)
nsHTMLObjectElement::RestoreState(nsPresState* aState)
{
return PR_FALSE;
}

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

@ -63,7 +63,7 @@
#include "nsIPrivateDOMEvent.h"
#include "nsGUIEvent.h"
#include "nsLinebreakConverter.h"
#include "nsIPresState.h"
#include "nsPresState.h"
#include "nsIDOMText.h"
#include "nsReadableUtils.h"
#include "nsITextContent.h"
@ -104,7 +104,7 @@ public:
NS_IMETHOD SubmitNamesValues(nsIFormSubmission* aFormSubmission,
nsIContent* aSubmitElement);
NS_IMETHOD SaveState();
virtual PRBool RestoreState(nsIPresState* aState);
virtual PRBool RestoreState(nsPresState* aState);
// nsITextControlElemet
NS_IMETHOD TakeTextFrameValue(const nsAString& aValue);
@ -817,8 +817,8 @@ nsHTMLTextAreaElement::SaveState()
// Only save if value != defaultValue (bug 62713)
if (mValueChanged) {
nsCOMPtr<nsIPresState> state;
rv = GetPrimaryPresState(this, getter_AddRefs(state));
nsPresState *state = nsnull;
rv = GetPrimaryPresState(this, &state);
if (state) {
nsAutoString value;
GetValueInternal(value, PR_TRUE);
@ -837,7 +837,7 @@ nsHTMLTextAreaElement::SaveState()
}
PRBool
nsHTMLTextAreaElement::RestoreState(nsIPresState* aState)
nsHTMLTextAreaElement::RestoreState(nsPresState* aState)
{
nsAutoString value;
#ifdef DEBUG

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

@ -102,13 +102,13 @@ EXPORTS = \
nsILayoutHistoryState.h \
nsIPercentHeightObserver.h \
nsIPresShell.h \
nsIPresState.h \
nsIReflowCallback.h \
nsLayoutAtomList.h \
nsLayoutAtoms.h \
nsLayoutErrors.h \
nsLayoutUtils.h \
nsPresContext.h \
nsPresState.h \
nsStyleChangeList.h \
nsStyleConsts.h \
$(NULL)

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

@ -66,7 +66,7 @@
#include "nsIStyleRule.h"
#endif
#include "nsILayoutHistoryState.h"
#include "nsIPresState.h"
#include "nsPresState.h"
#include "nsIContent.h"
#include "nsINameSpaceManager.h"
#include "nsIXBLBinding.h"
@ -1717,9 +1717,9 @@ nsFrameManager::CaptureFrameStateFor(nsIFrame* aFrame,
}
// Capture the state, exit early if we get null (nothing to save)
nsCOMPtr<nsIPresState> frameState;
nsresult rv = NS_OK;
rv = statefulFrame->SaveState(GetPresContext(), getter_AddRefs(frameState));
nsAutoPtr<nsPresState> frameState;
nsresult rv = statefulFrame->SaveState(GetPresContext(),
getter_Transfers(frameState));
if (!frameState) {
return;
}
@ -1735,7 +1735,11 @@ nsFrameManager::CaptureFrameStateFor(nsIFrame* aFrame,
}
// Store the state
aState->AddState(stateKey, frameState);
rv = aState->AddState(stateKey, frameState);
if (NS_SUCCEEDED(rv)) {
// aState owns frameState now.
frameState.forget();
}
}
void
@ -1796,8 +1800,8 @@ nsFrameManager::RestoreFrameStateFor(nsIFrame* aFrame,
}
// Get the state from the hash
nsCOMPtr<nsIPresState> frameState;
rv = aState->GetState(stateKey, getter_AddRefs(frameState));
nsPresState *frameState;
rv = aState->GetState(stateKey, &frameState);
if (!frameState) {
return;
}

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

@ -1,21 +1,73 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Pierre Phaneuf <pp@ludusdesign.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef _nsILayoutHistoryState_h
#define _nsILayoutHistoryState_h
#include "nsISupports.h"
#include "nsIPresState.h"
#include "nsStringFwd.h"
#define NS_ILAYOUTHISTORYSTATE_IID_STR "306c8ca0-5f0c-11d3-a9fb-000064657374"
class nsPresState;
#define NS_ILAYOUTHISTORYSTATE_IID \
{0x306c8ca0, 0x5f0c, 0x11d3, \
{0xa9, 0xfb, 0x00, 0x00, 0x64, 0x65, 0x73, 0x74}}
{0xe6abfb7c, 0x6624, 0x4b4d, \
{0x9d, 0xfe, 0xea, 0x62, 0xae, 0xfe, 0x03, 0x31}}
class nsILayoutHistoryState : public nsISupports {
public:
NS_DEFINE_STATIC_IID_ACCESSOR(NS_ILAYOUTHISTORYSTATE_IID)
NS_IMETHOD AddState(const nsCString& aKey, nsIPresState* aState) = 0;
NS_IMETHOD GetState(const nsCString& aKey, nsIPresState** aState) = 0;
/**
* Set |aState| as the state object for |aKey|.
* This _transfers_ownership_ of |aState| to the LayoutHistoryState.
* It will be freed when RemoveState() is called or when the
* LayoutHistoryState is destroyed.
*/
NS_IMETHOD AddState(const nsCString& aKey, nsPresState* aState) = 0;
/**
* Look up the state object for |aKey|.
*/
NS_IMETHOD GetState(const nsCString& aKey, nsPresState** aState) = 0;
/**
* Remove the state object for |aKey|.
*/
NS_IMETHOD RemoveState(const nsCString& aKey) = 0;
};

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

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

@ -52,7 +52,7 @@
#define NS_ERROR_FRAME_REPLACED \
NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_LAYOUT, 4)
/** Error codes for nsIPresState::GetProperty() */
/** Error codes for nsPresState::GetProperty() */
/** Returned if the property exists */
#define NS_STATE_PROPERTY_EXISTS NS_OK

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

@ -1,4 +1,4 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
@ -38,107 +38,76 @@
#include "nsILayoutHistoryState.h"
#include "nsWeakReference.h"
#include "nsHashtable.h"
#include "nsClassHashtable.h"
#include "nsPresState.h"
class nsLayoutHistoryState : public nsILayoutHistoryState,
public nsSupportsWeakReference
{
public:
nsLayoutHistoryState();
virtual ~nsLayoutHistoryState();
NS_HIDDEN_(nsresult) Init();
NS_DECL_ISUPPORTS
// nsILayoutHistoryState
NS_IMETHOD AddState(const nsCString& aKey, nsIPresState* aState);
NS_IMETHOD GetState(const nsCString& aKey, nsIPresState** aState);
NS_IMETHOD AddState(const nsCString& aKey, nsPresState* aState);
NS_IMETHOD GetState(const nsCString& aKey, nsPresState** aState);
NS_IMETHOD RemoveState(const nsCString& aKey);
private:
nsSupportsHashtable mStates;
~nsLayoutHistoryState() {}
nsClassHashtable<nsCStringHashKey,nsPresState> mStates;
};
nsresult
NS_NewLayoutHistoryState(nsILayoutHistoryState** aState)
{
NS_ENSURE_ARG_POINTER(aState);
if (! aState)
return NS_ERROR_NULL_POINTER;
nsLayoutHistoryState *state;
nsLayoutHistoryState *state = new nsLayoutHistoryState();
if (!state)
return NS_ERROR_OUT_OF_MEMORY;
*aState = nsnull;
state = new nsLayoutHistoryState();
if (!state)
return NS_ERROR_OUT_OF_MEMORY;
*aState = NS_STATIC_CAST(nsILayoutHistoryState *, state);
NS_ADDREF(*aState);
NS_ADDREF(state);
nsresult rv = state->Init();
if (NS_SUCCEEDED(rv))
*aState = state;
else
NS_RELEASE(state);
return NS_OK;
}
nsLayoutHistoryState::nsLayoutHistoryState()
{
}
nsLayoutHistoryState::~nsLayoutHistoryState()
{
return rv;
}
NS_IMPL_ISUPPORTS2(nsLayoutHistoryState,
nsILayoutHistoryState,
nsISupportsWeakReference)
NS_IMETHODIMP
nsLayoutHistoryState::AddState(const nsCString& aStateKey,
nsIPresState* aState)
nsresult
nsLayoutHistoryState::Init()
{
nsCStringKey key(aStateKey);
/*
* nsSupportsHashtable::Put() returns false when no object was
* replaced when inserting the new one, true if one was.
*/
#ifdef DEBUG_pollmann
PRBool replaced =
#endif
mStates.Put (&key, aState);
#ifdef DEBUG_pollmann
NS_ASSERTION(!replaced,
"nsLayoutHistoryState::AddState OOPS!. There was already a state in the hash table for the key\n");
#endif
return NS_OK;
return mStates.Init() ? NS_OK : NS_ERROR_FAILURE;
}
NS_IMETHODIMP
nsLayoutHistoryState::GetState(const nsCString& aKey,
nsIPresState** aState)
nsLayoutHistoryState::AddState(const nsCString& aStateKey, nsPresState* aState)
{
nsresult rv = NS_OK;
nsCStringKey key(aKey);
nsISupports *state = nsnull;
state = mStates.Get(&key);
if (state) {
*aState = (nsIPresState *)state;
}
else {
#if 0
printf("nsLayoutHistoryState::GetState, ERROR getting History state for the key\n");
#endif
*aState = nsnull;
rv = NS_OK;
}
return rv;
return mStates.Put(aStateKey, aState) ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
}
NS_IMETHODIMP
nsLayoutHistoryState::GetState(const nsCString& aKey, nsPresState** aState)
{
mStates.Get(aKey, aState);
return NS_OK;
}
NS_IMETHODIMP
nsLayoutHistoryState::RemoveState(const nsCString& aKey)
{
nsresult rv = NS_OK;
nsCStringKey key(aKey);
mStates.Remove(&key);
return rv;
mStates.Remove(aKey);
return NS_OK;
}

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

@ -36,169 +36,102 @@
* ***** END LICENSE BLOCK ***** */
#include "nsCOMPtr.h"
#include "nsIPresState.h"
#include "nsHashtable.h"
#include "nsXPCOM.h"
#include "nsISupportsPrimitives.h"
#include "nsIComponentManager.h"
#include "nsXPIDLString.h"
#include "nsReadableUtils.h"
#include "nsLayoutErrors.h"
class nsPresState: public nsIPresState
{
NS_DECL_ISUPPORTS
NS_IMETHOD GetStatePropertyAsSupports(const nsAString& aName, nsISupports** aResult);
NS_IMETHOD SetStatePropertyAsSupports(const nsAString& aName, nsISupports* aValue);
NS_IMETHOD GetStateProperty(const nsAString& aProperty, nsAString& aResult);
NS_IMETHOD SetStateProperty(const nsAString& aProperty, const nsAString& aValue);
NS_IMETHOD RemoveStateProperty(const nsAString& aProperty);
public:
nsPresState();
virtual ~nsPresState();
// Static members
// Internal member functions
protected:
// MEMBER VARIABLES
protected:
// A string table that holds property/value pairs.
nsSupportsHashtable* mPropertyTable;
};
// Static initialization
#include "nsPresState.h"
#include "nsString.h"
// Implementation /////////////////////////////////////////////////////////////////
// Implement our nsISupports methods
NS_IMPL_ISUPPORTS1(nsPresState, nsIPresState)
// Constructors/Destructors
nsPresState::nsPresState(void)
:mPropertyTable(nsnull)
nsresult
nsPresState::Init()
{
return mPropertyTable.Init(8) ? NS_OK : NS_ERROR_FAILURE;
}
nsPresState::~nsPresState(void)
{
delete mPropertyTable;
}
// nsIPresState Interface ////////////////////////////////////////////////////////////////
NS_IMETHODIMP
nsPresState::GetStateProperty(const nsAString& aName,
nsAString& aResult)
nsresult
nsPresState::GetStateProperty(const nsAString& aName, nsAString& aResult)
{
nsresult rv = NS_STATE_PROPERTY_NOT_THERE;
aResult.Truncate();
// Retrieve from hashtable.
if (mPropertyTable) {
const nsPromiseFlatString& flatString = PromiseFlatString(aName);
nsStringKey key(flatString);
nsISupports *data = mPropertyTable.GetWeak(aName);
nsCOMPtr<nsISupportsCString> supportsStr =
dont_AddRef(NS_STATIC_CAST(nsISupportsCString*,
mPropertyTable->Get(&key)));
// Strings are stored in the table as UTF-8, to save space.
// XXX minimize conversions here...
if (supportsStr) {
nsCAutoString data;
supportsStr->GetData(data);
nsCOMPtr<nsISupportsCString> supportsStr = do_QueryInterface(data);
if (supportsStr) {
nsCAutoString data;
supportsStr->GetData(data);
CopyUTF8toUTF16(data, aResult);
rv = NS_STATE_PROPERTY_EXISTS;
}
CopyUTF8toUTF16(data, aResult);
rv = NS_STATE_PROPERTY_EXISTS;
}
return rv;
}
NS_IMETHODIMP
nsresult
nsPresState::SetStateProperty(const nsAString& aName, const nsAString& aValue)
{
if (!mPropertyTable) {
mPropertyTable = new nsSupportsHashtable(8);
NS_ENSURE_TRUE(mPropertyTable, NS_ERROR_OUT_OF_MEMORY);
}
// Add to hashtable
const nsPromiseFlatString& flatString = PromiseFlatString(aName);
nsStringKey key(flatString);
nsCOMPtr<nsISupportsCString> supportsStr(do_CreateInstance(NS_SUPPORTS_CSTRING_CONTRACTID));
NS_ENSURE_TRUE(supportsStr, NS_ERROR_OUT_OF_MEMORY);
supportsStr->SetData(NS_ConvertUCS2toUTF8(aValue));
mPropertyTable->Put(&key, supportsStr);
mPropertyTable.Put(aName, supportsStr);
return NS_OK;
}
NS_IMETHODIMP
nsPresState::RemoveStateProperty(const nsAString& aName)
{
if (!mPropertyTable)
return NS_OK;
const nsPromiseFlatString& flatString = PromiseFlatString(aName);
nsStringKey key(flatString);
mPropertyTable->Remove(&key);
return NS_OK;
}
NS_IMETHODIMP
nsPresState::GetStatePropertyAsSupports(const nsAString& aName, nsISupports** aResult)
{
// Retrieve from hashtable.
nsCOMPtr<nsISupports> supp;
if (mPropertyTable) {
const nsPromiseFlatString& flatString = PromiseFlatString(aName);
nsStringKey key(flatString);
supp = dont_AddRef(NS_STATIC_CAST(nsISupports*, mPropertyTable->Get(&key)));
}
*aResult = supp;
NS_IF_ADDREF(*aResult);
return NS_OK;
}
NS_IMETHODIMP
nsPresState::SetStatePropertyAsSupports(const nsAString& aName, nsISupports* aValue)
{
if (!mPropertyTable) {
mPropertyTable = new nsSupportsHashtable(8);
NS_ENSURE_TRUE(mPropertyTable, NS_ERROR_OUT_OF_MEMORY);
}
// Add to hashtable
const nsPromiseFlatString& flatString = PromiseFlatString(aName);
nsStringKey key(flatString);
mPropertyTable->Put(&key, aValue);
return NS_OK;
}
// Creation Routine ///////////////////////////////////////////////////////////////////////
nsresult
NS_NewPresState(nsIPresState** aResult)
nsPresState::RemoveStateProperty(const nsAString& aName)
{
*aResult = new nsPresState;
if (!*aResult)
return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(*aResult);
mPropertyTable.Remove(aName);
return NS_OK;
}
nsresult
nsPresState::GetStatePropertyAsSupports(const nsAString& aName,
nsISupports** aResult)
{
// Retrieve from hashtable.
mPropertyTable.Get(aName, aResult);
return NS_OK;
}
nsresult
nsPresState::SetStatePropertyAsSupports(const nsAString& aName,
nsISupports* aValue)
{
mPropertyTable.Put(aName, aValue);
return NS_OK;
}
nsresult
NS_NewPresState(nsPresState** aState)
{
nsPresState *state;
*aState = nsnull;
state = new nsPresState();
if (!state)
return NS_ERROR_OUT_OF_MEMORY;
nsresult rv = state->Init();
if (NS_SUCCEEDED(rv))
*aState = state;
else
delete state;
return rv;
}

71
layout/base/nsPresState.h Executable file
Просмотреть файл

@ -0,0 +1,71 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef nsPresState_h_
#define nsPresState_h_
#include "nsStringFwd.h"
#include "nsInterfaceHashtable.h"
class nsPresState
{
public:
NS_HIDDEN_(nsresult) Init();
NS_HIDDEN_(nsresult) GetStatePropertyAsSupports(const nsAString& aName,
nsISupports** aResult);
NS_HIDDEN_(nsresult) SetStatePropertyAsSupports(const nsAString& aName,
nsISupports* aValue);
NS_HIDDEN_(nsresult) GetStateProperty(const nsAString& aProperty,
nsAString& aResult);
NS_HIDDEN_(nsresult) SetStateProperty(const nsAString& aProperty,
const nsAString& aValue);
NS_HIDDEN_(nsresult) RemoveStateProperty(const nsAString& aProperty);
// MEMBER VARIABLES
protected:
// A string table that holds property/value pairs.
nsInterfaceHashtable<nsStringHashKey,nsISupports> mPropertyTable;
};
NS_HIDDEN_(nsresult) NS_NewPresState(nsPresState **aState);
#endif

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

@ -101,10 +101,6 @@
#define NS_PRESSHELL_CID \
{ 0xe6fd9940, 0x899d, 0x11d2, { 0x8e, 0xae, 0x0, 0x80, 0x5f, 0x29, 0xf3, 0x70 } }
// {A1FDE861-E802-11d4-9885-00C04FA0CF4B}
#define NS_PRESSTATE_CID \
{ 0xa1fde861, 0xe802, 0x11d4, { 0x98, 0x85, 0x0, 0xc0, 0x4f, 0xa0, 0xcf, 0x4b } }
// {95F46161-D177-11d2-BF86-00105A1B0627}
#define NS_HTML_CSS_STYLESHEET_CID \
{ 0x95f46161, 0xd177, 0x11d2, { 0xbf, 0x86, 0x0, 0x10, 0x5a, 0x1b, 0x6, 0x27 } }

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

@ -460,7 +460,6 @@ nsresult NS_NewCanvasRenderingContext2D(nsICanvasRenderingContext2D** aResult);
#endif
nsresult NS_CreateFrameTraversal(nsIFrameTraversal** aResult);
nsresult NS_NewLayoutHistoryState(nsILayoutHistoryState** aResult);
nsresult NS_NewAutoCopyService(nsIAutoCopyService** aResult);
nsresult NS_NewSelectionImageService(nsISelectionImageService** aResult);
@ -520,9 +519,7 @@ MAKE_CTOR(CreateNewLayoutDebugger, nsILayoutDebugger, NS_NewLay
#endif
MAKE_CTOR(CreateNewFrameTraversal, nsIFrameTraversal, NS_CreateFrameTraversal)
MAKE_CTOR(CreateNewLayoutHistoryState, nsILayoutHistoryState, NS_NewLayoutHistoryState)
MAKE_CTOR(CreateNewPresShell, nsIPresShell, NS_NewPresShell)
MAKE_CTOR(CreateNewPresState, nsIPresState, NS_NewPresState)
#ifdef MOZ_XUL
MAKE_CTOR(CreateNewBoxObject, nsIBoxObject, NS_NewBoxObject)
MAKE_CTOR(CreateNewListBoxObject, nsIBoxObject, NS_NewListBoxObject)
@ -834,11 +831,6 @@ static const nsModuleComponentInfo gComponents[] = {
nsnull,
CreateNewFrameTraversal },
{ "Layout History State",
NS_LAYOUT_HISTORY_STATE_CID,
nsnull,
CreateNewLayoutHistoryState },
{ "selection image storage",
NS_SELECTIONIMAGESERVICE_CID,
nsnull,
@ -855,11 +847,6 @@ static const nsModuleComponentInfo gComponents[] = {
nsnull,
CreateNewPresShell },
{ "Presentation state",
NS_PRESSTATE_CID,
nsnull,
CreateNewPresState },
// XXX end ick
#ifdef MOZ_XUL

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

@ -54,7 +54,6 @@
#include "nsIDOMHTMLOptionElement.h"
#include "nsIDOMNSHTMLOptionCollectn.h"
#include "nsIPresShell.h"
#include "nsIPresState.h"
#include "nsIDeviceContext.h"
#include "nsIView.h"
#include "nsIScrollableView.h"
@ -93,6 +92,7 @@
#include "nsIFontMetrics.h"
#endif
class nsPresState;
#define FIX_FOR_BUG_53259
@ -2417,7 +2417,7 @@ nsComboboxControlFrame::OnContentReset()
//--------------------------------------------------------
NS_IMETHODIMP
nsComboboxControlFrame::SaveState(nsPresContext* aPresContext,
nsIPresState** aState)
nsPresState** aState)
{
nsCOMPtr<nsIStatefulFrame> stateful(do_QueryInterface(mListControlFrame));
NS_ASSERTION(stateful, "Couldn't cast list frame to stateful frame!!!");
@ -2429,7 +2429,7 @@ nsComboboxControlFrame::SaveState(nsPresContext* aPresContext,
NS_IMETHODIMP
nsComboboxControlFrame::RestoreState(nsPresContext* aPresContext,
nsIPresState* aState)
nsPresState* aState)
{
if (!mListControlFrame)
return NS_ERROR_FAILURE;

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

@ -58,7 +58,7 @@
#include "nsIAnonymousContentCreator.h"
#include "nsISelectControlFrame.h"
#include "nsIRollupListener.h"
#include "nsIPresState.h"
#include "nsPresState.h"
#include "nsCSSFrameConstructor.h"
#include "nsITextContent.h"
#include "nsIScrollableViewProvider.h"
@ -209,8 +209,8 @@ public:
virtual nsIScrollableView* GetScrollableView();
//nsIStatefulFrame
NS_IMETHOD SaveState(nsPresContext* aPresContext, nsIPresState** aState);
NS_IMETHOD RestoreState(nsPresContext* aPresContext, nsIPresState* aState);
NS_IMETHOD SaveState(nsPresContext* aPresContext, nsPresState** aState);
NS_IMETHOD RestoreState(nsPresContext* aPresContext, nsPresState* aState);
protected:

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

@ -43,7 +43,6 @@
#include "nsIAtom.h"
#include "nsPresContext.h"
#include "nsHTMLAtoms.h"
#include "nsIPresState.h"
#include "nsWidgetsCID.h"
#include "nsIComponentManager.h"
#include "nsIView.h"

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

@ -48,7 +48,6 @@
#include "nsFormControlHelper.h"
typedef nsTextControlFrame nsNewFrame;
class nsIPresState;
class nsISupportsArray;
class nsFileControlFrame : public nsAreaFrame,

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

@ -49,7 +49,6 @@
class nsIView;
class nsPresContext;
class nsStyleCoord;
class nsIPresState;
class nsStyleContext;
#define CSS_NOTSET -1

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

@ -56,8 +56,6 @@
// MouseEvent suppression in PP
#include "nsGUIEvent.h"
// Saving PresState
#include "nsIPresState.h"
#include "nsNodeInfoManager.h"
const nscoord kSuggestedNotSet = -1;

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

@ -53,8 +53,6 @@ class nsIAccessible;
// The label for button is specified through generated content
// in the ua.css file.
class nsIPresState;
class nsGfxButtonControlFrame : public nsHTMLButtonControlFrame,
public nsIAnonymousContentCreator
{

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

@ -43,7 +43,6 @@
#include "nsIContent.h"
#include "nsIComponentManager.h"
#include "nsHTMLAtoms.h"
#include "nsIPresState.h"
#include "nsIPresShell.h"
#include "nsIDocument.h"
#include "nsCSSRendering.h"

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

@ -44,7 +44,6 @@
#include "nsIComponentManager.h"
#include "nsCOMPtr.h"
#include "nsCSSRendering.h"
#include "nsIPresState.h"
#include "nsIPresShell.h"
#include "nsIDocument.h"
#ifdef ACCESSIBILITY

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

@ -43,7 +43,6 @@
class nsPresContext;
class nsAString;
class nsIContent;
class nsIPresState;
// IID for the nsIListControlFrame class
#define NS_ILISTCONTROLFRAME_IID \

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

@ -42,7 +42,7 @@
#include "nsIAtom.h"
#include "nsPresContext.h"
#include "nsHTMLAtoms.h"
#include "nsIPresState.h"
#include "nsPresState.h"
#include "nsWidgetsCID.h"
#include "nsIComponentManager.h"
#include "nsIView.h"
@ -559,7 +559,7 @@ nsIsIndexFrame::URLEncode(const nsString& aString, nsIUnicodeEncoder* encoder, n
// nsIStatefulFrame
//----------------------------------------------------------------------
NS_IMETHODIMP
nsIsIndexFrame::SaveState(nsPresContext* aPresContext, nsIPresState** aState)
nsIsIndexFrame::SaveState(nsPresContext* aPresContext, nsPresState** aState)
{
NS_ENSURE_ARG_POINTER(aState);
@ -580,7 +580,7 @@ nsIsIndexFrame::SaveState(nsPresContext* aPresContext, nsIPresState** aState)
}
NS_IMETHODIMP
nsIsIndexFrame::RestoreState(nsPresContext* aPresContext, nsIPresState* aState)
nsIsIndexFrame::RestoreState(nsPresContext* aPresContext, nsPresState* aState)
{
NS_ENSURE_ARG_POINTER(aState);

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

@ -49,7 +49,6 @@
#include "nsFormControlHelper.h"
typedef nsTextControlFrame nsNewFrame;
class nsIPresState;
class nsISupportsArray;
class nsIsIndexFrame : public nsAreaFrame,
@ -130,8 +129,8 @@ public:
NS_IMETHOD OnSubmit(nsPresContext* aPresContext);
//nsIStatefulFrame
NS_IMETHOD SaveState(nsPresContext* aPresContext, nsIPresState** aState);
NS_IMETHOD RestoreState(nsPresContext* aPresContext, nsIPresState* aState);
NS_IMETHOD SaveState(nsPresContext* aPresContext, nsPresState** aState);
NS_IMETHOD RestoreState(nsPresContext* aPresContext, nsPresState* aState);
protected:
nsCOMPtr<nsITextContent> mTextContent;

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

@ -53,7 +53,6 @@
#include "nsIListControlFrame.h"
#include "nsISelectControlFrame.h"
#include "nsIDOMEventListener.h"
#include "nsIPresState.h"
#include "nsIContent.h"
#include "nsAutoPtr.h"

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

@ -67,7 +67,6 @@
#include "nsIScrollableFrame.h" //to turn off scroll bars
#include "nsFormControlFrame.h" //for registering accesskeys
#include "nsIDeviceContext.h" // to measure fonts
#include "nsIPresState.h" //for saving state
#include "nsIContent.h"
#include "nsIAtom.h"

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

@ -51,7 +51,6 @@
#include "nsIScrollableViewProvider.h"
#include "nsIPhonetic.h"
class nsIPresState;
class nsISupportsArray;
class nsIEditor;
class nsISelectionController;

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

@ -72,6 +72,8 @@
#include "nsContentCreatorFunctions.h"
#include "nsISupportsPrimitives.h"
#include "nsIPresShell.h"
#include "nsAutoPtr.h"
#include "nsPresState.h"
#ifdef ACCESSIBILITY
#include "nsIAccessibilityService.h"
#endif
@ -2176,7 +2178,7 @@ nsGfxScrollFrameInner::GetIntegerAttribute(nsIBox* aBox, nsIAtom* atom, PRInt32
return defaultValue;
}
already_AddRefed<nsIPresState>
nsPresState*
nsGfxScrollFrameInner::SaveState()
{
nsCOMPtr<nsIScrollbarMediator> mediator;
@ -2202,8 +2204,8 @@ nsGfxScrollFrameInner::SaveState()
}
nsRect childRect = child->GetBounds();
nsCOMPtr<nsIPresState> state;
nsresult rv = NS_NewPresState(getter_AddRefs(state));
nsAutoPtr<nsPresState> state;
nsresult rv = NS_NewPresState(getter_Transfers(state));
NS_ENSURE_SUCCESS(rv, nsnull);
nsCOMPtr<nsISupportsPRInt32> xoffset = do_CreateInstance(NS_SUPPORTS_PRINT32_CONTRACTID);
@ -2233,13 +2235,11 @@ nsGfxScrollFrameInner::SaveState()
NS_ENSURE_SUCCESS(rv, nsnull);
state->SetStatePropertyAsSupports(NS_LITERAL_STRING("height"), height);
}
nsIPresState* result = state;
NS_ADDREF(result);
return result;
return state.forget();
}
void
nsGfxScrollFrameInner::RestoreState(nsIPresState* aState)
nsGfxScrollFrameInner::RestoreState(nsPresState* aState)
{
nsCOMPtr<nsISupportsPRInt32> xoffset;
nsCOMPtr<nsISupportsPRInt32> yoffset;

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

@ -42,7 +42,6 @@
#include "nsBoxFrame.h"
#include "nsIScrollableFrame.h"
#include "nsIScrollPositionListener.h"
#include "nsIPresState.h"
#include "nsIStatefulFrame.h"
class nsISupportsArray;
@ -53,6 +52,7 @@ class nsIContent;
class nsIAtom;
class nsIDocument;
class nsIScrollFrameInternal;
class nsPresState;
class nsGfxScrollFrameInner : public nsIScrollPositionListener {
public:
@ -113,8 +113,8 @@ public:
void ScrollToRestoredPosition();
already_AddRefed<nsIPresState> SaveState();
void RestoreState(nsIPresState* aState);
nsPresState* SaveState();
void RestoreState(nsPresState* aState);
nsIFrame* GetScrolledFrame() const {
nsIFrame* childBox;
@ -254,12 +254,12 @@ public:
virtual void CurPosAttributeChanged(nsIContent* aChild, PRInt32 aModType);
// nsIStatefulFrame
NS_IMETHOD SaveState(nsPresContext* aPresContext, nsIPresState** aState) {
NS_IMETHOD SaveState(nsPresContext* aPresContext, nsPresState** aState) {
NS_ENSURE_ARG_POINTER(aState);
*aState = mInner.SaveState().get();
*aState = mInner.SaveState();
return NS_OK;
}
NS_IMETHOD RestoreState(nsPresContext* aPresContext, nsIPresState* aState) {
NS_IMETHOD RestoreState(nsPresContext* aPresContext, nsPresState* aState) {
NS_ENSURE_ARG_POINTER(aState);
mInner.RestoreState(aState);
return NS_OK;
@ -400,12 +400,12 @@ public:
virtual void CurPosAttributeChanged(nsIContent* aChild, PRInt32 aModType);
// nsIStatefulFrame
NS_IMETHOD SaveState(nsPresContext* aPresContext, nsIPresState** aState) {
NS_IMETHOD SaveState(nsPresContext* aPresContext, nsPresState** aState) {
NS_ENSURE_ARG_POINTER(aState);
*aState = mInner.SaveState().get();
*aState = mInner.SaveState();
return NS_OK;
}
NS_IMETHOD RestoreState(nsPresContext* aPresContext, nsIPresState* aState) {
NS_IMETHOD RestoreState(nsPresContext* aPresContext, nsPresState* aState) {
NS_ENSURE_ARG_POINTER(aState);
mInner.RestoreState(aState);
return NS_OK;

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

@ -4,13 +4,11 @@
#include "nsISupports.h"
class nsPresContext;
class nsIPresState;
#define NS_ISTATEFULFRAME_IID_STR "306c8ca0-5f0c-11d3-a9fb-000064657374"
class nsPresState;
#define NS_ISTATEFULFRAME_IID \
{0x306c8ca0, 0x5f0c, 0x11d3, \
{0xa9, 0xfb, 0x00, 0x00, 0x64, 0x65, 0x73, 0x74}}
{0x26254ab7, 0xdea3, 0x4375, \
{0xb0, 0x1d, 0xbd, 0x11, 0xa1, 0x4b, 0x54, 0xbc}}
class nsIStatefulFrame : public nsISupports {
public:
@ -24,8 +22,8 @@ class nsIStatefulFrame : public nsISupports {
// offset NS_CONTENT_ID_COUNTER_BASE
enum SpecialStateID {eNoID=0, eDocumentScrollState};
NS_IMETHOD SaveState(nsPresContext* aPresContext, nsIPresState** aState) = 0;
NS_IMETHOD RestoreState(nsPresContext* aPresContext, nsIPresState* aState) = 0;
NS_IMETHOD SaveState(nsPresContext* aPresContext, nsPresState** aState) = 0;
NS_IMETHOD RestoreState(nsPresContext* aPresContext, nsPresState* aState) = 0;
};
#endif /* _nsIStatefulFrame_h */

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

@ -412,7 +412,7 @@ NS_IMETHODIMP
nsBoxObject::SetPropertyAsSupports(const PRUnichar* aPropertyName, nsISupports* aValue)
{
if (!mPresState)
NS_NewPresState(getter_AddRefs(mPresState));
NS_NewPresState(getter_Transfers(mPresState));
nsDependentString propertyName(aPropertyName);
return mPresState->SetStatePropertyAsSupports(propertyName, aValue);
@ -439,7 +439,7 @@ NS_IMETHODIMP
nsBoxObject::SetProperty(const PRUnichar* aPropertyName, const PRUnichar* aPropertyValue)
{
if (!mPresState)
NS_NewPresState(getter_AddRefs(mPresState));
NS_NewPresState(getter_Transfers(mPresState));
nsDependentString propertyName(aPropertyName);
nsDependentString propertyValue(aPropertyValue);

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

@ -38,8 +38,9 @@
#include "nsCOMPtr.h"
#include "nsIBoxObject.h"
#include "nsPIBoxObject.h"
#include "nsIPresState.h"
#include "nsPresState.h"
#include "nsPoint.h"
#include "nsAutoPtr.h"
class nsIBoxLayoutManager;
class nsIBoxPaintManager;
@ -73,7 +74,7 @@ protected:
// MEMBER VARIABLES
nsCOMPtr<nsIBoxLayoutManager> mLayoutManager; // [OWNER]
nsCOMPtr<nsIBoxPaintManager> mPaintManager; // [OWNER]
nsCOMPtr<nsIPresState> mPresState; // [OWNER]
nsAutoPtr<nsPresState> mPresState; // [OWNER]
nsIContent* mContent; // [WEAK]
nsIPresShell* mPresShell; // [WEAK]

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

@ -57,7 +57,6 @@
#include "nsGfxScrollFrame.h"
#include "nsXPCOM.h"
#include "nsISupportsPrimitives.h"
#include "nsIPresState.h"
#include "nsButtonBoxFrame.h"
#include "nsITimer.h"
#include "nsRepeatService.h"