Upstream version 5.34.92.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / rendering / svg / SVGResources.h
1 /*
2  * Copyright (C) Research In Motion Limited 2010. All rights reserved.
3  *
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.
8  *
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.
13  *
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.
18  */
19
20 #ifndef SVGResources_h
21 #define SVGResources_h
22
23 #include "wtf/FastAllocBase.h"
24 #include "wtf/HashSet.h"
25 #include "wtf/Noncopyable.h"
26 #include "wtf/OwnPtr.h"
27 #include "wtf/PassOwnPtr.h"
28
29 namespace WebCore {
30
31 class Document;
32 class RenderObject;
33 class RenderSVGResourceClipper;
34 class RenderSVGResourceContainer;
35 class RenderSVGResourceFilter;
36 class RenderSVGResourceMarker;
37 class RenderSVGResourceMasker;
38 class SVGRenderStyle;
39
40 // Holds a set of resources associated with a RenderObject
41 class SVGResources {
42     WTF_MAKE_NONCOPYABLE(SVGResources); WTF_MAKE_FAST_ALLOCATED;
43 public:
44     SVGResources();
45
46     static PassOwnPtr<SVGResources> buildResources(const RenderObject*, const SVGRenderStyle*);
47     void layoutIfNeeded();
48
49     // Ordinary resources
50     RenderSVGResourceClipper* clipper() const { return m_clipperFilterMaskerData ? m_clipperFilterMaskerData->clipper : 0; }
51     RenderSVGResourceMarker* markerStart() const { return m_markerData ? m_markerData->markerStart : 0; }
52     RenderSVGResourceMarker* markerMid() const { return m_markerData ? m_markerData->markerMid : 0; }
53     RenderSVGResourceMarker* markerEnd() const { return m_markerData ? m_markerData->markerEnd : 0; }
54     RenderSVGResourceMasker* masker() const { return m_clipperFilterMaskerData ? m_clipperFilterMaskerData->masker : 0; }
55
56     RenderSVGResourceFilter* filter() const
57     {
58         if (m_clipperFilterMaskerData)
59             return m_clipperFilterMaskerData->filter;
60         return 0;
61     }
62
63     // Paint servers
64     RenderSVGResourceContainer* fill() const { return m_fillStrokeData ? m_fillStrokeData->fill : 0; }
65     RenderSVGResourceContainer* stroke() const { return m_fillStrokeData ? m_fillStrokeData->stroke : 0; }
66
67     // Chainable resources - linked through xlink:href
68     RenderSVGResourceContainer* linkedResource() const { return m_linkedResource; }
69
70     void buildSetOfResources(HashSet<RenderSVGResourceContainer*>&);
71
72     // Methods operating on all cached resources
73     void removeClientFromCache(RenderObject*, bool markForInvalidation = true) const;
74     void resourceDestroyed(RenderSVGResourceContainer*);
75
76 #ifndef NDEBUG
77     void dump(const RenderObject*);
78 #endif
79
80 private:
81     friend class SVGResourcesCycleSolver;
82
83     bool hasResourceData() const;
84
85     // Only used by SVGResourcesCache cycle detection logic
86     void resetClipper();
87     void resetFilter();
88     void resetMarkerStart();
89     void resetMarkerMid();
90     void resetMarkerEnd();
91     void resetMasker();
92     void resetFill();
93     void resetStroke();
94     void resetLinkedResource();
95
96     bool setClipper(RenderSVGResourceClipper*);
97     bool setFilter(RenderSVGResourceFilter*);
98     bool setMarkerStart(RenderSVGResourceMarker*);
99     bool setMarkerMid(RenderSVGResourceMarker*);
100     bool setMarkerEnd(RenderSVGResourceMarker*);
101     bool setMasker(RenderSVGResourceMasker*);
102     bool setFill(RenderSVGResourceContainer*);
103     bool setStroke(RenderSVGResourceContainer*);
104     bool setLinkedResource(RenderSVGResourceContainer*);
105
106     // From SVG 1.1 2nd Edition
107     // clipper: 'container elements' and 'graphics elements'
108     // filter:  'container elements' and 'graphics elements'
109     // masker:  'container elements' and 'graphics elements'
110     // -> a, circle, defs, ellipse, glyph, g, image, line, marker, mask, missing-glyph, path, pattern, polygon, polyline, rect, svg, switch, symbol, text, use
111     struct ClipperFilterMaskerData {
112         WTF_MAKE_FAST_ALLOCATED;
113     public:
114         ClipperFilterMaskerData()
115             : clipper(0)
116             , filter(0)
117             , masker(0)
118         {
119         }
120
121         static PassOwnPtr<ClipperFilterMaskerData> create()
122         {
123             return adoptPtr(new ClipperFilterMaskerData);
124         }
125
126         RenderSVGResourceClipper* clipper;
127         RenderSVGResourceFilter* filter;
128         RenderSVGResourceMasker* masker;
129     };
130
131     // From SVG 1.1 2nd Edition
132     // marker: line, path, polygon, polyline
133     struct MarkerData {
134         WTF_MAKE_FAST_ALLOCATED;
135     public:
136         MarkerData()
137             : markerStart(0)
138             , markerMid(0)
139             , markerEnd(0)
140         {
141         }
142
143         static PassOwnPtr<MarkerData> create()
144         {
145             return adoptPtr(new MarkerData);
146         }
147
148         RenderSVGResourceMarker* markerStart;
149         RenderSVGResourceMarker* markerMid;
150         RenderSVGResourceMarker* markerEnd;
151     };
152
153     // From SVG 1.1 2nd Edition
154     // fill:       'shapes' and 'text content elements'
155     // stroke:     'shapes' and 'text content elements'
156     // -> altGlyph, circle, ellipse, line, path, polygon, polyline, rect, text, textPath, tspan
157     struct FillStrokeData {
158         WTF_MAKE_FAST_ALLOCATED;
159     public:
160         FillStrokeData()
161             : fill(0)
162             , stroke(0)
163         {
164         }
165
166         static PassOwnPtr<FillStrokeData> create()
167         {
168             return adoptPtr(new FillStrokeData);
169         }
170
171         RenderSVGResourceContainer* fill;
172         RenderSVGResourceContainer* stroke;
173     };
174
175     OwnPtr<ClipperFilterMaskerData> m_clipperFilterMaskerData;
176     OwnPtr<MarkerData> m_markerData;
177     OwnPtr<FillStrokeData> m_fillStrokeData;
178     RenderSVGResourceContainer* m_linkedResource;
179 };
180
181 }
182
183 #endif