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

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
Index: Source/core/svg/SVGLinearGradientElement.cpp
diff --git a/Source/core/svg/SVGLinearGradientElement.cpp b/Source/core/svg/SVGLinearGradientElement.cpp
index 19df4d50b46b7eedc0f0ac5a5057ca7f93c6c38b..7d26f7ec6b781324328ee168c1edb7211e71883a 100644
--- a/Source/core/svg/SVGLinearGradientElement.cpp
+++ b/Source/core/svg/SVGLinearGradientElement.cpp
@@ -119,52 +119,18 @@ bool SVGLinearGradientElement::collectGradientAttributes(LinearGradientAttribute
{
HashSet<SVGGradientElement*> processedGradients;
- bool isLinear = true;
SVGGradientElement* current = this;
+ if (!current->renderer())
+ 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.
- while (current) {
- if (!current->renderer())
- return false;
-
- if (!attributes.hasSpreadMethod() && current->hasAttribute(SVGNames::spreadMethodAttr))
- attributes.setSpreadMethod(current->spreadMethodCurrentValue());
-
- if (!attributes.hasGradientUnits() && current->hasAttribute(SVGNames::gradientUnitsAttr))
- attributes.setGradientUnits(current->gradientUnitsCurrentValue());
-
- if (!attributes.hasGradientTransform() && current->hasAttribute(SVGNames::gradientTransformAttr)) {
- AffineTransform transform;
- current->gradientTransformCurrentValue().concatenate(transform);
- attributes.setGradientTransform(transform);
- }
-
- if (!attributes.hasStops()) {
- const Vector<Gradient::ColorStop>& stops(current->buildStops());
- if (!stops.isEmpty())
- attributes.setStops(stops);
- }
-
- if (isLinear) {
- SVGLinearGradientElement* linear = toSVGLinearGradientElement(current);
-
- if (!attributes.hasX1() && current->hasAttribute(SVGNames::x1Attr))
- attributes.setX1(linear->x1()->currentValue());
-
- if (!attributes.hasY1() && current->hasAttribute(SVGNames::y1Attr))
- attributes.setY1(linear->y1()->currentValue());
-
- if (!attributes.hasX2() && current->hasAttribute(SVGNames::x2Attr))
- attributes.setX2(linear->x2()->currentValue());
-
- if (!attributes.hasY2() && current->hasAttribute(SVGNames::y2Attr))
- attributes.setY2(linear->y2()->currentValue());
- }
+ setAttributeAnimatedLength(current, attributes);
+ do {
Stephen Chennney 2014/01/16 15:39:34 while (true)
gyuyoung-inactive 2014/01/17 05:38:26 Done.
processedGradients.add(current);
// 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
@@ -173,14 +139,55 @@ bool SVGLinearGradientElement::collectGradientAttributes(LinearGradientAttribute
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
}
- isLinear = current->hasTagName(SVGNames::linearGradientTag);
- } else
+ if (!current->renderer())
+ return false;
+
+ setAttributeAnimatedLength(current, attributes, current->hasTagName(SVGNames::linearGradientTag));
+ } else {
current = 0;
Stephen Chennney 2014/01/16 15:39:34 return true;
gyuyoung-inactive 2014/01/17 05:38:26 Done.
- }
+ }
+ } while (current);
Stephen Chennney 2014/01/16 15:39:34 } ASSERT_NOT_REACHED();
gyuyoung-inactive 2014/01/17 05:38:26 Done.
return true;
}
+void SVGLinearGradientElement::setAttributeAnimatedLength(SVGGradientElement* element, LinearGradientAttributes& attributes, bool isLinear)
+{
+ if (!attributes.hasSpreadMethod() && element->hasAttribute(SVGNames::spreadMethodAttr))
+ attributes.setSpreadMethod(element->spreadMethodCurrentValue());
+
+ if (!attributes.hasGradientUnits() && element->hasAttribute(SVGNames::gradientUnitsAttr))
+ attributes.setGradientUnits(element->gradientUnitsCurrentValue());
+
+ if (!attributes.hasGradientTransform() && element->hasAttribute(SVGNames::gradientTransformAttr)) {
+ AffineTransform transform;
+ element->gradientTransformCurrentValue().concatenate(transform);
+ attributes.setGradientTransform(transform);
+ }
+
+ if (!attributes.hasStops()) {
+ const Vector<Gradient::ColorStop>& stops(element->buildStops());
+ if (!stops.isEmpty())
+ attributes.setStops(stops);
+ }
+
+ if (isLinear) {
+ SVGLinearGradientElement* linear = toSVGLinearGradientElement(element);
+
+ if (!attributes.hasX1() && element->hasAttribute(SVGNames::x1Attr))
+ attributes.setX1(linear->x1()->currentValue());
+
+ if (!attributes.hasY1() && element->hasAttribute(SVGNames::y1Attr))
+ attributes.setY1(linear->y1()->currentValue());
+
+ if (!attributes.hasX2() && element->hasAttribute(SVGNames::x2Attr))
+ attributes.setX2(linear->x2()->currentValue());
+
+ if (!attributes.hasY2() && element->hasAttribute(SVGNames::y2Attr))
+ attributes.setY2(linear->y2()->currentValue());
+ }
+}
+
bool SVGLinearGradientElement::selfHasRelativeLengths() const
{
return m_x1->currentValue()->isRelative()

Powered by Google App Engine
This is Rietveld 408576698