Source/WebCore/ChangeLog

 12012-06-26 Yoshifumi Inoue <yosin@chromium.org>
 2
 3 [Platform][DateTime][ICU] Change implementation of LocaleICU class to support more DateFormat.
 4 https://bugs.webkit.org/show_bug.cgi?id=89967
 5
 6 Reviewed by NOBODY (OOPS!).
 7
 8 This patch changes internal functions of LocalICU class to process
 9 multiple ICU date time format handles in addition to short date time
 10 format handle.
 11
 12 This patch is a part of implementing input type time. I'll add time
 13 format related ICU date time format handles.
 14
 15 No new tests. This patch doesn't change behavior.
 16
 17 * platform/text/LocaleICU.cpp:
 18 (WebCore::LocaleICU::initializeShortDateFormat): Changed to use openDateFormat().
 19 (WebCore::LocaleICU::openDateFormat): Added for common usage of udt_open().
 20 (WebCore::getDateFormatPattern): Added for common usage of udt_toPattern().
 21 (WebCore::localizeFormat): Changed to take String parameter.
 22 (WebCore::LocaleICU::initializeLocalizedDateFormatText): Changed to use getDateFormatPattern.
 23 (WebCore::LocaleICU::createLabelVector): Changed to take UDateFormat parameter.
 24 (WebCore::LocaleICU::initializeCalendar): Changed for helper functions.
 25 * platform/text/LocaleICU.h:
 26 (LocaleICU):
 27
1282012-06-26 Kevin Ellis <kevers@chromium.org>
229
330 Touch adjustment does not target shadow DOM elements

Source/WebCore/platform/text/LocaleICU.cpp

@@bool LocaleICU::initializeShortDateFormat()
272272{
273273 if (m_didCreateShortDateFormat)
274274 return m_shortDateFormat;
275  const UChar gmtTimezone[3] = {'G', 'M', 'T'};
276  UErrorCode status = U_ZERO_ERROR;
277  m_shortDateFormat = udat_open(UDAT_NONE, UDAT_SHORT, m_locale.data(), gmtTimezone, WTF_ARRAY_LENGTH(gmtTimezone), 0, -1, &status);
 275 m_shortDateFormat = openDateFormat(UDAT_NONE, UDAT_SHORT);
278276 m_didCreateShortDateFormat = true;
279277 return m_shortDateFormat;
280278}
281279
 280UDateFormat* LocaleICU::openDateFormat(UDateFormatStyle timeStyle, UDateFormatStyle dateStyle) const
 281{
 282 const UChar gmtTimezone[3] = {'G', 'M', 'T'};
 283 UErrorCode status = U_ZERO_ERROR;
 284 return udat_open(timeStyle, dateStyle, m_locale.data(), gmtTimezone, WTF_ARRAY_LENGTH(gmtTimezone), 0, -1, &status);
 285}
 286
282287double LocaleICU::parseLocalizedDate(const String& input)
283288{
284289 if (!initializeShortDateFormat())

@@String LocaleICU::formatLocalizedDate(const DateComponents& dateComponents)
313318}
314319
315320#if ENABLE(CALENDAR_PICKER)
 321static String getDateFormatPattern(const UDateFormat* dateFormat)
 322{
 323 if (!dateFormat)
 324 return emptyString();
 325
 326 UErrorCode status = U_ZERO_ERROR;
 327 int32_t length = udat_toPattern(dateFormat, TRUE, 0, 0, &status);
 328 if (status != U_BUFFER_OVERFLOW_ERROR || !length)
 329 return emptyString();
 330 Vector<UChar> buffer(length);
 331 status = U_ZERO_ERROR;
 332 udat_toPattern(dateFormat, TRUE, buffer.data(), length, &status);
 333 if (U_FAILURE(status))
 334 return emptyString();
 335 return String::adopt(buffer);
 336}
 337
