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>
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.
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.
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.
21 #ifndef SVGUseElement_h
22 #define SVGUseElement_h
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"
33 class DocumentResource;
35 class SVGUseElement FINAL : public SVGGraphicsElement,
36 public SVGURIReference,
37 public DocumentResourceClient {
38 DEFINE_WRAPPERTYPEINFO();
40 static PassRefPtrWillBeRawPtr<SVGUseElement> create(Document&);
41 virtual ~SVGUseElement();
43 void invalidateShadowTree();
45 RenderObject* rendererClipChild() const;
47 SVGAnimatedLength* x() const { return m_x.get(); }
48 SVGAnimatedLength* y() const { return m_y.get(); }
49 SVGAnimatedLength* width() const { return m_width.get(); }
50 SVGAnimatedLength* height() const { return m_height.get(); }
52 virtual void buildPendingResource() OVERRIDE;
54 virtual void trace(Visitor*) OVERRIDE;
57 explicit SVGUseElement(Document&);
59 virtual bool isStructurallyExternal() const OVERRIDE { return !hrefString().isNull() && isExternalURIReference(hrefString(), document()); }
61 virtual InsertionNotificationRequest insertedInto(ContainerNode*) OVERRIDE;
62 virtual void removedFrom(ContainerNode*) OVERRIDE;
64 bool isSupportedAttribute(const QualifiedName&);
65 virtual void parseAttribute(const QualifiedName&, const AtomicString&) OVERRIDE;
66 virtual void svgAttributeChanged(const QualifiedName&) OVERRIDE;
68 virtual RenderObject* createRenderer(RenderStyle*) OVERRIDE;
69 virtual void toClipPath(Path&) OVERRIDE;
71 void clearResourceReferences();
72 void buildShadowAndInstanceTree(SVGElement* target);
74 void scheduleShadowTreeRecreation();
75 virtual bool haveLoadedRequiredResources() OVERRIDE { return !isStructurallyExternal() || m_haveFiredLoadEvent; }
77 virtual bool selfHasRelativeLengths() const OVERRIDE;
79 // Instance tree handling
80 bool buildShadowTree(SVGElement* target, SVGElement* targetInstance, bool foundUse);
81 bool hasCycleUseReferencing(SVGUseElement*, ContainerNode* targetInstance, SVGElement*& newTarget);
82 bool expandUseElementsInShadowTree(SVGElement*);
83 void expandSymbolElementsInShadowTree(SVGElement*);
85 void transferUseAttributesToReplacedElement(SVGElement* from, SVGElement* to) const;
87 void invalidateDependentShadowTrees();
89 bool resourceIsStillLoading();
90 Document* externalDocument() const;
91 bool instanceTreeIsLoading(SVGElement*);
92 virtual void notifyFinished(Resource*) OVERRIDE;
93 TreeScope* referencedScope() const;
94 void setDocumentResource(ResourcePtr<DocumentResource>);
96 virtual Timer<SVGElement>* svgLoadEventTimer() OVERRIDE { return &m_svgLoadEventTimer; }
98 RefPtr<SVGAnimatedLength> m_x;
99 RefPtr<SVGAnimatedLength> m_y;
100 RefPtr<SVGAnimatedLength> m_width;
101 RefPtr<SVGAnimatedLength> m_height;
103 bool m_haveFiredLoadEvent;
104 bool m_needsShadowTreeRecreation;
105 RefPtrWillBeMember<SVGElement> m_targetElementInstance;
106 ResourcePtr<DocumentResource> m_resource;
107 Timer<SVGElement> m_svgLoadEventTimer;
112 #endif // SVGUseElement_h