OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) Research In Motion Limited 2011-2012. All rights reserved. | 2 * Copyright (C) Research In Motion Limited 2011-2012. All rights reserved. |
3 * Copyright (C) 2013 Samsung Electronics. All rights reserved. | 3 * Copyright (C) 2013 Samsung Electronics. All rights reserved. |
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 "core/svg/SVGAnimatedTypeAnimator.h" | 21 #include "core/svg/SVGAnimatedTypeAnimator.h" |
22 | 22 |
23 #include "core/svg/SVGAnimateTransformElement.h" | 23 #include "core/svg/SVGAnimateTransformElement.h" |
24 #include "core/svg/SVGAnimatedColor.h" | 24 #include "core/svg/SVGAnimatedColor.h" |
25 #include "core/svg/SVGAnimationElement.h" | 25 #include "core/svg/SVGAnimationElement.h" |
26 #include "core/svg/SVGLength.h" | 26 #include "core/svg/SVGLength.h" |
27 #include "core/svg/SVGLengthList.h" | 27 #include "core/svg/SVGLengthList.h" |
28 #include "core/svg/SVGNumber.h" | 28 #include "core/svg/SVGNumber.h" |
29 #include "core/svg/SVGPointList.h" | |
30 #include "core/svg/SVGString.h" | 29 #include "core/svg/SVGString.h" |
31 #include "core/svg/SVGTransformList.h" | 30 #include "core/svg/SVGTransformList.h" |
32 #include "core/svg/properties/SVGAnimatedProperty.h" | 31 #include "core/svg/properties/SVGAnimatedProperty.h" |
33 | 32 |
34 namespace blink { | 33 namespace blink { |
35 | 34 |
36 SVGAnimatedTypeAnimator::SVGAnimatedTypeAnimator(SVGAnimationElement* animationE
lement) | 35 SVGAnimatedTypeAnimator::SVGAnimatedTypeAnimator(SVGAnimationElement* animationE
lement) |
37 : m_animationElement(animationElement) | 36 : m_animationElement(animationElement) |
38 , m_contextElement(nullptr) | 37 , m_contextElement(nullptr) |
39 , m_type(AnimatedUnknown) | 38 , m_type(AnimatedUnknown) |
40 { | 39 { |
41 ASSERT(m_animationElement); | 40 DCHECK(m_animationElement); |
42 } | 41 } |
43 | 42 |
44 void SVGAnimatedTypeAnimator::clear() | 43 void SVGAnimatedTypeAnimator::clear() |
45 { | 44 { |
46 m_contextElement = nullptr; | 45 m_contextElement = nullptr; |
47 m_animatedProperty = nullptr; | 46 m_animatedProperty = nullptr; |
48 m_type = AnimatedUnknown; | 47 m_type = AnimatedUnknown; |
49 } | 48 } |
50 | 49 |
51 void SVGAnimatedTypeAnimator::reset(SVGElement* contextElement) | 50 void SVGAnimatedTypeAnimator::reset(SVGElement* contextElement) |
52 { | 51 { |
53 ASSERT(contextElement); | 52 DCHECK(contextElement); |
54 m_contextElement = contextElement; | 53 m_contextElement = contextElement; |
55 | 54 |
56 const QualifiedName& attributeName = m_animationElement->attributeName(); | 55 const QualifiedName& attributeName = m_animationElement->attributeName(); |
57 m_animatedProperty = m_contextElement->propertyFromAttribute(attributeName); | 56 m_animatedProperty = m_contextElement->propertyFromAttribute(attributeName); |
58 m_type = m_animatedProperty ? m_animatedProperty->type() | 57 m_type = m_animatedProperty ? m_animatedProperty->type() |
59 : SVGElement::animatedPropertyTypeForCSSAttribute(attributeName); | 58 : SVGElement::animatedPropertyTypeForCSSAttribute(attributeName); |
60 | 59 |
61 // Only <animateTransform> is allowed to animate AnimatedTransformList. | 60 // Only <animateTransform> is allowed to animate AnimatedTransformList. |
62 // http://www.w3.org/TR/SVG/animate.html#AnimationAttributesAndProperties | 61 // http://www.w3.org/TR/SVG/animate.html#AnimationAttributesAndProperties |
63 if (m_type == AnimatedTransformList && !isSVGAnimateTransformElement(*m_anim
ationElement)) | 62 if (m_type == AnimatedTransformList && !isSVGAnimateTransformElement(*m_anim
ationElement)) |
64 m_type = AnimatedUnknown; | 63 m_type = AnimatedUnknown; |
65 | 64 |
66 ASSERT(m_type != AnimatedPoint | 65 DCHECK(m_type != AnimatedPoint |
67 && m_type != AnimatedStringList | 66 && m_type != AnimatedStringList |
68 && m_type != AnimatedTransform); | 67 && m_type != AnimatedTransform); |
69 } | 68 } |
70 | 69 |
71 SVGPropertyBase* SVGAnimatedTypeAnimator::createPropertyForAnimation(const Strin
g& value) | 70 SVGPropertyBase* SVGAnimatedTypeAnimator::createPropertyForAttributeAnimation(co
nst String& value) const |
72 { | 71 { |
73 ASSERT(m_contextElement); | 72 // SVG DOM animVal animation code-path. |
| 73 if (m_type == AnimatedTransformList) { |
| 74 // TransformList must be animated via <animateTransform>, |
| 75 // and its {from,by,to} attribute values needs to be parsed w.r.t. its "
type" attribute. |
| 76 // Spec: http://www.w3.org/TR/SVG/single-page.html#animate-AnimateTransf
ormElement |
| 77 DCHECK(m_animationElement); |
| 78 SVGTransformType transformType = toSVGAnimateTransformElement(m_animatio
nElement)->transformType(); |
| 79 return SVGTransformList::create(transformType, value); |
| 80 } |
| 81 DCHECK(m_animatedProperty); |
| 82 return m_animatedProperty->currentValueBase()->cloneForAnimation(value); |
| 83 } |
74 | 84 |
75 if (isAnimatingSVGDom()) { | 85 SVGPropertyBase* SVGAnimatedTypeAnimator::createPropertyForCSSAnimation(const St
ring& value) const |
76 // SVG DOM animVal animation code-path. | 86 { |
77 | |
78 if (m_type == AnimatedTransformList) { | |
79 // TransformList must be animated via <animateTransform>, | |
80 // and its {from,by,to} attribute values needs to be parsed w.r.t. i
ts "type" attribute. | |
81 // Spec: http://www.w3.org/TR/SVG/single-page.html#animate-AnimateTr
ansformElement | |
82 ASSERT(m_animationElement); | |
83 SVGTransformType transformType = toSVGAnimateTransformElement(m_anim
ationElement)->transformType(); | |
84 return SVGTransformList::create(transformType, value); | |
85 } | |
86 | |
87 ASSERT(m_animatedProperty); | |
88 return m_animatedProperty->currentValueBase()->cloneForAnimation(value); | |
89 } | |
90 | |
91 ASSERT(isAnimatingCSSProperty()); | |
92 | |
93 // CSS properties animation code-path. | 87 // CSS properties animation code-path. |
94 // Create a basic instance of the corresponding SVG property. | 88 // Create a basic instance of the corresponding SVG property. |
95 // The instance will not have full context info. (e.g. SVGLengthMode) | 89 // The instance will not have full context info. (e.g. SVGLengthMode) |
96 | |
97 switch (m_type) { | 90 switch (m_type) { |
98 case AnimatedColor: | 91 case AnimatedColor: |
99 return SVGColorProperty::create(value); | 92 return SVGColorProperty::create(value); |
100 case AnimatedNumber: { | 93 case AnimatedNumber: { |
101 SVGNumber* property = SVGNumber::create(); | 94 SVGNumber* property = SVGNumber::create(); |
102 property->setValueAsString(value); | 95 property->setValueAsString(value); |
103 return property; | 96 return property; |
104 } | 97 } |
105 case AnimatedLength: { | 98 case AnimatedLength: { |
106 SVGLength* property = SVGLength::create(); | 99 SVGLength* property = SVGLength::create(); |
107 property->setValueAsString(value); | 100 property->setValueAsString(value); |
108 return property; | 101 return property; |
109 } | 102 } |
110 case AnimatedLengthList: { | 103 case AnimatedLengthList: { |
111 SVGLengthList* property = SVGLengthList::create(); | 104 SVGLengthList* property = SVGLengthList::create(); |
112 property->setValueAsString(value); | 105 property->setValueAsString(value); |
113 return property; | 106 return property; |
114 } | 107 } |
115 case AnimatedString: { | 108 case AnimatedString: { |
116 SVGString* property = SVGString::create(); | 109 SVGString* property = SVGString::create(); |
117 property->setValueAsString(value); | 110 property->setValueAsString(value); |
118 return property; | 111 return property; |
119 } | 112 } |
120 | 113 // These types don't appear in the table in |
121 // These types don't appear in the table in SVGElement::animatedPropertyType
ForCSSAttribute() and thus don't need support. | 114 // SVGElement::animatedPropertyTypeForCSSAttribute() and thus don't need |
| 115 // support. |
122 case AnimatedAngle: | 116 case AnimatedAngle: |
123 case AnimatedBoolean: | 117 case AnimatedBoolean: |
124 case AnimatedEnumeration: | 118 case AnimatedEnumeration: |
125 case AnimatedInteger: | 119 case AnimatedInteger: |
126 case AnimatedIntegerOptionalInteger: | 120 case AnimatedIntegerOptionalInteger: |
127 case AnimatedNumberList: | 121 case AnimatedNumberList: |
128 case AnimatedNumberOptionalNumber: | 122 case AnimatedNumberOptionalNumber: |
129 case AnimatedPath: | 123 case AnimatedPath: |
130 case AnimatedPoint: | 124 case AnimatedPoint: |
131 case AnimatedPoints: | 125 case AnimatedPoints: |
132 case AnimatedPreserveAspectRatio: | 126 case AnimatedPreserveAspectRatio: |
133 case AnimatedRect: | 127 case AnimatedRect: |
134 case AnimatedStringList: | 128 case AnimatedStringList: |
135 case AnimatedTransform: | 129 case AnimatedTransform: |
136 case AnimatedTransformList: | 130 case AnimatedTransformList: |
137 ASSERT_NOT_REACHED(); | |
138 | |
139 case AnimatedUnknown: | 131 case AnimatedUnknown: |
140 ASSERT_NOT_REACHED(); | 132 break; |
141 }; | 133 } |
142 | 134 NOTREACHED(); |
143 ASSERT_NOT_REACHED(); | |
144 return nullptr; | 135 return nullptr; |
145 } | 136 } |
146 | 137 |
147 SVGPropertyBase* SVGAnimatedTypeAnimator::createAnimatedValueFromString(const St
ring& value) | 138 SVGPropertyBase* SVGAnimatedTypeAnimator::createPropertyForAnimation(const Strin
g& value) const |
148 { | 139 { |
149 return createPropertyForAnimation(value); | 140 DCHECK(m_contextElement); |
| 141 if (isAnimatingSVGDom()) |
| 142 return createPropertyForAttributeAnimation(value); |
| 143 DCHECK(isAnimatingCSSProperty()); |
| 144 return createPropertyForCSSAnimation(value); |
150 } | 145 } |
151 | 146 |
152 void SVGAnimatedTypeAnimator::calculateFromAndToValues(Member<SVGPropertyBase>&
from, Member<SVGPropertyBase>& to, const String& fromString, const String& toStr
ing) | 147 SVGPropertyBase* SVGAnimatedTypeAnimator::createAnimatedValue() const |
153 { | |
154 from = createAnimatedValueFromString(fromString); | |
155 to = createAnimatedValueFromString(toString); | |
156 } | |
157 | |
158 void SVGAnimatedTypeAnimator::calculateFromAndByValues(Member<SVGPropertyBase>&
from, Member<SVGPropertyBase>& to, const String& fromString, const String& byStr
ing) | |
159 { | |
160 from = createAnimatedValueFromString(fromString); | |
161 to = createAnimatedValueFromString(byString); | |
162 to->add(from, m_contextElement); | |
163 } | |
164 | |
165 SVGPropertyBase* SVGAnimatedTypeAnimator::createAnimatedValue() | |
166 { | 148 { |
167 DCHECK(isAnimatingSVGDom()); | 149 DCHECK(isAnimatingSVGDom()); |
168 SVGPropertyBase* animatedValue = m_animatedProperty->createAnimatedValue(); | 150 SVGPropertyBase* animatedValue = m_animatedProperty->createAnimatedValue(); |
169 DCHECK_EQ(animatedValue->type(), m_type); | 151 DCHECK_EQ(animatedValue->type(), m_type); |
170 return animatedValue; | 152 return animatedValue; |
171 } | 153 } |
172 | 154 |
173 class ParsePropertyFromString { | |
174 STACK_ALLOCATED(); | |
175 public: | |
176 explicit ParsePropertyFromString(SVGAnimatedTypeAnimator* animator) | |
177 : m_animator(animator) | |
178 { | |
179 } | |
180 | |
181 SVGPropertyBase* operator()(SVGAnimationElement*, const String& value) | |
182 { | |
183 return m_animator->createPropertyForAnimation(value); | |
184 } | |
185 | |
186 private: | |
187 SVGAnimatedTypeAnimator* m_animator; | |
188 }; | |
189 | |
190 void SVGAnimatedTypeAnimator::calculateAnimatedValue(float percentage, unsigned
repeatCount, SVGPropertyBase* from, SVGPropertyBase* to, SVGPropertyBase* toAtEn
dOfDuration, SVGPropertyBase* animated) | |
191 { | |
192 ASSERT(m_animationElement); | |
193 ASSERT(m_contextElement); | |
194 | |
195 SVGPropertyBase* fromValue = m_animationElement->getAnimationMode() == ToAni
mation ? animated : from; | |
196 SVGPropertyBase* toValue = to; | |
197 SVGPropertyBase* toAtEndOfDurationValue = toAtEndOfDuration; | |
198 SVGPropertyBase* animatedValue = animated; | |
199 | |
200 // Apply CSS inheritance rules. | |
201 ParsePropertyFromString parsePropertyFromString(this); | |
202 m_animationElement->adjustForInheritance<SVGPropertyBase*, ParsePropertyFrom
String>(parsePropertyFromString, m_animationElement->fromPropertyValueType(), fr
omValue, m_contextElement); | |
203 m_animationElement->adjustForInheritance<SVGPropertyBase*, ParsePropertyFrom
String>(parsePropertyFromString, m_animationElement->toPropertyValueType(), toVa
lue, m_contextElement); | |
204 | |
205 animatedValue->calculateAnimatedValue(m_animationElement, percentage, repeat
Count, fromValue, toValue, toAtEndOfDurationValue, m_contextElement); | |
206 } | |
207 | |
208 float SVGAnimatedTypeAnimator::calculateDistance(const String& fromString, const
String& toString) | |
209 { | |
210 ASSERT(m_contextElement); | |
211 SVGPropertyBase* fromValue = createPropertyForAnimation(fromString); | |
212 SVGPropertyBase* toValue = createPropertyForAnimation(toString); | |
213 return fromValue->calculateDistance(toValue, m_contextElement); | |
214 } | |
215 | |
216 DEFINE_TRACE(SVGAnimatedTypeAnimator) | 155 DEFINE_TRACE(SVGAnimatedTypeAnimator) |
217 { | 156 { |
218 visitor->trace(m_animationElement); | 157 visitor->trace(m_animationElement); |
219 visitor->trace(m_contextElement); | 158 visitor->trace(m_contextElement); |
220 visitor->trace(m_animatedProperty); | 159 visitor->trace(m_animatedProperty); |
221 } | 160 } |
222 | 161 |
223 } // namespace blink | 162 } // namespace blink |
OLD | NEW |