Bug 940760 - Make the CSS pseudo-class :focus apply to <input type=number>, fixing B2G forms styling. r=smaug
authorJonathan Watt <jwatt@jwatt.org>
Sun, 08 Dec 2013 21:26:42 +0000
changeset 159418 036c9a8c2025488a97fa054c917e3bf41188195b
parent 159417 2827800c529aee3ea948dfd9674fd50b91481c59
child 159419 6c8900219c19b356d35544782b620f79d766a420
push id25791
push userjwatt@jwatt.org
push dateSun, 08 Dec 2013 21:28:21 +0000
treeherdermozilla-central@6f6294b469f0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs940760
milestone28.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 940760 - Make the CSS pseudo-class :focus apply to <input type=number>, fixing B2G forms styling. r=smaug
content/base/public/Element.h
content/html/content/src/HTMLInputElement.cpp
content/html/content/src/HTMLInputElement.h
layout/reftests/forms/input/number/reftest.list
--- a/content/base/public/Element.h
+++ b/content/base/public/Element.h
@@ -108,18 +108,18 @@ namespace dom {
 
 class Link;
 class UndoManager;
 class DOMRect;
 class DOMRectList;
 
 // IID for the dom::Element interface
 #define NS_ELEMENT_IID \
-{ 0xec962aa7, 0x53ee, 0x46ff, \
-  { 0x90, 0x34, 0x68, 0xea, 0x79, 0x9d, 0x7d, 0xf7 } }
+{ 0xf7c18f0f, 0xa8fd, 0x4a95, \
+  { 0x91, 0x72, 0xd3, 0xa7, 0x4a, 0xb8, 0xc4, 0xbe } }
 
 class Element : public FragmentOrElement
 {
 public:
 #ifdef MOZILLA_INTERNAL_API
   Element(already_AddRefed<nsINodeInfo> aNodeInfo) :
     FragmentOrElement(aNodeInfo),
     mState(NS_EVENT_STATE_MOZ_READONLY)
@@ -380,26 +380,27 @@ private:
 
   void NotifyStateChange(nsEventStates aStates);
 
   void NotifyStyleStateChange(nsEventStates aStates);
 
   // Style state computed from element's state and style locks.
   nsEventStates StyleStateFromLocks() const;
 
+protected:
   // Methods for the ESM to manage state bits.  These will handle
   // setting up script blockers when they notify, so no need to do it
   // in the callers unless desired.
-  void AddStates(nsEventStates aStates) {
+  virtual void AddStates(nsEventStates aStates) {
     NS_PRECONDITION(!aStates.HasAtLeastOneOfStates(INTRINSIC_STATES),
                     "Should only be adding ESM-managed states here");
     AddStatesSilently(aStates);
     NotifyStateChange(aStates);
   }
-  void RemoveStates(nsEventStates aStates) {
+  virtual void RemoveStates(nsEventStates aStates) {
     NS_PRECONDITION(!aStates.HasAtLeastOneOfStates(INTRINSIC_STATES),
                     "Should only be removing ESM-managed states here");
     RemoveStatesSilently(aStates);
     NotifyStateChange(aStates);
   }
 public:
   virtual void UpdateEditableState(bool aNotify) MOZ_OVERRIDE;
 
--- a/content/html/content/src/HTMLInputElement.cpp
+++ b/content/html/content/src/HTMLInputElement.cpp
@@ -5727,16 +5727,48 @@ HTMLInputElement::IntrinsicState() const
               GetValidityState(VALIDITY_STATE_RANGE_UNDERFLOW))
                ? NS_EVENT_STATE_OUTOFRANGE
                : NS_EVENT_STATE_INRANGE;
   }
 
   return state;
 }
 
+void
+HTMLInputElement::AddStates(nsEventStates aStates)
+{
+  if (mType == NS_FORM_INPUT_TEXT) {
+    nsEventStates focusStates(aStates & (NS_EVENT_STATE_FOCUS |
+                                         NS_EVENT_STATE_FOCUSRING));
+    if (!focusStates.IsEmpty()) {
+      HTMLInputElement* ownerNumberControl = GetOwnerNumberControl();
+      if (ownerNumberControl) {
+        ownerNumberControl->AddStates(focusStates);
+      }
+    }
+  }
+  nsGenericHTMLFormElementWithState::AddStates(aStates);                          
+}
+
+void
+HTMLInputElement::RemoveStates(nsEventStates aStates)
+{
+  if (mType == NS_FORM_INPUT_TEXT) {
+    nsEventStates focusStates(aStates & (NS_EVENT_STATE_FOCUS |
+                                         NS_EVENT_STATE_FOCUSRING));
+    if (!focusStates.IsEmpty()) {
+      HTMLInputElement* ownerNumberControl = GetOwnerNumberControl();
+      if (ownerNumberControl) {
+        ownerNumberControl->RemoveStates(focusStates);
+      }
+    }
+  }
+  nsGenericHTMLFormElementWithState::RemoveStates(aStates);
+}
+
 bool
 HTMLInputElement::RestoreState(nsPresState* aState)
 {
   bool restoredCheckedState = false;
 
   nsCOMPtr<HTMLInputElementState> inputState
     (do_QueryInterface(aState->GetStateProperty()));
 
--- a/content/html/content/src/HTMLInputElement.h
+++ b/content/html/content/src/HTMLInputElement.h
@@ -161,16 +161,22 @@ public:
                               bool aCompileEventHandlers) MOZ_OVERRIDE;
   virtual void UnbindFromTree(bool aDeep = true,
                               bool aNullParent = true) MOZ_OVERRIDE;
 
   virtual void DoneCreatingElement() MOZ_OVERRIDE;
 
   virtual nsEventStates IntrinsicState() const MOZ_OVERRIDE;
 
+  // Element
+private:
+  virtual void AddStates(nsEventStates aStates);
+  virtual void RemoveStates(nsEventStates aStates);
+public:
+
   // nsITextControlElement
   NS_IMETHOD SetValueChanged(bool aValueChanged) MOZ_OVERRIDE;
   NS_IMETHOD_(bool) IsSingleLineTextControl() const MOZ_OVERRIDE;
   NS_IMETHOD_(bool) IsTextArea() const MOZ_OVERRIDE;
   NS_IMETHOD_(bool) IsPlainTextControl() const MOZ_OVERRIDE;
   NS_IMETHOD_(bool) IsPasswordTextControl() const MOZ_OVERRIDE;
   NS_IMETHOD_(int32_t) GetCols() MOZ_OVERRIDE;
   NS_IMETHOD_(int32_t) GetWrapCols() MOZ_OVERRIDE;
--- a/layout/reftests/forms/input/number/reftest.list
+++ b/layout/reftests/forms/input/number/reftest.list
@@ -13,13 +13,13 @@ skip-if(!Android&&!B2G) == number-same-a
 # dynamic type changes:
 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
+needs-focus == focus-handling.html focus-handling-ref.html
 
 # pseudo-elements not usable from content:
 == number-pseudo-elements.html number-pseudo-elements-ref.html