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

Side by Side 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 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) 2013 Samsung Electronics. All rights reserved. 2 * Copyright (C) 2013 Samsung Electronics. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 21 matching lines...) Expand all
32 32
33 #include "core/SVGNames.h" 33 #include "core/SVGNames.h"
34 #include "core/layout/HitTestRequest.h" 34 #include "core/layout/HitTestRequest.h"
35 #include "core/layout/PointerEventsHitRules.h" 35 #include "core/layout/PointerEventsHitRules.h"
36 #include "core/layout/svg/LayoutSVGPath.h" 36 #include "core/layout/svg/LayoutSVGPath.h"
37 #include "core/layout/svg/LayoutSVGShape.h" 37 #include "core/layout/svg/LayoutSVGShape.h"
38 #include "core/svg/SVGPointTearOff.h" 38 #include "core/svg/SVGPointTearOff.h"
39 39
40 namespace blink { 40 namespace blink {
41 41
42 class SVGAnimatedPathLength final : public SVGAnimatedNumber {
43 public:
44 static SVGAnimatedPathLength* create(SVGGeometryElement* contextElement) {
45 return new SVGAnimatedPathLength(contextElement);
46 }
47
48 SVGParsingError setBaseValueAsString(const String& value) override {
49 SVGParsingError parseStatus =
50 SVGAnimatedNumber::setBaseValueAsString(value);
51 if (parseStatus == SVGParseStatus::NoError && baseValue()->value() < 0)
52 parseStatus = SVGParseStatus::NegativeValue;
53 return parseStatus;
54 }
55
56 private:
57 explicit SVGAnimatedPathLength(SVGGeometryElement* contextElement)
58 : SVGAnimatedNumber(contextElement,
59 SVGNames::pathLengthAttr,
60 SVGNumber::create()) {}
61 };
62
42 SVGGeometryElement::SVGGeometryElement(const QualifiedName& tagName, 63 SVGGeometryElement::SVGGeometryElement(const QualifiedName& tagName,
43 Document& document, 64 Document& document,
44 ConstructionType constructionType) 65 ConstructionType constructionType)
45 : SVGGraphicsElement(tagName, document, constructionType) {} 66 : SVGGraphicsElement(tagName, document, constructionType),
67 m_pathLength(SVGAnimatedPathLength::create(this)) {
68 addToPropertyMap(m_pathLength);
69 }
70
71 DEFINE_TRACE(SVGGeometryElement) {
72 visitor->trace(m_pathLength);
73 SVGGraphicsElement::trace(visitor);
74 }
46 75
47 bool SVGGeometryElement::isPointInFill(SVGPointTearOff* point) const { 76 bool SVGGeometryElement::isPointInFill(SVGPointTearOff* point) const {
48 document().updateStyleAndLayoutIgnorePendingStylesheets(); 77 document().updateStyleAndLayoutIgnorePendingStylesheets();
49 78
50 // FIXME: Eventually we should support isPointInFill for display:none 79 // FIXME: Eventually we should support isPointInFill for display:none
51 // elements. 80 // elements.
52 if (!layoutObject() || !layoutObject()->isSVGShape()) 81 if (!layoutObject() || !layoutObject()->isSVGShape())
53 return false; 82 return false;
54 83
55 HitTestRequest request(HitTestRequest::ReadOnly); 84 HitTestRequest request(HitTestRequest::ReadOnly);
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 SVGPointTearOff* SVGGeometryElement::getPointAtLength(float length) { 127 SVGPointTearOff* SVGGeometryElement::getPointAtLength(float length) {
99 document().updateStyleAndLayoutIgnorePendingStylesheets(); 128 document().updateStyleAndLayoutIgnorePendingStylesheets();
100 129
101 FloatPoint point; 130 FloatPoint point;
102 if (layoutObject()) 131 if (layoutObject())
103 point = asPath().pointAtLength(length); 132 point = asPath().pointAtLength(length);
104 return SVGPointTearOff::create(SVGPoint::create(point), 0, 133 return SVGPointTearOff::create(SVGPoint::create(point), 0,
105 PropertyIsNotAnimVal); 134 PropertyIsNotAnimVal);
106 } 135 }
107 136
137 float SVGGeometryElement::computePathLength() const {
138 return asPath().length();
139 }
140
141 float SVGGeometryElement::pathLengthScaleFactor() const {
142 if (!pathLength()->isSpecified())
143 return 1;
144 float authorPathLength = pathLength()->currentValue()->value();
145 if (authorPathLength < 0)
146 return 1;
147 if (!authorPathLength)
148 return 0;
149 DCHECK(layoutObject());
150 float computedPathLength = computePathLength();
151 if (!computedPathLength)
152 return 1;
153 return computedPathLength / authorPathLength;
154 }
155
108 LayoutObject* SVGGeometryElement::createLayoutObject(const ComputedStyle&) { 156 LayoutObject* SVGGeometryElement::createLayoutObject(const ComputedStyle&) {
109 // By default, any subclass is expected to do path-based drawing. 157 // By default, any subclass is expected to do path-based drawing.
110 return new LayoutSVGPath(this); 158 return new LayoutSVGPath(this);
111 } 159 }
112 160
113 } // namespace blink 161 } // namespace blink
OLDNEW
« 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