From ee57d4145307c123fb73e9aed7e8a0abb5545863 Mon Sep 17 00:00:00 2001 From: "jst%netscape.com" Date: Tue, 28 Nov 2000 03:41:50 +0000 Subject: [PATCH] Fixing bug 49597. Setting the 'checked' state on a dynamically created radio button that wasn't yet part of the document in JS was throwing an exception since our internal pres state code was generating a failure code when the input element didn't have a document. sr=vidur, r=pollmann git-svn-id: svn://10.0.0.236/trunk@82959 18797224-902f-48f8-a5cc-f745e15eee43 --- .../html/content/src/nsHTMLInputElement.cpp | 22 ++++++++----------- .../html/content/src/nsHTMLInputElement.cpp | 22 ++++++++----------- 2 files changed, 18 insertions(+), 26 deletions(-) diff --git a/mozilla/content/html/content/src/nsHTMLInputElement.cpp b/mozilla/content/html/content/src/nsHTMLInputElement.cpp index 40fe45d5e5c..29d8b3809c5 100644 --- a/mozilla/content/html/content/src/nsHTMLInputElement.cpp +++ b/mozilla/content/html/content/src/nsHTMLInputElement.cpp @@ -181,12 +181,11 @@ public: NS_IMETHOD GetType(PRInt32* aType); NS_IMETHOD Init() { return NS_OK; } - // Helper method - NS_IMETHOD SetPresStateChecked(nsIHTMLContent * aHTMLContent, - nsIStatefulFrame::StateType aStateType, - PRBool aValue); - protected: + // Helper method + void SetPresStateChecked(nsIHTMLContent * aHTMLContent, + nsIStatefulFrame::StateType aStateType, + PRBool aValue); nsresult GetSelectionRange(PRInt32* aSelectionStart, PRInt32* aSelectionEnd); @@ -498,21 +497,20 @@ nsHTMLInputElement::GetChecked(PRBool* aValue) return NS_OK; } -NS_IMETHODIMP +void nsHTMLInputElement::SetPresStateChecked(nsIHTMLContent * aHTMLContent, nsIStatefulFrame::StateType aStateType, PRBool aValue) { nsCOMPtr presState; - nsGenericHTMLElement::GetPrimaryPresState(aHTMLContent, aStateType, getter_AddRefs(presState)); + nsGenericHTMLElement::GetPrimaryPresState(aHTMLContent, aStateType, + getter_AddRefs(presState)); // Obtain the value property from the presentation state. if (presState) { nsAutoString value; value.AssignWithConversion( aValue ? "1" : "0" ); presState->SetStateProperty(NS_ConvertASCIItoUCS2("checked"), value); - return NS_OK; } - return NS_ERROR_FAILURE; } NS_IMETHODIMP @@ -543,9 +541,7 @@ nsHTMLInputElement::SetChecked(PRBool aValue) GetType(&type); nsIStatefulFrame::StateType stateType = (type == NS_FORM_INPUT_CHECKBOX?nsIStatefulFrame::eCheckboxType: nsIStatefulFrame::eRadioType); - if (NS_FAILED(SetPresStateChecked(this, stateType, aValue))) { - return NS_ERROR_FAILURE; - } + SetPresStateChecked(this, stateType, aValue); if (stateType == nsIStatefulFrame::eRadioType) { nsIDOMHTMLInputElement * radioElement = (nsIDOMHTMLInputElement*)this; @@ -553,7 +549,7 @@ nsHTMLInputElement::SetChecked(PRBool aValue) GetName(name); nsCOMPtr formElement; - if (NS_SUCCEEDED(GetForm(getter_AddRefs(formElement)))) { + if (NS_SUCCEEDED(GetForm(getter_AddRefs(formElement))) && formElement) { nsCOMPtr controls; nsresult rv = formElement->GetElements(getter_AddRefs(controls)); if (controls) { diff --git a/mozilla/layout/html/content/src/nsHTMLInputElement.cpp b/mozilla/layout/html/content/src/nsHTMLInputElement.cpp index 40fe45d5e5c..29d8b3809c5 100644 --- a/mozilla/layout/html/content/src/nsHTMLInputElement.cpp +++ b/mozilla/layout/html/content/src/nsHTMLInputElement.cpp @@ -181,12 +181,11 @@ public: NS_IMETHOD GetType(PRInt32* aType); NS_IMETHOD Init() { return NS_OK; } - // Helper method - NS_IMETHOD SetPresStateChecked(nsIHTMLContent * aHTMLContent, - nsIStatefulFrame::StateType aStateType, - PRBool aValue); - protected: + // Helper method + void SetPresStateChecked(nsIHTMLContent * aHTMLContent, + nsIStatefulFrame::StateType aStateType, + PRBool aValue); nsresult GetSelectionRange(PRInt32* aSelectionStart, PRInt32* aSelectionEnd); @@ -498,21 +497,20 @@ nsHTMLInputElement::GetChecked(PRBool* aValue) return NS_OK; } -NS_IMETHODIMP +void nsHTMLInputElement::SetPresStateChecked(nsIHTMLContent * aHTMLContent, nsIStatefulFrame::StateType aStateType, PRBool aValue) { nsCOMPtr presState; - nsGenericHTMLElement::GetPrimaryPresState(aHTMLContent, aStateType, getter_AddRefs(presState)); + nsGenericHTMLElement::GetPrimaryPresState(aHTMLContent, aStateType, + getter_AddRefs(presState)); // Obtain the value property from the presentation state. if (presState) { nsAutoString value; value.AssignWithConversion( aValue ? "1" : "0" ); presState->SetStateProperty(NS_ConvertASCIItoUCS2("checked"), value); - return NS_OK; } - return NS_ERROR_FAILURE; } NS_IMETHODIMP @@ -543,9 +541,7 @@ nsHTMLInputElement::SetChecked(PRBool aValue) GetType(&type); nsIStatefulFrame::StateType stateType = (type == NS_FORM_INPUT_CHECKBOX?nsIStatefulFrame::eCheckboxType: nsIStatefulFrame::eRadioType); - if (NS_FAILED(SetPresStateChecked(this, stateType, aValue))) { - return NS_ERROR_FAILURE; - } + SetPresStateChecked(this, stateType, aValue); if (stateType == nsIStatefulFrame::eRadioType) { nsIDOMHTMLInputElement * radioElement = (nsIDOMHTMLInputElement*)this; @@ -553,7 +549,7 @@ nsHTMLInputElement::SetChecked(PRBool aValue) GetName(name); nsCOMPtr formElement; - if (NS_SUCCEEDED(GetForm(getter_AddRefs(formElement)))) { + if (NS_SUCCEEDED(GetForm(getter_AddRefs(formElement))) && formElement) { nsCOMPtr controls; nsresult rv = formElement->GetElements(getter_AddRefs(controls)); if (controls) {