Diff
Modified: trunk/LayoutTests/ChangeLog (87370 => 87371)
--- trunk/LayoutTests/ChangeLog 2011-05-26 08:48:09 UTC (rev 87370)
+++ trunk/LayoutTests/ChangeLog 2011-05-26 09:10:51 UTC (rev 87371)
@@ -1,3 +1,14 @@
+2011-05-26 Kent Tamura <[email protected]>
+
+ Reviewed by Dimitri Glazkov.
+
+ Fix a bug that <input type="number"> dispatches two blurs when tabbing
+ from an invalid number
+ https://bugs.webkit.org/show_bug.cgi?id=59071
+
+ * fast/forms/input-number-blur-twice-expected.txt: Added.
+ * fast/forms/input-number-blur-twice.html: Added.
+
2011-05-26 Shane Stephens <[email protected]>
Reviewed by James Robinson.
Added: trunk/LayoutTests/fast/forms/input-number-blur-twice-expected.txt (0 => 87371)
--- trunk/LayoutTests/fast/forms/input-number-blur-twice-expected.txt (rev 0)
+++ trunk/LayoutTests/fast/forms/input-number-blur-twice-expected.txt 2011-05-26 09:10:51 UTC (rev 87371)
@@ -0,0 +1,8 @@
+There was a bug that moving focus with TAB from a number input with an invalid string dispatched an extra focus event and an extra blur event.
+
+PASS numOfFocus is 1
+PASS numOfBlur is 1
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
Added: trunk/LayoutTests/fast/forms/input-number-blur-twice.html (0 => 87371)
--- trunk/LayoutTests/fast/forms/input-number-blur-twice.html (rev 0)
+++ trunk/LayoutTests/fast/forms/input-number-blur-twice.html 2011-05-26 09:10:51 UTC (rev 87371)
@@ -0,0 +1,42 @@
+<!DOCTYPE html>
+<html>
+<head>
+<link rel="stylesheet" href=""
+<script src=""
+</head>
+<body>
+<p id="description">There was a bug that moving focus with TAB from a number input with an invalid string dispatched an extra focus event and an extra blur event.</p>
+<div id="console"></div>
+
+<input type=number id=number>
+<input type=text>
+
+<script>
+function handleFocus() {
+ numOfFocus++;
+}
+
+function handleBlur() {
+ numOfBlur++;
+}
+
+var numOfFocus = 0;
+var numOfBlur = 0;
+var num = document.getElementById('number');
+num.addEventListener('focus', handleFocus);
+num.addEventListener('blur', handleBlur);
+num.focus();
+document.execCommand('InsertText', false, '123');
+document.execCommand('InsertText', false, 'a');
+var tabEvent = document.createEvent('KeyboardEvent');
+tabEvent.initKeyboardEvent('keydown', true, true, document.defaultView, 'U+0009');
+num.dispatchEvent(tabEvent);
+
+shouldBe('numOfFocus', '1');
+shouldBe('numOfBlur', '1');
+
+var successfullyParsed = true;
+</script>
+<script src=""
+</body>
+</html>
Modified: trunk/Source/WebCore/ChangeLog (87370 => 87371)
--- trunk/Source/WebCore/ChangeLog 2011-05-26 08:48:09 UTC (rev 87370)
+++ trunk/Source/WebCore/ChangeLog 2011-05-26 09:10:51 UTC (rev 87371)
@@ -1,3 +1,47 @@
+2011-05-26 Kent Tamura <[email protected]>
+
+ Reviewed by Dimitri Glazkov.
+
+ Fix a bug that <input type="number"> dispatches two blurs when tabbing
+ from an invalid number
+ https://bugs.webkit.org/show_bug.cgi?id=59071
+
+ NumberInputType::handleBlurEvent() dispatched an extra focus event
+ and an extra blur event because
+ SelectionController::textWillBeReplaced() called by
+ RenderTextControlSingleLine::updateFromElement() focuses a node
+ with the selection.
+
+ In order to avoid this problem,
+ - Introduce Node::willBlur()
+ It is called before any state changes by a blur event.
+ - Call RenderTextControlSingleLine::updateFromElement() in willBlur()
+ It avoids extra focus/blur events because Document::m_focusedNode is
+ still the number input during willBlur().
+
+ Test: fast/forms/input-number-blur-twice.html
+
+ * dom/Document.cpp:
+ (WebCore::Document::setFocusedNode): Calls Node::beforeBlueEvent().
+ * dom/Node.cpp:
+ (WebCore::Node::willBlur):
+ Default empty implementation of willBlur().
+ * dom/Node.h: Declare willBlur().
+ * html/HTMLInputElement.cpp:
+ (WebCore::HTMLInputElement::willBlur):
+ Added. It just calls InputType::willBlur().
+ (WebCore::HTMLInputElement::handleBlurEvent):
+ Removed InputType::handleBlurEvent() call.
+ * html/HTMLInputElement.h: Declare willBlur().
+ * html/InputType.cpp:
+ (WebCore::InputType::willBlur): Default empty implementation.
+ (WebCore::InputType::handleBlurEvent): Removed.
+ * html/InputType.h: Declare willBlur(), remove handleBlurEvent().
+ * html/NumberInputType.cpp:
+ (WebCore::NumberInputType::willBlur):
+ Move the code in handleBlurEvent() here.
+ * html/NumberInputType.h: Declare willBlur().
+
2011-05-25 Hans Wennborg <[email protected]>
Reviewed by Steve Block.
Modified: trunk/Source/WebCore/dom/Document.cpp (87370 => 87371)
--- trunk/Source/WebCore/dom/Document.cpp 2011-05-26 08:48:09 UTC (rev 87370)
+++ trunk/Source/WebCore/dom/Document.cpp 2011-05-26 09:10:51 UTC (rev 87371)
@@ -3220,10 +3220,12 @@
bool focusChangeBlocked = false;
RefPtr<Node> oldFocusedNode = m_focusedNode;
- m_focusedNode = 0;
// Remove focus from the existing focus node (if any)
- if (oldFocusedNode && !oldFocusedNode->inDetach()) {
+ if (oldFocusedNode && !oldFocusedNode->inDetach()) {
+ // willBlur() should be called before any status changes.
+ oldFocusedNode->willBlur();
+ m_focusedNode = 0;
if (oldFocusedNode->active())
oldFocusedNode->setActive(false);
@@ -3268,7 +3270,8 @@
else
view()->setFocus(false);
}
- }
+ } else
+ m_focusedNode = 0;
if (newFocusedNode) {
if (newFocusedNode == newFocusedNode->rootEditableElement() && !acceptsEditingFocus(newFocusedNode.get())) {
Modified: trunk/Source/WebCore/dom/Node.cpp (87370 => 87371)
--- trunk/Source/WebCore/dom/Node.cpp 2011-05-26 08:48:09 UTC (rev 87370)
+++ trunk/Source/WebCore/dom/Node.cpp 2011-05-26 09:10:51 UTC (rev 87371)
@@ -2731,6 +2731,10 @@
dispatchEvent(Event::create(eventNames().focusEvent, false, false));
}
+void Node::willBlur()
+{
+}
+
void Node::dispatchBlurEvent()
{
if (document()->page())
Modified: trunk/Source/WebCore/dom/Node.h (87370 => 87371)
--- trunk/Source/WebCore/dom/Node.h 2011-05-26 08:48:09 UTC (rev 87370)
+++ trunk/Source/WebCore/dom/Node.h 2011-05-26 09:10:51 UTC (rev 87371)
@@ -555,6 +555,7 @@
void dispatchSimulatedClick(PassRefPtr<Event> underlyingEvent, bool sendMouseEvents = false, bool showPressedLook = true);
virtual void dispatchFocusEvent();
+ virtual void willBlur();
virtual void dispatchBlurEvent();
virtual void dispatchChangeEvent();
virtual void dispatchInputEvent();
Modified: trunk/Source/WebCore/html/HTMLInputElement.cpp (87370 => 87371)
--- trunk/Source/WebCore/html/HTMLInputElement.cpp 2011-05-26 08:48:09 UTC (rev 87370)
+++ trunk/Source/WebCore/html/HTMLInputElement.cpp 2011-05-26 09:10:51 UTC (rev 87371)
@@ -496,10 +496,14 @@
document()->setUseSecureKeyboardEntryWhenActive(true);
}
+void HTMLInputElement::willBlur()
+{
+ m_inputType->willBlur();
+ HTMLTextFormControlElement::willBlur();
+}
+
void HTMLInputElement::handleBlurEvent()
{
- m_inputType->handleBlurEvent();
-
if (!isTextField())
return;
Frame* frame = document()->frame();
Modified: trunk/Source/WebCore/html/HTMLInputElement.h (87370 => 87371)
--- trunk/Source/WebCore/html/HTMLInputElement.h 2011-05-26 08:48:09 UTC (rev 87370)
+++ trunk/Source/WebCore/html/HTMLInputElement.h 2011-05-26 09:10:51 UTC (rev 87371)
@@ -301,6 +301,7 @@
virtual bool isEmptyValue() const { return value().isEmpty(); }
virtual bool isEmptySuggestedValue() const { return suggestedValue().isEmpty(); }
virtual void handleFocusEvent();
+ virtual void willBlur();
virtual void handleBlurEvent();
virtual int cachedSelectionStart() const { return m_cachedSelectionStart; }
virtual int cachedSelectionEnd() const { return m_cachedSelectionEnd; }
Modified: trunk/Source/WebCore/html/InputType.cpp (87370 => 87371)
--- trunk/Source/WebCore/html/InputType.cpp 2011-05-26 08:48:09 UTC (rev 87370)
+++ trunk/Source/WebCore/html/InputType.cpp 2011-05-26 09:10:51 UTC (rev 87371)
@@ -410,7 +410,7 @@
return false;
}
-void InputType::handleBlurEvent()
+void InputType::willBlur()
{
}
Modified: trunk/Source/WebCore/html/InputType.h (87370 => 87371)
--- trunk/Source/WebCore/html/InputType.h 2011-05-26 08:48:09 UTC (rev 87370)
+++ trunk/Source/WebCore/html/InputType.h 2011-05-26 09:10:51 UTC (rev 87371)
@@ -178,7 +178,7 @@
virtual PassRefPtr<HTMLFormElement> formForSubmission() const;
virtual bool isKeyboardFocusable() const;
virtual bool shouldUseInputMethod() const;
- virtual void handleBlurEvent();
+ virtual void willBlur();
virtual void accessKeyAction(bool sendToAnyElement);
virtual bool canBeSuccessfulSubmitButton();
Modified: trunk/Source/WebCore/html/NumberInputType.cpp (87370 => 87371)
--- trunk/Source/WebCore/html/NumberInputType.cpp 2011-05-26 08:48:09 UTC (rev 87370)
+++ trunk/Source/WebCore/html/NumberInputType.cpp 2011-05-26 09:10:51 UTC (rev 87371)
@@ -211,7 +211,7 @@
return step / pow(2.0, FLT_MANT_DIG);
}
-void NumberInputType::handleBlurEvent()
+void NumberInputType::willBlur()
{
// Reset the renderer value, which might be unmatched with the element value.
element()->setFormControlValueMatchesRenderer(false);
Modified: trunk/Source/WebCore/html/NumberInputType.h (87370 => 87371)
--- trunk/Source/WebCore/html/NumberInputType.h 2011-05-26 08:48:09 UTC (rev 87370)
+++ trunk/Source/WebCore/html/NumberInputType.h 2011-05-26 09:10:51 UTC (rev 87371)
@@ -63,7 +63,7 @@
virtual double parseToDoubleWithDecimalPlaces(const String&, double, unsigned*) const;
virtual String serialize(double) const;
virtual double acceptableError(double) const;
- virtual void handleBlurEvent();
+ virtual void willBlur();
virtual String visibleValue() const;
virtual String convertFromVisibleValue(const String&) const;
virtual bool isAcceptableValue(const String&);