OLD | NEW |
1 // Copyright 2014 Google Inc. All rights reserved. | 1 // Copyright 2014 Google Inc. All rights reserved. |
2 // | 2 // |
3 // Licensed under the Apache License, Version 2.0 (the "License"); | 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
4 // you may not use this file except in compliance with 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 | 5 // You may obtain a copy of the License at |
6 // | 6 // |
7 // http://www.apache.org/licenses/LICENSE-2.0 | 7 // http://www.apache.org/licenses/LICENSE-2.0 |
8 // | 8 // |
9 // Unless required by applicable law or agreed to in writing, software | 9 // Unless required by applicable law or agreed to in writing, software |
10 // distributed under the License is distributed on an "AS IS" BASIS, | 10 // distributed under the License is distributed on an "AS IS" BASIS, |
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 // See the License for the specific language governing permissions and | 12 // See the License for the specific language governing permissions and |
13 // limitations under the License. | 13 // limitations under the License. |
14 | 14 |
15 | 15 |
16 (function(shared, scope, testing) { | 16 (function(shared, scope, testing) { |
17 | 17 |
18 scope.AnimationTimeline = function() { | 18 scope.AnimationTimeline = function() { |
19 this._players = []; | 19 this._players = []; |
20 this.currentTime = undefined; | 20 this.currentTime = undefined; |
21 }; | 21 }; |
22 | 22 |
23 scope.AnimationTimeline.prototype = { | 23 scope.AnimationTimeline.prototype = { |
24 // FIXME: This needs to return the wrapped players in maxifill | 24 // FIXME: This needs to return the wrapped players in Web Animations Next |
25 // TODO: Does this need to be sorted? | 25 // TODO: Does this need to be sorted? |
26 // TODO: Do we need to consider needsRetick? | 26 // TODO: Do we need to consider needsRetick? |
27 getAnimationPlayers: function() { | 27 getAnimationPlayers: function() { |
28 this._discardPlayers(); | 28 this._discardPlayers(); |
29 return this._players.slice(); | 29 return this._players.slice(); |
30 }, | 30 }, |
31 _discardPlayers: function() { | 31 _discardPlayers: function() { |
32 this._players = this._players.filter(function(player) { | 32 this._players = this._players.filter(function(player) { |
33 return player.playState != 'finished' && player.playState != 'idle'; | 33 return player.playState != 'finished' && player.playState != 'idle'; |
34 }); | 34 }); |
35 }, | 35 }, |
36 play: function(source) { | 36 play: function(source) { |
37 var player = new scope.Player(source); | 37 var player = new scope.Player(source); |
38 this._players.push(player); | 38 this._players.push(player); |
39 scope.restartMaxifillTick(); | 39 scope.restartWebAnimationsNextTick(); |
40 player.play(); | 40 player.play(); |
41 return player; | 41 return player; |
42 }, | 42 }, |
43 }; | 43 }; |
44 | 44 |
45 var ticking = false; | 45 var ticking = false; |
46 | 46 |
47 scope.restartMaxifillTick = function() { | 47 scope.restartWebAnimationsNextTick = function() { |
48 if (!ticking) { | 48 if (!ticking) { |
49 ticking = true; | 49 ticking = true; |
50 requestAnimationFrame(maxifillTick); | 50 requestAnimationFrame(webAnimationsNextTick); |
51 } | 51 } |
52 }; | 52 }; |
53 | 53 |
54 function maxifillTick(t) { | 54 function webAnimationsNextTick(t) { |
55 var timeline = window.document.timeline; | 55 var timeline = window.document.timeline; |
56 timeline.currentTime = t; | 56 timeline.currentTime = t; |
57 timeline._discardPlayers(); | 57 timeline._discardPlayers(); |
58 if (timeline._players.length == 0) | 58 if (timeline._players.length == 0) |
59 ticking = false; | 59 ticking = false; |
60 else | 60 else |
61 requestAnimationFrame(maxifillTick); | 61 requestAnimationFrame(webAnimationsNextTick); |
62 } | 62 } |
63 | 63 |
64 var timeline = new scope.AnimationTimeline(); | 64 var timeline = new scope.AnimationTimeline(); |
65 scope.timeline = timeline; | 65 scope.timeline = timeline; |
66 | 66 |
67 try { | 67 try { |
68 Object.defineProperty(window.document, 'timeline', { | 68 Object.defineProperty(window.document, 'timeline', { |
69 configurable: true, | 69 configurable: true, |
70 get: function() { return timeline; } | 70 get: function() { return timeline; } |
71 }); | 71 }); |
72 } catch (e) { } | 72 } catch (e) { } |
73 try { | 73 try { |
74 window.document.timeline = timeline; | 74 window.document.timeline = timeline; |
75 } catch (e) { } | 75 } catch (e) { } |
76 | 76 |
77 })(webAnimationsShared, webAnimationsMaxifill, webAnimationsTesting); | 77 })(webAnimationsShared, webAnimationsNext, webAnimationsTesting); |
OLD | NEW |