1 /* 2 * Copyright (C) 2006 Apple Inc. All rights reserved. 3 * Copyright (C) 2006, 2008 Nikolas Zimmermann <zimmermann (at) kde.org> 4 * 5 * This library is free software; you can redistribute it and/or 6 * modify it under the terms of the GNU Library General Public 7 * License as published by the Free Software Foundation; either 8 * version 2 of the License, or (at your option) any later version. 9 * 10 * This library is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 * Library General Public License for more details. 14 * 15 * You should have received a copy of the GNU Library General Public License 16 * along with this library; see the file COPYING.LIB. If not, write to 17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 18 * Boston, MA 02110-1301, USA. 19 */ 20 21 #ifndef SVGDocumentExtensions_h 22 #define SVGDocumentExtensions_h 23 24 #include "wtf/Forward.h" 25 #include "wtf/HashMap.h" 26 #include "wtf/HashSet.h" 27 #include "wtf/text/AtomicStringHash.h" 28 29 namespace WebCore { 30 31 class Document; 32 class RenderSVGResourceContainer; 33 class SubtreeLayoutScope; 34 class SVGElement; 35 #if ENABLE(SVG_FONTS) 36 class SVGFontFaceElement; 37 #endif 38 class SVGResourcesCache; 39 class SVGSMILElement; 40 class SVGSVGElement; 41 class Element; 42 43 class SVGDocumentExtensions { 44 WTF_MAKE_NONCOPYABLE(SVGDocumentExtensions); WTF_MAKE_FAST_ALLOCATED; 45 public: 46 typedef HashSet<Element*> SVGPendingElements; 47 SVGDocumentExtensions(Document*); 48 ~SVGDocumentExtensions(); 49 50 void addTimeContainer(SVGSVGElement*); 51 void removeTimeContainer(SVGSVGElement*); 52 53 void addResource(const AtomicString& id, RenderSVGResourceContainer*); 54 void removeResource(const AtomicString& id); 55 RenderSVGResourceContainer* resourceById(const AtomicString& id) const; 56 57 void startAnimations(); 58 void pauseAnimations(); 59 void unpauseAnimations(); 60 void dispatchSVGLoadEventToOutermostSVGElements(); 61 62 void reportWarning(const String&); 63 void reportError(const String&); 64 65 SVGResourcesCache* resourcesCache() const { return m_resourcesCache.get(); } 66 67 HashSet<SVGElement*>* setOfElementsReferencingTarget(SVGElement* referencedElement) const; 68 void addElementReferencingTarget(SVGElement* referencingElement, SVGElement* referencedElement); 69 void removeAllTargetReferencesForElement(SVGElement*); 70 void rebuildAllElementReferencesForTarget(SVGElement*); 71 void removeAllElementReferencesForTarget(SVGElement*); 72 73 void addSVGRootWithRelativeLengthDescendents(SVGSVGElement*); 74 void removeSVGRootWithRelativeLengthDescendents(SVGSVGElement*); 75 bool isSVGRootWithRelativeLengthDescendents(SVGSVGElement*) const; 76 void invalidateSVGRootsWithRelativeLengthDescendents(SubtreeLayoutScope*); 77 78 #if ENABLE(SVG_FONTS) 79 const HashSet<SVGFontFaceElement*>& svgFontFaceElements() const { return m_svgFontFaceElements; } 80 void registerSVGFontFaceElement(SVGFontFaceElement*); 81 void unregisterSVGFontFaceElement(SVGFontFaceElement*); 82 #endif 83 84 private: 85 Document* m_document; // weak reference 86 HashSet<SVGSVGElement*> m_timeContainers; // For SVG 1.2 support this will need to be made more general. 87 #if ENABLE(SVG_FONTS) 88 HashSet<SVGFontFaceElement*> m_svgFontFaceElements; 89 #endif 90 HashMap<AtomicString, RenderSVGResourceContainer*> m_resources; 91 HashMap<AtomicString, OwnPtr<SVGPendingElements> > m_pendingResources; // Resources that are pending. 92 HashMap<AtomicString, OwnPtr<SVGPendingElements> > m_pendingResourcesForRemoval; // Resources that are pending and scheduled for removal. 93 HashMap<SVGElement*, OwnPtr<HashSet<SVGElement*> > > m_elementDependencies; 94 OwnPtr<SVGResourcesCache> m_resourcesCache; 95 HashSet<SVGSVGElement*> m_relativeLengthSVGRoots; // Root SVG elements with relative length descendants. 96 #if !ASSERT_DISABLED 97 bool m_inRelativeLengthSVGRootsInvalidation; 98 #endif 99 100 public: 101 // This HashMap contains a list of pending resources. Pending resources, are such 102 // which are referenced by any object in the SVG document, but do NOT exist yet. 103 // For instance, dynamically build gradients / patterns / clippers... 104 void addPendingResource(const AtomicString& id, Element*); 105 bool hasPendingResource(const AtomicString& id) const; 106 bool isElementPendingResources(Element*) const; 107 bool isElementPendingResource(Element*, const AtomicString& id) const; 108 void clearHasPendingResourcesIfPossible(Element*); 109 void removeElementFromPendingResources(Element*); 110 PassOwnPtr<SVGPendingElements> removePendingResource(const AtomicString& id); 111 112 // The following two functions are used for scheduling a pending resource to be removed. 113 void markPendingResourcesForRemoval(const AtomicString&); 114 Element* removeElementFromPendingResourcesForRemoval(const AtomicString&); 115 116 private: 117 PassOwnPtr<SVGPendingElements> removePendingResourceForRemoval(const AtomicString&); 118 }; 119 120 } 121 122 #endif 123