Changeset 68996 in webkit


Ignore:
Timestamp:
Oct 3, 2010 10:59:15 PM (14 years ago)
Author:
tkent@chromium.org
Message:

2010-10-03 Kent Tamura <tkent@chromium.org>

Reviewed by Dimitri Glazkov.

Refactor HTMLInputElement: Move parseToDouble() and
parseToDateComponents() to InputType.
https://bugs.webkit.org/show_bug.cgi?id=46965

Introduce BaseDateAndTimeInputType, which is a super class of
date, datetime, datetime-local, month, time, and week types.

No new tests. Just a refactoring.

  • Android.mk: Add BaseDateAndTimeInputType.
  • CMakeLists.txt: ditto.
  • GNUmakefile.am: ditto.
  • WebCore.gypi: ditto.
  • WebCore.pro: ditto.
  • WebCore.vcproj/WebCore.vcproj: ditto.
  • WebCore.xcodeproj/project.pbxproj: ditto.
  • html/BaseDateAndTimeInputType.cpp: Added. (WebCore::BaseDateAndTimeInputType::parseToDouble): (WebCore::BaseDateAndTimeInputType::parseToDateComponents):
  • html/BaseDateAndTimeInputType.h: Added. (WebCore::BaseDateAndTimeInputType::BaseDateAndTimeInputType):
  • html/DateInputType.cpp: (WebCore::DateInputType::parseToDateComponentsInternal):
  • html/DateInputType.h: (WebCore::DateInputType::DateInputType):
  • html/DateTimeInputType.cpp: (WebCore::DateTimeInputType::parseToDateComponentsInternal):
  • html/DateTimeInputType.h: (WebCore::DateTimeInputType::DateTimeInputType):
  • html/DateTimeLocalInputType.cpp: (WebCore::DateTimeLocalInputType::parseToDateComponentsInternal):
  • html/DateTimeLocalInputType.h: (WebCore::DateTimeLocalInputType::DateTimeLocalInputType):
  • html/HTMLInputElement.cpp: Replace parseToD* calls with m_inputType->parseToD*. (WebCore::HTMLInputElement::typeMismatch): (WebCore::HTMLInputElement::rangeUnderflow): (WebCore::HTMLInputElement::rangeOverflow): (WebCore::HTMLInputElement::minimum): (WebCore::HTMLInputElement::maximum): (WebCore::HTMLInputElement::stepBase): (WebCore::HTMLInputElement::stepMismatch): (WebCore::HTMLInputElement::applyStep): (WebCore::HTMLInputElement::valueAsDate): (WebCore::HTMLInputElement::valueAsNumber): (WebCore::HTMLInputElement::handleKeyEventForRange): (WebCore::HTMLInputElement::stepUpFromRenderer):
  • html/HTMLInputElement.h:
  • html/InputType.cpp: (WebCore::InputType::parseToDouble): (WebCore::InputType::parseToDateComponents):
  • html/InputType.h:
  • html/MonthInputType.cpp: (WebCore::MonthInputType::parseToDouble): (WebCore::MonthInputType::parseToDateComponentsInternal):
  • html/MonthInputType.h: (WebCore::MonthInputType::MonthInputType):
  • html/NumberInputType.cpp: (WebCore::NumberInputType::parseToDouble):
  • html/NumberInputType.h:
  • html/RangeInputType.cpp: (WebCore::RangeInputType::parseToDouble):
  • html/RangeInputType.h:
  • html/TimeInputType.cpp: (WebCore::TimeInputType::parseToDateComponentsInternal):
  • html/TimeInputType.h: (WebCore::TimeInputType::TimeInputType):
  • html/WeekInputType.cpp: (WebCore::WeekInputType::parseToDateComponentsInternal):
  • html/WeekInputType.h: (WebCore::WeekInputType::WeekInputType):
