2 Copyright (C) 2006 Apple Computer, Inc.
3 2006, 2008 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/HashSet.h>
30 #include <wtf/HashMap.h>
32 #include "StringHash.h"
33 #include "StringImpl.h"
34 #include "SVGAnimatedTemplate.h"
42 class SVGElementInstance
;
43 class SVGStyledElement
;
47 class SVGDocumentExtensions
: public Noncopyable
{
49 SVGDocumentExtensions(Document
*);
50 ~SVGDocumentExtensions();
52 void addTimeContainer(SVGSVGElement
*);
53 void removeTimeContainer(SVGSVGElement
*);
55 void startAnimations();
56 void pauseAnimations();
57 void unpauseAnimations();
58 bool sampleAnimationAtTime(const String
& elementId
, SVGSMILElement
*, double time
);
60 void reportWarning(const String
&);
61 void reportError(const String
&);
64 Document
* m_doc
; // weak reference
65 HashSet
<SVGSVGElement
*> m_timeContainers
; // For SVG 1.2 support this will need to be made more general.
66 HashMap
<String
, HashSet
<SVGStyledElement
*>*> m_pendingResources
;
68 SVGDocumentExtensions(const SVGDocumentExtensions
&);
69 SVGDocumentExtensions
& operator=(const SVGDocumentExtensions
&);
71 template<typename ValueType
>
72 HashMap
<const SVGElement
*, HashMap
<StringImpl
*, ValueType
>*>* baseValueMap() const
74 static HashMap
<const SVGElement
*, HashMap
<StringImpl
*, ValueType
>*>* s_baseValueMap
= new HashMap
<const SVGElement
*, HashMap
<StringImpl
*, ValueType
>*>();
75 return s_baseValueMap
;
79 // This HashMap contains a list of pending resources. Pending resources, are such
80 // which are referenced by any object in the SVG document, but do NOT exist yet.
81 // For instance, dynamically build gradients / patterns / clippers...
82 void addPendingResource(const AtomicString
& id
, SVGStyledElement
*);
83 bool isPendingResource(const AtomicString
& id
) const;
84 std::auto_ptr
<HashSet
<SVGStyledElement
*> > removePendingResource(const AtomicString
& id
);
86 // Used by the ANIMATED_PROPERTY_* macros
87 template<typename ValueType
>
88 ValueType
baseValue(const SVGElement
* element
, const AtomicString
& propertyName
) const
90 HashMap
<StringImpl
*, ValueType
>* propertyMap
= baseValueMap
<ValueType
>()->get(element
);
92 return propertyMap
->get(propertyName
.impl());
94 return SVGAnimatedTypeValue
<ValueType
>::null();
97 template<typename ValueType
>
98 void setBaseValue(const SVGElement
* element
, const AtomicString
& propertyName
, ValueType newValue
)
100 HashMap
<StringImpl
*, ValueType
>* propertyMap
= baseValueMap
<ValueType
>()->get(element
);
102 propertyMap
= new HashMap
<StringImpl
*, ValueType
>();
103 baseValueMap
<ValueType
>()->set(element
, propertyMap
);
106 propertyMap
->set(propertyName
.impl(), newValue
);
109 template<typename ValueType
>
110 void removeBaseValue(const SVGElement
* element
, const AtomicString
& propertyName
)
112 HashMap
<StringImpl
*, ValueType
>* propertyMap
= baseValueMap
<ValueType
>()->get(element
);
116 propertyMap
->remove(propertyName
.impl());
119 template<typename ValueType
>
120 bool hasBaseValue(const SVGElement
* element
, const AtomicString
& propertyName
) const
122 HashMap
<StringImpl
*, ValueType
>* propertyMap
= baseValueMap
<ValueType
>()->get(element
);
124 return propertyMap
->contains(propertyName
.impl());
132 #endif // ENABLE(SVG)