Changeset 133134 in webkit
- Timestamp:
- Nov 1, 2012 12:31:58 AM (11 years ago)
- Location:
- trunk/Source
- Files:
-
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r133130 r133134 1 2012-11-01 Kent Tamura <tkent@chromium.org> 2 3 Remove unused Locale::parseDateTime 4 https://bugs.webkit.org/show_bug.cgi?id=100910 5 6 Reviewed by Kentaro Hara. 7 8 For date/time input types, InputType::convertFromVisibleValue is never 9 called. convertFromVisibleValue is called when an inner editable node is 10 updated. However input elements don't have such editable nodes if 11 ENABLE_INPUT_MULTIPLE_FIELDS_UI is enabled, and a user can't edit the 12 inner editable node otherwise because we open date/time pickers when a 13 user try to change the field value. 14 15 We had used convertFromVisibleValue for input[type=date] with an old UI. 16 17 No new tests because of no behavior changes. 18 19 * html/BaseDateAndTimeInputType.cpp: 20 (WebCore::BaseDateAndTimeInputType::convertFromVisibleValue): 21 Remove Locale::parseDateTiem and put ASSERT_NOT_REACHED. 22 23 * platform/text/PlatformLocale.h: Remove parseDateTime. 24 25 * platform/text/LocaleICU.h: Remove parseDateTime and a bogus comment. 26 * platform/text/LocaleICU.cpp: Remove parseDateTime. 27 28 * platform/text/LocaleNone.cpp: Remove parseDateTime. 29 30 * platform/text/mac/LocaleMac.h: Remove parseDateTime. 31 * platform/text/mac/LocaleMac.mm: Ditto. 32 * platform/text/win/LocaleWin.h: 33 - Remove parseDateTime, its helpers, and m_baseYear. 34 - Remove appendNumber, appendTwoDigitsNumber, appendFourDigitsNumber, 35 and formatDate. They don't exist. 36 * platform/text/win/LocaleWin.cpp: 37 Remove the above functions. 38 (WebCore::LocaleWin::LocaleWin): Remove m_baseYear iniitalization. 39 1 40 2012-10-31 Nate Chapin <japhet@chromium.org> 2 41 -
trunk/Source/WebCore/html/BaseDateAndTimeInputType.cpp
r132774 r133134 168 168 String BaseDateAndTimeInputType::convertFromVisibleValue(const String& visibleValue) const 169 169 { 170 if (visibleValue.isEmpty()) 171 return visibleValue; 172 173 double parsedValue = element()->locale().parseDateTime(visibleValue, dateType()); 174 if (!isfinite(parsedValue)) 175 return visibleValue; 176 177 return serializeWithMilliseconds(parsedValue); 170 // convertFromVisibleValue is used in the textfield UI. Though this class 171 // inherits TextFieldInputType, users are unable to edit visible values, and 172 // this function is never called. 173 ASSERT_NOT_REACHED(); 174 return visibleValue; 178 175 } 179 176 -
trunk/Source/WebCore/platform/text/LocaleICU.cpp
r132896 r133134 156 156 } 157 157 158 double LocaleICU::parseDateTime(const String& input, DateComponents::Type type)159 {160 if (type != DateComponents::Date)161 return std::numeric_limits<double>::quiet_NaN();162 if (!initializeShortDateFormat())163 return numeric_limits<double>::quiet_NaN();164 if (input.length() > static_cast<unsigned>(numeric_limits<int32_t>::max()))165 return numeric_limits<double>::quiet_NaN();166 int32_t inputLength = static_cast<int32_t>(input.length());167 UErrorCode status = U_ZERO_ERROR;168 int32_t parsePosition = 0;169 UDate date = udat_parse(m_shortDateFormat, input.characters(), inputLength, &parsePosition, &status);170 if (parsePosition != inputLength || U_FAILURE(status))171 return numeric_limits<double>::quiet_NaN();172 // UDate, which is an alias of double, is compatible with our expectation.173 return date;174 }175 176 158 #if ENABLE(CALENDAR_PICKER) || ENABLE(INPUT_MULTIPLE_FIELDS_UI) 177 159 static String getDateFormatPattern(const UDateFormat* dateFormat) -
trunk/Source/WebCore/platform/text/LocaleICU.h
r132896 r133134 50 50 virtual ~LocaleICU(); 51 51 52 // For LocalizedDate53 virtual double parseDateTime(const String&, DateComponents::Type) OVERRIDE;54 52 #if ENABLE(CALENDAR_PICKER) 55 53 virtual const Vector<String>& weekDayShortLabels() OVERRIDE; -
trunk/Source/WebCore/platform/text/LocaleNone.cpp
r132896 r133134 37 37 private: 38 38 virtual void initializeLocaleData() OVERRIDE FINAL; 39 virtual double parseDateTime(const String&, DateComponents::Type) OVERRIDE;40 39 #if ENABLE(CALENDAR_PICKER) 41 40 virtual bool isRTL() OVERRIDE; … … 73 72 void LocaleNone::initializeLocaleData() 74 73 { 75 }76 77 double LocaleNone::parseDateTime(const String&, DateComponents::Type)78 {79 return std::numeric_limits<double>::quiet_NaN();80 74 } 81 75 -
trunk/Source/WebCore/platform/text/PlatformLocale.h
r132896 r133134 123 123 #endif 124 124 125 // Parses a string representation of a date/time string localized126 // for this Locale locale. If the input string is not valid or127 // an implementation doesn't support localized dates, this128 // function returns NaN. If the input string is valid this129 // function returns the number of milliseconds since 1970-01-01130 // 00:00:00.000 UTC.131 virtual double parseDateTime(const String&, DateComponents::Type) = 0;132 133 125 enum FormatType { FormatTypeUnspecified, FormatTypeShort, FormatTypeMedium }; 134 126 -
trunk/Source/WebCore/platform/text/mac/LocaleMac.h
r132896 r133134 51 51 static PassOwnPtr<LocaleMac> create(NSLocale*); 52 52 ~LocaleMac(); 53 virtual double parseDateTime(const String&, DateComponents::Type) OVERRIDE;54 53 55 54 #if ENABLE(CALENDAR_PICKER) -
trunk/Source/WebCore/platform/text/mac/LocaleMac.mm
r132896 r133134 115 115 } 116 116 117 double LocaleMac::parseDateTime(const String& input, DateComponents::Type type)118 {119 if (type != DateComponents::Date)120 return std::numeric_limits<double>::quiet_NaN();121 NSDate *date = [shortDateFormatter().get() dateFromString:input];122 if (!date)123 return std::numeric_limits<double>::quiet_NaN();124 return [date timeIntervalSince1970] * msPerSecond;125 }126 127 117 #if ENABLE(CALENDAR_PICKER) || ENABLE(INPUT_MULTIPLE_FIELDS_UI) 128 118 const Vector<String>& LocaleMac::monthLabels() -
trunk/Source/WebCore/platform/text/win/LocaleWin.cpp
r132896 r133134 92 92 } 93 93 94 // Windows doesn't have an API to parse locale-specific date string,95 // and GetDateFormat() and GetDateFormatEx() don't support years older96 // than 1600, which we should support according to the HTML97 // standard. So, we obtain the date format from the system, but we98 // format/parse a date by our own code.99 100 94 inline LocaleWin::LocaleWin(LCID lcid) 101 95 : m_lcid(lcid) 102 96 , m_didInitializeNumberData(false) 103 97 { 104 SYSTEMTIME systemTime;105 GetLocalTime(&systemTime);106 m_baseYear = systemTime.wYear;107 108 98 #if ENABLE(CALENDAR_PICKER) 109 99 DWORD value = 0; … … 299 289 } 300 290 301 // -------------------------------- Parsing302 303 bool LocaleWin::isLocalizedDigit(UChar ch)304 {305 String normalizedDigit = convertFromLocalizedNumber(String(&ch, 1));306 if (normalizedDigit.length() != 1)307 return false;308 return isASCIIDigit(normalizedDigit[0]);309 }310 311 // Returns -1 if parsing fails.312 int LocaleWin::parseNumber(const String& input, unsigned& index)313 {314 unsigned digitsStart = index;315 while (index < input.length() && isASCIIDigit(input[index]))316 index++;317 if (digitsStart != index) {318 bool ok = false;319 int number = input.substring(digitsStart, index - digitsStart).toInt(&ok);320 return ok ? number : -1;321 }322 323 while (index < input.length() && isLocalizedDigit(input[index]))324 index++;325 if (digitsStart == index)326 return -1;327 bool ok = false;328 int number = convertFromLocalizedNumber(input.substring(digitsStart, index - digitsStart)).toInt(&ok);329 return ok ? number : -1;330 }331 332 // Returns 0-based month number. Returns -1 if parsing fails.333 int LocaleWin::parseNumberOrMonth(const String& input, unsigned& index)334 {335 int result = parseNumber(input, index);336 if (result >= 0) {337 if (result < 1 || result > 12)338 return -1;339 return result - 1;340 }341 for (unsigned m = 0; m < m_monthLabels.size(); ++m) {342 unsigned labelLength = m_monthLabels[m].length();343 if (equalIgnoringCase(input.substring(index, labelLength), m_monthLabels[m])) {344 index += labelLength;345 return m;346 }347 }348 for (unsigned m = 0; m < m_shortMonthLabels.size(); ++m) {349 unsigned labelLength = m_shortMonthLabels[m].length();350 if (equalIgnoringCase(input.substring(index, labelLength), m_shortMonthLabels[m])) {351 index += labelLength;352 return m;353 }354 }355 return -1;356 }357 358 double LocaleWin::parseDateTime(const String& input, DateComponents::Type type)359 {360 if (type != DateComponents::Date)361 return std::numeric_limits<double>::quiet_NaN();362 ensureShortDateTokens();363 return parseDate(m_shortDateTokens, m_baseYear, input);364 }365 366 double LocaleWin::parseDate(const String& format, int baseYear, const String& input)367 {368 return parseDate(parseDateFormat(format), baseYear, input);369 }370 371 double LocaleWin::parseDate(const Vector<DateFormatToken>& tokens, int baseYear, const String& input)372 {373 ensureShortMonthLabels();374 ensureMonthLabels();375 const double NaN = numeric_limits<double>::quiet_NaN();376 unsigned inputIndex = 0;377 int day = -1, month = -1, year = -1;378 for (unsigned i = 0; i < tokens.size(); ++i) {379 switch (tokens[i].type) {380 case DateFormatToken::Literal: {381 String data = tokens[i].data;382 unsigned literalLength = data.length();383 if (input.substring(inputIndex, literalLength) == data)384 inputIndex += literalLength;385 // Go ahead even if the input doesn't have this string.386 break;387 }388 case DateFormatToken::Day1:389 case DateFormatToken::Day2:390 day = parseNumber(input, inputIndex);391 if (day < 1 || day > 31)392 return NaN;393 break;394 case DateFormatToken::Month1:395 case DateFormatToken::Month2:396 case DateFormatToken::Month3:397 case DateFormatToken::Month4:398 month = parseNumberOrMonth(input, inputIndex);399 if (month < 0 || month > 11)400 return NaN;401 break;402 case DateFormatToken::Year1: {403 unsigned oldIndex = inputIndex;404 year = parseNumber(input, inputIndex);405 if (year <= 0)406 return NaN;407 if (inputIndex - oldIndex == 1) {408 int shortYear = baseYear % 10;409 int decade = baseYear - shortYear;410 if (shortYear >= 5)411 year += shortYear - 4 <= year ? decade : decade + 10;412 else413 year += shortYear + 5 >= year ? decade : decade - 10;414 }415 break;416 }417 case DateFormatToken::Year2: {418 unsigned oldIndex = inputIndex;419 year = parseNumber(input, inputIndex);420 if (year <= 0)421 return NaN;422 if (inputIndex - oldIndex == 2) {423 int shortYear = baseYear % 100;424 int century = baseYear - shortYear;425 if (shortYear >= 50)426 year += shortYear - 49 <= year ? century : century + 100;427 else428 year += shortYear + 50 >= year ? century : century - 100;429 }430 break;431 }432 case DateFormatToken::Year4:433 year = parseNumber(input, inputIndex);434 if (year <= 0)435 return NaN;436 break;437 }438 }439 if (year <= 0 || month < 0 || day <= 0)440 return NaN;441 return dateToDaysFrom1970(year, month, day) * msPerDay;442 }443 444 // -------------------------------- Formatting445 446 291 void LocaleWin::ensureShortDateTokens() 447 292 { -
trunk/Source/WebCore/platform/text/win/LocaleWin.h
r132896 r133134 47 47 static PassOwnPtr<LocaleWin> create(LCID); 48 48 ~LocaleWin(); 49 virtual double parseDateTime(const String&, DateComponents::Type) OVERRIDE;50 49 #if ENABLE(CALENDAR_PICKER) 51 50 virtual const Vector<String>& weekDayShortLabels() OVERRIDE; … … 67 66 #endif 68 67 69 // For testing.70 double parseDate(const String& format, int baseYear, const String& input);71 68 #if ENABLE(INPUT_MULTIPLE_FIELDS_UI) 72 69 static String dateFormat(const String&); … … 80 77 void ensureMonthLabels(); 81 78 void ensureShortDateTokens(); 82 bool isLocalizedDigit(UChar);83 int parseNumber(const String&, unsigned& index);84 int parseNumberOrMonth(const String&, unsigned& index);85 double parseDate(const Vector<DateFormatToken>&, int baseYear, const String&);86 void appendNumber(int, StringBuilder&);87 void appendTwoDigitsNumber(int, StringBuilder&);88 void appendFourDigitsNumber(int, StringBuilder&);89 String formatDate(const Vector<DateFormatToken>&, int baseYear, int year, int month, int day);90 79 #if ENABLE(CALENDAR_PICKER) 91 80 void ensureWeekDayShortLabels(); … … 95 84 96 85 LCID m_lcid; 97 int m_baseYear;98 86 Vector<DateFormatToken> m_shortDateTokens; 99 87 Vector<String> m_shortMonthLabels; -
trunk/Source/WebKit/chromium/ChangeLog
r133132 r133134 1 2012-11-01 Kent Tamura <tkent@chromium.org> 2 3 Remove unused Locale::parseDateTime 4 https://bugs.webkit.org/show_bug.cgi?id=100910 5 6 Reviewed by Kentaro Hara. 7 8 * tests/LocaleMacTest.cpp: Remove tests for parseDateTime. 9 * tests/LocaleWinTest.cpp: Ditto. 10 1 11 2012-10-31 Keishi Hattori <keishi@webkit.org> 2 12 -
trunk/Source/WebKit/chromium/tests/LocaleMacTest.cpp
r132896 r133134 82 82 } 83 83 84 double parseDate(const String& localeString, const String& dateString)85 {86 OwnPtr<LocaleMac> locale = LocaleMac::create(localeString);87 return locale->parseDateTime(dateString, DateComponents::Date);88 }89 90 84 #if ENABLE(CALENDAR_PICKER) 91 85 unsigned firstDayOfWeek(const String& localeString) … … 191 185 EXPECT_STREQ("\xD9\xA7:\xD9\xA0\xD9\xA7:\xD9\xA0\xD9\xA7\xD9\xAB\xD9\xA0\xD9\xA0\xD9\xA7 \xD8\xB5", formatTime("ar", 07, 07, 07, 007, false).utf8().data()); 192 186 EXPECT_STREQ("\xDB\xB7:\xDB\xB0\xDB\xB7:\xDB\xB0\xDB\xB7\xD9\xAB\xDB\xB0\xDB\xB0\xDB\xB7", formatTime("fa", 07, 07, 07, 007, false).utf8().data()); 193 }194 195 TEST_F(LocaleMacTest, parseDate)196 {197 EXPECT_EQ(msForDate(2005, April, 27), parseDate("en_US", "April 27, 2005"));198 EXPECT_EQ(msForDate(2005, April, 27), parseDate("fr_FR", "27 avril 2005"));199 EXPECT_EQ(msForDate(2005, April, 27), parseDate("ja_JP", "2005/04/27"));200 187 } 201 188 -
trunk/Source/WebKit/chromium/tests/LocaleWinTest.cpp
r132896 r133134 91 91 } 92 92 93 double parseDate(LCID lcid, const String& dateString)94 {95 OwnPtr<LocaleWin> locale = LocaleWin::create(lcid);96 return locale->parseDateTime(dateString, DateComponents::Date);97 }98 99 93 #if ENABLE(CALENDAR_PICKER) 100 94 unsigned firstDayOfWeek(LCID lcid) … … 161 155 #endif 162 156 }; 163 164 TEST_F(LocaleWinTest, TestParse)165 {166 OwnPtr<LocaleWin> locale = LocaleWin::create(EnglishUS);167 168 EXPECT_EQ(msForDate(2012, April, 27), locale->parseDate("MM/dd/yy", 2012, "04/27/12"));169 EXPECT_EQ(msForDate(2062, April, 27), locale->parseDate("MM/dd/yy", 2012, "04/27/62"));170 EXPECT_EQ(msForDate(1963, April, 27), locale->parseDate("MM/dd/yy", 2012, "04/27/63"));171 EXPECT_EQ(msForDate(2012, April, 27), locale->parseDate("MM/dd/yy", 2012, "4/27/2012"));172 EXPECT_EQ(msForDate(2012, April, 27), locale->parseDate("MM/dd/yy", 2012, "Apr/27/2012"));173 EXPECT_EQ(msForDate(2, April, 27), locale->parseDate("MM/d/yy", 2012, "April/27/2"));174 EXPECT_EQ(msForDate(2, April, 27), locale->parseDate("MM/d/yy", 2012, "april/27/2"));175 EXPECT_TRUE(isnan(locale->parseDate("MM/d/yy", 2012, "april/27")));176 EXPECT_TRUE(isnan(locale->parseDate("MM/d/yy", 2012, "april/27/")));177 EXPECT_TRUE(isnan(locale->parseDate("MM/d/yy", 2012, " april/27/")));178 179 EXPECT_EQ(msForDate(12, April, 7), locale->parseDate("MMM/d/yyyy", 2012, "04/7/12"));180 EXPECT_EQ(msForDate(62, April, 7), locale->parseDate("MMM/d/yyyy", 2012, "04/07/62"));181 EXPECT_EQ(msForDate(63, April, 7), locale->parseDate("MMM/d/yyyy", 2012, "04/07/63"));182 EXPECT_EQ(msForDate(2012, April, 7), locale->parseDate("MMM/d/yyyy", 2012, "4/7/2012"));183 EXPECT_EQ(msForDate(2012, May, 7), locale->parseDate("MMM/d/yyyy", 2012, "May/007/2012"));184 EXPECT_EQ(msForDate(2, May, 27), locale->parseDate("MM/d/yyyy", 2012, "May/0027/2"));185 EXPECT_TRUE(isnan(locale->parseDate("MM/d/yyyy", 2012, "May///0027///2")));186 EXPECT_TRUE(isnan(locale->parseDate("MM/d/yyyy", 2012, "Mayyyyyy/0027/2")));187 188 EXPECT_EQ(msForDate(2012, April, 27), locale->parseDate("MMMM/dd/y", 2012, "04/27/2"));189 EXPECT_EQ(msForDate(2017, April, 27), locale->parseDate("MMMM/dd/y", 2012, "04/27/7"));190 EXPECT_EQ(msForDate(2008, April, 27), locale->parseDate("MMMM/dd/y", 2012, "04/27/8"));191 EXPECT_EQ(msForDate(2012, April, 27), locale->parseDate("MMMM/dd/y", 2012, "4/27/2012"));192 EXPECT_EQ(msForDate(2012, December, 27), locale->parseDate("MMMM/dd/y", 2012, "December/27/2012"));193 EXPECT_EQ(msForDate(2012, November, 27), locale->parseDate("MMMM/d/y", 2012, "November/27/2"));194 EXPECT_TRUE(isnan(locale->parseDate("MMMM/d/y", 2012, "November 27 2")));195 EXPECT_TRUE(isnan(locale->parseDate("MMMM/d/y", 2012, "November 32 2")));196 EXPECT_TRUE(isnan(locale->parseDate("MMMM/d/y", 2012, "-1/-1/-1")));197 198 OwnPtr<LocaleWin> persian = LocaleWin::create(Persian);199 // U+06F1 U+06F6 / U+06F0 U+06F8 / 2012200 EXPECT_EQ(msForDate(2012, August, 16), persian->parseDate("dd/MM/yyyy", 2012, String::fromUTF8("\xDB\xB1\xDB\xB6/\xDB\xB0\xDB\xB8/2012")));201 }202 157 203 158 TEST_F(LocaleWinTest, formatDate) … … 206 161 EXPECT_STREQ("27/04/2005", formatDate(FrenchFR, 2005, April, 27).utf8().data()); 207 162 EXPECT_STREQ("2005/04/27", formatDate(JapaneseJP, 2005, April, 27).utf8().data()); 208 }209 210 TEST_F(LocaleWinTest, parseDate)211 {212 EXPECT_EQ(msForDate(2005, April, 27), parseDate(EnglishUS, "April/27/2005"));213 EXPECT_EQ(msForDate(2005, April, 27), parseDate(FrenchFR, "27/avril/2005"));214 EXPECT_EQ(msForDate(2005, April, 27), parseDate(JapaneseJP, "2005/04/27"));215 163 } 216 164
Note: See TracChangeset
for help on using the changeset viewer.