Location:
trunk/WebCore
Files:
28 edited
2 copied

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/Android.mk

    r68976 r68996  
    262262        \
    263263        html/AsyncImageResizer.cpp \
     264        html/BaseDateAndTimeInputType.cpp \
    264265        html/BaseTextInputType.cpp \
    265266        html/ButtonInputType.cpp \
  • trunk/WebCore/CMakeLists.txt

    r68976 r68996  
    945945
    946946    html/AsyncImageResizer.cpp
     947    html/BaseDateAndTimeInputType.cpp
    947948    html/BaseTextInputType.cpp
    948949    html/ButtonInputType.cpp
  • trunk/WebCore/ChangeLog

    r68986 r68996  
     12010-10-03  Kent Tamura  <tkent@chromium.org>
     2
     3        Reviewed by Dimitri Glazkov.
     4
     5        Refactor HTMLInputElement: Move parseToDouble() and
     6        parseToDateComponents() to InputType.
     7        https://bugs.webkit.org/show_bug.cgi?id=46965
     8
     9        Introduce BaseDateAndTimeInputType, which is a super class of
     10        date, datetime, datetime-local, month, time, and week types.
     11
     12        No new tests. Just a refactoring.
     13
     14        * Android.mk: Add BaseDateAndTimeInputType.
     15        * CMakeLists.txt: ditto.
     16        * GNUmakefile.am: ditto.
     17        * WebCore.gypi: ditto.
     18        * WebCore.pro: ditto.
     19        * WebCore.vcproj/WebCore.vcproj: ditto.
     20        * WebCore.xcodeproj/project.pbxproj: ditto.
     21        * html/BaseDateAndTimeInputType.cpp: Added.
     22        (WebCore::BaseDateAndTimeInputType::parseToDouble):
     23        (WebCore::BaseDateAndTimeInputType::parseToDateComponents):
     24        * html/BaseDateAndTimeInputType.h: Added.
     25        (WebCore::BaseDateAndTimeInputType::BaseDateAndTimeInputType):
     26        * html/DateInputType.cpp:
     27        (WebCore::DateInputType::parseToDateComponentsInternal):
     28        * html/DateInputType.h:
     29        (WebCore::DateInputType::DateInputType):
     30        * html/DateTimeInputType.cpp:
     31        (WebCore::DateTimeInputType::parseToDateComponentsInternal):
     32        * html/DateTimeInputType.h:
     33        (WebCore::DateTimeInputType::DateTimeInputType):
     34        * html/DateTimeLocalInputType.cpp:
     35        (WebCore::DateTimeLocalInputType::parseToDateComponentsInternal):
     36        * html/DateTimeLocalInputType.h:
     37        (WebCore::DateTimeLocalInputType::DateTimeLocalInputType):
     38        * html/HTMLInputElement.cpp: Replace parseToD* calls with m_inputType->parseToD*.
     39        (WebCore::HTMLInputElement::typeMismatch):
     40        (WebCore::HTMLInputElement::rangeUnderflow):
     41        (WebCore::HTMLInputElement::rangeOverflow):
     42        (WebCore::HTMLInputElement::minimum):
     43        (WebCore::HTMLInputElement::maximum):
     44        (WebCore::HTMLInputElement::stepBase):
     45        (WebCore::HTMLInputElement::stepMismatch):
     46        (WebCore::HTMLInputElement::applyStep):
     47        (WebCore::HTMLInputElement::valueAsDate):
     48        (WebCore::HTMLInputElement::valueAsNumber):
     49        (WebCore::HTMLInputElement::handleKeyEventForRange):
     50        (WebCore::HTMLInputElement::stepUpFromRenderer):
     51        * html/HTMLInputElement.h:
     52        * html/InputType.cpp:
     53        (WebCore::InputType::parseToDouble):
     54        (WebCore::InputType::parseToDateComponents):
     55        * html/InputType.h:
     56        * html/MonthInputType.cpp:
     57        (WebCore::MonthInputType::parseToDouble):
     58        (WebCore::MonthInputType::parseToDateComponentsInternal):
     59        * html/MonthInputType.h:
     60        (WebCore::MonthInputType::MonthInputType):
     61        * html/NumberInputType.cpp:
     62        (WebCore::NumberInputType::parseToDouble):
     63        * html/NumberInputType.h:
     64        * html/RangeInputType.cpp:
     65        (WebCore::RangeInputType::parseToDouble):
     66        * html/RangeInputType.h:
     67        * html/TimeInputType.cpp:
     68        (WebCore::TimeInputType::parseToDateComponentsInternal):
     69        * html/TimeInputType.h:
     70        (WebCore::TimeInputType::TimeInputType):
     71        * html/WeekInputType.cpp:
     72        (WebCore::WeekInputType::parseToDateComponentsInternal):
     73        * html/WeekInputType.h:
     74        (WebCore::WeekInputType::WeekInputType):
     75
    1762010-10-03  Adam Barth  <abarth@webkit.org>
    277
  • trunk/WebCore/GNUmakefile.am

    r68976 r68996  
    14281428        WebCore/html/AsyncImageResizer.cpp \
    14291429        WebCore/html/AsyncImageResizer.h \
     1430        WebCore/html/BaseDateAndTimeInputType.cpp \
     1431        WebCore/html/BaseDateAndTimeInputType.h \
    14301432        WebCore/html/BaseTextInputType.cpp \
    14311433        WebCore/html/BaseTextInputType.h \
  • trunk/WebCore/WebCore.gypi

    r68976 r68996  
    15141514            'html/AsyncImageResizer.cpp',
    15151515            'html/AsyncImageResizer.h',
     1516            'html/BaseDateAndTimeInputType.cpp',
     1517            'html/BaseDateAndTimeInputType.h',
    15161518            'html/BaseTextInputType.cpp',
    15171519            'html/BaseTextInputType.h',
  • trunk/WebCore/WebCore.pro

    r68978 r68996  
    837837    history/PageCache.cpp \
    838838    html/AsyncImageResizer.cpp \
     839    html/BaseDateAndTimeInputType.cpp \
    839840    html/BaseTextInputType.cpp \
    840841    html/ButtonInputType.cpp \
  • trunk/WebCore/WebCore.vcproj/WebCore.vcproj

    r68976 r68996  
    3741237412                        </File>
    3741337413                        <File
     37414                                RelativePath="..\html\BaseDateAndTimeInputType.cpp"
     37415                                >
     37416                        </File>
     37417                        <File
     37418                                RelativePath="..\html\BaseDateAndTimeInputType.h"
     37419                                >
     37420                        </File>
     37421                        <File
    3741437422                                RelativePath="..\html\BaseTextInputType.cpp"
    3741537423                                >
  • trunk/WebCore/WebCore.xcodeproj/project.pbxproj

    r68976 r68996  
    54695469                F55B3DDF1251F12D003EF269 /* WeekInputType.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F55B3DAB1251F12D003EF269 /* WeekInputType.cpp */; };
    54705470                F55B3DE01251F12D003EF269 /* WeekInputType.h in Headers */ = {isa = PBXBuildFile; fileRef = F55B3DAC1251F12D003EF269 /* WeekInputType.h */; };
     5471                F59C95FF1255B23F000623C0 /* BaseDateAndTimeInputType.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F59C95FD1255B23F000623C0 /* BaseDateAndTimeInputType.cpp */; };
     5472                F59C96001255B23F000623C0 /* BaseDateAndTimeInputType.h in Headers */ = {isa = PBXBuildFile; fileRef = F59C95FE1255B23F000623C0 /* BaseDateAndTimeInputType.h */; };
    54715473                F5C041DA0FFCA7CE00839D4A /* HTMLDataListElement.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F5C041D70FFCA7CE00839D4A /* HTMLDataListElement.cpp */; };
    54725474                F5C041DB0FFCA7CE00839D4A /* HTMLDataListElement.h in Headers */ = {isa = PBXBuildFile; fileRef = F5C041D80FFCA7CE00839D4A /* HTMLDataListElement.h */; };
     
    1146711469                F587868402DE3B8601EA4122 /* Cursor.h */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.c.h; path = Cursor.h; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
    1146811470                F587869902DE3B8601EA4122 /* DeprecatedPtrList.h */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.c.h; path = DeprecatedPtrList.h; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
     11471                F59C95FD1255B23F000623C0 /* BaseDateAndTimeInputType.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = BaseDateAndTimeInputType.cpp; sourceTree = "<group>"; };
     11472                F59C95FE1255B23F000623C0 /* BaseDateAndTimeInputType.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BaseDateAndTimeInputType.h; sourceTree = "<group>"; };
    1146911473                F5C041D70FFCA7CE00839D4A /* HTMLDataListElement.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = HTMLDataListElement.cpp; sourceTree = "<group>"; };
    1147011474                F5C041D80FFCA7CE00839D4A /* HTMLDataListElement.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HTMLDataListElement.h; sourceTree = "<group>"; };
     
    1441314417                                B0149E7911A4B21500196A7B /* AsyncImageResizer.cpp */,
    1441414418                                B0149E7A11A4B21500196A7B /* AsyncImageResizer.h */,
     14419                                F59C95FD1255B23F000623C0 /* BaseDateAndTimeInputType.cpp */,
     14420                                F59C95FE1255B23F000623C0 /* BaseDateAndTimeInputType.h */,
    1441514421                                F55B3D791251F12D003EF269 /* BaseTextInputType.cpp */,
    1441614422                                F55B3D7A1251F12D003EF269 /* BaseTextInputType.h */,
     
    1821718223                                BC124EE80C2641CD009E2349 /* BarInfo.h in Headers */,
    1821818224                                B2C3DA220D006C1D00EF6F26 /* Base64.h in Headers */,
     18225                                F59C96001255B23F000623C0 /* BaseDateAndTimeInputType.h in Headers */,
    1821918226                                F55B3DAE1251F12D003EF269 /* BaseTextInputType.h in Headers */,
    1822018227                                BC9462D8107A7B4C00857193 /* BeforeLoadEvent.h in Headers */,
     
    2131821325                                BC124EE70C2641CD009E2349 /* BarInfo.cpp in Sources */,
    2131921326                                B2C3DA210D006C1D00EF6F26 /* Base64.cpp in Sources */,
     21327                                F59C95FF1255B23F000623C0 /* BaseDateAndTimeInputType.cpp in Sources */,
    2132021328                                F55B3DAD1251F12D003EF269 /* BaseTextInputType.cpp in Sources */,
    2132121329                                5172204B11D2960500638B42 /* BeforeProcessEvent.cpp in Sources */,
  • trunk/WebCore/html/BaseDateAndTimeInputType.cpp

    r68995 r68996  
    3030
    3131#include "config.h"
    32 #include "DateInputType.h"
     32#include "BaseDateAndTimeInputType.h"
    3333
     34#include "DateComponents.h"
    3435#include <wtf/PassOwnPtr.h>
     36#include <wtf/text/WTFString.h>
    3537
    3638namespace WebCore {
    3739
    38 PassOwnPtr<InputType> DateInputType::create(HTMLInputElement* element)
     40double BaseDateAndTimeInputType::parseToDouble(const String& src, double defaultValue) const
    3941{
    40     return adoptPtr(new DateInputType(element));
     42    DateComponents date;
     43    if (!parseToDateComponents(src, &date))
     44        return defaultValue;
     45    double msec = date.millisecondsSinceEpoch();
     46    ASSERT(isfinite(msec));
     47    return msec;
    4148}
    4249
    43 const AtomicString& DateInputType::formControlType() const
     50bool BaseDateAndTimeInputType::parseToDateComponents(const String& source, DateComponents* out) const
    4451{
    45     return InputTypeNames::date();
     52    if (source.isEmpty())
     53        return false;
     54    DateComponents ignoredResult;
     55    if (!out)
     56        out = &ignoredResult;
     57    return parseToDateComponentsInternal(source.characters(), source.length(), out);
    4658}
    4759
  • trunk/WebCore/html/BaseDateAndTimeInputType.h

    r68995 r68996  
    2929 */
    3030
    31 #ifndef DateTimeInputType_h
    32 #define DateTimeInputType_h
     31#ifndef BaseDateAndTimeInputType_h
     32#define BaseDateAndTimeInputType_h
    3333
    3434#include "TextFieldInputType.h"
     35#include <wtf/unicode/Unicode.h>
    3536
    3637namespace WebCore {
    3738
    38 class DateTimeInputType : public TextFieldInputType {
    39 public:
    40     static PassOwnPtr<InputType> create(HTMLInputElement*);
    41 
     39// A super class of date, datetime, datetime-local, month, time, and week types.
     40class BaseDateAndTimeInputType : public TextFieldInputType {
     41protected:
     42    BaseDateAndTimeInputType(HTMLInputElement* element) : TextFieldInputType(element) { }
     43    virtual bool parseToDateComponents(const String&, DateComponents*) const;
     44    // A helper for parseToDateComponents().
     45    virtual bool parseToDateComponentsInternal(const UChar*, unsigned length, DateComponents*) const = 0;
    4246private:
    43     DateTimeInputType(HTMLInputElement* element) : TextFieldInputType(element) { }
    44     virtual const AtomicString& formControlType() const;
     47    virtual double parseToDouble(const String&, double) const;
    4548};
    4649
    4750} // namespace WebCore
    4851
    49 #endif // DateTimeInputType_h
     52#endif // BaseDateAndTimeInputType_h
  • trunk/WebCore/html/DateInputType.cpp

    r68629 r68996  
    3232#include "DateInputType.h"
    3333
     34#include "DateComponents.h"
    3435#include <wtf/PassOwnPtr.h>
    3536
     
    4647}
    4748
     49bool DateInputType::parseToDateComponentsInternal(const UChar* characters, unsigned length, DateComponents* out) const
     50{
     51    ASSERT(out);
     52    unsigned end;
     53    return out->parseDate(characters, length, 0, end) && end == length;
     54}
     55
    4856} // namespace WebCore
  • trunk/WebCore/html/DateInputType.h

    r68629 r68996  
    3232#define DateInputType_h
    3333
    34 #include "TextFieldInputType.h"
     34#include "BaseDateAndTimeInputType.h"
    3535
    3636namespace WebCore {
    3737
    38 class DateInputType : public TextFieldInputType {
     38class DateInputType : public BaseDateAndTimeInputType {
    3939public:
    4040    static PassOwnPtr<InputType> create(HTMLInputElement*);
    4141
    4242private:
    43     DateInputType(HTMLInputElement* element) : TextFieldInputType(element) { }
     43    DateInputType(HTMLInputElement* element) : BaseDateAndTimeInputType(element) { }
    4444    virtual const AtomicString& formControlType() const;
     45    virtual bool parseToDateComponentsInternal(const UChar*, unsigned length, DateComponents*) const;
    4546};
    4647
  • trunk/WebCore/html/DateTimeInputType.cpp

    r68629 r68996  
    3232#include "DateTimeInputType.h"
    3333
     34#include "DateComponents.h"
    3435#include <wtf/PassOwnPtr.h>
    3536
     
    4647}
    4748
     49bool DateTimeInputType::parseToDateComponentsInternal(const UChar* characters, unsigned length, DateComponents* out) const
     50{
     51    ASSERT(out);
     52    unsigned end;
     53    return out->parseDateTime(characters, length, 0, end) && end == length;
     54}
     55
    4856} // namespace WebCore
  • trunk/WebCore/html/DateTimeInputType.h

    r68629 r68996  
    3232#define DateTimeInputType_h
    3333
    34 #include "TextFieldInputType.h"
     34#include "BaseDateAndTimeInputType.h"
    3535
    3636namespace WebCore {
    3737
    38 class DateTimeInputType : public TextFieldInputType {
     38class DateTimeInputType : public BaseDateAndTimeInputType {
    3939public:
    4040    static PassOwnPtr<InputType> create(HTMLInputElement*);
    4141
    4242private:
    43     DateTimeInputType(HTMLInputElement* element) : TextFieldInputType(element) { }
     43    DateTimeInputType(HTMLInputElement* element) : BaseDateAndTimeInputType(element) { }
    4444    virtual const AtomicString& formControlType() const;
     45    virtual bool parseToDateComponentsInternal(const UChar*, unsigned length, DateComponents*) const;
    4546};
    4647
  • trunk/WebCore/html/DateTimeLocalInputType.cpp

    r68629 r68996  
    3232#include "DateTimeLocalInputType.h"
    3333
     34#include "DateComponents.h"
    3435#include <wtf/PassOwnPtr.h>
    3536
     
    4647}
    4748
     49bool DateTimeLocalInputType::parseToDateComponentsInternal(const UChar* characters, unsigned length, DateComponents* out) const
     50{
     51    ASSERT(out);
     52    unsigned end;
     53    return out->parseDateTimeLocal(characters, length, 0, end) && end == length;
     54}
     55
    4856} // namespace WebCore
  • trunk/WebCore/html/DateTimeLocalInputType.h

    r68629 r68996  
    3232#define DateTimeLocalInputType_h
    3333
    34 #include "TextFieldInputType.h"
     34#include "BaseDateAndTimeInputType.h"
    3535
    3636namespace WebCore {
    3737
    38 class DateTimeLocalInputType : public TextFieldInputType {
     38class DateTimeLocalInputType : public BaseDateAndTimeInputType {
    3939public:
    4040    static PassOwnPtr<InputType> create(HTMLInputElement*);
    4141
    4242private:
    43     DateTimeLocalInputType(HTMLInputElement* element) : TextFieldInputType(element) { }
     43    DateTimeLocalInputType(HTMLInputElement* element) : BaseDateAndTimeInputType(element) { }
    4444    virtual const AtomicString& formControlType() const;
     45    virtual bool parseToDateComponentsInternal(const UChar*, unsigned length, DateComponents*) const;
    4546};
    4647
  • trunk/WebCore/html/HTMLInputElement.cpp

    r68749 r68996  
    284284    case TIME:
    285285    case WEEK:
    286         return !parseToDateComponents(deprecatedInputType(), value, 0);
     286        return !m_inputType->parseToDateComponents(value, 0);
    287287    case BUTTON:
    288288    case CHECKBOX:
     
    380380    case TIME:
    381381    case WEEK: {
    382         double doubleValue = parseToDouble(value, nan);
     382        double doubleValue = m_inputType->parseToDouble(value, nan);
    383383        return isfinite(doubleValue) && doubleValue < minimum();
    384384    }
    385385    case RANGE: // Guaranteed by sanitization.
    386         ASSERT(parseToDouble(value, nan) >= minimum());
     386        ASSERT(m_inputType->parseToDouble(value, nan) >= minimum());
    387387    case BUTTON:
    388388    case CHECKBOX:
     
    417417    case TIME:
    418418    case WEEK: {
    419         double doubleValue = parseToDouble(value, nan);
     419        double doubleValue = m_inputType->parseToDouble(value, nan);
    420420        return isfinite(doubleValue) && doubleValue > maximum();
    421421    }
    422422    case RANGE: // Guaranteed by sanitization.
    423         ASSERT(parseToDouble(value, nan) <= maximum());
     423        ASSERT(m_inputType->parseToDouble(value, nan) <= maximum());
    424424    case BUTTON:
    425425    case CHECKBOX:
     
    447447    switch (deprecatedInputType()) {
    448448    case DATE:
    449         return parseToDouble(getAttribute(minAttr), DateComponents::minimumDate());
     449        return m_inputType->parseToDouble(getAttribute(minAttr), DateComponents::minimumDate());
    450450    case DATETIME:
    451451    case DATETIMELOCAL:
    452         return parseToDouble(getAttribute(minAttr), DateComponents::minimumDateTime());
     452        return m_inputType->parseToDouble(getAttribute(minAttr), DateComponents::minimumDateTime());
    453453    case MONTH:
    454         return parseToDouble(getAttribute(minAttr), DateComponents::minimumMonth());
     454        return m_inputType->parseToDouble(getAttribute(minAttr), DateComponents::minimumMonth());
    455455    case NUMBER:
    456         return parseToDouble(getAttribute(minAttr), numberDefaultMinimum);
     456        return m_inputType->parseToDouble(getAttribute(minAttr), numberDefaultMinimum);
    457457    case RANGE:
    458         return parseToDouble(getAttribute(minAttr), rangeDefaultMinimum);
     458        return m_inputType->parseToDouble(getAttribute(minAttr), rangeDefaultMinimum);
    459459    case TIME:
    460         return parseToDouble(getAttribute(minAttr), DateComponents::minimumTime());
     460        return m_inputType->parseToDouble(getAttribute(minAttr), DateComponents::minimumTime());
    461461    case WEEK:
    462         return parseToDouble(getAttribute(minAttr), DateComponents::minimumWeek());
     462        return m_inputType->parseToDouble(getAttribute(minAttr), DateComponents::minimumWeek());
    463463    case BUTTON:
    464464    case CHECKBOX:
     
    487487    switch (deprecatedInputType()) {
    488488    case DATE:
    489         return parseToDouble(getAttribute(maxAttr), DateComponents::maximumDate());
     489        return m_inputType->parseToDouble(getAttribute(maxAttr), DateComponents::maximumDate());
    490490    case DATETIME:
    491491    case DATETIMELOCAL:
    492         return parseToDouble(getAttribute(maxAttr), DateComponents::maximumDateTime());
     492        return m_inputType->parseToDouble(getAttribute(maxAttr), DateComponents::maximumDateTime());
    493493    case MONTH:
    494         return parseToDouble(getAttribute(maxAttr), DateComponents::maximumMonth());
     494        return m_inputType->parseToDouble(getAttribute(maxAttr), DateComponents::maximumMonth());
    495495    case NUMBER:
    496         return parseToDouble(getAttribute(maxAttr), numberDefaultMaximum);
     496        return m_inputType->parseToDouble(getAttribute(maxAttr), numberDefaultMaximum);
    497497    case RANGE: {
    498         double max = parseToDouble(getAttribute(maxAttr), rangeDefaultMaximum);
     498        double max = m_inputType->parseToDouble(getAttribute(maxAttr), rangeDefaultMaximum);
    499499        // A remedy for the inconsistent min/max values for RANGE.
    500500        // Sets the maximum to the default or the minimum value.
     
    505505    }
    506506    case TIME:
    507         return parseToDouble(getAttribute(maxAttr), DateComponents::maximumTime());
     507        return m_inputType->parseToDouble(getAttribute(maxAttr), DateComponents::maximumTime());
    508508    case WEEK:
    509         return parseToDouble(getAttribute(maxAttr), DateComponents::maximumWeek());
     509        return m_inputType->parseToDouble(getAttribute(maxAttr), DateComponents::maximumWeek());
    510510    case BUTTON:
    511511    case CHECKBOX:
     
    541541    case NUMBER:
    542542    case TIME:
    543         return parseToDouble(getAttribute(minAttr), defaultStepBase);
     543        return m_inputType->parseToDouble(getAttribute(minAttr), defaultStepBase);
    544544    case WEEK:
    545         return parseToDouble(getAttribute(minAttr), weekDefaultStepBase);
     545        return m_inputType->parseToDouble(getAttribute(minAttr), weekDefaultStepBase);
    546546    case BUTTON:
    547547    case CHECKBOX:
     
    601601    case WEEK: {
    602602        const double nan = numeric_limits<double>::quiet_NaN();
    603         double doubleValue = parseToDouble(value, nan);
     603        double doubleValue = m_inputType->parseToDouble(value, nan);
    604604        doubleValue = fabs(doubleValue - stepBase());
    605605        if (!isfinite(doubleValue))
     
    724724    }
    725725    const double nan = numeric_limits<double>::quiet_NaN();
    726     double current = parseToDouble(value(), nan);
     726    double current = m_inputType->parseToDouble(value(), nan);
    727727    if (!isfinite(current)) {
    728728        ec = INVALID_STATE_ERR;
     
    16441644}
    16451645
    1646 double HTMLInputElement::parseToDouble(const String& src, double defaultValue) const
    1647 {
    1648     switch (deprecatedInputType()) {
    1649     case DATE:
    1650     case DATETIME:
    1651     case DATETIMELOCAL:
    1652     case TIME:
    1653     case WEEK: {
    1654         DateComponents date;
    1655         if (!parseToDateComponents(deprecatedInputType(), src, &date))
    1656             return defaultValue;
    1657         double msec = date.millisecondsSinceEpoch();
    1658         ASSERT(isfinite(msec));
    1659         return msec;
    1660     }
    1661     case MONTH: {
    1662         DateComponents date;
    1663         if (!parseToDateComponents(deprecatedInputType(), src, &date))
    1664             return defaultValue;
    1665         double months = date.monthsSinceEpoch();
    1666         ASSERT(isfinite(months));
    1667         return months;
    1668     }
    1669     case NUMBER:
    1670     case RANGE: {
    1671         double numberValue;
    1672         if (!parseToDoubleForNumberType(src, &numberValue))
    1673             return defaultValue;
    1674         ASSERT(isfinite(numberValue));
    1675         return numberValue;
    1676     }
    1677 
    1678     case BUTTON:
    1679     case CHECKBOX:
    1680     case COLOR:
    1681     case EMAIL:
    1682     case FILE:
    1683     case HIDDEN:
    1684     case IMAGE:
    1685     case ISINDEX:
    1686     case PASSWORD:
    1687     case RADIO:
    1688     case RESET:
    1689     case SEARCH:
    1690     case SUBMIT:
    1691     case TELEPHONE:
    1692     case TEXT:
    1693     case URL:
    1694         return defaultValue;
    1695     }
    1696     ASSERT_NOT_REACHED();
    1697     return defaultValue;
    1698 }
    1699 
    17001646double HTMLInputElement::valueAsDate() const
    17011647{
     
    17051651    case TIME:
    17061652    case WEEK:
    1707         return parseToDouble(value(), DateComponents::invalidMilliseconds());
     1653        return m_inputType->parseToDouble(value(), DateComponents::invalidMilliseconds());
    17081654    case MONTH: {
    17091655        DateComponents date;
    1710         if (!parseToDateComponents(deprecatedInputType(), value(), &date))
     1656        if (!m_inputType->parseToDateComponents(value(), &date))
    17111657            return DateComponents::invalidMilliseconds();
    17121658        double msec = date.millisecondsSinceEpoch();
     
    17951741    case TIME:
    17961742    case WEEK:
    1797         return parseToDouble(value(), nan);
     1743        return m_inputType->parseToDouble(value(), nan);
    17981744
    17991745    case BUTTON:
     
    24932439        // FIXME: Is 1/100 reasonable?
    24942440        double step = (max - min) / 100;
    2495         double current = parseToDouble(value(), numeric_limits<double>::quiet_NaN());
     2441        double current = m_inputType->parseToDouble(value(), numeric_limits<double>::quiet_NaN());
    24962442        ASSERT(isfinite(current));
    24972443        double newValue;
     
    27922738}
    27932739
    2794 bool HTMLInputElement::parseToDateComponents(DeprecatedInputType type, const String& formString, DateComponents* out)
    2795 {
    2796     if (formString.isEmpty())
    2797         return false;
    2798     DateComponents ignoredResult;
    2799     if (!out)
    2800         out = &ignoredResult;
    2801     const UChar* characters = formString.characters();
    2802     unsigned length = formString.length();
    2803     unsigned end;
    2804 
    2805     switch (type) {
    2806     case DATE:
    2807         return out->parseDate(characters, length, 0, end) && end == length;
    2808     case DATETIME:
    2809         return out->parseDateTime(characters, length, 0, end) && end == length;
    2810     case DATETIMELOCAL:
    2811         return out->parseDateTimeLocal(characters, length, 0, end) && end == length;
    2812     case MONTH:
    2813         return out->parseMonth(characters, length, 0, end) && end == length;
    2814     case WEEK:
    2815         return out->parseWeek(characters, length, 0, end) && end == length;
    2816     case TIME:
    2817         return out->parseTime(characters, length, 0, end) && end == length;
    2818     default:
    2819         ASSERT_NOT_REACHED();
    2820         return false;
    2821     }
    2822 }
    2823 
    28242740#if ENABLE(DATALIST)
    28252741
     
    29132829    const double nan = numeric_limits<double>::quiet_NaN();
    29142830    String currentStringValue = value();
    2915     double current = parseToDouble(currentStringValue, nan);
     2831    double current = m_inputType->parseToDouble(currentStringValue, nan);
    29162832    if (!isfinite(current) || (n > 0 && current < minimum()) || (n < 0 && current > maximum()))
    29172833        setValue(serialize(n > 0 ? minimum() : maximum()));
  • trunk/WebCore/html/HTMLInputElement.h

    r68749 r68996  
    331331    double stepBase() const;
    332332
    333     // Parses the specified string as the DeprecatedInputType, and returns true if it is successfully parsed.
    334     // An instance pointed by the DateComponents* parameter will have parsed values and be
    335     // modified even if the parsing fails.  The DateComponents* parameter may be 0.
    336     static bool parseToDateComponents(DeprecatedInputType, const String&, DateComponents*);
    337 
    338     // Parses the specified string for the current type, and return
    339     // the double value for the parsing result if the parsing
    340     // succeeds; Returns defaultValue otherwise. This function can
    341     // return NaN or Infinity only if defaultValue is NaN or Infinity.
    342     double parseToDouble(const String&, double defaultValue) const;
    343333    // Create a string representation of the specified double value for the
    344334    // current input type. If NaN or Infinity is specified, this returns an
  • trunk/WebCore/html/InputType.cpp

    r68629 r68996  
    123123}
    124124
     125double InputType::parseToDouble(const String&, double defaultValue) const
     126{
     127    return defaultValue;
     128}
     129
     130bool InputType::parseToDateComponents(const String&, DateComponents*) const
     131{
     132    ASSERT_NOT_REACHED();
     133    return false;
     134}
     135
     136
    125137namespace InputTypeNames {
    126138
  • trunk/WebCore/html/InputType.h

    r68629 r68996  
    3737namespace WebCore {
    3838
     39class DateComponents;
    3940class HTMLInputElement;
    4041
     
    5051
    5152    virtual bool patternMismatch(const String&) const;
     53
     54    // Parses the specified string for the type, and return
     55    // the double value for the parsing result if the parsing
     56    // succeeds; Returns defaultValue otherwise. This function can
     57    // return NaN or Infinity only if defaultValue is NaN or Infinity.
     58    virtual double parseToDouble(const String&, double defaultValue) const;
     59    // Parses the specified string for this InputType, and returns true if it
     60    // is successfully parsed. An instance pointed by the DateComponents*
     61    // parameter will have parsed values and be modified even if the parsing
     62    // fails. The DateComponents* parameter may be 0.
     63    virtual bool parseToDateComponents(const String&, DateComponents*) const;
    5264
    5365protected:
  • trunk/WebCore/html/MonthInputType.cpp

    r68629 r68996  
    3232#include "MonthInputType.h"
    3333
     34#include "DateComponents.h"
    3435#include <wtf/PassOwnPtr.h>
    3536
     
    4647}
    4748
     49double MonthInputType::parseToDouble(const String& src, double defaultValue) const
     50{
     51    DateComponents date;
     52    if (!parseToDateComponents(src, &date))
     53        return defaultValue;
     54    double months = date.monthsSinceEpoch();
     55    ASSERT(isfinite(months));
     56    return months;
     57}
     58
     59bool MonthInputType::parseToDateComponentsInternal(const UChar* characters, unsigned length, DateComponents* out) const
     60{
     61    ASSERT(out);
     62    unsigned end;
     63    return out->parseMonth(characters, length, 0, end) && end == length;
     64}
     65
    4866} // namespace WebCore
  • trunk/WebCore/html/MonthInputType.h

    r68629 r68996  
    3232#define MonthInputType_h
    3333
    34 #include "TextFieldInputType.h"
     34#include "BaseDateAndTimeInputType.h"
    3535
    3636namespace WebCore {
    3737
    38 class MonthInputType : public TextFieldInputType {
     38class MonthInputType : public BaseDateAndTimeInputType {
    3939public:
    4040    static PassOwnPtr<InputType> create(HTMLInputElement*);
    4141
    4242private:
    43     MonthInputType(HTMLInputElement* element) : TextFieldInputType(element) { }
     43    MonthInputType(HTMLInputElement* element) : BaseDateAndTimeInputType(element) { }
    4444    virtual const AtomicString& formControlType() const;
     45    virtual double parseToDouble(const String&, double) const;
     46    virtual bool parseToDateComponentsInternal(const UChar*, unsigned length, DateComponents*) const;
    4547};
    4648
  • trunk/WebCore/html/NumberInputType.cpp

    r68629 r68996  
    3232#include "NumberInputType.h"
    3333
     34#include "HTMLParserIdioms.h"
    3435#include <wtf/PassOwnPtr.h>
    3536
     
    4647}
    4748
     49double NumberInputType::parseToDouble(const String& src, double defaultValue) const
     50{
     51    double numberValue;
     52    if (!parseToDoubleForNumberType(src, &numberValue))
     53        return defaultValue;
     54    ASSERT(isfinite(numberValue));
     55    return numberValue;
     56}
     57
    4858} // namespace WebCore
  • trunk/WebCore/html/NumberInputType.h

    r68629 r68996  
    4343    NumberInputType(HTMLInputElement* element) : TextFieldInputType(element) { }
    4444    virtual const AtomicString& formControlType() const;
     45    virtual double parseToDouble(const String&, double) const;
    4546};
    4647
  • trunk/WebCore/html/RangeInputType.cpp

    r68629 r68996  
    3232#include "RangeInputType.h"
    3333
     34#include "HTMLParserIdioms.h"
    3435#include <wtf/PassOwnPtr.h>
    3536
     
    4647}
    4748
     49double RangeInputType::parseToDouble(const String& src, double defaultValue) const
     50{
     51    double numberValue;
     52    if (!parseToDoubleForNumberType(src, &numberValue))
     53        return defaultValue;
     54    ASSERT(isfinite(numberValue));
     55    return numberValue;
     56}
     57
    4858} // namespace WebCore
  • trunk/WebCore/html/RangeInputType.h

    r68629 r68996  
    4343    RangeInputType(HTMLInputElement* element) : InputType(element) { }
    4444    virtual const AtomicString& formControlType() const;
     45    virtual double parseToDouble(const String&, double) const;
    4546};
    4647
  • trunk/WebCore/html/TimeInputType.cpp

    r68629 r68996  
    3232#include "TimeInputType.h"
    3333
     34#include "DateComponents.h"
    3435#include <wtf/PassOwnPtr.h>
    3536
     
    4647}
    4748
     49bool TimeInputType::parseToDateComponentsInternal(const UChar* characters, unsigned length, DateComponents* out) const
     50{
     51    ASSERT(out);
     52    unsigned end;
     53    return out->parseTime(characters, length, 0, end) && end == length;
     54}
     55
    4856} // namespace WebCore
  • trunk/WebCore/html/TimeInputType.h

    r68629 r68996  
    3232#define TimeInputType_h
    3333
    34 #include "TextFieldInputType.h"
     34#include "BaseDateAndTimeInputType.h"
    3535
    3636namespace WebCore {
    3737
    38 class TimeInputType : public TextFieldInputType {
     38class TimeInputType : public BaseDateAndTimeInputType {
    3939public:
    4040    static PassOwnPtr<InputType> create(HTMLInputElement*);
    4141
    4242private:
    43     TimeInputType(HTMLInputElement* element) : TextFieldInputType(element) { }
     43    TimeInputType(HTMLInputElement* element) : BaseDateAndTimeInputType(element) { }
    4444    virtual const AtomicString& formControlType() const;
     45    virtual bool parseToDateComponentsInternal(const UChar*, unsigned length, DateComponents*) const;
    4546};
    4647
  • trunk/WebCore/html/WeekInputType.cpp

    r68629 r68996  
    3232#include "WeekInputType.h"
    3333
     34#include "DateComponents.h"
    3435#include <wtf/PassOwnPtr.h>
    3536
     
    4647}
    4748
     49bool WeekInputType::parseToDateComponentsInternal(const UChar* characters, unsigned length, DateComponents* out) const
     50{
     51    ASSERT(out);
     52    unsigned end;
     53    return out->parseWeek(characters, length, 0, end) && end == length;
     54}
     55
    4856} // namespace WebCore
  • trunk/WebCore/html/WeekInputType.h

    r68629 r68996  
    3232#define WeekInputType_h
    3333
    34 #include "TextFieldInputType.h"
     34#include "BaseDateAndTimeInputType.h"
    3535
    3636namespace WebCore {
    3737
    38 class WeekInputType : public TextFieldInputType {
     38class WeekInputType : public BaseDateAndTimeInputType {
    3939public:
    4040    static PassOwnPtr<InputType> create(HTMLInputElement*);
    4141
    4242private:
    43     WeekInputType(HTMLInputElement* element) : TextFieldInputType(element) { }
     43    WeekInputType(HTMLInputElement* element) : BaseDateAndTimeInputType(element) { }
    4444    virtual const AtomicString& formControlType() const;
     45    virtual bool parseToDateComponentsInternal(const UChar*, unsigned length, DateComponents*) const;
    4546};
    4647
Note: See TracChangeset for help on using the changeset viewer.