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

Unified Diff: third_party/WebKit/Source/core/svg/SVGUseElement.cpp

Issue 1763033002: Add SVGUseElement::createInstanceTree helper (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@svg-useelm-shadowbuilder-cleanup-10
Patch Set: Created 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/Source/core/svg/SVGUseElement.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/core/svg/SVGUseElement.cpp
diff --git a/third_party/WebKit/Source/core/svg/SVGUseElement.cpp b/third_party/WebKit/Source/core/svg/SVGUseElement.cpp
index 681abed9465765101428ab9ab9c9919a64bea4ea..c7cc2a1c8f75c12e48ba7f68d46d31ff4086c945 100644
--- a/third_party/WebKit/Source/core/svg/SVGUseElement.cpp
+++ b/third_party/WebKit/Source/core/svg/SVGUseElement.cpp
@@ -245,21 +245,15 @@ void SVGUseElement::svgAttributeChanged(const QualifiedName& attrName)
SVGGraphicsElement::svgAttributeChanged(attrName);
}
-static bool isDisallowedElement(const Node& node)
+static bool isDisallowedElement(const Element& element)
{
// Spec: "Any 'svg', 'symbol', 'g', graphics element or other 'use' is potentially a template object that can be re-used
// (i.e., "instanced") in the SVG document via a 'use' element."
// "Graphics Element" is defined as 'circle', 'ellipse', 'image', 'line', 'path', 'polygon', 'polyline', 'rect', 'text'
// Excluded are anything that is used by reference or that only make sense to appear once in a document.
- // We must also allow the shadow roots of other use elements.
- if (node.isShadowRoot() || node.isTextNode())
- return false;
-
- if (!node.isSVGElement())
+ if (!element.isSVGElement())
return true;
- const Element& element = toElement(node);
-
DEFINE_STATIC_LOCAL(HashSet<QualifiedName>, allowedElementTags, ());
if (allowedElementTags.isEmpty()) {
allowedElementTags.add(SVGNames::aTag);
@@ -386,6 +380,15 @@ static inline void removeDisallowedElementsFromSubtree(SVGElement& subtree)
}
}
+PassRefPtrWillBeRawPtr<Element> SVGUseElement::createInstanceTree(SVGElement& targetRoot) const
+{
+ RefPtrWillBeRawPtr<Element> instanceRoot = targetRoot.cloneElementWithChildren();
+ ASSERT(instanceRoot->isSVGElement());
+ associateCorrespondingElements(targetRoot, toSVGElement(*instanceRoot));
+ removeDisallowedElementsFromSubtree(toSVGElement(*instanceRoot));
+ return instanceRoot.release();
+}
+
void SVGUseElement::buildShadowAndInstanceTree(SVGElement& target)
{
ASSERT(!m_targetElementInstance);
@@ -403,11 +406,7 @@ void SVGUseElement::buildShadowAndInstanceTree(SVGElement& target)
// Set up root SVG element in shadow tree.
// Clone the target subtree into the shadow tree, not handling <use> and <symbol> yet.
- RefPtrWillBeRawPtr<Element> instanceRoot = target.cloneElementWithChildren();
- ASSERT(instanceRoot->isSVGElement());
- associateCorrespondingElements(target, toSVGElement(*instanceRoot));
- removeDisallowedElementsFromSubtree(toSVGElement(*instanceRoot));
-
+ RefPtrWillBeRawPtr<Element> instanceRoot = createInstanceTree(target);
m_targetElementInstance = toSVGElement(instanceRoot.get());
ShadowRoot* shadowTreeRootElement = userAgentShadowRoot();
shadowTreeRootElement->appendChild(instanceRoot.release());
@@ -606,11 +605,8 @@ bool SVGUseElement::expandUseElementsInShadowTree()
moveChildrenToReplacementElement(*use, *cloneParent);
if (target) {
- RefPtrWillBeRawPtr<Element> instanceRoot = target->cloneElementWithChildren();
- ASSERT(instanceRoot->isSVGElement());
- associateCorrespondingElements(*target, toSVGElement(*instanceRoot));
+ RefPtrWillBeRawPtr<Element> instanceRoot = use->createInstanceTree(*target);
transferUseWidthAndHeightIfNeeded(*use, toSVGElement(*instanceRoot), *target);
- removeDisallowedElementsFromSubtree(toSVGElement(*instanceRoot));
cloneParent->appendChild(instanceRoot.release());
}
@@ -643,8 +639,6 @@ void SVGUseElement::expandSymbolElementsInShadowTree()
// Move already cloned elements to the new <svg> element.
moveChildrenToReplacementElement(*symbol, *svgElement);
- removeDisallowedElementsFromSubtree(*svgElement);
-
RefPtrWillBeRawPtr<SVGElement> replacingElement(svgElement.get());
// Replace <symbol> with <svg>.
« no previous file with comments | « third_party/WebKit/Source/core/svg/SVGUseElement.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698