KHtml

SVGDocumentExtensions.h
1 /*
2  Copyright (C) 2006 Apple Computer, Inc.
3  2006 Nikolas Zimmermann <[email protected]>
4 
5  This file is part of the WebKit 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 SVGDocumentExtensions_h
24 #define SVGDocumentExtensions_h
25 
26 #if ENABLE(SVG)
27 
28 #include <memory>
29 #include <wtf/Forward.h>
30 #include <wtf/HashSet.h>
31 #include <wtf/HashMap.h>
32 
33 #include "FloatRect.h"
34 #include "StringHash.h"
35 //#include "StringImpl.h"
36 #include "AtomicString.h"
37 #include "xml/Document.h"
38 
39 namespace DOM
40 {
41 class EventListener;
42 }
43 
44 namespace WebCore
45 {
46 
47 //class AtomicString;
48 //class Document;
49 //class EventListener;
50 //class Node;
51 //class String;
52 class SVGElement;
53 class SVGElementInstance;
54 class SVGStyledElement;
55 class SVGSVGElement;
56 class TimeScheduler;
57 
58 class DOMStringHash
59 {
60 public:
61  static unsigned hash(DOMString key)
62  {
63  return qHash(key.implementation());
64  }
65  static bool equal(DOMString a, DOMString b)
66  {
67  return a == b;
68  }
69  static const bool safeToCompareToEmptyOrDeleted = false;
70 };
71 
72 class SVGDocumentExtensions
73 {
74 public:
75  SVGDocumentExtensions(Document *);
76  ~SVGDocumentExtensions();
77 
78  DOM::EventListener *createSVGEventListener(const DOMString &functionName, const DOMString &code, DOM::NodeImpl *);
79 
80  void addTimeContainer(SVGSVGElement *);
81  void removeTimeContainer(SVGSVGElement *);
82 
83  void startAnimations();
84  void pauseAnimations();
85  void unpauseAnimations();
86 
87  void reportWarning(const String &);
88  void reportError(const String &);
89 
90 private:
91  Document *m_doc; // weak reference
92  HashSet<SVGSVGElement *> m_timeContainers; // For SVG 1.2 support this will need to be made more general.
93  //HashMap<String, HashSet<SVGStyledElement*>*, DOMStringHash> m_pendingResources;
94  HashMap<SVGElement *, HashSet<SVGElementInstance *>*> m_elementInstances;
95 
96  SVGDocumentExtensions(const SVGDocumentExtensions &);
97  SVGDocumentExtensions &operator=(const SVGDocumentExtensions &);
98 
99  template<typename ValueType>
100  HashMap<const SVGElement *, HashMap<StringImpl *, ValueType>*> *baseValueMap() const
101  {
102  static HashMap<const SVGElement *, HashMap<StringImpl *, ValueType>*> *s_baseValueMap = new HashMap<const SVGElement *, HashMap<StringImpl *, ValueType>*>();
103  return s_baseValueMap;
104  }
105 
106 public:
107  // This HashMap contains a list of pending resources. Pending resources, are such
108  // which are referenced by any object in the SVG document, but do NOT exist yet.
109  // For instance, dynamically build gradients / patterns / clippers...
110  void addPendingResource(const AtomicString &id, SVGStyledElement *);
111  bool isPendingResource(const AtomicString &id) const;
112  std::unique_ptr<HashSet<SVGStyledElement *> > removePendingResource(const AtomicString &id);
113 
114  // This HashMap maps elements to their instances, when they are used by <use> elements.
115  // This is needed to synchronize the original element with the internally cloned one.
116  void mapInstanceToElement(SVGElementInstance *, SVGElement *);
117  void removeInstanceMapping(SVGElementInstance *, SVGElement *);
118  HashSet<SVGElementInstance *> *instancesForElement(SVGElement *) const;
119 
120  // Used by the ANIMATED_PROPERTY_* macros
121  template<typename ValueType>
122  ValueType baseValue(const SVGElement *element, const AtomicString &propertyName) const
123  {
124  HashMap<StringImpl *, ValueType> *propertyMap = baseValueMap<ValueType>()->get(element);
125  if (propertyMap) {
126  return propertyMap->get(propertyName.impl());
127  }
128 
129  return ValueType();
130  }
131 
132  template<typename ValueType>
133  void setBaseValue(const SVGElement *element, const AtomicString &propertyName, ValueType newValue)
134  {
135  HashMap<StringImpl *, ValueType> *propertyMap = baseValueMap<ValueType>()->get(element);
136  if (!propertyMap) {
137  propertyMap = new HashMap<StringImpl *, ValueType>();
138  baseValueMap<ValueType>()->set(element, propertyMap);
139  }
140 
141  propertyMap->set(propertyName.impl(), newValue);
142  }
143 
144  template<typename ValueType>
145  void removeBaseValue(const SVGElement *element, const AtomicString &propertyName)
146  {
147  HashMap<StringImpl *, ValueType> *propertyMap = baseValueMap<ValueType>()->get(element);
148  if (!propertyMap) {
149  return;
150  }
151 
152  propertyMap->remove(propertyName.impl());
153  }
154 
155  template<typename ValueType>
156  bool hasBaseValue(const SVGElement *element, const AtomicString &propertyName) const
157  {
158  HashMap<StringImpl *, ValueType> *propertyMap = baseValueMap<ValueType>()->get(element);
159  if (propertyMap) {
160  return propertyMap->contains(propertyName.impl());
161  }
162 
163  return false;
164  }
165 };
166 
167 // Special handling for WebCore::String
168 template<>
169 inline String SVGDocumentExtensions::baseValue<String>(const SVGElement *element, const AtomicString &propertyName) const
170 {
171  HashMap<StringImpl *, String> *propertyMap = baseValueMap<String>()->get(element);
172  if (propertyMap) {
173  return propertyMap->get(propertyName.impl());
174  }
175 
176  return String();
177 }
178 
179 // Special handling for WebCore::FloatRect
180 template<>
181 inline FloatRect SVGDocumentExtensions::baseValue<FloatRect>(const SVGElement *element, const AtomicString &propertyName) const
182 {
183  HashMap<StringImpl *, FloatRect> *propertyMap = baseValueMap<FloatRect>()->get(element);
184  if (propertyMap) {
185  return propertyMap->get(propertyName.impl());
186  }
187 
188  return FloatRect();
189 }
190 
191 // Special handling for booleans
192 template<>
193 inline bool SVGDocumentExtensions::baseValue<bool>(const SVGElement *element, const AtomicString &propertyName) const
194 {
195  HashMap<StringImpl *, bool> *propertyMap = baseValueMap<bool>()->get(element);
196  if (propertyMap) {
197  return propertyMap->get(propertyName.impl());
198  }
199 
200  return false;
201 }
202 
203 // Special handling for doubles
204 template<>
205 inline double SVGDocumentExtensions::baseValue<double>(const SVGElement *element, const AtomicString &propertyName) const
206 {
207  HashMap<StringImpl *, double> *propertyMap = baseValueMap<double>()->get(element);
208  if (propertyMap) {
209  return propertyMap->get(propertyName.impl());
210  }
211 
212  return 0.0;
213 }
214 
215 }
216 
217 #endif // ENABLE(SVG)
218 
219 #endif
KCALENDARCORE_EXPORT uint qHash(const KCalendarCore::Period &key)
Introduced in DOM Level 2.
Definition: dom2_events.h:69
This library provides a full-featured HTML parser and widget.
KCMUTILS_EXPORT KCModule * reportError(ErrorReporting report, const QString &text, const QString &details, QWidget *parent)
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Fri Oct 15 2021 22:48:13 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.