don't discard iframe children.
[kdelibs.git] / khtml / svg / SVGDocumentExtensions.h
blob68daa8a2863a8f68b432aba84fbf47f7ea9464d1
1 /*
2 Copyright (C) 2006 Apple Computer, Inc.
3 2006 Nikolas Zimmermann <zimmermann@kde.org>
5 This file is part of the WebKit 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 SVGDocumentExtensions_h
24 #define SVGDocumentExtensions_h
26 #if ENABLE(SVG)
28 #include <memory>
29 #include <wtf/Forward.h>
30 #include <wtf/HashSet.h>
31 #include <wtf/HashMap.h>
33 #include "FloatRect.h"
34 #include "StringHash.h"
35 //#include "StringImpl.h"
36 #include "AtomicString.h"
37 #include "xml/Document.h"
39 namespace DOM {
40 class EventListener;
43 namespace WebCore {
45 //class AtomicString;
46 //class Document;
47 //class EventListener;
48 //class Node;
49 //class String;
50 class SVGElement;
51 class SVGElementInstance;
52 class SVGStyledElement;
53 class SVGSVGElement;
54 class TimeScheduler;
56 class DOMStringHash
58 public:
59 static unsigned hash(DOMString key) { return qHash(key.implementation()); }
60 static bool equal(DOMString a, DOMString b) { return a == b; }
61 static const bool safeToCompareToEmptyOrDeleted = false;
64 class SVGDocumentExtensions {
65 public:
66 SVGDocumentExtensions(Document*);
67 ~SVGDocumentExtensions();
69 EventListener* createSVGEventListener(const String& functionName, const String& code, Node*);
71 void addTimeContainer(SVGSVGElement*);
72 void removeTimeContainer(SVGSVGElement*);
74 void startAnimations();
75 void pauseAnimations();
76 void unpauseAnimations();
78 void reportWarning(const String&);
79 void reportError(const String&);
81 private:
82 Document* m_doc; // weak reference
83 HashSet<SVGSVGElement*> m_timeContainers; // For SVG 1.2 support this will need to be made more general.
84 //HashMap<String, HashSet<SVGStyledElement*>*, DOMStringHash> m_pendingResources;
85 HashMap<SVGElement*, HashSet<SVGElementInstance*>*> m_elementInstances;
87 SVGDocumentExtensions(const SVGDocumentExtensions&);
88 SVGDocumentExtensions& operator=(const SVGDocumentExtensions&);
90 template<typename ValueType>
91 HashMap<const SVGElement*, HashMap<StringImpl*, ValueType>*>* baseValueMap() const
93 static HashMap<const SVGElement*, HashMap<StringImpl*, ValueType>*>* s_baseValueMap = new HashMap<const SVGElement*, HashMap<StringImpl*, ValueType>*>();
94 return s_baseValueMap;
97 public:
98 // This HashMap contains a list of pending resources. Pending resources, are such
99 // which are referenced by any object in the SVG document, but do NOT exist yet.
100 // For instance, dynamically build gradients / patterns / clippers...
101 void addPendingResource(const AtomicString& id, SVGStyledElement*);
102 bool isPendingResource(const AtomicString& id) const;
103 std::auto_ptr<HashSet<SVGStyledElement*> > removePendingResource(const AtomicString& id);
105 // This HashMap maps elements to their instances, when they are used by <use> elements.
106 // This is needed to synchronize the original element with the internally cloned one.
107 void mapInstanceToElement(SVGElementInstance*, SVGElement*);
108 void removeInstanceMapping(SVGElementInstance*, SVGElement*);
109 HashSet<SVGElementInstance*>* instancesForElement(SVGElement*) const;
111 // Used by the ANIMATED_PROPERTY_* macros
112 template<typename ValueType>
113 ValueType baseValue(const SVGElement* element, const AtomicString& propertyName) const
115 HashMap<StringImpl*, ValueType>* propertyMap = baseValueMap<ValueType>()->get(element);
116 if (propertyMap)
117 return propertyMap->get(propertyName.impl());
119 return 0;
122 template<typename ValueType>
123 void setBaseValue(const SVGElement* element, const AtomicString& propertyName, ValueType newValue)
125 HashMap<StringImpl*, ValueType>* propertyMap = baseValueMap<ValueType>()->get(element);
126 if (!propertyMap) {
127 propertyMap = new HashMap<StringImpl*, ValueType>();
128 baseValueMap<ValueType>()->set(element, propertyMap);
131 propertyMap->set(propertyName.impl(), newValue);
134 template<typename ValueType>
135 void removeBaseValue(const SVGElement* element, const AtomicString& propertyName)
137 HashMap<StringImpl*, ValueType>* propertyMap = baseValueMap<ValueType>()->get(element);
138 if (!propertyMap)
139 return;
141 propertyMap->remove(propertyName.impl());
144 template<typename ValueType>
145 bool hasBaseValue(const SVGElement* element, const AtomicString& propertyName) const
147 HashMap<StringImpl*, ValueType>* propertyMap = baseValueMap<ValueType>()->get(element);
148 if (propertyMap)
149 return propertyMap->contains(propertyName.impl());
151 return false;
155 // Special handling for WebCore::String
156 template<>
157 inline String SVGDocumentExtensions::baseValue<String>(const SVGElement* element, const AtomicString& propertyName) const
159 HashMap<StringImpl*, String>* propertyMap = baseValueMap<String>()->get(element);
160 if (propertyMap)
161 return propertyMap->get(propertyName.impl());
163 return String();
166 // Special handling for WebCore::FloatRect
167 template<>
168 inline FloatRect SVGDocumentExtensions::baseValue<FloatRect>(const SVGElement* element, const AtomicString& propertyName) const
170 HashMap<StringImpl*, FloatRect>* propertyMap = baseValueMap<FloatRect>()->get(element);
171 if (propertyMap)
172 return propertyMap->get(propertyName.impl());
174 return FloatRect();
177 // Special handling for booleans
178 template<>
179 inline bool SVGDocumentExtensions::baseValue<bool>(const SVGElement* element, const AtomicString& propertyName) const
181 HashMap<StringImpl*, bool>* propertyMap = baseValueMap<bool>()->get(element);
182 if (propertyMap)
183 return propertyMap->get(propertyName.impl());
185 return false;
188 // Special handling for doubles
189 template<>
190 inline double SVGDocumentExtensions::baseValue<double>(const SVGElement* element, const AtomicString& propertyName) const
192 HashMap<StringImpl*, double>* propertyMap = baseValueMap<double>()->get(element);
193 if (propertyMap)
194 return propertyMap->get(propertyName.impl());
196 return 0.0;
201 #endif // ENABLE(SVG)
203 #endif