• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "TimingFunction.h"
30 #include <wtf/PassRefPtr.h>
31 #include <wtf/RefCounted.h>
32 
33 namespace WebCore {
34 
35 const int cAnimateNone = 0;
36 const int cAnimateAll = -2;
37 
38 class Animation : public RefCounted<Animation> {
39 public:
40     ~Animation();
41 
create()42     static PassRefPtr<Animation> create() { return adoptRef(new Animation); };
43 
isDelaySet()44     bool isDelaySet() const { return m_delaySet; }
isDirectionSet()45     bool isDirectionSet() const { return m_directionSet; }
isDurationSet()46     bool isDurationSet() const { return m_durationSet; }
isIterationCountSet()47     bool isIterationCountSet() const { return m_iterationCountSet; }
isNameSet()48     bool isNameSet() const { return m_nameSet; }
isPlayStateSet()49     bool isPlayStateSet() const { return m_playStateSet; }
isPropertySet()50     bool isPropertySet() const { return m_propertySet; }
isTimingFunctionSet()51     bool isTimingFunctionSet() const { return m_timingFunctionSet; }
52 
53     // Flags this to be the special "none" animation (animation-name: none)
isNoneAnimation()54     bool isNoneAnimation() const { return m_isNone; }
55     // We can make placeholder Animation objects to keep the comma-separated lists
56     // of properties in sync. isValidAnimation means this is not a placeholder.
isValidAnimation()57     bool isValidAnimation() const { return !m_isNone && !m_name.isEmpty(); }
58 
isEmpty()59     bool isEmpty() const
60     {
61         return (!m_directionSet && !m_durationSet && !m_nameSet && !m_playStateSet &&
62                !m_iterationCountSet && !m_delaySet && !m_timingFunctionSet && !m_propertySet);
63     }
64 
isEmptyOrZeroDuration()65     bool isEmptyOrZeroDuration() const
66     {
67         return isEmpty() || (m_duration == 0 && m_delay <= 0);
68     }
69 
clearDelay()70     void clearDelay() { m_delaySet = false; }
clearDirection()71     void clearDirection() { m_directionSet = false; }
clearDuration()72     void clearDuration() { m_durationSet = false; }
clearIterationCount()73     void clearIterationCount() { m_iterationCountSet = false; }
clearName()74     void clearName() { m_nameSet = false; }
clearPlayState()75     void clearPlayState() { m_playStateSet = AnimPlayStatePlaying; }
clearProperty()76     void clearProperty() { m_propertySet = false; }
clearTimingFunction()77     void clearTimingFunction() { m_timingFunctionSet = false; }
78 
delay()79     double delay() const { return m_delay; }
80 
81     enum AnimationDirection { AnimationDirectionNormal, AnimationDirectionAlternate };
direction()82     AnimationDirection direction() const { return m_direction; }
83 
duration()84     double duration() const { return m_duration; }
85 
86     enum { IterationCountInfinite = -1 };
iterationCount()87     int iterationCount() const { return m_iterationCount; }
name()88     const String& name() const { return m_name; }
playState()89     unsigned playState() const { return m_playState; }
property()90     int property() const { return m_property; }
timingFunction()91     const TimingFunction& timingFunction() const { return m_timingFunction; }
92 
setDelay(double c)93     void setDelay(double c) { m_delay = c; m_delaySet = true; }
setDirection(AnimationDirection d)94     void setDirection(AnimationDirection d) { m_direction = d; m_directionSet = true; }
setDuration(double d)95     void setDuration(double d) { ASSERT(d >= 0); m_duration = d; m_durationSet = true; }
setIterationCount(int c)96     void setIterationCount(int c) { m_iterationCount = c; m_iterationCountSet = true; }
setName(const String & n)97     void setName(const String& n) { m_name = n; m_nameSet = true; }
setPlayState(unsigned d)98     void setPlayState(unsigned d) { m_playState = d; m_playStateSet = true; }
setProperty(int t)99     void setProperty(int t) { m_property = t; m_propertySet = true; }
setTimingFunction(const TimingFunction & f)100     void setTimingFunction(const TimingFunction& f) { m_timingFunction = f; m_timingFunctionSet = true; }
101 
setIsNoneAnimation(bool n)102     void setIsNoneAnimation(bool n) { m_isNone = n; }
103 
104     Animation& operator=(const Animation& o);
105 
106     // return true if all members of this class match (excluding m_next)
107     bool animationsMatch(const Animation*, bool matchPlayStates = true) const;
108 
109     // return true every Animation in the chain (defined by m_next) match
110     bool operator==(const Animation& o) const { return animationsMatch(&o); }
111     bool operator!=(const Animation& o) const { return !(*this == o); }
112 
113 private:
114     Animation();
115     Animation(const Animation& o);
116 
117     String m_name;
118     int m_property;
119     int m_iterationCount;
120     double m_delay;
121     double m_duration;
122     TimingFunction m_timingFunction;
123     AnimationDirection m_direction : 1;
124 
125     unsigned m_playState     : 2;
126 
127     bool m_delaySet          : 1;
128     bool m_directionSet      : 1;
129     bool m_durationSet       : 1;
130     bool m_iterationCountSet : 1;
131     bool m_nameSet           : 1;
132     bool m_playStateSet      : 1;
133     bool m_propertySet       : 1;
134     bool m_timingFunctionSet : 1;
135 
136     bool m_isNone            : 1;
137 
138 public:
initialAnimationDelay()139     static float initialAnimationDelay() { return 0; }
initialAnimationDirection()140     static AnimationDirection initialAnimationDirection() { return AnimationDirectionNormal; }
initialAnimationDuration()141     static double initialAnimationDuration() { return 0; }
initialAnimationIterationCount()142     static int initialAnimationIterationCount() { return 1; }
initialAnimationName()143     static String initialAnimationName() { return String("none"); }
initialAnimationPlayState()144     static unsigned initialAnimationPlayState() { return AnimPlayStatePlaying; }
initialAnimationProperty()145     static int initialAnimationProperty() { return cAnimateAll; }
initialAnimationTimingFunction()146     static TimingFunction initialAnimationTimingFunction() { return TimingFunction(); }
147 };
148 
149 } // namespace WebCore
150 
151 #endif // Animation_h
152