Title: [113422] trunk
Revision
113422
Author
[email protected]
Date
2012-04-06 03:01:09 -0700 (Fri, 06 Apr 2012)

Log Message

Initial LocalizedDateICU.cpp implementation
https://bugs.webkit.org/show_bug.cgi?id=60868

Reviewed by Hajime Morita.

Source/WebCore:

Add LocalizedDateICU.cpp, which supports only Date type.  It uses a
short format because a date field is keyboard-editable.
e.g. 5/15/11 in US locale.

* WebCore.gyp/WebCore.gyp: Exclude LocalizedDateNone.cpp.
* WebCore.gypi: Add LocalizedDateICU.cpp.
* platform/text/LocalizedDateICU.cpp: Added.
(WebCore::parseLocalizedDate):
(WebCore::formatLocalizedDate):

LayoutTests:

* platform/chromium-mac-snowleopard/fast/forms/date/date-appearance-expected.png:
* platform/chromium-mac-snowleopard/fast/forms/date/date-appearance-expected.txt:
* platform/chromium/fast/forms/date/date-input-visible-strings-expected.txt: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (113421 => 113422)


--- trunk/LayoutTests/ChangeLog	2012-04-06 09:02:48 UTC (rev 113421)
+++ trunk/LayoutTests/ChangeLog	2012-04-06 10:01:09 UTC (rev 113422)
@@ -1,3 +1,14 @@
+2012-04-06  Kent Tamura  <[email protected]>
+
+        Initial LocalizedDateICU.cpp implementation
+        https://bugs.webkit.org/show_bug.cgi?id=60868
+
+        Reviewed by Hajime Morita.
+
+        * platform/chromium-mac-snowleopard/fast/forms/date/date-appearance-expected.png:
+        * platform/chromium-mac-snowleopard/fast/forms/date/date-appearance-expected.txt:
+        * platform/chromium/fast/forms/date/date-input-visible-strings-expected.txt: Added.
+
 2012-04-06  Csaba Osztrogonác  <[email protected]>
 
         [Qt] Unreviewed gardening, update platform specific expected results.

Added: trunk/LayoutTests/platform/chromium/fast/forms/date/date-input-visible-strings-expected.txt (0 => 113422)


--- trunk/LayoutTests/platform/chromium/fast/forms/date/date-input-visible-strings-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/platform/chromium/fast/forms/date/date-input-visible-strings-expected.txt	2012-04-06 10:01:09 UTC (rev 113422)
@@ -0,0 +1,7 @@
+The user-visible values of date input fields should be localized if the platform has a LocalizedDate implementation. Otherwise, they should be in the HTML5 formats.
+
+date: value='2011-04-27' visible='4/27/11'
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Modified: trunk/LayoutTests/platform/chromium-mac-snowleopard/fast/forms/date/date-appearance-expected.png


(Binary files differ)

Modified: trunk/LayoutTests/platform/chromium-mac-snowleopard/fast/forms/date/date-appearance-expected.txt (113421 => 113422)


