WebKit Bugzilla
New
Browse
Search+
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
[patch]
Patch 3
bug-90248-20120710105957.patch (text/plain), 30.73 KB, created by
yosin
on 2012-07-09 18:59:59 PDT
(
hide
)
Description:
Patch 3
Filename:
MIME Type:
Creator:
yosin
Created:
2012-07-09 18:59:59 PDT
Size:
30.73 KB
patch
obsolete
>Subversion Revision: 122176 >diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog >index bde59c6d7edeb775615a55140724057d6189dce1..0709e511c68ca6866211e17ce19bfeb0437fc461 100644 >--- a/Source/WebCore/ChangeLog >+++ b/Source/WebCore/ChangeLog >@@ -1,3 +1,41 @@ >+2012-07-09 Yoshifumi Inoue <yosin@chromium.org> >+ >+ [Platform] Introduce LocaleMac class >+ https://bugs.webkit.org/show_bug.cgi?id=90248 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ This patch moves implementation of localized date format related >+ functions into LocaleMac class as of LocaleWin class for ease of >+ maintain and using specific locale in testing rather than system >+ default locale. >+ >+ Tests: WebKit/chromium/tests/LocaleMacTest.cpp >+ >+ * WebCore.gyp/WebCore.gyp: Include LocaleMac.mm >+ * WebCore.gypi: >+ * platform/text/mac/LocaleMac.h: Replace LocaleWin to LocaleMac. >+ * platform/text/mac/LocaleMac.mm: >+ (WebCore::LocaleMac::LocaleMac): >+ (WebCore::LocaleMac::~LocaleMac): >+ (WebCore::LocaleMac::create): >+ (WebCore::LocaleMac::currentLocale): >+ (WebCore::LocaleMac::createShortDateFormatter): >+ (WebCore::LocaleMac::parseDate): >+ (WebCore::LocaleMac::formatDate): >+ (WebCore::LocaleMac::dateFormatText): >+ (WebCore::LocaleMac::monthLabels): >+ (WebCore::LocaleMac::weekDayShortLabels): >+ (WebCore::LocaleMac::firstDayOfWeek): >+ * platform/text/mac/LocalizedDateMac.cpp: >+ (WebCore::parseLocalizedDate): >+ (WebCore::formatLocalizedDate): >+ (WebCore::localizedDateFormatText): >+ (WebCore::monthLabels): >+ (WebCore::weekDayShortLabels): >+ (WebCore::firstDayOfWeek): >+ * platform/text/mac/LocalizedDateMac.mm: Removed. >+ > 2012-07-09 Alice Cheng <alice_cheng@apple.com> > > Editing: Autocorrection in blockquotes causes text to break out of quote >diff --git a/Source/WebKit/chromium/ChangeLog b/Source/WebKit/chromium/ChangeLog >index 1552e032f66d773449ceca987580dc145a8bebc3..96a61c51582163b6a36ef3cee014b6b1d998ae1f 100644 >--- a/Source/WebKit/chromium/ChangeLog >+++ b/Source/WebKit/chromium/ChangeLog >@@ -1,3 +1,25 @@ >+2012-07-09 Yoshifumi Inoue <yosin@chromium.org> >+ >+ [Platform] Introduce LocaleMac class >+ https://bugs.webkit.org/show_bug.cgi?id=90248 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ This patch added tests for LocaleMac class. >+ >+ * WebKit.gypi: >+ * tests/LocaleMacTest.cpp: Added. >+ (LocaleMacTest): >+ (LocaleMacTest::dateComponents): >+ (LocaleMacTest::msForDate): >+ (LocaleMacTest::formatDate): >+ (LocaleMacTest::parseDate): >+ (LocaleMacTest::dateFormatText): >+ (LocaleMacTest::firstDayOfWeek): >+ (LocaleMacTest::monthLabel): >+ (LocaleMacTest::weekDayShortLabel): >+ (TEST_F): >+ > 2012-07-09 Joshua Bell <jsbell@chromium.org> > > IndexedDB: Remove obsolete accessor plumbing >diff --git a/Source/WebCore/WebCore.gyp/WebCore.gyp b/Source/WebCore/WebCore.gyp/WebCore.gyp >index cb0e76a050a0570f6ebdfd2e378cd7713c7ae799..ebe539d9521b9bc1b5852fa3729d63495758c5df 100644 >--- a/Source/WebCore/WebCore.gyp/WebCore.gyp >+++ b/Source/WebCore/WebCore.gyp/WebCore.gyp >@@ -1648,9 +1648,10 @@ > > ['include', 'WebKit/mac/WebCoreSupport/WebSystemInterface\\.mm$'], > >- # We use LocalizedDateMac.mm instead of LocalizedDateICU.cpp. >+ # We use LocalizedDateMac.cpp with LocaleMac.mm instead of LocalizedDateICU.cpp. > ['exclude', 'platform/text/LocalizedDateICU\\.cpp$'], >- ['include', 'platform/text/mac/LocalizedDateMac\\.mm$'], >+ ['include', 'platform/text/mac/LocaleMac\\.mm$'], >+ ['include', 'platform/text/mac/LocalizedDateMac\\.cpp$'], > > # The Mac uses platform/mac/KillRingMac.mm instead of the dummy > # implementation. >diff --git a/Source/WebCore/WebCore.gypi b/Source/WebCore/WebCore.gypi >index 79ec16532b5fa4609f79e9ed7e4803ff9f16eb9b..eaafdf3fd56ac89f3365682242b91ee6d3b56616 100644 >--- a/Source/WebCore/WebCore.gypi >+++ b/Source/WebCore/WebCore.gypi >@@ -4436,7 +4436,9 @@ > 'platform/text/gtk/TextCodecGtk.cpp', > 'platform/text/gtk/TextCodecGtk.h', > 'platform/text/mac/HyphenationMac.mm', >- 'platform/text/mac/LocalizedDateMac.mm', >+ 'platform/text/mac/LocaleMac.h', >+ 'platform/text/mac/LocaleMac.mm', >+ 'platform/text/mac/LocalizedDateMac.cpp', > 'platform/text/mac/LocalizedNumberMac.mm', > 'platform/text/mac/ShapeArabic.c', > 'platform/text/mac/ShapeArabic.h', >diff --git a/Source/WebCore/platform/text/mac/LocaleMac.h b/Source/WebCore/platform/text/mac/LocaleMac.h >index 6a75c994557f570a98cbf7f609b456f3dce23c44..4c371ed7a81df39cc2a375ca8209511c87734a41 100644 >--- a/Source/WebCore/platform/text/mac/LocaleMac.h >+++ b/Source/WebCore/platform/text/mac/LocaleMac.h >@@ -28,60 +28,46 @@ > * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. > */ > >-#ifndef LocaleWin_h >-#define LocaleWin_h >+#ifndef LocaleMac_h >+#define LocaleMac_h > >-#include <windows.h> > #include <wtf/Forward.h> >+#include <wtf/RetainPtr.h> > #include <wtf/Vector.h> >+#include <wtf/text/WTFString.h> >+ >+OBJC_CLASS NSDateFormatter; >+OBJC_CLASS NSLocale; > > namespace WebCore { > > class DateComponents; >-struct DateFormatToken; > >-class LocaleWin { >+class LocaleMac { > public: >- static PassOwnPtr<LocaleWin> create(LCID); >- static LocaleWin* currentLocale(); >- ~LocaleWin(); >+ static PassOwnPtr<LocaleMac> create(const String&); >+ static LocaleMac* currentLocale(); >+ ~LocaleMac(); > double parseDate(const String&); > String formatDate(const DateComponents&); >+ > #if ENABLE(CALENDAR_PICKER) > String dateFormatText(); > const Vector<String>& monthLabels(); > const Vector<String>& weekDayShortLabels(); >- unsigned firstDayOfWeek() { return m_firstDayOfWeek; } >+ unsigned firstDayOfWeek(); > #endif > >- // For testing. >- double parseDate(const String& format, int baseYear, const String& input); >- String formatDate(const String& format, int baseYear, int year, int month, int day); >- static String dateFormatText(const String& format, const String& yearText, const String& monthText, const String& dayText); >- > private: >- explicit LocaleWin(LCID); >- String getLocaleInfoString(LCTYPE); >- void ensureShortMonthLabels(); >- void ensureMonthLabels(); >- void ensureShortDateTokens(); >- int parseNumberOrMonth(const String&, unsigned& index); >- double parseDate(const Vector<DateFormatToken>&, int baseYear, const String&); >- String formatDate(const Vector<DateFormatToken>&, int baseYear, int year, int month, int day); >-#if ENABLE(CALENDAR_PICKER) >- void ensureWeekDayShortLabels(); >-#endif >+ explicit LocaleMac(const String&); >+ NSDateFormatter *createShortDateFormatter(); > >- LCID m_lcid; >- int m_baseYear; >- Vector<DateFormatToken> m_shortDateTokens; >- Vector<String> m_shortMonthLabels; >- Vector<String> m_monthLabels; >+ RetainPtr<NSLocale> m_locale; > #if ENABLE(CALENDAR_PICKER) >+ String m_localizedDateFormatText; >+ Vector<String> m_monthLabels; > Vector<String> m_weekDayShortLabels; >- unsigned m_firstDayOfWeek; > #endif >- > }; > > } >diff --git a/Source/WebCore/platform/text/mac/LocaleMac.mm b/Source/WebCore/platform/text/mac/LocaleMac.mm >index 08876f9d381350b8ccfd9532fc22bb9f6ba4bb21..c7097cecefecfc5cef554425350606e2bbb86cfc 100644 >--- a/Source/WebCore/platform/text/mac/LocaleMac.mm >+++ b/Source/WebCore/platform/text/mac/LocaleMac.mm >@@ -29,12 +29,14 @@ > */ > > #include "config.h" >-#include "LocalizedDate.h" >+#include "LocaleMac.h" > > #import <Foundation/NSDateFormatter.h> >+#import <Foundation/NSLocale.h> >+#include "LocalizedDate.h" > #include "LocalizedStrings.h" >-#include <limits> > #include <wtf/DateMath.h> >+#include <wtf/PassOwnPtr.h> > #include <wtf/RetainPtr.h> > #include <wtf/text/StringBuilder.h> > >@@ -42,9 +44,30 @@ using namespace std; > > namespace WebCore { > >-static NSDateFormatter *createShortDateFormatter() >+LocaleMac::LocaleMac(const String& localeIdentifier) >+ : m_locale([[NSLocale alloc] initWithLocaleIdentifier:localeIdentifier]) >+{ >+} >+ >+LocaleMac::~LocaleMac() >+{ >+} >+ >+PassOwnPtr<LocaleMac> LocaleMac::create(const String& localeIdentifier) >+{ >+ return adoptPtr(new LocaleMac(localeIdentifier)); >+} >+ >+LocaleMac* LocaleMac::currentLocale() >+{ >+ static LocaleMac* currentLocale = LocaleMac::create([NSLocale currentLocale]).leakPtr(); >+ return currentLocale; >+} >+ >+NSDateFormatter* LocaleMac::createShortDateFormatter() > { > NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; >+ [formatter setLocale:m_locale.get()]; > [formatter setDateStyle:NSDateFormatterShortStyle]; > [formatter setTimeStyle:NSDateFormatterNoStyle]; > [formatter setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"UTC"]]; >@@ -52,44 +75,20 @@ static NSDateFormatter *createShortDateFormatter() > return formatter; > } > >-double parseLocalizedDate(const String& input, DateComponents::Type type) >+double LocaleMac::parseDate(const String& input) > { >- switch (type) { >- case DateComponents::Date: { >- RetainPtr<NSDateFormatter> formatter(AdoptNS, createShortDateFormatter()); >- NSDate *date = [formatter.get() dateFromString:input]; >- if (!date) >- break; >- return [date timeIntervalSince1970] * msPerSecond; >- } >- 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(); >+ RetainPtr<NSDateFormatter> formatter(AdoptNS, createShortDateFormatter()); >+ NSDate *date = [formatter.get() dateFromString:input]; >+ if (!date) >+ return std::numeric_limits<double>::quiet_NaN(); >+ return [date timeIntervalSince1970] * msPerSecond; > } > >-String formatLocalizedDate(const DateComponents& dateComponents) >+String LocaleMac::formatDate(const DateComponents& dateComponents) > { >- switch (dateComponents.type()) { >- case DateComponents::Date: { >- RetainPtr<NSDateFormatter> formatter(AdoptNS, createShortDateFormatter()); >- NSTimeInterval interval = dateComponents.millisecondsSinceEpoch() / msPerSecond; >- return String([formatter.get() stringFromDate:[NSDate dateWithTimeIntervalSince1970:interval]]); >- } >- case DateComponents::DateTime: >- case DateComponents::DateTimeLocal: >- case DateComponents::Month: >- case DateComponents::Time: >- case DateComponents::Week: >- case DateComponents::Invalid: >- break; >- } >- return String(); >+ RetainPtr<NSDateFormatter> formatter(AdoptNS, createShortDateFormatter()); >+ NSTimeInterval interval = dateComponents.millisecondsSinceEpoch() / msPerSecond; >+ return String([formatter.get() stringFromDate:[NSDate dateWithTimeIntervalSince1970:interval]]); > } > > #if ENABLE(CALENDAR_PICKER) >@@ -140,62 +139,59 @@ static String localizeDateFormat(const String& format) > return buffer.toString(); > } > >-String localizedDateFormatText() >+String LocaleMac::dateFormatText() > { >- DEFINE_STATIC_LOCAL(String, text, ()); >- if (!text.isEmpty()) >- return text; >+ if (!m_localizedDateFormatText.isEmpty()) >+ return m_localizedDateFormatText; > RetainPtr<NSDateFormatter> formatter(AdoptNS, createShortDateFormatter()); >- text = localizeDateFormat(String([formatter.get() dateFormat])); >- return text; >+ m_localizedDateFormatText = localizeDateFormat(String([formatter.get() dateFormat])); >+ return m_localizedDateFormatText; > } > >-const Vector<String>& monthLabels() >+const Vector<String>& LocaleMac::monthLabels() > { >- DEFINE_STATIC_LOCAL(Vector<String>, labels, ()); >- if (!labels.isEmpty()) >- return labels; >- labels.reserveCapacity(12); >+ if (!m_monthLabels.isEmpty()) >+ return m_monthLabels; >+ m_monthLabels.reserveCapacity(12); > RetainPtr<NSDateFormatter> formatter(AdoptNS, createShortDateFormatter()); > NSArray *array = [formatter.get() monthSymbols]; > if ([array count] == 12) { > for (unsigned i = 0; i < 12; ++i) >- labels.append(String([array objectAtIndex:i])); >- return labels; >+ m_monthLabels.append(String([array objectAtIndex:i])); >+ return m_monthLabels; > } > for (unsigned i = 0; i < WTF_ARRAY_LENGTH(WTF::monthFullName); ++i) >- labels.append(WTF::monthFullName[i]); >- return labels; >+ m_monthLabels.append(WTF::monthFullName[i]); >+ return m_monthLabels; > } > >-const Vector<String>& weekDayShortLabels() >+const Vector<String>& LocaleMac::weekDayShortLabels() > { >- DEFINE_STATIC_LOCAL(Vector<String>, labels, ()); >- if (!labels.isEmpty()) >- return labels; >- labels.reserveCapacity(7); >+ if (!m_weekDayShortLabels.isEmpty()) >+ return m_weekDayShortLabels; >+ m_weekDayShortLabels.reserveCapacity(7); > RetainPtr<NSDateFormatter> formatter(AdoptNS, createShortDateFormatter()); > NSArray *array = [formatter.get() shortWeekdaySymbols]; > if ([array count] == 7) { > for (unsigned i = 0; i < 7; ++i) >- labels.append(String([array objectAtIndex:i])); >- return labels; >+ m_weekDayShortLabels.append(String([array objectAtIndex:i])); >+ return m_weekDayShortLabels; > } > for (unsigned i = 0; i < WTF_ARRAY_LENGTH(WTF::weekdayName); ++i) { > // weekdayName starts with Monday. >- labels.append(WTF::weekdayName[(i + 6) % 7]); >+ m_weekDayShortLabels.append(WTF::weekdayName[(i + 6) % 7]); > } >- return labels; >+ return m_weekDayShortLabels; > } > >-unsigned firstDayOfWeek() >+unsigned LocaleMac::firstDayOfWeek() > { > RetainPtr<NSCalendar> calendar(AdoptNS, [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]); >+ [calendar.get() setLocale:m_locale.get()]; > // The document for NSCalendar - firstWeekday doesn't have an explanation of > // firstWeekday value. We can guess it by the document of NSDateComponents - > // weekDay, so it can be 1 through 7 and 1 is Sunday. > return [calendar.get() firstWeekday] - 1; > } > #endif >- > } >diff --git a/Source/WebCore/platform/text/mac/LocalizedDateMac.cpp b/Source/WebCore/platform/text/mac/LocalizedDateMac.cpp >index bd8f367f3a5dc1b89c5d78e02e5e347afc847ab5..e67c93817a01756770fe0e83c7ffee49c6e26acb 100644 >--- a/Source/WebCore/platform/text/mac/LocalizedDateMac.cpp >+++ b/Source/WebCore/platform/text/mac/LocalizedDateMac.cpp >@@ -31,7 +31,7 @@ > #include "config.h" > #include "LocalizedDate.h" > >-#include "LocaleWin.h" >+#include "LocaleMac.h" > #include <limits> > > using namespace std; >@@ -42,7 +42,7 @@ double parseLocalizedDate(const String& input, DateComponents::Type type) > { > switch (type) { > case DateComponents::Date: >- return LocaleWin::currentLocale()->parseDate(input); >+ return LocaleMac::currentLocale()->parseDate(input); > case DateComponents::DateTime: > case DateComponents::DateTimeLocal: > case DateComponents::Month: >@@ -58,7 +58,7 @@ String formatLocalizedDate(const DateComponents& dateComponents) > { > switch (dateComponents.type()) { > case DateComponents::Date: >- return LocaleWin::currentLocale()->formatDate(dateComponents); >+ return LocaleMac::currentLocale()->formatDate(dateComponents); > case DateComponents::DateTime: > case DateComponents::DateTimeLocal: > case DateComponents::Month: >@@ -73,22 +73,22 @@ String formatLocalizedDate(const DateComponents& dateComponents) > #if ENABLE(CALENDAR_PICKER) > String localizedDateFormatText() > { >- return LocaleWin::currentLocale()->dateFormatText(); >+ return LocaleMac::currentLocale()->dateFormatText(); > } > > const Vector<String>& monthLabels() > { >- return LocaleWin::currentLocale()->monthLabels(); >+ return LocaleMac::currentLocale()->monthLabels(); > } > > const Vector<String>& weekDayShortLabels() > { >- return LocaleWin::currentLocale()->weekDayShortLabels(); >+ return LocaleMac::currentLocale()->weekDayShortLabels(); > } > > unsigned firstDayOfWeek() > { >- return LocaleWin::currentLocale()->firstDayOfWeek(); >+ return LocaleMac::currentLocale()->firstDayOfWeek(); > } > #endif > >diff --git a/Source/WebCore/platform/text/mac/LocalizedDateMac.mm b/Source/WebCore/platform/text/mac/LocalizedDateMac.mm >deleted file mode 100644 >index 08876f9d381350b8ccfd9532fc22bb9f6ba4bb21..0000000000000000000000000000000000000000 >--- a/Source/WebCore/platform/text/mac/LocalizedDateMac.mm >+++ /dev/null >@@ -1,201 +0,0 @@ >-/* >- * 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" >- >-#import <Foundation/NSDateFormatter.h> >-#include "LocalizedStrings.h" >-#include <limits> >-#include <wtf/DateMath.h> >-#include <wtf/RetainPtr.h> >-#include <wtf/text/StringBuilder.h> >- >-using namespace std; >- >-namespace WebCore { >- >-static NSDateFormatter *createShortDateFormatter() >-{ >- NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; >- [formatter setDateStyle:NSDateFormatterShortStyle]; >- [formatter setTimeStyle:NSDateFormatterNoStyle]; >- [formatter setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"UTC"]]; >- [formatter setCalendar:[[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]]; >- return formatter; >-} >- >-double parseLocalizedDate(const String& input, DateComponents::Type type) >-{ >- switch (type) { >- case DateComponents::Date: { >- RetainPtr<NSDateFormatter> formatter(AdoptNS, createShortDateFormatter()); >- NSDate *date = [formatter.get() dateFromString:input]; >- if (!date) >- break; >- return [date timeIntervalSince1970] * msPerSecond; >- } >- 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: { >- RetainPtr<NSDateFormatter> formatter(AdoptNS, createShortDateFormatter()); >- NSTimeInterval interval = dateComponents.millisecondsSinceEpoch() / msPerSecond; >- return String([formatter.get() stringFromDate:[NSDate dateWithTimeIntervalSince1970:interval]]); >- } >- case DateComponents::DateTime: >- case DateComponents::DateTimeLocal: >- case DateComponents::Month: >- case DateComponents::Time: >- case DateComponents::Week: >- case DateComponents::Invalid: >- break; >- } >- return String(); >-} >- >-#if ENABLE(CALENDAR_PICKER) >-static bool isYearSymbol(UChar letter) { return letter == 'y' || letter == 'Y' || letter == 'u'; } >-static bool isMonthSymbol(UChar letter) { return letter == 'M' || letter == 'L'; } >-static bool isDaySymbol(UChar letter) { return letter == 'd'; } >- >-// http://unicode.org/reports/tr35/tr35-6.html#Date_Format_Patterns >-static String localizeDateFormat(const String& format) >-{ >- String yearText = dateFormatYearText().isEmpty() ? "Year" : dateFormatYearText(); >- String monthText = dateFormatMonthText().isEmpty() ? "Month" : dateFormatMonthText(); >- String dayText = dateFormatDayInMonthText().isEmpty() ? "Day" : dateFormatDayInMonthText(); >- StringBuilder buffer; >- bool inQuote = false; >- for (unsigned i = 0; i < format.length(); ++i) { >- UChar ch = format[i]; >- if (inQuote) { >- if (ch == '\'') { >- inQuote = false; >- ASSERT(i); >- if (format[i - 1] == '\'') >- buffer.append('\''); >- } else >- buffer.append(ch); >- continue; >- } >- >- if (ch == '\'') { >- inQuote = true; >- if (i > 0 && format[i - 1] == '\'') >- buffer.append(ch); >- } else if (isYearSymbol(ch)) { >- if (i > 0 && format[i - 1] == ch) >- continue; >- buffer.append(yearText); >- } else if (isMonthSymbol(ch)) { >- if (i > 0 && format[i - 1] == ch) >- continue; >- buffer.append(monthText); >- } else if (isDaySymbol(ch)) { >- if (i > 0 && format[i - 1] == ch) >- continue; >- buffer.append(dayText); >- } else >- buffer.append(ch); >- } >- return buffer.toString(); >-} >- >-String localizedDateFormatText() >-{ >- DEFINE_STATIC_LOCAL(String, text, ()); >- if (!text.isEmpty()) >- return text; >- RetainPtr<NSDateFormatter> formatter(AdoptNS, createShortDateFormatter()); >- text = localizeDateFormat(String([formatter.get() dateFormat])); >- return text; >-} >- >-const Vector<String>& monthLabels() >-{ >- DEFINE_STATIC_LOCAL(Vector<String>, labels, ()); >- if (!labels.isEmpty()) >- return labels; >- labels.reserveCapacity(12); >- RetainPtr<NSDateFormatter> formatter(AdoptNS, createShortDateFormatter()); >- NSArray *array = [formatter.get() monthSymbols]; >- if ([array count] == 12) { >- for (unsigned i = 0; i < 12; ++i) >- labels.append(String([array objectAtIndex:i])); >- return labels; >- } >- for (unsigned i = 0; i < WTF_ARRAY_LENGTH(WTF::monthFullName); ++i) >- labels.append(WTF::monthFullName[i]); >- return labels; >-} >- >-const Vector<String>& weekDayShortLabels() >-{ >- DEFINE_STATIC_LOCAL(Vector<String>, labels, ()); >- if (!labels.isEmpty()) >- return labels; >- labels.reserveCapacity(7); >- RetainPtr<NSDateFormatter> formatter(AdoptNS, createShortDateFormatter()); >- NSArray *array = [formatter.get() shortWeekdaySymbols]; >- if ([array count] == 7) { >- for (unsigned i = 0; i < 7; ++i) >- labels.append(String([array objectAtIndex:i])); >- return labels; >- } >- for (unsigned i = 0; i < WTF_ARRAY_LENGTH(WTF::weekdayName); ++i) { >- // weekdayName starts with Monday. >- labels.append(WTF::weekdayName[(i + 6) % 7]); >- } >- return labels; >-} >- >-unsigned firstDayOfWeek() >-{ >- RetainPtr<NSCalendar> calendar(AdoptNS, [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]); >- // The document for NSCalendar - firstWeekday doesn't have an explanation of >- // firstWeekday value. We can guess it by the document of NSDateComponents - >- // weekDay, so it can be 1 through 7 and 1 is Sunday. >- return [calendar.get() firstWeekday] - 1; >-} >-#endif >- >-} >diff --git a/Source/WebKit/chromium/WebKit.gypi b/Source/WebKit/chromium/WebKit.gypi >index 7b3e68c8b82afee11d18aa720f689e4f2e65154a..44b983c76e83ddc1d53e09975cc679fa66d7c474 100644 >--- a/Source/WebKit/chromium/WebKit.gypi >+++ b/Source/WebKit/chromium/WebKit.gypi >@@ -180,6 +180,11 @@ > 'tests/WebPageSerializerTest.cpp', > ], > }], >+ ['OS=="mac"', { >+ 'webkit_unittest_files': [ >+ 'tests/LocaleMacTest.cpp', >+ ], >+ }], > ['OS!="mac"', { > 'webkit_unittest_files': [ > # Mac uses ScrollAnimatorMac instead of ScrollAnimatorNone. >diff --git a/Source/WebKit/chromium/tests/LocaleMacTest.cpp b/Source/WebKit/chromium/tests/LocaleMacTest.cpp >new file mode 100644 >index 0000000000000000000000000000000000000000..d53b83c7a919a57c5486cc2d406d15b9f8997056 >--- /dev/null >+++ b/Source/WebKit/chromium/tests/LocaleMacTest.cpp >@@ -0,0 +1,162 @@ >+/* >+ * 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: >+ * 1. Redistributions of source code must retain the above copyright >+ * notice, this list of conditions and the following disclaimer. >+ * 2. 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. >+ * >+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS 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 APPLE INC. OR ITS 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 "LocaleMac.h" >+ >+#include "DateComponents.h" >+#include <gtest/gtest.h> >+#include <wtf/DateMath.h> >+#include <wtf/MathExtras.h> >+#include <wtf/PassOwnPtr.h> >+#include <wtf/text/CString.h> >+ >+using namespace WebCore; >+ >+class LocaleMacTest : public ::testing::Test { >+protected: >+ enum { >+ January = 0, February, March, >+ April, May, June, >+ July, August, September, >+ October, November, December, >+ }; >+ >+ enum { >+ Sunday = 0, Monday, Tuesday, >+ Wednesday, Thursday, Friday, >+ Saturday, >+ }; >+ >+ DateComponents dateComponents(int year, int month, int day) >+ { >+ DateComponents date; >+ date.setMillisecondsSinceEpochForDate(msForDate(year, month, day)); >+ return date; >+ } >+ >+ double msForDate(int year, int month, int day) >+ { >+ return dateToDaysFrom1970(year, month, day) * msPerDay; >+ } >+ >+ String formatDate(const String& localeString, int year, int month, int day) >+ { >+ OwnPtr<LocaleMac> locale = LocaleMac::create(localeString); >+ return locale->formatDate(dateComponents(year, month, day)); >+ } >+ >+ double parseDate(const String& localeString, const String& dateString) >+ { >+ OwnPtr<LocaleMac> locale = LocaleMac::create(localeString); >+ return locale->parseDate(dateString); >+ } >+ >+#if ENABLE(CALENDAR_PICKER) >+ String dateFormatText(const String& localeString) >+ { >+ OwnPtr<LocaleMac> locale = LocaleMac::create(localeString); >+ return locale->dateFormatText(); >+ } >+ >+ unsigned firstDayOfWeek(const String& localeString) >+ { >+ OwnPtr<LocaleMac> locale = LocaleMac::create(localeString); >+ return locale->firstDayOfWeek(); >+ } >+ >+ String monthLabel(const String& localeString, unsigned index) >+ { >+ OwnPtr<LocaleMac> locale = LocaleMac::create(localeString); >+ return locale->monthLabels()[index]; >+ } >+ >+ String weekDayShortLabel(const String& localeString, unsigned index) >+ { >+ OwnPtr<LocaleMac> locale = LocaleMac::create(localeString); >+ return locale->weekDayShortLabels()[index]; >+ } >+#endif >+}; >+ >+TEST_F(LocaleMacTest, formatDate) >+{ >+ EXPECT_STREQ("4/27/05", formatDate("en_US", 2005, April, 27).utf8().data()); >+ EXPECT_STREQ("27/04/05", formatDate("fr_FR", 2005, April, 27).utf8().data()); >+ EXPECT_STREQ("05/04/27", formatDate("ja_JP", 2005, April, 27).utf8().data()); >+} >+ >+TEST_F(LocaleMacTest, parseDate) >+{ >+ EXPECT_EQ(msForDate(2005, April, 27), parseDate("en_US", "April 27, 2005")); >+ EXPECT_EQ(msForDate(2005, April, 27), parseDate("fr_FR", "27 avril 2005")); >+ EXPECT_EQ(msForDate(2005, April, 27), parseDate("ja_JP", "2005/04/27")); >+} >+ >+#if ENABLE(CALENDAR_PICKER) >+TEST_F(LocaleMacTest, dateFormatText) >+{ >+ EXPECT_STREQ("Month/Day/Year", dateFormatText("en_US").utf8().data()); >+ EXPECT_STREQ("Day/Month/Year", dateFormatText("fr_FR").utf8().data()); >+ EXPECT_STREQ("Year/Month/Day", dateFormatText("ja_JP").utf8().data()); >+} >+ >+TEST_F(LocaleMacTest, firstDayOfWeek) >+{ >+ EXPECT_EQ(Sunday, firstDayOfWeek("en_US")); >+ EXPECT_EQ(Monday, firstDayOfWeek("fr_FR")); >+ EXPECT_EQ(Sunday, firstDayOfWeek("ja_JP")); >+} >+ >+TEST_F(LocaleMacTest, monthLabels) >+{ >+ EXPECT_STREQ("January", monthLabel("en_US", January).utf8().data()); >+ EXPECT_STREQ("June", monthLabel("en_US", June).utf8().data()); >+ EXPECT_STREQ("December", monthLabel("en_US", December).utf8().data()); >+ >+ EXPECT_STREQ("janvier", monthLabel("fr_FR", January).utf8().data()); >+ EXPECT_STREQ("juin", monthLabel("fr_FR", June).utf8().data()); >+ EXPECT_STREQ("d\xC3\xA9" "cembre", monthLabel("fr_FR", December).utf8().data()); >+ >+ EXPECT_STREQ("1\xE6\x9C\x88", monthLabel("ja_JP", January).utf8().data()); >+ EXPECT_STREQ("6\xE6\x9C\x88", monthLabel("ja_JP", June).utf8().data()); >+ EXPECT_STREQ("12\xE6\x9C\x88", monthLabel("ja_JP", December).utf8().data()); >+} >+ >+TEST_F(LocaleMacTest, weekDayShortLabels) >+{ >+ EXPECT_STREQ("Sun", weekDayShortLabel("en_US", Sunday).utf8().data()); >+ EXPECT_STREQ("Wed", weekDayShortLabel("en_US", Wednesday).utf8().data()); >+ EXPECT_STREQ("Sat", weekDayShortLabel("en_US", Saturday).utf8().data()); >+ >+ EXPECT_STREQ("dim.", weekDayShortLabel("fr_FR", Sunday).utf8().data()); >+ EXPECT_STREQ("mer.", weekDayShortLabel("fr_FR", Wednesday).utf8().data()); >+ EXPECT_STREQ("sam.", weekDayShortLabel("fr_FR", Saturday).utf8().data()); >+ >+ EXPECT_STREQ("\xE6\x97\xA5", weekDayShortLabel("ja_JP", Sunday).utf8().data()); >+ EXPECT_STREQ("\xE6\xB0\xB4", weekDayShortLabel("ja_JP", Wednesday).utf8().data()); >+ EXPECT_STREQ("\xE5\x9C\x9F", weekDayShortLabel("ja_JP", Saturday).utf8().data()); >+} >+#endif
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 90248
:
151212
|
151214
| 151384