1 /* 2 * Copyright (C) 2000 Lars Knoll (knoll@kde.org) 3 * (C) 2000 Antti Koivisto (koivisto@kde.org) 4 * (C) 2000 Dirk Mueller (mueller@kde.org) 5 * Copyright (C) 2003, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. 6 * Copyright (C) 2006 Graham Dennis (graham.dennis@gmail.com) 7 * 8 * This library is free software; you can redistribute it and/or 9 * modify it under the terms of the GNU Library General Public 10 * License as published by the Free Software Foundation; either 11 * version 2 of the License, or (at your option) any later version. 12 * 13 * This library is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 * Library General Public License for more details. 17 * 18 * You should have received a copy of the GNU Library General Public License 19 * along with this library; see the file COPYING.LIB. If not, write to 20 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 21 * Boston, MA 02110-1301, USA. 22 * 23 */ 24 25 #ifndef Animation_h 26 #define Animation_h 27 28 #include "PlatformString.h" 29 #include "RenderStyleConstants.h" 30 #include "TimingFunction.h" 31 #include <wtf/PassRefPtr.h> 32 #include <wtf/RefCounted.h> 33 34 namespace WebCore { 35 36 const int cAnimateNone = 0; 37 const int cAnimateAll = -2; 38 39 class Animation : public RefCounted<Animation> { 40 public: 41 ~Animation(); 42 create()43 static PassRefPtr<Animation> create() { return adoptRef(new Animation); } create(const Animation * o)44 static PassRefPtr<Animation> create(const Animation* o) { return adoptRef(new Animation(*o)); } 45 isDelaySet()46 bool isDelaySet() const { return m_delaySet; } isDirectionSet()47 bool isDirectionSet() const { return m_directionSet; } isDurationSet()48 bool isDurationSet() const { return m_durationSet; } isFillModeSet()49 bool isFillModeSet() const { return m_fillModeSet; } isIterationCountSet()50 bool isIterationCountSet() const { return m_iterationCountSet; } isNameSet()51 bool isNameSet() const { return m_nameSet; } isPlayStateSet()52 bool isPlayStateSet() const { return m_playStateSet; } isPropertySet()53 bool isPropertySet() const { return m_propertySet; } isTimingFunctionSet()54 bool isTimingFunctionSet() const { return m_timingFunctionSet; } 55 56 // Flags this to be the special "none" animation (animation-name: none) isNoneAnimation()57 bool isNoneAnimation() const { return m_isNone; } 58 // We can make placeholder Animation objects to keep the comma-separated lists 59 // of properties in sync. isValidAnimation means this is not a placeholder. isValidAnimation()60 bool isValidAnimation() const { return !m_isNone && !m_name.isEmpty(); } 61 isEmpty()62 bool isEmpty() const 63 { 64 return (!m_directionSet && !m_durationSet && !m_fillModeSet 65 && !m_nameSet && !m_playStateSet && !m_iterationCountSet 66 && !m_delaySet && !m_timingFunctionSet && !m_propertySet); 67 } 68 isEmptyOrZeroDuration()69 bool isEmptyOrZeroDuration() const 70 { 71 return isEmpty() || (m_duration == 0 && m_delay <= 0); 72 } 73 clearDelay()74 void clearDelay() { m_delaySet = false; } clearDirection()75 void clearDirection() { m_directionSet = false; } clearDuration()76 void clearDuration() { m_durationSet = false; } clearFillMode()77 void clearFillMode() { m_fillModeSet = false; } clearIterationCount()78 void clearIterationCount() { m_iterationCountSet = false; } clearName()79 void clearName() { m_nameSet = false; } clearPlayState()80 void clearPlayState() { m_playStateSet = AnimPlayStatePlaying; } clearProperty()81 void clearProperty() { m_propertySet = false; } clearTimingFunction()82 void clearTimingFunction() { m_timingFunctionSet = false; } 83 delay()84 double delay() const { return m_delay; } 85 86 enum AnimationDirection { AnimationDirectionNormal, AnimationDirectionAlternate }; direction()87 AnimationDirection direction() const { return static_cast<AnimationDirection>(m_direction); } 88 fillMode()89 unsigned fillMode() const { return m_fillMode; } 90 duration()91 double duration() const { return m_duration; } 92 93 enum { IterationCountInfinite = -1 }; iterationCount()94 int iterationCount() const { return m_iterationCount; } name()95 const String& name() const { return m_name; } playState()96 EAnimPlayState playState() const { return static_cast<EAnimPlayState>(m_playState); } property()97 int property() const { return m_property; } timingFunction()98 const PassRefPtr<TimingFunction> timingFunction() const { return m_timingFunction; } 99 setDelay(double c)100 void setDelay(double c) { m_delay = c; m_delaySet = true; } setDirection(AnimationDirection d)101 void setDirection(AnimationDirection d) { m_direction = d; m_directionSet = true; } setDuration(double d)102 void setDuration(double d) { ASSERT(d >= 0); m_duration = d; m_durationSet = true; } setFillMode(unsigned f)103 void setFillMode(unsigned f) { m_fillMode = f; m_fillModeSet = true; } setIterationCount(int c)104 void setIterationCount(int c) { m_iterationCount = c; m_iterationCountSet = true; } setName(const String & n)105 void setName(const String& n) { m_name = n; m_nameSet = true; } setPlayState(EAnimPlayState d)106 void setPlayState(EAnimPlayState d) { m_playState = d; m_playStateSet = true; } setProperty(int t)107 void setProperty(int t) { m_property = t; m_propertySet = true; } setTimingFunction(PassRefPtr<TimingFunction> f)108 void setTimingFunction(PassRefPtr<TimingFunction> f) { m_timingFunction = f; m_timingFunctionSet = true; } 109 setIsNoneAnimation(bool n)110 void setIsNoneAnimation(bool n) { m_isNone = n; } 111 112 Animation& operator=(const Animation& o); 113 114 // return true if all members of this class match (excluding m_next) 115 bool animationsMatch(const Animation*, bool matchPlayStates = true) const; 116 117 // return true every Animation in the chain (defined by m_next) match 118 bool operator==(const Animation& o) const { return animationsMatch(&o); } 119 bool operator!=(const Animation& o) const { return !(*this == o); } 120 fillsBackwards()121 bool fillsBackwards() const { return m_fillModeSet && (m_fillMode == AnimationFillModeBackwards || m_fillMode == AnimationFillModeBoth); } fillsForwards()122 bool fillsForwards() const { return m_fillModeSet && (m_fillMode == AnimationFillModeForwards || m_fillMode == AnimationFillModeBoth); } 123 124 private: 125 Animation(); 126 Animation(const Animation& o); 127 128 String m_name; 129 int m_property; 130 int m_iterationCount; 131 double m_delay; 132 double m_duration; 133 RefPtr<TimingFunction> m_timingFunction; 134 unsigned m_direction : 1; // AnimationDirection 135 unsigned m_fillMode : 2; 136 137 unsigned m_playState : 2; 138 139 bool m_delaySet : 1; 140 bool m_directionSet : 1; 141 bool m_durationSet : 1; 142 bool m_fillModeSet : 1; 143 bool m_iterationCountSet : 1; 144 bool m_nameSet : 1; 145 bool m_playStateSet : 1; 146 bool m_propertySet : 1; 147 bool m_timingFunctionSet : 1; 148 149 bool m_isNone : 1; 150 151 public: initialAnimationDelay()152 static float initialAnimationDelay() { return 0; } initialAnimationDirection()153 static AnimationDirection initialAnimationDirection() { return AnimationDirectionNormal; } initialAnimationDuration()154 static double initialAnimationDuration() { return 0; } initialAnimationFillMode()155 static unsigned initialAnimationFillMode() { return AnimationFillModeNone; } initialAnimationIterationCount()156 static int initialAnimationIterationCount() { return 1; } initialAnimationName()157 static String initialAnimationName() { return String("none"); } initialAnimationPlayState()158 static EAnimPlayState initialAnimationPlayState() { return AnimPlayStatePlaying; } initialAnimationProperty()159 static int initialAnimationProperty() { return cAnimateAll; } initialAnimationTimingFunction()160 static PassRefPtr<TimingFunction> initialAnimationTimingFunction() { return CubicBezierTimingFunction::create(); } 161 }; 162 163 } // namespace WebCore 164 165 #endif // Animation_h 166