Move XPath related utilities from TSTBase to TSTUtils
This commit is contained in:
parent
bad68d5a9b
commit
fe7cf571f5
@ -23,7 +23,9 @@
|
||||
}, false);
|
||||
ReferenceCounter.add('window,aEvent.type,onDOMContentLoaded,false');
|
||||
|
||||
var ns = {};
|
||||
Components.utils.import('resource://treestyletab-modules/window.js', ns);
|
||||
new ns.TreeStyleTabWindow(window);
|
||||
var { TreeStyleTabUtils } = Components.utils.import('resource://treestyletab-modules/utils.js', {});
|
||||
window.TreeStyleTabUtils = TreeStyleTabUtils;
|
||||
|
||||
var { TreeStyleTabWindow } = Components.utils.import('resource://treestyletab-modules/window.js', {});
|
||||
new TreeStyleTabWindow(window);
|
||||
})();
|
||||
|
@ -84,7 +84,7 @@
|
||||
event.stopPropagation();
|
||||
this.parentNode.hidePopup();
|
||||
}"
|
||||
multipletab-insertbefore="TreeStyleTabService.evaluateXPath(
|
||||
multipletab-insertbefore="TreeStyleTabUtils.evaluateXPath(
|
||||
"(descendant::*[starts-with(@id, 'multipletab-context-removeAll') | starts-with(@id, 'context_closeTab')][1] | child::xul:menuitem[last()])/preceding-sibling::xul:menuseparator[1]"
|
||||
, tabContextMenu, XPathResult.FIRST_ORDERED_NODE_TYPE).singleNodeValue"/>
|
||||
<menuitem id="context-item-removeDescendantTabs"
|
||||
@ -107,7 +107,7 @@
|
||||
label="&context.bookmarkTabSubtree.label;"
|
||||
accesskey="&context.bookmarkTabSubtree.accesskey;"
|
||||
oncommand="TreeStyleTabBookmarksService.bookmarkTabSubtree(TreeStyleTabService.getTabBrowserFromChild(this).mContextTab);"
|
||||
multipletab-insertafter="TreeStyleTabService.evaluateXPath(
|
||||
multipletab-insertafter="TreeStyleTabUtils.evaluateXPath(
|
||||
"descendant::*[starts-with(@id, 'context_bookmarkTab')][1] | descendant::*[@command='Browser:BookmarkAllTabs']/preceding-sibling[1]"
|
||||
, tabContextMenu, XPathResult.FIRST_ORDERED_NODE_TYPE).singleNodeValue"/>
|
||||
|
||||
|
@ -1122,7 +1122,7 @@ TreeStyleTabWindowHelper.overrideExtensionsAfterBrowserInit = function TSTWH_ove
|
||||
return;
|
||||
|
||||
case 'click':
|
||||
if (sv.evaluateXPath(
|
||||
if (TreeStyleTabUtils.evaluateXPath(
|
||||
'ancestor-or-self::*['
|
||||
+'contains(concat(" ", normalize-space(@class), " "), " textbox-presentation-segment ")'
|
||||
+']',
|
||||
|
@ -1311,7 +1311,7 @@ AutoHideBrowser.prototype = inherit(AutoHideBase.prototype, {
|
||||
if (
|
||||
aEvent.target &&
|
||||
!this.isResizing &&
|
||||
sv.evaluateXPath(
|
||||
utils.evaluateXPath(
|
||||
'ancestor-or-self::*[@class="'+sv.kSPLITTER+'"]',
|
||||
aEvent.originalTarget || aEvent.target,
|
||||
Ci.nsIDOMXPathResult.BOOLEAN_TYPE
|
||||
@ -1343,7 +1343,7 @@ AutoHideBrowser.prototype = inherit(AutoHideBase.prototype, {
|
||||
var sv = this.treeStyleTab;
|
||||
if (this.isResizing &&
|
||||
aEvent.originalTarget &&
|
||||
sv.evaluateXPath(
|
||||
utils.evaluateXPath(
|
||||
'ancestor-or-self::*[@class="'+sv.kSPLITTER+'"]',
|
||||
aEvent.originalTarget,
|
||||
Ci.nsIDOMXPathResult.BOOLEAN_TYPE
|
||||
|
100
modules/base.js
100
modules/base.js
@ -546,7 +546,7 @@ var TreeStyleTabBase = inherit(TreeStyleTabConstants, {
|
||||
|
||||
isEventFiredOnClosebox : function TSTBase_isEventFiredOnClosebox(aEvent)
|
||||
{
|
||||
return this.evaluateXPath(
|
||||
return utils.evaluateXPath(
|
||||
'ancestor-or-self::*[contains(concat(" ", normalize-space(@class), " "), " tab-close-button ")]',
|
||||
aEvent.originalTarget || aEvent.target,
|
||||
Ci.nsIDOMXPathResult.BOOLEAN_TYPE
|
||||
@ -555,7 +555,7 @@ var TreeStyleTabBase = inherit(TreeStyleTabConstants, {
|
||||
|
||||
isEventFiredOnClickable : function TSTBase_isEventFiredOnClickable(aEvent)
|
||||
{
|
||||
return this.evaluateXPath(
|
||||
return utils.evaluateXPath(
|
||||
'ancestor-or-self::*[contains(" button toolbarbutton scrollbar nativescrollbar popup menupopup panel tooltip splitter textbox ", concat(" ", local-name(), " "))]',
|
||||
aEvent.originalTarget,
|
||||
Ci.nsIDOMXPathResult.BOOLEAN_TYPE
|
||||
@ -564,7 +564,7 @@ var TreeStyleTabBase = inherit(TreeStyleTabConstants, {
|
||||
|
||||
isEventFiredOnScrollbar : function TSTBase_isEventFiredOnScrollbar(aEvent)
|
||||
{
|
||||
return this.evaluateXPath(
|
||||
return utils.evaluateXPath(
|
||||
'ancestor-or-self::*[local-name()="scrollbar" or local-name()="nativescrollbar"]',
|
||||
aEvent.originalTarget,
|
||||
Ci.nsIDOMXPathResult.BOOLEAN_TYPE
|
||||
@ -728,66 +728,6 @@ var TreeStyleTabBase = inherit(TreeStyleTabConstants, {
|
||||
return 'about:treestyletab-group?' + parameters.join('&');
|
||||
},
|
||||
|
||||
// xpath
|
||||
|
||||
NSResolver : {
|
||||
lookupNamespaceURI : function(aPrefix)
|
||||
{
|
||||
switch (aPrefix)
|
||||
{
|
||||
case 'xul':
|
||||
return 'http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul';
|
||||
case 'html':
|
||||
case 'xhtml':
|
||||
return 'http://www.w3.org/1999/xhtml';
|
||||
case 'xlink':
|
||||
return 'http://www.w3.org/1999/xlink';
|
||||
default:
|
||||
return '';
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
evaluateXPath : function TSTBase_evaluateXPath(aExpression, aContext, aType)
|
||||
{
|
||||
if (!aType)
|
||||
aType = Ci.nsIDOMXPathResult.ORDERED_NODE_SNAPSHOT_TYPE;
|
||||
try {
|
||||
var XPathResult = (aContext.ownerDocument || aContext).evaluate(
|
||||
aExpression,
|
||||
(aContext || document),
|
||||
this.NSResolver,
|
||||
aType,
|
||||
null
|
||||
);
|
||||
}
|
||||
catch(e) {
|
||||
return {
|
||||
singleNodeValue : null,
|
||||
snapshotLength : 0,
|
||||
snapshotItem : function() {
|
||||
return null
|
||||
}
|
||||
};
|
||||
}
|
||||
return XPathResult;
|
||||
},
|
||||
|
||||
getArrayFromXPathResult : function TSTBase_getArrayFromXPathResult(aXPathResult)
|
||||
{
|
||||
var max = aXPathResult.snapshotLength;
|
||||
var array = new Array(max);
|
||||
if (!max)
|
||||
return array;
|
||||
|
||||
for (var i = 0; i < max; i++)
|
||||
{
|
||||
array[i] = aXPathResult.snapshotItem(i);
|
||||
}
|
||||
|
||||
return array;
|
||||
},
|
||||
|
||||
/* Session Store API */
|
||||
|
||||
getTabValue : function TSTBase_getTabValue(aTab, aKey)
|
||||
@ -889,7 +829,7 @@ var TreeStyleTabBase = inherit(TreeStyleTabConstants, {
|
||||
var strip = aTabBrowser.mStrip;
|
||||
return (strip && strip instanceof this.window.Element) ?
|
||||
strip :
|
||||
this.evaluateXPath(
|
||||
utils.evaluateXPath(
|
||||
'ancestor::xul:toolbar[1]',
|
||||
aTabBrowser.tabContainer,
|
||||
Ci.nsIDOMXPathResult.FIRST_ORDERED_NODE_TYPE
|
||||
@ -981,7 +921,7 @@ var TreeStyleTabBase = inherit(TreeStyleTabConstants, {
|
||||
|
||||
getTabFromChild : function TSTBase_getTabFromChild(aTab)
|
||||
{
|
||||
return this.evaluateXPath(
|
||||
return utils.evaluateXPath(
|
||||
'ancestor-or-self::xul:tab',
|
||||
aTab,
|
||||
Ci.nsIDOMXPathResult.FIRST_ORDERED_NODE_TYPE
|
||||
@ -995,7 +935,7 @@ var TreeStyleTabBase = inherit(TreeStyleTabConstants, {
|
||||
|
||||
getNewTabButtonFromEvent : function TSTBase_getNewTabButtonFromEvent(aEvent)
|
||||
{
|
||||
return this.evaluateXPath(
|
||||
return utils.evaluateXPath(
|
||||
'ancestor-or-self::*['
|
||||
+'@id="new-tab-button" or '
|
||||
+'contains(concat(" ", normalize-space(@class), " "), " tabs-newtab-button ")'
|
||||
@ -1007,7 +947,7 @@ var TreeStyleTabBase = inherit(TreeStyleTabConstants, {
|
||||
|
||||
getSplitterFromEvent : function TSTBase_getSplitterFromEvent(aEvent)
|
||||
{
|
||||
return this.evaluateXPath(
|
||||
return utils.evaluateXPath(
|
||||
'ancestor-or-self::xul:splitter[contains(concat(" ", normalize-space(@class), " "), " '+this.kSPLITTER+' ")]',
|
||||
aEvent.originalTarget,
|
||||
Ci.nsIDOMXPathResult.FIRST_ORDERED_NODE_TYPE
|
||||
@ -1016,7 +956,7 @@ var TreeStyleTabBase = inherit(TreeStyleTabConstants, {
|
||||
|
||||
isEventFiredOnGrippy : function TSTBase_isEventFiredOnGrippy(aEvent)
|
||||
{
|
||||
return this.evaluateXPath(
|
||||
return utils.evaluateXPath(
|
||||
'ancestor-or-self::xul:grippy',
|
||||
aEvent.originalTarget,
|
||||
Ci.nsIDOMXPathResult.BOOLEAN_TYPE
|
||||
@ -1056,7 +996,7 @@ var TreeStyleTabBase = inherit(TreeStyleTabConstants, {
|
||||
|
||||
getTabbarFromChild : function TSTBase_getTabbarFromChild(aNode)
|
||||
{
|
||||
return this.evaluateXPath(
|
||||
return utils.evaluateXPath(
|
||||
'ancestor-or-self::*[contains(concat(" ", normalize-space(@class), " "), " tabbrowser-strip ")] | ' +
|
||||
'ancestor-or-self::xul:tabs[@tabbrowser] | ' +
|
||||
'ancestor-or-self::xul:toolbar/child::xul:tabs[@tabbrowser]',
|
||||
@ -1066,7 +1006,7 @@ var TreeStyleTabBase = inherit(TreeStyleTabConstants, {
|
||||
},
|
||||
getAncestorTabbarFromChild : function TSTBase_getAncestorTabbarFromChild(aNode)
|
||||
{
|
||||
return this.evaluateXPath(
|
||||
return utils.evaluateXPath(
|
||||
'ancestor-or-self::*[contains(concat(" ", normalize-space(@class), " "), " tabbrowser-strip ")] | ' +
|
||||
'ancestor-or-self::xul:tabs[@tabbrowser]',
|
||||
aNode,
|
||||
@ -1164,7 +1104,7 @@ var TreeStyleTabBase = inherit(TreeStyleTabConstants, {
|
||||
return aTabBrowserChild.getElementsByTagName('tabs')[0].tabbrowser;
|
||||
|
||||
// tab context menu
|
||||
var popup = this.evaluateXPath(
|
||||
var popup = utils.evaluateXPath(
|
||||
'ancestor-or-self::xul:menupopup[@id="tabContextMenu"]',
|
||||
aTabBrowserChild,
|
||||
Ci.nsIDOMXPathResult.FIRST_ORDERED_NODE_TYPE
|
||||
@ -1172,7 +1112,7 @@ var TreeStyleTabBase = inherit(TreeStyleTabConstants, {
|
||||
if (popup && 'TabContextMenu' in aTabBrowserChild.ownerDocument.defaultView)
|
||||
return this.getTabBrowserFromChild(aTabBrowserChild.ownerDocument.defaultView.TabContextMenu.contextTab);
|
||||
|
||||
var b = this.evaluateXPath(
|
||||
var b = utils.evaluateXPath(
|
||||
'ancestor::xul:tabbrowser | '+
|
||||
'ancestor::xul:tabs[@tabbrowser] |'+
|
||||
'ancestor::xul:toolbar/descendant::xul:tabs',
|
||||
@ -1858,7 +1798,7 @@ var TreeStyleTabBase = inherit(TreeStyleTabConstants, {
|
||||
}
|
||||
}
|
||||
else {
|
||||
parent = this.evaluateXPath(
|
||||
parent = utils.evaluateXPath(
|
||||
'preceding-sibling::xul:tab[@'+this.kID+'="'+id+'"][1]',
|
||||
aTab,
|
||||
Ci.nsIDOMXPathResult.FIRST_ORDERED_NODE_TYPE
|
||||
@ -1914,7 +1854,7 @@ var TreeStyleTabBase = inherit(TreeStyleTabConstants, {
|
||||
return ancestors.length ? ancestors[ancestors.length-1] : aTab ;
|
||||
}
|
||||
|
||||
return this.evaluateXPath(
|
||||
return utils.evaluateXPath(
|
||||
'(self::*[not(@'+this.kPARENT+')] | preceding-sibling::xul:tab[not(@'+this.kPARENT+')])[last()]',
|
||||
aTab,
|
||||
Ci.nsIDOMXPathResult.FIRST_ORDERED_NODE_TYPE
|
||||
@ -1955,7 +1895,7 @@ var TreeStyleTabBase = inherit(TreeStyleTabConstants, {
|
||||
}
|
||||
|
||||
var parent = aTab.getAttribute(this.kPARENT);
|
||||
return this.evaluateXPath(
|
||||
return utils.evaluateXPath(
|
||||
'following-sibling::xul:tab['+
|
||||
(parent ? '@'+this.kPARENT+'="'+parent+'"' : 'not(@'+this.kPARENT+')' )+
|
||||
'][1]',
|
||||
@ -1997,7 +1937,7 @@ var TreeStyleTabBase = inherit(TreeStyleTabConstants, {
|
||||
}
|
||||
|
||||
var parent = aTab.getAttribute(this.kPARENT);
|
||||
return this.evaluateXPath(
|
||||
return utils.evaluateXPath(
|
||||
'preceding-sibling::xul:tab['+
|
||||
(parent ? '@'+this.kPARENT+'="'+parent+'"' : 'not(@'+this.kPARENT+')' )+
|
||||
'][1]',
|
||||
@ -2088,7 +2028,7 @@ var TreeStyleTabBase = inherit(TreeStyleTabConstants, {
|
||||
return firstChild;
|
||||
}
|
||||
|
||||
return this.evaluateXPath(
|
||||
return utils.evaluateXPath(
|
||||
'following-sibling::xul:tab[@'+this.kPARENT+'="'+aTab.getAttribute(this.kID)+'"][1]',
|
||||
aTab,
|
||||
Ci.nsIDOMXPathResult.FIRST_ORDERED_NODE_TYPE
|
||||
@ -2115,7 +2055,7 @@ var TreeStyleTabBase = inherit(TreeStyleTabConstants, {
|
||||
return lastChild;
|
||||
}
|
||||
|
||||
return this.evaluateXPath(
|
||||
return utils.evaluateXPath(
|
||||
'following-sibling::xul:tab[@'+this.kPARENT+'="'+aTab.getAttribute(this.kID)+'"][last()]',
|
||||
aTab,
|
||||
Ci.nsIDOMXPathResult.FIRST_ORDERED_NODE_TYPE
|
||||
@ -2184,7 +2124,7 @@ var TreeStyleTabBase = inherit(TreeStyleTabConstants, {
|
||||
'[not(@'+this.kCOLLAPSED+'="true")]' :
|
||||
'' ;
|
||||
|
||||
return this.evaluateXPath(
|
||||
return utils.evaluateXPath(
|
||||
'sum((self::* | preceding-sibling::xul:tab[not(@hidden="true")]'+extraCondition+')'+
|
||||
'/attribute::'+this.kX_OFFSET+')',
|
||||
aTab,
|
||||
@ -2197,7 +2137,7 @@ var TreeStyleTabBase = inherit(TreeStyleTabConstants, {
|
||||
'[not(@'+this.kCOLLAPSED+'="true")]' :
|
||||
'';
|
||||
|
||||
return this.evaluateXPath(
|
||||
return utils.evaluateXPath(
|
||||
'sum((self::* | preceding-sibling::xul:tab[not(@hidden="true")]'+extraCondition+')'+
|
||||
'/attribute::'+this.kY_OFFSET+')',
|
||||
aTab,
|
||||
|
@ -433,7 +433,7 @@ TreeStyleTabBrowser.prototype = inherit(TreeStyleTabWindow.prototype, {
|
||||
|
||||
get ownerToolbar()
|
||||
{
|
||||
return this.evaluateXPath(
|
||||
return utils.evaluateXPath(
|
||||
'ancestor-or-self::xul:toolbar[1]',
|
||||
this.mTabBrowser.tabContainer,
|
||||
Ci.nsIDOMXPathResult.FIRST_ORDERED_NODE_TYPE
|
||||
@ -6471,7 +6471,7 @@ TreeStyleTabBrowser.prototype = inherit(TreeStyleTabWindow.prototype, {
|
||||
var id = this.getTabValue(aTab, this.kID);
|
||||
aTab.__treestyletab__checkTabsIndentOverflowOnMouseLeave = function checkTabsIndentOverflowOnMouseLeave(aEvent, aDelayed) {
|
||||
if (aEvent.type == 'mouseover') {
|
||||
if (self.evaluateXPath(
|
||||
if (utils.evaluateXPath(
|
||||
'ancestor-or-self::*[@' + self.kID + '="' + id + '"]',
|
||||
aEvent.originalTarget || aEvent.target,
|
||||
Ci.nsIDOMXPathResult.BOOLEAN_TYPE
|
||||
@ -6758,7 +6758,7 @@ TreeStyleTabBrowser.prototype = inherit(TreeStyleTabWindow.prototype, {
|
||||
}, this)
|
||||
.join('|');
|
||||
|
||||
var xpathResult = this.evaluateXPath(
|
||||
var xpathResult = utils.evaluateXPath(
|
||||
'child::xul:tab[@'+this.kCHILDREN+' and not(@'+this.kCOLLAPSED+'="true") and not(@'+this.kSUBTREE_COLLAPSED+'="true") and @'+this.kID+' and not(contains("'+expandedAncestors+'", @'+this.kID+')) and not(@hidden="true")]',
|
||||
b.mTabContainer
|
||||
);
|
||||
|
@ -153,7 +153,7 @@ BrowserUIShowHideObserver.prototype = {
|
||||
if (
|
||||
// ignore modifications of each tab
|
||||
TST.getTabFromChild(target) ||
|
||||
TST.evaluateXPath(
|
||||
utils.evaluateXPath(
|
||||
// ignore modifications in the location bar (ex. identity icon)
|
||||
'ancestor-or-self::xul:textbox |' +
|
||||
// or menu items
|
||||
@ -205,7 +205,7 @@ BrowserUIShowHideObserver.prototype = {
|
||||
if (
|
||||
// I must ignore show/hide of elements managed by TST,
|
||||
// to avoid infinity loop.
|
||||
TST.evaluateXPath(
|
||||
utils.evaluateXPath(
|
||||
'ancestor-or-self::xul:*[@' + TreeStyleTabConstants.kTAB_STRIP_ELEMENT + '="true"]',
|
||||
target,
|
||||
Components.interfaces.nsIDOMXPathResult.FIRST_ORDERED_NODE_TYPE
|
||||
|
@ -148,7 +148,7 @@ FullTooltipManager.prototype = inherit(TreeStyleTabBase, {
|
||||
|
||||
getFullTooltipFromEvent : function FTM_getFullTooltipFromEvent(aEvent)
|
||||
{
|
||||
return this.evaluateXPath(
|
||||
return utils.evaluateXPath(
|
||||
'ancestor-or-self::xul:tooltip[@id="'+this.tabFullTooltip.id+'"]',
|
||||
aEvent.target,
|
||||
Ci.nsIDOMXPathResult.FIRST_ORDERED_NODE_TYPE
|
||||
|
@ -89,7 +89,7 @@ TabbarDNDObserver.prototype = {
|
||||
var sv = this.treeStyleTab;
|
||||
|
||||
if (
|
||||
sv.evaluateXPath(
|
||||
utils.evaluateXPath(
|
||||
'ancestor-or-self::*[' +
|
||||
'contains(" scrollbar popup menupopup panel tooltip ", concat(" ", local-name(), " ")) or' +
|
||||
'(local-name()="toolbarbutton" and @type="menu")' +
|
||||
|
@ -336,6 +336,66 @@ var TreeStyleTabUtils = {
|
||||
},
|
||||
|
||||
|
||||
// xpath
|
||||
|
||||
NSResolver : {
|
||||
lookupNamespaceURI : function(aPrefix)
|
||||
{
|
||||
switch (aPrefix)
|
||||
{
|
||||
case 'xul':
|
||||
return 'http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul';
|
||||
case 'html':
|
||||
case 'xhtml':
|
||||
return 'http://www.w3.org/1999/xhtml';
|
||||
case 'xlink':
|
||||
return 'http://www.w3.org/1999/xlink';
|
||||
default:
|
||||
return '';
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
evaluateXPath : function utils_evaluateXPath(aExpression, aContext, aType)
|
||||
{
|
||||
if (!aType)
|
||||
aType = Ci.nsIDOMXPathResult.ORDERED_NODE_SNAPSHOT_TYPE;
|
||||
try {
|
||||
var XPathResult = (aContext.ownerDocument || aContext).evaluate(
|
||||
aExpression,
|
||||
(aContext || document),
|
||||
this.NSResolver,
|
||||
aType,
|
||||
null
|
||||
);
|
||||
}
|
||||
catch(e) {
|
||||
return {
|
||||
singleNodeValue : null,
|
||||
snapshotLength : 0,
|
||||
snapshotItem : function() {
|
||||
return null
|
||||
}
|
||||
};
|
||||
}
|
||||
return XPathResult;
|
||||
},
|
||||
|
||||
getArrayFromXPathResult : function utils_getArrayFromXPathResult(aXPathResult)
|
||||
{
|
||||
var max = aXPathResult.snapshotLength;
|
||||
var array = new Array(max);
|
||||
if (!max)
|
||||
return array;
|
||||
|
||||
for (var i = 0; i < max; i++)
|
||||
{
|
||||
array[i] = aXPathResult.snapshotItem(i);
|
||||
}
|
||||
|
||||
return array;
|
||||
},
|
||||
|
||||
|
||||
getTreeStructureFromTabs : function TSTUtils_getTreeStructureFromTabs(aTabs)
|
||||
{
|
||||
|
@ -1236,7 +1236,7 @@ TreeStyleTabWindow.prototype = inherit(TreeStyleTabBase, {
|
||||
onPopupShown : function TSTWindow_onPopupShown(aPopup)
|
||||
{
|
||||
if (!aPopup.boxObject ||
|
||||
this.evaluateXPath(
|
||||
utils.evaluateXPath(
|
||||
'parent::*/ancestor-or-self::*[local-name()="tooltip" or local-name()="panel" or local-name()="popup" or local-name()="menupopup"]',
|
||||
aPopup,
|
||||
Ci.nsIDOMXPathResult.BOOLEAN_TYPE
|
||||
|
Loading…
Reference in New Issue
Block a user