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 NS_IMETHODIMP
nsFileControlFrame::SaveState(nsIPresContext* aPresContext, nsIPresState** aState) nsFileControlFrame::SaveState(nsIPresContext* aPresContext, nsIPresState** aState)
{ {
// Construct a pres state. NS_ENSURE_ARG_POINTER(aState);
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);
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 NS_IMETHODIMP
nsFileControlFrame::RestoreState(nsIPresContext* aPresContext, nsIPresState* aState) nsFileControlFrame::RestoreState(nsIPresContext* aPresContext, nsIPresState* aState)
{ {
nsAutoString string; NS_ENSURE_ARG_POINTER(aState);
aState->GetStateProperty(NS_ConvertASCIItoUCS2("checked"), string);
SetProperty(aPresContext, nsHTMLAtoms::value, string);
return NS_OK;
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, NS_IMETHODIMP nsGfxCheckboxControlFrame::SaveState(nsIPresContext* aPresContext,
nsIPresState** aState) nsIPresState** aState)
{ {
// Construct a pres state. NS_ENSURE_ARG_POINTER(aState);
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);
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, NS_IMETHODIMP nsGfxCheckboxControlFrame::RestoreState(nsIPresContext* aPresContext,
nsIPresState* aState) nsIPresState* aState)
{ {
NS_ENSURE_ARG_POINTER(aState);
if (!mDidInit) { if (!mDidInit) {
mPresContext = aPresContext; mPresContext = aPresContext;
InitializeControl(aPresContext); InitializeControl(aPresContext);
mDidInit = PR_TRUE; mDidInit = PR_TRUE;
} }
nsAutoString string;
aState->GetStateProperty(NS_ConvertASCIItoUCS2("checked"), string); // Set the value to the stored state.
SetCheckboxControlFrameState(aPresContext, string); nsAutoString stateString;
nsresult res = aState->GetStateProperty(NS_LITERAL_STRING("checked"), stateString);
NS_ENSURE_SUCCESS(res, res);
SetCheckboxControlFrameState(aPresContext, stateString);
return NS_OK; return NS_OK;
} }

View File

@ -370,15 +370,26 @@ nsGfxRadioControlFrame::GetStateType(nsIPresContext* aPresContext, nsIStatefulFr
NS_IMETHODIMP NS_IMETHODIMP
nsGfxRadioControlFrame::SaveState(nsIPresContext* aPresContext, nsIPresState** aState) nsGfxRadioControlFrame::SaveState(nsIPresContext* aPresContext, nsIPresState** aState)
{ {
// Construct a pres state. NS_ENSURE_ARG_POINTER(aState);
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);
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 NS_IMETHODIMP
nsGfxRadioControlFrame::RestoreState(nsIPresContext* aPresContext, nsIPresState* aState) nsGfxRadioControlFrame::RestoreState(nsIPresContext* aPresContext, nsIPresState* aState)
{ {
NS_ENSURE_ARG_POINTER(aState);
if (!mDidInit) { if (!mDidInit) {
mPresContext = aPresContext; mPresContext = aPresContext;
InitializeControl(aPresContext); InitializeControl(aPresContext);
@ -394,9 +407,13 @@ nsGfxRadioControlFrame::RestoreState(nsIPresContext* aPresContext, nsIPresState*
} }
mIsRestored = PR_TRUE; mIsRestored = PR_TRUE;
nsAutoString string; nsAutoString stateString;
aState->GetStateProperty(NS_ConvertASCIItoUCS2("checked"), string); nsresult res = aState->GetStateProperty(NS_LITERAL_STRING("checked"), stateString);
SetProperty(aPresContext, nsHTMLAtoms::checked, string); NS_ENSURE_SUCCESS(res, res);
res = SetProperty(aPresContext, nsHTMLAtoms::checked, stateString);
NS_ENSURE_SUCCESS(res, res);
mRestoredChecked = mChecked; mRestoredChecked = mChecked;
return NS_OK; return NS_OK;

View File

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

View File

@ -679,23 +679,39 @@ nsFileControlFrame::GetStateType(nsIPresContext* aPresContext, nsIStatefulFrame:
NS_IMETHODIMP NS_IMETHODIMP
nsFileControlFrame::SaveState(nsIPresContext* aPresContext, nsIPresState** aState) nsFileControlFrame::SaveState(nsIPresContext* aPresContext, nsIPresState** aState)
{ {
// Construct a pres state. NS_ENSURE_ARG_POINTER(aState);
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);
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 NS_IMETHODIMP
nsFileControlFrame::RestoreState(nsIPresContext* aPresContext, nsIPresState* aState) nsFileControlFrame::RestoreState(nsIPresContext* aPresContext, nsIPresState* aState)
{ {
nsAutoString string; NS_ENSURE_ARG_POINTER(aState);
aState->GetStateProperty(NS_ConvertASCIItoUCS2("checked"), string);
SetProperty(aPresContext, nsHTMLAtoms::value, string);
return NS_OK;
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, NS_IMETHODIMP nsGfxCheckboxControlFrame::SaveState(nsIPresContext* aPresContext,
nsIPresState** aState) nsIPresState** aState)
{ {
// Construct a pres state. NS_ENSURE_ARG_POINTER(aState);
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);
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, NS_IMETHODIMP nsGfxCheckboxControlFrame::RestoreState(nsIPresContext* aPresContext,
nsIPresState* aState) nsIPresState* aState)
{ {
NS_ENSURE_ARG_POINTER(aState);
if (!mDidInit) { if (!mDidInit) {
mPresContext = aPresContext; mPresContext = aPresContext;
InitializeControl(aPresContext); InitializeControl(aPresContext);
mDidInit = PR_TRUE; mDidInit = PR_TRUE;
} }
nsAutoString string;
aState->GetStateProperty(NS_ConvertASCIItoUCS2("checked"), string); // Set the value to the stored state.
SetCheckboxControlFrameState(aPresContext, string); nsAutoString stateString;
nsresult res = aState->GetStateProperty(NS_LITERAL_STRING("checked"), stateString);
NS_ENSURE_SUCCESS(res, res);
SetCheckboxControlFrameState(aPresContext, stateString);
return NS_OK; return NS_OK;
} }

View File

@ -370,15 +370,26 @@ nsGfxRadioControlFrame::GetStateType(nsIPresContext* aPresContext, nsIStatefulFr
NS_IMETHODIMP NS_IMETHODIMP
nsGfxRadioControlFrame::SaveState(nsIPresContext* aPresContext, nsIPresState** aState) nsGfxRadioControlFrame::SaveState(nsIPresContext* aPresContext, nsIPresState** aState)
{ {
// Construct a pres state. NS_ENSURE_ARG_POINTER(aState);
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);
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 NS_IMETHODIMP
nsGfxRadioControlFrame::RestoreState(nsIPresContext* aPresContext, nsIPresState* aState) nsGfxRadioControlFrame::RestoreState(nsIPresContext* aPresContext, nsIPresState* aState)
{ {
NS_ENSURE_ARG_POINTER(aState);
if (!mDidInit) { if (!mDidInit) {
mPresContext = aPresContext; mPresContext = aPresContext;
InitializeControl(aPresContext); InitializeControl(aPresContext);
@ -394,9 +407,13 @@ nsGfxRadioControlFrame::RestoreState(nsIPresContext* aPresContext, nsIPresState*
} }
mIsRestored = PR_TRUE; mIsRestored = PR_TRUE;
nsAutoString string; nsAutoString stateString;
aState->GetStateProperty(NS_ConvertASCIItoUCS2("checked"), string); nsresult res = aState->GetStateProperty(NS_LITERAL_STRING("checked"), stateString);
SetProperty(aPresContext, nsHTMLAtoms::checked, string); NS_ENSURE_SUCCESS(res, res);
res = SetProperty(aPresContext, nsHTMLAtoms::checked, stateString);
NS_ENSURE_SUCCESS(res, res);
mRestoredChecked = mChecked; mRestoredChecked = mChecked;
return NS_OK; return NS_OK;

View File

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

View File

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