Chromium Code Reviews| 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..27a91a3855bee62093dc44a05778f5a3fa599358 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,26 @@ 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; |
| + if (!layoutObject()) |
|
fs
2016/11/28 12:42:47
Nit: DCHECK
Shanmuga Pandi
2016/11/28 14:16:13
Done.
|
| + return 1; |
| + 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); |