Commit 7bd8b8d0 authored by Jonathan Watt's avatar Jonathan Watt
Browse files

Bug 665884 - Redirect focus from <input type=number> to its anonymous text...

Bug 665884 - Redirect focus from <input type=number> to its anonymous text control, and get autofocus working. r=dbaron
parent f8dfb4d3
Loading
Loading
Loading
Loading
+17 −0
Original line number Diff line number Diff line
<!DOCTYPE html>
<html class="reftest-wait">
  <!-- In this case we're using reftest-wait to make sure the test doesn't         
       get snapshotted before it's been focused. We're not testing                 
       invalidation so we don't need to listen for MozReftestInvalidate.           
  -->                                                                              
  <head>
    <meta charset="utf-8">
  </head>
  <body onload="document.getElementsByTagName('input')[0].focus();">
    <input onfocus="document.documentElement.removeAttribute('class');"
           style="-moz-appearance: none;">
    <!-- 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:100px; top:0px; left:100px;">
  </body>
</html>
+26 −0
Original line number Diff line number Diff line
<!DOCTYPE html>
<html class="reftest-wait">
  <!-- In this case we're using reftest-wait to make sure the test doesn't
       get snapshotted before it's been focused. We're not testing
       invalidation so we don't need to listen for MozReftestInvalidate.
  -->
  <head>
    <meta charset="utf-8">
    <script>

function focusHandler() {
  setTimeout(function() {
    document.documentElement.removeAttribute('class');
  }, 0);
}

    </script>
  </head>
  <body>
    <input type="number" autofocus onfocus="focusHandler();"
           style="-moz-appearance: none;">
    <!-- 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:100px; top:0px; left:100px;">
  </body>
</html>
+1 −0
Original line number Diff line number Diff line
needs-focus == input-load.html input-ref.html
needs-focus == input-create.html input-ref.html
fails-if(Android) needs-focus == input-number.html input-number-ref.html # bug 940764
needs-focus == button-load.html button-ref.html
needs-focus == button-create.html button-ref.html
needs-focus == textarea-load.html textarea-ref.html
+33 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@
#include "nsIControllers.h"
#include "nsIStringBundle.h"
#include "nsFocusManager.h"
#include "nsNumberControlFrame.h"
#include "nsPIDOMWindow.h"
#include "nsContentCID.h"
#include "nsIComponentManager.h"
@@ -2960,9 +2961,41 @@ HTMLInputElement::SetCheckedInternal(bool aChecked, bool aNotify)
  UpdateState(aNotify);
}

void
HTMLInputElement::Blur(ErrorResult& aError)
{
  if (mType == NS_FORM_INPUT_NUMBER) {
    // Blur our anonymous text control, if we have one. (DOM 'change' event
    // firing and other things depend on this.)
    nsNumberControlFrame* numberControlFrame =
      do_QueryFrame(GetPrimaryFrame());
    if (numberControlFrame) {
      HTMLInputElement* textControl = numberControlFrame->GetAnonTextControl();
      if (textControl) {
        textControl->Blur(aError);
        return;
      }
    }
  }
  nsGenericHTMLElement::Blur(aError);
}

void
HTMLInputElement::Focus(ErrorResult& aError)
{
  if (mType == NS_FORM_INPUT_NUMBER) {
    // Focus our anonymous text control, if we have one.
    nsNumberControlFrame* numberControlFrame =
      do_QueryFrame(GetPrimaryFrame());
    if (numberControlFrame) {
      HTMLInputElement* textControl = numberControlFrame->GetAnonTextControl();
      if (textControl) {
        textControl->Focus(aError);
        return;
      }
    }
  }

  if (mType != NS_FORM_INPUT_FILE) {
    nsGenericHTMLElement::Focus(aError);
    return;
+1 −0
Original line number Diff line number Diff line
@@ -108,6 +108,7 @@ public:

  virtual int32_t TabIndexDefault() MOZ_OVERRIDE;
  using nsGenericHTMLElement::Focus;
  virtual void Blur(ErrorResult& aError) MOZ_OVERRIDE;
  virtual void Focus(ErrorResult& aError) MOZ_OVERRIDE;

  // nsIDOMHTMLInputElement
Loading