Reduce use of eval()
This commit is contained in:
parent
bbdb2eea40
commit
bc0c05e1a5
@ -517,43 +517,74 @@ var TreeStyleTabWindowHelper = {
|
|||||||
return b.mTabContainer.__treestyletab__advanceSelectedTab.call(this, ...aArgs);
|
return b.mTabContainer.__treestyletab__advanceSelectedTab.call(this, ...aArgs);
|
||||||
};
|
};
|
||||||
|
|
||||||
TreeStyleTabUtils.doPatching(b.mTabContainer._notifyBackgroundTab, 'b.mTabContainer._notifyBackgroundTab', function(aName, aSource) {
|
if (!b.tabContainer.__treestyletab__notifyBackgroundTab) {
|
||||||
return eval(aName+' = '+aSource.replace(
|
// original: https://dxr.mozilla.org/mozilla-central/rev/dbe4b47941c7b3d6298a0ead5e40dd828096c808/browser/base/content/tabbrowser.xml#5459
|
||||||
'{',
|
b.tabContainer.__treestyletab__notifyBackgroundTab = b.tabContainer._notifyBackgroundTab;
|
||||||
'{\n' +
|
b.tabContainer._notifyBackgroundTab = function(aTab, ...aArgs) {
|
||||||
' var treeStyleTab = TreeStyleTabService.getTabBrowserFromChild(this).treeStyleTab;\n' +
|
var treeStyleTab = gBrowser.treeStyleTab;
|
||||||
' if (treeStyleTab.scrollToNewTabMode == 0 ||\n' +
|
if (aTab.pinned ||
|
||||||
' treeStyleTab.shouldCancelEnsureElementIsVisible())\n' +
|
treeStyleTab.scrollToNewTabMode == 0 ||
|
||||||
' return;'
|
treeStyleTab.shouldCancelEnsureElementIsVisible())
|
||||||
).replace(
|
return;
|
||||||
/\.screenX/g, '[treeStyleTab.screenPositionProp]'
|
|
||||||
).replace(
|
|
||||||
/\.width/g, '[treeStyleTab.sizeProp]'
|
|
||||||
).replace(
|
|
||||||
/\.left/g, '[treeStyleTab.startProp]'
|
|
||||||
).replace(
|
|
||||||
/\.right/g, '[treeStyleTab.endProp]'
|
|
||||||
|
|
||||||
// replace such codes:
|
let scrollRect = this.mTabstrip.scrollClientRect;
|
||||||
// tab = {left: tab.left, right: tab.right};
|
let tabRect = aTab.getBoundingClientRect();
|
||||||
).replace(
|
this.mTabstrip._calcTabMargins(aTab);
|
||||||
/left\s*:/g, 'start:'
|
|
||||||
).replace(
|
|
||||||
/right\s*:/g, 'end:'
|
|
||||||
).replace(
|
|
||||||
/((tab|selected)\s*=\s*\{\s*start:[^\}]+\})/g,
|
|
||||||
'$1; $2[treeStyleTab.startProp] = $2.start; $2[treeStyleTab.endProp] = $2.end;'
|
|
||||||
|
|
||||||
).replace(
|
tabRect = {
|
||||||
'!selected ||',
|
start : tabRect[treeStyleTab.startProp],
|
||||||
'$& treeStyleTab.scrollToNewTabMode == 1 && '
|
end : tabRect[treeStyleTab.endProp]
|
||||||
).replace(
|
};
|
||||||
/(\}\)?)$/,
|
tabRect[treeStyleTab.startProp] = tabRect.start;
|
||||||
'treeStyleTab.notifyBackgroundTab(); $1'
|
tabRect[treeStyleTab.endProp] = tabRect.end;
|
||||||
));
|
|
||||||
}, 'TreeStyleTabService.getTabBrowserFromChild');
|
if (tabRect[treeStyleTab.startProp] >= scrollRect[treeStyleTab.startProp] ||
|
||||||
|
tabRect[treeStyleTab.endProp] <= scrollRect[treeStyleTab.endProp])
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (this.mTabstrip.smoothScroll) {
|
||||||
|
let selectedRect = !this.selectedItem.pinned && this.selectedItem.getBoundingClientRect();
|
||||||
|
if (selectedRect) {
|
||||||
|
selectedRect = {
|
||||||
|
start : selectedRect[treeStyleTab.startProp],
|
||||||
|
end : selectedRect[treeStyleTab.endProp]
|
||||||
|
};
|
||||||
|
selectedRect[treeStyleTab.startProp] = selectedRect.start + this.mTabstrip._tabMarginLeft;
|
||||||
|
selectedRect[treeStyleTab.endProp] = selectedRect.end - this.mTabstrip._tabMarginRight;
|
||||||
|
}
|
||||||
|
tabRect[treeStyleTab.startProp] += this.mTabstrip._tabMarginLeft;
|
||||||
|
tabRect[treeStyleTab.endProp] -= this.mTabstrip._tabMarginRight;
|
||||||
|
|
||||||
|
if (!selectedRect ||
|
||||||
|
treeStyleTab.scrollToNewTabMode == 1 &&
|
||||||
|
Math.max(
|
||||||
|
tabRect[treeStyleTab.endProp] - selectedRect[treeStyleTab.startProp],
|
||||||
|
selectedRect[treeStyleTab.endProp] - tabRect[treeStyleTab.startProp]
|
||||||
|
) <= scrollRect[treeStyleTab.sizeProp]) {
|
||||||
|
this.mTabstrip.ensureElementIsVisible(aTab);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.mTabstrip._smoothScrollByPixels(
|
||||||
|
this.mTabstrip._isRTLScrollbox ?
|
||||||
|
selectedRect[treeStyleTab.endProp] - scrollRect[treeStyleTab.endProp] :
|
||||||
|
selectedRect[treeStyleTab.startProp] - scrollRect[treeStyleTab.startProp]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!this._animateElement.hasAttribute('notifybgtab')) {
|
||||||
|
this._animateElement.setAttribute('notifybgtab', 'true');
|
||||||
|
setTimeout(function(aAnimateElement) {
|
||||||
|
aAnimateElement.removeAttribute('notifybgtab');
|
||||||
|
}, 150, this._animateElement);
|
||||||
|
}
|
||||||
|
|
||||||
|
treeStyleTab.notifyBackgroundTab();
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
if (!b.tabContainer.__treestyletab__getDragTargetTab) {
|
if (!b.tabContainer.__treestyletab__getDragTargetTab) {
|
||||||
|
// original: https://dxr.mozilla.org/mozilla-central/rev/dbe4b47941c7b3d6298a0ead5e40dd828096c808/browser/base/content/tabbrowser.xml#5511
|
||||||
b.tabContainer.__treestyletab__getDragTargetTab = b.tabContainer._getDragTargetTab;
|
b.tabContainer.__treestyletab__getDragTargetTab = b.tabContainer._getDragTargetTab;
|
||||||
b.tabContainer._getDragTargetTab = function(aEvent, aIsLink, ...aArgs) {
|
b.tabContainer._getDragTargetTab = function(aEvent, aIsLink, ...aArgs) {
|
||||||
var treeStyleTab = gBrowser.treeStyleTab;
|
var treeStyleTab = gBrowser.treeStyleTab;
|
||||||
@ -575,6 +606,7 @@ var TreeStyleTabWindowHelper = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!b.tabContainer.__treestyletab__getDropIndex) {
|
if (!b.tabContainer.__treestyletab__getDropIndex) {
|
||||||
|
// original: https://dxr.mozilla.org/mozilla-central/rev/dbe4b47941c7b3d6298a0ead5e40dd828096c808/browser/base/content/tabbrowser.xml#5526
|
||||||
b.tabContainer.__treestyletab__getDropIndex = b.tabContainer._getDropIndex;
|
b.tabContainer.__treestyletab__getDropIndex = b.tabContainer._getDropIndex;
|
||||||
b.tabContainer._getDropIndex = function(aEvent, aIsLink, ...aArgs) {
|
b.tabContainer._getDropIndex = function(aEvent, aIsLink, ...aArgs) {
|
||||||
var treeStyleTab = gBrowser.treeStyleTab;
|
var treeStyleTab = gBrowser.treeStyleTab;
|
||||||
@ -624,6 +656,7 @@ var TreeStyleTabWindowHelper = {
|
|||||||
{
|
{
|
||||||
let popup = document.getElementById('alltabs-popup');
|
let popup = document.getElementById('alltabs-popup');
|
||||||
if (!popup.__treestyletab__updateTabsVisibilityStatus) {
|
if (!popup.__treestyletab__updateTabsVisibilityStatus) {
|
||||||
|
// original https://dxr.mozilla.org/mozilla-central/rev/dbe4b47941c7b3d6298a0ead5e40dd828096c808/browser/base/content/tabbrowser.xml#6588
|
||||||
popup.__treestyletab__updateTabsVisibilityStatus = popup._updateTabsVisibilityStatus;
|
popup.__treestyletab__updateTabsVisibilityStatus = popup._updateTabsVisibilityStatus;
|
||||||
popup._updateTabsVisibilityStatus = function(...aArgs) {
|
popup._updateTabsVisibilityStatus = function(...aArgs) {
|
||||||
var treeStyleTab = gBrowser.treeStyleTab;
|
var treeStyleTab = gBrowser.treeStyleTab;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user