OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 16 matching lines...) Expand all Loading... |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 29 */ |
30 | 30 |
31 #include "config.h" | 31 #include "config.h" |
32 #include "core/animation/KeyframeEffectModel.h" | 32 #include "core/animation/KeyframeEffectModel.h" |
33 | 33 |
34 #include "core/animation/TimedItem.h" | 34 #include "core/animation/TimedItem.h" |
35 #include "wtf/text/StringHash.h" | 35 #include "wtf/text/StringHash.h" |
36 | 36 |
37 namespace { | |
38 | |
39 using namespace WebCore; | |
40 | |
41 class AddCompositableValue FINAL : public AnimationEffect::CompositableValue { | |
42 public: | |
43 static PassRefPtr<AddCompositableValue> create(const AnimatableValue* value) | |
44 { | |
45 return adoptRef(new AddCompositableValue(value)); | |
46 } | |
47 virtual bool dependsOnUnderlyingValue() const OVERRIDE | |
48 { | |
49 return true; | |
50 } | |
51 virtual PassRefPtr<AnimatableValue> compositeOnto(const AnimatableValue* und
erlyingValue) const OVERRIDE | |
52 { | |
53 return AnimatableValue::add(underlyingValue, m_value.get()); | |
54 } | |
55 private: | |
56 AddCompositableValue(const AnimatableValue* value) | |
57 : m_value(const_cast<AnimatableValue*>(value)) | |
58 { | |
59 } | |
60 RefPtr<AnimatableValue> m_value; | |
61 }; | |
62 | |
63 class BlendedCompositableValue FINAL : public AnimationEffect::CompositableValue
{ | |
64 public: | |
65 static PassRefPtr<BlendedCompositableValue> create(const AnimationEffect::Co
mpositableValue* before, const AnimationEffect::CompositableValue* after, double
fraction) | |
66 { | |
67 return adoptRef(new BlendedCompositableValue(before, after, fraction)); | |
68 } | |
69 virtual bool dependsOnUnderlyingValue() const OVERRIDE | |
70 { | |
71 return m_dependsOnUnderlyingValue; | |
72 } | |
73 virtual PassRefPtr<AnimatableValue> compositeOnto(const AnimatableValue* und
erlyingValue) const OVERRIDE | |
74 { | |
75 return AnimatableValue::interpolate(m_before->compositeOnto(underlyingVa
lue).get(), m_after->compositeOnto(underlyingValue).get(), m_fraction); | |
76 } | |
77 private: | |
78 BlendedCompositableValue(const AnimationEffect::CompositableValue* before, c
onst AnimationEffect::CompositableValue* after, double fraction) | |
79 : m_before(const_cast<AnimationEffect::CompositableValue*>(before)) | |
80 , m_after(const_cast<AnimationEffect::CompositableValue*>(after)) | |
81 , m_fraction(fraction) | |
82 , m_dependsOnUnderlyingValue(before->dependsOnUnderlyingValue() || after
->dependsOnUnderlyingValue()) | |
83 { } | |
84 RefPtr<AnimationEffect::CompositableValue> m_before; | |
85 RefPtr<AnimationEffect::CompositableValue> m_after; | |
86 double m_fraction; | |
87 bool m_dependsOnUnderlyingValue; | |
88 }; | |
89 | |
90 } // namespace | |
91 | |
92 | |
93 namespace WebCore { | 37 namespace WebCore { |
94 | 38 |
95 Keyframe::Keyframe() | 39 Keyframe::Keyframe() |
96 : m_offset(nullValue()) | 40 : m_offset(nullValue()) |
97 , m_composite(AnimationEffect::CompositeReplace) | 41 , m_composite(AnimationEffect::CompositeReplace) |
98 , m_easing(LinearTimingFunction::preset()) | 42 , m_easing(LinearTimingFunction::preset()) |
99 { } | 43 { } |
100 | 44 |
101 Keyframe::Keyframe(const Keyframe& copyFrom) | 45 Keyframe::Keyframe(const Keyframe& copyFrom) |
102 : m_offset(copyFrom.m_offset) | 46 : m_offset(copyFrom.m_offset) |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 } | 218 } |
275 | 219 |
276 void KeyframeEffectModel::ensureInterpolationEffect() const | 220 void KeyframeEffectModel::ensureInterpolationEffect() const |
277 { | 221 { |
278 if (m_interpolationEffect) | 222 if (m_interpolationEffect) |
279 return; | 223 return; |
280 m_interpolationEffect = InterpolationEffect::create(); | 224 m_interpolationEffect = InterpolationEffect::create(); |
281 | 225 |
282 for (KeyframeGroupMap::const_iterator iter = m_keyframeGroups->begin(); iter
!= m_keyframeGroups->end(); ++iter) { | 226 for (KeyframeGroupMap::const_iterator iter = m_keyframeGroups->begin(); iter
!= m_keyframeGroups->end(); ++iter) { |
283 const PropertySpecificKeyframeVector& keyframes = iter->value->keyframes
(); | 227 const PropertySpecificKeyframeVector& keyframes = iter->value->keyframes
(); |
284 ASSERT(keyframes[0]->value()->isAnimatableValue()); | |
285 const AnimatableValue* start; | 228 const AnimatableValue* start; |
286 const AnimatableValue* end = toAnimatableValue(keyframes[0]->value()); | 229 const AnimatableValue* end = keyframes[0]->value(); |
287 for (size_t i = 0; i < keyframes.size() - 1; i++) { | 230 for (size_t i = 0; i < keyframes.size() - 1; i++) { |
288 ASSERT(keyframes[i + 1]->value()->isAnimatableValue()); | |
289 start = end; | 231 start = end; |
290 end = toAnimatableValue(keyframes[i + 1]->value()); | 232 end = keyframes[i + 1]->value(); |
291 double applyFrom = i ? keyframes[i]->offset() : (-std::numeric_limit
s<double>::infinity()); | 233 double applyFrom = i ? keyframes[i]->offset() : (-std::numeric_limit
s<double>::infinity()); |
292 double applyTo = i == keyframes.size() - 2 ? std::numeric_limits<dou
ble>::infinity() : keyframes[i+1]->offset(); | 234 double applyTo = i == keyframes.size() - 2 ? std::numeric_limits<dou
ble>::infinity() : keyframes[i + 1]->offset(); |
293 if (applyTo == 1) | 235 if (applyTo == 1) |
294 applyTo = std::numeric_limits<double>::infinity(); | 236 applyTo = std::numeric_limits<double>::infinity(); |
295 m_interpolationEffect->addInterpolation( | 237 m_interpolationEffect->addInterpolation( |
296 LegacyStyleInterpolation::create( | 238 LegacyStyleInterpolation::create( |
297 AnimatableValue::takeConstRef(start), | 239 AnimatableValue::takeConstRef(start), |
298 AnimatableValue::takeConstRef(end), iter->key), | 240 AnimatableValue::takeConstRef(end), iter->key), |
299 keyframes[i]->easing(), keyframes[i]->offset(), keyframes[i+1]->
offset(), applyFrom, applyTo); | 241 keyframes[i]->easing(), keyframes[i]->offset(), keyframes[i + 1]
->offset(), applyFrom, applyTo); |
300 } | 242 } |
301 } | 243 } |
302 } | 244 } |
303 | 245 |
304 KeyframeEffectModel::PropertySpecificKeyframe::PropertySpecificKeyframe(double o
ffset, PassRefPtr<TimingFunction> easing, const AnimatableValue* value, Composit
eOperation composite) | 246 KeyframeEffectModel::PropertySpecificKeyframe::PropertySpecificKeyframe(double o
ffset, PassRefPtr<TimingFunction> easing, const AnimatableValue* value, Composit
eOperation composite) |
305 : m_offset(offset) | 247 : m_offset(offset) |
306 , m_easing(easing) | 248 , m_easing(easing) |
307 , m_value(composite == AnimationEffect::CompositeReplace ? | |
308 AnimatableValue::takeConstRef(value) : | |
309 static_cast<PassRefPtr<CompositableValue> >(AddCompositableValue::create
(value))) | |
310 { | 249 { |
| 250 ASSERT(composite == AnimationEffect::CompositeReplace); |
| 251 m_value = AnimatableValue::takeConstRef(value); |
311 } | 252 } |
312 | 253 |
313 KeyframeEffectModel::PropertySpecificKeyframe::PropertySpecificKeyframe(double o
ffset, PassRefPtr<TimingFunction> easing, PassRefPtr<CompositableValue> value) | 254 KeyframeEffectModel::PropertySpecificKeyframe::PropertySpecificKeyframe(double o
ffset, PassRefPtr<TimingFunction> easing, PassRefPtr<AnimatableValue> value) |
314 : m_offset(offset) | 255 : m_offset(offset) |
315 , m_easing(easing) | 256 , m_easing(easing) |
316 , m_value(value) | 257 , m_value(value) |
317 { | 258 { |
318 ASSERT(!isNull(m_offset)); | 259 ASSERT(!isNull(m_offset)); |
319 } | 260 } |
320 | 261 |
321 PassOwnPtr<KeyframeEffectModel::PropertySpecificKeyframe> KeyframeEffectModel::P
ropertySpecificKeyframe::cloneWithOffset(double offset) const | 262 PassOwnPtr<KeyframeEffectModel::PropertySpecificKeyframe> KeyframeEffectModel::P
ropertySpecificKeyframe::cloneWithOffset(double offset) const |
322 { | 263 { |
323 return adoptPtr(new PropertySpecificKeyframe(offset, m_easing, PassRefPtr<Co
mpositableValue>(m_value))); | 264 return adoptPtr(new PropertySpecificKeyframe(offset, m_easing, m_value)); |
324 } | 265 } |
325 | 266 |
326 | 267 |
327 void KeyframeEffectModel::PropertySpecificKeyframeGroup::appendKeyframe(PassOwnP
tr<PropertySpecificKeyframe> keyframe) | 268 void KeyframeEffectModel::PropertySpecificKeyframeGroup::appendKeyframe(PassOwnP
tr<PropertySpecificKeyframe> keyframe) |
328 { | 269 { |
329 ASSERT(m_keyframes.isEmpty() || m_keyframes.last()->offset() <= keyframe->of
fset()); | 270 ASSERT(m_keyframes.isEmpty() || m_keyframes.last()->offset() <= keyframe->of
fset()); |
330 m_keyframes.append(keyframe); | 271 m_keyframes.append(keyframe); |
331 } | 272 } |
332 | 273 |
333 void KeyframeEffectModel::PropertySpecificKeyframeGroup::removeRedundantKeyframe
s() | 274 void KeyframeEffectModel::PropertySpecificKeyframeGroup::removeRedundantKeyframe
s() |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
368 else | 309 else |
369 m_keyframes.insert(0, adoptPtr(new PropertySpecificKeyframe(0.0, nullptr
, AnimatableValue::neutralValue(), CompositeAdd))); | 310 m_keyframes.insert(0, adoptPtr(new PropertySpecificKeyframe(0.0, nullptr
, AnimatableValue::neutralValue(), CompositeAdd))); |
370 } | 311 } |
371 | 312 |
372 void KeyframeEffectModel::trace(Visitor* visitor) | 313 void KeyframeEffectModel::trace(Visitor* visitor) |
373 { | 314 { |
374 visitor->trace(m_keyframes); | 315 visitor->trace(m_keyframes); |
375 } | 316 } |
376 | 317 |
377 } // namespace | 318 } // namespace |
OLD | NEW |