forked from ZenBrowserMirrors/zen-desktop
480 lines
17 KiB
C++
480 lines
17 KiB
C++
diff --git a/browser/components/tabbrowser/content/tabbrowser.js b/browser/components/tabbrowser/content/tabbrowser.js
|
|
index 628aa6596627c85efe361fc1ece8fd58f7ee653e..8bc9d9806ba6283bfa1b6b738b6c7c7547437c9f 100644
|
|
--- a/browser/components/tabbrowser/content/tabbrowser.js
|
|
+++ b/browser/components/tabbrowser/content/tabbrowser.js
|
|
@@ -412,11 +412,50 @@
|
|
return this.tabContainer.visibleTabs;
|
|
}
|
|
|
|
+ get _numVisiblePinTabs() {
|
|
+ let i = 0;
|
|
+ for (let tab of this.tabs) {
|
|
+ if (!tab.pinned && !tab.hasAttribute("zen-glance-tab")) {
|
|
+ break;
|
|
+ }
|
|
+ if (!tab.hidden) {
|
|
+ i += !tab.hasAttribute("zen-glance-tab");
|
|
+ }
|
|
+ }
|
|
+ return i;
|
|
+ }
|
|
+
|
|
+ get _numZenEssentials() {
|
|
+ let i = 0;
|
|
+ for (let tab of this.tabs) {
|
|
+ if (!tab.hasAttribute("zen-essential") && !tab.hasAttribute("zen-glance-tab")) {
|
|
+ break;
|
|
+ }
|
|
+ i += !tab.hasAttribute("zen-glance-tab");
|
|
+ }
|
|
+ return i;
|
|
+ }
|
|
+
|
|
+ get _numZenVisibleEssentials() {
|
|
+ let i = 0;
|
|
+ for (let tab of this.tabs) {
|
|
+ if (!tab.hasAttribute("zen-essential") && !tab.hasAttribute("zen-glance-tab")) {
|
|
+ break;
|
|
+ }
|
|
+ if (!tab.hidden) {
|
|
+ i += !tab.hasAttribute("zen-glance-tab");
|
|
+ }
|
|
+ }
|
|
+ return i;
|
|
+ }
|
|
+
|
|
get pinnedTabCount() {
|
|
- for (var i = 0; i < this.tabs.length; i++) {
|
|
- if (!this.tabs[i].pinned) {
|
|
+ let i = 0;
|
|
+ for (let tab of this.tabs) {
|
|
+ if (!tab.pinned && !tab.hasAttribute("zen-glance-tab")) {
|
|
break;
|
|
}
|
|
+ i += !tab.hasAttribute("zen-glance-tab");
|
|
}
|
|
return i;
|
|
}
|
|
@@ -814,7 +853,7 @@
|
|
this.ungroupTab(aTab);
|
|
if (this.tabContainer.verticalMode) {
|
|
this._handleTabMove(aTab, () =>
|
|
- this.verticalPinnedTabsContainer.appendChild(aTab)
|
|
+ aTab.hasAttribute("zen-essential") ? document.getElementById("zen-essentials-container").appendChild(aTab) : this.verticalPinnedTabsContainer.insertBefore(aTab, this.verticalPinnedTabsContainer.lastChild)
|
|
);
|
|
} else {
|
|
this.moveTabTo(aTab, this.pinnedTabCount, { forceStandaloneTab: true });
|
|
@@ -835,7 +874,7 @@
|
|
// the moving of a tab from the vertical pinned tabs container
|
|
// and back into arrowscrollbox.
|
|
aTab.removeAttribute("pinned");
|
|
- this.tabContainer.arrowScrollbox.prepend(aTab);
|
|
+ ZenWorkspaces.activeWorkspaceStrip.prepend(aTab);
|
|
});
|
|
} else {
|
|
this.moveTabTo(aTab, this.pinnedTabCount - 1, {
|
|
@@ -1018,6 +1057,8 @@
|
|
|
|
let LOCAL_PROTOCOLS = ["chrome:", "about:", "resource:", "data:"];
|
|
|
|
+ try {
|
|
+ gZenPinnedTabManager.onTabIconChanged(aTab, aIconURL);
|
|
if (
|
|
aIconURL &&
|
|
!aLoadingPrincipal &&
|
|
@@ -1028,6 +1069,9 @@
|
|
);
|
|
return;
|
|
}
|
|
+ } catch (e) {
|
|
+ console.warn(e);
|
|
+ }
|
|
|
|
let browser = this.getBrowserForTab(aTab);
|
|
browser.mIconURL = aIconURL;
|
|
@@ -1273,6 +1317,7 @@
|
|
if (!this._previewMode) {
|
|
newTab.recordTimeFromUnloadToReload();
|
|
newTab.updateLastAccessed();
|
|
+ newTab.removeAttribute("unread");
|
|
oldTab.updateLastAccessed();
|
|
// if this is the foreground window, update the last-seen timestamps.
|
|
if (this.ownerGlobal == BrowserWindowTracker.getTopWindow()) {
|
|
@@ -1425,6 +1470,9 @@
|
|
}
|
|
|
|
let activeEl = document.activeElement;
|
|
+ if (gURLBar._zenHandleUrlbarClose) {
|
|
+ gURLBar._zenHandleUrlbarClose(true);
|
|
+ }
|
|
// If focus is on the old tab, move it to the new tab.
|
|
if (activeEl == oldTab) {
|
|
newTab.focus();
|
|
@@ -1748,7 +1796,7 @@
|
|
}
|
|
|
|
_setTabLabel(aTab, aLabel, { beforeTabOpen, isContentTitle, isURL } = {}) {
|
|
- if (!aLabel || aLabel.includes("about:reader?")) {
|
|
+ if (!aLabel || aLabel.includes("about:reader?") || aTab.hasAttribute("zen-has-static-label")) {
|
|
return false;
|
|
}
|
|
|
|
@@ -1851,7 +1899,7 @@
|
|
newIndex = this.selectedTab._tPos + 1;
|
|
}
|
|
|
|
- if (replace) {
|
|
+ if (replace && !(!targetTab && this.selectedTab?.hasAttribute('zen-empty-tab'))) {
|
|
let browser;
|
|
if (targetTab) {
|
|
browser = this.getBrowserForTab(targetTab);
|
|
@@ -2182,7 +2230,8 @@
|
|
b.setAttribute("name", name);
|
|
}
|
|
|
|
- if (this._allowTransparentBrowser) {
|
|
+ if (this._allowTransparentBrowser || this._forZenEmptyTab) {
|
|
+ delete this._forZenEmptyTab;
|
|
b.setAttribute("transparent", "true");
|
|
}
|
|
|
|
@@ -2347,7 +2396,7 @@
|
|
|
|
let panel = this.getPanel(browser);
|
|
let uniqueId = this._generateUniquePanelID();
|
|
- panel.id = uniqueId;
|
|
+ if (!panel.id?.startsWith("zen-")) panel.id = uniqueId;
|
|
aTab.linkedPanel = uniqueId;
|
|
|
|
// Inject the <browser> into the DOM if necessary.
|
|
@@ -2406,8 +2455,8 @@
|
|
// If we transitioned from one browser to two browsers, we need to set
|
|
// hasSiblings=false on both the existing browser and the new browser.
|
|
if (this.tabs.length == 2) {
|
|
- this.tabs[0].linkedBrowser.browsingContext.hasSiblings = true;
|
|
- this.tabs[1].linkedBrowser.browsingContext.hasSiblings = true;
|
|
+ if (this.tabs[0].linkedBrowser.browsingContext) this.tabs[0].linkedBrowser.browsingContext.hasSiblings = true;
|
|
+ if (this.tabs[1].linkedBrowser.browsingContext) this.tabs[1].linkedBrowser.browsingContext.hasSiblings = true;
|
|
} else {
|
|
aTab.linkedBrowser.browsingContext.hasSiblings = this.tabs.length > 1;
|
|
}
|
|
@@ -2639,6 +2688,12 @@
|
|
);
|
|
}
|
|
|
|
+ let hasZenDefaultUserContextId = false;
|
|
+ let zenForcedWorkspaceId = undefined;
|
|
+ if (typeof ZenWorkspaces !== "undefined") {
|
|
+ [userContextId, hasZenDefaultUserContextId, zenForcedWorkspaceId] = ZenWorkspaces.getContextIdIfNeeded(userContextId, fromExternal, allowInheritPrincipal);
|
|
+ }
|
|
+
|
|
if (!UserInteraction.running("browser.tabs.opening", window)) {
|
|
UserInteraction.start("browser.tabs.opening", "initting", window);
|
|
}
|
|
@@ -2702,6 +2757,12 @@
|
|
noInitialLabel,
|
|
skipBackgroundNotify,
|
|
});
|
|
+ if (hasZenDefaultUserContextId) {
|
|
+ t.setAttribute("zenDefaultUserContextId", "true");
|
|
+ }
|
|
+ if (zenForcedWorkspaceId !== undefined) {
|
|
+ t.setAttribute("zen-workspace-id", zenForcedWorkspaceId);
|
|
+ }
|
|
if (insertTab) {
|
|
// insert the tab into the tab container in the correct position
|
|
this._insertTabAtIndex(t, {
|
|
@@ -2845,6 +2906,9 @@
|
|
}
|
|
}
|
|
|
|
+ if (typeof window.gZenVerticalTabsManager !== "undefined") {
|
|
+ gZenVerticalTabsManager.animateTab(t);
|
|
+ }
|
|
// Additionally send pinned tab events
|
|
if (pinned) {
|
|
this._notifyPinnedStatus(t);
|
|
@@ -3367,6 +3431,24 @@
|
|
) {
|
|
tabWasReused = true;
|
|
tab = this.selectedTab;
|
|
+ if (tabData.zenWorkspace) {
|
|
+ tab.setAttribute("zen-workspace-id", tabData.zenWorkspace);
|
|
+ }
|
|
+ if (tabData.zenIsEmpty) {
|
|
+ tab.setAttribute("zen-empty-tab", "true");
|
|
+ }
|
|
+ if (tabData.zenPinnedId) {
|
|
+ tab.setAttribute("zen-pin-id", tabData.zenPinnedId);
|
|
+ }
|
|
+ if (tabData.zenEssential) {
|
|
+ tab.setAttribute("zen-essential", "true");
|
|
+ }
|
|
+ if (tabData.zenDefaultUserContextId) {
|
|
+ tab.setAttribute("zenDefaultUserContextId", "true");
|
|
+ }
|
|
+ if (tabData.zenPinnedEntry) {
|
|
+ tab.setAttribute("zen-pinned-entry", tabData.zenPinnedEntry);
|
|
+ }
|
|
if (!tabData.pinned) {
|
|
this.unpinTab(tab);
|
|
} else {
|
|
@@ -3380,6 +3462,7 @@
|
|
restoreTabsLazily && !select && !tabData.pinned;
|
|
|
|
let url = "about:blank";
|
|
+ gZenPinnedTabManager.resetPinnedTabData(tabData);
|
|
if (tabData.entries?.length) {
|
|
let activeIndex = (tabData.index || tabData.entries.length) - 1;
|
|
// Ensure the index is in bounds.
|
|
@@ -3415,7 +3498,24 @@
|
|
skipLoad: true,
|
|
preferredRemoteType,
|
|
});
|
|
-
|
|
+ if (tabData.zenWorkspace) {
|
|
+ tab.setAttribute("zen-workspace-id", tabData.zenWorkspace);
|
|
+ }
|
|
+ if (tabData.zenPinnedId) {
|
|
+ tab.setAttribute("zen-pin-id", tabData.zenPinnedId);
|
|
+ }
|
|
+ if (tabData.zenIsEmpty) {
|
|
+ tab.setAttribute("zen-empty-tab", "true");
|
|
+ }
|
|
+ if (tabData.zenEssential) {
|
|
+ tab.setAttribute("zen-essential", "true");
|
|
+ }
|
|
+ if (tabData.zenDefaultUserContextId) {
|
|
+ tab.setAttribute("zenDefaultUserContextId", "true");
|
|
+ }
|
|
+ if (tabData.zenPinnedEntry) {
|
|
+ tab.setAttribute("zen-pinned-entry", tabData.zenPinnedEntry);
|
|
+ }
|
|
if (select) {
|
|
tabToSelect = tab;
|
|
}
|
|
@@ -3428,8 +3528,8 @@
|
|
// inserted in the DOM. If the tab is not yet in the DOM,
|
|
// just insert it in the right place from the start.
|
|
if (!tab.parentNode) {
|
|
- tab._tPos = this.pinnedTabCount;
|
|
- this.tabContainer.insertBefore(tab, this.tabs[this.pinnedTabCount]);
|
|
+ tab._tPos = this._numVisiblePinTabs;
|
|
+ this.tabContainer.insertBefore(tab, this.tabs[this._numVisiblePinTabs]);
|
|
tab.toggleAttribute("pinned", true);
|
|
this.tabContainer._invalidateCachedTabs();
|
|
// Then ensure all the tab open/pinning information is sent.
|
|
@@ -3693,7 +3793,7 @@
|
|
// Ensure we have an index if one was not provided.
|
|
if (typeof index != "number") {
|
|
// Move the new tab after another tab if needed, to the end otherwise.
|
|
- index = Infinity;
|
|
+ index = Services.prefs.getBoolPref("zen.view.show-newtab-button-top") ? this.pinnedTabCount : Infinity;
|
|
if (
|
|
!bulkOrderedOpen &&
|
|
((openerTab &&
|
|
@@ -3744,7 +3844,7 @@
|
|
}
|
|
|
|
/** @type {MozTabbrowserTab|undefined} */
|
|
- let tabAfter = this.tabs.at(index);
|
|
+ let tabAfter = this.tabs.filter(tab => !tab.hasAttribute("zen-glance-tab")).at(index);
|
|
this.tabContainer._invalidateCachedTabs();
|
|
|
|
if (tabGroup) {
|
|
@@ -4059,6 +4159,9 @@
|
|
return;
|
|
}
|
|
|
|
+ for (let tab of selectedTabs) {
|
|
+ gZenPinnedTabManager._removePinnedAttributes(tab, true);
|
|
+ }
|
|
this.removeTabs(selectedTabs);
|
|
}
|
|
|
|
@@ -4391,6 +4494,7 @@
|
|
skipSessionStore,
|
|
} = {}
|
|
) {
|
|
+ gZenUIManager.saveScrollbarState();
|
|
if (UserInteraction.running("browser.tabs.opening", window)) {
|
|
UserInteraction.finish("browser.tabs.opening", window);
|
|
}
|
|
@@ -4407,6 +4511,12 @@
|
|
TelemetryStopwatch.start("FX_TAB_CLOSE_TIME_NO_ANIM_MS", aTab);
|
|
}
|
|
|
|
+ if (ZenWorkspaces.workspaceEnabled) {
|
|
+ let newTab = ZenWorkspaces.handleTabBeforeClose(aTab);
|
|
+ if (newTab) {
|
|
+ this.selectedTab = newTab;
|
|
+ }
|
|
+ }
|
|
// Handle requests for synchronously removing an already
|
|
// asynchronously closing tab.
|
|
if (!animate && aTab.closing) {
|
|
@@ -4421,7 +4531,9 @@
|
|
// frame created for it (for example, by updating the visually selected
|
|
// state).
|
|
let tabWidth = window.windowUtils.getBoundsWithoutFlushing(aTab).width;
|
|
-
|
|
+ if (gZenGlanceManager.manageTabClose(aTab)) {
|
|
+ return;
|
|
+ }
|
|
if (
|
|
!this._beginRemoveTab(aTab, {
|
|
closeWindowFastpath: true,
|
|
@@ -4435,7 +4547,6 @@
|
|
TelemetryStopwatch.cancel("FX_TAB_CLOSE_TIME_NO_ANIM_MS", aTab);
|
|
return;
|
|
}
|
|
-
|
|
let lockTabSizing =
|
|
!this.tabContainer.verticalMode &&
|
|
!aTab.pinned &&
|
|
@@ -4574,14 +4685,14 @@
|
|
!!this.tabsInCollapsedTabGroups.length;
|
|
if (
|
|
aTab.visible &&
|
|
- this.visibleTabs.length == 1 &&
|
|
+ this.visibleTabs.length == 1 && !aTab._closingGlance &&
|
|
!anyRemainingTabsInCollapsedTabGroups
|
|
) {
|
|
closeWindow =
|
|
closeWindowWithLastTab != null
|
|
? closeWindowWithLastTab
|
|
: !window.toolbar.visible ||
|
|
- Services.prefs.getBoolPref("browser.tabs.closeWindowWithLastTab");
|
|
+ Services.prefs.getBoolPref("browser.tabs.closeWindowWithLastTab") && !ZenWorkspaces._isClosingWindow && !ZenWorkspaces._removedByStartupPage;
|
|
|
|
if (closeWindow) {
|
|
// We've already called beforeunload on all the relevant tabs if we get here,
|
|
@@ -4605,6 +4716,7 @@
|
|
|
|
newTab = true;
|
|
}
|
|
+ ZenWorkspaces._removedByStartupPage = false;
|
|
aTab._endRemoveArgs = [closeWindow, newTab];
|
|
|
|
// swapBrowsersAndCloseOther will take care of closing the window without animation.
|
|
@@ -4645,9 +4757,7 @@
|
|
aTab._mouseleave();
|
|
|
|
if (newTab) {
|
|
- this.addTrustedTab(BROWSER_NEW_TAB_URL, {
|
|
- skipAnimation: true,
|
|
- });
|
|
+ ZenWorkspaces.selectEmptyTab();
|
|
} else {
|
|
TabBarVisibility.update();
|
|
}
|
|
@@ -4776,6 +4886,8 @@
|
|
this.tabs[i]._tPos = i;
|
|
}
|
|
|
|
+ ZenWorkspaces.updateTabsContainers();
|
|
+
|
|
if (!this._windowIsClosing) {
|
|
if (wasPinned) {
|
|
this.tabContainer._positionPinnedTabs();
|
|
@@ -4994,7 +5106,7 @@
|
|
!excludeTabs.has(aTab.owner) &&
|
|
Services.prefs.getBoolPref("browser.tabs.selectOwnerOnClose")
|
|
) {
|
|
- return aTab.owner;
|
|
+ return ZenWorkspaces.findTabToBlur(aTab.owner);
|
|
}
|
|
|
|
// Try to find a remaining tab that comes after the given tab
|
|
@@ -5016,7 +5128,7 @@
|
|
}
|
|
|
|
if (tab) {
|
|
- return tab;
|
|
+ return ZenWorkspaces.findTabToBlur(tab);
|
|
}
|
|
|
|
// If no qualifying visible tab was found, see if there is a tab in
|
|
@@ -5434,10 +5546,10 @@
|
|
SessionStore.deleteCustomTabValue(aTab, "hiddenBy");
|
|
}
|
|
|
|
- hideTab(aTab, aSource) {
|
|
+ hideTab(aTab, aSource, forZenWorkspaces = false) {
|
|
if (
|
|
aTab.hidden ||
|
|
- aTab.pinned ||
|
|
+ (aTab.pinned && !forZenWorkspaces) ||
|
|
aTab.selected ||
|
|
aTab.closing ||
|
|
// Tabs that are sharing the screen, microphone or camera cannot be hidden.
|
|
@@ -5675,7 +5787,7 @@
|
|
|
|
// Don't allow mixing pinned and unpinned tabs.
|
|
if (aTab.pinned) {
|
|
- aIndex = Math.min(aIndex, this.pinnedTabCount - 1);
|
|
+ aIndex = aTab.hasAttribute('zen-essential') ? Math.min(aIndex, this._numZenEssentials - 1) : Math.min(aIndex, this.pinnedTabCount - 1);
|
|
} else {
|
|
aIndex = Math.max(aIndex, this.pinnedTabCount);
|
|
}
|
|
@@ -5684,7 +5796,7 @@
|
|
}
|
|
|
|
this._handleTabMove(aTab, () => {
|
|
- let neighbor = this.tabs[aIndex];
|
|
+ let neighbor = this.tabs.filter(tab => !tab.hasAttribute("zen-glance-tab"))[aIndex];
|
|
if (forceStandaloneTab && neighbor.group) {
|
|
neighbor = neighbor.group;
|
|
}
|
|
@@ -5721,6 +5833,8 @@
|
|
|
|
moveActionCallback();
|
|
|
|
+ ZenWorkspaces._makeSureEmptyTabIsLast();
|
|
+
|
|
// Clear tabs cache after moving nodes because the order of tabs may have
|
|
// changed.
|
|
this.tabContainer._invalidateCachedTabs();
|
|
@@ -5771,7 +5885,7 @@
|
|
createLazyBrowser,
|
|
};
|
|
|
|
- let numPinned = this.pinnedTabCount;
|
|
+ let numPinned = this._numVisiblePinTabs;
|
|
if (aIndex < numPinned || (aTab.pinned && aIndex == numPinned)) {
|
|
params.pinned = true;
|
|
}
|
|
@@ -7415,6 +7529,7 @@
|
|
aWebProgress.isTopLevel
|
|
) {
|
|
this.mTab.setAttribute("busy", "true");
|
|
+ if (!this.mTab.selected) this.mTab.setAttribute("unread", "true");
|
|
gBrowser._tabAttrModified(this.mTab, ["busy"]);
|
|
this.mTab._notselectedsinceload = !this.mTab.selected;
|
|
}
|
|
@@ -8381,7 +8496,7 @@ var TabContextMenu = {
|
|
);
|
|
contextUnpinSelectedTabs.hidden =
|
|
!this.contextTab.pinned || !multiselectionContext;
|
|
-
|
|
+ gZenPinnedTabManager.updatePinnedTabContextMenu(this.contextTab);
|
|
// Move Tab items
|
|
let contextMoveTabOptions = document.getElementById(
|
|
"context_moveTabOptions"
|
|
@@ -8414,7 +8529,7 @@ var TabContextMenu = {
|
|
let contextMoveTabToStart = document.getElementById("context_moveToStart");
|
|
let isFirstTab =
|
|
tabsToMove[0] == visibleTabs[0] ||
|
|
- tabsToMove[0] == visibleTabs[gBrowser.pinnedTabCount];
|
|
+ tabsToMove[0] == visibleTabs[gBrowser._numVisiblePinTabs];
|
|
contextMoveTabToStart.disabled = isFirstTab && allSelectedTabsAdjacent;
|
|
|
|
document.getElementById("context_openTabInWindow").disabled =
|
|
@@ -8647,6 +8762,7 @@ var TabContextMenu = {
|
|
if (this.contextTab.multiselected) {
|
|
gBrowser.removeMultiSelectedTabs();
|
|
} else {
|
|
+ gZenPinnedTabManager._removePinnedAttributes(this.contextTab, true);
|
|
gBrowser.removeTab(this.contextTab, { animate: true });
|
|
}
|
|
},
|