Changeset 133134 in webkit


Ignore:
Timestamp:
Nov 1, 2012 12:31:58 AM (11 years ago)
Author:
tkent@chromium.org
Message:

Remove unused Locale::parseDateTime
https://bugs.webkit.org/show_bug.cgi?id=100910

Reviewed by Kentaro Hara.

Source/WebCore:

For date/time input types, InputType::convertFromVisibleValue is never
called. convertFromVisibleValue is called when an inner editable node is
updated. However input elements don't have such editable nodes if
ENABLE_INPUT_MULTIPLE_FIELDS_UI is enabled, and a user can't edit the
inner editable node otherwise because we open date/time pickers when a
user try to change the field value.

We had used convertFromVisibleValue for input[type=date] with an old UI.

No new tests because of no behavior changes.

  • html/BaseDateAndTimeInputType.cpp:

(WebCore::BaseDateAndTimeInputType::convertFromVisibleValue):
Remove Locale::parseDateTiem and put ASSERT_NOT_REACHED.

  • platform/text/PlatformLocale.h: Remove parseDateTime.
  • platform/text/LocaleICU.h: Remove parseDateTime and a bogus comment.
  • platform/text/LocaleICU.cpp: Remove parseDateTime.
  • platform/text/LocaleNone.cpp: Remove parseDateTime.
  • platform/text/mac/LocaleMac.h: Remove parseDateTime.
  • platform/text/mac/LocaleMac.mm: Ditto.
  • platform/text/win/LocaleWin.h:
  • Remove parseDateTime, its helpers, and m_baseYear.
  • Remove appendNumber, appendTwoDigitsNumber, appendFourDigitsNumber, and formatDate. They don't exist.
  • platform/text/win/LocaleWin.cpp:

Remove the above functions.
(WebCore::LocaleWin::LocaleWin): Remove m_baseYear iniitalization.

Source/WebKit/chromium:

  • tests/LocaleMacTest.cpp: Remove tests for parseDateTime.
  • tests/LocaleWinTest.cpp: Ditto.
