Bug 345339. Make nsPresState not use a hashtable in favor of using less memory and only storing the things it really wants to store. Switch box objects to their own hashtable. r+sr=roc

This commit is contained in:
Graeme McCutcheon 2008-12-12 14:25:22 -05:00
Родитель 57817d5106
Коммит 5a486a7210
14 изменённых файлов: 333 добавлений и 273 удалений

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

@ -0,0 +1,27 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/REC-html401-19991224/strict.dtd">
<html>
<head>
<title>Form Elements</title>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
</head>
<body>
<p>
<select id="select">
<option value="Mozilla">Mozilla</option>
<option value="Firefox">Firefox</option>
</select>
<form name="radioform" id="radioform">
<input type="radio" id="radio1" name="answer" value="Yes"
checked="checked" />
<input type="radio" id="radio2" name="answer" value="No" />
</form>
<input type="password" id="password" />
<input type="hidden" id="hidden" />
<input type="file" id="file" />
</p>
</body>
</html>

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

@ -98,6 +98,8 @@ _TEST_FILES = test_bug5141.html \
test_bug339494.xhtml \
test_bug339494.xul \
test_bug343596.html \
test_bug345339.html \
345339_iframe.html \
test_bug352728.html \
test_bug352728.xhtml \
test_bug353334.html \

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

@ -0,0 +1,67 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=345339
-->
<head>
<title>Test for Bug 345339</title>
<script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=345339">Mozilla Bug 345339</a>
<p id="display"></p>
<div id="content" style="display: none">
</div>
<iframe id="testframe"
src="http://localhost:8888/tests/content/base/test/345339_iframe.html">
</iframe>
<pre id="test">
<script class="testbody" type="text/javascript">
/** Test for Bug 345339 **/
SimpleTest.waitForExplicitFinish();
function afterLoad() {
var iframeDoc = $("testframe").contentDocument;
/* change all the form controls */
iframeDoc.getElementById("select").selectedIndex = 1;
iframeDoc.getElementById("radio2").checked = true;
iframeDoc.getElementById("password").value = "123456";
iframeDoc.getElementById("hidden").value = "gecko";
netscape.security.PrivilegeManager.enablePrivilege("UniversalFileRead");
iframeDoc.getElementById("file").value = "dummyfile.txt";
/* Reload the page */
$("testframe").setAttribute("onload", "afterReload()");
iframeDoc.location.reload();
}
addLoadEvent(afterLoad);
function afterReload() {
var iframeDoc = $("testframe").contentDocument;
is(iframeDoc.getElementById("select").selectedIndex, 1,
"select element selected index preserved");
is(iframeDoc.getElementById("radio1").checked, false,
"radio button #1 value preserved");
is(iframeDoc.getElementById("radio2").checked, true,
"radio button #2 value preserved");
isnot(iframeDoc.getElementById("password").value, "123456",
"password field value forgotten");
is(iframeDoc.getElementById("hidden").value, "gecko",
"hidden field value preserved");
netscape.security.PrivilegeManager.enablePrivilege("UniversalFileRead");
is(iframeDoc.getElementById("file").value, "dummyfile.txt",
"file field value preserved");
SimpleTest.finish();
}
</script>
</pre>
</body>
</html>

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

@ -1364,10 +1364,12 @@ 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 = NS_NewPresState(aPresState);
if (NS_SUCCEEDED(result)) {
result = history->AddState(key, *aPresState);
*aPresState = new nsPresState();
if (!*aPresState) {
return NS_ERROR_OUT_OF_MEMORY;
}
result = history->AddState(key, *aPresState);
}
}

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

@ -591,14 +591,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;
@ -607,12 +600,10 @@ 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);
if (aState->IsDisabledSet()) {
SetDisabled(aState->GetDisabled());
}
return PR_FALSE;

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

