Reduce use of eval()
This commit is contained in:
parent
96ea62988a
commit
bbdb2eea40
@ -553,21 +553,54 @@ var TreeStyleTabWindowHelper = {
|
|||||||
));
|
));
|
||||||
}, 'TreeStyleTabService.getTabBrowserFromChild');
|
}, 'TreeStyleTabService.getTabBrowserFromChild');
|
||||||
|
|
||||||
TreeStyleTabUtils.doPatching(b.tabContainer._getDragTargetTab, 'b.tabContainer._getDragTargetTab', function(aName, aSource) {
|
if (!b.tabContainer.__treestyletab__getDragTargetTab) {
|
||||||
return eval(aName+' = '+aSource.replace(
|
b.tabContainer.__treestyletab__getDragTargetTab = b.tabContainer._getDragTargetTab;
|
||||||
/\.screenX/g, '[this.treeStyleTab.screenPositionProp]'
|
b.tabContainer._getDragTargetTab = function(aEvent, aIsLink, ...aArgs) {
|
||||||
).replace(
|
var treeStyleTab = gBrowser.treeStyleTab;
|
||||||
/\.width/g, '[this.treeStyleTab.sizeProp]'
|
if (!treeStyleTab.isVertical)
|
||||||
));
|
return this.__treestyletab__getDragTargetTab(aEvent, aIsLink, ...aArgs);
|
||||||
}, 'treeStyleTab');
|
|
||||||
|
|
||||||
TreeStyleTabUtils.doPatching(b.tabContainer._getDropIndex, 'b.tabContainer._getDropIndex', function(aName, aSource) {
|
var draggedTab = aEvent.target.localName == 'tab' ? aEvent.target : null;
|
||||||
return eval(aName+' = '+aSource.replace(
|
if (draggedTab && aIsLink) {
|
||||||
/\.screenX/g, '[this.treeStyleTab.screenPositionProp]'
|
let tabBox = draggedTab.boxObject;
|
||||||
).replace(
|
let tabPosition = tabBox[treeStyleTab.screenPositionProp];
|
||||||
/\.width/g, '[this.treeStyleTab.sizeProp]'
|
let tabSize = tabBox[treeStyleTab.sizeProp];
|
||||||
));
|
let currentPosition = aEvent[treeStyleTab.screenPositionProp];
|
||||||
}, 'treeStyleTab');
|
if (currentPosition < tabPosition + tabSize * 0.25 ||
|
||||||
|
currentPosition > tabPosition + tabSize * 0.75)
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return draggedTab;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!b.tabContainer.__treestyletab__getDropIndex) {
|
||||||
|
b.tabContainer.__treestyletab__getDropIndex = b.tabContainer._getDropIndex;
|
||||||
|
b.tabContainer._getDropIndex = function(aEvent, aIsLink, ...aArgs) {
|
||||||
|
var treeStyleTab = gBrowser.treeStyleTab;
|
||||||
|
if (!treeStyleTab.isVertical)
|
||||||
|
return this.__treestyletab__getDropIndex(aEvent, aIsLink, ...aArgs);
|
||||||
|
|
||||||
|
var tabs = this.childNodes;
|
||||||
|
var draggedTab = this._getDragTargetTab(aEvent, aIsLink);
|
||||||
|
var currentPosition = aEvent[treeStyleTab.screenPositionProp];
|
||||||
|
var isLTR = window.getComputedStyle(this, null).direction == 'ltr';
|
||||||
|
for (let i = draggedTab ? draggedTab._tPos : 0; i < tabs.length; i++)
|
||||||
|
{
|
||||||
|
let tabBox = tabs[i].boxObject;
|
||||||
|
let tabCenter = tabBox[treeStyleTab.screenPositionProp] + tabBox[treeStyleTab.sizeProp] / 2;
|
||||||
|
if (isLTR) {
|
||||||
|
if (currentPosition < tabCenter)
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (currentPosition > tabCenter)
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return tabs.length;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The default implementation fails to scroll to tab if it is expanding.
|
* The default implementation fails to scroll to tab if it is expanding.
|
||||||
@ -590,16 +623,32 @@ var TreeStyleTabWindowHelper = {
|
|||||||
|
|
||||||
{
|
{
|
||||||
let popup = document.getElementById('alltabs-popup');
|
let popup = document.getElementById('alltabs-popup');
|
||||||
TreeStyleTabUtils.doPatching(popup._updateTabsVisibilityStatus, 'popup._updateTabsVisibilityStatus', function(aName, aSource) {
|
if (!popup.__treestyletab__updateTabsVisibilityStatus) {
|
||||||
return eval(aName+' = '+aSource.replace(
|
popup.__treestyletab__updateTabsVisibilityStatus = popup._updateTabsVisibilityStatus;
|
||||||
'{',
|
popup._updateTabsVisibilityStatus = function(...aArgs) {
|
||||||
'{ var treeStyleTab = gBrowser.treeStyleTab;'
|
var treeStyleTab = gBrowser.treeStyleTab;
|
||||||
).replace(
|
if (!treeStyleTab.isVertical)
|
||||||
/\.screenX/g, '[treeStyleTab.screenPositionProp]'
|
return this.__treestyletab__updateTabsVisibilityStatus(...aArgs);
|
||||||
).replace(
|
|
||||||
/\.width/g, '[treeStyleTab.sizeProp]'
|
var tabContainer = gBrowser.tabContainer;
|
||||||
));
|
if (tabContainer.getAttribute('overflow') != 'true')
|
||||||
}, 'treeStyleTab');
|
return;
|
||||||
|
|
||||||
|
var tabbarBox = tabContainer.mTabstrip.scrollBoxObject;
|
||||||
|
Array.forEach(this.childNodes, function(aItem) {
|
||||||
|
let tab = aItem.tab;
|
||||||
|
if (!tab) // not tab item
|
||||||
|
return;
|
||||||
|
|
||||||
|
let tabBox = tab.boxObject;
|
||||||
|
if (tabBox[treeStyleTab.screenPositionProp] >= tabbarBox[treeStyleTab.screenPositionProp] &&
|
||||||
|
tabBox[treeStyleTab.screenPositionProp] + tabBox[treeStyleTab.sizeProp] <= tabbarBox[treeStyleTab.screenPositionProp] + tabbarBox[treeStyleTab.sizeProp])
|
||||||
|
aItem.setAttribute('tabIsVisible', true);
|
||||||
|
else
|
||||||
|
aItem.removeAttribute('tabIsVisible');
|
||||||
|
}, this);
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user