| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | |
| 3 * | |
| 4 * Redistribution and use in source and binary forms, with or without | |
| 5 * modification, are permitted provided that the following conditions are | |
| 6 * met: | |
| 7 * | |
| 8 * * Redistributions of source code must retain the above copyright | |
| 9 * notice, this list of conditions and the following disclaimer. | |
| 10 * * Redistributions in binary form must reproduce the above | |
| 11 * copyright notice, this list of conditions and the following disclaimer | |
| 12 * in the documentation and/or other materials provided with the | |
| 13 * distribution. | |
| 14 * * Neither the name of Google Inc. nor the names of its | |
| 15 * contributors may be used to endorse or promote products derived from | |
| 16 * this software without specific prior written permission. | |
| 17 * | |
| 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
| 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
| 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
| 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
| 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 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. | |
| 29 */ | |
| 30 | |
| 31 #ifndef SKY_ENGINE_CORE_ANIMATION_KEYFRAMEEFFECTMODEL_H_ | |
| 32 #define SKY_ENGINE_CORE_ANIMATION_KEYFRAMEEFFECTMODEL_H_ | |
| 33 | |
| 34 #include "sky/engine/core/animation/AnimationEffect.h" | |
| 35 #include "sky/engine/core/animation/AnimationNode.h" | |
| 36 #include "sky/engine/core/animation/InterpolationEffect.h" | |
| 37 #include "sky/engine/core/animation/StringKeyframe.h" | |
| 38 #include "sky/engine/core/animation/animatable/AnimatableValueKeyframe.h" | |
| 39 #include "sky/engine/platform/animation/TimingFunction.h" | |
| 40 #include "sky/engine/wtf/HashMap.h" | |
| 41 #include "sky/engine/wtf/PassOwnPtr.h" | |
| 42 #include "sky/engine/wtf/PassRefPtr.h" | |
| 43 #include "sky/engine/wtf/Vector.h" | |
| 44 | |
| 45 namespace blink { | |
| 46 | |
| 47 class Element; | |
| 48 class KeyframeEffectModelTest; | |
| 49 | |
| 50 class KeyframeEffectModelBase : public AnimationEffect { | |
| 51 public: | |
| 52 // FIXME: Implement accumulation. | |
| 53 | |
| 54 typedef Vector<OwnPtr<Keyframe::PropertySpecificKeyframe> > PropertySpecific
KeyframeVector; | |
| 55 class PropertySpecificKeyframeGroup { | |
| 56 public: | |
| 57 void appendKeyframe(PassOwnPtr<Keyframe::PropertySpecificKeyframe>); | |
| 58 const PropertySpecificKeyframeVector& keyframes() const { return m_keyfr
ames; } | |
| 59 | |
| 60 private: | |
| 61 void removeRedundantKeyframes(); | |
| 62 void addSyntheticKeyframeIfRequired(const KeyframeEffectModelBase* conte
xt); | |
| 63 | |
| 64 PropertySpecificKeyframeVector m_keyframes; | |
| 65 | |
| 66 friend class KeyframeEffectModelBase; | |
| 67 }; | |
| 68 | |
| 69 bool isReplaceOnly(); | |
| 70 | |
| 71 PropertySet properties() const; | |
| 72 | |
| 73 typedef Vector<RefPtr<Keyframe> > KeyframeVector; | |
| 74 const KeyframeVector& getFrames() const { return m_keyframes; } | |
| 75 // FIXME: Implement setFrames() | |
| 76 | |
| 77 const PropertySpecificKeyframeVector& getPropertySpecificKeyframes(CSSProper
tyID id) const | |
| 78 { | |
| 79 ensureKeyframeGroups(); | |
| 80 return m_keyframeGroups->get(id)->keyframes(); | |
| 81 } | |
| 82 | |
| 83 // AnimationEffect implementation. | |
| 84 virtual PassOwnPtr<Vector<RefPtr<Interpolation> > > sample(int iteration, do
uble fraction, double iterationDuration) const override; | |
| 85 | |
| 86 virtual bool isKeyframeEffectModel() const override { return true; } | |
| 87 | |
| 88 virtual bool isAnimatableValueKeyframeEffectModel() const { return false; } | |
| 89 virtual bool isStringKeyframeEffectModel() const { return false; } | |
| 90 | |
| 91 // FIXME: This is a hack used to resolve CSSValues to AnimatableValues while
we have a valid handle on an element. | |
| 92 // This should be removed once StringKeyframes no longer uses InterpolableAn
imatableValues. | |
| 93 void forceConversionsToAnimatableValues(Element* element) | |
| 94 { | |
| 95 ensureKeyframeGroups(); | |
| 96 ensureInterpolationEffect(element); | |
| 97 } | |
| 98 | |
| 99 protected: | |
| 100 static KeyframeVector normalizedKeyframes(const KeyframeVector& keyframes); | |
| 101 | |
| 102 // Lazily computes the groups of property-specific keyframes. | |
| 103 void ensureKeyframeGroups() const; | |
| 104 void ensureInterpolationEffect(Element* = 0) const; | |
| 105 | |
| 106 KeyframeVector m_keyframes; | |
| 107 // The spec describes filtering the normalized keyframes at sampling time | |
| 108 // to get the 'property-specific keyframes'. For efficiency, we cache the | |
| 109 // property-specific lists. | |
| 110 typedef HashMap<CSSPropertyID, OwnPtr<PropertySpecificKeyframeGroup> > Keyfr
ameGroupMap; | |
| 111 mutable OwnPtr<KeyframeGroupMap> m_keyframeGroups; | |
| 112 mutable RefPtr<InterpolationEffect> m_interpolationEffect; | |
| 113 | |
| 114 friend class KeyframeEffectModelTest; | |
| 115 | |
| 116 bool affects(CSSPropertyID property) | |
| 117 { | |
| 118 ensureKeyframeGroups(); | |
| 119 return m_keyframeGroups->contains(property); | |
| 120 } | |
| 121 }; | |
| 122 | |
| 123 template <class Keyframe> | |
| 124 class KeyframeEffectModel final : public KeyframeEffectModelBase { | |
| 125 public: | |
| 126 typedef Vector<RefPtr<Keyframe> > KeyframeVector; | |
| 127 static PassRefPtr<KeyframeEffectModel<Keyframe> > create(const KeyframeVecto
r& keyframes) { return adoptRef(new KeyframeEffectModel(keyframes)); } | |
| 128 | |
| 129 private: | |
| 130 KeyframeEffectModel(const KeyframeVector& keyframes) | |
| 131 { | |
| 132 m_keyframes.appendVector(keyframes); | |
| 133 } | |
| 134 | |
| 135 virtual bool isAnimatableValueKeyframeEffectModel() const { return false; } | |
| 136 virtual bool isStringKeyframeEffectModel() const { return false; } | |
| 137 | |
| 138 }; | |
| 139 | |
| 140 typedef KeyframeEffectModelBase::KeyframeVector KeyframeVector; | |
| 141 typedef KeyframeEffectModelBase::PropertySpecificKeyframeVector PropertySpecific
KeyframeVector; | |
| 142 | |
| 143 typedef KeyframeEffectModel<AnimatableValueKeyframe> AnimatableValueKeyframeEffe
ctModel; | |
| 144 typedef AnimatableValueKeyframeEffectModel::KeyframeVector AnimatableValueKeyfra
meVector; | |
| 145 typedef AnimatableValueKeyframeEffectModel::PropertySpecificKeyframeVector Anima
tableValuePropertySpecificKeyframeVector; | |
| 146 | |
| 147 typedef KeyframeEffectModel<StringKeyframe> StringKeyframeEffectModel; | |
| 148 typedef StringKeyframeEffectModel::KeyframeVector StringKeyframeVector; | |
| 149 typedef StringKeyframeEffectModel::PropertySpecificKeyframeVector StringProperty
SpecificKeyframeVector; | |
| 150 | |
| 151 DEFINE_TYPE_CASTS(KeyframeEffectModelBase, AnimationEffect, value, value->isKeyf
rameEffectModel(), value.isKeyframeEffectModel()); | |
| 152 DEFINE_TYPE_CASTS(AnimatableValueKeyframeEffectModel, KeyframeEffectModelBase, v
alue, value->isAnimatableValueKeyframeEffectModel(), value.isAnimatableValueKeyf
rameEffectModel()); | |
| 153 | |
| 154 inline const AnimatableValueKeyframeEffectModel* toAnimatableValueKeyframeEffect
Model(const AnimationEffect* base) | |
| 155 { | |
| 156 return toAnimatableValueKeyframeEffectModel(toKeyframeEffectModelBase(base))
; | |
| 157 } | |
| 158 | |
| 159 inline AnimatableValueKeyframeEffectModel* toAnimatableValueKeyframeEffectModel(
AnimationEffect* base) | |
| 160 { | |
| 161 return toAnimatableValueKeyframeEffectModel(toKeyframeEffectModelBase(base))
; | |
| 162 } | |
| 163 | |
| 164 template <> | |
| 165 inline bool KeyframeEffectModel<AnimatableValueKeyframe>::isAnimatableValueKeyfr
ameEffectModel() const { return true; } | |
| 166 | |
| 167 template <> | |
| 168 inline bool KeyframeEffectModel<StringKeyframe>::isStringKeyframeEffectModel() c
onst { return true; } | |
| 169 | |
| 170 } // namespace blink | |
| 171 | |
| 172 #endif // SKY_ENGINE_CORE_ANIMATION_KEYFRAMEEFFECTMODEL_H_ | |
| OLD | NEW |