Title: [146584] trunk
Revision
146584
Author
[email protected]
Date
2013-03-22 03:04:16 -0700 (Fri, 22 Mar 2013)

Log Message

INPUT_MULTIPLE_FIELDS_UI: Incomplete datetime format should fallback to default
https://bugs.webkit.org/show_bug.cgi?id=113005

Patch by Kunihiko Sakamoto <[email protected]> on 2013-03-22
Reviewed by Kent Tamura.

Source/WebCore:

Use fallback format when datetime format from locale is not complete.

Tests: fast/forms/date-multiple-fields/date-multiple-fields-fallback-format.html
       fast/forms/datetime-multiple-fields/datetime-multiple-fields-fallback-format.html
       fast/forms/datetimelocal-multiple-fields/datetimelocal-multiple-fields-fallback-format.html
       fast/forms/month-multiple-fields/month-multiple-fields-fallback-format.html
       fast/forms/time-multiple-fields/time-multiple-fields-fallback-format.html
       fast/forms/week-multiple-fields/week-multiple-fields-fallback-format.html

* html/BaseMultipleFieldsDateAndTimeInputType.cpp:
(DateTimeFormatValidator): A helper class that parses datetime format and tests existence of fields.
(WebCore::DateTimeFormatValidator::DateTimeFormatValidator):
(WebCore::DateTimeFormatValidator::visitField):
(WebCore::DateTimeFormatValidator::validateFormat): Parses datetime format and validates by calling BaseMultipleFieldsDateAndTimeInputType::isValidFormat.
(WebCore::BaseMultipleFieldsDateAndTimeInputType::updateInnerTextValue): Checks if dateTimeFormat is valid, and uses fallback format if not.
* html/BaseMultipleFieldsDateAndTimeInputType.h:
(BaseMultipleFieldsDateAndTimeInputType): Declare isValidFormat.
* html/DateInputType.cpp:
(WebCore::DateInputType::isValidFormat): Added.
* html/DateInputType.h:
(DateInputType):
* html/DateTimeInputType.cpp:
(WebCore::DateTimeInputType::isValidFormat): Added.
* html/DateTimeInputType.h:
(DateTimeInputType):
* html/DateTimeLocalInputType.cpp:
(WebCore::DateTimeLocalInputType::isValidFormat): Added.
* html/DateTimeLocalInputType.h:
(DateTimeLocalInputType):
* html/MonthInputType.cpp:
(WebCore::MonthInputType::isValidFormat): Added.
* html/MonthInputType.h:
(MonthInputType):
* html/TimeInputType.cpp:
(WebCore::TimeInputType::isValidFormat): Added.
* html/TimeInputType.h:
(TimeInputType):
* html/WeekInputType.cpp:
(WebCore::WeekInputType::isValidFormat): Added.
* html/WeekInputType.h:
(WeekInputType):

LayoutTests:

* fast/forms/date-multiple-fields/date-multiple-fields-fallback-format-expected.txt: Added.
* fast/forms/date-multiple-fields/date-multiple-fields-fallback-format.html: Added.
* fast/forms/datetime-multiple-fields/datetime-multiple-fields-fallback-format-expected.txt: Added.
* fast/forms/datetime-multiple-fields/datetime-multiple-fields-fallback-format.html: Added.
* fast/forms/datetimelocal-multiple-fields/datetimelocal-multiple-fields-fallback-format-expected.txt: Added.
* fast/forms/datetimelocal-multiple-fields/datetimelocal-multiple-fields-fallback-format.html: Added.
* fast/forms/month-multiple-fields/month-multiple-fields-fallback-format-expected.txt: Added.
* fast/forms/month-multiple-fields/month-multiple-fields-fallback-format.html: Added.
* fast/forms/time-multiple-fields/time-multiple-fields-fallback-format-expected.txt: Added.
* fast/forms/time-multiple-fields/time-multiple-fields-fallback-format.html: Added.
* fast/forms/week-multiple-fields/week-multiple-fields-fallback-format-expected.txt: Added.
* fast/forms/week-multiple-fields/week-multiple-fields-fallback-format.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (146583 => 146584)


--- trunk/LayoutTests/ChangeLog	2013-03-22 09:54:06 UTC (rev 146583)
+++ trunk/LayoutTests/ChangeLog	2013-03-22 10:04:16 UTC (rev 146584)
@@ -1,3 +1,23 @@
+2013-03-22  Kunihiko Sakamoto  <[email protected]>
+
+        INPUT_MULTIPLE_FIELDS_UI: Incomplete datetime format should fallback to default
+        https://bugs.webkit.org/show_bug.cgi?id=113005
+
+        Reviewed by Kent Tamura.
+
+        * fast/forms/date-multiple-fields/date-multiple-fields-fallback-format-expected.txt: Added.
+        * fast/forms/date-multiple-fields/date-multiple-fields-fallback-format.html: Added.
+        * fast/forms/datetime-multiple-fields/datetime-multiple-fields-fallback-format-expected.txt: Added.
+        * fast/forms/datetime-multiple-fields/datetime-multiple-fields-fallback-format.html: Added.
+        * fast/forms/datetimelocal-multiple-fields/datetimelocal-multiple-fields-fallback-format-expected.txt: Added.
+        * fast/forms/datetimelocal-multiple-fields/datetimelocal-multiple-fields-fallback-format.html: Added.
+        * fast/forms/month-multiple-fields/month-multiple-fields-fallback-format-expected.txt: Added.
+        * fast/forms/month-multiple-fields/month-multiple-fields-fallback-format.html: Added.
+        * fast/forms/time-multiple-fields/time-multiple-fields-fallback-format-expected.txt: Added.
+        * fast/forms/time-multiple-fields/time-multiple-fields-fallback-format.html: Added.
+        * fast/forms/week-multiple-fields/week-multiple-fields-fallback-format-expected.txt: Added.
+        * fast/forms/week-multiple-fields/week-multiple-fields-fallback-format.html: Added.
+
 2013-03-22  Hajime Morrita  <[email protected]>
 
         Custom Elements: "readyCallback" lifecycle callback should be called.

