Bug 641409 - Move methods using only using GetType from nsGenericHTMLFormElement to nsIFormControl. r=bz

This commit is contained in:
Mounir Lamouri 2011-03-24 17:06:58 +01:00
parent 65ba1c0595
commit bdebc24a2b
5 changed files with 98 additions and 94 deletions

View File

@ -101,8 +101,8 @@ PR_STATIC_ASSERT((PRUint32)eButtonElementTypesMax < (PRUint32)NS_FORM_INPUT_ELEM
PR_STATIC_ASSERT((PRUint32)eInputElementTypesMax < 1<<8); PR_STATIC_ASSERT((PRUint32)eInputElementTypesMax < 1<<8);
#define NS_IFORMCONTROL_IID \ #define NS_IFORMCONTROL_IID \
{ 0x218eb090, 0x32eb, 0x4e2a, \ { 0x58865437, 0xd468, 0x4189, \
{ 0x96, 0x42, 0xcd, 0xcd, 0x33, 0xae, 0xdb, 0x95 } } { 0x9a, 0x3f, 0xde, 0x6e, 0x1c, 0xff, 0x79, 0x09 } }
/** /**
* Interface which all form controls (e.g. buttons, checkboxes, text, * Interface which all form controls (e.g. buttons, checkboxes, text,
@ -181,39 +181,114 @@ public:
virtual PRBool AllowDrop() = 0; virtual PRBool AllowDrop() = 0;
/** /**
* Returns true if this is a control which submits the form when * Returns whether this is a control which submits the form when activated by
* activated by the user. * the user.
* @return Whether this is a submit control. * @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. * @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. * @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. * Returns whether this is a labelable form control.
* @return 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. * Returns whether this is a submittable form control.
* @return 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) NS_DEFINE_STATIC_IID_ACCESSOR(nsIFormControl, NS_IFORMCONTROL_IID)
#endif /* nsIFormControl_h___ */ #endif /* nsIFormControl_h___ */

View File

@ -2762,64 +2762,6 @@ nsGenericHTMLFormElement::IsHTMLFocusable(PRBool aWithMouse,
return PR_FALSE; 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 nsEventStates
nsGenericHTMLFormElement::IntrinsicState() const nsGenericHTMLFormElement::IntrinsicState() const
{ {

View File

@ -860,16 +860,6 @@ public:
{ {
return PR_TRUE; return PR_TRUE;
} }
virtual PRBool IsSubmitControl() const;
PRBool IsTextControl(PRBool aExcludePassword) const;
PRBool IsSingleLineTextControl(PRBool aExcludePassword) const;
PRBool IsLabelableControl() const;
PRBool IsSubmittableControl() const;
// nsIContent // nsIContent
virtual nsresult BindToTree(nsIDocument* aDocument, nsIContent* aParent, virtual nsresult BindToTree(nsIDocument* aDocument, nsIContent* aParent,
@ -944,8 +934,6 @@ protected:
void UpdateEditableFormControlState(); void UpdateEditableFormControlState();
PRBool IsSingleLineTextControlInternal(PRBool aExcludePassword, PRInt32 mType) const;
/** /**
* This method will update the form owner, using @form or looking to a parent. * This method will update the form owner, using @form or looking to a parent.
* *

View File

@ -2604,10 +2604,9 @@ nsHTMLInputElement::HandleTypeChange(PRUint8 aNewType)
} }
// Only single line text inputs have a text editor state. // Only single line text inputs have a text editor state.
PRBool isNewTypeSingleLine = bool isNewTypeSingleLine = IsSingleLineTextControl(PR_FALSE, aNewType);
IsSingleLineTextControlInternal(PR_FALSE, aNewType); bool isCurrentTypeSingleLine = IsSingleLineTextControl(PR_FALSE, mType);
PRBool isCurrentTypeSingleLine =
IsSingleLineTextControl(PR_FALSE);
if (isNewTypeSingleLine && !isCurrentTypeSingleLine) { if (isNewTypeSingleLine && !isCurrentTypeSingleLine) {
FreeData(); FreeData();
mInputData.mState = new nsTextEditorState(this); mInputData.mState = new nsTextEditorState(this);

View File

@ -531,7 +531,7 @@ protected:
/** /**
* Returns if the maxlength attribute applies for the current type. * 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(); void FreeData();
nsTextEditorState *GetEditorState() const; nsTextEditorState *GetEditorState() const;
@ -550,7 +550,7 @@ protected:
/** /**
* Returns whether the placeholder attribute applies for the current type. * 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. * Set the current default value to the value of the input element.