Diff
Modified: trunk/Source/WebCore/ChangeLog (124734 => 124735)
--- trunk/Source/WebCore/ChangeLog 2012-08-06 06:35:32 UTC (rev 124734)
+++ trunk/Source/WebCore/ChangeLog 2012-08-06 06:39:49 UTC (rev 124735)
@@ -1,3 +1,36 @@
+2012-08-05 Kent Tamura <[email protected]>
+
+ [Chromium-win] Use system locale for number representation
+ https://bugs.webkit.org/show_bug.cgi?id=93085
+
+ Reviewed by Hajime Morita.
+
+ We have used LocaleICU for number localization (presentation of <input
+ type=number>) even on Windows. This patch introduces number localization
+ feature with Windows API to LocaleWin, and we stop using LocaleICU on
+ Windows.
+
+ Tests: Add new test cases to WebKit/chromium/tests/LocaleWinTest.cpp.
+
+ * WebCore.gyp/WebCore.gyp:
+ - Stop using LocaleICU.{cpp,h} and LocalizedNumberICU.cpp.
+ - Add LocalizedNumberWin.cpp.
+ * platform/text/LocaleWin.cpp:
+ (WebCore::LocaleWin::LocaleWin):
+ - Initialize m_didInitializeNumberData.
+ - Use getLocaleInfo() to obtain LOCALE_IFIRSTDAYOFWEEK.
+ (WebCore::LocaleWin::getLocaleInfo):
+ Added. A helper to obtain integer locale value.
+ (WebCore::LocaleWin::initializeNumberLocalizerData):
+ Added. Prepare data for number localization, and pass it to NumberLocalizer.
+ * platform/text/LocaleWin.h:
+ (LocaleWin): Inherit NumberLocalizer, and declare some new members.
+ * platform/text/win/LocalizedNumberWin.cpp: Added.
+ (WebCore::convertToLocalizedNumber):
+ Forward to the corresponding function of LocaleWin.
+ (WebCore::convertFromLocalizedNumber): ditto.
+ (WebCore::localizedDecimalSeparator): ditto.
+
2012-08-05 Philip Rogers <[email protected]>
Fix assertion during detach of SVG wrappers without baseVal
Modified: trunk/Source/WebCore/WebCore.gyp/WebCore.gyp (124734 => 124735)
--- trunk/Source/WebCore/WebCore.gyp/WebCore.gyp 2012-08-06 06:35:32 UTC (rev 124734)
+++ trunk/Source/WebCore/WebCore.gyp/WebCore.gyp 2012-08-06 06:39:49 UTC (rev 124735)
@@ -1794,10 +1794,14 @@
# SystemInfo.cpp is useful and we don't want to copy it.
['include', 'platform/win/SystemInfo\\.cpp$'],
+ ['exclude', 'platform/text/LocaleICU\\.cpp$'],
+ ['exclude', 'platform/text/LocaleICU\\.h$'],
['exclude', 'platform/text/LocalizedDateICU\.cpp$'],
+ ['exclude', 'platform/text/LocalizedNumberICU\.cpp$'],
['include', 'platform/text/LocalizedDateWin\.cpp$'],
['include', 'platform/text/LocaleWin\.cpp$'],
['include', 'platform/text/LocaleWin\.h$'],
+ ['include', 'platform/text/win/LocalizedNumberWin\\.cpp$'],
],
},{ # OS!="win"
'sources/': [
Modified: trunk/Source/WebCore/WebCore.gypi (124734 => 124735)
--- trunk/Source/WebCore/WebCore.gypi 2012-08-06 06:35:32 UTC (rev 124734)
+++ trunk/Source/WebCore/WebCore.gypi 2012-08-06 06:39:49 UTC (rev 124735)
@@ -4485,6 +4485,7 @@
'platform/text/qt/TextCodecQt.h',
'platform/text/transcoder/FontTranscoder.cpp',
'platform/text/transcoder/FontTranscoder.h',
+ 'platform/text/win/LocalizedNumberWin.cpp',
'platform/text/win/TextBreakIteratorInternalICUWin.cpp',
'platform/text/win/TextCodecWin.cpp',
'platform/text/win/TextCodecWin.h',
Modified: trunk/Source/WebCore/platform/text/LocaleWin.cpp (124734 => 124735)
--- trunk/Source/WebCore/platform/text/LocaleWin.cpp 2012-08-06 06:35:32 UTC (rev 124734)
+++ trunk/Source/WebCore/platform/text/LocaleWin.cpp 2012-08-06 06:39:49 UTC (rev 124735)
@@ -57,6 +57,7 @@
inline LocaleWin::LocaleWin(LCID lcid)
: m_lcid(lcid)
+ , m_didInitializeNumberData(false)
{
SYSTEMTIME systemTime;
GetLocalTime(&systemTime);
@@ -64,7 +65,7 @@
#if ENABLE(CALENDAR_PICKER)
DWORD value = 0;
- ::GetLocaleInfo(m_lcid, LOCALE_IFIRSTDAYOFWEEK | LOCALE_RETURN_NUMBER, reinterpret_cast<LPWSTR>(&value), sizeof(value) / sizeof(TCHAR));
+ getLocaleInfo(LOCALE_IFIRSTDAYOFWEEK, value);
// 0:Monday, ..., 6:Sunday.
// We need 1 for Monday, 0 for Sunday.
m_firstDayOfWeek = (value + 1) % 7;
@@ -118,6 +119,11 @@
return String::adopt(buffer);
}
+void LocaleWin::getLocaleInfo(LCTYPE type, DWORD& result)
+{
+ ::GetLocaleInfo(m_lcid, type | LOCALE_RETURN_NUMBER, reinterpret_cast<LPWSTR>(&result), sizeof(DWORD) / sizeof(TCHAR));
+}
+
void LocaleWin::ensureShortMonthLabels()
{
if (!m_shortMonthLabels.isEmpty())
@@ -690,4 +696,75 @@
}
#endif
+void LocaleWin::initializeNumberLocalizerData()
+{
+ if (m_didInitializeNumberData)
+ return;
+
+ Vector<String, DecimalSymbolsSize> symbols;
+ enum DigitSubstitution {
+ DigitSubstitutionContext = 0,
+ DigitSubstitution0to9 = 1,
+ DigitSubstitutionNative = 2,
+ };
+ DWORD digitSubstitution = DigitSubstitution0to9;
+ getLocaleInfo(LOCALE_IDIGITSUBSTITUTION, digitSubstitution);
+ if (digitSubstitution != DigitSubstitutionNative) {
+ symbols.append("0");
+ symbols.append("1");
+ symbols.append("2");
+ symbols.append("3");
+ symbols.append("4");
+ symbols.append("5");
+ symbols.append("6");
+ symbols.append("7");
+ symbols.append("8");
+ symbols.append("9");
+ } else {
+ String digits = getLocaleInfoString(LOCALE_SNATIVEDIGITS);
+ ASSERT(digits.length() >= 10);
+ for (unsigned i = 0; i < 10; ++i)
+ symbols.append(digits.substring(i, 1));
+ }
+ ASSERT(symbols.size() == DecimalSeparatorIndex);
+ symbols.append(getLocaleInfoString(LOCALE_SDECIMAL));
+ ASSERT(symbols.size() == GroupSeparatorIndex);
+ symbols.append(getLocaleInfoString(LOCALE_STHOUSAND));
+ ASSERT(symbols.size() == DecimalSymbolsSize);
+
+ String negativeSign = getLocaleInfoString(LOCALE_SNEGATIVESIGN);
+ enum NegativeFormat {
+ NegativeFormatParenthesis = 0,
+ NegativeFormatSignPrefix = 1,
+ NegativeFormatSignSpacePrefix = 2,
+ NegativeFormatSignSuffix = 3,
+ NegativeFormatSpaceSignSuffix = 4,
+ };
+ DWORD negativeFormat = NegativeFormatSignPrefix;
+ getLocaleInfo(LOCALE_INEGNUMBER, negativeFormat);
+ String negativePrefix = emptyString();
+ String negativeSuffix = emptyString();
+ switch (negativeFormat) {
+ case NegativeFormatParenthesis:
+ negativePrefix = "(";
+ negativeSuffix = ")";
+ break;
+ case NegativeFormatSignSpacePrefix:
+ negativePrefix = negativeSign + " ";
+ break;
+ case NegativeFormatSignSuffix:
+ negativeSuffix = negativeSign;
+ break;
+ case NegativeFormatSpaceSignSuffix:
+ negativeSuffix = " " + negativeSign;
+ break;
+ case NegativeFormatSignPrefix: // Fall through.
+ default:
+ negativePrefix = negativeSign;
+ break;
+ }
+ m_didInitializeNumberData = true;
+ setNumberLocalizerData(symbols, emptyString(), emptyString(), negativePrefix, negativeSuffix);
}
+
+}
Modified: trunk/Source/WebCore/platform/text/LocaleWin.h (124734 => 124735)
--- trunk/Source/WebCore/platform/text/LocaleWin.h 2012-08-06 06:35:32 UTC (rev 124734)
+++ trunk/Source/WebCore/platform/text/LocaleWin.h 2012-08-06 06:39:49 UTC (rev 124735)
@@ -31,6 +31,7 @@
#ifndef LocaleWin_h
#define LocaleWin_h
+#include "NumberLocalizer.h"
#include <windows.h>
#include <wtf/Forward.h>
#include <wtf/Vector.h>
@@ -41,7 +42,7 @@
class DateComponents;
struct DateFormatToken;
-class LocaleWin {
+class LocaleWin : public NumberLocalizer {
public:
static PassOwnPtr<LocaleWin> create(LCID);
static LocaleWin* currentLocale();
@@ -69,6 +70,7 @@
private:
explicit LocaleWin(LCID);
String getLocaleInfoString(LCTYPE);
+ void getLocaleInfo(LCTYPE, DWORD&);
void ensureShortMonthLabels();
void ensureMonthLabels();
void ensureShortDateTokens();
@@ -78,6 +80,8 @@
#if ENABLE(CALENDAR_PICKER)
void ensureWeekDayShortLabels();
#endif
+ // NumberLocalizer function:
+ virtual void initializeNumberLocalizerData() OVERRIDE;
LCID m_lcid;
int m_baseYear;
@@ -92,6 +96,7 @@
String m_timeFormatText;
Vector<String> m_timeAMPMLabels;
#endif
+ bool m_didInitializeNumberData;
};
} // namespace WebCore
Added: trunk/Source/WebCore/platform/text/win/LocalizedNumberWin.cpp (0 => 124735)
--- trunk/Source/WebCore/platform/text/win/LocalizedNumberWin.cpp (rev 0)
+++ trunk/Source/WebCore/platform/text/win/LocalizedNumberWin.cpp 2012-08-06 06:39:49 UTC (rev 124735)
@@ -0,0 +1,49 @@
+/*
+ * 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 "LocalizedNumber.h"
+
+#include "LocaleWin.h"
+
+namespace WebCore {
+
+String convertToLocalizedNumber(const String& canonicalNumberString, unsigned fractionDigits)
+{
+ return LocaleWin::currentLocale()->convertToLocalizedNumber(canonicalNumberString);
+}
+
+String convertFromLocalizedNumber(const String& localizedNumberString)
+{
+ return LocaleWin::currentLocale()->convertFromLocalizedNumber(localizedNumberString);
+}
+
+#if ENABLE(INPUT_TYPE_TIME_MULTIPLE_FIELDS)
+String localizedDecimalSeparator()
+{
+ return LocaleWin::currentLocale()->localizedDecimalSeparator();
+}
+#endif
+} // namespace WebCore
Property changes on: trunk/Source/WebCore/platform/text/win/LocalizedNumberWin.cpp
___________________________________________________________________
Added: svn:eol-style
Modified: trunk/Source/WebKit/chromium/ChangeLog (124734 => 124735)
--- trunk/Source/WebKit/chromium/ChangeLog 2012-08-06 06:35:32 UTC (rev 124734)
+++ trunk/Source/WebKit/chromium/ChangeLog 2012-08-06 06:39:49 UTC (rev 124735)
@@ -1,3 +1,27 @@
+2012-08-05 Kent Tamura <[email protected]>
+
+ [Chromium-win] Use system locale for number representation
+ https://bugs.webkit.org/show_bug.cgi?id=93085
+
+ Reviewed by Hajime Morita.
+
+ * WebKit.gypi:
+ Don't include Localized*ICUTest.cpp in Windows and OSX. They are unnecessary.
+ * tests/LocaleWinTest.cpp:
+ (LocaleWinTest): Add some LCID symbols.
+ (LocaleWinTest::decimalSeparator):
+ A helper for LocaleWinTest.decimalSeparator.
+ (TEST_F(LocaleWinTest, decimalSeparator)):
+ A test for LocaleWin::localizedDecimalSeparator(). This is a copy of the
+ corresponding test in LocalizedNumberICUTest.cpp.
+ (testNumberIsReversible):
+ A test helper LocaleWinTest.localizedNumberRoundTrip. This is a copy of
+ the corresponding test in LocalizedNumberICUTest.cpp.
+ (testNumbers): ditto.
+ (TEST_F(LocaleWinTest, localizedNumberRoundTrip)):
+ Tests for LocaleWin changes. This is a copy of the corresponding tests
+ in LocalizedNumberICUTest.cpp.
+
2012-08-04 Sheriff Bot <[email protected]>
Unreviewed. Rolled DEPS.
Modified: trunk/Source/WebKit/chromium/WebKit.gypi (124734 => 124735)
--- trunk/Source/WebKit/chromium/WebKit.gypi 2012-08-06 06:35:32 UTC (rev 124734)
+++ trunk/Source/WebKit/chromium/WebKit.gypi 2012-08-06 06:39:49 UTC (rev 124735)
@@ -125,8 +125,6 @@
'tests/LevelDBTest.cpp',
'tests/LinkHighlightTest.cpp',
'tests/ListenerLeakTest.cpp',
- 'tests/LocalizedDateICUTest.cpp',
- 'tests/LocalizedNumberICUTest.cpp',
'tests/MemoryInfo.cpp',
'tests/MemoryInstrumentationTest.cpp',
'tests/MockCCQuadCuller.h',
@@ -195,6 +193,12 @@
'tests/ScrollAnimatorNoneTest.cpp',
],
}],
+ ['os_posix==1 and OS!="mac"', {
+ 'webkit_unittest_files': [
+ 'tests/LocalizedDateICUTest.cpp',
+ 'tests/LocalizedNumberICUTest.cpp',
+ ],
+ }],
['toolkit_uses_gtk == 1', {
'webkit_unittest_files': [
'tests/WebInputEventFactoryTestGtk.cpp',
Modified: trunk/Source/WebKit/chromium/tests/LocaleWinTest.cpp (124734 => 124735)
--- trunk/Source/WebKit/chromium/tests/LocaleWinTest.cpp 2012-08-06 06:35:32 UTC (rev 124734)
+++ trunk/Source/WebKit/chromium/tests/LocaleWinTest.cpp 2012-08-06 06:39:49 UTC (rev 124735)
@@ -57,10 +57,19 @@
};
// See http://msdn.microsoft.com/en-us/goglobal/bb964664.aspx
+ // Note that some locales are country-neutral.
enum {
- EnglishUS = 0x409,
- FrenchFR = 0x40C,
- JapaneseJP = 0x411,
+ ArabicEG = 0x0C01, // ar-eg
+ ChineseCN = 0x0804, // zh-cn
+ ChineseHK = 0x0C04, // zh-hk
+ ChineseTW = 0x0404, // zh-tw
+ German = 0x0407, // de
+ EnglishUS = 0x409, // en-us
+ FrenchFR = 0x40C, // fr
+ JapaneseJP = 0x411, // ja
+ KoreanKR = 0x0412, // ko
+ Persian = 0x0429, // fa
+ Spanish = 0x040A, // es
};
DateComponents dateComponents(int year, int month, int day)
@@ -131,6 +140,12 @@
OwnPtr<LocaleWin> locale = LocaleWin::create(lcid);
return locale->timeAMPMLabels()[index];
}
+
+ String decimalSeparator(LCID lcid)
+ {
+ OwnPtr<LocaleWin> locale = LocaleWin::create(lcid);
+ return locale->localizedDecimalSeparator();
+ }
#endif
};
@@ -328,4 +343,52 @@
EXPECT_STREQ("\xE5\x8D\x88\xE5\x89\x8D", timeAMPMLabel(JapaneseJP, 0).utf8().data());
EXPECT_STREQ("\xE5\x8D\x88\xE5\xBE\x8C", timeAMPMLabel(JapaneseJP, 1).utf8().data());
}
+
+TEST_F(LocaleWinTest, decimalSeparator)
+{
+ EXPECT_STREQ(".", decimalSeparator(EnglishUS).utf8().data());
+ EXPECT_STREQ(",", decimalSeparator(FrenchFR).utf8().data());
+}
#endif
+
+static void testNumberIsReversible(LCID lcid, const char* original, const char* shouldHave = 0)
+{
+ OwnPtr<LocaleWin> locale = LocaleWin::create(lcid);
+ String localized = locale->convertToLocalizedNumber(original);
+ if (shouldHave)
+ EXPECT_TRUE(localized.contains(shouldHave));
+ String converted = locale->convertFromLocalizedNumber(localized);
+ EXPECT_STREQ(original, converted.utf8().data());
+}
+
+void testNumbers(LCID lcid)
+{
+ testNumberIsReversible(lcid, "123456789012345678901234567890");
+ testNumberIsReversible(lcid, "-123.456");
+ testNumberIsReversible(lcid, ".456");
+ testNumberIsReversible(lcid, "-0.456");
+}
+
+TEST_F(LocaleWinTest, localizedNumberRoundTrip)
+{
+ testNumberIsReversible(EnglishUS, "123456789012345678901234567890");
+ testNumberIsReversible(EnglishUS, "-123.456", ".");
+ testNumberIsReversible(EnglishUS, ".456", ".");
+ testNumberIsReversible(EnglishUS, "-0.456", ".");
+
+ testNumberIsReversible(FrenchFR, "123456789012345678901234567890");
+ testNumberIsReversible(FrenchFR, "-123.456", ",");
+ testNumberIsReversible(FrenchFR, ".456", ",");
+ testNumberIsReversible(FrenchFR, "-0.456", ",");
+
+ // Test some of major locales.
+ testNumbers(ArabicEG);
+ testNumbers(German);
+ testNumbers(Spanish);
+ testNumbers(Persian);
+ testNumbers(JapaneseJP);
+ testNumbers(KoreanKR);
+ testNumbers(ChineseCN);
+ testNumbers(ChineseHK);
+ testNumbers(ChineseTW);
+}