Added: trunk/LayoutTests/fast/forms/date-multiple-fields/date-multiple-fields-fallback-format-expected.txt (0 => 146584)


--- trunk/LayoutTests/fast/forms/date-multiple-fields/date-multiple-fields-fallback-format-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/forms/date-multiple-fields/date-multiple-fields-fallback-format-expected.txt	2013-03-22 10:04:16 UTC (rev 146584)
@@ -0,0 +1,15 @@
+Checks incomplete datetime formats are rejected.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+Valid format
+PASS getUserAgentShadowTextContent(input) is "31-07-1999"
+Invalid format, fallback to yyyy-MM-dd
+PASS getUserAgentShadowTextContent(input) is "1999-07-31"
+PASS getUserAgentShadowTextContent(input) is "1999-07-31"
+PASS getUserAgentShadowTextContent(input) is "1999-07-31"
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/fast/forms/date-multiple-fields/date-multiple-fields-fallback-format.html (0 => 146584)


--- trunk/LayoutTests/fast/forms/date-multiple-fields/date-multiple-fields-fallback-format.html	                        (rev 0)
+++ trunk/LayoutTests/fast/forms/date-multiple-fields/date-multiple-fields-fallback-format.html	2013-03-22 10:04:16 UTC (rev 146584)
@@ -0,0 +1,39 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src=""
+<script src=""
+</head>
+<body>
+<script>
+description('Checks incomplete datetime formats are rejected.');
+
+var input = document.createElement('input');
+input.type = 'date';
+document.body.appendChild(input);
+
+function setDateTimeFormat(pattern) {
+    var value = input.value;
+    getElementByPseudoId(internals.youngestShadowRoot(input), '-webkit-datetime-edit').setAttribute('pattern', pattern);
+    input.value = ''; // Updates the element for new format
+    input.value = value;
+}
+
+input.value = '1999-07-31';
+
+debug('Valid format');
+setDateTimeFormat("dd-MM-yyyy");
+shouldBeEqualToString('getUserAgentShadowTextContent(input)', '31-07-1999');
+
+debug("Invalid format, fallback to yyyy-MM-dd");
+setDateTimeFormat('yyyy-MM');
+shouldBeEqualToString('getUserAgentShadowTextContent(input)', '1999-07-31');
+setDateTimeFormat('MM/dd');
+shouldBeEqualToString('getUserAgentShadowTextContent(input)', '1999-07-31');
+setDateTimeFormat('dd-yyyy');
+shouldBeEqualToString('getUserAgentShadowTextContent(input)', '1999-07-31');
+
+</script>
+<script src=""
+</body>
+</html>

Added: trunk/LayoutTests/fast/forms/datetime-multiple-fields/datetime-multiple-fields-fallback-format-expected.txt (0 => 146584)


--- trunk/LayoutTests/fast/forms/datetime-multiple-fields/datetime-multiple-fields-fallback-format-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/forms/datetime-multiple-fields/datetime-multiple-fields-fallback-format-expected.txt	2013-03-22 10:04:16 UTC (rev 146584)
@@ -0,0 +1,15 @@
+Checks incomplete datetime formats are rejected.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+Valid format
+PASS getUserAgentShadowTextContent(input) is "1999-07-31 11:59 PM"
+Invalid format, fallback to yyyy-MM-dd'T'HH:mm
+PASS getUserAgentShadowTextContent(input) is "1999-07-31T23:59"
+PASS getUserAgentShadowTextContent(input) is "1999-07-31T23:59"
+PASS getUserAgentShadowTextContent(input) is "1999-07-31T23:59"
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/fast/forms/datetime-multiple-fields/datetime-multiple-fields-fallback-format.html (0 => 146584)


