Diff
Modified: trunk/LayoutTests/ChangeLog (94657 => 94658)
--- trunk/LayoutTests/ChangeLog 2011-09-07 09:52:28 UTC (rev 94657)
+++ trunk/LayoutTests/ChangeLog 2011-09-07 10:07:10 UTC (rev 94658)
@@ -1,3 +1,15 @@
+2011-09-07 Ryosuke Niwa <[email protected]>
+
+ Change event is not fired for input[type=number] when the user reverts a change made by script
+ https://bugs.webkit.org/show_bug.cgi?id=67697
+
+ Reviewed by Kent Tamura.
+
+ Add a regression test to ensure WebKit fires change event when the user reverts a change made by script.
+
+ * fast/forms/number-input-changeevent-expected.txt: Added.
+ * fast/forms/number-input-changeevent.html: Added.
+
2011-09-07 Csaba Osztrogonác <[email protected]>
[Qt][Mac] Unreviewed gardening after r94646.
Added: trunk/LayoutTests/fast/forms/number-input-changeevent-expected.txt (0 => 94658)
--- trunk/LayoutTests/fast/forms/number-input-changeevent-expected.txt (rev 0)
+++ trunk/LayoutTests/fast/forms/number-input-changeevent-expected.txt 2011-09-07 10:07:10 UTC (rev 94658)
@@ -0,0 +1,9 @@
+This test ensures change event is fired for input[type=number] when the user reverts the change made by a script.
+
+PASS eventSender.keyDown('1');eventSender.keyDown('2');dummy.focus();numberOfChangeEventsFired is 1
+PASS test.value = '34';numberOfChangeEventsFired is 1
+PASS test.focus();test.value = '34';document.execCommand('SelectAll'); eventSender.keyDown('1');eventSender.keyDown('2');dummy.focus();numberOfChangeEventsFired is 2
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
Added: trunk/LayoutTests/fast/forms/number-input-changeevent.html (0 => 94658)
--- trunk/LayoutTests/fast/forms/number-input-changeevent.html (rev 0)
+++ trunk/LayoutTests/fast/forms/number-input-changeevent.html 2011-09-07 10:07:10 UTC (rev 94658)
@@ -0,0 +1,31 @@
+<!DOCTYPE html>
+<html>
+<body>
+<p>This test ensures change event is fired for input[type=number] when the user reverts the change made by a script.</p>
+<div id="console"></div>
+<div><input id="test" type="number" _onchange_="numberOfChangeEventsFired++;"><input id="dummy"></div>
+<script src=""
+<script>
+
+if (window.layoutTestController)
+ layoutTestController.dumpAsText();
+
+var numberOfChangeEventsFired = 0;
+var test = document.getElementById('test');
+var dummy = document.getElementById('dummy');
+test.focus();
+
+if (window.eventSender) {
+ shouldBe("eventSender.keyDown('1');eventSender.keyDown('2');dummy.focus();numberOfChangeEventsFired", '1');
+ shouldBe("test.value = '34';numberOfChangeEventsFired", '1');
+ shouldBe("test.focus();test.value = '34';document.execCommand('SelectAll');\n"
+ + "eventSender.keyDown('1');eventSender.keyDown('2');dummy.focus();numberOfChangeEventsFired", '2');
+ test.parentNode.style.display = 'none';
+}
+
+var successfullyParsed = true;
+
+</script>
+<script src=""
+</body>
+</html>
Modified: trunk/Source/WebCore/ChangeLog (94657 => 94658)
--- trunk/Source/WebCore/ChangeLog 2011-09-07 09:52:28 UTC (rev 94657)
+++ trunk/Source/WebCore/ChangeLog 2011-09-07 10:07:10 UTC (rev 94658)
@@ -1,3 +1,42 @@
+2011-09-07 Ryosuke Niwa <[email protected]>
+
+ Change event is not fired for input[type=number] when the user reverts a change made by script
+ https://bugs.webkit.org/show_bug.cgi?id=67697
+
+ Reviewed by Kent Tamura.
+
+ The bug was caused by HTMLInputElement::setValue not calling setTextAsOfLastFormControlChangeEvent
+ for text fields other than type=text.
+
+ Also fixed a that stepUpFromRenderer does not call setTextAsOfLastFormControlChangeEvent at appropriate
+ timing due to setValueAsNumber always passing sendChangeEvent=false to setValue by propagating values
+ through setValueAsNumber and applyStep. This refactoring allows us to remove calls to dispatch* in
+ stepUpFromRenderer because they're now called in setValueAsNumber or applyStep.
+
+ Test: fast/forms/number-input-changeevent.html
+
+ * html/BaseDateAndTimeInputType.cpp:
+ (WebCore::BaseDateAndTimeInputType::setValueAsNumber):
+ * html/BaseDateAndTimeInputType.h:
+ * html/HTMLInputElement.cpp:
+ (WebCore::HTMLInputElement::applyStep):
+ (WebCore::HTMLInputElement::stepUp):
+ (WebCore::HTMLInputElement::stepDown):
+ (WebCore::HTMLInputElement::setValue):
+ (WebCore::HTMLInputElement::setValueAsNumber):
+ (WebCore::HTMLInputElement::stepUpFromRenderer):
+ * html/HTMLInputElement.h:
+ * html/InputType.cpp:
+ (WebCore::InputType::setValueAsNumber):
+ * html/InputType.h:
+ * html/NumberInputType.cpp:
+ (WebCore::NumberInputType::setValueAsNumber):
+ * html/NumberInputType.h:
+ * html/RangeInputType.cpp:
+ (WebCore::RangeInputType::setValueAsNumber):
+ (WebCore::RangeInputType::handleKeydownEvent):
+ * html/RangeInputType.h:
+
2011-09-07 Antti Koivisto <[email protected]>
Try to fix Qt build by moving the Qt specific include (which is not really allowed here!).
Modified: trunk/Source/WebCore/html/BaseDateAndTimeInputType.cpp (94657 => 94658)
--- trunk/Source/WebCore/html/BaseDateAndTimeInputType.cpp 2011-09-07 09:52:28 UTC (rev 94657)
+++ trunk/Source/WebCore/html/BaseDateAndTimeInputType.cpp 2011-09-07 10:07:10 UTC (rev 94658)
@@ -65,9 +65,9 @@
return parseToDouble(element()->value(), numeric_limits<double>::quiet_NaN());
}
-void BaseDateAndTimeInputType::setValueAsNumber(double newValue, ExceptionCode&) const
+void BaseDateAndTimeInputType::setValueAsNumber(double newValue, bool sendChangeEvent, ExceptionCode&) const
{
- element()->setValue(serialize(newValue));
+ element()->setValue(serialize(newValue), sendChangeEvent);
}
bool BaseDateAndTimeInputType::typeMismatchFor(const String& value) const
Modified: trunk/Source/WebCore/html/BaseDateAndTimeInputType.h (94657 => 94658)
--- trunk/Source/WebCore/html/BaseDateAndTimeInputType.h 2011-09-07 09:52:28 UTC (rev 94657)
+++ trunk/Source/WebCore/html/BaseDateAndTimeInputType.h 2011-09-07 10:07:10 UTC (rev 94658)
@@ -52,7 +52,7 @@
virtual double valueAsDate() const;
virtual void setValueAsDate(double, ExceptionCode&) const;
virtual double valueAsNumber() const;
- virtual void setValueAsNumber(double, ExceptionCode&) const;
+ virtual void setValueAsNumber(double, bool sendChangeEvent, ExceptionCode&) const;
virtual bool typeMismatchFor(const String&) const;
virtual bool typeMismatch() const;
virtual bool rangeUnderflow(const String&) const;
Modified: trunk/Source/WebCore/html/HTMLInputElement.cpp (94657 => 94658)
--- trunk/Source/WebCore/html/HTMLInputElement.cpp 2011-09-07 09:52:28 UTC (rev 94657)
+++ trunk/Source/WebCore/html/HTMLInputElement.cpp 2011-09-07 10:07:10 UTC (rev 94658)
@@ -388,7 +388,7 @@
return true;
}
-void HTMLInputElement::applyStep(double count, AnyStepHandling anyStepHandling, ExceptionCode& ec)
+void HTMLInputElement::applyStep(double count, AnyStepHandling anyStepHandling, bool sendChangeEvent, ExceptionCode& ec)
{
double step;
unsigned stepDecimalPlaces, currentDecimalPlaces;
@@ -428,7 +428,7 @@
if (newValue > m_inputType->maximum())
newValue = m_inputType->maximum();
- setValueAsNumber(newValue, ec);
+ setValueAsNumber(newValue, ec, sendChangeEvent);
if (AXObjectCache::accessibilityEnabled())
document()->axObjectCache()->postNotification(renderer(), AXObjectCache::AXValueChanged, true);
@@ -455,12 +455,14 @@
void HTMLInputElement::stepUp(int n, ExceptionCode& ec)
{
- applyStep(n, RejectAny, ec);
+ bool sendChangeEvent = false;
+ applyStep(n, RejectAny, sendChangeEvent, ec);
}
void HTMLInputElement::stepDown(int n, ExceptionCode& ec)
{
- applyStep(-n, RejectAny, ec);
+ bool sendChangeEvent = false;
+ applyStep(-n, RejectAny, sendChangeEvent, ec);
}
bool HTMLInputElement::isKeyboardFocusable(KeyboardEvent* event) const
@@ -1117,7 +1119,7 @@
dispatchFormControlChangeEvent();
}
- if (isText() && (!focused() || !sendChangeEvent))
+ if (isTextField() && (!focused() || !sendChangeEvent))
setTextAsOfLastFormControlChangeEvent(value);
notifyFormStateChanged();
@@ -1144,13 +1146,13 @@
return m_inputType->valueAsNumber();
}
-void HTMLInputElement::setValueAsNumber(double newValue, ExceptionCode& ec)
+void HTMLInputElement::setValueAsNumber(double newValue, ExceptionCode& ec, bool sendChangeEvent)
{
if (!isfinite(newValue)) {
ec = NOT_SUPPORTED_ERR;
return;
}
- m_inputType->setValueAsNumber(newValue, ec);
+ m_inputType->setValueAsNumber(newValue, sendChangeEvent, ec);
}
String HTMLInputElement::placeholder() const
@@ -1628,6 +1630,7 @@
const double nan = numeric_limits<double>::quiet_NaN();
String currentStringValue = value();
double current = m_inputType->parseToDouble(currentStringValue, nan);
+ const bool sendChangeEvent = true;
if (!isfinite(current)) {
ExceptionCode ec;
current = m_inputType->defaultValueForStepUp();
@@ -1636,10 +1639,10 @@
current = m_inputType->minimum() - nextDiff;
if (current > m_inputType->maximum() - nextDiff)
current = m_inputType->maximum() - nextDiff;
- setValueAsNumber(current, ec);
+ setValueAsNumber(current, ec, sendChangeEvent);
}
if ((sign > 0 && current < m_inputType->minimum()) || (sign < 0 && current > m_inputType->maximum()))
- setValue(m_inputType->serialize(sign > 0 ? m_inputType->minimum() : m_inputType->maximum()));
+ setValue(m_inputType->serialize(sign > 0 ? m_inputType->minimum() : m_inputType->maximum()), sendChangeEvent);
else {
ExceptionCode ec;
if (stepMismatch(value())) {
@@ -1659,22 +1662,15 @@
if (newValue > m_inputType->maximum())
newValue = m_inputType->maximum();
- setValueAsNumber(newValue, ec);
+ setValueAsNumber(newValue, ec, n == 1 || n == -1);
current = newValue;
if (n > 1)
- applyStep(n - 1, AnyIsDefaultStep, ec);
+ applyStep(n - 1, AnyIsDefaultStep, sendChangeEvent, ec);
else if (n < -1)
- applyStep(n + 1, AnyIsDefaultStep, ec);
+ applyStep(n + 1, AnyIsDefaultStep, sendChangeEvent, ec);
} else
- applyStep(n, AnyIsDefaultStep, ec);
+ applyStep(n, AnyIsDefaultStep, sendChangeEvent, ec);
}
-
- if (currentStringValue != value()) {
- if (m_inputType->isRangeControl())
- dispatchFormControlChangeEvent();
- else
- dispatchFormControlInputEvent();
- }
}
#if ENABLE(WCSS)
Modified: trunk/Source/WebCore/html/HTMLInputElement.h (94657 => 94658)
--- trunk/Source/WebCore/html/HTMLInputElement.h 2011-09-07 09:52:28 UTC (rev 94657)
+++ trunk/Source/WebCore/html/HTMLInputElement.h 2011-09-07 10:07:10 UTC (rev 94658)
@@ -160,7 +160,7 @@
void setValueAsDate(double, ExceptionCode&);
double valueAsNumber() const;
- void setValueAsNumber(double, ExceptionCode&);
+ void setValueAsNumber(double, ExceptionCode&, bool sendChangeEvent = false);
virtual String placeholder() const;
virtual void setPlaceholder(const String&);
@@ -326,7 +326,7 @@
bool getAllowedValueStepWithDecimalPlaces(AnyStepHandling, double*, unsigned*) const;
// Helper for stepUp()/stepDown(). Adds step value * count to the current value.
- void applyStep(double count, AnyStepHandling, ExceptionCode&);
+ void applyStep(double count, AnyStepHandling, bool sendChangeEvent, ExceptionCode&);
double alignValueForStep(double value, double step, unsigned currentDecimalPlaces, unsigned stepDecimalPlaces);
#if ENABLE(DATALIST)
Modified: trunk/Source/WebCore/html/InputType.cpp (94657 => 94658)
--- trunk/Source/WebCore/html/InputType.cpp 2011-09-07 09:52:28 UTC (rev 94657)
+++ trunk/Source/WebCore/html/InputType.cpp 2011-09-07 10:07:10 UTC (rev 94658)
@@ -182,7 +182,7 @@
return numeric_limits<double>::quiet_NaN();
}
-void InputType::setValueAsNumber(double, ExceptionCode& ec) const
+void InputType::setValueAsNumber(double, bool, ExceptionCode& ec) const
{
ec = INVALID_STATE_ERR;
}
Modified: trunk/Source/WebCore/html/InputType.h (94657 => 94658)
--- trunk/Source/WebCore/html/InputType.h 2011-09-07 09:52:28 UTC (rev 94657)
+++ trunk/Source/WebCore/html/InputType.h 2011-09-07 10:07:10 UTC (rev 94658)
@@ -126,7 +126,7 @@
virtual double valueAsDate() const;
virtual void setValueAsDate(double, ExceptionCode&) const;
virtual double valueAsNumber() const;
- virtual void setValueAsNumber(double, ExceptionCode&) const;
+ virtual void setValueAsNumber(double, bool sendChangeEvent, ExceptionCode&) const;
// Validation functions
Modified: trunk/Source/WebCore/html/NumberInputType.cpp (94657 => 94658)
--- trunk/Source/WebCore/html/NumberInputType.cpp 2011-09-07 09:52:28 UTC (rev 94657)
+++ trunk/Source/WebCore/html/NumberInputType.cpp 2011-09-07 10:07:10 UTC (rev 94658)
@@ -83,7 +83,7 @@
return parseToDouble(element()->value(), numeric_limits<double>::quiet_NaN());
}
-void NumberInputType::setValueAsNumber(double newValue, ExceptionCode& ec) const
+void NumberInputType::setValueAsNumber(double newValue, bool sendChangeEvent, ExceptionCode& ec) const
{
if (newValue < -numeric_limits<float>::max()) {
ec = INVALID_STATE_ERR;
@@ -93,7 +93,7 @@
ec = INVALID_STATE_ERR;
return;
}
- element()->setValue(serialize(newValue));
+ element()->setValue(serialize(newValue), sendChangeEvent);
}
bool NumberInputType::typeMismatchFor(const String& value) const
Modified: trunk/Source/WebCore/html/NumberInputType.h (94657 => 94658)
--- trunk/Source/WebCore/html/NumberInputType.h 2011-09-07 09:52:28 UTC (rev 94657)
+++ trunk/Source/WebCore/html/NumberInputType.h 2011-09-07 10:07:10 UTC (rev 94658)
@@ -43,7 +43,7 @@
NumberInputType(HTMLInputElement* element) : TextFieldInputType(element) { }
virtual const AtomicString& formControlType() const;
virtual double valueAsNumber() const;
- virtual void setValueAsNumber(double, ExceptionCode&) const;
+ virtual void setValueAsNumber(double, bool sendChangeEvent, ExceptionCode&) const;
virtual bool typeMismatchFor(const String&) const;
virtual bool typeMismatch() const;
virtual bool rangeUnderflow(const String&) const;
Modified: trunk/Source/WebCore/html/RangeInputType.cpp (94657 => 94658)
--- trunk/Source/WebCore/html/RangeInputType.cpp 2011-09-07 09:52:28 UTC (rev 94657)
+++ trunk/Source/WebCore/html/RangeInputType.cpp 2011-09-07 10:07:10 UTC (rev 94658)
@@ -78,9 +78,9 @@
return parseToDouble(element()->value(), numeric_limits<double>::quiet_NaN());
}
-void RangeInputType::setValueAsNumber(double newValue, ExceptionCode&) const
+void RangeInputType::setValueAsNumber(double newValue, bool sendChangeEvent, ExceptionCode&) const
{
- element()->setValue(serialize(newValue));
+ element()->setValue(serialize(newValue), sendChangeEvent);
}
bool RangeInputType::supportsRequired() const
@@ -220,7 +220,8 @@
if (newValue != current) {
ExceptionCode ec;
- setValueAsNumber(newValue, ec);
+ bool sendChangeEvent = true;
+ setValueAsNumber(newValue, sendChangeEvent, ec);
if (AXObjectCache::accessibilityEnabled())
element()->document()->axObjectCache()->postNotification(element()->renderer(), AXObjectCache::AXValueChanged, true);
Modified: trunk/Source/WebCore/html/RangeInputType.h (94657 => 94658)
--- trunk/Source/WebCore/html/RangeInputType.h 2011-09-07 09:52:28 UTC (rev 94657)
+++ trunk/Source/WebCore/html/RangeInputType.h 2011-09-07 10:07:10 UTC (rev 94658)
@@ -46,7 +46,7 @@
virtual bool isRangeControl() const;
virtual const AtomicString& formControlType() const;
virtual double valueAsNumber() const;
- virtual void setValueAsNumber(double, ExceptionCode&) const;
+ virtual void setValueAsNumber(double, bool sendChangeEvent, ExceptionCode&) const;
virtual bool supportsRequired() const;
virtual bool rangeUnderflow(const String&) const;
virtual bool rangeOverflow(const String&) const;