Location:
trunk/Source
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r133130 r133134  
     12012-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
    1402012-10-31  Nate Chapin  <japhet@chromium.org>
    241
  • trunk/Source/WebCore/html/BaseDateAndTimeInputType.cpp

    r132774 r133134  
    168168String BaseDateAndTimeInputType::convertFromVisibleValue(const String& visibleValue) const
    169169{
    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;
    178175}
    179176
  • trunk/Source/WebCore/platform/text/LocaleICU.cpp

    r132896 r133134  
    156156}
    157157
    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 
    176158#if ENABLE(CALENDAR_PICKER) || ENABLE(INPUT_MULTIPLE_FIELDS_UI)
    177159static String getDateFormatPattern(const UDateFormat* dateFormat)
  • trunk/Source/WebCore/platform/text/LocaleICU.h

    r132896 r133134  
    5050    virtual ~LocaleICU();
    5151
    52     // For LocalizedDate
    53     virtual double parseDateTime(const String&, DateComponents::Type) OVERRIDE;
    5452#if ENABLE(CALENDAR_PICKER)
    5553    virtual const Vector<String>& weekDayShortLabels() OVERRIDE;
  • trunk/Source/WebCore/platform/text/LocaleNone.cpp

    r132896 r133134  
    3737private:
    3838    virtual void initializeLocaleData() OVERRIDE FINAL;
    39     virtual double parseDateTime(const String&, DateComponents::Type) OVERRIDE;
    4039#if ENABLE(CALENDAR_PICKER)
    4140    virtual bool isRTL() OVERRIDE;
     
    7372void LocaleNone::initializeLocaleData()
    7473{
    75 }
    76 
    77 double LocaleNone::parseDateTime(const String&, DateComponents::Type)
    78 {
    79     return std::numeric_limits<double>::quiet_NaN();
    8074}
    8175
  • trunk/Source/WebCore/platform/text/PlatformLocale.h

    r132896 r133134  
    123123#endif
    124124
    125     // Parses a string representation of a date/time string localized
    126     // for this Locale locale. If the input string is not valid or
    127     // an implementation doesn't support localized dates, this
    128     // function returns NaN. If the input string is valid this
    129     // function returns the number of milliseconds since 1970-01-01
    130     // 00:00:00.000 UTC.
    131     virtual double parseDateTime(const String&, DateComponents::Type) = 0;
    132 
    133125    enum FormatType { FormatTypeUnspecified, FormatTypeShort, FormatTypeMedium };
    134126
  • trunk/Source/WebCore/platform/text/mac/LocaleMac.h

    r132896 r133134  
    5151    static PassOwnPtr<LocaleMac> create(NSLocale*);
    5252    ~LocaleMac();
    53     virtual double parseDateTime(const String&, DateComponents::Type) OVERRIDE;
    5453
    5554#if ENABLE(CALENDAR_PICKER)
  • trunk/Source/WebCore/platform/text/mac/LocaleMac.mm

    r132896 r133134  
    115115}
    116116
    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 
    127117#if ENABLE(CALENDAR_PICKER) || ENABLE(INPUT_MULTIPLE_FIELDS_UI)
    128118const Vector<String>& LocaleMac::monthLabels()
  • trunk/Source/WebCore/platform/text/win/LocaleWin.cpp

    r132896 r133134  
    9292}
    9393
    94 // Windows doesn't have an API to parse locale-specific date string,
    95 // and GetDateFormat() and GetDateFormatEx() don't support years older
    96 // than 1600, which we should support according to the HTML
    97 // standard. So, we obtain the date format from the system, but we
    98 // format/parse a date by our own code.
    99 
    10094inline LocaleWin::LocaleWin(LCID lcid)
    10195    : m_lcid(lcid)
    10296    , m_didInitializeNumberData(false)
    10397{
    104     SYSTEMTIME systemTime;
    105     GetLocalTime(&systemTime);
    106     m_baseYear = systemTime.wYear;
    107 
    10898#if ENABLE(CALENDAR_PICKER)
    10999    DWORD value = 0;
     
    299289}
    300290
    301 // -------------------------------- Parsing
    302 
    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                 else
    413                     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                 else
    428                     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 // -------------------------------- Formatting
    445 
    446291void LocaleWin::ensureShortDateTokens()
    447292{
  • trunk/Source/WebCore/platform/text/win/LocaleWin.h

    r132896 r133134  
    4747    static PassOwnPtr<LocaleWin> create(LCID);
    4848    ~LocaleWin();
    49     virtual double parseDateTime(const String&, DateComponents::Type) OVERRIDE;
    5049#if ENABLE(CALENDAR_PICKER)
    5150    virtual const Vector<String>& weekDayShortLabels() OVERRIDE;
     
    6766#endif
    6867
    69     // For testing.
    70     double parseDate(const String& format, int baseYear, const String& input);
    7168#if ENABLE(INPUT_MULTIPLE_FIELDS_UI)
    7269    static String dateFormat(const String&);
     
    8077    void ensureMonthLabels();
    8178    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);
    9079#if ENABLE(CALENDAR_PICKER)
    9180    void ensureWeekDayShortLabels();
     
    9584
    9685    LCID m_lcid;
    97     int m_baseYear;
    9886    Vector<DateFormatToken> m_shortDateTokens;
    9987    Vector<String> m_shortMonthLabels;
  • trunk/Source/WebKit/chromium/ChangeLog

    r133132 r133134  
     12012-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
    1112012-10-31  Keishi Hattori  <keishi@webkit.org>
    212
  • trunk/Source/WebKit/chromium/tests/LocaleMacTest.cpp

    r132896 r133134  
    8282    }
    8383
    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 
    9084#if ENABLE(CALENDAR_PICKER)
    9185    unsigned firstDayOfWeek(const String& localeString)
     
    191185    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());
    192186    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"));
    200187}
    201188
  • trunk/Source/WebKit/chromium/tests/LocaleWinTest.cpp

    r132896 r133134  
    9191    }
    9292
    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 
    9993#if ENABLE(CALENDAR_PICKER)
    10094    unsigned firstDayOfWeek(LCID lcid)
     
    161155#endif
    162156};
    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 / 2012
    200     EXPECT_EQ(msForDate(2012, August, 16), persian->parseDate("dd/MM/yyyy", 2012, String::fromUTF8("\xDB\xB1\xDB\xB6/\xDB\xB0\xDB\xB8/2012")));
    201 }
    202157
    203158TEST_F(LocaleWinTest, formatDate)
     
    206161    EXPECT_STREQ("27/04/2005", formatDate(FrenchFR, 2005, April, 27).utf8().data());
    207162    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"));
    215163}
    216164
Note: See TracChangeset for help on using the changeset viewer.