forked from ZenBrowserMirrors/zen-desktop
380 lines
13 KiB
C++
380 lines
13 KiB
C++
diff --git a/browser/components/tabbrowser/content/tabbrowser.js b/browser/components/tabbrowser/content/tabbrowser.js
|
|
index ff90a70bdad6c94ec4b90027ff102972d0eb28e5..4faba37097f376b57c7376e320f46e9cd3aacffe 100644
|
|
--- a/browser/components/tabbrowser/content/tabbrowser.js
|
|
+++ b/browser/components/tabbrowser/content/tabbrowser.js
|
|
@@ -406,11 +406,52 @@
|
|
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 _numVisiblePinTabsWithoutGlance() {
|
|
+ let i = 0;
|
|
+ for (let tab of this.tabs) {
|
|
+ if (!tab.pinned) {
|
|
+ break;
|
|
+ }
|
|
+ if (!tab.hidden) {
|
|
+ i++;
|
|
+ }
|
|
+ }
|
|
+ return i;
|
|
+ }
|
|
+
|
|
+ get _numZenEssentials() {
|
|
+ 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;
|
|
}
|
|
@@ -807,7 +848,7 @@
|
|
this.showTab(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 });
|
|
@@ -828,7 +869,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, {
|
|
@@ -1055,6 +1096,8 @@
|
|
|
|
let LOCAL_PROTOCOLS = ["chrome:", "about:", "resource:", "data:"];
|
|
|
|
+ try {
|
|
+ gZenPinnedTabManager.onTabIconChanged(aTab, aIconURL);
|
|
if (
|
|
aIconURL &&
|
|
!aLoadingPrincipal &&
|
|
@@ -1065,6 +1108,9 @@
|
|
);
|
|
return;
|
|
}
|
|
+ } catch (e) {
|
|
+ console.warn(e);
|
|
+ }
|
|
|
|
let browser = this.getBrowserForTab(aTab);
|
|
browser.mIconURL = aIconURL;
|
|
@@ -1310,6 +1356,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()) {
|
|
@@ -1462,6 +1509,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();
|
|
@@ -1785,7 +1835,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;
|
|
}
|
|
|
|
@@ -2387,7 +2437,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.
|
|
@@ -2446,8 +2496,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;
|
|
}
|
|
@@ -2679,6 +2729,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);
|
|
}
|
|
@@ -2742,6 +2798,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, {
|
|
@@ -2885,6 +2947,9 @@
|
|
}
|
|
}
|
|
|
|
+ if (typeof window.gZenVerticalTabsManager !== "undefined") {
|
|
+ gZenVerticalTabsManager.animateTab(t);
|
|
+ }
|
|
// Additionally send pinned tab events
|
|
if (pinned) {
|
|
this._notifyPinnedStatus(t);
|
|
@@ -3403,6 +3455,24 @@
|
|
) {
|
|
tabWasReused = true;
|
|
tab = this.selectedTab;
|
|
+ if (tabData.zenWorkspace) {
|
|
+ tab.setAttribute("zen-workspace-id", tabData.zenWorkspace);
|
|
+ }
|
|
+ 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.zenHasStaticLabel) {
|
|
+ tab.setAttribute("zen-has-static-label", "true");
|
|
+ }
|
|
if (!tabData.pinned) {
|
|
this.unpinTab(tab);
|
|
} else {
|
|
@@ -3416,6 +3486,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.
|
|
@@ -3451,7 +3522,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.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.zenHasStaticLabel) {
|
|
+ tab.setAttribute("zen-has-static-label", "true");
|
|
+ }
|
|
if (select) {
|
|
tabToSelect = tab;
|
|
}
|
|
@@ -3729,7 +3817,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 &&
|
|
@@ -3780,7 +3868,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) {
|
|
@@ -4095,6 +4183,9 @@
|
|
return;
|
|
}
|
|
|
|
+ for (let tab of selectedTabs) {
|
|
+ gZenPinnedTabManager._removePinnedAttributes(tab, true);
|
|
+ }
|
|
this.removeTabs(selectedTabs);
|
|
}
|
|
|
|
@@ -4427,6 +4518,7 @@
|
|
skipSessionStore,
|
|
} = {}
|
|
) {
|
|
+ gZenUIManager.saveScrollbarState();
|
|
if (UserInteraction.running("browser.tabs.opening", window)) {
|
|
UserInteraction.finish("browser.tabs.opening", window);
|
|
}
|
|
@@ -4443,6 +4535,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) {
|
|
@@ -4457,7 +4555,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,
|
|
@@ -4471,7 +4571,6 @@
|
|
TelemetryStopwatch.cancel("FX_TAB_CLOSE_TIME_NO_ANIM_MS", aTab);
|
|
return;
|
|
}
|
|
-
|
|
let lockTabSizing =
|
|
!this.tabContainer.verticalMode &&
|
|
!aTab.pinned &&
|
|
@@ -4610,14 +4709,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;
|
|
|
|
if (closeWindow) {
|
|
// We've already called beforeunload on all the relevant tabs if we get here,
|
|
@@ -5465,10 +5564,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.
|
|
@@ -5727,6 +5826,9 @@
|
|
this.tabContainer.insertBefore(aTab, neighbor);
|
|
}
|
|
});
|
|
+ if (aTab.hasAttribute("glance-id")) {
|
|
+ this.moveTabTo(aTab.querySelector("tab[glance-id]"), aIndex, options);
|
|
+ }
|
|
}
|
|
|
|
moveTabToGroup(aTab, aGroup) {
|
|
@@ -7443,6 +7545,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;
|
|
gBrowser.syncThrobberAnimations(this.mTab);
|
|
@@ -8411,7 +8514,7 @@ var TabContextMenu = {
|
|
);
|
|
contextUnpinSelectedTabs.hidden =
|
|
!this.contextTab.pinned || !multiselectionContext;
|
|
-
|
|
+ gZenPinnedTabManager.updatePinnedTabContextMenu(this.contextTab);
|
|
// Move Tab items
|
|
let contextMoveTabOptions = document.getElementById(
|
|
"context_moveTabOptions"
|
|
@@ -8444,7 +8547,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 =
|
|
@@ -8677,6 +8780,7 @@ var TabContextMenu = {
|
|
if (this.contextTab.multiselected) {
|
|
gBrowser.removeMultiSelectedTabs();
|
|
} else {
|
|
+ gZenPinnedTabManager._removePinnedAttributes(this.contextTab, true);
|
|
gBrowser.removeTab(this.contextTab, { animate: true });
|
|
}
|
|
},
|