Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(829)

Side by Side Diff: Source/core/html/HTMLFormElement.cpp

Issue 182053002: Have Node::highestAncestor() return a reference (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Reupload Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/core/html/HTMLFormElement.h ('k') | Source/core/html/HTMLImageElement.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 reserv ed. 5 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserv ed.
6 * (C) 2006 Alexey Proskuryakov (ap@nypop.com) 6 * (C) 2006 Alexey Proskuryakov (ap@nypop.com)
7 * 7 *
8 * This library is free software; you can redistribute it and/or 8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public 9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either 10 * License as published by the Free Software Foundation; either
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 116
117 Node::InsertionNotificationRequest HTMLFormElement::insertedInto(ContainerNode* insertionPoint) 117 Node::InsertionNotificationRequest HTMLFormElement::insertedInto(ContainerNode* insertionPoint)
118 { 118 {
119 HTMLElement::insertedInto(insertionPoint); 119 HTMLElement::insertedInto(insertionPoint);
120 if (insertionPoint->inDocument()) 120 if (insertionPoint->inDocument())
121 this->document().didAssociateFormControl(this); 121 this->document().didAssociateFormControl(this);
122 return InsertionDone; 122 return InsertionDone;
123 } 123 }
124 124
125 template<class T> 125 template<class T>
126 void notifyFormRemovedFromTree(const Vector<T*>& elements, Node* root) 126 void notifyFormRemovedFromTree(const Vector<T*>& elements, Node& root)
127 { 127 {
128 size_t size = elements.size(); 128 size_t size = elements.size();
129 for (size_t i = 0; i < size; ++i) 129 for (size_t i = 0; i < size; ++i)
130 elements[i]->formRemovedFromTree(root); 130 elements[i]->formRemovedFromTree(root);
131 ASSERT(elements.size() == size); 131 ASSERT(elements.size() == size);
132 } 132 }
133 133
134 void HTMLFormElement::removedFrom(ContainerNode* insertionPoint) 134 void HTMLFormElement::removedFrom(ContainerNode* insertionPoint)
135 { 135 {
136 // We don't need to take care of form association by 'form' content 136 // We don't need to take care of form association by 'form' content
137 // attribute becuse IdTargetObserver handles it. 137 // attribute becuse IdTargetObserver handles it.
138 if (m_hasElementsAssociatedByParser) { 138 if (m_hasElementsAssociatedByParser) {
139 Node* root = highestAncestor(); 139 Node& root = highestAncestor();
140 if (!m_associatedElementsAreDirty) { 140 if (!m_associatedElementsAreDirty) {
141 Vector<FormAssociatedElement*> elements(associatedElements()); 141 Vector<FormAssociatedElement*> elements(associatedElements());
142 notifyFormRemovedFromTree(elements, root); 142 notifyFormRemovedFromTree(elements, root);
143 } else { 143 } else {
144 Vector<FormAssociatedElement*> elements; 144 Vector<FormAssociatedElement*> elements;
145 collectAssociatedElements(insertionPoint->highestAncestor(), element s); 145 collectAssociatedElements(insertionPoint->highestAncestor(), element s);
146 notifyFormRemovedFromTree(elements, root); 146 notifyFormRemovedFromTree(elements, root);
147 collectAssociatedElements(root, elements); 147 collectAssociatedElements(root, elements);
148 notifyFormRemovedFromTree(elements, root); 148 notifyFormRemovedFromTree(elements, root);
149 } 149 }
(...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after
567 return; 567 return;
568 m_hasElementsAssociatedByParser = true; 568 m_hasElementsAssociatedByParser = true;
569 UseCounter::count(document(), UseCounter::FormAssociationByParser); 569 UseCounter::count(document(), UseCounter::FormAssociationByParser);
570 } 570 }
571 571
572 PassRefPtr<HTMLCollection> HTMLFormElement::elements() 572 PassRefPtr<HTMLCollection> HTMLFormElement::elements()
573 { 573 {
574 return ensureCachedHTMLCollection(FormControls); 574 return ensureCachedHTMLCollection(FormControls);
575 } 575 }
576 576
577 void HTMLFormElement::collectAssociatedElements(Node* root, Vector<FormAssociate dElement*>& elements) const 577 void HTMLFormElement::collectAssociatedElements(Node& root, Vector<FormAssociate dElement*>& elements) const
578 { 578 {
579 elements.clear(); 579 elements.clear();
580 for (Node* node = root; node; node = NodeTraversal::next(*node)) { 580 for (Node* node = &root; node; node = NodeTraversal::next(*node)) {
581 if (!node->isHTMLElement()) 581 if (!node->isHTMLElement())
582 continue; 582 continue;
583 FormAssociatedElement* element = 0; 583 FormAssociatedElement* element = 0;
584 if (toElement(node)->isFormControlElement()) 584 if (toElement(node)->isFormControlElement())
585 element = toHTMLFormControlElement(node); 585 element = toHTMLFormControlElement(node);
586 else if (node->hasTagName(objectTag)) 586 else if (node->hasTagName(objectTag))
587 element = toHTMLObjectElement(node); 587 element = toHTMLObjectElement(node);
588 else 588 else
589 continue; 589 continue;
590 if (element->form()== this) 590 if (element->form()== this)
591 elements.append(element); 591 elements.append(element);
592 } 592 }
593 } 593 }
594 594
595 // This function should be const conceptually. However we update some fields 595 // This function should be const conceptually. However we update some fields
596 // because of lazy evaluation. 596 // because of lazy evaluation.
597 const Vector<FormAssociatedElement*>& HTMLFormElement::associatedElements() cons t 597 const Vector<FormAssociatedElement*>& HTMLFormElement::associatedElements() cons t
598 { 598 {
599 if (!m_associatedElementsAreDirty) 599 if (!m_associatedElementsAreDirty)
600 return m_associatedElements; 600 return m_associatedElements;
601 HTMLFormElement* mutableThis = const_cast<HTMLFormElement*>(this); 601 HTMLFormElement* mutableThis = const_cast<HTMLFormElement*>(this);
602 Node* scope = mutableThis; 602 Node* scope = mutableThis;
603 if (m_hasElementsAssociatedByParser) 603 if (m_hasElementsAssociatedByParser)
604 scope = highestAncestor(); 604 scope = &highestAncestor();
605 if (inDocument() && treeScope().idTargetObserverRegistry().hasObservers(fast GetAttribute(idAttr))) 605 if (inDocument() && treeScope().idTargetObserverRegistry().hasObservers(fast GetAttribute(idAttr)))
606 scope = &treeScope().rootNode(); 606 scope = &treeScope().rootNode();
607 collectAssociatedElements(scope, mutableThis->m_associatedElements); 607 ASSERT(scope);
608 collectAssociatedElements(*scope, mutableThis->m_associatedElements);
608 mutableThis->m_associatedElementsAreDirty = false; 609 mutableThis->m_associatedElementsAreDirty = false;
609 return m_associatedElements; 610 return m_associatedElements;
610 } 611 }
611 612
612 void HTMLFormElement::collectImageElements(Node* root, Vector<HTMLImageElement*> & elements) 613 void HTMLFormElement::collectImageElements(Node& root, Vector<HTMLImageElement*> & elements)
613 { 614 {
614 elements.clear(); 615 elements.clear();
615 for (Node* node = root; node; node = NodeTraversal::next(*node)) { 616 for (Node* node = &root; node; node = NodeTraversal::next(*node)) {
616 if (node->isHTMLElement() && node->hasTagName(imgTag) && toHTMLElement(n ode)->formOwner() == this) 617 if (node->isHTMLElement() && node->hasTagName(imgTag) && toHTMLElement(n ode)->formOwner() == this)
617 elements.append(toHTMLImageElement(node)); 618 elements.append(toHTMLImageElement(node));
618 } 619 }
619 } 620 }
620 621
621 const Vector<HTMLImageElement*>& HTMLFormElement::imageElements() 622 const Vector<HTMLImageElement*>& HTMLFormElement::imageElements()
622 { 623 {
623 if (!m_imageElementsAreDirty) 624 if (!m_imageElementsAreDirty)
624 return m_imageElements; 625 return m_imageElements;
625 collectImageElements(m_hasElementsAssociatedByParser ? highestAncestor() : t his, m_imageElements); 626 collectImageElements(m_hasElementsAssociatedByParser ? highestAncestor() : * this, m_imageElements);
626 m_imageElementsAreDirty = false; 627 m_imageElementsAreDirty = false;
627 return m_imageElements; 628 return m_imageElements;
628 } 629 }
629 630
630 String HTMLFormElement::name() const 631 String HTMLFormElement::name() const
631 { 632 {
632 return getNameAttribute(); 633 return getNameAttribute();
633 } 634 }
634 635
635 bool HTMLFormElement::noValidate() const 636 bool HTMLFormElement::noValidate() const
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
815 } 816 }
816 817
817 void HTMLFormElement::setDemoted(bool demoted) 818 void HTMLFormElement::setDemoted(bool demoted)
818 { 819 {
819 if (demoted) 820 if (demoted)
820 UseCounter::count(document(), UseCounter::DemotedFormElement); 821 UseCounter::count(document(), UseCounter::DemotedFormElement);
821 m_wasDemoted = demoted; 822 m_wasDemoted = demoted;
822 } 823 }
823 824
824 } // namespace 825 } // namespace
OLDNEW
« no previous file with comments | « Source/core/html/HTMLFormElement.h ('k') | Source/core/html/HTMLImageElement.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698