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

KHTML

  • khtml
  • svg
SVGAnimatedTemplate.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2004, 2005, 2006, 2007, 2008 Nikolas Zimmermann <zimmermann@kde.org>
3 2004, 2005 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 SVGAnimatedTemplate_h
24#define SVGAnimatedTemplate_h
25
26#if ENABLE(SVG)
27#include <wtf/RefCounted.h>
28//#include "AtomicString.h"
29//#include "Attribute.h"
30#include <wtf/HashTraits.h>
31#include <wtf/HashMap.h>
32
33
34namespace WebCore {
35
36 class FloatRect;
37 class SVGAngle;
38 class SVGElement;
39 class SVGLength;
40 class SVGLengthList;
41 class SVGNumberList;
42 class SVGPreserveAspectRatio;
43 class SVGTransformList;
44 //class String;
45 //class QualifiedName;
46
47 struct SVGAnimatedTypeWrapperKey {
48 // Empty value
49 SVGAnimatedTypeWrapperKey()
50 : element(0)
51 , attributeName(0)
52 { }
53
54 // Deleted value
55 SVGAnimatedTypeWrapperKey(WTF::HashTableDeletedValueType)
56 : element(reinterpret_cast<SVGElement*>(-1))
57 {
58 }
59 bool isHashTableDeletedValue() const
60 {
61 return element == reinterpret_cast<SVGElement*>(-1);
62 }
63
64 SVGAnimatedTypeWrapperKey(const SVGElement* _element, const AtomicString& _attributeName)
65 : element(_element)
66 , attributeName(_attributeName.impl())
67 {
68 ASSERT(element);
69 ASSERT(attributeName);
70 }
71
72 bool operator==(const SVGAnimatedTypeWrapperKey& other) const
73 {
74 return element == other.element && attributeName == other.attributeName;
75 }
76
77 const SVGElement* element;
78 AtomicStringImpl* attributeName;
79 };
80
81 struct SVGAnimatedTypeWrapperKeyHash {
82 static unsigned hash(const SVGAnimatedTypeWrapperKey& key)
83 {
84 return StringImpl::computeHash(reinterpret_cast<const UChar*>(&key), sizeof(SVGAnimatedTypeWrapperKey) / sizeof(UChar));
85 }
86
87 static bool equal(const SVGAnimatedTypeWrapperKey& a, const SVGAnimatedTypeWrapperKey& b)
88 {
89 return a == b;
90 }
91
92 static const bool safeToCompareToEmptyOrDeleted = true;
93 };
94
95 struct SVGAnimatedTypeWrapperKeyHashTraits : WTF::GenericHashTraits<SVGAnimatedTypeWrapperKey> {
96 static const bool emptyValueIsZero = true;
97
98 static void constructDeletedValue(SVGAnimatedTypeWrapperKey* slot)
99 {
100 new (slot) SVGAnimatedTypeWrapperKey(WTF::HashTableDeletedValue);
101 }
102 static bool isDeletedValue(const SVGAnimatedTypeWrapperKey& value)
103 {
104 return value.isHashTableDeletedValue();
105 }
106 };
107
108 template<typename BareType>
109 class SVGAnimatedTemplate : public RefCounted<SVGAnimatedTemplate<BareType> > {
110 public:
111 SVGAnimatedTemplate(const QualifiedName& attributeName)
112 : RefCounted<SVGAnimatedTemplate<BareType> >(0)
113 , m_associatedAttributeName(attributeName)
114 {
115 }
116
117 virtual ~SVGAnimatedTemplate() { forgetWrapper(this); }
118
119 virtual BareType baseVal() const = 0;
120 virtual void setBaseVal(BareType newBaseVal) = 0;
121
122 virtual BareType animVal() const = 0;
123 virtual void setAnimVal(BareType newAnimVal) = 0;
124
125 typedef HashMap<SVGAnimatedTypeWrapperKey, SVGAnimatedTemplate<BareType>*, SVGAnimatedTypeWrapperKeyHash, SVGAnimatedTypeWrapperKeyHashTraits > ElementToWrapperMap;
126 typedef typename ElementToWrapperMap::const_iterator ElementToWrapperMapIterator;
127
128 static ElementToWrapperMap* wrapperCache()
129 {
130 static ElementToWrapperMap* s_wrapperCache = new ElementToWrapperMap;
131 return s_wrapperCache;
132 }
133
134 static void forgetWrapper(SVGAnimatedTemplate<BareType>* wrapper)
135 {
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);
142 break;
143 }
144 }
145 }
146
147 const QualifiedName& associatedAttributeName() const { return m_associatedAttributeName; }
148
149 private:
150 const QualifiedName& m_associatedAttributeName;
151 };
152
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));
157 if (!wrapper) {
158 wrapper = new Type(element, domAttrName);
159 Type::wrapperCache()->set(key, wrapper);
160 }
161 return wrapper;
162 }
163
164 // Common type definitions, to ease IDL generation...
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;
177}
178
179#endif // ENABLE(SVG)
180#endif // SVGAnimatedTemplate_h
KShortcut::remove
void remove(const QKeySequence &keySeq, enum EmptyHandling handleEmpty=RemoveEmpty)
operator==
bool operator==(const KEntry &k1, const KEntry &k2)
Type
Type
end
const KShortcut & end()
WebCore
Definition: CSSHelper.h:7
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Feb 20 2023 00:00:00 by doxygen 1.9.6 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-4.14.38 API Reference

Skip menu "kdelibs-4.14.38 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
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
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