Changeset 116915 in webkit


Ignore:
Timestamp:
May 13, 2012 9:22:44 PM (12 years ago)
Author:
commit-queue@webkit.org
Message:

[Forms] Move ValidityState methods implementation to another place
https://bugs.webkit.org/show_bug.cgi?id=86058

Patch by Yoshifumi Inoue <yosin@chromium.org> on 2012-05-13
Reviewed by Kent Tamura.

This patch changes ValidityState class for limiting scope of
number/range input type related methods for introducing decimal
arithmetic.

Methods related to validation are moved from ValidateState to
input, select and textarea elements with virtual method based
dispatching via FormAssociateElement instead of tag name
dispatching so far for code simplification.

No new tests. This patch doesn't change behavior.

  • html/FormAssociatedElement.cpp:

(WebCore::FormAssociatedElement::customError): Added. Called from ValidateState. Returns custom error mssage in member variable.
(WebCore::FormAssociatedElement::patternMismatch): Added. Called from ValidateState. This is default implementation.
(WebCore::FormAssociatedElement::rangeOverflow): Added. Called from ValidateState. This is default implementation.
(WebCore::FormAssociatedElement::rangeUnderflow): Added. Called from ValidateState. This is default implementation.
(WebCore::FormAssociatedElement::stepMismatch): Added. Called from ValidateState. This is default implementation.
(WebCore::FormAssociatedElement::tooLong): Added. Called from ValidateState. This is default implementation.
(WebCore::FormAssociatedElement::typeMismatch): Added. Called from ValidateState. This is default implementation.
(WebCore::FormAssociatedElement::valid): Added. Called from ValidateState. This is default implementation.
(WebCore::FormAssociatedElement::valueMissing): Added. Called from ValidateState. This is default implementation.
(WebCore::FormAssociatedElement::customValidationMessage): Added. Called from ValidateState. This is default implementation.
(WebCore::FormAssociatedElement::validationMessage): Added. Called from ValidateState. This is default implementation.
(WebCore::FormAssociatedElement::setCustomValidity): Added. set custom error message.

  • html/FormAssociatedElement.h:

(FormAssociatedElement): Added new instance value m_customValidationMessage.

  • html/HTMLFormControlElement.cpp:

(WebCore::HTMLFormControlElement::validationMessage): Removed. Note: HTMLInputElement, HTMLSelectElement, and HTMLTextAreaElement implement this method.
(WebCore::HTMLFormControlElement::setCustomValidity): Changed. Calls base class setCustomValidity.

  • html/HTMLFormControlElement.h:

(HTMLFormControlElement):

  • html/HTMLInputElement.cpp:

(WebCore::HTMLInputElement::isValidValue): Call m_inputType methods instead of HTMLInputElement's.
(WebCore::HTMLInputElement::tooLong): Call m_inputType methods instead of HTMLInputElement's.
(WebCore):
(WebCore::HTMLInputElement::typeMismatch): Move implementation to InputType.
(WebCore::HTMLInputElement::valueMissing): Move implementation to InputType.
(WebCore::HTMLInputElement::patternMismatch): Move implementation to InputType.
(WebCore::HTMLInputElement::rangeUnderflow): Move implementation to InputType.
(WebCore::HTMLInputElement::rangeOverflow): Move implementation to InputType.
(WebCore::HTMLInputElement::validationMessage): Move implementation to InputType.
(WebCore::HTMLInputElement::stepMismatch): Move implementation to InputType.
(WebCore::HTMLInputElement::isInRange): Call m_inputType methods instead of HTMLInputElement's.
(WebCore::HTMLInputElement::isOutOfRange): Call m_inputType methods instead of HTMLInputElement's.

  • html/HTMLInputElement.h:

(HTMLInputElement): Make tooLong method private.

  • html/HTMLObjectElement.h: Add "virtual" and "OVERRIDE".
  • html/HTMLSelectElement.cpp:

(WebCore::HTMLSelectElement::validationMessage): Added. Implementation for HTMLSelectElement.
(WebCore::HTMLSelectElement::valueMissing): Added. Implementation for HTMLSelectElement.

  • html/HTMLSelectElement.h:

(HTMLSelectElement): Added entries for newly added methods.

  • html/HTMLTextAreaElement.cpp:

