Use SCHEME_HTTP for HTTPS proxies on Android.
[chromium-blink-merge.git] / cc / active_animation.h
blob413e9f2053197930e5bce6ce4979ca8f6276b020
1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CC_ACTIVE_ANIMATION_H_
6 #define CC_ACTIVE_ANIMATION_H_
8 #include "base/basictypes.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "cc/cc_export.h"
12 namespace cc {
14 class AnimationCurve;
16 // An ActiveAnimation, contains all the state required to play an AnimationCurve.
17 // Specifically, the affected property, the run state (paused, finished, etc.),
18 // loop count, last pause time, and the total time spent paused.
19 class CC_EXPORT ActiveAnimation {
20 public:
21 // Animations begin in one of the 'waiting' states. Animations waiting for the next tick
22 // will start the next time the controller animates. Animations waiting for target
23 // availibility will run as soon as their target property is free (and all the animations
24 // animating with it are also able to run). Animations waiting for their start time to
25 // come have be scheduled to run at a particular point in time. When this time arrives,
26 // the controller will move the animations into the Running state. Running animations
27 // may toggle between Running and Paused, and may be stopped by moving into either the
28 // Aborted or Finished states. A Finished animation was allowed to run to completion, but
29 // an Aborted animation was not.
30 enum RunState {
31 WaitingForNextTick = 0,
32 WaitingForTargetAvailability,
33 WaitingForStartTime,
34 WaitingForDeletion,
35 Running,
36 Paused,
37 Finished,
38 Aborted,
39 // This sentinel must be last.
40 RunStateEnumSize
43 enum TargetProperty {
44 Transform = 0,
45 Opacity,
46 // This sentinel must be last.
47 TargetPropertyEnumSize
50 static scoped_ptr<ActiveAnimation> create(scoped_ptr<AnimationCurve>, int animationId, int groupId, TargetProperty);
52 virtual ~ActiveAnimation();
54 int id() const { return m_id; }
55 int group() const { return m_group; }
56 TargetProperty targetProperty() const { return m_targetProperty; }
58 RunState runState() const { return m_runState; }
59 void setRunState(RunState, double monotonicTime);
61 // This is the number of times that the animation will play. If this
62 // value is zero the animation will not play. If it is negative, then
63 // the animation will loop indefinitely.
64 int iterations() const { return m_iterations; }
65 void setIterations(int n) { m_iterations = n; }
67 double startTime() const { return m_startTime; }
68 void setStartTime(double monotonicTime) { m_startTime = monotonicTime; }
69 bool hasSetStartTime() const { return !!m_startTime; }
71 double timeOffset() const { return m_timeOffset; }
72 void setTimeOffset(double monotonicTime) { m_timeOffset = monotonicTime; }
74 void suspend(double monotonicTime);
75 void resume(double monotonicTime);
77 // If alternatesDirection is true, on odd numbered iterations we reverse the curve.
78 bool alternatesDirection() const { return m_alternatesDirection; }
79 void setAlternatesDirection(bool alternates) { m_alternatesDirection = alternates; }
81 bool isFinishedAt(double monotonicTime) const;
82 bool isFinished() const { return m_runState == Finished
83 || m_runState == Aborted
84 || m_runState == WaitingForDeletion; }
86 AnimationCurve* curve() { return m_curve.get(); }
87 const AnimationCurve* curve() const { return m_curve.get(); }
89 // If this is true, even if the animation is running, it will not be tickable until
90 // it is given a start time. This is true for animations running on the main thread.
91 bool needsSynchronizedStartTime() const { return m_needsSynchronizedStartTime; }
92 void setNeedsSynchronizedStartTime(bool needsSynchronizedStartTime) { m_needsSynchronizedStartTime = needsSynchronizedStartTime; }
94 // Takes the given absolute time, and using the start time and the number
95 // of iterations, returns the relative time in the current iteration.
96 double trimTimeToCurrentIteration(double monotonicTime) const;
98 enum InstanceType {
99 ControllingInstance = 0,
100 NonControllingInstance
103 scoped_ptr<ActiveAnimation> clone(InstanceType) const;
104 scoped_ptr<ActiveAnimation> cloneAndInitialize(InstanceType, RunState initialRunState, double startTime) const;
105 bool isControllingInstance() const { return m_isControllingInstance; }
107 void pushPropertiesTo(ActiveAnimation*) const;
109 private:
110 ActiveAnimation(scoped_ptr<AnimationCurve>, int animationId, int groupId, TargetProperty);
112 scoped_ptr<AnimationCurve> m_curve;
114 // IDs are not necessarily unique.
115 int m_id;
117 // Animations that must be run together are called 'grouped' and have the same group id
118 // Grouped animations are guaranteed to start at the same time and no other animations
119 // may animate any of the group's target properties until all animations in the
120 // group have finished animating. Note: an active animation's group id and target
121 // property uniquely identify that animation.
122 int m_group;
124 TargetProperty m_targetProperty;
125 RunState m_runState;
126 int m_iterations;
127 double m_startTime;
128 bool m_alternatesDirection;
130 // The time offset effectively pushes the start of the animation back in time. This is
131 // used for resuming paused animations -- an animation is added with a non-zero time
132 // offset, causing the animation to skip ahead to the desired point in time.
133 double m_timeOffset;
135 bool m_needsSynchronizedStartTime;
137 // When an animation is suspended, it behaves as if it is paused and it also ignores
138 // all run state changes until it is resumed. This is used for testing purposes.
139 bool m_suspended;
141 // These are used in trimTimeToCurrentIteration to account for time
142 // spent while paused. This is not included in AnimationState since it
143 // there is absolutely no need for clients of this controller to know
144 // about these values.
145 double m_pauseTime;
146 double m_totalPausedTime;
148 // Animations lead dual lives. An active animation will be conceptually owned by
149 // two controllers, one on the impl thread and one on the main. In reality, there
150 // will be two separate ActiveAnimation instances for the same animation. They
151 // will have the same group id and the same target property (these two values
152 // uniquely identify an animation). The instance on the impl thread is the instance
153 // that ultimately controls the values of the animating layer and so we will refer
154 // to it as the 'controlling instance'.
155 bool m_isControllingInstance;
157 DISALLOW_COPY_AND_ASSIGN(ActiveAnimation);
160 } // namespace cc
162 #endif // CC_ACTIVE_ANIMATION_H_