Skip to content

Commit 3e7c1c8

Browse files
committed
fix: preserve tab owner for multiple background tabs
1 parent 2ac1db0 commit 3e7c1c8

File tree

1 file changed

+44
-36
lines changed

1 file changed

+44
-36
lines changed

src/browser/components/tabbrowser/content/tabbrowser-js.patch

Lines changed: 44 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
diff --git a/browser/components/tabbrowser/content/tabbrowser.js b/browser/components/tabbrowser/content/tabbrowser.js
2-
index c0eafd4faf8d57b8486c5bf8917375850ec8147e..2ab3908f421d6bc126eb7a0f886646ad0c761fb5 100644
2+
index c0eafd4faf8d57b8486c5bf8917375850ec8147e..6e15ac62a5b40ab47cd16b5a400a424e27446023 100644
33
--- a/browser/components/tabbrowser/content/tabbrowser.js
44
+++ b/browser/components/tabbrowser/content/tabbrowser.js
55
@@ -450,15 +450,64 @@
@@ -453,7 +453,7 @@ index c0eafd4faf8d57b8486c5bf8917375850ec8147e..2ab3908f421d6bc126eb7a0f886646ad
453453
tabGroup = previousTab.group;
454454
}
455455
if (
456-
@@ -4264,7 +4391,7 @@
456+
@@ -4264,14 +4391,12 @@
457457
) {
458458
elementIndex = Infinity;
459459
} else if (previousTab.visible) {
@@ -462,7 +462,15 @@ index c0eafd4faf8d57b8486c5bf8917375850ec8147e..2ab3908f421d6bc126eb7a0f886646ad
462462
} else if (previousTab == FirefoxViewHandler.tab) {
463463
elementIndex = 0;
464464
}
465-
@@ -4292,14 +4419,14 @@
465+
466+
- if (lastRelatedTab) {
467+
- lastRelatedTab.owner = null;
468+
- } else if (openerTab) {
469+
+ if (openerTab) {
470+
tab.owner = openerTab;
471+
}
472+
// Always set related map if opener exists.
473+
@@ -4292,14 +4417,14 @@
466474
}
467475
// Ensure index is within bounds.
468476
if (tab.pinned) {
@@ -481,7 +489,7 @@ index c0eafd4faf8d57b8486c5bf8917375850ec8147e..2ab3908f421d6bc126eb7a0f886646ad
481489

482490
if (pinned && !itemAfter?.pinned) {
483491
itemAfter = null;
484-
@@ -4310,7 +4437,7 @@
492+
@@ -4310,7 +4435,7 @@
485493

486494
this.tabContainer._invalidateCachedTabs();
487495

@@ -490,15 +498,15 @@ index c0eafd4faf8d57b8486c5bf8917375850ec8147e..2ab3908f421d6bc126eb7a0f886646ad
490498
if (this.isTab(itemAfter) && itemAfter.group == tabGroup) {
491499
// Place at the front of, or between tabs in, the same tab group
492500
this.tabContainer.insertBefore(tab, itemAfter);
493-
@@ -4346,6 +4473,7 @@
501+
@@ -4346,6 +4471,7 @@
494502
if (pinned) {
495503
this._updateTabBarForPinnedTabs();
496504
}
497505
+ gZenWorkspaces.fixTabInsertLocation(tab, itemAfter);
498506

499507
TabBarVisibility.update();
500508
}
501-
@@ -4635,6 +4763,9 @@
509+
@@ -4635,6 +4761,9 @@
502510
return;
503511
}
504512

@@ -508,23 +516,23 @@ index c0eafd4faf8d57b8486c5bf8917375850ec8147e..2ab3908f421d6bc126eb7a0f886646ad
508516
this.removeTabs(selectedTabs, { isUserTriggered, telemetrySource });
509517
}
510518

511-
@@ -4896,6 +5027,7 @@
519+
@@ -4896,6 +5025,7 @@
512520
telemetrySource,
513521
} = {}
514522
) {
515523
+ tabs = tabs.filter(tab => !tab.hasAttribute("zen-empty-tab"));
516524
// When 'closeWindowWithLastTab' pref is enabled, closing all tabs
517525
// can be considered equivalent to closing the window.
518526
if (
519-
@@ -4985,6 +5117,7 @@
527+
@@ -4985,6 +5115,7 @@
520528
if (lastToClose) {
521529
this.removeTab(lastToClose, aParams);
522530
}
523531
+ gZenUIManager.onTabClose(undefined);
524532
} catch (e) {
525533
console.error(e);
526534
}
527-
@@ -5023,6 +5156,12 @@
535+
@@ -5023,6 +5154,12 @@
528536
aTab._closeTimeNoAnimTimerId = Glean.browserTabclose.timeNoAnim.start();
529537
}
530538