(WebCore::HTMLTextAreaElement::validationMessage): Added. Implementation for HTMLTextAreaElement.
(WebCore::HTMLTextAreaElement::valueMissing): Added. Implementation for HTMLTextAreaElement.
(WebCore::HTMLTextAreaElement::tooLong): Added. Implementation for HTMLTextAreaElement.

  • html/HTMLTextAreaElement.h:

(HTMLTextAreaElement): Added entries for newly added methods. Change tooLong and valueMissing private.

  • html/InputType.cpp:

(WebCore::InputType::stepMismatch): Change method signature.
(WebCore::InputType::alignValueForStep): Changed for calling InputClass instead of HTMLINputElement.
(WebCore::InputType::stepUpFromRenderer): Added. Moved from HTMLInputElement.
(WebCore::InputType::validationMessage): Added. Moved from HTMLInputElement.

  • html/InputType.h:

(InputType): Added entries for newly added methods and update methods signature.

  • html/ValidityState.cpp: Move actual implementation to FormAssociatedElement and derived classes for localizing implementation change of elements and input types.

(WebCore::ValidityState::validationMessage): Changed to call FormAssociatedElement's method.
(WebCore::ValidityState::valueMissing): Changed to call FormAssociatedElement's method.
(WebCore::ValidityState::typeMismatch): Changed to call FormAssociatedElement's method.
(WebCore::ValidityState::patternMismatch): Changed to call FormAssociatedElement's method.
(WebCore::ValidityState::tooLong): Changed to call FormAssociatedElement's method.
(WebCore::ValidityState::rangeUnderflow): Changed to call FormAssociatedElement's method.
(WebCore::ValidityState::rangeOverflow): Changed to call FormAssociatedElement's method.
(WebCore::ValidityState::stepMismatch): Changed to call FormAssociatedElement's method.
(WebCore::ValidityState::customError): Changed to call FormAssociatedElement's method.
(WebCore::ValidityState::valid):

  • html/ValidityState.h:

(ValidityState): Remove custom validation message related things.

