スムーズスクロールをアニメーション用ライブラリを使って書き直した

git-svn-id: http://www.cozmixng.org/repos/piro/treestyletab/trunk@4083 599a83e7-65a4-db11-8015-0010dcdd6dc2
This commit is contained in:
piro 2009-04-08 10:03:17 +00:00
parent 27b7da7bc9
commit 6ea5440b1d
2 changed files with 44 additions and 65 deletions

View File

@ -87,12 +87,17 @@
{
// task should return true if it finishes.
aSelf.tasks = aSelf.tasks.filter(function(aTask) {
try {
return !aTask.task(
Date.now() - aTask.start,
aTask.beginning,
aTask.final,
aTask.delay
);
}
catch(e) {
}
return true;
});
if (!aSelf.tasks.length)
aSelf.stop();

View File

@ -3230,39 +3230,29 @@ 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;
smoothScrollToCallback : function(aSelf, aStartX, aStartY, aEndX, aEndY, aStartTime, aTimeout)
{
var past = Date.now() - aStartTime;
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 newX = aStartX + parseInt(
(aEndX - aStartX) * (past / aTimeout)
);
var newY = aStartY + parseInt(
(aEndY - aStartY) * (past / aTimeout)
);
var powerForPositioning = Math.sin(90 * power * Math.PI / 180);
var newX = startX + parseInt(deltaX * powerForPositioning);
var newY = startY + parseInt(deltaY * powerForPositioning);
var scrollBoxObject = aSelf.scrollBoxObject;
var x = {}, y = {};
scrollBoxObject.getPosition(x, y);
@ -3270,31 +3260,15 @@ TreeStyleTabBrowser.prototype = {
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);
return false;
};
window['piro.sakura.ne.jp'].animationManager.addTask(
this.smoothScrollTask,
0, 0, this.getTreePref('tabbar.scroll.timeout')
);
},
smoothScrollTask : null,
scrollToTab : function(aTab)
{