@@ -537,7 +545,7 @@ index c0eafd4faf8d57b8486c5bf8917375850ec8147e..2ab3908f421d6bc126eb7a0f886646ad
537545
// Handle requests for synchronously removing an already
538546
// asynchronously closing tab.
539547
if (!animate && aTab.closing) {
540-
@@ -5037,6 +5176,9 @@
548+
@@ -5037,6 +5174,9 @@
541549
// state).
542550
let tabWidth = window.windowUtils.getBoundsWithoutFlushing(aTab).width;
543551
let isLastTab = this.#isLastTabInWindow(aTab);
@@ -547,7 +555,7 @@ index c0eafd4faf8d57b8486c5bf8917375850ec8147e..2ab3908f421d6bc126eb7a0f886646ad
547555
if (
548556
!this._beginRemoveTab(aTab, {
549557
closeWindowFastpath: true,
550-
@@ -5085,7 +5227,13 @@
558+
@@ -5085,7 +5225,13 @@
551559
// We're not animating, so we can cancel the animation stopwatch.
552560
Glean.browserTabclose.timeAnim.cancel(aTab._closeTimeAnimTimerId);
553561
aTab._closeTimeAnimTimerId = null;
@@ -562,7 +570,7 @@ index c0eafd4faf8d57b8486c5bf8917375850ec8147e..2ab3908f421d6bc126eb7a0f886646ad
562570
return;
563571
}
564572

565-
@@ -5219,7 +5367,7 @@
573+
@@ -5219,7 +5365,7 @@
566574
closeWindowWithLastTab != null
567575
? closeWindowWithLastTab
568576
: !window.toolbar.visible ||
@@ -571,15 +579,15 @@ index c0eafd4faf8d57b8486c5bf8917375850ec8147e..2ab3908f421d6bc126eb7a0f886646ad
571579

572580
if (closeWindow) {
573581
// We've already called beforeunload on all the relevant tabs if we get here,
574-
@@ -5243,6 +5391,7 @@
582+
@@ -5243,6 +5389,7 @@
575583

576584
newTab = true;
577585
}
578586
+ gZenWorkspaces._removedByStartupPage = false;
579587
aTab._endRemoveArgs = [closeWindow, newTab];
580588

581589
// swapBrowsersAndCloseOther will take care of closing the window without animation.
582-
@@ -5283,13 +5432,7 @@
590+
@@ -5283,13 +5430,7 @@
583591
aTab._mouseleave();
584592

585593
if (newTab) {
@@ -594,23 +602,23 @@ index c0eafd4faf8d57b8486c5bf8917375850ec8147e..2ab3908f421d6bc126eb7a0f886646ad
594602
} else {
595603
TabBarVisibility.update();
596604
}
597-
@@ -5422,6 +5565,7 @@
605+
@@ -5422,6 +5563,7 @@
598606
this.tabs[i]._tPos = i;
599607
}
600608

601609
+ gZenWorkspaces.updateTabsContainers();
602610
if (!this._windowIsClosing) {
603611
// update tab close buttons state
604612
this.tabContainer._updateCloseButtons();
605-
@@ -5643,6 +5787,7 @@
613+
@@ -5643,6 +5785,7 @@
606614
}
607615

608616
let excludeTabs = new Set(aExcludeTabs);
609617
+ gZenWorkspaces.getTabsToExclude(aTab).forEach(tab => excludeTabs.add(tab));
610618

611619
// If this tab has a successor, it should be selectable, since
612620
// hiding or closing a tab removes that tab as a successor.
613-
@@ -5655,13 +5800,13 @@
621+
@@ -5655,13 +5798,13 @@
614622
!excludeTabs.has(aTab.owner) &&
615623
Services.prefs.getBoolPref("browser.tabs.selectOwnerOnClose")
616624
) {
@@ -626,7 +634,7 @@ index c0eafd4faf8d57b8486c5bf8917375850ec8147e..2ab3908f421d6bc126eb7a0f886646ad
626634
);
627635

628636
let tab = this.tabContainer.findNextTab(aTab, {
629-
@@ -5677,7 +5822,7 @@
637+
@@ -5677,7 +5820,7 @@
630638
}
631639

632640
if (tab) {
@@ -635,7 +643,7 @@ index c0eafd4faf8d57b8486c5bf8917375850ec8147e..2ab3908f421d6bc126eb7a0f886646ad
635643
}
636644

637645
// If no qualifying visible tab was found, see if there is a tab in
638-
@@ -5698,7 +5843,7 @@
646+
@@ -5698,7 +5841,7 @@
639647
});
640648
}
641649

