Changeset 56385 in webkit


Ignore:
Timestamp:
Mar 23, 2010 4:07:45 AM (14 years ago)
Author:
tkent@chromium.org
Message:

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

Reviewed by Adam Barth.

Add checks if setNeedsWillValidateCheck() and
setNeedsValidityCheck() are called correctly.
https://bugs.webkit.org/show_bug.cgi?id=34924

Introduce HTMLFormControlElement::m_willValidate and
m_isValid. They are the caches of willValidate() and
isValidFormControlElement(). setNeedsWillValidateCheck() updates
m_willValidate and setNeedsValidityCheck() updates m_isValid.

willValidate() and isValidFormControlElement() have assertions to
check m_willvalidate or m_isValid has the correct state. If
setNeedsWillValidateCheck() or setNeedsValidityCheck() is needed
to be called and is not called, these assertions fail.

  • html/HTMLButtonElement.h: (WebCore::HTMLButtonElement::recalcWillValidate):
  • html/HTMLFieldSetElement.h: (WebCore::HTMLFieldSetElement::recalcWillValidate):
  • html/HTMLFormControlElement.cpp: (WebCore::HTMLFormControlElement::HTMLFormControlElement): (WebCore::HTMLFormControlElement::parseMappedAttribute): (WebCore::HTMLFormControlElement::recalcWillValidate): (WebCore::HTMLFormControlElement::willValidate): (WebCore::HTMLFormControlElement::setNeedsWillValidateCheck): (WebCore::HTMLFormControlElement::validationMessage): (WebCore::HTMLFormControlElement::isValidFormControlElement): (WebCore::HTMLFormControlElement::setNeedsValidityCheck):
  • html/HTMLFormControlElement.h:
  • html/HTMLInputElement.cpp: (WebCore::HTMLInputElement::setInputType): (WebCore::HTMLInputElement::parseMappedAttribute): (WebCore::HTMLInputElement::setValue): (WebCore::HTMLInputElement::recalcWillValidate):
  • html/HTMLInputElement.h:
  • html/HTMLTextAreaElement.cpp: (WebCore::HTMLTextAreaElement::setNonDirtyValue):
