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

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

Issue 20061003: Move isValid/isCurrentColor from Color to StyleColor (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 5 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.
(...skipping 16 matching lines...) Expand all
27 #include "core/page/FrameView.h" 27 #include "core/page/FrameView.h"
28 #include "core/rendering/svg/RenderSVGResourceClipper.h" 28 #include "core/rendering/svg/RenderSVGResourceClipper.h"
29 #include "core/rendering/svg/RenderSVGResourceFilter.h" 29 #include "core/rendering/svg/RenderSVGResourceFilter.h"
30 #include "core/rendering/svg/RenderSVGResourceMasker.h" 30 #include "core/rendering/svg/RenderSVGResourceMasker.h"
31 #include "core/rendering/svg/RenderSVGResourceSolidColor.h" 31 #include "core/rendering/svg/RenderSVGResourceSolidColor.h"
32 #include "core/rendering/svg/SVGResources.h" 32 #include "core/rendering/svg/SVGResources.h"
33 #include "core/rendering/svg/SVGResourcesCache.h" 33 #include "core/rendering/svg/SVGResourcesCache.h"
34 34
35 namespace WebCore { 35 namespace WebCore {
36 36
37 static inline bool inheritColorFromParentStyleIfNeeded(RenderObject* object, boo l applyToFill, Color& color) 37 static inline bool inheritColorFromParentStyleIfNeeded(RenderObject* object, boo l applyToFill, StyleColor& color)
38 { 38 {
39 if (color.isValid()) 39 if (color.isValid())
40 return true; 40 return true;
41 if (!object->parent() || !object->parent()->style()) 41 if (!object->parent() || !object->parent()->style())
42 return false; 42 return false;
43 const SVGRenderStyle* parentSVGStyle = object->parent()->style()->svgStyle() ; 43 const SVGRenderStyle* parentSVGStyle = object->parent()->style()->svgStyle() ;
44 color = applyToFill ? parentSVGStyle->fillPaintColor() : parentSVGStyle->str okePaintColor(); 44 color = applyToFill ? parentSVGStyle->fillPaintColor() : parentSVGStyle->str okePaintColor();
45 return true; 45 return true;
46 } 46 }
47 47
48 static inline RenderSVGResource* requestPaintingResource(RenderSVGResourceMode m ode, RenderObject* object, const RenderStyle* style, Color& fallbackColor) 48 static inline RenderSVGResource* requestPaintingResource(RenderSVGResourceMode m ode, RenderObject* object, const RenderStyle* style, StyleColor& fallbackColor)
49 { 49 {
50 ASSERT(object); 50 ASSERT(object);
51 ASSERT(style); 51 ASSERT(style);
52 52
53 // If we have no style at all, ignore it. 53 // If we have no style at all, ignore it.
54 const SVGRenderStyle* svgStyle = style->svgStyle(); 54 const SVGRenderStyle* svgStyle = style->svgStyle();
55 if (!svgStyle) 55 if (!svgStyle)
56 return 0; 56 return 0;
57 57
58 bool isRenderingMask = false; 58 bool isRenderingMask = false;
(...skipping 14 matching lines...) Expand all
73 } else { 73 } else {
74 if (!svgStyle->hasStroke() || isRenderingMask) 74 if (!svgStyle->hasStroke() || isRenderingMask)
75 return 0; 75 return 0;
76 } 76 }
77 77
78 bool applyToFill = mode == ApplyToFillMode; 78 bool applyToFill = mode == ApplyToFillMode;
79 SVGPaint::SVGPaintType paintType = applyToFill ? svgStyle->fillPaintType() : svgStyle->strokePaintType(); 79 SVGPaint::SVGPaintType paintType = applyToFill ? svgStyle->fillPaintType() : svgStyle->strokePaintType();
80 if (paintType == SVGPaint::SVG_PAINTTYPE_NONE) 80 if (paintType == SVGPaint::SVG_PAINTTYPE_NONE)
81 return 0; 81 return 0;
82 82
83 Color color; 83 StyleColor color;
84 switch (paintType) { 84 switch (paintType) {
85 case SVGPaint::SVG_PAINTTYPE_CURRENTCOLOR: 85 case SVGPaint::SVG_PAINTTYPE_CURRENTCOLOR:
86 case SVGPaint::SVG_PAINTTYPE_RGBCOLOR: 86 case SVGPaint::SVG_PAINTTYPE_RGBCOLOR:
87 case SVGPaint::SVG_PAINTTYPE_RGBCOLOR_ICCCOLOR: 87 case SVGPaint::SVG_PAINTTYPE_RGBCOLOR_ICCCOLOR:
88 case SVGPaint::SVG_PAINTTYPE_URI_CURRENTCOLOR: 88 case SVGPaint::SVG_PAINTTYPE_URI_CURRENTCOLOR:
89 case SVGPaint::SVG_PAINTTYPE_URI_RGBCOLOR: 89 case SVGPaint::SVG_PAINTTYPE_URI_RGBCOLOR:
90 case SVGPaint::SVG_PAINTTYPE_URI_RGBCOLOR_ICCCOLOR: 90 case SVGPaint::SVG_PAINTTYPE_URI_RGBCOLOR_ICCCOLOR:
91 color = applyToFill ? svgStyle->fillPaintColor() : svgStyle->strokePaint Color(); 91 color = applyToFill ? svgStyle->fillPaintColor() : svgStyle->strokePaint Color();
92 default: 92 default:
93 break; 93 break;
94 } 94 }
95 95
96 if (style->insideLink() == InsideVisitedLink) { 96 if (style->insideLink() == InsideVisitedLink) {
97 // FIXME: This code doesn't support the uri component of the visited lin k paint, https://bugs.webkit.org/show_bug.cgi?id=70006 97 // FIXME: This code doesn't support the uri component of the visited lin k paint, https://bugs.webkit.org/show_bug.cgi?id=70006
98 SVGPaint::SVGPaintType visitedPaintType = applyToFill ? svgStyle->visite dLinkFillPaintType() : svgStyle->visitedLinkStrokePaintType(); 98 SVGPaint::SVGPaintType visitedPaintType = applyToFill ? svgStyle->visite dLinkFillPaintType() : svgStyle->visitedLinkStrokePaintType();
99 99
100 // For SVG_PAINTTYPE_CURRENTCOLOR, 'color' already contains the 'visited Color'. 100 // For SVG_PAINTTYPE_CURRENTCOLOR, 'color' already contains the 'visited Color'.
101 if (visitedPaintType < SVGPaint::SVG_PAINTTYPE_URI_NONE && visitedPaintT ype != SVGPaint::SVG_PAINTTYPE_CURRENTCOLOR) { 101 if (visitedPaintType < SVGPaint::SVG_PAINTTYPE_URI_NONE && visitedPaintT ype != SVGPaint::SVG_PAINTTYPE_CURRENTCOLOR) {
102 const Color& visitedColor = applyToFill ? svgStyle->visitedLinkFillP aintColor() : svgStyle->visitedLinkStrokePaintColor(); 102 const Color& visitedColor = applyToFill ? svgStyle->visitedLinkFillP aintColor() : svgStyle->visitedLinkStrokePaintColor();
103 if (visitedColor.isValid()) 103 color = Color(visitedColor.red(), visitedColor.green(), visitedColor .blue(), color.alpha());
104 color = Color(visitedColor.red(), visitedColor.green(), visitedC olor.blue(), color.alpha());
105 } 104 }
106 } 105 }
107 106
108 // If the primary resource is just a color, return immediately. 107 // If the primary resource is just a color, return immediately.
109 RenderSVGResourceSolidColor* colorResource = RenderSVGResource::sharedSolidP aintingResource(); 108 RenderSVGResourceSolidColor* colorResource = RenderSVGResource::sharedSolidP aintingResource();
110 if (paintType < SVGPaint::SVG_PAINTTYPE_URI_NONE) { 109 if (paintType < SVGPaint::SVG_PAINTTYPE_URI_NONE) {
111 if (!inheritColorFromParentStyleIfNeeded(object, applyToFill, color)) 110 if (!inheritColorFromParentStyleIfNeeded(object, applyToFill, color))
112 return 0; 111 return 0;
113 112
114 colorResource->setColor(color); 113 colorResource->setColor(color.color());
115 return colorResource; 114 return colorResource;
116 } 115 }
117 116
118 // If no resources are associated with the given renderer, return the color resource. 117 // If no resources are associated with the given renderer, return the color resource.
119 SVGResources* resources = SVGResourcesCache::cachedResourcesForRenderObject( object); 118 SVGResources* resources = SVGResourcesCache::cachedResourcesForRenderObject( object);
120 if (!resources) { 119 if (!resources) {
121 if (paintType == SVGPaint::SVG_PAINTTYPE_URI_NONE || !inheritColorFromPa rentStyleIfNeeded(object, applyToFill, color)) 120 if (paintType == SVGPaint::SVG_PAINTTYPE_URI_NONE || !inheritColorFromPa rentStyleIfNeeded(object, applyToFill, color))
122 return 0; 121 return 0;
123 122
124 colorResource->setColor(color); 123 colorResource->setColor(color.color());
125 return colorResource; 124 return colorResource;
126 } 125 }
127 126
128 // If the requested resource is not available, return the color resource. 127 // If the requested resource is not available, return the color resource.
129 RenderSVGResource* uriResource = mode == ApplyToFillMode ? resources->fill() : resources->stroke(); 128 RenderSVGResource* uriResource = mode == ApplyToFillMode ? resources->fill() : resources->stroke();
130 if (!uriResource) { 129 if (!uriResource) {
131 if (!inheritColorFromParentStyleIfNeeded(object, applyToFill, color)) 130 if (!inheritColorFromParentStyleIfNeeded(object, applyToFill, color))
132 return 0; 131 return 0;
133 132
134 colorResource->setColor(color); 133 colorResource->setColor(color.color());
135 return colorResource; 134 return colorResource;
136 } 135 }
137 136
138 // The paint server resource exists, though it may be invalid (pattern with width/height=0). Pass the fallback color to our caller 137 // The paint server resource exists, though it may be invalid (pattern with width/height=0). Pass the fallback color to our caller
139 // so it can use the solid color painting resource, if applyResource() on th e URI resource failed. 138 // so it can use the solid color painting resource, if applyResource() on th e URI resource failed.
140 fallbackColor = color; 139 fallbackColor = color;
141 return uriResource; 140 return uriResource;
142 } 141 }
143 142
144 RenderSVGResource* RenderSVGResource::fillPaintingResource(RenderObject* object, const RenderStyle* style, Color& fallbackColor) 143 RenderSVGResource* RenderSVGResource::fillPaintingResource(RenderObject* object, const RenderStyle* style, StyleColor& fallbackColor)
145 { 144 {
146 return requestPaintingResource(ApplyToFillMode, object, style, fallbackColor ); 145 return requestPaintingResource(ApplyToFillMode, object, style, fallbackColor );
147 } 146 }
148 147
149 RenderSVGResource* RenderSVGResource::strokePaintingResource(RenderObject* objec t, const RenderStyle* style, Color& fallbackColor) 148 RenderSVGResource* RenderSVGResource::strokePaintingResource(RenderObject* objec t, const RenderStyle* style, StyleColor& fallbackColor)
150 { 149 {
151 return requestPaintingResource(ApplyToStrokeMode, object, style, fallbackCol or); 150 return requestPaintingResource(ApplyToStrokeMode, object, style, fallbackCol or);
152 } 151 }
153 152
154 RenderSVGResourceSolidColor* RenderSVGResource::sharedSolidPaintingResource() 153 RenderSVGResourceSolidColor* RenderSVGResource::sharedSolidPaintingResource()
155 { 154 {
156 static RenderSVGResourceSolidColor* s_sharedSolidPaintingResource = 0; 155 static RenderSVGResourceSolidColor* s_sharedSolidPaintingResource = 0;
157 if (!s_sharedSolidPaintingResource) 156 if (!s_sharedSolidPaintingResource)
158 s_sharedSolidPaintingResource = new RenderSVGResourceSolidColor; 157 s_sharedSolidPaintingResource = new RenderSVGResourceSolidColor;
159 return s_sharedSolidPaintingResource; 158 return s_sharedSolidPaintingResource;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 // This will process the rest of the ancestors. 204 // This will process the rest of the ancestors.
206 current->toRenderSVGResourceContainer()->removeAllClientsFromCache() ; 205 current->toRenderSVGResourceContainer()->removeAllClientsFromCache() ;
207 break; 206 break;
208 } 207 }
209 208
210 current = current->parent(); 209 current = current->parent();
211 } 210 }
212 } 211 }
213 212
214 } 213 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698