Changeset 71994 in webkit


Ignore:
Timestamp:
Nov 14, 2010 8:57:04 PM (13 years ago)
Author:
commit-queue@webkit.org
Message:

2010-11-14 Kenichi Ishibashi <bashi@google.com>

Reviewed by Kent Tamura.

[HTML5] "form" attribute support for form control elements
https://bugs.webkit.org/show_bug.cgi?id=47813

Adds a test file for "form" attribute of form-associated elements.
The test might need to be revised because <label> and <object> don't
support "form" attribute for now, in spite of the HTML5 spec says that
they should support.

  • fast/forms/form-attribute-elements-expected.txt: Added.
  • fast/forms/form-attribute-elements-order-expected.txt: Added.
  • fast/forms/form-attribute-elements-order.html: Added.
  • fast/forms/form-attribute-elements-order2-expected.txt: Added.
  • fast/forms/form-attribute-elements-order2.html: Added.
  • fast/forms/form-attribute-elements.html: Added.
  • fast/forms/form-attribute-expected.txt: Added.
  • fast/forms/form-attribute.html: Added.
  • fast/forms/script-tests/form-attribute-elements-order.js: Added.
  • fast/forms/script-tests/form-attribute-elements-order2.js: Added.
  • fast/forms/script-tests/form-attribute-elements.js: Added.
  • fast/forms/script-tests/form-attribute.js: Added.

2010-11-14 Kenichi Ishibashi <bashi@google.com>

Reviewed by Kent Tamura.

[HTML5] "form" attribute support for form control elements
https://bugs.webkit.org/show_bug.cgi?id=47813

Adds a list of form-associated elements with form attribute into
the Document class to support form attribute.
Adds a function to determine the right place to locate
form-associated elements with form attribute into
m_associatedElements of HTMLFormElement class.

Tests: fast/forms/form-attribute-elements-order.html

fast/forms/form-attribute-elements-order2.html
fast/forms/form-attribute-elements.html
fast/forms/form-attribute.html

  • dom/Document.cpp: (WebCore::Document::registerFormElementWithFormAttribute): Added. (WebCore::Document::unregisterFormElementWithFormAttribute): Added. (WebCore::Document::resetFormElementsOwner): Added.
  • dom/Document.h: Added the list for elements with form attribute.
  • html/HTMLAttributeNames.in: Added form attribute.
  • html/HTMLFormControlElement.cpp: (WebCore::HTMLFormControlElement::insertedIntoTree): Modified to handle form attribute. (WebCore::HTMLFormControlElement::removedFromTree): Ditto. (WebCore::HTMLFormControlElement::resetFormOwner): Added. (WebCore::HTMLFormControlElement::attributeChanged): Added.
  • html/HTMLFormControlElement.h:
  • html/HTMLFormElement.cpp: (WebCore::HTMLFormElement::HTMLFormElement): Modified to initialize newly-added variables. (WebCore::HTMLFormElement::insertedIntoDocument): Modified to reset form owner of form-associated elements. (WebCore::HTMLFormElement::removedFromDocument): Ditto. (WebCore::HTMLFormElement::formElementIndexWithFormAttribute): Added. (WebCore::HTMLFormElement::formElementIndex): Modified to treat form-associated elements with form attribute separately. (WebCore::HTMLFormElement::removeFormElement): Modified to handle form-associated elements with form attribute.
  • html/HTMLFormElement.h: Added three variables to handle form attribute.
  • html/HTMLOutputElement.cpp: Removed "FIXME" comment. (WebCore::HTMLOutputElement::parseMappedAttribute):
  • html/HTMLOutputElement.h: Removed setForm().
