Tab Mix Plusのセッション保存機能に対応

git-svn-id: http://www.cozmixng.org/repos/piro/treestyletab/trunk@2700 599a83e7-65a4-db11-8015-0010dcdd6dc2
This commit is contained in:
piro 2008-06-20 05:57:38 +00:00
parent 9a63c01ef8
commit 7a54211b25
3 changed files with 97 additions and 12 deletions

View File

@ -21,6 +21,66 @@ TreeStyleTabService.overrideExtensionsPreInit = function() {
);
}
// Tab Mix Plus, SessionStore API
if ('SessionData' in window &&
'getTabProperties' in SessionData &&
'setTabProperties' in SessionData) {
var prefix = this.kTMP_SESSION_DATA_PREFIX;
SessionData.tabTSTProperties = [
prefix+this.kID,
prefix+this.kCOLLAPSED,
prefix+this.kSUBTREE_COLLAPSED,
prefix+this.kCHILDREN,
prefix+this.kPARENT,
prefix+this.kANCESTOR,
prefix+this.kINSERT_BEFORE
];
eval('SessionData.getTabProperties = '+
SessionData.getTabProperties.toSource().replace(
'return tabProperties;',
<![CDATA[
this.tabTSTProperties.forEach(function(aProp) {
tabProperties += '|' + aProp + '=' + encodeURIComponent(aTab.getAttribute(aProp));
});
$&]]>
)
);
eval('SessionData.setTabProperties = '+
SessionData.setTabProperties.toSource().replace(
'{',
<![CDATA[$&
var TSTProps = tabProperties.split('|');
tabProperties = TSTProps.shift();
TSTProps.forEach(function(aSet) {
var index = aSet.indexOf('=');
var name = aSet.substring(0, index);
var value = decodeURIComponent(aSet.substring(index+1));
if (name && value)
aTab.setAttribute(name, value);
});
]]>
)
);
eval('SessionManager.loadOneTab = '+
SessionManager.loadOneTab.toSource().replace(
/(\}\))?$/,
<![CDATA[
if (gBrowser.treeStyleTab.useTMPSessionAPI)
gBrowser.treeStyleTab.onTabRestored({ target : aTab, originalTarget : aTab });
$1]]>
)
);
var source = tablib.init.toSource().split('gBrowser.restoreTab = ');
source[1] = source[1].replace(
'return newTab;',
<![CDATA[
if (this.treeStyleTab.useTMPSessionAPI)
this.treeStyleTab.onTabRestored({ target : newTab, originalTarget : newTab });
$&]]>
);
eval('tablib.init = '+source.join('gBrowser.restoreTab = '));
this.useTMPSessionAPI = true;
}
};
TreeStyleTabService.overrideExtensionsOnInitBefore = function() {

View File

@ -779,20 +779,28 @@ var TreeStyleTabService = {
catch(e) {
}
if (this.useTMPSessionAPI) {
var TMPValue = aTab.getAttribute(this.kTMP_SESSION_DATA_PREFIX+aKey);
if (TMPValue) value = TMPValue;
}
return value;
},
setTabValue : function(aTab, aKey, aValue)
{
if (!aValue) {
return this.deleteTabValue(aTab, aKey);
}
if (!aValue) return this.deleteTabValue(aTab, aKey);
aTab.setAttribute(aKey, aValue);
try {
this.SessionStore.setTabValue(aTab, aKey, aValue);
}
catch(e) {
}
if (this.useTMPSessionAPI)
aTab.setAttribute(this.kTMP_SESSION_DATA_PREFIX+aKey, aValue);
return aValue;
},
@ -804,8 +812,14 @@ var TreeStyleTabService = {
}
catch(e) {
}
if (this.useTMPSessionAPI)
aTab.removeAttribute(this.kTMP_SESSION_DATA_PREFIX+aKey);
},
useTMPSessionAPI : false,
kTMP_SESSION_DATA_PREFIX : 'tmp-session-data-',
/* Initializing */
preInit : function()

View File

