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

KHTML

SVGDocumentExtensions.h

Go to the documentation of this file.
00001 /*
00002     Copyright (C) 2006 Apple Computer, Inc.
00003                   2006 Nikolas Zimmermann <zimmermann@kde.org>
00004 
00005     This file is part of the WebKit project
00006 
00007     This library is free software; you can redistribute it and/or
00008     modify it under the terms of the GNU Library General Public
00009     License as published by the Free Software Foundation; either
00010     version 2 of the License, or (at your option) any later version.
00011 
00012     This library is distributed in the hope that it will be useful,
00013     but WITHOUT ANY WARRANTY; without even the implied warranty of
00014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015     Library General Public License for more details.
00016 
00017     You should have received a copy of the GNU Library General Public License
00018     along with this library; see the file COPYING.LIB.  If not, write to
00019     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00020     Boston, MA 02110-1301, USA.
00021 */
00022 
00023 #ifndef SVGDocumentExtensions_h
00024 #define SVGDocumentExtensions_h
00025 
00026 #if ENABLE(SVG)
00027 
00028 #include <memory>
00029 #include <wtf/Forward.h>
00030 #include <wtf/HashSet.h>
00031 #include <wtf/HashMap.h>
00032 
00033 #include "FloatRect.h"
00034 #include "StringHash.h"
00035 //#include "StringImpl.h"
00036 #include "AtomicString.h"
00037 #include "xml/Document.h"
00038 
00039 namespace DOM {
00040     class EventListener;
00041 }
00042 
00043 namespace WebCore {
00044 
00045 //class AtomicString;
00046 //class Document;
00047 //class EventListener;
00048 //class Node;
00049 //class String;
00050 class SVGElement;
00051 class SVGElementInstance;
00052 class SVGStyledElement;
00053 class SVGSVGElement;
00054 class TimeScheduler;
00055 
00056 class DOMStringHash
00057 {
00058     public:
00059         static unsigned hash(DOMString key) { return qHash(key.implementation()); }
00060         static bool equal(DOMString a, DOMString b) { return a == b; }
00061         static const bool safeToCompareToEmptyOrDeleted = false;
00062 };
00063 
00064 class SVGDocumentExtensions {
00065 public:
00066     SVGDocumentExtensions(Document*);
00067     ~SVGDocumentExtensions();
00068     
00069     EventListener* createSVGEventListener(const String& functionName, const String& code, Node*);
00070     
00071     void addTimeContainer(SVGSVGElement*);
00072     void removeTimeContainer(SVGSVGElement*);
00073     
00074     void startAnimations();
00075     void pauseAnimations();
00076     void unpauseAnimations();
00077 
00078     void reportWarning(const String&);
00079     void reportError(const String&);
00080 
00081 private:
00082     Document* m_doc; // weak reference
00083     HashSet<SVGSVGElement*> m_timeContainers; // For SVG 1.2 support this will need to be made more general.
00084     //HashMap<String, HashSet<SVGStyledElement*>*, DOMStringHash> m_pendingResources;
00085     HashMap<SVGElement*, HashSet<SVGElementInstance*>*> m_elementInstances;
00086 
00087     SVGDocumentExtensions(const SVGDocumentExtensions&);
00088     SVGDocumentExtensions& operator=(const SVGDocumentExtensions&);
00089 
00090     template<typename ValueType>
00091     HashMap<const SVGElement*, HashMap<StringImpl*, ValueType>*>* baseValueMap() const
00092     {
00093         static HashMap<const SVGElement*, HashMap<StringImpl*, ValueType>*>* s_baseValueMap = new HashMap<const SVGElement*, HashMap<StringImpl*, ValueType>*>();
00094         return s_baseValueMap;
00095     }
00096 
00097 public:
00098     // This HashMap contains a list of pending resources. Pending resources, are such
00099     // which are referenced by any object in the SVG document, but do NOT exist yet.
00100     // For instance, dynamically build gradients / patterns / clippers...
00101     void addPendingResource(const AtomicString& id, SVGStyledElement*);
00102     bool isPendingResource(const AtomicString& id) const;
00103     std::auto_ptr<HashSet<SVGStyledElement*> > removePendingResource(const AtomicString& id);
00104 
00105     // This HashMap maps elements to their instances, when they are used by <use> elements.
00106     // This is needed to synchronize the original element with the internally cloned one.
00107     void mapInstanceToElement(SVGElementInstance*, SVGElement*);
00108     void removeInstanceMapping(SVGElementInstance*, SVGElement*);
00109     HashSet<SVGElementInstance*>* instancesForElement(SVGElement*) const;
00110 
00111     // Used by the ANIMATED_PROPERTY_* macros
00112     template<typename ValueType>
00113     ValueType baseValue(const SVGElement* element, const AtomicString& propertyName) const
00114     {
00115         HashMap<StringImpl*, ValueType>* propertyMap = baseValueMap<ValueType>()->get(element);
00116         if (propertyMap)
00117             return propertyMap->get(propertyName.impl());
00118 
00119         return 0;
00120     }
00121 
00122     template<typename ValueType>
00123     void setBaseValue(const SVGElement* element, const AtomicString& propertyName, ValueType newValue)
00124     {
00125         HashMap<StringImpl*, ValueType>* propertyMap = baseValueMap<ValueType>()->get(element);
00126         if (!propertyMap) {
00127             propertyMap = new HashMap<StringImpl*, ValueType>();
00128             baseValueMap<ValueType>()->set(element, propertyMap);
00129         }
00130 
00131         propertyMap->set(propertyName.impl(), newValue);
00132     }
00133 
00134     template<typename ValueType>
00135     void removeBaseValue(const SVGElement* element, const AtomicString& propertyName)
00136     {
00137         HashMap<StringImpl*, ValueType>* propertyMap = baseValueMap<ValueType>()->get(element);
00138         if (!propertyMap)
00139             return;
00140 
00141         propertyMap->remove(propertyName.impl());
00142     }
00143 
00144     template<typename ValueType>
00145     bool hasBaseValue(const SVGElement* element, const AtomicString& propertyName) const
00146     {
00147         HashMap<StringImpl*, ValueType>* propertyMap = baseValueMap<ValueType>()->get(element);
00148         if (propertyMap)
00149             return propertyMap->contains(propertyName.impl());
00150 
00151         return false;
00152     }
00153 };
00154 
00155 // Special handling for WebCore::String
00156 template<>
00157 inline String SVGDocumentExtensions::baseValue<String>(const SVGElement* element, const AtomicString& propertyName) const
00158 {
00159     HashMap<StringImpl*, String>* propertyMap = baseValueMap<String>()->get(element);
00160     if (propertyMap)
00161         return propertyMap->get(propertyName.impl());
00162 
00163     return String();
00164 }
00165 
00166 // Special handling for WebCore::FloatRect
00167 template<>
00168 inline FloatRect SVGDocumentExtensions::baseValue<FloatRect>(const SVGElement* element, const AtomicString& propertyName) const
00169 {
00170     HashMap<StringImpl*, FloatRect>* propertyMap = baseValueMap<FloatRect>()->get(element);
00171     if (propertyMap)
00172         return propertyMap->get(propertyName.impl());
00173 
00174     return FloatRect();
00175 }
00176 
00177 // Special handling for booleans
00178 template<>
00179 inline bool SVGDocumentExtensions::baseValue<bool>(const SVGElement* element, const AtomicString& propertyName) const
00180 {
00181     HashMap<StringImpl*, bool>* propertyMap = baseValueMap<bool>()->get(element);
00182     if (propertyMap)
00183         return propertyMap->get(propertyName.impl());
00184 
00185     return false;
00186 }
00187 
00188 // Special handling for doubles
00189 template<>
00190 inline double SVGDocumentExtensions::baseValue<double>(const SVGElement* element, const AtomicString& propertyName) const
00191 {
00192     HashMap<StringImpl*, double>* propertyMap = baseValueMap<double>()->get(element);
00193     if (propertyMap)
00194         return propertyMap->get(propertyName.impl());
00195 
00196     return 0.0;
00197 }
00198 
00199 }
00200 
00201 #endif // ENABLE(SVG)
00202 
00203 #endif

KHTML

Skip menu "KHTML"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • Kross
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.7
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal