Diff
Modified: trunk/Source/WebCore/ChangeLog (122183 => 122184)
--- trunk/Source/WebCore/ChangeLog 2012-07-10 02:14:10 UTC (rev 122183)
+++ trunk/Source/WebCore/ChangeLog 2012-07-10 02:16:27 UTC (rev 122184)
@@ -1,3 +1,41 @@
+2012-07-09 Yoshifumi Inoue <[email protected]>
+
+ [Platform] Introduce LocaleMac class
+ https://bugs.webkit.org/show_bug.cgi?id=90248
+
+ Reviewed by Kent Tamura.
+
+ 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 Dana Jansens <[email protected]>
[chromium] Create CCScopedTexture class for creating/freeing textures
Modified: trunk/Source/WebCore/WebCore.gyp/WebCore.gyp (122183 => 122184)
--- trunk/Source/WebCore/WebCore.gyp/WebCore.gyp 2012-07-10 02:14:10 UTC (rev 122183)
+++ trunk/Source/WebCore/WebCore.gyp/WebCore.gyp 2012-07-10 02:16:27 UTC (rev 122184)
@@ -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.
Modified: trunk/Source/WebCore/WebCore.gypi (122183 => 122184)
--- trunk/Source/WebCore/WebCore.gypi 2012-07-10 02:14:10 UTC (rev 122183)
+++ trunk/Source/WebCore/WebCore.gypi 2012-07-10 02:16:27 UTC (rev 122184)
@@ -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',
Modified: trunk/Source/WebCore/platform/text/mac/LocaleMac.h (122183 => 122184)
--- trunk/Source/WebCore/platform/text/mac/LocaleMac.h 2012-07-10 02:14:10 UTC (rev 122183)
+++ trunk/Source/WebCore/platform/text/mac/LocaleMac.h 2012-07-10 02:16:27 UTC (rev 122184)
@@ -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
-
};
}
Modified: trunk/Source/WebCore/platform/text/mac/LocaleMac.mm (122183 => 122184)
--- trunk/Source/WebCore/platform/text/mac/LocaleMac.mm 2012-07-10 02:14:10 UTC (rev 122183)
+++ trunk/Source/WebCore/platform/text/mac/LocaleMac.mm 2012-07-10 02:16:27 UTC (rev 122184)
@@ -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 @@
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 @@
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 @@
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
-
}
Modified: trunk/Source/WebCore/platform/text/mac/LocalizedDateMac.cpp (122183 => 122184)
--- trunk/Source/WebCore/platform/text/mac/LocalizedDateMac.cpp 2012-07-10 02:14:10 UTC (rev 122183)
+++ trunk/Source/WebCore/platform/text/mac/LocalizedDateMac.cpp 2012-07-10 02:16:27 UTC (rev 122184)
@@ -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 @@
{
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 @@
{
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 @@
#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
Deleted: trunk/Source/WebCore/platform/text/mac/LocalizedDateMac.mm (122183 => 122184)
--- trunk/Source/WebCore/platform/text/mac/LocalizedDateMac.mm 2012-07-10 02:14:10 UTC (rev 122183)
+++ trunk/Source/WebCore/platform/text/mac/LocalizedDateMac.mm 2012-07-10 02:16:27 UTC (rev 122184)
@@ -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
-
-}
Modified: trunk/Source/WebKit/chromium/ChangeLog (122183 => 122184)
--- trunk/Source/WebKit/chromium/ChangeLog 2012-07-10 02:14:10 UTC (rev 122183)
+++ trunk/Source/WebKit/chromium/ChangeLog 2012-07-10 02:16:27 UTC (rev 122184)
@@ -1,3 +1,25 @@
+2012-07-09 Yoshifumi Inoue <[email protected]>
+
+ [Platform] Introduce LocaleMac class
+ https://bugs.webkit.org/show_bug.cgi?id=90248
+
+ Reviewed by Kent Tamura.
+
+ 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 Dana Jansens <[email protected]>
[chromium] Create CCScopedTexture class for creating/freeing textures
Modified: trunk/Source/WebKit/chromium/WebKit.gypi (122183 => 122184)
--- trunk/Source/WebKit/chromium/WebKit.gypi 2012-07-10 02:14:10 UTC (rev 122183)
+++ trunk/Source/WebKit/chromium/WebKit.gypi 2012-07-10 02:16:27 UTC (rev 122184)
@@ -181,6 +181,11 @@
'tests/WebPageSerializerTest.cpp',
],
}],
+ ['OS=="mac"', {
+ 'webkit_unittest_files': [
+ 'tests/LocaleMacTest.cpp',
+ ],
+ }],
['OS!="mac"', {
'webkit_unittest_files': [
# Mac uses ScrollAnimatorMac instead of ScrollAnimatorNone.
Added: trunk/Source/WebKit/chromium/tests/LocaleMacTest.cpp (0 => 122184)
--- trunk/Source/WebKit/chromium/tests/LocaleMacTest.cpp (rev 0)
+++ trunk/Source/WebKit/chromium/tests/LocaleMacTest.cpp 2012-07-10 02:16:27 UTC (rev 122184)
@@ -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
Property changes on: trunk/Source/WebKit/chromium/tests/LocaleMacTest.cpp
___________________________________________________________________
Added: svn:eol-style