From 9f420c88588df1a5481022c832b028cf63bc25c7 Mon Sep 17 00:00:00 2001 From: piro Date: Mon, 29 Oct 2007 14:52:52 +0000 Subject: [PATCH] =?UTF-8?q?=E9=80=9A=E5=B8=B8=E3=81=AE=E3=83=AA=E3=83=B3?= =?UTF-8?q?=E3=82=AF=E3=82=AF=E3=83=AA=E3=83=83=E3=82=AF=E3=82=84=E5=90=8C?= =?UTF-8?q?=E3=81=98=E3=82=B5=E3=82=A4=E3=83=88=E3=81=AEURI=E3=82=92?= =?UTF-8?q?=E3=83=AD=E3=82=B1=E3=83=BC=E3=82=B7=E3=83=A7=E3=83=B3=E3=83=90?= =?UTF-8?q?=E3=83=BC=E3=81=AB=E5=85=A5=E5=8A=9B=E3=81=97=E3=81=9F=E9=9A=9B?= =?UTF-8?q?=E3=81=AB=20=E7=8F=BE=E5=9C=A8=E3=81=AE=E3=82=BF=E3=83=96?= =?UTF-8?q?=E3=81=AE=E5=85=84=E5=BC=9F=E3=81=A8=E3=81=97=E3=81=A6=E9=96=8B?= =?UTF-8?q?=E3=81=8B=E3=82=8C=E3=82=8B=E3=82=BF=E3=83=96=E3=81=AB=E3=81=A4?= =?UTF-8?q?=E3=81=84=E3=81=A6=E3=80=81=E4=BB=AE=E6=83=B3=E7=9A=84=E3=81=AA?= =?UTF-8?q?=E3=82=B5=E3=83=96=E3=83=84=E3=83=AA=E3=83=BC=E3=82=92=20?= =?UTF-8?q?=E5=BD=A2=E6=88=90=E3=81=99=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB?= =?UTF-8?q?=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@1384 599a83e7-65a4-db11-8015-0010dcdd6dc2 --- content/treestyletab/treestyletab.js | 82 +++++++++++++++++++++------- 1 file changed, 62 insertions(+), 20 deletions(-) diff --git a/content/treestyletab/treestyletab.js b/content/treestyletab/treestyletab.js index db5feacc..2ec28456 100644 --- a/content/treestyletab/treestyletab.js +++ b/content/treestyletab/treestyletab.js @@ -95,7 +95,7 @@ var TreeStyleTabService = { /* API */ - readyToOpenChildTab : function(aFrameOrTabBrowser, aMultiple) + readyToOpenChildTab : function(aFrameOrTabBrowser, aMultiple, aInsertBefore) { var frame = this.getFrameFromTabBrowserElements(aFrameOrTabBrowser); if (!frame) return; @@ -104,6 +104,7 @@ var TreeStyleTabService = { ownerBrowser.__treestyletab__readyToAttachNewTab = true; ownerBrowser.__treestyletab__readyToAttachMultiple = aMultiple || false ; ownerBrowser.__treestyletab__parentTab = this.getTabFromFrame(frame, ownerBrowser).getAttribute(this.kID); + ownerBrowser.__treestyletab__insertBefore = aInsertBefore ? aInsertBefore.getAttribute(this.kID) : null ; }, readyToOpenNewTabGroup : function(aFrameOrTabBrowser) @@ -128,6 +129,7 @@ var TreeStyleTabService = { ownerBrowser.__treestyletab__readyToAttachNewTabGroup = false; ownerBrowser.__treestyletab__readyToAttachMultiple = false; ownerBrowser.__treestyletab__parentTab = null; + ownerBrowser.__treestyletab__insertBefore = null; }, checkToOpenChildTab : function(aFrameOrTabBrowser) @@ -144,6 +146,27 @@ var TreeStyleTabService = { var frame = this.getFrameFromTabBrowserElements(aFrameOrTabBrowser); if (!frame) return false; +/* + 挙動の説明 + + ・現在のサイトと異なるサイトを読み込む場合にタブを開く時: + →特に何もしない。新しく開くタブを子タブにする場合は別途 + readyToOpenChildTabを使う。 + + ・現在のサイトと同じサイトのページを読み込む場合にタブを開く時: + →親のタブは同じサイトか? + No :子タブを開く + Yes:兄弟としてタブを開く。ただし、このタブからのタブはすべて + 現在のタブと次の兄弟タブとの間に開かれ、仮想サブツリーとなる。 + →現在のタブに「__treestyletab__next」プロパティが + あるか? + Yes:__treestyletab__nextで示されたタブの直前に + 新しい兄弟タブを挿入する。 + No :現在のタブの次の兄弟タブのIDを__treestyletab__next + プロパティに保持し、仮想の子タブを挿入する位置の + 基準とする。 +*/ + var info = aInfo || { uri : '' }; if (/^javascript:/.test(info.uri)) return false; @@ -151,31 +174,39 @@ var TreeStyleTabService = { var internal = info.internal || {}; var targetHost = /^\w+:\/\/([^:\/]+)(\/|$)/.test(info.uri) ? RegExp.$1 : null ; + var currentTab = this.getTabFromFrame(frame); var currentURI = frame.location.href; var currentHost = currentURI.match(/^\w+:\/\/([^:\/]+)(\/|$)/) ? RegExp.$1 : null ; - var parentTab = this.getParentTab(this.getTabFromFrame(frame)); + var parentTab = this.getParentTab(currentTab); var parentURI = parentTab ? parentTab.linkedBrowser.currentURI : null ; var parentHost = parentURI && parentURI.spec.match(/^\w+:\/\/([^:\/]+)(\/|$)/) ? RegExp.$1 : null ; + var b = this.getTabBrowserFromFrame(frame); + var nextTab = this.getNextSiblingTab(currentTab); + return ( - ( - internal.newTab && - currentHost == targetHost && - currentURI != 'about:blank' && - currentURI.split('#')[0] != info.uri.split('#')[0] && - (this.readyToOpenChildTab( - parentHost == targetHost && !internal.forceChild ? - parentTab : - frame - ), true) - ) || - ( - external.newTab && - currentHost != targetHost && - currentURI != 'about:blank' && - (external.forceChild ? (this.readyToOpenChildTab(frame), true) : true ) - ) - ); + ( + internal.newTab && + currentHost == targetHost && + currentURI != 'about:blank' && + currentURI.split('#')[0] != info.uri.split('#')[0] && + (this.readyToOpenChildTab( + (parentHost == targetHost && !internal.forceChild ? parentTab : frame), + false, + (parentHost == targetHost && !internal.forceChild && ( + this.getTabById(currentTab.__treestyletab__next, b) || + (nextTab ? (currentTab.__treestyletab__next = nextTab.getAttribute(this.kID), nextTab) : null ) + )) + ), + true) + ) || + ( + external.newTab && + currentHost != targetHost && + currentURI != 'about:blank' && + (external.forceChild ? (this.readyToOpenChildTab(frame), true) : true ) + ) + ); }, /* Utilities */ @@ -1177,6 +1208,16 @@ catch(e) { var parent = this.getTabById(b.__treestyletab__parentTab, b); if (parent) this.attachTabTo(tab, parent); + + var insertBefore; + if (b.__treestyletab__insertBefore && + (insertBefore = this.getTabById(b.__treestyletab__insertBefore, b))) { + var index = insertBefore._tPos; + if (index > tab._tPos) index--; + b.__treestyletab__internallyTabMoving = true; + b.moveTabTo(tab, index); + b.__treestyletab__internallyTabMoving = false; + } } if (!b.__treestyletab__readyToAttachMultiple) { @@ -1505,6 +1546,7 @@ catch(e) { getTabById : function(aId, aTabBrowser) { + if (!aId || !aTabBrowser) return null; return this.evaluateXPath( 'descendant::xul:tab[@'+this.kID+' = "'+aId+'"]', aTabBrowser.mTabContainer,