Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
SeleniumHQ
GitHub Repository: SeleniumHQ/Selenium
Path: blob/trunk/third_party/closure/goog/fx/transitionbase.js
4142 views
1
/**
2
* @license
3
* Copyright The Closure Library Authors.
4
* SPDX-License-Identifier: Apache-2.0
5
*/
6
7
/**
8
* @fileoverview An abstract base class for transitions. This is a simple
9
* interface that allows for playing, pausing and stopping an animation. It adds
10
* a simple event model, and animation status.
11
*/
12
goog.provide('goog.fx.TransitionBase');
13
14
goog.require('goog.events.EventTarget');
15
goog.require('goog.fx.Transition'); // Unreferenced: interface
16
17
18
19
/**
20
* Constructor for a transition object.
21
*
22
* @constructor
23
* @struct
24
* @implements {goog.fx.Transition}
25
* @extends {goog.events.EventTarget}
26
*/
27
goog.fx.TransitionBase = function() {
28
'use strict';
29
goog.fx.TransitionBase.base(this, 'constructor');
30
31
/**
32
* The internal state of the animation.
33
* @type {goog.fx.TransitionBase.State}
34
* @private
35
*/
36
this.state_ = goog.fx.TransitionBase.State.STOPPED;
37
38
/**
39
* Timestamp for when the animation was started.
40
* @type {?number}
41
* @protected
42
*/
43
this.startTime = null;
44
45
/**
46
* Timestamp for when the animation finished or was stopped.
47
* @type {?number}
48
* @protected
49
*/
50
this.endTime = null;
51
};
52
goog.inherits(goog.fx.TransitionBase, goog.events.EventTarget);
53
54
55
/**
56
* Enum for the possible states of an animation.
57
* @enum {number}
58
*/
59
goog.fx.TransitionBase.State = {
60
STOPPED: 0,
61
PAUSED: -1,
62
PLAYING: 1
63
};
64
65
66
/**
67
* Plays the animation.
68
*
69
* @param {boolean=} opt_restart Optional parameter to restart the animation.
70
* @return {boolean} True iff the animation was started.
71
* @override
72
*/
73
goog.fx.TransitionBase.prototype.play = goog.abstractMethod;
74
75
76
/**
77
* Stops the animation.
78
*
79
* @param {boolean=} opt_gotoEnd Optional boolean parameter to go the end of
80
* the animation.
81
* @override
82
*/
83
goog.fx.TransitionBase.prototype.stop = goog.abstractMethod;
84
85
86
/**
87
* Pauses the animation.
88
*/
89
goog.fx.TransitionBase.prototype.pause = goog.abstractMethod;
90
91
92
/**
93
* Returns the current state of the animation.
94
* @return {goog.fx.TransitionBase.State} State of the animation.
95
*/
96
goog.fx.TransitionBase.prototype.getStateInternal = function() {
97
'use strict';
98
return this.state_;
99
};
100
101
102
/**
103
* Sets the current state of the animation to playing.
104
* @protected
105
*/
106
goog.fx.TransitionBase.prototype.setStatePlaying = function() {
107
'use strict';
108
this.state_ = goog.fx.TransitionBase.State.PLAYING;
109
};
110
111
112
/**
113
* Sets the current state of the animation to paused.
114
* @protected
115
*/
116
goog.fx.TransitionBase.prototype.setStatePaused = function() {
117
'use strict';
118
this.state_ = goog.fx.TransitionBase.State.PAUSED;
119
};
120
121
122
/**
123
* Sets the current state of the animation to stopped.
124
* @protected
125
*/
126
goog.fx.TransitionBase.prototype.setStateStopped = function() {
127
'use strict';
128
this.state_ = goog.fx.TransitionBase.State.STOPPED;
129
};
130
131
132
/**
133
* @return {boolean} True iff the current state of the animation is playing.
134
*/
135
goog.fx.TransitionBase.prototype.isPlaying = function() {
136
'use strict';
137
return this.state_ == goog.fx.TransitionBase.State.PLAYING;
138
};
139
140
141
/**
142
* @return {boolean} True iff the current state of the animation is paused.
143
*/
144
goog.fx.TransitionBase.prototype.isPaused = function() {
145
'use strict';
146
return this.state_ == goog.fx.TransitionBase.State.PAUSED;
147
};
148
149
150
/**
151
* @return {boolean} True iff the current state of the animation is stopped.
152
*/
153
goog.fx.TransitionBase.prototype.isStopped = function() {
154
'use strict';
155
return this.state_ == goog.fx.TransitionBase.State.STOPPED;
156
};
157
158
159
/**
160
* Dispatches the BEGIN event. Sub classes should override this instead
161
* of listening to the event, and call this instead of dispatching the event.
162
* @protected
163
*/
164
goog.fx.TransitionBase.prototype.onBegin = function() {
165
'use strict';
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
'use strict';
177
this.dispatchAnimationEvent(goog.fx.Transition.EventType.END);
178
};
179
180
181
/**
182
* Dispatches the FINISH event. Sub classes should override this instead
183
* of listening to the event, and call this instead of dispatching the event.
184
* @protected
185
*/
186
goog.fx.TransitionBase.prototype.onFinish = function() {
187
'use strict';
188
this.dispatchAnimationEvent(goog.fx.Transition.EventType.FINISH);
189
};
190
191
192
/**
193
* Dispatches the PAUSE event. Sub classes should override this instead
194
* of listening to the event, and call this instead of dispatching the event.
195
* @protected
196
*/
197
goog.fx.TransitionBase.prototype.onPause = function() {
198
'use strict';
199
this.dispatchAnimationEvent(goog.fx.Transition.EventType.PAUSE);
200
};
201
202
203
/**
204
* Dispatches the PLAY event. Sub classes should override this instead
205
* of listening to the event, and call this instead of dispatching the event.
206
* @protected
207
*/
208
goog.fx.TransitionBase.prototype.onPlay = function() {
209
'use strict';
210
this.dispatchAnimationEvent(goog.fx.Transition.EventType.PLAY);
211
};
212
213
214
/**
215
* Dispatches the RESUME event. Sub classes should override this instead
216
* of listening to the event, and call this instead of dispatching the event.
217
* @protected
218
*/
219
goog.fx.TransitionBase.prototype.onResume = function() {
220
'use strict';
221
this.dispatchAnimationEvent(goog.fx.Transition.EventType.RESUME);
222
};
223
224
225
/**
226
* Dispatches the STOP event. Sub classes should override this instead
227
* of listening to the event, and call this instead of dispatching the event.
228
* @protected
229
*/
230
goog.fx.TransitionBase.prototype.onStop = function() {
231
'use strict';
232
this.dispatchAnimationEvent(goog.fx.Transition.EventType.STOP);
233
};
234
235
236
/**
237
* Dispatches an event object for the current animation.
238
* @param {string} type Event type that will be dispatched.
239
* @protected
240
*/
241
goog.fx.TransitionBase.prototype.dispatchAnimationEvent = function(type) {
242
'use strict';
243
this.dispatchEvent(type);
244
};
245
246