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 | #pragma once |
21 | |
22 | #include "RenderSVGResourceMarker.h" |
23 | #include <memory> |
24 | #include <wtf/HashSet.h> |
25 | #include <wtf/Noncopyable.h> |
26 | |
27 | namespace WebCore { |
28 | |
29 | class Document; |
30 | class RenderElement; |
31 | class RenderObject; |
32 | class RenderStyle; |
33 | class RenderSVGResourceClipper; |
34 | class RenderSVGResourceContainer; |
35 | class RenderSVGResourceFilter; |
36 | class RenderSVGResourceMarker; |
37 | class RenderSVGResourceMasker; |
38 | class RenderSVGRoot; |
39 | class SVGRenderStyle; |
40 | |
41 | // Holds a set of resources associated with a RenderObject |
42 | class SVGResources { |
43 | WTF_MAKE_NONCOPYABLE(SVGResources); WTF_MAKE_FAST_ALLOCATED; |
44 | public: |
45 | SVGResources(); |
46 | |
47 | bool buildCachedResources(const RenderElement&, const RenderStyle&); |
48 | void layoutDifferentRootIfNeeded(const RenderSVGRoot*); |
49 | |
50 | // Ordinary resources |
51 | RenderSVGResourceClipper* clipper() const { return m_clipperFilterMaskerData ? m_clipperFilterMaskerData->clipper : nullptr; } |
52 | RenderSVGResourceMarker* markerStart() const { return m_markerData ? m_markerData->markerStart : nullptr; } |
53 | RenderSVGResourceMarker* markerMid() const { return m_markerData ? m_markerData->markerMid : nullptr; } |
54 | RenderSVGResourceMarker* markerEnd() const { return m_markerData ? m_markerData->markerEnd : nullptr; } |
55 | bool markerReverseStart() const; |
56 | RenderSVGResourceMasker* masker() const { return m_clipperFilterMaskerData ? m_clipperFilterMaskerData->masker : nullptr; } |
57 | RenderSVGResourceFilter* filter() const { return m_clipperFilterMaskerData ? m_clipperFilterMaskerData->filter : nullptr; } |
58 | |
59 | // Paint servers |
60 | RenderSVGResourceContainer* fill() const { return m_fillStrokeData ? m_fillStrokeData->fill : nullptr; } |
61 | RenderSVGResourceContainer* stroke() const { return m_fillStrokeData ? m_fillStrokeData->stroke : nullptr; } |
62 | |
63 | // Chainable resources - linked through xlink:href |
64 | RenderSVGResourceContainer* linkedResource() const { return m_linkedResource; } |
65 | |
66 | void buildSetOfResources(HashSet<RenderSVGResourceContainer*>&); |
67 | |
68 | // Methods operating on all cached resources |
69 | void removeClientFromCache(RenderElement&, bool markForInvalidation = true) const; |
70 | // Returns true if the resource-to-be-destroyed is one of our resources. |
71 | bool resourceDestroyed(RenderSVGResourceContainer&); |
72 | |
73 | #if ENABLE(TREE_DEBUGGING) |
74 | void dump(const RenderObject*); |
75 | #endif |
76 | |
77 | private: |
78 | friend class SVGResourcesCycleSolver; |
79 | |
80 | // Only used by SVGResourcesCache cycle detection logic |
81 | void resetClipper(); |
82 | void resetFilter(); |
83 | void resetMarkerStart(); |
84 | void resetMarkerMid(); |
85 | void resetMarkerEnd(); |
86 | void resetMasker(); |
87 | void resetFill(); |
88 | void resetStroke(); |
89 | void resetLinkedResource(); |
90 | |
91 | private: |
92 | bool setClipper(RenderSVGResourceClipper*); |
93 | bool setFilter(RenderSVGResourceFilter*); |
94 | bool setMarkerStart(RenderSVGResourceMarker*); |
95 | bool setMarkerMid(RenderSVGResourceMarker*); |
96 | bool setMarkerEnd(RenderSVGResourceMarker*); |
97 | bool setMasker(RenderSVGResourceMasker*); |
98 | bool setFill(RenderSVGResourceContainer*); |
99 | bool setStroke(RenderSVGResourceContainer*); |
100 | bool setLinkedResource(RenderSVGResourceContainer*); |
101 | |
102 | bool isEmpty() const { return !m_clipperFilterMaskerData && !m_markerData && !m_fillStrokeData && !m_linkedResource; } |
103 | |
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 | WTF_MAKE_FAST_ALLOCATED; |
111 | public: |
112 | ClipperFilterMaskerData() = default; |
113 | RenderSVGResourceClipper* clipper { nullptr }; |
114 | RenderSVGResourceFilter* filter { nullptr }; |
115 | RenderSVGResourceMasker* masker { nullptr }; |
116 | }; |
117 | |
118 | // From SVG 1.1 2nd Edition |
119 | // marker: line, path, polygon, polyline |
120 | struct MarkerData { |
121 | WTF_MAKE_FAST_ALLOCATED; |
122 | public: |
123 | MarkerData() = default; |
124 | RenderSVGResourceMarker* markerStart { nullptr }; |
125 | RenderSVGResourceMarker* markerMid { nullptr }; |
126 | RenderSVGResourceMarker* markerEnd { nullptr }; |
127 | }; |
128 | |
129 | // From SVG 1.1 2nd Edition |
130 | // fill: 'shapes' and 'text content elements' |
131 | // stroke: 'shapes' and 'text content elements' |
132 | // -> altGlyph, circle, ellipse, line, path, polygon, polyline, rect, text, textPath, tref, tspan |
133 | struct FillStrokeData { |
134 | WTF_MAKE_FAST_ALLOCATED; |
135 | public: |
136 | FillStrokeData() = default; |
137 | RenderSVGResourceContainer* fill { nullptr }; |
138 | RenderSVGResourceContainer* stroke { nullptr }; |
139 | }; |
140 | |
141 | std::unique_ptr<ClipperFilterMaskerData> m_clipperFilterMaskerData; |
142 | std::unique_ptr<MarkerData> m_markerData; |
143 | std::unique_ptr<FillStrokeData> m_fillStrokeData; |
144 | RenderSVGResourceContainer* m_linkedResource { nullptr }; |
145 | }; |
146 | |
147 | } // namespace WebCore |
148 | |