Changeset 71994 in webkit
- Timestamp:
- Nov 14, 2010 8:57:04 PM (13 years ago)
- Location:
- trunk
- Files:
-
- 12 added
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r71992 r71994 1 2010-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 1 26 2010-11-14 Mihai Parparita <mihaip@chromium.org> 2 27 -
trunk/WebCore/ChangeLog
r71993 r71994 1 2010-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 1 48 2010-11-14 David Hyatt <hyatt@apple.com> 2 49 -
trunk/WebCore/dom/Document.cpp
r71767 r71994 4366 4366 } 4367 4367 4368 void Document::registerFormElementWithFormAttribute(Element* control) 4369 { 4370 ASSERT(control->fastHasAttribute(formAttr)); 4371 m_formElementsWithFormAttribute.add(control); 4372 } 4373 4374 void Document::unregisterFormElementWithFormAttribute(Element* control) 4375 { 4376 m_formElementsWithFormAttribute.remove(control); 4377 } 4378 4379 void 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 4368 4387 void Document::setUseSecureKeyboardEntryWhenActive(bool usesSecureKeyboard) 4369 4388 { -
trunk/WebCore/dom/Document.h
r71543 r71994 484 484 bool takeStateForFormElement(AtomicStringImpl* name, AtomicStringImpl* type, String& state); 485 485 486 void registerFormElementWithFormAttribute(Element*); 487 void unregisterFormElementWithFormAttribute(Element*); 488 void resetFormElementsOwner(HTMLFormElement*); 489 486 490 FrameView* view() const; // can be NULL 487 491 Frame* frame() const { return m_frame; } // can be NULL … … 1198 1202 typedef ListHashSet<Element*, 64> FormElementListHashSet; 1199 1203 FormElementListHashSet m_formElementsWithState; 1204 FormElementListHashSet m_formElementsWithFormAttribute; 1200 1205 1201 1206 typedef HashMap<FormElementKey, Vector<String>, FormElementKeyHash, FormElementKeyHashTraits> FormElementStateMap; -
trunk/WebCore/html/HTMLAttributeNames.in
r70567 r71994 95 95 focused 96 96 for 97 form 97 98 formnovalidate 98 99 frame -
trunk/WebCore/html/HTMLFormControlElement.cpp
r71309 r71994 155 155 void HTMLFormControlElement::insertedIntoTree(bool deep) 156 156 { 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 } 157 167 if (!m_form) { 158 168 // This handles the case of a new form element being created by … … 180 190 void HTMLFormControlElement::removedFromTree(bool deep) 181 191 { 192 if (fastHasAttribute(formAttr)) 193 document()->unregisterFormElementWithFormAttribute(this); 194 182 195 // If the form and element are both in the same tree, preserve the connection to the form. 183 196 // Otherwise, null out our form and remove ourselves from the form's list of elements. … … 432 445 } 433 446 447 void 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 473 void 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 434 491 bool HTMLFormControlElement::isLabelable() const 435 492 { -
trunk/WebCore/html/HTMLFormControlElement.h
r71309 r71994 100 100 bool readOnly() const { return m_readOnly; } 101 101 102 void resetFormOwner(HTMLFormElement*); 103 virtual void attributeChanged(Attribute*, bool preserveDecls = false); 104 102 105 protected: 103 106 HTMLFormControlElement(const QualifiedName& tagName, Document*, HTMLFormElement*); -
trunk/WebCore/html/HTMLFormElement.cpp
r71309 r71994 66 66 HTMLFormElement::HTMLFormElement(const QualifiedName& tagName, Document* document) 67 67 : HTMLElement(tagName, document) 68 , m_associatedElementsBeforeIndex(0) 69 , m_associatedElementsAfterIndex(0) 68 70 , m_wasUserSubmitted(false) 69 71 , m_autocomplete(true) … … 134 136 135 137 HTMLElement::insertedIntoDocument(); 138 139 if (hasID()) 140 document()->resetFormElementsOwner(this); 136 141 } 137 142 … … 142 147 143 148 HTMLElement::removedFromDocument(); 149 150 if (hasID()) 151 document()->resetFormElementsOwner(0); 144 152 } 145 153 … … 389 397 } 390 398 399 unsigned 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 391 432 unsigned HTMLFormElement::formElementIndex(HTMLFormControlElement* e) 392 433 { 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 393 439 // Check for the special case where this element is the very last thing in 394 440 // the form's tree of children; we don't want to walk the entire tree in that … … 396 442 // that says "add this form element to the end of the array". 397 443 if (e->traverseNextNode(this)) { 398 unsigned i = 0;444 unsigned i = m_associatedElementsBeforeIndex; 399 445 for (Node* node = this; node; node = node->traverseNextNode(this)) { 400 if (node == e) 446 if (node == e) { 447 ++m_associatedElementsAfterIndex; 401 448 return i; 449 } 402 450 if (node->isHTMLElement() 403 451 && static_cast<Element*>(node)->isFormControlElement() … … 406 454 } 407 455 } 408 return m_associatedElements .size();456 return m_associatedElementsAfterIndex++; 409 457 } 410 458 … … 419 467 { 420 468 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; 421 481 removeFromVector(m_associatedElements, e); 422 482 } -
trunk/WebCore/html/HTMLFormElement.h
r67240 r71994 132 132 void submit(Event*, bool activateSubmitButton, bool processingUserGesture, FormSubmissionTrigger); 133 133 134 unsigned formElementIndexWithFormAttribute(HTMLFormControlElement*); 134 135 unsigned formElementIndex(HTMLFormControlElement*); 135 136 // Returns true if the submission should be proceeded. … … 149 150 CheckedRadioButtons m_checkedRadioButtons; 150 151 152 unsigned m_associatedElementsBeforeIndex; 153 unsigned m_associatedElementsAfterIndex; 151 154 Vector<HTMLFormControlElement*> m_associatedElements; 152 155 Vector<HTMLImageElement*> m_imageElements; -
trunk/WebCore/html/HTMLOutputElement.cpp
r71373 r71994 59 59 void HTMLOutputElement::parseMappedAttribute(Attribute* attr) 60 60 { 61 // FIXME: Should handle the 'form' attribute here.62 61 if (attr->name() == HTMLNames::forAttr) 63 62 setFor(attr->value()); … … 74 73 { 75 74 m_tokens->setValue(value); 76 }77 78 void HTMLOutputElement::setForm(const String& /*id*/)79 {80 // FIXME: Implement this function.81 75 } 82 76 -
trunk/WebCore/html/HTMLOutputElement.h
r71373 r71994 44 44 virtual bool willValidate() const { return false; } 45 45 46 void setForm(const String&);47 46 String value() const; 48 47 void setValue(const String&);
Note: See TracChangeset
for help on using the changeset viewer.