1 // Copyright 2014 Google Inc. All rights reserved.
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
7 // http://www.apache.org/licenses/LICENSE-2.0
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 (function(shared, scope, testing) {
16 var nullTarget = document.createElementNS('http://www.w3.org/1999/xhtml', 'div');
18 var sequenceNumber = 0;
19 scope.bindPlayerForCustomEffect = function(player) {
20 var target = player.source.target;
21 var effect = player.source.effect;
22 var timing = player.source.timing;
24 timing = shared.normalizeTimingInput(timing);
25 var callback = function() {
26 var t = callback._player ? callback._player.currentTime : null;
28 t = shared.calculateTimeFraction(shared.calculateActiveDuration(timing), t, timing);
32 // FIXME: There are actually more conditions under which the effect
35 effect(t, target, player.source);
39 callback._player = player;
40 callback._registered = false;
41 callback._sequenceNumber = sequenceNumber++;
42 player._callback = callback;
48 function register(callback) {
49 if (callback._registered)
51 callback._registered = true;
52 callbacks.push(callback);
55 requestAnimationFrame(tick);
60 var updating = callbacks;
62 updating.sort(function(left, right) {
63 return left._sequenceNumber - right._sequenceNumber;
65 updating.filter(function(callback) {
67 if (!callback._player || callback._player.finished || callback._player.paused)
68 callback._registered = false;
69 return callback._registered;
71 callbacks.push.apply(callbacks, updating);
73 if (callbacks.length) {
75 requestAnimationFrame(tick);
81 scope.Player.prototype._register = function() {
83 register(this._callback);
86 })(webAnimationsShared, webAnimationsNext, webAnimationsTesting);