@ -44,6 +44,15 @@ TreeStyleTabBrowser.prototype = {
},
_container : null,
get scrollBox()
{
return this.mTabBrowser.mTabContainer.mTabstrip;
},
get scrollBoxObject()
{
return this.scrollBox.scrollBoxObject;
},
/* utils */
/* get tab contents */
@ -69,7 +78,7 @@ TreeStyleTabBrowser.prototype = {
{
var b = this.mTabBrowser;
if (!b) return false;
var box = b.mTabContainer.mTabstrip || b.mTabContainer ;
var box = this.scrollBox || b.mTabContainer ;
return (box.getAttribute('orient') || window.getComputedStyle(box, '').getPropertyValue('-moz-box-orient')) == 'vertical';
},
@ -77,7 +86,7 @@ TreeStyleTabBrowser.prototype = {
{
if (!aTab) return false;
var tabBox = aTab.boxObject;
var barBox = this.mTabBrowser.mTabContainer.mTabstrip.boxObject;
var barBox = this.scrollBox.boxObject;
return (tabBox.screenX >= barBox.screenX &&
tabBox.screenX + tabBox.width <= barBox.screenX + barBox.width &&
tabBox.screenY >= barBox.screenY &&
@ -562,6 +571,7 @@ TreeStyleTabBrowser.prototype = {
continue;
nodes[i].setAttribute('ordinal', (nodes.length - i + 1) * 10);
}
if (counter)
counter.setAttribute('ordinal', parseInt(label.getAttribute('ordinal')) + 1);
close.setAttribute('ordinal', parseInt(label.parentNode.getAttribute('ordinal')) - 5);
}
@ -974,7 +984,8 @@ TreeStyleTabBrowser.prototype = {
this.onTabRemoved(aEvent);
if (this.isVertical) {
var x = {}, y = {};
var scrollBoxObject = this.mTabBrowser.mTabContainer.mTabstrip.scrollBoxObject;
var scrollBoxObject = this.scrollBoxObject;
if (!scrollBoxObject) return;
scrollBoxObject.getPosition(x, y);
this.lastScrollX = x.value;
this.lastScrollY = y.value;
@ -1115,7 +1126,7 @@ TreeStyleTabBrowser.prototype = {
if (node && node.ownerDocument == document) {
if (this.lastScrollX < 0 || this.lastScrollY < 0) return;
var x = {}, y = {};
var scrollBoxObject = this.mTabBrowser.mTabContainer.mTabstrip.scrollBoxObject;
var scrollBoxObject = this.scrollBoxObject;
scrollBoxObject.getPosition(x, y);
if (x.value != this.lastScrollX || y.value != this.lastScrollY)
scrollBoxObject.scrollTo(this.lastScrollX, this.lastScrollY);
@ -2643,7 +2654,7 @@ TreeStyleTabBrowser.prototype = {
}
else {
try {
this.mTabBrowser.mTabContainer.mTabstrip.scrollBoxObject.scrollTo(aEndX, aEndY);
this.scrollBoxObject.scrollTo(aEndX, aEndY);
}
catch(e) {
}
@ -2658,7 +2669,7 @@ TreeStyleTabBrowser.prototype = {
this.smoothScrollTimer = null;
}
var scrollBoxObject = b.mTabContainer.mTabstrip.scrollBoxObject;
var scrollBoxObject = this.scrollBoxObject;
var x = {}, y = {};
scrollBoxObject.getPosition(x, y);
this.smoothScrollTimer = window.setInterval(
@ -2685,7 +2696,7 @@ TreeStyleTabBrowser.prototype = {
(aEndY - aStartY) * (past / aTimeout)
);
var scrollBoxObject = aSelf.mTabBrowser.mTabContainer.mTabstrip.scrollBoxObject;
var scrollBoxObject = aSelf.scrollBoxObject;
var x = {}, y = {};
scrollBoxObject.getPosition(x, y);
@ -2725,7 +2736,7 @@ TreeStyleTabBrowser.prototype = {
var b = this.mTabBrowser;
var scrollBoxObject = b.mTabContainer.mTabstrip.scrollBoxObject;
var scrollBoxObject = this.scrollBoxObject;
var w = {}, h = {};
try {
scrollBoxObject.getScrolledSize(w, h);