diff --git a/mozilla/layout/forms/nsFileControlFrame.cpp b/mozilla/layout/forms/nsFileControlFrame.cpp index d5b0e36bf78..03744aeeb80 100644 --- a/mozilla/layout/forms/nsFileControlFrame.cpp +++ b/mozilla/layout/forms/nsFileControlFrame.cpp @@ -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 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; } diff --git a/mozilla/layout/forms/nsGfxCheckboxControlFrame.cpp b/mozilla/layout/forms/nsGfxCheckboxControlFrame.cpp index d641ca7ca9b..72e8b4912cf 100644 --- a/mozilla/layout/forms/nsGfxCheckboxControlFrame.cpp +++ b/mozilla/layout/forms/nsGfxCheckboxControlFrame.cpp @@ -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; } diff --git a/mozilla/layout/forms/nsGfxRadioControlFrame.cpp b/mozilla/layout/forms/nsGfxRadioControlFrame.cpp index 8598a7a480e..5a7b3aae639 100644 --- a/mozilla/layout/forms/nsGfxRadioControlFrame.cpp +++ b/mozilla/layout/forms/nsGfxRadioControlFrame.cpp @@ -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; diff --git a/mozilla/layout/forms/nsIsIndexFrame.cpp b/mozilla/layout/forms/nsIsIndexFrame.cpp index 121216f810d..d2c76dd1c95 100644 --- a/mozilla/layout/forms/nsIsIndexFrame.cpp +++ b/mozilla/layout/forms/nsIsIndexFrame.cpp @@ -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); } diff --git a/mozilla/layout/forms/nsListControlFrame.cpp b/mozilla/layout/forms/nsListControlFrame.cpp index 91048c67e99..facc23942f3 100644 --- a/mozilla/layout/forms/nsListControlFrame.cpp +++ b/mozilla/layout/forms/nsListControlFrame.cpp @@ -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 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 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 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 content = dont_AddRef(GetOptionContent(i)); + nsCOMPtr 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 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 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 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 diff --git a/mozilla/layout/html/forms/src/nsFileControlFrame.cpp b/mozilla/layout/html/forms/src/nsFileControlFrame.cpp index d5b0e36bf78..03744aeeb80 100644 --- a/mozilla/layout/html/forms/src/nsFileControlFrame.cpp +++ b/mozilla/layout/html/forms/src/nsFileControlFrame.cpp @@ -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 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; } diff --git a/mozilla/layout/html/forms/src/nsGfxCheckboxControlFrame.cpp b/mozilla/layout/html/forms/src/nsGfxCheckboxControlFrame.cpp index d641ca7ca9b..72e8b4912cf 100644 --- a/mozilla/layout/html/forms/src/nsGfxCheckboxControlFrame.cpp +++ b/mozilla/layout/html/forms/src/nsGfxCheckboxControlFrame.cpp @@ -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; } diff --git a/mozilla/layout/html/forms/src/nsGfxRadioControlFrame.cpp b/mozilla/layout/html/forms/src/nsGfxRadioControlFrame.cpp index 8598a7a480e..5a7b3aae639 100644 --- a/mozilla/layout/html/forms/src/nsGfxRadioControlFrame.cpp +++ b/mozilla/layout/html/forms/src/nsGfxRadioControlFrame.cpp @@ -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; diff --git a/mozilla/layout/html/forms/src/nsGfxTextControlFrame2.cpp b/mozilla/layout/html/forms/src/nsGfxTextControlFrame2.cpp index 43b392e6e5b..0f24eac5fba 100644 --- a/mozilla/layout/html/forms/src/nsGfxTextControlFrame2.cpp +++ b/mozilla/layout/html/forms/src/nsGfxTextControlFrame2.cpp @@ -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 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 diff --git a/mozilla/layout/html/forms/src/nsIsIndexFrame.cpp b/mozilla/layout/html/forms/src/nsIsIndexFrame.cpp index 121216f810d..d2c76dd1c95 100644 --- a/mozilla/layout/html/forms/src/nsIsIndexFrame.cpp +++ b/mozilla/layout/html/forms/src/nsIsIndexFrame.cpp @@ -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); } diff --git a/mozilla/layout/html/forms/src/nsListControlFrame.cpp b/mozilla/layout/html/forms/src/nsListControlFrame.cpp index 91048c67e99..facc23942f3 100644 --- a/mozilla/layout/html/forms/src/nsListControlFrame.cpp +++ b/mozilla/layout/html/forms/src/nsListControlFrame.cpp @@ -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 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 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 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 content = dont_AddRef(GetOptionContent(i)); + nsCOMPtr 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 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 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 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