• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef SVGDocumentExtensions_h
22 #define SVGDocumentExtensions_h
23 
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"
30 
31 namespace WebCore {
32 
33 class Document;
34 class RenderSVGResourceContainer;
35 class SubtreeLayoutScope;
36 class SVGElement;
37 #if ENABLE(SVG_FONTS)
38 class SVGFontFaceElement;
39 #endif
40 class SVGResourcesCache;
41 class SVGSVGElement;
42 class Element;
43 
44 typedef WillBeHeapHashSet<RawPtrWillBeMember<SVGElement> > SVGElementSet;
45 
46 class SVGDocumentExtensions : public NoBaseWillBeGarbageCollectedFinalized<SVGDocumentExtensions> {
47     WTF_MAKE_NONCOPYABLE(SVGDocumentExtensions); WTF_MAKE_FAST_ALLOCATED_WILL_BE_REMOVED;
48 public:
49     typedef HashSet<Element*> SVGPendingElements;
50     explicit SVGDocumentExtensions(Document*);
51     ~SVGDocumentExtensions();
52 
53     void addTimeContainer(SVGSVGElement*);
54     void removeTimeContainer(SVGSVGElement*);
55 
56     void addResource(const AtomicString& id, RenderSVGResourceContainer*);
57     void removeResource(const AtomicString& id);
58     RenderSVGResourceContainer* resourceById(const AtomicString& id) const;
59 
60     static void serviceOnAnimationFrame(Document&, double monotonicAnimationStartTime);
61 
62     void startAnimations();
63     void pauseAnimations();
64     void dispatchSVGLoadEventToOutermostSVGElements();
65 
66     void reportWarning(const String&);
67     void reportError(const String&);
68 
resourcesCache()69     SVGResourcesCache* resourcesCache() const { return m_resourcesCache.get(); }
70 
71     SVGElementSet* setOfElementsReferencingTarget(SVGElement* referencedElement) const;
72     void addElementReferencingTarget(SVGElement* referencingElement, SVGElement* referencedElement);
73     void removeAllTargetReferencesForElement(SVGElement*);
74     void rebuildAllElementReferencesForTarget(SVGElement*);
75     void removeAllElementReferencesForTarget(SVGElement*);
76 
77     void addSVGRootWithRelativeLengthDescendents(SVGSVGElement*);
78     void removeSVGRootWithRelativeLengthDescendents(SVGSVGElement*);
79     bool isSVGRootWithRelativeLengthDescendents(SVGSVGElement*) const;
80     void invalidateSVGRootsWithRelativeLengthDescendents(SubtreeLayoutScope*);
81 
82 #if ENABLE(SVG_FONTS)
svgFontFaceElements()83     const WillBeHeapHashSet<RawPtrWillBeMember<SVGFontFaceElement> >& svgFontFaceElements() const { return m_svgFontFaceElements; }
84     void registerSVGFontFaceElement(SVGFontFaceElement*);
85     void unregisterSVGFontFaceElement(SVGFontFaceElement*);
86 
87     void registerPendingSVGFontFaceElementsForRemoval(PassRefPtrWillBeRawPtr<SVGFontFaceElement>);
88     void removePendingSVGFontFaceElementsForRemoval();
89 #endif
90 
91     bool zoomAndPanEnabled() const;
92 
93     void startPan(const FloatPoint& start);
94     void updatePan(const FloatPoint& pos) const;
95 
96     static SVGSVGElement* rootElement(const Document&);
97     SVGSVGElement* rootElement() const;
98 
99     void trace(Visitor*);
100 
101 private:
102     RawPtrWillBeMember<Document> m_document;
103     WillBeHeapHashSet<RawPtrWillBeMember<SVGSVGElement> > m_timeContainers; // For SVG 1.2 support this will need to be made more general.
104 #if ENABLE(SVG_FONTS)
105     WillBeHeapHashSet<RawPtrWillBeMember<SVGFontFaceElement> > m_svgFontFaceElements;
106     // SVGFontFaceElements that are pending and scheduled for removal.
107     WillBeHeapHashSet<RefPtrWillBeMember<SVGFontFaceElement> > m_pendingSVGFontFaceElementsForRemoval;
108 #endif
109     HashMap<AtomicString, RenderSVGResourceContainer*> m_resources;
110     HashMap<AtomicString, OwnPtr<SVGPendingElements> > m_pendingResources; // Resources that are pending.
111     HashMap<AtomicString, OwnPtr<SVGPendingElements> > m_pendingResourcesForRemoval; // Resources that are pending and scheduled for removal.
112     typedef WillBeHeapHashMap<RawPtrWillBeMember<SVGElement>, OwnPtrWillBeMember<SVGElementSet> > ElementDependenciesMap;
113     ElementDependenciesMap m_elementDependencies;
114     OwnPtr<SVGResourcesCache> m_resourcesCache;
115     WillBeHeapHashSet<RawPtrWillBeMember<SVGSVGElement> > m_relativeLengthSVGRoots; // Root SVG elements with relative length descendants.
116     FloatPoint m_translate;
117 #if ASSERT_ENABLED
118     bool m_inRelativeLengthSVGRootsInvalidation;
119 #endif
120 
121 public:
122     // This HashMap contains a list of pending resources. Pending resources, are such
123     // which are referenced by any object in the SVG document, but do NOT exist yet.
124     // For instance, dynamically build gradients / patterns / clippers...
125     void addPendingResource(const AtomicString& id, Element*);
126     bool hasPendingResource(const AtomicString& id) const;
127     bool isElementPendingResources(Element*) const;
128     bool isElementPendingResource(Element*, const AtomicString& id) const;
129     void clearHasPendingResourcesIfPossible(Element*);
130     void removeElementFromPendingResources(Element*);
131     PassOwnPtr<SVGPendingElements> removePendingResource(const AtomicString& id);
132 
133     void serviceAnimations(double monotonicAnimationStartTime);
134 
135     // The following two functions are used for scheduling a pending resource to be removed.
136     void markPendingResourcesForRemoval(const AtomicString&);
137     Element* removeElementFromPendingResourcesForRemoval(const AtomicString&);
138 
139 private:
140     PassOwnPtr<SVGPendingElements> removePendingResourceForRemoval(const AtomicString&);
141 };
142 
143 }
144 
145 #endif
146