--- trunk/LayoutTests/fast/forms/datetime-multiple-fields/datetime-multiple-fields-fallback-format.html	                        (rev 0)
+++ trunk/LayoutTests/fast/forms/datetime-multiple-fields/datetime-multiple-fields-fallback-format.html	2013-03-22 10:04:16 UTC (rev 146584)
@@ -0,0 +1,39 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src=""
+<script src=""
+</head>
+<body>
+<script>
+description('Checks incomplete datetime formats are rejected.');
+
+var input = document.createElement('input');
+input.type = 'datetime-local';
+document.body.appendChild(input);
+
+function setDateTimeFormat(pattern) {
+    var value = input.value;
+    getElementByPseudoId(internals.youngestShadowRoot(input), '-webkit-datetime-edit').setAttribute('pattern', pattern);
+    input.value = ''; // Updates the element for new format
+    input.value = value;
+}
+
+input.value = '1999-07-31T23:59';
+
+debug('Valid format');
+setDateTimeFormat("yyyy-MM-dd hh:mm a");
+shouldBeEqualToString('getUserAgentShadowTextContent(input)', '1999-07-31 11:59 PM');
+
+debug("Invalid format, fallback to yyyy-MM-dd'T'HH:mm");
+setDateTimeFormat('yyyy-MM-dd');
+shouldBeEqualToString('getUserAgentShadowTextContent(input)', '1999-07-31T23:59');
+setDateTimeFormat('HH:mm');
+shouldBeEqualToString('getUserAgentShadowTextContent(input)', '1999-07-31T23:59');
+setDateTimeFormat("yyyy-MM-dd'T'hh:mm");
+shouldBeEqualToString('getUserAgentShadowTextContent(input)', '1999-07-31T23:59');
+
+</script>
+<script src=""
+</body>
+</html>

Added: trunk/LayoutTests/fast/forms/datetimelocal-multiple-fields/datetimelocal-multiple-fields-fallback-format-expected.txt (0 => 146584)


--- trunk/LayoutTests/fast/forms/datetimelocal-multiple-fields/datetimelocal-multiple-fields-fallback-format-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/forms/datetimelocal-multiple-fields/datetimelocal-multiple-fields-fallback-format-expected.txt	2013-03-22 10:04:16 UTC (rev 146584)
@@ -0,0 +1,15 @@
+Checks incomplete datetime formats are rejected.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+Valid format
+PASS getUserAgentShadowTextContent(input) is "1999-07-31 11:59 PM"
+Invalid format, fallback to yyyy-MM-dd'T'HH:mm
+PASS getUserAgentShadowTextContent(input) is "1999-07-31T23:59"
+PASS getUserAgentShadowTextContent(input) is "1999-07-31T23:59"
+PASS getUserAgentShadowTextContent(input) is "1999-07-31T23:59"
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/fast/forms/datetimelocal-multiple-fields/datetimelocal-multiple-fields-fallback-format.html (0 => 146584)


--- trunk/LayoutTests/fast/forms/datetimelocal-multiple-fields/datetimelocal-multiple-fields-fallback-format.html	                        (rev 0)
+++ trunk/LayoutTests/fast/forms/datetimelocal-multiple-fields/datetimelocal-multiple-fields-fallback-format.html	2013-03-22 10:04:16 UTC (rev 146584)
@@ -0,0 +1,39 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src=""
+<script src=""
+</head>
+<body>
+<script>
+description('Checks incomplete datetime formats are rejected.');
+
+var input = document.createElement('input');
+input.type = 'datetime-local';
+document.body.appendChild(input);
+
+function setDateTimeFormat(pattern) {
+    var value = input.value;
+    getElementByPseudoId(internals.youngestShadowRoot(input), '-webkit-datetime-edit').setAttribute('pattern', pattern);
+    input.value = ''; // Updates the element for new format
+    input.value = value;
+}
+
+input.value = '1999-07-31T23:59';
+
+debug('Valid format');
+setDateTimeFormat("yyyy-MM-dd hh:mm a");
+shouldBeEqualToString('getUserAgentShadowTextContent(input)', '1999-07-31 11:59 PM');
+
+debug("Invalid format, fallback to yyyy-MM-dd'T'HH:mm");
+setDateTimeFormat('yyyy-MM-dd');
+shouldBeEqualToString('getUserAgentShadowTextContent(input)', '1999-07-31T23:59');
+setDateTimeFormat('HH:mm');
+shouldBeEqualToString('getUserAgentShadowTextContent(input)', '1999-07-31T23:59');
+setDateTimeFormat("yyyy-MM-dd'T'hh:mm");
+shouldBeEqualToString('getUserAgentShadowTextContent(input)', '1999-07-31T23:59');
+
+</script>
+<script src=""
+</body>
+</html>

Added: trunk/LayoutTests/fast/forms/month-multiple-fields/month-multiple-fields-fallback-format-expected.txt (0 => 146584)


--- trunk/LayoutTests/fast/forms/month-multiple-fields/month-multiple-fields-fallback-format-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/forms/month-multiple-fields/month-multiple-fields-fallback-format-expected.txt	2013-03-22 10:04:16 UTC (rev 146584)
@@ -0,0 +1,14 @@
+Checks incomplete datetime formats are rejected.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+Valid format
+PASS getUserAgentShadowTextContent(input) is "07-1999"
+Invalid format, fallback to yyyy-MM
+PASS getUserAgentShadowTextContent(input) is "1999-07"
+PASS getUserAgentShadowTextContent(input) is "1999-07"
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/fast/forms/month-multiple-fields/month-multiple-fields-fallback-format.html (0 => 146584)


