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

KHTML

  • sources
  • kde-4.12
  • kdelibs
  • khtml
  • svg
SVGDocumentExtensions.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2006 Apple Computer, Inc.
3  2006 Nikolas Zimmermann <zimmermann@kde.org>
4 
5  This file is part of the WebKit 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 SVGDocumentExtensions_h
24 #define SVGDocumentExtensions_h
25 
26 #if ENABLE(SVG)
27 
28 #include <memory>
29 #include <wtf/Forward.h>
30 #include <wtf/HashSet.h>
31 #include <wtf/HashMap.h>
32 
33 #include "FloatRect.h"
34 #include "StringHash.h"
35 //#include "StringImpl.h"
36 #include "AtomicString.h"
37 #include "xml/Document.h"
38 
39 namespace DOM {
40  class EventListener;
41 }
42 
43 namespace WebCore {
44 
45 //class AtomicString;
46 //class Document;
47 //class EventListener;
48 //class Node;
49 //class String;
50 class SVGElement;
51 class SVGElementInstance;
52 class SVGStyledElement;
53 class SVGSVGElement;
54 class TimeScheduler;
55 
56 class DOMStringHash
57 {
58  public:
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;
62 };
63 
64 class SVGDocumentExtensions {
65 public:
66  SVGDocumentExtensions(Document*);
67  ~SVGDocumentExtensions();
68 
69  DOM::EventListener* createSVGEventListener(const DOMString& functionName, const DOMString& code, DOM::NodeImpl*);
70 
71  void addTimeContainer(SVGSVGElement*);
72  void removeTimeContainer(SVGSVGElement*);
73 
74  void startAnimations();
75  void pauseAnimations();
76  void unpauseAnimations();
77 
78  void reportWarning(const String&);
79  void reportError(const String&);
80 
81 private:
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;
86 
87  SVGDocumentExtensions(const SVGDocumentExtensions&);
88  SVGDocumentExtensions& operator=(const SVGDocumentExtensions&);
89 
90  template<typename ValueType>
91  HashMap<const SVGElement*, HashMap<StringImpl*, ValueType>*>* baseValueMap() const
92  {
93  static HashMap<const SVGElement*, HashMap<StringImpl*, ValueType>*>* s_baseValueMap = new HashMap<const SVGElement*, HashMap<StringImpl*, ValueType>*>();
94  return s_baseValueMap;
95  }
96 
97 public:
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);
104 
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;
110 
111  // Used by the ANIMATED_PROPERTY_* macros
112  template<typename ValueType>
113  ValueType baseValue(const SVGElement* element, const AtomicString& propertyName) const
114  {
115  HashMap<StringImpl*, ValueType>* propertyMap = baseValueMap<ValueType>()->get(element);
116  if (propertyMap)
117  return propertyMap->get(propertyName.impl());
118 
119  return 0;
120  }
121 
122  template<typename ValueType>
123  void setBaseValue(const SVGElement* element, const AtomicString& propertyName, ValueType newValue)
124  {
125  HashMap<StringImpl*, ValueType>* propertyMap = baseValueMap<ValueType>()->get(element);
126  if (!propertyMap) {
127  propertyMap = new HashMap<StringImpl*, ValueType>();
128  baseValueMap<ValueType>()->set(element, propertyMap);
129  }
130 
131  propertyMap->set(propertyName.impl(), newValue);
132  }
133 
134  template<typename ValueType>
135  void removeBaseValue(const SVGElement* element, const AtomicString& propertyName)
136  {
137  HashMap<StringImpl*, ValueType>* propertyMap = baseValueMap<ValueType>()->get(element);
138  if (!propertyMap)
139  return;
140 
141  propertyMap->remove(propertyName.impl());
142  }
143 
144  template<typename ValueType>
145  bool hasBaseValue(const SVGElement* element, const AtomicString& propertyName) const
146  {
147  HashMap<StringImpl*, ValueType>* propertyMap = baseValueMap<ValueType>()->get(element);
148  if (propertyMap)
149  return propertyMap->contains(propertyName.impl());
150 
151  return false;
152  }
153 };
154 
155 // Special handling for WebCore::String
156 template<>
157 inline String SVGDocumentExtensions::baseValue<String>(const SVGElement* element, const AtomicString& propertyName) const
158 {
159  HashMap<StringImpl*, String>* propertyMap = baseValueMap<String>()->get(element);
160  if (propertyMap)
161  return propertyMap->get(propertyName.impl());
162 
163  return String();
164 }
165 
166 // Special handling for WebCore::FloatRect
167 template<>
168 inline FloatRect SVGDocumentExtensions::baseValue<FloatRect>(const SVGElement* element, const AtomicString& propertyName) const
169 {
170  HashMap<StringImpl*, FloatRect>* propertyMap = baseValueMap<FloatRect>()->get(element);
171  if (propertyMap)
172  return propertyMap->get(propertyName.impl());
173 
174  return FloatRect();
175 }
176 
177 // Special handling for booleans
178 template<>
179 inline bool SVGDocumentExtensions::baseValue<bool>(const SVGElement* element, const AtomicString& propertyName) const
180 {
181  HashMap<StringImpl*, bool>* propertyMap = baseValueMap<bool>()->get(element);
182  if (propertyMap)
183  return propertyMap->get(propertyName.impl());
184 
185  return false;
186 }
187 
188 // Special handling for doubles
189 template<>
190 inline double SVGDocumentExtensions::baseValue<double>(const SVGElement* element, const AtomicString& propertyName) const
191 {
192  HashMap<StringImpl*, double>* propertyMap = baseValueMap<double>()->get(element);
193  if (propertyMap)
194  return propertyMap->get(propertyName.impl());
195 
196  return 0.0;
197 }
198 
199 }
200 
201 #endif // ENABLE(SVG)
202 
203 #endif
qHash
uint qHash(const KPluginInfo &p)
DOM::EventListener
Introduced in DOM Level 2.
Definition: dom2_events.h:70
FloatRect.h
WebCore::String
DOM::DOMString String
Definition: PlatformString.h:8
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:51:22 by doxygen 1.8.7 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 API Reference

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

Search



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