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
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();
+}
+
+}