From 6ea5440b1da872656339008e8482f556e3f1cb67 Mon Sep 17 00:00:00 2001 From: piro Date: Wed, 8 Apr 2009 10:03:17 +0000 Subject: [PATCH] =?UTF-8?q?=E3=82=B9=E3=83=A0=E3=83=BC=E3=82=BA=E3=82=B9?= =?UTF-8?q?=E3=82=AF=E3=83=AD=E3=83=BC=E3=83=AB=E3=82=92=E3=82=A2=E3=83=8B?= =?UTF-8?q?=E3=83=A1=E3=83=BC=E3=82=B7=E3=83=A7=E3=83=B3=E7=94=A8=E3=83=A9?= =?UTF-8?q?=E3=82=A4=E3=83=96=E3=83=A9=E3=83=AA=E3=82=92=E4=BD=BF=E3=81=A3?= =?UTF-8?q?=E3=81=A6=E6=9B=B8=E3=81=8D=E7=9B=B4=E3=81=97=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: http://www.cozmixng.org/repos/piro/treestyletab/trunk@4083 599a83e7-65a4-db11-8015-0010dcdd6dc2 --- content/treestyletab/res/animationManager.js | 17 ++-- content/treestyletab/treestyletabbrowser.js | 92 +++++++------------- 2 files changed, 44 insertions(+), 65 deletions(-) diff --git a/content/treestyletab/res/animationManager.js b/content/treestyletab/res/animationManager.js index 3a48c729..cdaa196c 100644 --- a/content/treestyletab/res/animationManager.js +++ b/content/treestyletab/res/animationManager.js @@ -87,12 +87,17 @@ { // task should return true if it finishes. aSelf.tasks = aSelf.tasks.filter(function(aTask) { - return !aTask.task( - Date.now() - aTask.start, - aTask.beginning, - aTask.final, - aTask.delay - ); + try { + return !aTask.task( + Date.now() - aTask.start, + aTask.beginning, + aTask.final, + aTask.delay + ); + } + catch(e) { + } + return true; }); if (!aSelf.tasks.length) aSelf.stop(); diff --git a/content/treestyletab/treestyletabbrowser.js b/content/treestyletab/treestyletabbrowser.js index c0fd5595..320e050e 100644 --- a/content/treestyletab/treestyletabbrowser.js +++ b/content/treestyletab/treestyletabbrowser.js @@ -3230,71 +3230,45 @@ TreeStyleTabBrowser.prototype = { smoothScrollTo : function(aEndX, aEndY) { var b = this.mTabBrowser; - if (this.smoothScrollTimer) { - window.clearInterval(this.smoothScrollTimer); - this.smoothScrollTimer = null; - } + window['piro.sakura.ne.jp'].animationManager.removeTask(this.smoothScrollTask); var scrollBoxObject = this.scrollBoxObject; var x = {}, y = {}; scrollBoxObject.getPosition(x, y); - this.smoothScrollTimer = window.setInterval( - this.smoothScrollToCallback, - 10, - this, - x.value, - y.value, - aEndX, - aEndY, - Date.now(), - this.getTreePref('tabbar.scroll.timeout') + var startX = x.value; + var startY = y.value; + var deltaX = aEndX - startX; + var deltaY = aEndY - startY; + + var self = this; + this.smoothScrollTask = function(aTime, aBeginning, aFinal, aDelay) { + var scrollBoxObject = self.scrollBoxObject; + var power = Math.min(1, aTime / aDelay); + if (power == 1) { + scrollBoxObject.scrollTo(aEndX, aEndY); + return true; + } + + var powerForPositioning = Math.sin(90 * power * Math.PI / 180); + var newX = startX + parseInt(deltaX * powerForPositioning); + var newY = startY + parseInt(deltaY * powerForPositioning); + + var x = {}, y = {}; + scrollBoxObject.getPosition(x, y); + + var w = {}, h = {}; + scrollBoxObject.getScrolledSize(w, h); + var maxX = Math.max(0, w.value - scrollBoxObject.width); + var maxY = Math.max(0, h.value - scrollBoxObject.height); + scrollBoxObject.scrollTo(newX, newY); + return false; + }; + window['piro.sakura.ne.jp'].animationManager.addTask( + this.smoothScrollTask, + 0, 0, this.getTreePref('tabbar.scroll.timeout') ); }, - - smoothScrollToCallback : function(aSelf, aStartX, aStartY, aEndX, aEndY, aStartTime, aTimeout) - { - var past = Date.now() - aStartTime; - - var newX = aStartX + parseInt( - (aEndX - aStartX) * (past / aTimeout) - ); - var newY = aStartY + parseInt( - (aEndY - aStartY) * (past / aTimeout) - ); - - var scrollBoxObject = aSelf.scrollBoxObject; - var x = {}, y = {}; - scrollBoxObject.getPosition(x, y); - - var w = {}, h = {}; - scrollBoxObject.getScrolledSize(w, h); - var maxX = Math.max(0, w.value - scrollBoxObject.width); - var maxY = Math.max(0, h.value - scrollBoxObject.height); - - if ( - (past > aTimeout) || - ( - ( - aEndX - aStartX > 0 ? - x.value >= Math.min(aEndX, maxX) : - x.value <= Math.min(aEndX, maxX) - ) && - ( - aEndY - aStartY > 0 ? - y.value >= Math.min(aEndY, maxY) : - y.value <= Math.min(aEndY, maxY) - ) - ) - ) { - if (aSelf.smoothScrollTimer) { - window.clearInterval(aSelf.smoothScrollTimer); - aSelf.smoothScrollTimer = null; - } - return; - } - - scrollBoxObject.scrollTo(newX, newY); - }, + smoothScrollTask : null, scrollToTab : function(aTab) {