Changeset 57274 in webkit


Ignore:
Timestamp:
Apr 8, 2010 7:10:49 AM (14 years ago)
Author:
tkent@chromium.org
Message:

willValidate doesn't need to check existence of a form element and a name attribute.
https://bugs.webkit.org/show_bug.cgi?id=34733

Reviewed by Darin Adler.

WebCore:

Remove checks against m_form and m_hasName in
HTMLFormControlElement::willValidate(), and remove the code to
track their updates.

Test: fast/forms/willvalidate.html

  • html/HTMLFormControlElement.cpp:

(WebCore::HTMLFormControlElement::HTMLFormControlElement):
(WebCore::HTMLFormControlElement::parseMappedAttribute):
(WebCore::HTMLFormControlElement::insertedIntoTree):
(WebCore::HTMLFormControlElement::removedFromTree):
(WebCore::HTMLFormControlElement::recalcWillValidate):
(WebCore::HTMLFormControlElement::willValidate):
(WebCore::HTMLFormControlElement::setNeedsWillValidateCheck):

  • html/HTMLFormControlElement.h:

(WebCore::HTMLFormControlElement::formDestroyed):

  • html/HTMLInputElement.cpp:

(WebCore::HTMLInputElement::setInputType):

setNeedsWillValidateCheck() should be called before
setAttribute(valueAttr, ...) is called.

LayoutTests:

  • Merge willvalidate-00x tests into one file.
  • Update tests affected by the willValidate behavior change.
  • 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/script-tests/willvalidate.js: Added.
  • fast/forms/textarea-live-pseudo-selectors-expected.txt:
  • fast/forms/willvalidate-000-expected.txt: Removed.
  • fast/forms/willvalidate-000.html: Removed.
  • fast/forms/willvalidate-001-expected.txt: Removed.
  • fast/forms/willvalidate-001.html: Removed.
  • fast/forms/willvalidate-002-expected.txt: Removed.
  • fast/forms/willvalidate-002.html: Removed.
  • fast/forms/willvalidate-003-expected.txt: Removed.
  • fast/forms/willvalidate-003.html: Removed.
  • fast/forms/willvalidate-004-expected.txt: Removed.
  • fast/forms/willvalidate-004.html: Removed.
  • fast/forms/willvalidate-005-expected.txt: Removed.
  • fast/forms/willvalidate-005.html: Removed.
  • fast/forms/willvalidate-006-expected.txt: Removed.
  • fast/forms/willvalidate-006.html: Removed.
  • fast/forms/willvalidate-007-expected.txt: Removed.
  • fast/forms/willvalidate-007.html: Removed.
  • fast/forms/willvalidate-008-expected.txt: Removed.
  • fast/forms/willvalidate-008.html: Removed.
  • fast/forms/willvalidate-009-expected.txt: Removed.
  • fast/forms/willvalidate-009.html: Removed.
  • fast/forms/willvalidate-expected.txt: Added.
  • fast/forms/willvalidate.html: Added.