Location:
trunk/WebCore
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r56383 r56385  
     12010-03-23  Kent Tamura  <tkent@chromium.org>
     2
     3        Reviewed by Adam Barth.
     4
     5        Add checks if setNeedsWillValidateCheck() and
     6        setNeedsValidityCheck() are called correctly.
     7        https://bugs.webkit.org/show_bug.cgi?id=34924
     8
     9        Introduce HTMLFormControlElement::m_willValidate and
     10        m_isValid. They are the caches of willValidate() and
     11        isValidFormControlElement(). setNeedsWillValidateCheck() updates
     12        m_willValidate and setNeedsValidityCheck() updates m_isValid.
     13
     14        willValidate() and isValidFormControlElement() have assertions to
     15        check m_willvalidate or m_isValid has the correct state. If
     16        setNeedsWillValidateCheck() or setNeedsValidityCheck() is needed
     17        to be called and is not called, these assertions fail.
     18
     19        * html/HTMLButtonElement.h:
     20        (WebCore::HTMLButtonElement::recalcWillValidate):
     21        * html/HTMLFieldSetElement.h:
     22        (WebCore::HTMLFieldSetElement::recalcWillValidate):
     23        * html/HTMLFormControlElement.cpp:
     24        (WebCore::HTMLFormControlElement::HTMLFormControlElement):
     25        (WebCore::HTMLFormControlElement::parseMappedAttribute):
     26        (WebCore::HTMLFormControlElement::recalcWillValidate):
     27        (WebCore::HTMLFormControlElement::willValidate):
     28        (WebCore::HTMLFormControlElement::setNeedsWillValidateCheck):
     29        (WebCore::HTMLFormControlElement::validationMessage):
     30        (WebCore::HTMLFormControlElement::isValidFormControlElement):
     31        (WebCore::HTMLFormControlElement::setNeedsValidityCheck):
     32        * html/HTMLFormControlElement.h:
     33        * html/HTMLInputElement.cpp:
     34        (WebCore::HTMLInputElement::setInputType):
     35        (WebCore::HTMLInputElement::parseMappedAttribute):
     36        (WebCore::HTMLInputElement::setValue):
     37        (WebCore::HTMLInputElement::recalcWillValidate):
     38        * html/HTMLInputElement.h:
     39        * html/HTMLTextAreaElement.cpp:
     40        (WebCore::HTMLTextAreaElement::setNonDirtyValue):
     41
    1422010-03-22  Pavel Feldman  <pfeldman@chromium.org>
    243
  • trunk/WebCore/html/HTMLButtonElement.h

    r46062 r56385  
    5858    void setValue(const String&);
    5959
    60     virtual bool willValidate() const { return false; }
    61    
    6260private:
    6361    enum Type { SUBMIT, RESET, BUTTON };
    6462    virtual bool isOptionalFormControl() const { return true; }
     63    virtual bool recalcWillValidate() const { return false; }
    6564
    6665    Type m_type;
  • trunk/WebCore/html/HTMLFieldSetElement.h

    r48106 r56385  
    4848    virtual RenderObject* createRenderer(RenderArena*, RenderStyle*);
    4949    virtual const AtomicString& formControlType() const;
    50 
    51     virtual bool willValidate() const { return false; }
     50private:
     51    virtual bool recalcWillValidate() const { return false; }
    5252};
    5353
  • trunk/WebCore/html/HTMLFormControlElement.cpp

    r55980 r56385  
    5858    , m_required(false)
    5959    , m_valueMatchesRenderer(false)
     60    , m_willValidate(false)
     61    , m_isValid(true)
    6062{
    6163    if (!m_form)
     
    9193void HTMLFormControlElement::parseMappedAttribute(MappedAttribute *attr)
    9294{
    93     bool oldWillValidate = willValidate();
    9495    if (attr->name() == nameAttr)
    9596        m_hasName = !attr->isEmpty();
     
    113114        bool oldRequired = m_required;
    114115        m_required = !attr->isNull();
    115         if (oldRequired != m_required)
    116             setNeedsStyleRecalc();
     116        if (oldRequired != m_required) {
     117            setNeedsValidityCheck();
     118            setNeedsStyleRecalc(); // Updates for :required :optional classes.
     119        }
    117120    } else
    118121        HTMLElement::parseMappedAttribute(attr);
    119     if (oldWillValidate != willValidate())
    120         setNeedsWillValidateCheck();
     122    setNeedsWillValidateCheck();
    121123}
    122124
     
    300302}
    301303
     304bool HTMLFormControlElement::recalcWillValidate() const
     305{
     306    // FIXME: Check if the control does not have a datalist element as an ancestor.
     307    return m_form && m_hasName && !m_disabled && !m_readOnly;
     308}
     309
    302310bool HTMLFormControlElement::willValidate() const
    303311{
    304     // FIXME: Implementation shall be completed with these checks:
    305     //      The control does not have a repetition template as an ancestor.
    306     //      The control does not have a datalist element as an ancestor.
    307     //      The control is not an output element.
    308     return m_form && m_hasName && !m_disabled && !m_readOnly;
    309 }
    310 
    311 String HTMLFormControlElement::validationMessage()
    312 {
    313     return validity()->validationMessage();
     312    // If the following assertion fails, setNeedsWillValidateCheck() is not
     313    // called correctly when something which changes recalcWillValidate() result
     314    // is updated.
     315    ASSERT(m_willValidate == recalcWillValidate());
     316    return m_willValidate;
    314317}
    315318
    316319void HTMLFormControlElement::setNeedsWillValidateCheck()
    317320{
     321    bool newWillValidate = recalcWillValidate();
     322    if (m_willValidate == newWillValidate)
     323        return;
     324    m_willValidate = newWillValidate;
    318325    setNeedsStyleRecalc();
    319326    // FIXME: Show/hide a validation message.
     327}
     328
     329String HTMLFormControlElement::validationMessage()
     330{
     331    return validity()->validationMessage();
    320332}
    321333
     
    330342}
    331343
     344bool HTMLFormControlElement::isValidFormControlElement()
     345{
     346    // If the following assertion fails, setNeedsValidityCheck() is not called
     347    // correctly when something which changes validity is updated.
     348    ASSERT(m_isValid == validity()->valid());
     349    return m_isValid;
     350}
     351
    332352void HTMLFormControlElement::setNeedsValidityCheck()
    333353{
    334     if (willValidate()) {
     354    bool newIsValid = validity()->valid();
     355    if (willValidate() && newIsValid != m_isValid) {
    335356        // Update style for pseudo classes such as :valid :invalid.
    336357        setNeedsStyleRecalc();
    337358    }
     359    m_isValid = newIsValid;
    338360    // FIXME: show/hide a validation message.
    339361}
     
    368390{
    369391    return isSuccessfulSubmitButton() && m_form && m_form->defaultButton() == this;
    370 }
    371 
    372 bool HTMLFormControlElement::isValidFormControlElement()
    373 {
    374     return validity()->valid();
    375392}
    376393
  • trunk/WebCore/html/HTMLFormControlElement.h

    r55980 r56385  
    107107    virtual short tabIndex() const;
    108108
    109     virtual bool willValidate() const;
     109    bool willValidate() const;
    110110    String validationMessage();
    111111    bool checkValidity();
     
    126126    // This must be called any time the result of willValidate() has changed.
    127127    void setNeedsWillValidateCheck();
     128    virtual bool recalcWillValidate() const;
    128129
    129130private:
     
    139140    bool m_required : 1;
    140141    bool m_valueMatchesRenderer : 1;
     142    bool m_willValidate : 1;
     143    // Cache of validity()->valid().
     144    // "candidate for constraint validation" doesn't affect to m_isValid.
     145    bool m_isValid : 1;
    141146};
    142147
  • trunk/WebCore/html/HTMLInputElement.cpp

    r56284 r56385  
    806806    // field's value to something like /etc/passwd and then change it to a file field.
    807807    if (inputType() != newType) {
    808         bool oldWillValidate = willValidate();
    809808        if (newType == FILE && m_haveType)
    810809            // Set the attribute back to the old value.
     
    863862        }
    864863
     864        setNeedsWillValidateCheck();
    865865        setNeedsValidityCheck();
    866         if (oldWillValidate != willValidate())
    867             setNeedsWillValidateCheck();
    868866        InputElement::notifyFormStateChanged(this);
    869867    }
     
    11471145        setNeedsStyleRecalc();
    11481146    else if (attr->name() == minAttr
    1149              || attr->name() == maxAttr
    1150              || attr->name() == multipleAttr
     1147             || attr->name() == maxAttr) {
     1148        if (inputType() == RANGE) {
     1149            // Sanitize the value.
     1150            setValue(value());
     1151            setNeedsStyleRecalc();
     1152        }
     1153        setNeedsValidityCheck();
     1154    } else if (attr->name() == multipleAttr
    11511155             || attr->name() == patternAttr
    11521156             || attr->name() == precisionAttr
     
    15741578    setFormControlValueMatchesRenderer(false);
    15751579    if (storesValueSeparateFromAttribute()) {
    1576         if (inputType() == FILE)
     1580        if (inputType() == FILE) {
    15771581            m_fileList->clear();
    1578         else {
     1582            setNeedsValidityCheck();
     1583        } else {
    15791584            m_data.setValue(sanitizeValue(value));
     1585            // setNeedsValidityCheck() needs to be called after updating the value,
     1586            // before style recalc.
     1587            setNeedsValidityCheck();
    15801588            if (isTextField()) {
    15811589                updatePlaceholderVisibility(false);
     
    15871595            renderer()->updateFromElement();
    15881596        setNeedsStyleRecalc();
    1589     } else
     1597    } else {
    15901598        setAttribute(valueAttr, sanitizeValue(value));
     1599        setNeedsValidityCheck();
     1600    }
    15911601
    15921602    if (isTextField()) {
     
    16051615
    16061616    InputElement::notifyFormStateChanged(this);
    1607     setNeedsValidityCheck();
    16081617}
    16091618
     
    26312640}
    26322641
    2633 bool HTMLInputElement::willValidate() const
    2634 {
    2635     // FIXME: This shall check for new WF2 input types too
    2636     return HTMLFormControlElementWithState::willValidate() && inputType() != HIDDEN &&
    2637            inputType() != BUTTON && inputType() != RESET;
     2642bool HTMLInputElement::recalcWillValidate() const
     2643{
     2644    return HTMLFormControlElementWithState::recalcWillValidate()
     2645        && inputType() != HIDDEN && inputType() != BUTTON && inputType() != RESET;
    26382646}
    26392647
  • trunk/WebCore/html/HTMLInputElement.h

    r56284 r56385  
    262262    virtual void addSubresourceAttributeURLs(ListHashSet<KURL>&) const;
    263263   
    264     virtual bool willValidate() const;
    265 
    266264    // Converts the specified string to a floating number.
    267265    // If the conversion fails, the return value is false. Take care that leading or trailing unnecessary characters make failures.  This returns false for an empty string input.
     
    296294    virtual bool isOptionalFormControl() const { return !isRequiredFormControl(); }
    297295    virtual bool isRequiredFormControl() const;
     296    virtual bool recalcWillValidate() const;
    298297
    299298    PassRefPtr<HTMLFormElement> createTemporaryFormForIsIndex();
  • trunk/WebCore/html/HTMLTextAreaElement.cpp

    r54695 r56385  
    292292
    293293    m_value = normalizedValue;
     294    setNeedsValidityCheck();
    294295    m_isDirty = false;
    295296    setFormControlValueMatchesRenderer(true);
     
    306307    }
    307308
    308     setNeedsValidityCheck();
    309309    notifyFormStateChanged(this);
    310310}
Note: See TracChangeset for help on using the changeset viewer.