@ -145,6 +145,66 @@ 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
PRBool IsCheckedSet() {
return mCheckedSet;
}
PRBool GetChecked() {
return mChecked;
}
void SetChecked(PRBool aChecked) {
mChecked = aChecked;
mCheckedSet = PR_TRUE;
}
const nsString& GetValue() {
return mValue;
}
void SetValue(const nsAString &aValue) {
mValue = aValue;
}
const nsString& GetFilename() {
return mFilename;
}
void SetFilename(const nsAString &aFilename) {
mFilename = aFilename;
}
nsHTMLInputElementState()
: mValue()
, mFilename()
, mChecked(PR_FALSE)
, mCheckedSet(PR_FALSE)
{};
protected:
nsString mValue;
nsString mFilename;
PRPackedBool mChecked;
PRPackedBool mCheckedSet;
};
NS_IMPL_ISUPPORTS1(nsHTMLInputElementState, nsHTMLInputElementState)
NS_DEFINE_STATIC_IID_ACCESSOR(nsHTMLInputElementState, NS_INPUT_ELEMENT_STATE_IID)
class nsHTMLInputElement : public nsGenericHTMLFormElement,
public nsImageLoadingContent,
public nsIDOMHTMLInputElement,
@ -2544,7 +2604,8 @@ nsHTMLInputElement::SaveState()
{
nsresult rv = NS_OK;
nsPresState *state = nsnull;
nsRefPtr<nsHTMLInputElementState> inputState = nsnull;
switch (mType) {
case NS_FORM_INPUT_CHECKBOX:
case NS_FORM_INPUT_RADIO:
@ -2557,17 +2618,12 @@ 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, &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 = new nsHTMLInputElementState();
if (!inputState) {
return NS_ERROR_OUT_OF_MEMORY;
}
inputState->SetChecked(checked);
}
break;
}
@ -2579,47 +2635,50 @@ nsHTMLInputElement::SaveState()
case NS_FORM_INPUT_HIDDEN:
{
if (GET_BOOLBIT(mBitField, BF_VALUE_CHANGED)) {
rv = GetPrimaryPresState(this, &state);
if (state) {
nsAutoString value;
GetValue(value);
rv = nsLinebreakConverter::ConvertStringLineBreaks(
value,
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 = new nsHTMLInputElementState();
if (!inputState) {
return NS_ERROR_OUT_OF_MEMORY;
}
}
break;
}
nsAutoString value;
GetValue(value);
rv = nsLinebreakConverter::ConvertStringLineBreaks(
value,
nsLinebreakConverter::eLinebreakPlatform,
nsLinebreakConverter::eLinebreakContent);
NS_ASSERTION(NS_SUCCEEDED(rv), "Converting linebreaks failed!");
inputState->SetValue(value);
}
break;
}
case NS_FORM_INPUT_FILE:
{
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 = new nsHTMLInputElementState();
if (!inputState) {
return NS_ERROR_OUT_OF_MEMORY;
}
inputState->SetFilename(*mFileName);
}
break;
}
}
nsPresState* state = nsnull;
if (inputState) {
rv = GetPrimaryPresState(this, &state);
if (state) {
state->SetStateProperty(inputState);
}
}
if (GET_BOOLBIT(mBitField, BF_DISABLED_CHANGED)) {
rv |= GetPrimaryPresState(this, &state);
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);
}
}
@ -2685,50 +2744,37 @@ nsHTMLInputElement::RestoreState(nsPresState* aState)
{
PRBool restoredCheckedState = PR_FALSE;
nsresult rv;
nsCOMPtr<nsHTMLInputElementState> inputState
(do_QueryInterface(aState->GetStateProperty()));
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);
if (inputState) {
switch (mType) {
case NS_FORM_INPUT_CHECKBOX:
case NS_FORM_INPUT_RADIO:
{
if (inputState->IsCheckedSet()) {
restoredCheckedState = PR_TRUE;
DoSetChecked(inputState->GetChecked());
}
break;
}
break;
}
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);
case NS_FORM_INPUT_TEXT:
case NS_FORM_INPUT_HIDDEN:
{
SetValueInternal(inputState->GetValue(), nsnull, PR_FALSE);
break;
}
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);
case NS_FORM_INPUT_FILE:
{
SetFileName(inputState->GetFilename());
break;
}
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->IsDisabledSet()) {
SetDisabled(aState->GetDisabled());
}
return restoredCheckedState;

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

@ -69,7 +69,8 @@
#include "nsRuleData.h"
#include "nsEventDispatcher.h"
NS_IMPL_ISUPPORTS0(nsSelectState)
NS_IMPL_ISUPPORTS1(nsSelectState, nsSelectState)
NS_DEFINE_STATIC_IID_ACCESSOR(nsSelectState, NS_SELECT_STATE_IID)
//----------------------------------------------------------------------
//
@ -1491,21 +1492,12 @@ 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);
}
}
@ -1516,22 +1508,19 @@ 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 (rv == NS_STATE_PROPERTY_EXISTS) {
RestoreStateTo((nsSelectState*)(nsISupports*)state);
nsCOMPtr<nsSelectState> state(
do_QueryInterface(aState->GetStateProperty()));
if (state) {
RestoreStateTo(state);
// Don't flush, if the frame doesn't exist yet it doesn't care if
// we're reset or not.
DispatchContentReset();
}
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->IsDisabledSet()) {
SetDisabled(aState->GetDisabled());
}
return PR_FALSE;
@ -1569,8 +1558,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);
}
}

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

