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

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
« no previous file with comments | « Source/core/svg/SVGLengthContext.cpp ('k') | Source/core/svg/SVGRadialGradientElement.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 RenderSVGResourceContainer* renderer = toRenderSVGResourceContainer(this->re nderer()); 108 RenderSVGResourceContainer* renderer = toRenderSVGResourceContainer(this->re nderer());
109 if (renderer) 109 if (renderer)
110 renderer->invalidateCacheAndMarkForLayout(); 110 renderer->invalidateCacheAndMarkForLayout();
111 } 111 }
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 static void setGradientAttributes(SVGGradientElement* element, LinearGradientAtt ributes& attributes, bool isLinear = true)
119 {
120 if (!attributes.hasSpreadMethod() && element->hasAttribute(SVGNames::spreadM ethodAttr))
121 attributes.setSpreadMethod(element->spreadMethodCurrentValue());
122
123 if (!attributes.hasGradientUnits() && element->hasAttribute(SVGNames::gradie ntUnitsAttr))
124 attributes.setGradientUnits(element->gradientUnitsCurrentValue());
125
126 if (!attributes.hasGradientTransform() && element->hasAttribute(SVGNames::gr adientTransformAttr)) {
127 AffineTransform transform;
128 element->gradientTransformCurrentValue().concatenate(transform);
129 attributes.setGradientTransform(transform);
130 }
131
132 if (!attributes.hasStops()) {
133 const Vector<Gradient::ColorStop>& stops(element->buildStops());
134 if (!stops.isEmpty())
135 attributes.setStops(stops);
136 }
137
138 if (isLinear) {
139 SVGLinearGradientElement* linear = toSVGLinearGradientElement(element);
140
141 if (!attributes.hasX1() && element->hasAttribute(SVGNames::x1Attr))
142 attributes.setX1(linear->x1()->currentValue());
143
144 if (!attributes.hasY1() && element->hasAttribute(SVGNames::y1Attr))
145 attributes.setY1(linear->y1()->currentValue());
146
147 if (!attributes.hasX2() && element->hasAttribute(SVGNames::x2Attr))
148 attributes.setX2(linear->x2()->currentValue());
149
150 if (!attributes.hasY2() && element->hasAttribute(SVGNames::y2Attr))
151 attributes.setY2(linear->y2()->currentValue());
152 }
153 }
154
118 bool SVGLinearGradientElement::collectGradientAttributes(LinearGradientAttribute s& attributes) 155 bool SVGLinearGradientElement::collectGradientAttributes(LinearGradientAttribute s& attributes)
119 { 156 {
157 if (!renderer())
158 return false;
159
120 HashSet<SVGGradientElement*> processedGradients; 160 HashSet<SVGGradientElement*> processedGradients;
121
122 bool isLinear = true;
123 SVGGradientElement* current = this; 161 SVGGradientElement* current = this;
124 162
125 while (current) { 163 setGradientAttributes(current, attributes);
126 if (!current->renderer()) 164 processedGradients.add(current);
127 return false;
128 165
129 if (!attributes.hasSpreadMethod() && current->hasAttribute(SVGNames::spr eadMethodAttr)) 166 while (true) {
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);
164
165 // Respect xlink:href, take attributes from referenced element 167 // Respect xlink:href, take attributes from referenced element
166 Node* refNode = SVGURIReference::targetElementFromIRIString(current->hre fCurrentValue(), document()); 168 Node* refNode = SVGURIReference::targetElementFromIRIString(current->hre fCurrentValue(), document());
167 if (refNode && (refNode->hasTagName(SVGNames::linearGradientTag) || refN ode->hasTagName(SVGNames::radialGradientTag))) { 169 if (refNode && isSVGGradientElement(*refNode)) {
168 current = toSVGGradientElement(refNode); 170 current = toSVGGradientElement(refNode);
169 171
170 // Cycle detection 172 // Cycle detection
171 if (processedGradients.contains(current)) { 173 if (processedGradients.contains(current))
172 current = 0; 174 return true;
173 break;
174 }
175 175
176 isLinear = current->hasTagName(SVGNames::linearGradientTag); 176 if (!current->renderer())
177 } else 177 return false;
178 current = 0; 178
179 setGradientAttributes(current, attributes, current->hasTagName(SVGNa mes::linearGradientTag));
180 processedGradients.add(current);
181 } else {
182 return true;
183 }
179 } 184 }
180 185
181 return true; 186 ASSERT_NOT_REACHED();
187 return false;
182 } 188 }
183 189
184 bool SVGLinearGradientElement::selfHasRelativeLengths() const 190 bool SVGLinearGradientElement::selfHasRelativeLengths() const
185 { 191 {
186 return m_x1->currentValue()->isRelative() 192 return m_x1->currentValue()->isRelative()
187 || m_y1->currentValue()->isRelative() 193 || m_y1->currentValue()->isRelative()
188 || m_x2->currentValue()->isRelative() 194 || m_x2->currentValue()->isRelative()
189 || m_y2->currentValue()->isRelative(); 195 || m_y2->currentValue()->isRelative();
190 } 196 }
191 197
192 } 198 }
OLDNEW
« no previous file with comments | « Source/core/svg/SVGLengthContext.cpp ('k') | Source/core/svg/SVGRadialGradientElement.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698