Title: [140651] branches/chromium/1364
Revision
140651
Author
[email protected]
Date
2013-01-23 21:48:35 -0800 (Wed, 23 Jan 2013)

Log Message

Merge 140385

> 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.
> 

[email protected]
Review URL: https://codereview.chromium.org/12045062

Modified Paths

Added Paths

Diff

Copied: branches/chromium/1364/LayoutTests/platform/chromium/fast/forms/calendar-picker/date-picker-events-expected.txt (from rev 140385, trunk/LayoutTests/platform/chromium/fast/forms/calendar-picker/date-picker-events-expected.txt) (0 => 140651)


--- branches/chromium/1364/LayoutTests/platform/chromium/fast/forms/calendar-picker/date-picker-events-expected.txt	                        (rev 0)
+++ branches/chromium/1364/LayoutTests/platform/chromium/fast/forms/calendar-picker/date-picker-events-expected.txt	2013-01-24 05:48:35 UTC (rev 140651)
@@ -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
+

Copied: branches/chromium/1364/LayoutTests/platform/chromium/fast/forms/calendar-picker/date-picker-events.html (from rev 140385, trunk/LayoutTests/platform/chromium/fast/forms/calendar-picker/date-picker-events.html) (0 => 140651)


--- branches/chromium/1364/LayoutTests/platform/chromium/fast/forms/calendar-picker/date-picker-events.html	                        (rev 0)
+++ branches/chromium/1364/LayoutTests/platform/chromium/fast/forms/calendar-picker/date-picker-events.html	2013-01-24 05:48:35 UTC (rev 140651)
@@ -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>

Copied: branches/chromium/1364/LayoutTests/platform/chromium/fast/forms/calendar-picker/datetimelocal-picker-events-expected.txt (from rev 140385, trunk/LayoutTests/platform/chromium/fast/forms/calendar-picker/datetimelocal-picker-events-expected.txt) (0 => 140651)


--- branches/chromium/1364/LayoutTests/platform/chromium/fast/forms/calendar-picker/datetimelocal-picker-events-expected.txt	                        (rev 0)
+++ branches/chromium/1364/LayoutTests/platform/chromium/fast/forms/calendar-picker/datetimelocal-picker-events-expected.txt	2013-01-24 05:48:35 UTC (rev 140651)
@@ -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
+

Copied: branches/chromium/1364/LayoutTests/platform/chromium/fast/forms/calendar-picker/datetimelocal-picker-events.html (from rev 140385, trunk/LayoutTests/platform/chromium/fast/forms/calendar-picker/datetimelocal-picker-events.html) (0 => 140651)


--- branches/chromium/1364/LayoutTests/platform/chromium/fast/forms/calendar-picker/datetimelocal-picker-events.html	                        (rev 0)
+++ branches/chromium/1364/LayoutTests/platform/chromium/fast/forms/calendar-picker/datetimelocal-picker-events.html	2013-01-24 05:48:35 UTC (rev 140651)
@@ -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: branches/chromium/1364/Source/WebCore/html/BaseChooserOnlyDateAndTimeInputType.cpp (140650 => 140651)


--- branches/chromium/1364/Source/WebCore/html/BaseChooserOnlyDateAndTimeInputType.cpp	2013-01-24 05:44:15 UTC (rev 140650)
+++ branches/chromium/1364/Source/WebCore/html/BaseChooserOnlyDateAndTimeInputType.cpp	2013-01-24 05:48:35 UTC (rev 140651)
@@ -115,7 +115,7 @@
 
 void BaseChooserOnlyDateAndTimeInputType::didChooseValue(const String& value)
 {
-    element()->setValue(value, DispatchChangeEvent);
+    element()->setValue(value, DispatchInputAndChangeEvent);
 }
 
 void BaseChooserOnlyDateAndTimeInputType::didEndChooser()

Modified: branches/chromium/1364/Source/WebCore/html/BaseMultipleFieldsDateAndTimeInputType.cpp (140650 => 140651)


--- branches/chromium/1364/Source/WebCore/html/BaseMultipleFieldsDateAndTimeInputType.cpp	2013-01-24 05:44:15 UTC (rev 140650)
+++ branches/chromium/1364/Source/WebCore/html/BaseMultipleFieldsDateAndTimeInputType.cpp	2013-01-24 05:48:35 UTC (rev 140651)
@@ -140,7 +140,7 @@
 void BaseMultipleFieldsDateAndTimeInputType::pickerIndicatorChooseValue(const String& value)
 {
     if (element()->isValidValue(value)) {
-        element()->setValue(value, DispatchChangeEvent);
+        element()->setValue(value, DispatchInputAndChangeEvent);
         return;
     }
 

Modified: branches/chromium/1364/Source/WebCore/html/InputType.cpp (140650 => 140651)


--- branches/chromium/1364/Source/WebCore/html/InputType.cpp	2013-01-24 05:44:15 UTC (rev 140650)
+++ branches/chromium/1364/Source/WebCore/html/InputType.cpp	2013-01-24 05:48:35 UTC (rev 140651)
@@ -670,8 +670,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&)
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to