From 6588425814c31b4540409e108c1146fa3d44f9b6 Mon Sep 17 00:00:00 2001 From: Mounir Lamouri Date: Thu, 22 Jul 2010 17:10:27 +0200 Subject: [PATCH] Bug 572896 - Split nsHTMLInputElement::Reset() to prevent calling it to set the default value to the current value; r=Olli.Pettay approval2.0=benjamin --- .../html/content/src/nsHTMLInputElement.cpp | 44 +++++++++++++------ content/html/content/src/nsHTMLInputElement.h | 5 +++ 2 files changed, 35 insertions(+), 14 deletions(-) diff --git a/content/html/content/src/nsHTMLInputElement.cpp b/content/html/content/src/nsHTMLInputElement.cpp index cb8efe55dcd3..e39208927ae3 100644 --- a/content/html/content/src/nsHTMLInputElement.cpp +++ b/content/html/content/src/nsHTMLInputElement.cpp @@ -411,11 +411,9 @@ nsHTMLInputElement::AfterSetAttr(PRInt32 aNameSpaceID, nsIAtom* aName, // If @value is changed and BF_VALUE_CHANGED is false, @value is the value // of the element so we call |Reset| which is getting the default value and // sets it to the current value. - // - // TODO: |Reset| should not be used as it's not really meant for that. if (aName == nsGkAtoms::value && !GET_BOOLBIT(mBitField, BF_VALUE_CHANGED)) { - Reset(); + SetDefaultValueAsValue(); } // @@ -2372,20 +2370,16 @@ FireEventForAccessibility(nsIDOMHTMLInputElement* aTarget, } #endif -NS_IMETHODIMP -nsHTMLInputElement::Reset() +nsresult +nsHTMLInputElement::SetDefaultValueAsValue() { - nsresult rv = NS_OK; - switch (mType) { case NS_FORM_INPUT_CHECKBOX: case NS_FORM_INPUT_RADIO: { PRBool resetVal; GetDefaultChecked(&resetVal); - rv = DoSetChecked(resetVal); - SetCheckedChanged(PR_FALSE); - break; + return DoSetChecked(resetVal); } case NS_FORM_INPUT_SEARCH: case NS_FORM_INPUT_PASSWORD: @@ -2395,9 +2389,7 @@ nsHTMLInputElement::Reset() nsAutoString resetVal; GetDefaultValue(resetVal); // SetValueInternal is going to sanitize the value. - rv = SetValueInternal(resetVal, PR_FALSE); - SetValueChanged(PR_FALSE); - break; + return SetValueInternal(resetVal, PR_FALSE); } case NS_FORM_INPUT_FILE: { @@ -2411,7 +2403,31 @@ nsHTMLInputElement::Reset() break; } - return rv; + return NS_OK; +} + +NS_IMETHODIMP +nsHTMLInputElement::Reset() +{ + nsresult rv = SetDefaultValueAsValue(); + NS_ENSURE_SUCCESS(rv, rv); + + switch (mType) { + case NS_FORM_INPUT_CHECKBOX: + case NS_FORM_INPUT_RADIO: + SetCheckedChanged(PR_FALSE); + break; + case NS_FORM_INPUT_SEARCH: + case NS_FORM_INPUT_PASSWORD: + case NS_FORM_INPUT_TEXT: + case NS_FORM_INPUT_TEL: + SetValueChanged(PR_FALSE); + break; + default: + break; + } + + return NS_OK; } NS_IMETHODIMP diff --git a/content/html/content/src/nsHTMLInputElement.h b/content/html/content/src/nsHTMLInputElement.h index e5626573e818..e1ca30f3fe54 100644 --- a/content/html/content/src/nsHTMLInputElement.h +++ b/content/html/content/src/nsHTMLInputElement.h @@ -336,6 +336,11 @@ protected: */ void SanitizeValue(nsAString& aValue); + /** + * Set the current default value to the value of the input element. + */ + nsresult SetDefaultValueAsValue(); + nsCOMPtr mControllers; /**