From ec8bca15a1ee864b746443610194be91e4b7a1c8 Mon Sep 17 00:00:00 2001 From: Justin Dolske Date: Wed, 10 Dec 2008 16:15:47 -0800 Subject: [PATCH] Bug 461680 - Improve video control fade in/out animation. r=enn --- toolkit/content/widgets/videocontrols.xml | 121 ++++++++++-------- .../pinstripe/global/media/videocontrols.css | 2 +- .../winstripe/global/media/videocontrols.css | 2 +- 3 files changed, 73 insertions(+), 52 deletions(-) diff --git a/toolkit/content/widgets/videocontrols.xml b/toolkit/content/widgets/videocontrols.xml index e5f44ca17bb..829266b8dea 100644 --- a/toolkit/content/widgets/videocontrols.xml +++ b/toolkit/content/widgets/videocontrols.xml @@ -14,7 +14,7 @@ - + @@ -77,15 +77,18 @@ = self.animationSteps) { - self.animationStep = self.animationSteps; - clearInterval(self.animationTimer); - self.animationTimer = null; + // Ignore events caused by transitions between child nodes. + if (this.isChildNode(event.target) && + this.isChildNode(event.relatedTarget)) + return; + + // Don't show controls when they're disabled, but do allow a + // mouseout to hide controls that were disabled after being shown. + if (!this.video.controls && (isMouseOver || !this.controlsVisible)) + return; + + this.log("Fading controls " + (isMouseOver ? "in" : "out")); + + var directionChange = (isMouseOver != this.fadingIn); + this.fadingIn = isMouseOver; + + // When switching direction mid-fade, adjust fade time for current fade state. + if (directionChange && this.fadeTime) + this.fadeTime = this.FADE_TIME_MAX - this.fadeTime; + + if (!this.fadeTimer) + this.fadeTimer = setInterval(this.fadeControls, this.FADE_TIME_STEP, this); + }, + + fadeControls : function (self, lateness) { + // Update elapsed time, and compute position as a percent + // of total. Last frame could run over, so clamp to 1. + self.fadeTime += self.FADE_TIME_STEP + lateness; + var pos = self.fadeTime / self.FADE_TIME_MAX; + if (pos > 1) + pos = 1; + + // Calculate the opacity for our position in the animation. + var opacity; + if (self.fadingIn) + opacity = Math.pow(pos, 0.5); + else + opacity = Math.pow(1 - pos, 0.5); + self.controlsVisible = (opacity ? true : false); + + self.controlBar.style.opacity = opacity; + + // Use .visibility to ignore mouse clicks when hidden. + if (self.controlsVisible) + self.controlBar.style.visibility = "visible"; + else + self.controlBar.style.visibility = "hidden"; + + // Is the animation done? + if (pos == 1) { + clearInterval(self.fadeTimer); + self.fadeTimer = null; + self.fadeTime = 0; } - - // XXX might be good to do logarithmic steps, maybe use timer error too (for smoothness)? - self.controls.style.opacity = self.animationStep / self.animationSteps; }, togglePause : function () { @@ -143,11 +186,11 @@ isChildNode : function (node) { while (node) { - if (node == this.controls) + if (node == this.video) break; node = node.parentNode; } - return (node == this); + return (node == this.video); }, log : function (msg) { @@ -162,15 +205,16 @@ - + this.Utils.onMouseInOut(event); - - + this.Utils.onMouseInOut(event); diff --git a/toolkit/themes/pinstripe/global/media/videocontrols.css b/toolkit/themes/pinstripe/global/media/videocontrols.css index 47e1ae6dbdb..70f2bab50c3 100644 --- a/toolkit/themes/pinstripe/global/media/videocontrols.css +++ b/toolkit/themes/pinstripe/global/media/videocontrols.css @@ -1,6 +1,6 @@ @namespace url("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"); -#controlsBackground { +#controlBar { height: 24px; background-color: #656363; } diff --git a/toolkit/themes/winstripe/global/media/videocontrols.css b/toolkit/themes/winstripe/global/media/videocontrols.css index 47e1ae6dbdb..70f2bab50c3 100644 --- a/toolkit/themes/winstripe/global/media/videocontrols.css +++ b/toolkit/themes/winstripe/global/media/videocontrols.css @@ -1,6 +1,6 @@ @namespace url("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"); -#controlsBackground { +#controlBar { height: 24px; background-color: #656363; }