--- trunk/LayoutTests/fast/forms/month-multiple-fields/month-multiple-fields-fallback-format.html	                        (rev 0)
+++ trunk/LayoutTests/fast/forms/month-multiple-fields/month-multiple-fields-fallback-format.html	2013-03-22 10:04:16 UTC (rev 146584)
@@ -0,0 +1,37 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src=""
+<script src=""
+</head>
+<body>
+<script>
+description('Checks incomplete datetime formats are rejected.');
+
+var input = document.createElement('input');
+input.type = 'month';
+document.body.appendChild(input);
+
+function setDateTimeFormat(pattern) {
+    var value = input.value;
+    getElementByPseudoId(internals.youngestShadowRoot(input), '-webkit-datetime-edit').setAttribute('pattern', pattern);
+    input.value = ''; // Updates the element for new format
+    input.value = value;
+}
+
+input.value = '1999-07';
+
+debug('Valid format');
+setDateTimeFormat('MM-yyyy');
+shouldBeEqualToString('getUserAgentShadowTextContent(input)', '07-1999');
+
+debug('Invalid format, fallback to yyyy-MM');
+setDateTimeFormat('mm-yyyy');
+shouldBeEqualToString('getUserAgentShadowTextContent(input)', '1999-07');
+setDateTimeFormat('M');
+shouldBeEqualToString('getUserAgentShadowTextContent(input)', '1999-07');
+
+</script>
+<script src=""
+</body>
+</html>

Added: trunk/LayoutTests/fast/forms/time-multiple-fields/time-multiple-fields-fallback-format-expected.txt (0 => 146584)


--- trunk/LayoutTests/fast/forms/time-multiple-fields/time-multiple-fields-fallback-format-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/forms/time-multiple-fields/time-multiple-fields-fallback-format-expected.txt	2013-03-22 10:04:16 UTC (rev 146584)
@@ -0,0 +1,17 @@
+Checks incomplete datetime formats are rejected.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+Valid format
+PASS getUserAgentShadowTextContent(input) is "01.234:59:11 PM"
+PASS getUserAgentShadowTextContent(input) is "01.234:59:23"
+PASS getUserAgentShadowTextContent(input) is "01.234:59:23 PM"
+Invalid format, fallback to HH:mm:ss
+PASS getUserAgentShadowTextContent(input) is "23:59:01.234"
+PASS getUserAgentShadowTextContent(input) is "23:59:01.234"
+PASS getUserAgentShadowTextContent(input) is "23:59:01.234"
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/fast/forms/time-multiple-fields/time-multiple-fields-fallback-format.html (0 => 146584)


--- trunk/LayoutTests/fast/forms/time-multiple-fields/time-multiple-fields-fallback-format.html	                        (rev 0)
+++ trunk/LayoutTests/fast/forms/time-multiple-fields/time-multiple-fields-fallback-format.html	2013-03-22 10:04:16 UTC (rev 146584)
@@ -0,0 +1,43 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src=""
+<script src=""
+</head>
+<body>
+<script>
+description('Checks incomplete datetime formats are rejected.');
+
+var input = document.createElement('input');
+input.type = 'time';
+document.body.appendChild(input);
+
+function setDateTimeFormat(pattern) {
+    var value = input.value;
+    getElementByPseudoId(internals.youngestShadowRoot(input), '-webkit-datetime-edit').setAttribute('pattern', pattern);
+    input.value = ''; // Updates the element for new format
+    input.value = value;
+}
+
+input.value = '23:59:01.234';
+
+debug('Valid format');
+setDateTimeFormat('ss:mm:hh a');
+shouldBeEqualToString('getUserAgentShadowTextContent(input)', '01.234:59:11 PM');
+setDateTimeFormat('ss:mm:HH');
+shouldBeEqualToString('getUserAgentShadowTextContent(input)', '01.234:59:23');
+setDateTimeFormat('ss:mm:HH a');
+shouldBeEqualToString('getUserAgentShadowTextContent(input)', '01.234:59:23 PM');
+
+debug('Invalid format, fallback to HH:mm:ss');
+setDateTimeFormat('HH');
+shouldBeEqualToString('getUserAgentShadowTextContent(input)', '23:59:01.234');
+setDateTimeFormat('mm:ss');
+shouldBeEqualToString('getUserAgentShadowTextContent(input)', '23:59:01.234');
+setDateTimeFormat('hh:mm:ss');
+shouldBeEqualToString('getUserAgentShadowTextContent(input)', '23:59:01.234');
+
+</script>
+<script src=""
+</body>
+</html>

Added: trunk/LayoutTests/fast/forms/week-multiple-fields/week-multiple-fields-fallback-format-expected.txt (0 => 146584)


--- trunk/LayoutTests/fast/forms/week-multiple-fields/week-multiple-fields-fallback-format-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/forms/week-multiple-fields/week-multiple-fields-fallback-format-expected.txt	2013-03-22 10:04:16 UTC (rev 146584)
@@ -0,0 +1,14 @@
+Checks incomplete datetime formats are rejected.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+Valid format
+PASS getUserAgentShadowTextContent(input) is "Week09 1999"
+Invalid format, fallback to yyyy-'W'ww
+PASS getUserAgentShadowTextContent(input) is "1999-W09"
+PASS getUserAgentShadowTextContent(input) is "1999-W09"
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/fast/forms/week-multiple-fields/week-multiple-fields-fallback-format.html (0 => 146584)


