23 #ifndef SVGAnimatedTemplate_h
24 #define SVGAnimatedTemplate_h
27 #include <wtf/RefCounted.h>
30 #include <wtf/HashTraits.h>
31 #include <wtf/HashMap.h>
42 class SVGPreserveAspectRatio;
43 class SVGTransformList;
47 struct SVGAnimatedTypeWrapperKey {
49 SVGAnimatedTypeWrapperKey()
55 SVGAnimatedTypeWrapperKey(WTF::HashTableDeletedValueType)
56 : element(reinterpret_cast<SVGElement*>(-1))
59 bool isHashTableDeletedValue()
const
61 return element ==
reinterpret_cast<SVGElement*
>(-1);
64 SVGAnimatedTypeWrapperKey(
const SVGElement* _element,
const AtomicString& _attributeName)
66 , attributeName(_attributeName.impl())
69 ASSERT(attributeName);
72 bool operator==(
const SVGAnimatedTypeWrapperKey& other)
const
74 return element == other.element && attributeName == other.attributeName;
77 const SVGElement* element;
78 AtomicStringImpl* attributeName;
81 struct SVGAnimatedTypeWrapperKeyHash {
82 static unsigned hash(
const SVGAnimatedTypeWrapperKey& key)
84 return StringImpl::computeHash(reinterpret_cast<const UChar*>(&key),
sizeof(SVGAnimatedTypeWrapperKey) /
sizeof(UChar));
87 static bool equal(
const SVGAnimatedTypeWrapperKey& a,
const SVGAnimatedTypeWrapperKey& b)
92 static const bool safeToCompareToEmptyOrDeleted =
true;
95 struct SVGAnimatedTypeWrapperKeyHashTraits : WTF::GenericHashTraits<SVGAnimatedTypeWrapperKey> {
96 static const bool emptyValueIsZero =
true;
98 static void constructDeletedValue(SVGAnimatedTypeWrapperKey* slot)
100 new (slot) SVGAnimatedTypeWrapperKey(WTF::HashTableDeletedValue);
102 static bool isDeletedValue(
const SVGAnimatedTypeWrapperKey& value)
104 return value.isHashTableDeletedValue();
108 template<
typename BareType>
109 class SVGAnimatedTemplate :
public RefCounted<SVGAnimatedTemplate<BareType> > {
111 SVGAnimatedTemplate(
const QualifiedName& attributeName)
112 : RefCounted<SVGAnimatedTemplate<BareType> >(0)
113 , m_associatedAttributeName(attributeName)
117 virtual ~SVGAnimatedTemplate() { forgetWrapper(
this); }
119 virtual BareType baseVal()
const = 0;
120 virtual void setBaseVal(BareType newBaseVal) = 0;
122 virtual BareType animVal()
const = 0;
123 virtual void setAnimVal(BareType newAnimVal) = 0;
125 typedef HashMap<SVGAnimatedTypeWrapperKey, SVGAnimatedTemplate<BareType>*, SVGAnimatedTypeWrapperKeyHash, SVGAnimatedTypeWrapperKeyHashTraits > ElementToWrapperMap;
126 typedef typename ElementToWrapperMap::const_iterator ElementToWrapperMapIterator;
128 static ElementToWrapperMap* wrapperCache()
130 static ElementToWrapperMap* s_wrapperCache =
new ElementToWrapperMap;
131 return s_wrapperCache;
134 static void forgetWrapper(SVGAnimatedTemplate<BareType>* wrapper)
136 ElementToWrapperMap* cache = wrapperCache();
137 ElementToWrapperMapIterator itr = cache->begin();
138 ElementToWrapperMapIterator
end = cache->end();
139 for (; itr != end; ++itr) {
140 if (itr->second == wrapper) {
141 cache->
remove(itr->first);
147 const QualifiedName& associatedAttributeName()
const {
return m_associatedAttributeName; }
150 const QualifiedName& m_associatedAttributeName;
153 template <
class Type,
class SVGElementSubClass>
154 Type* lookupOrCreateWrapper(
const SVGElementSubClass* element,
const QualifiedName& domAttrName,
const AtomicString& attrIdentifier) {
155 SVGAnimatedTypeWrapperKey key(element, attrIdentifier);
156 Type* wrapper =
static_cast<Type*
>(Type::wrapperCache()->get(key));
158 wrapper =
new Type(element, domAttrName);
159 Type::wrapperCache()->set(key, wrapper);
165 typedef SVGAnimatedTemplate<SVGAngle*> SVGAnimatedAngle;
166 typedef SVGAnimatedTemplate<bool> SVGAnimatedBoolean;
167 typedef SVGAnimatedTemplate<int> SVGAnimatedEnumeration;
168 typedef SVGAnimatedTemplate<long> SVGAnimatedInteger;
169 typedef SVGAnimatedTemplate<SVGLength> SVGAnimatedLength;
170 typedef SVGAnimatedTemplate<SVGLengthList*> SVGAnimatedLengthList;
171 typedef SVGAnimatedTemplate<float> SVGAnimatedNumber;
172 typedef SVGAnimatedTemplate<SVGNumberList*> SVGAnimatedNumberList;
173 typedef SVGAnimatedTemplate<SVGPreserveAspectRatio*> SVGAnimatedPreserveAspectRatio;
174 typedef SVGAnimatedTemplate<FloatRect> SVGAnimatedRect;
175 typedef SVGAnimatedTemplate<String> SVGAnimatedString;
176 typedef SVGAnimatedTemplate<SVGTransformList*> SVGAnimatedTransformList;
179 #endif // ENABLE(SVG)
180 #endif // SVGAnimatedTemplate_h
void remove(const QKeySequence &keySeq, enum EmptyHandling handleEmpty=RemoveEmpty)
bool operator==(const FloatPoint &a, const FloatPoint &b)