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

Unified Diff: third_party/WebKit/Source/core/svg/SVGGeometryElement.cpp

Issue 2525233002: Move pathLength attribute from SVGPathElement to SVGGeometryElement. (Closed)
Patch Set: Align with review comments Created 4 years, 1 month 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: 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);
« no previous file with comments | « third_party/WebKit/Source/core/svg/SVGGeometryElement.h ('k') | third_party/WebKit/Source/core/svg/SVGGeometryElement.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698