--- trunk/LayoutTests/fast/forms/week-multiple-fields/week-multiple-fields-fallback-format.html	                        (rev 0)
+++ trunk/LayoutTests/fast/forms/week-multiple-fields/week-multiple-fields-fallback-format.html	2013-03-22 10:04:16 UTC (rev 146584)
@@ -0,0 +1,37 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src=""
+<script src=""
+</head>
+<body>
+<script>
+description('Checks incomplete datetime formats are rejected.');
+
+var input = document.createElement('input');
+input.type = 'week';
+document.body.appendChild(input);
+
+function setDateTimeFormat(pattern) {
+    var value = input.value;
+    getElementByPseudoId(internals.youngestShadowRoot(input), '-webkit-datetime-edit').setAttribute('pattern', pattern);
+    input.value = ''; // Updates the element for new format
+    input.value = value;
+}
+
+input.value = '1999-W09';
+
+debug('Valid format');
+setDateTimeFormat("'Week'ww yyyy");
+shouldBeEqualToString('getUserAgentShadowTextContent(input)', 'Week09 1999');
+
+debug("Invalid format, fallback to yyyy-'W'ww");
+setDateTimeFormat('ww');
+shouldBeEqualToString('getUserAgentShadowTextContent(input)', '1999-W09');
+setDateTimeFormat('yyyy');
+shouldBeEqualToString('getUserAgentShadowTextContent(input)', '1999-W09');
+
+</script>
+<script src=""
+</body>
+</html>

Modified: trunk/Source/WebCore/ChangeLog (146583 => 146584)


--- trunk/Source/WebCore/ChangeLog	2013-03-22 09:54:06 UTC (rev 146583)
+++ trunk/Source/WebCore/ChangeLog	2013-03-22 10:04:16 UTC (rev 146584)
@@ -1,3 +1,52 @@
+2013-03-22  Kunihiko Sakamoto  <[email protected]>
+
+        INPUT_MULTIPLE_FIELDS_UI: Incomplete datetime format should fallback to default
+        https://bugs.webkit.org/show_bug.cgi?id=113005
+
+        Reviewed by Kent Tamura.
+
+        Use fallback format when datetime format from locale is not complete.
+
+        Tests: fast/forms/date-multiple-fields/date-multiple-fields-fallback-format.html
+               fast/forms/datetime-multiple-fields/datetime-multiple-fields-fallback-format.html
+               fast/forms/datetimelocal-multiple-fields/datetimelocal-multiple-fields-fallback-format.html
+               fast/forms/month-multiple-fields/month-multiple-fields-fallback-format.html
+               fast/forms/time-multiple-fields/time-multiple-fields-fallback-format.html
+               fast/forms/week-multiple-fields/week-multiple-fields-fallback-format.html
+
+        * html/BaseMultipleFieldsDateAndTimeInputType.cpp:
+        (DateTimeFormatValidator): A helper class that parses datetime format and tests existence of fields.
+        (WebCore::DateTimeFormatValidator::DateTimeFormatValidator):
+        (WebCore::DateTimeFormatValidator::visitField):
+        (WebCore::DateTimeFormatValidator::validateFormat): Parses datetime format and validates by calling BaseMultipleFieldsDateAndTimeInputType::isValidFormat.
+        (WebCore::BaseMultipleFieldsDateAndTimeInputType::updateInnerTextValue): Checks if dateTimeFormat is valid, and uses fallback format if not.
+        * html/BaseMultipleFieldsDateAndTimeInputType.h:
+        (BaseMultipleFieldsDateAndTimeInputType): Declare isValidFormat.
+        * html/DateInputType.cpp:
+        (WebCore::DateInputType::isValidFormat): Added.
+        * html/DateInputType.h:
+        (DateInputType):
+        * html/DateTimeInputType.cpp:
+        (WebCore::DateTimeInputType::isValidFormat): Added.
+        * html/DateTimeInputType.h:
+        (DateTimeInputType):
+        * html/DateTimeLocalInputType.cpp:
+        (WebCore::DateTimeLocalInputType::isValidFormat): Added.
+        * html/DateTimeLocalInputType.h:
+        (DateTimeLocalInputType):
+        * html/MonthInputType.cpp:
+        (WebCore::MonthInputType::isValidFormat): Added.
+        * html/MonthInputType.h:
+        (MonthInputType):
+        * html/TimeInputType.cpp:
+        (WebCore::TimeInputType::isValidFormat): Added.
+        * html/TimeInputType.h:
+        (TimeInputType):
+        * html/WeekInputType.cpp:
+        (WebCore::WeekInputType::isValidFormat): Added.
+        * html/WeekInputType.h:
+        (WeekInputType):
+
 2013-03-22  Hajime Morrita  <[email protected]>
 
         Custom Elements: "readyCallback" lifecycle callback should be called.

Modified: trunk/Source/WebCore/html/BaseMultipleFieldsDateAndTimeInputType.cpp (146583 => 146584)


