Changeset 54274 in webkit


Ignore:
Timestamp:
Feb 2, 2010 10:56:30 PM (14 years ago)
Author:
tkent@chromium.org
Message:

2010-02-02 Kent Tamura <tkent@chromium.org>

Reviewed by Darin Adler.

Fix a bug that changes for some constraint attributes doesn't
update validation CSS selectors.
https://bugs.webkit.org/show_bug.cgi?id=31716

Add tests for maxLength changes and step changes.

  • fast/forms/input-live-pseudo-selectors-expected.txt:
  • fast/forms/resources/input-live-pseudo-selectors.js:
  • fast/forms/resources/textarea-live-pseudo-selectors.js:
  • fast/forms/textarea-live-pseudo-selectors-expected.txt:

2010-02-02 Kent Tamura <tkent@chromium.org>

Reviewed by Darin Adler.

Fix a bug that changes for some constraint attributes doesn't
update validation CSS selectors.
https://bugs.webkit.org/show_bug.cgi?id=31716

  • Rename HTMLFormControlElement::updateValidity() to setNeedsValidityCheck()
  • Introduce HTMLFormControlElement::setNeedsWillValidate()
  • Introduce HTMLFormControlElement::m_hasName to make willValidate() work in parseMappedAttribute().
  • We need to call setNeedsValidityCheck() when HTMLInputElement::step or HTMLTextAreaElement::maxLength is changed.
  • html/HTMLFormControlElement.cpp: (WebCore::HTMLFormControlElement::HTMLFormControlElement): (WebCore::HTMLFormControlElement::parseMappedAttribute): (WebCore::HTMLFormControlElement::insertedIntoTree): (WebCore::HTMLFormControlElement::removedFromTree): (WebCore::HTMLFormControlElement::formDestroyed): (WebCore::HTMLFormControlElement::willValidate): Avoids function calls. (WebCore::HTMLFormControlElement::setNeedsWillValidateCheck): (WebCore::HTMLFormControlElement::setNeedsValidityCheck):
  • html/HTMLFormControlElement.h: (WebCore::HTMLFormControlElement::disabled): Move the code from .cpp.
  • html/HTMLInputElement.cpp: (WebCore::HTMLInputElement::setInputType): (WebCore::HTMLInputElement::parseMappedAttribute): (WebCore::HTMLInputElement::setValue): (WebCore::HTMLInputElement::setValueFromRenderer): (WebCore::HTMLInputElement::setFileListFromRenderer):
  • html/HTMLTextAreaElement.cpp: (WebCore::HTMLTextAreaElement::parseMappedAttribute): (WebCore::HTMLTextAreaElement::setValue):
  • rendering/RenderTextControlMultiLine.cpp: (WebCore::RenderTextControlMultiLine::subtreeHasChanged):
