Bug 1373798 part 1. Stop calling SetHasDirAuto/ClearHasDirAuto in input element code. r=mystor draft
authorBoris Zbarsky <bzbarsky@mit.edu>
Mon, 19 Jun 2017 14:41:48 -0400
changeset 596741 c71739095e4b65e7db10f6174a875891f97738d6
parent 596083 316014448e427486cce211217e2aee2f18ee3d69
child 596742 b2e588d6aab951eeb46b5b1e9321c82c83e0afa4
push id64748
push userbzbarsky@mozilla.com
push dateMon, 19 Jun 2017 18:45:34 +0000
reviewersmystor
bugs1373798
milestone56.0a1
Bug 1373798 part 1. Stop calling SetHasDirAuto/ClearHasDirAuto in input element code. r=mystor The old setup unset the HasDirAuto flag when changing the "dir" attr away from the value "auto", and reset it when setting it to "auto", before calling SetDirectionalityFromValue. But SetDirectionalityFromValue doesn't depend on the HasDirAuto flag, and that flag is set correctly for us by nsGenericElement, so we don't have to manage it ourselves at all. The callers outside BeforeSetAttr/AfterSetAttr just preserved the flag value, so there's no behavior change at all for them. MozReview-Commit-ID: AC8uV3cOtH2
dom/html/HTMLInputElement.cpp
dom/html/HTMLInputElement.h
--- a/dom/html/HTMLInputElement.cpp
+++ b/dom/html/HTMLInputElement.cpp
@@ -1366,20 +1366,16 @@ HTMLInputElement::BeforeSetAttr(int32_t 
 
         LoadImage(aValue->String(), true, aNotify, eImageLoadType_Normal);
       } else {
         // Null value means the attr got unset; drop the image
         CancelImageRequests(aNotify);
       }
     } else if (aNotify && aName == nsGkAtoms::disabled) {
       mDisabledChanged = true;
-    } else if (aName == nsGkAtoms::dir &&
-               AttrValueIs(kNameSpaceID_None, nsGkAtoms::dir,
-                           nsGkAtoms::_auto, eIgnoreCase)) {
-      SetDirectionIfAuto(false, aNotify);
     } else if (mType == NS_FORM_INPUT_RADIO && aName == nsGkAtoms::required) {
       nsCOMPtr<nsIRadioGroupContainer> container = GetRadioGroupContainer();
 
       if (container &&
           ((aValue && !HasAttr(aNameSpaceID, aName)) ||
            (!aValue && HasAttr(aNameSpaceID, aName)))) {
         nsAutoString name;
         GetAttr(kNameSpaceID_None, nsGkAtoms::name, name);
@@ -1497,17 +1493,17 @@ HTMLInputElement::AfterSetAttr(int32_t a
       // See corresponding @max comment
       UpdateStepMismatchValidityState();
       MOZ_ASSERT(!mDoneCreating ||
                  mType != NS_FORM_INPUT_RANGE ||
                  !GetValidityState(VALIDITY_STATE_RANGE_UNDERFLOW),
                  "HTML5 spec does not allow underflow for type=range");
     } else if (aName == nsGkAtoms::dir &&
                aValue && aValue->Equals(nsGkAtoms::_auto, eIgnoreCase)) {
-      SetDirectionIfAuto(true, aNotify);
+      SetDirectionFromValue(aNotify);
     } else if (aName == nsGkAtoms::lang) {
       if (mType == NS_FORM_INPUT_NUMBER) {
         // Update the value that is displayed to the user to the new locale:
         nsAutoString value;
         GetNonFileValueInternal(value);
         nsNumberControlFrame* numberControlFrame =
           do_QueryFrame(GetPrimaryFrame());
         if (numberControlFrame) {
@@ -4861,17 +4857,19 @@ HTMLInputElement::BindToTree(nsIDocument
 
   // Add radio to document if we don't have a form already (if we do it's
   // already been added into that group)
   if (aDocument && !mForm && mType == NS_FORM_INPUT_RADIO) {
     AddedToRadioGroup();
   }
 
   // Set direction based on value if dir=auto
-  SetDirectionIfAuto(HasDirAuto(), false);
+  if (HasDirAuto()) {
+    SetDirectionFromValue(false);
+  }
 
   // An element can't suffer from value missing if it is not in a document.
   // We have to check if we suffer from that as we are now in a document.
   UpdateValueMissingValidityState();
 
   // If there is a disabled fieldset in the parent chain, the element is now
   // barred from constraint validation and can't suffer from value missing
   // (call done before).
@@ -6299,27 +6297,22 @@ HTMLInputElement::SetDefaultValueAsValue
   nsAutoString resetVal;
   GetDefaultValue(resetVal);
 
   // SetValueInternal is going to sanitize the value.
   return SetValueInternal(resetVal, nsTextEditorState::eSetValue_Internal);
 }
 
 void
-HTMLInputElement::SetDirectionIfAuto(bool aAuto, bool aNotify)
-{
-  if (aAuto) {
-    SetHasDirAuto();
-    if (IsSingleLineTextControl(true)) {
-      nsAutoString value;
-      GetValue(value, CallerType::System);
-      SetDirectionalityFromValue(this, value, aNotify);
-    }
-  } else {
-    ClearHasDirAuto();
+HTMLInputElement::SetDirectionFromValue(bool aNotify)
+{
+  if (IsSingleLineTextControl(true)) {
+    nsAutoString value;
+    GetValue(value, CallerType::System);
+    SetDirectionalityFromValue(this, value, aNotify);
   }
 }
 
 NS_IMETHODIMP
 HTMLInputElement::Reset()
 {
   // We should be able to reset all dirty flags regardless of the type.
   SetCheckedChanged(false);
@@ -7742,17 +7735,17 @@ HTMLInputElement::InitializeKeyboardEven
 NS_IMETHODIMP_(void)
 HTMLInputElement::OnValueChanged(bool aNotify, bool aWasInteractiveUserChange)
 {
   mLastValueChangeWasInteractive = aWasInteractiveUserChange;
 
   UpdateAllValidityStates(aNotify);
 
   if (HasDirAuto()) {
-    SetDirectionIfAuto(true, aNotify);
+    SetDirectionFromValue(aNotify);
   }
 
   // :placeholder-shown pseudo-class may change when the value changes.
   // However, we don't want to waste cycles if the state doesn't apply.
   if (PlaceholderApplies() &&
       HasAttr(kNameSpaceID_None, nsGkAtoms::placeholder)) {
     UpdateState(aNotify);
   }
--- a/dom/html/HTMLInputElement.h
+++ b/dom/html/HTMLInputElement.h
@@ -1124,17 +1124,17 @@ protected:
 
   /**
    * Set the current default value to the value of the input element.
    * @note You should not call this method if GetValueMode() doesn't return
    * VALUE_MODE_VALUE.
    */
   nsresult SetDefaultValueAsValue();
 
-  virtual void SetDirectionIfAuto(bool aAuto, bool aNotify);
+  void SetDirectionFromValue(bool aNotify);
 
   /**
    * Return if an element should have a specific validity UI
    * (with :-moz-ui-invalid and :-moz-ui-valid pseudo-classes).
    *
    * @return Whether the element should have a validity UI.
    */
   bool ShouldShowValidityUI() const {