Location:
trunk
Files:
12 added
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r71992 r71994  
     12010-11-14  Kenichi Ishibashi  <bashi@google.com>
     2
     3        Reviewed by Kent Tamura.
     4
     5        [HTML5] "form" attribute support for form control elements
     6        https://bugs.webkit.org/show_bug.cgi?id=47813
     7
     8        Adds a test file for "form" attribute of form-associated elements.
     9        The test might need to be revised because <label> and <object> don't
     10        support "form" attribute for now, in spite of the HTML5 spec says that
     11        they should support.
     12
     13        * fast/forms/form-attribute-elements-expected.txt: Added.
     14        * fast/forms/form-attribute-elements-order-expected.txt: Added.
     15        * fast/forms/form-attribute-elements-order.html: Added.
     16        * fast/forms/form-attribute-elements-order2-expected.txt: Added.
     17        * fast/forms/form-attribute-elements-order2.html: Added.
     18        * fast/forms/form-attribute-elements.html: Added.
     19        * fast/forms/form-attribute-expected.txt: Added.
     20        * fast/forms/form-attribute.html: Added.
     21        * fast/forms/script-tests/form-attribute-elements-order.js: Added.
     22        * fast/forms/script-tests/form-attribute-elements-order2.js: Added.
     23        * fast/forms/script-tests/form-attribute-elements.js: Added.
     24        * fast/forms/script-tests/form-attribute.js: Added.
     25
    1262010-11-14  Mihai Parparita  <mihaip@chromium.org>
    227
  • trunk/WebCore/ChangeLog

    r71993 r71994  
     12010-11-14  Kenichi Ishibashi  <bashi@google.com>
     2
     3        Reviewed by Kent Tamura.
     4
     5        [HTML5] "form" attribute support for form control elements
     6        https://bugs.webkit.org/show_bug.cgi?id=47813
     7
     8        Adds a list of form-associated elements with form attribute into
     9        the Document class to support form attribute.
     10        Adds a function to determine the right place to locate
     11        form-associated elements with form attribute into
     12        m_associatedElements of HTMLFormElement class.
     13
     14        Tests: fast/forms/form-attribute-elements-order.html
     15               fast/forms/form-attribute-elements-order2.html
     16               fast/forms/form-attribute-elements.html
     17               fast/forms/form-attribute.html
     18
     19        * dom/Document.cpp:
     20        (WebCore::Document::registerFormElementWithFormAttribute): Added.
     21        (WebCore::Document::unregisterFormElementWithFormAttribute): Added.
     22        (WebCore::Document::resetFormElementsOwner): Added.
     23        * dom/Document.h: Added the list for elements with form attribute.
     24        * html/HTMLAttributeNames.in: Added form attribute.
     25        * html/HTMLFormControlElement.cpp:
     26        (WebCore::HTMLFormControlElement::insertedIntoTree): Modified to handle
     27        form attribute.
     28        (WebCore::HTMLFormControlElement::removedFromTree): Ditto.
     29        (WebCore::HTMLFormControlElement::resetFormOwner): Added.
     30        (WebCore::HTMLFormControlElement::attributeChanged): Added.
     31        * html/HTMLFormControlElement.h:
     32        * html/HTMLFormElement.cpp:
     33        (WebCore::HTMLFormElement::HTMLFormElement): Modified to initialize
     34        newly-added variables.
     35        (WebCore::HTMLFormElement::insertedIntoDocument): Modified to reset
     36        form owner of form-associated elements.
     37        (WebCore::HTMLFormElement::removedFromDocument): Ditto.
     38        (WebCore::HTMLFormElement::formElementIndexWithFormAttribute): Added.
     39        (WebCore::HTMLFormElement::formElementIndex): Modified to treat
     40        form-associated elements with form attribute separately.
     41        (WebCore::HTMLFormElement::removeFormElement): Modified to handle
     42        form-associated elements with form attribute.
     43        * html/HTMLFormElement.h: Added three variables to handle form attribute.
     44        * html/HTMLOutputElement.cpp: Removed "FIXME" comment.
     45        (WebCore::HTMLOutputElement::parseMappedAttribute):
     46        * html/HTMLOutputElement.h: Removed setForm().
     47
    1482010-11-14  David Hyatt  <hyatt@apple.com>
    249
  • trunk/WebCore/dom/Document.cpp

    r71767 r71994  
    43664366}
    43674367
     4368void Document::registerFormElementWithFormAttribute(Element* control)
     4369{
     4370    ASSERT(control->fastHasAttribute(formAttr));
     4371    m_formElementsWithFormAttribute.add(control);
     4372}
     4373
     4374void Document::unregisterFormElementWithFormAttribute(Element* control)
     4375{
     4376    m_formElementsWithFormAttribute.remove(control);
     4377}
     4378
     4379void Document::resetFormElementsOwner(HTMLFormElement* form)
     4380{
     4381    typedef FormElementListHashSet::iterator Iterator;
     4382    Iterator end = m_formElementsWithFormAttribute.end();
     4383    for (Iterator it = m_formElementsWithFormAttribute.begin(); it != end; ++it)
     4384        static_cast<HTMLFormControlElement*>(*it)->resetFormOwner(form);
     4385}
     4386
    43684387void Document::setUseSecureKeyboardEntryWhenActive(bool usesSecureKeyboard)
    43694388{
  • trunk/WebCore/dom/Document.h

    r71543 r71994  
    484484    bool takeStateForFormElement(AtomicStringImpl* name, AtomicStringImpl* type, String& state);
    485485
     486    void registerFormElementWithFormAttribute(Element*);
     487    void unregisterFormElementWithFormAttribute(Element*);
     488    void resetFormElementsOwner(HTMLFormElement*);
     489
    486490    FrameView* view() const; // can be NULL
    487491    Frame* frame() const { return m_frame; } // can be NULL
     
    11981202    typedef ListHashSet<Element*, 64> FormElementListHashSet;
    11991203    FormElementListHashSet m_formElementsWithState;
     1204    FormElementListHashSet m_formElementsWithFormAttribute;
    12001205
    12011206    typedef HashMap<FormElementKey, Vector<String>, FormElementKeyHash, FormElementKeyHashTraits> FormElementStateMap;
  • trunk/WebCore/html/HTMLAttributeNames.in

    r70567 r71994  
    9595focused
    9696for
     97form
    9798formnovalidate
    9899frame
  • trunk/WebCore/html/HTMLFormControlElement.cpp

    r71309 r71994  
    155155void HTMLFormControlElement::insertedIntoTree(bool deep)
    156156{
     157    if (fastHasAttribute(formAttr)) {
     158        document()->registerFormElementWithFormAttribute(this);
     159        Element* element = document()->getElementById(fastGetAttribute(formAttr));
     160        if (element && element->hasTagName(formTag)) {
     161            if (m_form)
     162                m_form->removeFormElement(this);
     163            m_form = static_cast<HTMLFormElement*>(element);
     164            m_form->registerFormElement(this);
     165        }
     166    }
    157167    if (!m_form) {
    158168        // This handles the case of a new form element being created by
     
    180190void HTMLFormControlElement::removedFromTree(bool deep)
    181191{
     192    if (fastHasAttribute(formAttr))
     193        document()->unregisterFormElementWithFormAttribute(this);
     194
    182195    // If the form and element are both in the same tree, preserve the connection to the form.
    183196    // Otherwise, null out our form and remove ourselves from the form's list of elements.
     
    432445}
    433446
     447void HTMLFormControlElement::resetFormOwner(HTMLFormElement* form)
     448{
     449    if (m_form) {
     450        if (!fastHasAttribute(formAttr))
     451            return;
     452        m_form->removeFormElement(this);
     453    }
     454    m_form = 0;
     455    if (fastHasAttribute(formAttr)) {
     456        // The HTML5 spec says that the element should be associated with
     457        // the first element in the document to have an ID that equal to
     458        // the value of form attribute, so we put the result of
     459        // document()->getElementById() over the given element.
     460        Element* firstElement = document()->getElementById(fastGetAttribute(formAttr));
     461        if (firstElement && firstElement->hasTagName(formTag))
     462            m_form = static_cast<HTMLFormElement*>(firstElement);
     463        else
     464            m_form = form;
     465    } else
     466        m_form = findFormAncestor();
     467    if (m_form)
     468        m_form->registerFormElement(this);
     469    else
     470        document()->checkedRadioButtons().addButton(this);
     471}
     472
     473void HTMLFormControlElement::attributeChanged(Attribute* attr, bool preserveDecls)
     474{
     475    if (attr->name() == formAttr) {
     476        if (!fastHasAttribute(formAttr)) {
     477            // The form attribute removed. We need to reset form owner here.
     478            if (m_form)
     479                m_form->removeFormElement(this);
     480            m_form = findFormAncestor();
     481            if (m_form)
     482                m_form->registerFormElement(this);
     483            else
     484                document()->checkedRadioButtons().addButton(this);
     485        } else
     486            resetFormOwner(0);
     487    }
     488    HTMLElement::attributeChanged(attr, preserveDecls);
     489}
     490
    434491bool HTMLFormControlElement::isLabelable() const
    435492{
  • trunk/WebCore/html/HTMLFormControlElement.h

    r71309 r71994  
    100100    bool readOnly() const { return m_readOnly; }
    101101
     102    void resetFormOwner(HTMLFormElement*);
     103    virtual void attributeChanged(Attribute*, bool preserveDecls = false);
     104
    102105protected:
    103106    HTMLFormControlElement(const QualifiedName& tagName, Document*, HTMLFormElement*);
  • trunk/WebCore/html/HTMLFormElement.cpp

    r71309 r71994  
    6666HTMLFormElement::HTMLFormElement(const QualifiedName& tagName, Document* document)
    6767    : HTMLElement(tagName, document)
     68    , m_associatedElementsBeforeIndex(0)
     69    , m_associatedElementsAfterIndex(0)
    6870    , m_wasUserSubmitted(false)
    6971    , m_autocomplete(true)
     
    134136
    135137    HTMLElement::insertedIntoDocument();
     138
     139    if (hasID())
     140        document()->resetFormElementsOwner(this);
    136141}
    137142
     
    142147
    143148    HTMLElement::removedFromDocument();
     149
     150    if (hasID())
     151        document()->resetFormElementsOwner(0);
    144152}
    145153
     
    389397}
    390398
     399unsigned HTMLFormElement::formElementIndexWithFormAttribute(HTMLFormControlElement* element)
     400{
     401    // Compares the position of the form element and the inserted element.
     402    // Updates the indeces in order to the relation of the position:
     403    unsigned short position = compareDocumentPosition(element);
     404    if (position & DOCUMENT_POSITION_CONTAINS)
     405        ++m_associatedElementsAfterIndex;
     406    else if (position & DOCUMENT_POSITION_PRECEDING) {
     407        ++m_associatedElementsBeforeIndex;
     408        ++m_associatedElementsAfterIndex;
     409    }
     410
     411    if (m_associatedElements.isEmpty())
     412        return 0;
     413
     414    // Does binary search on m_associatedElements in order to find the index
     415    // to be inserted.
     416    unsigned left = 0, right = m_associatedElements.size() - 1;
     417    while (left != right) {
     418        unsigned middle = left + ((right - left) / 2);
     419        position = element->compareDocumentPosition(m_associatedElements[middle]);
     420        if (position & DOCUMENT_POSITION_FOLLOWING)
     421            right = middle;
     422        else
     423            left = middle + 1;
     424    }
     425
     426    position = element->compareDocumentPosition(m_associatedElements[left]);
     427    if (position & DOCUMENT_POSITION_FOLLOWING)
     428        return left;
     429    return left + 1;
     430}
     431
    391432unsigned HTMLFormElement::formElementIndex(HTMLFormControlElement* e)
    392433{
     434    // Treats separately the case where this element has the form attribute
     435    // for performance consideration.
     436    if (e->fastHasAttribute(formAttr))
     437        return formElementIndexWithFormAttribute(e);
     438
    393439    // Check for the special case where this element is the very last thing in
    394440    // the form's tree of children; we don't want to walk the entire tree in that
     
    396442    // that says "add this form element to the end of the array".
    397443    if (e->traverseNextNode(this)) {
    398         unsigned i = 0;
     444        unsigned i = m_associatedElementsBeforeIndex;
    399445        for (Node* node = this; node; node = node->traverseNextNode(this)) {
    400             if (node == e)
     446            if (node == e) {
     447                ++m_associatedElementsAfterIndex;
    401448                return i;
     449            }
    402450            if (node->isHTMLElement()
    403451                    && static_cast<Element*>(node)->isFormControlElement()
     
    406454        }
    407455    }
    408     return m_associatedElements.size();
     456    return m_associatedElementsAfterIndex++;
    409457}
    410458
     
    419467{
    420468    m_checkedRadioButtons.removeButton(e);
     469    if (e->fastHasAttribute(formAttr)) {
     470        unsigned index;
     471        for (index = 0; index < m_associatedElements.size(); ++index)
     472            if (m_associatedElements[index] == e)
     473                break;
     474        ASSERT(index < m_associatedElements.size());
     475        if (index < m_associatedElementsBeforeIndex)
     476            --m_associatedElementsBeforeIndex;
     477        if (index < m_associatedElementsAfterIndex)
     478            --m_associatedElementsAfterIndex;
     479    } else
     480        --m_associatedElementsAfterIndex;
    421481    removeFromVector(m_associatedElements, e);
    422482}
  • trunk/WebCore/html/HTMLFormElement.h

    r67240 r71994  
    132132    void submit(Event*, bool activateSubmitButton, bool processingUserGesture, FormSubmissionTrigger);
    133133
     134    unsigned formElementIndexWithFormAttribute(HTMLFormControlElement*);
    134135    unsigned formElementIndex(HTMLFormControlElement*);
    135136    // Returns true if the submission should be proceeded.
     
    149150    CheckedRadioButtons m_checkedRadioButtons;
    150151
     152    unsigned m_associatedElementsBeforeIndex;
     153    unsigned m_associatedElementsAfterIndex;
    151154    Vector<HTMLFormControlElement*> m_associatedElements;
    152155    Vector<HTMLImageElement*> m_imageElements;
  • trunk/WebCore/html/HTMLOutputElement.cpp

    r71373 r71994  
    5959void HTMLOutputElement::parseMappedAttribute(Attribute* attr)
    6060{
    61     // FIXME: Should handle the 'form' attribute here.
    6261    if (attr->name() == HTMLNames::forAttr)
    6362        setFor(attr->value());
     
    7473{
    7574    m_tokens->setValue(value);
    76 }
    77 
    78 void HTMLOutputElement::setForm(const String& /*id*/)
    79 {
    80     // FIXME: Implement this function.
    8175}
    8276
  • trunk/WebCore/html/HTMLOutputElement.h

    r71373 r71994  
    4444    virtual bool willValidate() const { return false; }
    4545
    46     void setForm(const String&);
    4746    String value() const;
    4847    void setValue(const String&);
Note: See TracChangeset for help on using the changeset viewer.