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

Unified Diff: third_party/polymer/v1_0/components-chromium/neon-animation/neon-animation-runner-behavior-extracted.js

Issue 2158913007: Roll Polymer from 1.5.0 -> 1.6.0 to pick up native CSS custom props (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: merge Created 4 years, 5 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 side-by-side diff with in-line comments
Download patch
Index: third_party/polymer/v1_0/components-chromium/neon-animation/neon-animation-runner-behavior-extracted.js
diff --git a/third_party/polymer/v1_0/components-chromium/neon-animation/neon-animation-runner-behavior-extracted.js b/third_party/polymer/v1_0/components-chromium/neon-animation/neon-animation-runner-behavior-extracted.js
index 04905d331cc93c40ea16ba19b4b0d3aa4023c895..c34d4e2b409f26ebd7a918e2400090740a21379c 100644
--- a/third_party/polymer/v1_0/components-chromium/neon-animation/neon-animation-runner-behavior-extracted.js
+++ b/third_party/polymer/v1_0/components-chromium/neon-animation/neon-animation-runner-behavior-extracted.js
@@ -5,28 +5,30 @@
*/
Polymer.NeonAnimationRunnerBehaviorImpl = {
- properties: {
-
- /** @type {?Object} */
- _player: {
- type: Object
- }
-
- },
-
- _configureAnimationEffects: function(allConfigs) {
- var allAnimations = [];
- if (allConfigs.length > 0) {
- for (var config, index = 0; config = allConfigs[index]; index++) {
- var animation = document.createElement(config.name);
+ _configureAnimations: function(configs) {
+ var results = [];
+ if (configs.length > 0) {
+ for (var config, index = 0; config = configs[index]; index++) {
+ var neonAnimation = document.createElement(config.name);
// is this element actually a neon animation?
- if (animation.isNeonAnimation) {
- var effect = animation.configure(config);
- if (effect) {
- allAnimations.push({
- animation: animation,
+ if (neonAnimation.isNeonAnimation) {
+ var result = null;
+ // configuration or play could fail if polyfills aren't loaded
+ try {
+ result = neonAnimation.configure(config);
+ // Check if we have an Effect rather than an Animation
+ if (typeof result.cancel != 'function') {
+ result = document.timeline.play(result);
+ }
+ } catch (e) {
+ result = null;
+ console.warn('Couldnt play', '(', config.name, ').', e);
+ }
+ if (result) {
+ results.push({
+ neonAnimation: neonAnimation,
config: config,
- effect: effect
+ animation: result,
});
}
} else {
@@ -34,16 +36,26 @@
}
}
}
- return allAnimations;
+ return results;
},
- _runAnimationEffects: function(allEffects) {
- return document.timeline.play(new GroupEffect(allEffects));
+ _shouldComplete: function(activeEntries) {
+ var finished = true;
+ for (var i = 0; i < activeEntries.length; i++) {
+ if (activeEntries[i].animation.playState != 'finished') {
+ finished = false;
+ break;
+ }
+ }
+ return finished;
},
- _completeAnimations: function(allAnimations) {
- for (var animation, index = 0; animation = allAnimations[index]; index++) {
- animation.animation.complete(animation.config);
+ _complete: function(activeEntries) {
+ for (var i = 0; i < activeEntries.length; i++) {
+ activeEntries[i].neonAnimation.complete(activeEntries[i].config);
+ }
+ for (var i = 0; i < activeEntries.length; i++) {
+ activeEntries[i].animation.cancel();
}
},
@@ -53,43 +65,44 @@
* @param {!Object=} cookie
*/
playAnimation: function(type, cookie) {
- var allConfigs = this.getAnimationConfig(type);
- if (!allConfigs) {
+ var configs = this.getAnimationConfig(type);
+ if (!configs) {
return;
}
- try {
- var allAnimations = this._configureAnimationEffects(allConfigs);
- var allEffects = allAnimations.map(function(animation) {
- return animation.effect;
- });
+ this._active = this._active || {};
+ if (this._active[type]) {
+ this._complete(this._active[type]);
+ delete this._active[type];
+ }
- if (allEffects.length > 0) {
- this._player = this._runAnimationEffects(allEffects);
- this._player.onfinish = function() {
- this._completeAnimations(allAnimations);
+ var activeEntries = this._configureAnimations(configs);
- if (this._player) {
- this._player.cancel();
- this._player = null;
- }
+ if (activeEntries.length == 0) {
+ this.fire('neon-animation-finish', cookie, {bubbles: false});
+ return;
+ }
+
+ this._active[type] = activeEntries;
+ for (var i = 0; i < activeEntries.length; i++) {
+ activeEntries[i].animation.onfinish = function() {
+ if (this._shouldComplete(activeEntries)) {
+ this._complete(activeEntries);
+ delete this._active[type];
this.fire('neon-animation-finish', cookie, {bubbles: false});
- }.bind(this);
- return;
- }
- } catch (e) {
- console.warn('Couldnt play', '(', type, allConfigs, ').', e);
+ }
+ }.bind(this);
}
- this.fire('neon-animation-finish', cookie, {bubbles: false});
},
/**
- * Cancels the currently running animation.
+ * Cancels the currently running animations.
*/
cancelAnimation: function() {
- if (this._player) {
- this._player.cancel();
+ for (var k in this._animations) {
+ this._animations[k].cancel();
}
+ this._animations = {};
}
};

Powered by Google App Engine
This is Rietveld 408576698