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

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

Issue 1759553005: Replace cloneNodeAndAssociate with Element::cloneElementWithChildren (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@svg-useelm-shadowbuilder-cleanup-6
Patch Set: Fix ASSERT-expression 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 | « no previous file | 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 0293b9e0379b059380a1cb89e820ab4545731fc0..46e52916022ba0e0e07e88645fd129e80e90cf68 100644
--- a/third_party/WebKit/Source/core/svg/SVGUseElement.cpp
+++ b/third_party/WebKit/Source/core/svg/SVGUseElement.cpp
@@ -356,19 +356,16 @@ void SVGUseElement::buildPendingResource()
ASSERT(!m_needsShadowTreeRecreation);
}
-static PassRefPtrWillBeRawPtr<Node> cloneNodeAndAssociate(Node& toClone)
-{
- RefPtrWillBeRawPtr<Node> clone = toClone.cloneNode(false);
- if (!clone->isSVGElement())
- return clone.release();
-
- SVGElement& svgElement = toSVGElement(toClone);
- ASSERT(!svgElement.correspondingElement());
- toSVGElement(clone.get())->setCorrespondingElement(&svgElement);
- TrackExceptionState exceptionState;
- for (RefPtrWillBeRawPtr<Node> node = toClone.firstChild(); node && !exceptionState.hadException(); node = node->nextSibling())
- clone->appendChild(cloneNodeAndAssociate(*node), exceptionState);
- return clone.release();
+static void associateCorrespondingElements(SVGElement& targetRoot, SVGElement& instanceRoot)
+{
+ auto targetRange = Traversal<SVGElement>::inclusiveDescendantsOf(targetRoot);
+ auto targetIterator = targetRange.begin();
+ for (SVGElement& instance : Traversal<SVGElement>::inclusiveDescendantsOf(instanceRoot)) {
+ ASSERT(!instance.correspondingElement());
+ instance.setCorrespondingElement(&*targetIterator);
+ ++targetIterator;
+ }
+ ASSERT(!(targetIterator != targetRange.end()));
Stephen Chennney 2016/03/03 16:42:01 So we have a != operator but no == operator? Inter
fs 2016/03/03 16:59:07 Yeah, I guess it's heavily tailored to the range-b
}
void SVGUseElement::buildShadowAndInstanceTree(SVGElement& target)
@@ -629,14 +626,14 @@ bool SVGUseElement::expandUseElementsInShadowTree()
moveChildrenToReplacementElement(*use, *cloneParent);
if (target) {
- RefPtrWillBeRawPtr<Node> newChild = cloneNodeAndAssociate(*target);
- ASSERT(newChild->isSVGElement());
- transferUseWidthAndHeightIfNeeded(*use, toSVGElement(*newChild), *target);
- cloneParent->appendChild(newChild.release());
+ RefPtrWillBeRawPtr<Element> instanceRoot = target->cloneElementWithChildren();
+ ASSERT(instanceRoot->isSVGElement());
+ associateCorrespondingElements(*target, toSVGElement(*instanceRoot));
+ transferUseWidthAndHeightIfNeeded(*use, toSVGElement(*instanceRoot), *target);
+ removeDisallowedElementsFromSubtree(toSVGElement(*instanceRoot));
+ cloneParent->appendChild(instanceRoot.release());
}
- removeDisallowedElementsFromSubtree(*cloneParent);
-
RefPtrWillBeRawPtr<SVGElement> replacingElement(cloneParent.get());
// Replace <use> with referenced content.
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698