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

Side by Side Diff: Source/core/svg/SVGUseElement.cpp

Issue 68173014: Have ElementTraversal::firstWithin() take a reference (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 7 years, 1 month 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
« no previous file with comments | « Source/core/svg/SVGElement.cpp ('k') | no next file » | 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) 2004, 2005, 2006, 2007, 2008 Nikolas Zimmermann <zimmermann@kde .org> 2 * Copyright (C) 2004, 2005, 2006, 2007, 2008 Nikolas Zimmermann <zimmermann@kde .org>
3 * Copyright (C) 2004, 2005, 2006, 2007 Rob Buis <buis@kde.org> 3 * Copyright (C) 2004, 2005, 2006, 2007 Rob Buis <buis@kde.org>
4 * Copyright (C) Research In Motion Limited 2009-2010. All rights reserved. 4 * Copyright (C) Research In Motion Limited 2009-2010. All rights reserved.
5 * Copyright (C) 2011 Torch Mobile (Beijing) Co. Ltd. All rights reserved. 5 * Copyright (C) 2011 Torch Mobile (Beijing) Co. Ltd. All rights reserved.
6 * Copyright (C) 2012 University of Szeged 6 * Copyright (C) 2012 University of Szeged
7 * Copyright (C) 2012 Renata Hodovan <reni@webkit.org> 7 * Copyright (C) 2012 Renata Hodovan <reni@webkit.org>
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 648 matching lines...) Expand 10 before | Expand all | Expand 10 after
659 SVGElement* element = instance->correspondingElement(); 659 SVGElement* element = instance->correspondingElement();
660 660
661 if (element->hasID() && element->getIdAttribute() == targetId && element ->document() == newTarget->document()) 661 if (element->hasID() && element->getIdAttribute() == targetId && element ->document() == newTarget->document())
662 return true; 662 return true;
663 663
664 instance = instance->parentNode(); 664 instance = instance->parentNode();
665 } 665 }
666 return false; 666 return false;
667 } 667 }
668 668
669 static inline void removeDisallowedElementsFromSubtree(Element* subtree) 669 static inline void removeDisallowedElementsFromSubtree(Element& subtree)
670 { 670 {
671 ASSERT(!subtree->inDocument()); 671 ASSERT(!subtree.inDocument());
672 Element* element = ElementTraversal::firstWithin(subtree); 672 Element* element = ElementTraversal::firstWithin(subtree);
673 while (element) { 673 while (element) {
674 if (isDisallowedElement(element)) { 674 if (isDisallowedElement(element)) {
675 Element* next = ElementTraversal::nextSkippingChildren(*element, sub tree); 675 Element* next = ElementTraversal::nextSkippingChildren(*element, &su btree);
676 // The subtree is not in document so this won't generate events that could mutate the tree. 676 // The subtree is not in document so this won't generate events that could mutate the tree.
677 element->parentNode()->removeChild(element); 677 element->parentNode()->removeChild(element);
678 element = next; 678 element = next;
679 } else { 679 } else {
680 element = ElementTraversal::next(*element, subtree); 680 element = ElementTraversal::next(*element, &subtree);
681 } 681 }
682 } 682 }
683 } 683 }
684 684
685 void SVGUseElement::buildShadowTree(SVGElement* target, SVGElementInstance* targ etInstance) 685 void SVGUseElement::buildShadowTree(SVGElement* target, SVGElementInstance* targ etInstance)
686 { 686 {
687 // For instance <use> on <foreignObject> (direct case). 687 // For instance <use> on <foreignObject> (direct case).
688 if (isDisallowedElement(target)) 688 if (isDisallowedElement(target))
689 return; 689 return;
690 690
691 RefPtr<Element> newChild = targetInstance->correspondingElement()->cloneElem entWithChildren(); 691 RefPtr<Element> newChild = targetInstance->correspondingElement()->cloneElem entWithChildren();
692 692
693 // We don't walk the target tree element-by-element, and clone each element, 693 // We don't walk the target tree element-by-element, and clone each element,
694 // but instead use cloneElementWithChildren(). This is an optimization for t he common 694 // but instead use cloneElementWithChildren(). This is an optimization for t he common
695 // case where <use> doesn't contain disallowed elements (ie. <foreignObject> ). 695 // case where <use> doesn't contain disallowed elements (ie. <foreignObject> ).
696 // Though if there are disallowed elements in the subtree, we have to remove them. 696 // Though if there are disallowed elements in the subtree, we have to remove them.
697 // For instance: <use> on <g> containing <foreignObject> (indirect case). 697 // For instance: <use> on <g> containing <foreignObject> (indirect case).
698 if (subtreeContainsDisallowedElement(newChild.get())) 698 if (subtreeContainsDisallowedElement(newChild.get()))
699 removeDisallowedElementsFromSubtree(newChild.get()); 699 removeDisallowedElementsFromSubtree(*newChild);
700 700
701 userAgentShadowRoot()->appendChild(newChild.release()); 701 userAgentShadowRoot()->appendChild(newChild.release());
702 } 702 }
703 703
704 void SVGUseElement::expandUseElementsInShadowTree(Node* element) 704 void SVGUseElement::expandUseElementsInShadowTree(Node* element)
705 { 705 {
706 // Why expand the <use> elements in the shadow tree here, and not just 706 // Why expand the <use> elements in the shadow tree here, and not just
707 // do this directly in buildShadowTree, if we encounter a <use> element? 707 // do this directly in buildShadowTree, if we encounter a <use> element?
708 // 708 //
709 // Short answer: Because we may miss to expand some elements. Ie. if a <symb ol> 709 // Short answer: Because we may miss to expand some elements. Ie. if a <symb ol>
(...skipping 24 matching lines...) Expand all
734 ASSERT(newChild->isSVGElement()); 734 ASSERT(newChild->isSVGElement());
735 cloneParent->appendChild(newChild.release()); 735 cloneParent->appendChild(newChild.release());
736 } 736 }
737 737
738 // We don't walk the target tree element-by-element, and clone each elem ent, 738 // We don't walk the target tree element-by-element, and clone each elem ent,
739 // but instead use cloneElementWithChildren(). This is an optimization f or the common 739 // but instead use cloneElementWithChildren(). This is an optimization f or the common
740 // case where <use> doesn't contain disallowed elements (ie. <foreignObj ect>). 740 // case where <use> doesn't contain disallowed elements (ie. <foreignObj ect>).
741 // Though if there are disallowed elements in the subtree, we have to re move them. 741 // Though if there are disallowed elements in the subtree, we have to re move them.
742 // For instance: <use> on <g> containing <foreignObject> (indirect case) . 742 // For instance: <use> on <g> containing <foreignObject> (indirect case) .
743 if (subtreeContainsDisallowedElement(cloneParent.get())) 743 if (subtreeContainsDisallowedElement(cloneParent.get()))
744 removeDisallowedElementsFromSubtree(cloneParent.get()); 744 removeDisallowedElementsFromSubtree(*cloneParent);
745 745
746 RefPtr<Node> replacingElement(cloneParent.get()); 746 RefPtr<Node> replacingElement(cloneParent.get());
747 747
748 // Replace <use> with referenced content. 748 // Replace <use> with referenced content.
749 ASSERT(use->parentNode()); 749 ASSERT(use->parentNode());
750 use->parentNode()->replaceChild(cloneParent.release(), use); 750 use->parentNode()->replaceChild(cloneParent.release(), use);
751 751
752 // Expand the siblings because the *element* is replaced and we will 752 // Expand the siblings because the *element* is replaced and we will
753 // lose the sibling chain when we are back from recursion. 753 // lose the sibling chain when we are back from recursion.
754 element = replacingElement.get(); 754 element = replacingElement.get();
(...skipping 25 matching lines...) Expand all
780 RefPtr<Node> newChild = child->cloneNode(true); 780 RefPtr<Node> newChild = child->cloneNode(true);
781 svgElement->appendChild(newChild.release()); 781 svgElement->appendChild(newChild.release());
782 } 782 }
783 783
784 // We don't walk the target tree element-by-element, and clone each elem ent, 784 // We don't walk the target tree element-by-element, and clone each elem ent,
785 // but instead use cloneNode(deep=true). This is an optimization for the common 785 // but instead use cloneNode(deep=true). This is an optimization for the common
786 // case where <use> doesn't contain disallowed elements (ie. <foreignObj ect>). 786 // case where <use> doesn't contain disallowed elements (ie. <foreignObj ect>).
787 // Though if there are disallowed elements in the subtree, we have to re move them. 787 // Though if there are disallowed elements in the subtree, we have to re move them.
788 // For instance: <use> on <g> containing <foreignObject> (indirect case) . 788 // For instance: <use> on <g> containing <foreignObject> (indirect case) .
789 if (subtreeContainsDisallowedElement(svgElement.get())) 789 if (subtreeContainsDisallowedElement(svgElement.get()))
790 removeDisallowedElementsFromSubtree(svgElement.get()); 790 removeDisallowedElementsFromSubtree(*svgElement);
791 791
792 RefPtr<Node> replacingElement(svgElement.get()); 792 RefPtr<Node> replacingElement(svgElement.get());
793 793
794 // Replace <symbol> with <svg>. 794 // Replace <symbol> with <svg>.
795 element->parentNode()->replaceChild(svgElement.release(), element); 795 element->parentNode()->replaceChild(svgElement.release(), element);
796 796
797 // Expand the siblings because the *element* is replaced and we will 797 // Expand the siblings because the *element* is replaced and we will
798 // lose the sibling chain when we are back from recursion. 798 // lose the sibling chain when we are back from recursion.
799 element = replacingElement.get(); 799 element = replacingElement.get();
800 for (RefPtr<Node> sibling = element->nextSibling(); sibling; sibling = s ibling->nextSibling()) 800 for (RefPtr<Node> sibling = element->nextSibling(); sibling; sibling = s ibling->nextSibling())
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
994 994
995 if (m_resource) 995 if (m_resource)
996 m_resource->removeClient(this); 996 m_resource->removeClient(this);
997 997
998 m_resource = resource; 998 m_resource = resource;
999 if (m_resource) 999 if (m_resource)
1000 m_resource->addClient(this); 1000 m_resource->addClient(this);
1001 } 1001 }
1002 1002
1003 } 1003 }
OLDNEW
« no previous file with comments | « Source/core/svg/SVGElement.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698