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

Side by Side Diff: third_party/WebKit/Source/core/svg/SVGPathElement.cpp

Issue 2525233002: Move pathLength attribute from SVGPathElement to SVGGeometryElement. (Closed)
Patch Set: Align with review comments Created 4 years 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2004, 2005, 2006, 2008 Nikolas Zimmermann <zimmermann@kde.org> 2 * Copyright (C) 2004, 2005, 2006, 2008 Nikolas Zimmermann <zimmermann@kde.org>
3 * Copyright (C) 2004, 2005, 2006, 2007 Rob Buis <buis@kde.org> 3 * Copyright (C) 2004, 2005, 2006, 2007 Rob Buis <buis@kde.org>
4 * 4 *
5 * This library is free software; you can redistribute it and/or 5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public 6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either 7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version. 8 * version 2 of the License, or (at your option) any later version.
9 * 9 *
10 * This library is distributed in the hope that it will be useful, 10 * This library is distributed in the hope that it will be useful,
(...skipping 12 matching lines...) Expand all
23 #include "core/css/CSSIdentifierValue.h" 23 #include "core/css/CSSIdentifierValue.h"
24 #include "core/dom/StyleChangeReason.h" 24 #include "core/dom/StyleChangeReason.h"
25 #include "core/layout/svg/LayoutSVGPath.h" 25 #include "core/layout/svg/LayoutSVGPath.h"
26 #include "core/svg/SVGMPathElement.h" 26 #include "core/svg/SVGMPathElement.h"
27 #include "core/svg/SVGPathQuery.h" 27 #include "core/svg/SVGPathQuery.h"
28 #include "core/svg/SVGPathUtilities.h" 28 #include "core/svg/SVGPathUtilities.h"
29 #include "core/svg/SVGPointTearOff.h" 29 #include "core/svg/SVGPointTearOff.h"
30 30
31 namespace blink { 31 namespace blink {
32 32
33 class SVGAnimatedPathLength final : public SVGAnimatedNumber {
34 public:
35 static SVGAnimatedPathLength* create(SVGPathElement* contextElement) {
36 return new SVGAnimatedPathLength(contextElement);
37 }
38
39 SVGParsingError setBaseValueAsString(const String& value) override {
40 SVGParsingError parseStatus =
41 SVGAnimatedNumber::setBaseValueAsString(value);
42 if (parseStatus == SVGParseStatus::NoError && baseValue()->value() < 0)
43 parseStatus = SVGParseStatus::NegativeValue;
44 return parseStatus;
45 }
46
47 private:
48 explicit SVGAnimatedPathLength(SVGPathElement* contextElement)
49 : SVGAnimatedNumber(contextElement,
50 SVGNames::pathLengthAttr,
51 SVGNumber::create()) {}
52 };
53
54 inline SVGPathElement::SVGPathElement(Document& document) 33 inline SVGPathElement::SVGPathElement(Document& document)
55 : SVGGeometryElement(SVGNames::pathTag, document), 34 : SVGGeometryElement(SVGNames::pathTag, document),
56 m_pathLength(SVGAnimatedPathLength::create(this)),
57 m_path(SVGAnimatedPath::create(this, SVGNames::dAttr, CSSPropertyD)) { 35 m_path(SVGAnimatedPath::create(this, SVGNames::dAttr, CSSPropertyD)) {
58 addToPropertyMap(m_pathLength);
59 addToPropertyMap(m_path); 36 addToPropertyMap(m_path);
60 } 37 }
61 38
62 DEFINE_TRACE(SVGPathElement) { 39 DEFINE_TRACE(SVGPathElement) {
63 visitor->trace(m_pathLength);
64 visitor->trace(m_path); 40 visitor->trace(m_path);
65 SVGGeometryElement::trace(visitor); 41 SVGGeometryElement::trace(visitor);
66 } 42 }
67 43
68 DEFINE_NODE_FACTORY(SVGPathElement) 44 DEFINE_NODE_FACTORY(SVGPathElement)
69 45
70 Path SVGPathElement::attributePath() const { 46 Path SVGPathElement::attributePath() const {
71 return m_path->currentValue()->stylePath()->path(); 47 return m_path->currentValue()->stylePath()->path();
72 } 48 }
73 49
74 const StylePath* SVGPathElement::stylePath() const { 50 const StylePath* SVGPathElement::stylePath() const {
75 if (LayoutObject* layoutObject = this->layoutObject()) { 51 if (LayoutObject* layoutObject = this->layoutObject()) {
76 const StylePath* stylePath = layoutObject->styleRef().svgStyle().d(); 52 const StylePath* stylePath = layoutObject->styleRef().svgStyle().d();
77 if (stylePath) 53 if (stylePath)
78 return stylePath; 54 return stylePath;
79 return StylePath::emptyPath(); 55 return StylePath::emptyPath();
80 } 56 }
81 return m_path->currentValue()->stylePath(); 57 return m_path->currentValue()->stylePath();
82 } 58 }
83 59
84 float SVGPathElement::pathLengthScaleFactor() const { 60 float SVGPathElement::computePathLength() const {
85 if (!pathLength()->isSpecified()) 61 return stylePath()->length();
86 return 1;
87 float authorPathLength = pathLength()->currentValue()->value();
88 if (authorPathLength < 0)
89 return 1;
90 if (!authorPathLength)
91 return 0;
92 float computedPathLength = stylePath()->length();
93 if (!computedPathLength)
94 return 1;
95 return computedPathLength / authorPathLength;
96 } 62 }
97 63
98 Path SVGPathElement::asPath() const { 64 Path SVGPathElement::asPath() const {
99 return stylePath()->path(); 65 return stylePath()->path();
100 } 66 }
101 67
102 float SVGPathElement::getTotalLength() { 68 float SVGPathElement::getTotalLength() {
103 document().updateStyleAndLayoutIgnorePendingStylesheets(); 69 document().updateStyleAndLayoutIgnorePendingStylesheets();
104 return SVGPathQuery(pathByteStream()).getTotalLength(); 70 return SVGPathQuery(pathByteStream()).getTotalLength();
105 } 71 }
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 } 158 }
193 159
194 FloatRect SVGPathElement::getBBox() { 160 FloatRect SVGPathElement::getBBox() {
195 document().updateStyleAndLayoutIgnorePendingStylesheets(); 161 document().updateStyleAndLayoutIgnorePendingStylesheets();
196 162
197 // We want the exact bounds. 163 // We want the exact bounds.
198 return SVGPathElement::asPath().boundingRect(Path::BoundsType::Exact); 164 return SVGPathElement::asPath().boundingRect(Path::BoundsType::Exact);
199 } 165 }
200 166
201 } // namespace blink 167 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/svg/SVGPathElement.h ('k') | third_party/WebKit/Source/core/svg/SVGPathElement.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698