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

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

Issue 198553002: Use new is*Element() helper functions even more in HTML code (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 9 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/HTMLFormControlsCollection.cpp ('k') | Source/core/html/HTMLFrameElement.cpp » ('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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 89
90 bool HTMLFormElement::rendererIsNeeded(const RenderStyle& style) 90 bool HTMLFormElement::rendererIsNeeded(const RenderStyle& style)
91 { 91 {
92 if (!m_wasDemoted) 92 if (!m_wasDemoted)
93 return HTMLElement::rendererIsNeeded(style); 93 return HTMLElement::rendererIsNeeded(style);
94 94
95 ContainerNode* node = parentNode(); 95 ContainerNode* node = parentNode();
96 RenderObject* parentRenderer = node->renderer(); 96 RenderObject* parentRenderer = node->renderer();
97 // FIXME: Shouldn't we also check for table caption (see |formIsTablePart| b elow). 97 // FIXME: Shouldn't we also check for table caption (see |formIsTablePart| b elow).
98 // FIXME: This check is not correct for Shadow DOM. 98 // FIXME: This check is not correct for Shadow DOM.
99 bool parentIsTableElementPart = (parentRenderer->isTable() && node->hasTagNa me(tableTag)) 99 bool parentIsTableElementPart = (parentRenderer->isTable() && isHTMLTableEle ment(*node))
100 || (parentRenderer->isTableRow() && node->hasTagName(trTag)) 100 || (parentRenderer->isTableRow() && isHTMLTableRowElement(*node))
101 || (parentRenderer->isTableSection() && node->hasTagName(tbodyTag)) 101 || (parentRenderer->isTableSection() && node->hasTagName(tbodyTag))
102 || (parentRenderer->isRenderTableCol() && node->hasTagName(colTag)) 102 || (parentRenderer->isRenderTableCol() && node->hasTagName(colTag))
103 || (parentRenderer->isTableCell() && node->hasTagName(trTag)); 103 || (parentRenderer->isTableCell() && isHTMLTableRowElement(*node));
104 104
105 if (!parentIsTableElementPart) 105 if (!parentIsTableElementPart)
106 return true; 106 return true;
107 107
108 EDisplay display = style.display(); 108 EDisplay display = style.display();
109 bool formIsTablePart = display == TABLE || display == INLINE_TABLE || displa y == TABLE_ROW_GROUP 109 bool formIsTablePart = display == TABLE || display == INLINE_TABLE || displa y == TABLE_ROW_GROUP
110 || display == TABLE_HEADER_GROUP || display == TABLE_FOOTER_GROUP || dis play == TABLE_ROW 110 || display == TABLE_HEADER_GROUP || display == TABLE_FOOTER_GROUP || dis play == TABLE_ROW
111 || display == TABLE_COLUMN_GROUP || display == TABLE_COLUMN || display = = TABLE_CELL 111 || display == TABLE_COLUMN_GROUP || display == TABLE_COLUMN || display = = TABLE_CELL
112 || display == TABLE_CAPTION; 112 || display == TABLE_CAPTION;
113 113
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 } 323 }
324 324
325 void HTMLFormElement::getTextFieldValues(StringPairVector& fieldNamesAndValues) const 325 void HTMLFormElement::getTextFieldValues(StringPairVector& fieldNamesAndValues) const
326 { 326 {
327 ASSERT_ARG(fieldNamesAndValues, fieldNamesAndValues.isEmpty()); 327 ASSERT_ARG(fieldNamesAndValues, fieldNamesAndValues.isEmpty());
328 328
329 const Vector<FormAssociatedElement*>& elements = associatedElements(); 329 const Vector<FormAssociatedElement*>& elements = associatedElements();
330 fieldNamesAndValues.reserveCapacity(elements.size()); 330 fieldNamesAndValues.reserveCapacity(elements.size());
331 for (unsigned i = 0; i < elements.size(); ++i) { 331 for (unsigned i = 0; i < elements.size(); ++i) {
332 FormAssociatedElement* control = elements[i]; 332 FormAssociatedElement* control = elements[i];
333 HTMLElement* element = toHTMLElement(control); 333 HTMLElement& element = toHTMLElement(*control);
334 if (!element->hasTagName(inputTag)) 334 if (!isHTMLInputElement(element))
335 continue; 335 continue;
336 336
337 HTMLInputElement* input = toHTMLInputElement(element); 337 HTMLInputElement& input = toHTMLInputElement(element);
338 if (!input->isTextField()) 338 if (!input.isTextField())
339 continue; 339 continue;
340 340
341 fieldNamesAndValues.append(make_pair(input->name().string(), input->valu e())); 341 fieldNamesAndValues.append(make_pair(input.name().string(), input.value( )));
342 } 342 }
343 } 343 }
344 344
345 void HTMLFormElement::submitDialog(PassRefPtr<FormSubmission> formSubmission) 345 void HTMLFormElement::submitDialog(PassRefPtr<FormSubmission> formSubmission)
346 { 346 {
347 for (Node* node = this; node; node = node->parentOrShadowHostNode()) { 347 for (Node* node = this; node; node = node->parentOrShadowHostNode()) {
348 if (node->hasTagName(dialogTag)) { 348 if (isHTMLDialogElement(*node)) {
349 toHTMLDialogElement(node)->closeDialog(formSubmission->result()); 349 toHTMLDialogElement(*node).closeDialog(formSubmission->result());
350 return; 350 return;
351 } 351 }
352 } 352 }
353 } 353 }
354 354
355 void HTMLFormElement::submit(Event* event, bool activateSubmitButton, bool proce ssingUserGesture, FormSubmissionTrigger formSubmissionTrigger) 355 void HTMLFormElement::submit(Event* event, bool activateSubmitButton, bool proce ssingUserGesture, FormSubmissionTrigger formSubmissionTrigger)
356 { 356 {
357 FrameView* view = document().view(); 357 FrameView* view = document().view();
358 LocalFrame* frame = document().frame(); 358 LocalFrame* frame = document().frame();
359 if (!view || !frame || !frame->page()) 359 if (!view || !frame || !frame->page())
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 (HTMLElement* element = Traversal<HTMLElement>::firstWithin(root); eleme nt; element = Traversal<HTMLElement>::next(*element)) {
581 if (!node->isHTMLElement()) 581 FormAssociatedElement* associatedElement = 0;
582 continue; 582 if (element->isFormControlElement())
583 FormAssociatedElement* element = 0; 583 associatedElement = toHTMLFormControlElement(element);
584 if (toElement(node)->isFormControlElement()) 584 else if (isHTMLObjectElement(*element))
585 element = toHTMLFormControlElement(node); 585 associatedElement = toHTMLObjectElement(element);
586 else if (node->hasTagName(objectTag))
587 element = toHTMLObjectElement(node);
588 else 586 else
589 continue; 587 continue;
590 if (element->form()== this) 588 if (associatedElement->form()== this)
591 elements.append(element); 589 elements.append(associatedElement);
592 } 590 }
593 } 591 }
594 592
595 // This function should be const conceptually. However we update some fields 593 // This function should be const conceptually. However we update some fields
596 // because of lazy evaluation. 594 // because of lazy evaluation.
597 const Vector<FormAssociatedElement*>& HTMLFormElement::associatedElements() cons t 595 const Vector<FormAssociatedElement*>& HTMLFormElement::associatedElements() cons t
598 { 596 {
599 if (!m_associatedElementsAreDirty) 597 if (!m_associatedElementsAreDirty)
600 return m_associatedElements; 598 return m_associatedElements;
601 HTMLFormElement* mutableThis = const_cast<HTMLFormElement*>(this); 599 HTMLFormElement* mutableThis = const_cast<HTMLFormElement*>(this);
602 Node* scope = mutableThis; 600 Node* scope = mutableThis;
603 if (m_hasElementsAssociatedByParser) 601 if (m_hasElementsAssociatedByParser)
604 scope = &highestAncestor(); 602 scope = &highestAncestor();
605 if (inDocument() && treeScope().idTargetObserverRegistry().hasObservers(fast GetAttribute(idAttr))) 603 if (inDocument() && treeScope().idTargetObserverRegistry().hasObservers(fast GetAttribute(idAttr)))
606 scope = &treeScope().rootNode(); 604 scope = &treeScope().rootNode();
607 ASSERT(scope); 605 ASSERT(scope);
608 collectAssociatedElements(*scope, mutableThis->m_associatedElements); 606 collectAssociatedElements(*scope, mutableThis->m_associatedElements);
609 mutableThis->m_associatedElementsAreDirty = false; 607 mutableThis->m_associatedElementsAreDirty = false;
610 return m_associatedElements; 608 return m_associatedElements;
611 } 609 }
612 610
613 void HTMLFormElement::collectImageElements(Node& root, Vector<HTMLImageElement*> & elements) 611 void HTMLFormElement::collectImageElements(Node& root, Vector<HTMLImageElement*> & elements)
614 { 612 {
615 elements.clear(); 613 elements.clear();
616 for (Node* node = &root; node; node = NodeTraversal::next(*node)) { 614 for (HTMLImageElement* image = Traversal<HTMLImageElement>::firstWithin(root ); image; image = Traversal<HTMLImageElement>::next(*image)) {
617 if (node->isHTMLElement() && node->hasTagName(imgTag) && toHTMLElement(n ode)->formOwner() == this) 615 if (image->formOwner() == this)
618 elements.append(toHTMLImageElement(node)); 616 elements.append(image);
619 } 617 }
620 } 618 }
621 619
622 const Vector<HTMLImageElement*>& HTMLFormElement::imageElements() 620 const Vector<HTMLImageElement*>& HTMLFormElement::imageElements()
623 { 621 {
624 if (!m_imageElementsAreDirty) 622 if (!m_imageElementsAreDirty)
625 return m_imageElements; 623 return m_imageElements;
626 collectImageElements(m_hasElementsAssociatedByParser ? highestAncestor() : * this, m_imageElements); 624 collectImageElements(m_hasElementsAssociatedByParser ? highestAncestor() : * this, m_imageElements);
627 m_imageElementsAreDirty = false; 625 m_imageElementsAreDirty = false;
628 return m_imageElements; 626 return m_imageElements;
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
714 712
715 Element* HTMLFormElement::elementFromPastNamesMap(const AtomicString& pastName) 713 Element* HTMLFormElement::elementFromPastNamesMap(const AtomicString& pastName)
716 { 714 {
717 if (pastName.isEmpty() || !m_pastNamesMap) 715 if (pastName.isEmpty() || !m_pastNamesMap)
718 return 0; 716 return 0;
719 Element* element = m_pastNamesMap->get(pastName); 717 Element* element = m_pastNamesMap->get(pastName);
720 #if !ASSERT_DISABLED 718 #if !ASSERT_DISABLED
721 if (!element) 719 if (!element)
722 return 0; 720 return 0;
723 ASSERT_WITH_SECURITY_IMPLICATION(toHTMLElement(element)->formOwner() == this ); 721 ASSERT_WITH_SECURITY_IMPLICATION(toHTMLElement(element)->formOwner() == this );
724 if (element->hasTagName(imgTag)) { 722 if (isHTMLImageElement(*element)) {
725 ASSERT_WITH_SECURITY_IMPLICATION(imageElements().find(element) != kNotFo und); 723 ASSERT_WITH_SECURITY_IMPLICATION(imageElements().find(element) != kNotFo und);
726 } else if (element->hasTagName(objectTag)) { 724 } else if (isHTMLObjectElement(*element)) {
727 ASSERT_WITH_SECURITY_IMPLICATION(associatedElements().find(toHTMLObjectE lement(element)) != kNotFound); 725 ASSERT_WITH_SECURITY_IMPLICATION(associatedElements().find(toHTMLObjectE lement(element)) != kNotFound);
728 } else { 726 } else {
729 ASSERT_WITH_SECURITY_IMPLICATION(associatedElements().find(toHTMLFormCon trolElement(element)) != kNotFound); 727 ASSERT_WITH_SECURITY_IMPLICATION(associatedElements().find(toHTMLFormCon trolElement(element)) != kNotFound);
730 } 728 }
731 #endif 729 #endif
732 return element; 730 return element;
733 } 731 }
734 732
735 void HTMLFormElement::addToPastNamesMap(Element* element, const AtomicString& pa stName) 733 void HTMLFormElement::addToPastNamesMap(Element* element, const AtomicString& pa stName)
736 { 734 {
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
803 Vector<RefPtr<Element> > elements; 801 Vector<RefPtr<Element> > elements;
804 getNamedElements(name, elements); 802 getNamedElements(name, elements);
805 ASSERT(!elements.isEmpty()); 803 ASSERT(!elements.isEmpty());
806 804
807 if (elements.size() == 1) { 805 if (elements.size() == 1) {
808 returnValue1Enabled = true; 806 returnValue1Enabled = true;
809 returnValue1 = elements.at(0); 807 returnValue1 = elements.at(0);
810 return; 808 return;
811 } 809 }
812 810
813 bool onlyMatchImg = elements.size() && elements.at(0)->hasTagName(imgTag); 811 bool onlyMatchImg = !elements.isEmpty() && isHTMLImageElement(*elements.firs t());
814 returnValue0Enabled = true; 812 returnValue0Enabled = true;
815 returnValue0 = radioNodeList(name, onlyMatchImg); 813 returnValue0 = radioNodeList(name, onlyMatchImg);
816 } 814 }
817 815
818 void HTMLFormElement::setDemoted(bool demoted) 816 void HTMLFormElement::setDemoted(bool demoted)
819 { 817 {
820 if (demoted) 818 if (demoted)
821 UseCounter::count(document(), UseCounter::DemotedFormElement); 819 UseCounter::count(document(), UseCounter::DemotedFormElement);
822 m_wasDemoted = demoted; 820 m_wasDemoted = demoted;
823 } 821 }
824 822
825 } // namespace 823 } // namespace
OLDNEW
« no previous file with comments | « Source/core/html/HTMLFormControlsCollection.cpp ('k') | Source/core/html/HTMLFrameElement.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698