通常のリンククリックや同じサイトのURIをロケーションバーに入力した際に

現在のタブの兄弟として開かれるタブについて、仮想的なサブツリーを
形成するようにした

git-svn-id: http://www.cozmixng.org/repos/piro/treestyletab/trunk@1384 599a83e7-65a4-db11-8015-0010dcdd6dc2
This commit is contained in:
piro 2007-10-29 14:52:52 +00:00
parent 62e5fed96e
commit 9f420c8858

View File

@ -95,7 +95,7 @@ var TreeStyleTabService = {
/* API */ /* API */
readyToOpenChildTab : function(aFrameOrTabBrowser, aMultiple) readyToOpenChildTab : function(aFrameOrTabBrowser, aMultiple, aInsertBefore)
{ {
var frame = this.getFrameFromTabBrowserElements(aFrameOrTabBrowser); var frame = this.getFrameFromTabBrowserElements(aFrameOrTabBrowser);
if (!frame) return; if (!frame) return;
@ -104,6 +104,7 @@ var TreeStyleTabService = {
ownerBrowser.__treestyletab__readyToAttachNewTab = true; ownerBrowser.__treestyletab__readyToAttachNewTab = true;
ownerBrowser.__treestyletab__readyToAttachMultiple = aMultiple || false ; ownerBrowser.__treestyletab__readyToAttachMultiple = aMultiple || false ;
ownerBrowser.__treestyletab__parentTab = this.getTabFromFrame(frame, ownerBrowser).getAttribute(this.kID); ownerBrowser.__treestyletab__parentTab = this.getTabFromFrame(frame, ownerBrowser).getAttribute(this.kID);
ownerBrowser.__treestyletab__insertBefore = aInsertBefore ? aInsertBefore.getAttribute(this.kID) : null ;
}, },
readyToOpenNewTabGroup : function(aFrameOrTabBrowser) readyToOpenNewTabGroup : function(aFrameOrTabBrowser)
@ -128,6 +129,7 @@ var TreeStyleTabService = {
ownerBrowser.__treestyletab__readyToAttachNewTabGroup = false; ownerBrowser.__treestyletab__readyToAttachNewTabGroup = false;
ownerBrowser.__treestyletab__readyToAttachMultiple = false; ownerBrowser.__treestyletab__readyToAttachMultiple = false;
ownerBrowser.__treestyletab__parentTab = null; ownerBrowser.__treestyletab__parentTab = null;
ownerBrowser.__treestyletab__insertBefore = null;
}, },
checkToOpenChildTab : function(aFrameOrTabBrowser) checkToOpenChildTab : function(aFrameOrTabBrowser)
@ -144,6 +146,27 @@ var TreeStyleTabService = {
var frame = this.getFrameFromTabBrowserElements(aFrameOrTabBrowser); var frame = this.getFrameFromTabBrowserElements(aFrameOrTabBrowser);
if (!frame) return false; if (!frame) return false;
/*
挙動の説明
現在のサイトと異なるサイトを読み込む場合にタブを開く時
特に何もしない新しく開くタブを子タブにする場合は別途
readyToOpenChildTabを使う
現在のサイトと同じサイトのページを読み込む場合にタブを開く時
親のタブは同じサイトか
No 子タブを開く
Yes兄弟としてタブを開くただしこのタブからのタブはすべて
現在のタブと次の兄弟タブとの間に開かれ仮想サブツリーとなる
現在のタブに__treestyletab__nextプロパティが
あるか
Yes__treestyletab__nextで示されたタブの直前に
新しい兄弟タブを挿入する
No 現在のタブの次の兄弟タブのIDを__treestyletab__next
プロパティに保持し仮想の子タブを挿入する位置の
基準とする
*/
var info = aInfo || { uri : '' }; var info = aInfo || { uri : '' };
if (/^javascript:/.test(info.uri)) return false; if (/^javascript:/.test(info.uri)) return false;
@ -151,31 +174,39 @@ var TreeStyleTabService = {
var internal = info.internal || {}; var internal = info.internal || {};
var targetHost = /^\w+:\/\/([^:\/]+)(\/|$)/.test(info.uri) ? RegExp.$1 : null ; var targetHost = /^\w+:\/\/([^:\/]+)(\/|$)/.test(info.uri) ? RegExp.$1 : null ;
var currentTab = this.getTabFromFrame(frame);
var currentURI = frame.location.href; var currentURI = frame.location.href;
var currentHost = currentURI.match(/^\w+:\/\/([^:\/]+)(\/|$)/) ? RegExp.$1 : null ; 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 parentURI = parentTab ? parentTab.linkedBrowser.currentURI : null ;
var parentHost = parentURI && parentURI.spec.match(/^\w+:\/\/([^:\/]+)(\/|$)/) ? RegExp.$1 : null ; var parentHost = parentURI && parentURI.spec.match(/^\w+:\/\/([^:\/]+)(\/|$)/) ? RegExp.$1 : null ;
var b = this.getTabBrowserFromFrame(frame);
var nextTab = this.getNextSiblingTab(currentTab);
return ( return (
( (
internal.newTab && internal.newTab &&
currentHost == targetHost && currentHost == targetHost &&
currentURI != 'about:blank' && currentURI != 'about:blank' &&
currentURI.split('#')[0] != info.uri.split('#')[0] && currentURI.split('#')[0] != info.uri.split('#')[0] &&
(this.readyToOpenChildTab( (this.readyToOpenChildTab(
parentHost == targetHost && !internal.forceChild ? (parentHost == targetHost && !internal.forceChild ? parentTab : frame),
parentTab : false,
frame (parentHost == targetHost && !internal.forceChild && (
), true) this.getTabById(currentTab.__treestyletab__next, b) ||
) || (nextTab ? (currentTab.__treestyletab__next = nextTab.getAttribute(this.kID), nextTab) : null )
( ))
external.newTab && ),
currentHost != targetHost && true)
currentURI != 'about:blank' && ) ||
(external.forceChild ? (this.readyToOpenChildTab(frame), true) : true ) (
) external.newTab &&
); currentHost != targetHost &&
currentURI != 'about:blank' &&
(external.forceChild ? (this.readyToOpenChildTab(frame), true) : true )
)
);
}, },
/* Utilities */ /* Utilities */
@ -1177,6 +1208,16 @@ catch(e) {
var parent = this.getTabById(b.__treestyletab__parentTab, b); var parent = this.getTabById(b.__treestyletab__parentTab, b);
if (parent) if (parent)
this.attachTabTo(tab, 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) { if (!b.__treestyletab__readyToAttachMultiple) {
@ -1505,6 +1546,7 @@ catch(e) {
getTabById : function(aId, aTabBrowser) getTabById : function(aId, aTabBrowser)
{ {
if (!aId || !aTabBrowser) return null;
return this.evaluateXPath( return this.evaluateXPath(
'descendant::xul:tab[@'+this.kID+' = "'+aId+'"]', 'descendant::xul:tab[@'+this.kID+' = "'+aId+'"]',
aTabBrowser.mTabContainer, aTabBrowser.mTabContainer,