@ -164,6 +164,13 @@ private:
nsHTMLSelectElement* mSelect;
};
#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
@ -177,6 +184,7 @@ public:
{
}
NS_DECLARE_STATIC_IID_ACCESSOR(NS_SELECT_STATE_IID)
NS_DECL_ISUPPORTS
void PutOption(PRInt32 aIndex, const nsAString& aValue)
@ -498,7 +506,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 "nsStubMutationObserver.h"
#include "nsDOMError.h"
#include "mozAutoDocUpdate.h"
#include "nsISupportsPrimitives.h"
static NS_DEFINE_CID(kXULControllersCID, NS_XULCONTROLLERS_CID);
@ -872,8 +873,14 @@ nsHTMLTextAreaElement::SaveState()
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!");
nsCOMPtr<nsISupportsString> pState
(do_CreateInstance(NS_SUPPORTS_STRING_CONTRACTID));
if (!pState) {
return NS_ERROR_OUT_OF_MEMORY;
}
pState->SetData(value);
state->SetStateProperty(pState);
}
}
@ -884,14 +891,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;
@ -900,23 +900,24 @@ nsHTMLTextAreaElement::SaveState()
PRBool
nsHTMLTextAreaElement::RestoreState(nsPresState* aState)
{
nsAutoString value;
nsresult rv =
aState->GetStateProperty(NS_LITERAL_STRING("value"), value);
if (rv == NS_STATE_PROPERTY_EXISTS) {
SetValue(value);
nsCOMPtr<nsISupportsString> state
(do_QueryInterface(aState->GetStateProperty()));
if (state) {
nsAutoString data;
state->GetData(data);
SetValue(data);
}
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->IsDisabledSet()) {
SetDisabled(aState->GetDisabled());
}
return PR_FALSE;
}
nsresult
nsHTMLTextAreaElement::BeforeSetAttr(PRInt32 aNameSpaceID, nsIAtom* aName,
const nsAString* aValue, PRBool aNotify)

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

@ -43,85 +43,10 @@
#include "nsCOMPtr.h"
#include "nsXPCOM.h"
#include "nsISupportsPrimitives.h"
#include "nsIComponentManager.h"
#include "nsXPIDLString.h"
#include "nsReadableUtils.h"
#include "nsLayoutErrors.h"
#include "nsPresState.h"
#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.
if (mPropertyTable.Get(aName, aResult))
return NS_STATE_PROPERTY_EXISTS;
return NS_STATE_PROPERTY_NOT_THERE;
}
nsresult
nsPresState::SetStatePropertyAsSupports(const nsAString& aName,
nsISupports* aValue)
{
mPropertyTable.Put(aName, aValue);
return NS_OK;
}
nsresult
nsPresState::SetScrollState(const nsRect& aRect)
{
@ -149,26 +74,6 @@ nsPresState::GetScrollState()
void
nsPresState::ClearNonScrollState()
{
mPropertyTable.Clear();
mContentData = nsnull;
mDisabledSet = PR_FALSE;
}
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;
}

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

@ -44,8 +44,6 @@
#define nsPresState_h_
#include "prtypes.h"
#include "nsStringFwd.h"
#include "nsInterfaceHashtable.h"
#include "nsPoint.h"
#include "nsAutoPtr.h"
#include "nsRect.h"
@ -53,21 +51,11 @@
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);
nsPresState()
: mContentData(nsnull)
, mDisabledSet(PR_FALSE)
, mDisabled(PR_FALSE)
{}
NS_HIDDEN_(nsresult) SetScrollState(const nsRect& aState);
@ -75,12 +63,38 @@ public:
NS_HIDDEN_(void) ClearNonScrollState();
PRBool GetDisabled()
{
return mDisabled;
}
void SetDisabled(PRBool aDisabled)
{
mDisabled = aDisabled;
mDisabledSet = PR_TRUE;
}
PRBool IsDisabledSet()
{
return mDisabledSet;
}
nsISupports* GetStateProperty()
{
return mContentData;
}
void SetStateProperty(nsISupports *aProperty)
{
mContentData = aProperty;
}
// MEMBER VARIABLES
protected:
nsInterfaceHashtable<nsStringHashKey,nsISupports> mPropertyTable;
nsCOMPtr<nsISupports> mContentData;
PRPackedBool mDisabledSet;
PRPackedBool mDisabled;
nsAutoPtr<nsRect> mScrollState;
};
NS_HIDDEN_(nsresult) NS_NewPresState(nsPresState **aState);
#endif /* nsPresState_h_ */

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

@ -535,9 +535,18 @@ nsIsIndexFrame::SaveState(SpecialStateID aStateID, nsPresState** aState)
if (! stateString.IsEmpty()) {
// 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);
*aState = new nsPresState();
if (!*aState)
return NS_ERROR_OUT_OF_MEMORY;
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;
@ -549,11 +558,12 @@ 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()));
nsAutoString data;
stateString->GetData(data);
SetInputValue(data);
if (res == NS_STATE_PROPERTY_EXISTS)
SetInputValue(stateString);
return NS_OK;
}

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

@ -2843,13 +2843,14 @@ nsGfxScrollFrameInner::SaveState(nsIStatefulFrame::SpecialStateID aStateID)
nsRect childRect = child->GetBounds();
childRect.x = x;
childRect.y = y;
nsAutoPtr<nsPresState> state;
nsresult rv = NS_NewPresState(getter_Transfers(state));
NS_ENSURE_SUCCESS(rv, nsnull);
nsPresState* state = new nsPresState();
if (!state) {
return nsnull;
}
state->SetScrollState(childRect);
return state.forget();
return state;
}
void

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

@ -356,11 +356,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