• 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; }
direction()80     bool direction() const { return m_direction; }
duration()81     double duration() const { return m_duration; }
iterationCount()82     int iterationCount() const { return m_iterationCount; }
name()83     const String& name() const { return m_name; }
playState()84     unsigned playState() const { return m_playState; }
property()85     int property() const { return m_property; }
timingFunction()86     const TimingFunction& timingFunction() const { return m_timingFunction; }
87 
setDelay(double c)88     void setDelay(double c) { m_delay = c; m_delaySet = true; }
setDirection(bool d)89     void setDirection(bool d) { m_direction = d; m_directionSet = true; }
setDuration(double d)90     void setDuration(double d) { ASSERT(d >= 0); m_duration = d; m_durationSet = true; }
setIterationCount(int c)91     void setIterationCount(int c) { m_iterationCount = c; m_iterationCountSet = true; }
setName(const String & n)92     void setName(const String& n) { m_name = n; m_nameSet = true; }
setPlayState(unsigned d)93     void setPlayState(unsigned d) { m_playState = d; m_playStateSet = true; }
setProperty(int t)94     void setProperty(int t) { m_property = t; m_propertySet = true; }
setTimingFunction(const TimingFunction & f)95     void setTimingFunction(const TimingFunction& f) { m_timingFunction = f; m_timingFunctionSet = true; }
96 
setIsNoneAnimation(bool n)97     void setIsNoneAnimation(bool n) { m_isNone = n; }
98 
99     Animation& operator=(const Animation& o);
100 
101     // return true if all members of this class match (excluding m_next)
102     bool animationsMatch(const Animation*, bool matchPlayStates = true) const;
103 
104     // return true every Animation in the chain (defined by m_next) match
105     bool operator==(const Animation& o) const { return animationsMatch(&o); }
106     bool operator!=(const Animation& o) const { return !(*this == o); }
107 
108 private:
109     Animation();
110     Animation(const Animation& o);
111 
112     double m_delay;
113     bool m_direction;
114     double m_duration;
115     int m_iterationCount;
116     String m_name;
117     int m_property;
118     TimingFunction m_timingFunction;
119 
120     unsigned m_playState     : 2;
121 
122     bool m_delaySet          : 1;
123     bool m_directionSet      : 1;
124     bool m_durationSet       : 1;
125     bool m_iterationCountSet : 1;
126     bool m_nameSet           : 1;
127     bool m_playStateSet      : 1;
128     bool m_propertySet       : 1;
129     bool m_timingFunctionSet : 1;
130 
131     bool m_isNone            : 1;
132 
133 public:
initialAnimationDelay()134     static float initialAnimationDelay() { return 0; }
initialAnimationDirection()135     static bool initialAnimationDirection() { return false; }
initialAnimationDuration()136     static double initialAnimationDuration() { return 0; }
initialAnimationIterationCount()137     static int initialAnimationIterationCount() { return 1; }
initialAnimationName()138     static String initialAnimationName() { return String("none"); }
initialAnimationPlayState()139     static unsigned initialAnimationPlayState() { return AnimPlayStatePlaying; }
initialAnimationProperty()140     static int initialAnimationProperty() { return cAnimateAll; }
initialAnimationTimingFunction()141     static TimingFunction initialAnimationTimingFunction() { return TimingFunction(); }
142 };
143 
144 } // namespace WebCore
145 
146 #endif // Animation_h
147