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

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

Issue 1439793003: SVG: Promote d to a property (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: CSSPropertyParser Created 5 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,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details. 13 * Library General Public License for more details.
14 * 14 *
15 * You should have received a copy of the GNU Library General Public License 15 * You should have received a copy of the GNU Library General Public License
16 * along with this library; see the file COPYING.LIB. If not, write to 16 * along with this library; see the file COPYING.LIB. If not, write to
17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA. 18 * Boston, MA 02110-1301, USA.
19 */ 19 */
20 20
21 #include "config.h" 21 #include "config.h"
22 #include "core/svg/SVGPathElement.h" 22 #include "core/svg/SVGPathElement.h"
23 23
24 #include "core/dom/NodeComputedStyle.h"
24 #include "core/layout/svg/LayoutSVGPath.h" 25 #include "core/layout/svg/LayoutSVGPath.h"
25 #include "core/svg/SVGDocumentExtensions.h" 26 #include "core/svg/SVGDocumentExtensions.h"
26 #include "core/svg/SVGMPathElement.h" 27 #include "core/svg/SVGMPathElement.h"
27 #include "core/svg/SVGPathQuery.h" 28 #include "core/svg/SVGPathQuery.h"
29 #include "core/svg/SVGPathUtilities.h"
28 #include "core/svg/SVGPointTearOff.h" 30 #include "core/svg/SVGPointTearOff.h"
29 31
30 namespace blink { 32 namespace blink {
31 33
32 class SVGAnimatedPathLength final : public SVGAnimatedNumber { 34 class SVGAnimatedPathLength final : public SVGAnimatedNumber {
33 public: 35 public:
34 static PassRefPtrWillBeRawPtr<SVGAnimatedPathLength> create(SVGPathElement* contextElement) 36 static PassRefPtrWillBeRawPtr<SVGAnimatedPathLength> create(SVGPathElement* contextElement)
35 { 37 {
36 return adoptRefWillBeNoop(new SVGAnimatedPathLength(contextElement)); 38 return adoptRefWillBeNoop(new SVGAnimatedPathLength(contextElement));
37 } 39 }
(...skipping 27 matching lines...) Expand all
65 { 67 {
66 visitor->trace(m_pathLength); 68 visitor->trace(m_pathLength);
67 visitor->trace(m_path); 69 visitor->trace(m_path);
68 SVGGeometryElement::trace(visitor); 70 SVGGeometryElement::trace(visitor);
69 } 71 }
70 72
71 DEFINE_NODE_FACTORY(SVGPathElement) 73 DEFINE_NODE_FACTORY(SVGPathElement)
72 74
73 Path SVGPathElement::asPath() const 75 Path SVGPathElement::asPath() const
74 { 76 {
75 // If this is a <use> instance, return the referenced path to maximize geome try sharing. 77 Path path;
76 if (const SVGElement* element = correspondingElement()) 78 buildPathFromByteStream(pathByteStream(), path);
77 return toSVGPathElement(element)->asPath(); 79 return path;
80 }
78 81
79 return m_path->currentValue()->path(); 82 const SVGPathByteStream& SVGPathElement::pathByteStream() const
83 {
84 if (const ComputedStyle* style = static_cast<const Element*>(this)->computed Style()) {
fs 2015/11/26 12:51:40 Per below, this code should probably move to asPat
Eric Willigers 2015/12/10 23:52:52 A complication with the old correspondingElement()
fs 2015/12/11 13:01:58 I think it would still be beneficial (and equivale
85 const SVGComputedStyle& svgStyle = style->svgStyle();
86 if (svgStyle.d())
87 return *svgStyle.d();
88 }
89
90 return m_path->currentValue()->byteStream();
fs 2015/11/26 12:51:40 Should only be using SVGComputedStyle here. No acc
80 } 91 }
81 92
82 float SVGPathElement::getTotalLength() 93 float SVGPathElement::getTotalLength()
83 { 94 {
95 static_cast<Element*>(this)->ensureComputedStyle();
fs 2015/11/26 12:51:40 I don't think these methods should need to care ab
pdr. 2015/12/02 05:36:50 I'm not quite sure what you mean about the compute
84 return SVGPathQuery(pathByteStream()).getTotalLength(); 96 return SVGPathQuery(pathByteStream()).getTotalLength();
85 } 97 }
86 98
87 PassRefPtrWillBeRawPtr<SVGPointTearOff> SVGPathElement::getPointAtLength(float l ength) 99 PassRefPtrWillBeRawPtr<SVGPointTearOff> SVGPathElement::getPointAtLength(float l ength)
88 { 100 {
101 static_cast<Element*>(this)->ensureComputedStyle();
89 FloatPoint point = SVGPathQuery(pathByteStream()).getPointAtLength(length); 102 FloatPoint point = SVGPathQuery(pathByteStream()).getPointAtLength(length);
90 return SVGPointTearOff::create(SVGPoint::create(point), 0, PropertyIsNotAnim Val); 103 return SVGPointTearOff::create(SVGPoint::create(point), 0, PropertyIsNotAnim Val);
91 } 104 }
92 105
93 unsigned SVGPathElement::getPathSegAtLength(float length) 106 unsigned SVGPathElement::getPathSegAtLength(float length)
94 { 107 {
108 static_cast<Element*>(this)->ensureComputedStyle();
95 return SVGPathQuery(pathByteStream()).getPathSegIndexAtLength(length); 109 return SVGPathQuery(pathByteStream()).getPathSegIndexAtLength(length);
96 } 110 }
97 111
112 bool SVGPathElement::isPresentationAttribute(const QualifiedName& attrName) cons t
113 {
114 if (attrName == SVGNames::dAttr)
115 return true;
116 return SVGGeometryElement::isPresentationAttribute(attrName);
117 }
118
119 bool SVGPathElement::isPresentationAttributeWithSVGDOM(const QualifiedName& attr Name) const
120 {
121 if (attrName == SVGNames::dAttr)
122 return true;
123 return SVGGeometryElement::isPresentationAttributeWithSVGDOM(attrName);
124 }
125
98 void SVGPathElement::svgAttributeChanged(const QualifiedName& attrName) 126 void SVGPathElement::svgAttributeChanged(const QualifiedName& attrName)
99 { 127 {
128 if (attrName == SVGNames::dAttr) {
129 SVGElement::InvalidationGuard invalidationGuard(this);
130 invalidateSVGPresentationAttributeStyle();
131 setNeedsStyleRecalc(LocalStyleChange,
132 StyleChangeReasonForTracing::fromAttribute(attrName));
133
134 if (LayoutSVGShape* layoutPath = toLayoutSVGShape(this->layoutObject()))
135 layoutPath->setNeedsShapeUpdate();
136
137 invalidateMPathDependencies();
138
139 if (layoutObject())
140 markForLayoutAndParentResourceInvalidation(layoutObject());
fs 2015/11/26 12:51:40 Missing InvalidationGuard - or drop this and don't
Eric Willigers 2015/12/10 23:52:52 InvalidationGuard is at line 129.
fs 2015/12/11 13:01:58 *goes to check eyesight*
141
142 return;
143 }
144
100 if (attrName == SVGNames::dAttr || attrName == SVGNames::pathLengthAttr) { 145 if (attrName == SVGNames::dAttr || attrName == SVGNames::pathLengthAttr) {
fs 2015/11/26 12:51:40 Checking for dAttr here is "dead", but depends on
Eric Willigers 2015/12/10 23:52:52 Acknowledged.
101 SVGElement::InvalidationGuard invalidationGuard(this); 146 SVGElement::InvalidationGuard invalidationGuard(this);
102 147 if (layoutObject())
103 LayoutSVGShape* layoutObject = toLayoutSVGShape(this->layoutObject()); 148 markForLayoutAndParentResourceInvalidation(layoutObject());
104
105 if (attrName == SVGNames::dAttr) {
106 if (layoutObject)
107 layoutObject->setNeedsShapeUpdate();
108
109 invalidateMPathDependencies();
110 }
111
112 if (layoutObject)
113 markForLayoutAndParentResourceInvalidation(layoutObject);
114
115 return; 149 return;
116 } 150 }
117 151
118 SVGGeometryElement::svgAttributeChanged(attrName); 152 SVGGeometryElement::svgAttributeChanged(attrName);
119 } 153 }
120 154
155 void SVGPathElement::collectStyleForPresentationAttribute(const QualifiedName& n ame, const AtomicString& value, MutableStylePropertySet* style)
156 {
157 RefPtrWillBeRawPtr<SVGAnimatedPropertyBase> property = propertyFromAttribute (name);
158 if (property == m_path)
159 addPropertyToPresentationAttributeStyle(style, CSSPropertyD, m_path->cur rentValue()->valueAsString());
fs 2015/11/26 12:51:40 This will make for a fairly inefficient round-trip
Eric Willigers 2015/12/10 23:52:52 Changed to use CSSPathValue
160 else
161 SVGGeometryElement::collectStyleForPresentationAttribute(name, value, st yle);
162 }
163
121 void SVGPathElement::invalidateMPathDependencies() 164 void SVGPathElement::invalidateMPathDependencies()
122 { 165 {
123 // <mpath> can only reference <path> but this dependency is not handled in 166 // <mpath> can only reference <path> but this dependency is not handled in
124 // markForLayoutAndParentResourceInvalidation so we update any mpath depende ncies manually. 167 // markForLayoutAndParentResourceInvalidation so we update any mpath depende ncies manually.
125 if (SVGElementSet* dependencies = setOfIncomingReferences()) { 168 if (SVGElementSet* dependencies = setOfIncomingReferences()) {
126 for (SVGElement* element : *dependencies) { 169 for (SVGElement* element : *dependencies) {
127 if (isSVGMPathElement(*element)) 170 if (isSVGMPathElement(*element))
128 toSVGMPathElement(element)->targetPathChanged(); 171 toSVGMPathElement(element)->targetPathChanged();
129 } 172 }
130 } 173 }
131 } 174 }
132 175
133 Node::InsertionNotificationRequest SVGPathElement::insertedInto(ContainerNode* r ootParent) 176 Node::InsertionNotificationRequest SVGPathElement::insertedInto(ContainerNode* r ootParent)
134 { 177 {
135 SVGGeometryElement::insertedInto(rootParent); 178 SVGGeometryElement::insertedInto(rootParent);
136 invalidateMPathDependencies(); 179 invalidateMPathDependencies();
137 return InsertionDone; 180 return InsertionDone;
138 } 181 }
139 182
140 void SVGPathElement::removedFrom(ContainerNode* rootParent) 183 void SVGPathElement::removedFrom(ContainerNode* rootParent)
141 { 184 {
142 SVGGeometryElement::removedFrom(rootParent); 185 SVGGeometryElement::removedFrom(rootParent);
143 invalidateMPathDependencies(); 186 invalidateMPathDependencies();
144 } 187 }
145 188
146 } // namespace blink 189 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698