--- trunk/Source/WebCore/html/BaseMultipleFieldsDateAndTimeInputType.cpp	2013-03-22 09:54:06 UTC (rev 146583)
+++ trunk/Source/WebCore/html/BaseMultipleFieldsDateAndTimeInputType.cpp	2013-03-22 10:04:16 UTC (rev 146584)
@@ -35,6 +35,7 @@
 #include "CSSValueKeywords.h"
 #include "DateComponents.h"
 #include "DateTimeFieldsState.h"
+#include "DateTimeFormat.h"
 #include "ElementShadow.h"
 #include "FocusController.h"
 #include "FormController.h"
@@ -53,6 +54,80 @@
 
 namespace WebCore {
 
+class DateTimeFormatValidator : public DateTimeFormat::TokenHandler {
+public:
+    DateTimeFormatValidator()
+        : m_hasYear(false)
+        , m_hasMonth(false)
+        , m_hasWeek(false)
+        , m_hasDay(false)
+        , m_hasAMPM(false)
+        , m_hasHour(false)
+        , m_hasMinute(false)
+        , m_hasSecond(false) { }
+
+    virtual void visitField(DateTimeFormat::FieldType, int) OVERRIDE FINAL;
+    virtual void visitLiteral(const String&) OVERRIDE FINAL { }
+
+    bool validateFormat(const String& format, const BaseMultipleFieldsDateAndTimeInputType&);
+
+private:
+    bool m_hasYear;
+    bool m_hasMonth;
+    bool m_hasWeek;
+    bool m_hasDay;
+    bool m_hasAMPM;
+    bool m_hasHour;
+    bool m_hasMinute;
+    bool m_hasSecond;
+};
+
+void DateTimeFormatValidator::visitField(DateTimeFormat::FieldType fieldType, int)
+{
+    switch (fieldType) {
+    case DateTimeFormat::FieldTypeYear:
+        m_hasYear = true;
+        break;
+    case DateTimeFormat::FieldTypeMonth: // Fallthrough.
+    case DateTimeFormat::FieldTypeMonthStandAlone:
+        m_hasMonth = true;
+        break;
+    case DateTimeFormat::FieldTypeWeekOfYear:
+        m_hasWeek = true;
+        break;
+    case DateTimeFormat::FieldTypeDayOfMonth:
+        m_hasDay = true;
+        break;
+    case DateTimeFormat::FieldTypePeriod:
+        m_hasAMPM = true;
+        break;
+    case DateTimeFormat::FieldTypeHour11: // Fallthrough.
+    case DateTimeFormat::FieldTypeHour12:
+        m_hasHour = true;
+        break;
+    case DateTimeFormat::FieldTypeHour23: // Fallthrough.
+    case DateTimeFormat::FieldTypeHour24:
+        m_hasHour = true;
+        m_hasAMPM = true;
+        break;
+    case DateTimeFormat::FieldTypeMinute:
+        m_hasMinute = true;
+        break;
+    case DateTimeFormat::FieldTypeSecond:
+        m_hasSecond = true;
+        break;
+    default:
+        break;
+    }
+}
+
+bool DateTimeFormatValidator::validateFormat(const String& format, const BaseMultipleFieldsDateAndTimeInputType& inputType)
+{
+    if (!DateTimeFormat::parse(format, *this))
+        return false;
+    return inputType.isValidFormat(m_hasYear, m_hasMonth, m_hasWeek, m_hasDay, m_hasAMPM, m_hasHour, m_hasMinute, m_hasSecond);
+}
+
 void BaseMultipleFieldsDateAndTimeInputType::didBlurFromControl()
 {
     // We don't need to call blur(). This function is called when control
@@ -410,6 +485,9 @@
     if (!pattern.isEmpty())
         layoutParameters.dateTimeFormat = pattern;
 
+    if (!DateTimeFormatValidator().validateFormat(layoutParameters.dateTimeFormat, *this))
+        layoutParameters.dateTimeFormat = layoutParameters.fallbackDateTimeFormat;
+
     if (hasValue)
         m_dateTimeEditElement->setValueAsDate(layoutParameters, date);
     else

Modified: trunk/Source/WebCore/html/BaseMultipleFieldsDateAndTimeInputType.h (146583 => 146584)


--- trunk/Source/WebCore/html/BaseMultipleFieldsDateAndTimeInputType.h	2013-03-22 09:54:06 UTC (rev 146583)
+++ trunk/Source/WebCore/html/BaseMultipleFieldsDateAndTimeInputType.h	2013-03-22 10:04:16 UTC (rev 146584)
@@ -49,6 +49,9 @@
     , protected PickerIndicatorElement::PickerIndicatorOwner
     , protected SpinButtonElement::SpinButtonOwner
     , protected ClearButtonElement::ClearButtonOwner {
+public:
+    virtual bool isValidFormat(bool hasYear, bool hasMonth, bool hasWeek, bool hasDay, bool hasAMPM, bool hasHour, bool hasMinute, bool hasSecond) const = 0;
+
 protected:
     BaseMultipleFieldsDateAndTimeInputType(HTMLInputElement*);
     virtual ~BaseMultipleFieldsDateAndTimeInputType();

Modified: trunk/Source/WebCore/html/DateInputType.cpp (146583 => 146584)


--- trunk/Source/WebCore/html/DateInputType.cpp	2013-03-22 09:54:06 UTC (rev 146583)
+++ trunk/Source/WebCore/html/DateInputType.cpp	2013-03-22 10:04:16 UTC (rev 146584)
@@ -126,6 +126,11 @@
     layoutParameters.placeholderForMonth = placeholderForMonthField();
     layoutParameters.placeholderForYear = placeholderForYearField();
 }
+
+bool DateInputType::isValidFormat(bool hasYear, bool hasMonth, bool hasWeek, bool hasDay, bool hasAMPM, bool hasHour, bool hasMinute, bool hasSecond) const
+{
+    return hasYear && hasMonth && hasDay;
+}
 #endif
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/html/DateInputType.h (146583 => 146584)


--- trunk/Source/WebCore/html/DateInputType.h	2013-03-22 09:54:06 UTC (rev 146583)
+++ trunk/Source/WebCore/html/DateInputType.h	2013-03-22 10:04:16 UTC (rev 146584)
@@ -64,6 +64,7 @@
     // BaseMultipleFieldsDateAndTimeInputType functions
     virtual String formatDateTimeFieldsState(const DateTimeFieldsState&) const OVERRIDE;
     virtual void setupLayoutParameters(DateTimeEditElement::LayoutParameters&, const DateComponents&) const OVERRIDE;
+    virtual bool isValidFormat(bool hasYear, bool hasMonth, bool hasWeek, bool hasDay, bool hasAMPM, bool hasHour, bool hasMinute, bool hasSecond) const;
 #endif
 };
 

Modified: trunk/Source/WebCore/html/DateTimeInputType.cpp (146583 => 146584)


--- trunk/Source/WebCore/html/DateTimeInputType.cpp	2013-03-22 09:54:06 UTC (rev 146583)
+++ trunk/Source/WebCore/html/DateTimeInputType.cpp	2013-03-22 10:04:16 UTC (rev 146584)
@@ -164,6 +164,11 @@
     layoutParameters.placeholderForMonth = placeholderForMonthField();
     layoutParameters.placeholderForYear = placeholderForYearField();
 }
