2 * Copyright (C) 2006 Apple Inc. All rights reserved.
3 * Copyright (C) 2006, 2008 Nikolas Zimmermann <zimmermann@kde.org>
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.
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.
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.
21 #ifndef SVGDocumentExtensions_h
22 #define SVGDocumentExtensions_h
24 #include "platform/geometry/FloatPoint.h"
25 #include "platform/heap/Handle.h"
26 #include "wtf/Forward.h"
27 #include "wtf/HashMap.h"
28 #include "wtf/HashSet.h"
29 #include "wtf/text/AtomicStringHash.h"
34 class RenderSVGResourceContainer;
35 class SubtreeLayoutScope;
38 class SVGFontFaceElement;
40 class SVGResourcesCache;
44 class SVGDocumentExtensions : public NoBaseWillBeGarbageCollectedFinalized<SVGDocumentExtensions> {
45 WTF_MAKE_NONCOPYABLE(SVGDocumentExtensions); WTF_MAKE_FAST_ALLOCATED_WILL_BE_REMOVED;
47 typedef WillBeHeapHashSet<RawPtrWillBeMember<Element> > SVGPendingElements;
48 explicit SVGDocumentExtensions(Document*);
49 ~SVGDocumentExtensions();
51 void addTimeContainer(SVGSVGElement*);
52 void removeTimeContainer(SVGSVGElement*);
54 void addResource(const AtomicString& id, RenderSVGResourceContainer*);
55 void removeResource(const AtomicString& id);
56 RenderSVGResourceContainer* resourceById(const AtomicString& id) const;
58 static void serviceOnAnimationFrame(Document&, double monotonicAnimationStartTime);
60 void startAnimations();
61 void pauseAnimations();
62 void dispatchSVGLoadEventToOutermostSVGElements();
64 void reportWarning(const String&);
65 void reportError(const String&);
67 SVGResourcesCache* resourcesCache() const { return m_resourcesCache.get(); }
69 void addSVGRootWithRelativeLengthDescendents(SVGSVGElement*);
70 void removeSVGRootWithRelativeLengthDescendents(SVGSVGElement*);
71 bool isSVGRootWithRelativeLengthDescendents(SVGSVGElement*) const;
72 void invalidateSVGRootsWithRelativeLengthDescendents(SubtreeLayoutScope*);
75 const WillBeHeapHashSet<RawPtrWillBeMember<SVGFontFaceElement> >& svgFontFaceElements() const { return m_svgFontFaceElements; }
76 void registerSVGFontFaceElement(SVGFontFaceElement*);
77 void unregisterSVGFontFaceElement(SVGFontFaceElement*);
79 void registerPendingSVGFontFaceElementsForRemoval(PassRefPtrWillBeRawPtr<SVGFontFaceElement>);
80 void removePendingSVGFontFaceElementsForRemoval();
83 bool zoomAndPanEnabled() const;
85 void startPan(const FloatPoint& start);
86 void updatePan(const FloatPoint& pos) const;
88 static SVGSVGElement* rootElement(const Document&);
89 SVGSVGElement* rootElement() const;
94 RawPtrWillBeMember<Document> m_document;
95 WillBeHeapHashSet<RawPtrWillBeMember<SVGSVGElement> > m_timeContainers; // For SVG 1.2 support this will need to be made more general.
97 WillBeHeapHashSet<RawPtrWillBeMember<SVGFontFaceElement> > m_svgFontFaceElements;
98 // SVGFontFaceElements that are pending and scheduled for removal.
99 WillBeHeapHashSet<RefPtrWillBeMember<SVGFontFaceElement> > m_pendingSVGFontFaceElementsForRemoval;
101 HashMap<AtomicString, RenderSVGResourceContainer*> m_resources;
102 WillBeHeapHashMap<AtomicString, OwnPtrWillBeMember<SVGPendingElements> > m_pendingResources; // Resources that are pending.
103 WillBeHeapHashMap<AtomicString, OwnPtrWillBeMember<SVGPendingElements> > m_pendingResourcesForRemoval; // Resources that are pending and scheduled for removal.
104 OwnPtr<SVGResourcesCache> m_resourcesCache;
105 WillBeHeapHashSet<RawPtrWillBeMember<SVGSVGElement> > m_relativeLengthSVGRoots; // Root SVG elements with relative length descendants.
106 FloatPoint m_translate;
108 bool m_inRelativeLengthSVGRootsInvalidation;
112 // This HashMap contains a list of pending resources. Pending resources, are such
113 // which are referenced by any object in the SVG document, but do NOT exist yet.
114 // For instance, dynamically build gradients / patterns / clippers...
115 void addPendingResource(const AtomicString& id, Element*);
116 bool hasPendingResource(const AtomicString& id) const;
117 bool isElementPendingResources(Element*) const;
118 bool isElementPendingResource(Element*, const AtomicString& id) const;
119 void clearHasPendingResourcesIfPossible(Element*);
120 void removeElementFromPendingResources(Element*);
121 PassOwnPtrWillBeRawPtr<SVGPendingElements> removePendingResource(const AtomicString& id);
123 void serviceAnimations(double monotonicAnimationStartTime);
125 // The following two functions are used for scheduling a pending resource to be removed.
126 void markPendingResourcesForRemoval(const AtomicString&);
127 Element* removeElementFromPendingResourcesForRemoval(const AtomicString&);
130 PassOwnPtrWillBeRawPtr<SVGPendingElements> removePendingResourceForRemoval(const AtomicString&);