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

Side by Side Diff: Source/core/svg/SVGLinearGradientElement.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 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 112
113 RenderObject* SVGLinearGradientElement::createRenderer(RenderStyle*) 113 RenderObject* SVGLinearGradientElement::createRenderer(RenderStyle*)
114 { 114 {
115 return new RenderSVGResourceLinearGradient(this); 115 return new RenderSVGResourceLinearGradient(this);
116 } 116 }
117 117
118 bool SVGLinearGradientElement::collectGradientAttributes(LinearGradientAttribute s& attributes) 118 bool SVGLinearGradientElement::collectGradientAttributes(LinearGradientAttribute s& attributes)
119 { 119 {
120 HashSet<SVGGradientElement*> processedGradients; 120 HashSet<SVGGradientElement*> processedGradients;
121 121
122 bool isLinear = true;
123 SVGGradientElement* current = this; 122 SVGGradientElement* current = this;
123 if (!current->renderer())
124 return false;
Stephen Chennney 2014/01/16 15:39:34 Should just be "if (!renderer()) return false;" at
gyuyoung-inactive 2014/01/17 05:38:26 Done.
124 125
125 while (current) { 126 setAttributeAnimatedLength(current, attributes);
126 if (!current->renderer())
127 return false;
128 127
129 if (!attributes.hasSpreadMethod() && current->hasAttribute(SVGNames::spr eadMethodAttr)) 128 do {
Stephen Chennney 2014/01/16 15:39:34 while (true)
gyuyoung-inactive 2014/01/17 05:38:26 Done.
130 attributes.setSpreadMethod(current->spreadMethodCurrentValue());
131
132 if (!attributes.hasGradientUnits() && current->hasAttribute(SVGNames::gr adientUnitsAttr))
133 attributes.setGradientUnits(current->gradientUnitsCurrentValue());
134
135 if (!attributes.hasGradientTransform() && current->hasAttribute(SVGNames ::gradientTransformAttr)) {
136 AffineTransform transform;
137 current->gradientTransformCurrentValue().concatenate(transform);
138 attributes.setGradientTransform(transform);
139 }
140
141 if (!attributes.hasStops()) {
142 const Vector<Gradient::ColorStop>& stops(current->buildStops());
143 if (!stops.isEmpty())
144 attributes.setStops(stops);
145 }
146
147 if (isLinear) {
148 SVGLinearGradientElement* linear = toSVGLinearGradientElement(curren t);
149
150 if (!attributes.hasX1() && current->hasAttribute(SVGNames::x1Attr))
151 attributes.setX1(linear->x1()->currentValue());
152
153 if (!attributes.hasY1() && current->hasAttribute(SVGNames::y1Attr))
154 attributes.setY1(linear->y1()->currentValue());
155
156 if (!attributes.hasX2() && current->hasAttribute(SVGNames::x2Attr))
157 attributes.setX2(linear->x2()->currentValue());
158
159 if (!attributes.hasY2() && current->hasAttribute(SVGNames::y2Attr))
160 attributes.setY2(linear->y2()->currentValue());
161 }
162
163 processedGradients.add(current); 129 processedGradients.add(current);
164 130
165 // Respect xlink:href, take attributes from referenced element 131 // Respect xlink:href, take attributes from referenced element
166 Node* refNode = SVGURIReference::targetElementFromIRIString(current->hre fCurrentValue(), document()); 132 Node* refNode = SVGURIReference::targetElementFromIRIString(current->hre fCurrentValue(), document());
167 if (refNode && (refNode->hasTagName(SVGNames::linearGradientTag) || refN ode->hasTagName(SVGNames::radialGradientTag))) { 133 if (refNode && isSVGGradientElement(*refNode)) {
168 current = toSVGGradientElement(refNode); 134 current = toSVGGradientElement(refNode);
169 135
170 // Cycle detection 136 // Cycle detection
171 if (processedGradients.contains(current)) { 137 if (processedGradients.contains(current)) {
172 current = 0; 138 current = 0;
173 break; 139 break;
Stephen Chennney 2014/01/16 15:39:34 return true;
gyuyoung-inactive 2014/01/17 05:38:26 In SVGRadialGradientElement, we can't return true
174 } 140 }
175 141
176 isLinear = current->hasTagName(SVGNames::linearGradientTag); 142 if (!current->renderer())
177 } else 143 return false;
144
145 setAttributeAnimatedLength(current, attributes, current->hasTagName( SVGNames::linearGradientTag));
146 } else {
178 current = 0; 147 current = 0;
Stephen Chennney 2014/01/16 15:39:34 return true;
gyuyoung-inactive 2014/01/17 05:38:26 Done.
148 }
149 } while (current);
Stephen Chennney 2014/01/16 15:39:34 } ASSERT_NOT_REACHED();
gyuyoung-inactive 2014/01/17 05:38:26 Done.
150
151 return true;
152 }
153
154 void SVGLinearGradientElement::setAttributeAnimatedLength(SVGGradientElement* el ement, LinearGradientAttributes& attributes, bool isLinear)
155 {
156 if (!attributes.hasSpreadMethod() && element->hasAttribute(SVGNames::spreadM ethodAttr))
157 attributes.setSpreadMethod(element->spreadMethodCurrentValue());
158
159 if (!attributes.hasGradientUnits() && element->hasAttribute(SVGNames::gradie ntUnitsAttr))
160 attributes.setGradientUnits(element->gradientUnitsCurrentValue());
161
162 if (!attributes.hasGradientTransform() && element->hasAttribute(SVGNames::gr adientTransformAttr)) {
163 AffineTransform transform;
164 element->gradientTransformCurrentValue().concatenate(transform);
165 attributes.setGradientTransform(transform);
179 } 166 }
180 167
181 return true; 168 if (!attributes.hasStops()) {
169 const Vector<Gradient::ColorStop>& stops(element->buildStops());
170 if (!stops.isEmpty())
171 attributes.setStops(stops);
172 }
173
174 if (isLinear) {
175 SVGLinearGradientElement* linear = toSVGLinearGradientElement(element);
176
177 if (!attributes.hasX1() && element->hasAttribute(SVGNames::x1Attr))
178 attributes.setX1(linear->x1()->currentValue());
179
180 if (!attributes.hasY1() && element->hasAttribute(SVGNames::y1Attr))
181 attributes.setY1(linear->y1()->currentValue());
182
183 if (!attributes.hasX2() && element->hasAttribute(SVGNames::x2Attr))
184 attributes.setX2(linear->x2()->currentValue());
185
186 if (!attributes.hasY2() && element->hasAttribute(SVGNames::y2Attr))
187 attributes.setY2(linear->y2()->currentValue());
188 }
182 } 189 }
183 190
184 bool SVGLinearGradientElement::selfHasRelativeLengths() const 191 bool SVGLinearGradientElement::selfHasRelativeLengths() const
185 { 192 {
186 return m_x1->currentValue()->isRelative() 193 return m_x1->currentValue()->isRelative()
187 || m_y1->currentValue()->isRelative() 194 || m_y1->currentValue()->isRelative()
188 || m_x2->currentValue()->isRelative() 195 || m_x2->currentValue()->isRelative()
189 || m_y2->currentValue()->isRelative(); 196 || m_y2->currentValue()->isRelative();
190 } 197 }
191 198
192 } 199 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698