+
+bool DateTimeInputType::isValidFormat(bool hasYear, bool hasMonth, bool hasWeek, bool hasDay, bool hasAMPM, bool hasHour, bool hasMinute, bool hasSecond) const
+{
+    return hasYear && hasMonth && hasDay && hasAMPM && hasHour && hasMinute;
+}
 #endif
 
 String DateTimeInputType::sanitizeValue(const String& proposedValue) const

Modified: trunk/Source/WebCore/html/DateTimeInputType.h (146583 => 146584)


--- trunk/Source/WebCore/html/DateTimeInputType.h	2013-03-22 09:54:06 UTC (rev 146583)
+++ trunk/Source/WebCore/html/DateTimeInputType.h	2013-03-22 10:04:16 UTC (rev 146584)
@@ -64,6 +64,7 @@
     // BaseMultipleFieldsDateAndTimeInputType functions
     virtual String formatDateTimeFieldsState(const DateTimeFieldsState&) const OVERRIDE FINAL;
     virtual void setupLayoutParameters(DateTimeEditElement::LayoutParameters&, const DateComponents&) const OVERRIDE FINAL;
+    virtual bool isValidFormat(bool hasYear, bool hasMonth, bool hasWeek, bool hasDay, bool hasAMPM, bool hasHour, bool hasMinute, bool hasSecond) const;
 #endif
 };
 

Modified: trunk/Source/WebCore/html/DateTimeLocalInputType.cpp (146583 => 146584)


--- trunk/Source/WebCore/html/DateTimeLocalInputType.cpp	2013-03-22 09:54:06 UTC (rev 146583)
+++ trunk/Source/WebCore/html/DateTimeLocalInputType.cpp	2013-03-22 10:04:16 UTC (rev 146584)
@@ -170,6 +170,11 @@
     layoutParameters.placeholderForMonth = placeholderForMonthField();
     layoutParameters.placeholderForYear = placeholderForYearField();
 }
+
+bool DateTimeLocalInputType::isValidFormat(bool hasYear, bool hasMonth, bool hasWeek, bool hasDay, bool hasAMPM, bool hasHour, bool hasMinute, bool hasSecond) const
+{
+    return hasYear && hasMonth && hasDay && hasAMPM && hasHour && hasMinute;
+}
 #endif
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/html/DateTimeLocalInputType.h (146583 => 146584)


--- trunk/Source/WebCore/html/DateTimeLocalInputType.h	2013-03-22 09:54:06 UTC (rev 146583)
+++ trunk/Source/WebCore/html/DateTimeLocalInputType.h	2013-03-22 10:04:16 UTC (rev 146584)
@@ -63,6 +63,7 @@
     // BaseMultipleFieldsDateAndTimeInputType functions
     virtual String formatDateTimeFieldsState(const DateTimeFieldsState&) const OVERRIDE FINAL;
     virtual void setupLayoutParameters(DateTimeEditElement::LayoutParameters&, const DateComponents&) const OVERRIDE FINAL;
+    virtual bool isValidFormat(bool hasYear, bool hasMonth, bool hasWeek, bool hasDay, bool hasAMPM, bool hasHour, bool hasMinute, bool hasSecond) const;
 #endif
 };
 

