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

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

Issue 190793011: Use isSVG*Element() helpers more in SVG code (Part 4) (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 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 | Annotate | Revision Log
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 485 matching lines...) Expand 10 before | Expand all | Expand 10 after
496 String markup = serializer->serializeToString(shadowTreeRootElement, ASSERT_ NO_EXCEPTION); 496 String markup = serializer->serializeToString(shadowTreeRootElement, ASSERT_ NO_EXCEPTION);
497 fprintf(stderr, "Dumping <use> shadow tree markup:\n%s\n", markup.latin1().d ata()); 497 fprintf(stderr, "Dumping <use> shadow tree markup:\n%s\n", markup.latin1().d ata());
498 #endif 498 #endif
499 } 499 }
500 500
501 RenderObject* SVGUseElement::createRenderer(RenderStyle*) 501 RenderObject* SVGUseElement::createRenderer(RenderStyle*)
502 { 502 {
503 return new RenderSVGTransformableContainer(this); 503 return new RenderSVGTransformableContainer(this);
504 } 504 }
505 505
506 static bool isDirectReference(const Node* node) 506 static bool isDirectReference(const Node& node)
507 { 507 {
508 return node->hasTagName(SVGNames::pathTag) 508 return isSVGPathElement(node)
509 || node->hasTagName(SVGNames::rectTag) 509 || isSVGRectElement(node)
510 || node->hasTagName(SVGNames::circleTag) 510 || isSVGCircleElement(node)
511 || node->hasTagName(SVGNames::ellipseTag) 511 || isSVGEllipseElement(node)
512 || node->hasTagName(SVGNames::polygonTag) 512 || isSVGPolygonElement(node)
513 || node->hasTagName(SVGNames::polylineTag) 513 || isSVGPolylineElement(node)
514 || node->hasTagName(SVGNames::textTag); 514 || isSVGTextElement(node);
515 } 515 }
516 516
517 void SVGUseElement::toClipPath(Path& path) 517 void SVGUseElement::toClipPath(Path& path)
518 { 518 {
519 ASSERT(path.isEmpty()); 519 ASSERT(path.isEmpty());
520 520
521 Node* n = m_targetElementInstance ? m_targetElementInstance->shadowTreeEleme nt() : 0; 521 Node* n = m_targetElementInstance ? m_targetElementInstance->shadowTreeEleme nt() : 0;
522 if (!n) 522 if (!n)
523 return; 523 return;
524 524
525 if (n->isSVGElement() && toSVGElement(n)->isSVGGraphicsElement()) { 525 if (n->isSVGElement() && toSVGElement(n)->isSVGGraphicsElement()) {
526 if (!isDirectReference(n)) { 526 if (!isDirectReference(*n)) {
527 // Spec: Indirect references are an error (14.3.5) 527 // Spec: Indirect references are an error (14.3.5)
528 document().accessSVGExtensions().reportError("Not allowed to use ind irect reference in <clip-path>"); 528 document().accessSVGExtensions().reportError("Not allowed to use ind irect reference in <clip-path>");
529 } else { 529 } else {
530 toSVGGraphicsElement(n)->toClipPath(path); 530 toSVGGraphicsElement(n)->toClipPath(path);
531 // FIXME: Avoid manual resolution of x/y here. Its potentially harmf ul. 531 // FIXME: Avoid manual resolution of x/y here. Its potentially harmf ul.
532 SVGLengthContext lengthContext(this); 532 SVGLengthContext lengthContext(this);
533 path.translate(FloatSize(m_x->currentValue()->value(lengthContext), m_y->currentValue()->value(lengthContext))); 533 path.translate(FloatSize(m_x->currentValue()->value(lengthContext), m_y->currentValue()->value(lengthContext)));
534 path.transform(animatedLocalTransform()); 534 path.transform(animatedLocalTransform());
535 } 535 }
536 } 536 }
537 } 537 }
538 538
539 RenderObject* SVGUseElement::rendererClipChild() const 539 RenderObject* SVGUseElement::rendererClipChild() const
540 { 540 {
541 Node* n = m_targetElementInstance ? m_targetElementInstance->shadowTreeEleme nt() : 0; 541 Node* n = m_targetElementInstance ? m_targetElementInstance->shadowTreeEleme nt() : 0;
542 if (!n) 542 if (!n)
543 return 0; 543 return 0;
544 544
545 if (n->isSVGElement() && isDirectReference(n)) 545 if (n->isSVGElement() && isDirectReference(*n))
546 return toSVGElement(n)->renderer(); 546 return toSVGElement(n)->renderer();
547 547
548 return 0; 548 return 0;
549 } 549 }
550 550
551 void SVGUseElement::buildInstanceTree(SVGElement* target, SVGElementInstance* ta rgetInstance, bool& foundProblem, bool foundUse) 551 void SVGUseElement::buildInstanceTree(SVGElement* target, SVGElementInstance* ta rgetInstance, bool& foundProblem, bool foundUse)
552 { 552 {
553 ASSERT(target); 553 ASSERT(target);
554 ASSERT(targetInstance); 554 ASSERT(targetInstance);
555 555
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
727 for (RefPtr<Node> sibling = element->nextSibling(); sibling; sibling = s ibling->nextSibling()) 727 for (RefPtr<Node> sibling = element->nextSibling(); sibling; sibling = s ibling->nextSibling())
728 expandUseElementsInShadowTree(sibling.get()); 728 expandUseElementsInShadowTree(sibling.get());
729 } 729 }
730 730
731 for (RefPtr<Node> child = element->firstChild(); child; child = child->nextS ibling()) 731 for (RefPtr<Node> child = element->firstChild(); child; child = child->nextS ibling())
732 expandUseElementsInShadowTree(child.get()); 732 expandUseElementsInShadowTree(child.get());
733 } 733 }
734 734
735 void SVGUseElement::expandSymbolElementsInShadowTree(Node* element) 735 void SVGUseElement::expandSymbolElementsInShadowTree(Node* element)
736 { 736 {
737 if (element->hasTagName(SVGNames::symbolTag)) { 737 ASSERT(element);
738 if (isSVGSymbolElement(*element)) {
738 // Spec: The referenced 'symbol' and its contents are deep-cloned into t he generated tree, 739 // Spec: The referenced 'symbol' and its contents are deep-cloned into t he generated tree,
739 // with the exception that the 'symbol' is replaced by an 'svg'. This ge nerated 'svg' will 740 // with the exception that the 'symbol' is replaced by an 'svg'. This ge nerated 'svg' will
740 // always have explicit values for attributes width and height. If attri butes width and/or 741 // always have explicit values for attributes width and height. If attri butes width and/or
741 // height are provided on the 'use' element, then these attributes will be transferred to 742 // height are provided on the 'use' element, then these attributes will be transferred to
742 // the generated 'svg'. If attributes width and/or height are not specif ied, the generated 743 // the generated 'svg'. If attributes width and/or height are not specif ied, the generated
743 // 'svg' element will use values of 100% for these attributes. 744 // 'svg' element will use values of 100% for these attributes.
744 ASSERT(referencedDocument()); 745 ASSERT(referencedDocument());
745 RefPtr<SVGSVGElement> svgElement = SVGSVGElement::create(*referencedDocu ment()); 746 RefPtr<SVGSVGElement> svgElement = SVGSVGElement::create(*referencedDocu ment());
746 747
747 // Transfer all data (attributes, etc.) from <symbol> to the new <svg> e lement. 748 // Transfer all data (attributes, etc.) from <symbol> to the new <svg> e lement.
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
793 for (SVGElementInstance* instance = target->firstChild(); instance; instance = instance->nextSibling()) 794 for (SVGElementInstance* instance = target->firstChild(); instance; instance = instance->nextSibling())
794 transferEventListenersToShadowTree(instance); 795 transferEventListenersToShadowTree(instance);
795 } 796 }
796 797
797 void SVGUseElement::associateInstancesWithShadowTreeElements(Node* target, SVGEl ementInstance* targetInstance) 798 void SVGUseElement::associateInstancesWithShadowTreeElements(Node* target, SVGEl ementInstance* targetInstance)
798 { 799 {
799 if (!target || !targetInstance) 800 if (!target || !targetInstance)
800 return; 801 return;
801 802
802 SVGElement* originalElement = targetInstance->correspondingElement(); 803 SVGElement* originalElement = targetInstance->correspondingElement();
803 804 ASSERT(originalElement);
804 if (originalElement->hasTagName(SVGNames::useTag)) { 805 if (isSVGUseElement(*originalElement)) {
805 // <use> gets replaced by <g> 806 // <use> gets replaced by <g>
806 ASSERT(AtomicString(target->nodeName()) == SVGNames::gTag); 807 ASSERT(AtomicString(target->nodeName()) == SVGNames::gTag);
807 } else if (originalElement->hasTagName(SVGNames::symbolTag)) { 808 } else if (isSVGSymbolElement(*originalElement)) {
808 // <symbol> gets replaced by <svg> 809 // <symbol> gets replaced by <svg>
809 ASSERT(AtomicString(target->nodeName()) == SVGNames::svgTag); 810 ASSERT(AtomicString(target->nodeName()) == SVGNames::svgTag);
810 } else { 811 } else {
811 ASSERT(AtomicString(target->nodeName()) == originalElement->nodeName()); 812 ASSERT(AtomicString(target->nodeName()) == originalElement->nodeName());
812 } 813 }
813 814
814 SVGElement* element = 0; 815 SVGElement* element = 0;
815 if (target->isSVGElement()) 816 if (target->isSVGElement())
816 element = toSVGElement(target); 817 element = toSVGElement(target);
817 818
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
973 974
974 if (m_resource) 975 if (m_resource)
975 m_resource->removeClient(this); 976 m_resource->removeClient(this);
976 977
977 m_resource = resource; 978 m_resource = resource;
978 if (m_resource) 979 if (m_resource)
979 m_resource->addClient(this); 980 m_resource->addClient(this);
980 } 981 }
981 982
982 } 983 }
OLDNEW
« no previous file with comments | « Source/core/svg/SVGTextPositioningElement.cpp ('k') | Source/core/svg/animation/SVGSMILElement.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698