Chromium Code Reviews| Index: chrome/browser/resources/print_preview/print_preview_animations.js |
| diff --git a/chrome/browser/resources/print_preview/print_preview_animations.js b/chrome/browser/resources/print_preview/print_preview_animations.js |
| index b717e249be8b283c14ec85ca349f2362ec6e5a5e..599512b7472ae964d53ba7c24f9e4c596c972508 100644 |
| --- a/chrome/browser/resources/print_preview/print_preview_animations.js |
| +++ b/chrome/browser/resources/print_preview/print_preview_animations.js |
| @@ -20,6 +20,29 @@ function addAnimation(code) { |
| } |
| /** |
| + * Generates css code for fading in an element by animating the height. |
| + * @param {number} targetHeight The desired height in pixels after the animation |
| + * ends. |
| + * @return {string} The css code for the fade in animation. |
| + */ |
| +function getFadeInAnimationCode(targetHeight) { |
| + return '0% { opacity: 0; height: 0; } ' + |
| + '80% { height: ' + (targetHeight + 4) + 'px; }' + |
| + '100% { opacity: 1; height: ' + targetHeight + 'px; }'; |
| +} |
| + |
| +/** |
| + * Generates css code for fading out an element by animating the height. |
| + * @param {number} startingHeight The desired height in pixels before the |
| + * animation starts. |
| + * @return {string} The css code for the fade in animation. |
| + */ |
| +function getFadeOutAnimationCode(startingHeight) { |
| + return '0% { opacity: 1; height: ' + startingHeight + 'px; }' + |
| + '100% { opacity: 1; height: 0; }'; |
| +} |
| + |
| +/** |
| * Fades in an element. Used for both printing options and error messages |
| * appearing underneath the textfields. |
| * @param {HTMLElement} el The element to be faded in. |
| @@ -28,21 +51,17 @@ function fadeInElement(el) { |
| if (el.classList.contains('visible')) |
| return; |
| el.classList.remove('closing'); |
| + el.hidden = false; |
| el.style.height = 'auto'; |
| var height = el.offsetHeight; |
| el.style.height = height + 'px'; |
| - var animName = addAnimation( |
| - '0% { opacity: 0; height: 0; } ' + |
| - '80% { height: ' + (height + 4) + 'px; }' + |
| - '100% { opacity: 1; height: ' + height + 'px; }'); |
| + var animName = addAnimation(getFadeInAnimationCode(height)); |
| + var eventTracker = new EventTracker(); |
| + eventTracker.add(el, 'webkitAnimationEnd', |
| + onFadeInAnimationEnd.bind(el, animName, eventTracker), |
| + false ); |
| el.style.webkitAnimationName = animName; |
| el.classList.add('visible'); |
| - el.addEventListener('webkitAnimationEnd', function() { |
| - el.style.height = ''; |
| - el.style.webkitAnimationName = ''; |
| - fadeInOutCleanup(animName); |
| - el.removeEventListener('webkitAnimationEnd', arguments.callee, false); |
| - }, false ); |
| } |
| /** |
| @@ -56,16 +75,41 @@ function fadeOutElement(el) { |
| el.style.height = 'auto'; |
| var height = el.offsetHeight; |
| el.style.height = height + 'px'; |
| - var animName = addAnimation( |
| - '0% { opacity: 1; height: ' + height + 'px; }' + |
| - '100% { opacity: 1; height: 0; }'); |
| + var animName = addAnimation(getFadeOutAnimationCode(height)); |
| + var eventTracker = new EventTracker(); |
| + eventTracker.add(el, 'webkitTransitionEnd', |
|
Evan Stade
2011/11/16 04:16:31
shuoldn't this be Animation not Transition
dpapad
2011/11/16 19:37:28
No, it is transition on purpose, since the fading
|
| + onFadeOutAnimationEnd.bind(el, animName, eventTracker), |
| + false ); |
| el.style.webkitAnimationName = animName; |
| el.classList.add('closing'); |
| el.classList.remove('visible'); |
| - el.addEventListener('webkitAnimationEnd', function() { |
| - fadeInOutCleanup(animName); |
| - el.removeEventListener('webkitAnimationEnd', arguments.callee, false); |
| - }, false ); |
| +} |
| + |
| +/** |
| + * Executes when a fade out animation ends. |
| + * @param {string} animationName The name of the animation to be removed. |
| + * @param{EventTracker} The |EventTracker| object that was used for adding this |
| + * listener. |
| + * @param {WebkitTransitionEvent} event The event that triggered this listener. |
| + */ |
| +function onFadeOutAnimationEnd(animationName, eventTracker, event) { |
| + fadeInOutCleanup(animationName); |
| + eventTracker.remove(event.target, 'webkitTransitionEnd'); |
| + event.target.hidden = true; |
| +} |
| + |
| +/** |
| + * Executes when a fade in animation ends. |
| + * @param {string} animationName The name of the animation to be removed. |
| + * @param{EventTracker} The |EventTracker| object that was used for adding this |
| + * listener. |
| + * @param {WebkitAnimationEvent} event The event that triggered this listener. |
| + */ |
| +function onFadeInAnimationEnd(animationName, eventTracker, event) { |
| + event.target.style.height = ''; |
| + event.target.style.webkitAnimationName = ''; |
| + fadeInOutCleanup(animationName); |
| + eventTracker.remove(event.target, 'webkitAnimationEnd'); |
| } |
| /** |