Modified: trunk/Source/WebCore/html/MonthInputType.cpp (146583 => 146584)


--- trunk/Source/WebCore/html/MonthInputType.cpp	2013-03-22 09:54:06 UTC (rev 146583)
+++ trunk/Source/WebCore/html/MonthInputType.cpp	2013-03-22 10:04:16 UTC (rev 146584)
@@ -167,6 +167,11 @@
     layoutParameters.placeholderForMonth = "--";
     layoutParameters.placeholderForYear = "----";
 }
+
+bool MonthInputType::isValidFormat(bool hasYear, bool hasMonth, bool hasWeek, bool hasDay, bool hasAMPM, bool hasHour, bool hasMinute, bool hasSecond) const
+{
+    return hasYear && hasMonth;
+}
 #endif
 } // namespace WebCore
 

Modified: trunk/Source/WebCore/html/MonthInputType.h (146583 => 146584)


--- trunk/Source/WebCore/html/MonthInputType.h	2013-03-22 09:54:06 UTC (rev 146583)
+++ trunk/Source/WebCore/html/MonthInputType.h	2013-03-22 10:04:16 UTC (rev 146584)
@@ -65,6 +65,7 @@
     // BaseMultipleFieldsDateAndTimeInputType functions
     virtual String formatDateTimeFieldsState(const DateTimeFieldsState&) const OVERRIDE FINAL;
     virtual void setupLayoutParameters(DateTimeEditElement::LayoutParameters&, const DateComponents&) const OVERRIDE FINAL;
+    virtual bool isValidFormat(bool hasYear, bool hasMonth, bool hasWeek, bool hasDay, bool hasAMPM, bool hasHour, bool hasMinute, bool hasSecond) const;
 #endif
 };
 

Modified: trunk/Source/WebCore/html/TimeInputType.cpp (146583 => 146584)


--- trunk/Source/WebCore/html/TimeInputType.cpp	2013-03-22 09:54:06 UTC (rev 146583)
+++ trunk/Source/WebCore/html/TimeInputType.cpp	2013-03-22 10:04:16 UTC (rev 146584)
@@ -170,6 +170,11 @@
     if (!parseToDateComponents(element()->fastGetAttribute(maxAttr), &layoutParameters.maximum))
         layoutParameters.maximum = DateComponents();
 }
+
+bool TimeInputType::isValidFormat(bool hasYear, bool hasMonth, bool hasWeek, bool hasDay, bool hasAMPM, bool hasHour, bool hasMinute, bool hasSecond) const
+{
+    return hasHour && hasMinute && hasAMPM;
+}
 #endif
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/html/TimeInputType.h (146583 => 146584)


--- trunk/Source/WebCore/html/TimeInputType.h	2013-03-22 09:54:06 UTC (rev 146583)
+++ trunk/Source/WebCore/html/TimeInputType.h	2013-03-22 10:04:16 UTC (rev 146584)
@@ -63,6 +63,7 @@
     // BaseMultipleFieldsDateAndTimeInputType functions
     virtual String formatDateTimeFieldsState(const DateTimeFieldsState&) const OVERRIDE FINAL;
     virtual void setupLayoutParameters(DateTimeEditElement::LayoutParameters&, const DateComponents&) const OVERRIDE FINAL;
+    virtual bool isValidFormat(bool hasYear, bool hasMonth, bool hasWeek, bool hasDay, bool hasAMPM, bool hasHour, bool hasMinute, bool hasSecond) const;
 #endif
 };
 

Modified: trunk/Source/WebCore/html/WeekInputType.cpp (146583 => 146584)


--- trunk/Source/WebCore/html/WeekInputType.cpp	2013-03-22 09:54:06 UTC (rev 146583)
+++ trunk/Source/WebCore/html/WeekInputType.cpp	2013-03-22 10:04:16 UTC (rev 146584)
@@ -120,6 +120,11 @@
         layoutParameters.maximum = DateComponents();
     layoutParameters.placeholderForYear = "----";
 }
+
+bool WeekInputType::isValidFormat(bool hasYear, bool hasMonth, bool hasWeek, bool hasDay, bool hasAMPM, bool hasHour, bool hasMinute, bool hasSecond) const
+{
+    return hasYear && hasWeek;
+}
 #endif
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/html/WeekInputType.h (146583 => 146584)


--- trunk/Source/WebCore/html/WeekInputType.h	2013-03-22 09:54:06 UTC (rev 146583)
+++ trunk/Source/WebCore/html/WeekInputType.h	2013-03-22 10:04:16 UTC (rev 146584)
@@ -61,6 +61,7 @@
     // BaseMultipleFieldsDateAndTimeInputType functions
     virtual String formatDateTimeFieldsState(const DateTimeFieldsState&) const OVERRIDE FINAL;
     virtual void setupLayoutParameters(DateTimeEditElement::LayoutParameters&, const DateComponents&) const OVERRIDE FINAL;
+    virtual bool isValidFormat(bool hasYear, bool hasMonth, bool hasWeek, bool hasDay, bool hasAMPM, bool hasHour, bool hasMinute, bool hasSecond) const;
 #endif
 };
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to