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

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

Issue 269843002: Use m_targetElementInstance in fewer places (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 7 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 | « Source/core/svg/SVGUseElement.h ('k') | 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 463 matching lines...) Expand 10 before | Expand all | Expand 10 after
474 ASSERT(!m_targetElementInstance->shadowTreeElement()); 474 ASSERT(!m_targetElementInstance->shadowTreeElement());
475 ASSERT(m_targetElementInstance->correspondingUseElement() == this); 475 ASSERT(m_targetElementInstance->correspondingUseElement() == this);
476 ASSERT(m_targetElementInstance->directUseElement() == this); 476 ASSERT(m_targetElementInstance->directUseElement() == this);
477 ASSERT(m_targetElementInstance->correspondingElement() == target); 477 ASSERT(m_targetElementInstance->correspondingElement() == target);
478 478
479 ShadowRoot* shadowTreeRootElement = userAgentShadowRoot(); 479 ShadowRoot* shadowTreeRootElement = userAgentShadowRoot();
480 ASSERT(shadowTreeRootElement); 480 ASSERT(shadowTreeRootElement);
481 481
482 // Build shadow tree from instance tree 482 // Build shadow tree from instance tree
483 // This also handles the special cases: <use> on <symbol>, <use> on <svg>. 483 // This also handles the special cases: <use> on <symbol>, <use> on <svg>.
484 buildShadowTree(target, m_targetElementInstance.get()); 484 buildShadowTree(target, m_targetElementInstance.get());
pdr. 2014/05/03 21:02:08 Could you pass in shadowTreeRootElement here to av
485 485
486 // Expand all <use> elements in the shadow tree. 486 // Expand all <use> elements in the shadow tree.
487 // Expand means: replace the actual <use> element by what it references. 487 // Expand means: replace the actual <use> element by what it references.
488 expandUseElementsInShadowTree(shadowTreeRootElement); 488 expandUseElementsInShadowTree(shadowTreeRootElement);
489 489
490 // Expand all <symbol> elements in the shadow tree. 490 // Expand all <symbol> elements in the shadow tree.
491 // Expand means: replace the actual <symbol> element by the <svg> element. 491 // Expand means: replace the actual <symbol> element by the <svg> element.
492 expandSymbolElementsInShadowTree(shadowTreeRootElement); 492 expandSymbolElementsInShadowTree(shadowTreeRootElement);
493 493
494 Node* shadowTreeTargetNode = shadowTreeRootElement->firstChild();
494 // Now that the shadow tree is completly expanded, we can associate 495 // Now that the shadow tree is completly expanded, we can associate
495 // shadow tree elements <-> instances in the instance tree. 496 // shadow tree elements <-> instances in the instance tree.
496 associateInstancesWithShadowTreeElements(shadowTreeRootElement->firstChild() , m_targetElementInstance.get()); 497 associateInstancesWithShadowTreeElements(shadowTreeTargetNode, m_targetEleme ntInstance.get());
pdr. 2014/05/03 21:02:08 Can this be moved below the !shadowTreeTargetNode
497
498 ASSERT(m_targetElementInstance->correspondingElement());
499 transferUseWidthAndHeightIfNeeded(*this, m_targetElementInstance->shadowTree Element(), *m_targetElementInstance->correspondingElement());
500 498
501 // If no shadow tree element is present, this means that the reference root 499 // If no shadow tree element is present, this means that the reference root
502 // element was removed, as it is disallowed (ie. <use> on <foreignObject>) 500 // element was removed, as it is disallowed (ie. <use> on <foreignObject>)
503 // Do NOT leave an inconsistent instance tree around, instead destruct it. 501 // Do NOT leave an inconsistent instance tree around, instead destruct it.
504 if (!m_targetElementInstance->shadowTreeElement()) { 502 if (!shadowTreeTargetNode) {
505 clearResourceReferences(); 503 clearResourceReferences();
506 return; 504 return;
507 } 505 }
508 506
509 ASSERT(m_targetElementInstance->shadowTreeElement()->parentNode() == shadowT reeRootElement); 507 SVGElement* shadowTreeTargetElement = toSVGElement(shadowTreeTargetNode);
508 ASSERT(shadowTreeTargetElement->correspondingElement());
509 transferUseWidthAndHeightIfNeeded(*this, shadowTreeTargetElement, *shadowTre eTargetElement->correspondingElement());
510
511 ASSERT(shadowTreeTargetNode()->parentNode() == shadowTreeRootElement);
510 512
511 // Transfer event listeners assigned to the referenced element to our shadow tree elements. 513 // Transfer event listeners assigned to the referenced element to our shadow tree elements.
512 transferEventListenersToShadowTree(m_targetElementInstance.get()); 514 transferEventListenersToShadowTree(shadowTreeTargetElement);
513 515
514 // Update relative length information. 516 // Update relative length information.
515 updateRelativeLengthsInformation(); 517 updateRelativeLengthsInformation();
516 518
517 // Eventually dump instance tree 519 // Eventually dump instance tree
518 #ifdef DUMP_INSTANCE_TREE 520 #ifdef DUMP_INSTANCE_TREE
519 String text; 521 String text;
520 unsigned depth = 0; 522 unsigned depth = 0;
521 523
522 dumpInstanceTree(depth, text, m_targetElementInstance.get()); 524 dumpInstanceTree(depth, text, m_targetElementInstance.get());
(...skipping 21 matching lines...) Expand all
544 || isSVGEllipseElement(node) 546 || isSVGEllipseElement(node)
545 || isSVGPolygonElement(node) 547 || isSVGPolygonElement(node)
546 || isSVGPolylineElement(node) 548 || isSVGPolylineElement(node)
547 || isSVGTextElement(node); 549 || isSVGTextElement(node);
548 } 550 }
549 551
550 void SVGUseElement::toClipPath(Path& path) 552 void SVGUseElement::toClipPath(Path& path)
551 { 553 {
552 ASSERT(path.isEmpty()); 554 ASSERT(path.isEmpty());
553 555
554 Node* n = m_targetElementInstance ? m_targetElementInstance->shadowTreeEleme nt() : 0; 556 Node* n = userAgentShadowRoot()->firstChild();
555 if (!n) 557 if (!n)
556 return; 558 return;
557 559
558 if (n->isSVGElement() && toSVGElement(n)->isSVGGraphicsElement()) { 560 if (n->isSVGElement() && toSVGElement(n)->isSVGGraphicsElement()) {
559 if (!isDirectReference(*n)) { 561 if (!isDirectReference(*n)) {
560 // Spec: Indirect references are an error (14.3.5) 562 // Spec: Indirect references are an error (14.3.5)
561 document().accessSVGExtensions().reportError("Not allowed to use ind irect reference in <clip-path>"); 563 document().accessSVGExtensions().reportError("Not allowed to use ind irect reference in <clip-path>");
562 } else { 564 } else {
563 toSVGGraphicsElement(n)->toClipPath(path); 565 toSVGGraphicsElement(n)->toClipPath(path);
564 // FIXME: Avoid manual resolution of x/y here. Its potentially harmf ul. 566 // FIXME: Avoid manual resolution of x/y here. Its potentially harmf ul.
565 SVGLengthContext lengthContext(this); 567 SVGLengthContext lengthContext(this);
566 path.translate(FloatSize(m_x->currentValue()->value(lengthContext), m_y->currentValue()->value(lengthContext))); 568 path.translate(FloatSize(m_x->currentValue()->value(lengthContext), m_y->currentValue()->value(lengthContext)));
567 path.transform(animatedLocalTransform()); 569 path.transform(animatedLocalTransform());
568 } 570 }
569 } 571 }
570 } 572 }
571 573
572 RenderObject* SVGUseElement::rendererClipChild() const 574 RenderObject* SVGUseElement::rendererClipChild() const
573 { 575 {
574 Node* n = m_targetElementInstance ? m_targetElementInstance->shadowTreeEleme nt() : 0; 576 if (Node* n = userAgentShadowRoot()->firstChild()) {
575 if (!n) 577 if (n->isSVGElement() && isDirectReference(*n))
576 return 0; 578 return toSVGElement(n)->renderer();
577 579 }
578 if (n->isSVGElement() && isDirectReference(*n))
579 return toSVGElement(n)->renderer();
580 580
581 return 0; 581 return 0;
582 } 582 }
583 583
584 void SVGUseElement::buildInstanceTree(SVGElement* target, SVGElementInstance* ta rgetInstance, bool& foundProblem, bool foundUse) 584 void SVGUseElement::buildInstanceTree(SVGElement* target, SVGElementInstance* ta rgetInstance, bool& foundProblem, bool foundUse)
585 { 585 {
586 ASSERT(target); 586 ASSERT(target);
587 ASSERT(targetInstance); 587 ASSERT(targetInstance);
588 588
589 // Spec: If the referenced object is itself a 'use', or if there are 'use' s ubelements within the referenced 589 // Spec: If the referenced object is itself a 'use', or if there are 'use' s ubelements within the referenced
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
801 // lose the sibling chain when we are back from recursion. 801 // lose the sibling chain when we are back from recursion.
802 element = replacingElement.get(); 802 element = replacingElement.get();
803 for (RefPtr<Node> sibling = element->nextSibling(); sibling; sibling = s ibling->nextSibling()) 803 for (RefPtr<Node> sibling = element->nextSibling(); sibling; sibling = s ibling->nextSibling())
804 expandSymbolElementsInShadowTree(sibling.get()); 804 expandSymbolElementsInShadowTree(sibling.get());
805 } 805 }
806 806
807 for (RefPtr<Node> child = element->firstChild(); child; child = child->nextS ibling()) 807 for (RefPtr<Node> child = element->firstChild(); child; child = child->nextS ibling())
808 expandSymbolElementsInShadowTree(child.get()); 808 expandSymbolElementsInShadowTree(child.get());
809 } 809 }
810 810
811 void SVGUseElement::transferEventListenersToShadowTree(SVGElementInstance* targe t) 811 void SVGUseElement::transferEventListenersToShadowTree(SVGElement* shadowElement )
pdr. 2014/05/03 21:02:08 For consistency, can we call this the shadowTreeTa
812 { 812 {
813 if (!target) 813 if (!shadowElement)
814 return; 814 return;
815 815
816 SVGElement* originalElement = target->correspondingElement(); 816 SVGElement* originalElement = shadowElement->correspondingElement();
817 ASSERT(originalElement); 817 ASSERT(originalElement);
818 if (EventTargetData* data = originalElement->eventTargetData())
819 data->eventListenerMap.copyEventListenersNotCreatedFromMarkupToTarget(sh adowElement);
818 820
819 if (SVGElement* shadowTreeElement = target->shadowTreeElement()) { 821 for (SVGElement* child = Traversal<SVGElement>::firstChild(*shadowElement); child; child = Traversal<SVGElement>::nextSibling(*child))
820 if (EventTargetData* data = originalElement->eventTargetData()) 822 transferEventListenersToShadowTree(child);
821 data->eventListenerMap.copyEventListenersNotCreatedFromMarkupToTarge t(shadowTreeElement);
822 }
823
824 for (SVGElementInstance* instance = target->firstChild(); instance; instance = instance->nextSibling())
825 transferEventListenersToShadowTree(instance);
826 } 823 }
827 824
828 void SVGUseElement::associateInstancesWithShadowTreeElements(Node* target, SVGEl ementInstance* targetInstance) 825 void SVGUseElement::associateInstancesWithShadowTreeElements(Node* target, SVGEl ementInstance* targetInstance)
829 { 826 {
830 if (!target || !targetInstance) 827 if (!target || !targetInstance)
831 return; 828 return;
832 829
833 SVGElement* originalElement = targetInstance->correspondingElement(); 830 SVGElement* originalElement = targetInstance->correspondingElement();
834 ASSERT(originalElement); 831 ASSERT(originalElement);
835 if (isSVGUseElement(*originalElement)) { 832 if (isSVGUseElement(*originalElement)) {
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
997 994
998 if (m_resource) 995 if (m_resource)
999 m_resource->removeClient(this); 996 m_resource->removeClient(this);
1000 997
1001 m_resource = resource; 998 m_resource = resource;
1002 if (m_resource) 999 if (m_resource)
1003 m_resource->addClient(this); 1000 m_resource->addClient(this);
1004 } 1001 }
1005 1002
1006 } 1003 }
OLDNEW
« no previous file with comments | « Source/core/svg/SVGUseElement.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698