diff --git a/mozilla/content/html/content/public/nsIFormControl.h b/mozilla/content/html/content/public/nsIFormControl.h index 4cea6ec1e44..6a532d1a75c 100644 --- a/mozilla/content/html/content/public/nsIFormControl.h +++ b/mozilla/content/html/content/public/nsIFormControl.h @@ -70,9 +70,6 @@ class nsIFormSubmission; #define NS_FORM_TEXTAREA 20 #define NS_FORM_OBJECT 21 -#define NS_FORM_NOTOK 0xFFFFFFF7 -#define NS_FORM_NOTSET 0xFFFFFFF7 - #define NS_IFORMCONTROL_IID \ { 0x282ff440, 0xcd7e, 0x11d1, \ {0x89, 0xad, 0x00, 0x60, 0x08, 0x91, 0x1b, 0x81} } diff --git a/mozilla/content/html/content/src/nsGenericHTMLElement.cpp b/mozilla/content/html/content/src/nsGenericHTMLElement.cpp index 3198744469c..fe851258c97 100644 --- a/mozilla/content/html/content/src/nsGenericHTMLElement.cpp +++ b/mozilla/content/html/content/src/nsGenericHTMLElement.cpp @@ -4225,7 +4225,8 @@ nsGenericHTMLContainerFormElement::nsGenericHTMLContainerFormElement() nsGenericHTMLContainerFormElement::~nsGenericHTMLContainerFormElement() { - // Do nothing + // Clean up. Set the form to nsnull so it knows we went away. + SetForm(nsnull); } NS_IMETHODIMP @@ -4471,7 +4472,8 @@ nsGenericHTMLLeafFormElement::nsGenericHTMLLeafFormElement() nsGenericHTMLLeafFormElement::~nsGenericHTMLLeafFormElement() { - // Do nothing + // Clean up. Set the form to nsnull so it knows we went away. + SetForm(nsnull); } diff --git a/mozilla/content/html/content/src/nsHTMLButtonElement.cpp b/mozilla/content/html/content/src/nsHTMLButtonElement.cpp index 78ff9563e10..b3c9a3ac5d2 100644 --- a/mozilla/content/html/content/src/nsHTMLButtonElement.cpp +++ b/mozilla/content/html/content/src/nsHTMLButtonElement.cpp @@ -163,8 +163,6 @@ nsHTMLButtonElement::nsHTMLButtonElement() nsHTMLButtonElement::~nsHTMLButtonElement() { - // Null out form's pointer to us - no ref counting here! - SetForm(nsnull); } // nsISupports @@ -249,7 +247,7 @@ nsHTMLButtonElement::CloneNode(PRBool aDeep, nsIDOMNode** aReturn) } -// nsIContent +// nsIDOMHTMLButtonElement NS_IMETHODIMP nsHTMLButtonElement::GetForm(nsIDOMHTMLFormElement** aForm) @@ -594,12 +592,9 @@ nsHTMLButtonElement::HandleDOMEvent(nsIPresContext* aPresContext, NS_IMETHODIMP nsHTMLButtonElement::GetType(PRInt32* aType) { - if (aType) { - *aType = mType; - return NS_OK; - } else { - return NS_FORM_NOTOK; - } + NS_ASSERTION(aType, "Null pointer bad!"); + *aType = mType; + return NS_OK; } #ifdef DEBUG diff --git a/mozilla/content/html/content/src/nsHTMLFieldSetElement.cpp b/mozilla/content/html/content/src/nsHTMLFieldSetElement.cpp index 454e6ff7ac3..000f15c3ea8 100644 --- a/mozilla/content/html/content/src/nsHTMLFieldSetElement.cpp +++ b/mozilla/content/html/content/src/nsHTMLFieldSetElement.cpp @@ -69,7 +69,7 @@ public: NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLContainerFormElement::) // nsIDOMHTMLFieldSetElement - NS_IMETHOD GetForm(nsIDOMHTMLFormElement** aForm); + NS_DECL_NSIDOMHTMLFIELDSETELEMENT // nsIFormControl NS_IMETHOD GetType(PRInt32* aType); @@ -118,8 +118,6 @@ nsHTMLFieldSetElement::nsHTMLFieldSetElement() nsHTMLFieldSetElement::~nsHTMLFieldSetElement() { - // Null out form's pointer to us - no ref counting here! - SetForm(nsnull); } // nsISupports @@ -166,8 +164,7 @@ nsHTMLFieldSetElement::CloneNode(PRBool aDeep, nsIDOMNode** aReturn) return NS_OK; } - -// nsIContent +// nsIDOMHTMLFieldSetElement NS_IMETHODIMP nsHTMLFieldSetElement::GetForm(nsIDOMHTMLFormElement** aForm) @@ -180,14 +177,13 @@ nsHTMLFieldSetElement::GetForm(nsIDOMHTMLFormElement** aForm) NS_IMETHODIMP nsHTMLFieldSetElement::GetType(PRInt32* aType) { - if (aType) { - *aType = NS_FORM_FIELDSET; - return NS_OK; - } else { - return NS_FORM_NOTOK; - } + NS_ASSERTION(aType, "Null pointer bad"); + *aType = NS_FORM_FIELDSET; + return NS_OK; } + + #ifdef DEBUG NS_IMETHODIMP nsHTMLFieldSetElement::SizeOf(nsISizeOfHandler* aSizer, diff --git a/mozilla/content/html/content/src/nsHTMLInputElement.cpp b/mozilla/content/html/content/src/nsHTMLInputElement.cpp index 082c625990b..0610e8389f3 100644 --- a/mozilla/content/html/content/src/nsHTMLInputElement.cpp +++ b/mozilla/content/html/content/src/nsHTMLInputElement.cpp @@ -158,8 +158,6 @@ public: NS_DECL_NSIDOMNSHTMLINPUTELEMENT // Overriden nsIFormControl methods - NS_IMETHOD SetForm(nsIDOMHTMLFormElement* aForm, - PRBool aRemoveFromForm = PR_TRUE); NS_IMETHOD GetType(PRInt32* aType); NS_IMETHOD Reset(); NS_IMETHOD SubmitNamesValues(nsIFormSubmission* aFormSubmission, @@ -389,9 +387,6 @@ nsHTMLInputElement::nsHTMLInputElement(PRBool aFromParser) nsHTMLInputElement::~nsHTMLInputElement() { - // Null out form's pointer to us - no ref counting here! - SetForm(nsnull); - if (mValue) { nsMemory::Free(mValue); } @@ -514,6 +509,8 @@ nsHTMLInputElement::AfterSetAttr(PRInt32 aNameSpaceID, nsIAtom* aName, } } +// nsIDOMHTMLInputElement + NS_IMETHODIMP nsHTMLInputElement::GetForm(nsIDOMHTMLFormElement** aForm) { @@ -910,14 +907,6 @@ nsHTMLInputElement::GetRadioGroupContainer() return retval; } -NS_IMETHODIMP -nsHTMLInputElement::SetForm(nsIDOMHTMLFormElement* aForm, - PRBool aRemoveFromForm) -{ - return nsGenericHTMLLeafFormElement::SetForm(aForm, aRemoveFromForm); -} - - nsresult nsHTMLInputElement::SetCheckedInternal(PRBool aChecked) { diff --git a/mozilla/content/html/content/src/nsHTMLLabelElement.cpp b/mozilla/content/html/content/src/nsHTMLLabelElement.cpp index b40ddb3c29d..0f1729a40d6 100644 --- a/mozilla/content/html/content/src/nsHTMLLabelElement.cpp +++ b/mozilla/content/html/content/src/nsHTMLLabelElement.cpp @@ -234,8 +234,6 @@ nsHTMLLabelElement::nsHTMLLabelElement() nsHTMLLabelElement::~nsHTMLLabelElement() { - // Null out form's pointer to us - no ref counting here! - SetForm(nsnull); } // nsISupports diff --git a/mozilla/content/html/content/src/nsHTMLLegendElement.cpp b/mozilla/content/html/content/src/nsHTMLLegendElement.cpp index 3b9512b7ffc..455b3e0b863 100644 --- a/mozilla/content/html/content/src/nsHTMLLegendElement.cpp +++ b/mozilla/content/html/content/src/nsHTMLLegendElement.cpp @@ -122,8 +122,6 @@ nsHTMLLegendElement::nsHTMLLegendElement() nsHTMLLegendElement::~nsHTMLLegendElement() { - // Null out form's pointer to us - no ref counting here! - SetForm(nsnull); } @@ -139,6 +137,7 @@ NS_HTML_CONTENT_INTERFACE_MAP_BEGIN(nsHTMLLegendElement, NS_HTML_CONTENT_INTERFACE_MAP_END +// nsIDOMHTMLLegendElement nsresult nsHTMLLegendElement::CloneNode(PRBool aDeep, nsIDOMNode** aReturn) { @@ -167,25 +166,20 @@ nsHTMLLegendElement::CloneNode(PRBool aDeep, nsIDOMNode** aReturn) return NS_OK; } - NS_IMETHODIMP nsHTMLLegendElement::GetForm(nsIDOMHTMLFormElement** aForm) { return nsGenericHTMLContainerFormElement::GetForm(aForm); } - // nsIFormControl NS_IMETHODIMP nsHTMLLegendElement::GetType(PRInt32* aType) { - if (aType) { - *aType = NS_FORM_LEGEND; - return NS_OK; - } else { - return NS_FORM_NOTOK; - } + NS_ASSERTION(aType, "Null pointer bad!"); + *aType = NS_FORM_LEGEND; + return NS_OK; } diff --git a/mozilla/content/html/content/src/nsHTMLObjectElement.cpp b/mozilla/content/html/content/src/nsHTMLObjectElement.cpp index 5133c9ebdd4..dcf289b138e 100644 --- a/mozilla/content/html/content/src/nsHTMLObjectElement.cpp +++ b/mozilla/content/html/content/src/nsHTMLObjectElement.cpp @@ -70,8 +70,6 @@ public: NS_DECL_NSIDOMHTMLOBJECTELEMENT // Overriden nsIFormControl methods - NS_IMETHOD SetForm(nsIDOMHTMLFormElement* aForm, - PRBool aRemoveFromForm = PR_TRUE); NS_IMETHOD GetType(PRInt32* aType); NS_IMETHOD Reset(); NS_IMETHOD SubmitNamesValues(nsIFormSubmission* aFormSubmission, @@ -126,8 +124,6 @@ nsHTMLObjectElement::nsHTMLObjectElement() nsHTMLObjectElement::~nsHTMLObjectElement() { - // Null out form's pointer to us - no ref counting here! - SetForm(nsnull); } @@ -141,6 +137,7 @@ NS_HTML_CONTENT_INTERFACE_MAP_BEGIN(nsHTMLObjectElement, NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(HTMLObjectElement) NS_HTML_CONTENT_INTERFACE_MAP_END +// nsIDOMHTMLObjectElement nsresult nsHTMLObjectElement::CloneNode(PRBool aDeep, nsIDOMNode** aReturn) { @@ -175,12 +172,7 @@ nsHTMLObjectElement::GetForm(nsIDOMHTMLFormElement** aForm) return nsGenericHTMLContainerFormElement::GetForm(aForm); } -NS_IMETHODIMP -nsHTMLObjectElement::SetForm(nsIDOMHTMLFormElement* aForm, - PRBool aRemoveFromForm) -{ - return nsGenericHTMLContainerFormElement::SetForm(aForm, aRemoveFromForm); -} +// nsIFormControl NS_IMETHODIMP nsHTMLObjectElement::GetType(PRInt32* aType) diff --git a/mozilla/content/html/content/src/nsHTMLSelectElement.cpp b/mozilla/content/html/content/src/nsHTMLSelectElement.cpp index 9b1f8789ef1..b81e5d23734 100644 --- a/mozilla/content/html/content/src/nsHTMLSelectElement.cpp +++ b/mozilla/content/html/content/src/nsHTMLSelectElement.cpp @@ -433,8 +433,6 @@ nsHTMLSelectElement::nsHTMLSelectElement(PRBool aFromParser) nsHTMLSelectElement::~nsHTMLSelectElement() { - // Null out form's pointer to us - no ref counting here! - SetForm(nsnull); if (mOptions) { mOptions->DropReference(); NS_RELEASE(mOptions); @@ -1896,12 +1894,9 @@ nsHTMLSelectElement::HandleDOMEvent(nsIPresContext* aPresContext, NS_IMETHODIMP nsHTMLSelectElement::GetType(PRInt32* aType) { - if (aType) { - *aType = NS_FORM_SELECT; - return NS_OK; - } - - return NS_FORM_NOTOK; + NS_ASSERTION(aType, "Null pointer bad!"); + *aType = NS_FORM_SELECT; + return NS_OK; } NS_IMETHODIMP diff --git a/mozilla/content/html/content/src/nsHTMLSharedObjectElement.cpp b/mozilla/content/html/content/src/nsHTMLSharedObjectElement.cpp index 5133c9ebdd4..dcf289b138e 100644 --- a/mozilla/content/html/content/src/nsHTMLSharedObjectElement.cpp +++ b/mozilla/content/html/content/src/nsHTMLSharedObjectElement.cpp @@ -70,8 +70,6 @@ public: NS_DECL_NSIDOMHTMLOBJECTELEMENT // Overriden nsIFormControl methods - NS_IMETHOD SetForm(nsIDOMHTMLFormElement* aForm, - PRBool aRemoveFromForm = PR_TRUE); NS_IMETHOD GetType(PRInt32* aType); NS_IMETHOD Reset(); NS_IMETHOD SubmitNamesValues(nsIFormSubmission* aFormSubmission, @@ -126,8 +124,6 @@ nsHTMLObjectElement::nsHTMLObjectElement() nsHTMLObjectElement::~nsHTMLObjectElement() { - // Null out form's pointer to us - no ref counting here! - SetForm(nsnull); } @@ -141,6 +137,7 @@ NS_HTML_CONTENT_INTERFACE_MAP_BEGIN(nsHTMLObjectElement, NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(HTMLObjectElement) NS_HTML_CONTENT_INTERFACE_MAP_END +// nsIDOMHTMLObjectElement nsresult nsHTMLObjectElement::CloneNode(PRBool aDeep, nsIDOMNode** aReturn) { @@ -175,12 +172,7 @@ nsHTMLObjectElement::GetForm(nsIDOMHTMLFormElement** aForm) return nsGenericHTMLContainerFormElement::GetForm(aForm); } -NS_IMETHODIMP -nsHTMLObjectElement::SetForm(nsIDOMHTMLFormElement* aForm, - PRBool aRemoveFromForm) -{ - return nsGenericHTMLContainerFormElement::SetForm(aForm, aRemoveFromForm); -} +// nsIFormControl NS_IMETHODIMP nsHTMLObjectElement::GetType(PRInt32* aType) diff --git a/mozilla/content/html/content/src/nsHTMLTextAreaElement.cpp b/mozilla/content/html/content/src/nsHTMLTextAreaElement.cpp index 9d69d3b04fc..0b7661f983e 100644 --- a/mozilla/content/html/content/src/nsHTMLTextAreaElement.cpp +++ b/mozilla/content/html/content/src/nsHTMLTextAreaElement.cpp @@ -200,8 +200,6 @@ nsHTMLTextAreaElement::nsHTMLTextAreaElement() nsHTMLTextAreaElement::~nsHTMLTextAreaElement() { - // Null out form's pointer to us - no ref counting here! - SetForm(nsnull); } @@ -768,12 +766,9 @@ nsHTMLTextAreaElement::DoneAddingChildren() NS_IMETHODIMP nsHTMLTextAreaElement::GetType(PRInt32* aType) { - if (aType) { - *aType = NS_FORM_TEXTAREA; - return NS_OK; - } else { - return NS_FORM_NOTOK; - } + NS_ASSERTION(aType, "Null pointer bad!"); + *aType = NS_FORM_TEXTAREA; + return NS_OK; } nsresult diff --git a/mozilla/layout/forms/nsComboboxControlFrame.cpp b/mozilla/layout/forms/nsComboboxControlFrame.cpp index 2ad0bed2a4d..6fe9e10f7ea 100644 --- a/mozilla/layout/forms/nsComboboxControlFrame.cpp +++ b/mozilla/layout/forms/nsComboboxControlFrame.cpp @@ -1744,20 +1744,7 @@ nsComboboxControlFrame::Reflow(nsIPresContext* aPresContext, NS_IMETHODIMP nsComboboxControlFrame::GetName(nsAString* aResult) { - nsresult result = NS_FORM_NOTOK; - - nsCOMPtr formControl(do_QueryInterface(mContent)); - - if (formControl) { - nsHTMLValue value; - result = formControl->GetHTMLAttribute(nsHTMLAtoms::name, value); - if (NS_CONTENT_ATTR_HAS_VALUE == result) { - if (eHTMLUnit_String == value.GetUnit()) { - value.GetStringValue(*aResult); - } - } - } - return result; + return nsFormControlHelper::GetName(mContent, aResult); } NS_IMETHODIMP diff --git a/mozilla/layout/forms/nsFileControlFrame.cpp b/mozilla/layout/forms/nsFileControlFrame.cpp index a98dcd7ade0..fdb12d44ca4 100644 --- a/mozilla/layout/forms/nsFileControlFrame.cpp +++ b/mozilla/layout/forms/nsFileControlFrame.cpp @@ -485,20 +485,7 @@ nsFileControlFrame::GetSkipSides() const NS_IMETHODIMP nsFileControlFrame::GetName(nsAString* aResult) { - nsresult result = NS_FORM_NOTOK; - - nsCOMPtr formControl(do_QueryInterface(mContent)); - - if (formControl) { - nsHTMLValue value; - result = formControl->GetHTMLAttribute(nsHTMLAtoms::name, value); - if (NS_CONTENT_ATTR_HAS_VALUE == result) { - if (eHTMLUnit_String == value.GetUnit()) { - value.GetStringValue(*aResult); - } - } - } - return result; + return nsFormControlHelper::GetName(mContent, aResult); } void diff --git a/mozilla/layout/forms/nsFormControlFrame.cpp b/mozilla/layout/forms/nsFormControlFrame.cpp index 41f233e1203..d74179c7ffe 100644 --- a/mozilla/layout/forms/nsFormControlFrame.cpp +++ b/mozilla/layout/forms/nsFormControlFrame.cpp @@ -711,55 +711,20 @@ nsFormControlFrame::GetSizeFromContent(PRInt32* aSize) const NS_IMETHODIMP nsFormControlFrame::GetType(PRInt32* aType) const { - nsresult result = NS_FORM_NOTOK; - if (mContent) { - nsIFormControl* formControl = nsnull; - result = mContent->QueryInterface(NS_GET_IID(nsIFormControl), (void**)&formControl); - if ((NS_OK == result) && formControl) { - result = formControl->GetType(aType); - NS_RELEASE(formControl); - } - } - return result; + return nsFormControlHelper::GetType(mContent, aType); } NS_IMETHODIMP nsFormControlFrame::GetName(nsAString* aResult) { - nsresult result = NS_FORM_NOTOK; - - nsCOMPtr formControl(do_QueryInterface(mContent)); - - if (formControl) { - nsHTMLValue value; - result = formControl->GetHTMLAttribute(nsHTMLAtoms::name, value); - if (NS_CONTENT_ATTR_HAS_VALUE == result) { - if (eHTMLUnit_String == value.GetUnit()) { - value.GetStringValue(*aResult); - } - } - } - return result; + return nsFormControlHelper::GetName(mContent, aResult); } NS_IMETHODIMP nsFormControlFrame::GetValue(nsAString* aResult) { - nsresult result = NS_FORM_NOTOK; - - nsCOMPtr formControl(do_QueryInterface(mContent)); - - if (formControl) { - nsHTMLValue value; - result = formControl->GetHTMLAttribute(nsHTMLAtoms::value, value); - if (NS_CONTENT_ATTR_HAS_VALUE == result) { - if (eHTMLUnit_String == value.GetUnit()) { - value.GetStringValue(*aResult); - } - } - } - return result; + return nsFormControlHelper::GetValueAttr(mContent, aResult); } diff --git a/mozilla/layout/forms/nsFormControlHelper.cpp b/mozilla/layout/forms/nsFormControlHelper.cpp index f27bb1c6887..85e7e1dc308 100644 --- a/mozilla/layout/forms/nsFormControlHelper.cpp +++ b/mozilla/layout/forms/nsFormControlHelper.cpp @@ -695,23 +695,45 @@ nsFormControlHelper::PaintCheckMark(nsIRenderingContext& aRenderingContext, nsresult nsFormControlHelper::GetName(nsIContent* aContent, nsAString* aResult) { - nsresult result = NS_FORM_NOTOK; - if (aContent) { - nsCOMPtr formControl(do_QueryInterface(aContent)); + NS_PRECONDITION(aResult, "Null pointer bad!"); + nsCOMPtr formControl(do_QueryInterface(aContent)); + if (!formControl) + return NS_ERROR_FAILURE; - if (formControl) { - nsHTMLValue value; - result = formControl->GetHTMLAttribute(nsHTMLAtoms::name, value); - if (NS_CONTENT_ATTR_HAS_VALUE == result) { - if (eHTMLUnit_String == value.GetUnit()) { - value.GetStringValue(*aResult); - } - } - } + nsHTMLValue value; + nsresult rv = formControl->GetHTMLAttribute(nsHTMLAtoms::name, value); + if (NS_CONTENT_ATTR_HAS_VALUE == rv && eHTMLUnit_String == value.GetUnit()) { + value.GetStringValue(*aResult); } - return result; + return rv; } +nsresult +nsFormControlHelper::GetType(nsIContent* aContent, PRInt32* aType) +{ + NS_PRECONDITION(aType, "Null pointer bad!"); + nsCOMPtr formControl(do_QueryInterface(aContent)); + if (!formControl) + return NS_ERROR_FAILURE; + + return formControl->GetType(aType); +} + +nsresult +nsFormControlHelper::GetValueAttr(nsIContent* aContent, nsAString* aResult) +{ + NS_PRECONDITION(aResult, "Null pointer bad!"); + nsCOMPtr formControl(do_QueryInterface(aContent)); + if (!formControl) + return NS_ERROR_FAILURE; + + nsHTMLValue value; + nsresult rv = formControl->GetHTMLAttribute(nsHTMLAtoms::value, value); + if (NS_CONTENT_ATTR_HAS_VALUE == rv && eHTMLUnit_String == value.GetUnit()) { + value.GetStringValue(*aResult); + } + return rv; +} //---------------------------------------------------------------------------------- // Return localised string for resource string (e.g. "Submit" -> "Submit Query") diff --git a/mozilla/layout/forms/nsFormControlHelper.h b/mozilla/layout/forms/nsFormControlHelper.h index 0034a95b940..cdfa2a97eb6 100644 --- a/mozilla/layout/forms/nsFormControlHelper.h +++ b/mozilla/layout/forms/nsFormControlHelper.h @@ -168,9 +168,27 @@ public: * @param aResult the returned name of the form control [OUT] * @return NS_CONTENT_ATTR_HAS_VALUE if things go well * @return NS_CONTENT_ATTR_NOT_THERE if the name attribute is undefined - * @return NS_FORM_NOTOK if aContent is null or is not HTML content + * @return NS_ERROR_FAILURE if aContent is null or is not HTML content */ static nsresult GetName(nsIContent* aContent, nsAString* aResult); + /** + * Get the type of the form control (if it's not obvious from the frame type) + * @param aContent the content to get the name of + * @param aType the returned type of the form control [OUT] + * @return NS_CONTENT_ATTR_HAS_VALUE if things go well + * @return NS_CONTENT_ATTR_NOT_THERE if the type attribute is undefined + * @return NS_ERROR_FAILURE if aContent is null or is not HTML content + */ + static nsresult GetType(nsIContent* aContent, PRInt32* aType); + /** + * Get the value of the form control (if it's just living in an attr) + * @param aContent the content to get the name of + * @param aResult the returned value of the form control [OUT] + * @return NS_CONTENT_ATTR_HAS_VALUE if things go well + * @return NS_CONTENT_ATTR_NOT_THERE if the value attribute is undefined + * @return NS_ERROR_FAILURE if aContent is null or is not HTML content + */ + static nsresult GetValueAttr(nsIContent* aContent, nsAString* aResult); /** * Cause the form control to reset its value * @param aFrame the frame who owns the form control diff --git a/mozilla/layout/forms/nsHTMLButtonControlFrame.cpp b/mozilla/layout/forms/nsHTMLButtonControlFrame.cpp index 2c34ccd406b..277138e2a2c 100644 --- a/mozilla/layout/forms/nsHTMLButtonControlFrame.cpp +++ b/mozilla/layout/forms/nsHTMLButtonControlFrame.cpp @@ -225,54 +225,19 @@ nsHTMLButtonControlFrame::GetDefaultLabel(nsString& aString) NS_IMETHODIMP nsHTMLButtonControlFrame::GetType(PRInt32* aType) const { - nsresult result = NS_FORM_NOTOK; - if (mContent) { - nsIFormControl* formControl = nsnull; - result = mContent->QueryInterface(NS_GET_IID(nsIFormControl), (void**)&formControl); - if ((NS_OK == result) && formControl) { - result = formControl->GetType(aType); - NS_RELEASE(formControl); - } - } - return result; + return nsFormControlHelper::GetType(mContent, aType); } NS_IMETHODIMP nsHTMLButtonControlFrame::GetName(nsAString* aResult) { - nsresult result = NS_FORM_NOTOK; - - nsCOMPtr formControl(do_QueryInterface(mContent)); - - if (formControl) { - nsHTMLValue value; - result = formControl->GetHTMLAttribute(nsHTMLAtoms::name, value); - if (NS_CONTENT_ATTR_HAS_VALUE == result) { - if (eHTMLUnit_String == value.GetUnit()) { - value.GetStringValue(*aResult); - } - } - } - return result; + return nsFormControlHelper::GetName(mContent, aResult); } NS_IMETHODIMP nsHTMLButtonControlFrame::GetValue(nsAString* aResult) { - nsresult result = NS_FORM_NOTOK; - - nsCOMPtr formControl(do_QueryInterface(mContent)); - - if (formControl) { - nsHTMLValue value; - result = formControl->GetHTMLAttribute(nsHTMLAtoms::value, value); - if (NS_CONTENT_ATTR_HAS_VALUE == result) { - if (eHTMLUnit_String == value.GetUnit()) { - value.GetStringValue(*aResult); - } - } - } - return result; + return nsFormControlHelper::GetValueAttr(mContent, aResult); } PRBool diff --git a/mozilla/layout/forms/nsImageControlFrame.cpp b/mozilla/layout/forms/nsImageControlFrame.cpp index f11c281bacb..465a061742d 100644 --- a/mozilla/layout/forms/nsImageControlFrame.cpp +++ b/mozilla/layout/forms/nsImageControlFrame.cpp @@ -401,11 +401,7 @@ nsImageControlFrame::GetType(PRInt32* aType) const NS_IMETHODIMP nsImageControlFrame::GetName(nsAString* aResult) { - if (nsnull == aResult) { - return NS_OK; - } else { - return nsFormControlHelper::GetName(mContent, aResult); - } + return nsFormControlHelper::GetName(mContent, aResult); } NS_IMETHODIMP diff --git a/mozilla/layout/forms/nsListControlFrame.cpp b/mozilla/layout/forms/nsListControlFrame.cpp index 7115642c0f7..dcaca1e1c8d 100644 --- a/mozilla/layout/forms/nsListControlFrame.cpp +++ b/mozilla/layout/forms/nsListControlFrame.cpp @@ -1972,22 +1972,7 @@ nsListControlFrame::ResetList(nsIPresContext* aPresContext, nsVoidArray * aInxLi NS_IMETHODIMP nsListControlFrame::GetName(nsAString* aResult) { - nsresult result = NS_FORM_NOTOK; - if (mContent) { - nsIHTMLContent* formControl = nsnull; - result = mContent->QueryInterface(NS_GET_IID(nsIHTMLContent),(void**)&formControl); - if (NS_SUCCEEDED(result) && formControl) { - nsHTMLValue value; - result = formControl->GetHTMLAttribute(nsHTMLAtoms::name, value); - if (NS_CONTENT_ATTR_HAS_VALUE == result) { - if (eHTMLUnit_String == value.GetUnit()) { - value.GetStringValue(*aResult); - } - } - NS_RELEASE(formControl); - } - } - return result; + return nsFormControlHelper::GetName(mContent, aResult); } diff --git a/mozilla/layout/forms/nsTextControlFrame.cpp b/mozilla/layout/forms/nsTextControlFrame.cpp index 25acff0a3f6..749a7962a86 100644 --- a/mozilla/layout/forms/nsTextControlFrame.cpp +++ b/mozilla/layout/forms/nsTextControlFrame.cpp @@ -2383,37 +2383,13 @@ nsTextControlFrame::GetAscent(nsBoxLayoutState& aState, nscoord& aAscent) NS_IMETHODIMP nsTextControlFrame::GetName(nsAString* aResult) { - nsresult rv = NS_FORM_NOTOK; - if (mContent) { - nsIHTMLContent* formControl = nsnull; - rv = mContent->QueryInterface(NS_GET_IID(nsIHTMLContent),(void**)&formControl); - if (NS_SUCCEEDED(rv) && formControl) { - nsHTMLValue value; - rv = formControl->GetHTMLAttribute(nsHTMLAtoms::name, value); - if (NS_CONTENT_ATTR_HAS_VALUE == rv) { - if (eHTMLUnit_String == value.GetUnit()) { - value.GetStringValue(*aResult); - } - } - NS_RELEASE(formControl); - } - } - return rv; + return nsFormControlHelper::GetName(mContent, aResult); } NS_IMETHODIMP nsTextControlFrame::GetType(PRInt32* aType) const { - nsresult rv = NS_FORM_NOTOK; - if (mContent) { - nsIFormControl* formControl = nsnull; - rv = mContent->QueryInterface(NS_GET_IID(nsIFormControl), (void**)&formControl); - if ((NS_OK == rv) && formControl) { - rv = formControl->GetType(aType); - NS_RELEASE(formControl); - } - } - return rv; + return nsFormControlHelper::GetType(mContent, aType); } nsresult diff --git a/mozilla/layout/html/forms/src/nsComboboxControlFrame.cpp b/mozilla/layout/html/forms/src/nsComboboxControlFrame.cpp index 2ad0bed2a4d..6fe9e10f7ea 100644 --- a/mozilla/layout/html/forms/src/nsComboboxControlFrame.cpp +++ b/mozilla/layout/html/forms/src/nsComboboxControlFrame.cpp @@ -1744,20 +1744,7 @@ nsComboboxControlFrame::Reflow(nsIPresContext* aPresContext, NS_IMETHODIMP nsComboboxControlFrame::GetName(nsAString* aResult) { - nsresult result = NS_FORM_NOTOK; - - nsCOMPtr formControl(do_QueryInterface(mContent)); - - if (formControl) { - nsHTMLValue value; - result = formControl->GetHTMLAttribute(nsHTMLAtoms::name, value); - if (NS_CONTENT_ATTR_HAS_VALUE == result) { - if (eHTMLUnit_String == value.GetUnit()) { - value.GetStringValue(*aResult); - } - } - } - return result; + return nsFormControlHelper::GetName(mContent, aResult); } NS_IMETHODIMP diff --git a/mozilla/layout/html/forms/src/nsFileControlFrame.cpp b/mozilla/layout/html/forms/src/nsFileControlFrame.cpp index a98dcd7ade0..fdb12d44ca4 100644 --- a/mozilla/layout/html/forms/src/nsFileControlFrame.cpp +++ b/mozilla/layout/html/forms/src/nsFileControlFrame.cpp @@ -485,20 +485,7 @@ nsFileControlFrame::GetSkipSides() const NS_IMETHODIMP nsFileControlFrame::GetName(nsAString* aResult) { - nsresult result = NS_FORM_NOTOK; - - nsCOMPtr formControl(do_QueryInterface(mContent)); - - if (formControl) { - nsHTMLValue value; - result = formControl->GetHTMLAttribute(nsHTMLAtoms::name, value); - if (NS_CONTENT_ATTR_HAS_VALUE == result) { - if (eHTMLUnit_String == value.GetUnit()) { - value.GetStringValue(*aResult); - } - } - } - return result; + return nsFormControlHelper::GetName(mContent, aResult); } void diff --git a/mozilla/layout/html/forms/src/nsFormControlFrame.cpp b/mozilla/layout/html/forms/src/nsFormControlFrame.cpp index 41f233e1203..d74179c7ffe 100644 --- a/mozilla/layout/html/forms/src/nsFormControlFrame.cpp +++ b/mozilla/layout/html/forms/src/nsFormControlFrame.cpp @@ -711,55 +711,20 @@ nsFormControlFrame::GetSizeFromContent(PRInt32* aSize) const NS_IMETHODIMP nsFormControlFrame::GetType(PRInt32* aType) const { - nsresult result = NS_FORM_NOTOK; - if (mContent) { - nsIFormControl* formControl = nsnull; - result = mContent->QueryInterface(NS_GET_IID(nsIFormControl), (void**)&formControl); - if ((NS_OK == result) && formControl) { - result = formControl->GetType(aType); - NS_RELEASE(formControl); - } - } - return result; + return nsFormControlHelper::GetType(mContent, aType); } NS_IMETHODIMP nsFormControlFrame::GetName(nsAString* aResult) { - nsresult result = NS_FORM_NOTOK; - - nsCOMPtr formControl(do_QueryInterface(mContent)); - - if (formControl) { - nsHTMLValue value; - result = formControl->GetHTMLAttribute(nsHTMLAtoms::name, value); - if (NS_CONTENT_ATTR_HAS_VALUE == result) { - if (eHTMLUnit_String == value.GetUnit()) { - value.GetStringValue(*aResult); - } - } - } - return result; + return nsFormControlHelper::GetName(mContent, aResult); } NS_IMETHODIMP nsFormControlFrame::GetValue(nsAString* aResult) { - nsresult result = NS_FORM_NOTOK; - - nsCOMPtr formControl(do_QueryInterface(mContent)); - - if (formControl) { - nsHTMLValue value; - result = formControl->GetHTMLAttribute(nsHTMLAtoms::value, value); - if (NS_CONTENT_ATTR_HAS_VALUE == result) { - if (eHTMLUnit_String == value.GetUnit()) { - value.GetStringValue(*aResult); - } - } - } - return result; + return nsFormControlHelper::GetValueAttr(mContent, aResult); } diff --git a/mozilla/layout/html/forms/src/nsFormControlHelper.cpp b/mozilla/layout/html/forms/src/nsFormControlHelper.cpp index f27bb1c6887..85e7e1dc308 100644 --- a/mozilla/layout/html/forms/src/nsFormControlHelper.cpp +++ b/mozilla/layout/html/forms/src/nsFormControlHelper.cpp @@ -695,23 +695,45 @@ nsFormControlHelper::PaintCheckMark(nsIRenderingContext& aRenderingContext, nsresult nsFormControlHelper::GetName(nsIContent* aContent, nsAString* aResult) { - nsresult result = NS_FORM_NOTOK; - if (aContent) { - nsCOMPtr formControl(do_QueryInterface(aContent)); + NS_PRECONDITION(aResult, "Null pointer bad!"); + nsCOMPtr formControl(do_QueryInterface(aContent)); + if (!formControl) + return NS_ERROR_FAILURE; - if (formControl) { - nsHTMLValue value; - result = formControl->GetHTMLAttribute(nsHTMLAtoms::name, value); - if (NS_CONTENT_ATTR_HAS_VALUE == result) { - if (eHTMLUnit_String == value.GetUnit()) { - value.GetStringValue(*aResult); - } - } - } + nsHTMLValue value; + nsresult rv = formControl->GetHTMLAttribute(nsHTMLAtoms::name, value); + if (NS_CONTENT_ATTR_HAS_VALUE == rv && eHTMLUnit_String == value.GetUnit()) { + value.GetStringValue(*aResult); } - return result; + return rv; } +nsresult +nsFormControlHelper::GetType(nsIContent* aContent, PRInt32* aType) +{ + NS_PRECONDITION(aType, "Null pointer bad!"); + nsCOMPtr formControl(do_QueryInterface(aContent)); + if (!formControl) + return NS_ERROR_FAILURE; + + return formControl->GetType(aType); +} + +nsresult +nsFormControlHelper::GetValueAttr(nsIContent* aContent, nsAString* aResult) +{ + NS_PRECONDITION(aResult, "Null pointer bad!"); + nsCOMPtr formControl(do_QueryInterface(aContent)); + if (!formControl) + return NS_ERROR_FAILURE; + + nsHTMLValue value; + nsresult rv = formControl->GetHTMLAttribute(nsHTMLAtoms::value, value); + if (NS_CONTENT_ATTR_HAS_VALUE == rv && eHTMLUnit_String == value.GetUnit()) { + value.GetStringValue(*aResult); + } + return rv; +} //---------------------------------------------------------------------------------- // Return localised string for resource string (e.g. "Submit" -> "Submit Query") diff --git a/mozilla/layout/html/forms/src/nsFormControlHelper.h b/mozilla/layout/html/forms/src/nsFormControlHelper.h index 0034a95b940..cdfa2a97eb6 100644 --- a/mozilla/layout/html/forms/src/nsFormControlHelper.h +++ b/mozilla/layout/html/forms/src/nsFormControlHelper.h @@ -168,9 +168,27 @@ public: * @param aResult the returned name of the form control [OUT] * @return NS_CONTENT_ATTR_HAS_VALUE if things go well * @return NS_CONTENT_ATTR_NOT_THERE if the name attribute is undefined - * @return NS_FORM_NOTOK if aContent is null or is not HTML content + * @return NS_ERROR_FAILURE if aContent is null or is not HTML content */ static nsresult GetName(nsIContent* aContent, nsAString* aResult); + /** + * Get the type of the form control (if it's not obvious from the frame type) + * @param aContent the content to get the name of + * @param aType the returned type of the form control [OUT] + * @return NS_CONTENT_ATTR_HAS_VALUE if things go well + * @return NS_CONTENT_ATTR_NOT_THERE if the type attribute is undefined + * @return NS_ERROR_FAILURE if aContent is null or is not HTML content + */ + static nsresult GetType(nsIContent* aContent, PRInt32* aType); + /** + * Get the value of the form control (if it's just living in an attr) + * @param aContent the content to get the name of + * @param aResult the returned value of the form control [OUT] + * @return NS_CONTENT_ATTR_HAS_VALUE if things go well + * @return NS_CONTENT_ATTR_NOT_THERE if the value attribute is undefined + * @return NS_ERROR_FAILURE if aContent is null or is not HTML content + */ + static nsresult GetValueAttr(nsIContent* aContent, nsAString* aResult); /** * Cause the form control to reset its value * @param aFrame the frame who owns the form control diff --git a/mozilla/layout/html/forms/src/nsHTMLButtonControlFrame.cpp b/mozilla/layout/html/forms/src/nsHTMLButtonControlFrame.cpp index 2c34ccd406b..277138e2a2c 100644 --- a/mozilla/layout/html/forms/src/nsHTMLButtonControlFrame.cpp +++ b/mozilla/layout/html/forms/src/nsHTMLButtonControlFrame.cpp @@ -225,54 +225,19 @@ nsHTMLButtonControlFrame::GetDefaultLabel(nsString& aString) NS_IMETHODIMP nsHTMLButtonControlFrame::GetType(PRInt32* aType) const { - nsresult result = NS_FORM_NOTOK; - if (mContent) { - nsIFormControl* formControl = nsnull; - result = mContent->QueryInterface(NS_GET_IID(nsIFormControl), (void**)&formControl); - if ((NS_OK == result) && formControl) { - result = formControl->GetType(aType); - NS_RELEASE(formControl); - } - } - return result; + return nsFormControlHelper::GetType(mContent, aType); } NS_IMETHODIMP nsHTMLButtonControlFrame::GetName(nsAString* aResult) { - nsresult result = NS_FORM_NOTOK; - - nsCOMPtr formControl(do_QueryInterface(mContent)); - - if (formControl) { - nsHTMLValue value; - result = formControl->GetHTMLAttribute(nsHTMLAtoms::name, value); - if (NS_CONTENT_ATTR_HAS_VALUE == result) { - if (eHTMLUnit_String == value.GetUnit()) { - value.GetStringValue(*aResult); - } - } - } - return result; + return nsFormControlHelper::GetName(mContent, aResult); } NS_IMETHODIMP nsHTMLButtonControlFrame::GetValue(nsAString* aResult) { - nsresult result = NS_FORM_NOTOK; - - nsCOMPtr formControl(do_QueryInterface(mContent)); - - if (formControl) { - nsHTMLValue value; - result = formControl->GetHTMLAttribute(nsHTMLAtoms::value, value); - if (NS_CONTENT_ATTR_HAS_VALUE == result) { - if (eHTMLUnit_String == value.GetUnit()) { - value.GetStringValue(*aResult); - } - } - } - return result; + return nsFormControlHelper::GetValueAttr(mContent, aResult); } PRBool diff --git a/mozilla/layout/html/forms/src/nsImageControlFrame.cpp b/mozilla/layout/html/forms/src/nsImageControlFrame.cpp index f11c281bacb..465a061742d 100644 --- a/mozilla/layout/html/forms/src/nsImageControlFrame.cpp +++ b/mozilla/layout/html/forms/src/nsImageControlFrame.cpp @@ -401,11 +401,7 @@ nsImageControlFrame::GetType(PRInt32* aType) const NS_IMETHODIMP nsImageControlFrame::GetName(nsAString* aResult) { - if (nsnull == aResult) { - return NS_OK; - } else { - return nsFormControlHelper::GetName(mContent, aResult); - } + return nsFormControlHelper::GetName(mContent, aResult); } NS_IMETHODIMP diff --git a/mozilla/layout/html/forms/src/nsListControlFrame.cpp b/mozilla/layout/html/forms/src/nsListControlFrame.cpp index 7115642c0f7..dcaca1e1c8d 100644 --- a/mozilla/layout/html/forms/src/nsListControlFrame.cpp +++ b/mozilla/layout/html/forms/src/nsListControlFrame.cpp @@ -1972,22 +1972,7 @@ nsListControlFrame::ResetList(nsIPresContext* aPresContext, nsVoidArray * aInxLi NS_IMETHODIMP nsListControlFrame::GetName(nsAString* aResult) { - nsresult result = NS_FORM_NOTOK; - if (mContent) { - nsIHTMLContent* formControl = nsnull; - result = mContent->QueryInterface(NS_GET_IID(nsIHTMLContent),(void**)&formControl); - if (NS_SUCCEEDED(result) && formControl) { - nsHTMLValue value; - result = formControl->GetHTMLAttribute(nsHTMLAtoms::name, value); - if (NS_CONTENT_ATTR_HAS_VALUE == result) { - if (eHTMLUnit_String == value.GetUnit()) { - value.GetStringValue(*aResult); - } - } - NS_RELEASE(formControl); - } - } - return result; + return nsFormControlHelper::GetName(mContent, aResult); } diff --git a/mozilla/layout/html/forms/src/nsTextControlFrame.cpp b/mozilla/layout/html/forms/src/nsTextControlFrame.cpp index 25acff0a3f6..749a7962a86 100644 --- a/mozilla/layout/html/forms/src/nsTextControlFrame.cpp +++ b/mozilla/layout/html/forms/src/nsTextControlFrame.cpp @@ -2383,37 +2383,13 @@ nsTextControlFrame::GetAscent(nsBoxLayoutState& aState, nscoord& aAscent) NS_IMETHODIMP nsTextControlFrame::GetName(nsAString* aResult) { - nsresult rv = NS_FORM_NOTOK; - if (mContent) { - nsIHTMLContent* formControl = nsnull; - rv = mContent->QueryInterface(NS_GET_IID(nsIHTMLContent),(void**)&formControl); - if (NS_SUCCEEDED(rv) && formControl) { - nsHTMLValue value; - rv = formControl->GetHTMLAttribute(nsHTMLAtoms::name, value); - if (NS_CONTENT_ATTR_HAS_VALUE == rv) { - if (eHTMLUnit_String == value.GetUnit()) { - value.GetStringValue(*aResult); - } - } - NS_RELEASE(formControl); - } - } - return rv; + return nsFormControlHelper::GetName(mContent, aResult); } NS_IMETHODIMP nsTextControlFrame::GetType(PRInt32* aType) const { - nsresult rv = NS_FORM_NOTOK; - if (mContent) { - nsIFormControl* formControl = nsnull; - rv = mContent->QueryInterface(NS_GET_IID(nsIFormControl), (void**)&formControl); - if ((NS_OK == rv) && formControl) { - rv = formControl->GetType(aType); - NS_RELEASE(formControl); - } - } - return rv; + return nsFormControlHelper::GetType(mContent, aType); } nsresult