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

Side by Side Diff: Source/core/rendering/svg/RenderSVGResource.cpp

Issue 673753004: Move RenderSVGResource into the inheritance hierarchy (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Non-move changes. Created 6 years, 2 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
(Empty)
1 /*
2 * Copyright (C) 2006 Nikolas Zimmermann <zimmermann@kde.org>
3 * Copyright (C) 2007 Rob Buis <buis@kde.org>
4 * Copyright (C) 2008 Dirk Schulze <krit@webkit.org>
5 * Copyright (C) Research In Motion Limited 2010. All rights reserved.
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
16 *
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
19 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
21 */
22
23 #include "config.h"
24 #include "core/rendering/svg/RenderSVGResource.h"
25
26 #include "core/rendering/style/RenderStyle.h"
27 #include "core/rendering/svg/RenderSVGResourceContainer.h"
28 #include "core/rendering/svg/SVGResources.h"
29 #include "core/rendering/svg/SVGResourcesCache.h"
30 #include "platform/graphics/GraphicsContext.h"
31 #include "platform/graphics/GraphicsContextStateSaver.h"
32
33 namespace blink {
34
35 SVGPaintServer::SVGPaintServer(Color color)
36 : m_color(color)
37 {
38 }
39
40 SVGPaintServer::SVGPaintServer(PassRefPtr<Gradient> gradient)
41 : m_gradient(gradient)
42 , m_color(Color::black)
43 {
44 }
45
46 SVGPaintServer::SVGPaintServer(PassRefPtr<Pattern> pattern)
47 : m_pattern(pattern)
48 , m_color(Color::black)
49 {
50 }
51
52 void SVGPaintServer::apply(GraphicsContext& context, RenderSVGResourceMode resou rceMode, GraphicsContextStateSaver* stateSaver)
53 {
54 ASSERT(resourceMode == ApplyToFillMode || resourceMode == ApplyToStrokeMode) ;
55 if (stateSaver && (m_gradient || m_pattern))
56 stateSaver->saveIfNeeded();
57
58 if (resourceMode == ApplyToFillMode) {
59 if (m_pattern)
60 context.setFillPattern(m_pattern);
61 else if (m_gradient)
62 context.setFillGradient(m_gradient);
63 else
64 context.setFillColor(m_color);
65 } else {
66 if (m_pattern)
67 context.setStrokePattern(m_pattern);
68 else if (m_gradient)
69 context.setStrokeGradient(m_gradient);
70 else
71 context.setStrokeColor(m_color);
72 }
73 }
74
75 void SVGPaintServer::prependTransform(const AffineTransform& transform)
76 {
77 ASSERT(m_gradient || m_pattern);
78 if (m_pattern)
79 m_pattern->setPatternSpaceTransform(transform * m_pattern->patternSpaceT ransform());
80 else
81 m_gradient->setGradientSpaceTransform(transform * m_gradient->gradientSp aceTransform());
82 }
83
84 static SVGPaintDescription requestPaint(const RenderObject& object, const Render Style* style, RenderSVGResourceMode mode)
85 {
86 ASSERT(style);
87
88 // If we have no style at all, ignore it.
89 const SVGRenderStyle& svgStyle = style->svgStyle();
90
91 // If we have no fill/stroke, return 0.
92 if (mode == ApplyToFillMode) {
93 if (!svgStyle.hasFill())
94 return SVGPaintDescription();
95 } else {
96 if (!svgStyle.hasStroke())
97 return SVGPaintDescription();
98 }
99
100 bool applyToFill = mode == ApplyToFillMode;
101 SVGPaintType paintType = applyToFill ? svgStyle.fillPaintType() : svgStyle.s trokePaintType();
102 ASSERT(paintType != SVG_PAINTTYPE_NONE);
103
104 Color color;
105 bool hasColor = false;
106 switch (paintType) {
107 case SVG_PAINTTYPE_CURRENTCOLOR:
108 case SVG_PAINTTYPE_RGBCOLOR:
109 case SVG_PAINTTYPE_URI_CURRENTCOLOR:
110 case SVG_PAINTTYPE_URI_RGBCOLOR:
111 color = applyToFill ? svgStyle.fillPaintColor() : svgStyle.strokePaintCo lor();
112 hasColor = true;
113 default:
114 break;
115 }
116
117 if (style->insideLink() == InsideVisitedLink) {
118 // FIXME: This code doesn't support the uri component of the visited lin k paint, https://bugs.webkit.org/show_bug.cgi?id=70006
119 SVGPaintType visitedPaintType = applyToFill ? svgStyle.visitedLinkFillPa intType() : svgStyle.visitedLinkStrokePaintType();
120
121 // For SVG_PAINTTYPE_CURRENTCOLOR, 'color' already contains the 'visited Color'.
122 if (visitedPaintType < SVG_PAINTTYPE_URI_NONE && visitedPaintType != SVG _PAINTTYPE_CURRENTCOLOR) {
123 const Color& visitedColor = applyToFill ? svgStyle.visitedLinkFillPa intColor() : svgStyle.visitedLinkStrokePaintColor();
124 color = Color(visitedColor.red(), visitedColor.green(), visitedColor .blue(), color.alpha());
125 hasColor = true;
126 }
127 }
128
129 // If the primary resource is just a color, return immediately.
130 if (paintType < SVG_PAINTTYPE_URI_NONE) {
131 // |paintType| will be either <current-color> or <rgb-color> here - both of which will have a color.
132 ASSERT(hasColor);
133 return SVGPaintDescription(color);
134 }
135
136 RenderSVGResource* uriResource = 0;
137 if (SVGResources* resources = SVGResourcesCache::cachedResourcesForRenderObj ect(&object))
138 uriResource = applyToFill ? resources->fill() : resources->stroke();
139
140 // If the requested resource is not available, return the color resource or 'none'.
141 if (!uriResource) {
142 // The fallback is 'none'. (SVG2 say 'none' is implied when no fallback is specified.)
143 if (paintType == SVG_PAINTTYPE_URI_NONE || !hasColor)
144 return SVGPaintDescription();
145
146 return SVGPaintDescription(color);
147 }
148
149 // The paint server resource exists, though it may be invalid (pattern with width/height=0).
150 // Return the fallback color to our caller so it can use it, if
151 // preparePaintServer() on the resource container failed.
152 if (hasColor)
153 return SVGPaintDescription(uriResource, color);
154
155 return SVGPaintDescription(uriResource);
156 }
157
158 SVGPaintServer SVGPaintServer::requestForRenderer(const RenderObject& renderer, const RenderStyle* style, RenderSVGResourceMode resourceMode)
159 {
160 ASSERT(style);
161 ASSERT(resourceMode == ApplyToFillMode || resourceMode == ApplyToStrokeMode) ;
162
163 SVGPaintDescription paintDescription = requestPaint(renderer, style, resourc eMode);
164 if (!paintDescription.isValid)
165 return invalid();
166 if (!paintDescription.resource)
167 return SVGPaintServer(paintDescription.color);
168 SVGPaintServer paintServer = paintDescription.resource->preparePaintServer(r enderer);
169 if (paintServer.isValid())
170 return paintServer;
171 if (paintDescription.hasFallback)
172 return SVGPaintServer(paintDescription.color);
173 return invalid();
174 }
175
176 bool SVGPaintServer::existsForRenderer(const RenderObject& renderer, const Rende rStyle* style, RenderSVGResourceMode resourceMode)
177 {
178 return requestPaint(renderer, style, resourceMode).isValid;
179 }
180
181 SVGPaintServer RenderSVGResource::preparePaintServer(const RenderObject&)
182 {
183 ASSERT_NOT_REACHED();
184 return SVGPaintServer::invalid();
185 }
186
187 SVGPaintDescription RenderSVGResource::requestPaintDescription(const RenderObjec t& renderer, const RenderStyle* style, RenderSVGResourceMode resourceMode)
188 {
189 return requestPaint(renderer, style, resourceMode);
190 }
191
192 }
OLDNEW
« no previous file with comments | « Source/core/rendering/svg/RenderSVGResource.h ('k') | Source/core/rendering/svg/RenderSVGResourceContainer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698