Revert of Roll src/third_party/WebKit e0eac24:489c548 (svn 193311:193320) (patchset...
[chromium-blink-merge.git] / third_party / web-animations-js / sources / src / group-constructors.js
blobfddf3dfbe14a70b94e4d6cf51b7cce6491f98f55
1 // Copyright 2014 Google Inc. 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.
15 (function(shared, scope, testing) {
17   function constructor(children, timingInput) {
18     this.children = children || [];
19     this._timing = shared.normalizeTimingInput(timingInput, true);
20     this.timing = shared.makeTiming(timingInput, true);
22     if (this._timing.duration === 'auto')
23       this._timing.duration = this.activeDuration;
24   }
26   window.AnimationSequence = function() {
27     constructor.apply(this, arguments);
28   };
30   window.AnimationGroup = function() {
31     constructor.apply(this, arguments);
32   };
34   window.AnimationSequence.prototype = {
35     get activeDuration() {
36       var total = 0;
37       this.children.forEach(function(child) {
38         total += scope.groupChildDuration(child);
39       });
40       return Math.max(total, 0);
41     }
42   };
44   window.AnimationGroup.prototype = {
45     get activeDuration() {
46       var max = 0;
47       this.children.forEach(function(child) {
48         max = Math.max(max, scope.groupChildDuration(child));
49       });
50       return max;
51     }
52   };
54   scope.newUnderlyingPlayerForGroup = function(group) {
55     var underlyingPlayer;
56     var ticker = function(tf) {
57       var player = underlyingPlayer._wrapper;
58       if (!player.source)
59         return;
60       if (tf == null) {
61         player._removePlayers();
62         return;
63       }
64       if (player.startTime === null)
65         return;
67       player._updateChildren();
68     };
70     underlyingPlayer = scope.timeline.play(new scope.Animation(null, ticker, group._timing));
71     return underlyingPlayer;
72   };
74   scope.bindPlayerForGroup = function(player) {
75     player._player._wrapper = player;
76     player._isGroup = true;
77     scope.awaitStartTime(player);
78     player._updateChildren();
79   };
82 })(webAnimationsShared, webAnimationsNext, webAnimationsTesting);