Title: [122190] trunk/Source
Revision
122190
Author
[email protected]
Date
2012-07-09 21:31:39 -0700 (Mon, 09 Jul 2012)

Log Message

[Chromium-Mac] Implement functions for localized time format information
https://bugs.webkit.org/show_bug.cgi?id=90237

Reviewed by Kent Tamura.

Source/WebCore:

This patch introduces following localized time format related
functions:
  - localizeTimeFormatText()
  - localizeShortTimeFormatText()
  - timeAMPMLabels
for Mac OSX in feature flag: ENABLE_INPUT_TYPE_TIME_MULTIPLE_FIELDS.

These function will be used by input type "time" with multiple input
fields UI.

Note: ICU version of localized time format functions are implemented
in https://bugs.webkit.org/show_bug.cgi?id=89965

Tests: WebKit/chromium/tests/LocaleMacTest.cpp

* platform/text/mac/LocaleMac.h:
(LocaleMac): Added time format related functions and variables.
* platform/text/mac/LocaleMac.mm:
(WebCore::createDateTimeFormatter): Added. A helper function for creating date time formatter.
(WebCore::LocaleMac::createShortDateFormatter): Changed to use createDateTimeFormatter.
(WebCore::LocaleMac::createTimeFormatter): Added.
(WebCore::LocaleMac::createShortTimeFormatter): Added.
(WebCore::LocaleMac::timeFormatText): Added.
(WebCore::LocaleMac::shortTimeFormatText): Added.
(WebCore::LocaleMac::timeAMPMLabels): Added.

Source/WebKit/chromium:

* tests/LocaleMacTest.cpp:
(LocaleMacTest):
(LocaleMacTest::timeFormatText):
(LocaleMacTest::shortTimeFormatText):
(LocaleMacTest::timeAMPMLabel):
(TEST_F):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (122189 => 122190)


--- trunk/Source/WebCore/ChangeLog	2012-07-10 03:27:37 UTC (rev 122189)
+++ trunk/Source/WebCore/ChangeLog	2012-07-10 04:31:39 UTC (rev 122190)
@@ -1,3 +1,36 @@
+2012-07-09  Yoshifumi Inoue  <[email protected]>
+
+        [Chromium-Mac] Implement functions for localized time format information
+        https://bugs.webkit.org/show_bug.cgi?id=90237
+
+        Reviewed by Kent Tamura.
+
+        This patch introduces following localized time format related
+        functions:
+          - localizeTimeFormatText()
+          - localizeShortTimeFormatText()
+          - timeAMPMLabels
+        for Mac OSX in feature flag: ENABLE_INPUT_TYPE_TIME_MULTIPLE_FIELDS.
+
+        These function will be used by input type "time" with multiple input
+        fields UI.
+
+        Note: ICU version of localized time format functions are implemented
+        in https://bugs.webkit.org/show_bug.cgi?id=89965
+
+        Tests: WebKit/chromium/tests/LocaleMacTest.cpp
+
+        * platform/text/mac/LocaleMac.h:
+        (LocaleMac): Added time format related functions and variables.
+        * platform/text/mac/LocaleMac.mm:
+        (WebCore::createDateTimeFormatter): Added. A helper function for creating date time formatter.
+        (WebCore::LocaleMac::createShortDateFormatter): Changed to use createDateTimeFormatter.
+        (WebCore::LocaleMac::createTimeFormatter): Added.
+        (WebCore::LocaleMac::createShortTimeFormatter): Added.
+        (WebCore::LocaleMac::timeFormatText): Added.
+        (WebCore::LocaleMac::shortTimeFormatText): Added.
+        (WebCore::LocaleMac::timeAMPMLabels): Added.
+
 2012-07-09  Alexandru Chiculita  <[email protected]>
 
         [CSS Shaders] The FECustomFilter is not making the GL context active

Modified: trunk/Source/WebCore/platform/text/mac/LocaleMac.h (122189 => 122190)


--- trunk/Source/WebCore/platform/text/mac/LocaleMac.h	2012-07-10 03:27:37 UTC (rev 122189)
+++ trunk/Source/WebCore/platform/text/mac/LocaleMac.h	2012-07-10 04:31:39 UTC (rev 122190)
@@ -58,6 +58,12 @@
     unsigned firstDayOfWeek();
 #endif
 
