DOM3 XPathの利用を減らした
git-svn-id: http://www.cozmixng.org/repos/piro/treestyletab/trunk@6335 599a83e7-65a4-db11-8015-0010dcdd6dc2
This commit is contained in:
parent
c18e0c611c
commit
992a34dc99
@ -574,10 +574,7 @@ TreeStyleTabService.overrideExtensionsOnInitAfter = function TSTService_override
|
|||||||
window.getRowHeight.toSource().replace(
|
window.getRowHeight.toSource().replace(
|
||||||
'var tabs = getBrowser().mTabContainer.childNodes;',
|
'var tabs = getBrowser().mTabContainer.childNodes;',
|
||||||
<![CDATA[
|
<![CDATA[
|
||||||
var tabsResult = TreeStyleTabService.getVisibleTabs(getBrowser().selectedTab);
|
var tabs = TreeStyleTabService.getVisibleTabsArray(getBrowser().selectedTab);
|
||||||
var tabs = [];
|
|
||||||
for (var t = 0, maxt = tabsResult.snapshotLength; t < maxt; t++)
|
|
||||||
tabs.push(tabsResult.snapshotItem(t));
|
|
||||||
]]>
|
]]>
|
||||||
).replace(
|
).replace(
|
||||||
/tabs.item\(([^\)]+)\)/g,
|
/tabs.item\(([^\)]+)\)/g,
|
||||||
|
@ -131,20 +131,19 @@ TreeStyleTabBrowser.prototype = {
|
|||||||
getTabById : function TSTBrowser_getTabById(aId, aTabBrowserChildren)
|
getTabById : function TSTBrowser_getTabById(aId, aTabBrowserChildren)
|
||||||
{
|
{
|
||||||
if (!aId) return null;
|
if (!aId) return null;
|
||||||
|
|
||||||
if (!aTabBrowserChildren)
|
if (!aTabBrowserChildren)
|
||||||
return aId in this._tabsCache ? this._tabsCache[aId] : null ;
|
return aId in this._tabsCache ? this._tabsCache[aId] : null ;
|
||||||
|
|
||||||
if (aTabBrowserChildren.__treestyletab__linkedTabBrowser)
|
var b = this.getTabBrowserFromChild(aTabBrowserChildren);
|
||||||
return aTabBrowserChildren.__treestyletab__linkedTabBrowser.treeStyleTab.getTabById(aId);
|
return b ? b.treeStyleTab.getTabById(aId) : null ;
|
||||||
|
|
||||||
return this.utils.getTabById(aId, aTabBrowserChildren);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
getParentTab : function TSTBrowser_getParentTab(aTab) /* PUBLIC API */
|
getParentTab : function TSTBrowser_getParentTab(aTab) /* PUBLIC API */
|
||||||
{
|
{
|
||||||
if (!aTab) return null;
|
if (!aTab) return null;
|
||||||
var parent = aTab.getAttribute(this.kPARENT);
|
var b = this.getTabBrowserFromChild(aTab);
|
||||||
return aTab.__treestyletab__linkedTabBrowser.treeStyleTab.getTabById(parent);
|
return b.treeStyleTab.getTabById(aTab.getAttribute(this.kPARENT));
|
||||||
},
|
},
|
||||||
|
|
||||||
// getParentTab : function TSTBrowser_getParentTab(aTab) /* PUBLIC API */
|
// getParentTab : function TSTBrowser_getParentTab(aTab) /* PUBLIC API */
|
||||||
@ -578,11 +577,10 @@ TreeStyleTabBrowser.prototype = {
|
|||||||
'{ if (!this.treeStyleTab.warnAboutClosingTabSubtreeOf(this.selectedTab)) return;'
|
'{ if (!this.treeStyleTab.warnAboutClosingTabSubtreeOf(this.selectedTab)) return;'
|
||||||
));
|
));
|
||||||
|
|
||||||
let (tabs, i, maxi) {
|
let (tabs = this.getTabsArray(b)) {
|
||||||
tabs = this.getTabs(b);
|
for each (let tab in tabs)
|
||||||
for (i = 0, maxi = tabs.snapshotLength; i < maxi; i++)
|
|
||||||
{
|
{
|
||||||
this.initTab(tabs.snapshotItem(i));
|
this.initTab(tab);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1673,7 +1671,7 @@ TreeStyleTabBrowser.prototype = {
|
|||||||
// for last tab closing, we have to open new tab manually if running on Firefox 3.0.
|
// for last tab closing, we have to open new tab manually if running on Firefox 3.0.
|
||||||
if (
|
if (
|
||||||
!('_beginRemoveTab' in b) && !('_endRemoveTab' in b) && // Firefox 3.0.x
|
!('_beginRemoveTab' in b) && !('_endRemoveTab' in b) && // Firefox 3.0.x
|
||||||
this.getTabs(b).snapshotLength == 1 // last tab
|
this.getTabsArray(b).length == 1 // last tab
|
||||||
) {
|
) {
|
||||||
b.addTab('about:blank');
|
b.addTab('about:blank');
|
||||||
}
|
}
|
||||||
@ -1925,7 +1923,7 @@ TreeStyleTabBrowser.prototype = {
|
|||||||
|
|
||||||
var old = aEvent.detail;
|
var old = aEvent.detail;
|
||||||
if (old > tab._tPos) old--;
|
if (old > tab._tPos) old--;
|
||||||
old = this.getTabs(b).snapshotItem(old);
|
old = this.getTabsArray(b)[old];
|
||||||
|
|
||||||
prev = this.getPreviousSiblingTab(old);
|
prev = this.getPreviousSiblingTab(old);
|
||||||
next = this.getNextSiblingTab(old);
|
next = this.getNextSiblingTab(old);
|
||||||
@ -1963,7 +1961,7 @@ TreeStyleTabBrowser.prototype = {
|
|||||||
if (aOldPosition === void(0)) aOldPosition = aTab._tPos;
|
if (aOldPosition === void(0)) aOldPosition = aTab._tPos;
|
||||||
|
|
||||||
var pos = this.getChildIndex(aTab, parent);
|
var pos = this.getChildIndex(aTab, parent);
|
||||||
var oldPos = this.getChildIndex(this.getTabs(this.mTabBrowser).snapshotItem(aOldPosition), parent);
|
var oldPos = this.getChildIndex(this.getTabsArray(this.mTabBrowser)[aOldPosition], parent);
|
||||||
var delta;
|
var delta;
|
||||||
if (pos == oldPos) { // no move?
|
if (pos == oldPos) { // no move?
|
||||||
return;
|
return;
|
||||||
@ -2677,10 +2675,10 @@ TreeStyleTabBrowser.prototype = {
|
|||||||
{
|
{
|
||||||
if (!this.getTreePref('enableSubtreeIndent.allTabsPopup')) return;
|
if (!this.getTreePref('enableSubtreeIndent.allTabsPopup')) return;
|
||||||
var items = aEvent.target.childNodes;
|
var items = aEvent.target.childNodes;
|
||||||
var tabs = this.getTabs(this.mTabBrowser);
|
var tabs = this.getTabsArray(this.mTabBrowser);
|
||||||
for (var i = 0, maxi = items.length; i < maxi; i++)
|
for (var i = 0, maxi = items.length; i < maxi; i++)
|
||||||
{
|
{
|
||||||
items[i].style.paddingLeft = tabs.snapshotItem(i).getAttribute(this.kNEST)+'em';
|
items[i].style.paddingLeft = tabs[i].getAttribute(this.kNEST)+'em';
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -2942,7 +2940,7 @@ TreeStyleTabBrowser.prototype = {
|
|||||||
var newRoots = [];
|
var newRoots = [];
|
||||||
var shouldClose = (
|
var shouldClose = (
|
||||||
aInfo.action & this.kACTION_IMPORT &&
|
aInfo.action & this.kACTION_IMPORT &&
|
||||||
this.getTabs(sourceBrowser).snapshotLength == draggedTabs.length
|
this.getTabsArray(sourceBrowser).length == draggedTabs.length
|
||||||
);
|
);
|
||||||
var oldTabs = [];
|
var oldTabs = [];
|
||||||
var newTabs = [];
|
var newTabs = [];
|
||||||
@ -3155,7 +3153,7 @@ TreeStyleTabBrowser.prototype = {
|
|||||||
action : this.kACTIONS_FOR_DESTINATION | this.kACTION_IMPORT
|
action : this.kACTIONS_FOR_DESTINATION | this.kACTION_IMPORT
|
||||||
};
|
};
|
||||||
var tabsInfo = this.getDraggedTabsInfoFromOneTab(actionInfo, aTab);
|
var tabsInfo = this.getDraggedTabsInfoFromOneTab(actionInfo, aTab);
|
||||||
return tabsInfo.draggedTabs.length == this.getTabs(this.mTabBrowser).snapshotLength;
|
return tabsInfo.draggedTabs.length == this.getTabsArray(this.mTabBrowser).length;
|
||||||
},
|
},
|
||||||
|
|
||||||
/* commands */
|
/* commands */
|
||||||
|
117
modules/utils.js
117
modules/utils.js
@ -689,11 +689,9 @@ var TreeStyleTabUtils = {
|
|||||||
.QueryInterface(Ci.nsIInterfaceRequestor)
|
.QueryInterface(Ci.nsIInterfaceRequestor)
|
||||||
.getInterface(Ci.nsIWebNavigation)
|
.getInterface(Ci.nsIWebNavigation)
|
||||||
.QueryInterface(Ci.nsIDocShell);
|
.QueryInterface(Ci.nsIDocShell);
|
||||||
var tabs = this.getTabs(b);
|
var tabs = this.getTabsArray(b);
|
||||||
var tab;
|
for each (var tab in tabs)
|
||||||
for (var i = 0, maxi = tabs.snapshotLength; i < maxi; i++)
|
|
||||||
{
|
{
|
||||||
tab = tabs.snapshotItem(i);
|
|
||||||
if (tab.linkedBrowser.docShell == docShell)
|
if (tab.linkedBrowser.docShell == docShell)
|
||||||
return tab;
|
return tab;
|
||||||
}
|
}
|
||||||
@ -837,7 +835,7 @@ var TreeStyleTabUtils = {
|
|||||||
).booleanValue;
|
).booleanValue;
|
||||||
},
|
},
|
||||||
|
|
||||||
getTabs : function TSTUtils_getTabs(aTabBrowserChild)
|
getTabs : function TSTUtils_getTabs(aTabBrowserChild) /* OBSOLETE */
|
||||||
{
|
{
|
||||||
var b = this.getTabBrowserFromChild(aTabBrowserChild);
|
var b = this.getTabBrowserFromChild(aTabBrowserChild);
|
||||||
return this.evaluateXPath(
|
return this.evaluateXPath(
|
||||||
@ -848,109 +846,84 @@ var TreeStyleTabUtils = {
|
|||||||
|
|
||||||
getTabsArray : function TSTUtils_getTabsArray(aTabBrowserChild)
|
getTabsArray : function TSTUtils_getTabsArray(aTabBrowserChild)
|
||||||
{
|
{
|
||||||
var tabs = this.getTabs(aTabBrowserChild);
|
var b = this.getTabBrowserFromChild(aTabBrowserChild);
|
||||||
var array = [];
|
return Array.slice(b.mTabContainer.childNodes);
|
||||||
for (var i = 0, maxi = tabs.snapshotLength; i < maxi; i++)
|
|
||||||
{
|
|
||||||
array.push(tabs.snapshotItem(i));
|
|
||||||
}
|
|
||||||
return array;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
getFirstTab : function TSTUtils_getFirstTab(aTabBrowserChild)
|
getFirstTab : function TSTUtils_getFirstTab(aTabBrowserChild)
|
||||||
{
|
{
|
||||||
var b = this.getTabBrowserFromChild(aTabBrowserChild);
|
var b = this.getTabBrowserFromChild(aTabBrowserChild);
|
||||||
return this.evaluateXPath(
|
return b.mTabContainer.firstChild;
|
||||||
'child::xul:tab[1]',
|
|
||||||
b.mTabContainer,
|
|
||||||
Ci.nsIDOMXPathResult.FIRST_ORDERED_NODE_TYPE
|
|
||||||
).singleNodeValue;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
getLastTab : function TSTUtils_getLastTab(aTabBrowserChild)
|
getLastTab : function TSTUtils_getLastTab(aTabBrowserChild)
|
||||||
{
|
{
|
||||||
var b = this.getTabBrowserFromChild(aTabBrowserChild);
|
var b = this.getTabBrowserFromChild(aTabBrowserChild);
|
||||||
return this.evaluateXPath(
|
return b.mTabContainer.lastChild;
|
||||||
'child::xul:tab[last()]',
|
|
||||||
b.mTabContainer,
|
|
||||||
Ci.nsIDOMXPathResult.FIRST_ORDERED_NODE_TYPE
|
|
||||||
).singleNodeValue;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
getNextTab : function TSTUtils_getNextTab(aTab)
|
getNextTab : function TSTUtils_getNextTab(aTab)
|
||||||
{
|
{
|
||||||
if (!aTab) return null;
|
if (!aTab) return null;
|
||||||
return this.evaluateXPath(
|
var tab = aTab.nextSibling;
|
||||||
'following-sibling::xul:tab[1]',
|
return (tab && tab.localName == 'tab') ? tab : null ;
|
||||||
aTab,
|
|
||||||
Ci.nsIDOMXPathResult.FIRST_ORDERED_NODE_TYPE
|
|
||||||
).singleNodeValue;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
getPreviousTab : function TSTUtils_getPreviousTab(aTab)
|
getPreviousTab : function TSTUtils_getPreviousTab(aTab)
|
||||||
{
|
{
|
||||||
if (!aTab) return null;
|
if (!aTab) return null;
|
||||||
return this.evaluateXPath(
|
var tab = aTab.previousSibling;
|
||||||
'preceding-sibling::xul:tab[1]',
|
return (tab && tab.localName == 'tab') ? tab : null ;
|
||||||
aTab,
|
|
||||||
Ci.nsIDOMXPathResult.FIRST_ORDERED_NODE_TYPE
|
|
||||||
).singleNodeValue;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
getTabIndex : function TSTUtils_getTabIndex(aTab)
|
getTabIndex : function TSTUtils_getTabIndex(aTab)
|
||||||
{
|
{
|
||||||
if (!aTab) return -1;
|
if (!aTab) return -1;
|
||||||
return this.evaluateXPath(
|
var b = this.getTabBrowserFromChild(aTab);
|
||||||
'count(preceding-sibling::xul:tab)',
|
return this.getTabsArray(b).indexOf(aTab);
|
||||||
aTab,
|
|
||||||
Ci.nsIDOMXPathResult.NUMBER_TYPE
|
|
||||||
).numberValue;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
getNextVisibleTab : function TSTUtils_getNextVisibleTab(aTab)
|
getNextVisibleTab : function TSTUtils_getNextVisibleTab(aTab)
|
||||||
{
|
{
|
||||||
if (!aTab) return null;
|
if (!aTab) return null;
|
||||||
|
|
||||||
if (!this.canCollapseSubtree(aTab))
|
var b = this.getTabBrowserFromChild(aTab);
|
||||||
|
if (!this.canCollapseSubtree(b))
|
||||||
return this.getNextTab(aTab);
|
return this.getNextTab(aTab);
|
||||||
|
|
||||||
return this.evaluateXPath(
|
var tabs = this.getVisibleTabsArray(b);
|
||||||
'following-sibling::xul:tab[not(@'+this.kCOLLAPSED+'="true")][1]',
|
if (tabs.indexOf(aTab) < 0) tabs.push(aTab);
|
||||||
aTab,
|
tabs.sort(this.sortTabsByOrder);
|
||||||
Ci.nsIDOMXPathResult.FIRST_ORDERED_NODE_TYPE
|
|
||||||
).singleNodeValue;
|
var index = tabs.indexOf(aTab);
|
||||||
|
return (index < tabs.length-1) ? tabs[index+1] : null ;
|
||||||
},
|
},
|
||||||
|
|
||||||
getPreviousVisibleTab : function TSTUtils_getPreviousVisibleTab(aTab)
|
getPreviousVisibleTab : function TSTUtils_getPreviousVisibleTab(aTab)
|
||||||
{
|
{
|
||||||
if (!aTab) return null;
|
if (!aTab) return null;
|
||||||
|
|
||||||
if (!this.canCollapseSubtree(aTab))
|
var b = this.getTabBrowserFromChild(aTab);
|
||||||
|
if (!this.canCollapseSubtree(b))
|
||||||
return this.getPreviousTab(aTab);
|
return this.getPreviousTab(aTab);
|
||||||
|
|
||||||
return this.evaluateXPath(
|
var tabs = this.getVisibleTabsArray(b);
|
||||||
'preceding-sibling::xul:tab[not(@'+this.kCOLLAPSED+'="true")][1]',
|
if (tabs.indexOf(aTab) < 0) tabs.push(aTab);
|
||||||
aTab,
|
tabs.sort(this.sortTabsByOrder);
|
||||||
Ci.nsIDOMXPathResult.FIRST_ORDERED_NODE_TYPE
|
|
||||||
).singleNodeValue;
|
var index = tabs.indexOf(aTab);
|
||||||
|
return (index > 0) ? tabs[index-1] : null ;
|
||||||
},
|
},
|
||||||
|
|
||||||
getLastVisibleTab : function TSTUtils_getLastVisibleTab(aTabBrowserChild)
|
getLastVisibleTab : function TSTUtils_getLastVisibleTab(aTabBrowserChild)
|
||||||
{
|
{
|
||||||
var b = this.getTabBrowserFromChild(aTabBrowserChild);
|
var b = this.getTabBrowserFromChild(aTabBrowserChild);
|
||||||
if (!b) return null;
|
if (!b) return null;
|
||||||
|
var tabs = this.getVisibleTabsArray(b);
|
||||||
if (!this.canCollapseSubtree(b))
|
return tabs.length ? tabs[tabs.length-1] : null ;
|
||||||
return this.getLastTab(b);
|
|
||||||
|
|
||||||
return this.evaluateXPath(
|
|
||||||
'child::xul:tab[not(@'+this.kCOLLAPSED+'="true")][last()]',
|
|
||||||
b.mTabContainer,
|
|
||||||
Ci.nsIDOMXPathResult.FIRST_ORDERED_NODE_TYPE
|
|
||||||
).singleNodeValue;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
getVisibleTabs : function TSTUtils_getVisibleTabs(aTabBrowserChild)
|
getVisibleTabs : function TSTUtils_getVisibleTabs(aTabBrowserChild) /* OBSOLETE */
|
||||||
{
|
{
|
||||||
var b = this.getTabBrowserFromChild(aTabBrowserChild);
|
var b = this.getTabBrowserFromChild(aTabBrowserChild);
|
||||||
if (!this.canCollapseSubtree(b))
|
if (!this.canCollapseSubtree(b))
|
||||||
@ -963,20 +936,22 @@ var TreeStyleTabUtils = {
|
|||||||
return XPathResult;
|
return XPathResult;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
getVisibleTabsArray : function TSTUtils_getVisibleTabsArray(aTabBrowserChild)
|
||||||
|
{
|
||||||
|
var b = this.getTabBrowserFromChild(aTabBrowserChild);
|
||||||
|
var tabs = this.getTabsArray(b);
|
||||||
|
return this.canCollapseSubtree(b) ?
|
||||||
|
tabs.filter(function(aTab) {
|
||||||
|
return aTab.getAttribute(this.kCOLLAPSED) != 'true';
|
||||||
|
}, this) :
|
||||||
|
tabs ;
|
||||||
|
},
|
||||||
|
|
||||||
getVisibleIndex : function TSTUtils_getVisibleIndex(aTab)
|
getVisibleIndex : function TSTUtils_getVisibleIndex(aTab)
|
||||||
{
|
{
|
||||||
if (!aTab) return -1;
|
if (!aTab) return -1;
|
||||||
|
var b = this.getTabBrowserFromChild(aTab);
|
||||||
if (!this.canCollapseSubtree(aTab))
|
return this.getVisibleTabsArray(b).indexOf(aTab);
|
||||||
return this.getTabIndex(aTab);
|
|
||||||
|
|
||||||
return aTab.getAttribute(this.kCOLLAPSED) == 'true' ?
|
|
||||||
-1 :
|
|
||||||
this.evaluateXPath(
|
|
||||||
'count(preceding-sibling::xul:tab[not(@'+this.kCOLLAPSED+'="true")])',
|
|
||||||
aTab,
|
|
||||||
Ci.nsIDOMXPathResult.NUMBER_TYPE
|
|
||||||
).numberValue;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/* notify "ready to open child tab(s)" */
|
/* notify "ready to open child tab(s)" */
|
||||||
@ -1246,7 +1221,7 @@ var TreeStyleTabUtils = {
|
|||||||
var b = this.getTabBrowserFromChild(aTab);
|
var b = this.getTabBrowserFromChild(aTab);
|
||||||
return (
|
return (
|
||||||
this.shouldCloseTabSubtreeOf(aTab) &&
|
this.shouldCloseTabSubtreeOf(aTab) &&
|
||||||
this.getDescendantTabs(aTab).length + 1 == this.getTabs(b).snapshotLength
|
this.getDescendantTabs(aTab).length + 1 == this.getTabsArray(b).length
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
shouldCloseLastTabSubTreeOf : function() { return this.shouldCloseLastTabSubtreeOf.apply(this, arguments); }, // obsolete, for backward compatibility
|
shouldCloseLastTabSubTreeOf : function() { return this.shouldCloseLastTabSubtreeOf.apply(this, arguments); }, // obsolete, for backward compatibility
|
||||||
|
@ -253,6 +253,22 @@ function test_getVisibleTabs()
|
|||||||
assert.equals(4, visibleResult.snapshotLength);
|
assert.equals(4, visibleResult.snapshotLength);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function test_getVisibleTabsArray()
|
||||||
|
{
|
||||||
|
tabs[1].setAttribute(sv.kCOLLAPSED, true);
|
||||||
|
tabs[3].setAttribute(sv.kCOLLAPSED, true);
|
||||||
|
|
||||||
|
gBrowser.setAttribute(sv.kALLOW_COLLAPSE, true);
|
||||||
|
|
||||||
|
var visibleTabs = sv.getVisibleTabsArray(tabs[0]);
|
||||||
|
assert.equals([tabs[0], tabs[2]], visibleTabs);
|
||||||
|
|
||||||
|
gBrowser.removeAttribute(sv.kALLOW_COLLAPSE);
|
||||||
|
|
||||||
|
visibleTabs = sv.getVisibleTabsArray(tabs[0]);
|
||||||
|
assert.equals([tabs[0], tabs[1], tabs[2], tabs[3]], visibleTabs);
|
||||||
|
}
|
||||||
|
|
||||||
function test_getVisibleIndex()
|
function test_getVisibleIndex()
|
||||||
{
|
{
|
||||||
tabs[1].setAttribute(sv.kCOLLAPSED, true);
|
tabs[1].setAttribute(sv.kCOLLAPSED, true);
|
||||||
|
Loading…
Reference in New Issue
Block a user