Path: blob/trunk/third_party/closure/goog/fx/transitionbase.js
2868 views
// Copyright 2011 The Closure Library Authors. All Rights Reserved.1//2// Licensed under the Apache License, Version 2.0 (the "License");3// you may not use this file except in compliance with the License.4// You may obtain a copy of the License at5//6// http://www.apache.org/licenses/LICENSE-2.07//8// Unless required by applicable law or agreed to in writing, software9// distributed under the License is distributed on an "AS-IS" BASIS,10// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.11// See the License for the specific language governing permissions and12// limitations under the License.1314/**15* @fileoverview An abstract base class for transitions. This is a simple16* interface that allows for playing, pausing and stopping an animation. It adds17* a simple event model, and animation status.18*/19goog.provide('goog.fx.TransitionBase');20goog.provide('goog.fx.TransitionBase.State');2122goog.require('goog.events.EventTarget');23goog.require('goog.fx.Transition'); // Unreferenced: interface24252627/**28* Constructor for a transition object.29*30* @constructor31* @struct32* @implements {goog.fx.Transition}33* @extends {goog.events.EventTarget}34*/35goog.fx.TransitionBase = function() {36goog.fx.TransitionBase.base(this, 'constructor');3738/**39* The internal state of the animation.40* @type {goog.fx.TransitionBase.State}41* @private42*/43this.state_ = goog.fx.TransitionBase.State.STOPPED;4445/**46* Timestamp for when the animation was started.47* @type {?number}48* @protected49*/50this.startTime = null;5152/**53* Timestamp for when the animation finished or was stopped.54* @type {?number}55* @protected56*/57this.endTime = null;58};59goog.inherits(goog.fx.TransitionBase, goog.events.EventTarget);606162/**63* Enum for the possible states of an animation.64* @enum {number}65*/66goog.fx.TransitionBase.State = {67STOPPED: 0,68PAUSED: -1,69PLAYING: 170};717273/**74* Plays the animation.75*76* @param {boolean=} opt_restart Optional parameter to restart the animation.77* @return {boolean} True iff the animation was started.78* @override79*/80goog.fx.TransitionBase.prototype.play = goog.abstractMethod;818283/**84* Stops the animation.85*86* @param {boolean=} opt_gotoEnd Optional boolean parameter to go the the end of87* the animation.88* @override89*/90goog.fx.TransitionBase.prototype.stop = goog.abstractMethod;919293/**94* Pauses the animation.95*/96goog.fx.TransitionBase.prototype.pause = goog.abstractMethod;979899/**100* Returns the current state of the animation.101* @return {goog.fx.TransitionBase.State} State of the animation.102*/103goog.fx.TransitionBase.prototype.getStateInternal = function() {104return this.state_;105};106107108/**109* Sets the current state of the animation to playing.110* @protected111*/112goog.fx.TransitionBase.prototype.setStatePlaying = function() {113this.state_ = goog.fx.TransitionBase.State.PLAYING;114};115116117/**118* Sets the current state of the animation to paused.119* @protected120*/121goog.fx.TransitionBase.prototype.setStatePaused = function() {122this.state_ = goog.fx.TransitionBase.State.PAUSED;123};124125126/**127* Sets the current state of the animation to stopped.128* @protected129*/130goog.fx.TransitionBase.prototype.setStateStopped = function() {131this.state_ = goog.fx.TransitionBase.State.STOPPED;132};133134135/**136* @return {boolean} True iff the current state of the animation is playing.137*/138goog.fx.TransitionBase.prototype.isPlaying = function() {139return this.state_ == goog.fx.TransitionBase.State.PLAYING;140};141142143/**144* @return {boolean} True iff the current state of the animation is paused.145*/146goog.fx.TransitionBase.prototype.isPaused = function() {147return this.state_ == goog.fx.TransitionBase.State.PAUSED;148};149150151/**152* @return {boolean} True iff the current state of the animation is stopped.153*/154goog.fx.TransitionBase.prototype.isStopped = function() {155return this.state_ == goog.fx.TransitionBase.State.STOPPED;156};157158159/**160* Dispatches the BEGIN event. Sub classes should override this instead161* of listening to the event, and call this instead of dispatching the event.162* @protected163*/164goog.fx.TransitionBase.prototype.onBegin = function() {165this.dispatchAnimationEvent(goog.fx.Transition.EventType.BEGIN);166};167168169/**170* Dispatches the END event. Sub classes should override this instead171* of listening to the event, and call this instead of dispatching the event.172* @protected173*/174goog.fx.TransitionBase.prototype.onEnd = function() {175this.dispatchAnimationEvent(goog.fx.Transition.EventType.END);176};177178179/**180* Dispatches the FINISH event. Sub classes should override this instead181* of listening to the event, and call this instead of dispatching the event.182* @protected183*/184goog.fx.TransitionBase.prototype.onFinish = function() {185this.dispatchAnimationEvent(goog.fx.Transition.EventType.FINISH);186};187188189/**190* Dispatches the PAUSE event. Sub classes should override this instead191* of listening to the event, and call this instead of dispatching the event.192* @protected193*/194goog.fx.TransitionBase.prototype.onPause = function() {195this.dispatchAnimationEvent(goog.fx.Transition.EventType.PAUSE);196};197198199/**200* Dispatches the PLAY event. Sub classes should override this instead201* of listening to the event, and call this instead of dispatching the event.202* @protected203*/204goog.fx.TransitionBase.prototype.onPlay = function() {205this.dispatchAnimationEvent(goog.fx.Transition.EventType.PLAY);206};207208209/**210* Dispatches the RESUME event. Sub classes should override this instead211* of listening to the event, and call this instead of dispatching the event.212* @protected213*/214goog.fx.TransitionBase.prototype.onResume = function() {215this.dispatchAnimationEvent(goog.fx.Transition.EventType.RESUME);216};217218219/**220* Dispatches the STOP event. Sub classes should override this instead221* of listening to the event, and call this instead of dispatching the event.222* @protected223*/224goog.fx.TransitionBase.prototype.onStop = function() {225this.dispatchAnimationEvent(goog.fx.Transition.EventType.STOP);226};227228229/**230* Dispatches an event object for the current animation.231* @param {string} type Event type that will be dispatched.232* @protected233*/234goog.fx.TransitionBase.prototype.dispatchAnimationEvent = function(type) {235this.dispatchEvent(type);236};237238239