KHTML
SVGDocumentExtensions.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef SVGDocumentExtensions_h
00024 #define SVGDocumentExtensions_h
00025
00026 #if ENABLE(SVG)
00027
00028 #include <memory>
00029 #include <wtf/Forward.h>
00030 #include <wtf/HashSet.h>
00031 #include <wtf/HashMap.h>
00032
00033 #include "FloatRect.h"
00034 #include "StringHash.h"
00035
00036 #include "AtomicString.h"
00037 #include "xml/Document.h"
00038
00039 namespace DOM {
00040 class EventListener;
00041 }
00042
00043 namespace WebCore {
00044
00045
00046
00047
00048
00049
00050 class SVGElement;
00051 class SVGElementInstance;
00052 class SVGStyledElement;
00053 class SVGSVGElement;
00054 class TimeScheduler;
00055
00056 class DOMStringHash
00057 {
00058 public:
00059 static unsigned hash(DOMString key) { return qHash(key.implementation()); }
00060 static bool equal(DOMString a, DOMString b) { return a == b; }
00061 static const bool safeToCompareToEmptyOrDeleted = false;
00062 };
00063
00064 class SVGDocumentExtensions {
00065 public:
00066 SVGDocumentExtensions(Document*);
00067 ~SVGDocumentExtensions();
00068
00069 DOM::EventListener* createSVGEventListener(const DOMString& functionName, const DOMString& code, DOM::NodeImpl*);
00070
00071 void addTimeContainer(SVGSVGElement*);
00072 void removeTimeContainer(SVGSVGElement*);
00073
00074 void startAnimations();
00075 void pauseAnimations();
00076 void unpauseAnimations();
00077
00078 void reportWarning(const String&);
00079 void reportError(const String&);
00080
00081 private:
00082 Document* m_doc;
00083 HashSet<SVGSVGElement*> m_timeContainers;
00084
00085 HashMap<SVGElement*, HashSet<SVGElementInstance*>*> m_elementInstances;
00086
00087 SVGDocumentExtensions(const SVGDocumentExtensions&);
00088 SVGDocumentExtensions& operator=(const SVGDocumentExtensions&);
00089
00090 template<typename ValueType>
00091 HashMap<const SVGElement*, HashMap<StringImpl*, ValueType>*>* baseValueMap() const
00092 {
00093 static HashMap<const SVGElement*, HashMap<StringImpl*, ValueType>*>* s_baseValueMap = new HashMap<const SVGElement*, HashMap<StringImpl*, ValueType>*>();
00094 return s_baseValueMap;
00095 }
00096
00097 public:
00098
00099
00100
00101 void addPendingResource(const AtomicString& id, SVGStyledElement*);
00102 bool isPendingResource(const AtomicString& id) const;
00103 std::auto_ptr<HashSet<SVGStyledElement*> > removePendingResource(const AtomicString& id);
00104
00105
00106
00107 void mapInstanceToElement(SVGElementInstance*, SVGElement*);
00108 void removeInstanceMapping(SVGElementInstance*, SVGElement*);
00109 HashSet<SVGElementInstance*>* instancesForElement(SVGElement*) const;
00110
00111
00112 template<typename ValueType>
00113 ValueType baseValue(const SVGElement* element, const AtomicString& propertyName) const
00114 {
00115 HashMap<StringImpl*, ValueType>* propertyMap = baseValueMap<ValueType>()->get(element);
00116 if (propertyMap)
00117 return propertyMap->get(propertyName.impl());
00118
00119 return 0;
00120 }
00121
00122 template<typename ValueType>
00123 void setBaseValue(const SVGElement* element, const AtomicString& propertyName, ValueType newValue)
00124 {
00125 HashMap<StringImpl*, ValueType>* propertyMap = baseValueMap<ValueType>()->get(element);
00126 if (!propertyMap) {
00127 propertyMap = new HashMap<StringImpl*, ValueType>();
00128 baseValueMap<ValueType>()->set(element, propertyMap);
00129 }
00130
00131 propertyMap->set(propertyName.impl(), newValue);
00132 }
00133
00134 template<typename ValueType>
00135 void removeBaseValue(const SVGElement* element, const AtomicString& propertyName)
00136 {
00137 HashMap<StringImpl*, ValueType>* propertyMap = baseValueMap<ValueType>()->get(element);
00138 if (!propertyMap)
00139 return;
00140
00141 propertyMap->remove(propertyName.impl());
00142 }
00143
00144 template<typename ValueType>
00145 bool hasBaseValue(const SVGElement* element, const AtomicString& propertyName) const
00146 {
00147 HashMap<StringImpl*, ValueType>* propertyMap = baseValueMap<ValueType>()->get(element);
00148 if (propertyMap)
00149 return propertyMap->contains(propertyName.impl());
00150
00151 return false;
00152 }
00153 };
00154
00155
00156 template<>
00157 inline String SVGDocumentExtensions::baseValue<String>(const SVGElement* element, const AtomicString& propertyName) const
00158 {
00159 HashMap<StringImpl*, String>* propertyMap = baseValueMap<String>()->get(element);
00160 if (propertyMap)
00161 return propertyMap->get(propertyName.impl());
00162
00163 return String();
00164 }
00165
00166
00167 template<>
00168 inline FloatRect SVGDocumentExtensions::baseValue<FloatRect>(const SVGElement* element, const AtomicString& propertyName) const
00169 {
00170 HashMap<StringImpl*, FloatRect>* propertyMap = baseValueMap<FloatRect>()->get(element);
00171 if (propertyMap)
00172 return propertyMap->get(propertyName.impl());
00173
00174 return FloatRect();
00175 }
00176
00177
00178 template<>
00179 inline bool SVGDocumentExtensions::baseValue<bool>(const SVGElement* element, const AtomicString& propertyName) const
00180 {
00181 HashMap<StringImpl*, bool>* propertyMap = baseValueMap<bool>()->get(element);
00182 if (propertyMap)
00183 return propertyMap->get(propertyName.impl());
00184
00185 return false;
00186 }
00187
00188
00189 template<>
00190 inline double SVGDocumentExtensions::baseValue<double>(const SVGElement* element, const AtomicString& propertyName) const
00191 {
00192 HashMap<StringImpl*, double>* propertyMap = baseValueMap<double>()->get(element);
00193 if (propertyMap)
00194 return propertyMap->get(propertyName.impl());
00195
00196 return 0.0;
00197 }
00198
00199 }
00200
00201 #endif // ENABLE(SVG)
00202
00203 #endif