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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/Source/core/svg/SVGLinearGradientElement.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/core/svg/SVGRadialGradientElement.cpp
diff --git a/third_party/WebKit/Source/core/svg/SVGRadialGradientElement.cpp b/third_party/WebKit/Source/core/svg/SVGRadialGradientElement.cpp
index b368ba24543eb067e99c6d5e7e7bcdb3ac4659bb..dfafb570089a13bf15101c70a4f23869e1ad9701 100644
--- a/third_party/WebKit/Source/core/svg/SVGRadialGradientElement.cpp
+++ b/third_party/WebKit/Source/core/svg/SVGRadialGradientElement.cpp
@@ -103,83 +103,51 @@ LayoutObject* SVGRadialGradientElement::createLayoutObject(
return new LayoutSVGResourceRadialGradient(this);
}
-static void setGradientAttributes(SVGGradientElement* element,
+static void setGradientAttributes(const SVGGradientElement& element,
RadialGradientAttributes& attributes,
- bool isRadial = true) {
- if (!attributes.hasSpreadMethod() && element->spreadMethod()->isSpecified())
- attributes.setSpreadMethod(
- element->spreadMethod()->currentValue()->enumValue());
-
- if (!attributes.hasGradientUnits() && element->gradientUnits()->isSpecified())
- attributes.setGradientUnits(
- element->gradientUnits()->currentValue()->enumValue());
-
- if (!attributes.hasGradientTransform() &&
- element->hasTransform(SVGElement::ExcludeMotionTransform)) {
- attributes.setGradientTransform(
- element->calculateTransform(SVGElement::ExcludeMotionTransform));
- }
-
- if (!attributes.hasStops()) {
- const Vector<Gradient::ColorStop>& stops(element->buildStops());
- if (!stops.isEmpty())
- attributes.setStops(stops);
- }
+ bool isRadial) {
+ element.collectCommonAttributes(attributes);
- if (isRadial) {
- SVGRadialGradientElement* radial = toSVGRadialGradientElement(element);
+ if (!isRadial)
+ return;
+ const SVGRadialGradientElement& radial = toSVGRadialGradientElement(element);
- if (!attributes.hasCx() && radial->cx()->isSpecified())
- attributes.setCx(radial->cx()->currentValue());
+ if (!attributes.hasCx() && radial.cx()->isSpecified())
+ attributes.setCx(radial.cx()->currentValue());
- if (!attributes.hasCy() && radial->cy()->isSpecified())
- attributes.setCy(radial->cy()->currentValue());
+ if (!attributes.hasCy() && radial.cy()->isSpecified())
+ attributes.setCy(radial.cy()->currentValue());
- if (!attributes.hasR() && radial->r()->isSpecified())
- attributes.setR(radial->r()->currentValue());
+ if (!attributes.hasR() && radial.r()->isSpecified())
+ attributes.setR(radial.r()->currentValue());
- if (!attributes.hasFx() && radial->fx()->isSpecified())
- attributes.setFx(radial->fx()->currentValue());
+ if (!attributes.hasFx() && radial.fx()->isSpecified())
+ attributes.setFx(radial.fx()->currentValue());
- if (!attributes.hasFy() && radial->fy()->isSpecified())
- attributes.setFy(radial->fy()->currentValue());
+ if (!attributes.hasFy() && radial.fy()->isSpecified())
+ attributes.setFy(radial.fy()->currentValue());
- if (!attributes.hasFr() && radial->fr()->isSpecified())
- attributes.setFr(radial->fr()->currentValue());
- }
+ if (!attributes.hasFr() && radial.fr()->isSpecified())
+ attributes.setFr(radial.fr()->currentValue());
}
bool SVGRadialGradientElement::collectGradientAttributes(
RadialGradientAttributes& attributes) {
- if (!layoutObject())
- return false;
-
- HeapHashSet<Member<SVGGradientElement>> processedGradients;
- SVGGradientElement* current = this;
+ DCHECK(layoutObject());
- setGradientAttributes(current, attributes);
- processedGradients.insert(current);
+ VisitedSet visited;
+ const SVGGradientElement* current = this;
while (true) {
- // Respect xlink:href, take attributes from referenced element
- Node* refNode = SVGURIReference::targetElementFromIRIString(
- current->href()->currentValue()->value(), treeScope());
- if (refNode && isSVGGradientElement(*refNode)) {
- current = toSVGGradientElement(refNode);
-
- // Cycle detection
- if (processedGradients.contains(current))
- break;
-
- if (!current->layoutObject())
- return false;
-
- setGradientAttributes(current, attributes,
- isSVGRadialGradientElement(*current));
- processedGradients.insert(current);
- } else {
+ setGradientAttributes(*current, attributes,
+ isSVGRadialGradientElement(*current));
+ visited.insert(current);
+
+ current = current->referencedElement();
+ if (!current || visited.contains(current))
break;
- }
+ if (!current->layoutObject())
+ return false;
}
// Handle default values for fx/fy
« 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