Bug 1439751 - Cleanup HTMLInputElement some more. r?qdot draft
authorAdrian Wielgosik <adrian.wielgosik@gmail.com>
Tue, 20 Feb 2018 23:11:27 +0100
changeset 757965 4d1eaec5ca2f0007b494db920a73d0e0110074f3
parent 757964 d22940dcef43957dca515e1f96ff929531f34ff5
push id99901
push userbmo:adrian.wielgosik@gmail.com
push dateWed, 21 Feb 2018 17:42:18 +0000
reviewersqdot
bugs1439751
milestone60.0a1
Bug 1439751 - Cleanup HTMLInputElement some more. r?qdot MozReview-Commit-ID: APunYKaGM8I
dom/html/HTMLInputElement.cpp
dom/html/HTMLInputElement.h
--- a/dom/html/HTMLInputElement.cpp
+++ b/dom/html/HTMLInputElement.cpp
@@ -13,17 +13,16 @@
 #include "mozilla/dom/Directory.h"
 #include "mozilla/dom/DOMPrefs.h"
 #include "mozilla/dom/HTMLFormSubmission.h"
 #include "mozilla/dom/FileSystemUtils.h"
 #include "mozilla/dom/GetFilesHelper.h"
 #include "nsAttrValueInlines.h"
 #include "nsCRTGlue.h"
 
-#include "nsIDOMHTMLInputElement.h"
 #include "nsITextControlElement.h"
 #include "nsIDOMNSEditableElement.h"
 #include "nsIRadioVisitor.h"
 #include "InputType.h"
 
 #include "HTMLFormSubmissionConstants.h"
 #include "mozilla/Telemetry.h"
 #include "nsIControllers.h"
@@ -253,23 +252,23 @@ public:
     Unused << NS_WARN_IF(NS_FAILED(DispatchEvents()));
   }
 
   nsresult
   DispatchEvents()
   {
     nsresult rv = NS_OK;
     rv = nsContentUtils::DispatchTrustedEvent(mInputElement->OwnerDoc(),
-                                              static_cast<nsIDOMHTMLInputElement*>(mInputElement.get()),
+                                              static_cast<Element*>(mInputElement.get()),
                                               NS_LITERAL_STRING("input"), true,
                                               false);
     NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "DispatchTrustedEvent failed");
 
     rv = nsContentUtils::DispatchTrustedEvent(mInputElement->OwnerDoc(),
-                                              static_cast<nsIDOMHTMLInputElement*>(mInputElement.get()),
+                                              static_cast<Element*>(mInputElement.get()),
                                               NS_LITERAL_STRING("change"), true,
                                               false);
 
     return rv;
   }
 
 private:
   RefPtr<HTMLInputElement> mInputElement;
@@ -755,17 +754,17 @@ nsColorPickerShownCallback::UpdateIntern
     if (!oldValue.Equals(newValue)) {
       valueChanged = true;
     }
   }
 
   if (valueChanged) {
     mValueChanged = true;
     return nsContentUtils::DispatchTrustedEvent(mInput->OwnerDoc(),
-                                                static_cast<nsIDOMHTMLInputElement*>(mInput.get()),
+                                                static_cast<Element*>(mInput.get()),
                                                 NS_LITERAL_STRING("input"), true,
                                                 false);
   }
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
@@ -789,17 +788,17 @@ nsColorPickerShownCallback::Done(const n
   mInput->PickerClosed();
 
   if (!aColor.IsEmpty()) {
     UpdateInternal(aColor, false);
   }
 
   if (mValueChanged) {
     rv = nsContentUtils::DispatchTrustedEvent(mInput->OwnerDoc(),
-                                              static_cast<nsIDOMHTMLInputElement*>(mInput.get()),
+                                              static_cast<Element*>(mInput.get()),
                                               NS_LITERAL_STRING("change"), true,
                                               false);
   }
 
   return rv;
 }
 
 NS_IMPL_ISUPPORTS(nsColorPickerShownCallback, nsIColorPickerShownCallback)
@@ -1081,17 +1080,17 @@ UploadLastDir::Observe(nsISupports* aSub
     if (contentPrefService)
       contentPrefService->RemoveByName(CPS_PREF_NAME, nullptr, nullptr);
   }
   return NS_OK;
 }
 
 #ifdef ACCESSIBILITY
 //Helper method
