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

Side by Side Diff: Source/core/svg/SVGRadialGradientElement.cpp

Issue 135913002: Do refactor in collectGradientAttributes() and renderStyleForLengthResolve() (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 11 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2004, 2005, 2006, 2008 Nikolas Zimmermann <zimmermann@kde.org> 2 * Copyright (C) 2004, 2005, 2006, 2008 Nikolas Zimmermann <zimmermann@kde.org>
3 * Copyright (C) 2004, 2005, 2006, 2007 Rob Buis <buis@kde.org> 3 * Copyright (C) 2004, 2005, 2006, 2007 Rob Buis <buis@kde.org>
4 * Copyright (C) 2008 Eric Seidel <eric@webkit.org> 4 * Copyright (C) 2008 Eric Seidel <eric@webkit.org>
5 * Copyright (C) 2008 Dirk Schulze <krit@webkit.org> 5 * Copyright (C) 2008 Dirk Schulze <krit@webkit.org>
6 * Copyright (C) Research In Motion Limited 2010. All rights reserved. 6 * Copyright (C) Research In Motion Limited 2010. All rights reserved.
7 * 7 *
8 * This library is free software; you can redistribute it and/or 8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public 9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either 10 * License as published by the Free Software Foundation; either
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 127
128 RenderObject* SVGRadialGradientElement::createRenderer(RenderStyle*) 128 RenderObject* SVGRadialGradientElement::createRenderer(RenderStyle*)
129 { 129 {
130 return new RenderSVGResourceRadialGradient(this); 130 return new RenderSVGResourceRadialGradient(this);
131 } 131 }
132 132
133 bool SVGRadialGradientElement::collectGradientAttributes(RadialGradientAttribute s& attributes) 133 bool SVGRadialGradientElement::collectGradientAttributes(RadialGradientAttribute s& attributes)
134 { 134 {
135 HashSet<SVGGradientElement*> processedGradients; 135 HashSet<SVGGradientElement*> processedGradients;
136 136
137 bool isRadial = true;
138 SVGGradientElement* current = this; 137 SVGGradientElement* current = this;
138 if (!current->renderer())
139 return false;
139 140
140 while (current) { 141 setAttributeAnimatedLength(current, attributes);
141 if (!current->renderer())
142 return false;
143 142
144 if (!attributes.hasSpreadMethod() && current->hasAttribute(SVGNames::spr eadMethodAttr)) 143 do {
145 attributes.setSpreadMethod(current->spreadMethodCurrentValue());
146
147 if (!attributes.hasGradientUnits() && current->hasAttribute(SVGNames::gr adientUnitsAttr))
148 attributes.setGradientUnits(current->gradientUnitsCurrentValue());
149
150 if (!attributes.hasGradientTransform() && current->hasAttribute(SVGNames ::gradientTransformAttr)) {
151 AffineTransform transform;
152 current->gradientTransformCurrentValue().concatenate(transform);
153 attributes.setGradientTransform(transform);
154 }
155
156 if (!attributes.hasStops()) {
157 const Vector<Gradient::ColorStop>& stops(current->buildStops());
158 if (!stops.isEmpty())
159 attributes.setStops(stops);
160 }
161
162 if (isRadial) {
163 SVGRadialGradientElement* radial = toSVGRadialGradientElement(curren t);
164
165 if (!attributes.hasCx() && current->hasAttribute(SVGNames::cxAttr))
166 attributes.setCx(radial->cx()->currentValue());
167
168 if (!attributes.hasCy() && current->hasAttribute(SVGNames::cyAttr))
169 attributes.setCy(radial->cy()->currentValue());
170
171 if (!attributes.hasR() && current->hasAttribute(SVGNames::rAttr))
172 attributes.setR(radial->r()->currentValue());
173
174 if (!attributes.hasFx() && current->hasAttribute(SVGNames::fxAttr))
175 attributes.setFx(radial->fx()->currentValue());
176
177 if (!attributes.hasFy() && current->hasAttribute(SVGNames::fyAttr))
178 attributes.setFy(radial->fy()->currentValue());
179
180 if (!attributes.hasFr() && current->hasAttribute(SVGNames::frAttr))
181 attributes.setFr(radial->fr()->currentValue());
182 }
183
184 processedGradients.add(current); 144 processedGradients.add(current);
gyuyoung-inactive 2014/01/16 03:34:11 I think this line doesn't need to call out of do-w
Stephen Chennney 2014/01/16 15:39:34 I think it needs to appear before entering the loo
gyuyoung-inactive 2014/01/17 05:38:26 Done.
185 145
186 // Respect xlink:href, take attributes from referenced element 146 // Respect xlink:href, take attributes from referenced element
187 Node* refNode = SVGURIReference::targetElementFromIRIString(current->hre fCurrentValue(), document()); 147 Node* refNode = SVGURIReference::targetElementFromIRIString(current->hre fCurrentValue(), document());
188 if (refNode && (refNode->hasTagName(SVGNames::radialGradientTag) || refN ode->hasTagName(SVGNames::linearGradientTag))) { 148 if (refNode && isSVGGradientElement(*refNode)) {
189 current = toSVGGradientElement(refNode); 149 current = toSVGGradientElement(refNode);
190 150
191 // Cycle detection 151 // Cycle detection
192 if (processedGradients.contains(current)) { 152 if (processedGradients.contains(current)) {
193 current = 0; 153 current = 0;
194 break; 154 break;
195 } 155 }
196 156
197 isRadial = current->hasTagName(SVGNames::radialGradientTag); 157 if (!current->renderer())
198 } else 158 return false;
159
160 setAttributeAnimatedLength(current, attributes, current->hasTagName( SVGNames::radialGradientTag));
161 } else {
199 current = 0; 162 current = 0;
200 } 163 }
164 } while (current);
201 165
202 // Handle default values for fx/fy 166 // Handle default values for fx/fy
203 if (!attributes.hasFx()) 167 if (!attributes.hasFx())
204 attributes.setFx(attributes.cx()); 168 attributes.setFx(attributes.cx());
205 169
206 if (!attributes.hasFy()) 170 if (!attributes.hasFy())
207 attributes.setFy(attributes.cy()); 171 attributes.setFy(attributes.cy());
208 return true; 172 return true;
209 } 173 }
210 174
175 void SVGRadialGradientElement::setAttributeAnimatedLength(SVGGradientElement* el ement, RadialGradientAttributes& attributes, bool isRadial)
176 {
177 if (!attributes.hasSpreadMethod() && element->hasAttribute(SVGNames::spreadM ethodAttr))
178 attributes.setSpreadMethod(element->spreadMethodCurrentValue());
179
180 if (!attributes.hasGradientUnits() && element->hasAttribute(SVGNames::gradie ntUnitsAttr))
181 attributes.setGradientUnits(element->gradientUnitsCurrentValue());
182
183 if (!attributes.hasGradientTransform() && element->hasAttribute(SVGNames::gr adientTransformAttr)) {
184 AffineTransform transform;
185 element->gradientTransformCurrentValue().concatenate(transform);
186 attributes.setGradientTransform(transform);
187 }
188
189 if (!attributes.hasStops()) {
190 const Vector<Gradient::ColorStop>& stops(element->buildStops());
191 if (!stops.isEmpty())
192 attributes.setStops(stops);
193 }
194
195 if (isRadial) {
196 SVGRadialGradientElement* radial = toSVGRadialGradientElement(element);
197
198 if (!attributes.hasCx() && element->hasAttribute(SVGNames::cxAttr))
199 attributes.setCx(radial->cx()->currentValue());
200
201 if (!attributes.hasCy() && element->hasAttribute(SVGNames::cyAttr))
202 attributes.setCy(radial->cy()->currentValue());
203
204 if (!attributes.hasR() && element->hasAttribute(SVGNames::rAttr))
205 attributes.setR(radial->r()->currentValue());
206
207 if (!attributes.hasFx() && element->hasAttribute(SVGNames::fxAttr))
208 attributes.setFx(radial->fx()->currentValue());
209
210 if (!attributes.hasFy() && element->hasAttribute(SVGNames::fyAttr))
211 attributes.setFy(radial->fy()->currentValue());
212
213 if (!attributes.hasFr() && element->hasAttribute(SVGNames::frAttr))
214 attributes.setFr(radial->fr()->currentValue());
215 }
216 }
217
211 bool SVGRadialGradientElement::selfHasRelativeLengths() const 218 bool SVGRadialGradientElement::selfHasRelativeLengths() const
212 { 219 {
213 return m_cx->currentValue()->isRelative() 220 return m_cx->currentValue()->isRelative()
214 || m_cy->currentValue()->isRelative() 221 || m_cy->currentValue()->isRelative()
215 || m_r->currentValue()->isRelative() 222 || m_r->currentValue()->isRelative()
216 || m_fx->currentValue()->isRelative() 223 || m_fx->currentValue()->isRelative()
217 || m_fy->currentValue()->isRelative() 224 || m_fy->currentValue()->isRelative()
218 || m_fr->currentValue()->isRelative(); 225 || m_fr->currentValue()->isRelative();
219 } 226 }
220 227
221 } 228 }
OLDNEW
« Source/core/svg/SVGLinearGradientElement.cpp ('K') | « Source/core/svg/SVGRadialGradientElement.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698