@@ -644,7 +652,7 @@ index c0eafd4faf8d57b8486c5bf8917375850ec8147e..2ab3908f421d6bc126eb7a0f886646ad
644652
}
645653

646654
_blurTab(aTab) {
647-
@@ -6104,10 +6249,10 @@
655+
@@ -6104,10 +6247,10 @@
648656
SessionStore.deleteCustomTabValue(aTab, "hiddenBy");
649657
}
650658

@@ -657,15 +665,15 @@ index c0eafd4faf8d57b8486c5bf8917375850ec8147e..2ab3908f421d6bc126eb7a0f886646ad
657665
aTab.selected ||
658666
aTab.closing ||
659667
// Tabs that are sharing the screen, microphone or camera cannot be hidden.
660-
@@ -6166,6 +6311,7 @@
668+
@@ -6166,6 +6309,7 @@
661669
* @param {MozTabbrowserTab|MozTabbrowserTabGroup|MozTabbrowserTabGroup.labelElement} aTab
662670
*/
663671
replaceTabWithWindow(aTab, aOptions) {
664672
+ if (!this.isTab(aTab)) return; // TODO: Handle tab groups
665673
if (this.tabs.length == 1) {
666674
return null;
667675
}
668-
@@ -6299,7 +6445,7 @@
676+
@@ -6299,7 +6443,7 @@
669677
* `true` if element is a `<tab-group>`
670678
*/
671679
isTabGroup(element) {
@@ -674,7 +682,7 @@ index c0eafd4faf8d57b8486c5bf8917375850ec8147e..2ab3908f421d6bc126eb7a0f886646ad
674682
}
675683

676684
/**
677-
@@ -6375,8 +6521,8 @@
685+
@@ -6375,8 +6519,8 @@
678686
}
679687

680688
// Don't allow mixing pinned and unpinned tabs.
@@ -685,7 +693,7 @@ index c0eafd4faf8d57b8486c5bf8917375850ec8147e..2ab3908f421d6bc126eb7a0f886646ad
685693
} else {
686694
tabIndex = Math.max(tabIndex, this.pinnedTabCount);
687695
}
688-
@@ -6402,10 +6548,16 @@
696+
@@ -6402,10 +6546,16 @@
689697
this.#handleTabMove(
690698
element,
691699
() => {
@@ -704,7 +712,7 @@ index c0eafd4faf8d57b8486c5bf8917375850ec8147e..2ab3908f421d6bc126eb7a0f886646ad
704712
if (neighbor && this.isTab(element) && tabIndex > element._tPos) {
705713
neighbor.after(element);
706714
} else {
707-
@@ -6463,23 +6615,28 @@
715+
@@ -6463,23 +6613,28 @@
708716
#moveTabNextTo(element, targetElement, moveBefore = false, metricsContext) {
709717
if (this.isTabGroupLabel(targetElement)) {
710718
targetElement = targetElement.group;
@@ -739,7 +747,7 @@ index c0eafd4faf8d57b8486c5bf8917375850ec8147e..2ab3908f421d6bc126eb7a0f886646ad
739747
} else if (!element.pinned && targetElement && targetElement.pinned) {
740748
// If the caller asks to move an unpinned element next to a pinned
741749
// tab, move the unpinned element to be the first unpinned element
742-
@@ -6492,14 +6649,34 @@
750+
@@ -6492,14 +6647,34 @@
743751
// move the tab group right before the first unpinned tab.
744752
// 4. Moving a tab group and the first unpinned tab is grouped:
745753
// move the tab group right before the first unpinned tab's tab group.
@@ -775,7 +783,7 @@ index c0eafd4faf8d57b8486c5bf8917375850ec8147e..2ab3908f421d6bc126eb7a0f886646ad
775783
element.pinned
776784
? this.tabContainer.pinnedTabsContainer
777785
: this.tabContainer;
778-
@@ -6508,7 +6685,7 @@
786+
@@ -6508,7 +6683,7 @@
779787
element,
780788
() => {
781789
if (moveBefore) {
@@ -784,7 +792,7 @@ index c0eafd4faf8d57b8486c5bf8917375850ec8147e..2ab3908f421d6bc126eb7a0f886646ad
784792
} else if (targetElement) {
785793
targetElement.after(element);
786794
} else {
787-
@@ -6580,10 +6757,10 @@
795+
@@ -6580,10 +6755,10 @@
788796
* @param {TabMetricsContext} [metricsContext]
789797
*/
790798
moveTabToGroup(aTab, aGroup, metricsContext) {
@@ -797,15 +805,15 @@ index c0eafd4faf8d57b8486c5bf8917375850ec8147e..2ab3908f421d6bc126eb7a0f886646ad
797805
return;
798806
}
799807
if (aTab.group && aTab.group.id === aGroup.id) {
800-
@@ -6613,6 +6790,7 @@
808+
@@ -6613,6 +6788,7 @@
801809

802810
let state = {
803811
tabIndex: tab._tPos,
804812
+ workspaceId: tab.getAttribute("zen-workspace-id")
805813
};
806814
if (tab.visible) {
807815
state.elementIndex = tab.elementIndex;
808-
@@ -6639,7 +6817,7 @@
816+
@@ -6639,7 +6815,7 @@
809817
let changedTabGroup =
810818
previousTabState.tabGroupId != currentTabState.tabGroupId;
811819

@@ -814,7 +822,7 @@ index c0eafd4faf8d57b8486c5bf8917375850ec8147e..2ab3908f421d6bc126eb7a0f886646ad
814822
tab.dispatchEvent(
815823
new CustomEvent("TabMove", {
816824
bubbles: true,
817-
@@ -6676,6 +6854,10 @@
825+
@@ -6676,6 +6852,10 @@
818826

819827
moveActionCallback();
820828

@@ -825,7 +833,7 @@ index c0eafd4faf8d57b8486c5bf8917375850ec8147e..2ab3908f421d6bc126eb7a0f886646ad
825833
// Clear tabs cache after moving nodes because the order of tabs may have
826834
// changed.
827835
this.tabContainer._invalidateCachedTabs();
828-
@@ -7576,7 +7758,7 @@
836+
@@ -7576,7 +7756,7 @@
829837
// preventDefault(). It will still raise the window if appropriate.
830838
break;
831839
}
@@ -834,23 +842,23 @@ index c0eafd4faf8d57b8486c5bf8917375850ec8147e..2ab3908f421d6bc126eb7a0f886646ad
834842
window.focus();
835843
aEvent.preventDefault();
836844
break;
837-
@@ -7593,7 +7775,6 @@
845+
@@ -7593,7 +7773,6 @@
838846
}
839847
case "TabGroupCollapse":
840848
aEvent.target.tabs.forEach(tab => {
841849
- this.removeFromMultiSelectedTabs(tab);
842850
});
843851
break;
844852
case "TabGroupCreateByUser":
845-
@@ -8542,6 +8723,7 @@
853+
@@ -8542,6 +8721,7 @@
846854
aWebProgress.isTopLevel
847855
) {
848856
this.mTab.setAttribute("busy", "true");
849857
+ if (!this.mTab.selected) this.mTab.setAttribute("unread", "true");
850858
gBrowser._tabAttrModified(this.mTab, ["busy"]);
851859
this.mTab._notselectedsinceload = !this.mTab.selected;
852860
}
853-
@@ -9543,7 +9725,7 @@ var TabContextMenu = {
861+
@@ -9543,7 +9723,7 @@ var TabContextMenu = {
854862
);
855863
contextUnpinSelectedTabs.hidden =
856864
!this.contextTab.pinned || !this.multiselected;
@@ -859,7 +867,7 @@ index c0eafd4faf8d57b8486c5bf8917375850ec8147e..2ab3908f421d6bc126eb7a0f886646ad
859867
// Build Ask Chat items
860868
TabContextMenu.GenAI.buildTabMenu(
861869
document.getElementById("context_askChat"),
862-
@@ -9863,6 +10045,7 @@ var TabContextMenu = {
870+
@@ -9863,6 +10043,7 @@ var TabContextMenu = {
863871
)
864872
);
865873
} else {

0 commit comments

Comments
 (0)