Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(83)

Side by Side Diff: polymer_0.5.0/bower_components/web-animations-js/src/animation-constructor.js

Issue 786953007: npm_modules: Fork bower_components into Polymer 0.4.0 and 0.5.0 versions (Closed) Base URL: https://chromium.googlesource.com/infra/third_party/npm_modules.git@master
Patch Set: Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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.
14
15 (function(shared, scope, testing) {
16
17 function groupChildDuration(node) {
18 return node._timing.delay + node.activeDuration + node._timing.endDelay;
19 };
20
21 function KeyframeEffect(effect) {
22 this._frames = shared.normalizeKeyframes(effect);
23 }
24
25 KeyframeEffect.prototype = {
26 getFrames: function() { return this._frames; }
27 };
28
29 scope.Animation = function(target, effect, timingInput) {
30 this.target = target;
31 // TODO: Make modifications to specified update the underlying player
32 this._timing = shared.normalizeTimingInput(timingInput);
33 this.timing = shared.makeTiming(timingInput);
34 // TODO: Make this a live object - will need to separate normalization of
35 // keyframes into a shared module.
36 if (typeof effect == 'function')
37 this.effect = effect;
38 else
39 this.effect = new KeyframeEffect(effect);
40 this._effect = effect;
41 this.activeDuration = shared.calculateActiveDuration(this._timing);
42 return this;
43 };
44
45 var originalElementAnimate = Element.prototype.animate;
46 Element.prototype.animate = function(effect, timing) {
47 return scope.timeline.play(new scope.Animation(this, effect, timing));
48 };
49
50 var nullTarget = document.createElement('div');
51 scope.newUnderlyingPlayerForAnimation = function(animation) {
52 var target = animation.target || nullTarget;
53 var effect = animation._effect;
54 if (typeof effect == 'function') {
55 effect = [];
56 }
57 return originalElementAnimate.apply(target, [effect, animation.timing]);
58 };
59
60 scope.bindPlayerForAnimation = function(player) {
61 if (player.source && typeof player.source.effect == 'function') {
62 scope.bindPlayerForCustomEffect(player);
63 }
64 };
65
66 var pendingGroups = [];
67 scope.awaitStartTime = function(groupPlayer) {
68 if (groupPlayer.startTime !== null || !groupPlayer._isGroup)
69 return;
70 if (pendingGroups.length == 0) {
71 requestAnimationFrame(updatePendingGroups);
72 }
73 pendingGroups.push(groupPlayer);
74 };
75 function updatePendingGroups() {
76 var updated = false;
77 while (pendingGroups.length) {
78 pendingGroups.shift()._updateChildren();
79 updated = true;
80 }
81 return updated;
82 }
83 var originalGetComputedStyle = window.getComputedStyle;
84 Object.defineProperty(window, 'getComputedStyle', {
85 configurable: true,
86 enumerable: true,
87 value: function() {
88 var result = originalGetComputedStyle.apply(this, arguments);
89 if (updatePendingGroups())
90 result = originalGetComputedStyle.apply(this, arguments);
91 return result;
92 },
93 });
94
95 // TODO: Call into this less frequently.
96 scope.Player.prototype._updateChildren = function() {
97 if (this.startTime === null || !this.source || !this._isGroup)
98 return;
99 var offset = this.source._timing.delay;
100 for (var i = 0; i < this.source.children.length; i++) {
101 var child = this.source.children[i];
102 var childPlayer;
103
104 if (i >= this._childPlayers.length) {
105 childPlayer = window.document.timeline.play(child);
106 child.player = this.source.player;
107 this._childPlayers.push(childPlayer);
108 } else {
109 childPlayer = this._childPlayers[i];
110 }
111
112 if (childPlayer.startTime != this.startTime + offset) {
113 childPlayer.startTime = this.startTime + offset;
114 childPlayer._updateChildren();
115 }
116
117 if (this.playbackRate == -1 && this.currentTime < offset && childPlayer.cu rrentTime !== -1) {
118 childPlayer.currentTime = -1;
119 }
120
121 if (this.source instanceof window.AnimationSequence)
122 offset += groupChildDuration(child);
123 }
124 };
125
126 window.Animation = scope.Animation;
127 window.Element.prototype.getAnimationPlayers = function() {
128 return document.timeline.getAnimationPlayers().filter(function(player) {
129 return player.source !== null && player.source.target == this;
130 }.bind(this));
131 };
132
133 scope.groupChildDuration = groupChildDuration;
134
135 }(webAnimationsShared, webAnimationsMaxifill, webAnimationsTesting));
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698