+#if ENABLE(INPUT_TYPE_TIME_MULTIPLE_FIELDS)
+    String timeFormatText();
+    String shortTimeFormatText();
+    const Vector<String>& timeAMPMLabels();
+#endif
+
 private:
     explicit LocaleMac(const String&);
     NSDateFormatter *createShortDateFormatter();
@@ -68,6 +74,14 @@
     Vector<String> m_monthLabels;
     Vector<String> m_weekDayShortLabels;
 #endif
+#if ENABLE(INPUT_TYPE_TIME_MULTIPLE_FIELDS)
+    NSDateFormatter *createTimeFormatter();
+    NSDateFormatter *createShortTimeFormatter();
+
+    String m_localizedTimeFormatText;
+    String m_localizedShortTimeFormatText;
+    Vector<String> m_timeAMPMLabels;
+#endif
 };
 
 }

Modified: trunk/Source/WebCore/platform/text/mac/LocaleMac.mm (122189 => 122190)


--- trunk/Source/WebCore/platform/text/mac/LocaleMac.mm	2012-07-10 03:27:37 UTC (rev 122189)
+++ trunk/Source/WebCore/platform/text/mac/LocaleMac.mm	2012-07-10 04:31:39 UTC (rev 122190)
@@ -44,6 +44,17 @@
 
 namespace WebCore {
 
+static NSDateFormatter* createDateTimeFormatter(NSLocale* locale, NSDateFormatterStyle dateStyle, NSDateFormatterStyle timeStyle)
+{
+    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
+    [formatter setLocale:locale];
+    [formatter setDateStyle:dateStyle];
+    [formatter setTimeStyle:timeStyle];
+    [formatter setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"UTC"]];
+    [formatter setCalendar:[[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]];
+    return formatter;
+}
+
 LocaleMac::LocaleMac(const String& localeIdentifier)
     : m_locale([[NSLocale alloc] initWithLocaleIdentifier:localeIdentifier])
 {
@@ -66,13 +77,7 @@
 
 NSDateFormatter* LocaleMac::createShortDateFormatter()
 {
-    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
-    [formatter setLocale:m_locale.get()];
-    [formatter setDateStyle:NSDateFormatterShortStyle];
-    [formatter setTimeStyle:NSDateFormatterNoStyle];
-    [formatter setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"UTC"]];
-    [formatter setCalendar:[[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]];
-    return formatter;
+    return createDateTimeFormatter(m_locale.get(), NSDateFormatterShortStyle, NSDateFormatterNoStyle);
 }
 
 double LocaleMac::parseDate(const String& input)
@@ -194,4 +199,45 @@
     return [calendar.get() firstWeekday] - 1;
 }
 #endif
+
+#if ENABLE(INPUT_TYPE_TIME_MULTIPLE_FIELDS)
+NSDateFormatter* LocaleMac::createTimeFormatter()
+{
+    return createDateTimeFormatter(m_locale.get(), NSDateFormatterNoStyle, NSDateFormatterMediumStyle);
 }
+
+NSDateFormatter* LocaleMac::createShortTimeFormatter()
+{
+    return createDateTimeFormatter(m_locale.get(), NSDateFormatterNoStyle, NSDateFormatterShortStyle);
+}
+
+String LocaleMac::timeFormatText()
+{
+    if (!m_localizedTimeFormatText.isEmpty())
+        return m_localizedTimeFormatText;
+    RetainPtr<NSDateFormatter> formatter(AdoptNS, createTimeFormatter());
+    m_localizedTimeFormatText = String([formatter.get() dateFormat]);
+    return m_localizedTimeFormatText;
+}
+
+String LocaleMac::shortTimeFormatText()
+{
+    if (!m_localizedShortTimeFormatText.isEmpty())
+        return m_localizedShortTimeFormatText;
+    RetainPtr<NSDateFormatter> formatter(AdoptNS, createShortTimeFormatter());
+    m_localizedShortTimeFormatText = String([formatter.get() dateFormat]);
+    return m_localizedShortTimeFormatText;
+}
+
+const Vector<String>& LocaleMac::timeAMPMLabels()
+{
+    if (!m_timeAMPMLabels.isEmpty())
+        return m_timeAMPMLabels;
+    m_timeAMPMLabels.reserveCapacity(2);
+    RetainPtr<NSDateFormatter> formatter(AdoptNS, createShortTimeFormatter());
+    m_timeAMPMLabels.append(String([formatter.get() AMSymbol]));
+    m_timeAMPMLabels.append(String([formatter.get() PMSymbol]));
+    return m_timeAMPMLabels;
+}
+#endif
+}

