1 /* 2 * Copyright (C) 2004, 2005, 2006, 2007, 2008 Nikolas Zimmermann <zimmermann (at) kde.org> 3 * Copyright (C) 2004, 2005, 2006, 2007 Rob Buis <buis (at) kde.org> 4 * 5 * This library is free software; you can redistribute it and/or 6 * modify it under the terms of the GNU Library General Public 7 * License as published by the Free Software Foundation; either 8 * version 2 of the License, or (at your option) any later version. 9 * 10 * This library is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 * Library General Public License for more details. 14 * 15 * You should have received a copy of the GNU Library General Public License 16 * along with this library; see the file COPYING.LIB. If not, write to 17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 18 * Boston, MA 02110-1301, USA. 19 */ 20 21 #ifndef SVGUseElement_h 22 #define SVGUseElement_h 23 24 #include "core/SVGNames.h" 25 #include "core/fetch/DocumentResource.h" 26 #include "core/svg/SVGAnimatedBoolean.h" 27 #include "core/svg/SVGAnimatedLength.h" 28 #include "core/svg/SVGGraphicsElement.h" 29 #include "core/svg/SVGURIReference.h" 30 31 namespace WebCore { 32 33 class DocumentResource; 34 35 class SVGUseElement FINAL : public SVGGraphicsElement, 36 public SVGURIReference, 37 public DocumentResourceClient { 38 public: 39 static PassRefPtrWillBeRawPtr<SVGUseElement> create(Document&); 40 virtual ~SVGUseElement(); 41 42 void invalidateShadowTree(); 43 44 RenderObject* rendererClipChild() const; 45 46 SVGAnimatedLength* x() const { return m_x.get(); } 47 SVGAnimatedLength* y() const { return m_y.get(); } 48 SVGAnimatedLength* width() const { return m_width.get(); } 49 SVGAnimatedLength* height() const { return m_height.get(); } 50 51 virtual void buildPendingResource() OVERRIDE; 52 53 virtual void trace(Visitor*) OVERRIDE; 54 55 private: 56 explicit SVGUseElement(Document&); 57 58 virtual bool isStructurallyExternal() const OVERRIDE { return !hrefString().isNull() && isExternalURIReference(hrefString(), document()); } 59 60 virtual InsertionNotificationRequest insertedInto(ContainerNode*) OVERRIDE; 61 virtual void removedFrom(ContainerNode*) OVERRIDE; 62 63 bool isSupportedAttribute(const QualifiedName&); 64 virtual void parseAttribute(const QualifiedName&, const AtomicString&) OVERRIDE; 65 virtual void svgAttributeChanged(const QualifiedName&) OVERRIDE; 66 67 virtual RenderObject* createRenderer(RenderStyle*) OVERRIDE; 68 virtual void toClipPath(Path&) OVERRIDE; 69 70 void clearResourceReferences(); 71 void buildShadowAndInstanceTree(SVGElement* target); 72 73 void scheduleShadowTreeRecreation(); 74 virtual bool haveLoadedRequiredResources() OVERRIDE { return !isStructurallyExternal() || m_haveFiredLoadEvent; } 75 76 virtual bool selfHasRelativeLengths() const OVERRIDE; 77 78 // Instance tree handling 79 bool buildShadowTree(SVGElement* target, SVGElement* targetInstance, bool foundUse); 80 bool hasCycleUseReferencing(SVGUseElement*, ContainerNode* targetInstance, SVGElement*& newTarget); 81 bool expandUseElementsInShadowTree(SVGElement*); 82 void expandSymbolElementsInShadowTree(SVGElement*); 83 84 void transferUseAttributesToReplacedElement(SVGElement* from, SVGElement* to) const; 85 86 void invalidateDependentShadowTrees(); 87 88 bool resourceIsStillLoading(); 89 Document* externalDocument() const; 90 bool instanceTreeIsLoading(SVGElement*); 91 virtual void notifyFinished(Resource*) OVERRIDE; 92 TreeScope* referencedScope() const; 93 void setDocumentResource(ResourcePtr<DocumentResource>); 94 95 virtual Timer<SVGElement>* svgLoadEventTimer() OVERRIDE { return &m_svgLoadEventTimer; } 96 97 RefPtr<SVGAnimatedLength> m_x; 98 RefPtr<SVGAnimatedLength> m_y; 99 RefPtr<SVGAnimatedLength> m_width; 100 RefPtr<SVGAnimatedLength> m_height; 101 102 bool m_haveFiredLoadEvent; 103 bool m_needsShadowTreeRecreation; 104 RefPtrWillBeMember<SVGElement> m_targetElementInstance; 105 ResourcePtr<DocumentResource> m_resource; 106 Timer<SVGElement> m_svgLoadEventTimer; 107 }; 108 109 } 110 111 #endif 112