KHtml

SVGElement.h
1 /*
2  Copyright (C) 2004, 2005, 2006, 2008 Nikolas Zimmermann <[email protected]>
3  2004, 2005, 2006 Rob Buis <[email protected]>
4 
5  This file is part of the KDE project
6 
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.
11 
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.
16 
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.
21 */
22 
23 #ifndef SVGElement_h
24 #define SVGElement_h
25 
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"
33 
34 #include "ExceptionCode.h"
35 
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) { ASSERT_NOT_REACHED(); }\
40  virtual BareType LowerProperty##BaseValue() const { ASSERT_NOT_REACHED(); return NullType; } \
41  virtual void set##UpperProperty##BaseValue(BareType) { ASSERT_NOT_REACHED(); } \
42  virtual void start##UpperProperty() const { ASSERT_NOT_REACHED(); } \
43  virtual void stop##UpperProperty() { ASSERT_NOT_REACHED(); }
44 
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(); }
53 
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); \
65  \
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(); \
77  \
78  private: \
79  StorageType m_##LowerProperty;
80 
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)) { } \
84  \
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); \
100  } \
101  BareType ClassName::LowerProperty() const \
102  { \
103  return StorageGetter; \
104  } \
105  void ClassName::set##UpperProperty(BareType newValue) \
106  { \
107  m_##LowerProperty = newValue; \
108  } \
109  BareType ClassName::LowerProperty##BaseValue() const \
110  { \
111  const SVGElement* context = ContextElement; \
112  ASSERT(context); \
113  SVGDocumentExtensions* extensions = (context->document() ? context->document()->accessSVGExtensions() : nullptr); \
114  if (extensions && extensions->hasBaseValue<BareType>(context, AttrName)) \
115  return extensions->baseValue<BareType>(context, AttrName); \
116  return LowerProperty(); \
117  } \
118  void ClassName::set##UpperProperty##BaseValue(BareType newValue) \
119  { \
120  const SVGElement* context = ContextElement; \
121  ASSERT(context); \
122  SVGDocumentExtensions* extensions = (context->document() ? context->document()->accessSVGExtensions() : nullptr); \
123  if (extensions && extensions->hasBaseValue<BareType>(context, AttrName)) { \
124  extensions->setBaseValue<BareType>(context, AttrName, newValue); \
125  return; \
126  } \
127  /* Only update stored property, if not animating */ \
128  set##UpperProperty(newValue); \
129  } \
130  \
131  void ClassName::start##UpperProperty() const \
132  { \
133  const SVGElement* context = ContextElement; \
134  ASSERT(context); \
135  SVGDocumentExtensions* extensions = (context->document() ? context->document()->accessSVGExtensions() : nullptr); \
136  if (extensions) { \
137  ASSERT(!extensions->hasBaseValue<BareType>(context, AttrName)); \
138  extensions->setBaseValue<BareType>(context, AttrName, LowerProperty()); \
139  } \
140  } \
141  \
142  void ClassName::stop##UpperProperty() \
143  { \
144  const SVGElement* context = ContextElement; \
145  ASSERT(context); \
146  SVGDocumentExtensions* extensions = (context->document() ? context->document()->accessSVGExtensions() : nullptr); \
147  if (extensions) { \
148  ASSERT(extensions->hasBaseValue<BareType>(context, AttrName)); \
149  set##UpperProperty(extensions->baseValue<BareType>(context, AttrName)); \
150  extensions->removeBaseValue<BareType>(context, AttrName); \
151  } \
152  }
153 
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)
157 
158 #define ANIMATED_PROPERTY_DECLARATIONS(ClassName, BareType, StorageType, UpperProperty, LowerProperty) \
159  ANIMATED_PROPERTY_DECLARATIONS_INTERNAL(ClassName, RefPtr<ClassName>, BareType, StorageType, UpperProperty, LowerProperty)
160 
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 \
164  { \
165  const SVGElement* context = contextElement(); \
166  ASSERT(context); \
167  return lookupOrCreateWrapper<ClassName::SVGAnimatedTemplate##UpperProperty, SVGElement>(context, AttrName, AttrName.localName()); \
168  }
169 
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 \
173  { \
174  return lookupOrCreateWrapper<ClassName::SVGAnimatedTemplate##UpperProperty, ClassName>(this, AttrName, AttrIdentifier); \
175  }
176 
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)
179 
180 namespace WebCore
181 {
182 
183 class SVGPreserveAspectRatio;
184 class SVGSVGElement;
185 
186 class SVGElement : public StyledElement
187 {
188 public:
189  SVGElement(const QualifiedName &, Document *);
190  virtual ~SVGElement();
191  bool isSVGElement() const override
192  {
193  return true;
194  }
195  virtual bool isSupported(StringImpl *feature, StringImpl *version) const;
196 
197  String attrid() const;
198  void setId(const String &, ExceptionCode &);
199  String xmlbase() const;
200  void setXmlbase(const String &, ExceptionCode &);
201 
202  SVGSVGElement *ownerSVGElement() const;
203  SVGElement *viewportElement() const;
204 
205  virtual void parseMappedAttribute(MappedAttribute *);
206 
207  virtual bool isStyled() const
208  {
209  return false;
210  }
211  virtual bool isStyledTransformable() const
212  {
213  return false;
214  }
215  virtual bool isStyledLocatable() const
216  {
217  return false;
218  }
219  virtual bool isSVG() const
220  {
221  return false;
222  }
223  virtual bool isFilterEffect() const
224  {
225  return false;
226  }
227  virtual bool isGradientStop() const
228  {
229  return false;
230  }
231  virtual bool isTextContent() const
232  {
233  return false;
234  }
235 
236  bool isShadowNode() const override
237  {
238  return false; /*FIXME khtml return m_shadowParent;*/
239  }
240  Node *shadowParentNode() override
241  {
242  return m_shadowParent;
243  }
244  void setShadowParentNode(Node *node)
245  {
246  m_shadowParent = node;
247  }
248  virtual Node *eventParentNode()
249  {
250  return isShadowNode() ? shadowParentNode() : parentNode();
251  }
252 
253  // For SVGTests
254  virtual bool isValid() const
255  {
256  return true;
257  }
258 
259  virtual void finishParsingChildren();
260  // KHTML compatibility
261  void close() override
262  {
263  finishParsingChildren();
264  Element::close();
265  }
266  bool rendererIsNeeded(RenderStyle *) override
267  {
268  return false;
269  }
270  virtual bool childShouldCreateRenderer(Node *) const;
271 
272  void insertedIntoDocument() override;
273  virtual void buildPendingResource() { }
274 
275  virtual void svgAttributeChanged(const QualifiedName &) { }
276  using DOM::ElementImpl::attributeChanged;
277  void attributeChanged(Attribute *, bool preserveDecls = false) override;
278 
279  void sendSVGLoadEventIfPossible(bool sendParentLoadEvents = false);
280 
281  virtual AffineTransform *supplementalTransform()
282  {
283  return nullptr;
284  }
285 
286  // Forwarded properties (declared/defined anywhere else in the inheritance structure)
287 
288  // -> For SVGURIReference
289  ANIMATED_PROPERTY_EMPTY_DECLARATIONS(String, String(), Href, href)
290 
291  // -> For SVGFitToViewBox
292  ANIMATED_PROPERTY_EMPTY_DECLARATIONS(FloatRect, FloatRect(), ViewBox, viewBox)
293  ANIMATED_PROPERTY_EMPTY_DECLARATIONS(SVGPreserveAspectRatio *, nullptr, PreserveAspectRatio, preserveAspectRatio)
294 
295  // -> For SVGExternalResourcesRequired
296  ANIMATED_PROPERTY_EMPTY_DECLARATIONS(bool, false, ExternalResourcesRequired, externalResourcesRequired)
297 
298  virtual bool dispatchEvent(Event *e, ExceptionCode &ec, bool tempEvent = false);
299 
300  // for KHTML compatibility
301  void parseAttribute(Attribute *attr) override
302  {
303  parseMappedAttribute(attr);
304  }
305  virtual void addCSSProperty(Attribute *attr, int id, const String &value);
306  virtual void addCSSProperty(Attribute *attr, int id, int value);
307 
308 private:
309  void addSVGEventListener(const DOM::EventImpl::EventId &eventType, const DOM::AttributeImpl *);
310  virtual bool haveLoadedRequiredResources();
311 
312  Node *m_shadowParent;
313 };
314 
315 } // namespace WebCore
316 
317 #endif // ENABLE(SVG)
318 #endif // SVGElement_h
const QList< QKeySequence > & close()
QCA_EXPORT bool isSupported(const char *features, const QString &provider=QString())
bool isValid(QStringView ifopt)
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Tue Oct 26 2021 22:48:09 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.