Location:
trunk/Source/WebCore
Files:
16 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r116914 r116915  
     12012-05-13  Yoshifumi Inoue  <yosin@chromium.org>
     2
     3        [Forms] Move ValidityState methods implementation to another place
     4        https://bugs.webkit.org/show_bug.cgi?id=86058
     5
     6        Reviewed by Kent Tamura.
     7
     8        This patch changes ValidityState class for limiting scope of
     9        number/range input type related methods for introducing decimal
     10        arithmetic.
     11
     12        Methods related to validation are moved from ValidateState to
     13        input, select and textarea elements with virtual method based
     14        dispatching via FormAssociateElement instead of tag name
     15        dispatching so far for code simplification.
     16
     17        No new tests. This patch doesn't change behavior.
     18
     19        * html/FormAssociatedElement.cpp:
     20        (WebCore::FormAssociatedElement::customError): Added. Called from ValidateState. Returns custom error mssage in member variable.
     21        (WebCore::FormAssociatedElement::patternMismatch): Added.  Called from ValidateState. This is default implementation.
     22        (WebCore::FormAssociatedElement::rangeOverflow): Added.  Called from ValidateState. This is default implementation.
     23        (WebCore::FormAssociatedElement::rangeUnderflow): Added.  Called from ValidateState. This is default implementation.
     24        (WebCore::FormAssociatedElement::stepMismatch): Added.  Called from ValidateState. This is default implementation.
     25        (WebCore::FormAssociatedElement::tooLong): Added.  Called from ValidateState. This is default implementation.
     26        (WebCore::FormAssociatedElement::typeMismatch): Added.  Called from ValidateState. This is default implementation.
     27        (WebCore::FormAssociatedElement::valid): Added.  Called from ValidateState. This is default implementation.
     28        (WebCore::FormAssociatedElement::valueMissing): Added.  Called from ValidateState. This is default implementation.
     29        (WebCore::FormAssociatedElement::customValidationMessage): Added.  Called from ValidateState. This is default implementation.
     30        (WebCore::FormAssociatedElement::validationMessage): Added.  Called from ValidateState. This is default implementation.
     31        (WebCore::FormAssociatedElement::setCustomValidity): Added.  set custom error message.
     32        * html/FormAssociatedElement.h:
     33        (FormAssociatedElement): Added new instance value m_customValidationMessage.
     34        * html/HTMLFormControlElement.cpp:
     35        (WebCore::HTMLFormControlElement::validationMessage): Removed. Note: HTMLInputElement, HTMLSelectElement, and HTMLTextAreaElement implement this method.
     36        (WebCore::HTMLFormControlElement::setCustomValidity): Changed. Calls base class setCustomValidity.
     37        * html/HTMLFormControlElement.h:
     38        (HTMLFormControlElement):
     39        * html/HTMLInputElement.cpp:
     40        (WebCore::HTMLInputElement::isValidValue): Call m_inputType methods instead of HTMLInputElement's.
     41        (WebCore::HTMLInputElement::tooLong): Call m_inputType methods instead of HTMLInputElement's.
     42        (WebCore):
     43        (WebCore::HTMLInputElement::typeMismatch): Move implementation to InputType.
     44        (WebCore::HTMLInputElement::valueMissing):  Move implementation to InputType.
     45        (WebCore::HTMLInputElement::patternMismatch): Move implementation to InputType.
     46        (WebCore::HTMLInputElement::rangeUnderflow): Move implementation to InputType.
     47        (WebCore::HTMLInputElement::rangeOverflow): Move implementation to InputType.
     48        (WebCore::HTMLInputElement::validationMessage): Move implementation to InputType.
     49        (WebCore::HTMLInputElement::stepMismatch): Move implementation to InputType.
     50        (WebCore::HTMLInputElement::isInRange): Call m_inputType methods instead of HTMLInputElement's.
     51        (WebCore::HTMLInputElement::isOutOfRange): Call m_inputType methods instead of HTMLInputElement's.
     52        * html/HTMLInputElement.h:
     53        (HTMLInputElement): Make tooLong method private.
     54        * html/HTMLObjectElement.h: Add "virtual" and "OVERRIDE".
     55        * html/HTMLSelectElement.cpp:
     56        (WebCore::HTMLSelectElement::validationMessage): Added. Implementation for HTMLSelectElement.
     57        (WebCore::HTMLSelectElement::valueMissing): Added. Implementation for HTMLSelectElement.
     58        * html/HTMLSelectElement.h:
     59        (HTMLSelectElement):  Added entries for newly added methods.
     60        * html/HTMLTextAreaElement.cpp:
     61        (WebCore::HTMLTextAreaElement::validationMessage): Added. Implementation for HTMLTextAreaElement.
     62        (WebCore::HTMLTextAreaElement::valueMissing): Added. Implementation for HTMLTextAreaElement.
     63        (WebCore::HTMLTextAreaElement::tooLong): Added. Implementation for HTMLTextAreaElement.
     64        * html/HTMLTextAreaElement.h:
     65        (HTMLTextAreaElement): Added entries for newly added methods. Change tooLong and valueMissing private.
     66        * html/InputType.cpp:
     67        (WebCore::InputType::stepMismatch): Change method signature.
     68        (WebCore::InputType::alignValueForStep):  Changed for calling InputClass instead of HTMLINputElement.
     69        (WebCore::InputType::stepUpFromRenderer):  Added. Moved from HTMLInputElement.
     70        (WebCore::InputType::validationMessage): Added.  Moved from HTMLInputElement.
     71        * html/InputType.h:
     72        (InputType): Added entries for newly added methods and update methods signature.
     73        * html/ValidityState.cpp: Move actual implementation to FormAssociatedElement and derived classes for localizing implementation change of elements and input types.
     74        (WebCore::ValidityState::validationMessage): Changed to call FormAssociatedElement's method.
     75        (WebCore::ValidityState::valueMissing): Changed to call FormAssociatedElement's method.
     76        (WebCore::ValidityState::typeMismatch): Changed to call FormAssociatedElement's method.
     77        (WebCore::ValidityState::patternMismatch): Changed to call FormAssociatedElement's method.
     78        (WebCore::ValidityState::tooLong): Changed to call FormAssociatedElement's method.
     79        (WebCore::ValidityState::rangeUnderflow): Changed to call FormAssociatedElement's method.
     80        (WebCore::ValidityState::rangeOverflow): Changed to call FormAssociatedElement's method.
     81        (WebCore::ValidityState::stepMismatch): Changed to call FormAssociatedElement's method.
     82        (WebCore::ValidityState::customError): Changed to call FormAssociatedElement's method.
     83        (WebCore::ValidityState::valid):
     84        * html/ValidityState.h:
     85        (ValidityState): Remove custom validation message related things.
     86
    1872012-05-13  Mike Lawther  <mikelawther@chromium.org>
    288
  • trunk/Source/WebCore/html/FormAssociatedElement.cpp

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

    r116756 r116915  
    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
    6379protected:
    6480    FormAssociatedElement();
     
    7793    virtual void didChangeForm();
    7894
     95    String customValidationMessage() const;
     96
    7997private:
    8098    virtual const AtomicString& formControlName() const = 0;
     
    85103    HTMLFormElement* m_form;
    86104    OwnPtr<ValidityState> m_validityState;
     105    String m_customValidationMessage;
    87106};
    88107
  • trunk/Source/WebCore/html/HTMLFormControlElement.cpp

    r116756 r116915  
    398398}
    399399
    400 String HTMLFormControlElement::validationMessage()
    401 {
    402     return validity()->validationMessage();
    403 }
    404 
    405400void HTMLFormControlElement::updateVisibleValidationMessage()
    406401{
     
    485480void HTMLFormControlElement::setCustomValidity(const String& error)
    486481{
    487     validity()->setCustomErrorMessage(error);
     482    FormAssociatedElement::setCustomValidity(error);
     483    setNeedsValidityCheck();
    488484}
    489485
  • trunk/Source/WebCore/html/HTMLFormControlElement.h

    r116756 r116915  
    9696
    9797    virtual bool willValidate() const;
    98     String validationMessage();
    9998    void updateVisibleValidationMessage();
    10099    void hideVisibleValidationMessage();
     
    102101    // This must be called when a validation constraint or control value is changed.
    103102    void setNeedsValidityCheck();
    104     void setCustomValidity(const String&);
     103    virtual void setCustomValidity(const String&) OVERRIDE;
    105104
    106105    bool readOnly() const { return m_readOnly; }
  • trunk/Source/WebCore/html/HTMLInputElement.cpp

    r116908 r116915  
    192192    }
    193193    return !m_inputType->typeMismatchFor(value)
    194         && !stepMismatch(value)
    195         && !rangeUnderflow(value)
    196         && !rangeOverflow(value)
     194        && !m_inputType->stepMismatch(value)
     195        && !m_inputType->rangeUnderflow(value)
     196        && !m_inputType->rangeOverflow(value)
    197197        && !tooLong(value, IgnoreDirtyFlag)
    198         && !patternMismatch(value)
    199         && !valueMissing(value);
     198        && !m_inputType->patternMismatch(value)
     199        && !m_inputType->valueMissing(value);
     200}
     201
     202bool HTMLInputElement::tooLong() const
     203{
     204    return willValidate() && tooLong(value(), CheckDirtyFlag);
    200205}
    201206
    202207bool HTMLInputElement::typeMismatch() const
    203208{
    204     return m_inputType->typeMismatch();
    205 }
    206 
    207 bool HTMLInputElement::valueMissing(const String& value) const
    208 {
    209     return m_inputType->valueMissing(value);
    210 }
    211 
    212 bool HTMLInputElement::patternMismatch(const String& value) const
    213 {
    214     return m_inputType->patternMismatch(value);
     209    return willValidate() && m_inputType->typeMismatch();
     210}
     211
     212bool HTMLInputElement::valueMissing() const
     213{
     214    return willValidate() && m_inputType->valueMissing(value());
     215}
     216
     217bool HTMLInputElement::patternMismatch() const
     218{
     219    return willValidate() && m_inputType->patternMismatch(value());
    215220}
    216221
     
    233238}
    234239
    235 bool HTMLInputElement::rangeUnderflow(const String& value) const
    236 {
    237     return m_inputType->rangeUnderflow(value);
    238 }
    239 
    240 bool HTMLInputElement::rangeOverflow(const String& value) const
    241 {
    242     return m_inputType->rangeOverflow(value);
     240bool HTMLInputElement::rangeUnderflow() const
     241{
     242    return willValidate() && m_inputType->rangeUnderflow(value());
     243}
     244
     245bool HTMLInputElement::rangeOverflow() const
     246{
     247    return willValidate() && m_inputType->rangeOverflow(value());
     248}
     249
     250String HTMLInputElement::validationMessage() const
     251{
     252    if (!willValidate())
     253        return String();
     254
     255    if (customError())
     256        return customValidationMessage();
     257
     258    return m_inputType->validationMessage();
    243259}
    244260
     
    253269}
    254270
    255 bool 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 
    263 String HTMLInputElement::minimumString() const
    264 {
    265     return m_inputType->serialize(minimum());
    266 }
    267 
    268 String HTMLInputElement::maximumString() const
    269 {
    270     return m_inputType->serialize(maximum());
    271 }
    272 
    273 String HTMLInputElement::stepBaseString() const
    274 {
    275     return m_inputType->serialize(m_inputType->stepBase());
    276 }
    277 
    278 String 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();
    284         return String();
    285     }
    286     return serializeForNumberType(step / m_inputType->stepScaleFactor());
    287 }
    288 
    289 String HTMLInputElement::typeMismatchText() const
    290 {
    291     return m_inputType->typeMismatchText();
    292 }
    293 
    294 String HTMLInputElement::valueMissingText() const
    295 {
    296     return m_inputType->valueMissingText();
     271bool HTMLInputElement::stepMismatch() const
     272{
     273    return willValidate() && m_inputType->stepMismatch(value());
    297274}
    298275
     
    12761253bool HTMLInputElement::isInRange() const
    12771254{
    1278     return m_inputType->supportsRangeLimitation() && !rangeUnderflow(value()) && !rangeOverflow(value());
     1255    return m_inputType->supportsRangeLimitation() && !m_inputType->rangeUnderflow(value()) && !m_inputType->rangeOverflow(value());
    12791256}
    12801257
    12811258bool HTMLInputElement::isOutOfRange() const
    12821259{
    1283     return m_inputType->supportsRangeLimitation() && (rangeUnderflow(value()) || rangeOverflow(value()));
     1260    return m_inputType->supportsRangeLimitation() && (m_inputType->rangeUnderflow(value()) || m_inputType->rangeOverflow(value()));
    12841261}
    12851262
  • trunk/Source/WebCore/html/HTMLInputElement.h

    r116756 r116915  
    4949
    5050    // For ValidityState
    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;
     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
    5860    // Returns the minimum value for type=date, number, or range.  Don't call this for other types.
    5961    double minimum() const;
     
    6466    // Returns false if there is no "allowed value step."
    6567    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;
    7568
    7669    // Implementations of HTMLInputElement::stepUp() and stepDown().
     
    326319    bool supportsMaxLength() const { return isTextType(); }
    327320    bool isTextType() const;
     321    bool tooLong(const String&, NeedsToCheckDirtyFlag) const;
    328322
    329323    virtual bool supportsPlaceholder() const;
  • trunk/Source/WebCore/html/HTMLObjectElement.h

    r116756 r116915  
    5555    // Implementations of constraint validation API.
    5656    // Note that the object elements are always barred from constraint validation.
    57     String validationMessage() { return String(); }
     57    virtual String validationMessage() const OVERRIDE { return String(); }
    5858    bool checkValidity() { return true; }
    59     void setCustomValidity(const String&) { }
     59    virtual void setCustomValidity(const String&) OVERRIDE { }
    6060
    6161    using TreeShared<ContainerNode>::ref;
  • trunk/Source/WebCore/html/HTMLSelectElement.cpp

    r116864 r116915  
    4242#include "HTMLOptionsCollection.h"
    4343#include "KeyboardEvent.h"
     44#include "LocalizedStrings.h"
    4445#include "MouseEvent.h"
    4546#include "NodeRenderingContext.h"
     
    146147}
    147148
     149String 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
    148160bool HTMLSelectElement::valueMissing() const
    149161{
     162    if (!willValidate())
     163        return false;
     164
    150165    if (!isRequiredFormControl())
    151166        return false;
  • trunk/Source/WebCore/html/HTMLSelectElement.h

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

    r116756 r116915  
    3838#include "Frame.h"
    3939#include "HTMLNames.h"
     40#include "LocalizedStrings.h"
    4041#include "RenderTextControlMultiLine.h"
    4142#include "ShadowRoot.h"
     
    424425}
    425426
     427String 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
     444bool HTMLTextAreaElement::valueMissing() const
     445{
     446    return willValidate() && valueMissing(value());
     447}
     448
     449bool HTMLTextAreaElement::tooLong() const
     450{
     451    return willValidate() && tooLong(value(), CheckDirtyFlag);
     452}
     453
    426454bool HTMLTextAreaElement::tooLong(const String& value, NeedsToCheckDirtyFlag check) const
    427455{
  • trunk/Source/WebCore/html/HTMLTextAreaElement.h

    r116756 r116915  
    4848    virtual int maxLength() const;
    4949    void setMaxLength(int, ExceptionCode&);
    50     bool valueMissing(const String& value) const { return isRequiredFormControl() && !disabled() && !readOnly() && value.isEmpty(); }
    51     bool tooLong(const String&, NeedsToCheckDirtyFlag) const;
     50    // For ValidityState
     51    virtual String validationMessage() const OVERRIDE;
     52    virtual bool valueMissing() const OVERRIDE;
     53    virtual bool tooLong() const OVERRIDE;
    5254    bool isValidValue(const String&) const;
    5355   
     
    109111    virtual bool shouldUseInputMethod();
    110112
     113    bool valueMissing(const String& value) const { return isRequiredFormControl() && !disabled() && !readOnly() && value.isEmpty(); }
     114    bool tooLong(const String&, NeedsToCheckDirtyFlag) const;
     115
    111116    int m_rows;
    112117    int m_cols;
  • trunk/Source/WebCore/html/InputType.cpp

    r116756 r116915  
    284284}
    285285
     286bool InputType::stepMismatch(const String& value) const
     287{
     288    double step;
     289    if (!getAllowedValueStep(&step))
     290        return false;
     291    return stepMismatch(value, step);
     292}
     293
    286294bool InputType::stepMismatch(const String&, double) const
    287295{
     
    337345{
    338346    return validationMessageValueMissingText();
     347}
     348
     349String 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();
    339382}
    340383
     
    871914    double base = stepBaseWithDecimalPlaces(&baseDecimalPlaces);
    872915    baseDecimalPlaces = min(baseDecimalPlaces, 16u);
    873     if (element()->stepMismatch(element()->value())) {
     916    if (stepMismatch(element()->value())) {
    874917        double scale = pow(10.0, static_cast<double>(max(stepDecimalPlaces, currentDecimalPlaces)));
    875918        newValue = round(newValue * scale) / scale;
     
    10241067    else {
    10251068        ExceptionCode ec;
    1026         if (element()->stepMismatch(element()->value())) {
     1069        if (stepMismatch(element()->value())) {
    10271070            ASSERT(step);
    10281071            double newValue;
  • trunk/Source/WebCore/html/InputType.h

    r116756 r116915  
    141141
    142142    // Validation functions
    143 
     143    virtual String validationMessage() const;
    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;
    160161    virtual bool stepMismatch(const String&, double step) const;
    161162    virtual double stepBase() const;
  • trunk/Source/WebCore/html/ValidityState.cpp

    r116756 r116915  
    3939String ValidityState::validationMessage() const
    4040{
    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 
    99 void ValidityState::setCustomErrorMessage(const String& message)
    100 {
    101     m_customErrorMessage = message;
    102     if (m_control->isFormControlElement())
    103         static_cast<HTMLFormControlElement*>(m_control)->setNeedsValidityCheck();
     41    return m_control->validationMessage();
    10442}
    10543
    10644bool ValidityState::valueMissing() const
    10745{
    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;
     46    return m_control->valueMissing();
    12347}
    12448
    12549bool ValidityState::typeMismatch() const
    12650{
    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();
     51    return m_control->typeMismatch();
    13452}
    13553
    13654bool ValidityState::patternMismatch() const
    13755{
    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());
     56    return m_control->patternMismatch();
    14657}
    14758
    14859bool ValidityState::tooLong() const
    14960{
    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;
     61    return m_control->tooLong();
    16362}
    16463
    16564bool ValidityState::rangeUnderflow() const
    16665{
    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());
     66    return m_control->rangeUnderflow();
    17567}
    17668
    17769bool ValidityState::rangeOverflow() const
    17870{
    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());
     71    return m_control->rangeOverflow();
    18772}
    18873
    18974bool ValidityState::stepMismatch() const
    19075{
    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());
     76    return m_control->stepMismatch();
    19977}
    20078
    20179bool ValidityState::customError() const
    20280{
    203     HTMLElement* element = toHTMLElement(m_control);
    204     return element->willValidate() && !m_customErrorMessage.isEmpty();
     81    return m_control->customError();
    20582}
    20683
    20784bool ValidityState::valid() const
    20885{
    209     bool someError = typeMismatch() || stepMismatch() || rangeUnderflow() || rangeOverflow()
    210         || tooLong() || patternMismatch() || valueMissing() || customError();
    211     return !someError;
     86    return m_control->valid();
    21287}
    21388
  • trunk/Source/WebCore/html/ValidityState.h

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