Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(92)

Side by Side Diff: Source/core/layout/svg/LayoutSVGResourcePaintServer.cpp

Issue 908243002: Move rendering/svg/RenderSVGResource* to layout/svg. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2006 Nikolas Zimmermann <zimmermann@kde.org> 2 * Copyright (C) 2006 Nikolas Zimmermann <zimmermann@kde.org>
3 * Copyright (C) 2007 Rob Buis <buis@kde.org> 3 * Copyright (C) 2007 Rob Buis <buis@kde.org>
4 * Copyright (C) 2008 Dirk Schulze <krit@webkit.org> 4 * Copyright (C) 2008 Dirk Schulze <krit@webkit.org>
5 * Copyright (C) Research In Motion Limited 2010. All rights reserved. 5 * Copyright (C) Research In Motion Limited 2010. All rights reserved.
6 * 6 *
7 * This library is free software; you can redistribute it and/or 7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public 8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either 9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version. 10 * version 2 of the License, or (at your option) any later version.
11 * 11 *
12 * This library is distributed in the hope that it will be useful, 12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details. 15 * Library General Public License for more details.
16 * 16 *
17 * You should have received a copy of the GNU Library General Public License 17 * You should have received a copy of the GNU Library General Public License
18 * along with this library; see the file COPYING.LIB. If not, write to 18 * along with this library; see the file COPYING.LIB. If not, write to
19 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 19 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 * Boston, MA 02110-1301, USA. 20 * Boston, MA 02110-1301, USA.
21 */ 21 */
22 22
23 #include "config.h" 23 #include "config.h"
24 #include "core/rendering/svg/RenderSVGResourcePaintServer.h" 24 #include "core/layout/svg/LayoutSVGResourcePaintServer.h"
25 25
26 #include "core/layout/style/LayoutStyle.h" 26 #include "core/layout/style/LayoutStyle.h"
27 #include "core/layout/svg/SVGResources.h" 27 #include "core/layout/svg/SVGResources.h"
28 #include "core/layout/svg/SVGResourcesCache.h" 28 #include "core/layout/svg/SVGResourcesCache.h"
29 #include "platform/graphics/GraphicsContext.h" 29 #include "platform/graphics/GraphicsContext.h"
30 #include "platform/graphics/GraphicsContextStateSaver.h" 30 #include "platform/graphics/GraphicsContextStateSaver.h"
31 31
32 namespace blink { 32 namespace blink {
33 33
34 SVGPaintServer::SVGPaintServer(Color color) 34 SVGPaintServer::SVGPaintServer(Color color)
35 : m_color(color) 35 : m_color(color)
36 { 36 {
37 } 37 }
38 38
39 SVGPaintServer::SVGPaintServer(PassRefPtr<Gradient> gradient) 39 SVGPaintServer::SVGPaintServer(PassRefPtr<Gradient> gradient)
40 : m_gradient(gradient) 40 : m_gradient(gradient)
41 , m_color(Color::black) 41 , m_color(Color::black)
42 { 42 {
43 } 43 }
44 44
45 SVGPaintServer::SVGPaintServer(PassRefPtr<Pattern> pattern) 45 SVGPaintServer::SVGPaintServer(PassRefPtr<Pattern> pattern)
46 : m_pattern(pattern) 46 : m_pattern(pattern)
47 , m_color(Color::black) 47 , m_color(Color::black)
48 { 48 {
49 } 49 }
50 50
51 void SVGPaintServer::apply(GraphicsContext& context, RenderSVGResourceMode resou rceMode, float paintAlpha, GraphicsContextStateSaver& stateSaver) 51 void SVGPaintServer::apply(GraphicsContext& context, LayoutSVGResourceMode resou rceMode, float paintAlpha, GraphicsContextStateSaver& stateSaver)
52 { 52 {
53 ASSERT(resourceMode == ApplyToFillMode || resourceMode == ApplyToStrokeMode) ; 53 ASSERT(resourceMode == ApplyToFillMode || resourceMode == ApplyToStrokeMode) ;
54 54
55 if (m_gradient || m_pattern) 55 if (m_gradient || m_pattern)
56 stateSaver.saveIfNeeded(); 56 stateSaver.saveIfNeeded();
57 57
58 if (resourceMode == ApplyToFillMode) { 58 if (resourceMode == ApplyToFillMode) {
59 if (m_pattern) 59 if (m_pattern)
60 context.setFillPattern(m_pattern, paintAlpha); 60 context.setFillPattern(m_pattern, paintAlpha);
61 else if (m_gradient) 61 else if (m_gradient)
(...skipping 12 matching lines...) Expand all
74 74
75 void SVGPaintServer::prependTransform(const AffineTransform& transform) 75 void SVGPaintServer::prependTransform(const AffineTransform& transform)
76 { 76 {
77 ASSERT(m_gradient || m_pattern); 77 ASSERT(m_gradient || m_pattern);
78 if (m_pattern) 78 if (m_pattern)
79 m_pattern->setPatternSpaceTransform(transform * m_pattern->patternSpaceT ransform()); 79 m_pattern->setPatternSpaceTransform(transform * m_pattern->patternSpaceT ransform());
80 else 80 else
81 m_gradient->setGradientSpaceTransform(transform * m_gradient->gradientSp aceTransform()); 81 m_gradient->setGradientSpaceTransform(transform * m_gradient->gradientSp aceTransform());
82 } 82 }
83 83
84 static SVGPaintDescription requestPaint(const LayoutObject& object, const Layout Style& style, RenderSVGResourceMode mode) 84 static SVGPaintDescription requestPaint(const LayoutObject& object, const Layout Style& style, LayoutSVGResourceMode mode)
85 { 85 {
86 // If we have no style at all, ignore it. 86 // If we have no style at all, ignore it.
87 const SVGLayoutStyle& svgStyle = style.svgStyle(); 87 const SVGLayoutStyle& svgStyle = style.svgStyle();
88 88
89 // If we have no fill/stroke, return 0. 89 // If we have no fill/stroke, return 0.
90 if (mode == ApplyToFillMode) { 90 if (mode == ApplyToFillMode) {
91 if (!svgStyle.hasFill()) 91 if (!svgStyle.hasFill())
92 return SVGPaintDescription(); 92 return SVGPaintDescription();
93 } else { 93 } else {
94 if (!svgStyle.hasStroke()) 94 if (!svgStyle.hasStroke())
(...skipping 29 matching lines...) Expand all
124 } 124 }
125 } 125 }
126 126
127 // If the primary resource is just a color, return immediately. 127 // If the primary resource is just a color, return immediately.
128 if (paintType < SVG_PAINTTYPE_URI_NONE) { 128 if (paintType < SVG_PAINTTYPE_URI_NONE) {
129 // |paintType| will be either <current-color> or <rgb-color> here - both of which will have a color. 129 // |paintType| will be either <current-color> or <rgb-color> here - both of which will have a color.
130 ASSERT(hasColor); 130 ASSERT(hasColor);
131 return SVGPaintDescription(color); 131 return SVGPaintDescription(color);
132 } 132 }
133 133
134 RenderSVGResourcePaintServer* uriResource = 0; 134 LayoutSVGResourcePaintServer* uriResource = 0;
135 if (SVGResources* resources = SVGResourcesCache::cachedResourcesForLayoutObj ect(&object)) 135 if (SVGResources* resources = SVGResourcesCache::cachedResourcesForLayoutObj ect(&object))
136 uriResource = applyToFill ? resources->fill() : resources->stroke(); 136 uriResource = applyToFill ? resources->fill() : resources->stroke();
137 137
138 // If the requested resource is not available, return the color resource or 'none'. 138 // If the requested resource is not available, return the color resource or 'none'.
139 if (!uriResource) { 139 if (!uriResource) {
140 // The fallback is 'none'. (SVG2 say 'none' is implied when no fallback is specified.) 140 // The fallback is 'none'. (SVG2 say 'none' is implied when no fallback is specified.)
141 if (paintType == SVG_PAINTTYPE_URI_NONE || !hasColor) 141 if (paintType == SVG_PAINTTYPE_URI_NONE || !hasColor)
142 return SVGPaintDescription(); 142 return SVGPaintDescription();
143 143
144 return SVGPaintDescription(color); 144 return SVGPaintDescription(color);
145 } 145 }
146 146
147 // The paint server resource exists, though it may be invalid (pattern with width/height=0). 147 // The paint server resource exists, though it may be invalid (pattern with width/height=0).
148 // Return the fallback color to our caller so it can use it, if 148 // Return the fallback color to our caller so it can use it, if
149 // preparePaintServer() on the resource container failed. 149 // preparePaintServer() on the resource container failed.
150 if (hasColor) 150 if (hasColor)
151 return SVGPaintDescription(uriResource, color); 151 return SVGPaintDescription(uriResource, color);
152 152
153 return SVGPaintDescription(uriResource); 153 return SVGPaintDescription(uriResource);
154 } 154 }
155 155
156 SVGPaintServer SVGPaintServer::requestForRenderer(const LayoutObject& renderer, const LayoutStyle& style, RenderSVGResourceMode resourceMode) 156 SVGPaintServer SVGPaintServer::requestForRenderer(const LayoutObject& renderer, const LayoutStyle& style, LayoutSVGResourceMode resourceMode)
157 { 157 {
158 ASSERT(resourceMode == ApplyToFillMode || resourceMode == ApplyToStrokeMode) ; 158 ASSERT(resourceMode == ApplyToFillMode || resourceMode == ApplyToStrokeMode) ;
159 159
160 SVGPaintDescription paintDescription = requestPaint(renderer, style, resourc eMode); 160 SVGPaintDescription paintDescription = requestPaint(renderer, style, resourc eMode);
161 if (!paintDescription.isValid) 161 if (!paintDescription.isValid)
162 return invalid(); 162 return invalid();
163 if (!paintDescription.resource) 163 if (!paintDescription.resource)
164 return SVGPaintServer(paintDescription.color); 164 return SVGPaintServer(paintDescription.color);
165 SVGPaintServer paintServer = paintDescription.resource->preparePaintServer(r enderer); 165 SVGPaintServer paintServer = paintDescription.resource->preparePaintServer(r enderer);
166 if (paintServer.isValid()) 166 if (paintServer.isValid())
167 return paintServer; 167 return paintServer;
168 if (paintDescription.hasFallback) 168 if (paintDescription.hasFallback)
169 return SVGPaintServer(paintDescription.color); 169 return SVGPaintServer(paintDescription.color);
170 return invalid(); 170 return invalid();
171 } 171 }
172 172
173 bool SVGPaintServer::existsForRenderer(const LayoutObject& renderer, const Layou tStyle& style, RenderSVGResourceMode resourceMode) 173 bool SVGPaintServer::existsForRenderer(const LayoutObject& renderer, const Layou tStyle& style, LayoutSVGResourceMode resourceMode)
174 { 174 {
175 return requestPaint(renderer, style, resourceMode).isValid; 175 return requestPaint(renderer, style, resourceMode).isValid;
176 } 176 }
177 177
178 RenderSVGResourcePaintServer::RenderSVGResourcePaintServer(SVGElement* element) 178 LayoutSVGResourcePaintServer::LayoutSVGResourcePaintServer(SVGElement* element)
179 : RenderSVGResourceContainer(element) 179 : LayoutSVGResourceContainer(element)
180 { 180 {
181 } 181 }
182 182
183 RenderSVGResourcePaintServer::~RenderSVGResourcePaintServer() 183 LayoutSVGResourcePaintServer::~LayoutSVGResourcePaintServer()
184 { 184 {
185 } 185 }
186 186
187 SVGPaintDescription RenderSVGResourcePaintServer::requestPaintDescription(const LayoutObject& renderer, const LayoutStyle& style, RenderSVGResourceMode resource Mode) 187 SVGPaintDescription LayoutSVGResourcePaintServer::requestPaintDescription(const LayoutObject& renderer, const LayoutStyle& style, LayoutSVGResourceMode resource Mode)
188 { 188 {
189 return requestPaint(renderer, style, resourceMode); 189 return requestPaint(renderer, style, resourceMode);
190 } 190 }
191 191
192 } 192 }
OLDNEW
« no previous file with comments | « Source/core/layout/svg/LayoutSVGResourcePaintServer.h ('k') | Source/core/layout/svg/LayoutSVGResourcePattern.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698