Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(22)

Side by Side Diff: Source/core/animation/KeyframeEffectModel.h

Issue 194733002: Web Animations: Use StringKeyframes for element.animate() (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 18 matching lines...) Expand all
29 */ 29 */
30 30
31 #ifndef KeyframeEffectModel_h 31 #ifndef KeyframeEffectModel_h
32 #define KeyframeEffectModel_h 32 #define KeyframeEffectModel_h
33 33
34 #include "core/animation/AnimatableDouble.h" 34 #include "core/animation/AnimatableDouble.h"
35 #include "core/animation/AnimatableValue.h" 35 #include "core/animation/AnimatableValue.h"
36 #include "core/animation/AnimationEffect.h" 36 #include "core/animation/AnimationEffect.h"
37 #include "core/animation/InterpolationEffect.h" 37 #include "core/animation/InterpolationEffect.h"
38 #include "core/animation/TimedItem.h" 38 #include "core/animation/TimedItem.h"
39 #include "core/dom/Element.h"
40 #include "core/rendering/style/RenderStyle.h"
41 #include "core/rendering/style/StyleInheritedData.h"
39 #include "heap/Handle.h" 42 #include "heap/Handle.h"
40 #include "platform/animation/TimingFunction.h" 43 #include "platform/animation/TimingFunction.h"
41 #include "wtf/HashMap.h" 44 #include "wtf/HashMap.h"
42 #include "wtf/HashSet.h" 45 #include "wtf/HashSet.h"
43 #include "wtf/PassOwnPtr.h" 46 #include "wtf/PassOwnPtr.h"
44 #include "wtf/PassRefPtr.h" 47 #include "wtf/PassRefPtr.h"
45 #include "wtf/RefCounted.h" 48 #include "wtf/RefCounted.h"
46 #include "wtf/Vector.h" 49 #include "wtf/Vector.h"
47 50
48 namespace WebCore { 51 namespace WebCore {
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 return static_cast<PropertySpecificKeyframe*>(keyframe); 265 return static_cast<PropertySpecificKeyframe*>(keyframe);
263 } 266 }
264 267
265 virtual PassRefPtr<Interpolation> createInterpolation(CSSPropertyID, Keyfram eEffectModelBase::PropertySpecificKeyframe *start, KeyframeEffectModelBase::Prop ertySpecificKeyframe *end) const; 268 virtual PassRefPtr<Interpolation> createInterpolation(CSSPropertyID, Keyfram eEffectModelBase::PropertySpecificKeyframe *start, KeyframeEffectModelBase::Prop ertySpecificKeyframe *end) const;
266 269
267 private: 270 private:
268 AVKeyframeEffectModel(const KeyframeVector& keyframes) 271 AVKeyframeEffectModel(const KeyframeVector& keyframes)
269 { 272 {
270 m_keyframes.appendVector(keyframes); 273 m_keyframes.appendVector(keyframes);
271 } 274 }
272
273 AVKeyframeEffectModel(PassRefPtr<InterpolationEffect>);
274 }; 275 };
275 276
276 277
277 class SKeyframeEffectModel FINAL : public KeyframeEffectModelBase { 278 class SKeyframeEffectModel FINAL : public KeyframeEffectModelBase {
278 public: 279 public:
279 class Keyframe : public KeyframeEffectModelBase::Keyframe { 280 class Keyframe : public KeyframeEffectModelBase::Keyframe {
280 public: 281 public:
281 static PassRefPtr<Keyframe> create() 282 static PassRefPtr<Keyframe> create()
282 { 283 {
283 return adoptRef(new Keyframe); 284 return adoptRef(new Keyframe);
284 } 285 }
285 void setPropertyValue(CSSPropertyID property, const String& value) 286
287 // This string setter will accept shorthand properties and expand them i nternally.
288 void setPropertyValue(CSSPropertyID, const String& value);
289 void setPropertyValue(CSSPropertyID property, PassRefPtr<CSSValue> value )
286 { 290 {
287 m_propertyValues.add(property, value); 291 m_propertyValues.add(property, value);
288 } 292 }
289 void clearPropertyValue(CSSPropertyID property) { m_propertyValues.remov e(property); } 293 void clearPropertyValue(CSSPropertyID property) { m_propertyValues.remov e(property); }
290 String propertyValue(CSSPropertyID property) const 294 CSSValue* propertyValue(CSSPropertyID property) const
291 { 295 {
292 ASSERT(m_propertyValues.contains(property)); 296 ASSERT(m_propertyValues.contains(property));
293 return m_propertyValues.get(property); 297 return m_propertyValues.get(property);
294 } 298 }
295 299
296 virtual PropertySet properties() const 300 virtual PropertySet properties() const
297 { 301 {
298 // This is not used in time-critical code, so we probably don't need to 302 // This is not used in time-critical code, so we probably don't need to
299 // worry about caching this result. 303 // worry about caching this result.
300 PropertySet properties; 304 PropertySet properties;
(...skipping 12 matching lines...) Expand all
313 Keyframe() 317 Keyframe()
314 : KeyframeEffectModelBase::Keyframe() 318 : KeyframeEffectModelBase::Keyframe()
315 { } 319 { }
316 Keyframe(const Keyframe& copyFrom) 320 Keyframe(const Keyframe& copyFrom)
317 : KeyframeEffectModelBase::Keyframe(copyFrom.m_offset, copyFrom.m_co mposite, copyFrom.m_easing) 321 : KeyframeEffectModelBase::Keyframe(copyFrom.m_offset, copyFrom.m_co mposite, copyFrom.m_easing)
318 { 322 {
319 for (typename PropertyValueMap::const_iterator iter = copyFrom.m_pro pertyValues.begin(); iter != copyFrom.m_propertyValues.end(); ++iter) 323 for (typename PropertyValueMap::const_iterator iter = copyFrom.m_pro pertyValues.begin(); iter != copyFrom.m_propertyValues.end(); ++iter)
320 setPropertyValue(iter->key, iter->value); 324 setPropertyValue(iter->key, iter->value);
321 } 325 }
322 326
323 typedef HashMap<CSSPropertyID, String> PropertyValueMap; 327 typedef HashMap<CSSPropertyID, RefPtr<CSSValue> > PropertyValueMap;
324 PropertyValueMap m_propertyValues; 328 PropertyValueMap m_propertyValues;
325 }; 329 };
326 330
327 typedef WillBeHeapVector<RefPtrWillBeMember<Keyframe> > KeyframeVector; 331 typedef WillBeHeapVector<RefPtrWillBeMember<Keyframe> > KeyframeVector;
328 // FIXME: Implement accumulation. 332 // FIXME: Implement accumulation.
329 static PassRefPtrWillBeRawPtr<SKeyframeEffectModel > create(const KeyframeVe ctor& keyframes) 333 static PassRefPtrWillBeRawPtr<SKeyframeEffectModel > create(Element& element , const KeyframeVector& keyframes)
330 { 334 {
331 return adoptRefWillBeNoop(new SKeyframeEffectModel(keyframes)); 335 return adoptRefWillBeNoop(new SKeyframeEffectModel(element, keyframes));
332 } 336 }
333 337
334 virtual bool affects(CSSPropertyID property) OVERRIDE 338 virtual bool affects(CSSPropertyID property) OVERRIDE
335 { 339 {
336 ensureKeyframeGroups(); 340 ensureKeyframeGroups();
337 return m_keyframeGroups->contains(property); 341 return m_keyframeGroups->contains(property);
338 } 342 }
339 343
340 // Represents the keyframes set through the API. 344 // Represents the keyframes set through the API.
341 class PropertySpecificKeyframe : public KeyframeEffectModelBase::PropertySpe cificKeyframe { 345 class PropertySpecificKeyframe : public KeyframeEffectModelBase::PropertySpe cificKeyframe {
342 public: 346 public:
343 PropertySpecificKeyframe(double offset, PassRefPtr<TimingFunction> easin g, const String& value, CompositeOperation op) 347 PropertySpecificKeyframe(double offset, PassRefPtr<TimingFunction> easin g, PassRefPtr<CSSValue> value, CompositeOperation op)
344 : KeyframeEffectModelBase::PropertySpecificKeyframe(offset, easing, op) 348 : KeyframeEffectModelBase::PropertySpecificKeyframe(offset, easing, op)
345 , m_value(value) 349 , m_value(value)
346 { } 350 { }
347 351
348 const String& value() const { return m_value; } 352 CSSValue* value() const { return m_value.get(); }
349 353
350 virtual PassOwnPtr<KeyframeEffectModelBase::PropertySpecificKeyframe> cl oneWithOffset(double offset) const 354 virtual PassOwnPtr<KeyframeEffectModelBase::PropertySpecificKeyframe> cl oneWithOffset(double offset) const
351 { 355 {
352 KeyframeEffectModelBase::PropertySpecificKeyframe *theClone = new Pr opertySpecificKeyframe(offset, m_easing, m_value); 356 KeyframeEffectModelBase::PropertySpecificKeyframe *theClone = new Pr opertySpecificKeyframe(offset, m_easing, m_value);
353 return adoptPtr(theClone); 357 return adoptPtr(theClone);
354 } 358 }
355 359
356 private: 360 private:
357 361
358 // Used by cloneWithOffset(). 362 // Used by cloneWithOffset().
359 PropertySpecificKeyframe(double offset, PassRefPtr<TimingFunction> easin g, const String& value) 363 PropertySpecificKeyframe(double offset, PassRefPtr<TimingFunction> easin g, PassRefPtr<CSSValue> value)
360 : KeyframeEffectModelBase::PropertySpecificKeyframe(offset, easing, AnimationEffect::CompositeReplace) 364 : KeyframeEffectModelBase::PropertySpecificKeyframe(offset, easing, AnimationEffect::CompositeReplace)
361 , m_value(value) 365 , m_value(value)
362 { 366 {
363 ASSERT(!isNull(m_offset)); 367 ASSERT(!isNull(m_offset));
364 } 368 }
365 String m_value; 369 RefPtr<CSSValue> m_value;
366 }; 370 };
367 371
368 virtual PassOwnPtr<KeyframeEffectModelBase::PropertySpecificKeyframe> neutra lKeyframe(double offset, PassRefPtr<TimingFunction> easing) const; 372 virtual PassOwnPtr<KeyframeEffectModelBase::PropertySpecificKeyframe> neutra lKeyframe(double offset, PassRefPtr<TimingFunction> easing) const;
369 373
370 static PropertySpecificKeyframe* toPropertySpecificKeyframe(KeyframeEffectMo delBase::PropertySpecificKeyframe* keyframe) 374 static PropertySpecificKeyframe* toPropertySpecificKeyframe(KeyframeEffectMo delBase::PropertySpecificKeyframe* keyframe)
371 { 375 {
372 return static_cast<PropertySpecificKeyframe*>(keyframe); 376 return static_cast<PropertySpecificKeyframe*>(keyframe);
373 } 377 }
374 378
375 virtual PassRefPtr<Interpolation> createInterpolation(CSSPropertyID, Keyfram eEffectModelBase::PropertySpecificKeyframe *start, KeyframeEffectModelBase::Prop ertySpecificKeyframe *end) const; 379 virtual PassRefPtr<Interpolation> createInterpolation(CSSPropertyID, Keyfram eEffectModelBase::PropertySpecificKeyframe *start, KeyframeEffectModelBase::Prop ertySpecificKeyframe *end) const;
376 380
377 private: 381 private:
378 SKeyframeEffectModel(const KeyframeVector& keyframes) 382 SKeyframeEffectModel(Element& element, const KeyframeVector& keyframes)
383 : m_element(&element)
384 , m_renderStyle(RenderStyle::create())
379 { 385 {
380 m_keyframes.appendVector(keyframes); 386 m_keyframes.appendVector(keyframes);
381 } 387 }
382 388
383 SKeyframeEffectModel(PassRefPtr<InterpolationEffect>); 389 // FIXME: Remove the need to snapshot computed style values, this will remov e the dependency on Element and RenderStyle.
390 RefPtr<Element> m_element;
391 RefPtr<RenderStyle> m_renderStyle;
384 }; 392 };
385 393
386 DEFINE_TYPE_CASTS(KeyframeEffectModelBase, AnimationEffect, value, value->isKeyf rameEffectModel(), value.isKeyframeEffectModel()); 394 DEFINE_TYPE_CASTS(KeyframeEffectModelBase, AnimationEffect, value, value->isKeyf rameEffectModel(), value.isKeyframeEffectModel());
387 395
388 typedef KeyframeEffectModelBase::Keyframe Keyframe; 396 typedef KeyframeEffectModelBase::Keyframe Keyframe;
389 typedef KeyframeEffectModelBase::KeyframeVector KeyframeVector; 397 typedef KeyframeEffectModelBase::KeyframeVector KeyframeVector;
390 typedef KeyframeEffectModelBase::PropertySpecificKeyframeVector PropertySpecific KeyframeVector; 398 typedef KeyframeEffectModelBase::PropertySpecificKeyframeVector PropertySpecific KeyframeVector;
391 399
392 typedef AVKeyframeEffectModel::Keyframe AVKeyframe; 400 typedef AVKeyframeEffectModel::Keyframe AVKeyframe;
393 typedef AVKeyframeEffectModel::KeyframeVector AVKeyframeVector; 401 typedef AVKeyframeEffectModel::KeyframeVector AVKeyframeVector;
(...skipping 13 matching lines...) Expand all
407 return static_cast<AVKeyframeEffectModel*>(effect); 415 return static_cast<AVKeyframeEffectModel*>(effect);
408 } 416 }
409 inline AVKeyframeEffectModel::Keyframe* toAVKeyframe(KeyframeEffectModelBase::Ke yframe* keyframe) 417 inline AVKeyframeEffectModel::Keyframe* toAVKeyframe(KeyframeEffectModelBase::Ke yframe* keyframe)
410 { 418 {
411 return static_cast<AVKeyframeEffectModel::Keyframe*>(keyframe); 419 return static_cast<AVKeyframeEffectModel::Keyframe*>(keyframe);
412 } 420 }
413 421
414 } // namespace WebCore 422 } // namespace WebCore
415 423
416 #endif // KeyframeEffectModel_h 424 #endif // KeyframeEffectModel_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698