1 | /* |
2 | * Copyright (C) 2018-2019 Apple Inc. All rights reserved. |
3 | * |
4 | * Redistribution and use in source and binary forms, with or without |
5 | * modification, are permitted provided that the following conditions |
6 | * are met: |
7 | * 1. Redistributions of source code must retain the above copyright |
8 | * notice, this list of conditions and the following disclaimer. |
9 | * 2. Redistributions in binary form must reproduce the above copyright |
10 | * notice, this list of conditions and the following disclaimer in the |
11 | * documentation and/or other materials provided with the distribution. |
12 | * |
13 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY |
14 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
15 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR |
17 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
18 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
19 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
20 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
21 | * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
24 | */ |
25 | |
26 | #pragma once |
27 | |
28 | #include "SVGAnimatedPropertyAnimator.h" |
29 | #include "SVGAnimatedPropertyImpl.h" |
30 | #include "SVGAnimationAdditiveListFunctionImpl.h" |
31 | #include "SVGAnimationAdditiveValueFunctionImpl.h" |
32 | #include "SVGAnimationDiscreteFunctionImpl.h" |
33 | |
34 | namespace WebCore { |
35 | |
36 | class SVGAnimatedAngleAnimator; |
37 | class SVGAnimatedIntegerPairAnimator; |
38 | class SVGAnimatedOrientTypeAnimator; |
39 | |
40 | template<typename AnimatedPropertyAnimator1, typename AnimatedPropertyAnimator2> |
41 | class SVGAnimatedPropertyPairAnimator; |
42 | |
43 | class SVGAnimatedAngleAnimator final : public SVGAnimatedPropertyAnimator<SVGAnimatedAngle, SVGAnimationAngleFunction> { |
44 | friend class SVGAnimatedPropertyPairAnimator<SVGAnimatedAngleAnimator, SVGAnimatedOrientTypeAnimator>; |
45 | friend class SVGAnimatedAngleOrientAnimator; |
46 | using Base = SVGAnimatedPropertyAnimator<SVGAnimatedAngle, SVGAnimationAngleFunction>; |
47 | using Base::Base; |
48 | |
49 | public: |
50 | static auto create(const QualifiedName& attributeName, Ref<SVGAnimatedAngle>& animated, AnimationMode animationMode, CalcMode calcMode, bool isAccumulated, bool isAdditive) |
51 | { |
52 | return std::make_unique<SVGAnimatedAngleAnimator>(attributeName, animated, animationMode, calcMode, isAccumulated, isAdditive); |
53 | } |
54 | |
55 | private: |
56 | void animate(SVGElement* targetElement, float progress, unsigned repeatCount) final |
57 | { |
58 | m_function.animate(targetElement, progress, repeatCount, m_animated->animVal()->value()); |
59 | } |
60 | }; |
61 | |
62 | class SVGAnimatedBooleanAnimator final : public SVGAnimatedPropertyAnimator<SVGAnimatedBoolean, SVGAnimationBooleanFunction> { |
63 | using Base = SVGAnimatedPropertyAnimator<SVGAnimatedBoolean, SVGAnimationBooleanFunction>; |
64 | |
65 | public: |
66 | using Base::Base; |
67 | |
68 | static auto create(const QualifiedName& attributeName, Ref<SVGAnimatedBoolean>& animated, AnimationMode animationMode, CalcMode calcMode, bool isAccumulated, bool isAdditive) |
69 | { |
70 | return std::make_unique<SVGAnimatedBooleanAnimator>(attributeName, animated, animationMode, calcMode, isAccumulated, isAdditive); |
71 | } |
72 | |
73 | private: |
74 | void animate(SVGElement* targetElement, float progress, unsigned repeatCount) final |
75 | { |
76 | bool& animated = m_animated->animVal(); |
77 | m_function.animate(targetElement, progress, repeatCount, animated); |
78 | } |
79 | }; |
80 | |
81 | template<typename EnumType> |
82 | class SVGAnimatedEnumerationAnimator final : public SVGAnimatedPropertyAnimator<SVGAnimatedEnumeration, SVGAnimationEnumerationFunction<EnumType>> { |
83 | using Base = SVGAnimatedPropertyAnimator<SVGAnimatedEnumeration, SVGAnimationEnumerationFunction<EnumType>>; |
84 | using Base::Base; |
85 | using Base::m_animated; |
86 | using Base::m_function; |
87 | |
88 | public: |
89 | static auto create(const QualifiedName& attributeName, Ref<SVGAnimatedEnumeration>& animated, AnimationMode animationMode, CalcMode calcMode, bool isAccumulated, bool isAdditive) |
90 | { |
91 | return std::make_unique<SVGAnimatedEnumerationAnimator<EnumType>>(attributeName, animated, animationMode, calcMode, isAccumulated, isAdditive); |
92 | } |
93 | |
94 | private: |
95 | void animate(SVGElement* targetElement, float progress, unsigned repeatCount) final |
96 | { |
97 | EnumType animated; |
98 | m_function.animate(targetElement, progress, repeatCount, animated); |
99 | m_animated->template setAnimVal<EnumType>(animated); |
100 | } |
101 | }; |
102 | |
103 | class SVGAnimatedIntegerAnimator final : public SVGAnimatedPropertyAnimator<SVGAnimatedInteger, SVGAnimationIntegerFunction> { |
104 | friend class SVGAnimatedPropertyPairAnimator<SVGAnimatedIntegerAnimator, SVGAnimatedIntegerAnimator>; |
105 | friend class SVGAnimatedIntegerPairAnimator; |
106 | using Base = SVGAnimatedPropertyAnimator<SVGAnimatedInteger, SVGAnimationIntegerFunction>; |
107 | |
108 | public: |
109 | using Base::Base; |
110 | |
111 | static auto create(const QualifiedName& attributeName, Ref<SVGAnimatedInteger>& animated, AnimationMode animationMode, CalcMode calcMode, bool isAccumulated, bool isAdditive) |
112 | { |
113 | return std::make_unique<SVGAnimatedIntegerAnimator>(attributeName, animated, animationMode, calcMode, isAccumulated, isAdditive); |
114 | } |
115 | |
116 | private: |
117 | void animate(SVGElement* targetElement, float progress, unsigned repeatCount) final |
118 | { |
119 | m_function.animate(targetElement, progress, repeatCount, m_animated->animVal()); |
120 | } |
121 | }; |
122 | |
123 | class SVGAnimatedLengthAnimator final : public SVGAnimatedPropertyAnimator<SVGAnimatedLength, SVGAnimationLengthFunction> { |
124 | using Base = SVGAnimatedPropertyAnimator<SVGAnimatedLength, SVGAnimationLengthFunction>; |
125 | |
126 | public: |
127 | SVGAnimatedLengthAnimator(const QualifiedName& attributeName, Ref<SVGAnimatedLength>& animated, AnimationMode animationMode, CalcMode calcMode, bool isAccumulated, bool isAdditive, SVGLengthMode lengthMode) |
128 | : Base(attributeName, animated, animationMode, calcMode, isAccumulated, isAdditive, lengthMode) |
129 | { |
130 | } |
131 | |
132 | static auto create(const QualifiedName& attributeName, Ref<SVGAnimatedLength>& animated, AnimationMode animationMode, CalcMode calcMode, bool isAccumulated, bool isAdditive, SVGLengthMode lengthMode) |
133 | { |
134 | return std::make_unique<SVGAnimatedLengthAnimator>(attributeName, animated, animationMode, calcMode, isAccumulated, isAdditive, lengthMode); |
135 | } |
136 | |
137 | private: |
138 | void animate(SVGElement* targetElement, float progress, unsigned repeatCount) final |
139 | { |
140 | m_function.animate(targetElement, progress, repeatCount, m_animated->animVal()->value()); |
141 | } |
142 | }; |
143 | |
144 | class SVGAnimatedLengthListAnimator final : public SVGAnimatedPropertyAnimator<SVGAnimatedLengthList, SVGAnimationLengthListFunction> { |
145 | using Base = SVGAnimatedPropertyAnimator<SVGAnimatedLengthList, SVGAnimationLengthListFunction>; |
146 | |
147 | public: |
148 | SVGAnimatedLengthListAnimator(const QualifiedName& attributeName, Ref<SVGAnimatedLengthList>& animated, AnimationMode animationMode, CalcMode calcMode, bool isAccumulated, bool isAdditive, SVGLengthMode lengthMode) |
149 | : Base(attributeName, animated, animationMode, calcMode, isAccumulated, isAdditive, lengthMode) |
150 | { |
151 | } |
152 | |
153 | static auto create(const QualifiedName& attributeName, Ref<SVGAnimatedLengthList>& animated, AnimationMode animationMode, CalcMode calcMode, bool isAccumulated, bool isAdditive, SVGLengthMode lengthMode) |
154 | { |
155 | return std::make_unique<SVGAnimatedLengthListAnimator>(attributeName, animated, animationMode, calcMode, isAccumulated, isAdditive, lengthMode); |
156 | } |
157 | |
158 | private: |
159 | void animate(SVGElement* targetElement, float progress, unsigned repeatCount) final |
160 | { |
161 | m_function.animate(targetElement, progress, repeatCount, m_animated->animVal()); |
162 | } |
163 | }; |
164 | |
165 | class SVGAnimatedNumberAnimator final : public SVGAnimatedPropertyAnimator<SVGAnimatedNumber, SVGAnimationNumberFunction> { |
166 | friend class SVGAnimatedPropertyPairAnimator<SVGAnimatedNumberAnimator, SVGAnimatedNumberAnimator>; |
167 | friend class SVGAnimatedNumberPairAnimator; |
168 | using Base = SVGAnimatedPropertyAnimator<SVGAnimatedNumber, SVGAnimationNumberFunction>; |
169 | using Base::Base; |
170 | |
171 | public: |
172 | static auto create(const QualifiedName& attributeName, Ref<SVGAnimatedNumber>& animated, AnimationMode animationMode, CalcMode calcMode, bool isAccumulated, bool isAdditive) |
173 | { |
174 | return std::make_unique<SVGAnimatedNumberAnimator>(attributeName, animated, animationMode, calcMode, isAccumulated, isAdditive); |
175 | } |
176 | |
177 | private: |
178 | void animate(SVGElement* targetElement, float progress, unsigned repeatCount) final |
179 | { |
180 | m_function.animate(targetElement, progress, repeatCount, m_animated->animVal()); |
181 | } |
182 | }; |
183 | |
184 | class SVGAnimatedNumberListAnimator final : public SVGAnimatedPropertyAnimator<SVGAnimatedNumberList, SVGAnimationNumberListFunction> { |
185 | using Base = SVGAnimatedPropertyAnimator<SVGAnimatedNumberList, SVGAnimationNumberListFunction>; |
186 | using Base::Base; |
187 | |
188 | public: |
189 | static auto create(const QualifiedName& attributeName, Ref<SVGAnimatedNumberList>& animated, AnimationMode animationMode, CalcMode calcMode, bool isAccumulated, bool isAdditive) |
190 | { |
191 | return std::make_unique<SVGAnimatedNumberListAnimator>(attributeName, animated, animationMode, calcMode, isAccumulated, isAdditive); |
192 | } |
193 | |
194 | private: |
195 | void animate(SVGElement* targetElement, float progress, unsigned repeatCount) final |
196 | { |
197 | m_function.animate(targetElement, progress, repeatCount, m_animated->animVal()); |
198 | } |
199 | }; |
200 | |
201 | class SVGAnimatedPathSegListAnimator final : public SVGAnimatedPropertyAnimator<SVGAnimatedPathSegList, SVGAnimationPathSegListFunction> { |
202 | using Base = SVGAnimatedPropertyAnimator<SVGAnimatedPathSegList, SVGAnimationPathSegListFunction>; |
203 | using Base::Base; |
204 | |
205 | public: |
206 | static auto create(const QualifiedName& attributeName, Ref<SVGAnimatedPathSegList>& animated, AnimationMode animationMode, CalcMode calcMode, bool isAccumulated, bool isAdditive) |
207 | { |
208 | return std::make_unique<SVGAnimatedPathSegListAnimator>(attributeName, animated, animationMode, calcMode, isAccumulated, isAdditive); |
209 | } |
210 | |
211 | private: |
212 | void animate(SVGElement* targetElement, float progress, unsigned repeatCount) final |
213 | { |
214 | m_animated->animVal()->pathByteStreamWillChange(); |
215 | m_function.animate(targetElement, progress, repeatCount, m_animated->animVal()->pathByteStream()); |
216 | } |
217 | }; |
218 | |
219 | class SVGAnimatedPointListAnimator final : public SVGAnimatedPropertyAnimator<SVGAnimatedPointList, SVGAnimationPointListFunction> { |
220 | using Base = SVGAnimatedPropertyAnimator<SVGAnimatedPointList, SVGAnimationPointListFunction>; |
221 | using Base::Base; |
222 | |
223 | public: |
224 | static auto create(const QualifiedName& attributeName, Ref<SVGAnimatedPointList>& animated, AnimationMode animationMode, CalcMode calcMode, bool isAccumulated, bool isAdditive) |
225 | { |
226 | return std::make_unique<SVGAnimatedPointListAnimator>(attributeName, animated, animationMode, calcMode, isAccumulated, isAdditive); |
227 | } |
228 | |
229 | private: |
230 | void animate(SVGElement* targetElement, float progress, unsigned repeatCount) final |
231 | { |
232 | m_function.animate(targetElement, progress, repeatCount, m_animated->animVal()); |
233 | } |
234 | }; |
235 | |
236 | class SVGAnimatedOrientTypeAnimator final : public SVGAnimatedPropertyAnimator<SVGAnimatedOrientType, SVGAnimationOrientTypeFunction> { |
237 | friend class SVGAnimatedPropertyPairAnimator<SVGAnimatedAngleAnimator, SVGAnimatedOrientTypeAnimator>; |
238 | friend class SVGAnimatedAngleOrientAnimator; |
239 | using Base = SVGAnimatedPropertyAnimator<SVGAnimatedOrientType, SVGAnimationOrientTypeFunction>; |
240 | using Base::Base; |
241 | |
242 | public: |
243 | static auto create(const QualifiedName& attributeName, Ref<SVGAnimatedOrientType>& animated, AnimationMode animationMode, CalcMode calcMode, bool isAccumulated, bool isAdditive) |
244 | { |
245 | return std::make_unique<SVGAnimatedOrientTypeAnimator>(attributeName, animated, animationMode, calcMode, isAccumulated, isAdditive); |
246 | } |
247 | |
248 | private: |
249 | void animate(SVGElement* targetElement, float progress, unsigned repeatCount) final |
250 | { |
251 | SVGMarkerOrientType animated; |
252 | m_function.animate(targetElement, progress, repeatCount, animated); |
253 | m_animated->setAnimVal(animated); |
254 | } |
255 | }; |
256 | |
257 | class SVGAnimatedPreserveAspectRatioAnimator final : public SVGAnimatedPropertyAnimator<SVGAnimatedPreserveAspectRatio, SVGAnimationPreserveAspectRatioFunction> { |
258 | using Base = SVGAnimatedPropertyAnimator<SVGAnimatedPreserveAspectRatio, SVGAnimationPreserveAspectRatioFunction>; |
259 | using Base::Base; |
260 | |
261 | public: |
262 | static auto create(const QualifiedName& attributeName, Ref<SVGAnimatedPreserveAspectRatio>& animated, AnimationMode animationMode, CalcMode calcMode, bool isAccumulated, bool isAdditive) |
263 | { |
264 | return std::make_unique<SVGAnimatedPreserveAspectRatioAnimator>(attributeName, animated, animationMode, calcMode, isAccumulated, isAdditive); |
265 | } |
266 | |
267 | private: |
268 | void animate(SVGElement* targetElement, float progress, unsigned repeatCount) final |
269 | { |
270 | SVGPreserveAspectRatioValue& animated = m_animated->animVal()->value(); |
271 | m_function.animate(targetElement, progress, repeatCount, animated); |
272 | } |
273 | }; |
274 | |
275 | class SVGAnimatedRectAnimator final : public SVGAnimatedPropertyAnimator<SVGAnimatedRect, SVGAnimationRectFunction> { |
276 | using Base = SVGAnimatedPropertyAnimator<SVGAnimatedRect, SVGAnimationRectFunction>; |
277 | |
278 | public: |
279 | using Base::Base; |
280 | |
281 | static auto create(const QualifiedName& attributeName, Ref<SVGAnimatedRect>& animated, AnimationMode animationMode, CalcMode calcMode, bool isAccumulated, bool isAdditive) |
282 | { |
283 | return std::make_unique<SVGAnimatedRectAnimator>(attributeName, animated, animationMode, calcMode, isAccumulated, isAdditive); |
284 | } |
285 | |
286 | private: |
287 | void animate(SVGElement* targetElement, float progress, unsigned repeatCount) final |
288 | { |
289 | m_function.animate(targetElement, progress, repeatCount, m_animated->animVal()->value()); |
290 | } |
291 | }; |
292 | |
293 | class SVGAnimatedStringAnimator final : public SVGAnimatedPropertyAnimator<SVGAnimatedString, SVGAnimationStringFunction> { |
294 | using Base = SVGAnimatedPropertyAnimator<SVGAnimatedString, SVGAnimationStringFunction>; |
295 | using Base::Base; |
296 | |
297 | public: |
298 | static auto create(const QualifiedName& attributeName, Ref<SVGAnimatedString>& animated, AnimationMode animationMode, CalcMode calcMode, bool isAccumulated, bool isAdditive) |
299 | { |
300 | return std::make_unique<SVGAnimatedStringAnimator>(attributeName, animated, animationMode, calcMode, isAccumulated, isAdditive); |
301 | } |
302 | |
303 | private: |
304 | void animate(SVGElement* targetElement, float progress, unsigned repeatCount) final |
305 | { |
306 | String& animated = m_animated->animVal(); |
307 | m_function.animate(targetElement, progress, repeatCount, animated); |
308 | } |
309 | }; |
310 | |
311 | class SVGAnimatedTransformListAnimator final : public SVGAnimatedPropertyAnimator<SVGAnimatedTransformList, SVGAnimationTransformListFunction> { |
312 | using Base = SVGAnimatedPropertyAnimator<SVGAnimatedTransformList, SVGAnimationTransformListFunction>; |
313 | using Base::Base; |
314 | |
315 | public: |
316 | static auto create(const QualifiedName& attributeName, Ref<SVGAnimatedTransformList>& animated, AnimationMode animationMode, CalcMode calcMode, bool isAccumulated, bool isAdditive) |
317 | { |
318 | return std::make_unique<SVGAnimatedTransformListAnimator>(attributeName, animated, animationMode, calcMode, isAccumulated, isAdditive); |
319 | } |
320 | |
321 | private: |
322 | void animate(SVGElement* targetElement, float progress, unsigned repeatCount) final |
323 | { |
324 | m_function.animate(targetElement, progress, repeatCount, m_animated->animVal()); |
325 | } |
326 | }; |
327 | |
328 | } |
329 | |