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

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

Issue 2741993002: Move common gradient attribute collection to SVGGradientElement (Closed)
Patch Set: Rebase; fix semantics on find cycle Created 3 years, 9 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 | « third_party/WebKit/Source/core/svg/SVGLinearGradientElement.cpp ('k') | no next file » | 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 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 } 96 }
97 97
98 SVGGradientElement::svgAttributeChanged(attrName); 98 SVGGradientElement::svgAttributeChanged(attrName);
99 } 99 }
100 100
101 LayoutObject* SVGRadialGradientElement::createLayoutObject( 101 LayoutObject* SVGRadialGradientElement::createLayoutObject(
102 const ComputedStyle&) { 102 const ComputedStyle&) {
103 return new LayoutSVGResourceRadialGradient(this); 103 return new LayoutSVGResourceRadialGradient(this);
104 } 104 }
105 105
106 static void setGradientAttributes(SVGGradientElement* element, 106 static void setGradientAttributes(const SVGGradientElement& element,
107 RadialGradientAttributes& attributes, 107 RadialGradientAttributes& attributes,
108 bool isRadial = true) { 108 bool isRadial) {
109 if (!attributes.hasSpreadMethod() && element->spreadMethod()->isSpecified()) 109 element.collectCommonAttributes(attributes);
110 attributes.setSpreadMethod(
111 element->spreadMethod()->currentValue()->enumValue());
112 110
113 if (!attributes.hasGradientUnits() && element->gradientUnits()->isSpecified()) 111 if (!isRadial)
114 attributes.setGradientUnits( 112 return;
115 element->gradientUnits()->currentValue()->enumValue()); 113 const SVGRadialGradientElement& radial = toSVGRadialGradientElement(element);
116 114
117 if (!attributes.hasGradientTransform() && 115 if (!attributes.hasCx() && radial.cx()->isSpecified())
118 element->hasTransform(SVGElement::ExcludeMotionTransform)) { 116 attributes.setCx(radial.cx()->currentValue());
119 attributes.setGradientTransform(
120 element->calculateTransform(SVGElement::ExcludeMotionTransform));
121 }
122 117
123 if (!attributes.hasStops()) { 118 if (!attributes.hasCy() && radial.cy()->isSpecified())
124 const Vector<Gradient::ColorStop>& stops(element->buildStops()); 119 attributes.setCy(radial.cy()->currentValue());
125 if (!stops.isEmpty())
126 attributes.setStops(stops);
127 }
128 120
129 if (isRadial) { 121 if (!attributes.hasR() && radial.r()->isSpecified())
130 SVGRadialGradientElement* radial = toSVGRadialGradientElement(element); 122 attributes.setR(radial.r()->currentValue());
131 123
132 if (!attributes.hasCx() && radial->cx()->isSpecified()) 124 if (!attributes.hasFx() && radial.fx()->isSpecified())
133 attributes.setCx(radial->cx()->currentValue()); 125 attributes.setFx(radial.fx()->currentValue());
134 126
135 if (!attributes.hasCy() && radial->cy()->isSpecified()) 127 if (!attributes.hasFy() && radial.fy()->isSpecified())
136 attributes.setCy(radial->cy()->currentValue()); 128 attributes.setFy(radial.fy()->currentValue());
137 129
138 if (!attributes.hasR() && radial->r()->isSpecified()) 130 if (!attributes.hasFr() && radial.fr()->isSpecified())
139 attributes.setR(radial->r()->currentValue()); 131 attributes.setFr(radial.fr()->currentValue());
140
141 if (!attributes.hasFx() && radial->fx()->isSpecified())
142 attributes.setFx(radial->fx()->currentValue());
143
144 if (!attributes.hasFy() && radial->fy()->isSpecified())
145 attributes.setFy(radial->fy()->currentValue());
146
147 if (!attributes.hasFr() && radial->fr()->isSpecified())
148 attributes.setFr(radial->fr()->currentValue());
149 }
150 } 132 }
151 133
152 bool SVGRadialGradientElement::collectGradientAttributes( 134 bool SVGRadialGradientElement::collectGradientAttributes(
153 RadialGradientAttributes& attributes) { 135 RadialGradientAttributes& attributes) {
154 if (!layoutObject()) 136 DCHECK(layoutObject());
155 return false;
156 137
157 HeapHashSet<Member<SVGGradientElement>> processedGradients; 138 VisitedSet visited;
158 SVGGradientElement* current = this; 139 const SVGGradientElement* current = this;
159
160 setGradientAttributes(current, attributes);
161 processedGradients.insert(current);
162 140
163 while (true) { 141 while (true) {
164 // Respect xlink:href, take attributes from referenced element 142 setGradientAttributes(*current, attributes,
165 Node* refNode = SVGURIReference::targetElementFromIRIString( 143 isSVGRadialGradientElement(*current));
166 current->href()->currentValue()->value(), treeScope()); 144 visited.insert(current);
167 if (refNode && isSVGGradientElement(*refNode)) {
168 current = toSVGGradientElement(refNode);
169 145
170 // Cycle detection 146 current = current->referencedElement();
171 if (processedGradients.contains(current)) 147 if (!current || visited.contains(current))
172 break;
173
174 if (!current->layoutObject())
175 return false;
176
177 setGradientAttributes(current, attributes,
178 isSVGRadialGradientElement(*current));
179 processedGradients.insert(current);
180 } else {
181 break; 148 break;
182 } 149 if (!current->layoutObject())
150 return false;
183 } 151 }
184 152
185 // Handle default values for fx/fy 153 // Handle default values for fx/fy
186 if (!attributes.hasFx()) 154 if (!attributes.hasFx())
187 attributes.setFx(attributes.cx()); 155 attributes.setFx(attributes.cx());
188 156
189 if (!attributes.hasFy()) 157 if (!attributes.hasFy())
190 attributes.setFy(attributes.cy()); 158 attributes.setFy(attributes.cy());
191 159
192 return true; 160 return true;
193 } 161 }
194 162
195 bool SVGRadialGradientElement::selfHasRelativeLengths() const { 163 bool SVGRadialGradientElement::selfHasRelativeLengths() const {
196 return m_cx->currentValue()->isRelative() || 164 return m_cx->currentValue()->isRelative() ||
197 m_cy->currentValue()->isRelative() || 165 m_cy->currentValue()->isRelative() ||
198 m_r->currentValue()->isRelative() || 166 m_r->currentValue()->isRelative() ||
199 m_fx->currentValue()->isRelative() || 167 m_fx->currentValue()->isRelative() ||
200 m_fy->currentValue()->isRelative() || 168 m_fy->currentValue()->isRelative() ||
201 m_fr->currentValue()->isRelative(); 169 m_fr->currentValue()->isRelative();
202 } 170 }
203 171
204 } // namespace blink 172 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/svg/SVGLinearGradientElement.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698