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