2 * Copyright (C) Research In Motion Limited 2010. All rights reserved.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public License
15 * along with this library; see the file COPYING.LIB. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
20 #ifndef SVGResources_h
21 #define SVGResources_h
24 #include <wtf/HashSet.h>
25 #include <wtf/Noncopyable.h>
26 #include <wtf/OwnPtr.h>
27 #include <wtf/PassOwnPtr.h>
33 class RenderSVGResourceClipper;
34 class RenderSVGResourceContainer;
35 class RenderSVGResourceFilter;
36 class RenderSVGResourceMarker;
37 class RenderSVGResourceMasker;
40 // Holds a set of resources associated with a RenderObject
42 WTF_MAKE_NONCOPYABLE(SVGResources); WTF_MAKE_FAST_ALLOCATED;
46 bool buildCachedResources(const RenderObject*, const SVGRenderStyle*);
49 RenderSVGResourceClipper* clipper() const { return m_clipperFilterMaskerData ? m_clipperFilterMaskerData->clipper : 0; }
51 RenderSVGResourceFilter* filter() const { return m_clipperFilterMaskerData ? m_clipperFilterMaskerData->filter : 0; }
53 RenderSVGResourceMarker* markerStart() const { return m_markerData ? m_markerData->markerStart : 0; }
54 RenderSVGResourceMarker* markerMid() const { return m_markerData ? m_markerData->markerMid : 0; }
55 RenderSVGResourceMarker* markerEnd() const { return m_markerData ? m_markerData->markerEnd : 0; }
56 RenderSVGResourceMasker* masker() const { return m_clipperFilterMaskerData ? m_clipperFilterMaskerData->masker : 0; }
59 RenderSVGResourceContainer* fill() const { return m_fillStrokeData ? m_fillStrokeData->fill : 0; }
60 RenderSVGResourceContainer* stroke() const { return m_fillStrokeData ? m_fillStrokeData->stroke : 0; }
62 // Chainable resources - linked through xlink:href
63 RenderSVGResourceContainer* linkedResource() const { return m_linkedResource; }
65 void buildSetOfResources(HashSet<RenderSVGResourceContainer*>&);
67 // Methods operating on all cached resources
68 void removeClientFromCache(RenderObject*, bool markForInvalidation = true) const;
69 void resourceDestroyed(RenderSVGResourceContainer*);
72 void dump(const RenderObject*);
76 friend class SVGResourcesCycleSolver;
78 // Only used by SVGResourcesCache cycle detection logic
83 void resetMarkerStart();
84 void resetMarkerMid();
85 void resetMarkerEnd();
89 void resetLinkedResource();
92 bool setClipper(RenderSVGResourceClipper*);
94 bool setFilter(RenderSVGResourceFilter*);
96 bool setMarkerStart(RenderSVGResourceMarker*);
97 bool setMarkerMid(RenderSVGResourceMarker*);
98 bool setMarkerEnd(RenderSVGResourceMarker*);
99 bool setMasker(RenderSVGResourceMasker*);
100 bool setFill(RenderSVGResourceContainer*);
101 bool setStroke(RenderSVGResourceContainer*);
102 bool setLinkedResource(RenderSVGResourceContainer*);
104 // From SVG 1.1 2nd Edition
105 // clipper: 'container elements' and 'graphics elements'
106 // filter: 'container elements' and 'graphics elements'
107 // masker: 'container elements' and 'graphics elements'
108 // -> a, circle, defs, ellipse, glyph, g, image, line, marker, mask, missing-glyph, path, pattern, polygon, polyline, rect, svg, switch, symbol, text, use
109 struct ClipperFilterMaskerData {
110 ClipperFilterMaskerData()
119 static PassOwnPtr<ClipperFilterMaskerData> create()
121 return adoptPtr(new ClipperFilterMaskerData);
124 RenderSVGResourceClipper* clipper;
126 RenderSVGResourceFilter* filter;
128 RenderSVGResourceMasker* masker;
131 // From SVG 1.1 2nd Edition
132 // marker: line, path, polygon, polyline
141 static PassOwnPtr<MarkerData> create()
143 return adoptPtr(new MarkerData);
146 RenderSVGResourceMarker* markerStart;
147 RenderSVGResourceMarker* markerMid;
148 RenderSVGResourceMarker* markerEnd;
151 // From SVG 1.1 2nd Edition
152 // fill: 'shapes' and 'text content elements'
153 // stroke: 'shapes' and 'text content elements'
154 // -> altGlyph, circle, ellipse, line, path, polygon, polyline, rect, text, textPath, tref, tspan
155 struct FillStrokeData {
162 static PassOwnPtr<FillStrokeData> create()
164 return adoptPtr(new FillStrokeData);
167 RenderSVGResourceContainer* fill;
168 RenderSVGResourceContainer* stroke;
171 OwnPtr<ClipperFilterMaskerData> m_clipperFilterMaskerData;
172 OwnPtr<MarkerData> m_markerData;
173 OwnPtr<FillStrokeData> m_fillStrokeData;
174 RenderSVGResourceContainer* m_linkedResource;