• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdelibs API Reference
  • KDE Home
  • Contact Us
 

KHTML

  • sources
  • kde-4.12
  • kdelibs
  • khtml
  • svg
SVGElement.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2004, 2005, 2006, 2008 Nikolas Zimmermann <zimmermann@kde.org>
3  2004, 2005, 2006 Rob Buis <buis@kde.org>
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() : 0); \
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() : 0); \
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() : 0); \
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() : 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); \
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  class SVGPreserveAspectRatio;
183  class SVGSVGElement;
184 
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;
191 
192  String attrid() const;
193  void setId(const String&, ExceptionCode&);
194  String xmlbase() const;
195  void setXmlbase(const String&, ExceptionCode&);
196 
197  SVGSVGElement* ownerSVGElement() const;
198  SVGElement* viewportElement() const;
199 
200  virtual void parseMappedAttribute(MappedAttribute*);
201 
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; }
209 
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(); }
214 
215  // For SVGTests
216  virtual bool isValid() const { return true; }
217 
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;
223 
224  virtual void insertedIntoDocument();
225  virtual void buildPendingResource() { }
226 
227  virtual void svgAttributeChanged(const QualifiedName&) { }
228  using DOM::ElementImpl::attributeChanged;
229  virtual void attributeChanged(Attribute*, bool preserveDecls = false);
230 
231  void sendSVGLoadEventIfPossible(bool sendParentLoadEvents = false);
232 
233  virtual AffineTransform* supplementalTransform() { return 0; }
234 
235  // Forwarded properties (declared/defined anywhere else in the inheritance structure)
236 
237 
238  // -> For SVGURIReference
239  ANIMATED_PROPERTY_EMPTY_DECLARATIONS(String, String(), Href, href)
240 
241  // -> For SVGFitToViewBox
242  ANIMATED_PROPERTY_EMPTY_DECLARATIONS(FloatRect, FloatRect(), ViewBox, viewBox)
243  ANIMATED_PROPERTY_EMPTY_DECLARATIONS(SVGPreserveAspectRatio*, 0, PreserveAspectRatio, preserveAspectRatio)
244 
245  // -> For SVGExternalResourcesRequired
246  ANIMATED_PROPERTY_EMPTY_DECLARATIONS(bool, false, ExternalResourcesRequired, externalResourcesRequired)
247 
248  virtual bool dispatchEvent(Event* e, ExceptionCode& ec, bool tempEvent = false);
249 
250  // for KHTML compatibility
251  virtual void parseAttribute(Attribute* attr) { parseMappedAttribute(attr); }
252  virtual void addCSSProperty(Attribute* attr, int id, const String& value);
253  virtual void addCSSProperty(Attribute* attr, int id, int value);
254 
255  private:
256  void addSVGEventListener(const DOM::EventImpl::EventId& eventType, const DOM::AttributeImpl*);
257  virtual bool haveLoadedRequiredResources();
258 
259  Node* m_shadowParent;
260  };
261 
262 } // namespace WebCore
263 
264 #endif // ENABLE(SVG)
265 #endif // SVGElement_h
isSupported
bool isSupported(const QString &mimeType, Mode mode=Writing)
SVGAnimatedTemplate.h
SVGNames.h
ExceptionCode.h
FloatRect.h
SVGDocumentExtensions.h
WebCore::String
DOM::DOMString String
Definition: PlatformString.h:8
close
KAction * close(const QObject *recvr, const char *slot, QObject *parent)
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:51:22 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KHTML

Skip menu "KHTML"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdelibs API Reference

Skip menu "kdelibs API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  • kjsembed
  •   WTF
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Nepomuk-Core
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal