- Revision
- 140385
- Author
- [email protected]
- Date
- 2013-01-21 22:17:21 -0800 (Mon, 21 Jan 2013)
Log Message
Date selection from calendar picker should dispatch 'input' event in addition to 'change' event
https://bugs.webkit.org/show_bug.cgi?id=107427
Reviewed by Kentaro Hara.
Source/WebCore:
According to the specification and Opera's behavior, we should dispatch
not only 'change' event but also 'input' event when a user chooses a
date from the calender picker.
http://www.whatwg.org/specs/web-apps/current-work/multipage/common-input-element-attributes.html#common-event-behaviors
> When the user agent changes the element's value on behalf of the user
> (e.g. as part of a form prefilling feature), the user agent must follow
> these steps:
> 1. If the input event applies, queue a task to fire a simple event
> that bubbles named input at the input element.
> 2. If the change event applies, queue a task to fire a simple event
> that bubbles named change at the input element.
Tests: platform/chromium/fast/forms/calendar-picker/date-picker-events.html
platform/chromium/fast/forms/calendar-picker/datetimelocal-picker-events.html
* html/InputType.cpp:
(WebCore::InputType::setValue): Add DispatchInputAndChangeEvent support.
* html/BaseChooserOnlyDateAndTimeInputType.cpp:
(WebCore::BaseChooserOnlyDateAndTimeInputType::didChooseValue):
Use DispatchInputAndChangeEvent, not DispatchChangeEvent.
* html/BaseMultipleFieldsDateAndTimeInputType.cpp:
(WebCore::BaseMultipleFieldsDateAndTimeInputType::pickerIndicatorChooseValue):
Ditto.
LayoutTests:
* platform/chromium/fast/forms/calendar-picker/date-picker-events-expected.txt: Added.
* platform/chromium/fast/forms/calendar-picker/date-picker-events.html: Added.
* platform/chromium/fast/forms/calendar-picker/datetimelocal-picker-events-expected.txt: Added.
* platform/chromium/fast/forms/calendar-picker/datetimelocal-picker-events.html: Added.
Modified Paths
Added Paths
Diff
Modified: trunk/LayoutTests/ChangeLog (140384 => 140385)
--- trunk/LayoutTests/ChangeLog 2013-01-22 06:13:26 UTC (rev 140384)
+++ trunk/LayoutTests/ChangeLog 2013-01-22 06:17:21 UTC (rev 140385)
@@ -1,3 +1,15 @@
+2013-01-21 Kent Tamura <[email protected]>
+
+ Date selection from calendar picker should dispatch 'input' event in addition to 'change' event
+ https://bugs.webkit.org/show_bug.cgi?id=107427
+
+ Reviewed by Kentaro Hara.
+
+ * platform/chromium/fast/forms/calendar-picker/date-picker-events-expected.txt: Added.
+ * platform/chromium/fast/forms/calendar-picker/date-picker-events.html: Added.
+ * platform/chromium/fast/forms/calendar-picker/datetimelocal-picker-events-expected.txt: Added.
+ * platform/chromium/fast/forms/calendar-picker/datetimelocal-picker-events.html: Added.
+
2013-01-21 Noel Gordon <[email protected]>
[chromium] Update webaudio/realtimeanalyser-fft-sizing.html expectation on Win
Added: trunk/LayoutTests/platform/chromium/fast/forms/calendar-picker/date-picker-events-expected.txt (0 => 140385)
--- trunk/LayoutTests/platform/chromium/fast/forms/calendar-picker/date-picker-events-expected.txt (rev 0)
+++ trunk/LayoutTests/platform/chromium/fast/forms/calendar-picker/date-picker-events-expected.txt 2013-01-22 06:17:21 UTC (rev 140385)
@@ -0,0 +1,19 @@
+Tests if value selection by calendar picker dispatches correct events.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+Choosing a new value from the calendar picker. "input" and "change" events should be dispatched in this order.
+==> "input" event was dispatched.
+==> "change" event was dispatched.
+PASS date1.value is "2000-01-03"
+PASS eventsCounter.input is 1
+PASS eventsCounter.change is 1
+Choosing the same value from the calendar picker. No events should be dispatched.
+PASS date1.value is "2000-01-03"
+PASS eventsCounter.input is undefined.
+PASS eventsCounter.change is undefined.
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
Added: trunk/LayoutTests/platform/chromium/fast/forms/calendar-picker/date-picker-events.html (0 => 140385)
--- trunk/LayoutTests/platform/chromium/fast/forms/calendar-picker/date-picker-events.html (rev 0)
+++ trunk/LayoutTests/platform/chromium/fast/forms/calendar-picker/date-picker-events.html 2013-01-22 06:17:21 UTC (rev 140385)
@@ -0,0 +1,62 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src=""
+<script src=""
+<script src=""
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+<input type="date" id="date1" value="2000-01-02">
+
+<script>
+description('Tests if value selection by calendar picker dispatches correct events.');
+
+var eventsCounter = {};
+function recordEvent(event) {
+ if (eventsCounter[event.type] === undefined)
+ eventsCounter[event.type] = 0;
+ eventsCounter[event.type]++;
+ debug('==> "' + event.type + '" event was dispatched.');
+}
+
+var date1 = document.getElementById('date1');
+date1.addEventListener('input', recordEvent, false);
+date1.addEventListener('change', recordEvent, false);
+
+openPicker(date1, test1);
+
+function test1() {
+ eventSender.keyDown('rightArrow');
+ debug('Choosing a new value from the calendar picker. "input" and "change" events should be dispatched in this order.');
+ eventSender.keyDown('\n');
+ waitUntilClosing(test1AfterClosing);
+}
+
+function test1AfterClosing() {
+ shouldBeEqualToString('date1.value', '2000-01-03');
+ shouldBe('eventsCounter.input', '1');
+ shouldBe('eventsCounter.change', '1');
+
+ eventsCounter = {};
+ openPicker(date1, test2);
+}
+
+function test2() {
+ debug('Choosing the same value from the calendar picker. No events should be dispatched.');
+ eventSender.keyDown('\n');
+ waitUntilClosing(test2AfterClosing);
+}
+
+function test2AfterClosing() {
+ shouldBeEqualToString('date1.value', '2000-01-03');
+ shouldBeUndefined('eventsCounter.input');
+ shouldBeUndefined('eventsCounter.change');
+
+ finishJSTest();
+}
+</script>
+<script src=""
+</body>
+</html>
Added: trunk/LayoutTests/platform/chromium/fast/forms/calendar-picker/datetimelocal-picker-events-expected.txt (0 => 140385)
--- trunk/LayoutTests/platform/chromium/fast/forms/calendar-picker/datetimelocal-picker-events-expected.txt (rev 0)
+++ trunk/LayoutTests/platform/chromium/fast/forms/calendar-picker/datetimelocal-picker-events-expected.txt 2013-01-22 06:17:21 UTC (rev 140385)
@@ -0,0 +1,19 @@
+Tests if value selection by calendar picker dispatches correct events.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+Choosing a new date value from the calendar picker. No events should be dispatched because the hour field and the minutes field are empty.
+PASS datetimelocal1.value is ""
+PASS eventsCounter.input is undefined.
+PASS eventsCounter.change is undefined.
+Choosing a new value from the calendar picker. "Input" and "change" events should be dispatched in this order.
+==> "input" event was dispatched.
+==> "change" event was dispatched.
+PASS datetimelocal1.value is "2013-01-22T17:49"
+PASS eventsCounter.input is 1
+PASS eventsCounter.change is 1
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
Added: trunk/LayoutTests/platform/chromium/fast/forms/calendar-picker/datetimelocal-picker-events.html (0 => 140385)
--- trunk/LayoutTests/platform/chromium/fast/forms/calendar-picker/datetimelocal-picker-events.html (rev 0)
+++ trunk/LayoutTests/platform/chromium/fast/forms/calendar-picker/datetimelocal-picker-events.html 2013-01-22 06:17:21 UTC (rev 140385)
@@ -0,0 +1,62 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src=""
+<script src=""
+<script src=""
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+<input type="datetime-local" id="datetimelocal1" value="">
+
+<script>
+description('Tests if value selection by calendar picker dispatches correct events.');
+
+var eventsCounter = {};
+function recordEvent(event) {
+ if (eventsCounter[event.type] === undefined)
+ eventsCounter[event.type] = 0;
+ eventsCounter[event.type]++;
+ debug('==> "' + event.type + '" event was dispatched.');
+}
+
+var datetimelocal1 = document.getElementById('datetimelocal1');
+datetimelocal1.addEventListener('input', recordEvent, false);
+datetimelocal1.addEventListener('change', recordEvent, false);
+
+openPicker(datetimelocal1, test1);
+
+function test1() {
+ debug('Choosing a new date value from the calendar picker. No events should be dispatched because the hour field and the minutes field are empty.');
+ eventSender.keyDown('\n');
+ waitUntilClosing(test1AfterClosing);
+}
+
+function test1AfterClosing() {
+ shouldBeEqualToString('datetimelocal1.value', '');
+ shouldBeUndefined('eventsCounter.input');
+ shouldBeUndefined('eventsCounter.change');
+
+ datetimelocal1.value = "2013-01-21T17:49";
+ openPicker(datetimelocal1, test2);
+}
+
+function test2() {
+ debug('Choosing a new value from the calendar picker. "Input" and "change" events should be dispatched in this order.');
+ eventSender.keyDown('rightArrow');
+ eventSender.keyDown('\n');
+ waitUntilClosing(test2AfterClosing);
+}
+
+function test2AfterClosing() {
+ shouldBeEqualToString('datetimelocal1.value', '2013-01-22T17:49');
+ shouldBe('eventsCounter.input', '1');
+ shouldBe('eventsCounter.change', '1');
+
+ finishJSTest();
+}
+</script>
+<script src=""
+</body>
+</html>
Modified: trunk/Source/WebCore/ChangeLog (140384 => 140385)
--- trunk/Source/WebCore/ChangeLog 2013-01-22 06:13:26 UTC (rev 140384)
+++ trunk/Source/WebCore/ChangeLog 2013-01-22 06:17:21 UTC (rev 140385)
@@ -1,3 +1,35 @@
+2013-01-21 Kent Tamura <[email protected]>
+
+ Date selection from calendar picker should dispatch 'input' event in addition to 'change' event
+ https://bugs.webkit.org/show_bug.cgi?id=107427
+
+ Reviewed by Kentaro Hara.
+
+ According to the specification and Opera's behavior, we should dispatch
+ not only 'change' event but also 'input' event when a user chooses a
+ date from the calender picker.
+
+ http://www.whatwg.org/specs/web-apps/current-work/multipage/common-input-element-attributes.html#common-event-behaviors
+ > When the user agent changes the element's value on behalf of the user
+ > (e.g. as part of a form prefilling feature), the user agent must follow
+ > these steps:
+ > 1. If the input event applies, queue a task to fire a simple event
+ > that bubbles named input at the input element.
+ > 2. If the change event applies, queue a task to fire a simple event
+ > that bubbles named change at the input element.
+
+ Tests: platform/chromium/fast/forms/calendar-picker/date-picker-events.html
+ platform/chromium/fast/forms/calendar-picker/datetimelocal-picker-events.html
+
+ * html/InputType.cpp:
+ (WebCore::InputType::setValue): Add DispatchInputAndChangeEvent support.
+ * html/BaseChooserOnlyDateAndTimeInputType.cpp:
+ (WebCore::BaseChooserOnlyDateAndTimeInputType::didChooseValue):
+ Use DispatchInputAndChangeEvent, not DispatchChangeEvent.
+ * html/BaseMultipleFieldsDateAndTimeInputType.cpp:
+ (WebCore::BaseMultipleFieldsDateAndTimeInputType::pickerIndicatorChooseValue):
+ Ditto.
+
2013-01-21 Justin Schuh <[email protected]>
[CHROMIUM] Suppress c4267 build warnings for Win64 targets
Modified: trunk/Source/WebCore/html/BaseChooserOnlyDateAndTimeInputType.cpp (140384 => 140385)
--- trunk/Source/WebCore/html/BaseChooserOnlyDateAndTimeInputType.cpp 2013-01-22 06:13:26 UTC (rev 140384)
+++ trunk/Source/WebCore/html/BaseChooserOnlyDateAndTimeInputType.cpp 2013-01-22 06:17:21 UTC (rev 140385)
@@ -96,7 +96,7 @@
void BaseChooserOnlyDateAndTimeInputType::didChooseValue(const String& value)
{
- element()->setValue(value, DispatchChangeEvent);
+ element()->setValue(value, DispatchInputAndChangeEvent);
}
void BaseChooserOnlyDateAndTimeInputType::didEndChooser()
Modified: trunk/Source/WebCore/html/BaseMultipleFieldsDateAndTimeInputType.cpp (140384 => 140385)
--- trunk/Source/WebCore/html/BaseMultipleFieldsDateAndTimeInputType.cpp 2013-01-22 06:13:26 UTC (rev 140384)
+++ trunk/Source/WebCore/html/BaseMultipleFieldsDateAndTimeInputType.cpp 2013-01-22 06:17:21 UTC (rev 140385)
@@ -140,7 +140,7 @@
void BaseMultipleFieldsDateAndTimeInputType::pickerIndicatorChooseValue(const String& value)
{
if (element()->isValidValue(value)) {
- element()->setValue(value, DispatchChangeEvent);
+ element()->setValue(value, DispatchInputAndChangeEvent);
return;
}
Modified: trunk/Source/WebCore/html/InputType.cpp (140384 => 140385)
--- trunk/Source/WebCore/html/InputType.cpp 2013-01-22 06:13:26 UTC (rev 140384)
+++ trunk/Source/WebCore/html/InputType.cpp 2013-01-22 06:17:21 UTC (rev 140385)
@@ -674,8 +674,19 @@
{
element()->setValueInternal(sanitizedValue, eventBehavior);
element()->setNeedsStyleRecalc();
- if (valueChanged && eventBehavior != DispatchNoEvent)
+ if (!valueChanged)
+ return;
+ switch (eventBehavior) {
+ case DispatchChangeEvent:
element()->dispatchFormControlChangeEvent();
+ break;
+ case DispatchInputAndChangeEvent:
+ element()->dispatchFormControlInputEvent();
+ element()->dispatchFormControlChangeEvent();
+ break;
+ case DispatchNoEvent:
+ break;
+ }
}
bool InputType::canSetValue(const String&)