Location:
trunk
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r54273 r54274  
     12010-02-02  Kent Tamura  <tkent@chromium.org>
     2
     3        Reviewed by Darin Adler.
     4
     5        Fix a bug that changes for some constraint attributes doesn't
     6        update validation CSS selectors.
     7        https://bugs.webkit.org/show_bug.cgi?id=31716
     8
     9        Add tests for maxLength changes and step changes.
     10
     11        * fast/forms/input-live-pseudo-selectors-expected.txt:
     12        * fast/forms/resources/input-live-pseudo-selectors.js:
     13        * fast/forms/resources/textarea-live-pseudo-selectors.js:
     14        * fast/forms/textarea-live-pseudo-selectors-expected.txt:
     15
    1162010-02-02  Roland Steiner  <rolandsteiner@chromium.org>
    217
  • trunk/LayoutTests/fast/forms/input-live-pseudo-selectors-expected.txt

    r49105 r54274  
    3131PASS backgroundOf(el) is invalidColor
    3232PASS backgroundOf(el) is validColor
     33Change step:
     34PASS backgroundOf(el) is validColor
     35PASS backgroundOf(el) is invalidColor
     36PASS backgroundOf(el) is validColor
    3337PASS successfullyParsed is true
    3438
  • trunk/LayoutTests/fast/forms/resources/input-live-pseudo-selectors.js

    r49105 r54274  
    9999shouldBe(elBackground, 'validColor');
    100100
     101debug('Change step:');
     102el = makeInvalid();
     103el.value = '1';
     104el.type = 'number';
     105shouldBe(elBackground, 'validColor');
     106el.step = '2';
     107shouldBe(elBackground, 'invalidColor');
     108el.step = '0.5';
     109shouldBe(elBackground, 'validColor');
    101110
    102111var successfullyParsed = true;
  • trunk/LayoutTests/fast/forms/resources/textarea-live-pseudo-selectors.js

    r49105 r54274  
    9090shouldBe(elBackground, 'invalidColor');
    9191
     92debug('Change maxlength:');
     93el = makeInvalid();
     94el.value = '1234567890';
     95shouldBe(elBackground, 'validColor');
     96// Make the value dirty by deleting the last character.
     97el.focus();
     98el.setSelectionRange(10, 10);
     99document.execCommand('delete');
     100el.maxLength = 5;
     101shouldBe(elBackground, 'invalidColor');
     102el.maxLength = 10;
     103shouldBe(elBackground, 'validColor');
    92104
    93105var successfullyParsed = true;
  • trunk/LayoutTests/fast/forms/textarea-live-pseudo-selectors-expected.txt

    r49105 r54274  
    2727PASS backgroundOf(el) is validColor
    2828PASS backgroundOf(el) is invalidColor
     29Change maxlength:
     30PASS backgroundOf(el) is validColor
     31PASS backgroundOf(el) is invalidColor
     32PASS backgroundOf(el) is validColor
    2933PASS successfullyParsed is true
    3034
  • trunk/WebCore/ChangeLog

    r54273 r54274  
     12010-02-02  Kent Tamura  <tkent@chromium.org>
     2
     3        Reviewed by Darin Adler.
     4
     5        Fix a bug that changes for some constraint attributes doesn't
     6        update validation CSS selectors.
     7        https://bugs.webkit.org/show_bug.cgi?id=31716
     8
     9        - Rename HTMLFormControlElement::updateValidity() to setNeedsValidityCheck()
     10        - Introduce HTMLFormControlElement::setNeedsWillValidate()
     11        - Introduce HTMLFormControlElement::m_hasName to make willValidate()
     12          work in parseMappedAttribute().
     13        - We need to call setNeedsValidityCheck() when HTMLInputElement::step or
     14          HTMLTextAreaElement::maxLength is changed.
     15
     16        * html/HTMLFormControlElement.cpp:
     17        (WebCore::HTMLFormControlElement::HTMLFormControlElement):
     18        (WebCore::HTMLFormControlElement::parseMappedAttribute):
     19        (WebCore::HTMLFormControlElement::insertedIntoTree):
     20        (WebCore::HTMLFormControlElement::removedFromTree):
     21        (WebCore::HTMLFormControlElement::formDestroyed):
     22        (WebCore::HTMLFormControlElement::willValidate): Avoids function calls.
     23        (WebCore::HTMLFormControlElement::setNeedsWillValidateCheck):
     24        (WebCore::HTMLFormControlElement::setNeedsValidityCheck):
     25        * html/HTMLFormControlElement.h:
     26        (WebCore::HTMLFormControlElement::disabled): Move the code from .cpp.
     27        * html/HTMLInputElement.cpp:
     28        (WebCore::HTMLInputElement::setInputType):
     29        (WebCore::HTMLInputElement::parseMappedAttribute):
     30        (WebCore::HTMLInputElement::setValue):
     31        (WebCore::HTMLInputElement::setValueFromRenderer):
     32        (WebCore::HTMLInputElement::setFileListFromRenderer):
     33        * html/HTMLTextAreaElement.cpp:
     34        (WebCore::HTMLTextAreaElement::parseMappedAttribute):
     35        (WebCore::HTMLTextAreaElement::setValue):
     36        * rendering/RenderTextControlMultiLine.cpp:
     37        (WebCore::RenderTextControlMultiLine::subtreeHasChanged):
     38
    1392010-02-02  Roland Steiner  <rolandsteiner@chromium.org>
    240
  • trunk/WebCore/html/HTMLFormControlElement.cpp

    r52967 r54274  
    5353    : HTMLElement(tagName, doc)
    5454    , m_form(f)
     55    , m_hasName(false)
    5556    , m_disabled(false)
    5657    , m_readOnly(false)
     
    9091void HTMLFormControlElement::parseMappedAttribute(MappedAttribute *attr)
    9192{
     93    bool oldWillValidate = willValidate();
    9294    if (attr->name() == nameAttr)
    93         setNeedsStyleRecalc();
     95        m_hasName = !attr->isEmpty();
    9496    else if (attr->name() == disabledAttr) {
    9597        bool oldDisabled = m_disabled;
     
    115117    } else
    116118        HTMLElement::parseMappedAttribute(attr);
     119    if (oldWillValidate != willValidate())
     120        setNeedsWillValidateCheck();
    117121}
    118122
     
    150154        // and so we don't need to do anything.
    151155        m_form = findFormAncestor();
    152         if (m_form)
     156        if (m_form) {
    153157            m_form->registerFormElement(this);
    154         else
     158            setNeedsWillValidateCheck();
     159        } else
    155160            document()->checkedRadioButtons().addButton(this);
    156161    }
     
    179184        m_form->removeFormElement(this);
    180185        m_form = 0;
     186        setNeedsWillValidateCheck();
    181187    }
    182188
    183189    HTMLElement::removedFromTree(deep);
     190}
     191
     192void HTMLFormControlElement::formDestroyed()
     193{
     194    if (m_form)
     195        setNeedsWillValidateCheck();
     196    m_form = 0;
    184197}
    185198
     
    198211{
    199212    dispatchEvent(Event::create(eventNames().changeEvent, true, false));
    200 }
    201 
    202 bool HTMLFormControlElement::disabled() const
    203 {
    204     return m_disabled;
    205213}
    206214
     
    298306    //      The control does not have a datalist element as an ancestor.
    299307    //      The control is not an output element.
    300     return form() && !name().isEmpty() && !disabled() && !isReadOnlyFormControl();
     308    return m_form && m_hasName && !m_disabled && !m_readOnly;
    301309}
    302310
     
    304312{
    305313    return validity()->validationMessage();
     314}
     315
     316void HTMLFormControlElement::setNeedsWillValidateCheck()
     317{
     318    setNeedsStyleRecalc();
     319    // FIXME: Show/hide a validation message.
    306320}
    307321
     
    316330}
    317331
    318 void HTMLFormControlElement::updateValidity()
     332void HTMLFormControlElement::setNeedsValidityCheck()
    319333{
    320334    if (willValidate()) {
     
    322336        setNeedsStyleRecalc();
    323337    }
     338    // FIXME: show/hide a validation message.
    324339}
    325340
  • trunk/WebCore/html/HTMLFormControlElement.h

    r53709 r54274  
    6464    virtual void dispatchFormControlChangeEvent();
    6565
    66     bool disabled() const;
     66    bool disabled() const { return m_disabled; }
    6767    void setDisabled(bool);
    6868
     
    110110    String validationMessage();
    111111    bool checkValidity();
    112     void updateValidity();
     112    // This must be called when a validation constraint or control value is changed.
     113    void setNeedsValidityCheck();
    113114    void setCustomValidity(const String&);
    114115    virtual bool valueMissing() const { return false; }
     
    116117    virtual bool tooLong() const { return false; }
    117118
    118     void formDestroyed() { m_form = 0; }
     119    void formDestroyed();
    119120
    120121    virtual void dispatchFocusEvent();
     
    123124protected:
    124125    void removeFromForm();
     126    // This must be called any time the result of willValidate() has changed.
     127    void setNeedsWillValidateCheck();
    125128
    126129private:
     
    131134    HTMLFormElement* m_form;
    132135    OwnPtr<ValidityState> m_validityState;
     136    bool m_hasName : 1;
    133137    bool m_disabled : 1;
    134138    bool m_readOnly : 1;
  • trunk/WebCore/html/HTMLInputElement.cpp

    r54271 r54274  
    714714    // field's value to something like /etc/passwd and then change it to a file field.
    715715    if (inputType() != newType) {
     716        bool oldWillValidate = willValidate();
    716717        if (newType == FILE && m_haveType)
    717718            // Set the attribute back to the old value.
     
    770771        }
    771772
     773        setNeedsValidityCheck();
     774        if (oldWillValidate != willValidate())
     775            setNeedsWillValidateCheck();
    772776        InputElement::notifyFormStateChanged(this);
    773         updateValidity();
    774777    }
    775778    m_haveType = true;
     
    993996            setNeedsStyleRecalc();
    994997        setFormControlValueMatchesRenderer(false);
    995         updateValidity();
     998        setNeedsValidityCheck();
    996999    } else if (attr->name() == checkedAttr) {
    9971000        m_defaultChecked = !attr->isNull();
     
    10001003            m_useDefaultChecked = true;
    10011004        }
    1002         updateValidity();
    1003     } else if (attr->name() == maxlengthAttr)
     1005        setNeedsValidityCheck();
     1006    } else if (attr->name() == maxlengthAttr) {
    10041007        InputElement::parseMaxLengthAttribute(m_data, this, this, attr);
    1005     else if (attr->name() == sizeAttr)
     1008        setNeedsValidityCheck();
     1009    } else if (attr->name() == sizeAttr)
    10061010        InputElement::parseSizeAttribute(m_data, this, attr);
    10071011    else if (attr->name() == altAttr) {
     
    10471051        }
    10481052        setNeedsStyleRecalc();
    1049     } else if (attr->name() == autosaveAttr ||
    1050              attr->name() == incrementalAttr ||
    1051              attr->name() == minAttr ||
    1052              attr->name() == maxAttr ||
    1053              attr->name() == multipleAttr ||
    1054              attr->name() == precisionAttr)
     1053    } else if (attr->name() == autosaveAttr
     1054               || attr->name() == incrementalAttr)
    10551055        setNeedsStyleRecalc();
    1056     else if (attr->name() == patternAttr)
    1057         updateValidity();
     1056    else if (attr->name() == minAttr
     1057             || attr->name() == maxAttr
     1058             || attr->name() == multipleAttr
     1059             || attr->name() == patternAttr
     1060             || attr->name() == precisionAttr
     1061             || attr->name() == stepAttr)
     1062        setNeedsValidityCheck();
    10581063#if ENABLE(DATALIST)
    10591064    else if (attr->name() == listAttr)
     
    14971502
    14981503    InputElement::notifyFormStateChanged(this);
    1499     updateValidity();
     1504    setNeedsValidityCheck();
    15001505}
    15011506
     
    17711776    updatePlaceholderVisibility(false);
    17721777    InputElement::setValueFromRenderer(m_data, this, this, value);
    1773     updateValidity();
     1778    setNeedsValidityCheck();
    17741779}
    17751780
     
    17831788    setFormControlValueMatchesRenderer(true);
    17841789    InputElement::notifyFormStateChanged(this);
    1785     updateValidity();
     1790    setNeedsValidityCheck();
    17861791}
    17871792
  • trunk/WebCore/html/HTMLTextAreaElement.cpp

    r53132 r54274  
    151151        // Don't map 'align' attribute.  This matches what Firefox, Opera and IE do.
    152152        // See http://bugs.webkit.org/show_bug.cgi?id=7075
    153     } else
     153    } else if (attr->name() == maxlengthAttr)
     154        setNeedsValidityCheck();
     155    else
    154156        HTMLTextFormControlElement::parseMappedAttribute(attr);
    155157}
     
    298300    }
    299301
    300     setNeedsStyleRecalc();
     302    setNeedsValidityCheck();
    301303    notifyFormStateChanged(this);
    302     updateValidity();
    303304}
    304305
  • trunk/WebCore/rendering/RenderTextControlMultiLine.cpp

    r50675 r54274  
    4848    HTMLTextAreaElement* textArea = static_cast<HTMLTextAreaElement*>(node());
    4949    textArea->setFormControlValueMatchesRenderer(false);
    50     textArea->updateValidity();
     50    textArea->setNeedsValidityCheck();
    5151
    5252    if (!node()->focused())
Note: See TracChangeset for help on using the changeset viewer.