don't discard iframe children.
[kdelibs.git] / khtml / svg / SVGElement.h
blob3805685b5883b48f8b329b325cd51b24a83c28d4
1 /*
2 Copyright (C) 2004, 2005, 2006, 2008 Nikolas Zimmermann <zimmermann@kde.org>
3 2004, 2005, 2006 Rob Buis <buis@kde.org>
5 This file is part of the KDE project
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Library General Public
9 License as published by the Free Software Foundation; either
10 version 2 of the License, or (at your option) any later version.
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Library General Public License for more details.
17 You should have received a copy of the GNU Library General Public License
18 along with this library; see the file COPYING.LIB. If not, write to
19 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, USA.
23 #ifndef SVGElement_h
24 #define SVGElement_h
26 #if ENABLE(SVG)
27 #include "Document.h"
28 #include "FloatRect.h"
29 //#include "StyledElement.h"
30 #include "SVGAnimatedTemplate.h"
31 #include "SVGDocumentExtensions.h"
32 #include "SVGNames.h"
34 #include "ExceptionCode.h"
36 #define ANIMATED_PROPERTY_EMPTY_DECLARATIONS(BareType, NullType, UpperProperty, LowerProperty) \
37 public: \
38 virtual BareType LowerProperty() const { ASSERT_NOT_REACHED(); return NullType; } \
39 virtual void set##UpperProperty(BareType newValue) { ASSERT_NOT_REACHED(); }\
40 virtual BareType LowerProperty##BaseValue() const { ASSERT_NOT_REACHED(); return NullType; } \
41 virtual void set##UpperProperty##BaseValue(BareType newValue) { ASSERT_NOT_REACHED(); } \
42 virtual void start##UpperProperty() const { ASSERT_NOT_REACHED(); } \
43 virtual void stop##UpperProperty() { ASSERT_NOT_REACHED(); }
45 #define ANIMATED_PROPERTY_FORWARD_DECLARATIONS(ForwardClass, BareType, UpperProperty, LowerProperty) \
46 public: \
47 virtual BareType LowerProperty() const { return ForwardClass::LowerProperty(); } \
48 virtual void set##UpperProperty(BareType newValue) { ForwardClass::set##UpperProperty(newValue); } \
49 virtual BareType LowerProperty##BaseValue() const { return ForwardClass::LowerProperty##BaseValue(); } \
50 virtual void set##UpperProperty##BaseValue(BareType newValue) { ForwardClass::set##UpperProperty##BaseValue(newValue); } \
51 virtual void start##UpperProperty() const { ForwardClass::start##UpperProperty(); } \
52 virtual void stop##UpperProperty() { ForwardClass::stop##UpperProperty(); }
54 #define ANIMATED_PROPERTY_DECLARATIONS_INTERNAL(ClassType, ClassStorageType, BareType, StorageType, UpperProperty, LowerProperty) \
55 class SVGAnimatedTemplate##UpperProperty \
56 : public SVGAnimatedTemplate<BareType> \
57 { \
58 public: \
59 SVGAnimatedTemplate##UpperProperty(const ClassType*, const QualifiedName&); \
60 virtual ~SVGAnimatedTemplate##UpperProperty() { } \
61 virtual BareType baseVal() const; \
62 virtual void setBaseVal(BareType); \
63 virtual BareType animVal() const; \
64 virtual void setAnimVal(BareType); \
66 protected: \
67 ClassStorageType m_element; \
68 }; \
69 public: \
70 BareType LowerProperty() const; \
71 void set##UpperProperty(BareType); \
72 BareType LowerProperty##BaseValue() const; \
73 void set##UpperProperty##BaseValue(BareType); \
74 PassRefPtr<SVGAnimatedTemplate##UpperProperty> LowerProperty##Animated() const; \
75 void start##UpperProperty() const; \
76 void stop##UpperProperty(); \
78 private: \
79 StorageType m_##LowerProperty;
81 #define ANIMATED_PROPERTY_DEFINITIONS_INTERNAL(ClassName, ClassType, BareType, UpperClassName, LowerClassName, UpperProperty, LowerProperty, AttrName, StorageGetter, ContextElement) \
82 ClassName::SVGAnimatedTemplate##UpperProperty::SVGAnimatedTemplate##UpperProperty(const ClassType* element, const QualifiedName& attributeName) \
83 : SVGAnimatedTemplate<BareType>(attributeName), m_element(const_cast<ClassType*>(element)) { } \
85 BareType ClassName::SVGAnimatedTemplate##UpperProperty::baseVal() const \
86 { \
87 return m_element->LowerProperty##BaseValue(); \
88 } \
89 void ClassName::SVGAnimatedTemplate##UpperProperty::setBaseVal(BareType newBaseVal) \
90 { \
91 m_element->set##UpperProperty##BaseValue(newBaseVal); \
92 } \
93 BareType ClassName::SVGAnimatedTemplate##UpperProperty::animVal() const \
94 { \
95 return m_element->LowerProperty(); \
96 } \
97 void ClassName::SVGAnimatedTemplate##UpperProperty::setAnimVal(BareType newAnimVal) \
98 { \
99 m_element->set##UpperProperty(newAnimVal); \
101 BareType ClassName::LowerProperty() const \
103 return StorageGetter; \
105 void ClassName::set##UpperProperty(BareType newValue) \
107 m_##LowerProperty = newValue; \
109 BareType ClassName::LowerProperty##BaseValue() const \
111 const SVGElement* context = ContextElement; \
112 ASSERT(context); \
113 SVGDocumentExtensions* extensions = (context->document() ? context->document()->accessSVGExtensions() : 0); \
114 if (extensions && extensions->hasBaseValue<BareType>(context, AttrName)) \
115 return extensions->baseValue<BareType>(context, AttrName); \
116 return LowerProperty(); \
118 void ClassName::set##UpperProperty##BaseValue(BareType newValue) \
120 const SVGElement* context = ContextElement; \
121 ASSERT(context); \
122 SVGDocumentExtensions* extensions = (context->document() ? context->document()->accessSVGExtensions() : 0); \
123 if (extensions && extensions->hasBaseValue<BareType>(context, AttrName)) { \
124 extensions->setBaseValue<BareType>(context, AttrName, newValue); \
125 return; \
127 /* Only update stored property, if not animating */ \
128 set##UpperProperty(newValue); \
131 void ClassName::start##UpperProperty() const \
133 const SVGElement* context = ContextElement; \
134 ASSERT(context); \
135 SVGDocumentExtensions* extensions = (context->document() ? context->document()->accessSVGExtensions() : 0); \
136 if (extensions) { \
137 ASSERT(!extensions->hasBaseValue<BareType>(context, AttrName)); \
138 extensions->setBaseValue<BareType>(context, AttrName, LowerProperty()); \
142 void ClassName::stop##UpperProperty() \
144 const SVGElement* context = ContextElement; \
145 ASSERT(context); \
146 SVGDocumentExtensions* extensions = (context->document() ? context->document()->accessSVGExtensions() : 0); \
147 if (extensions) { \
148 ASSERT(extensions->hasBaseValue<BareType>(context, AttrName)); \
149 set##UpperProperty(extensions->baseValue<BareType>(context, AttrName)); \
150 extensions->removeBaseValue<BareType>(context, AttrName); \
154 // These are the macros which will be used to declare/implement the svg animated properties...
155 #define ANIMATED_PROPERTY_DECLARATIONS_WITH_CONTEXT(ClassName, BareType, StorageType, UpperProperty, LowerProperty) \
156 ANIMATED_PROPERTY_DECLARATIONS_INTERNAL(SVGElement, RefPtr<SVGElement>, BareType, StorageType, UpperProperty, LowerProperty)
158 #define ANIMATED_PROPERTY_DECLARATIONS(ClassName, BareType, StorageType, UpperProperty, LowerProperty) \
159 ANIMATED_PROPERTY_DECLARATIONS_INTERNAL(ClassName, RefPtr<ClassName>, BareType, StorageType, UpperProperty, LowerProperty)
161 #define ANIMATED_PROPERTY_DEFINITIONS_WITH_CONTEXT(ClassName, BareType, UpperClassName, LowerClassName, UpperProperty, LowerProperty, AttrName, StorageGetter) \
162 ANIMATED_PROPERTY_DEFINITIONS_INTERNAL(ClassName, SVGElement, BareType, UpperClassName, LowerClassName, UpperProperty, LowerProperty, AttrName.localName(), StorageGetter, contextElement()) \
163 PassRefPtr<ClassName::SVGAnimatedTemplate##UpperProperty> ClassName::LowerProperty##Animated() const \
165 const SVGElement* context = contextElement(); \
166 ASSERT(context); \
167 return lookupOrCreateWrapper<ClassName::SVGAnimatedTemplate##UpperProperty, SVGElement>(context, AttrName, AttrName.localName()); \
170 #define ANIMATED_PROPERTY_DEFINITIONS_WITH_CUSTOM_IDENTIFIER(ClassName, BareType, UpperClassName, LowerClassName, UpperProperty, LowerProperty, AttrName, AttrIdentifier, StorageGetter) \
171 ANIMATED_PROPERTY_DEFINITIONS_INTERNAL(ClassName, ClassName, BareType, UpperClassName, LowerClassName, UpperProperty, LowerProperty, AttrName.localName(), StorageGetter, this) \
172 PassRefPtr<ClassName::SVGAnimatedTemplate##UpperProperty> ClassName::LowerProperty##Animated() const \
174 return lookupOrCreateWrapper<ClassName::SVGAnimatedTemplate##UpperProperty, ClassName>(this, AttrName, AttrIdentifier); \
177 #define ANIMATED_PROPERTY_DEFINITIONS(ClassName, BareType, UpperClassName, LowerClassName, UpperProperty, LowerProperty, AttrName, StorageGetter) \
178 ANIMATED_PROPERTY_DEFINITIONS_WITH_CUSTOM_IDENTIFIER(ClassName, BareType, UpperClassName, LowerClassName, UpperProperty, LowerProperty, AttrName, AttrName.localName(), StorageGetter)
180 namespace WebCore {
182 class SVGPreserveAspectRatio;
183 class SVGSVGElement;
185 class SVGElement : public StyledElement {
186 public:
187 SVGElement(const QualifiedName&, Document*);
188 virtual ~SVGElement();
189 virtual bool isSVGElement() const { return true; }
190 virtual bool isSupported(StringImpl* feature, StringImpl* version) const;
192 String attrid() const;
193 void setId(const String&, ExceptionCode&);
194 String xmlbase() const;
195 void setXmlbase(const String&, ExceptionCode&);
197 SVGSVGElement* ownerSVGElement() const;
198 SVGElement* viewportElement() const;
200 virtual void parseMappedAttribute(MappedAttribute*);
202 virtual bool isStyled() const { return false; }
203 virtual bool isStyledTransformable() const { return false; }
204 virtual bool isStyledLocatable() const { return false; }
205 virtual bool isSVG() const { return false; }
206 virtual bool isFilterEffect() const { return false; }
207 virtual bool isGradientStop() const { return false; }
208 virtual bool isTextContent() const { return false; }
210 virtual bool isShadowNode() const { return false; /*FIXME khtml return m_shadowParent;*/ }
211 virtual Node* shadowParentNode() { return m_shadowParent; }
212 void setShadowParentNode(Node* node) { m_shadowParent = node; }
213 virtual Node* eventParentNode() { return isShadowNode() ? shadowParentNode() : parentNode(); }
215 // For SVGTests
216 virtual bool isValid() const { return true; }
218 virtual void finishParsingChildren();
219 // KHTML compatibility
220 virtual void close() { finishParsingChildren(); Element::close(); }
221 virtual bool rendererIsNeeded(RenderStyle*) { return false; }
222 virtual bool childShouldCreateRenderer(Node*) const;
224 virtual void insertedIntoDocument();
225 virtual void buildPendingResource() { }
227 virtual void svgAttributeChanged(const QualifiedName&) { }
228 virtual void attributeChanged(Attribute*, bool preserveDecls = false);
230 void sendSVGLoadEventIfPossible(bool sendParentLoadEvents = false);
232 virtual AffineTransform* supplementalTransform() { return 0; }
234 // Forwarded properties (declared/defined anywhere else in the inheritance structure)
237 // -> For SVGURIReference
238 ANIMATED_PROPERTY_EMPTY_DECLARATIONS(String, String(), Href, href)
240 // -> For SVGFitToViewBox
241 ANIMATED_PROPERTY_EMPTY_DECLARATIONS(FloatRect, FloatRect(), ViewBox, viewBox)
242 ANIMATED_PROPERTY_EMPTY_DECLARATIONS(SVGPreserveAspectRatio*, 0, PreserveAspectRatio, preserveAspectRatio)
244 // -> For SVGExternalResourcesRequired
245 ANIMATED_PROPERTY_EMPTY_DECLARATIONS(bool, false, ExternalResourcesRequired, externalResourcesRequired)
247 virtual bool dispatchEvent(Event* e, ExceptionCode& ec, bool tempEvent = false);
249 // for KHTML compatibility
250 virtual void parseAttribute(Attribute* attr) { parseMappedAttribute(attr); }
251 virtual void addCSSProperty(Attribute* attr, int id, const String& value);
252 virtual void addCSSProperty(Attribute* attr, int id, int value);
254 private:
255 void addSVGEventListener(const EventImpl::EventId& eventType, const Attribute*);
256 virtual bool haveLoadedRequiredResources();
258 Node* m_shadowParent;
261 } // namespace WebCore
263 #endif // ENABLE(SVG)
264 #endif // SVGElement_h