-static nsresult FireEventForAccessibility(nsIDOMHTMLInputElement* aTarget,
+static nsresult FireEventForAccessibility(HTMLInputElement* aTarget,
                                           nsPresContext* aPresContext,
                                           EventMessage aEventMessage);
 #endif
 
 nsTextEditorState* HTMLInputElement::sCachedTextEditorState = nullptr;
 bool HTMLInputElement::sShutdown = false;
 
 /* static */ void
@@ -2382,44 +2381,44 @@ void
 HTMLInputElement::OpenDateTimePicker(const DateTimeValue& aInitialValue)
 {
   if (NS_WARN_IF(!IsDateTimeInputType(mType))) {
     return;
   }
 
   mDateTimeInputBoxValue = new DateTimeValue(aInitialValue);
   nsContentUtils::DispatchChromeEvent(OwnerDoc(),
-                                      static_cast<nsIDOMHTMLInputElement*>(this),
+                                      static_cast<Element*>(this),
                                       NS_LITERAL_STRING("MozOpenDateTimePicker"),
                                       true, true);
 }
 
 void
 HTMLInputElement::UpdateDateTimePicker(const DateTimeValue& aValue)
 {
   if (NS_WARN_IF(!IsDateTimeInputType(mType))) {
     return;
   }
 
   mDateTimeInputBoxValue = new DateTimeValue(aValue);
   nsContentUtils::DispatchChromeEvent(OwnerDoc(),
-                                      static_cast<nsIDOMHTMLInputElement*>(this),
+                                      static_cast<Element*>(this),
                                       NS_LITERAL_STRING("MozUpdateDateTimePicker"),
                                       true, true);
 }
 
 void
 HTMLInputElement::CloseDateTimePicker()
 {
   if (NS_WARN_IF(!IsDateTimeInputType(mType))) {
     return;
   }
 
   nsContentUtils::DispatchChromeEvent(OwnerDoc(),
-                                      static_cast<nsIDOMHTMLInputElement*>(this),
+                                      static_cast<Element*>(this),
                                       NS_LITERAL_STRING("MozCloseDateTimePicker"),
                                       true, true);
 }
 
 void
 HTMLInputElement::SetFocusState(bool aIsFocused)
 {
   if (NS_WARN_IF(!IsDateTimeInputType(mType))) {
@@ -2503,17 +2502,17 @@ HTMLInputElement::SetUserInput(const nsA
       SetValueInternal(aValue,
         nsTextEditorState::eSetValue_BySetUserInput |
         nsTextEditorState::eSetValue_Notify|
         nsTextEditorState::eSetValue_MoveCursorToEndIfValueChanged);
     NS_ENSURE_SUCCESS(rv, rv);
   }
 
   nsContentUtils::DispatchTrustedEvent(OwnerDoc(),
-                                       static_cast<nsIDOMHTMLInputElement*>(this),
+                                       static_cast<Element*>(this),
                                        NS_LITERAL_STRING("input"), true,
                                        true);
 
   // If this element is not currently focused, it won't receive a change event for this
   // update through the normal channels. So fire a change event immediately, instead.
   if (!ShouldBlur(this)) {
     FireChangeEventIfNeeded();
   }
@@ -3171,24 +3170,23 @@ HTMLInputElement::DoSetChecked(bool aChe
   // the currently selected radio.
   SetCheckedInternal(false, aNotify);
 }
 
 void
 HTMLInputElement::RadioSetChecked(bool aNotify)
 {
   // Find the selected radio button so we can deselect it
-  nsCOMPtr<nsIDOMHTMLInputElement> currentlySelected = GetSelectedRadioButton();
+  HTMLInputElement* currentlySelected = GetSelectedRadioButton();
 
   // Deselect the currently selected radio button
   if (currentlySelected) {
     // Pass true for the aNotify parameter since the currently selected
     // button is already in the document.
-    static_cast<HTMLInputElement*>(currentlySelected.get())
-      ->SetCheckedInternal(false, true);
+    currentlySelected->SetCheckedInternal(false, true);
   }
 
   // Let the group know that we are now the One True Radio Button
   nsIRadioGroupContainer* container = GetRadioGroupContainer();
   if (container) {
     nsAutoString name;
     GetAttr(kNameSpaceID_None, nsGkAtoms::name, name);
     container->SetCurrentRadioButton(name, this);
@@ -3215,29 +3213,29 @@ HTMLInputElement::GetRadioGroupContainer
   if (mForm) {
     return mForm;
   }
 
   //XXXsmaug It isn't clear how this should work in Shadow DOM.
   return static_cast<nsDocument*>(GetUncomposedDoc());
 }
 
-already_AddRefed<nsIDOMHTMLInputElement>
+HTMLInputElement*
 HTMLInputElement::GetSelectedRadioButton() const
 {
   nsIRadioGroupContainer* container = GetRadioGroupContainer();
   if (!container) {
     return nullptr;
   }
 
   nsAutoString name;
   GetAttr(kNameSpaceID_None, nsGkAtoms::name, name);
 
-  nsCOMPtr<nsIDOMHTMLInputElement> selected = container->GetCurrentRadioButton(name);
-  return selected.forget();
+  HTMLInputElement* selected = container->GetCurrentRadioButton(name);
+  return selected;
 }
 
 nsresult
 HTMLInputElement::MaybeSubmitForm(nsPresContext* aPresContext)
 {
   if (!mForm) {
     // Nothing to do here.
     return NS_OK;
@@ -3602,18 +3600,18 @@ HTMLInputElement::GetEventTargetParent(E
           originalCheckedValue = Checked();
           DoSetChecked(!originalCheckedValue, true, true);
           mCheckedIsToggled = true;
         }
         break;
 
       case NS_FORM_INPUT_RADIO:
         {
-          nsCOMPtr<nsIDOMHTMLInputElement> selectedRadioButton = GetSelectedRadioButton();
-          aVisitor.mItemData = selectedRadioButton;
+          HTMLInputElement* selectedRadioButton = GetSelectedRadioButton();
+          aVisitor.mItemData = static_cast<Element*>(selectedRadioButton);
 
           originalCheckedValue = mChecked;
           if (!originalCheckedValue) {
             DoSetChecked(true, true, true);
             mCheckedIsToggled = true;
           }
         }
         break;
@@ -3948,17 +3946,17 @@ HTMLInputElement::SetValueOfRangeForUser
                         nsTextEditorState::eSetValue_Notify);
   nsRangeFrame* frame = do_QueryFrame(GetPrimaryFrame());
   if (frame) {
     frame->UpdateForValueChange();
   }
 
   if (GetValueAsDecimal() != oldValue) {
     nsContentUtils::DispatchTrustedEvent(OwnerDoc(),
-                                         static_cast<nsIDOMHTMLInputElement*>(this),
+                                         static_cast<Element*>(this),
                                          NS_LITERAL_STRING("input"), true,
                                          false);
   }
 }
 
 void
 HTMLInputElement::StartNumberControlSpinnerSpin()
 {
@@ -4046,17 +4044,17 @@ HTMLInputElement::StepNumberControlForUs
   nsAutoString newVal;
   mInputType->ConvertNumberToString(newValue, newVal);
   // TODO: What should we do if SetValueInternal fails?  (The allocation
   // is small, so we should be fine here.)
   SetValueInternal(newVal, nsTextEditorState::eSetValue_BySetUserInput |
                            nsTextEditorState::eSetValue_Notify);
 
   nsContentUtils::DispatchTrustedEvent(OwnerDoc(),
-                                       static_cast<nsIDOMHTMLInputElement*>(this),
+                                       static_cast<Element*>(this),
                                        NS_LITERAL_STRING("input"), true,
                                        false);
 }
 
 static bool
 SelectTextFieldOnFocus()
 {
   if (!gSelectTextFieldOnFocus) {
@@ -4258,21 +4256,21 @@ HTMLInputElement::PostHandleEvent(EventC
         bool originalIndeterminateValue =
           !!(aVisitor.mItemFlags & NS_ORIGINAL_INDETERMINATE_VALUE);
         SetIndeterminateInternal(originalIndeterminateValue, false);
         DoSetChecked(originalCheckedValue, true, true);
       }
     } else {
       // Fire input event and then change event.
       nsContentUtils::DispatchTrustedEvent<InternalEditorInputEvent>
-        (OwnerDoc(), static_cast<nsIDOMHTMLInputElement*>(this),
+        (OwnerDoc(), static_cast<Element*>(this),
          eEditorInput, true, false);
 
       nsContentUtils::DispatchTrustedEvent<WidgetEvent>
-        (OwnerDoc(), static_cast<nsIDOMHTMLInputElement*>(this),
+        (OwnerDoc(), static_cast<Element*>(this),
          eFormChange, true, false);
 #ifdef ACCESSIBILITY
       // Fire an event to notify accessibility
       if (mType == NS_FORM_INPUT_CHECKBOX) {
         FireEventForAccessibility(this, aVisitor.mPresContext,
                                   eFormCheckboxStateChange);
       } else {
         FireEventForAccessibility(this, aVisitor.mPresContext,
@@ -6184,23 +6182,23 @@ HTMLInputElement::SetSelectionDirection(
 
   nsTextEditorState* state = GetEditorState();
   MOZ_ASSERT(state, "SupportsTextSelection came back true!");
   state->SetSelectionDirection(aDirection, aRv);
 }
 
 #ifdef ACCESSIBILITY
 /*static*/ nsresult
-FireEventForAccessibility(nsIDOMHTMLInputElement* aTarget,
+FireEventForAccessibility(HTMLInputElement* aTarget,
                           nsPresContext* aPresContext,
                           EventMessage aEventMessage)
 {
-  nsCOMPtr<mozilla::dom::Element> element = do_QueryInterface(aTarget);
+  Element* element = static_cast<Element*>(aTarget);
   return nsContentUtils::DispatchTrustedEvent<WidgetEvent>
-    (element->OwnerDoc(), aTarget, aEventMessage, true, true);
+    (element->OwnerDoc(), element, aEventMessage, true, true);
 }
 #endif
 
 void
 HTMLInputElement::UpdateApzAwareFlag()
 {
 #if !defined(ANDROID) && !defined(XP_MACOSX)
   if ((mType == NS_FORM_INPUT_NUMBER) || (mType == NS_FORM_INPUT_RANGE)) {
@@ -6494,17 +6492,17 @@ HTMLInputElement::IntrinsicState() const
     }
 
     // Check current indeterminate state (:indeterminate)
     if (mType == NS_FORM_INPUT_CHECKBOX && mIndeterminate) {
       state |= NS_EVENT_STATE_INDETERMINATE;
     }
 
     if (mType == NS_FORM_INPUT_RADIO) {
-      nsCOMPtr<nsIDOMHTMLInputElement> selected = GetSelectedRadioButton();
+      HTMLInputElement* selected = GetSelectedRadioButton();
       bool indeterminate = !selected && !mChecked;
 
       if (indeterminate) {
         state |= NS_EVENT_STATE_INDETERMINATE;
       }
     }
 
     // Check whether we are the default checked element (:default)
@@ -7203,17 +7201,17 @@ HTMLInputElement::UpdateTooShortValidity
 
 void
 HTMLInputElement::UpdateValueMissingValidityStateForRadio(bool aIgnoreSelf)
 {
   MOZ_ASSERT(mType == NS_FORM_INPUT_RADIO,
              "This should be called only for radio input types");
 
   bool notify = mDoneCreating;
-  nsCOMPtr<nsIDOMHTMLInputElement> selection = GetSelectedRadioButton();
+  HTMLInputElement* selection = GetSelectedRadioButton();
 
   aIgnoreSelf = aIgnoreSelf || !IsMutable();
 
   // If there is no selection, that might mean the radio is not in a group.
   // In that case, we can look for the checked state of the radio.
   bool selected = selection || (!aIgnoreSelf && mChecked);
   bool required = !aIgnoreSelf && IsRequired();
   bool valueMissing = false;
--- a/dom/html/HTMLInputElement.h
+++ b/dom/html/HTMLInputElement.h
@@ -292,17 +292,17 @@ public:
 
  /**
    * Helper function returning the currently selected button in the radio group.
    * Returning null if the element is not a button or if there is no selectied
    * button in the group.
    *
    * @return the selected button (or null).
    */
-  already_AddRefed<nsIDOMHTMLInputElement> GetSelectedRadioButton() const;
+  HTMLInputElement* GetSelectedRadioButton() const;
 
   virtual nsresult Clone(mozilla::dom::NodeInfo *aNodeInfo, nsINode **aResult,
                          bool aPreallocateChildren) const override;
 
   NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(HTMLInputElement,
                                            nsGenericHTMLFormElementWithState)
 
   static UploadLastDir* gUploadLastDir;