| 1 | /* |
| 2 | * Copyright (C) 2006 Apple Inc. All rights reserved. |
| 3 | * Copyright (C) 2006, 2008 Nikolas Zimmermann <zimmermann@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 | #pragma once |
| 22 | |
| 23 | #include <wtf/Forward.h> |
| 24 | #include <wtf/HashMap.h> |
| 25 | #include <wtf/HashSet.h> |
| 26 | #include <wtf/text/AtomicStringHash.h> |
| 27 | |
| 28 | namespace WebCore { |
| 29 | |
| 30 | class Document; |
| 31 | class Element; |
| 32 | class RenderSVGResourceContainer; |
| 33 | class SVGElement; |
| 34 | class SVGFontFaceElement; |
| 35 | class SVGResourcesCache; |
| 36 | class SVGSMILElement; |
| 37 | class SVGSVGElement; |
| 38 | |
| 39 | class SVGDocumentExtensions { |
| 40 | WTF_MAKE_NONCOPYABLE(SVGDocumentExtensions); WTF_MAKE_FAST_ALLOCATED; |
| 41 | public: |
| 42 | typedef HashSet<Element*> PendingElements; |
| 43 | explicit SVGDocumentExtensions(Document&); |
| 44 | ~SVGDocumentExtensions(); |
| 45 | |
| 46 | void addTimeContainer(SVGSVGElement&); |
| 47 | void removeTimeContainer(SVGSVGElement&); |
| 48 | |
| 49 | void addResource(const AtomicString& id, RenderSVGResourceContainer&); |
| 50 | void removeResource(const AtomicString& id); |
| 51 | RenderSVGResourceContainer* resourceById(const AtomicString& id) const; |
| 52 | |
| 53 | void startAnimations(); |
| 54 | void pauseAnimations(); |
| 55 | void unpauseAnimations(); |
| 56 | void dispatchSVGLoadEventToOutermostSVGElements(); |
| 57 | bool areAnimationsPaused() const { return m_areAnimationsPaused; } |
| 58 | |
| 59 | void reportWarning(const String&); |
| 60 | void reportError(const String&); |
| 61 | |
| 62 | SVGResourcesCache& resourcesCache() { return *m_resourcesCache; } |
| 63 | |
| 64 | HashSet<SVGElement*>* setOfElementsReferencingTarget(SVGElement& referencedElement) const; |
| 65 | void addElementReferencingTarget(SVGElement& referencingElement, SVGElement& referencedElement); |
| 66 | void removeAllTargetReferencesForElement(SVGElement&); |
| 67 | void rebuildAllElementReferencesForTarget(SVGElement&); |
| 68 | void removeAllElementReferencesForTarget(SVGElement&); |
| 69 | |
| 70 | void clearTargetDependencies(SVGElement&); |
| 71 | void rebuildElements(); |
| 72 | |
| 73 | #if ENABLE(SVG_FONTS) |
| 74 | const HashSet<SVGFontFaceElement*>& svgFontFaceElements() const { return m_svgFontFaceElements; } |
| 75 | void registerSVGFontFaceElement(SVGFontFaceElement&); |
| 76 | void unregisterSVGFontFaceElement(SVGFontFaceElement&); |
| 77 | #endif |
| 78 | |
| 79 | private: |
| 80 | Document& m_document; |
| 81 | HashSet<SVGSVGElement*> m_timeContainers; // For SVG 1.2 support this will need to be made more general. |
| 82 | #if ENABLE(SVG_FONTS) |
| 83 | HashSet<SVGFontFaceElement*> m_svgFontFaceElements; |
| 84 | #endif |
| 85 | HashMap<AtomicString, RenderSVGResourceContainer*> m_resources; |
| 86 | HashMap<AtomicString, std::unique_ptr<PendingElements>> m_pendingResources; // Resources that are pending. |
| 87 | HashMap<AtomicString, std::unique_ptr<PendingElements>> m_pendingResourcesForRemoval; // Resources that are pending and scheduled for removal. |
| 88 | HashMap<SVGElement*, std::unique_ptr<HashSet<SVGElement*>>> m_elementDependencies; |
| 89 | std::unique_ptr<SVGResourcesCache> m_resourcesCache; |
| 90 | |
| 91 | Vector<SVGElement*> m_rebuildElements; |
| 92 | bool m_areAnimationsPaused; |
| 93 | |
| 94 | public: |
| 95 | // This HashMap contains a list of pending resources. Pending resources, are such |
| 96 | // which are referenced by any object in the SVG document, but do NOT exist yet. |
| 97 | // For instance, dynamically build gradients / patterns / clippers... |
| 98 | void addPendingResource(const AtomicString& id, Element&); |
| 99 | bool isIdOfPendingResource(const AtomicString& id) const; |
| 100 | bool isPendingResource(Element&, const AtomicString& id) const; |
| 101 | void clearHasPendingResourcesIfPossible(Element&); |
| 102 | void removeElementFromPendingResources(Element&); |
| 103 | std::unique_ptr<PendingElements> removePendingResource(const AtomicString& id); |
| 104 | |
| 105 | // The following two functions are used for scheduling a pending resource to be removed. |
| 106 | void markPendingResourcesForRemoval(const AtomicString&); |
| 107 | RefPtr<Element> removeElementFromPendingResourcesForRemovalMap(const AtomicString&); |
| 108 | |
| 109 | private: |
| 110 | bool isElementWithPendingResources(Element&) const; |
| 111 | std::unique_ptr<PendingElements> removePendingResourceForRemoval(const AtomicString&); |
| 112 | }; |
| 113 | |
| 114 | } // namespace WebCore |
| 115 | |