зеркало из https://github.com/mozilla/pjs.git
Bug 345339. Stop using a generic hashtable to store element session history state in nsPresState. patch by Karthik Sarma, r+sr=roc,a=sicking
This commit is contained in:
Родитель
bee64c709b
Коммит
c15b5b5849
|
@ -595,14 +595,7 @@ nsHTMLButtonElement::SaveState()
|
|||
if (state) {
|
||||
PRBool disabled;
|
||||
GetDisabled(&disabled);
|
||||
if (disabled) {
|
||||
rv |= state->SetStateProperty(NS_LITERAL_STRING("disabled"),
|
||||
NS_LITERAL_STRING("t"));
|
||||
} else {
|
||||
rv |= state->SetStateProperty(NS_LITERAL_STRING("disabled"),
|
||||
NS_LITERAL_STRING("f"));
|
||||
}
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "disabled save failed!");
|
||||
state->SetDisabled(disabled);
|
||||
}
|
||||
|
||||
return rv;
|
||||
|
@ -611,13 +604,9 @@ nsHTMLButtonElement::SaveState()
|
|||
PRBool
|
||||
nsHTMLButtonElement::RestoreState(nsPresState* aState)
|
||||
{
|
||||
nsAutoString disabled;
|
||||
nsresult rv =
|
||||
aState->GetStateProperty(NS_LITERAL_STRING("disabled"), disabled);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "disabled restore failed!");
|
||||
if (rv == NS_STATE_PROPERTY_EXISTS) {
|
||||
SetDisabled(disabled.EqualsLiteral("t"));
|
||||
}
|
||||
NS_ENSURE_ARG_POINTER(aState);
|
||||
|
||||
SetDisabled(aState->GetDisabled());
|
||||
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
|
|
@ -35,6 +35,9 @@
|
|||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsISupportsPrimitives.h"
|
||||
#include "nsISupportsImpl.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIDOMHTMLInputElement.h"
|
||||
#include "nsIDOMNSHTMLInputElement.h"
|
||||
|
@ -143,6 +146,55 @@ static NS_DEFINE_CID(kXULControllersCID, NS_XULCONTROLLERS_CID);
|
|||
|
||||
static const char kWhitespace[] = "\n\r\t\b";
|
||||
|
||||
#define NS_INPUT_ELEMENT_STATE_IID \
|
||||
{ /* dc3b3d14-23e2-4479-b513-7b369343e3a0 */ \
|
||||
0xdc3b3d14, \
|
||||
0x23e2, \
|
||||
0x4479, \
|
||||
{0xb5, 0x13, 0x7b, 0x36, 0x93, 0x43, 0xe3, 0xa0} \
|
||||
}
|
||||
|
||||
class nsHTMLInputElementState : public nsISupports
|
||||
{
|
||||
public:
|
||||
NS_DECLARE_STATIC_IID_ACCESSOR(NS_INPUT_ELEMENT_STATE_IID)
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
enum { UNKNOWN = -1 };
|
||||
|
||||
void SetChecked(PRInt8 aChecked) {
|
||||
mChecked = aChecked;
|
||||
}
|
||||
PRInt8 GetChecked() {
|
||||
return mChecked;
|
||||
}
|
||||
|
||||
void SetValue(const nsAString &aValue) {
|
||||
mValue = aValue;
|
||||
}
|
||||
const nsString& GetValue() {
|
||||
return mValue;
|
||||
}
|
||||
|
||||
void SetFileName(const nsAString &aFilename) {
|
||||
mFilename = aFilename;
|
||||
}
|
||||
const nsString& GetFileName() {
|
||||
return mFilename;
|
||||
}
|
||||
|
||||
nsHTMLInputElementState() : mValue(), mFilename(), mChecked(UNKNOWN) {};
|
||||
|
||||
protected:
|
||||
nsString mValue;
|
||||
nsString mFilename;
|
||||
PRInt8 mChecked;
|
||||
};
|
||||
|
||||
NS_IMPL_ISUPPORTS0(nsHTMLInputElementState)
|
||||
NS_DEFINE_STATIC_IID_ACCESSOR(nsHTMLInputElementState,
|
||||
NS_INPUT_ELEMENT_STATE_IID)
|
||||
|
||||
class nsHTMLInputElement : public nsGenericHTMLFormElement,
|
||||
public nsImageLoadingContent,
|
||||
public nsIDOMHTMLInputElement,
|
||||
|
@ -2572,6 +2624,12 @@ NS_IMETHODIMP
|
|||
nsHTMLInputElement::SaveState()
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
nsRefPtr<nsHTMLInputElementState> inputState
|
||||
(new nsHTMLInputElementState());
|
||||
|
||||
if (!inputState)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
nsPresState *state = nsnull;
|
||||
switch (mType) {
|
||||
|
@ -2579,7 +2637,7 @@ nsHTMLInputElement::SaveState()
|
|||
case NS_FORM_INPUT_RADIO:
|
||||
{
|
||||
PRBool checked = PR_FALSE;
|
||||
GetChecked(&checked);
|
||||
rv = GetChecked(&checked);
|
||||
PRBool defaultChecked = PR_FALSE;
|
||||
GetDefaultChecked(&defaultChecked);
|
||||
// Only save if checked != defaultChecked (bug 62713)
|
||||
|
@ -2588,14 +2646,7 @@ nsHTMLInputElement::SaveState()
|
|||
if (mType == NS_FORM_INPUT_RADIO || checked != defaultChecked) {
|
||||
rv = GetPrimaryPresState(this, &state);
|
||||
if (state) {
|
||||
if (checked) {
|
||||
rv = state->SetStateProperty(NS_LITERAL_STRING("checked"),
|
||||
NS_LITERAL_STRING("t"));
|
||||
} else {
|
||||
rv = state->SetStateProperty(NS_LITERAL_STRING("checked"),
|
||||
NS_LITERAL_STRING("f"));
|
||||
}
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "checked save failed!");
|
||||
inputState->SetChecked(checked);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
@ -2617,8 +2668,7 @@ nsHTMLInputElement::SaveState()
|
|||
nsLinebreakConverter::eLinebreakPlatform,
|
||||
nsLinebreakConverter::eLinebreakContent);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "Converting linebreaks failed!");
|
||||
rv = state->SetStateProperty(NS_LITERAL_STRING("v"), value);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "value save failed!");
|
||||
inputState->SetValue(value);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
@ -2628,8 +2678,7 @@ nsHTMLInputElement::SaveState()
|
|||
if (mFileName) {
|
||||
rv = GetPrimaryPresState(this, &state);
|
||||
if (state) {
|
||||
rv = state->SetStateProperty(NS_LITERAL_STRING("f"), *mFileName);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "value save failed!");
|
||||
inputState->SetFileName(*mFileName);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
@ -2641,16 +2690,14 @@ nsHTMLInputElement::SaveState()
|
|||
if (state) {
|
||||
PRBool disabled;
|
||||
GetDisabled(&disabled);
|
||||
if (disabled) {
|
||||
rv |= state->SetStateProperty(NS_LITERAL_STRING("disabled"),
|
||||
NS_LITERAL_STRING("t"));
|
||||
} else {
|
||||
rv |= state->SetStateProperty(NS_LITERAL_STRING("disabled"),
|
||||
NS_LITERAL_STRING("f"));
|
||||
}
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "disabled save failed!");
|
||||
state->SetDisabled(disabled);
|
||||
}
|
||||
}
|
||||
|
||||
rv |= GetPrimaryPresState(this, &state);
|
||||
if (state) {
|
||||
state->SetStateProperty(inputState);
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
@ -2714,18 +2761,19 @@ nsHTMLInputElement::RestoreState(nsPresState* aState)
|
|||
{
|
||||
PRBool restoredCheckedState = PR_FALSE;
|
||||
|
||||
nsresult rv;
|
||||
|
||||
nsCOMPtr<nsHTMLInputElementState> inputState
|
||||
(do_QueryInterface(aState->GetStateProperty()));
|
||||
if (!inputState)
|
||||
return PR_FALSE;
|
||||
|
||||
switch (mType) {
|
||||
case NS_FORM_INPUT_CHECKBOX:
|
||||
case NS_FORM_INPUT_RADIO:
|
||||
{
|
||||
nsAutoString checked;
|
||||
rv = aState->GetStateProperty(NS_LITERAL_STRING("checked"), checked);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "checked restore failed!");
|
||||
if (rv == NS_STATE_PROPERTY_EXISTS) {
|
||||
restoredCheckedState = PR_TRUE;
|
||||
DoSetChecked(checked.EqualsLiteral("t"), PR_FALSE);
|
||||
PRInt8 checked = inputState->GetChecked();
|
||||
if (checked != nsHTMLInputElementState::UNKNOWN) {
|
||||
restoredCheckedState = PR_TRUE;
|
||||
DoSetChecked(checked, PR_FALSE);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -2733,31 +2781,18 @@ nsHTMLInputElement::RestoreState(nsPresState* aState)
|
|||
case NS_FORM_INPUT_TEXT:
|
||||
case NS_FORM_INPUT_HIDDEN:
|
||||
{
|
||||
nsAutoString value;
|
||||
rv = aState->GetStateProperty(NS_LITERAL_STRING("v"), value);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "value restore failed!");
|
||||
if (rv == NS_STATE_PROPERTY_EXISTS) {
|
||||
SetValueInternal(value, nsnull, PR_FALSE);
|
||||
}
|
||||
SetValueInternal(inputState->GetValue(), nsnull, PR_FALSE);
|
||||
break;
|
||||
}
|
||||
case NS_FORM_INPUT_FILE:
|
||||
{
|
||||
nsAutoString value;
|
||||
rv = aState->GetStateProperty(NS_LITERAL_STRING("f"), value);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "value restore failed!");
|
||||
if (rv == NS_STATE_PROPERTY_EXISTS) {
|
||||
SetFileName(value);
|
||||
}
|
||||
SetFileName(inputState->GetFileName());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
nsAutoString disabled;
|
||||
rv = aState->GetStateProperty(NS_LITERAL_STRING("disabled"), disabled);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "disabled restore failed!");
|
||||
if (rv == NS_STATE_PROPERTY_EXISTS) {
|
||||
SetDisabled(disabled.EqualsLiteral("t"));
|
||||
if (aState->DisabledIsSet()) {
|
||||
SetDisabled(aState->GetDisabled());
|
||||
}
|
||||
|
||||
return restoredCheckedState;
|
||||
|
|
|
@ -70,6 +70,7 @@
|
|||
#include "nsEventDispatcher.h"
|
||||
|
||||
NS_IMPL_ISUPPORTS0(nsSelectState)
|
||||
NS_DEFINE_STATIC_IID_ACCESSOR(nsSelectState, NS_SELECT_STATE_IID)
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
//
|
||||
|
@ -1512,21 +1513,14 @@ nsHTMLSelectElement::SaveState()
|
|||
nsPresState *presState = nsnull;
|
||||
nsresult rv = GetPrimaryPresState(this, &presState);
|
||||
if (presState) {
|
||||
rv = presState->SetStatePropertyAsSupports(NS_LITERAL_STRING("selecteditems"),
|
||||
state);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "selecteditems set failed!");
|
||||
|
||||
presState->SetStateProperty(state);
|
||||
|
||||
|
||||
if (mDisabledChanged) {
|
||||
PRBool disabled;
|
||||
GetDisabled(&disabled);
|
||||
if (disabled) {
|
||||
rv |= presState->SetStateProperty(NS_LITERAL_STRING("disabled"),
|
||||
NS_LITERAL_STRING("t"));
|
||||
} else {
|
||||
rv |= presState->SetStateProperty(NS_LITERAL_STRING("disabled"),
|
||||
NS_LITERAL_STRING("f"));
|
||||
}
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "disabled save failed!");
|
||||
presState->SetDisabled(disabled);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1537,22 +1531,20 @@ PRBool
|
|||
nsHTMLSelectElement::RestoreState(nsPresState* aState)
|
||||
{
|
||||
// Get the presentation state object to retrieve our stuff out of.
|
||||
nsCOMPtr<nsISupports> state;
|
||||
nsresult rv = aState->GetStatePropertyAsSupports(NS_LITERAL_STRING("selecteditems"),
|
||||
getter_AddRefs(state));
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
RestoreStateTo((nsSelectState*)(nsISupports*)state);
|
||||
|
||||
// Don't flush, if the frame doesn't exist yet it doesn't care if
|
||||
// we're reset or not.
|
||||
DispatchContentReset();
|
||||
}
|
||||
nsCOMPtr<nsSelectState> state(do_QueryInterface(aState->GetStateProperty()));
|
||||
|
||||
nsAutoString disabled;
|
||||
rv = aState->GetStateProperty(NS_LITERAL_STRING("disabled"), disabled);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "disabled restore failed!");
|
||||
if (rv == NS_STATE_PROPERTY_EXISTS) {
|
||||
SetDisabled(disabled.EqualsLiteral("t"));
|
||||
if (!state) return PR_FALSE;
|
||||
|
||||
RestoreStateTo(state);
|
||||
|
||||
|
||||
// Don't flush, if the frame doesn't exist yet it doesn't care if
|
||||
// we're reset or not.
|
||||
DispatchContentReset();
|
||||
|
||||
if (aState->DisabledIsSet()) {
|
||||
SetDisabled(aState->GetDisabled());
|
||||
}
|
||||
|
||||
return PR_FALSE;
|
||||
|
@ -1590,8 +1582,8 @@ nsHTMLSelectElement::RestoreStateTo(nsSelectState* aNewSelected)
|
|||
nsIDOMHTMLOptionElement *option = mOptions->ItemAsOption(i);
|
||||
if (option) {
|
||||
nsAutoString value;
|
||||
option->GetValue(value);
|
||||
if (aNewSelected->ContainsOption(i, value)) {
|
||||
nsresult rv = option->GetValue(value);
|
||||
if (NS_SUCCEEDED(rv) && aNewSelected->ContainsOption(i, value)) {
|
||||
SetOptionsSelectedByIndex(i, i, PR_TRUE, PR_FALSE, PR_TRUE, PR_TRUE, nsnull);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -156,6 +156,15 @@ private:
|
|||
};
|
||||
|
||||
|
||||
#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
|
||||
*/
|
||||
|
@ -168,6 +177,7 @@ public:
|
|||
{
|
||||
}
|
||||
|
||||
NS_DECLARE_STATIC_IID_ACCESSOR(NS_SELECT_STATE_IID)
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
void PutOption(PRInt32 aIndex, const nsAString& aValue)
|
||||
|
@ -490,7 +500,7 @@ protected:
|
|||
* The temporary restore state in case we try to restore before parser is
|
||||
* done adding options
|
||||
*/
|
||||
nsRefPtr<nsSelectState> mRestoreState;
|
||||
nsCOMPtr<nsSelectState> mRestoreState;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -75,6 +75,7 @@
|
|||
#include "nsLayoutErrors.h"
|
||||
#include "nsStubMutationObserver.h"
|
||||
#include "nsDOMError.h"
|
||||
#include "nsISupportsPrimitives.h"
|
||||
|
||||
static NS_DEFINE_CID(kXULControllersCID, NS_XULCONTROLLERS_CID);
|
||||
|
||||
|
@ -908,6 +909,11 @@ nsHTMLTextAreaElement::SaveState()
|
|||
if (mValueChanged) {
|
||||
rv = GetPrimaryPresState(this, &state);
|
||||
if (state) {
|
||||
nsCOMPtr<nsISupportsString> pState
|
||||
(do_CreateInstance(NS_SUPPORTS_STRING_CONTRACTID));
|
||||
|
||||
if (!pState) return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
nsAutoString value;
|
||||
GetValueInternal(value, PR_TRUE);
|
||||
|
||||
|
@ -915,9 +921,10 @@ nsHTMLTextAreaElement::SaveState()
|
|||
value,
|
||||
nsLinebreakConverter::eLinebreakPlatform,
|
||||
nsLinebreakConverter::eLinebreakContent);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "Converting linebreaks failed!");
|
||||
rv = state->SetStateProperty(NS_LITERAL_STRING("value"), value);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "value save failed!");
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
pState->SetData(value);
|
||||
state->SetStateProperty(pState);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -928,14 +935,7 @@ nsHTMLTextAreaElement::SaveState()
|
|||
if (state) {
|
||||
PRBool disabled;
|
||||
GetDisabled(&disabled);
|
||||
if (disabled) {
|
||||
rv |= state->SetStateProperty(NS_LITERAL_STRING("disabled"),
|
||||
NS_LITERAL_STRING("t"));
|
||||
} else {
|
||||
rv |= state->SetStateProperty(NS_LITERAL_STRING("disabled"),
|
||||
NS_LITERAL_STRING("f"));
|
||||
}
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "disabled save failed!");
|
||||
state->SetDisabled(disabled);
|
||||
}
|
||||
}
|
||||
return rv;
|
||||
|
@ -944,17 +944,18 @@ nsHTMLTextAreaElement::SaveState()
|
|||
PRBool
|
||||
nsHTMLTextAreaElement::RestoreState(nsPresState* aState)
|
||||
{
|
||||
nsAutoString value;
|
||||
nsresult rv =
|
||||
aState->GetStateProperty(NS_LITERAL_STRING("value"), value);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "value restore failed!");
|
||||
SetValue(value);
|
||||
|
||||
nsAutoString disabled;
|
||||
rv = aState->GetStateProperty(NS_LITERAL_STRING("disabled"), disabled);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "disabled restore failed!");
|
||||
if (rv == NS_STATE_PROPERTY_EXISTS) {
|
||||
SetDisabled(disabled.EqualsLiteral("t"));
|
||||
nsCOMPtr<nsISupportsString> state
|
||||
(do_QueryInterface(aState->GetStateProperty()));
|
||||
|
||||
if (!state) return false;
|
||||
|
||||
nsAutoString data;
|
||||
state->GetData(data);
|
||||
SetValue(data);
|
||||
|
||||
if (aState->DisabledIsSet()) {
|
||||
SetDisabled(aState->GetDisabled());
|
||||
}
|
||||
|
||||
return PR_FALSE;
|
||||
|
|
|
@ -51,75 +51,6 @@
|
|||
#include "nsString.h"
|
||||
// Implementation /////////////////////////////////////////////////////////////////
|
||||
|
||||
nsresult
|
||||
nsPresState::Init()
|
||||
{
|
||||
return mPropertyTable.Init(8) ? NS_OK : NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsPresState::GetStateProperty(const nsAString& aName, nsAString& aResult)
|
||||
{
|
||||
nsresult rv = NS_STATE_PROPERTY_NOT_THERE;
|
||||
aResult.Truncate();
|
||||
|
||||
// Retrieve from hashtable.
|
||||
nsISupports *data = mPropertyTable.GetWeak(aName);
|
||||
|
||||
// Strings are stored in the table as UTF-8, to save space.
|
||||
// XXX minimize conversions here...
|
||||
|
||||
nsCOMPtr<nsISupportsCString> supportsStr = do_QueryInterface(data);
|
||||
if (supportsStr) {
|
||||
nsCAutoString data;
|
||||
supportsStr->GetData(data);
|
||||
|
||||
CopyUTF8toUTF16(data, aResult);
|
||||
aResult.SetIsVoid(data.IsVoid());
|
||||
rv = NS_STATE_PROPERTY_EXISTS;
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsPresState::SetStateProperty(const nsAString& aName, const nsAString& aValue)
|
||||
{
|
||||
// Add to hashtable
|
||||
nsCOMPtr<nsISupportsCString> supportsStr(do_CreateInstance(NS_SUPPORTS_CSTRING_CONTRACTID));
|
||||
NS_ENSURE_TRUE(supportsStr, NS_ERROR_OUT_OF_MEMORY);
|
||||
NS_ConvertUTF16toUTF8 data(aValue);
|
||||
data.SetIsVoid(aValue.IsVoid());
|
||||
supportsStr->SetData(data);
|
||||
|
||||
mPropertyTable.Put(aName, supportsStr);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsPresState::RemoveStateProperty(const nsAString& aName)
|
||||
{
|
||||
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
|
||||
nsPresState::SetScrollState(const nsRect& aRect)
|
||||
{
|
||||
|
@ -147,20 +78,16 @@ nsPresState::GetScrollState()
|
|||
nsresult
|
||||
NS_NewPresState(nsPresState** aState)
|
||||
{
|
||||
nsPresState *state;
|
||||
NS_ENSURE_ARG_POINTER(aState);
|
||||
|
||||
nsPresState *state = new nsPresState();
|
||||
|
||||
*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;
|
||||
*aState = state;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -53,21 +53,29 @@
|
|||
class nsPresState
|
||||
{
|
||||
public:
|
||||
NS_HIDDEN_(nsresult) Init();
|
||||
nsPresState() : mContentState(nsnull), mDisabledSet(PR_FALSE),
|
||||
mScrollState(nsnull) {};
|
||||
|
||||
NS_HIDDEN_(nsresult) GetStatePropertyAsSupports(const nsAString& aName,
|
||||
nsISupports** aResult);
|
||||
PRBool GetDisabled() {
|
||||
return mDisabled;
|
||||
}
|
||||
|
||||
NS_HIDDEN_(nsresult) SetStatePropertyAsSupports(const nsAString& aName,
|
||||
nsISupports* aValue);
|
||||
PRBool DisabledIsSet() {
|
||||
return mDisabledSet;
|
||||
}
|
||||
|
||||
NS_HIDDEN_(nsresult) GetStateProperty(const nsAString& aProperty,
|
||||
nsAString& aResult);
|
||||
void SetDisabled(PRBool aDisabled) {
|
||||
mDisabled = aDisabled;
|
||||
mDisabledSet = PR_TRUE;
|
||||
}
|
||||
|
||||
NS_HIDDEN_(nsresult) SetStateProperty(const nsAString& aProperty,
|
||||
const nsAString& aValue);
|
||||
nsISupports* GetStateProperty() {
|
||||
return mContentState;
|
||||
}
|
||||
|
||||
NS_HIDDEN_(nsresult) RemoveStateProperty(const nsAString& aProperty);
|
||||
void SetStateProperty(nsISupports *aProperty) {
|
||||
mContentState = aProperty;
|
||||
}
|
||||
|
||||
NS_HIDDEN_(nsresult) SetScrollState(const nsRect& aState);
|
||||
|
||||
|
@ -75,7 +83,10 @@ public:
|
|||
|
||||
// MEMBER VARIABLES
|
||||
protected:
|
||||
nsInterfaceHashtable<nsStringHashKey,nsISupports> mPropertyTable;
|
||||
nsCOMPtr<nsISupports> mContentState;
|
||||
PRPackedBool mDisabled;
|
||||
PRPackedBool mDisabledSet;
|
||||
|
||||
nsAutoPtr<nsRect> mScrollState;
|
||||
};
|
||||
|
||||
|
|
|
@ -534,7 +534,13 @@ nsIsIndexFrame::SaveState(SpecialStateID aStateID, nsPresState** aState)
|
|||
// Construct a pres state and store value in it.
|
||||
res = NS_NewPresState(aState);
|
||||
NS_ENSURE_SUCCESS(res, res);
|
||||
res = (*aState)->SetStateProperty(NS_LITERAL_STRING("value"), stateString);
|
||||
|
||||
nsCOMPtr<nsISupportsString> state
|
||||
(do_CreateInstance(NS_SUPPORTS_STRING_CONTRACTID));
|
||||
if (!state) return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
state->SetData(stateString);
|
||||
(*aState)->SetStateProperty(state);
|
||||
}
|
||||
|
||||
return res;
|
||||
|
@ -546,10 +552,11 @@ nsIsIndexFrame::RestoreState(nsPresState* aState)
|
|||
NS_ENSURE_ARG_POINTER(aState);
|
||||
|
||||
// Set the value to the stored state.
|
||||
nsAutoString stateString;
|
||||
nsresult res = aState->GetStateProperty(NS_LITERAL_STRING("value"), stateString);
|
||||
NS_ENSURE_SUCCESS(res, res);
|
||||
nsCOMPtr<nsISupportsString> stateString
|
||||
(do_QueryInterface(aState->GetStateProperty()));
|
||||
|
||||
SetInputValue(stateString);
|
||||
nsAutoString data;
|
||||
stateString->GetData(data);
|
||||
SetInputValue(data);
|
||||
return NS_OK;
|
||||
}
|
||||
|
|
|
@ -394,11 +394,8 @@ nsBoxObject::GetProperty(const PRUnichar* aPropertyName, PRUnichar** aResult)
|
|||
nsCOMPtr<nsISupportsString> supportsStr = do_QueryInterface(data);
|
||||
if (!supportsStr)
|
||||
return NS_ERROR_FAILURE;
|
||||
nsAutoString result;
|
||||
supportsStr->GetData(result);
|
||||
|
||||
*aResult = result.IsVoid() ? nsnull : ToNewUnicode(result);
|
||||
return NS_OK;
|
||||
return supportsStr->ToString(aResult);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
|
Загрузка…
Ссылка в новой задаче