Diff
Modified: trunk/Source/WebCore/ChangeLog (131853 => 131854)
--- trunk/Source/WebCore/ChangeLog 2012-10-19 04:45:47 UTC (rev 131853)
+++ trunk/Source/WebCore/ChangeLog 2012-10-19 05:08:47 UTC (rev 131854)
@@ -1,3 +1,46 @@
+2012-10-18 Kent Tamura <[email protected]>
+
+ Add shortMonthLabels and shortStandAloneMonthLabels to Localizer
+ https://bugs.webkit.org/show_bug.cgi?id=99787
+
+ Reviewed by Kentaro Hara.
+
+ This is going to be used for input[type=month] UI. This doesn't affect
+ any bahevior yet.
+
+ Tests: Add some tests to Source/WebKit/chromium/tests/, and will add
+ layout tests later.
+
+ * platform/text/Localizer.h:
+ (Localizer): Add shortMonthLabels and shortStandAloneMonthLabels as pure
+ virtual member functions.
+
+ * platform/text/LocaleICU.h:
+ (LocaleICU): Declare shortMonthLabels and shortStandAloneMonthLabels.
+ * platform/text/LocaleICU.cpp:
+ (WebCore::LocaleICU::shortMonthLabels): Added.
+ (WebCore::LocaleICU::shortStandAloneMonthLabels): Added.
+
+ * platform/text/LocaleNone.cpp:
+ (LocaleNone): Declare shortMonthLabels and shortStandAloneMonthLabels.
+ (WebCore::LocaleNone::shortMonthLabels):
+ Added. Always returns English labels.
+ (WebCore::LocaleNone::shortStandAloneMonthLabels):
+ Addes. Just calls shortMonthLabels.
+
+ * platform/text/LocaleWin.h:
+ (LocaleWin): Declare shortMonthLabels and shortStandAloneMonthLabels.
+ * platform/text/LocaleWin.cpp:
+ (WebCore::LocaleWin::shortMonthLabels): Added.
+ (WebCore::LocaleWin::shortStandAloneMonthLabels):
+ Added. Always returns shortMonthLabels.
+
+ * platform/text/mac/LocaleMac.h:
+ (LocaleMac): Declare shortMonthLabels and shortStandAloneMonthLabels.
+ * platform/text/mac/LocaleMac.mm:
+ (WebCore::LocaleMac::shortMonthLabels): Added.
+ (WebCore::LocaleMac::shortStandAloneMonthLabels): Added.
+
2012-10-18 Kunihiko Sakamoto <[email protected]>
Implement value sanitization algorithm for type=datetime
Modified: trunk/Source/WebCore/platform/text/LocaleICU.cpp (131853 => 131854)
--- trunk/Source/WebCore/platform/text/LocaleICU.cpp 2012-10-19 04:45:47 UTC (rev 131853)
+++ trunk/Source/WebCore/platform/text/LocaleICU.cpp 2012-10-19 05:08:47 UTC (rev 131854)
@@ -441,6 +441,36 @@
return m_localizedShortTimeFormatText;
}
+const Vector<String>& LocaleICU::shortMonthLabels()
+{
+ if (!m_shortMonthLabels.isEmpty())
+ return m_shortMonthLabels;
+ if (initializeShortDateFormat()) {
+ if (OwnPtr<Vector<String> > labels = createLabelVector(m_shortDateFormat, UDAT_SHORT_MONTHS, UCAL_JANUARY, 12)) {
+ m_shortMonthLabels = *labels;
+ return m_shortMonthLabels;
+ }
+ }
+ m_shortMonthLabels.reserveCapacity(WTF_ARRAY_LENGTH(WTF::monthName));
+ for (unsigned i = 0; i < WTF_ARRAY_LENGTH(WTF::monthName); ++i)
+ m_shortMonthLabels.append(WTF::monthName[i]);
+ return m_shortMonthLabels;
+}
+
+const Vector<String>& LocaleICU::shortStandAloneMonthLabels()
+{
+ if (!m_shortStandAloneMonthLabels.isEmpty())
+ return m_shortStandAloneMonthLabels;
+ if (initializeShortDateFormat()) {
+ if (OwnPtr<Vector<String> > labels = createLabelVector(m_shortDateFormat, UDAT_STANDALONE_SHORT_MONTHS, UCAL_JANUARY, 12)) {
+ m_shortStandAloneMonthLabels = *labels;
+ return m_shortStandAloneMonthLabels;
+ }
+ }
+ m_shortStandAloneMonthLabels = shortMonthLabels();
+ return m_shortStandAloneMonthLabels;
+}
+
const Vector<String>& LocaleICU::timeAMPMLabels()
{
initializeDateTimeFormat();
Modified: trunk/Source/WebCore/platform/text/LocaleICU.h (131853 => 131854)
--- trunk/Source/WebCore/platform/text/LocaleICU.h 2012-10-19 04:45:47 UTC (rev 131853)
+++ trunk/Source/WebCore/platform/text/LocaleICU.h 2012-10-19 05:08:47 UTC (rev 131854)
@@ -65,6 +65,8 @@
virtual String monthFormat() OVERRIDE;
virtual String timeFormat() OVERRIDE;
virtual String shortTimeFormat() OVERRIDE;
+ virtual const Vector<String>& shortMonthLabels() OVERRIDE;
+ virtual const Vector<String>& shortStandAloneMonthLabels() OVERRIDE;
virtual const Vector<String>& timeAMPMLabels() OVERRIDE;
#endif
@@ -111,6 +113,8 @@
String m_monthFormat;
UDateFormat* m_mediumTimeFormat;
UDateFormat* m_shortTimeFormat;
+ Vector<String> m_shortMonthLabels;
+ Vector<String> m_shortStandAloneMonthLabels;
Vector<String> m_timeAMPMLabels;
bool m_didCreateTimeFormat;
#endif
Modified: trunk/Source/WebCore/platform/text/LocaleNone.cpp (131853 => 131854)
--- trunk/Source/WebCore/platform/text/LocaleNone.cpp 2012-10-19 04:45:47 UTC (rev 131853)
+++ trunk/Source/WebCore/platform/text/LocaleNone.cpp 2012-10-19 05:08:47 UTC (rev 131854)
@@ -25,6 +25,7 @@
#include "config.h"
#include "Localizer.h"
+#include <wtf/DateMath.h>
#include <wtf/PassOwnPtr.h>
namespace WebCore {
@@ -43,7 +44,11 @@
#if ENABLE(INPUT_MULTIPLE_FIELDS_UI)
virtual String dateFormat() OVERRIDE;
virtual String monthFormat() OVERRIDE;
+ virtual const Vector<String>& shortMonthLabels() OVERRIDE;
+ virtual const Vector<String>& shortStandAloneMonthLabels() OVERRIDE;
#endif
+
+ Vector<String> m_shortMonthLabels;
};
PassOwnPtr<Localizer> Localizer::create(const AtomicString&)
@@ -86,6 +91,21 @@
{
return ASCIILiteral("yyyy-MM");
}
+
+const Vector<String>& LocaleNone::shortMonthLabels()
+{
+ if (!m_shortMonthLabels.isEmpty())
+ return m_shortMonthLabels;
+ m_shortMonthLabels.reserveCapacity(WTF_ARRAY_LENGTH(WTF::monthName));
+ for (unsigned i = 0; i < WTF_ARRAY_LENGTH(WTF::monthName); ++i)
+ m_shortMonthLabels.append(WTF::monthName[i]);
+ return m_shortMonthLabels;
+}
+
+const Vector<String>& LocaleNone::shortStandAloneMonthLabels()
+{
+ return shortMonthLabels();
+}
#endif
} // namespace WebCore
Modified: trunk/Source/WebCore/platform/text/LocaleWin.cpp (131853 => 131854)
--- trunk/Source/WebCore/platform/text/LocaleWin.cpp 2012-10-19 04:45:47 UTC (rev 131853)
+++ trunk/Source/WebCore/platform/text/LocaleWin.cpp 2012-10-19 05:08:47 UTC (rev 131854)
@@ -735,6 +735,18 @@
return timeFormat();
}
+const Vector<String>& LocaleWin::shortMonthLabels()
+{
+ ensureShortMonthLabels();
+ return m_shortMonthLabels;
+}
+
+const Vector<String>& LocaleWin::shortStandAloneMonthLabels()
+{
+ // Windows doesn't provide a way to get stand-alone month labels.
+ return shortMonthLabels();
+}
+
const Vector<String>& LocaleWin::timeAMPMLabels()
{
if (m_timeAMPMLabels.isEmpty()) {
Modified: trunk/Source/WebCore/platform/text/LocaleWin.h (131853 => 131854)
--- trunk/Source/WebCore/platform/text/LocaleWin.h 2012-10-19 04:45:47 UTC (rev 131853)
+++ trunk/Source/WebCore/platform/text/LocaleWin.h 2012-10-19 05:08:47 UTC (rev 131854)
@@ -60,6 +60,8 @@
virtual String monthFormat() OVERRIDE;
virtual String timeFormat() OVERRIDE;
virtual String shortTimeFormat() OVERRIDE;
+ virtual const Vector<String>& shortMonthLabels() OVERRIDE;
+ virtual const Vector<String>& shortStandAloneMonthLabels() OVERRIDE;
virtual const Vector<String>& timeAMPMLabels() OVERRIDE;
#endif
Modified: trunk/Source/WebCore/platform/text/Localizer.h (131853 => 131854)
--- trunk/Source/WebCore/platform/text/Localizer.h 2012-10-19 04:45:47 UTC (rev 131853)
+++ trunk/Source/WebCore/platform/text/Localizer.h 2012-10-19 05:08:47 UTC (rev 131854)
@@ -83,6 +83,14 @@
// field.
String dateTimeFormatWithoutSeconds();
+ // Returns a vector of string of which size is 12. The first item is a
+ // localized string of Jan and the last item is a localized string of
+ // Dec. These strings should be short.
+ virtual const Vector<String>& shortMonthLabels() = 0;
+
+ // Stand-alone month version of shortMonthLabels.
+ virtual const Vector<String>& shortStandAloneMonthLabels() = 0;
+
// Returns localized period field(AM/PM) strings.
virtual const Vector<String>& timeAMPMLabels();
#endif
Modified: trunk/Source/WebCore/platform/text/mac/LocaleMac.h (131853 => 131854)
--- trunk/Source/WebCore/platform/text/mac/LocaleMac.h 2012-10-19 04:45:47 UTC (rev 131853)
+++ trunk/Source/WebCore/platform/text/mac/LocaleMac.h 2012-10-19 05:08:47 UTC (rev 131854)
@@ -65,6 +65,8 @@
virtual String monthFormat() OVERRIDE;
virtual String timeFormat() OVERRIDE;
virtual String shortTimeFormat() OVERRIDE;
+ virtual const Vector<String>& shortMonthLabels() OVERRIDE;
+ virtual const Vector<String>& shortStandAloneMonthLabels() OVERRIDE;
virtual const Vector<String>& timeAMPMLabels() OVERRIDE;
#endif
@@ -88,6 +90,8 @@
String m_monthFormat;
String m_localizedTimeFormatText;
String m_localizedShortTimeFormatText;
+ Vector<String> m_shortMonthLabels;
+ Vector<String> m_shortStandAloneMonthLabels;
Vector<String> m_timeAMPMLabels;
#endif
bool m_didInitializeNumberData;
Modified: trunk/Source/WebCore/platform/text/mac/LocaleMac.mm (131853 => 131854)
--- trunk/Source/WebCore/platform/text/mac/LocaleMac.mm 2012-10-19 04:45:47 UTC (rev 131853)
+++ trunk/Source/WebCore/platform/text/mac/LocaleMac.mm 2012-10-19 05:08:47 UTC (rev 131854)
@@ -272,6 +272,37 @@
return m_localizedShortTimeFormatText;
}
+const Vector<String>& LocaleMac::shortMonthLabels()
+{
+ if (!m_shortMonthLabels.isEmpty())
+ return m_shortMonthLabels;
+ m_shortMonthLabels.reserveCapacity(12);
+ NSArray *array = [shortDateFormatter().get() shortMonthSymbols];
+ if ([array count] == 12) {
+ for (unsigned i = 0; i < 12; ++i)
+ m_shortMonthLabels.append([array objectAtIndex:i]);
+ return m_shortMonthLabels;
+ }
+ for (unsigned i = 0; i < WTF_ARRAY_LENGTH(WTF::monthName); ++i)
+ m_shortMonthLabels.append(WTF::monthName[i]);
+ return m_shortMonthLabels;
+}
+
+const Vector<String>& LocaleMac::shortStandAloneMonthLabels()
+{
+ if (!m_shortStandAloneMonthLabels.isEmpty())
+ return m_shortStandAloneMonthLabels;
+ NSArray *array = [shortDateFormatter().get() shortStandaloneMonthSymbols];
+ if ([array count] == 12) {
+ m_shortStandAloneMonthLabels.reserveCapacity(12);
+ for (unsigned i = 0; i < 12; ++i)
+ m_shortStandAloneMonthLabels.append([array objectAtIndex:i]);
+ return m_shortStandAloneMonthLabels;
+ }
+ m_shortStandAloneMonthLabels = shortMonthLabels();
+ return m_shortStandAloneMonthLabels;
+}
+
const Vector<String>& LocaleMac::timeAMPMLabels()
{
if (!m_timeAMPMLabels.isEmpty())
Modified: trunk/Source/WebKit/chromium/ChangeLog (131853 => 131854)
--- trunk/Source/WebKit/chromium/ChangeLog 2012-10-19 04:45:47 UTC (rev 131853)
+++ trunk/Source/WebKit/chromium/ChangeLog 2012-10-19 05:08:47 UTC (rev 131854)
@@ -1,3 +1,24 @@
+2012-10-18 Kent Tamura <[email protected]>
+
+ Add shortMonthLabels and shortStandAloneMonthLabels to Localizer
+ https://bugs.webkit.org/show_bug.cgi?id=99787
+
+ Reviewed by Kentaro Hara.
+
+ * tests/LocaleMacTest.cpp:
+ (LocaleMacTest::shortMonthLabel): A helper.
+ (LocaleMacTest::shortStandAloneMonthLabel): Ditto.
+ (TEST_F): Added tests for some locales.
+ * tests/LocaleWinTest.cpp:
+ (LocaleWinTest::shortMonthLabel): A helper.
+ (TEST_F): Added tests for some locales. We don't test
+ LocaleWin::shortStandAloneMonthLabels because it is identical to
+ shortMonthLabels.
+ * tests/LocalizedDateICUTest.cpp:
+ (LocalizedDateICUTest::shortMonthLabel): A helper.
+ (LocalizedDateICUTest::shortStandAloneMonthLabel): Ditto.
+ (TEST_F): Added tests for some locales.
+
2012-10-18 Jochen Eisinger <[email protected]>
[chromium] Add a webkit_test_support target that WebTestingSupport
Modified: trunk/Source/WebKit/chromium/tests/LocaleMacTest.cpp (131853 => 131854)
--- trunk/Source/WebKit/chromium/tests/LocaleMacTest.cpp 2012-10-19 04:45:47 UTC (rev 131853)
+++ trunk/Source/WebKit/chromium/tests/LocaleMacTest.cpp 2012-10-19 05:08:47 UTC (rev 131854)
@@ -138,6 +138,18 @@
return locale->shortTimeFormat();
}
+ String shortMonthLabel(const String& localeString, unsigned index)
+ {
+ OwnPtr<LocaleMac> locale = LocaleMac::create(localeString);
+ return locale->shortMonthLabels()[index];
+ }
+
+ String shortStandAloneMonthLabel(const String& localeString, unsigned index)
+ {
+ OwnPtr<LocaleMac> locale = LocaleMac::create(localeString);
+ return locale->shortStandAloneMonthLabels()[index];
+ }
+
String timeAMPMLabel(const String& localeString, unsigned index)
{
OwnPtr<LocaleMac> locale = LocaleMac::create(localeString);
@@ -266,6 +278,29 @@
EXPECT_STREQ("H:mm", shortTimeFormat("ja_JP").utf8().data());
}
+TEST_F(LocaleMacTest, shortMonthLabels)
+{
+ EXPECT_STREQ("Jan", shortMonthLabel("en_US", 0).utf8().data());
+ EXPECT_STREQ("Jan", shortStandAloneMonthLabel("en_US", 0).utf8().data());
+ EXPECT_STREQ("Dec", shortMonthLabel("en_US", 11).utf8().data());
+ EXPECT_STREQ("Dec", shortStandAloneMonthLabel("en_US", 11).utf8().data());
+
+ EXPECT_STREQ("janv.", shortMonthLabel("fr_FR", 0).utf8().data());
+ EXPECT_STREQ("janv.", shortStandAloneMonthLabel("fr_FR", 0).utf8().data());
+ EXPECT_STREQ("d\xC3\xA9" "c.", shortMonthLabel("fr_FR", 11).utf8().data());
+ EXPECT_STREQ("d\xC3\xA9" "c.", shortStandAloneMonthLabel("fr_FR", 11).utf8().data());
+
+ EXPECT_STREQ("1\xE6\x9C\x88", shortMonthLabel("ja_JP", 0).utf8().data());
+ EXPECT_STREQ("1\xE6\x9C\x88", shortStandAloneMonthLabel("ja_JP", 0).utf8().data());
+ EXPECT_STREQ("12\xE6\x9C\x88", shortMonthLabel("ja_JP", 11).utf8().data());
+ EXPECT_STREQ("12\xE6\x9C\x88", shortStandAloneMonthLabel("ja_JP", 11).utf8().data());
+
+ EXPECT_STREQ("\xD0\xBC\xD0\xB0\xD1\x80\xD1\x82\xD0\xB0", shortMonthLabel("ru_RU", 2).utf8().data());
+ EXPECT_STREQ("\xD0\x9C\xD0\xB0\xD1\x80\xD1\x82", shortStandAloneMonthLabel("ru_RU", 2).utf8().data());
+ EXPECT_STREQ("\xD0\xBC\xD0\xB0\xD1\x8F", shortMonthLabel("ru_RU", 4).utf8().data());
+ EXPECT_STREQ("\xD0\x9C\xD0\xB0\xD0\xB9", shortStandAloneMonthLabel("ru_RU", 4).utf8().data());
+}
+
TEST_F(LocaleMacTest, timeAMPMLabels)
{
EXPECT_STREQ("AM", timeAMPMLabel("en_US", 0).utf8().data());
Modified: trunk/Source/WebKit/chromium/tests/LocaleWinTest.cpp (131853 => 131854)
--- trunk/Source/WebKit/chromium/tests/LocaleWinTest.cpp 2012-10-19 04:45:47 UTC (rev 131853)
+++ trunk/Source/WebKit/chromium/tests/LocaleWinTest.cpp 2012-10-19 05:08:47 UTC (rev 131854)
@@ -147,6 +147,12 @@
return locale->shortTimeFormat();
}
+ String shortMonthLabel(LCID lcid, unsigned index)
+ {
+ OwnPtr<LocaleWin> locale = LocaleWin::create(lcid);
+ return locale->shortMonthLabels()[index];
+ }
+
String timeAMPMLabel(LCID lcid, unsigned index)
{
OwnPtr<LocaleWin> locale = LocaleWin::create(lcid);
@@ -311,6 +317,16 @@
EXPECT_STREQ("H:mm:ss", shortTimeFormat(JapaneseJP).utf8().data());
}
+TEST_F(LocaleWinTest, shortMonthLabels)
+{
+ EXPECT_STREQ("Jan", shortMonthLabel(EnglishUS, 0).utf8().data());
+ EXPECT_STREQ("Dec", shortMonthLabel(EnglishUS, 11).utf8().data());
+ EXPECT_STREQ("janv.", shortMonthLabel(FrenchFR, 0).utf8().data());
+ EXPECT_STREQ("d\xC3\xA9" "c.", shortMonthLabel(FrenchFR, 11).utf8().data());
+ EXPECT_STREQ("1", shortMonthLabel(JapaneseJP, 0).utf8().data());
+ EXPECT_STREQ("12", shortMonthLabel(JapaneseJP, 11).utf8().data());
+}
+
TEST_F(LocaleWinTest, timeAMPMLabels)
{
EXPECT_STREQ("AM", timeAMPMLabel(EnglishUS, 0).utf8().data());
Modified: trunk/Source/WebKit/chromium/tests/LocalizedDateICUTest.cpp (131853 => 131854)
--- trunk/Source/WebKit/chromium/tests/LocalizedDateICUTest.cpp 2012-10-19 04:45:47 UTC (rev 131853)
+++ trunk/Source/WebKit/chromium/tests/LocalizedDateICUTest.cpp 2012-10-19 05:08:47 UTC (rev 131854)
@@ -106,6 +106,18 @@
return locale->shortTimeFormat();
}
+ String shortMonthLabel(const char* localeString, unsigned index)
+ {
+ OwnPtr<LocaleICU> locale = LocaleICU::create(localeString);
+ return locale->shortMonthLabels()[index];
+ }
+
+ String shortStandAloneMonthLabel(const char* localeString, unsigned index)
+ {
+ OwnPtr<LocaleICU> locale = LocaleICU::create(localeString);
+ return locale->shortStandAloneMonthLabels()[index];
+ }
+
Labels timeAMPMLabels(const char* localeString)
{
OwnPtr<LocaleICU> locale = LocaleICU::create(localeString);
@@ -154,6 +166,29 @@
EXPECT_STREQ("H:mm", localizedShortDateFormatText("ja").utf8().data());
}
+TEST_F(LocalizedDateICUTest, shortMonthLabels)
+{
+ EXPECT_STREQ("Jan", shortMonthLabel("en_US", 0).utf8().data());
+ EXPECT_STREQ("Jan", shortStandAloneMonthLabel("en_US", 0).utf8().data());
+ EXPECT_STREQ("Dec", shortMonthLabel("en_US", 11).utf8().data());
+ EXPECT_STREQ("Dec", shortStandAloneMonthLabel("en_US", 11).utf8().data());
+
+ EXPECT_STREQ("janv.", shortMonthLabel("fr_FR", 0).utf8().data());
+ EXPECT_STREQ("janv.", shortStandAloneMonthLabel("fr_FR", 0).utf8().data());
+ EXPECT_STREQ("d\xC3\xA9" "c.", shortMonthLabel("fr_FR", 11).utf8().data());
+ EXPECT_STREQ("d\xC3\xA9" "c.", shortStandAloneMonthLabel("fr_FR", 11).utf8().data());
+
+ EXPECT_STREQ("1\xE6\x9C\x88", shortMonthLabel("ja_JP", 0).utf8().data());
+ EXPECT_STREQ("1\xE6\x9C\x88", shortStandAloneMonthLabel("ja_JP", 0).utf8().data());
+ EXPECT_STREQ("12\xE6\x9C\x88", shortMonthLabel("ja_JP", 11).utf8().data());
+ EXPECT_STREQ("12\xE6\x9C\x88", shortStandAloneMonthLabel("ja_JP", 11).utf8().data());
+
+ EXPECT_STREQ("\xD0\xBC\xD0\xB0\xD1\x80\xD1\x82\xD0\xB0", shortMonthLabel("ru_RU", 2).utf8().data());
+ EXPECT_STREQ("\xD0\xBC\xD0\xB0\xD1\x80\xD1\x82", shortStandAloneMonthLabel("ru_RU", 2).utf8().data());
+ EXPECT_STREQ("\xD0\xBC\xD0\xB0\xD1\x8F", shortMonthLabel("ru_RU", 4).utf8().data());
+ EXPECT_STREQ("\xD0\xBC\xD0\xB0\xD0\xB9", shortStandAloneMonthLabel("ru_RU", 4).utf8().data());
+}
+
TEST_F(LocalizedDateICUTest, timeAMPMLabels)
{
EXPECT_EQ(labels("AM", "PM"), timeAMPMLabels("en_US"));