Bug 1351860 - Move mType from HTMLInputElement to nsIFormControl and make GetType non-virtual inlined, r=jessica

This commit is contained in:
Olli Pettay
2017-03-31 22:49:00 -04:00
parent fa165c1239
commit 45822311b7
37 changed files with 69 additions and 77 deletions

View File

@@ -1557,7 +1557,7 @@ ChromeContextMenuListener::HandleEvent(nsIDOMEvent* aMouseEvent)
nsCOMPtr<nsIFormControl> formControl(do_QueryInterface(node)); nsCOMPtr<nsIFormControl> formControl(do_QueryInterface(node));
if (formControl) { if (formControl) {
if (formControl->GetType() == NS_FORM_TEXTAREA) { if (formControl->ControlType() == NS_FORM_TEXTAREA) {
flags |= nsIContextMenuListener::CONTEXT_TEXT; flags |= nsIContextMenuListener::CONTEXT_TEXT;
flags2 |= nsIContextMenuListener2::CONTEXT_TEXT; flags2 |= nsIContextMenuListener2::CONTEXT_TEXT;
targetDOMnode = node; targetDOMnode = node;

View File

@@ -466,7 +466,7 @@ DragDataProducer::Produce(DataTransfer* aDataTransfer,
// Note that while <object> elements implement nsIFormControl, we should // Note that while <object> elements implement nsIFormControl, we should
// really allow dragging them if they happen to be images. // really allow dragging them if they happen to be images.
nsCOMPtr<nsIFormControl> form(do_QueryInterface(mTarget)); nsCOMPtr<nsIFormControl> form(do_QueryInterface(mTarget));
if (form && !mIsAltKeyPressed && form->GetType() != NS_FORM_OBJECT) { if (form && !mIsAltKeyPressed && form->ControlType() != NS_FORM_OBJECT) {
*aCanDrag = false; *aCanDrag = false;
return NS_OK; return NS_OK;
} }

View File

@@ -2763,7 +2763,7 @@ nsContentUtils::GenerateStateKey(nsIContent* aContent,
if (control && htmlFormControls && htmlForms) { if (control && htmlFormControls && htmlForms) {
// Append the control type // Append the control type
KeyAppendInt(control->GetType(), aKey); KeyAppendInt(control->ControlType(), aKey);
// If in a form, add form name / index of form / index in form // If in a form, add form name / index of form / index in form
int32_t index = -1; int32_t index = -1;

View File

@@ -869,7 +869,7 @@ nsCopySupport::FireClipboardEvent(EventMessage aEventMessage,
// check if we are looking at a password input // check if we are looking at a password input
nsCOMPtr<nsIFormControl> formControl = do_QueryInterface(srcNode); nsCOMPtr<nsIFormControl> formControl = do_QueryInterface(srcNode);
if (formControl) { if (formControl) {
if (formControl->GetType() == NS_FORM_INPUT_PASSWORD) { if (formControl->ControlType() == NS_FORM_INPUT_PASSWORD) {
return false; return false;
} }
} }

View File

@@ -318,7 +318,7 @@ nsFocusManager::GetRedirectedFocus(nsIContent* aContent)
// For input number, redirect focus to our anonymous text control. // For input number, redirect focus to our anonymous text control.
if (aContent->IsHTMLElement(nsGkAtoms::input)) { if (aContent->IsHTMLElement(nsGkAtoms::input)) {
bool typeIsNumber = bool typeIsNumber =
static_cast<dom::HTMLInputElement*>(aContent)->GetType() == static_cast<dom::HTMLInputElement*>(aContent)->ControlType() ==
NS_FORM_INPUT_NUMBER; NS_FORM_INPUT_NUMBER;
if (typeIsNumber) { if (typeIsNumber) {

View File

@@ -1534,7 +1534,7 @@ EventStateManager::FireContextClick()
if (formCtrl) { if (formCtrl) {
allowedToDispatch = formCtrl->IsTextOrNumberControl(/*aExcludePassword*/ false) || allowedToDispatch = formCtrl->IsTextOrNumberControl(/*aExcludePassword*/ false) ||
formCtrl->GetType() == NS_FORM_INPUT_FILE; formCtrl->ControlType() == NS_FORM_INPUT_FILE;
} }
else if (mGestureDownContent->IsAnyOfHTMLElements(nsGkAtoms::applet, else if (mGestureDownContent->IsAnyOfHTMLElements(nsGkAtoms::applet,
nsGkAtoms::embed, nsGkAtoms::embed,

View File

@@ -1035,7 +1035,7 @@ IMEStateManager::SetIMEState(const IMEState& aState,
} }
} }
context.mActionHint.Assign( context.mActionHint.Assign(
willSubmit ? (control->GetType() == NS_FORM_INPUT_SEARCH ? willSubmit ? (control->ControlType() == NS_FORM_INPUT_SEARCH ?
NS_LITERAL_STRING("search") : NS_LITERAL_STRING("go")) : NS_LITERAL_STRING("search") : NS_LITERAL_STRING("go")) :
(formElement ? (formElement ?
NS_LITERAL_STRING("next") : EmptyString())); NS_LITERAL_STRING("next") : EmptyString()));

View File

@@ -57,8 +57,7 @@ static const nsAttrValue::EnumTable* kButtonDefaultType = &kButtonTypeTable[2];
// Construction, destruction // Construction, destruction
HTMLButtonElement::HTMLButtonElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo, HTMLButtonElement::HTMLButtonElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo,
FromParser aFromParser) FromParser aFromParser)
: nsGenericHTMLFormElementWithState(aNodeInfo), : nsGenericHTMLFormElementWithState(aNodeInfo, kButtonDefaultType->value),
mType(kButtonDefaultType->value),
mDisabledChanged(false), mDisabledChanged(false),
mInInternalActivate(false), mInInternalActivate(false),
mInhibitStateRestoration(!!(aFromParser & FROM_PARSER_FRAGMENT)) mInhibitStateRestoration(!!(aFromParser & FROM_PARSER_FRAGMENT))

View File

@@ -47,7 +47,6 @@ public:
NS_DECL_NSIDOMHTMLBUTTONELEMENT NS_DECL_NSIDOMHTMLBUTTONELEMENT
// overriden nsIFormControl methods // overriden nsIFormControl methods
NS_IMETHOD_(uint32_t) GetType() const override { return mType; }
NS_IMETHOD Reset() override; NS_IMETHOD Reset() override;
NS_IMETHOD SubmitNamesValues(HTMLFormSubmission* aFormSubmission) override; NS_IMETHOD SubmitNamesValues(HTMLFormSubmission* aFormSubmission) override;
NS_IMETHOD SaveState() override; NS_IMETHOD SaveState() override;
@@ -172,7 +171,6 @@ public:
protected: protected:
virtual ~HTMLButtonElement(); virtual ~HTMLButtonElement();
uint8_t mType;
bool mDisabledChanged; bool mDisabledChanged;
bool mInInternalActivate; bool mInInternalActivate;
bool mInhibitStateRestoration; bool mInhibitStateRestoration;

View File

@@ -18,7 +18,7 @@ namespace mozilla {
namespace dom { namespace dom {
HTMLFieldSetElement::HTMLFieldSetElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo) HTMLFieldSetElement::HTMLFieldSetElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo)
: nsGenericHTMLFormElement(aNodeInfo) : nsGenericHTMLFormElement(aNodeInfo, NS_FORM_FIELDSET)
, mElements(nullptr) , mElements(nullptr)
, mFirstLegend(nullptr) , mFirstLegend(nullptr)
, mInvalidElementsCount(0) , mInvalidElementsCount(0)

View File

@@ -50,7 +50,6 @@ public:
virtual void RemoveChildAt(uint32_t aIndex, bool aNotify) override; virtual void RemoveChildAt(uint32_t aIndex, bool aNotify) override;
// nsIFormControl // nsIFormControl
NS_IMETHOD_(uint32_t) GetType() const override { return NS_FORM_FIELDSET; }
NS_IMETHOD Reset() override; NS_IMETHOD Reset() override;
NS_IMETHOD SubmitNamesValues(HTMLFormSubmission* aFormSubmission) override; NS_IMETHOD SubmitNamesValues(HTMLFormSubmission* aFormSubmission) override;
virtual bool IsDisabledForEvents(EventMessage aMessage) override; virtual bool IsDisabledForEvents(EventMessage aMessage) override;

View File

@@ -29,7 +29,7 @@ HTMLFormControlsCollection::ShouldBeInElements(nsIFormControl* aFormControl)
// <input type=image> elements to the list of form controls in a // <input type=image> elements to the list of form controls in a
// form. // form.
switch (aFormControl->GetType()) { switch (aFormControl->ControlType()) {
case NS_FORM_BUTTON_BUTTON : case NS_FORM_BUTTON_BUTTON :
case NS_FORM_BUTTON_RESET : case NS_FORM_BUTTON_RESET :
case NS_FORM_BUTTON_SUBMIT : case NS_FORM_BUTTON_SUBMIT :

View File

@@ -1251,7 +1251,7 @@ HTMLFormElement::AddElement(nsGenericHTMLFormElement* aChild,
AssertDocumentOrder(controlList, this); AssertDocumentOrder(controlList, this);
#endif #endif
int32_t type = aChild->GetType(); int32_t type = aChild->ControlType();
// //
// If it is a password control, and the password manager has not yet been // If it is a password control, and the password manager has not yet been
@@ -1352,7 +1352,7 @@ HTMLFormElement::RemoveElement(nsGenericHTMLFormElement* aChild,
// Remove it from the radio group if it's a radio button // Remove it from the radio group if it's a radio button
// //
nsresult rv = NS_OK; nsresult rv = NS_OK;
if (aChild->GetType() == NS_FORM_INPUT_RADIO) { if (aChild->ControlType() == NS_FORM_INPUT_RADIO) {
RefPtr<HTMLInputElement> radio = RefPtr<HTMLInputElement> radio =
static_cast<HTMLInputElement*>(aChild); static_cast<HTMLInputElement*>(aChild);
radio->WillRemoveFromRadioGroup(); radio->WillRemoveFromRadioGroup();
@@ -1818,7 +1818,7 @@ HTMLFormElement::ImplicitSubmissionIsDisabled() const
uint32_t length = mControls->mElements.Length(); uint32_t length = mControls->mElements.Length();
for (uint32_t i = 0; i < length && numDisablingControlsFound < 2; ++i) { for (uint32_t i = 0; i < length && numDisablingControlsFound < 2; ++i) {
if (mControls->mElements[i]->IsSingleLineTextControl(false) || if (mControls->mElements[i]->IsSingleLineTextControl(false) ||
mControls->mElements[i]->GetType() == NS_FORM_INPUT_NUMBER) { mControls->mElements[i]->ControlType() == NS_FORM_INPUT_NUMBER) {
numDisablingControlsFound++; numDisablingControlsFound++;
} }
} }
@@ -2024,7 +2024,7 @@ HTMLFormElement::SubmissionCanProceed(Element* aSubmitter)
nsCOMPtr<nsIFormControl> fc = do_QueryInterface(aSubmitter); nsCOMPtr<nsIFormControl> fc = do_QueryInterface(aSubmitter);
MOZ_ASSERT(fc); MOZ_ASSERT(fc);
uint32_t type = fc->GetType(); uint32_t type = fc->ControlType();
MOZ_ASSERT(type == NS_FORM_INPUT_SUBMIT || MOZ_ASSERT(type == NS_FORM_INPUT_SUBMIT ||
type == NS_FORM_INPUT_IMAGE || type == NS_FORM_INPUT_IMAGE ||
type == NS_FORM_BUTTON_SUBMIT, type == NS_FORM_BUTTON_SUBMIT,
@@ -2225,7 +2225,7 @@ HTMLFormElement::GetNextRadioButton(const nsAString& aName,
index = 0; index = 0;
} }
radio = HTMLInputElement::FromContentOrNull(radioGroup->Item(index)); radio = HTMLInputElement::FromContentOrNull(radioGroup->Item(index));
isRadio = radio && radio->GetType() == NS_FORM_INPUT_RADIO; isRadio = radio && radio->ControlType() == NS_FORM_INPUT_RADIO;
if (!isRadio) { if (!isRadio) {
continue; continue;
} }
@@ -2253,7 +2253,7 @@ HTMLFormElement::WalkRadioGroup(const nsAString& aName,
uint32_t len = GetElementCount(); uint32_t len = GetElementCount();
for (uint32_t i = 0; i < len; i++) { for (uint32_t i = 0; i < len; i++) {
control = GetElementAt(i); control = GetElementAt(i);
if (control->GetType() == NS_FORM_INPUT_RADIO) { if (control->ControlType() == NS_FORM_INPUT_RADIO) {
nsCOMPtr<nsIContent> controlContent = do_QueryInterface(control); nsCOMPtr<nsIContent> controlContent = do_QueryInterface(control);
if (controlContent && if (controlContent &&
controlContent->AttrValueIs(kNameSpaceID_None, nsGkAtoms::name, controlContent->AttrValueIs(kNameSpaceID_None, nsGkAtoms::name,
@@ -2275,7 +2275,7 @@ HTMLFormElement::WalkRadioGroup(const nsAString& aName,
// If it's just a lone radio button, then select it. // If it's just a lone radio button, then select it.
nsCOMPtr<nsIFormControl> formControl = do_QueryInterface(item); nsCOMPtr<nsIFormControl> formControl = do_QueryInterface(item);
if (formControl) { if (formControl) {
if (formControl->GetType() == NS_FORM_INPUT_RADIO) { if (formControl->ControlType() == NS_FORM_INPUT_RADIO) {
aVisitor->Visit(formControl); aVisitor->Visit(formControl);
} }
return NS_OK; return NS_OK;
@@ -2291,7 +2291,7 @@ HTMLFormElement::WalkRadioGroup(const nsAString& aName,
nsCOMPtr<nsIDOMNode> node; nsCOMPtr<nsIDOMNode> node;
nodeList->Item(i, getter_AddRefs(node)); nodeList->Item(i, getter_AddRefs(node));
nsCOMPtr<nsIFormControl> formControl = do_QueryInterface(node); nsCOMPtr<nsIFormControl> formControl = do_QueryInterface(node);
if (formControl && formControl->GetType() == NS_FORM_INPUT_RADIO && if (formControl && formControl->ControlType() == NS_FORM_INPUT_RADIO &&
!aVisitor->Visit(formControl)) { !aVisitor->Visit(formControl)) {
break; break;
} }

View File

@@ -1054,8 +1054,7 @@ static nsresult FireEventForAccessibility(nsIDOMHTMLInputElement* aTarget,
HTMLInputElement::HTMLInputElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo, HTMLInputElement::HTMLInputElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo,
FromParser aFromParser, FromClone aFromClone) FromParser aFromParser, FromClone aFromClone)
: nsGenericHTMLFormElementWithState(aNodeInfo) : nsGenericHTMLFormElementWithState(aNodeInfo, kInputDefaultType->value)
, mType(kInputDefaultType->value)
, mAutocompleteAttrState(nsContentUtils::eAutocompleteAttrState_Unknown) , mAutocompleteAttrState(nsContentUtils::eAutocompleteAttrState_Unknown)
, mDisabledChanged(false) , mDisabledChanged(false)
, mValueChanged(false) , mValueChanged(false)
@@ -3514,7 +3513,7 @@ HTMLInputElement::Focus(ErrorResult& aError)
// See if the child is a button control. // See if the child is a button control.
nsCOMPtr<nsIFormControl> formCtrl = nsCOMPtr<nsIFormControl> formCtrl =
do_QueryInterface(childFrame->GetContent()); do_QueryInterface(childFrame->GetContent());
if (formCtrl && formCtrl->GetType() == NS_FORM_BUTTON_BUTTON) { if (formCtrl && formCtrl->ControlType() == NS_FORM_BUTTON_BUTTON) {
nsCOMPtr<nsIDOMElement> element = do_QueryInterface(formCtrl); nsCOMPtr<nsIDOMElement> element = do_QueryInterface(formCtrl);
nsIFocusManager* fm = nsFocusManager::GetFocusManager(); nsIFocusManager* fm = nsFocusManager::GetFocusManager();
if (fm && element) { if (fm && element) {

View File

@@ -164,7 +164,6 @@ public:
NS_IMETHOD SetUserInput(const nsAString& aInput) override; NS_IMETHOD SetUserInput(const nsAString& aInput) override;
// Overriden nsIFormControl methods // Overriden nsIFormControl methods
NS_IMETHOD_(uint32_t) GetType() const override { return mType; }
NS_IMETHOD Reset() override; NS_IMETHOD Reset() override;
NS_IMETHOD SubmitNamesValues(HTMLFormSubmission* aFormSubmission) override; NS_IMETHOD SubmitNamesValues(HTMLFormSubmission* aFormSubmission) override;
NS_IMETHOD SaveState() override; NS_IMETHOD SaveState() override;
@@ -1609,12 +1608,6 @@ protected:
// Milliseconds in a day. // Milliseconds in a day.
static const double kMsPerDay; static const double kMsPerDay;
/**
* The type of this input (<input type=...>) as an integer.
* @see nsIFormControl.h (specifically NS_FORM_INPUT_*)
*/
uint8_t mType;
nsContentUtils::AutocompleteAttrState mAutocompleteAttrState; nsContentUtils::AutocompleteAttrState mAutocompleteAttrState;
bool mDisabledChanged : 1; bool mDisabledChanged : 1;
bool mValueChanged : 1; bool mValueChanged : 1;

View File

@@ -30,7 +30,7 @@ namespace dom {
HTMLObjectElement::HTMLObjectElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo, HTMLObjectElement::HTMLObjectElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo,
FromParser aFromParser) FromParser aFromParser)
: nsGenericHTMLFormElement(aNodeInfo), : nsGenericHTMLFormElement(aNodeInfo, NS_FORM_OBJECT),
mIsDoneAddingChildren(!aFromParser) mIsDoneAddingChildren(!aFromParser)
{ {
RegisterActivityObserver(); RegisterActivityObserver();

View File

@@ -69,11 +69,6 @@ public:
virtual IMEState GetDesiredIMEState() override; virtual IMEState GetDesiredIMEState() override;
// Overriden nsIFormControl methods // Overriden nsIFormControl methods
NS_IMETHOD_(uint32_t) GetType() const override
{
return NS_FORM_OBJECT;
}
NS_IMETHOD Reset() override; NS_IMETHOD Reset() override;
NS_IMETHOD SubmitNamesValues(HTMLFormSubmission *aFormSubmission) override; NS_IMETHOD SubmitNamesValues(HTMLFormSubmission *aFormSubmission) override;

View File

@@ -21,7 +21,7 @@ namespace dom {
HTMLOutputElement::HTMLOutputElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo, HTMLOutputElement::HTMLOutputElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo,
FromParser aFromParser) FromParser aFromParser)
: nsGenericHTMLFormElement(aNodeInfo) : nsGenericHTMLFormElement(aNodeInfo, NS_FORM_OUTPUT)
, mValueModeFlag(eModeDefault) , mValueModeFlag(eModeDefault)
, mIsDoneAddingChildren(!aFromParser) , mIsDoneAddingChildren(!aFromParser)
{ {

View File

@@ -31,7 +31,6 @@ public:
NS_DECL_ISUPPORTS_INHERITED NS_DECL_ISUPPORTS_INHERITED
// nsIFormControl // nsIFormControl
NS_IMETHOD_(uint32_t) GetType() const override { return NS_FORM_OUTPUT; }
NS_IMETHOD Reset() override; NS_IMETHOD Reset() override;
NS_IMETHOD SubmitNamesValues(HTMLFormSubmission* aFormSubmission) override; NS_IMETHOD SubmitNamesValues(HTMLFormSubmission* aFormSubmission) override;

View File

@@ -117,7 +117,7 @@ SafeOptionListMutation::~SafeOptionListMutation()
HTMLSelectElement::HTMLSelectElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo, HTMLSelectElement::HTMLSelectElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo,
FromParser aFromParser) FromParser aFromParser)
: nsGenericHTMLFormElementWithState(aNodeInfo), : nsGenericHTMLFormElementWithState(aNodeInfo, NS_FORM_SELECT),
mOptions(new HTMLOptionsCollection(this)), mOptions(new HTMLOptionsCollection(this)),
mAutocompleteAttrState(nsContentUtils::eAutocompleteAttrState_Unknown), mAutocompleteAttrState(nsContentUtils::eAutocompleteAttrState_Unknown),
mIsDoneAddingChildren(!aFromParser), mIsDoneAddingChildren(!aFromParser),

View File

@@ -296,7 +296,6 @@ public:
virtual void RemoveChildAt(uint32_t aIndex, bool aNotify) override; virtual void RemoveChildAt(uint32_t aIndex, bool aNotify) override;
// Overriden nsIFormControl methods // Overriden nsIFormControl methods
NS_IMETHOD_(uint32_t) GetType() const override { return NS_FORM_SELECT; }
NS_IMETHOD Reset() override; NS_IMETHOD Reset() override;
NS_IMETHOD SubmitNamesValues(HTMLFormSubmission* aFormSubmission) override; NS_IMETHOD SubmitNamesValues(HTMLFormSubmission* aFormSubmission) override;
NS_IMETHOD SaveState() override; NS_IMETHOD SaveState() override;

View File

@@ -53,7 +53,7 @@ namespace dom {
HTMLTextAreaElement::HTMLTextAreaElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo, HTMLTextAreaElement::HTMLTextAreaElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo,
FromParser aFromParser) FromParser aFromParser)
: nsGenericHTMLFormElementWithState(aNodeInfo), : nsGenericHTMLFormElementWithState(aNodeInfo, NS_FORM_TEXTAREA),
mValueChanged(false), mValueChanged(false),
mLastValueChangeWasInteractive(false), mLastValueChangeWasInteractive(false),
mHandlingSelect(false), mHandlingSelect(false),

View File

@@ -72,7 +72,6 @@ public:
NS_IMETHOD SetUserInput(const nsAString& aInput) override; NS_IMETHOD SetUserInput(const nsAString& aInput) override;
// nsIFormControl // nsIFormControl
NS_IMETHOD_(uint32_t) GetType() const override { return NS_FORM_TEXTAREA; }
NS_IMETHOD Reset() override; NS_IMETHOD Reset() override;
NS_IMETHOD SubmitNamesValues(HTMLFormSubmission* aFormSubmission) override; NS_IMETHOD SubmitNamesValues(HTMLFormSubmission* aFormSubmission) override;
NS_IMETHOD SaveState() override; NS_IMETHOD SaveState() override;

View File

@@ -25,7 +25,7 @@ HTMLInputElement*
GetAsRadio(nsIContent* node) GetAsRadio(nsIContent* node)
{ {
HTMLInputElement* el = HTMLInputElement::FromContent(node); HTMLInputElement* el = HTMLInputElement::FromContent(node);
if (el && el->GetType() == NS_FORM_INPUT_RADIO) { if (el && el->ControlType() == NS_FORM_INPUT_RADIO) {
return el; return el;
} }
return nullptr; return nullptr;

View File

@@ -403,7 +403,7 @@ nsGenericHTMLElement::Spellcheck()
} }
// Is this a multiline plaintext input? // Is this a multiline plaintext input?
int32_t controlType = formControl->GetType(); int32_t controlType = formControl->ControlType();
if (controlType == NS_FORM_TEXTAREA) { if (controlType == NS_FORM_TEXTAREA) {
return true; // Spellchecked by default return true; // Spellchecked by default
} }
@@ -1730,8 +1730,10 @@ nsGenericHTMLElement::TouchEventsEnabled(JSContext* aCx, JSObject* aGlobal)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
nsGenericHTMLFormElement::nsGenericHTMLFormElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo) nsGenericHTMLFormElement::nsGenericHTMLFormElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo,
uint8_t aType)
: nsGenericHTMLElement(aNodeInfo) : nsGenericHTMLElement(aNodeInfo)
, nsIFormControl(aType)
, mForm(nullptr) , mForm(nullptr)
, mFieldSet(nullptr) , mFieldSet(nullptr)
{ {
@@ -2090,7 +2092,7 @@ nsGenericHTMLFormElement::ForgetFieldSet(nsIContent* aFieldset)
bool bool
nsGenericHTMLFormElement::CanBeDisabled() const nsGenericHTMLFormElement::CanBeDisabled() const
{ {
int32_t type = GetType(); int32_t type = ControlType();
// It's easier to test the types that _cannot_ be disabled // It's easier to test the types that _cannot_ be disabled
return return
type != NS_FORM_OBJECT && type != NS_FORM_OBJECT &&
@@ -2403,7 +2405,7 @@ bool
nsGenericHTMLFormElement::IsLabelable() const nsGenericHTMLFormElement::IsLabelable() const
{ {
// TODO: keygen should be in that list, see bug 101019. // TODO: keygen should be in that list, see bug 101019.
uint32_t type = GetType(); uint32_t type = ControlType();
return (type & NS_FORM_INPUT_ELEMENT && type != NS_FORM_INPUT_HIDDEN) || return (type & NS_FORM_INPUT_ELEMENT && type != NS_FORM_INPUT_HIDDEN) ||
type & NS_FORM_BUTTON_ELEMENT || type & NS_FORM_BUTTON_ELEMENT ||
// type == NS_FORM_KEYGEN || // type == NS_FORM_KEYGEN ||
@@ -2730,9 +2732,9 @@ nsGenericHTMLElement::ChangeEditableState(int32_t aChange)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
nsGenericHTMLFormElementWithState::nsGenericHTMLFormElementWithState( nsGenericHTMLFormElementWithState::nsGenericHTMLFormElementWithState(
already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo, uint8_t aType
) )
: nsGenericHTMLFormElement(aNodeInfo) : nsGenericHTMLFormElement(aNodeInfo, aType)
{ {
mStateKey.SetIsVoid(true); mStateKey.SetIsVoid(true);
} }

View File

@@ -1208,7 +1208,8 @@ class nsGenericHTMLFormElement : public nsGenericHTMLElement,
public nsIFormControl public nsIFormControl
{ {
public: public:
explicit nsGenericHTMLFormElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo); nsGenericHTMLFormElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo,
uint8_t aType);
NS_DECL_ISUPPORTS_INHERITED NS_DECL_ISUPPORTS_INHERITED
@@ -1368,7 +1369,8 @@ protected:
class nsGenericHTMLFormElementWithState : public nsGenericHTMLFormElement class nsGenericHTMLFormElementWithState : public nsGenericHTMLFormElement
{ {
public: public:
explicit nsGenericHTMLFormElementWithState(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo); nsGenericHTMLFormElementWithState(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo,
uint8_t aType);
/** /**
* Get the presentation state for a piece of content, or create it if it does * Get the presentation state for a piece of content, or create it if it does

View File

@@ -92,6 +92,10 @@ static_assert(static_cast<uint32_t>(eInputElementTypesMax) < 1<<8,
class nsIFormControl : public nsISupports class nsIFormControl : public nsISupports
{ {
public: public:
nsIFormControl(uint8_t aType)
: mType(aType)
{
}
NS_DECLARE_STATIC_IID_ACCESSOR(NS_IFORMCONTROL_IID) NS_DECLARE_STATIC_IID_ACCESSOR(NS_IFORMCONTROL_IID)
@@ -130,7 +134,7 @@ public:
* Get the type of this control as an int (see NS_FORM_* above) * Get the type of this control as an int (see NS_FORM_* above)
* @return the type of this control * @return the type of this control
*/ */
NS_IMETHOD_(uint32_t) GetType() const = 0 ; uint32_t ControlType() const { return mType; }
/** /**
* Reset this form control (as it should be when the user clicks the Reset * Reset this form control (as it should be when the user clicks the Reset
@@ -226,12 +230,14 @@ protected:
* @return whether this is a auto-focusable form control. * @return whether this is a auto-focusable form control.
*/ */
inline bool IsAutofocusable() const; inline bool IsAutofocusable() const;
uint8_t mType;
}; };
bool bool
nsIFormControl::IsSubmitControl() const nsIFormControl::IsSubmitControl() const
{ {
uint32_t type = GetType(); uint32_t type = ControlType();
return type == NS_FORM_INPUT_SUBMIT || return type == NS_FORM_INPUT_SUBMIT ||
type == NS_FORM_INPUT_IMAGE || type == NS_FORM_INPUT_IMAGE ||
type == NS_FORM_BUTTON_SUBMIT; type == NS_FORM_BUTTON_SUBMIT;
@@ -240,7 +246,7 @@ nsIFormControl::IsSubmitControl() const
bool bool
nsIFormControl::IsTextControl(bool aExcludePassword) const nsIFormControl::IsTextControl(bool aExcludePassword) const
{ {
uint32_t type = GetType(); uint32_t type = ControlType();
return type == NS_FORM_TEXTAREA || return type == NS_FORM_TEXTAREA ||
IsSingleLineTextControl(aExcludePassword, type); IsSingleLineTextControl(aExcludePassword, type);
} }
@@ -248,13 +254,13 @@ nsIFormControl::IsTextControl(bool aExcludePassword) const
bool bool
nsIFormControl::IsTextOrNumberControl(bool aExcludePassword) const nsIFormControl::IsTextOrNumberControl(bool aExcludePassword) const
{ {
return IsTextControl(aExcludePassword) || GetType() == NS_FORM_INPUT_NUMBER; return IsTextControl(aExcludePassword) || ControlType() == NS_FORM_INPUT_NUMBER;
} }
bool bool
nsIFormControl::IsSingleLineTextControl(bool aExcludePassword) const nsIFormControl::IsSingleLineTextControl(bool aExcludePassword) const
{ {
return IsSingleLineTextControl(aExcludePassword, GetType()); return IsSingleLineTextControl(aExcludePassword, ControlType());
} }
/*static*/ /*static*/
@@ -282,7 +288,7 @@ bool
nsIFormControl::IsSubmittableControl() const nsIFormControl::IsSubmittableControl() const
{ {
// TODO: keygen should be in that list, see bug 101019. // TODO: keygen should be in that list, see bug 101019.
uint32_t type = GetType(); uint32_t type = ControlType();
return type == NS_FORM_OBJECT || return type == NS_FORM_OBJECT ||
type == NS_FORM_TEXTAREA || type == NS_FORM_TEXTAREA ||
type == NS_FORM_SELECT || type == NS_FORM_SELECT ||
@@ -294,7 +300,7 @@ nsIFormControl::IsSubmittableControl() const
bool bool
nsIFormControl::AllowDraggableChildren() const nsIFormControl::AllowDraggableChildren() const
{ {
uint32_t type = GetType(); uint32_t type = ControlType();
return type == NS_FORM_OBJECT || return type == NS_FORM_OBJECT ||
type == NS_FORM_FIELDSET || type == NS_FORM_FIELDSET ||
type == NS_FORM_OUTPUT; type == NS_FORM_OUTPUT;
@@ -303,7 +309,7 @@ nsIFormControl::AllowDraggableChildren() const
bool bool
nsIFormControl::IsAutofocusable() const nsIFormControl::IsAutofocusable() const
{ {
uint32_t type = GetType(); uint32_t type = ControlType();
return type & NS_FORM_INPUT_ELEMENT || return type & NS_FORM_INPUT_ELEMENT ||
type & NS_FORM_BUTTON_ELEMENT || type & NS_FORM_BUTTON_ELEMENT ||
type == NS_FORM_TEXTAREA || type == NS_FORM_TEXTAREA ||

View File

@@ -1979,7 +1979,7 @@ nsTextEditorState::GetParentNumberControl(nsFrame* aFrame) const
// that situation, the type of the control has changed, but its frame has // that situation, the type of the control has changed, but its frame has
// not been reconstructed yet. So we need to check the type of the input // not been reconstructed yet. So we need to check the type of the input
// control in addition to the type of the frame. // control in addition to the type of the frame.
return (input->GetType() == NS_FORM_INPUT_NUMBER) ? input : nullptr; return (input->ControlType() == NS_FORM_INPUT_NUMBER) ? input : nullptr;
} }
return nullptr; return nullptr;

View File

@@ -1208,7 +1208,7 @@ PersistNodeFixup::FixupNode(nsIDOMNode *aNodeIn,
RefPtr<dom::HTMLInputElement> outElt = RefPtr<dom::HTMLInputElement> outElt =
dom::HTMLInputElement::FromContentOrNull(content); dom::HTMLInputElement::FromContentOrNull(content);
nsCOMPtr<nsIFormControl> formControl = do_QueryInterface(*aNodeOut); nsCOMPtr<nsIFormControl> formControl = do_QueryInterface(*aNodeOut);
switch (formControl->GetType()) { switch (formControl->ControlType()) {
case NS_FORM_INPUT_EMAIL: case NS_FORM_INPUT_EMAIL:
case NS_FORM_INPUT_SEARCH: case NS_FORM_INPUT_SEARCH:
case NS_FORM_INPUT_TEXT: case NS_FORM_INPUT_TEXT:

View File

@@ -1208,7 +1208,7 @@ EditorEventListener::IsFileControlTextBox()
return false; return false;
} }
nsCOMPtr<nsIFormControl> formControl = do_QueryInterface(parent); nsCOMPtr<nsIFormControl> formControl = do_QueryInterface(parent);
return formControl->GetType() == NS_FORM_INPUT_FILE; return formControl->ControlType() == NS_FORM_INPUT_FILE;
} }
bool bool

View File

@@ -3728,7 +3728,7 @@ nsCSSFrameConstructor::FindInputData(Element* aElement,
nsCOMPtr<nsIFormControl> control = do_QueryInterface(aElement); nsCOMPtr<nsIFormControl> control = do_QueryInterface(aElement);
NS_ASSERTION(control, "input doesn't implement nsIFormControl?"); NS_ASSERTION(control, "input doesn't implement nsIFormControl?");
auto controlType = control->GetType(); auto controlType = control->ControlType();
// Note that Android/Gonk widgets don't have theming support and thus // Note that Android/Gonk widgets don't have theming support and thus
// appearance:none is the same as any other appearance value. // appearance:none is the same as any other appearance value.

View File

@@ -121,7 +121,7 @@ nsColorControlFrame::AttributeChanged(int32_t aNameSpaceID,
// still a color control, which might not be the case if the type attribute // still a color control, which might not be the case if the type attribute
// was removed/changed. // was removed/changed.
nsCOMPtr<nsIFormControl> fctrl = do_QueryInterface(GetContent()); nsCOMPtr<nsIFormControl> fctrl = do_QueryInterface(GetContent());
if (fctrl->GetType() == NS_FORM_INPUT_COLOR && if (fctrl->ControlType() == NS_FORM_INPUT_COLOR &&
aNameSpaceID == kNameSpaceID_None && nsGkAtoms::value == aAttribute) { aNameSpaceID == kNameSpaceID_None && nsGkAtoms::value == aAttribute) {
UpdateColor(); UpdateColor();
} }

View File

@@ -1450,7 +1450,7 @@ nsComboboxControlFrame::SetInitialChildList(ChildListID aListID,
for (nsFrameList::Enumerator e(aChildList); !e.AtEnd(); e.Next()) { for (nsFrameList::Enumerator e(aChildList); !e.AtEnd(); e.Next()) {
nsCOMPtr<nsIFormControl> formControl = nsCOMPtr<nsIFormControl> formControl =
do_QueryInterface(e.get()->GetContent()); do_QueryInterface(e.get()->GetContent());
if (formControl && formControl->GetType() == NS_FORM_BUTTON_BUTTON) { if (formControl && formControl->ControlType() == NS_FORM_BUTTON_BUTTON) {
mButtonFrame = e.get(); mButtonFrame = e.get();
break; break;
} }

View File

@@ -383,8 +383,8 @@ nsDateTimeControlFrame::AttributeChanged(int32_t aNameSpaceID,
auto contentAsInputElem = static_cast<dom::HTMLInputElement*>(mContent); auto contentAsInputElem = static_cast<dom::HTMLInputElement*>(mContent);
// If script changed the <input>'s type before setting these attributes // If script changed the <input>'s type before setting these attributes
// then we don't need to do anything since we are going to be reframed. // then we don't need to do anything since we are going to be reframed.
if (contentAsInputElem->GetType() == NS_FORM_INPUT_TIME || if (contentAsInputElem->ControlType() == NS_FORM_INPUT_TIME ||
contentAsInputElem->GetType() == NS_FORM_INPUT_DATE) { contentAsInputElem->ControlType() == NS_FORM_INPUT_DATE) {
nsCOMPtr<nsIDateTimeInputArea> inputAreaContent = nsCOMPtr<nsIDateTimeInputArea> inputAreaContent =
do_QueryInterface(mInputAreaContent); do_QueryInterface(mInputAreaContent);
if (aAttribute == nsGkAtoms::value) { if (aAttribute == nsGkAtoms::value) {

View File

@@ -94,7 +94,7 @@ nsGfxButtonControlFrame::GetDefaultLabel(nsXPIDLString& aString) const
nsCOMPtr<nsIFormControl> form = do_QueryInterface(mContent); nsCOMPtr<nsIFormControl> form = do_QueryInterface(mContent);
NS_ENSURE_TRUE(form, NS_ERROR_UNEXPECTED); NS_ENSURE_TRUE(form, NS_ERROR_UNEXPECTED);
int32_t type = form->GetType(); int32_t type = form->ControlType();
const char *prop; const char *prop;
if (type == NS_FORM_INPUT_RESET) { if (type == NS_FORM_INPUT_RESET) {
prop = "Reset"; prop = "Reset";

View File

@@ -489,7 +489,7 @@ nsRangeFrame::GetValueAsFractionOfRange()
MOZ_ASSERT(mContent->IsHTMLElement(nsGkAtoms::input), "bad cast"); MOZ_ASSERT(mContent->IsHTMLElement(nsGkAtoms::input), "bad cast");
dom::HTMLInputElement* input = static_cast<dom::HTMLInputElement*>(mContent); dom::HTMLInputElement* input = static_cast<dom::HTMLInputElement*>(mContent);
MOZ_ASSERT(input->GetType() == NS_FORM_INPUT_RANGE); MOZ_ASSERT(input->ControlType() == NS_FORM_INPUT_RANGE);
Decimal value = input->GetValueAsDecimal(); Decimal value = input->GetValueAsDecimal();
Decimal minimum = input->GetMinimum(); Decimal minimum = input->GetMinimum();
@@ -518,7 +518,7 @@ nsRangeFrame::GetValueAtEventPoint(WidgetGUIEvent* aEvent)
MOZ_ASSERT(mContent->IsHTMLElement(nsGkAtoms::input), "bad cast"); MOZ_ASSERT(mContent->IsHTMLElement(nsGkAtoms::input), "bad cast");
dom::HTMLInputElement* input = static_cast<dom::HTMLInputElement*>(mContent); dom::HTMLInputElement* input = static_cast<dom::HTMLInputElement*>(mContent);
MOZ_ASSERT(input->GetType() == NS_FORM_INPUT_RANGE); MOZ_ASSERT(input->ControlType() == NS_FORM_INPUT_RANGE);
Decimal minimum = input->GetMinimum(); Decimal minimum = input->GetMinimum();
Decimal maximum = input->GetMaximum(); Decimal maximum = input->GetMaximum();
@@ -750,7 +750,8 @@ nsRangeFrame::AttributeChanged(int32_t aNameSpaceID,
// and this frame will shortly be destroyed, there's no point in calling // and this frame will shortly be destroyed, there's no point in calling
// UpdateForValueChange() anyway. // UpdateForValueChange() anyway.
MOZ_ASSERT(mContent->IsHTMLElement(nsGkAtoms::input), "bad cast"); MOZ_ASSERT(mContent->IsHTMLElement(nsGkAtoms::input), "bad cast");
bool typeIsRange = static_cast<dom::HTMLInputElement*>(mContent)->GetType() == bool typeIsRange =
static_cast<dom::HTMLInputElement*>(mContent)->ControlType() ==
NS_FORM_INPUT_RANGE; NS_FORM_INPUT_RANGE;
// If script changed the <input>'s type before setting these attributes // If script changed the <input>'s type before setting these attributes
// then we don't need to do anything since we are going to be reframed. // then we don't need to do anything since we are going to be reframed.

View File

@@ -740,8 +740,9 @@ nsFormFillController::StartSearch(const nsAString &aSearchString, const nsAStrin
// If the login manager has indicated it's responsible for this field, let it // If the login manager has indicated it's responsible for this field, let it
// handle the autocomplete. Otherwise, handle with form history. // handle the autocomplete. Otherwise, handle with form history.
// This method is sometimes called in unit tests and from XUL without a focused node. // This method is sometimes called in unit tests and from XUL without a focused node.
if (mFocusedInputNode && (mPwmgrInputs.Get(mFocusedInputNode) || if (mFocusedInputNode &&
formControl->GetType() == NS_FORM_INPUT_PASSWORD)) { (mPwmgrInputs.Get(mFocusedInputNode) ||
formControl->ControlType() == NS_FORM_INPUT_PASSWORD)) {
// Handle the case where a password field is focused but // Handle the case where a password field is focused but
// MarkAsLoginManagerField wasn't called because password manager is disabled. // MarkAsLoginManagerField wasn't called because password manager is disabled.
@@ -1033,7 +1034,7 @@ nsFormFillController::MaybeStartControllingInput(nsIDOMHTMLInputElement* aInput)
bool isPwmgrInput = false; bool isPwmgrInput = false;
if (mPwmgrInputs.Get(inputNode) || if (mPwmgrInputs.Get(inputNode) ||
formControl->GetType() == NS_FORM_INPUT_PASSWORD) { formControl->ControlType() == NS_FORM_INPUT_PASSWORD) {
isPwmgrInput = true; isPwmgrInput = true;
} }
@@ -1048,7 +1049,7 @@ nsFormFillController::FocusEventDelayedCallback(nsIFormControl* aFormControl)
nsCOMPtr<nsIFormControl> formControl = do_QueryInterface(mFocusedInputNode); nsCOMPtr<nsIFormControl> formControl = do_QueryInterface(mFocusedInputNode);
if (!formControl || formControl != aFormControl || if (!formControl || formControl != aFormControl ||
formControl->GetType() != NS_FORM_INPUT_PASSWORD) { formControl->ControlType() != NS_FORM_INPUT_PASSWORD) {
return; return;
} }