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

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

Issue 2197533002: Use an open shadow root in <use> (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 ThreadState::current()->registerPreFinalizer(this); 67 ThreadState::current()->registerPreFinalizer(this);
68 68
69 addToPropertyMap(m_x); 69 addToPropertyMap(m_x);
70 addToPropertyMap(m_y); 70 addToPropertyMap(m_y);
71 addToPropertyMap(m_width); 71 addToPropertyMap(m_width);
72 addToPropertyMap(m_height); 72 addToPropertyMap(m_height);
73 } 73 }
74 74
75 SVGUseElement* SVGUseElement::create(Document& document) 75 SVGUseElement* SVGUseElement::create(Document& document)
76 { 76 {
77 // Always build a user agent #shadow-root for SVGUseElement. 77 // Always build a closed #shadow-root for SVGUseElement.
78 SVGUseElement* use = new SVGUseElement(document); 78 SVGUseElement* use = new SVGUseElement(document);
79 use->ensureUserAgentShadowRoot(); 79 use->ensureShadow().addShadowRoot(*use, ShadowRootType::Open);
80 return use; 80 return use;
81 } 81 }
82 82
83 SVGUseElement::~SVGUseElement() 83 SVGUseElement::~SVGUseElement()
84 { 84 {
85 } 85 }
86 86
87 void SVGUseElement::dispose() 87 void SVGUseElement::dispose()
88 { 88 {
89 setDocumentResource(nullptr); 89 setDocumentResource(nullptr);
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 { 295 {
296 if (m_targetElementInstance) 296 if (m_targetElementInstance)
297 m_targetElementInstance = nullptr; 297 m_targetElementInstance = nullptr;
298 } 298 }
299 299
300 void SVGUseElement::clearShadowTree() 300 void SVGUseElement::clearShadowTree()
301 { 301 {
302 clearInstanceRoot(); 302 clearInstanceRoot();
303 303
304 // FIXME: We should try to optimize this, to at least allow partial reclones . 304 // FIXME: We should try to optimize this, to at least allow partial reclones .
305 if (ShadowRoot* shadowTreeRootElement = userAgentShadowRoot()) 305 if (ShadowRoot* shadowTreeRootElement = openShadowRoot())
306 shadowTreeRootElement->removeChildren(OmitSubtreeModifiedEvent); 306 shadowTreeRootElement->removeChildren(OmitSubtreeModifiedEvent);
307 307
308 removeAllOutgoingReferences(); 308 removeAllOutgoingReferences();
309 } 309 }
310 310
311 Element* SVGUseElement::resolveTargetElement() 311 Element* SVGUseElement::resolveTargetElement()
312 { 312 {
313 if (m_elementIdentifier.isEmpty()) 313 if (m_elementIdentifier.isEmpty())
314 return nullptr; 314 return nullptr;
315 const TreeScope* lookupScope = nullptr; 315 const TreeScope* lookupScope = nullptr;
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
430 return; 430 return;
431 431
432 // Do not allow self-referencing. 432 // Do not allow self-referencing.
433 if (&target == this || isDisallowedElement(target)) 433 if (&target == this || isDisallowedElement(target))
434 return; 434 return;
435 435
436 // Set up root SVG element in shadow tree. 436 // Set up root SVG element in shadow tree.
437 // Clone the target subtree into the shadow tree, not handling <use> and <sy mbol> yet. 437 // Clone the target subtree into the shadow tree, not handling <use> and <sy mbol> yet.
438 Element* instanceRoot = createInstanceTree(target); 438 Element* instanceRoot = createInstanceTree(target);
439 m_targetElementInstance = toSVGElement(instanceRoot); 439 m_targetElementInstance = toSVGElement(instanceRoot);
440 ShadowRoot* shadowTreeRootElement = userAgentShadowRoot(); 440 ShadowRoot* shadowTreeRootElement = openShadowRoot();
441 shadowTreeRootElement->appendChild(instanceRoot); 441 shadowTreeRootElement->appendChild(instanceRoot);
442 442
443 addReferencesToFirstDegreeNestedUseElements(target); 443 addReferencesToFirstDegreeNestedUseElements(target);
444 444
445 if (instanceTreeIsLoading()) { 445 if (instanceTreeIsLoading()) {
446 cloneNonMarkupEventListeners(); 446 cloneNonMarkupEventListeners();
447 return; 447 return;
448 } 448 }
449 449
450 // Assure shadow tree building was successful. 450 // Assure shadow tree building was successful.
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
499 toSVGGeometryElement(*element).toClipPath(path); 499 toSVGGeometryElement(*element).toClipPath(path);
500 // FIXME: Avoid manual resolution of x/y here. Its potentially harmful. 500 // FIXME: Avoid manual resolution of x/y here. Its potentially harmful.
501 SVGLengthContext lengthContext(this); 501 SVGLengthContext lengthContext(this);
502 path.translate(FloatSize(m_x->currentValue()->value(lengthContext), m_y- >currentValue()->value(lengthContext))); 502 path.translate(FloatSize(m_x->currentValue()->value(lengthContext), m_y- >currentValue()->value(lengthContext)));
503 path.transform(calculateAnimatedLocalTransform()); 503 path.transform(calculateAnimatedLocalTransform());
504 } 504 }
505 } 505 }
506 506
507 SVGGraphicsElement* SVGUseElement::visibleTargetGraphicsElementForClipping() con st 507 SVGGraphicsElement* SVGUseElement::visibleTargetGraphicsElementForClipping() con st
508 { 508 {
509 Node* n = userAgentShadowRoot()->firstChild(); 509 Node* n = openShadowRoot()->firstChild();
510 if (!n || !n->isSVGElement()) 510 if (!n || !n->isSVGElement())
511 return nullptr; 511 return nullptr;
512 512
513 SVGElement& element = toSVGElement(*n); 513 SVGElement& element = toSVGElement(*n);
514 514
515 if (!element.isSVGGraphicsElement()) 515 if (!element.isSVGGraphicsElement())
516 return nullptr; 516 return nullptr;
517 517
518 if (!element.layoutObject()) 518 if (!element.layoutObject())
519 return nullptr; 519 return nullptr;
(...skipping 23 matching lines...) Expand all
543 // references are handled as the invalidation bubbles up the dependency 543 // references are handled as the invalidation bubbles up the dependency
544 // chain. 544 // chain.
545 SVGUseElement* useElement = 545 SVGUseElement* useElement =
546 isSVGUseElement(target) ? toSVGUseElement(&target) : Traversal<SVGUseEle ment>::firstWithin(target); 546 isSVGUseElement(target) ? toSVGUseElement(&target) : Traversal<SVGUseEle ment>::firstWithin(target);
547 for (; useElement; useElement = Traversal<SVGUseElement>::nextSkippingChildr en(*useElement, &target)) 547 for (; useElement; useElement = Traversal<SVGUseElement>::nextSkippingChildr en(*useElement, &target))
548 addReferenceTo(useElement); 548 addReferenceTo(useElement);
549 } 549 }
550 550
551 void SVGUseElement::cloneNonMarkupEventListeners() 551 void SVGUseElement::cloneNonMarkupEventListeners()
552 { 552 {
553 for (SVGElement& element : Traversal<SVGElement>::descendantsOf(*userAgentSh adowRoot())) { 553 for (SVGElement& element : Traversal<SVGElement>::descendantsOf(*openShadowR oot())) {
554 if (EventTargetData* data = element.correspondingElement()->eventTargetD ata()) 554 if (EventTargetData* data = element.correspondingElement()->eventTargetD ata())
555 data->eventListenerMap.copyEventListenersNotCreatedFromMarkupToTarge t(&element); 555 data->eventListenerMap.copyEventListenersNotCreatedFromMarkupToTarge t(&element);
556 } 556 }
557 } 557 }
558 558
559 bool SVGUseElement::hasCycleUseReferencing(const SVGUseElement& use, const Conta inerNode& targetInstance, SVGElement*& newTarget) const 559 bool SVGUseElement::hasCycleUseReferencing(const SVGUseElement& use, const Conta inerNode& targetInstance, SVGElement*& newTarget) const
560 { 560 {
561 Element* targetElement = targetElementFromIRIString(use.hrefString(), use.tr eeScope()); 561 Element* targetElement = targetElementFromIRIString(use.hrefString(), use.tr eeScope());
562 newTarget = 0; 562 newTarget = 0;
563 if (targetElement && targetElement->isSVGElement()) 563 if (targetElement && targetElement->isSVGElement())
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
597 597
598 bool SVGUseElement::expandUseElementsInShadowTree() 598 bool SVGUseElement::expandUseElementsInShadowTree()
599 { 599 {
600 // Why expand the <use> elements in the shadow tree here, and not just 600 // Why expand the <use> elements in the shadow tree here, and not just
601 // do this directly in buildShadowTree, if we encounter a <use> element? 601 // do this directly in buildShadowTree, if we encounter a <use> element?
602 // 602 //
603 // Short answer: Because we may miss to expand some elements. For example, i f a <symbol> 603 // Short answer: Because we may miss to expand some elements. For example, i f a <symbol>
604 // contains <use> tags, we'd miss them. So once we're done with setting up t he 604 // contains <use> tags, we'd miss them. So once we're done with setting up t he
605 // actual shadow tree (after the special case modification for svg/symbol) w e have 605 // actual shadow tree (after the special case modification for svg/symbol) w e have
606 // to walk it completely and expand all <use> elements. 606 // to walk it completely and expand all <use> elements.
607 ShadowRoot* shadowRoot = userAgentShadowRoot(); 607 ShadowRoot* shadowRoot = openShadowRoot();
608 for (SVGUseElement* use = Traversal<SVGUseElement>::firstWithin(*shadowRoot) ; use; ) { 608 for (SVGUseElement* use = Traversal<SVGUseElement>::firstWithin(*shadowRoot) ; use; ) {
609 ASSERT(!use->resourceIsStillLoading()); 609 ASSERT(!use->resourceIsStillLoading());
610 610
611 SVGUseElement& originalUse = toSVGUseElement(*use->correspondingElement( )); 611 SVGUseElement& originalUse = toSVGUseElement(*use->correspondingElement( ));
612 SVGElement* target = nullptr; 612 SVGElement* target = nullptr;
613 if (hasCycleUseReferencing(originalUse, *use, target)) 613 if (hasCycleUseReferencing(originalUse, *use, target))
614 return false; 614 return false;
615 615
616 if (target && isDisallowedElement(*target)) 616 if (target && isDisallowedElement(*target))
617 return false; 617 return false;
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
735 bool SVGUseElement::resourceIsValid() const 735 bool SVGUseElement::resourceIsValid() const
736 { 736 {
737 return m_resource 737 return m_resource
738 && m_resource->isLoaded() 738 && m_resource->isLoaded()
739 && !m_resource->errorOccurred() 739 && !m_resource->errorOccurred()
740 && m_resource->document(); 740 && m_resource->document();
741 } 741 }
742 742
743 bool SVGUseElement::instanceTreeIsLoading() const 743 bool SVGUseElement::instanceTreeIsLoading() const
744 { 744 {
745 for (const SVGUseElement& useElement : Traversal<SVGUseElement>::descendants Of(*userAgentShadowRoot())) { 745 for (const SVGUseElement& useElement : Traversal<SVGUseElement>::descendants Of(*openShadowRoot())) {
746 if (useElement.resourceIsStillLoading()) 746 if (useElement.resourceIsStillLoading())
747 return true; 747 return true;
748 } 748 }
749 return false; 749 return false;
750 } 750 }
751 751
752 void SVGUseElement::setDocumentResource(DocumentResource* resource) 752 void SVGUseElement::setDocumentResource(DocumentResource* resource)
753 { 753 {
754 if (m_resource == resource) 754 if (m_resource == resource)
755 return; 755 return;
756 756
757 if (m_resource) 757 if (m_resource)
758 m_resource->removeClient(this); 758 m_resource->removeClient(this);
759 759
760 m_resource = resource; 760 m_resource = resource;
761 if (m_resource) 761 if (m_resource)
762 m_resource->addClient(this); 762 m_resource->addClient(this);
763 } 763 }
764 764
765 } // namespace blink 765 } // 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