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 20 matching lines...) Expand all Loading... |
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 { | 37 namespace { |
38 | 38 |
39 using namespace WebCore; | 39 using namespace WebCore; |
40 | 40 |
41 class ReplaceCompositableValue : public AnimationEffect::CompositableValue { | |
42 public: | |
43 static PassRefPtr<ReplaceCompositableValue> create(const AnimatableValue* va
lue) | |
44 { | |
45 return adoptRef(new ReplaceCompositableValue(value)); | |
46 } | |
47 virtual bool dependsOnUnderlyingValue() const | |
48 { | |
49 return false; | |
50 } | |
51 virtual PassRefPtr<AnimatableValue> compositeOnto(const AnimatableValue* und
erlyingValue) const | |
52 { | |
53 return PassRefPtr<AnimatableValue>(m_value); | |
54 } | |
55 private: | |
56 ReplaceCompositableValue(const AnimatableValue* value) | |
57 : m_value(const_cast<AnimatableValue*>(value)) | |
58 { | |
59 } | |
60 RefPtr<AnimatableValue> m_value; | |
61 }; | |
62 | |
63 class AddCompositableValue : public AnimationEffect::CompositableValue { | 41 class AddCompositableValue : public AnimationEffect::CompositableValue { |
64 public: | 42 public: |
65 static PassRefPtr<AddCompositableValue> create(const AnimatableValue* value) | 43 static PassRefPtr<AddCompositableValue> create(const AnimatableValue* value) |
66 { | 44 { |
67 return adoptRef(new AddCompositableValue(value)); | 45 return adoptRef(new AddCompositableValue(value)); |
68 } | 46 } |
69 virtual bool dependsOnUnderlyingValue() const | 47 virtual bool dependsOnUnderlyingValue() const |
70 { | 48 { |
71 return true; | 49 return true; |
72 } | 50 } |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 result = m_keyframes[0]->properties(); | 152 result = m_keyframes[0]->properties(); |
175 for (size_t i = 1; i < m_keyframes.size(); i++) { | 153 for (size_t i = 1; i < m_keyframes.size(); i++) { |
176 PropertySet extras = m_keyframes[i]->properties(); | 154 PropertySet extras = m_keyframes[i]->properties(); |
177 for (PropertySet::const_iterator it = extras.begin(); it != extras.end()
; ++it) { | 155 for (PropertySet::const_iterator it = extras.begin(); it != extras.end()
; ++it) { |
178 result.add(*it); | 156 result.add(*it); |
179 } | 157 } |
180 } | 158 } |
181 return result; | 159 return result; |
182 } | 160 } |
183 | 161 |
184 PassOwnPtr<AnimationEffect::CompositableValueList> KeyframeEffectModel::sample(i
nt iteration, double fraction) const | 162 PassOwnPtr<Vector<RefPtr<Interpolation> > > KeyframeEffectModel::sample(int iter
ation, double fraction) const |
185 { | 163 { |
186 ASSERT(iteration >= 0); | 164 ASSERT(iteration >= 0); |
187 ASSERT(!isNull(fraction)); | 165 ASSERT(!isNull(fraction)); |
188 const_cast<KeyframeEffectModel*>(this)->ensureKeyframeGroups(); | 166 ensureKeyframeGroups(); |
189 OwnPtr<CompositableValueList> map = adoptPtr(new CompositableValueList()); | 167 ensureInterpolationEffect(); |
190 for (KeyframeGroupMap::const_iterator iter = m_keyframeGroups->begin(); iter
!= m_keyframeGroups->end(); ++iter) | 168 |
191 map->append(std::make_pair(iter->key, iter->value->sample(iteration, fra
ction))); | 169 return m_interpolationEffect->getActiveInterpolations(fraction); |
192 return map.release(); | |
193 } | 170 } |
194 | 171 |
195 KeyframeEffectModel::KeyframeVector KeyframeEffectModel::normalizedKeyframes() c
onst | 172 KeyframeEffectModel::KeyframeVector KeyframeEffectModel::normalizedKeyframes() c
onst |
196 { | 173 { |
197 KeyframeVector keyframes = getFrames(); | 174 KeyframeVector keyframes = getFrames(); |
198 | 175 |
199 // Set offsets at 0.0 and 1.0 at ends if unset. | 176 // Set offsets at 0.0 and 1.0 at ends if unset. |
200 if (keyframes.size() >= 2) { | 177 if (keyframes.size() >= 2) { |
201 Keyframe* firstKeyframe = keyframes.first().get(); | 178 Keyframe* firstKeyframe = keyframes.first().get(); |
202 if (isNull(firstKeyframe->offset())) | 179 if (isNull(firstKeyframe->offset())) |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 } | 217 } |
241 } | 218 } |
242 | 219 |
243 // Add synthetic keyframes. | 220 // Add synthetic keyframes. |
244 for (KeyframeGroupMap::iterator iter = m_keyframeGroups->begin(); iter != m_
keyframeGroups->end(); ++iter) { | 221 for (KeyframeGroupMap::iterator iter = m_keyframeGroups->begin(); iter != m_
keyframeGroups->end(); ++iter) { |
245 iter->value->addSyntheticKeyframeIfRequired(); | 222 iter->value->addSyntheticKeyframeIfRequired(); |
246 iter->value->removeRedundantKeyframes(); | 223 iter->value->removeRedundantKeyframes(); |
247 } | 224 } |
248 } | 225 } |
249 | 226 |
| 227 void KeyframeEffectModel::ensureInterpolationEffect() const |
| 228 { |
| 229 if (m_interpolationEffect) |
| 230 return; |
| 231 m_interpolationEffect = InterpolationEffect::create(); |
| 232 |
| 233 for (KeyframeGroupMap::const_iterator iter = m_keyframeGroups->begin(); iter
!= m_keyframeGroups->end(); ++iter) |
| 234 { |
| 235 const PropertySpecificKeyframeVector& keyframes = iter->value->keyframes
(); |
| 236 ASSERT(keyframes[0]->value()->isAnimatableValue()); |
| 237 const AnimatableValue* start; |
| 238 const AnimatableValue* end = toAnimatableValue(keyframes[0]->value()); |
| 239 for (size_t i = 0; i < keyframes.size() - 1; i++) { |
| 240 ASSERT(keyframes[i+1]->value()->isAnimatableValue()); |
| 241 start = end; |
| 242 end = toAnimatableValue(keyframes[i+1]->value()); |
| 243 m_interpolationEffect->addInterpolation( |
| 244 LegacyStyleInterpolation::create( |
| 245 AnimatableValue::takeConstRef(start), |
| 246 AnimatableValue::takeConstRef(end), iter->key), |
| 247 keyframes[i]->offset(), keyframes[i+1]->offset()); |
| 248 } |
| 249 } |
| 250 } |
250 | 251 |
251 KeyframeEffectModel::PropertySpecificKeyframe::PropertySpecificKeyframe(double o
ffset, const AnimatableValue* value, CompositeOperation composite) | 252 KeyframeEffectModel::PropertySpecificKeyframe::PropertySpecificKeyframe(double o
ffset, const AnimatableValue* value, CompositeOperation composite) |
252 : m_offset(offset) | 253 : m_offset(offset) |
253 , m_value(composite == AnimationEffect::CompositeReplace ? | 254 , m_value(composite == AnimationEffect::CompositeReplace ? |
254 static_cast<PassRefPtr<CompositableValue> >(ReplaceCompositableValue::cr
eate(value)) : | 255 AnimatableValue::takeConstRef(value) : |
255 static_cast<PassRefPtr<CompositableValue> >(AddCompositableValue::create
(value))) | 256 static_cast<PassRefPtr<CompositableValue> >(AddCompositableValue::create
(value))) |
256 { | 257 { |
257 } | 258 } |
258 | 259 |
259 KeyframeEffectModel::PropertySpecificKeyframe::PropertySpecificKeyframe(double o
ffset, PassRefPtr<CompositableValue> value) | 260 KeyframeEffectModel::PropertySpecificKeyframe::PropertySpecificKeyframe(double o
ffset, PassRefPtr<CompositableValue> value) |
260 : m_offset(offset) | 261 : m_offset(offset) |
261 , m_value(value) | 262 , m_value(value) |
262 { | 263 { |
263 ASSERT(!isNull(m_offset)); | 264 ASSERT(!isNull(m_offset)); |
264 } | 265 } |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
357 | 358 |
358 if ((*before)->offset() == offset) | 359 if ((*before)->offset() == offset) |
359 return const_cast<CompositableValue*>((*before)->value()); | 360 return const_cast<CompositableValue*>((*before)->value()); |
360 if ((*after)->offset() == offset) | 361 if ((*after)->offset() == offset) |
361 return const_cast<CompositableValue*>((*after)->value()); | 362 return const_cast<CompositableValue*>((*after)->value()); |
362 return BlendedCompositableValue::create((*before)->value(), (*after)->value(
), | 363 return BlendedCompositableValue::create((*before)->value(), (*after)->value(
), |
363 (offset - (*before)->offset()) / ((*after)->offset() - (*before)->offset
())); | 364 (offset - (*before)->offset()) / ((*after)->offset() - (*before)->offset
())); |
364 } | 365 } |
365 | 366 |
366 } // namespace | 367 } // namespace |
OLD | NEW |