OLD | NEW |
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 Loading... |
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(); |
| 79 } |
78 | 80 |
79 return m_path->currentValue()->path(); | 81 return m_path->currentValue()->pathValue()->path(); |
| 82 } |
| 83 |
| 84 const SVGPathByteStream& SVGPathElement::pathByteStream() const |
| 85 { |
| 86 if (layoutObject()) { |
| 87 const SVGComputedStyle& svgStyle = layoutObject()->styleRef().svgStyle()
; |
| 88 return svgStyle.d()->byteStream(); |
| 89 } |
| 90 |
| 91 return m_path->currentValue()->byteStream(); |
80 } | 92 } |
81 | 93 |
82 float SVGPathElement::getTotalLength() | 94 float SVGPathElement::getTotalLength() |
83 { | 95 { |
84 return SVGPathQuery(m_path->currentValue()->byteStream()).getTotalLength(); | 96 document().updateLayoutIgnorePendingStylesheets(); |
| 97 return SVGPathQuery(pathByteStream()).getTotalLength(); |
85 } | 98 } |
86 | 99 |
87 PassRefPtrWillBeRawPtr<SVGPointTearOff> SVGPathElement::getPointAtLength(float l
ength) | 100 PassRefPtrWillBeRawPtr<SVGPointTearOff> SVGPathElement::getPointAtLength(float l
ength) |
88 { | 101 { |
89 FloatPoint point = SVGPathQuery(m_path->currentValue()->byteStream()).getPoi
ntAtLength(length); | 102 document().updateLayoutIgnorePendingStylesheets(); |
| 103 FloatPoint point = SVGPathQuery(pathByteStream()).getPointAtLength(length); |
90 return SVGPointTearOff::create(SVGPoint::create(point), 0, PropertyIsNotAnim
Val); | 104 return SVGPointTearOff::create(SVGPoint::create(point), 0, PropertyIsNotAnim
Val); |
91 } | 105 } |
92 | 106 |
93 unsigned SVGPathElement::getPathSegAtLength(float length) | 107 unsigned SVGPathElement::getPathSegAtLength(float length) |
94 { | 108 { |
95 return SVGPathQuery(m_path->currentValue()->byteStream()).getPathSegIndexAtL
ength(length); | 109 document().updateLayoutIgnorePendingStylesheets(); |
| 110 return SVGPathQuery(pathByteStream()).getPathSegIndexAtLength(length); |
| 111 } |
| 112 |
| 113 bool SVGPathElement::isPresentationAttribute(const QualifiedName& attrName) cons
t |
| 114 { |
| 115 if (attrName == SVGNames::dAttr) |
| 116 return true; |
| 117 return SVGGeometryElement::isPresentationAttribute(attrName); |
| 118 } |
| 119 |
| 120 bool SVGPathElement::isPresentationAttributeWithSVGDOM(const QualifiedName& attr
Name) const |
| 121 { |
| 122 if (attrName == SVGNames::dAttr) |
| 123 return true; |
| 124 return SVGGeometryElement::isPresentationAttributeWithSVGDOM(attrName); |
96 } | 125 } |
97 | 126 |
98 void SVGPathElement::svgAttributeChanged(const QualifiedName& attrName) | 127 void SVGPathElement::svgAttributeChanged(const QualifiedName& attrName) |
99 { | 128 { |
100 if (attrName == SVGNames::dAttr || attrName == SVGNames::pathLengthAttr) { | 129 if (attrName == SVGNames::dAttr) { |
101 SVGElement::InvalidationGuard invalidationGuard(this); | 130 SVGElement::InvalidationGuard invalidationGuard(this); |
| 131 invalidateSVGPresentationAttributeStyle(); |
| 132 setNeedsStyleRecalc(LocalStyleChange, |
| 133 StyleChangeReasonForTracing::fromAttribute(attrName)); |
102 | 134 |
103 LayoutSVGShape* layoutObject = toLayoutSVGShape(this->layoutObject()); | 135 if (LayoutSVGShape* layoutPath = toLayoutSVGShape(this->layoutObject())) |
| 136 layoutPath->setNeedsShapeUpdate(); |
104 | 137 |
105 if (attrName == SVGNames::dAttr) { | 138 invalidateMPathDependencies(); |
106 if (layoutObject) | 139 if (layoutObject()) |
107 layoutObject->setNeedsShapeUpdate(); | 140 markForLayoutAndParentResourceInvalidation(layoutObject()); |
108 | 141 |
109 invalidateMPathDependencies(); | 142 return; |
110 } | 143 } |
111 | 144 |
112 if (layoutObject) | 145 if (attrName == SVGNames::pathLengthAttr) { |
113 markForLayoutAndParentResourceInvalidation(layoutObject); | 146 SVGElement::InvalidationGuard invalidationGuard(this); |
114 | 147 if (layoutObject()) |
| 148 markForLayoutAndParentResourceInvalidation(layoutObject()); |
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()->pathValue()); |
| 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, Node* next) | 183 void SVGPathElement::removedFrom(ContainerNode* rootParent, Node* next) |
141 { | 184 { |
142 SVGGeometryElement::removedFrom(rootParent, next); | 185 SVGGeometryElement::removedFrom(rootParent, next); |
143 invalidateMPathDependencies(); | 186 invalidateMPathDependencies(); |
144 } | 187 } |
145 | 188 |
146 } // namespace blink | 189 } // namespace blink |
OLD | NEW |