Changeset 122190 in webkit
- Timestamp:
- Jul 9, 2012 9:31:39 PM (12 years ago)
- Location:
- trunk/Source
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r122189 r122190 1 2012-07-09 Yoshifumi Inoue <yosin@chromium.org> 2 3 [Chromium-Mac] Implement functions for localized time format information 4 https://bugs.webkit.org/show_bug.cgi?id=90237 5 6 Reviewed by Kent Tamura. 7 8 This patch introduces following localized time format related 9 functions: 10 - localizeTimeFormatText() 11 - localizeShortTimeFormatText() 12 - timeAMPMLabels 13 for Mac OSX in feature flag: ENABLE_INPUT_TYPE_TIME_MULTIPLE_FIELDS. 14 15 These function will be used by input type "time" with multiple input 16 fields UI. 17 18 Note: ICU version of localized time format functions are implemented 19 in https://bugs.webkit.org/show_bug.cgi?id=89965 20 21 Tests: WebKit/chromium/tests/LocaleMacTest.cpp 22 23 * platform/text/mac/LocaleMac.h: 24 (LocaleMac): Added time format related functions and variables. 25 * platform/text/mac/LocaleMac.mm: 26 (WebCore::createDateTimeFormatter): Added. A helper function for creating date time formatter. 27 (WebCore::LocaleMac::createShortDateFormatter): Changed to use createDateTimeFormatter. 28 (WebCore::LocaleMac::createTimeFormatter): Added. 29 (WebCore::LocaleMac::createShortTimeFormatter): Added. 30 (WebCore::LocaleMac::timeFormatText): Added. 31 (WebCore::LocaleMac::shortTimeFormatText): Added. 32 (WebCore::LocaleMac::timeAMPMLabels): Added. 33 1 34 2012-07-09 Alexandru Chiculita <achicu@adobe.com> 2 35 -
trunk/Source/WebCore/platform/text/mac/LocaleMac.h
r122184 r122190 59 59 #endif 60 60 61 #if ENABLE(INPUT_TYPE_TIME_MULTIPLE_FIELDS) 62 String timeFormatText(); 63 String shortTimeFormatText(); 64 const Vector<String>& timeAMPMLabels(); 65 #endif 66 61 67 private: 62 68 explicit LocaleMac(const String&); … … 69 75 Vector<String> m_weekDayShortLabels; 70 76 #endif 77 #if ENABLE(INPUT_TYPE_TIME_MULTIPLE_FIELDS) 78 NSDateFormatter *createTimeFormatter(); 79 NSDateFormatter *createShortTimeFormatter(); 80 81 String m_localizedTimeFormatText; 82 String m_localizedShortTimeFormatText; 83 Vector<String> m_timeAMPMLabels; 84 #endif 71 85 }; 72 86 -
trunk/Source/WebCore/platform/text/mac/LocaleMac.mm
r122184 r122190 45 45 namespace WebCore { 46 46 47 LocaleMac::LocaleMac(const String& localeIdentifier) 48 : m_locale([[NSLocale alloc] initWithLocaleIdentifier:localeIdentifier]) 49 { 50 } 51 52 LocaleMac::~LocaleMac() 53 { 54 } 55 56 PassOwnPtr<LocaleMac> LocaleMac::create(const String& localeIdentifier) 57 { 58 return adoptPtr(new LocaleMac(localeIdentifier)); 59 } 60 61 LocaleMac* LocaleMac::currentLocale() 62 { 63 static LocaleMac* currentLocale = LocaleMac::create([NSLocale currentLocale]).leakPtr(); 64 return currentLocale; 65 } 66 67 NSDateFormatter* LocaleMac::createShortDateFormatter() 47 static NSDateFormatter* createDateTimeFormatter(NSLocale* locale, NSDateFormatterStyle dateStyle, NSDateFormatterStyle timeStyle) 68 48 { 69 49 NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; 70 [formatter setLocale: m_locale.get()];71 [formatter setDateStyle: NSDateFormatterShortStyle];72 [formatter setTimeStyle: NSDateFormatterNoStyle];50 [formatter setLocale:locale]; 51 [formatter setDateStyle:dateStyle]; 52 [formatter setTimeStyle:timeStyle]; 73 53 [formatter setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"UTC"]]; 74 54 [formatter setCalendar:[[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]]; 75 55 return formatter; 56 } 57 58 LocaleMac::LocaleMac(const String& localeIdentifier) 59 : m_locale([[NSLocale alloc] initWithLocaleIdentifier:localeIdentifier]) 60 { 61 } 62 63 LocaleMac::~LocaleMac() 64 { 65 } 66 67 PassOwnPtr<LocaleMac> LocaleMac::create(const String& localeIdentifier) 68 { 69 return adoptPtr(new LocaleMac(localeIdentifier)); 70 } 71 72 LocaleMac* LocaleMac::currentLocale() 73 { 74 static LocaleMac* currentLocale = LocaleMac::create([NSLocale currentLocale]).leakPtr(); 75 return currentLocale; 76 } 77 78 NSDateFormatter* LocaleMac::createShortDateFormatter() 79 { 80 return createDateTimeFormatter(m_locale.get(), NSDateFormatterShortStyle, NSDateFormatterNoStyle); 76 81 } 77 82 … … 195 200 } 196 201 #endif 197 } 202 203 #if ENABLE(INPUT_TYPE_TIME_MULTIPLE_FIELDS) 204 NSDateFormatter* LocaleMac::createTimeFormatter() 205 { 206 return createDateTimeFormatter(m_locale.get(), NSDateFormatterNoStyle, NSDateFormatterMediumStyle); 207 } 208 209 NSDateFormatter* LocaleMac::createShortTimeFormatter() 210 { 211 return createDateTimeFormatter(m_locale.get(), NSDateFormatterNoStyle, NSDateFormatterShortStyle); 212 } 213 214 String LocaleMac::timeFormatText() 215 { 216 if (!m_localizedTimeFormatText.isEmpty()) 217 return m_localizedTimeFormatText; 218 RetainPtr<NSDateFormatter> formatter(AdoptNS, createTimeFormatter()); 219 m_localizedTimeFormatText = String([formatter.get() dateFormat]); 220 return m_localizedTimeFormatText; 221 } 222 223 String LocaleMac::shortTimeFormatText() 224 { 225 if (!m_localizedShortTimeFormatText.isEmpty()) 226 return m_localizedShortTimeFormatText; 227 RetainPtr<NSDateFormatter> formatter(AdoptNS, createShortTimeFormatter()); 228 m_localizedShortTimeFormatText = String([formatter.get() dateFormat]); 229 return m_localizedShortTimeFormatText; 230 } 231 232 const Vector<String>& LocaleMac::timeAMPMLabels() 233 { 234 if (!m_timeAMPMLabels.isEmpty()) 235 return m_timeAMPMLabels; 236 m_timeAMPMLabels.reserveCapacity(2); 237 RetainPtr<NSDateFormatter> formatter(AdoptNS, createShortTimeFormatter()); 238 m_timeAMPMLabels.append(String([formatter.get() AMSymbol])); 239 m_timeAMPMLabels.append(String([formatter.get() PMSymbol])); 240 return m_timeAMPMLabels; 241 } 242 #endif 243 } -
trunk/Source/WebKit/chromium/ChangeLog
r122185 r122190 1 2012-07-09 Yoshifumi Inoue <yosin@chromium.org> 2 3 [Chromium-Mac] Implement functions for localized time format information 4 https://bugs.webkit.org/show_bug.cgi?id=90237 5 6 Reviewed by Kent Tamura. 7 8 * tests/LocaleMacTest.cpp: 9 (LocaleMacTest): 10 (LocaleMacTest::timeFormatText): 11 (LocaleMacTest::shortTimeFormatText): 12 (LocaleMacTest::timeAMPMLabel): 13 (TEST_F): 14 1 15 2012-07-09 Eric Penner <epenner@google.com> 2 16 -
trunk/Source/WebKit/chromium/tests/LocaleMacTest.cpp
r122184 r122190 100 100 } 101 101 #endif 102 103 #if ENABLE(INPUT_TYPE_TIME_MULTIPLE_FIELDS) 104 String timeFormatText(const String& localeString) 105 { 106 OwnPtr<LocaleMac> locale = LocaleMac::create(localeString); 107 return locale->timeFormatText(); 108 } 109 110 String shortTimeFormatText(const String& localeString) 111 { 112 OwnPtr<LocaleMac> locale = LocaleMac::create(localeString); 113 return locale->shortTimeFormatText(); 114 } 115 116 String timeAMPMLabel(const String& localeString, unsigned index) 117 { 118 OwnPtr<LocaleMac> locale = LocaleMac::create(localeString); 119 return locale->timeAMPMLabels()[index]; 120 } 121 #endif 102 122 }; 103 123 … … 161 181 } 162 182 #endif 183 184 #if ENABLE(INPUT_TYPE_TIME_MULTIPLE_FIELDS) 185 TEST_F(LocaleMacTest, timeFormatText) 186 { 187 EXPECT_STREQ("h:mm:ss a", timeFormatText("en_US").utf8().data()); 188 EXPECT_STREQ("HH:mm:ss", timeFormatText("fr_FR").utf8().data()); 189 EXPECT_STREQ("H:mm:ss", timeFormatText("ja_JP").utf8().data()); 190 } 191 192 TEST_F(LocaleMacTest, shortTimeFormatText) 193 { 194 EXPECT_STREQ("h:mm a", shortTimeFormatText("en_US").utf8().data()); 195 EXPECT_STREQ("HH:mm", shortTimeFormatText("fr_FR").utf8().data()); 196 EXPECT_STREQ("H:mm", shortTimeFormatText("ja_JP").utf8().data()); 197 } 198 199 TEST_F(LocaleMacTest, timeAMPMLabels) 200 { 201 EXPECT_STREQ("AM", timeAMPMLabel("en_US", 0).utf8().data()); 202 EXPECT_STREQ("PM", timeAMPMLabel("en_US", 1).utf8().data()); 203 204 EXPECT_STREQ("AM", timeAMPMLabel("fr_FR", 0).utf8().data()); 205 EXPECT_STREQ("PM", timeAMPMLabel("fr_FR", 1).utf8().data()); 206 207 EXPECT_STREQ("\xE5\x8D\x88\xE5\x89\x8D", timeAMPMLabel("ja_JP", 0).utf8().data()); 208 EXPECT_STREQ("\xE5\x8D\x88\xE5\xBE\x8C", timeAMPMLabel("ja_JP", 1).utf8().data()); 209 } 210 #endif
Note: See TracChangeset
for help on using the changeset viewer.