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 Animation_h 32 #define Animation_h 33 34 #include "core/animation/AnimationEffect.h" 35 #include "core/animation/AnimationNode.h" 36 #include "core/animation/EffectInput.h" 37 #include "core/animation/TimingInput.h" 38 #include "platform/heap/Handle.h" 39 #include "wtf/RefPtr.h" 40 41 namespace blink { 42 43 class Dictionary; 44 class Element; 45 class ExceptionState; 46 class SampledEffect; 47 48 class Animation FINAL : public AnimationNode { 49 DEFINE_WRAPPERTYPEINFO(); 50 public: 51 enum Priority { DefaultPriority, TransitionPriority }; 52 53 static PassRefPtrWillBeRawPtr<Animation> create(Element*, PassRefPtrWillBeRawPtr<AnimationEffect>, const Timing&, Priority = DefaultPriority, PassOwnPtrWillBeRawPtr<EventDelegate> = nullptr); 54 // Web Animations API Bindings constructors. 55 static PassRefPtrWillBeRawPtr<Animation> create(Element*, PassRefPtrWillBeRawPtr<AnimationEffect>, const Dictionary& timingInputDictionary); 56 static PassRefPtrWillBeRawPtr<Animation> create(Element*, PassRefPtrWillBeRawPtr<AnimationEffect>, double duration); 57 static PassRefPtrWillBeRawPtr<Animation> create(Element*, PassRefPtrWillBeRawPtr<AnimationEffect>); 58 static PassRefPtrWillBeRawPtr<Animation> create(Element*, const Vector<Dictionary>& keyframeDictionaryVector, const Dictionary& timingInputDictionary, ExceptionState&); 59 static PassRefPtrWillBeRawPtr<Animation> create(Element*, const Vector<Dictionary>& keyframeDictionaryVector, double duration, ExceptionState&); 60 static PassRefPtrWillBeRawPtr<Animation> create(Element*, const Vector<Dictionary>& keyframeDictionaryVector, ExceptionState&); 61 62 virtual ~Animation(); 63 isAnimation()64 virtual bool isAnimation() const OVERRIDE { return true; } 65 66 bool affects(CSSPropertyID) const; effect()67 const AnimationEffect* effect() const { return m_effect.get(); } effect()68 AnimationEffect* effect() { return m_effect.get(); } priority()69 Priority priority() const { return m_priority; } target()70 Element* target() { return m_target; } 71 72 void notifySampledEffectRemovedFromAnimationStack(); 73 #if !ENABLE(OILPAN) 74 void notifyElementDestroyed(); 75 #endif 76 77 bool isCandidateForAnimationOnCompositor(double playerPlaybackRate) const; 78 // Must only be called once. 79 bool maybeStartAnimationOnCompositor(double startTime, double timeOffset); 80 bool maybeStartAnimationOnCompositor(double startTime, double timeOffset, double playerPlaybackRate); 81 bool hasActiveAnimationsOnCompositor() const; 82 bool hasActiveAnimationsOnCompositor(CSSPropertyID) const; 83 void cancelAnimationOnCompositor(); 84 void pauseAnimationForTestingOnCompositor(double pauseTime); 85 86 virtual void trace(Visitor*); 87 88 protected: 89 void applyEffects(); 90 void clearEffects(); 91 virtual void updateChildrenAndEffects() const OVERRIDE; 92 virtual void attach(AnimationPlayer*) OVERRIDE; 93 virtual void detach() OVERRIDE; 94 virtual void specifiedTimingChanged() OVERRIDE; 95 virtual double calculateTimeToEffectChange(bool forwards, double inheritedTime, double timeToNextIteration) const OVERRIDE; 96 97 private: 98 Animation(Element*, PassRefPtrWillBeRawPtr<AnimationEffect>, const Timing&, Priority, PassOwnPtrWillBeRawPtr<EventDelegate>); 99 100 RawPtrWillBeMember<Element> m_target; 101 RefPtrWillBeMember<AnimationEffect> m_effect; 102 RawPtrWillBeMember<SampledEffect> m_sampledEffect; 103 104 Priority m_priority; 105 106 Vector<int> m_compositorAnimationIds; 107 108 friend class AnimationAnimationV8Test; 109 }; 110 111 DEFINE_TYPE_CASTS(Animation, AnimationNode, animationNode, animationNode->isAnimation(), animationNode.isAnimation()); 112 113 } // namespace blink 114 115 #endif // Animation_h 116