Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
| 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) | 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) |
| 4 * (C) 2001 Dirk Mueller (mueller@kde.org) | 4 * (C) 2001 Dirk Mueller (mueller@kde.org) |
| 5 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights | 5 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights |
| 6 * reserved. | 6 * reserved. |
| 7 * (C) 2006 Alexey Proskuryakov (ap@nypop.com) | 7 * (C) 2006 Alexey Proskuryakov (ap@nypop.com) |
| 8 * | 8 * |
| 9 * This library is free software; you can redistribute it and/or | 9 * This library is free software; you can redistribute it and/or |
| 10 * modify it under the terms of the GNU Library General Public | 10 * modify it under the terms of the GNU Library General Public |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 148 for (const auto& element : elements) | 148 for (const auto& element : elements) |
| 149 element->formRemovedFromTree(root); | 149 element->formRemovedFromTree(root); |
| 150 } | 150 } |
| 151 | 151 |
| 152 void HTMLFormElement::removedFrom(ContainerNode* insertionPoint) { | 152 void HTMLFormElement::removedFrom(ContainerNode* insertionPoint) { |
| 153 // We don't need to take care of form association by 'form' content | 153 // We don't need to take care of form association by 'form' content |
| 154 // attribute becuse IdTargetObserver handles it. | 154 // attribute becuse IdTargetObserver handles it. |
| 155 if (m_hasElementsAssociatedByParser) { | 155 if (m_hasElementsAssociatedByParser) { |
| 156 Node& root = NodeTraversal::highestAncestorOrSelf(*this); | 156 Node& root = NodeTraversal::highestAncestorOrSelf(*this); |
| 157 if (!m_associatedElementsAreDirty) { | 157 if (!m_associatedElementsAreDirty) { |
| 158 FormAssociatedElement::List elements(associatedElements()); | 158 ListedElement::List elements(associatedElements()); |
| 159 notifyFormRemovedFromTree(elements, root); | 159 notifyFormRemovedFromTree(elements, root); |
| 160 } else { | 160 } else { |
| 161 FormAssociatedElement::List elements; | 161 ListedElement::List elements; |
| 162 collectAssociatedElements( | 162 collectAssociatedElements( |
| 163 NodeTraversal::highestAncestorOrSelf(*insertionPoint), elements); | 163 NodeTraversal::highestAncestorOrSelf(*insertionPoint), elements); |
| 164 notifyFormRemovedFromTree(elements, root); | 164 notifyFormRemovedFromTree(elements, root); |
| 165 collectAssociatedElements(root, elements); | 165 collectAssociatedElements(root, elements); |
| 166 notifyFormRemovedFromTree(elements, root); | 166 notifyFormRemovedFromTree(elements, root); |
| 167 } | 167 } |
| 168 | 168 |
| 169 if (!m_imageElementsAreDirty) { | 169 if (!m_imageElementsAreDirty) { |
| 170 HeapVector<Member<HTMLImageElement>> images(imageElements()); | 170 HeapVector<Member<HTMLImageElement>> images(imageElements()); |
| 171 notifyFormRemovedFromTree(images, root); | 171 notifyFormRemovedFromTree(images, root); |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 187 if (event.eventPhase() != Event::kCapturingPhase && targetNode && | 187 if (event.eventPhase() != Event::kCapturingPhase && targetNode && |
| 188 targetNode != this && (event.type() == EventTypeNames::submit || | 188 targetNode != this && (event.type() == EventTypeNames::submit || |
| 189 event.type() == EventTypeNames::reset)) { | 189 event.type() == EventTypeNames::reset)) { |
| 190 event.stopPropagation(); | 190 event.stopPropagation(); |
| 191 return; | 191 return; |
| 192 } | 192 } |
| 193 HTMLElement::handleLocalEvents(event); | 193 HTMLElement::handleLocalEvents(event); |
| 194 } | 194 } |
| 195 | 195 |
| 196 unsigned HTMLFormElement::length() const { | 196 unsigned HTMLFormElement::length() const { |
| 197 const FormAssociatedElement::List& elements = associatedElements(); | 197 const ListedElement::List& elements = associatedElements(); |
| 198 unsigned len = 0; | 198 unsigned len = 0; |
| 199 for (unsigned i = 0; i < elements.size(); ++i) { | 199 for (unsigned i = 0; i < elements.size(); ++i) { |
| 200 if (elements[i]->isEnumeratable()) | 200 if (elements[i]->isEnumeratable()) |
| 201 ++len; | 201 ++len; |
| 202 } | 202 } |
| 203 return len; | 203 return len; |
| 204 } | 204 } |
| 205 | 205 |
| 206 HTMLElement* HTMLFormElement::item(unsigned index) { | 206 HTMLElement* HTMLFormElement::item(unsigned index) { |
| 207 return elements()->item(index); | 207 return elements()->item(index); |
| 208 } | 208 } |
| 209 | 209 |
| 210 void HTMLFormElement::submitImplicitly(Event* event, | 210 void HTMLFormElement::submitImplicitly(Event* event, |
| 211 bool fromImplicitSubmissionTrigger) { | 211 bool fromImplicitSubmissionTrigger) { |
| 212 int submissionTriggerCount = 0; | 212 int submissionTriggerCount = 0; |
| 213 bool seenDefaultButton = false; | 213 bool seenDefaultButton = false; |
| 214 const FormAssociatedElement::List& elements = associatedElements(); | 214 const ListedElement::List& elements = associatedElements(); |
| 215 for (unsigned i = 0; i < elements.size(); ++i) { | 215 for (unsigned i = 0; i < elements.size(); ++i) { |
| 216 FormAssociatedElement* formAssociatedElement = elements[i]; | 216 ListedElement* ListedElement = elements[i]; |
|
tkent
2016/12/02 13:24:37
Rename this variable to listedElement (lower l)
| |
| 217 if (!formAssociatedElement->isFormControlElement()) | 217 if (!ListedElement->isFormControlElement()) |
| 218 continue; | 218 continue; |
| 219 HTMLFormControlElement* control = | 219 HTMLFormControlElement* control = toHTMLFormControlElement(ListedElement); |
| 220 toHTMLFormControlElement(formAssociatedElement); | |
| 221 if (!seenDefaultButton && control->canBeSuccessfulSubmitButton()) { | 220 if (!seenDefaultButton && control->canBeSuccessfulSubmitButton()) { |
| 222 if (fromImplicitSubmissionTrigger) | 221 if (fromImplicitSubmissionTrigger) |
| 223 seenDefaultButton = true; | 222 seenDefaultButton = true; |
| 224 if (control->isSuccessfulSubmitButton()) { | 223 if (control->isSuccessfulSubmitButton()) { |
| 225 control->dispatchSimulatedClick(event); | 224 control->dispatchSimulatedClick(event); |
| 226 return; | 225 return; |
| 227 } | 226 } |
| 228 if (fromImplicitSubmissionTrigger) { | 227 if (fromImplicitSubmissionTrigger) { |
| 229 // Default (submit) button is not activated; no implicit submission. | 228 // Default (submit) button is not activated; no implicit submission. |
| 230 return; | 229 return; |
| 231 } | 230 } |
| 232 } else if (control->canTriggerImplicitSubmission()) { | 231 } else if (control->canTriggerImplicitSubmission()) { |
| 233 ++submissionTriggerCount; | 232 ++submissionTriggerCount; |
| 234 } | 233 } |
| 235 } | 234 } |
| 236 if (fromImplicitSubmissionTrigger && submissionTriggerCount == 1) | 235 if (fromImplicitSubmissionTrigger && submissionTriggerCount == 1) |
| 237 prepareForSubmission(event, nullptr); | 236 prepareForSubmission(event, nullptr); |
| 238 } | 237 } |
| 239 | 238 |
| 240 bool HTMLFormElement::validateInteractively() { | 239 bool HTMLFormElement::validateInteractively() { |
| 241 UseCounter::count(document(), UseCounter::FormValidationStarted); | 240 UseCounter::count(document(), UseCounter::FormValidationStarted); |
| 242 const FormAssociatedElement::List& elements = associatedElements(); | 241 const ListedElement::List& elements = associatedElements(); |
| 243 for (unsigned i = 0; i < elements.size(); ++i) { | 242 for (unsigned i = 0; i < elements.size(); ++i) { |
| 244 if (elements[i]->isFormControlElement()) | 243 if (elements[i]->isFormControlElement()) |
| 245 toHTMLFormControlElement(elements[i])->hideVisibleValidationMessage(); | 244 toHTMLFormControlElement(elements[i])->hideVisibleValidationMessage(); |
| 246 } | 245 } |
| 247 | 246 |
| 248 HeapVector<Member<HTMLFormControlElement>> unhandledInvalidControls; | 247 HeapVector<Member<HTMLFormControlElement>> unhandledInvalidControls; |
| 249 if (!checkInvalidControlsAndCollectUnhandled( | 248 if (!checkInvalidControlsAndCollectUnhandled( |
| 250 &unhandledInvalidControls, CheckValidityDispatchInvalidEvent)) | 249 &unhandledInvalidControls, CheckValidityDispatchInvalidEvent)) |
| 251 return true; | 250 return true; |
| 252 UseCounter::count(document(), UseCounter::FormValidationAbortedSubmission); | 251 UseCounter::count(document(), UseCounter::FormValidationAbortedSubmission); |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 466 return; | 465 return; |
| 467 | 466 |
| 468 m_isInResetFunction = true; | 467 m_isInResetFunction = true; |
| 469 | 468 |
| 470 if (dispatchEvent(Event::createCancelableBubble(EventTypeNames::reset)) != | 469 if (dispatchEvent(Event::createCancelableBubble(EventTypeNames::reset)) != |
| 471 DispatchEventResult::NotCanceled) { | 470 DispatchEventResult::NotCanceled) { |
| 472 m_isInResetFunction = false; | 471 m_isInResetFunction = false; |
| 473 return; | 472 return; |
| 474 } | 473 } |
| 475 | 474 |
| 476 const FormAssociatedElement::List& elements = associatedElements(); | 475 const ListedElement::List& elements = associatedElements(); |
| 477 for (unsigned i = 0; i < elements.size(); ++i) { | 476 for (unsigned i = 0; i < elements.size(); ++i) { |
| 478 if (elements[i]->isFormControlElement()) | 477 if (elements[i]->isFormControlElement()) |
| 479 toHTMLFormControlElement(elements[i])->reset(); | 478 toHTMLFormControlElement(elements[i])->reset(); |
| 480 } | 479 } |
| 481 | 480 |
| 482 m_isInResetFunction = false; | 481 m_isInResetFunction = false; |
| 483 } | 482 } |
| 484 | 483 |
| 485 void HTMLFormElement::parseAttribute(const QualifiedName& name, | 484 void HTMLFormElement::parseAttribute(const QualifiedName& name, |
| 486 const AtomicString& oldValue, | 485 const AtomicString& oldValue, |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 507 m_attributes.updateMethodType(value); | 506 m_attributes.updateMethodType(value); |
| 508 } else if (name == enctypeAttr) { | 507 } else if (name == enctypeAttr) { |
| 509 m_attributes.updateEncodingType(value); | 508 m_attributes.updateEncodingType(value); |
| 510 } else if (name == accept_charsetAttr) { | 509 } else if (name == accept_charsetAttr) { |
| 511 m_attributes.setAcceptCharset(value); | 510 m_attributes.setAcceptCharset(value); |
| 512 } else { | 511 } else { |
| 513 HTMLElement::parseAttribute(name, oldValue, value); | 512 HTMLElement::parseAttribute(name, oldValue, value); |
| 514 } | 513 } |
| 515 } | 514 } |
| 516 | 515 |
| 517 void HTMLFormElement::associate(FormAssociatedElement& e) { | 516 void HTMLFormElement::associate(ListedElement& e) { |
| 518 m_associatedElementsAreDirty = true; | 517 m_associatedElementsAreDirty = true; |
| 519 m_associatedElements.clear(); | 518 m_associatedElements.clear(); |
| 520 if (toHTMLElement(e).fastHasAttribute(formAttr)) | 519 if (toHTMLElement(e).fastHasAttribute(formAttr)) |
| 521 m_hasElementsAssociatedByFormAttribute = true; | 520 m_hasElementsAssociatedByFormAttribute = true; |
| 522 } | 521 } |
| 523 | 522 |
| 524 void HTMLFormElement::disassociate(FormAssociatedElement& e) { | 523 void HTMLFormElement::disassociate(ListedElement& e) { |
| 525 m_associatedElementsAreDirty = true; | 524 m_associatedElementsAreDirty = true; |
| 526 m_associatedElements.clear(); | 525 m_associatedElements.clear(); |
| 527 removeFromPastNamesMap(toHTMLElement(e)); | 526 removeFromPastNamesMap(toHTMLElement(e)); |
| 528 } | 527 } |
| 529 | 528 |
| 530 bool HTMLFormElement::isURLAttribute(const Attribute& attribute) const { | 529 bool HTMLFormElement::isURLAttribute(const Attribute& attribute) const { |
| 531 return attribute.name() == actionAttr || | 530 return attribute.name() == actionAttr || |
| 532 HTMLElement::isURLAttribute(attribute); | 531 HTMLElement::isURLAttribute(attribute); |
| 533 } | 532 } |
| 534 | 533 |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 553 m_hasElementsAssociatedByParser = true; | 552 m_hasElementsAssociatedByParser = true; |
| 554 UseCounter::count(document(), UseCounter::FormAssociationByParser); | 553 UseCounter::count(document(), UseCounter::FormAssociationByParser); |
| 555 } | 554 } |
| 556 | 555 |
| 557 HTMLFormControlsCollection* HTMLFormElement::elements() { | 556 HTMLFormControlsCollection* HTMLFormElement::elements() { |
| 558 return ensureCachedCollection<HTMLFormControlsCollection>(FormControls); | 557 return ensureCachedCollection<HTMLFormControlsCollection>(FormControls); |
| 559 } | 558 } |
| 560 | 559 |
| 561 void HTMLFormElement::collectAssociatedElements( | 560 void HTMLFormElement::collectAssociatedElements( |
| 562 Node& root, | 561 Node& root, |
| 563 FormAssociatedElement::List& elements) const { | 562 ListedElement::List& elements) const { |
| 564 elements.clear(); | 563 elements.clear(); |
| 565 for (HTMLElement& element : Traversal<HTMLElement>::startsAfter(root)) { | 564 for (HTMLElement& element : Traversal<HTMLElement>::startsAfter(root)) { |
| 566 FormAssociatedElement* associatedElement = 0; | 565 ListedElement* associatedElement = 0; |
|
tkent
2016/12/02 13:24:37
Rename this variable to listedElement.
| |
| 567 if (element.isFormControlElement()) | 566 if (element.isFormControlElement()) |
| 568 associatedElement = toHTMLFormControlElement(&element); | 567 associatedElement = toHTMLFormControlElement(&element); |
| 569 else if (isHTMLObjectElement(element)) | 568 else if (isHTMLObjectElement(element)) |
| 570 associatedElement = toHTMLObjectElement(&element); | 569 associatedElement = toHTMLObjectElement(&element); |
| 571 else | 570 else |
| 572 continue; | 571 continue; |
| 573 if (associatedElement->form() == this) | 572 if (associatedElement->form() == this) |
| 574 elements.append(associatedElement); | 573 elements.append(associatedElement); |
| 575 } | 574 } |
| 576 } | 575 } |
| 577 | 576 |
| 578 // This function should be const conceptually. However we update some fields | 577 // This function should be const conceptually. However we update some fields |
| 579 // because of lazy evaluation. | 578 // because of lazy evaluation. |
| 580 const FormAssociatedElement::List& HTMLFormElement::associatedElements() const { | 579 const ListedElement::List& HTMLFormElement::associatedElements() const { |
| 581 if (!m_associatedElementsAreDirty) | 580 if (!m_associatedElementsAreDirty) |
| 582 return m_associatedElements; | 581 return m_associatedElements; |
| 583 HTMLFormElement* mutableThis = const_cast<HTMLFormElement*>(this); | 582 HTMLFormElement* mutableThis = const_cast<HTMLFormElement*>(this); |
| 584 Node* scope = mutableThis; | 583 Node* scope = mutableThis; |
| 585 if (m_hasElementsAssociatedByParser) | 584 if (m_hasElementsAssociatedByParser) |
| 586 scope = &NodeTraversal::highestAncestorOrSelf(*mutableThis); | 585 scope = &NodeTraversal::highestAncestorOrSelf(*mutableThis); |
| 587 if (isConnected() && m_hasElementsAssociatedByFormAttribute) | 586 if (isConnected() && m_hasElementsAssociatedByFormAttribute) |
| 588 scope = &treeScope().rootNode(); | 587 scope = &treeScope().rootNode(); |
| 589 DCHECK(scope); | 588 DCHECK(scope); |
| 590 collectAssociatedElements(*scope, mutableThis->m_associatedElements); | 589 collectAssociatedElements(*scope, mutableThis->m_associatedElements); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 656 bool HTMLFormElement::checkValidity() { | 655 bool HTMLFormElement::checkValidity() { |
| 657 return !checkInvalidControlsAndCollectUnhandled( | 656 return !checkInvalidControlsAndCollectUnhandled( |
| 658 0, CheckValidityDispatchInvalidEvent); | 657 0, CheckValidityDispatchInvalidEvent); |
| 659 } | 658 } |
| 660 | 659 |
| 661 bool HTMLFormElement::checkInvalidControlsAndCollectUnhandled( | 660 bool HTMLFormElement::checkInvalidControlsAndCollectUnhandled( |
| 662 HeapVector<Member<HTMLFormControlElement>>* unhandledInvalidControls, | 661 HeapVector<Member<HTMLFormControlElement>>* unhandledInvalidControls, |
| 663 CheckValidityEventBehavior eventBehavior) { | 662 CheckValidityEventBehavior eventBehavior) { |
| 664 // Copy associatedElements because event handlers called from | 663 // Copy associatedElements because event handlers called from |
| 665 // HTMLFormControlElement::checkValidity() might change associatedElements. | 664 // HTMLFormControlElement::checkValidity() might change associatedElements. |
| 666 const FormAssociatedElement::List& associatedElements = | 665 const ListedElement::List& associatedElements = this->associatedElements(); |
|
tkent
2016/12/02 13:24:37
Rename this variable to listedElements.
| |
| 667 this->associatedElements(); | 666 HeapVector<Member<ListedElement>> elements; |
| 668 HeapVector<Member<FormAssociatedElement>> elements; | |
| 669 elements.reserveCapacity(associatedElements.size()); | 667 elements.reserveCapacity(associatedElements.size()); |
| 670 for (unsigned i = 0; i < associatedElements.size(); ++i) | 668 for (unsigned i = 0; i < associatedElements.size(); ++i) |
| 671 elements.append(associatedElements[i]); | 669 elements.append(associatedElements[i]); |
| 672 int invalidControlsCount = 0; | 670 int invalidControlsCount = 0; |
| 673 for (unsigned i = 0; i < elements.size(); ++i) { | 671 for (unsigned i = 0; i < elements.size(); ++i) { |
| 674 if (elements[i]->form() == this && elements[i]->isFormControlElement()) { | 672 if (elements[i]->form() == this && elements[i]->isFormControlElement()) { |
| 675 HTMLFormControlElement* control = | 673 HTMLFormControlElement* control = |
| 676 toHTMLFormControlElement(elements[i].get()); | 674 toHTMLFormControlElement(elements[i].get()); |
| 677 if (control->isSubmittableElement() && | 675 if (control->isSubmittableElement() && |
| 678 !control->checkValidity(unhandledInvalidControls, eventBehavior) && | 676 !control->checkValidity(unhandledInvalidControls, eventBehavior) && |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 815 for (const auto& control : associatedElements()) { | 813 for (const auto& control : associatedElements()) { |
| 816 if (!control->isFormControlElement()) | 814 if (!control->isFormControlElement()) |
| 817 continue; | 815 continue; |
| 818 if (toHTMLFormControlElement(control)->canBeSuccessfulSubmitButton()) | 816 if (toHTMLFormControlElement(control)->canBeSuccessfulSubmitButton()) |
| 819 toHTMLFormControlElement(control)->pseudoStateChanged( | 817 toHTMLFormControlElement(control)->pseudoStateChanged( |
| 820 CSSSelector::PseudoDefault); | 818 CSSSelector::PseudoDefault); |
| 821 } | 819 } |
| 822 } | 820 } |
| 823 | 821 |
| 824 } // namespace blink | 822 } // namespace blink |
| OLD | NEW |