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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/core/svg/SVGLengthContext.cpp ('k') | Source/core/svg/SVGRadialGradientElement.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/svg/SVGLinearGradientElement.cpp
diff --git a/Source/core/svg/SVGLinearGradientElement.cpp b/Source/core/svg/SVGLinearGradientElement.cpp
index 19df4d50b46b7eedc0f0ac5a5057ca7f93c6c38b..8a596e44944328a425c13512bd5d2d1486448084 100644
--- a/Source/core/svg/SVGLinearGradientElement.cpp
+++ b/Source/core/svg/SVGLinearGradientElement.cpp
@@ -115,70 +115,76 @@ RenderObject* SVGLinearGradientElement::createRenderer(RenderStyle*)
return new RenderSVGResourceLinearGradient(this);
}
-bool SVGLinearGradientElement::collectGradientAttributes(LinearGradientAttributes& attributes)
+static void setGradientAttributes(SVGGradientElement* element, LinearGradientAttributes& attributes, bool isLinear = true)
{
- HashSet<SVGGradientElement*> processedGradients;
+ if (!attributes.hasSpreadMethod() && element->hasAttribute(SVGNames::spreadMethodAttr))
+ attributes.setSpreadMethod(element->spreadMethodCurrentValue());
- bool isLinear = true;
- SVGGradientElement* current = this;
+ if (!attributes.hasGradientUnits() && element->hasAttribute(SVGNames::gradientUnitsAttr))
+ attributes.setGradientUnits(element->gradientUnitsCurrentValue());
- while (current) {
- if (!current->renderer())
- return false;
-
- if (!attributes.hasSpreadMethod() && current->hasAttribute(SVGNames::spreadMethodAttr))
- attributes.setSpreadMethod(current->spreadMethodCurrentValue());
+ if (!attributes.hasGradientTransform() && element->hasAttribute(SVGNames::gradientTransformAttr)) {
+ AffineTransform transform;
+ element->gradientTransformCurrentValue().concatenate(transform);
+ attributes.setGradientTransform(transform);
+ }
- if (!attributes.hasGradientUnits() && current->hasAttribute(SVGNames::gradientUnitsAttr))
- attributes.setGradientUnits(current->gradientUnitsCurrentValue());
+ if (!attributes.hasStops()) {
+ const Vector<Gradient::ColorStop>& stops(element->buildStops());
+ if (!stops.isEmpty())
+ attributes.setStops(stops);
+ }
- if (!attributes.hasGradientTransform() && current->hasAttribute(SVGNames::gradientTransformAttr)) {
- AffineTransform transform;
- current->gradientTransformCurrentValue().concatenate(transform);
- attributes.setGradientTransform(transform);
- }
+ if (isLinear) {
+ SVGLinearGradientElement* linear = toSVGLinearGradientElement(element);
- if (!attributes.hasStops()) {
- const Vector<Gradient::ColorStop>& stops(current->buildStops());
- if (!stops.isEmpty())
- attributes.setStops(stops);
- }
+ if (!attributes.hasX1() && element->hasAttribute(SVGNames::x1Attr))
+ attributes.setX1(linear->x1()->currentValue());
- if (isLinear) {
- SVGLinearGradientElement* linear = toSVGLinearGradientElement(current);
+ if (!attributes.hasY1() && element->hasAttribute(SVGNames::y1Attr))
+ attributes.setY1(linear->y1()->currentValue());
- if (!attributes.hasX1() && current->hasAttribute(SVGNames::x1Attr))
- attributes.setX1(linear->x1()->currentValue());
+ if (!attributes.hasX2() && element->hasAttribute(SVGNames::x2Attr))
+ attributes.setX2(linear->x2()->currentValue());
- if (!attributes.hasY1() && current->hasAttribute(SVGNames::y1Attr))
- attributes.setY1(linear->y1()->currentValue());
+ if (!attributes.hasY2() && element->hasAttribute(SVGNames::y2Attr))
+ attributes.setY2(linear->y2()->currentValue());
+ }
+}
- if (!attributes.hasX2() && current->hasAttribute(SVGNames::x2Attr))
- attributes.setX2(linear->x2()->currentValue());
+bool SVGLinearGradientElement::collectGradientAttributes(LinearGradientAttributes& attributes)
+{
+ if (!renderer())
+ return false;
- if (!attributes.hasY2() && current->hasAttribute(SVGNames::y2Attr))
- attributes.setY2(linear->y2()->currentValue());
- }
+ HashSet<SVGGradientElement*> processedGradients;
+ SVGGradientElement* current = this;
- processedGradients.add(current);
+ setGradientAttributes(current, attributes);
+ processedGradients.add(current);
+ while (true) {
// Respect xlink:href, take attributes from referenced element
Node* refNode = SVGURIReference::targetElementFromIRIString(current->hrefCurrentValue(), document());
- if (refNode && (refNode->hasTagName(SVGNames::linearGradientTag) || refNode->hasTagName(SVGNames::radialGradientTag))) {
+ if (refNode && isSVGGradientElement(*refNode)) {
current = toSVGGradientElement(refNode);
// Cycle detection
- if (processedGradients.contains(current)) {
- current = 0;
- break;
- }
-
- isLinear = current->hasTagName(SVGNames::linearGradientTag);
- } else
- current = 0;
+ if (processedGradients.contains(current))
+ return true;
+
+ if (!current->renderer())
+ return false;
+
+ setGradientAttributes(current, attributes, current->hasTagName(SVGNames::linearGradientTag));
+ processedGradients.add(current);
+ } else {
+ return true;
+ }
}
- return true;
+ ASSERT_NOT_REACHED();
+ return false;
}
bool SVGLinearGradientElement::selfHasRelativeLengths() const
« 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