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

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

Issue 65303008: 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
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 649 matching lines...) Expand 10 before | Expand all | Expand 10 after
660 SVGElement* element = instance->correspondingElement(); 660 SVGElement* element = instance->correspondingElement();
661 661
662 if (element->hasID() && element->getIdAttribute() == targetId && element ->document() == newTarget->document()) 662 if (element->hasID() && element->getIdAttribute() == targetId && element ->document() == newTarget->document())
663 return true; 663 return true;
664 664
665 instance = instance->parentNode(); 665 instance = instance->parentNode();
666 } 666 }
667 return false; 667 return false;
668 } 668 }
669 669
670 static inline void removeDisallowedElementsFromSubtree(Element* subtree) 670 static inline void removeDisallowedElementsFromSubtree(Element& subtree)
671 { 671 {
672 ASSERT(!subtree->inDocument()); 672 ASSERT(!subtree.inDocument());
673 Element* element = ElementTraversal::firstWithin(subtree); 673 Element* element = ElementTraversal::firstWithin(subtree);
674 while (element) { 674 while (element) {
675 if (isDisallowedElement(element)) { 675 if (isDisallowedElement(element)) {
676 Element* next = ElementTraversal::nextSkippingChildren(element, subt ree); 676 Element* next = ElementTraversal::nextSkippingChildren(element, &sub tree);
677 // The subtree is not in document so this won't generate events that could mutate the tree. 677 // The subtree is not in document so this won't generate events that could mutate the tree.
678 element->parentNode()->removeChild(element); 678 element->parentNode()->removeChild(element);
679 element = next; 679 element = next;
680 } else { 680 } else {
681 element = ElementTraversal::next(*element, subtree); 681 element = ElementTraversal::next(*element, &subtree);
682 } 682 }
683 } 683 }
684 } 684 }
685 685
686 void SVGUseElement::buildShadowTree(SVGElement* target, SVGElementInstance* targ etInstance) 686 void SVGUseElement::buildShadowTree(SVGElement* target, SVGElementInstance* targ etInstance)
687 { 687 {
688 // For instance <use> on <foreignObject> (direct case). 688 // For instance <use> on <foreignObject> (direct case).
689 if (isDisallowedElement(target)) 689 if (isDisallowedElement(target))
690 return; 690 return;
691 691
692 RefPtr<Element> newChild = targetInstance->correspondingElement()->cloneElem entWithChildren(); 692 RefPtr<Element> newChild = targetInstance->correspondingElement()->cloneElem entWithChildren();
693 693
694 // We don't walk the target tree element-by-element, and clone each element, 694 // We don't walk the target tree element-by-element, and clone each element,
695 // but instead use cloneElementWithChildren(). This is an optimization for t he common 695 // but instead use cloneElementWithChildren(). This is an optimization for t he common
696 // case where <use> doesn't contain disallowed elements (ie. <foreignObject> ). 696 // case where <use> doesn't contain disallowed elements (ie. <foreignObject> ).
697 // Though if there are disallowed elements in the subtree, we have to remove them. 697 // Though if there are disallowed elements in the subtree, we have to remove them.
698 // For instance: <use> on <g> containing <foreignObject> (indirect case). 698 // For instance: <use> on <g> containing <foreignObject> (indirect case).
699 if (subtreeContainsDisallowedElement(newChild.get())) 699 if (subtreeContainsDisallowedElement(newChild.get()))
700 removeDisallowedElementsFromSubtree(newChild.get()); 700 removeDisallowedElementsFromSubtree(*newChild);
701 701
702 userAgentShadowRoot()->appendChild(newChild.release()); 702 userAgentShadowRoot()->appendChild(newChild.release());
703 } 703 }
704 704
705 void SVGUseElement::expandUseElementsInShadowTree(Node* element) 705 void SVGUseElement::expandUseElementsInShadowTree(Node* element)
706 { 706 {
707 // Why expand the <use> elements in the shadow tree here, and not just 707 // Why expand the <use> elements in the shadow tree here, and not just
708 // do this directly in buildShadowTree, if we encounter a <use> element? 708 // do this directly in buildShadowTree, if we encounter a <use> element?
709 // 709 //
710 // Short answer: Because we may miss to expand some elements. Ie. if a <symb ol> 710 // Short answer: Because we may miss to expand some elements. Ie. if a <symb ol>
(...skipping 24 matching lines...) Expand all
735 ASSERT(newChild->isSVGElement()); 735 ASSERT(newChild->isSVGElement());
736 cloneParent->appendChild(newChild.release()); 736 cloneParent->appendChild(newChild.release());
737 } 737 }
738 738
739 // We don't walk the target tree element-by-element, and clone each elem ent, 739 // We don't walk the target tree element-by-element, and clone each elem ent,
740 // but instead use cloneElementWithChildren(). This is an optimization f or the common 740 // but instead use cloneElementWithChildren(). This is an optimization f or the common
741 // case where <use> doesn't contain disallowed elements (ie. <foreignObj ect>). 741 // case where <use> doesn't contain disallowed elements (ie. <foreignObj ect>).
742 // Though if there are disallowed elements in the subtree, we have to re move them. 742 // Though if there are disallowed elements in the subtree, we have to re move them.
743 // For instance: <use> on <g> containing <foreignObject> (indirect case) . 743 // For instance: <use> on <g> containing <foreignObject> (indirect case) .
744 if (subtreeContainsDisallowedElement(cloneParent.get())) 744 if (subtreeContainsDisallowedElement(cloneParent.get()))
745 removeDisallowedElementsFromSubtree(cloneParent.get()); 745 removeDisallowedElementsFromSubtree(*cloneParent);
746 746
747 RefPtr<Node> replacingElement(cloneParent.get()); 747 RefPtr<Node> replacingElement(cloneParent.get());
748 748
749 // Replace <use> with referenced content. 749 // Replace <use> with referenced content.
750 ASSERT(use->parentNode()); 750 ASSERT(use->parentNode());
751 use->parentNode()->replaceChild(cloneParent.release(), use); 751 use->parentNode()->replaceChild(cloneParent.release(), use);
752 752
753 // Expand the siblings because the *element* is replaced and we will 753 // Expand the siblings because the *element* is replaced and we will
754 // lose the sibling chain when we are back from recursion. 754 // lose the sibling chain when we are back from recursion.
755 element = replacingElement.get(); 755 element = replacingElement.get();
(...skipping 25 matching lines...) Expand all
781 RefPtr<Node> newChild = child->cloneNode(true); 781 RefPtr<Node> newChild = child->cloneNode(true);
782 svgElement->appendChild(newChild.release()); 782 svgElement->appendChild(newChild.release());
783 } 783 }
784 784
785 // We don't walk the target tree element-by-element, and clone each elem ent, 785 // We don't walk the target tree element-by-element, and clone each elem ent,
786 // but instead use cloneNode(deep=true). This is an optimization for the common 786 // but instead use cloneNode(deep=true). This is an optimization for the common
787 // case where <use> doesn't contain disallowed elements (ie. <foreignObj ect>). 787 // case where <use> doesn't contain disallowed elements (ie. <foreignObj ect>).
788 // Though if there are disallowed elements in the subtree, we have to re move them. 788 // Though if there are disallowed elements in the subtree, we have to re move them.
789 // For instance: <use> on <g> containing <foreignObject> (indirect case) . 789 // For instance: <use> on <g> containing <foreignObject> (indirect case) .
790 if (subtreeContainsDisallowedElement(svgElement.get())) 790 if (subtreeContainsDisallowedElement(svgElement.get()))
791 removeDisallowedElementsFromSubtree(svgElement.get()); 791 removeDisallowedElementsFromSubtree(*svgElement);
792 792
793 RefPtr<Node> replacingElement(svgElement.get()); 793 RefPtr<Node> replacingElement(svgElement.get());
794 794
795 // Replace <symbol> with <svg>. 795 // Replace <symbol> with <svg>.
796 element->parentNode()->replaceChild(svgElement.release(), element); 796 element->parentNode()->replaceChild(svgElement.release(), element);
797 797
798 // Expand the siblings because the *element* is replaced and we will 798 // Expand the siblings because the *element* is replaced and we will
799 // lose the sibling chain when we are back from recursion. 799 // lose the sibling chain when we are back from recursion.
800 element = replacingElement.get(); 800 element = replacingElement.get();
801 for (RefPtr<Node> sibling = element->nextSibling(); sibling; sibling = s ibling->nextSibling()) 801 for (RefPtr<Node> sibling = element->nextSibling(); sibling; sibling = s ibling->nextSibling())
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
995 995
996 if (m_resource) 996 if (m_resource)
997 m_resource->removeClient(this); 997 m_resource->removeClient(this);
998 998
999 m_resource = resource; 999 m_resource = resource;
1000 if (m_resource) 1000 if (m_resource)
1001 m_resource->addClient(this); 1001 m_resource->addClient(this);
1002 } 1002 }
1003 1003
1004 } 1004 }
OLDNEW
« Source/core/dom/TreeScope.cpp ('K') | « Source/core/svg/SVGElement.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698