From bdebc24a2b711fa6f8d76d1fae560132aaed8984 Mon Sep 17 00:00:00 2001 From: Mounir Lamouri Date: Thu, 24 Mar 2011 17:06:58 +0100 Subject: [PATCH] Bug 641409 - Move methods using only using GetType from nsGenericHTMLFormElement to nsIFormControl. r=bz --- content/html/content/public/nsIFormControl.h | 111 +++++++++++++++--- .../html/content/src/nsGenericHTMLElement.cpp | 58 --------- .../html/content/src/nsGenericHTMLElement.h | 12 -- .../html/content/src/nsHTMLInputElement.cpp | 7 +- content/html/content/src/nsHTMLInputElement.h | 4 +- 5 files changed, 98 insertions(+), 94 deletions(-) diff --git a/content/html/content/public/nsIFormControl.h b/content/html/content/public/nsIFormControl.h index c736e68753d..c2ed847b4fb 100644 --- a/content/html/content/public/nsIFormControl.h +++ b/content/html/content/public/nsIFormControl.h @@ -101,8 +101,8 @@ PR_STATIC_ASSERT((PRUint32)eButtonElementTypesMax < (PRUint32)NS_FORM_INPUT_ELEM PR_STATIC_ASSERT((PRUint32)eInputElementTypesMax < 1<<8); #define NS_IFORMCONTROL_IID \ -{ 0x218eb090, 0x32eb, 0x4e2a, \ - { 0x96, 0x42, 0xcd, 0xcd, 0x33, 0xae, 0xdb, 0x95 } } +{ 0x58865437, 0xd468, 0x4189, \ + { 0x9a, 0x3f, 0xde, 0x6e, 0x1c, 0xff, 0x79, 0x09 } } /** * Interface which all form controls (e.g. buttons, checkboxes, text, @@ -181,39 +181,114 @@ public: virtual PRBool AllowDrop() = 0; /** - * Returns true if this is a control which submits the form when - * activated by the user. - * @return Whether this is a submit control. + * Returns whether this is a control which submits the form when activated by + * the user. + * @return whether this is a submit control. */ - virtual PRBool IsSubmitControl() const = 0; + inline PRBool IsSubmitControl() const; /** - * Returns true if this is a control which has a text field. + * Returns whether this is a text control. * @param aExcludePassword to have NS_FORM_INPUT_PASSWORD returning false. - * @return Whether this is a text control. + * @return whether this is a text control. */ - virtual PRBool IsTextControl(PRBool aExcludePassword) const = 0; + inline PRBool IsTextControl(PRBool aExcludePassword) const ; /** - * Returns true if this is a control which has a single line text field. + * Returns whether this is a single line text control. * @param aExcludePassword to have NS_FORM_INPUT_PASSWORD returning false. - * @return Whether this is a single line text control. + * @return whether this is a single line text control. */ - virtual PRBool IsSingleLineTextControl(PRBool aExcludePassword) const = 0; + inline PRBool IsSingleLineTextControl(PRBool aExcludePassword) const; /** - * Returns true if this is a labelable form control. - * @return Whether this is a labelable form control. + * Returns whether this is a labelable form control. + * @return whether this is a labelable form control. */ - virtual PRBool IsLabelableControl() const = 0; + inline PRBool IsLabelableControl() const; /** - * Returns true if this is a submittable form control. - * @return Whether this is a submittable form control. + * Returns whether this is a submittable form control. + * @return whether this is a submittable form control. */ - virtual PRBool IsSubmittableControl() const = 0; + inline PRBool IsSubmittableControl() const; + +protected: + + /** + * Returns whether mType corresponds to a single line text control type. + * @param aExcludePassword to have NS_FORM_INPUT_PASSWORD ignored. + * @param aType the type to be tested. + * @return whether mType corresponds to a single line text control type. + */ + inline static bool IsSingleLineTextControl(bool aExcludePassword, PRUint32 aType); }; +PRBool +nsIFormControl::IsSubmitControl() const +{ + PRUint32 type = GetType(); + return type == NS_FORM_INPUT_SUBMIT || + type == NS_FORM_INPUT_IMAGE || + type == NS_FORM_BUTTON_SUBMIT; +} + +PRBool +nsIFormControl::IsTextControl(PRBool aExcludePassword) const +{ + PRUint32 type = GetType(); + return type == NS_FORM_TEXTAREA || + IsSingleLineTextControl(aExcludePassword, type); +} + +PRBool +nsIFormControl::IsSingleLineTextControl(PRBool aExcludePassword) const +{ + return IsSingleLineTextControl(aExcludePassword, GetType()); +} + +/*static*/ +bool +nsIFormControl::IsSingleLineTextControl(bool aExcludePassword, PRUint32 aType) +{ + return aType == NS_FORM_INPUT_TEXT || + aType == NS_FORM_INPUT_EMAIL || + aType == NS_FORM_INPUT_SEARCH || + aType == NS_FORM_INPUT_TEL || + aType == NS_FORM_INPUT_URL || + (!aExcludePassword && aType == NS_FORM_INPUT_PASSWORD); +} + +PRBool +nsIFormControl::IsLabelableControl() const +{ + // TODO: keygen should be in that list, see bug 101019. + // TODO: meter should be added, see bug 555985. + // TODO: NS_FORM_INPUT_HIDDEN should be removed, see bug 597650. + PRUint32 type = GetType(); + return type & NS_FORM_INPUT_ELEMENT || + type & NS_FORM_BUTTON_ELEMENT || + // type == NS_FORM_KEYGEN || + // type == NS_FORM_METER || + type == NS_FORM_OUTPUT || + // type == NS_FORM_PROGRESS || + type == NS_FORM_SELECT || + type == NS_FORM_TEXTAREA; +} + +PRBool +nsIFormControl::IsSubmittableControl() const +{ + // TODO: keygen should be in that list, see bug 101019. + PRUint32 type = GetType(); + return type == NS_FORM_OBJECT || + type == NS_FORM_TEXTAREA || + type == NS_FORM_SELECT || + // type == NS_FORM_KEYGEN || + type & NS_FORM_BUTTON_ELEMENT || + type & NS_FORM_INPUT_ELEMENT; +} + NS_DEFINE_STATIC_IID_ACCESSOR(nsIFormControl, NS_IFORMCONTROL_IID) #endif /* nsIFormControl_h___ */ diff --git a/content/html/content/src/nsGenericHTMLElement.cpp b/content/html/content/src/nsGenericHTMLElement.cpp index f7c4de0b3a3..6bf74aa4ec6 100644 --- a/content/html/content/src/nsGenericHTMLElement.cpp +++ b/content/html/content/src/nsGenericHTMLElement.cpp @@ -2762,64 +2762,6 @@ nsGenericHTMLFormElement::IsHTMLFocusable(PRBool aWithMouse, return PR_FALSE; } -PRBool -nsGenericHTMLFormElement::IsSubmitControl() const -{ - PRInt32 type = GetType(); - return type == NS_FORM_INPUT_SUBMIT || - type == NS_FORM_BUTTON_SUBMIT || - type == NS_FORM_INPUT_IMAGE; -} - -PRBool -nsGenericHTMLFormElement::IsTextControl(PRBool aExcludePassword) const -{ - PRInt32 type = GetType(); - return nsGenericHTMLFormElement::IsSingleLineTextControl(aExcludePassword) || - type == NS_FORM_TEXTAREA; -} - -PRBool -nsGenericHTMLFormElement::IsSingleLineTextControlInternal(PRBool aExcludePassword, - PRInt32 aType) const -{ - return aType == NS_FORM_INPUT_TEXT || - aType == NS_FORM_INPUT_EMAIL || - aType == NS_FORM_INPUT_SEARCH || - aType == NS_FORM_INPUT_TEL || - aType == NS_FORM_INPUT_URL || - (!aExcludePassword && aType == NS_FORM_INPUT_PASSWORD); -} - -PRBool -nsGenericHTMLFormElement::IsSingleLineTextControl(PRBool aExcludePassword) const -{ - return IsSingleLineTextControlInternal(aExcludePassword, GetType()); -} - -PRBool -nsGenericHTMLFormElement::IsLabelableControl() const -{ - // Check for non-labelable form controls as they are not numerous. - // TODO: datalist should be added to this list. - PRInt32 type = GetType(); - return type != NS_FORM_FIELDSET && - type != NS_FORM_LABEL && - type != NS_FORM_OBJECT; -} - -PRBool -nsGenericHTMLFormElement::IsSubmittableControl() const -{ - // TODO: keygen should be in that list, see bug 101019. - PRInt32 type = GetType(); - return type == NS_FORM_OBJECT || - type == NS_FORM_TEXTAREA || - type == NS_FORM_SELECT || - type & NS_FORM_BUTTON_ELEMENT || - type & NS_FORM_INPUT_ELEMENT; -} - nsEventStates nsGenericHTMLFormElement::IntrinsicState() const { diff --git a/content/html/content/src/nsGenericHTMLElement.h b/content/html/content/src/nsGenericHTMLElement.h index 06f258ed378..0b3d8cf4bd2 100644 --- a/content/html/content/src/nsGenericHTMLElement.h +++ b/content/html/content/src/nsGenericHTMLElement.h @@ -860,16 +860,6 @@ public: { return PR_TRUE; } - - virtual PRBool IsSubmitControl() const; - - PRBool IsTextControl(PRBool aExcludePassword) const; - - PRBool IsSingleLineTextControl(PRBool aExcludePassword) const; - - PRBool IsLabelableControl() const; - - PRBool IsSubmittableControl() const; // nsIContent virtual nsresult BindToTree(nsIDocument* aDocument, nsIContent* aParent, @@ -944,8 +934,6 @@ protected: void UpdateEditableFormControlState(); - PRBool IsSingleLineTextControlInternal(PRBool aExcludePassword, PRInt32 mType) const; - /** * This method will update the form owner, using @form or looking to a parent. * diff --git a/content/html/content/src/nsHTMLInputElement.cpp b/content/html/content/src/nsHTMLInputElement.cpp index c65bdcb866b..e7ea6f076e6 100644 --- a/content/html/content/src/nsHTMLInputElement.cpp +++ b/content/html/content/src/nsHTMLInputElement.cpp @@ -2604,10 +2604,9 @@ nsHTMLInputElement::HandleTypeChange(PRUint8 aNewType) } // Only single line text inputs have a text editor state. - PRBool isNewTypeSingleLine = - IsSingleLineTextControlInternal(PR_FALSE, aNewType); - PRBool isCurrentTypeSingleLine = - IsSingleLineTextControl(PR_FALSE); + bool isNewTypeSingleLine = IsSingleLineTextControl(PR_FALSE, aNewType); + bool isCurrentTypeSingleLine = IsSingleLineTextControl(PR_FALSE, mType); + if (isNewTypeSingleLine && !isCurrentTypeSingleLine) { FreeData(); mInputData.mState = new nsTextEditorState(this); diff --git a/content/html/content/src/nsHTMLInputElement.h b/content/html/content/src/nsHTMLInputElement.h index 938cfec142b..1178284d0c9 100644 --- a/content/html/content/src/nsHTMLInputElement.h +++ b/content/html/content/src/nsHTMLInputElement.h @@ -531,7 +531,7 @@ protected: /** * Returns if the maxlength attribute applies for the current type. */ - bool MaxLengthApplies() const { return IsSingleLineTextControlInternal(PR_FALSE, mType); } + bool MaxLengthApplies() const { return IsSingleLineTextControl(false, mType); } void FreeData(); nsTextEditorState *GetEditorState() const; @@ -550,7 +550,7 @@ protected: /** * Returns whether the placeholder attribute applies for the current type. */ - bool PlaceholderApplies() const { return IsSingleLineTextControlInternal(PR_FALSE, mType); } + bool PlaceholderApplies() const { return IsSingleLineTextControl(false, mType); } /** * Set the current default value to the value of the input element.