From 7a54211b252a7b2aee7caebb745cdb2801f13380 Mon Sep 17 00:00:00 2001 From: piro Date: Fri, 20 Jun 2008 05:57:38 +0000 Subject: [PATCH] =?UTF-8?q?Tab=20Mix=20Plus=E3=81=AE=E3=82=BB=E3=83=83?= =?UTF-8?q?=E3=82=B7=E3=83=A7=E3=83=B3=E4=BF=9D=E5=AD=98=E6=A9=9F=E8=83=BD?= =?UTF-8?q?=E3=81=AB=E5=AF=BE=E5=BF=9C?= 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@2700 599a83e7-65a4-db11-8015-0010dcdd6dc2 --- content/treestyletab/hacks.js | 60 +++++++++++++++++++++ content/treestyletab/treestyletab.js | 20 +++++-- content/treestyletab/treestyletabbrowser.js | 29 ++++++---- 3 files changed, 97 insertions(+), 12 deletions(-) diff --git a/content/treestyletab/hacks.js b/content/treestyletab/hacks.js index 69910fbb..b1210b38 100644 --- a/content/treestyletab/hacks.js +++ b/content/treestyletab/hacks.js @@ -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;', + + ) + ); + eval('SessionData.setTabProperties = '+ + SessionData.setTabProperties.toSource().replace( + '{', + + ) + ); + eval('SessionManager.loadOneTab = '+ + SessionManager.loadOneTab.toSource().replace( + /(\}\))?$/, + + ) + ); + var source = tablib.init.toSource().split('gBrowser.restoreTab = '); + source[1] = source[1].replace( + 'return newTab;', + + ); + eval('tablib.init = '+source.join('gBrowser.restoreTab = ')); + this.useTMPSessionAPI = true; + } }; TreeStyleTabService.overrideExtensionsOnInitBefore = function() { diff --git a/content/treestyletab/treestyletab.js b/content/treestyletab/treestyletab.js index fcfbf01e..0e54c339 100644 --- a/content/treestyletab/treestyletab.js +++ b/content/treestyletab/treestyletab.js @@ -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,7 +812,13 @@ 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 */ diff --git a/content/treestyletab/treestyletabbrowser.js b/content/treestyletab/treestyletabbrowser.js index 8f0c3c3f..bfbd0d73 100644 --- a/content/treestyletab/treestyletabbrowser.js +++ b/content/treestyletab/treestyletabbrowser.js @@ -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,7 +571,8 @@ TreeStyleTabBrowser.prototype = { continue; nodes[i].setAttribute('ordinal', (nodes.length - i + 1) * 10); } - counter.setAttribute('ordinal', parseInt(label.getAttribute('ordinal')) + 1); + if (counter) + counter.setAttribute('ordinal', parseInt(label.getAttribute('ordinal')) + 1); close.setAttribute('ordinal', parseInt(label.parentNode.getAttribute('ordinal')) - 5); } else { @@ -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);