diff options
author | commit-queue@webkit.org <commit-queue@webkit.org@bbb929c8-8fbe-4397-9dbb-9b2b20218538> | 2013-03-22 10:04:16 +0000 |
---|---|---|
committer | commit-queue@webkit.org <commit-queue@webkit.org@bbb929c8-8fbe-4397-9dbb-9b2b20218538> | 2013-03-22 10:04:16 +0000 |
commit | 1b5ee4337fe825d39095d42dbd596f153c48ac36 (patch) | |
tree | e2ceefb56b6cf2edc4e4a264ab8def5b8cc7530a /third_party/WebKit | |
parent | 7551108a40902e5e45d0679df2ce7e0bc8c090c1 (diff) | |
download | chromium_src-1b5ee4337fe825d39095d42dbd596f153c48ac36.zip chromium_src-1b5ee4337fe825d39095d42dbd596f153c48ac36.tar.gz chromium_src-1b5ee4337fe825d39095d42dbd596f153c48ac36.tar.bz2 |
INPUT_MULTIPLE_FIELDS_UI: Incomplete datetime format should fallback to default
https://bugs.webkit.org/show_bug.cgi?id=113005
Patch by Kunihiko Sakamoto <ksakamoto@chromium.org> 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.
git-svn-id: svn://svn.chromium.org/blink/trunk@146584 bbb929c8-8fbe-4397-9dbb-9b2b20218538
Diffstat (limited to 'third_party/WebKit')
28 files changed, 510 insertions, 0 deletions
diff --git a/third_party/WebKit/LayoutTests/ChangeLog b/third_party/WebKit/LayoutTests/ChangeLog index 0026c50..0f6d0c7 100644 --- a/third_party/WebKit/LayoutTests/ChangeLog +++ b/third_party/WebKit/LayoutTests/ChangeLog @@ -1,3 +1,23 @@ +2013-03-22 Kunihiko Sakamoto <ksakamoto@chromium.org> + + 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 <morrita@google.com> Custom Elements: "readyCallback" lifecycle callback should be called. diff --git a/third_party/WebKit/LayoutTests/fast/forms/date-multiple-fields/date-multiple-fields-fallback-format-expected.txt b/third_party/WebKit/LayoutTests/fast/forms/date-multiple-fields/date-multiple-fields-fallback-format-expected.txt new file mode 100644 index 0000000..56631f1 --- /dev/null +++ b/third_party/WebKit/LayoutTests/fast/forms/date-multiple-fields/date-multiple-fields-fallback-format-expected.txt @@ -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 + diff --git a/third_party/WebKit/LayoutTests/fast/forms/date-multiple-fields/date-multiple-fields-fallback-format.html b/third_party/WebKit/LayoutTests/fast/forms/date-multiple-fields/date-multiple-fields-fallback-format.html new file mode 100644 index 0000000..cd9b260 --- /dev/null +++ b/third_party/WebKit/LayoutTests/fast/forms/date-multiple-fields/date-multiple-fields-fallback-format.html @@ -0,0 +1,39 @@ +<!DOCTYPE html> +<html> +<head> +<script src="../../js/resources/js-test-pre.js"></script> +<script src="../resources/common.js"></script> +</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="../../js/resources/js-test-post.js"></script> +</body> +</html> diff --git a/third_party/WebKit/LayoutTests/fast/forms/datetime-multiple-fields/datetime-multiple-fields-fallback-format-expected.txt b/third_party/WebKit/LayoutTests/fast/forms/datetime-multiple-fields/datetime-multiple-fields-fallback-format-expected.txt new file mode 100644 index 0000000..a72bb79 --- /dev/null +++ b/third_party/WebKit/LayoutTests/fast/forms/datetime-multiple-fields/datetime-multiple-fields-fallback-format-expected.txt @@ -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 + diff --git a/third_party/WebKit/LayoutTests/fast/forms/datetime-multiple-fields/datetime-multiple-fields-fallback-format.html b/third_party/WebKit/LayoutTests/fast/forms/datetime-multiple-fields/datetime-multiple-fields-fallback-format.html new file mode 100644 index 0000000..209f688 --- /dev/null +++ b/third_party/WebKit/LayoutTests/fast/forms/datetime-multiple-fields/datetime-multiple-fields-fallback-format.html @@ -0,0 +1,39 @@ +<!DOCTYPE html> +<html> +<head> +<script src="../../js/resources/js-test-pre.js"></script> +<script src="../resources/common.js"></script> +</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="../../js/resources/js-test-post.js"></script> +</body> +</html> diff --git a/third_party/WebKit/LayoutTests/fast/forms/datetimelocal-multiple-fields/datetimelocal-multiple-fields-fallback-format-expected.txt b/third_party/WebKit/LayoutTests/fast/forms/datetimelocal-multiple-fields/datetimelocal-multiple-fields-fallback-format-expected.txt new file mode 100644 index 0000000..a72bb79 --- /dev/null +++ b/third_party/WebKit/LayoutTests/fast/forms/datetimelocal-multiple-fields/datetimelocal-multiple-fields-fallback-format-expected.txt @@ -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 + diff --git a/third_party/WebKit/LayoutTests/fast/forms/datetimelocal-multiple-fields/datetimelocal-multiple-fields-fallback-format.html b/third_party/WebKit/LayoutTests/fast/forms/datetimelocal-multiple-fields/datetimelocal-multiple-fields-fallback-format.html new file mode 100644 index 0000000..209f688 --- /dev/null +++ b/third_party/WebKit/LayoutTests/fast/forms/datetimelocal-multiple-fields/datetimelocal-multiple-fields-fallback-format.html @@ -0,0 +1,39 @@ +<!DOCTYPE html> +<html> +<head> +<script src="../../js/resources/js-test-pre.js"></script> +<script src="../resources/common.js"></script> +</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="../../js/resources/js-test-post.js"></script> +</body> +</html> diff --git a/third_party/WebKit/LayoutTests/fast/forms/month-multiple-fields/month-multiple-fields-fallback-format-expected.txt b/third_party/WebKit/LayoutTests/fast/forms/month-multiple-fields/month-multiple-fields-fallback-format-expected.txt new file mode 100644 index 0000000..b38b96a --- /dev/null +++ b/third_party/WebKit/LayoutTests/fast/forms/month-multiple-fields/month-multiple-fields-fallback-format-expected.txt @@ -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 + diff --git a/third_party/WebKit/LayoutTests/fast/forms/month-multiple-fields/month-multiple-fields-fallback-format.html b/third_party/WebKit/LayoutTests/fast/forms/month-multiple-fields/month-multiple-fields-fallback-format.html new file mode 100644 index 0000000..29511ab --- /dev/null +++ b/third_party/WebKit/LayoutTests/fast/forms/month-multiple-fields/month-multiple-fields-fallback-format.html @@ -0,0 +1,37 @@ +<!DOCTYPE html> +<html> +<head> +<script src="../../js/resources/js-test-pre.js"></script> +<script src="../resources/common.js"></script> +</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="../../js/resources/js-test-post.js"></script> +</body> +</html> diff --git a/third_party/WebKit/LayoutTests/fast/forms/time-multiple-fields/time-multiple-fields-fallback-format-expected.txt b/third_party/WebKit/LayoutTests/fast/forms/time-multiple-fields/time-multiple-fields-fallback-format-expected.txt new file mode 100644 index 0000000..42174d4 --- /dev/null +++ b/third_party/WebKit/LayoutTests/fast/forms/time-multiple-fields/time-multiple-fields-fallback-format-expected.txt @@ -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 + diff --git a/third_party/WebKit/LayoutTests/fast/forms/time-multiple-fields/time-multiple-fields-fallback-format.html b/third_party/WebKit/LayoutTests/fast/forms/time-multiple-fields/time-multiple-fields-fallback-format.html new file mode 100644 index 0000000..766e161 --- /dev/null +++ b/third_party/WebKit/LayoutTests/fast/forms/time-multiple-fields/time-multiple-fields-fallback-format.html @@ -0,0 +1,43 @@ +<!DOCTYPE html> +<html> +<head> +<script src="../../js/resources/js-test-pre.js"></script> +<script src="../resources/common.js"></script> +</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="../../js/resources/js-test-post.js"></script> +</body> +</html> diff --git a/third_party/WebKit/LayoutTests/fast/forms/week-multiple-fields/week-multiple-fields-fallback-format-expected.txt b/third_party/WebKit/LayoutTests/fast/forms/week-multiple-fields/week-multiple-fields-fallback-format-expected.txt new file mode 100644 index 0000000..7b2cca8 --- /dev/null +++ b/third_party/WebKit/LayoutTests/fast/forms/week-multiple-fields/week-multiple-fields-fallback-format-expected.txt @@ -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 + diff --git a/third_party/WebKit/LayoutTests/fast/forms/week-multiple-fields/week-multiple-fields-fallback-format.html b/third_party/WebKit/LayoutTests/fast/forms/week-multiple-fields/week-multiple-fields-fallback-format.html new file mode 100644 index 0000000..25f492b --- /dev/null +++ b/third_party/WebKit/LayoutTests/fast/forms/week-multiple-fields/week-multiple-fields-fallback-format.html @@ -0,0 +1,37 @@ +<!DOCTYPE html> +<html> +<head> +<script src="../../js/resources/js-test-pre.js"></script> +<script src="../resources/common.js"></script> +</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="../../js/resources/js-test-post.js"></script> +</body> +</html> diff --git a/third_party/WebKit/Source/WebCore/ChangeLog b/third_party/WebKit/Source/WebCore/ChangeLog index 574217f..fd1aea1 100644 --- a/third_party/WebKit/Source/WebCore/ChangeLog +++ b/third_party/WebKit/Source/WebCore/ChangeLog @@ -1,3 +1,52 @@ +2013-03-22 Kunihiko Sakamoto <ksakamoto@chromium.org> + + 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 <morrita@google.com> Custom Elements: "readyCallback" lifecycle callback should be called. diff --git a/third_party/WebKit/Source/WebCore/html/BaseMultipleFieldsDateAndTimeInputType.cpp b/third_party/WebKit/Source/WebCore/html/BaseMultipleFieldsDateAndTimeInputType.cpp index f31af2d..265f8d1 100644 --- a/third_party/WebKit/Source/WebCore/html/BaseMultipleFieldsDateAndTimeInputType.cpp +++ b/third_party/WebKit/Source/WebCore/html/BaseMultipleFieldsDateAndTimeInputType.cpp @@ -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 @@ void BaseMultipleFieldsDateAndTimeInputType::updateInnerTextValue() if (!pattern.isEmpty()) layoutParameters.dateTimeFormat = pattern; + if (!DateTimeFormatValidator().validateFormat(layoutParameters.dateTimeFormat, *this)) + layoutParameters.dateTimeFormat = layoutParameters.fallbackDateTimeFormat; + if (hasValue) m_dateTimeEditElement->setValueAsDate(layoutParameters, date); else diff --git a/third_party/WebKit/Source/WebCore/html/BaseMultipleFieldsDateAndTimeInputType.h b/third_party/WebKit/Source/WebCore/html/BaseMultipleFieldsDateAndTimeInputType.h index 84483ad..096e312 100644 --- a/third_party/WebKit/Source/WebCore/html/BaseMultipleFieldsDateAndTimeInputType.h +++ b/third_party/WebKit/Source/WebCore/html/BaseMultipleFieldsDateAndTimeInputType.h @@ -49,6 +49,9 @@ class BaseMultipleFieldsDateAndTimeInputType , 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(); diff --git a/third_party/WebKit/Source/WebCore/html/DateInputType.cpp b/third_party/WebKit/Source/WebCore/html/DateInputType.cpp index 8d7a928..9810624 100644 --- a/third_party/WebKit/Source/WebCore/html/DateInputType.cpp +++ b/third_party/WebKit/Source/WebCore/html/DateInputType.cpp @@ -126,6 +126,11 @@ void DateInputType::setupLayoutParameters(DateTimeEditElement::LayoutParameters& 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 diff --git a/third_party/WebKit/Source/WebCore/html/DateInputType.h b/third_party/WebKit/Source/WebCore/html/DateInputType.h index fd75f91..cf83721 100644 --- a/third_party/WebKit/Source/WebCore/html/DateInputType.h +++ b/third_party/WebKit/Source/WebCore/html/DateInputType.h @@ -64,6 +64,7 @@ private: // 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 }; diff --git a/third_party/WebKit/Source/WebCore/html/DateTimeInputType.cpp b/third_party/WebKit/Source/WebCore/html/DateTimeInputType.cpp index b08d9d6..139e9fa 100644 --- a/third_party/WebKit/Source/WebCore/html/DateTimeInputType.cpp +++ b/third_party/WebKit/Source/WebCore/html/DateTimeInputType.cpp @@ -164,6 +164,11 @@ void DateTimeInputType::setupLayoutParameters(DateTimeEditElement::LayoutParamet 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 diff --git a/third_party/WebKit/Source/WebCore/html/DateTimeInputType.h b/third_party/WebKit/Source/WebCore/html/DateTimeInputType.h index 9d72bc85f..729d60c 100644 --- a/third_party/WebKit/Source/WebCore/html/DateTimeInputType.h +++ b/third_party/WebKit/Source/WebCore/html/DateTimeInputType.h @@ -64,6 +64,7 @@ private: // 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 }; diff --git a/third_party/WebKit/Source/WebCore/html/DateTimeLocalInputType.cpp b/third_party/WebKit/Source/WebCore/html/DateTimeLocalInputType.cpp index 21c5f42..687bffae 100644 --- a/third_party/WebKit/Source/WebCore/html/DateTimeLocalInputType.cpp +++ b/third_party/WebKit/Source/WebCore/html/DateTimeLocalInputType.cpp @@ -170,6 +170,11 @@ void DateTimeLocalInputType::setupLayoutParameters(DateTimeEditElement::LayoutPa 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 diff --git a/third_party/WebKit/Source/WebCore/html/DateTimeLocalInputType.h b/third_party/WebKit/Source/WebCore/html/DateTimeLocalInputType.h index 31eea4d..b16abe8 100644 --- a/third_party/WebKit/Source/WebCore/html/DateTimeLocalInputType.h +++ b/third_party/WebKit/Source/WebCore/html/DateTimeLocalInputType.h @@ -63,6 +63,7 @@ private: // 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 }; diff --git a/third_party/WebKit/Source/WebCore/html/MonthInputType.cpp b/third_party/WebKit/Source/WebCore/html/MonthInputType.cpp index 03fe167..db80cbf 100644 --- a/third_party/WebKit/Source/WebCore/html/MonthInputType.cpp +++ b/third_party/WebKit/Source/WebCore/html/MonthInputType.cpp @@ -167,6 +167,11 @@ void MonthInputType::setupLayoutParameters(DateTimeEditElement::LayoutParameters 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 diff --git a/third_party/WebKit/Source/WebCore/html/MonthInputType.h b/third_party/WebKit/Source/WebCore/html/MonthInputType.h index 7ed318b..8fae5bb 100644 --- a/third_party/WebKit/Source/WebCore/html/MonthInputType.h +++ b/third_party/WebKit/Source/WebCore/html/MonthInputType.h @@ -65,6 +65,7 @@ private: // 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 }; diff --git a/third_party/WebKit/Source/WebCore/html/TimeInputType.cpp b/third_party/WebKit/Source/WebCore/html/TimeInputType.cpp index d5b4a7a..2b6bbc0 100644 --- a/third_party/WebKit/Source/WebCore/html/TimeInputType.cpp +++ b/third_party/WebKit/Source/WebCore/html/TimeInputType.cpp @@ -170,6 +170,11 @@ void TimeInputType::setupLayoutParameters(DateTimeEditElement::LayoutParameters& 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 diff --git a/third_party/WebKit/Source/WebCore/html/TimeInputType.h b/third_party/WebKit/Source/WebCore/html/TimeInputType.h index 32eab5e..16f519e 100644 --- a/third_party/WebKit/Source/WebCore/html/TimeInputType.h +++ b/third_party/WebKit/Source/WebCore/html/TimeInputType.h @@ -63,6 +63,7 @@ private: // 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 }; diff --git a/third_party/WebKit/Source/WebCore/html/WeekInputType.cpp b/third_party/WebKit/Source/WebCore/html/WeekInputType.cpp index 060b181..ad8b8d5 100644 --- a/third_party/WebKit/Source/WebCore/html/WeekInputType.cpp +++ b/third_party/WebKit/Source/WebCore/html/WeekInputType.cpp @@ -120,6 +120,11 @@ void WeekInputType::setupLayoutParameters(DateTimeEditElement::LayoutParameters& 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 diff --git a/third_party/WebKit/Source/WebCore/html/WeekInputType.h b/third_party/WebKit/Source/WebCore/html/WeekInputType.h index 385bd6d..89e743d 100644 --- a/third_party/WebKit/Source/WebCore/html/WeekInputType.h +++ b/third_party/WebKit/Source/WebCore/html/WeekInputType.h @@ -61,6 +61,7 @@ private: // 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 }; |