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

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::pathLengthScaleFactor() const {
138 if (!pathLength()->isSpecified())
139 return 1;
140 float authorPathLength = pathLength()->currentValue()->value();
141 if (authorPathLength < 0)
142 return 1;
143 if (!authorPathLength)
144 return 0;
145 if (!layoutObject())
fs 2016/11/28 10:29:42 I think you could DCHECK this instead. But I think
Shanmuga Pandi 2016/11/28 12:24:14 Done.
146 return 1;
147 float computedPathLength = asPath().length();
fs 2016/11/28 10:29:42 Optionally, pathLengthScaleFactor could be non-vir
Shanmuga Pandi 2016/11/28 12:24:14 Done.
148 if (!computedPathLength)
149 return 1;
150 return computedPathLength / authorPathLength;
151 }
152
108 LayoutObject* SVGGeometryElement::createLayoutObject(const ComputedStyle&) { 153 LayoutObject* SVGGeometryElement::createLayoutObject(const ComputedStyle&) {
109 // By default, any subclass is expected to do path-based drawing. 154 // By default, any subclass is expected to do path-based drawing.
110 return new LayoutSVGPath(this); 155 return new LayoutSVGPath(this);
111 } 156 }
112 157
113 } // namespace blink 158 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698