| OLD | NEW |
| 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/RenderSVGResource.h" | 24 #include "core/rendering/svg/RenderSVGResource.h" |
| 25 | 25 |
| 26 #include "core/rendering/svg/RenderSVGResourceClipper.h" | 26 #include "core/rendering/svg/RenderSVGResourceClipper.h" |
| 27 #include "core/rendering/svg/RenderSVGResourceFilter.h" | 27 #include "core/rendering/svg/RenderSVGResourceFilter.h" |
| 28 #include "core/rendering/svg/RenderSVGResourceMasker.h" | 28 #include "core/rendering/svg/RenderSVGResourceMasker.h" |
| 29 #include "core/rendering/svg/RenderSVGResourceSolidColor.h" | |
| 30 #include "core/rendering/svg/SVGRenderSupport.h" | |
| 31 #include "core/rendering/svg/SVGResources.h" | 29 #include "core/rendering/svg/SVGResources.h" |
| 32 #include "core/rendering/svg/SVGResourcesCache.h" | 30 #include "core/rendering/svg/SVGResourcesCache.h" |
| 33 #include "platform/graphics/GraphicsContext.h" | 31 #include "platform/graphics/GraphicsContext.h" |
| 34 #include "platform/graphics/GraphicsContextStateSaver.h" | 32 #include "platform/graphics/GraphicsContextStateSaver.h" |
| 35 | 33 |
| 36 namespace blink { | 34 namespace blink { |
| 37 | 35 |
| 38 SVGPaintServer::SVGPaintServer(Color color) | 36 SVGPaintServer::SVGPaintServer(Color color) |
| 39 : m_color(color) | 37 : m_color(color) |
| 40 { | 38 { |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 | 75 |
| 78 void SVGPaintServer::prependTransform(const AffineTransform& transform) | 76 void SVGPaintServer::prependTransform(const AffineTransform& transform) |
| 79 { | 77 { |
| 80 ASSERT(m_gradient || m_pattern); | 78 ASSERT(m_gradient || m_pattern); |
| 81 if (m_pattern) | 79 if (m_pattern) |
| 82 m_pattern->setPatternSpaceTransform(transform * m_pattern->patternSpaceT
ransform()); | 80 m_pattern->setPatternSpaceTransform(transform * m_pattern->patternSpaceT
ransform()); |
| 83 else | 81 else |
| 84 m_gradient->setGradientSpaceTransform(transform * m_gradient->gradientSp
aceTransform()); | 82 m_gradient->setGradientSpaceTransform(transform * m_gradient->gradientSp
aceTransform()); |
| 85 } | 83 } |
| 86 | 84 |
| 87 SVGPaintServer SVGPaintServer::requestForRenderer(const RenderObject& renderer,
const RenderStyle* style, RenderSVGResourceMode resourceMode) | 85 static SVGPaintDescription requestPaint(const RenderObject& object, const Render
Style* style, RenderSVGResourceMode mode) |
| 88 { | |
| 89 ASSERT(style); | |
| 90 ASSERT(resourceMode == ApplyToFillMode || resourceMode == ApplyToStrokeMode)
; | |
| 91 | |
| 92 bool hasFallback = false; | |
| 93 RenderSVGResource* paintingResource = RenderSVGResource::requestPaintingReso
urce(resourceMode, renderer, style, hasFallback); | |
| 94 if (!paintingResource) | |
| 95 return invalid(); | |
| 96 | |
| 97 SVGPaintServer paintServer = paintingResource->preparePaintServer(renderer); | |
| 98 if (paintServer.isValid()) | |
| 99 return paintServer; | |
| 100 if (hasFallback) | |
| 101 return SVGPaintServer(RenderSVGResource::sharedSolidPaintingResource()->
color()); | |
| 102 return invalid(); | |
| 103 } | |
| 104 | |
| 105 SVGPaintServer RenderSVGResource::preparePaintServer(const RenderObject&) | |
| 106 { | |
| 107 ASSERT_NOT_REACHED(); | |
| 108 return SVGPaintServer::invalid(); | |
| 109 } | |
| 110 | |
| 111 RenderSVGResource* RenderSVGResource::requestPaintingResource(RenderSVGResourceM
ode mode, const RenderObject& object, const RenderStyle* style, bool& hasFallbac
k) | |
| 112 { | 86 { |
| 113 ASSERT(style); | 87 ASSERT(style); |
| 114 | 88 |
| 115 hasFallback = false; | |
| 116 | |
| 117 // If we have no style at all, ignore it. | 89 // If we have no style at all, ignore it. |
| 118 const SVGRenderStyle& svgStyle = style->svgStyle(); | 90 const SVGRenderStyle& svgStyle = style->svgStyle(); |
| 119 | 91 |
| 120 // If we have no fill/stroke, return 0. | 92 // If we have no fill/stroke, return 0. |
| 121 if (mode == ApplyToFillMode) { | 93 if (mode == ApplyToFillMode) { |
| 122 if (!svgStyle.hasFill()) | 94 if (!svgStyle.hasFill()) |
| 123 return 0; | 95 return SVGPaintDescription(); |
| 124 } else { | 96 } else { |
| 125 if (!svgStyle.hasStroke()) | 97 if (!svgStyle.hasStroke()) |
| 126 return 0; | 98 return SVGPaintDescription(); |
| 127 } | 99 } |
| 128 | 100 |
| 129 bool applyToFill = mode == ApplyToFillMode; | 101 bool applyToFill = mode == ApplyToFillMode; |
| 130 SVGPaintType paintType = applyToFill ? svgStyle.fillPaintType() : svgStyle.s
trokePaintType(); | 102 SVGPaintType paintType = applyToFill ? svgStyle.fillPaintType() : svgStyle.s
trokePaintType(); |
| 131 ASSERT(paintType != SVG_PAINTTYPE_NONE); | 103 ASSERT(paintType != SVG_PAINTTYPE_NONE); |
| 132 | 104 |
| 133 Color color; | 105 Color color; |
| 134 bool hasColor = false; | 106 bool hasColor = false; |
| 135 switch (paintType) { | 107 switch (paintType) { |
| 136 case SVG_PAINTTYPE_CURRENTCOLOR: | 108 case SVG_PAINTTYPE_CURRENTCOLOR: |
| (...skipping 12 matching lines...) Expand all Loading... |
| 149 | 121 |
| 150 // For SVG_PAINTTYPE_CURRENTCOLOR, 'color' already contains the 'visited
Color'. | 122 // For SVG_PAINTTYPE_CURRENTCOLOR, 'color' already contains the 'visited
Color'. |
| 151 if (visitedPaintType < SVG_PAINTTYPE_URI_NONE && visitedPaintType != SVG
_PAINTTYPE_CURRENTCOLOR) { | 123 if (visitedPaintType < SVG_PAINTTYPE_URI_NONE && visitedPaintType != SVG
_PAINTTYPE_CURRENTCOLOR) { |
| 152 const Color& visitedColor = applyToFill ? svgStyle.visitedLinkFillPa
intColor() : svgStyle.visitedLinkStrokePaintColor(); | 124 const Color& visitedColor = applyToFill ? svgStyle.visitedLinkFillPa
intColor() : svgStyle.visitedLinkStrokePaintColor(); |
| 153 color = Color(visitedColor.red(), visitedColor.green(), visitedColor
.blue(), color.alpha()); | 125 color = Color(visitedColor.red(), visitedColor.green(), visitedColor
.blue(), color.alpha()); |
| 154 hasColor = true; | 126 hasColor = true; |
| 155 } | 127 } |
| 156 } | 128 } |
| 157 | 129 |
| 158 // If the primary resource is just a color, return immediately. | 130 // If the primary resource is just a color, return immediately. |
| 159 RenderSVGResourceSolidColor* colorResource = RenderSVGResource::sharedSolidP
aintingResource(); | |
| 160 if (paintType < SVG_PAINTTYPE_URI_NONE) { | 131 if (paintType < SVG_PAINTTYPE_URI_NONE) { |
| 161 // |paintType| will be either <current-color> or <rgb-color> here - both
of which will have a color. | 132 // |paintType| will be either <current-color> or <rgb-color> here - both
of which will have a color. |
| 162 ASSERT(hasColor); | 133 ASSERT(hasColor); |
| 163 colorResource->setColor(color); | 134 return SVGPaintDescription(color); |
| 164 return colorResource; | |
| 165 } | 135 } |
| 166 | 136 |
| 167 RenderSVGResource* uriResource = 0; | 137 RenderSVGResource* uriResource = 0; |
| 168 if (SVGResources* resources = SVGResourcesCache::cachedResourcesForRenderObj
ect(&object)) | 138 if (SVGResources* resources = SVGResourcesCache::cachedResourcesForRenderObj
ect(&object)) |
| 169 uriResource = applyToFill ? resources->fill() : resources->stroke(); | 139 uriResource = applyToFill ? resources->fill() : resources->stroke(); |
| 170 | 140 |
| 171 // If the requested resource is not available, return the color resource or
'none'. | 141 // If the requested resource is not available, return the color resource or
'none'. |
| 172 if (!uriResource) { | 142 if (!uriResource) { |
| 173 // The fallback is 'none'. (SVG2 say 'none' is implied when no fallback
is specified.) | 143 // The fallback is 'none'. (SVG2 say 'none' is implied when no fallback
is specified.) |
| 174 if (paintType == SVG_PAINTTYPE_URI_NONE || !hasColor) | 144 if (paintType == SVG_PAINTTYPE_URI_NONE || !hasColor) |
| 175 return 0; | 145 return SVGPaintDescription(); |
| 176 | 146 |
| 177 colorResource->setColor(color); | 147 return SVGPaintDescription(color); |
| 178 return colorResource; | |
| 179 } | 148 } |
| 180 | 149 |
| 181 // The paint server resource exists, though it may be invalid (pattern with
width/height=0). Pass the fallback color to our caller | 150 // The paint server resource exists, though it may be invalid (pattern with
width/height=0). |
| 182 // via sharedSolidPaintingResource so it can use the solid color painting re
source, if applyResource() on the URI resource failed. | 151 // Return the fallback color to our caller so it can use it, if |
| 183 if (hasColor) { | 152 // preparePaintServer() on the resource container failed. |
| 184 colorResource->setColor(color); | 153 if (hasColor) |
| 185 hasFallback = true; | 154 return SVGPaintDescription(uriResource, color); |
| 186 } | 155 |
| 187 return uriResource; | 156 return SVGPaintDescription(uriResource); |
| 188 } | 157 } |
| 189 | 158 |
| 190 RenderSVGResourceSolidColor* RenderSVGResource::sharedSolidPaintingResource() | 159 SVGPaintServer SVGPaintServer::requestForRenderer(const RenderObject& renderer,
const RenderStyle* style, RenderSVGResourceMode resourceMode) |
| 191 { | 160 { |
| 192 static RenderSVGResourceSolidColor* s_sharedSolidPaintingResource = 0; | 161 ASSERT(style); |
| 193 if (!s_sharedSolidPaintingResource) | 162 ASSERT(resourceMode == ApplyToFillMode || resourceMode == ApplyToStrokeMode)
; |
| 194 s_sharedSolidPaintingResource = new RenderSVGResourceSolidColor; | 163 |
| 195 return s_sharedSolidPaintingResource; | 164 SVGPaintDescription paintDescription = requestPaint(renderer, style, resourc
eMode); |
| 165 if (!paintDescription.isValid) |
| 166 return invalid(); |
| 167 if (!paintDescription.resource) |
| 168 return SVGPaintServer(paintDescription.color); |
| 169 SVGPaintServer paintServer = paintDescription.resource->preparePaintServer(r
enderer); |
| 170 if (paintServer.isValid()) |
| 171 return paintServer; |
| 172 if (paintDescription.hasFallback) |
| 173 return SVGPaintServer(paintDescription.color); |
| 174 return invalid(); |
| 175 } |
| 176 |
| 177 bool SVGPaintServer::existsForRenderer(const RenderObject& renderer, const Rende
rStyle* style, RenderSVGResourceMode resourceMode) |
| 178 { |
| 179 return requestPaint(renderer, style, resourceMode).isValid; |
| 180 } |
| 181 |
| 182 SVGPaintServer RenderSVGResource::preparePaintServer(const RenderObject&) |
| 183 { |
| 184 ASSERT_NOT_REACHED(); |
| 185 return SVGPaintServer::invalid(); |
| 186 } |
| 187 |
| 188 SVGPaintDescription RenderSVGResource::requestPaintDescription(const RenderObjec
t& renderer, const RenderStyle* style, RenderSVGResourceMode resourceMode) |
| 189 { |
| 190 return requestPaint(renderer, style, resourceMode); |
| 196 } | 191 } |
| 197 | 192 |
| 198 static inline void removeFromCacheAndInvalidateDependencies(RenderObject* object
, bool needsLayout) | 193 static inline void removeFromCacheAndInvalidateDependencies(RenderObject* object
, bool needsLayout) |
| 199 { | 194 { |
| 200 ASSERT(object); | 195 ASSERT(object); |
| 201 if (SVGResources* resources = SVGResourcesCache::cachedResourcesForRenderObj
ect(object)) { | 196 if (SVGResources* resources = SVGResourcesCache::cachedResourcesForRenderObj
ect(object)) { |
| 202 if (RenderSVGResourceFilter* filter = resources->filter()) | 197 if (RenderSVGResourceFilter* filter = resources->filter()) |
| 203 filter->removeClientFromCache(object); | 198 filter->removeClientFromCache(object); |
| 204 | 199 |
| 205 if (RenderSVGResourceMasker* masker = resources->masker()) | 200 if (RenderSVGResourceMasker* masker = resources->masker()) |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 // This will process the rest of the ancestors. | 250 // This will process the rest of the ancestors. |
| 256 toRenderSVGResourceContainer(current)->removeAllClientsFromCache(); | 251 toRenderSVGResourceContainer(current)->removeAllClientsFromCache(); |
| 257 break; | 252 break; |
| 258 } | 253 } |
| 259 | 254 |
| 260 current = current->parent(); | 255 current = current->parent(); |
| 261 } | 256 } |
| 262 } | 257 } |
| 263 | 258 |
| 264 } | 259 } |
| OLD | NEW |