Debian Codegraph @

closure-library/closure/goog/fx/transitionbase.js

raw
1 // Copyright 2011 The Closure Library Authors. All Rights Reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS-IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 /**
16 * @fileoverview An abstract base class for transitions. This is a simple
17 * interface that allows for playing, pausing and stopping an animation. It adds
18 * a simple event model, and animation status.
19 */
20 goog.provide('goog.fx.TransitionBase');
21 goog.provide('goog.fx.TransitionBase.State');
22
23 goog.require('goog.events.EventTarget');
24 goog.require('goog.fx.Transition'); // Unreferenced: interface
25
26
27
28 /**
29 * Constructor for a transition object.
30 *
31 * @constructor
32 * @struct
33 * @implements {goog.fx.Transition}
34 * @extends {goog.events.EventTarget}
35 */
36 goog.fx.TransitionBase = function() {
37 goog.fx.TransitionBase.base(this, 'constructor');
38
39 /**
40 * The internal state of the animation.
41 * @type {goog.fx.TransitionBase.State}
42 * @private
43 */
44 this.state_ = goog.fx.TransitionBase.State.STOPPED;
45
46 /**
47 * Timestamp for when the animation was started.
48 * @type {?number}
49 * @protected
50 */
51 this.startTime = null;
52
53 /**
54 * Timestamp for when the animation finished or was stopped.
55 * @type {?number}
56 * @protected
57 */
58 this.endTime = null;
59 };
60 goog.inherits(goog.fx.TransitionBase, goog.events.EventTarget);
61
62
63 /**
64 * Enum for the possible states of an animation.
65 * @enum {number}
66 */
67 goog.fx.TransitionBase.State = {
68 STOPPED: 0,
69 PAUSED: -1,
70 PLAYING: 1
71 };
72
73
74 /**
75 * Plays the animation.
76 *
77 * @param {boolean=} opt_restart Optional parameter to restart the animation.
78 * @return {boolean} True iff the animation was started.
79 * @override
80 */
81 goog.fx.TransitionBase.prototype.play = goog.abstractMethod;
82
83
84 /**
85 * Stops the animation.
86 *
87 * @param {boolean=} opt_gotoEnd Optional boolean parameter to go the the end of
88 * the animation.
89 * @override
90 */
91 goog.fx.TransitionBase.prototype.stop = goog.abstractMethod;
92
93
94 /**
95 * Pauses the animation.
96 */
97 goog.fx.TransitionBase.prototype.pause = goog.abstractMethod;
98
99
100 /**
101 * Returns the current state of the animation.
102 * @return {goog.fx.TransitionBase.State} State of the animation.
103 */
104 goog.fx.TransitionBase.prototype.getStateInternal = function() {
105 return this.state_;
106 };
107
108
109 /**
110 * Sets the current state of the animation to playing.
111 * @protected
112 */
113 goog.fx.TransitionBase.prototype.setStatePlaying = function() {
114 this.state_ = goog.fx.TransitionBase.State.PLAYING;
115 };
116
117
118 /**
119 * Sets the current state of the animation to paused.
120 * @protected
121 */
122 goog.fx.TransitionBase.prototype.setStatePaused = function() {
123 this.state_ = goog.fx.TransitionBase.State.PAUSED;
124 };
125
126
127 /**
128 * Sets the current state of the animation to stopped.
129 * @protected
130 */
131 goog.fx.TransitionBase.prototype.setStateStopped = function() {
132 this.state_ = goog.fx.TransitionBase.State.STOPPED;
133 };
134
135
136 /**
137 * @return {boolean} True iff the current state of the animation is playing.
138 */
139 goog.fx.TransitionBase.prototype.isPlaying = function() {
140 return this.state_ == goog.fx.TransitionBase.State.PLAYING;
141 };
142
143
144 /**
145 * @return {boolean} True iff the current state of the animation is paused.
146 */
147 goog.fx.TransitionBase.prototype.isPaused = function() {
148 return this.state_ == goog.fx.TransitionBase.State.PAUSED;
149 };
150
151
152 /**
153 * @return {boolean} True iff the current state of the animation is stopped.
154 */
155 goog.fx.TransitionBase.prototype.isStopped = function() {
156 return this.state_ == goog.fx.TransitionBase.State.STOPPED;
157 };
158
159
160 /**
161 * Dispatches the BEGIN event. Sub classes should override this instead
162 * of listening to the event, and call this instead of dispatching the event.
163 * @protected
164 */
165 goog.fx.TransitionBase.prototype.onBegin = function() {
166 this.dispatchAnimationEvent(goog.fx.Transition.EventType.BEGIN);
167 };
168
169
170 /**
171 * Dispatches the END event. Sub classes should override this instead
172 * of listening to the event, and call this instead of dispatching the event.
173 * @protected
174 */
175 goog.fx.TransitionBase.prototype.onEnd = function() {
176 this.dispatchAnimationEvent(goog.fx.Transition.EventType.END);
177 };
178
179
180 /**
181 * Dispatches the FINISH event. Sub classes should override this instead
182 * of listening to the event, and call this instead of dispatching the event.
183 * @protected
184 */
185 goog.fx.TransitionBase.prototype.onFinish = function() {
186 this.dispatchAnimationEvent(goog.fx.Transition.EventType.FINISH);
187 };
188
189
190 /**
191 * Dispatches the PAUSE event. Sub classes should override this instead
192 * of listening to the event, and call this instead of dispatching the event.
193 * @protected
194 */
195 goog.fx.TransitionBase.prototype.onPause = function() {
196 this.dispatchAnimationEvent(goog.fx.Transition.EventType.PAUSE);
197 };
198
199
200 /**
201 * Dispatches the PLAY event. Sub classes should override this instead
202 * of listening to the event, and call this instead of dispatching the event.
203 * @protected
204 */
205 goog.fx.TransitionBase.prototype.onPlay = function() {
206 this.dispatchAnimationEvent(goog.fx.Transition.EventType.PLAY);
207 };
208
209
210 /**
211 * Dispatches the RESUME event. Sub classes should override this instead
212 * of listening to the event, and call this instead of dispatching the event.
213 * @protected
214 */
215 goog.fx.TransitionBase.prototype.onResume = function() {
216 this.dispatchAnimationEvent(goog.fx.Transition.EventType.RESUME);
217 };
218
219
220 /**
221 * Dispatches the STOP event. Sub classes should override this instead
222 * of listening to the event, and call this instead of dispatching the event.
223 * @protected
224 */
225 goog.fx.TransitionBase.prototype.onStop = function() {
226 this.dispatchAnimationEvent(goog.fx.Transition.EventType.STOP);
227 };
228
229
230 /**
231 * Dispatches an event object for the current animation.
232 * @param {string} type Event type that will be dispatched.
233 * @protected
234 */
235 goog.fx.TransitionBase.prototype.dispatchAnimationEvent = function(type) {
236 this.dispatchEvent(type);
237 };