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

Side by Side 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, 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
« no previous file with comments | « no previous file | 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 338 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 } 349 }
350 350
351 if (target->isSVGElement()) { 351 if (target->isSVGElement()) {
352 buildShadowAndInstanceTree(toSVGElement(*target)); 352 buildShadowAndInstanceTree(toSVGElement(*target));
353 invalidateDependentShadowTrees(); 353 invalidateDependentShadowTrees();
354 } 354 }
355 355
356 ASSERT(!m_needsShadowTreeRecreation); 356 ASSERT(!m_needsShadowTreeRecreation);
357 } 357 }
358 358
359 static PassRefPtrWillBeRawPtr<Node> cloneNodeAndAssociate(Node& toClone) 359 static void associateCorrespondingElements(SVGElement& targetRoot, SVGElement& i nstanceRoot)
360 { 360 {
361 RefPtrWillBeRawPtr<Node> clone = toClone.cloneNode(false); 361 auto targetRange = Traversal<SVGElement>::inclusiveDescendantsOf(targetRoot) ;
362 if (!clone->isSVGElement()) 362 auto targetIterator = targetRange.begin();
363 return clone.release(); 363 for (SVGElement& instance : Traversal<SVGElement>::inclusiveDescendantsOf(in stanceRoot)) {
364 364 ASSERT(!instance.correspondingElement());
365 SVGElement& svgElement = toSVGElement(toClone); 365 instance.setCorrespondingElement(&*targetIterator);
366 ASSERT(!svgElement.correspondingElement()); 366 ++targetIterator;
367 toSVGElement(clone.get())->setCorrespondingElement(&svgElement); 367 }
368 TrackExceptionState exceptionState; 368 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
369 for (RefPtrWillBeRawPtr<Node> node = toClone.firstChild(); node && !exceptio nState.hadException(); node = node->nextSibling())
370 clone->appendChild(cloneNodeAndAssociate(*node), exceptionState);
371 return clone.release();
372 } 369 }
373 370
374 void SVGUseElement::buildShadowAndInstanceTree(SVGElement& target) 371 void SVGUseElement::buildShadowAndInstanceTree(SVGElement& target)
375 { 372 {
376 ASSERT(!m_targetElementInstance); 373 ASSERT(!m_targetElementInstance);
377 ASSERT(!m_needsShadowTreeRecreation); 374 ASSERT(!m_needsShadowTreeRecreation);
378 375
379 // <use> creates a "user agent" shadow root. Do not build the shadow/instanc e tree for <use> 376 // <use> creates a "user agent" shadow root. Do not build the shadow/instanc e tree for <use>
380 // elements living in a user agent shadow tree because they will get expande d in a second 377 // elements living in a user agent shadow tree because they will get expande d in a second
381 // pass -- see expandUseElementsInShadowTree(). 378 // pass -- see expandUseElementsInShadowTree().
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
622 // Transfer all data (attributes, etc.) from <use> to the new <g> elemen t. 619 // Transfer all data (attributes, etc.) from <use> to the new <g> elemen t.
623 cloneParent->cloneDataFromElement(*use); 620 cloneParent->cloneDataFromElement(*use);
624 cloneParent->setCorrespondingElement(use->correspondingElement()); 621 cloneParent->setCorrespondingElement(use->correspondingElement());
625 622
626 removeAttributesFromReplacementElement(*cloneParent); 623 removeAttributesFromReplacementElement(*cloneParent);
627 624
628 // Move already cloned elements to the new <g> element. 625 // Move already cloned elements to the new <g> element.
629 moveChildrenToReplacementElement(*use, *cloneParent); 626 moveChildrenToReplacementElement(*use, *cloneParent);
630 627
631 if (target) { 628 if (target) {
632 RefPtrWillBeRawPtr<Node> newChild = cloneNodeAndAssociate(*target); 629 RefPtrWillBeRawPtr<Element> instanceRoot = target->cloneElementWithC hildren();
633 ASSERT(newChild->isSVGElement()); 630 ASSERT(instanceRoot->isSVGElement());
634 transferUseWidthAndHeightIfNeeded(*use, toSVGElement(*newChild), *ta rget); 631 associateCorrespondingElements(*target, toSVGElement(*instanceRoot)) ;
635 cloneParent->appendChild(newChild.release()); 632 transferUseWidthAndHeightIfNeeded(*use, toSVGElement(*instanceRoot), *target);
633 removeDisallowedElementsFromSubtree(toSVGElement(*instanceRoot));
634 cloneParent->appendChild(instanceRoot.release());
636 } 635 }
637 636
638 removeDisallowedElementsFromSubtree(*cloneParent);
639
640 RefPtrWillBeRawPtr<SVGElement> replacingElement(cloneParent.get()); 637 RefPtrWillBeRawPtr<SVGElement> replacingElement(cloneParent.get());
641 638
642 // Replace <use> with referenced content. 639 // Replace <use> with referenced content.
643 use->parentNode()->replaceChild(cloneParent.release(), use); 640 use->parentNode()->replaceChild(cloneParent.release(), use);
644 641
645 use = Traversal<SVGUseElement>::next(*replacingElement, shadowRoot); 642 use = Traversal<SVGUseElement>::next(*replacingElement, shadowRoot);
646 } 643 }
647 return true; 644 return true;
648 } 645 }
649 646
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
793 790
794 if (m_resource) 791 if (m_resource)
795 m_resource->removeClient(this); 792 m_resource->removeClient(this);
796 793
797 m_resource = resource; 794 m_resource = resource;
798 if (m_resource) 795 if (m_resource)
799 m_resource->addClient(this); 796 m_resource->addClient(this);
800 } 797 }
801 798
802 } // namespace blink 799 } // namespace blink
OLDNEW
« 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