Commit 9f8bfb29 authored by Jonathan Watt's avatar Jonathan Watt
Browse files

Bug 638293 - When the value of <input type=number> changes, keep its anonymous...

Bug 638293 - When the value of <input type=number> changes, keep its anonymous text input field child in sync as appropriate. r=smaug
parent 7bd8b8d0
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -2696,6 +2696,14 @@ HTMLInputElement::SetValueInternal(const nsAString& aValue,
          SetValueChanged(true);
        }
        OnValueChanged(!mParserCreating);

        if (mType == NS_FORM_INPUT_NUMBER) {
          nsNumberControlFrame* numberControlFrame =
            do_QueryFrame(GetPrimaryFrame());
          if (numberControlFrame) {
            numberControlFrame->UpdateForValueChange(value);
          }
        }
      }

      // Call parent's SetAttr for color input so its control frame is notified
+15 −0
Original line number Diff line number Diff line
@@ -223,6 +223,11 @@ nsNumberControlFrame::CreateAnonymousContent(nsTArray<ContentInfo>& aElements)
  mTextField->SetAttr(kNameSpaceID_None, nsGkAtoms::type,
                      NS_LITERAL_STRING("text"), PR_FALSE);

  // Initialize the text field value:
  nsAutoString value;
  HTMLInputElement::FromContent(mContent)->GetValue(value);
  mTextField->SetAttr(kNameSpaceID_None, nsGkAtoms::value, value, false);

  if (mContent->AsElement()->State().HasState(NS_EVENT_STATE_FOCUS)) {
    // We don't want to focus the frame but the text field.
    nsIFocusManager* fm = nsFocusManager::GetFocusManager();
@@ -277,3 +282,13 @@ nsNumberControlFrame::AppendAnonymousContentTo(nsBaseContentList& aElements,
  // Only one direct anonymous child:
  aElements.MaybeAppendElement(mOuterWrapper);
}

void
nsNumberControlFrame::UpdateForValueChange(const nsAString& aValue)
{
  // We need to update the value of our anonymous text control here. Note that
  // this must be its value, and not its 'value' attribute (the default value),
  // since the default value is ignored once a user types into the text
  // control.
  HTMLInputElement::FromContent(mTextField)->SetValue(aValue);
}
+6 −0
Original line number Diff line number Diff line
@@ -65,6 +65,12 @@ public:
      ~(nsIFrame::eReplaced | nsIFrame::eReplacedContainsBlock));
  }

  /**
   * When our HTMLInputElement's value changes, it calls this method to tell
   * us to sync up our anonymous text input field child.
   */
  void UpdateForValueChange(const nsAString& aValue);

  HTMLInputElement* GetAnonTextControl();

private:
+3 −0
Original line number Diff line number Diff line
@@ -14,6 +14,9 @@ skip-if(!Android&&!B2G) == number-same-as-text-unthemed.html number-same-as-text
fuzzy-if(/^Windows\x20NT\x205\.1/.test(http.oscpu),64,4) fuzzy-if(cocoaWidget,63,4) == to-number-from-other-type-unthemed-1.html to-number-from-other-type-unthemed-1-ref.html
== from-number-to-other-type-unthemed-1.html from-number-to-other-type-unthemed-1-ref.html

# dynamic value changes:
== show-value.html show-value-ref.html

# focus
fails-if(B2G) needs-focus == focus-handling.html focus-handling-ref.html # bug 940760
+26 −0
Original line number Diff line number Diff line
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">                                                         
    <style>                                                                        
                                                                                   
input {                                                                            
  -moz-appearance: none;                                                           
}                                                                                  
                                                                                   
    </style>                                                                       
  </head>
  <body>
    <input value='42'><br>
    <input value='42'><br>
    <input value='42'><br>
    <input value='42'><br>
    <input value='42'><br>
    <form>
      <input value='42'>
    </form>
    <!-- div to cover spin box area for type=number to type=text comparison -->
    <div style="display:block; position:absolute; background-color:black; width:200px; height:400px; top:0px; left:100px;">
  </body>
</html>
Loading