Modified: trunk/Source/WebKit/chromium/ChangeLog (122189 => 122190)


--- trunk/Source/WebKit/chromium/ChangeLog	2012-07-10 03:27:37 UTC (rev 122189)
+++ trunk/Source/WebKit/chromium/ChangeLog	2012-07-10 04:31:39 UTC (rev 122190)
@@ -1,3 +1,17 @@
+2012-07-09  Yoshifumi Inoue  <[email protected]>
+
+        [Chromium-Mac] Implement functions for localized time format information
+        https://bugs.webkit.org/show_bug.cgi?id=90237
+
+        Reviewed by Kent Tamura.
+
+        * tests/LocaleMacTest.cpp:
+        (LocaleMacTest):
+        (LocaleMacTest::timeFormatText):
+        (LocaleMacTest::shortTimeFormatText):
+        (LocaleMacTest::timeAMPMLabel):
+        (TEST_F):
+
 2012-07-09  Eric Penner  <[email protected]>
 
         [chromium] Merge updates and idle updates into one pass

Modified: trunk/Source/WebKit/chromium/tests/LocaleMacTest.cpp (122189 => 122190)


--- trunk/Source/WebKit/chromium/tests/LocaleMacTest.cpp	2012-07-10 03:27:37 UTC (rev 122189)
+++ trunk/Source/WebKit/chromium/tests/LocaleMacTest.cpp	2012-07-10 04:31:39 UTC (rev 122190)
@@ -99,6 +99,26 @@
         return locale->weekDayShortLabels()[index];
     }
 #endif
+
+#if ENABLE(INPUT_TYPE_TIME_MULTIPLE_FIELDS)
+    String timeFormatText(const String& localeString)
+    {
+        OwnPtr<LocaleMac> locale = LocaleMac::create(localeString);
+        return locale->timeFormatText();
+    }
+
+    String shortTimeFormatText(const String& localeString)
+    {
+        OwnPtr<LocaleMac> locale = LocaleMac::create(localeString);
+        return locale->shortTimeFormatText();
+    }
+
+    String timeAMPMLabel(const String& localeString, unsigned index)
+    {
+        OwnPtr<LocaleMac> locale = LocaleMac::create(localeString);
+        return locale->timeAMPMLabels()[index];
+    }
+#endif
 };
 
 TEST_F(LocaleMacTest, formatDate)
@@ -160,3 +180,31 @@
     EXPECT_STREQ("\xE5\x9C\x9F", weekDayShortLabel("ja_JP", Saturday).utf8().data());
 }
 #endif
+
+#if ENABLE(INPUT_TYPE_TIME_MULTIPLE_FIELDS)
+TEST_F(LocaleMacTest, timeFormatText)
+{
+    EXPECT_STREQ("h:mm:ss a", timeFormatText("en_US").utf8().data());
+    EXPECT_STREQ("HH:mm:ss", timeFormatText("fr_FR").utf8().data());
+    EXPECT_STREQ("H:mm:ss", timeFormatText("ja_JP").utf8().data());
+}
+
+TEST_F(LocaleMacTest, shortTimeFormatText)
+{
+    EXPECT_STREQ("h:mm a", shortTimeFormatText("en_US").utf8().data());
+    EXPECT_STREQ("HH:mm", shortTimeFormatText("fr_FR").utf8().data());
+    EXPECT_STREQ("H:mm", shortTimeFormatText("ja_JP").utf8().data());
+}
+
+TEST_F(LocaleMacTest, timeAMPMLabels)
+{
+    EXPECT_STREQ("AM", timeAMPMLabel("en_US", 0).utf8().data());
+    EXPECT_STREQ("PM", timeAMPMLabel("en_US", 1).utf8().data());
+
+    EXPECT_STREQ("AM", timeAMPMLabel("fr_FR", 0).utf8().data());
+    EXPECT_STREQ("PM", timeAMPMLabel("fr_FR", 1).utf8().data());
+
+    EXPECT_STREQ("\xE5\x8D\x88\xE5\x89\x8D", timeAMPMLabel("ja_JP", 0).utf8().data());
+    EXPECT_STREQ("\xE5\x8D\x88\xE5\xBE\x8C", timeAMPMLabel("ja_JP", 1).utf8().data());
+}
+#endif
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to