mirror of
https://github.com/zen-browser/desktop.git
synced 2025-09-05 19:08:18 +00:00
Refactor ZenPinnedTabManager and ZenUIManager for improved tab closing behavior and URL bar handling
This commit is contained in:
@@ -29,7 +29,6 @@ var gZenUIManager = {
|
||||
});
|
||||
|
||||
window.addEventListener('TabClose', this.onTabClose.bind(this));
|
||||
window.addEventListener('TabSelect', this.onTabSelect.bind(this));
|
||||
},
|
||||
|
||||
updateTabsToolbar() {
|
||||
@@ -147,38 +146,40 @@ var gZenUIManager = {
|
||||
_prevUrlbarLabel: null,
|
||||
_lastSearch: "",
|
||||
|
||||
onTabSelect(event) {
|
||||
this._prevUrlbarLabel = null;
|
||||
this._lastSearch = "";
|
||||
if (gURLBar.hasAttribute('zen-newtab')) {
|
||||
this.handleUrlbarClose();
|
||||
}
|
||||
},
|
||||
|
||||
handleNewTab(werePassedURL, searchClipboard, where) {
|
||||
const shouldOpenURLBar = Services.prefs.getBoolPref('zen.urlbar.replace-newtab')
|
||||
&& !werePassedURL && !searchClipboard && where === 'tab';
|
||||
if (shouldOpenURLBar) {
|
||||
if (this._prevUrlbarLabel !== gURLBar._untrimmedValue) {
|
||||
this._lastSearch = "";
|
||||
}
|
||||
this._prevUrlbarLabel = gURLBar._untrimmedValue;
|
||||
gURLBar._untrimmedValue = this._lastSearch;
|
||||
gURLBar._zenHandleUrlbarClose = this.handleUrlbarClose.bind(this);
|
||||
gURLBar.setAttribute('zen-newtab', true);
|
||||
document.getElementById('Browser:OpenLocation').doCommand();
|
||||
gURLBar.search(this._lastSearch);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
},
|
||||
|
||||
handleUrlbarClose() {
|
||||
gURLBar.controller.clearLastQueryContextCache();
|
||||
gURLBar.blur();
|
||||
handleUrlbarClose(onSwitch) {
|
||||
gURLBar._zenHandleUrlbarClose = null;
|
||||
if (onSwitch) {
|
||||
this._prevUrlbarLabel = null;
|
||||
this._lastSearch = "";
|
||||
} else {
|
||||
this._lastSearch = gURLBar._untrimmedValue;
|
||||
}
|
||||
if (this._prevUrlbarLabel) {
|
||||
gURLBar.setURI(this._prevUrlbarLabel, false, false, false, true);
|
||||
}
|
||||
gURLBar.removeAttribute('zen-newtab');
|
||||
this._lastSearch = gURLBar._untrimmedValue;
|
||||
gURLBar.handleRevert();
|
||||
if (gURLBar.focused) {
|
||||
gURLBar.view.close();
|
||||
gURLBar.updateTextOverflow();
|
||||
if (gBrowser.selectedTab.linkedBrowser && onSwitch) {
|
||||
gURLBar.getBrowserState(gBrowser.selectedTab.linkedBrowser).urlbarFocused = false;
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
|
@@ -29,7 +29,7 @@
|
||||
|
||||
& #zen-sidebar-top-buttons .toolbarbutton-1 {
|
||||
& > .toolbarbutton-icon {
|
||||
padding: 5px;
|
||||
padding: 4px;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -749,12 +749,15 @@
|
||||
/* Mark: Override the default tab close button */
|
||||
#tabbrowser-tabs {
|
||||
& .tabbrowser-tab {
|
||||
&[pinned][visuallyselected] .tab-close-button {
|
||||
&[pinned]:not([pending='true']) .tab-close-button {
|
||||
display: none !important;
|
||||
}
|
||||
|
||||
&[pinned][visuallyselected]:not([zen-essential]) .tab-reset-button {
|
||||
display: block;
|
||||
&[pinned]:not([pending='true']):not([zen-essential]) {
|
||||
&:hover .tab-reset-button,
|
||||
&[visuallyselected] .tab-reset-button {
|
||||
display: block;
|
||||
}
|
||||
}
|
||||
|
||||
&[zen-essential] .tab-reset-button {
|
||||
|
@@ -450,7 +450,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
_onCloseTabShortcut(event, selectedTab = gBrowser.selectedTab) {
|
||||
_onCloseTabShortcut(event, selectedTab = gBrowser.selectedTab, behavior = lazy.zenPinnedTabCloseShortcutBehavior) {
|
||||
if (!selectedTab?.pinned) {
|
||||
return;
|
||||
}
|
||||
@@ -458,8 +458,6 @@
|
||||
event.stopPropagation();
|
||||
event.preventDefault();
|
||||
|
||||
const behavior = lazy.zenPinnedTabCloseShortcutBehavior;
|
||||
|
||||
switch (behavior) {
|
||||
case 'close':
|
||||
this._removePinnedAttributes(selectedTab, true);
|
||||
|
@@ -1,5 +1,5 @@
|
||||
diff --git a/browser/components/tabbrowser/content/tab.js b/browser/components/tabbrowser/content/tab.js
|
||||
index d41c486c02a6f09dcff5741a59ad8b617294c481..855152a13afdf58433c228e3675e2e0eebe3892e 100644
|
||||
index d41c486c02a6f09dcff5741a59ad8b617294c481..44535569b609d9bcd09f10e46e3161ce0a331c30 100644
|
||||
--- a/browser/components/tabbrowser/content/tab.js
|
||||
+++ b/browser/components/tabbrowser/content/tab.js
|
||||
@@ -37,6 +37,7 @@
|
||||
@@ -33,7 +33,7 @@ index d41c486c02a6f09dcff5741a59ad8b617294c481..855152a13afdf58433c228e3675e2e0e
|
||||
}
|
||||
+
|
||||
+ if (event.target.classList.contains("tab-reset-button")) {
|
||||
+ gZenPinnedTabManager._resetTabToStoredState(this);
|
||||
+ gZenPinnedTabManager._onCloseTabShortcut(event, this, 'unload-switch');
|
||||
+ gBrowser.tabContainer._blockDblClick = true;
|
||||
+ }
|
||||
}
|
||||
|
@@ -1,5 +1,5 @@
|
||||
diff --git a/browser/components/tabbrowser/content/tabbrowser.js b/browser/components/tabbrowser/content/tabbrowser.js
|
||||
index ff90a70bdad6c94ec4b90027ff102972d0eb28e5..cca93dc8fe6300a5bee22029bbe2369e9240ba35 100644
|
||||
index ff90a70bdad6c94ec4b90027ff102972d0eb28e5..dfc5d5cc1144a0098508a28de4f1433b9417f545 100644
|
||||
--- a/browser/components/tabbrowser/content/tabbrowser.js
|
||||
+++ b/browser/components/tabbrowser/content/tabbrowser.js
|
||||
@@ -406,11 +406,39 @@
|
||||
@@ -80,7 +80,17 @@ index ff90a70bdad6c94ec4b90027ff102972d0eb28e5..cca93dc8fe6300a5bee22029bbe2369e
|
||||
oldTab.updateLastAccessed();
|
||||
// if this is the foreground window, update the last-seen timestamps.
|
||||
if (this.ownerGlobal == BrowserWindowTracker.getTopWindow()) {
|
||||
@@ -2387,7 +2421,7 @@
|
||||
@@ -1477,6 +1511,9 @@
|
||||
newBrowser &&
|
||||
gURLBar.getBrowserState(newBrowser).urlbarFocused &&
|
||||
gURLBar.focused;
|
||||
+ if (gURLBar._zenHandleUrlbarClose) {
|
||||
+ gURLBar._zenHandleUrlbarClose(true);
|
||||
+ }
|
||||
if (!keepFocusOnUrlBar) {
|
||||
// Clear focus so that _adjustFocusAfterTabSwitch can detect if
|
||||
// some element has been focused and respect that.
|
||||
@@ -2387,7 +2424,7 @@
|
||||
|
||||
let panel = this.getPanel(browser);
|
||||
let uniqueId = this._generateUniquePanelID();
|
||||
@@ -89,7 +99,7 @@ index ff90a70bdad6c94ec4b90027ff102972d0eb28e5..cca93dc8fe6300a5bee22029bbe2369e
|
||||
aTab.linkedPanel = uniqueId;
|
||||
|
||||
// Inject the <browser> into the DOM if necessary.
|
||||
@@ -2447,7 +2481,7 @@
|
||||
@@ -2447,7 +2484,7 @@
|
||||
// hasSiblings=false on both the existing browser and the new browser.
|
||||
if (this.tabs.length == 2) {
|
||||
this.tabs[0].linkedBrowser.browsingContext.hasSiblings = true;
|
||||
@@ -98,7 +108,7 @@ index ff90a70bdad6c94ec4b90027ff102972d0eb28e5..cca93dc8fe6300a5bee22029bbe2369e
|
||||
} else {
|
||||
aTab.linkedBrowser.browsingContext.hasSiblings = this.tabs.length > 1;
|
||||
}
|
||||
@@ -2679,6 +2713,12 @@
|
||||
@@ -2679,6 +2716,12 @@
|
||||
);
|
||||
}
|
||||
|
||||
@@ -111,7 +121,7 @@ index ff90a70bdad6c94ec4b90027ff102972d0eb28e5..cca93dc8fe6300a5bee22029bbe2369e
|
||||
if (!UserInteraction.running("browser.tabs.opening", window)) {
|
||||
UserInteraction.start("browser.tabs.opening", "initting", window);
|
||||
}
|
||||
@@ -2742,6 +2782,12 @@
|
||||
@@ -2742,6 +2785,12 @@
|
||||
noInitialLabel,
|
||||
skipBackgroundNotify,
|
||||
});
|
||||
@@ -124,7 +134,7 @@ index ff90a70bdad6c94ec4b90027ff102972d0eb28e5..cca93dc8fe6300a5bee22029bbe2369e
|
||||
if (insertTab) {
|
||||
// insert the tab into the tab container in the correct position
|
||||
this._insertTabAtIndex(t, {
|
||||
@@ -2885,6 +2931,9 @@
|
||||
@@ -2885,6 +2934,9 @@
|
||||
}
|
||||
}
|
||||
|
||||
@@ -134,7 +144,7 @@ index ff90a70bdad6c94ec4b90027ff102972d0eb28e5..cca93dc8fe6300a5bee22029bbe2369e
|
||||
// Additionally send pinned tab events
|
||||
if (pinned) {
|
||||
this._notifyPinnedStatus(t);
|
||||
@@ -3403,6 +3452,21 @@
|
||||
@@ -3403,6 +3455,21 @@
|
||||
) {
|
||||
tabWasReused = true;
|
||||
tab = this.selectedTab;
|
||||
@@ -156,7 +166,7 @@ index ff90a70bdad6c94ec4b90027ff102972d0eb28e5..cca93dc8fe6300a5bee22029bbe2369e
|
||||
if (!tabData.pinned) {
|
||||
this.unpinTab(tab);
|
||||
} else {
|
||||
@@ -3416,6 +3480,7 @@
|
||||
@@ -3416,6 +3483,7 @@
|
||||
restoreTabsLazily && !select && !tabData.pinned;
|
||||
|
||||
let url = "about:blank";
|
||||
@@ -164,7 +174,7 @@ index ff90a70bdad6c94ec4b90027ff102972d0eb28e5..cca93dc8fe6300a5bee22029bbe2369e
|
||||
if (tabData.entries?.length) {
|
||||
let activeIndex = (tabData.index || tabData.entries.length) - 1;
|
||||
// Ensure the index is in bounds.
|
||||
@@ -3451,7 +3516,21 @@
|
||||
@@ -3451,7 +3519,21 @@
|
||||
skipLoad: true,
|
||||
preferredRemoteType,
|
||||
});
|
||||
@@ -187,7 +197,7 @@ index ff90a70bdad6c94ec4b90027ff102972d0eb28e5..cca93dc8fe6300a5bee22029bbe2369e
|
||||
if (select) {
|
||||
tabToSelect = tab;
|
||||
}
|
||||
@@ -3729,7 +3808,7 @@
|
||||
@@ -3729,7 +3811,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.
|
||||
@@ -196,7 +206,7 @@ index ff90a70bdad6c94ec4b90027ff102972d0eb28e5..cca93dc8fe6300a5bee22029bbe2369e
|
||||
if (
|
||||
!bulkOrderedOpen &&
|
||||
((openerTab &&
|
||||
@@ -3780,7 +3859,7 @@
|
||||
@@ -3780,7 +3862,7 @@
|
||||
}
|
||||
|
||||
/** @type {MozTabbrowserTab|undefined} */
|
||||
@@ -205,7 +215,7 @@ index ff90a70bdad6c94ec4b90027ff102972d0eb28e5..cca93dc8fe6300a5bee22029bbe2369e
|
||||
this.tabContainer._invalidateCachedTabs();
|
||||
|
||||
if (tabGroup) {
|
||||
@@ -4095,6 +4174,9 @@
|
||||
@@ -4095,6 +4177,9 @@
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -215,7 +225,7 @@ index ff90a70bdad6c94ec4b90027ff102972d0eb28e5..cca93dc8fe6300a5bee22029bbe2369e
|
||||
this.removeTabs(selectedTabs);
|
||||
}
|
||||
|
||||
@@ -4443,6 +4525,12 @@
|
||||
@@ -4443,6 +4528,12 @@
|
||||
TelemetryStopwatch.start("FX_TAB_CLOSE_TIME_NO_ANIM_MS", aTab);
|
||||
}
|
||||
|
||||
@@ -228,7 +238,7 @@ index ff90a70bdad6c94ec4b90027ff102972d0eb28e5..cca93dc8fe6300a5bee22029bbe2369e
|
||||
// Handle requests for synchronously removing an already
|
||||
// asynchronously closing tab.
|
||||
if (!animate && aTab.closing) {
|
||||
@@ -4457,7 +4545,9 @@
|
||||
@@ -4457,7 +4548,9 @@
|
||||
// frame created for it (for example, by updating the visually selected
|
||||
// state).
|
||||
let tabWidth = window.windowUtils.getBoundsWithoutFlushing(aTab).width;
|
||||
@@ -239,7 +249,7 @@ index ff90a70bdad6c94ec4b90027ff102972d0eb28e5..cca93dc8fe6300a5bee22029bbe2369e
|
||||
if (
|
||||
!this._beginRemoveTab(aTab, {
|
||||
closeWindowFastpath: true,
|
||||
@@ -4471,7 +4561,6 @@
|
||||
@@ -4471,7 +4564,6 @@
|
||||
TelemetryStopwatch.cancel("FX_TAB_CLOSE_TIME_NO_ANIM_MS", aTab);
|
||||
return;
|
||||
}
|
||||
@@ -247,7 +257,7 @@ index ff90a70bdad6c94ec4b90027ff102972d0eb28e5..cca93dc8fe6300a5bee22029bbe2369e
|
||||
let lockTabSizing =
|
||||
!this.tabContainer.verticalMode &&
|
||||
!aTab.pinned &&
|
||||
@@ -4610,14 +4699,14 @@
|
||||
@@ -4610,14 +4702,14 @@
|
||||
!!this.tabsInCollapsedTabGroups.length;
|
||||
if (
|
||||
aTab.visible &&
|
||||
@@ -264,7 +274,7 @@ index ff90a70bdad6c94ec4b90027ff102972d0eb28e5..cca93dc8fe6300a5bee22029bbe2369e
|
||||
|
||||
if (closeWindow) {
|
||||
// We've already called beforeunload on all the relevant tabs if we get here,
|
||||
@@ -5465,10 +5554,10 @@
|
||||
@@ -5465,10 +5557,10 @@
|
||||
SessionStore.deleteCustomTabValue(aTab, "hiddenBy");
|
||||
}
|
||||
|
||||
@@ -277,7 +287,7 @@ index ff90a70bdad6c94ec4b90027ff102972d0eb28e5..cca93dc8fe6300a5bee22029bbe2369e
|
||||
aTab.selected ||
|
||||
aTab.closing ||
|
||||
// Tabs that are sharing the screen, microphone or camera cannot be hidden.
|
||||
@@ -5727,6 +5816,9 @@
|
||||
@@ -5727,6 +5819,9 @@
|
||||
this.tabContainer.insertBefore(aTab, neighbor);
|
||||
}
|
||||
});
|
||||
@@ -287,7 +297,7 @@ index ff90a70bdad6c94ec4b90027ff102972d0eb28e5..cca93dc8fe6300a5bee22029bbe2369e
|
||||
}
|
||||
|
||||
moveTabToGroup(aTab, aGroup) {
|
||||
@@ -7443,6 +7535,7 @@
|
||||
@@ -7443,6 +7538,7 @@
|
||||
aWebProgress.isTopLevel
|
||||
) {
|
||||
this.mTab.setAttribute("busy", "true");
|
||||
@@ -295,7 +305,7 @@ index ff90a70bdad6c94ec4b90027ff102972d0eb28e5..cca93dc8fe6300a5bee22029bbe2369e
|
||||
gBrowser._tabAttrModified(this.mTab, ["busy"]);
|
||||
this.mTab._notselectedsinceload = !this.mTab.selected;
|
||||
gBrowser.syncThrobberAnimations(this.mTab);
|
||||
@@ -8411,7 +8504,7 @@ var TabContextMenu = {
|
||||
@@ -8411,7 +8507,7 @@ var TabContextMenu = {
|
||||
);
|
||||
contextUnpinSelectedTabs.hidden =
|
||||
!this.contextTab.pinned || !multiselectionContext;
|
||||
@@ -304,7 +314,7 @@ index ff90a70bdad6c94ec4b90027ff102972d0eb28e5..cca93dc8fe6300a5bee22029bbe2369e
|
||||
// Move Tab items
|
||||
let contextMoveTabOptions = document.getElementById(
|
||||
"context_moveTabOptions"
|
||||
@@ -8444,7 +8537,7 @@ var TabContextMenu = {
|
||||
@@ -8444,7 +8540,7 @@ var TabContextMenu = {
|
||||
let contextMoveTabToStart = document.getElementById("context_moveToStart");
|
||||
let isFirstTab =
|
||||
tabsToMove[0] == visibleTabs[0] ||
|
||||
@@ -313,7 +323,7 @@ index ff90a70bdad6c94ec4b90027ff102972d0eb28e5..cca93dc8fe6300a5bee22029bbe2369e
|
||||
contextMoveTabToStart.disabled = isFirstTab && allSelectedTabsAdjacent;
|
||||
|
||||
document.getElementById("context_openTabInWindow").disabled =
|
||||
@@ -8677,6 +8770,7 @@ var TabContextMenu = {
|
||||
@@ -8677,6 +8773,7 @@ var TabContextMenu = {
|
||||
if (this.contextTab.multiselected) {
|
||||
gBrowser.removeMultiSelectedTabs();
|
||||
} else {
|
||||
|
@@ -1 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" height="18" width="18" viewBox="0 0 18 18"><g stroke-linecap="round" stroke-width="1.5" fill="none" stroke="currentColor" stroke-linejoin="round" class="nc-icon-wrapper"><path d="M11.75,6.75h1c1.105,0,2,.895,2,2v5.5c0,1.105-.895,2-2,2H5.25c-1.105,0-2-.895-2-2v-5.5c0-1.105,.895-2,2-2h1"></path><polyline points="12 10.25 9 13.25 6 10.25" data-color="color-2"></polyline><line x1="9" y1="13.25" x2="9" y2="1.75" data-color="color-2"></line></g></svg>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" height="18" width="18" viewBox="0 0 18 18"><g stroke-linecap="round" stroke-width="1.5" fill="none" stroke="currentColor" stroke-linejoin="round" class="nc-icon-wrapper"><path d="M15.25,11.75v1.5c0,1.105-.895,2-2,2H4.75c-1.105,0-2-.895-2-2v-1.5"></path><polyline points="5.5 6.75 9 10.25 12.5 6.75" data-color="color-2"></polyline><line x1="9" y1="10.25" x2="9" y2="2.75" data-color="color-2"></line></g></svg>
|
||||
|
Before Width: | Height: | Size: 490 B After Width: | Height: | Size: 451 B |
@@ -1 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" height="18" width="18" viewBox="0 0 18 18"><g stroke-linecap="round" stroke-width="1.5" fill="none" stroke="currentColor" stroke-linejoin="round" class="nc-icon-wrapper"><path d="M3,13.071c1.304,1.919,3.505,3.179,6,3.179,4.004,0,7.25-3.246,7.25-7.25S13.004,1.75,9,1.75c-3.031,0-5.627,1.86-6.71,4.5" data-color="color-2"></path><polyline points="1.88 3.305 2.288 6.25 5.232 5.843"></polyline></g></svg>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" height="18" width="18" viewBox="0 0 18 18"><g stroke-linecap="round" stroke-width="1.5" fill="none" stroke="currentColor" stroke-linejoin="round" class="nc-icon-wrapper"><path d="M15,13.071c-1.304,1.919-3.505,3.179-6,3.179-4.004,0-7.25-3.246-7.25-7.25S4.996,1.75,9,1.75c3.031,0,5.627,1.86,6.71,4.5" data-color="color-2"></path><polyline points="16.12 3.305 15.712 6.25 12.768 5.843"></polyline></g></svg>
|
||||
|
Before Width: | Height: | Size: 442 B After Width: | Height: | Size: 445 B |
Reference in New Issue
Block a user