316338static inline bool isICUYearSymbol(UChar letter)
317339{
318340 return letter == 'y' || letter == 'Y';

@@static inline bool isICUDayInMonthSymbol(UChar letter)
330352
331353// Specification of the input:
332354// http://icu-project.org/apiref/icu4c/classSimpleDateFormat.html#details
333 static String localizeFormat(const Vector<UChar>& buffer)
 355static String localizeFormat(const String& buffer)
334356{
335357 StringBuilder builder;
336358 UChar lastChar = 0;
337359 bool inQuote = false;
338  for (unsigned i = 0; i < buffer.size(); ++i) {
 360 for (unsigned i = 0; i < buffer.length(); ++i) {
339361 if (inQuote) {
340362 if (buffer[i] == '\'') {
341363 inQuote = false;

@@void LocaleICU::initializeLocalizedDateFormatText()
374396 m_localizedDateFormatText = emptyString();
375397 if (!initializeShortDateFormat())
376398 return;
377  UErrorCode status = U_ZERO_ERROR;
378  int32_t length = udat_toPattern(m_shortDateFormat, TRUE, 0, 0, &status);
379  if (status != U_BUFFER_OVERFLOW_ERROR)
380  return;
381  Vector<UChar> buffer(length);
382  status = U_ZERO_ERROR;
383  udat_toPattern(m_shortDateFormat, TRUE, buffer.data(), length, &status);
384  if (U_FAILURE(status))
385  return;
386  m_localizedDateFormatText = localizeFormat(buffer);
 399 m_localizedDateFormatText = localizeFormat(getDateFormatPattern(m_shortDateFormat));
387400}
388401
389402String LocaleICU::localizedDateFormatText()

@@String LocaleICU::localizedDateFormatText()
392405 return m_localizedDateFormatText;
393406}
394407
395 PassOwnPtr<Vector<String> > LocaleICU::createLabelVector(UDateFormatSymbolType type, int32_t startIndex, int32_t size)
 408PassOwnPtr<Vector<String> > LocaleICU::createLabelVector(const UDateFormat* dateFormat, UDateFormatSymbolType type, int32_t startIndex, int32_t size)
396409{
397  if (!m_shortDateFormat)
 410 if (!dateFormat)
398411 return PassOwnPtr<Vector<String> >();
399  if (udat_countSymbols(m_shortDateFormat, type) != startIndex + size)
 412 if (udat_countSymbols(dateFormat, type) != startIndex + size)
400413 return PassOwnPtr<Vector<String> >();
401414
402415 OwnPtr<Vector<String> > labels = adoptPtr(new Vector<String>());
403416 labels->reserveCapacity(size);
404417 for (int32_t i = 0; i < size; ++i) {
405418 UErrorCode status = U_ZERO_ERROR;
406  int32_t length = udat_getSymbols(m_shortDateFormat, type, startIndex + i, 0, 0, &status);
 419 int32_t length = udat_getSymbols(dateFormat, type, startIndex + i, 0, 0, &status);
407420 if (status != U_BUFFER_OVERFLOW_ERROR)
408421 return PassOwnPtr<Vector<String> >();
409422 Vector<UChar> buffer(length);
410423 status = U_ZERO_ERROR;
411  udat_getSymbols(m_shortDateFormat, type, startIndex + i, buffer.data(), length, &status);
 424 udat_getSymbols(dateFormat, type, startIndex + i, buffer.data(), length, &status);
412425 if (U_FAILURE(status))
413426 return PassOwnPtr<Vector<String> >();
414427 labels->append(String::adopt(buffer));

@@void LocaleICU::initializeCalendar()
452465 }
453466 m_firstDayOfWeek = ucal_getAttribute(udat_getCalendar(m_shortDateFormat), UCAL_FIRST_DAY_OF_WEEK) - UCAL_SUNDAY;
454467
455  m_monthLabels = createLabelVector(UDAT_MONTHS, UCAL_JANUARY, 12);
 468 m_monthLabels = createLabelVector(m_shortDateFormat, UDAT_MONTHS, UCAL_JANUARY, 12);
456469 if (!m_monthLabels)
457470 m_monthLabels = createFallbackMonthLabels();
458471
459  m_weekDayShortLabels = createLabelVector(UDAT_SHORT_WEEKDAYS, UCAL_SUNDAY, 7);
 472 m_weekDayShortLabels = createLabelVector(m_shortDateFormat, UDAT_SHORT_WEEKDAYS, UCAL_SUNDAY, 7);
460473 if (!m_weekDayShortLabels)
461474 m_weekDayShortLabels = createFallbackWeekDayShortLabels();
462475}

Source/WebCore/platform/text/LocaleICU.h

@@private:
7575 unsigned matchedDecimalSymbolIndex(const String& input, unsigned& position);
7676
7777 bool initializeShortDateFormat();
 78 UDateFormat* openDateFormat(UDateFormatStyle timeStyle, UDateFormatStyle dateStyle) const;
7879
7980#if ENABLE(CALENDAR_PICKER)
8081 void initializeLocalizedDateFormatText();
81  PassOwnPtr<Vector<String> > createLabelVector(UDateFormatSymbolType, int32_t startIndex, int32_t size);
 82 PassOwnPtr<Vector<String> > createLabelVector(const UDateFormat*, UDateFormatSymbolType, int32_t startIndex, int32_t size);
8283 void initializeCalendar();
8384#endif
8485