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

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: parser 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/layout/svg/LayoutSVGPath.h" 24 #include "core/layout/svg/LayoutSVGPath.h"
25 #include "core/svg/SVGDocumentExtensions.h" 25 #include "core/svg/SVGDocumentExtensions.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/SVGPointTearOff.h" 29 #include "core/svg/SVGPointTearOff.h"
29 30
30 namespace blink { 31 namespace blink {
31 32
32 class SVGAnimatedPathLength final : public SVGAnimatedNumber { 33 class SVGAnimatedPathLength final : public SVGAnimatedNumber {
33 public: 34 public:
34 static PassRefPtrWillBeRawPtr<SVGAnimatedPathLength> create(SVGPathElement* contextElement) 35 static PassRefPtrWillBeRawPtr<SVGAnimatedPathLength> create(SVGPathElement* contextElement)
35 { 36 {
36 return adoptRefWillBeNoop(new SVGAnimatedPathLength(contextElement)); 37 return adoptRefWillBeNoop(new SVGAnimatedPathLength(contextElement));
37 } 38 }
(...skipping 27 matching lines...) Expand all
65 { 66 {
66 visitor->trace(m_pathLength); 67 visitor->trace(m_pathLength);
67 visitor->trace(m_path); 68 visitor->trace(m_path);
68 SVGGeometryElement::trace(visitor); 69 SVGGeometryElement::trace(visitor);
69 } 70 }
70 71
71 DEFINE_NODE_FACTORY(SVGPathElement) 72 DEFINE_NODE_FACTORY(SVGPathElement)
72 73
73 Path SVGPathElement::asPath() const 74 Path SVGPathElement::asPath() const
74 { 75 {
75 // If this is a <use> instance, return the referenced path to maximize geome try sharing. 76 if (layoutObject()) {
76 if (const SVGElement* element = correspondingElement()) 77 const SVGComputedStyle& svgStyle = layoutObject()->styleRef().svgStyle() ;
77 return toSVGPathElement(element)->asPath(); 78 return svgStyle.d()->path();
78 79
fs 2015/12/14 11:51:40 Nit: Remove blank line.
Eric Willigers 2015/12/14 22:18:23 Done.
79 return m_path->currentValue()->path(); 80 }
81
82 return m_path->currentValue()->pathValue()->path();
83 }
84
85 const SVGPathByteStream& SVGPathElement::pathByteStream() const
86 {
87 if (layoutObject()) {
88 const SVGComputedStyle& svgStyle = layoutObject()->styleRef().svgStyle() ;
89 return svgStyle.d()->byteStream();
90
fs 2015/12/14 11:51:40 Ditto.
Eric Willigers 2015/12/14 22:18:23 Done.
91 }
92
93 return m_path->currentValue()->byteStream();
80 } 94 }
81 95
82 float SVGPathElement::getTotalLength() 96 float SVGPathElement::getTotalLength()
83 { 97 {
84 return SVGPathQuery(m_path->currentValue()->byteStream()).getTotalLength(); 98 document().updateLayoutIgnorePendingStylesheets();
99 return SVGPathQuery(pathByteStream()).getTotalLength();
85 } 100 }
86 101
87 PassRefPtrWillBeRawPtr<SVGPointTearOff> SVGPathElement::getPointAtLength(float l ength) 102 PassRefPtrWillBeRawPtr<SVGPointTearOff> SVGPathElement::getPointAtLength(float l ength)
88 { 103 {
89 FloatPoint point = SVGPathQuery(m_path->currentValue()->byteStream()).getPoi ntAtLength(length); 104 document().updateLayoutIgnorePendingStylesheets();
105 FloatPoint point = SVGPathQuery(pathByteStream()).getPointAtLength(length);
90 return SVGPointTearOff::create(SVGPoint::create(point), 0, PropertyIsNotAnim Val); 106 return SVGPointTearOff::create(SVGPoint::create(point), 0, PropertyIsNotAnim Val);
91 } 107 }
92 108
93 unsigned SVGPathElement::getPathSegAtLength(float length) 109 unsigned SVGPathElement::getPathSegAtLength(float length)
94 { 110 {
95 return SVGPathQuery(m_path->currentValue()->byteStream()).getPathSegIndexAtL ength(length); 111 document().updateLayoutIgnorePendingStylesheets();
112 return SVGPathQuery(pathByteStream()).getPathSegIndexAtLength(length);
113 }
114
115 bool SVGPathElement::isPresentationAttribute(const QualifiedName& attrName) cons t
116 {
117 if (attrName == SVGNames::dAttr)
118 return true;
119 return SVGGeometryElement::isPresentationAttribute(attrName);
120 }
121
122 bool SVGPathElement::isPresentationAttributeWithSVGDOM(const QualifiedName& attr Name) const
123 {
124 if (attrName == SVGNames::dAttr)
125 return true;
126 return SVGGeometryElement::isPresentationAttributeWithSVGDOM(attrName);
96 } 127 }
97 128
98 void SVGPathElement::svgAttributeChanged(const QualifiedName& attrName) 129 void SVGPathElement::svgAttributeChanged(const QualifiedName& attrName)
99 { 130 {
100 if (attrName == SVGNames::dAttr || attrName == SVGNames::pathLengthAttr) { 131 if (attrName == SVGNames::dAttr) {
101 SVGElement::InvalidationGuard invalidationGuard(this); 132 SVGElement::InvalidationGuard invalidationGuard(this);
133 invalidateSVGPresentationAttributeStyle();
134 setNeedsStyleRecalc(LocalStyleChange,
135 StyleChangeReasonForTracing::fromAttribute(attrName));
102 136
103 LayoutSVGShape* layoutObject = toLayoutSVGShape(this->layoutObject()); 137 if (LayoutSVGShape* layoutPath = toLayoutSVGShape(this->layoutObject()))
138 layoutPath->setNeedsShapeUpdate();
104 139
105 if (attrName == SVGNames::dAttr) { 140 invalidateMPathDependencies();
106 if (layoutObject) 141 if (layoutObject())
107 layoutObject->setNeedsShapeUpdate(); 142 markForLayoutAndParentResourceInvalidation(layoutObject());
108 143
109 invalidateMPathDependencies(); 144 return;
110 } 145 }
111 146
112 if (layoutObject) 147 if (attrName == SVGNames::pathLengthAttr) {
113 markForLayoutAndParentResourceInvalidation(layoutObject); 148 SVGElement::InvalidationGuard invalidationGuard(this);
114 149 if (layoutObject())
150 markForLayoutAndParentResourceInvalidation(layoutObject());
115 return; 151 return;
116 } 152 }
117 153
118 SVGGeometryElement::svgAttributeChanged(attrName); 154 SVGGeometryElement::svgAttributeChanged(attrName);
119 } 155 }
120 156
157 void SVGPathElement::collectStyleForPresentationAttribute(const QualifiedName& n ame, const AtomicString& value, MutableStylePropertySet* style)
158 {
159 RefPtrWillBeRawPtr<SVGAnimatedPropertyBase> property = propertyFromAttribute (name);
160 if (property == m_path)
161 addPropertyToPresentationAttributeStyle(style, CSSPropertyD, m_path->cur rentValue()->pathValue());
162 else
163 SVGGeometryElement::collectStyleForPresentationAttribute(name, value, st yle);
164 }
165
121 void SVGPathElement::invalidateMPathDependencies() 166 void SVGPathElement::invalidateMPathDependencies()
122 { 167 {
123 // <mpath> can only reference <path> but this dependency is not handled in 168 // <mpath> can only reference <path> but this dependency is not handled in
124 // markForLayoutAndParentResourceInvalidation so we update any mpath depende ncies manually. 169 // markForLayoutAndParentResourceInvalidation so we update any mpath depende ncies manually.
125 if (SVGElementSet* dependencies = setOfIncomingReferences()) { 170 if (SVGElementSet* dependencies = setOfIncomingReferences()) {
126 for (SVGElement* element : *dependencies) { 171 for (SVGElement* element : *dependencies) {
127 if (isSVGMPathElement(*element)) 172 if (isSVGMPathElement(*element))
128 toSVGMPathElement(element)->targetPathChanged(); 173 toSVGMPathElement(element)->targetPathChanged();
129 } 174 }
130 } 175 }
131 } 176 }
132 177
133 Node::InsertionNotificationRequest SVGPathElement::insertedInto(ContainerNode* r ootParent) 178 Node::InsertionNotificationRequest SVGPathElement::insertedInto(ContainerNode* r ootParent)
134 { 179 {
135 SVGGeometryElement::insertedInto(rootParent); 180 SVGGeometryElement::insertedInto(rootParent);
136 invalidateMPathDependencies(); 181 invalidateMPathDependencies();
137 return InsertionDone; 182 return InsertionDone;
138 } 183 }
139 184
140 void SVGPathElement::removedFrom(ContainerNode* rootParent, Node* next) 185 void SVGPathElement::removedFrom(ContainerNode* rootParent, Node* next)
141 { 186 {
142 SVGGeometryElement::removedFrom(rootParent, next); 187 SVGGeometryElement::removedFrom(rootParent, next);
143 invalidateMPathDependencies(); 188 invalidateMPathDependencies();
144 } 189 }
145 190
146 } // namespace blink 191 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698