# HG changeset patch # User Jessica Jong # Parent 46fe2115d46a5bb40523b8466341d8f9a26e1bdf Bug 1268556 - clicking padding area of 'number' input should not blur. r=smaug diff --git a/dom/base/moz.build b/dom/base/moz.build --- a/dom/base/moz.build +++ b/dom/base/moz.build @@ -439,16 +439,17 @@ LOCAL_INCLUDES += [ '/dom/xml', '/dom/xslt/xpath', '/dom/xul', '/gfx/2d', '/image', '/js/xpconnect/src', '/js/xpconnect/wrappers', '/layout/base', + '/layout/forms', '/layout/generic', '/layout/style', '/layout/svg', '/layout/xul', '/netwerk/base', '/security/manager/ssl', '/widget', '/xpcom/ds', diff --git a/dom/base/nsFocusManager.cpp b/dom/base/nsFocusManager.cpp --- a/dom/base/nsFocusManager.cpp +++ b/dom/base/nsFocusManager.cpp @@ -37,16 +37,17 @@ #include "nsIScriptObjectPrincipal.h" #include "nsIPrincipal.h" #include "nsIObserverService.h" #include "nsIObjectFrame.h" #include "nsBindingManager.h" #include "nsStyleCoord.h" #include "TabChild.h" #include "nsFrameLoader.h" +#include "nsNumberControlFrame.h" #include "mozilla/ContentEvents.h" #include "mozilla/dom/Element.h" #include "mozilla/EventDispatcher.h" #include "mozilla/EventStateManager.h" #include "mozilla/EventStates.h" #include "mozilla/IMEStateManager.h" #include "mozilla/LookAndFeel.h" @@ -305,16 +306,34 @@ nsFocusManager::GetFocusedDescendant(nsP return currentContent; } // static nsIContent* nsFocusManager::GetRedirectedFocus(nsIContent* aContent) { + // For input number, redirect focus to our anonymous text control. + if (aContent->IsHTMLElement(nsGkAtoms::input)) { + bool typeIsNumber = + static_cast(aContent)->GetType() == + NS_FORM_INPUT_NUMBER; + + if (typeIsNumber) { + nsNumberControlFrame* numberControlFrame = + do_QueryFrame(aContent->GetPrimaryFrame()); + + if (numberControlFrame) { + HTMLInputElement* textControl = + numberControlFrame->GetAnonTextControl(); + return static_cast(textControl); + } + } + } + #ifdef MOZ_XUL if (aContent->IsXULElement()) { nsCOMPtr inputField; nsCOMPtr textbox = do_QueryInterface(aContent); if (textbox) { textbox->GetInputField(getter_AddRefs(inputField)); } @@ -1500,18 +1519,18 @@ nsFocusManager::IsNonFocusableRoot(nsICo } nsIContent* nsFocusManager::CheckIfFocusable(nsIContent* aContent, uint32_t aFlags) { if (!aContent) return nullptr; - // this is a special case for some XUL elements where an anonymous child is - // actually focusable and not the element itself. + // this is a special case for some XUL elements or input number, where an + // anonymous child is actually focusable and not the element itself. nsIContent* redirectedFocus = GetRedirectedFocus(aContent); if (redirectedFocus) return CheckIfFocusable(redirectedFocus, aFlags); nsCOMPtr doc = aContent->GetComposedDoc(); // can't focus elements that are not in documents if (!doc) { LOGCONTENT("Cannot focus %s because content not in document", aContent) diff --git a/dom/base/nsFocusManager.h b/dom/base/nsFocusManager.h --- a/dom/base/nsFocusManager.h +++ b/dom/base/nsFocusManager.h @@ -109,17 +109,17 @@ public: * aWindow and aFocusedWindow must both be non-null. */ static nsIContent* GetFocusedDescendant(nsPIDOMWindowOuter* aWindow, bool aDeep, nsPIDOMWindowOuter** aFocusedWindow); /** * Returns the content node that focus will be redirected to if aContent was * focused. This is used for the special case of certain XUL elements such - * as textboxes which redirect focus to an anonymous child. + * as textboxes or input number which redirect focus to an anonymous child. * * aContent must be non-null. * * XXXndeakin this should be removed eventually but I want to do that as * followup work. */ static nsIContent* GetRedirectedFocus(nsIContent* aContent); diff --git a/dom/html/test/forms/mochitest.ini b/dom/html/test/forms/mochitest.ini --- a/dom/html/test/forms/mochitest.ini +++ b/dom/html/test/forms/mochitest.ini @@ -46,16 +46,17 @@ skip-if = os == "android" || appname == [test_input_number_mouse_events.html] # Not run on Firefox OS and Firefox for Android where the spin buttons are hidden: skip-if = os == "android" || appname == "b2g" || buildapp == "mulet" [test_input_number_rounding.html] skip-if = os == "android" || buildapp == "mulet" [test_input_number_validation.html] # We don't build ICU for Firefox for Android or Firefox OS: skip-if = os == "android" || appname == "b2g" +[test_input_number_focus.html] [test_input_range_attr_order.html] [test_input_range_key_events.html] skip-if = (buildapp == 'b2g' && toolkit != 'gonk') #Bug 931116, b2g desktop specific, initial triage [test_input_range_mouse_and_touch_events.html] skip-if = (toolkit == 'gonk' && debug) #debug-only failure; bug 926546 [test_input_range_rounding.html] skip-if = (buildapp == 'b2g' && toolkit != 'gonk') #Bug 931116, b2g desktop specific, initial triage [test_input_sanitization.html] diff --git a/dom/html/test/forms/test_input_number_focus.html b/dom/html/test/forms/test_input_number_focus.html new file mode 100644 --- /dev/null +++ b/dom/html/test/forms/test_input_number_focus.html @@ -0,0 +1,54 @@ + + + + + Test focus behaviour for <input type='number'> + + + + +Mozilla Bug 1268556 +

+
+ +
+
+
+
+ +