File indexing completed on 2024-04-28 15:24:43
0001 /* 0002 Copyright (C) 2004, 2005, 2006, 2007, 2008 Nikolas Zimmermann <zimmermann@kde.org> 0003 2004, 2005, 2006, 2007 Rob Buis <buis@kde.org> 0004 0005 This file is part of the KDE project 0006 0007 This library is free software; you can redistribute it and/or 0008 modify it under the terms of the GNU Library General Public 0009 License as published by the Free Software Foundation; either 0010 version 2 of the License, or (at your option) any later version. 0011 0012 This library is distributed in the hope that it will be useful, 0013 but WITHOUT ANY WARRANTY; without even the implied warranty of 0014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0015 Library General Public License for more details. 0016 0017 You should have received a copy of the GNU Library General Public License 0018 along with this library; see the file COPYING.LIB. If not, write to 0019 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0020 Boston, MA 02110-1301, USA. 0021 */ 0022 0023 #ifndef SVGUseElement_h 0024 #define SVGUseElement_h 0025 0026 #if ENABLE(SVG) 0027 #include "SVGExternalResourcesRequired.h" 0028 #include "SVGLangSpace.h" 0029 #include "SVGStyledTransformableElement.h" 0030 #include "SVGTests.h" 0031 #include "SVGURIReference.h" 0032 0033 namespace WebCore 0034 { 0035 0036 class SVGElementInstance; 0037 class SVGLength; 0038 0039 class SVGUseElement : public SVGStyledTransformableElement, 0040 public SVGTests, 0041 public SVGLangSpace, 0042 public SVGExternalResourcesRequired, 0043 public SVGURIReference 0044 { 0045 public: 0046 SVGUseElement(const QualifiedName &, Document *); 0047 virtual ~SVGUseElement(); 0048 0049 SVGElementInstance *instanceRoot() const; 0050 SVGElementInstance *animatedInstanceRoot() const; 0051 0052 bool isValid() const override 0053 { 0054 return SVGTests::isValid(); 0055 } 0056 0057 void insertedIntoDocument() override; 0058 void removedFromDocument() override; 0059 void buildPendingResource() override; 0060 0061 void parseMappedAttribute(MappedAttribute *) override; 0062 using DOM::NodeImpl::childrenChanged; 0063 void childrenChanged(bool changedByParser = false, Node *beforeChange = nullptr, Node *afterChange = nullptr, int childCountDelta = 0) override; 0064 0065 void svgAttributeChanged(const QualifiedName &) override; 0066 void recalcStyle(StyleChange = NoChange) override; 0067 0068 RenderObject *createRenderer(RenderArena *, RenderStyle *) override; 0069 void attach() override; 0070 void detach() override; 0071 0072 Path toClipPath() const override; 0073 0074 static void removeDisallowedElementsFromSubtree(Node *element); 0075 0076 // KHTML ElementImpl pure virtual method 0077 quint32 id() const override 0078 { 0079 return SVGNames::useTag.id(); 0080 } 0081 protected: 0082 const SVGElement *contextElement() const override 0083 { 0084 return this; 0085 } 0086 0087 private: 0088 ANIMATED_PROPERTY_FORWARD_DECLARATIONS(SVGExternalResourcesRequired, bool, ExternalResourcesRequired, externalResourcesRequired) 0089 ANIMATED_PROPERTY_FORWARD_DECLARATIONS(SVGURIReference, String, Href, href) 0090 0091 ANIMATED_PROPERTY_DECLARATIONS(SVGUseElement, SVGLength, SVGLength, X, x) 0092 ANIMATED_PROPERTY_DECLARATIONS(SVGUseElement, SVGLength, SVGLength, Y, y) 0093 ANIMATED_PROPERTY_DECLARATIONS(SVGUseElement, SVGLength, SVGLength, Width, width) 0094 ANIMATED_PROPERTY_DECLARATIONS(SVGUseElement, SVGLength, SVGLength, Height, height) 0095 0096 private: 0097 friend class SVGElement; 0098 SVGElementInstance *instanceForShadowTreeElement(Node *element) const; 0099 0100 private: 0101 // Instance tree handling 0102 void buildInstanceTree(SVGElement *target, SVGElementInstance *targetInstance, bool &foundCycle); 0103 void handleDeepUseReferencing(SVGElement *use, SVGElementInstance *targetInstance, bool &foundCycle); 0104 0105 // Shadow tree handling 0106 PassRefPtr<SVGSVGElement> buildShadowTreeForSymbolTag(SVGElement *target, SVGElementInstance *targetInstance); 0107 void alterShadowTreeForSVGTag(SVGElement *target); 0108 0109 void buildShadowTree(SVGElement *target, SVGElementInstance *targetInstance); 0110 0111 #if ENABLE(SVG) && ENABLE(SVG_USE) 0112 void expandUseElementsInShadowTree(Node *element); 0113 void expandSymbolElementsInShadowTree(Node *element); 0114 #endif 0115 0116 void attachShadowTree(); 0117 0118 // "Tree connector" 0119 void associateInstancesWithShadowTreeElements(Node *target, SVGElementInstance *targetInstance); 0120 0121 SVGElementInstance *instanceForShadowTreeElement(Node *element, SVGElementInstance *instance) const; 0122 void transferUseAttributesToReplacedElement(SVGElement *from, SVGElement *to) const; 0123 0124 RefPtr<SVGElement> m_shadowTreeRootElement; 0125 RefPtr<SVGElementInstance> m_targetElementInstance; 0126 }; 0127 0128 } // namespace WebCore 0129 0130 #endif // ENABLE(SVG) 0131 #endif