Changeset 116756 in webkit


Ignore:
Timestamp:
May 11, 2012 5:56:04 AM (12 years ago)
Author:
commit-queue@webkit.org
Message:

Unreviewed, rolling out r116752.
http://trac.webkit.org/changeset/116752
https://bugs.webkit.org/show_bug.cgi?id=86201

Build failure on Chromium-mac (Requested by tkent on #webkit).

Patch by Sheriff Bot <webkit.review.bot@gmail.com> on 2012-05-11

  • html/FormAssociatedElement.cpp:
  • html/FormAssociatedElement.h:

(FormAssociatedElement):

  • html/HTMLFormControlElement.cpp:

(WebCore::HTMLFormControlElement::setCustomValidity):

  • html/HTMLFormControlElement.h:

(HTMLFormControlElement):

  • html/HTMLInputElement.cpp:

(WebCore::HTMLInputElement::isValidValue):
(WebCore::HTMLInputElement::typeMismatch):
(WebCore::HTMLInputElement::valueMissing):
(WebCore::HTMLInputElement::patternMismatch):
(WebCore::HTMLInputElement::rangeUnderflow):
(WebCore::HTMLInputElement::rangeOverflow):
(WebCore::HTMLInputElement::minimum):
(WebCore::HTMLInputElement::maximum):
(WebCore::HTMLInputElement::stepMismatch):
(WebCore::HTMLInputElement::minimumString):
(WebCore::HTMLInputElement::maximumString):
(WebCore):
(WebCore::HTMLInputElement::stepBaseString):
(WebCore::HTMLInputElement::stepString):
(WebCore::HTMLInputElement::typeMismatchText):
(WebCore::HTMLInputElement::valueMissingText):
(WebCore::HTMLInputElement::isInRange):
(WebCore::HTMLInputElement::isOutOfRange):

  • html/HTMLInputElement.h:

(HTMLInputElement):

  • html/HTMLObjectElement.h:

(WebCore::HTMLObjectElement::setCustomValidity):

  • html/HTMLSelectElement.cpp:

(WebCore::HTMLSelectElement::valueMissing):

  • html/HTMLSelectElement.h:

(HTMLSelectElement):

  • html/HTMLTextAreaElement.cpp:
  • html/HTMLTextAreaElement.h:

(WebCore::HTMLTextAreaElement::valueMissing):
(HTMLTextAreaElement):

  • html/InputType.cpp:

(WebCore::InputType::alignValueForStep):
(WebCore::InputType::stepUpFromRenderer):

  • html/InputType.h:

(InputType):

  • html/ValidityState.cpp:

(WebCore::ValidityState::validationMessage):
(WebCore):
(WebCore::ValidityState::setCustomErrorMessage):
(WebCore::ValidityState::valueMissing):
(WebCore::ValidityState::typeMismatch):
(WebCore::ValidityState::patternMismatch):
(WebCore::ValidityState::tooLong):
(WebCore::ValidityState::rangeUnderflow):
(WebCore::ValidityState::rangeOverflow):
(WebCore::ValidityState::stepMismatch):
(WebCore::ValidityState::customError):
(WebCore::ValidityState::valid):

  • html/ValidityState.h:

(ValidityState):

Location:
trunk/Source/WebCore
Files:
16 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r116755 r116756  
     12012-05-11  Sheriff Bot  <webkit.review.bot@gmail.com>
     2
     3        Unreviewed, rolling out r116752.
     4        http://trac.webkit.org/changeset/116752
     5        https://bugs.webkit.org/show_bug.cgi?id=86201
     6
     7        Build failure on Chromium-mac (Requested by tkent on #webkit).
     8
     9        * html/FormAssociatedElement.cpp:
     10        * html/FormAssociatedElement.h:
     11        (FormAssociatedElement):
     12        * html/HTMLFormControlElement.cpp:
     13        (WebCore::HTMLFormControlElement::setCustomValidity):
     14        * html/HTMLFormControlElement.h:
     15        (HTMLFormControlElement):
     16        * html/HTMLInputElement.cpp:
     17        (WebCore::HTMLInputElement::isValidValue):
     18        (WebCore::HTMLInputElement::typeMismatch):
     19        (WebCore::HTMLInputElement::valueMissing):
     20        (WebCore::HTMLInputElement::patternMismatch):
     21        (WebCore::HTMLInputElement::rangeUnderflow):
     22        (WebCore::HTMLInputElement::rangeOverflow):
     23        (WebCore::HTMLInputElement::minimum):
     24        (WebCore::HTMLInputElement::maximum):
     25        (WebCore::HTMLInputElement::stepMismatch):
     26        (WebCore::HTMLInputElement::minimumString):
     27        (WebCore::HTMLInputElement::maximumString):
     28        (WebCore):
     29        (WebCore::HTMLInputElement::stepBaseString):
     30        (WebCore::HTMLInputElement::stepString):
     31        (WebCore::HTMLInputElement::typeMismatchText):
     32        (WebCore::HTMLInputElement::valueMissingText):
     33        (WebCore::HTMLInputElement::isInRange):
     34        (WebCore::HTMLInputElement::isOutOfRange):
     35        * html/HTMLInputElement.h:
     36        (HTMLInputElement):
     37        * html/HTMLObjectElement.h:
     38        (WebCore::HTMLObjectElement::setCustomValidity):
     39        * html/HTMLSelectElement.cpp:
     40        (WebCore::HTMLSelectElement::valueMissing):
     41        * html/HTMLSelectElement.h:
     42        (HTMLSelectElement):
     43        * html/HTMLTextAreaElement.cpp:
     44        * html/HTMLTextAreaElement.h:
     45        (WebCore::HTMLTextAreaElement::valueMissing):
     46        (HTMLTextAreaElement):
     47        * html/InputType.cpp:
     48        (WebCore::InputType::alignValueForStep):
     49        (WebCore::InputType::stepUpFromRenderer):
     50        * html/InputType.h:
     51        (InputType):
     52        * html/ValidityState.cpp:
     53        (WebCore::ValidityState::validationMessage):
     54        (WebCore):
     55        (WebCore::ValidityState::setCustomErrorMessage):
     56        (WebCore::ValidityState::valueMissing):
     57        (WebCore::ValidityState::typeMismatch):
     58        (WebCore::ValidityState::patternMismatch):
     59        (WebCore::ValidityState::tooLong):
     60        (WebCore::ValidityState::rangeUnderflow):
     61        (WebCore::ValidityState::rangeOverflow):
     62        (WebCore::ValidityState::stepMismatch):
     63        (WebCore::ValidityState::customError):
     64        (WebCore::ValidityState::valid):
     65        * html/ValidityState.h:
     66        (ValidityState):
     67
    1682012-05-11  Alexander Pavlov  <apavlov@chromium.org>
    269
  • trunk/Source/WebCore/html/FormAssociatedElement.cpp

    r116752 r116756  
    158158}
    159159
    160 bool FormAssociatedElement::customError() const
    161 {
    162     const HTMLElement* element = toHTMLElement(this);
    163     return element->willValidate() && !m_customValidationMessage.isEmpty();
    164 }
    165 
    166 bool FormAssociatedElement::patternMismatch() const
    167 {
    168     return false;
    169 }
    170 
    171 bool FormAssociatedElement::rangeOverflow() const
    172 {
    173     return false;
    174 }
    175 
    176 bool FormAssociatedElement::rangeUnderflow() const
    177 {
    178     return false;
    179 }
    180 
    181 bool FormAssociatedElement::stepMismatch() const
    182 {
    183     return false;
    184 }
    185 
    186 bool FormAssociatedElement::tooLong() const
    187 {
    188     return false;
    189 }
    190 
    191 bool FormAssociatedElement::typeMismatch() const
    192 {
    193     return false;
    194 }
    195 
    196 bool FormAssociatedElement::valid() const
    197 {
    198     bool someError = typeMismatch() || stepMismatch() || rangeUnderflow() || rangeOverflow()
    199         || tooLong() || patternMismatch() || valueMissing() || customError();
    200     return !someError;
    201 }
    202 
    203 bool FormAssociatedElement::valueMissing() const
    204 {
    205     return false;
    206 }
    207 
    208 String FormAssociatedElement::customValidationMessage() const
    209 {
    210     return m_customValidationMessage;
    211 }
    212 
    213 String FormAssociatedElement::validationMessage() const
    214 {
    215     return customError() ? m_customValidationMessage : String();
    216 }
    217 
    218 void FormAssociatedElement::setCustomValidity(const String& error)
    219 {
    220     m_customValidationMessage = error;
    221 }
    222 
    223160const HTMLElement* toHTMLElement(const FormAssociatedElement* associatedElement)
    224161{
  • trunk/Source/WebCore/html/FormAssociatedElement.h

    r116752 r116756  
    6161    void formRemovedFromTree(const Node* formRoot);
    6262
    63     // ValidityState attribute implementations
    64     bool customError() const;
    65 
    66     // Override functions for patterMismatch, rangeOverflow, rangerUnderflow,
    67     // stepMismatch, tooLong and valueMissing must call willValidate method.
    68     virtual bool patternMismatch() const;
    69     virtual bool rangeOverflow() const;
    70     virtual bool rangeUnderflow() const;
    71     virtual bool stepMismatch() const;
    72     virtual bool tooLong() const;
    73     virtual bool typeMismatch() const;
    74     virtual bool valueMissing() const;
    75     virtual String validationMessage() const;
    76     bool valid() const;
    77     virtual void setCustomValidity(const String&);
    78 
    7963protected:
    8064    FormAssociatedElement();
     
    9377    virtual void didChangeForm();
    9478
    95     String customValidationMessage() const;
    96 
    9779private:
    9880    virtual const AtomicString& formControlName() const = 0;
     
    10385    HTMLFormElement* m_form;
    10486    OwnPtr<ValidityState> m_validityState;
    105     String m_customValidationMessage;
    10687};
    10788
  • trunk/Source/WebCore/html/HTMLFormControlElement.cpp

    r116752 r116756  
    485485void HTMLFormControlElement::setCustomValidity(const String& error)
    486486{
    487     FormAssociatedElement::setCustomValidity(error);
    488     setNeedsValidityCheck();
     487    validity()->setCustomErrorMessage(error);
    489488}
    490489
  • trunk/Source/WebCore/html/HTMLFormControlElement.h

    r116752 r116756  
    102102    // This must be called when a validation constraint or control value is changed.
    103103    void setNeedsValidityCheck();
    104     virtual void setCustomValidity(const String&) OVERRIDE;
     104    void setCustomValidity(const String&);
    105105
    106106    bool readOnly() const { return m_readOnly; }
  • trunk/Source/WebCore/html/HTMLInputElement.cpp

    r116752 r116756  
    192192    }
    193193    return !m_inputType->typeMismatchFor(value)
    194         && !m_inputType->stepMismatch(value)
    195         && !m_inputType->rangeUnderflow(value)
    196         && !m_inputType->rangeOverflow(value)
     194        && !stepMismatch(value)
     195        && !rangeUnderflow(value)
     196        && !rangeOverflow(value)
    197197        && !tooLong(value, IgnoreDirtyFlag)
    198         && !m_inputType->patternMismatch(value)
    199         && !m_inputType->valueMissing(value);
    200 }
    201 
    202 bool HTMLInputElement::tooLong() const
    203 {
    204     return willValidate() && tooLong(value(), CheckDirtyFlag);
     198        && !patternMismatch(value)
     199        && !valueMissing(value);
    205200}
    206201
    207202bool HTMLInputElement::typeMismatch() const
    208203{
    209     return willValidate() && m_inputType->typeMismatch();
    210 }
    211 
    212 bool HTMLInputElement::valueMissing() const
    213 {
    214     return willValidate() && m_inputType->valueMissing(value());
    215 }
    216 
    217 bool HTMLInputElement::patternMismatch() const
    218 {
    219     return willValidate() && m_inputType->patternMismatch(value());
     204    return m_inputType->typeMismatch();
     205}
     206
     207bool HTMLInputElement::valueMissing(const String& value) const
     208{
     209    return m_inputType->valueMissing(value);
     210}
     211
     212bool HTMLInputElement::patternMismatch(const String& value) const
     213{
     214    return m_inputType->patternMismatch(value);
    220215}
    221216
     
    238233}
    239234
    240 bool HTMLInputElement::rangeUnderflow() const
    241 {
    242     return willValidate() && m_inputType->rangeUnderflow(value());
    243 }
    244 
    245 bool HTMLInputElement::rangeOverflow() const
    246 {
    247     return willValidate() && m_inputType->rangeOverflow(value());
    248 }
    249 
    250 String HTMLInputElement::validationMessage() const
    251 {
    252     if (!willValidate())
     235bool HTMLInputElement::rangeUnderflow(const String& value) const
     236{
     237    return m_inputType->rangeUnderflow(value);
     238}
     239
     240bool HTMLInputElement::rangeOverflow(const String& value) const
     241{
     242    return m_inputType->rangeOverflow(value);
     243}
     244
     245double HTMLInputElement::minimum() const
     246{
     247    return m_inputType->minimum();
     248}
     249
     250double HTMLInputElement::maximum() const
     251{
     252    return m_inputType->maximum();
     253}
     254
     255bool HTMLInputElement::stepMismatch(const String& value) const
     256{
     257    double step;
     258    if (!getAllowedValueStep(&step))
     259        return false;
     260    return m_inputType->stepMismatch(value, step);
     261}
     262
     263String HTMLInputElement::minimumString() const
     264{
     265    return m_inputType->serialize(minimum());
     266}
     267
     268String HTMLInputElement::maximumString() const
     269{
     270    return m_inputType->serialize(maximum());
     271}
     272
     273String HTMLInputElement::stepBaseString() const
     274{
     275    return m_inputType->serialize(m_inputType->stepBase());
     276}
     277
     278String HTMLInputElement::stepString() const
     279{
     280    double step;
     281    if (!getAllowedValueStep(&step)) {
     282        // stepString() should be called only if stepMismatch() can be true.
     283        ASSERT_NOT_REACHED();
    253284        return String();
    254 
    255     if (customError())
    256         return customValidationMessage();
    257 
    258     return m_inputType->validationMessage();
    259 }
    260 
    261 double HTMLInputElement::minimum() const
    262 {
    263     return m_inputType->minimum();
    264 }
    265 
    266 double HTMLInputElement::maximum() const
    267 {
    268     return m_inputType->maximum();
    269 }
    270 
    271 bool HTMLInputElement::stepMismatch() const
    272 {
    273     return willValidate() && m_inputType->stepMismatch(value());
     285    }
     286    return serializeForNumberType(step / m_inputType->stepScaleFactor());
     287}
     288
     289String HTMLInputElement::typeMismatchText() const
     290{
     291    return m_inputType->typeMismatchText();
     292}
     293
     294String HTMLInputElement::valueMissingText() const
     295{
     296    return m_inputType->valueMissingText();
    274297}
    275298
     
    12531276bool HTMLInputElement::isInRange() const
    12541277{
    1255     return m_inputType->supportsRangeLimitation() && !m_inputType->rangeUnderflow(value()) && !m_inputType->rangeOverflow(value());
     1278    return m_inputType->supportsRangeLimitation() && !rangeUnderflow(value()) && !rangeOverflow(value());
    12561279}
    12571280
    12581281bool HTMLInputElement::isOutOfRange() const
    12591282{
    1260     return m_inputType->supportsRangeLimitation() && (m_inputType->rangeUnderflow(value()) || m_inputType->rangeOverflow(value()));
     1283    return m_inputType->supportsRangeLimitation() && (rangeUnderflow(value()) || rangeOverflow(value()));
    12611284}
    12621285
  • trunk/Source/WebCore/html/HTMLInputElement.h

    r116752 r116756  
    4949
    5050    // For ValidityState
    51     virtual bool patternMismatch() const OVERRIDE;
    52     virtual bool rangeUnderflow() const OVERRIDE;
    53     virtual bool rangeOverflow() const;
    54     virtual bool stepMismatch() const OVERRIDE;
    55     virtual bool tooLong() const OVERRIDE;
    56     virtual bool typeMismatch() const OVERRIDE;
    57     virtual bool valueMissing() const OVERRIDE;
    58     virtual String validationMessage() const OVERRIDE;
    59 
     51    bool typeMismatch() const;
     52    // valueMissing() ignores the specified string value for CHECKBOX and RADIO.
     53    bool valueMissing(const String&) const;
     54    bool patternMismatch(const String&) const;
     55    bool tooLong(const String&, NeedsToCheckDirtyFlag) const;
     56    bool rangeUnderflow(const String&) const;
     57    bool rangeOverflow(const String&) const;
    6058    // Returns the minimum value for type=date, number, or range.  Don't call this for other types.
    6159    double minimum() const;
     
    6664    // Returns false if there is no "allowed value step."
    6765    bool getAllowedValueStep(double*) const;
     66
     67    // For ValidityState.
     68    bool stepMismatch(const String&) const;
     69    String minimumString() const;
     70    String maximumString() const;
     71    String stepBaseString() const;
     72    String stepString() const;
     73    String typeMismatchText() const;
     74    String valueMissingText() const;
    6875
    6976    // Implementations of HTMLInputElement::stepUp() and stepDown().
     
    319326    bool supportsMaxLength() const { return isTextType(); }
    320327    bool isTextType() const;
    321     bool tooLong(const String&, NeedsToCheckDirtyFlag) const;
    322328
    323329    virtual bool supportsPlaceholder() const;
  • trunk/Source/WebCore/html/HTMLObjectElement.h

    r116752 r116756  
    5757    String validationMessage() { return String(); }
    5858    bool checkValidity() { return true; }
    59     virtual void setCustomValidity(const String&) OVERRIDE { }
     59    void setCustomValidity(const String&) { }
    6060
    6161    using TreeShared<ContainerNode>::ref;
  • trunk/Source/WebCore/html/HTMLSelectElement.cpp

    r116752 r116756  
    4242#include "HTMLOptionsCollection.h"
    4343#include "KeyboardEvent.h"
    44 #include "LocalizedStrings.h"
    4544#include "MouseEvent.h"
    4645#include "NodeRenderingContext.h"
     
    147146}
    148147
    149 String HTMLSelectElement::validationMessage() const
    150 {
    151     if (!willValidate())
    152         return String();
    153 
    154     if (customError())
    155         return customValidationMessage();
    156 
    157     return valueMissing() ? validationMessageValueMissingForSelectText() : String();
    158 }
    159 
    160148bool HTMLSelectElement::valueMissing() const
    161149{
    162     if (!willValidate())
    163         return false;
    164 
    165150    if (!isRequiredFormControl())
    166151        return false;
  • trunk/Source/WebCore/html/HTMLSelectElement.h

    r116752 r116756  
    4747
    4848    // For ValidityState
    49     virtual String validationMessage() const OVERRIDE;
    50     virtual bool valueMissing() const OVERRIDE;
     49    bool valueMissing() const;
    5150
    5251    unsigned length() const;
  • trunk/Source/WebCore/html/HTMLTextAreaElement.cpp

    r116752 r116756  
    3838#include "Frame.h"
    3939#include "HTMLNames.h"
    40 #include "LocalizedStrings.h"
    4140#include "RenderTextControlMultiLine.h"
    4241#include "ShadowRoot.h"
     
    425424}
    426425
    427 String HTMLTextAreaElement::validationMessage() const
    428 {
    429     if (!willValidate())
    430         return String();
    431 
    432     if (customError())
    433         return customValidationMessage();
    434 
    435     if (valueMissing())
    436         return validationMessageValueMissingText();
    437 
    438     if (tooLong())
    439         return validationMessageTooLongText(numGraphemeClusters(value()), maxLength());
    440 
    441     return String();
    442 }
    443 
    444 bool HTMLTextAreaElement::valueMissing() const
    445 {
    446     return willValidate() && valueMissing(value());
    447 }
    448 
    449 bool HTMLTextAreaElement::tooLong() const
    450 {
    451     return willValidate() && tooLong(value(), CheckDirtyFlag);
    452 }
    453 
    454426bool HTMLTextAreaElement::tooLong(const String& value, NeedsToCheckDirtyFlag check) const
    455427{
  • trunk/Source/WebCore/html/HTMLTextAreaElement.h

    r116752 r116756  
    4848    virtual int maxLength() const;
    4949    void setMaxLength(int, ExceptionCode&);
    50     // For ValidityState
    51     virtual String validationMessage() const OVERRIDE;
    52     virtual bool valueMissing() const OVERRIDE;
    53     virtual bool tooLong() const OVERRIDE;
     50    bool valueMissing(const String& value) const { return isRequiredFormControl() && !disabled() && !readOnly() && value.isEmpty(); }
     51    bool tooLong(const String&, NeedsToCheckDirtyFlag) const;
    5452    bool isValidValue(const String&) const;
    5553   
     
    111109    virtual bool shouldUseInputMethod();
    112110
    113     bool valueMissing(const String& value) const { return isRequiredFormControl() && !disabled() && !readOnly() && value.isEmpty(); }
    114     bool tooLong(const String&, NeedsToCheckDirtyFlag) const;
    115 
    116111    int m_rows;
    117112    int m_cols;
  • trunk/Source/WebCore/html/InputType.cpp

    r116752 r116756  
    284284}
    285285
    286 bool InputType::stepMismatch(const String& value) const
    287 {
    288     double step;
    289     if (!getAllowedValueStep(&step))
    290         return false;
    291     return stepMismatch(value, step);
    292 }
    293 
    294286bool InputType::stepMismatch(const String&, double) const
    295287{
     
    345337{
    346338    return validationMessageValueMissingText();
    347 }
    348 
    349 String InputType::validationMessage() const
    350 {
    351     const String value = element()->value();
    352 
    353     // The order of the following checks is meaningful. e.g. We'd like to show the
    354     // valueMissing message even if the control has other validation errors.
    355     if (valueMissing(value))
    356         return valueMissingText();
    357 
    358     if (typeMismatch())
    359         return typeMismatchText();
    360 
    361     if (patternMismatch(value))
    362         return validationMessagePatternMismatchText();
    363 
    364     if (element()->tooLong())
    365         return validationMessageTooLongText(numGraphemeClusters(value), element()->maxLength());
    366 
    367     if (rangeUnderflow(value))
    368         return validationMessageRangeUnderflowText(serialize(minimum()));
    369 
    370     if (rangeOverflow(value))
    371         return validationMessageRangeOverflowText(serialize(maximum()));
    372 
    373     if (stepMismatch(value)) {
    374         String stepString;
    375         double step;
    376         if (getAllowedValueStep(&step))
    377             stepString = serializeForNumberType(step / stepScaleFactor());
    378         return validationMessageStepMismatchText(serialize(stepBase()), stepString);
    379     }
    380 
    381     return String();
    382339}
    383340
     
    914871    double base = stepBaseWithDecimalPlaces(&baseDecimalPlaces);
    915872    baseDecimalPlaces = min(baseDecimalPlaces, 16u);
    916     if (stepMismatch(element()->value())) {
     873    if (element()->stepMismatch(element()->value())) {
    917874        double scale = pow(10.0, static_cast<double>(max(stepDecimalPlaces, currentDecimalPlaces)));
    918875        newValue = round(newValue * scale) / scale;
     
    10671024    else {
    10681025        ExceptionCode ec;
    1069         if (stepMismatch(element()->value())) {
     1026        if (element()->stepMismatch(element()->value())) {
    10701027            ASSERT(step);
    10711028            double newValue;
  • trunk/Source/WebCore/html/InputType.h

    r116752 r116756  
    141141
    142142    // Validation functions
    143     virtual String validationMessage() const;
     143
    144144    virtual bool supportsValidation() const;
    145145    virtual bool typeMismatchFor(const String&) const;
     
    158158    virtual double maximum() const;
    159159    virtual bool sizeShouldIncludeDecoration(int defaultSize, int& preferredSize) const;
    160     bool stepMismatch(const String&) const;
    161160    virtual bool stepMismatch(const String&, double step) const;
    162161    virtual double stepBase() const;
  • trunk/Source/WebCore/html/ValidityState.cpp

    r116752 r116756  
    3939String ValidityState::validationMessage() const
    4040{
    41     return m_control->validationMessage();
     41    if (!toHTMLElement(m_control)->willValidate())
     42        return String();
     43
     44    if (customError())
     45        return m_customErrorMessage;
     46    HTMLElement* element = toHTMLElement(m_control);
     47    bool isInputElement = element->isFormControlElement() && element->hasTagName(inputTag);
     48    bool isTextAreaElement = element->isFormControlElement() && element->hasTagName(textareaTag);
     49    // The order of the following checks is meaningful. e.g. We'd like to show the
     50    // valueMissing message even if the control has other validation errors.
     51    if (valueMissing()) {
     52        if (element->hasTagName(selectTag))
     53            return validationMessageValueMissingForSelectText();
     54        if (isInputElement)
     55            return static_cast<HTMLInputElement*>(element)->valueMissingText();
     56        return validationMessageValueMissingText();
     57    }
     58    if (typeMismatch()) {
     59        if (isInputElement)
     60            return static_cast<HTMLInputElement*>(element)->typeMismatchText();
     61        return validationMessageTypeMismatchText();
     62    }
     63    if (patternMismatch())
     64        return validationMessagePatternMismatchText();
     65    if (tooLong()) {
     66        if (!isInputElement && !isTextAreaElement) {
     67            ASSERT_NOT_REACHED();
     68            return String();
     69        }
     70        HTMLTextFormControlElement* text = static_cast<HTMLTextFormControlElement*>(element);
     71        return validationMessageTooLongText(numGraphemeClusters(text->value()), text->maxLength());
     72    }
     73    if (rangeUnderflow()) {
     74        if (!isInputElement) {
     75            ASSERT_NOT_REACHED();
     76            return String();
     77        }
     78        return validationMessageRangeUnderflowText(static_cast<HTMLInputElement*>(element)->minimumString());
     79    }
     80    if (rangeOverflow()) {
     81        if (!isInputElement) {
     82            ASSERT_NOT_REACHED();
     83            return String();
     84        }
     85        return validationMessageRangeOverflowText(static_cast<HTMLInputElement*>(element)->maximumString());
     86    }
     87    if (stepMismatch()) {
     88        if (!isInputElement) {
     89            ASSERT_NOT_REACHED();
     90            return String();
     91        }
     92        HTMLInputElement* input = static_cast<HTMLInputElement*>(element);
     93        return validationMessageStepMismatchText(input->stepBaseString(), input->stepString());
     94    }
     95
     96    return String();
     97}
     98
     99void ValidityState::setCustomErrorMessage(const String& message)
     100{
     101    m_customErrorMessage = message;
     102    if (m_control->isFormControlElement())
     103        static_cast<HTMLFormControlElement*>(m_control)->setNeedsValidityCheck();
    42104}
    43105
    44106bool ValidityState::valueMissing() const
    45107{
    46     return m_control->valueMissing();
     108    HTMLElement* element = toHTMLElement(m_control);
     109    if (!element->willValidate())
     110        return false;
     111
     112    if (element->hasTagName(inputTag)) {
     113        HTMLInputElement* input = static_cast<HTMLInputElement*>(element);
     114        return input->valueMissing(input->value());
     115    }
     116    if (element->hasTagName(textareaTag)) {
     117        HTMLTextAreaElement* textArea = static_cast<HTMLTextAreaElement*>(element);
     118        return textArea->valueMissing(textArea->value());
     119    }
     120    if (element->hasTagName(selectTag))
     121        return toHTMLSelectElement(element)->valueMissing();
     122    return false;
    47123}
    48124
    49125bool ValidityState::typeMismatch() const
    50126{
    51     return m_control->typeMismatch();
     127    HTMLElement* element = toHTMLElement(m_control);
     128    if (!element->willValidate())
     129        return false;
     130
     131    if (!element->hasTagName(inputTag))
     132        return false;
     133    return static_cast<HTMLInputElement*>(element)->typeMismatch();
    52134}
    53135
    54136bool ValidityState::patternMismatch() const
    55137{
    56     return m_control->patternMismatch();
     138    HTMLElement* element = toHTMLElement(m_control);
     139    if (!element->willValidate())
     140        return false;
     141
     142    if (!element->hasTagName(inputTag))
     143        return false;
     144    HTMLInputElement* input = static_cast<HTMLInputElement*>(element);
     145    return input->patternMismatch(input->value());
    57146}
    58147
    59148bool ValidityState::tooLong() const
    60149{
    61     return m_control->tooLong();
     150    HTMLElement* element = toHTMLElement(m_control);
     151    if (!element->willValidate())
     152        return false;
     153
     154    if (element->hasTagName(inputTag)) {
     155        HTMLInputElement* input = static_cast<HTMLInputElement*>(element);
     156        return input->tooLong(input->value(), HTMLTextFormControlElement::CheckDirtyFlag);
     157    }
     158    if (element->hasTagName(textareaTag)) {
     159        HTMLTextAreaElement* textArea = static_cast<HTMLTextAreaElement*>(element);
     160        return textArea->tooLong(textArea->value(), HTMLTextFormControlElement::CheckDirtyFlag);
     161    }
     162    return false;
    62163}
    63164
    64165bool ValidityState::rangeUnderflow() const
    65166{
    66     return m_control->rangeUnderflow();
     167    HTMLElement* element = toHTMLElement(m_control);
     168    if (!element->willValidate())
     169        return false;
     170
     171    if (!element->hasTagName(inputTag))
     172        return false;
     173    HTMLInputElement* input = static_cast<HTMLInputElement*>(element);
     174    return input->rangeUnderflow(input->value());
    67175}
    68176
    69177bool ValidityState::rangeOverflow() const
    70178{
    71     return m_control->rangeOverflow();
     179    HTMLElement* element = toHTMLElement(m_control);
     180    if (!element->willValidate())
     181        return false;
     182
     183    if (!element->hasTagName(inputTag))
     184        return false;
     185    HTMLInputElement* input = static_cast<HTMLInputElement*>(element);
     186    return input->rangeOverflow(input->value());
    72187}
    73188
    74189bool ValidityState::stepMismatch() const
    75190{
    76     return m_control->stepMismatch();
     191    HTMLElement* element = toHTMLElement(m_control);
     192    if (!element->willValidate())
     193        return false;
     194
     195    if (!element->hasTagName(inputTag))
     196        return false;
     197    HTMLInputElement* input = static_cast<HTMLInputElement*>(element);
     198    return input->stepMismatch(input->value());
    77199}
    78200
    79201bool ValidityState::customError() const
    80202{
    81     return m_control->customError();
     203    HTMLElement* element = toHTMLElement(m_control);
     204    return element->willValidate() && !m_customErrorMessage.isEmpty();
    82205}
    83206
    84207bool ValidityState::valid() const
    85208{
    86     return m_control->valid();
     209    bool someError = typeMismatch() || stepMismatch() || rangeUnderflow() || rangeOverflow()
     210        || tooLong() || patternMismatch() || valueMissing() || customError();
     211    return !someError;
    87212}
    88213
  • trunk/Source/WebCore/html/ValidityState.h

    r116752 r116756  
    5858    ValidityState(FormAssociatedElement* control) : m_control(control) { }
    5959
     60    static bool isValidColorString(const String&);
     61    static bool isValidEmailAddress(const String&);
     62
    6063    FormAssociatedElement* m_control;
     64    String m_customErrorMessage;
    6165};
    6266
Note: See TracChangeset for help on using the changeset viewer.