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
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"
47 //class EventListener;
51 class SVGElementInstance
;
52 class SVGStyledElement
;
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
{
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
&);
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
;
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
);
117 return propertyMap
->get(propertyName
.impl());
122 template<typename ValueType
>
123 void setBaseValue(const SVGElement
* element
, const AtomicString
& propertyName
, ValueType newValue
)
125 HashMap
<StringImpl
*, ValueType
>* propertyMap
= baseValueMap
<ValueType
>()->get(element
);
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
);
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
);
149 return propertyMap
->contains(propertyName
.impl());
155 // Special handling for WebCore::String
157 inline String
SVGDocumentExtensions::baseValue
<String
>(const SVGElement
* element
, const AtomicString
& propertyName
) const
159 HashMap
<StringImpl
*, String
>* propertyMap
= baseValueMap
<String
>()->get(element
);
161 return propertyMap
->get(propertyName
.impl());
166 // Special handling for WebCore::FloatRect
168 inline FloatRect
SVGDocumentExtensions::baseValue
<FloatRect
>(const SVGElement
* element
, const AtomicString
& propertyName
) const
170 HashMap
<StringImpl
*, FloatRect
>* propertyMap
= baseValueMap
<FloatRect
>()->get(element
);
172 return propertyMap
->get(propertyName
.impl());
177 // Special handling for booleans
179 inline bool SVGDocumentExtensions::baseValue
<bool>(const SVGElement
* element
, const AtomicString
& propertyName
) const
181 HashMap
<StringImpl
*, bool>* propertyMap
= baseValueMap
<bool>()->get(element
);
183 return propertyMap
->get(propertyName
.impl());
188 // Special handling for doubles
190 inline double SVGDocumentExtensions::baseValue
<double>(const SVGElement
* element
, const AtomicString
& propertyName
) const
192 HashMap
<StringImpl
*, double>* propertyMap
= baseValueMap
<double>()->get(element
);
194 return propertyMap
->get(propertyName
.impl());
201 #endif // ENABLE(SVG)