Index: third_party/WebKit/Source/core/svg/SVGGeometryElement.cpp |
diff --git a/third_party/WebKit/Source/core/svg/SVGGeometryElement.cpp b/third_party/WebKit/Source/core/svg/SVGGeometryElement.cpp |
index 993675de9cf557c2e3ecbdf056578fe7ce6e8438..ebe12ac15b3c3d30d69d5e033b2665543bea0f1f 100644 |
--- a/third_party/WebKit/Source/core/svg/SVGGeometryElement.cpp |
+++ b/third_party/WebKit/Source/core/svg/SVGGeometryElement.cpp |
@@ -39,10 +39,39 @@ |
namespace blink { |
+class SVGAnimatedPathLength final : public SVGAnimatedNumber { |
+ public: |
+ static SVGAnimatedPathLength* create(SVGGeometryElement* contextElement) { |
+ return new SVGAnimatedPathLength(contextElement); |
+ } |
+ |
+ SVGParsingError setBaseValueAsString(const String& value) override { |
+ SVGParsingError parseStatus = |
+ SVGAnimatedNumber::setBaseValueAsString(value); |
+ if (parseStatus == SVGParseStatus::NoError && baseValue()->value() < 0) |
+ parseStatus = SVGParseStatus::NegativeValue; |
+ return parseStatus; |
+ } |
+ |
+ private: |
+ explicit SVGAnimatedPathLength(SVGGeometryElement* contextElement) |
+ : SVGAnimatedNumber(contextElement, |
+ SVGNames::pathLengthAttr, |
+ SVGNumber::create()) {} |
+}; |
+ |
SVGGeometryElement::SVGGeometryElement(const QualifiedName& tagName, |
Document& document, |
ConstructionType constructionType) |
- : SVGGraphicsElement(tagName, document, constructionType) {} |
+ : SVGGraphicsElement(tagName, document, constructionType), |
+ m_pathLength(SVGAnimatedPathLength::create(this)) { |
+ addToPropertyMap(m_pathLength); |
+} |
+ |
+DEFINE_TRACE(SVGGeometryElement) { |
+ visitor->trace(m_pathLength); |
+ SVGGraphicsElement::trace(visitor); |
+} |
bool SVGGeometryElement::isPointInFill(SVGPointTearOff* point) const { |
document().updateStyleAndLayoutIgnorePendingStylesheets(); |
@@ -105,6 +134,25 @@ SVGPointTearOff* SVGGeometryElement::getPointAtLength(float length) { |
PropertyIsNotAnimVal); |
} |
+float SVGGeometryElement::computePathLength() const { |
+ return asPath().length(); |
+} |
+ |
+float SVGGeometryElement::pathLengthScaleFactor() const { |
+ if (!pathLength()->isSpecified()) |
+ return 1; |
+ float authorPathLength = pathLength()->currentValue()->value(); |
+ if (authorPathLength < 0) |
+ return 1; |
+ if (!authorPathLength) |
+ return 0; |
+ DCHECK(layoutObject()); |
+ float computedPathLength = computePathLength(); |
+ if (!computedPathLength) |
+ return 1; |
+ return computedPathLength / authorPathLength; |
+} |
+ |
LayoutObject* SVGGeometryElement::createLayoutObject(const ComputedStyle&) { |
// By default, any subclass is expected to do path-based drawing. |
return new LayoutSVGPath(this); |