Location:
trunk
Files:
3 added
20 deleted
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r57269 r57274  
     12010-04-08  Kent Tamura  <tkent@chromium.org>
     2
     3        Reviewed by Darin Adler.
     4
     5        willValidate doesn't need to check existence of a form element and a name attribute.
     6        https://bugs.webkit.org/show_bug.cgi?id=34733
     7
     8        - Merge willvalidate-00x tests into one file.
     9        - Update tests affected by the willValidate behavior change.
     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/script-tests/willvalidate.js: Added.
     15        * fast/forms/textarea-live-pseudo-selectors-expected.txt:
     16        * fast/forms/willvalidate-000-expected.txt: Removed.
     17        * fast/forms/willvalidate-000.html: Removed.
     18        * fast/forms/willvalidate-001-expected.txt: Removed.
     19        * fast/forms/willvalidate-001.html: Removed.
     20        * fast/forms/willvalidate-002-expected.txt: Removed.
     21        * fast/forms/willvalidate-002.html: Removed.
     22        * fast/forms/willvalidate-003-expected.txt: Removed.
     23        * fast/forms/willvalidate-003.html: Removed.
     24        * fast/forms/willvalidate-004-expected.txt: Removed.
     25        * fast/forms/willvalidate-004.html: Removed.
     26        * fast/forms/willvalidate-005-expected.txt: Removed.
     27        * fast/forms/willvalidate-005.html: Removed.
     28        * fast/forms/willvalidate-006-expected.txt: Removed.
     29        * fast/forms/willvalidate-006.html: Removed.
     30        * fast/forms/willvalidate-007-expected.txt: Removed.
     31        * fast/forms/willvalidate-007.html: Removed.
     32        * fast/forms/willvalidate-008-expected.txt: Removed.
     33        * fast/forms/willvalidate-008.html: Removed.
     34        * fast/forms/willvalidate-009-expected.txt: Removed.
     35        * fast/forms/willvalidate-009.html: Removed.
     36        * fast/forms/willvalidate-expected.txt: Added.
     37        * fast/forms/willvalidate.html: Added.
     38
    1392010-04-08  Vitaly Repeshko  <vitalyr@chromium.org>
    240
  • trunk/LayoutTests/fast/forms/input-live-pseudo-selectors-expected.txt

    r54274 r57274  
    77PASS backgroundOf(el) is invalidColor
    88Change name:
    9 PASS backgroundOf(el) is normalColor
     9PASS backgroundOf(el) is invalidColor
    1010PASS backgroundOf(el) is invalidColor
    1111Change disabled:
     
    1616PASS backgroundOf(el) is invalidColor
    1717Inside/outside of a form:
    18 PASS backgroundOf(el) is normalColor
     18PASS backgroundOf(el) is invalidColor
    1919PASS backgroundOf(el) is invalidColor
    2020Change the value by DOM attribute:
  • trunk/LayoutTests/fast/forms/resources/input-live-pseudo-selectors.js

    r54274 r57274  
    3737debug('Change name:');
    3838el.name = '';
    39 shouldBe(elBackground, 'normalColor');
     39shouldBe(elBackground, 'invalidColor');
    4040el.name = 'bar';
    4141shouldBe(elBackground, 'invalidColor');
     
    5858el = makeInvalid();
    5959nonForm.appendChild(el);
    60 shouldBe(elBackground, 'normalColor');
     60shouldBe(elBackground, 'invalidColor');
    6161form.appendChild(el);
    6262shouldBe(elBackground, 'invalidColor');
  • trunk/LayoutTests/fast/forms/resources/textarea-live-pseudo-selectors.js

    r54274 r57274  
    3737debug('Change name:');
    3838el.name = '';
    39 shouldBe(elBackground, 'normalColor');
     39shouldBe(elBackground, 'invalidColor');
    4040el.name = 'bar';
    4141shouldBe(elBackground, 'invalidColor');
     
    5858el = makeInvalid();
    5959nonForm.appendChild(el);
    60 shouldBe(elBackground, 'normalColor');
     60shouldBe(elBackground, 'invalidColor');
    6161form.appendChild(el);
    6262shouldBe(elBackground, 'invalidColor');
  • trunk/LayoutTests/fast/forms/textarea-live-pseudo-selectors-expected.txt

    r54274 r57274  
    77PASS backgroundOf(el) is invalidColor
    88Change name:
    9 PASS backgroundOf(el) is normalColor
     9PASS backgroundOf(el) is invalidColor
    1010PASS backgroundOf(el) is invalidColor
    1111Change disabled:
     
    1616PASS backgroundOf(el) is invalidColor
    1717Inside/outside of a form:
    18 PASS backgroundOf(el) is normalColor
     18PASS backgroundOf(el) is invalidColor
    1919PASS backgroundOf(el) is invalidColor
    2020Change the value by DOM attribute:
  • trunk/WebCore/ChangeLog

    r57273 r57274  
     12010-04-08  Kent Tamura  <tkent@chromium.org>
     2
     3        Reviewed by Darin Adler.
     4
     5        willValidate doesn't need to check existence of a form element and a name attribute.
     6        https://bugs.webkit.org/show_bug.cgi?id=34733
     7
     8        Remove checks against m_form and m_hasName in
     9        HTMLFormControlElement::willValidate(), and remove the code to
     10        track their updates.
     11
     12        Test: fast/forms/willvalidate.html
     13
     14        * html/HTMLFormControlElement.cpp:
     15        (WebCore::HTMLFormControlElement::HTMLFormControlElement):
     16        (WebCore::HTMLFormControlElement::parseMappedAttribute):
     17        (WebCore::HTMLFormControlElement::insertedIntoTree):
     18        (WebCore::HTMLFormControlElement::removedFromTree):
     19        (WebCore::HTMLFormControlElement::recalcWillValidate):
     20        (WebCore::HTMLFormControlElement::willValidate):
     21        (WebCore::HTMLFormControlElement::setNeedsWillValidateCheck):
     22        * html/HTMLFormControlElement.h:
     23        (WebCore::HTMLFormControlElement::formDestroyed):
     24        * html/HTMLInputElement.cpp:
     25        (WebCore::HTMLInputElement::setInputType):
     26          setNeedsWillValidateCheck() should be called before
     27          setAttribute(valueAttr, ...) is called.
     28
    1292010-04-08  Young Han Lee  <joybro@company100.net>
    230
  • trunk/WebCore/html/HTMLFormControlElement.cpp

    r57012 r57274  
    5353    : HTMLElement(tagName, doc, constructionType)
    5454    , m_form(f)
    55     , m_hasName(false)
    5655    , m_disabled(false)
    5756    , m_readOnly(false)
    5857    , m_required(false)
    5958    , m_valueMatchesRenderer(false)
    60     , m_willValidate(false)
     59    , m_willValidateInitialized(false)
     60    , m_willValidate(true)
    6161    , m_isValid(true)
    6262{
     
    9393void HTMLFormControlElement::parseMappedAttribute(MappedAttribute *attr)
    9494{
    95     if (attr->name() == nameAttr)
    96         m_hasName = !attr->isEmpty();
    97     else if (attr->name() == disabledAttr) {
     95    if (attr->name() == disabledAttr) {
    9896        bool oldDisabled = m_disabled;
    9997        m_disabled = !attr->isNull();
     
    156154        // and so we don't need to do anything.
    157155        m_form = findFormAncestor();
    158         if (m_form) {
     156        if (m_form)
    159157            m_form->registerFormElement(this);
    160             setNeedsWillValidateCheck();
    161         } else
     158        else
    162159            document()->checkedRadioButtons().addButton(this);
    163160    }
     
    186183        m_form->removeFormElement(this);
    187184        m_form = 0;
    188         setNeedsWillValidateCheck();
    189185    }
    190186
    191187    HTMLElement::removedFromTree(deep);
    192 }
    193 
    194 void HTMLFormControlElement::formDestroyed()
    195 {
    196     if (m_form)
    197         setNeedsWillValidateCheck();
    198     m_form = 0;
    199188}
    200189
     
    304293bool HTMLFormControlElement::recalcWillValidate() const
    305294{
    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;
     295    // FIXME: Should return false if this element has a datalist element as an
     296    // ancestor. See HTML5 4.10.10 'The datalist element.'
     297    return !m_disabled && !m_readOnly;
    308298}
    309299
    310300bool HTMLFormControlElement::willValidate() const
    311301{
    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());
     302    if (!m_willValidateInitialized) {
     303        m_willValidateInitialized = true;
     304        m_willValidate = recalcWillValidate();
     305    } else {
     306        // If the following assertion fails, setNeedsWillValidateCheck() is not
     307        // called correctly when something which changes recalcWillValidate() result
     308        // is updated.
     309        ASSERT(m_willValidate == recalcWillValidate());
     310    }
    316311    return m_willValidate;
    317312}
     
    319314void HTMLFormControlElement::setNeedsWillValidateCheck()
    320315{
     316    // We need to recalculate willValidte immediately because willValidate
     317    // change can causes style change.
    321318    bool newWillValidate = recalcWillValidate();
    322     if (m_willValidate == newWillValidate)
     319    if (m_willValidateInitialized && m_willValidate == newWillValidate)
    323320        return;
     321    m_willValidateInitialized = true;
    324322    m_willValidate = newWillValidate;
    325323    setNeedsStyleRecalc();
  • trunk/WebCore/html/HTMLFormControlElement.h

    r57012 r57274  
    107107    virtual short tabIndex() const;
    108108
    109     bool willValidate() const;
     109    virtual bool willValidate() const;
    110110    String validationMessage();
    111111    bool checkValidity();
     
    117117    virtual bool tooLong() const { return false; }
    118118
    119     void formDestroyed();
     119    void formDestroyed() { m_form = 0; }
    120120
    121121    virtual void dispatchFocusEvent();
     
    135135    HTMLFormElement* m_form;
    136136    OwnPtr<ValidityState> m_validityState;
    137     bool m_hasName : 1;
    138137    bool m_disabled : 1;
    139138    bool m_readOnly : 1;
    140139    bool m_required : 1;
    141140    bool m_valueMatchesRenderer : 1;
    142     bool m_willValidate : 1;
     141    // The initial value of m_willValidate depends on a subclass, and we can't
     142    // initialize it with a virtual function in the constructor. m_willValidate
     143    // is not deterministic during m_willValidateInitialized=false.
     144    mutable bool m_willValidateInitialized: 1;
     145    mutable bool m_willValidate : 1;
    143146    // Cache of validity()->valid().
    144147    // "candidate for constraint validation" doesn't affect to m_isValid.
  • trunk/WebCore/html/HTMLInputElement.cpp

    r57109 r57274  
    818818            bool didRespectHeightAndWidth = respectHeightAndWidthAttrs();
    819819            m_type = newType;
     820            setNeedsWillValidateCheck();
    820821            bool willStoreValue = storesValueSeparateFromAttribute();
    821822            bool isPasswordField = inputType() == PASSWORD;
     
    856857        }
    857858
    858         setNeedsWillValidateCheck();
    859859        setNeedsValidityCheck();
    860860        InputElement::notifyFormStateChanged(this);
Note: See TracChangeset for help on using the changeset viewer.