--- trunk/LayoutTests/platform/chromium-mac-snowleopard/fast/forms/date/date-appearance-expected.txt	2012-04-06 09:02:48 UTC (rev 113421)
+++ trunk/LayoutTests/platform/chromium-mac-snowleopard/fast/forms/date/date-appearance-expected.txt	2012-04-06 10:01:09 UTC (rev 113422)
@@ -6,81 +6,81 @@
       RenderBlock {DIV} at (0,0) size 784x23
         RenderTextControl {INPUT} at (2,2) size 125x19 [bgcolor=#FFFFFF] [border: (2px inset #000000)]
           RenderDeprecatedFlexibleBox {DIV} at (3,3) size 119x13
-            RenderBlock {DIV} at (0,0) size 108x13
-              RenderBlock {DIV} at (0,0) size 108x13
-                RenderText {#text} at (1,0) size 69x13
-                  text run at (1,0) width 69: "2012-04-02"
-            RenderBlock (anonymous) at (108,0) size 11x13
+            RenderBlock {DIV} at (0,0) size 110x13
+              RenderBlock {DIV} at (0,0) size 110x13
+                RenderText {#text} at (1,0) size 40x13
+                  text run at (1,0) width 40: "4/2/12"
+            RenderBlock (anonymous) at (110,0) size 9x13
               RenderDetailsMarker {DIV} at (0,4) size 7x7: down
       RenderBlock {DIV} at (0,23) size 784x23
         RenderTextControl {INPUT} at (2,2) size 125x19 [bgcolor=#FFFFFF] [border: (2px inset #000000)]
           RenderDeprecatedFlexibleBox {DIV} at (3,3) size 119x13
-            RenderBlock {DIV} at (0,0) size 108x13
-              RenderBlock {DIV} at (0,0) size 108x13
-                RenderText {#text} at (1,0) size 69x13
-                  text run at (1,0) width 69: "2012-04-02"
-            RenderBlock (anonymous) at (108,0) size 11x13
+            RenderBlock {DIV} at (0,0) size 110x13
+              RenderBlock {DIV} at (0,0) size 110x13
+                RenderText {#text} at (1,0) size 40x13
+                  text run at (1,0) width 40: "4/2/12"
+            RenderBlock (anonymous) at (110,0) size 9x13
               RenderDetailsMarker {DIV} at (0,4) size 7x7: down
       RenderBlock {DIV} at (0,46) size 784x23
         RenderTextControl {INPUT} at (2,2) size 125x19 [color=#545454] [bgcolor=#FFFFFF] [border: (2px inset #545454)]
           RenderDeprecatedFlexibleBox {DIV} at (3,3) size 119x13
-            RenderBlock {DIV} at (0,0) size 108x13
-              RenderBlock {DIV} at (0,0) size 108x13
-                RenderText {#text} at (1,0) size 69x13
-                  text run at (1,0) width 69: "2012-04-02"
-            RenderBlock (anonymous) at (108,0) size 11x13
+            RenderBlock {DIV} at (0,0) size 110x13
+              RenderBlock {DIV} at (0,0) size 110x13
+                RenderText {#text} at (1,0) size 40x13
+                  text run at (1,0) width 40: "4/2/12"
+            RenderBlock (anonymous) at (110,0) size 9x13
               RenderDetailsMarker {DIV} at (0,4) size 7x7: down
       RenderBlock {DIV} at (0,69) size 784x23
         RenderTextControl {INPUT} at (2,2) size 125x19 [color=#FFFFFF] [bgcolor=#000000] [border: (2px inset #FFFFFF)]
           RenderDeprecatedFlexibleBox {DIV} at (3,3) size 119x13
-            RenderBlock {DIV} at (0,0) size 108x13
-              RenderBlock {DIV} at (0,0) size 108x13
-                RenderText {#text} at (1,0) size 69x13
-                  text run at (1,0) width 69: "2012-04-02"
-            RenderBlock (anonymous) at (108,0) size 11x13
+            RenderBlock {DIV} at (0,0) size 110x13
+              RenderBlock {DIV} at (0,0) size 110x13
+                RenderText {#text} at (1,0) size 40x13
+                  text run at (1,0) width 40: "4/2/12"
+            RenderBlock (anonymous) at (110,0) size 9x13
               RenderDetailsMarker {DIV} at (0,4) size 7x7: down
       RenderBlock {DIV} at (0,92) size 784x23
         RenderTextControl {INPUT} at (2,2) size 125x19 [color=#FFFFFF] [bgcolor=#000000] [border: (2px inset #FFFFFF)]
           RenderDeprecatedFlexibleBox {DIV} at (3,3) size 119x13
-            RenderBlock {DIV} at (0,0) size 108x13
-              RenderBlock {DIV} at (0,0) size 108x13
-                RenderText {#text} at (1,0) size 69x13
-                  text run at (1,0) width 69: "2012-04-02"
-            RenderBlock (anonymous) at (108,0) size 11x13
+            RenderBlock {DIV} at (0,0) size 110x13
+              RenderBlock {DIV} at (0,0) size 110x13
+                RenderText {#text} at (1,0) size 40x13
+                  text run at (1,0) width 40: "4/2/12"
+            RenderBlock (anonymous) at (110,0) size 9x13
               RenderDetailsMarker {DIV} at (0,4) size 7x7: down
       RenderBlock {DIV} at (0,115) size 784x23
         RenderTextControl {INPUT} at (2,2) size 125x19 [color=#FFFFFF] [bgcolor=#000000] [border: (2px inset #FFFFFF)]
           RenderDeprecatedFlexibleBox {DIV} at (3,3) size 119x13
-            RenderBlock {DIV} at (0,0) size 108x13
-              RenderBlock {DIV} at (0,0) size 108x13
-                RenderText {#text} at (1,0) size 69x13
-                  text run at (1,0) width 69: "2012-04-02"
-            RenderBlock (anonymous) at (108,0) size 11x13
+            RenderBlock {DIV} at (0,0) size 110x13
+              RenderBlock {DIV} at (0,0) size 110x13
+                RenderText {#text} at (1,0) size 40x13
+                  text run at (1,0) width 40: "4/2/12"
+            RenderBlock (anonymous) at (110,0) size 9x13
               RenderDetailsMarker {DIV} at (0,4) size 7x7: down
       RenderBlock {DIV} at (0,138) size 784x45
         RenderTextControl {INPUT} at (2,2) size 314x41 [bgcolor=#FFFFFF] [border: (2px inset #000000)]
           RenderDeprecatedFlexibleBox {DIV} at (3,3) size 308x35
-            RenderBlock {DIV} at (0,0) size 277x35
-              RenderBlock {DIV} at (0,0) size 277x35
-                RenderText {#text} at (1,0) size 187x35
-                  text run at (1,0) width 187: "2012-04-02"
-            RenderBlock (anonymous) at (277,0) size 31x35
+            RenderBlock {DIV} at (0,0) size 283x35
+              RenderBlock {DIV} at (0,0) size 283x35
+                RenderText {#text} at (1,0) size 108x35
+                  text run at (1,0) width 108: "4/2/12"
+            RenderBlock (anonymous) at (283,0) size 25x35
               RenderDetailsMarker {DIV} at (0,10) size 19x19: down
       RenderBlock {DIV} at (0,183) size 784x45
         RenderTextControl {INPUT} at (2,2) size 314x41 [bgcolor=#FFFFFF] [border: (2px inset #000000)]
           RenderDeprecatedFlexibleBox {DIV} at (3,3) size 308x35
-            RenderBlock {DIV} at (0,0) size 277x35
-              RenderBlock {DIV} at (0,0) size 277x35
-                RenderText {#text} at (1,0) size 187x35
-                  text run at (1,0) width 187: "2012-04-02"
-            RenderBlock (anonymous) at (277,0) size 31x35
+            RenderBlock {DIV} at (0,0) size 283x35
+              RenderBlock {DIV} at (0,0) size 283x35
+                RenderText {#text} at (1,0) size 108x35
+                  text run at (1,0) width 108: "4/2/12"
+            RenderBlock (anonymous) at (283,0) size 25x35
               RenderDetailsMarker {DIV} at (0,10) size 19x19: down
       RenderBlock {DIV} at (0,228) size 784x45
         RenderTextControl {INPUT} at (2,2) size 314x41 [color=#545454] [bgcolor=#FFFFFF] [border: (2px inset #545454)]
           RenderDeprecatedFlexibleBox {DIV} at (3,3) size 308x35
-            RenderBlock {DIV} at (0,0) size 277x35
-              RenderBlock {DIV} at (0,0) size 277x35
-                RenderText {#text} at (1,0) size 187x35
-                  text run at (1,0) width 187: "2012-04-02"
-            RenderBlock (anonymous) at (277,0) size 31x35
+            RenderBlock {DIV} at (0,0) size 283x35
+              RenderBlock {DIV} at (0,0) size 283x35
+                RenderText {#text} at (1,0) size 108x35
+                  text run at (1,0) width 108: "4/2/12"
+            RenderBlock (anonymous) at (283,0) size 25x35
               RenderDetailsMarker {DIV} at (0,10) size 19x19: down

Modified: trunk/Source/WebCore/ChangeLog (113421 => 113422)


--- trunk/Source/WebCore/ChangeLog	2012-04-06 09:02:48 UTC (rev 113421)
+++ trunk/Source/WebCore/ChangeLog	2012-04-06 10:01:09 UTC (rev 113422)
@@ -1,3 +1,20 @@
+2012-04-06  Kent Tamura  <[email protected]>
+
+        Initial LocalizedDateICU.cpp implementation
+        https://bugs.webkit.org/show_bug.cgi?id=60868
+
+        Reviewed by Hajime Morita.
+
+        Add LocalizedDateICU.cpp, which supports only Date type.  It uses a
+        short format because a date field is keyboard-editable.
+        e.g. 5/15/11 in US locale.
+
+        * WebCore.gyp/WebCore.gyp: Exclude LocalizedDateNone.cpp.
+        * WebCore.gypi: Add LocalizedDateICU.cpp.
+        * platform/text/LocalizedDateICU.cpp: Added.
+        (WebCore::parseLocalizedDate):
+        (WebCore::formatLocalizedDate):
+
 2012-04-05  Alexander Pavlov  <[email protected]>
 
         [REGRESSION] Refreshed autofill popup renders garbage

Modified: trunk/Source/WebCore/WebCore.gyp/WebCore.gyp (113421 => 113422)


--- trunk/Source/WebCore/WebCore.gyp/WebCore.gyp	2012-04-06 09:02:48 UTC (rev 113421)
+++ trunk/Source/WebCore/WebCore.gyp/WebCore.gyp	2012-04-06 10:01:09 UTC (rev 113422)
@@ -1487,6 +1487,7 @@
         ['exclude', 'platform/network/ResourceHandle\\.cpp$'],
         ['exclude', 'platform/sql/SQLiteFileSystem\\.cpp$'],
         ['exclude', 'platform/text/LocaleToScriptMappingICU\\.cpp$'],
+        ['exclude', 'platform/text/LocalizedDateNone\\.cpp$'],
         ['exclude', 'platform/text/LocalizedNumberNone\\.cpp$'],
         ['exclude', 'platform/text/TextEncodingDetectorNone\\.cpp$'],
       ],

Modified: trunk/Source/WebCore/WebCore.gypi (113421 => 113422)


--- trunk/Source/WebCore/WebCore.gypi	2012-04-06 09:02:48 UTC (rev 113421)
+++ trunk/Source/WebCore/WebCore.gypi	2012-04-06 10:01:09 UTC (rev 113422)
@@ -4429,6 +4429,7 @@
             'platform/text/LocalizedCalendar.h',
             'platform/text/LocalizedCalendarICU.cpp',
             'platform/text/LocalizedDate.h',
+            'platform/text/LocalizedDateICU.cpp',
             'platform/text/LocalizedDateNone.cpp',
             'platform/text/LocalizedNumber.h',
             'platform/text/LocalizedNumberICU.cpp',

Added: trunk/Source/WebCore/platform/text/LocalizedDateICU.cpp (0 => 113422)


--- trunk/Source/WebCore/platform/text/LocalizedDateICU.cpp	                        (rev 0)
+++ trunk/Source/WebCore/platform/text/LocalizedDateICU.cpp	2012-04-06 10:01:09 UTC (rev 113422)
@@ -0,0 +1,110 @@
+/*
+ * Copyright (C) 2012 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *     * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "LocalizedDate.h"
+
+#include "Language.h"
+#include <limits>
+#include <unicode/udat.h>
+#include <wtf/OwnPtr.h>
+#include <wtf/PassOwnPtr.h>
+#include <wtf/text/CString.h>
+
+using namespace icu;
+using namespace std;
+
+namespace WebCore {
+
+double parseLocalizedDate(const String& input, DateComponents::Type type)
+{
+    switch (type) {
+    case DateComponents::Date: {
+        if (input.length() > static_cast<unsigned>(numeric_limits<int32_t>::max()))
+            break;
+        int32_t inputLength = static_cast<int32_t>(input.length());
+        UErrorCode status = U_ZERO_ERROR;
+        UDateFormat* dateFormat = udat_open(UDAT_NONE, UDAT_SHORT, defaultLanguage().utf8().data(), 0, -1, 0, -1, &status);
+        if (!dateFormat)
+            break;
+        status = U_ZERO_ERROR;
+        int32_t parsePosition = 0;
+        UDate date = udat_parse(dateFormat, input.characters(), inputLength, &parsePosition, &status);
+        udat_close(dateFormat);
+        if (parsePosition != inputLength || U_FAILURE(status))
+            break;
+        // UDate, which is an alias of double, is compatible with our expectation.
+        return date;
+    }
+    case DateComponents::DateTime:
+    case DateComponents::DateTimeLocal:
+    case DateComponents::Month:
+    case DateComponents::Time:
+    case DateComponents::Week:
+    case DateComponents::Invalid:
+        break;
+    }
+    return numeric_limits<double>::quiet_NaN();
+}
+
+String formatLocalizedDate(const DateComponents& dateComponents)
+{
+    switch (dateComponents.type()) {
+    case DateComponents::Date: {
+        UErrorCode status = U_ZERO_ERROR;
+        UDateFormat* dateFormat = udat_open(UDAT_NONE, UDAT_SHORT, defaultLanguage().utf8().data(), 0, -1, 0, -1, &status);
+        if (!dateFormat)
+            break;
+        double input = dateComponents.millisecondsSinceEpoch();
+        int32_t length = udat_format(dateFormat, input, 0, 0, 0, &status);
+        if (status != U_BUFFER_OVERFLOW_ERROR) {
+            udat_close(dateFormat);
+            break;
+        }
+        Vector<UChar> buffer(length);
+        status = U_ZERO_ERROR;
+        udat_format(dateFormat, input, buffer.data(), length, 0, &status);
+        udat_close(dateFormat);
+        if (U_FAILURE(status))
+            break;
+        return String::adopt(buffer);
+    }
+    case DateComponents::DateTime:
+    case DateComponents::DateTimeLocal:
+    case DateComponents::Month:
+    case DateComponents::Time:
+    case DateComponents::Week:
+    case DateComponents::Invalid:
+        break;
+    }
+    return String();
+}
+
+}
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to