Diff
Modified: trunk/Source/WebCore/ChangeLog (122090 => 122091)
--- trunk/Source/WebCore/ChangeLog 2012-07-09 06:19:54 UTC (rev 122090)
+++ trunk/Source/WebCore/ChangeLog 2012-07-09 06:30:27 UTC (rev 122091)
@@ -1,3 +1,24 @@
+2012-07-08 Yoshifumi Inoue <[email protected]>
+
+ [Platform-Mac] Derive LocaleMac.{cpp,h} and LocalizedDateMac.cpp from LocaleWin
+ https://bugs.webkit.org/show_bug.cgi?id=90752
+
+ Reviewed by Kent Tamura.
+
+ This patch is preparation of introducing LocaleMac class for localize date form.
+ This patch copies LocaleWin and LocalizedDateWin.cpp as below:
+ - LocaleMac.h from LocaleWin.h
+ - LocaleMac.mm from LocaliedDateMac.mm
+ - LocaliedDateMac.cpp from LocalizedDateWin.cpp
+
+ Due by git, diffs are appeared as new thing. I'll do svn copy at landing time.
+
+ No new tests. This patch doesn't change behavior.
+
+ * platform/text/mac/LocaleMac.h: Copied from platform/text/LocaleWin.h
+ * platform/text/mac/LocaleMac.mm: Copied from platform/text/mac/LocalizedDateMac.mm
+ * platform/text/mac/LocalizedDateMac.cpp: Copied from platform/text/LocalizedDateWin.cpp
+
2012-07-08 Laszlo Gombos <[email protected]>
Introduce a build flag for low quality JPEG images
Copied: trunk/Source/WebCore/platform/text/mac/LocaleMac.h (from rev 122090, trunk/Source/WebCore/platform/text/LocaleWin.h) (0 => 122091)
--- trunk/Source/WebCore/platform/text/mac/LocaleMac.h (rev 0)
+++ trunk/Source/WebCore/platform/text/mac/LocaleMac.h 2012-07-09 06:30:27 UTC (rev 122091)
@@ -0,0 +1,88 @@
+/*
+ * 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.
+ */
+
+#ifndef LocaleWin_h
+#define LocaleWin_h
+
+#include <windows.h>
+#include <wtf/Forward.h>
+#include <wtf/Vector.h>
+
+namespace WebCore {
+
+class DateComponents;
+struct DateFormatToken;
+
+class LocaleWin {
+public:
+ static PassOwnPtr<LocaleWin> create(LCID);
+ static LocaleWin* currentLocale();
+ ~LocaleWin();
+ 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; }
+#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
+
+ LCID m_lcid;
+ int m_baseYear;
+ Vector<DateFormatToken> m_shortDateTokens;
+ Vector<String> m_shortMonthLabels;
+ Vector<String> m_monthLabels;
+#if ENABLE(CALENDAR_PICKER)
+ Vector<String> m_weekDayShortLabels;
+ unsigned m_firstDayOfWeek;
+#endif
+
+};
+
+}
+#endif
Copied: trunk/Source/WebCore/platform/text/mac/LocaleMac.mm (from rev 122090, trunk/Source/WebCore/platform/text/mac/LocalizedDateMac.mm) (0 => 122091)
--- trunk/Source/WebCore/platform/text/mac/LocaleMac.mm (rev 0)
+++ trunk/Source/WebCore/platform/text/mac/LocaleMac.mm 2012-07-09 06:30:27 UTC (rev 122091)
@@ -0,0 +1,201 @@
+/*
+ * 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
+
+}
Copied: trunk/Source/WebCore/platform/text/mac/LocalizedDateMac.cpp (from rev 122090, trunk/Source/WebCore/platform/text/LocalizedDateWin.cpp) (0 => 122091)
--- trunk/Source/WebCore/platform/text/mac/LocalizedDateMac.cpp (rev 0)
+++ trunk/Source/WebCore/platform/text/mac/LocalizedDateMac.cpp 2012-07-09 06:30:27 UTC (rev 122091)
@@ -0,0 +1,95 @@
+/*
+ * 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 "LocaleWin.h"
+#include <limits>
+
+using namespace std;
+
+namespace WebCore {
+
+double parseLocalizedDate(const String& input, DateComponents::Type type)
+{
+ switch (type) {
+ case DateComponents::Date:
+ return LocaleWin::currentLocale()->parseDate(input);
+ 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:
+ return LocaleWin::currentLocale()->formatDate(dateComponents);
+ 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)
+String localizedDateFormatText()
+{
+ return LocaleWin::currentLocale()->dateFormatText();
+}
+
+const Vector<String>& monthLabels()
+{
+ return LocaleWin::currentLocale()->monthLabels();
+}
+
+const Vector<String>& weekDayShortLabels()
+{
+ return LocaleWin::currentLocale()->weekDayShortLabels();
+}
+
+unsigned firstDayOfWeek()
+{
+ return LocaleWin::currentLocale()->firstDayOfWeek();
+}
+#endif
+
+}