Skip to content

Commit

Permalink
Bug 1351860 - Move mType from HTMLInputElement to nsIFormControl and …
Browse files Browse the repository at this point in the history
…make GetType non-virtual inlined, r=jessica
  • Loading branch information
Olli Pettay authored and Olli Pettay committed Mar 31, 2017
1 parent 61f607b commit cb2dec3
Show file tree
Hide file tree
Showing 37 changed files with 69 additions and 76 deletions.
2 changes: 1 addition & 1 deletion docshell/base/nsDocShellTreeOwner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1557,7 +1557,7 @@ ChromeContextMenuListener::HandleEvent(nsIDOMEvent* aMouseEvent)

nsCOMPtr<nsIFormControl> formControl(do_QueryInterface(node));
if (formControl) {
if (formControl->GetType() == NS_FORM_TEXTAREA) {
if (formControl->ControlType() == NS_FORM_TEXTAREA) {
flags |= nsIContextMenuListener::CONTEXT_TEXT;
flags2 |= nsIContextMenuListener2::CONTEXT_TEXT;
targetDOMnode = node;
Expand Down
2 changes: 1 addition & 1 deletion dom/base/nsContentAreaDragDrop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ DragDataProducer::Produce(DataTransfer* aDataTransfer,
// Note that while <object> elements implement nsIFormControl, we should
// really allow dragging them if they happen to be images.
nsCOMPtr<nsIFormControl> form(do_QueryInterface(mTarget));
if (form && !mIsAltKeyPressed && form->GetType() != NS_FORM_OBJECT) {
if (form && !mIsAltKeyPressed && form->ControlType() != NS_FORM_OBJECT) {
*aCanDrag = false;
return NS_OK;
}
Expand Down
2 changes: 1 addition & 1 deletion dom/base/nsContentUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2763,7 +2763,7 @@ nsContentUtils::GenerateStateKey(nsIContent* aContent,
if (control && htmlFormControls && htmlForms) {

// 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
int32_t index = -1;
Expand Down
2 changes: 1 addition & 1 deletion dom/base/nsCopySupport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -869,7 +869,7 @@ nsCopySupport::FireClipboardEvent(EventMessage aEventMessage,
// check if we are looking at a password input
nsCOMPtr<nsIFormControl> formControl = do_QueryInterface(srcNode);
if (formControl) {
if (formControl->GetType() == NS_FORM_INPUT_PASSWORD) {
if (formControl->ControlType() == NS_FORM_INPUT_PASSWORD) {
return false;
}
}
Expand Down
2 changes: 1 addition & 1 deletion dom/base/nsFocusManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ nsFocusManager::GetRedirectedFocus(nsIContent* aContent)
// For input number, redirect focus to our anonymous text control.
if (aContent->IsHTMLElement(nsGkAtoms::input)) {
bool typeIsNumber =
static_cast<dom::HTMLInputElement*>(aContent)->GetType() ==
static_cast<dom::HTMLInputElement*>(aContent)->ControlType() ==
NS_FORM_INPUT_NUMBER;

if (typeIsNumber) {
Expand Down
2 changes: 1 addition & 1 deletion dom/events/EventStateManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1534,7 +1534,7 @@ EventStateManager::FireContextClick()

if (formCtrl) {
allowedToDispatch = formCtrl->IsTextOrNumberControl(/*aExcludePassword*/ false) ||
formCtrl->GetType() == NS_FORM_INPUT_FILE;
formCtrl->ControlType() == NS_FORM_INPUT_FILE;
}
else if (mGestureDownContent->IsAnyOfHTMLElements(nsGkAtoms::applet,
nsGkAtoms::embed,
Expand Down
2 changes: 1 addition & 1 deletion dom/events/IMEStateManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1035,7 +1035,7 @@ IMEStateManager::SetIMEState(const IMEState& aState,
}
}
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")) :
(formElement ?
NS_LITERAL_STRING("next") : EmptyString()));
Expand Down
3 changes: 1 addition & 2 deletions dom/html/HTMLButtonElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ static const nsAttrValue::EnumTable* kButtonDefaultType = &kButtonTypeTable[2];
// Construction, destruction
HTMLButtonElement::HTMLButtonElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo,
FromParser aFromParser)
: nsGenericHTMLFormElementWithState(aNodeInfo),
mType(kButtonDefaultType->value),
: nsGenericHTMLFormElementWithState(aNodeInfo, kButtonDefaultType->value),
mDisabledChanged(false),
mInInternalActivate(false),
mInhibitStateRestoration(!!(aFromParser & FROM_PARSER_FRAGMENT))
Expand Down
1 change: 0 additions & 1 deletion dom/html/HTMLButtonElement.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ class HTMLButtonElement final : public nsGenericHTMLFormElementWithState,
NS_DECL_NSIDOMHTMLBUTTONELEMENT

// overriden nsIFormControl methods
NS_IMETHOD_(uint32_t) GetType() const override { return mType; }
NS_IMETHOD Reset() override;
NS_IMETHOD SubmitNamesValues(HTMLFormSubmission* aFormSubmission) override;
NS_IMETHOD SaveState() override;
Expand Down
2 changes: 1 addition & 1 deletion dom/html/HTMLFieldSetElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace mozilla {
namespace dom {

HTMLFieldSetElement::HTMLFieldSetElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo)
: nsGenericHTMLFormElement(aNodeInfo)
: nsGenericHTMLFormElement(aNodeInfo, NS_FORM_FIELDSET)
, mElements(nullptr)
, mFirstLegend(nullptr)
, mInvalidElementsCount(0)
Expand Down
1 change: 0 additions & 1 deletion dom/html/HTMLFieldSetElement.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ class HTMLFieldSetElement final : public nsGenericHTMLFormElement,
virtual void RemoveChildAt(uint32_t aIndex, bool aNotify) override;

// nsIFormControl
NS_IMETHOD_(uint32_t) GetType() const override { return NS_FORM_FIELDSET; }
NS_IMETHOD Reset() override;
NS_IMETHOD SubmitNamesValues(HTMLFormSubmission* aFormSubmission) override;
virtual bool IsDisabledForEvents(EventMessage aMessage) override;
Expand Down
2 changes: 1 addition & 1 deletion dom/html/HTMLFormControlsCollection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ HTMLFormControlsCollection::ShouldBeInElements(nsIFormControl* aFormControl)
// <input type=image> elements to the list of form controls in a
// form.

switch (aFormControl->GetType()) {
switch (aFormControl->ControlType()) {
case NS_FORM_BUTTON_BUTTON :
case NS_FORM_BUTTON_RESET :
case NS_FORM_BUTTON_SUBMIT :
Expand Down
16 changes: 8 additions & 8 deletions dom/html/HTMLFormElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1251,7 +1251,7 @@ HTMLFormElement::AddElement(nsGenericHTMLFormElement* aChild,
AssertDocumentOrder(controlList, this);
#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
Expand Down Expand Up @@ -1352,7 +1352,7 @@ HTMLFormElement::RemoveElement(nsGenericHTMLFormElement* aChild,
// Remove it from the radio group if it's a radio button
//
nsresult rv = NS_OK;
if (aChild->GetType() == NS_FORM_INPUT_RADIO) {
if (aChild->ControlType() == NS_FORM_INPUT_RADIO) {
RefPtr<HTMLInputElement> radio =
static_cast<HTMLInputElement*>(aChild);
radio->WillRemoveFromRadioGroup();
Expand Down Expand Up @@ -1818,7 +1818,7 @@ HTMLFormElement::ImplicitSubmissionIsDisabled() const
uint32_t length = mControls->mElements.Length();
for (uint32_t i = 0; i < length && numDisablingControlsFound < 2; ++i) {
if (mControls->mElements[i]->IsSingleLineTextControl(false) ||
mControls->mElements[i]->GetType() == NS_FORM_INPUT_NUMBER) {
mControls->mElements[i]->ControlType() == NS_FORM_INPUT_NUMBER) {
numDisablingControlsFound++;
}
}
Expand Down Expand Up @@ -2024,7 +2024,7 @@ HTMLFormElement::SubmissionCanProceed(Element* aSubmitter)
nsCOMPtr<nsIFormControl> fc = do_QueryInterface(aSubmitter);
MOZ_ASSERT(fc);

uint32_t type = fc->GetType();
uint32_t type = fc->ControlType();
MOZ_ASSERT(type == NS_FORM_INPUT_SUBMIT ||
type == NS_FORM_INPUT_IMAGE ||
type == NS_FORM_BUTTON_SUBMIT,
Expand Down Expand Up @@ -2225,7 +2225,7 @@ HTMLFormElement::GetNextRadioButton(const nsAString& aName,
index = 0;
}
radio = HTMLInputElement::FromContentOrNull(radioGroup->Item(index));
isRadio = radio && radio->GetType() == NS_FORM_INPUT_RADIO;
isRadio = radio && radio->ControlType() == NS_FORM_INPUT_RADIO;
if (!isRadio) {
continue;
}
Expand Down Expand Up @@ -2253,7 +2253,7 @@ HTMLFormElement::WalkRadioGroup(const nsAString& aName,
uint32_t len = GetElementCount();
for (uint32_t i = 0; i < len; i++) {
control = GetElementAt(i);
if (control->GetType() == NS_FORM_INPUT_RADIO) {
if (control->ControlType() == NS_FORM_INPUT_RADIO) {
nsCOMPtr<nsIContent> controlContent = do_QueryInterface(control);
if (controlContent &&
controlContent->AttrValueIs(kNameSpaceID_None, nsGkAtoms::name,
Expand All @@ -2275,7 +2275,7 @@ HTMLFormElement::WalkRadioGroup(const nsAString& aName,
// If it's just a lone radio button, then select it.
nsCOMPtr<nsIFormControl> formControl = do_QueryInterface(item);
if (formControl) {
if (formControl->GetType() == NS_FORM_INPUT_RADIO) {
if (formControl->ControlType() == NS_FORM_INPUT_RADIO) {
aVisitor->Visit(formControl);
}
return NS_OK;
Expand All @@ -2291,7 +2291,7 @@ HTMLFormElement::WalkRadioGroup(const nsAString& aName,
nsCOMPtr<nsIDOMNode> node;
nodeList->Item(i, getter_AddRefs(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)) {
break;
}
Expand Down
5 changes: 2 additions & 3 deletions dom/html/HTMLInputElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1054,8 +1054,7 @@ static nsresult FireEventForAccessibility(nsIDOMHTMLInputElement* aTarget,

HTMLInputElement::HTMLInputElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo,
FromParser aFromParser, FromClone aFromClone)
: nsGenericHTMLFormElementWithState(aNodeInfo)
, mType(kInputDefaultType->value)
: nsGenericHTMLFormElementWithState(aNodeInfo, kInputDefaultType->value)
, mAutocompleteAttrState(nsContentUtils::eAutocompleteAttrState_Unknown)
, mDisabledChanged(false)
, mValueChanged(false)
Expand Down Expand Up @@ -3514,7 +3513,7 @@ HTMLInputElement::Focus(ErrorResult& aError)
// See if the child is a button control.
nsCOMPtr<nsIFormControl> formCtrl =
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);
nsIFocusManager* fm = nsFocusManager::GetFocusManager();
if (fm && element) {
Expand Down
7 changes: 0 additions & 7 deletions dom/html/HTMLInputElement.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@ class HTMLInputElement final : public nsGenericHTMLFormElementWithState,
NS_IMETHOD SetUserInput(const nsAString& aInput) override;

// Overriden nsIFormControl methods
NS_IMETHOD_(uint32_t) GetType() const override { return mType; }
NS_IMETHOD Reset() override;
NS_IMETHOD SubmitNamesValues(HTMLFormSubmission* aFormSubmission) override;
NS_IMETHOD SaveState() override;
Expand Down Expand Up @@ -1609,12 +1608,6 @@ class HTMLInputElement final : public nsGenericHTMLFormElementWithState,
// Milliseconds in a day.
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;
bool mDisabledChanged : 1;
bool mValueChanged : 1;
Expand Down
2 changes: 1 addition & 1 deletion dom/html/HTMLObjectElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ namespace dom {

HTMLObjectElement::HTMLObjectElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo,
FromParser aFromParser)
: nsGenericHTMLFormElement(aNodeInfo),
: nsGenericHTMLFormElement(aNodeInfo, NS_FORM_OBJECT),
mIsDoneAddingChildren(!aFromParser)
{
RegisterActivityObserver();
Expand Down
5 changes: 0 additions & 5 deletions dom/html/HTMLObjectElement.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,6 @@ class HTMLObjectElement final : public nsGenericHTMLFormElement
virtual IMEState GetDesiredIMEState() override;

// Overriden nsIFormControl methods
NS_IMETHOD_(uint32_t) GetType() const override
{
return NS_FORM_OBJECT;
}

NS_IMETHOD Reset() override;
NS_IMETHOD SubmitNamesValues(HTMLFormSubmission *aFormSubmission) override;

Expand Down
2 changes: 1 addition & 1 deletion dom/html/HTMLOutputElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace dom {

HTMLOutputElement::HTMLOutputElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo,
FromParser aFromParser)
: nsGenericHTMLFormElement(aNodeInfo)
: nsGenericHTMLFormElement(aNodeInfo, NS_FORM_OUTPUT)
, mValueModeFlag(eModeDefault)
, mIsDoneAddingChildren(!aFromParser)
{
Expand Down
1 change: 0 additions & 1 deletion dom/html/HTMLOutputElement.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ class HTMLOutputElement final : public nsGenericHTMLFormElement,
NS_DECL_ISUPPORTS_INHERITED

// nsIFormControl
NS_IMETHOD_(uint32_t) GetType() const override { return NS_FORM_OUTPUT; }
NS_IMETHOD Reset() override;
NS_IMETHOD SubmitNamesValues(HTMLFormSubmission* aFormSubmission) override;

Expand Down
2 changes: 1 addition & 1 deletion dom/html/HTMLSelectElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ SafeOptionListMutation::~SafeOptionListMutation()

HTMLSelectElement::HTMLSelectElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo,
FromParser aFromParser)
: nsGenericHTMLFormElementWithState(aNodeInfo),
: nsGenericHTMLFormElementWithState(aNodeInfo, NS_FORM_SELECT),
mOptions(new HTMLOptionsCollection(this)),
mAutocompleteAttrState(nsContentUtils::eAutocompleteAttrState_Unknown),
mIsDoneAddingChildren(!aFromParser),
Expand Down
1 change: 0 additions & 1 deletion dom/html/HTMLSelectElement.h
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,6 @@ class HTMLSelectElement final : public nsGenericHTMLFormElementWithState,
virtual void RemoveChildAt(uint32_t aIndex, bool aNotify) override;

// Overriden nsIFormControl methods
NS_IMETHOD_(uint32_t) GetType() const override { return NS_FORM_SELECT; }
NS_IMETHOD Reset() override;
NS_IMETHOD SubmitNamesValues(HTMLFormSubmission* aFormSubmission) override;
NS_IMETHOD SaveState() override;
Expand Down
2 changes: 1 addition & 1 deletion dom/html/HTMLTextAreaElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ namespace dom {

HTMLTextAreaElement::HTMLTextAreaElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo,
FromParser aFromParser)
: nsGenericHTMLFormElementWithState(aNodeInfo),
: nsGenericHTMLFormElementWithState(aNodeInfo, NS_FORM_TEXTAREA),
mValueChanged(false),
mLastValueChangeWasInteractive(false),
mHandlingSelect(false),
Expand Down
1 change: 0 additions & 1 deletion dom/html/HTMLTextAreaElement.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ class HTMLTextAreaElement final : public nsGenericHTMLFormElementWithState,
NS_IMETHOD SetUserInput(const nsAString& aInput) override;

// nsIFormControl
NS_IMETHOD_(uint32_t) GetType() const override { return NS_FORM_TEXTAREA; }
NS_IMETHOD Reset() override;
NS_IMETHOD SubmitNamesValues(HTMLFormSubmission* aFormSubmission) override;
NS_IMETHOD SaveState() override;
Expand Down
2 changes: 1 addition & 1 deletion dom/html/RadioNodeList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ HTMLInputElement*
GetAsRadio(nsIContent* 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 nullptr;
Expand Down
14 changes: 8 additions & 6 deletions dom/html/nsGenericHTMLElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ nsGenericHTMLElement::Spellcheck()
}

// Is this a multiline plaintext input?
int32_t controlType = formControl->GetType();
int32_t controlType = formControl->ControlType();
if (controlType == NS_FORM_TEXTAREA) {
return true; // Spellchecked by default
}
Expand Down Expand Up @@ -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)
, nsIFormControl(aType)
, mForm(nullptr)
, mFieldSet(nullptr)
{
Expand Down Expand Up @@ -2090,7 +2092,7 @@ nsGenericHTMLFormElement::ForgetFieldSet(nsIContent* aFieldset)
bool
nsGenericHTMLFormElement::CanBeDisabled() const
{
int32_t type = GetType();
int32_t type = ControlType();
// It's easier to test the types that _cannot_ be disabled
return
type != NS_FORM_OBJECT &&
Expand Down Expand Up @@ -2403,7 +2405,7 @@ bool
nsGenericHTMLFormElement::IsLabelable() const
{
// 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) ||
type & NS_FORM_BUTTON_ELEMENT ||
// type == NS_FORM_KEYGEN ||
Expand Down Expand Up @@ -2730,9 +2732,9 @@ nsGenericHTMLElement::ChangeEditableState(int32_t aChange)
//----------------------------------------------------------------------

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);
}
Expand Down
6 changes: 4 additions & 2 deletions dom/html/nsGenericHTMLElement.h
Original file line number Diff line number Diff line change
Expand Up @@ -1208,7 +1208,8 @@ class nsGenericHTMLFormElement : public nsGenericHTMLElement,
public nsIFormControl
{
public:
explicit nsGenericHTMLFormElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo);
nsGenericHTMLFormElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo,
uint8_t aType);

NS_DECL_ISUPPORTS_INHERITED

Expand Down Expand Up @@ -1368,7 +1369,8 @@ class nsGenericHTMLFormElement : public nsGenericHTMLElement,
class nsGenericHTMLFormElementWithState : public nsGenericHTMLFormElement
{
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
Expand Down
Loading

0 comments on commit cb2dec3

Please sign in to comment.