Bug 62713: Only save form input values in SH if changed plus cleanups (error handling, NS_LITERAL_STRING), r=jst@netscape.com, sr=vidur@netscape.com

This commit is contained in:
pollmann%netscape.com 2001-02-06 01:59:59 +00:00
parent f42e833e2c
commit c9046692ff
11 changed files with 358 additions and 164 deletions

View File

@ -679,23 +679,39 @@ nsFileControlFrame::GetStateType(nsIPresContext* aPresContext, nsIStatefulFrame:
NS_IMETHODIMP
nsFileControlFrame::SaveState(nsIPresContext* aPresContext, nsIPresState** aState)
{
// Construct a pres state.
NS_NewPresState(aState); // The addref happens here.
// This string will hold a single item, whether or not we're checked.
nsAutoString stateString;
GetProperty(nsHTMLAtoms::value, stateString);
(*aState)->SetStateProperty(NS_ConvertASCIItoUCS2("checked"), stateString);
NS_ENSURE_ARG_POINTER(aState);
return NS_OK;
// Get the value string
nsAutoString stateString;
nsresult res = GetProperty(nsHTMLAtoms::value, stateString);
NS_ENSURE_SUCCESS(res, res);
// Compare to default value, and only save if needed (Bug 62713)
nsAutoString defaultStateString;
nsCOMPtr<nsIDOMHTMLInputElement> formControl(do_QueryInterface(mContent));
if (formControl) {
formControl->GetDefaultValue(defaultStateString);
}
if (! stateString.Equals(defaultStateString)) {
// 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);
}
return res;
}
NS_IMETHODIMP
nsFileControlFrame::RestoreState(nsIPresContext* aPresContext, nsIPresState* aState)
{
nsAutoString string;
aState->GetStateProperty(NS_ConvertASCIItoUCS2("checked"), string);
SetProperty(aPresContext, nsHTMLAtoms::value, string);
return NS_OK;
NS_ENSURE_ARG_POINTER(aState);
nsAutoString string;
aState->GetStateProperty(NS_LITERAL_STRING("value"), string);
SetProperty(aPresContext, nsHTMLAtoms::value, string);
return NS_OK;
}

View File

@ -609,28 +609,48 @@ NS_IMETHODIMP nsGfxCheckboxControlFrame::GetStateType(nsIPresContext* aPresConte
NS_IMETHODIMP nsGfxCheckboxControlFrame::SaveState(nsIPresContext* aPresContext,
nsIPresState** aState)
{
// Construct a pres state.
NS_NewPresState(aState); // The addref happens here.
// This string will hold a single item, whether or not we're checked.
nsAutoString stateString;
GetCheckboxControlFrameState(stateString);
(*aState)->SetStateProperty(NS_ConvertASCIItoUCS2("checked"), stateString);
NS_ENSURE_ARG_POINTER(aState);
return NS_OK;
CheckState stateCheck = GetCheckboxState();
PRBool defaultStateBool = PR_FALSE;
nsresult res = GetDefaultCheckState(&defaultStateBool);
// Compare to default value, and only save if needed (Bug 62713)
// eOn/eOff comparisons used to handle 'mixed' state (alway save)
if (!(NS_CONTENT_ATTR_HAS_VALUE == res &&
((eOn == stateCheck && defaultStateBool) ||
(eOff == stateCheck && !defaultStateBool)))) {
// Get the value string
nsAutoString stateString;
CheckStateToString(stateCheck, stateString);
// Construct a pres state and store value in it.
res = NS_NewPresState(aState);
NS_ENSURE_SUCCESS(res, res);
res = (*aState)->SetStateProperty(NS_LITERAL_STRING("checked"), stateString);
}
return res;
}
NS_IMETHODIMP nsGfxCheckboxControlFrame::RestoreState(nsIPresContext* aPresContext,
nsIPresState* aState)
{
NS_ENSURE_ARG_POINTER(aState);
if (!mDidInit) {
mPresContext = aPresContext;
InitializeControl(aPresContext);
mDidInit = PR_TRUE;
}
nsAutoString string;
aState->GetStateProperty(NS_ConvertASCIItoUCS2("checked"), string);
SetCheckboxControlFrameState(aPresContext, string);
// Set the value to the stored state.
nsAutoString stateString;
nsresult res = aState->GetStateProperty(NS_LITERAL_STRING("checked"), stateString);
NS_ENSURE_SUCCESS(res, res);
SetCheckboxControlFrameState(aPresContext, stateString);
return NS_OK;
}

View File

@ -370,15 +370,26 @@ nsGfxRadioControlFrame::GetStateType(nsIPresContext* aPresContext, nsIStatefulFr
NS_IMETHODIMP
nsGfxRadioControlFrame::SaveState(nsIPresContext* aPresContext, nsIPresState** aState)
{
// Construct a pres state.
NS_NewPresState(aState); // The addref happens here.
// This string will hold a single item, whether or not we're checked.
nsAutoString stateString;
nsFormControlHelper::GetBoolString(GetRadioState(), stateString);
(*aState)->SetStateProperty(NS_ConvertASCIItoUCS2("checked"), stateString);
NS_ENSURE_ARG_POINTER(aState);
return NS_OK;
nsresult res = NS_OK;
PRBool stateBool = GetRadioState();
PRBool defaultStateBool = GetDefaultChecked();
// Compare to default value, and only save if needed (Bug 62713)
if (stateBool != defaultStateBool) {
// Get the value string
nsAutoString stateString;
nsFormControlHelper::GetBoolString(stateBool, stateString);
// Construct a pres state and store value in it.
res = NS_NewPresState(aState);
NS_ENSURE_SUCCESS(res, res);
res = (*aState)->SetStateProperty(NS_LITERAL_STRING("checked"), stateString);
}
return res;
}
@ -387,6 +398,8 @@ nsGfxRadioControlFrame::SaveState(nsIPresContext* aPresContext, nsIPresState** a
NS_IMETHODIMP
nsGfxRadioControlFrame::RestoreState(nsIPresContext* aPresContext, nsIPresState* aState)
{
NS_ENSURE_ARG_POINTER(aState);
if (!mDidInit) {
mPresContext = aPresContext;
InitializeControl(aPresContext);
@ -394,9 +407,13 @@ nsGfxRadioControlFrame::RestoreState(nsIPresContext* aPresContext, nsIPresState*
}
mIsRestored = PR_TRUE;
nsAutoString string;
aState->GetStateProperty(NS_ConvertASCIItoUCS2("checked"), string);
SetProperty(aPresContext, nsHTMLAtoms::checked, string);
nsAutoString stateString;
nsresult res = aState->GetStateProperty(NS_LITERAL_STRING("checked"), stateString);
NS_ENSURE_SUCCESS(res, res);
res = SetProperty(aPresContext, nsHTMLAtoms::checked, stateString);
NS_ENSURE_SUCCESS(res, res);
mRestoredChecked = mChecked;
return NS_OK;

View File

@ -557,23 +557,33 @@ nsIsIndexFrame::GetStateType(nsIPresContext* aPresContext, nsIStatefulFrame::Sta
NS_IMETHODIMP
nsIsIndexFrame::SaveState(nsIPresContext* aPresContext, nsIPresState** aState)
{
// Construct a pres state.
NS_NewPresState(aState); // The addref happens here.
// This string will hold a single item, whether or not we're checked.
nsAutoString stateString;
GetInputValue(aPresContext, stateString);
(*aState)->SetStateProperty(NS_ConvertASCIItoUCS2("value"), stateString);
NS_ENSURE_ARG_POINTER(aState);
return NS_OK;
// Get the value string
nsAutoString stateString;
nsresult res = GetInputValue(aPresContext, stateString);
NS_ENSURE_SUCCESS(res, res);
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);
}
return res;
}
NS_IMETHODIMP
nsIsIndexFrame::RestoreState(nsIPresContext* aPresContext, nsIPresState* aState)
{
nsAutoString string;
aState->GetStateProperty(NS_ConvertASCIItoUCS2("value"), string);
SetInputValue(aPresContext, string);
NS_ENSURE_ARG_POINTER(aState);
return NS_OK;
// Set the value to the stored state.
nsAutoString stateString;
nsresult res = aState->GetStateProperty(NS_LITERAL_STRING("value"), stateString);
NS_ENSURE_SUCCESS(res, res);
return SetInputValue(aPresContext, stateString);
}

View File

@ -1959,7 +1959,7 @@ nsListControlFrame::Reset(nsIPresContext* aPresContext)
// Ok, so we were restored, now set the last known selections from the restore state.
if (hasBeenRestored) {
nsCOMPtr<nsISupports> supp;
mPresState->GetStatePropertyAsSupports(NS_ConvertASCIItoUCS2("selecteditems"), getter_AddRefs(supp));
mPresState->GetStatePropertyAsSupports(NS_LITERAL_STRING("selecteditems"), getter_AddRefs(supp));
nsresult res = NS_ERROR_NULL_POINTER;
if (!supp)
@ -2424,7 +2424,7 @@ nsresult nsListControlFrame::GetPresStateAndValueArray(nsISupportsArray ** aSupp
nsresult res = NS_ERROR_FAILURE;
if (mPresState) {
nsCOMPtr<nsISupports> supp;
mPresState->GetStatePropertyAsSupports(NS_ConvertASCIItoUCS2("selecteditems"), getter_AddRefs(supp));
mPresState->GetStatePropertyAsSupports(NS_LITERAL_STRING("selecteditems"), getter_AddRefs(supp));
if (supp) {
res = supp->QueryInterface(NS_GET_IID(nsISupportsArray), (void**)aSuppArray);
if (NS_FAILED(res)) {
@ -2439,7 +2439,7 @@ nsresult nsListControlFrame::GetPresStateAndValueArray(nsISupportsArray ** aSupp
if (createSupportsArray) {
res = NS_NewISupportsArray(aSuppArray);
if (NS_SUCCEEDED(res)) {
res = mPresState->SetStatePropertyAsSupports(NS_ConvertASCIItoUCS2("selecteditems"), *aSuppArray);
res = mPresState->SetStatePropertyAsSupports(NS_LITERAL_STRING("selecteditems"), *aSuppArray);
}
}
return res;
@ -3926,38 +3926,56 @@ nsListControlFrame::GetStateType(nsIPresContext* aPresContext,
NS_IMETHODIMP
nsListControlFrame::SaveStateInternal(nsIPresContext* aPresContext, nsIPresState** aState)
{
nsCOMPtr<nsISupportsArray> value;
nsresult res = NS_NewISupportsArray(getter_AddRefs(value));
if (NS_SUCCEEDED(res) && value) {
PRInt32 j=0;
PRInt32 length = 0;
GetNumberOfOptions(&length);
PRInt32 i;
for (i=0; i<length; i++) {
PRBool selected = PR_FALSE;
res = GetOptionSelected(i, &selected);
if (NS_SUCCEEDED(res) && selected) {
PRBool saveState = PR_FALSE;
nsresult res = NS_OK;
// Determine if we need to save state (non-default options selected)
PRInt32 i, numOptions = 0;
GetNumberOfOptions(&numOptions);
for (i = 0; i < numOptions; i++) {
nsCOMPtr<nsIContent> content = dont_AddRef(GetOptionContent(i));
nsCOMPtr<nsIDOMHTMLOptionElement> option(do_QueryInterface(content));
if (option) {
PRBool stateBool = IsContentSelected(content);
PRBool defaultStateBool = PR_FALSE;
res = option->GetDefaultSelected(&defaultStateBool);
NS_ENSURE_SUCCESS(res, res);
if (stateBool != defaultStateBool) {
saveState = PR_TRUE;
break;
}
}
}
if (saveState) {
nsCOMPtr<nsISupportsArray> value;
nsresult res = NS_NewISupportsArray(getter_AddRefs(value));
NS_ENSURE_TRUE(value, res);
PRInt32 j = 0;
for (i = 0; i < numOptions; i++) {
if (IsContentSelectedByIndex(i)) {
#ifdef FIX_FOR_BUG_50376
res = SetOptionIntoPresState(value, i, j++);
#else
nsCOMPtr<nsISupportsPRInt32> thisVal;
res = nsComponentManager::CreateInstance(NS_SUPPORTS_PRINT32_CONTRACTID,
nsnull, NS_GET_IID(nsISupportsPRInt32), (void**)getter_AddRefs(thisVal));
if (NS_SUCCEEDED(res) && thisVal) {
res = thisVal->SetData(i);
if (NS_SUCCEEDED(res)) {
PRBool okay = value->InsertElementAt((nsISupports *)thisVal, j++);
if (!okay) res = NS_ERROR_OUT_OF_MEMORY; // Most likely cause;
}
}
nsCOMPtr<nsISupportsPRInt32> thisVal(do_CreateInstance(NS_SUPPORTS_PRINT32_CONTRACTID));
NS_ENSURE_TRUE(thisVal, res);
res = thisVal->SetData(i);
NS_ENSURE_SUCCEEDED(res, res);
PRBool okay = value->InsertElementAt((nsISupports *)thisVal, j++);
NS_ENSURE_TRUE(okay, NS_ERROR_OUT_OF_MEMORY);
#endif
}
if (!NS_SUCCEEDED(res)) break;
}
res = NS_NewPresState(aState);
NS_ENSURE_SUCCESS(res, res);
res = (*aState)->SetStatePropertyAsSupports(NS_LITERAL_STRING("selecteditems"), value);
}
NS_NewPresState(aState);
(*aState)->SetStatePropertyAsSupports(NS_ConvertASCIItoUCS2("selecteditems"), value);
return res;
}
@ -3966,8 +3984,10 @@ NS_IMETHODIMP
nsListControlFrame::SaveState(nsIPresContext* aPresContext,
nsIPresState** aState)
{
NS_ENSURE_ARG_POINTER(aState);
if (mComboboxFrame == nsnull) {
return SaveStateInternal(aPresContext, aState);\
return SaveStateInternal(aPresContext, aState);
}
return NS_ERROR_FAILURE;
@ -3979,6 +3999,10 @@ nsListControlFrame::RestoreStateInternal(nsIPresContext* aPresContext,
nsIPresState* aState)
{
mPresState = aState;
if (mHasBeenInitialized) { // Already called Reset, call again to update selection
Reset(aPresContext);
}
return NS_OK;
}
@ -3987,6 +4011,7 @@ NS_IMETHODIMP
nsListControlFrame::RestoreState(nsIPresContext* aPresContext,
nsIPresState* aState)
{
NS_ENSURE_ARG_POINTER(aState);
// ignore requests for saving state that are made directly
// to the list frame by the system
// The combobox frame will call RestoreStateInternal

View File

@ -679,23 +679,39 @@ nsFileControlFrame::GetStateType(nsIPresContext* aPresContext, nsIStatefulFrame:
NS_IMETHODIMP
nsFileControlFrame::SaveState(nsIPresContext* aPresContext, nsIPresState** aState)
{
// Construct a pres state.
NS_NewPresState(aState); // The addref happens here.
// This string will hold a single item, whether or not we're checked.
nsAutoString stateString;
GetProperty(nsHTMLAtoms::value, stateString);
(*aState)->SetStateProperty(NS_ConvertASCIItoUCS2("checked"), stateString);
NS_ENSURE_ARG_POINTER(aState);
return NS_OK;
// Get the value string
nsAutoString stateString;
nsresult res = GetProperty(nsHTMLAtoms::value, stateString);
NS_ENSURE_SUCCESS(res, res);
// Compare to default value, and only save if needed (Bug 62713)
nsAutoString defaultStateString;
nsCOMPtr<nsIDOMHTMLInputElement> formControl(do_QueryInterface(mContent));
if (formControl) {
formControl->GetDefaultValue(defaultStateString);
}
if (! stateString.Equals(defaultStateString)) {
// 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);
}
return res;
}
NS_IMETHODIMP
nsFileControlFrame::RestoreState(nsIPresContext* aPresContext, nsIPresState* aState)
{
nsAutoString string;
aState->GetStateProperty(NS_ConvertASCIItoUCS2("checked"), string);
SetProperty(aPresContext, nsHTMLAtoms::value, string);
return NS_OK;
NS_ENSURE_ARG_POINTER(aState);
nsAutoString string;
aState->GetStateProperty(NS_LITERAL_STRING("value"), string);
SetProperty(aPresContext, nsHTMLAtoms::value, string);
return NS_OK;
}

View File

@ -609,28 +609,48 @@ NS_IMETHODIMP nsGfxCheckboxControlFrame::GetStateType(nsIPresContext* aPresConte
NS_IMETHODIMP nsGfxCheckboxControlFrame::SaveState(nsIPresContext* aPresContext,
nsIPresState** aState)
{
// Construct a pres state.
NS_NewPresState(aState); // The addref happens here.
// This string will hold a single item, whether or not we're checked.
nsAutoString stateString;
GetCheckboxControlFrameState(stateString);
(*aState)->SetStateProperty(NS_ConvertASCIItoUCS2("checked"), stateString);
NS_ENSURE_ARG_POINTER(aState);
return NS_OK;
CheckState stateCheck = GetCheckboxState();
PRBool defaultStateBool = PR_FALSE;
nsresult res = GetDefaultCheckState(&defaultStateBool);
// Compare to default value, and only save if needed (Bug 62713)
// eOn/eOff comparisons used to handle 'mixed' state (alway save)
if (!(NS_CONTENT_ATTR_HAS_VALUE == res &&
((eOn == stateCheck && defaultStateBool) ||
(eOff == stateCheck && !defaultStateBool)))) {
// Get the value string
nsAutoString stateString;
CheckStateToString(stateCheck, stateString);
// Construct a pres state and store value in it.
res = NS_NewPresState(aState);
NS_ENSURE_SUCCESS(res, res);
res = (*aState)->SetStateProperty(NS_LITERAL_STRING("checked"), stateString);
}
return res;
}
NS_IMETHODIMP nsGfxCheckboxControlFrame::RestoreState(nsIPresContext* aPresContext,
nsIPresState* aState)
{
NS_ENSURE_ARG_POINTER(aState);
if (!mDidInit) {
mPresContext = aPresContext;
InitializeControl(aPresContext);
mDidInit = PR_TRUE;
}
nsAutoString string;
aState->GetStateProperty(NS_ConvertASCIItoUCS2("checked"), string);
SetCheckboxControlFrameState(aPresContext, string);
// Set the value to the stored state.
nsAutoString stateString;
nsresult res = aState->GetStateProperty(NS_LITERAL_STRING("checked"), stateString);
NS_ENSURE_SUCCESS(res, res);
SetCheckboxControlFrameState(aPresContext, stateString);
return NS_OK;
}

View File

@ -370,15 +370,26 @@ nsGfxRadioControlFrame::GetStateType(nsIPresContext* aPresContext, nsIStatefulFr
NS_IMETHODIMP
nsGfxRadioControlFrame::SaveState(nsIPresContext* aPresContext, nsIPresState** aState)
{
// Construct a pres state.
NS_NewPresState(aState); // The addref happens here.
// This string will hold a single item, whether or not we're checked.
nsAutoString stateString;
nsFormControlHelper::GetBoolString(GetRadioState(), stateString);
(*aState)->SetStateProperty(NS_ConvertASCIItoUCS2("checked"), stateString);
NS_ENSURE_ARG_POINTER(aState);
return NS_OK;
nsresult res = NS_OK;
PRBool stateBool = GetRadioState();
PRBool defaultStateBool = GetDefaultChecked();
// Compare to default value, and only save if needed (Bug 62713)
if (stateBool != defaultStateBool) {
// Get the value string
nsAutoString stateString;
nsFormControlHelper::GetBoolString(stateBool, stateString);
// Construct a pres state and store value in it.
res = NS_NewPresState(aState);
NS_ENSURE_SUCCESS(res, res);
res = (*aState)->SetStateProperty(NS_LITERAL_STRING("checked"), stateString);
}
return res;
}
@ -387,6 +398,8 @@ nsGfxRadioControlFrame::SaveState(nsIPresContext* aPresContext, nsIPresState** a
NS_IMETHODIMP
nsGfxRadioControlFrame::RestoreState(nsIPresContext* aPresContext, nsIPresState* aState)
{
NS_ENSURE_ARG_POINTER(aState);
if (!mDidInit) {
mPresContext = aPresContext;
InitializeControl(aPresContext);
@ -394,9 +407,13 @@ nsGfxRadioControlFrame::RestoreState(nsIPresContext* aPresContext, nsIPresState*
}
mIsRestored = PR_TRUE;
nsAutoString string;
aState->GetStateProperty(NS_ConvertASCIItoUCS2("checked"), string);
SetProperty(aPresContext, nsHTMLAtoms::checked, string);
nsAutoString stateString;
nsresult res = aState->GetStateProperty(NS_LITERAL_STRING("checked"), stateString);
NS_ENSURE_SUCCESS(res, res);
res = SetProperty(aPresContext, nsHTMLAtoms::checked, stateString);
NS_ENSURE_SUCCESS(res, res);
mRestoredChecked = mChecked;
return NS_OK;

View File

@ -3169,29 +3169,47 @@ nsGfxTextControlFrame2::GetStateType(nsIPresContext* aPresContext, nsIStatefulFr
NS_IMETHODIMP
nsGfxTextControlFrame2::SaveState(nsIPresContext* aPresContext, nsIPresState** aState)
{
// Construct a pres state.
NS_NewPresState(aState); // The addref happens here.
nsString theString;
nsresult res = GetProperty(nsHTMLAtoms::value, theString);
if (NS_FAILED(res))
return res;
res = nsLinebreakConverter::ConvertStringLineBreaks(theString,
nsLinebreakConverter::eLinebreakPlatform, nsLinebreakConverter::eLinebreakContent);
NS_ASSERTION(NS_SUCCEEDED(res), "Converting linebreaks failed!");
(*aState)->SetStateProperty(NS_ConvertASCIItoUCS2("value"), theString);
NS_ENSURE_ARG_POINTER(aState);
// Get the value string
nsString stateString;
nsresult res = GetProperty(nsHTMLAtoms::value, stateString);
NS_ENSURE_SUCCESS(res, res);
// Compare to default value, and only save if needed (Bug 62713)
nsAutoString defaultStateString;
nsCOMPtr<nsIHTMLContent> formControl(do_QueryInterface(mContent));
if (formControl) {
formControl->GetAttribute(kNameSpaceID_None, nsHTMLAtoms::value, defaultStateString);
}
if (! stateString.Equals(defaultStateString)) {
// XXX Should use nsAutoString above but ConvertStringLineBreaks requires mOwnsBuffer!
res = nsLinebreakConverter::ConvertStringLineBreaks(stateString,
nsLinebreakConverter::eLinebreakPlatform, nsLinebreakConverter::eLinebreakContent);
NS_ASSERTION(NS_SUCCEEDED(res), "Converting linebreaks failed!");
// 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);
}
return res;
}
NS_IMETHODIMP
nsGfxTextControlFrame2::RestoreState(nsIPresContext* aPresContext, nsIPresState* aState)
{
NS_ENSURE_ARG_POINTER(aState);
// Set the value to the stored state.
nsAutoString stateString;
aState->GetStateProperty(NS_ConvertASCIItoUCS2("value"), stateString);
nsresult res = SetProperty(aPresContext, nsHTMLAtoms::value, stateString);
return res;
nsresult res = aState->GetStateProperty(NS_LITERAL_STRING("value"), stateString);
NS_ENSURE_SUCCESS(res, res);
return SetProperty(aPresContext, nsHTMLAtoms::value, stateString);
}
NS_IMETHODIMP

View File

@ -557,23 +557,33 @@ nsIsIndexFrame::GetStateType(nsIPresContext* aPresContext, nsIStatefulFrame::Sta
NS_IMETHODIMP
nsIsIndexFrame::SaveState(nsIPresContext* aPresContext, nsIPresState** aState)
{
// Construct a pres state.
NS_NewPresState(aState); // The addref happens here.
// This string will hold a single item, whether or not we're checked.
nsAutoString stateString;
GetInputValue(aPresContext, stateString);
(*aState)->SetStateProperty(NS_ConvertASCIItoUCS2("value"), stateString);
NS_ENSURE_ARG_POINTER(aState);
return NS_OK;
// Get the value string
nsAutoString stateString;
nsresult res = GetInputValue(aPresContext, stateString);
NS_ENSURE_SUCCESS(res, res);
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);
}
return res;
}
NS_IMETHODIMP
nsIsIndexFrame::RestoreState(nsIPresContext* aPresContext, nsIPresState* aState)
{
nsAutoString string;
aState->GetStateProperty(NS_ConvertASCIItoUCS2("value"), string);
SetInputValue(aPresContext, string);
NS_ENSURE_ARG_POINTER(aState);
return NS_OK;
// Set the value to the stored state.
nsAutoString stateString;
nsresult res = aState->GetStateProperty(NS_LITERAL_STRING("value"), stateString);
NS_ENSURE_SUCCESS(res, res);
return SetInputValue(aPresContext, stateString);
}

View File

@ -1959,7 +1959,7 @@ nsListControlFrame::Reset(nsIPresContext* aPresContext)
// Ok, so we were restored, now set the last known selections from the restore state.
if (hasBeenRestored) {
nsCOMPtr<nsISupports> supp;
mPresState->GetStatePropertyAsSupports(NS_ConvertASCIItoUCS2("selecteditems"), getter_AddRefs(supp));
mPresState->GetStatePropertyAsSupports(NS_LITERAL_STRING("selecteditems"), getter_AddRefs(supp));
nsresult res = NS_ERROR_NULL_POINTER;
if (!supp)
@ -2424,7 +2424,7 @@ nsresult nsListControlFrame::GetPresStateAndValueArray(nsISupportsArray ** aSupp
nsresult res = NS_ERROR_FAILURE;
if (mPresState) {
nsCOMPtr<nsISupports> supp;
mPresState->GetStatePropertyAsSupports(NS_ConvertASCIItoUCS2("selecteditems"), getter_AddRefs(supp));
mPresState->GetStatePropertyAsSupports(NS_LITERAL_STRING("selecteditems"), getter_AddRefs(supp));
if (supp) {
res = supp->QueryInterface(NS_GET_IID(nsISupportsArray), (void**)aSuppArray);
if (NS_FAILED(res)) {
@ -2439,7 +2439,7 @@ nsresult nsListControlFrame::GetPresStateAndValueArray(nsISupportsArray ** aSupp
if (createSupportsArray) {
res = NS_NewISupportsArray(aSuppArray);
if (NS_SUCCEEDED(res)) {
res = mPresState->SetStatePropertyAsSupports(NS_ConvertASCIItoUCS2("selecteditems"), *aSuppArray);
res = mPresState->SetStatePropertyAsSupports(NS_LITERAL_STRING("selecteditems"), *aSuppArray);
}
}
return res;
@ -3926,38 +3926,56 @@ nsListControlFrame::GetStateType(nsIPresContext* aPresContext,
NS_IMETHODIMP
nsListControlFrame::SaveStateInternal(nsIPresContext* aPresContext, nsIPresState** aState)
{
nsCOMPtr<nsISupportsArray> value;
nsresult res = NS_NewISupportsArray(getter_AddRefs(value));
if (NS_SUCCEEDED(res) && value) {
PRInt32 j=0;
PRInt32 length = 0;
GetNumberOfOptions(&length);
PRInt32 i;
for (i=0; i<length; i++) {
PRBool selected = PR_FALSE;
res = GetOptionSelected(i, &selected);
if (NS_SUCCEEDED(res) && selected) {
PRBool saveState = PR_FALSE;
nsresult res = NS_OK;
// Determine if we need to save state (non-default options selected)
PRInt32 i, numOptions = 0;
GetNumberOfOptions(&numOptions);
for (i = 0; i < numOptions; i++) {
nsCOMPtr<nsIContent> content = dont_AddRef(GetOptionContent(i));
nsCOMPtr<nsIDOMHTMLOptionElement> option(do_QueryInterface(content));
if (option) {
PRBool stateBool = IsContentSelected(content);
PRBool defaultStateBool = PR_FALSE;
res = option->GetDefaultSelected(&defaultStateBool);
NS_ENSURE_SUCCESS(res, res);
if (stateBool != defaultStateBool) {
saveState = PR_TRUE;
break;
}
}
}
if (saveState) {
nsCOMPtr<nsISupportsArray> value;
nsresult res = NS_NewISupportsArray(getter_AddRefs(value));
NS_ENSURE_TRUE(value, res);
PRInt32 j = 0;
for (i = 0; i < numOptions; i++) {
if (IsContentSelectedByIndex(i)) {
#ifdef FIX_FOR_BUG_50376
res = SetOptionIntoPresState(value, i, j++);
#else
nsCOMPtr<nsISupportsPRInt32> thisVal;
res = nsComponentManager::CreateInstance(NS_SUPPORTS_PRINT32_CONTRACTID,
nsnull, NS_GET_IID(nsISupportsPRInt32), (void**)getter_AddRefs(thisVal));
if (NS_SUCCEEDED(res) && thisVal) {
res = thisVal->SetData(i);
if (NS_SUCCEEDED(res)) {
PRBool okay = value->InsertElementAt((nsISupports *)thisVal, j++);
if (!okay) res = NS_ERROR_OUT_OF_MEMORY; // Most likely cause;
}
}
nsCOMPtr<nsISupportsPRInt32> thisVal(do_CreateInstance(NS_SUPPORTS_PRINT32_CONTRACTID));
NS_ENSURE_TRUE(thisVal, res);
res = thisVal->SetData(i);
NS_ENSURE_SUCCEEDED(res, res);
PRBool okay = value->InsertElementAt((nsISupports *)thisVal, j++);
NS_ENSURE_TRUE(okay, NS_ERROR_OUT_OF_MEMORY);
#endif
}
if (!NS_SUCCEEDED(res)) break;
}
res = NS_NewPresState(aState);
NS_ENSURE_SUCCESS(res, res);
res = (*aState)->SetStatePropertyAsSupports(NS_LITERAL_STRING("selecteditems"), value);
}
NS_NewPresState(aState);
(*aState)->SetStatePropertyAsSupports(NS_ConvertASCIItoUCS2("selecteditems"), value);
return res;
}
@ -3966,8 +3984,10 @@ NS_IMETHODIMP
nsListControlFrame::SaveState(nsIPresContext* aPresContext,
nsIPresState** aState)
{
NS_ENSURE_ARG_POINTER(aState);
if (mComboboxFrame == nsnull) {
return SaveStateInternal(aPresContext, aState);\
return SaveStateInternal(aPresContext, aState);
}
return NS_ERROR_FAILURE;
@ -3979,6 +3999,10 @@ nsListControlFrame::RestoreStateInternal(nsIPresContext* aPresContext,
nsIPresState* aState)
{
mPresState = aState;
if (mHasBeenInitialized) { // Already called Reset, call again to update selection
Reset(aPresContext);
}
return NS_OK;
}
@ -3987,6 +4011,7 @@ NS_IMETHODIMP
nsListControlFrame::RestoreState(nsIPresContext* aPresContext,
nsIPresState* aState)
{
NS_ENSURE_ARG_POINTER(aState);
// ignore requests for saving state that are made directly
// to the list frame by the system
// The combobox frame will call RestoreStateInternal