1/* 2 Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies) 3 4 This library is free software; you can redistribute it and/or 5 modify it under the terms of the GNU Library General Public 6 License as published by the Free Software Foundation; either 7 version 2 of the License, or (at your option) any later version. 8 9 This library is distributed in the hope that it will be useful, 10 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 Library General Public License for more details. 13 14 You should have received a copy of the GNU Library General Public License 15 along with this library; see the file COPYING.LIB. If not, write to 16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 17 Boston, MA 02110-1301, USA. 18 */ 19 20#ifndef GraphicsLayerAnimation_h 21#define GraphicsLayerAnimation_h 22 23#if USE(ACCELERATED_COMPOSITING) 24 25#include "GraphicsLayer.h" 26#include "TransformationMatrix.h" 27#include <wtf/HashMap.h> 28#include <wtf/text/StringHash.h> 29 30namespace WebCore { 31 32class GraphicsLayerAnimation { 33public: 34 enum AnimationState { PlayingState, PausedState, StoppedState }; 35 class Client { 36 public: 37 virtual void setAnimatedTransform(const TransformationMatrix&) = 0; 38 virtual void setAnimatedOpacity(float) = 0; 39#if ENABLE(CSS_FILTERS) 40 virtual void setAnimatedFilters(const FilterOperations&) = 0; 41#endif 42 }; 43 44 GraphicsLayerAnimation() 45 : m_keyframes(AnimatedPropertyInvalid) 46 { } 47 GraphicsLayerAnimation(const String&, const KeyframeValueList&, const IntSize&, const Animation*, double, bool); 48 void apply(Client*); 49 void pause(double); 50 void resume(); 51 double computeTotalRunningTime(); 52 AnimationState state() const { return m_state; } 53 void setState(AnimationState s, double pauseTime = 0) 54 { 55 m_state = s; 56 m_pauseTime = pauseTime; 57 } 58 AnimatedPropertyID property() const { return m_keyframes.property(); } 59 bool isActive() const; 60 String name() const { return m_name; } 61 IntSize boxSize() const { return m_boxSize; } 62 double startTime() const { return m_startTime; } 63 double pauseTime() const { return m_pauseTime; } 64 PassRefPtr<Animation> animation() const { return m_animation.get(); } 65 const KeyframeValueList& keyframes() const { return m_keyframes; } 66 bool listsMatch() const { return m_listsMatch; } 67 68private: 69 void applyInternal(Client*, const AnimationValue& from, const AnimationValue& to, float progress); 70 KeyframeValueList m_keyframes; 71 IntSize m_boxSize; 72 RefPtr<Animation> m_animation; 73 String m_name; 74 bool m_listsMatch; 75 double m_startTime; 76 double m_pauseTime; 77 double m_totalRunningTime; 78 double m_lastRefreshedTime; 79 AnimationState m_state; 80}; 81 82class GraphicsLayerAnimations { 83public: 84 GraphicsLayerAnimations() { } 85 86 void add(const GraphicsLayerAnimation&); 87 void remove(const String& name); 88 void remove(const String& name, AnimatedPropertyID); 89 void pause(const String&, double); 90 void suspend(double); 91 void resume(); 92 void apply(GraphicsLayerAnimation::Client*); 93 bool isEmpty() const { return m_animations.isEmpty(); } 94 size_t size() const { return m_animations.size(); } 95 const Vector<GraphicsLayerAnimation>& animations() const { return m_animations; } 96 Vector<GraphicsLayerAnimation>& animations() { return m_animations; } 97 98 bool hasRunningAnimations() const; 99 bool hasActiveAnimationsOfType(AnimatedPropertyID type) const; 100 101 GraphicsLayerAnimations getActiveAnimations() const; 102 103private: 104 Vector<GraphicsLayerAnimation> m_animations; 105}; 106 107} 108#endif 109 110#endif // GraphicsLayerAnimation_h 111