Fix OOP <webview> resize and autosize.
[chromium-blink-merge.git] / third_party / polymer / v1_0 / components-chromium / neon-animation / neon-animation-runner-behavior-extracted.js
blob1c88739c99616cc4ed48ad378c437927a580f959
1 /**
2    * `Polymer.NeonAnimationRunnerBehavior` adds a method to run animations.
3    *
4    * @polymerBehavior Polymer.NeonAnimationRunnerBehavior
5    */
6   Polymer.NeonAnimationRunnerBehaviorImpl = {
8     properties: {
10       _animationMeta: {
11         type: Object,
12         value: function() {
13           return new Polymer.IronMeta({type: 'animation'});
14         }
15       },
17       /** @type {?Object} */
18       _player: {
19         type: Object
20       }
22     },
24     _configureAnimationEffects: function(allConfigs) {
25       var allAnimations = [];
26       if (allConfigs.length > 0) {
27         for (var config, index = 0; config = allConfigs[index]; index++) {
28           var animationConstructor = this._animationMeta.byKey(config.name);
29           if (animationConstructor) {
30             var animation = animationConstructor && new animationConstructor();
31             var effect = animation.configure(config);
32             if (effect) {
33               allAnimations.push({
34                 animation: animation,
35                 config: config,
36                 effect: effect
37               });
38             }
39           } else {
40             console.warn(this.is + ':', config.name, 'not found!');
41           }
42         }
43       }
44       return allAnimations;
45     },
47     _runAnimationEffects: function(allEffects) {
48       return document.timeline.play(new GroupEffect(allEffects));
49     },
51     _completeAnimations: function(allAnimations) {
52       for (var animation, index = 0; animation = allAnimations[index]; index++) {
53         animation.animation.complete(animation.config);
54       }
55     },
57     /**
58      * Plays an animation with an optional `type`.
59      * @param {string=} type
60      * @param {!Object=} cookie
61      */
62     playAnimation: function(type, cookie) {
63       var allConfigs = this.getAnimationConfig(type);
64       if (!allConfigs) {
65         return;
66       }
67       var allAnimations = this._configureAnimationEffects(allConfigs);
68       var allEffects = allAnimations.map(function(animation) {
69         return animation.effect;
70       });
72       if (allEffects.length > 0) {
73         this._player = this._runAnimationEffects(allEffects);
74         this._player.onfinish = function() {
75           this._completeAnimations(allAnimations);
77           if (this._player) {
78             this._player.cancel();
79             this._player = null;
80           }
82           this.fire('neon-animation-finish', cookie, {bubbles: false});
83         }.bind(this);
85       } else {
86         this.fire('neon-animation-finish', cookie, {bubbles: false});
87       }
88     },
90     /**
91      * Cancels the currently running animation.
92      */
93     cancelAnimation: function() {
94       if (this._player) {
95         this._player.cancel();
96       }
97     }
98   };
100   /** @polymerBehavior Polymer.NeonAnimationRunnerBehavior */
101   Polymer.NeonAnimationRunnerBehavior = [
102     Polymer.NeonAnimatableBehavior,
103     Polymer.NeonAnimationRunnerBehaviorImpl
104   ];