chore: Update tab icons and labels in sync, b=(no-bug), c=tabs, workspaces

This commit is contained in:
mr. m 2025-04-30 18:28:44 +02:00
parent c87cd9fd04
commit e7c3631a71
No known key found for this signature in database
GPG key ID: 419302196C23B258
3 changed files with 77 additions and 35 deletions

View file

@ -1,5 +1,5 @@
diff --git a/browser/components/tabbrowser/content/tabbrowser.js b/browser/components/tabbrowser/content/tabbrowser.js diff --git a/browser/components/tabbrowser/content/tabbrowser.js b/browser/components/tabbrowser/content/tabbrowser.js
index 6dece2b9d0462d90a28e75350ce983d87816ef73..ccf33e469c3e4b8d0fb55a50561023b15b3451aa 100644 index 6dece2b9d0462d90a28e75350ce983d87816ef73..fc09d86f76ce3de8ecc2731450681069b17d16d7 100644
--- a/browser/components/tabbrowser/content/tabbrowser.js --- a/browser/components/tabbrowser/content/tabbrowser.js
+++ b/browser/components/tabbrowser/content/tabbrowser.js +++ b/browser/components/tabbrowser/content/tabbrowser.js
@@ -415,11 +415,58 @@ @@ -415,11 +415,58 @@
@ -323,12 +323,12 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..ccf33e469c3e4b8d0fb55a50561023b1
+ if (tabData.zenHasStaticLabel) { + if (tabData.zenHasStaticLabel) {
+ tab.setAttribute("zen-has-static-label", "true"); + tab.setAttribute("zen-has-static-label", "true");
+ } + }
+ if (tabData.zenTabId) {
+ tab.setAttribute("zen-tab-id", tabData.zenTabId);
+ }
+ if (tabData.zenPinnedId) { + if (tabData.zenPinnedId) {
+ tab.setAttribute("zen-pin-id", tabData.zenPinnedId); + tab.setAttribute("zen-pin-id", tabData.zenPinnedId);
+ } + }
+ if (tabData.zenTabId) {
+ tab.setAttribute("zen-tab-id", tabData.zenTabId);
+ }
+ if (tabData.zenEssential) { + if (tabData.zenEssential) {
+ tab.setAttribute("zen-essential", "true"); + tab.setAttribute("zen-essential", "true");
+ } + }
@ -395,17 +395,23 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..ccf33e469c3e4b8d0fb55a50561023b1
); );
tabsFragment.appendChild(tabGroup.node); tabsFragment.appendChild(tabGroup.node);
} }
@@ -3726,6 +3872,9 @@ @@ -3723,8 +3869,15 @@
// to remove the old selected tab.
if (tabToSelect) {
let leftoverTab = this.selectedTab;
+ if (tabToSelect.pinned) {
+ ZenWorkspaces._tabToRemoveForEmpty = leftoverTab;
+ } else {
this.selectedTab = tabToSelect; this.selectedTab = tabToSelect;
this.removeTab(leftoverTab); this.removeTab(leftoverTab);
} + }
+ }
+ else { + else {
+ this.selectedTab._possiblyEmpty = this.selectedTab.isEmpty; // Not needed, but just in case. + this.selectedTab._possiblyEmpty = this.selectedTab.isEmpty; // Not needed, but just in case.
+ } }
if (tabs.length > 1 || !tabs[0].selected) { if (tabs.length > 1 || !tabs[0].selected) {
this._updateTabsAfterInsert(); @@ -3912,7 +4065,7 @@
@@ -3912,7 +4061,7 @@
// Ensure we have an index if one was not provided. // Ensure we have an index if one was not provided.
if (typeof index != "number") { if (typeof index != "number") {
// Move the new tab after another tab if needed, to the end otherwise. // Move the new tab after another tab if needed, to the end otherwise.
@ -414,7 +420,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..ccf33e469c3e4b8d0fb55a50561023b1
if ( if (
!bulkOrderedOpen && !bulkOrderedOpen &&
((openerTab && ((openerTab &&
@@ -3958,18 +4107,18 @@ @@ -3958,18 +4111,18 @@
// Ensure index is within bounds. // Ensure index is within bounds.
if (tab.pinned) { if (tab.pinned) {
@ -437,7 +443,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..ccf33e469c3e4b8d0fb55a50561023b1
if (this.isTab(itemAfter) && itemAfter.group == tabGroup) { if (this.isTab(itemAfter) && itemAfter.group == tabGroup) {
// Place at the front of, or between tabs in, the same tab group // Place at the front of, or between tabs in, the same tab group
this.tabContainer.insertBefore(tab, itemAfter); this.tabContainer.insertBefore(tab, itemAfter);
@@ -4290,6 +4439,9 @@ @@ -4290,6 +4443,9 @@
return; return;
} }
@ -447,7 +453,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..ccf33e469c3e4b8d0fb55a50561023b1
this.removeTabs(selectedTabs, { telemetrySource }); this.removeTabs(selectedTabs, { telemetrySource });
} }
@@ -4542,6 +4694,7 @@ @@ -4542,6 +4698,7 @@
telemetrySource, telemetrySource,
} = {} } = {}
) { ) {
@ -455,7 +461,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..ccf33e469c3e4b8d0fb55a50561023b1
// When 'closeWindowWithLastTab' pref is enabled, closing all tabs // When 'closeWindowWithLastTab' pref is enabled, closing all tabs
// can be considered equivalent to closing the window. // can be considered equivalent to closing the window.
if ( if (
@@ -4626,6 +4779,7 @@ @@ -4626,6 +4783,7 @@
if (lastToClose) { if (lastToClose) {
this.removeTab(lastToClose, aParams); this.removeTab(lastToClose, aParams);
} }
@ -463,7 +469,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..ccf33e469c3e4b8d0fb55a50561023b1
} catch (e) { } catch (e) {
console.error(e); console.error(e);
} }
@@ -4650,6 +4804,7 @@ @@ -4650,6 +4808,7 @@
telemetrySource, telemetrySource,
} = {} } = {}
) { ) {
@ -471,7 +477,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..ccf33e469c3e4b8d0fb55a50561023b1
if (UserInteraction.running("browser.tabs.opening", window)) { if (UserInteraction.running("browser.tabs.opening", window)) {
UserInteraction.finish("browser.tabs.opening", window); UserInteraction.finish("browser.tabs.opening", window);
} }
@@ -4663,6 +4818,12 @@ @@ -4663,6 +4822,12 @@
aTab._closeTimeNoAnimTimerId = Glean.browserTabclose.timeNoAnim.start(); aTab._closeTimeNoAnimTimerId = Glean.browserTabclose.timeNoAnim.start();
} }
@ -484,7 +490,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..ccf33e469c3e4b8d0fb55a50561023b1
// Handle requests for synchronously removing an already // Handle requests for synchronously removing an already
// asynchronously closing tab. // asynchronously closing tab.
if (!animate && aTab.closing) { if (!animate && aTab.closing) {
@@ -4677,7 +4838,9 @@ @@ -4677,7 +4842,9 @@
// frame created for it (for example, by updating the visually selected // frame created for it (for example, by updating the visually selected
// state). // state).
let tabWidth = window.windowUtils.getBoundsWithoutFlushing(aTab).width; let tabWidth = window.windowUtils.getBoundsWithoutFlushing(aTab).width;
@ -495,7 +501,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..ccf33e469c3e4b8d0fb55a50561023b1
if ( if (
!this._beginRemoveTab(aTab, { !this._beginRemoveTab(aTab, {
closeWindowFastpath: true, closeWindowFastpath: true,
@@ -4840,7 +5003,7 @@ @@ -4840,7 +5007,7 @@
closeWindowWithLastTab != null closeWindowWithLastTab != null
? closeWindowWithLastTab ? closeWindowWithLastTab
: !window.toolbar.visible || : !window.toolbar.visible ||
@ -504,7 +510,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..ccf33e469c3e4b8d0fb55a50561023b1
if (closeWindow) { if (closeWindow) {
// We've already called beforeunload on all the relevant tabs if we get here, // We've already called beforeunload on all the relevant tabs if we get here,
@@ -4864,6 +5027,7 @@ @@ -4864,6 +5031,7 @@
newTab = true; newTab = true;
} }
@ -512,7 +518,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..ccf33e469c3e4b8d0fb55a50561023b1
aTab._endRemoveArgs = [closeWindow, newTab]; aTab._endRemoveArgs = [closeWindow, newTab];
// swapBrowsersAndCloseOther will take care of closing the window without animation. // swapBrowsersAndCloseOther will take care of closing the window without animation.
@@ -4903,9 +5067,7 @@ @@ -4903,9 +5071,7 @@
aTab._mouseleave(); aTab._mouseleave();
if (newTab) { if (newTab) {
@ -523,7 +529,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..ccf33e469c3e4b8d0fb55a50561023b1
} else { } else {
TabBarVisibility.update(); TabBarVisibility.update();
} }
@@ -5034,6 +5196,8 @@ @@ -5034,6 +5200,8 @@
this.tabs[i]._tPos = i; this.tabs[i]._tPos = i;
} }
@ -532,7 +538,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..ccf33e469c3e4b8d0fb55a50561023b1
if (!this._windowIsClosing) { if (!this._windowIsClosing) {
if (wasPinned) { if (wasPinned) {
this.tabContainer._positionPinnedTabs(); this.tabContainer._positionPinnedTabs();
@@ -5159,8 +5323,8 @@ @@ -5159,8 +5327,8 @@
return closedCount; return closedCount;
} }
@ -543,7 +549,15 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..ccf33e469c3e4b8d0fb55a50561023b1
if (unloadBlocked) { if (unloadBlocked) {
return; return;
} }
@@ -5260,13 +5424,13 @@ @@ -5247,6 +5415,7 @@
aExcludeTabs.push(FirefoxViewHandler.tab);
}
+ aExcludeTabs.push(...ZenWorkspaces.getTabsToExclude(aTab));
let excludeTabs = new Set(aExcludeTabs);
// If this tab has a successor, it should be selectable, since
@@ -5260,13 +5429,13 @@
!excludeTabs.has(aTab.owner) && !excludeTabs.has(aTab.owner) &&
Services.prefs.getBoolPref("browser.tabs.selectOwnerOnClose") Services.prefs.getBoolPref("browser.tabs.selectOwnerOnClose")
) { ) {
@ -559,7 +573,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..ccf33e469c3e4b8d0fb55a50561023b1
); );
let tab = this.tabContainer.findNextTab(aTab, { let tab = this.tabContainer.findNextTab(aTab, {
@@ -5282,7 +5446,7 @@ @@ -5282,7 +5451,7 @@
} }
if (tab) { if (tab) {
@ -568,7 +582,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..ccf33e469c3e4b8d0fb55a50561023b1
} }
// If no qualifying visible tab was found, see if there is a tab in // If no qualifying visible tab was found, see if there is a tab in
@@ -5303,7 +5467,7 @@ @@ -5303,7 +5472,7 @@
}); });
} }
@ -577,7 +591,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..ccf33e469c3e4b8d0fb55a50561023b1
} }
_blurTab(aTab) { _blurTab(aTab) {
@@ -5704,10 +5868,10 @@ @@ -5704,10 +5873,10 @@
SessionStore.deleteCustomTabValue(aTab, "hiddenBy"); SessionStore.deleteCustomTabValue(aTab, "hiddenBy");
} }
@ -590,7 +604,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..ccf33e469c3e4b8d0fb55a50561023b1
aTab.selected || aTab.selected ||
aTab.closing || aTab.closing ||
// Tabs that are sharing the screen, microphone or camera cannot be hidden. // Tabs that are sharing the screen, microphone or camera cannot be hidden.
@@ -6001,7 +6165,7 @@ @@ -6001,7 +6170,7 @@
// Don't allow mixing pinned and unpinned tabs. // Don't allow mixing pinned and unpinned tabs.
if (this.isTab(element) && element.pinned) { if (this.isTab(element) && element.pinned) {
@ -599,7 +613,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..ccf33e469c3e4b8d0fb55a50561023b1
} else { } else {
tabIndex = Math.max(tabIndex, this.pinnedTabCount); tabIndex = Math.max(tabIndex, this.pinnedTabCount);
} }
@@ -6028,9 +6192,16 @@ @@ -6028,9 +6197,16 @@
element, element,
() => { () => {
let neighbor = this.tabs[tabIndex]; let neighbor = this.tabs[tabIndex];
@ -617,7 +631,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..ccf33e469c3e4b8d0fb55a50561023b1
if (neighbor && this.isTab(element) && tabIndex > element._tPos) { if (neighbor && this.isTab(element) && tabIndex > element._tPos) {
neighbor.after(element); neighbor.after(element);
} else { } else {
@@ -6099,7 +6270,9 @@ @@ -6099,7 +6275,9 @@
targetElement = targetElement.group; targetElement = targetElement.group;
} }
} }
@ -628,7 +642,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..ccf33e469c3e4b8d0fb55a50561023b1
// Don't allow mixing pinned and unpinned tabs. // Don't allow mixing pinned and unpinned tabs.
if (element.pinned && !targetElement?.pinned) { if (element.pinned && !targetElement?.pinned) {
targetElement = this.tabs[this.pinnedTabCount - 1]; targetElement = this.tabs[this.pinnedTabCount - 1];
@@ -6109,7 +6282,13 @@ @@ -6109,7 +6287,13 @@
moveBefore = true; moveBefore = true;
} }
@ -642,7 +656,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..ccf33e469c3e4b8d0fb55a50561023b1
if (element.pinned && this.tabContainer.verticalMode) { if (element.pinned && this.tabContainer.verticalMode) {
return this.tabContainer.verticalPinnedTabsContainer; return this.tabContainer.verticalPinnedTabsContainer;
} }
@@ -6169,7 +6348,7 @@ @@ -6169,7 +6353,7 @@
if (!this.isTab(aTab)) { if (!this.isTab(aTab)) {
throw new Error("Can only move a tab into a tab group"); throw new Error("Can only move a tab into a tab group");
} }
@ -651,7 +665,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..ccf33e469c3e4b8d0fb55a50561023b1
return; return;
} }
if (aTab.group && aTab.group.id === aGroup.id) { if (aTab.group && aTab.group.id === aGroup.id) {
@@ -6263,6 +6442,10 @@ @@ -6263,6 +6447,10 @@
moveActionCallback(); moveActionCallback();
@ -662,7 +676,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..ccf33e469c3e4b8d0fb55a50561023b1
// Clear tabs cache after moving nodes because the order of tabs may have // Clear tabs cache after moving nodes because the order of tabs may have
// changed. // changed.
this.tabContainer._invalidateCachedTabs(); this.tabContainer._invalidateCachedTabs();
@@ -7080,7 +7263,7 @@ @@ -7080,7 +7268,7 @@
// preventDefault(). It will still raise the window if appropriate. // preventDefault(). It will still raise the window if appropriate.
break; break;
} }
@ -671,7 +685,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..ccf33e469c3e4b8d0fb55a50561023b1
window.focus(); window.focus();
aEvent.preventDefault(); aEvent.preventDefault();
break; break;
@@ -7981,6 +8164,7 @@ @@ -7981,6 +8169,7 @@
aWebProgress.isTopLevel aWebProgress.isTopLevel
) { ) {
this.mTab.setAttribute("busy", "true"); this.mTab.setAttribute("busy", "true");
@ -679,7 +693,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..ccf33e469c3e4b8d0fb55a50561023b1
gBrowser._tabAttrModified(this.mTab, ["busy"]); gBrowser._tabAttrModified(this.mTab, ["busy"]);
this.mTab._notselectedsinceload = !this.mTab.selected; this.mTab._notselectedsinceload = !this.mTab.selected;
} }
@@ -8954,7 +9138,7 @@ var TabContextMenu = { @@ -8954,7 +9143,7 @@ var TabContextMenu = {
); );
contextUnpinSelectedTabs.hidden = contextUnpinSelectedTabs.hidden =
!this.contextTab.pinned || !this.multiselected; !this.contextTab.pinned || !this.multiselected;
@ -688,7 +702,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..ccf33e469c3e4b8d0fb55a50561023b1
// Move Tab items // Move Tab items
let contextMoveTabOptions = document.getElementById( let contextMoveTabOptions = document.getElementById(
"context_moveTabOptions" "context_moveTabOptions"
@@ -9223,6 +9407,7 @@ var TabContextMenu = { @@ -9223,6 +9412,7 @@ var TabContextMenu = {
telemetrySource: gBrowser.TabMetrics.METRIC_SOURCE.TAB_STRIP, telemetrySource: gBrowser.TabMetrics.METRIC_SOURCE.TAB_STRIP,
}); });
} else { } else {

View file

@ -82,6 +82,7 @@
} }
onTabIconChanged(tab, url = null) { onTabIconChanged(tab, url = null) {
tab.dispatchEvent(new CustomEvent('Zen:TabIconChanged', { bubbles: true, detail: { tab } }));
const iconUrl = url ?? tab.iconImage.src; const iconUrl = url ?? tab.iconImage.src;
if (!iconUrl) { if (!iconUrl) {
try { try {
@ -1015,6 +1016,7 @@
} }
async onTabLabelChanged(tab) { async onTabLabelChanged(tab) {
tab.dispatchEvent(new CustomEvent('Zen:TabLabelChanged', { detail: { tab } }));
if (!this._pinsCache) { if (!this._pinsCache) {
return; return;
} }

View file

@ -2950,6 +2950,8 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
'TabHide', 'TabHide',
'TabShow', 'TabShow',
'TabMove', 'TabMove',
'Zen:TabIconChanged',
'Zen:TabLabelChanged',
]; ];
const eventListener = this.#handleEvent.bind(this); const eventListener = this.#handleEvent.bind(this);
for (const event of kEvents) { for (const event of kEvents) {
@ -3008,6 +3010,12 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
case 'TabMove': case 'TabMove':
this.#onTabMove(event); this.#onTabMove(event);
break; break;
case 'Zen:TabIconChanged':
this.#onTabIconChanged(event);
break;
case 'Zen:TabLabelChanged':
this.#onTabLabelChanged(event);
break;
default: default:
console.warn(`Unhandled event type: ${event.type}`); console.warn(`Unhandled event type: ${event.type}`);
break; break;
@ -3028,6 +3036,24 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
return null; return null;
} }
#onTabIconChanged(event) {
this.#updateTabIconAndLabel(event);
}
#onTabLabelChanged(event) {
this.#updateTabIconAndLabel(event);
}
#updateTabIconAndLabel(event) {
const targetTab = event.target;
const tabId = this.#getTabId(targetTab);
const tabToChange = this.#getTabWithId(tabId);
if (tabToChange) {
gBrowser.setIcon(tabToChange, gBrowser.getIcon(targetTab));
gBrowser._setTabLabel(tabToChange, targetTab.label);
}
}
#onTabClose(event) { #onTabClose(event) {
const targetTab = event.target; const targetTab = event.target;
const tabId = this.#getTabId(targetTab); const tabId = this.#getTabId(targetTab);