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