Move XPath related utilities from TSTBase to TSTUtils

This commit is contained in:
YUKI Hiroshi 2016-02-10 17:42:37 +09:00
parent bad68d5a9b
commit fe7cf571f5
11 changed files with 98 additions and 96 deletions

View File

@ -23,7 +23,9 @@
}, false); }, false);
ReferenceCounter.add('window,aEvent.type,onDOMContentLoaded,false'); ReferenceCounter.add('window,aEvent.type,onDOMContentLoaded,false');
var ns = {}; var { TreeStyleTabUtils } = Components.utils.import('resource://treestyletab-modules/utils.js', {});
Components.utils.import('resource://treestyletab-modules/window.js', ns); window.TreeStyleTabUtils = TreeStyleTabUtils;
new ns.TreeStyleTabWindow(window);
var { TreeStyleTabWindow } = Components.utils.import('resource://treestyletab-modules/window.js', {});
new TreeStyleTabWindow(window);
})(); })();

View File

@ -84,7 +84,7 @@
event.stopPropagation(); event.stopPropagation();
this.parentNode.hidePopup(); 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]" "(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"/> , tabContextMenu, XPathResult.FIRST_ORDERED_NODE_TYPE).singleNodeValue"/>
<menuitem id="context-item-removeDescendantTabs" <menuitem id="context-item-removeDescendantTabs"
@ -107,7 +107,7 @@
label="&context.bookmarkTabSubtree.label;" label="&context.bookmarkTabSubtree.label;"
accesskey="&context.bookmarkTabSubtree.accesskey;" accesskey="&context.bookmarkTabSubtree.accesskey;"
oncommand="TreeStyleTabBookmarksService.bookmarkTabSubtree(TreeStyleTabService.getTabBrowserFromChild(this).mContextTab);" oncommand="TreeStyleTabBookmarksService.bookmarkTabSubtree(TreeStyleTabService.getTabBrowserFromChild(this).mContextTab);"
multipletab-insertafter="TreeStyleTabService.evaluateXPath( multipletab-insertafter="TreeStyleTabUtils.evaluateXPath(
&quot;descendant::*[starts-with(@id, 'context_bookmarkTab')][1] | descendant::*[@command='Browser:BookmarkAllTabs']/preceding-sibling[1]&quot; &quot;descendant::*[starts-with(@id, 'context_bookmarkTab')][1] | descendant::*[@command='Browser:BookmarkAllTabs']/preceding-sibling[1]&quot;
, tabContextMenu, XPathResult.FIRST_ORDERED_NODE_TYPE).singleNodeValue"/> , tabContextMenu, XPathResult.FIRST_ORDERED_NODE_TYPE).singleNodeValue"/>

View File

@ -1122,7 +1122,7 @@ TreeStyleTabWindowHelper.overrideExtensionsAfterBrowserInit = function TSTWH_ove
return; return;
case 'click': case 'click':
if (sv.evaluateXPath( if (TreeStyleTabUtils.evaluateXPath(
'ancestor-or-self::*[' 'ancestor-or-self::*['
+'contains(concat(" ", normalize-space(@class), " "), " textbox-presentation-segment ")' +'contains(concat(" ", normalize-space(@class), " "), " textbox-presentation-segment ")'
+']', +']',

View File

@ -1311,7 +1311,7 @@ AutoHideBrowser.prototype = inherit(AutoHideBase.prototype, {
if ( if (
aEvent.target && aEvent.target &&
!this.isResizing && !this.isResizing &&
sv.evaluateXPath( utils.evaluateXPath(
'ancestor-or-self::*[@class="'+sv.kSPLITTER+'"]', 'ancestor-or-self::*[@class="'+sv.kSPLITTER+'"]',
aEvent.originalTarget || aEvent.target, aEvent.originalTarget || aEvent.target,
Ci.nsIDOMXPathResult.BOOLEAN_TYPE Ci.nsIDOMXPathResult.BOOLEAN_TYPE
@ -1343,7 +1343,7 @@ AutoHideBrowser.prototype = inherit(AutoHideBase.prototype, {
var sv = this.treeStyleTab; var sv = this.treeStyleTab;
if (this.isResizing && if (this.isResizing &&
aEvent.originalTarget && aEvent.originalTarget &&
sv.evaluateXPath( utils.evaluateXPath(
'ancestor-or-self::*[@class="'+sv.kSPLITTER+'"]', 'ancestor-or-self::*[@class="'+sv.kSPLITTER+'"]',
aEvent.originalTarget, aEvent.originalTarget,
Ci.nsIDOMXPathResult.BOOLEAN_TYPE Ci.nsIDOMXPathResult.BOOLEAN_TYPE

View File

@ -546,7 +546,7 @@ var TreeStyleTabBase = inherit(TreeStyleTabConstants, {
isEventFiredOnClosebox : function TSTBase_isEventFiredOnClosebox(aEvent) isEventFiredOnClosebox : function TSTBase_isEventFiredOnClosebox(aEvent)
{ {
return this.evaluateXPath( return utils.evaluateXPath(
'ancestor-or-self::*[contains(concat(" ", normalize-space(@class), " "), " tab-close-button ")]', 'ancestor-or-self::*[contains(concat(" ", normalize-space(@class), " "), " tab-close-button ")]',
aEvent.originalTarget || aEvent.target, aEvent.originalTarget || aEvent.target,
Ci.nsIDOMXPathResult.BOOLEAN_TYPE Ci.nsIDOMXPathResult.BOOLEAN_TYPE
@ -555,7 +555,7 @@ var TreeStyleTabBase = inherit(TreeStyleTabConstants, {
isEventFiredOnClickable : function TSTBase_isEventFiredOnClickable(aEvent) 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(), " "))]', 'ancestor-or-self::*[contains(" button toolbarbutton scrollbar nativescrollbar popup menupopup panel tooltip splitter textbox ", concat(" ", local-name(), " "))]',
aEvent.originalTarget, aEvent.originalTarget,
Ci.nsIDOMXPathResult.BOOLEAN_TYPE Ci.nsIDOMXPathResult.BOOLEAN_TYPE
@ -564,7 +564,7 @@ var TreeStyleTabBase = inherit(TreeStyleTabConstants, {
isEventFiredOnScrollbar : function TSTBase_isEventFiredOnScrollbar(aEvent) isEventFiredOnScrollbar : function TSTBase_isEventFiredOnScrollbar(aEvent)
{ {
return this.evaluateXPath( return utils.evaluateXPath(
'ancestor-or-self::*[local-name()="scrollbar" or local-name()="nativescrollbar"]', 'ancestor-or-self::*[local-name()="scrollbar" or local-name()="nativescrollbar"]',
aEvent.originalTarget, aEvent.originalTarget,
Ci.nsIDOMXPathResult.BOOLEAN_TYPE Ci.nsIDOMXPathResult.BOOLEAN_TYPE
@ -728,66 +728,6 @@ var TreeStyleTabBase = inherit(TreeStyleTabConstants, {
return 'about:treestyletab-group?' + parameters.join('&'); 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 */ /* Session Store API */
getTabValue : function TSTBase_getTabValue(aTab, aKey) getTabValue : function TSTBase_getTabValue(aTab, aKey)
@ -889,7 +829,7 @@ var TreeStyleTabBase = inherit(TreeStyleTabConstants, {
var strip = aTabBrowser.mStrip; var strip = aTabBrowser.mStrip;
return (strip && strip instanceof this.window.Element) ? return (strip && strip instanceof this.window.Element) ?
strip : strip :
this.evaluateXPath( utils.evaluateXPath(
'ancestor::xul:toolbar[1]', 'ancestor::xul:toolbar[1]',
aTabBrowser.tabContainer, aTabBrowser.tabContainer,
Ci.nsIDOMXPathResult.FIRST_ORDERED_NODE_TYPE Ci.nsIDOMXPathResult.FIRST_ORDERED_NODE_TYPE
@ -981,7 +921,7 @@ var TreeStyleTabBase = inherit(TreeStyleTabConstants, {
getTabFromChild : function TSTBase_getTabFromChild(aTab) getTabFromChild : function TSTBase_getTabFromChild(aTab)
{ {
return this.evaluateXPath( return utils.evaluateXPath(
'ancestor-or-self::xul:tab', 'ancestor-or-self::xul:tab',
aTab, aTab,
Ci.nsIDOMXPathResult.FIRST_ORDERED_NODE_TYPE Ci.nsIDOMXPathResult.FIRST_ORDERED_NODE_TYPE
@ -995,7 +935,7 @@ var TreeStyleTabBase = inherit(TreeStyleTabConstants, {
getNewTabButtonFromEvent : function TSTBase_getNewTabButtonFromEvent(aEvent) getNewTabButtonFromEvent : function TSTBase_getNewTabButtonFromEvent(aEvent)
{ {
return this.evaluateXPath( return utils.evaluateXPath(
'ancestor-or-self::*[' 'ancestor-or-self::*['
+'@id="new-tab-button" or ' +'@id="new-tab-button" or '
+'contains(concat(" ", normalize-space(@class), " "), " tabs-newtab-button ")' +'contains(concat(" ", normalize-space(@class), " "), " tabs-newtab-button ")'
@ -1007,7 +947,7 @@ var TreeStyleTabBase = inherit(TreeStyleTabConstants, {
getSplitterFromEvent : function TSTBase_getSplitterFromEvent(aEvent) getSplitterFromEvent : function TSTBase_getSplitterFromEvent(aEvent)
{ {
return this.evaluateXPath( return utils.evaluateXPath(
'ancestor-or-self::xul:splitter[contains(concat(" ", normalize-space(@class), " "), " '+this.kSPLITTER+' ")]', 'ancestor-or-self::xul:splitter[contains(concat(" ", normalize-space(@class), " "), " '+this.kSPLITTER+' ")]',
aEvent.originalTarget, aEvent.originalTarget,
Ci.nsIDOMXPathResult.FIRST_ORDERED_NODE_TYPE Ci.nsIDOMXPathResult.FIRST_ORDERED_NODE_TYPE
@ -1016,7 +956,7 @@ var TreeStyleTabBase = inherit(TreeStyleTabConstants, {
isEventFiredOnGrippy : function TSTBase_isEventFiredOnGrippy(aEvent) isEventFiredOnGrippy : function TSTBase_isEventFiredOnGrippy(aEvent)
{ {
return this.evaluateXPath( return utils.evaluateXPath(
'ancestor-or-self::xul:grippy', 'ancestor-or-self::xul:grippy',
aEvent.originalTarget, aEvent.originalTarget,
Ci.nsIDOMXPathResult.BOOLEAN_TYPE Ci.nsIDOMXPathResult.BOOLEAN_TYPE
@ -1056,7 +996,7 @@ var TreeStyleTabBase = inherit(TreeStyleTabConstants, {
getTabbarFromChild : function TSTBase_getTabbarFromChild(aNode) getTabbarFromChild : function TSTBase_getTabbarFromChild(aNode)
{ {
return this.evaluateXPath( return utils.evaluateXPath(
'ancestor-or-self::*[contains(concat(" ", normalize-space(@class), " "), " tabbrowser-strip ")] | ' + 'ancestor-or-self::*[contains(concat(" ", normalize-space(@class), " "), " tabbrowser-strip ")] | ' +
'ancestor-or-self::xul:tabs[@tabbrowser] | ' + 'ancestor-or-self::xul:tabs[@tabbrowser] | ' +
'ancestor-or-self::xul:toolbar/child::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) getAncestorTabbarFromChild : function TSTBase_getAncestorTabbarFromChild(aNode)
{ {
return this.evaluateXPath( return utils.evaluateXPath(
'ancestor-or-self::*[contains(concat(" ", normalize-space(@class), " "), " tabbrowser-strip ")] | ' + 'ancestor-or-self::*[contains(concat(" ", normalize-space(@class), " "), " tabbrowser-strip ")] | ' +
'ancestor-or-self::xul:tabs[@tabbrowser]', 'ancestor-or-self::xul:tabs[@tabbrowser]',
aNode, aNode,
@ -1164,7 +1104,7 @@ var TreeStyleTabBase = inherit(TreeStyleTabConstants, {
return aTabBrowserChild.getElementsByTagName('tabs')[0].tabbrowser; return aTabBrowserChild.getElementsByTagName('tabs')[0].tabbrowser;
// tab context menu // tab context menu
var popup = this.evaluateXPath( var popup = utils.evaluateXPath(
'ancestor-or-self::xul:menupopup[@id="tabContextMenu"]', 'ancestor-or-self::xul:menupopup[@id="tabContextMenu"]',
aTabBrowserChild, aTabBrowserChild,
Ci.nsIDOMXPathResult.FIRST_ORDERED_NODE_TYPE Ci.nsIDOMXPathResult.FIRST_ORDERED_NODE_TYPE
@ -1172,7 +1112,7 @@ var TreeStyleTabBase = inherit(TreeStyleTabConstants, {
if (popup && 'TabContextMenu' in aTabBrowserChild.ownerDocument.defaultView) if (popup && 'TabContextMenu' in aTabBrowserChild.ownerDocument.defaultView)
return this.getTabBrowserFromChild(aTabBrowserChild.ownerDocument.defaultView.TabContextMenu.contextTab); return this.getTabBrowserFromChild(aTabBrowserChild.ownerDocument.defaultView.TabContextMenu.contextTab);
var b = this.evaluateXPath( var b = utils.evaluateXPath(
'ancestor::xul:tabbrowser | '+ 'ancestor::xul:tabbrowser | '+
'ancestor::xul:tabs[@tabbrowser] |'+ 'ancestor::xul:tabs[@tabbrowser] |'+
'ancestor::xul:toolbar/descendant::xul:tabs', 'ancestor::xul:toolbar/descendant::xul:tabs',
@ -1858,7 +1798,7 @@ var TreeStyleTabBase = inherit(TreeStyleTabConstants, {
} }
} }
else { else {
parent = this.evaluateXPath( parent = utils.evaluateXPath(
'preceding-sibling::xul:tab[@'+this.kID+'="'+id+'"][1]', 'preceding-sibling::xul:tab[@'+this.kID+'="'+id+'"][1]',
aTab, aTab,
Ci.nsIDOMXPathResult.FIRST_ORDERED_NODE_TYPE Ci.nsIDOMXPathResult.FIRST_ORDERED_NODE_TYPE
@ -1914,7 +1854,7 @@ var TreeStyleTabBase = inherit(TreeStyleTabConstants, {
return ancestors.length ? ancestors[ancestors.length-1] : aTab ; 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()]', '(self::*[not(@'+this.kPARENT+')] | preceding-sibling::xul:tab[not(@'+this.kPARENT+')])[last()]',
aTab, aTab,
Ci.nsIDOMXPathResult.FIRST_ORDERED_NODE_TYPE Ci.nsIDOMXPathResult.FIRST_ORDERED_NODE_TYPE
@ -1955,7 +1895,7 @@ var TreeStyleTabBase = inherit(TreeStyleTabConstants, {
} }
var parent = aTab.getAttribute(this.kPARENT); var parent = aTab.getAttribute(this.kPARENT);
return this.evaluateXPath( return utils.evaluateXPath(
'following-sibling::xul:tab['+ 'following-sibling::xul:tab['+
(parent ? '@'+this.kPARENT+'="'+parent+'"' : 'not(@'+this.kPARENT+')' )+ (parent ? '@'+this.kPARENT+'="'+parent+'"' : 'not(@'+this.kPARENT+')' )+
'][1]', '][1]',
@ -1997,7 +1937,7 @@ var TreeStyleTabBase = inherit(TreeStyleTabConstants, {
} }
var parent = aTab.getAttribute(this.kPARENT); var parent = aTab.getAttribute(this.kPARENT);
return this.evaluateXPath( return utils.evaluateXPath(
'preceding-sibling::xul:tab['+ 'preceding-sibling::xul:tab['+
(parent ? '@'+this.kPARENT+'="'+parent+'"' : 'not(@'+this.kPARENT+')' )+ (parent ? '@'+this.kPARENT+'="'+parent+'"' : 'not(@'+this.kPARENT+')' )+
'][1]', '][1]',
@ -2088,7 +2028,7 @@ var TreeStyleTabBase = inherit(TreeStyleTabConstants, {
return firstChild; return firstChild;
} }
return this.evaluateXPath( return utils.evaluateXPath(
'following-sibling::xul:tab[@'+this.kPARENT+'="'+aTab.getAttribute(this.kID)+'"][1]', 'following-sibling::xul:tab[@'+this.kPARENT+'="'+aTab.getAttribute(this.kID)+'"][1]',
aTab, aTab,
Ci.nsIDOMXPathResult.FIRST_ORDERED_NODE_TYPE Ci.nsIDOMXPathResult.FIRST_ORDERED_NODE_TYPE
@ -2115,7 +2055,7 @@ var TreeStyleTabBase = inherit(TreeStyleTabConstants, {
return lastChild; return lastChild;
} }
return this.evaluateXPath( return utils.evaluateXPath(
'following-sibling::xul:tab[@'+this.kPARENT+'="'+aTab.getAttribute(this.kID)+'"][last()]', 'following-sibling::xul:tab[@'+this.kPARENT+'="'+aTab.getAttribute(this.kID)+'"][last()]',
aTab, aTab,
Ci.nsIDOMXPathResult.FIRST_ORDERED_NODE_TYPE Ci.nsIDOMXPathResult.FIRST_ORDERED_NODE_TYPE
@ -2184,7 +2124,7 @@ var TreeStyleTabBase = inherit(TreeStyleTabConstants, {
'[not(@'+this.kCOLLAPSED+'="true")]' : '[not(@'+this.kCOLLAPSED+'="true")]' :
'' ; '' ;
return this.evaluateXPath( return utils.evaluateXPath(
'sum((self::* | preceding-sibling::xul:tab[not(@hidden="true")]'+extraCondition+')'+ 'sum((self::* | preceding-sibling::xul:tab[not(@hidden="true")]'+extraCondition+')'+
'/attribute::'+this.kX_OFFSET+')', '/attribute::'+this.kX_OFFSET+')',
aTab, aTab,
@ -2197,7 +2137,7 @@ var TreeStyleTabBase = inherit(TreeStyleTabConstants, {
'[not(@'+this.kCOLLAPSED+'="true")]' : '[not(@'+this.kCOLLAPSED+'="true")]' :
''; '';
return this.evaluateXPath( return utils.evaluateXPath(
'sum((self::* | preceding-sibling::xul:tab[not(@hidden="true")]'+extraCondition+')'+ 'sum((self::* | preceding-sibling::xul:tab[not(@hidden="true")]'+extraCondition+')'+
'/attribute::'+this.kY_OFFSET+')', '/attribute::'+this.kY_OFFSET+')',
aTab, aTab,

View File

@ -433,7 +433,7 @@ TreeStyleTabBrowser.prototype = inherit(TreeStyleTabWindow.prototype, {
get ownerToolbar() get ownerToolbar()
{ {
return this.evaluateXPath( return utils.evaluateXPath(
'ancestor-or-self::xul:toolbar[1]', 'ancestor-or-self::xul:toolbar[1]',
this.mTabBrowser.tabContainer, this.mTabBrowser.tabContainer,
Ci.nsIDOMXPathResult.FIRST_ORDERED_NODE_TYPE Ci.nsIDOMXPathResult.FIRST_ORDERED_NODE_TYPE
@ -6471,7 +6471,7 @@ TreeStyleTabBrowser.prototype = inherit(TreeStyleTabWindow.prototype, {
var id = this.getTabValue(aTab, this.kID); var id = this.getTabValue(aTab, this.kID);
aTab.__treestyletab__checkTabsIndentOverflowOnMouseLeave = function checkTabsIndentOverflowOnMouseLeave(aEvent, aDelayed) { aTab.__treestyletab__checkTabsIndentOverflowOnMouseLeave = function checkTabsIndentOverflowOnMouseLeave(aEvent, aDelayed) {
if (aEvent.type == 'mouseover') { if (aEvent.type == 'mouseover') {
if (self.evaluateXPath( if (utils.evaluateXPath(
'ancestor-or-self::*[@' + self.kID + '="' + id + '"]', 'ancestor-or-self::*[@' + self.kID + '="' + id + '"]',
aEvent.originalTarget || aEvent.target, aEvent.originalTarget || aEvent.target,
Ci.nsIDOMXPathResult.BOOLEAN_TYPE Ci.nsIDOMXPathResult.BOOLEAN_TYPE
@ -6758,7 +6758,7 @@ TreeStyleTabBrowser.prototype = inherit(TreeStyleTabWindow.prototype, {
}, this) }, this)
.join('|'); .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")]', '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 b.mTabContainer
); );

View File

@ -153,7 +153,7 @@ BrowserUIShowHideObserver.prototype = {
if ( if (
// ignore modifications of each tab // ignore modifications of each tab
TST.getTabFromChild(target) || TST.getTabFromChild(target) ||
TST.evaluateXPath( utils.evaluateXPath(
// ignore modifications in the location bar (ex. identity icon) // ignore modifications in the location bar (ex. identity icon)
'ancestor-or-self::xul:textbox |' + 'ancestor-or-self::xul:textbox |' +
// or menu items // or menu items
@ -205,7 +205,7 @@ BrowserUIShowHideObserver.prototype = {
if ( if (
// I must ignore show/hide of elements managed by TST, // I must ignore show/hide of elements managed by TST,
// to avoid infinity loop. // to avoid infinity loop.
TST.evaluateXPath( utils.evaluateXPath(
'ancestor-or-self::xul:*[@' + TreeStyleTabConstants.kTAB_STRIP_ELEMENT + '="true"]', 'ancestor-or-self::xul:*[@' + TreeStyleTabConstants.kTAB_STRIP_ELEMENT + '="true"]',
target, target,
Components.interfaces.nsIDOMXPathResult.FIRST_ORDERED_NODE_TYPE Components.interfaces.nsIDOMXPathResult.FIRST_ORDERED_NODE_TYPE

View File

@ -148,7 +148,7 @@ FullTooltipManager.prototype = inherit(TreeStyleTabBase, {
getFullTooltipFromEvent : function FTM_getFullTooltipFromEvent(aEvent) getFullTooltipFromEvent : function FTM_getFullTooltipFromEvent(aEvent)
{ {
return this.evaluateXPath( return utils.evaluateXPath(
'ancestor-or-self::xul:tooltip[@id="'+this.tabFullTooltip.id+'"]', 'ancestor-or-self::xul:tooltip[@id="'+this.tabFullTooltip.id+'"]',
aEvent.target, aEvent.target,
Ci.nsIDOMXPathResult.FIRST_ORDERED_NODE_TYPE Ci.nsIDOMXPathResult.FIRST_ORDERED_NODE_TYPE

View File

@ -89,7 +89,7 @@ TabbarDNDObserver.prototype = {
var sv = this.treeStyleTab; var sv = this.treeStyleTab;
if ( if (
sv.evaluateXPath( utils.evaluateXPath(
'ancestor-or-self::*[' + 'ancestor-or-self::*[' +
'contains(" scrollbar popup menupopup panel tooltip ", concat(" ", local-name(), " ")) or' + 'contains(" scrollbar popup menupopup panel tooltip ", concat(" ", local-name(), " ")) or' +
'(local-name()="toolbarbutton" and @type="menu")' + '(local-name()="toolbarbutton" and @type="menu")' +

View File

@ -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) getTreeStructureFromTabs : function TSTUtils_getTreeStructureFromTabs(aTabs)
{ {

View File

@ -1236,7 +1236,7 @@ TreeStyleTabWindow.prototype = inherit(TreeStyleTabBase, {
onPopupShown : function TSTWindow_onPopupShown(aPopup) onPopupShown : function TSTWindow_onPopupShown(aPopup)
{ {
if (!aPopup.boxObject || 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"]', 'parent::*/ancestor-or-self::*[local-name()="tooltip" or local-name()="panel" or local-name()="popup" or local-name()="menupopup"]',
aPopup, aPopup,
Ci.nsIDOMXPathResult.BOOLEAN_TYPE Ci.nsIDOMXPathResult.BOOLEAN_TYPE