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)
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.
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.
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.
28 #include "PlatformString.h"
29 #include "TimingFunction.h"
30 #include <wtf/PassRefPtr.h>
31 #include <wtf/RefCounted.h>
35 const int cAnimateNone
= 0;
36 const int cAnimateAll
= -2;
38 class Animation
: public RefCounted
<Animation
> {
42 static PassRefPtr
<Animation
> create() { return adoptRef(new Animation
); };
44 bool isDelaySet() const { return m_delaySet
; }
45 bool isDirectionSet() const { return m_directionSet
; }
46 bool isDurationSet() const { return m_durationSet
; }
47 bool isIterationCountSet() const { return m_iterationCountSet
; }
48 bool isNameSet() const { return m_nameSet
; }
49 bool isPlayStateSet() const { return m_playStateSet
; }
50 bool isPropertySet() const { return m_propertySet
; }
51 bool isTimingFunctionSet() const { return m_timingFunctionSet
; }
53 // Flags this to be the special "none" animation (animation-name: none)
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.
57 bool isValidAnimation() const { return !m_isNone
&& !m_name
.isEmpty(); }
61 return (!m_directionSet
&& !m_durationSet
&& !m_nameSet
&& !m_playStateSet
&&
62 !m_iterationCountSet
&& !m_delaySet
&& !m_timingFunctionSet
&& !m_propertySet
);
65 bool isEmptyOrZeroDuration() const
67 return isEmpty() || (m_duration
== 0 && m_delay
<= 0);
70 void clearDelay() { m_delaySet
= false; }
71 void clearDirection() { m_directionSet
= false; }
72 void clearDuration() { m_durationSet
= false; }
73 void clearIterationCount() { m_iterationCountSet
= false; }
74 void clearName() { m_nameSet
= false; }
75 void clearPlayState() { m_playStateSet
= AnimPlayStatePlaying
; }
76 void clearProperty() { m_propertySet
= false; }
77 void clearTimingFunction() { m_timingFunctionSet
= false; }
79 double delay() const { return m_delay
; }
81 enum AnimationDirection
{ AnimationDirectionNormal
, AnimationDirectionAlternate
};
82 AnimationDirection
direction() const { return m_direction
; }
84 double duration() const { return m_duration
; }
86 enum { IterationCountInfinite
= -1 };
87 int iterationCount() const { return m_iterationCount
; }
88 const String
& name() const { return m_name
; }
89 unsigned playState() const { return m_playState
; }
90 int property() const { return m_property
; }
91 const TimingFunction
& timingFunction() const { return m_timingFunction
; }
93 void setDelay(double c
) { m_delay
= c
; m_delaySet
= true; }
94 void setDirection(AnimationDirection d
) { m_direction
= d
; m_directionSet
= true; }
95 void setDuration(double d
) { ASSERT(d
>= 0); m_duration
= d
; m_durationSet
= true; }
96 void setIterationCount(int c
) { m_iterationCount
= c
; m_iterationCountSet
= true; }
97 void setName(const String
& n
) { m_name
= n
; m_nameSet
= true; }
98 void setPlayState(unsigned d
) { m_playState
= d
; m_playStateSet
= true; }
99 void setProperty(int t
) { m_property
= t
; m_propertySet
= true; }
100 void setTimingFunction(const TimingFunction
& f
) { m_timingFunction
= f
; m_timingFunctionSet
= true; }
102 void setIsNoneAnimation(bool n
) { m_isNone
= n
; }
104 Animation
& operator=(const Animation
& o
);
106 // return true if all members of this class match (excluding m_next)
107 bool animationsMatch(const Animation
*, bool matchPlayStates
= true) const;
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
); }
115 Animation(const Animation
& o
);
119 int m_iterationCount
;
122 TimingFunction m_timingFunction
;
123 AnimationDirection m_direction
: 1;
125 unsigned m_playState
: 2;
128 bool m_directionSet
: 1;
129 bool m_durationSet
: 1;
130 bool m_iterationCountSet
: 1;
132 bool m_playStateSet
: 1;
133 bool m_propertySet
: 1;
134 bool m_timingFunctionSet
: 1;
139 static float initialAnimationDelay() { return 0; }
140 static AnimationDirection
initialAnimationDirection() { return AnimationDirectionNormal
; }
141 static double initialAnimationDuration() { return 0; }
142 static int initialAnimationIterationCount() { return 1; }
143 static String
initialAnimationName() { return String("none"); }
144 static unsigned initialAnimationPlayState() { return AnimPlayStatePlaying
; }
145 static int initialAnimationProperty() { return cAnimateAll
; }
146 static TimingFunction
initialAnimationTimingFunction() { return TimingFunction(); }
149 } // namespace WebCore
151 #endif // Animation_h