Home | History | Annotate | Download | only in animation
      1 // Copyright 2014 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #ifndef Keyframe_h
      6 #define Keyframe_h
      7 
      8 #include "core/CSSPropertyNames.h"
      9 #include "core/animation/AnimatableValue.h"
     10 #include "core/animation/AnimationEffect.h"
     11 #include "core/animation/AnimationNode.h"
     12 
     13 namespace WebCore {
     14 
     15 typedef HashSet<CSSPropertyID> PropertySet;
     16 
     17 class Element;
     18 
     19 // FIXME: Make Keyframe immutable
     20 class Keyframe : public RefCountedWillBeGarbageCollectedFinalized<Keyframe> {
     21 public:
     22     virtual ~Keyframe() { }
     23 
     24     void setOffset(double offset) { m_offset = offset; }
     25     double offset() const { return m_offset; }
     26 
     27     void setComposite(AnimationEffect::CompositeOperation composite) { m_composite = composite; }
     28     AnimationEffect::CompositeOperation composite() const { return m_composite; }
     29 
     30     void setEasing(PassRefPtr<TimingFunction> easing) { m_easing = easing; }
     31     TimingFunction* easing() const { return m_easing.get(); }
     32 
     33     static bool compareOffsets(const RefPtrWillBeMember<Keyframe>& a, const RefPtrWillBeMember<Keyframe>& b)
     34     {
     35         return a->offset() < b->offset();
     36     }
     37 
     38     virtual PropertySet properties() const = 0;
     39 
     40     virtual PassRefPtrWillBeRawPtr<Keyframe> clone() const = 0;
     41     PassRefPtrWillBeRawPtr<Keyframe> cloneWithOffset(double offset) const
     42     {
     43         RefPtrWillBeRawPtr<Keyframe> theClone = clone();
     44         theClone->setOffset(offset);
     45         return theClone.release();
     46     }
     47 
     48     virtual bool isAnimatableValueKeyframe() const { return false; }
     49     virtual bool isStringKeyframe() const { return false; }
     50 
     51     virtual void trace(Visitor*) { }
     52 
     53     class PropertySpecificKeyframe : public NoBaseWillBeGarbageCollectedFinalized<PropertySpecificKeyframe> {
     54     public:
     55         virtual ~PropertySpecificKeyframe() { }
     56         double offset() const { return m_offset; }
     57         TimingFunction* easing() const { return m_easing.get(); }
     58         AnimationEffect::CompositeOperation composite() const { return m_composite; }
     59         virtual PassOwnPtrWillBeRawPtr<PropertySpecificKeyframe> cloneWithOffset(double offset) const = 0;
     60 
     61         virtual const PassRefPtrWillBeRawPtr<AnimatableValue> getAnimatableValue() const = 0;
     62 
     63         virtual bool isAnimatableValuePropertySpecificKeyframe() const { return false; }
     64         virtual bool isStringPropertySpecificKeyframe() const { return false; }
     65 
     66         virtual PassOwnPtrWillBeRawPtr<PropertySpecificKeyframe> neutralKeyframe(double offset, PassRefPtr<TimingFunction> easing) const = 0;
     67         virtual PassRefPtrWillBeRawPtr<Interpolation> createInterpolation(CSSPropertyID, WebCore::Keyframe::PropertySpecificKeyframe* end, Element*) const = 0;
     68 
     69         virtual void trace(Visitor*) { }
     70 
     71     protected:
     72         PropertySpecificKeyframe(double offset, PassRefPtr<TimingFunction> easing, AnimationEffect::CompositeOperation);
     73 
     74         double m_offset;
     75         RefPtr<TimingFunction> m_easing;
     76         AnimationEffect::CompositeOperation m_composite;
     77     };
     78 
     79     virtual PassOwnPtrWillBeRawPtr<PropertySpecificKeyframe> createPropertySpecificKeyframe(CSSPropertyID) const = 0;
     80 
     81 protected:
     82     Keyframe()
     83         : m_offset(nullValue())
     84         , m_composite(AnimationEffect::CompositeReplace)
     85         , m_easing(LinearTimingFunction::shared())
     86     {
     87     }
     88     Keyframe(double offset, AnimationEffect::CompositeOperation composite, PassRefPtr<TimingFunction> easing)
     89         : m_offset(offset)
     90         , m_composite(composite)
     91         , m_easing(easing)
     92     {
     93     }
     94 
     95     double m_offset;
     96     AnimationEffect::CompositeOperation m_composite;
     97     RefPtr<TimingFunction> m_easing;
     98 };
     99 
    100 }
    101 
    102 #endif
    103