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

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. // task should return true if it finishes.
aSelf.tasks = aSelf.tasks.filter(function(aTask) { aSelf.tasks = aSelf.tasks.filter(function(aTask) {
return !aTask.task( try {
Date.now() - aTask.start, return !aTask.task(
aTask.beginning, Date.now() - aTask.start,
aTask.final, aTask.beginning,
aTask.delay aTask.final,
); aTask.delay
);
}
catch(e) {
}
return true;
}); });
if (!aSelf.tasks.length) if (!aSelf.tasks.length)
aSelf.stop(); aSelf.stop();

View File

@ -3230,71 +3230,45 @@ TreeStyleTabBrowser.prototype = {
smoothScrollTo : function(aEndX, aEndY) smoothScrollTo : function(aEndX, aEndY)
{ {
var b = this.mTabBrowser; var b = this.mTabBrowser;
if (this.smoothScrollTimer) { window['piro.sakura.ne.jp'].animationManager.removeTask(this.smoothScrollTask);
window.clearInterval(this.smoothScrollTimer);
this.smoothScrollTimer = null;
}
var scrollBoxObject = this.scrollBoxObject; var scrollBoxObject = this.scrollBoxObject;
var x = {}, y = {}; var x = {}, y = {};
scrollBoxObject.getPosition(x, y); scrollBoxObject.getPosition(x, y);
this.smoothScrollTimer = window.setInterval( var startX = x.value;
this.smoothScrollToCallback, var startY = y.value;
10, var deltaX = aEndX - startX;
this, var deltaY = aEndY - startY;
x.value,
y.value, var self = this;
aEndX, this.smoothScrollTask = function(aTime, aBeginning, aFinal, aDelay) {
aEndY, var scrollBoxObject = self.scrollBoxObject;
Date.now(), var power = Math.min(1, aTime / aDelay);
this.getTreePref('tabbar.scroll.timeout') 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')
); );
}, },
smoothScrollTask : null,
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);
},
scrollToTab : function(aTab) scrollToTab : function(aTab)
{ {