diff --git a/browser/components/tabbrowser/content/tabs.js b/browser/components/tabbrowser/content/tabs.js index fa96568d366fd3608f9bd583fa793150bd815c8b..5e25d78b04675fbb736192fb0bbcbf6067cbc257 100644 --- a/browser/components/tabbrowser/content/tabs.js +++ b/browser/components/tabbrowser/content/tabs.js @@ -94,7 +94,7 @@ }; this.arrowScrollbox._canScrollToElement = element => { if (isTab(element)) { - return !element.pinned || !this.hasAttribute("positionpinnedtabs"); + return !element.hasAttribute("zen-essential") || !this.hasAttribute("positionpinnedtabs"); } return true; }; @@ -339,7 +339,7 @@ // and we're not hitting the scroll buttons. if ( event.button != 0 || - event.target != this.arrowScrollbox || + event.target != document.getElementById("zen-tabs-wrapper") || event.composedTarget.localName == "toolbarbutton" ) { return; @@ -388,6 +388,7 @@ // Reset the "ignored click" flag target._ignoredCloseButtonClicks = false; } + gZenUIManager.saveScrollbarState(); } /* Protects from close-tab-button errant doubleclick: @@ -683,7 +684,7 @@ if (this.#isContainerVerticalPinnedExpanded(tab)) { // In expanded vertical mode, the max number of pinned tabs per row is dynamic // Set this before adjusting dragged tab's position - let pinnedTabs = this.visibleTabs.slice(0, gBrowser.pinnedTabCount); + let pinnedTabs = this.visibleTabs.filter(tab => !tab.hasAttribute("zen-glance-tab")).slice(0, gBrowser._numZenVisibleEssentials); let tabsPerRow = 0; let position = 0; for (let pinnedTab of pinnedTabs) { @@ -883,6 +884,9 @@ } let draggedTab = event.dataTransfer.mozGetDataAt(TAB_DROP_TYPE, 0); + if (draggedTab && effects === "move") { + gZenPinnedTabManager.applyDragoverClass(event, draggedTab); + } if ( (effects == "move" || effects == "copy") && this == draggedTab.container && @@ -996,6 +1000,14 @@ this._tabDropIndicator.hidden = true; event.stopPropagation(); + if (draggedTab && dropEffect == "move") { + let moved = gZenPinnedTabManager.moveToAnotherTabContainerIfNecessary(event, movingTabs); + + if (moved) { + this._finishMoveTogetherSelectedTabs(draggedTab); + return; + } + } if (draggedTab && dropEffect == "copy") { // copy the dropped tab (wherever it's from) let newIndex = this._getDropIndex(event); @@ -1034,8 +1046,8 @@ } } else { let pinned = draggedTab.pinned; - let numPinned = gBrowser.pinnedTabCount; - let tabs = this.visibleTabs.slice( + let numPinned = gBrowser._numVisiblePinTabs; + let tabs = this.visibleTabs.filter(tab => !tab.hasAttribute("zen-glance-tab")).slice( pinned ? 0 : numPinned, pinned ? numPinned : undefined ); @@ -1114,7 +1126,7 @@ let postTransitionCleanup = () => { tab.removeAttribute("tabdrop-samewindow"); - this._finishAnimateTabMove(); + this._finishAnimateTabMove(true); if (dropIndex !== false) { gBrowser.moveTabTo(tab, dropIndex); if (!directionForward) { @@ -1122,7 +1134,7 @@ } } }; - if (gReduceMotion) { + if (true || gReduceMotion) { postTransitionCleanup(); } else { let onTransitionEnd = transitionendEvent => { @@ -1279,13 +1291,23 @@ return; } - this._finishMoveTogetherSelectedTabs(draggedTab); this._finishAnimateTabMove(); + if (event.ctrlKey && !dt.mozUserCancelled && dt.dropEffect == "none" && !this._isCustomizing) { + const moved = gZenViewSplitter.moveTabToSplitView(event, draggedTab); + if (moved) { + delete draggedTab._dragData; + return; + } + } + + this._finishMoveTogetherSelectedTabs(draggedTab); + if ( dt.mozUserCancelled || dt.dropEffect != "none" || - this._isCustomizing + this._isCustomizing || + draggedTab.pinned ) { delete draggedTab._dragData; return; @@ -1517,7 +1539,7 @@ } get newTabButton() { - return this.querySelector("#tabs-newtab-button"); + return ZenWorkspaces.activeWorkspaceStrip.querySelector("#tabs-newtab-button"); } get verticalMode() { @@ -1537,7 +1559,7 @@ if (this.#allTabs) { return this.#allTabs; } - let children = Array.from(this.arrowScrollbox.children); + let children = ZenWorkspaces.tabboxChildren; // remove arrowScrollbox periphery element children.pop(); @@ -1551,14 +1573,29 @@ } this.#allTabs = [ - ...this.verticalPinnedTabsContainer.children, + ...document.getElementById("zen-essentials-container").children, ...this.verticalPinnedTabsContainer.children, ...children, ]; + const lastPinnedTabIdx = gBrowser.pinnedTabCount; + for (let i = 0; i < this.#allTabs.length; i++) { + // add glance tabs (tabs inside tabs) to the list + const glanceTab = this.#allTabs[i].querySelector("tab[zen-glance-tab]"); + if (glanceTab) { + // insert right after the parent tab. note: it must be inserted before + // the last pinned tab so it can be inserted in the correct order + this.#allTabs.splice(Math.min(i + 1, lastPinnedTabIdx), 0, glanceTab); + i++; + } else if (this.#allTabs[i].classList.contains("vertical-pinned-tabs-container-separator")) { + // remove the separator from the list + this.#allTabs.splice(i, 1); + i--; + } + } return this.#allTabs; } get allGroups() { - let children = Array.from(this.arrowScrollbox.children); + let children = ZenWorkspaces.tabboxChildren; return children.filter(node => node.tagName == "tab-group"); } @@ -1579,7 +1616,7 @@ */ get visibleTabs() { if (!this.#visibleTabs) { - this.#visibleTabs = this.openTabs.filter(tab => tab.visible); + this.#visibleTabs = this.openTabs.filter(tab => tab.visible && !tab.hasAttribute("zen-empty-tab")); } return this.#visibleTabs; } @@ -1613,10 +1650,8 @@ return this.#focusableItems; } - let verticalPinnedTabsContainer = document.getElementById( - "vertical-pinned-tabs-container" - ); - let children = Array.from(this.arrowScrollbox.children); + let verticalPinnedTabsContainer = this.verticalPinnedTabsContainer; + let children = ZenWorkspaces.tabboxChildrenWithoutEmpty; let focusableItems = []; for (let child of children) { @@ -1632,6 +1667,7 @@ } this.#focusableItems = [ + ...document.getElementById("zen-essentials-container").children, ...verticalPinnedTabsContainer.children, ...focusableItems, ]; @@ -1642,6 +1678,7 @@ _invalidateCachedTabs() { this.#allTabs = null; this._invalidateCachedVisibleTabs(); + ZenWorkspaces._allStoredTabs = null; } _invalidateCachedVisibleTabs() { @@ -1656,8 +1693,8 @@ #isContainerVerticalPinnedExpanded(tab) { return ( this.verticalMode && - tab.hasAttribute("pinned") && - this.hasAttribute("expanded") + (tab.hasAttribute("zen-essential")) && + (this.hasAttribute("expanded") || document.documentElement.hasAttribute("zen-sidebar-expanded")) ); } @@ -1672,7 +1709,7 @@ if (node == null) { // We have a container for non-tab elements at the end of the scrollbox. - node = this.arrowScrollbox.lastChild; + node = ZenWorkspaces.activeWorkspaceStrip.lastChild; } node.before(tab); @@ -1772,7 +1809,7 @@ // There are separate "new tab" buttons for horizontal tabs toolbar, vertical tabs and // for when the tab strip is overflowed (which is shared by vertical and horizontal tabs); // Attach the long click popup to all of them. - const newTab = document.getElementById("new-tab-button"); + const newTab = ZenWorkspaces.activeWorkspaceStrip.querySelector("#tabs-newtab-button"); const newTab2 = this.newTabButton; const newTabVertical = document.getElementById( "vertical-tabs-newtab-button" @@ -1855,7 +1892,7 @@ let rect = ele => { return window.windowUtils.getBoundsWithoutFlushing(ele); }; - let tab = this.visibleTabs[gBrowser.pinnedTabCount]; + let tab = this.visibleTabs[gBrowser._numVisiblePinTabs]; if (tab && rect(tab).width <= this._tabClipWidth) { this.setAttribute("closebuttons", "activetab"); } else { @@ -1867,10 +1904,12 @@ _handleTabSelect(aInstant) { let selectedTab = this.selectedItem; + if (!selectedTab) return; if (this.overflowing) { this.arrowScrollbox.ensureElementIsVisible(selectedTab, aInstant); } + gZenCompactModeManager.flashSidebarIfNecessary(aInstant); selectedTab._notselectedsinceload = false; } @@ -1882,7 +1921,7 @@ return; } - let tabs = this.visibleTabs; + let tabs = this.visibleTabs.filter(tab => !tab.hasAttribute("zen-glance-tab")); if (!tabs.length) { return; } @@ -1918,7 +1957,7 @@ if (isEndTab && !this._hasTabTempMaxWidth) { return; } - let numPinned = gBrowser.pinnedTabCount; + let numPinned = gBrowser._numVisiblePinTabs; // Force tabs to stay the same width, unless we're closing the last tab, // which case we need to let them expand just enough so that the overall // tabbar width is the same. @@ -1933,7 +1972,7 @@ let tabsToReset = []; for (let i = numPinned; i < tabs.length; i++) { let tab = tabs[i]; - tab.style.setProperty("max-width", aTabWidth, "important"); + //tab.style.setProperty("max-width", aTabWidth, "important"); if (!isEndTab) { // keep tabs the same width tab.style.transition = "none"; @@ -1999,16 +2038,15 @@ // Move pinned tabs to another container when the tabstrip is toggled to vertical // and when session restore code calls _positionPinnedTabs; update styling whenever // the number of pinned tabs changes. - let verticalTabsContainer = document.getElementById( - "vertical-pinned-tabs-container" - ); + let verticalTabsContainer = this.verticalPinnedTabsContainer; let numPinned = gBrowser.pinnedTabCount; - - if (gBrowser.pinnedTabCount !== verticalTabsContainer.children.length) { - let tabs = this.visibleTabs; + if (!ZenWorkspaces._hasInitializedTabsStrip) return; + let count = ZenWorkspaces.makeSurePinTabIsInCorrectPosition(); + if (gBrowser.pinnedTabCount !== (verticalTabsContainer.children.length - count - 1 + document.getElementById("zen-essentials-container").children.length)) { + let tabs = this.allTabs.filter(tab => !tab.hasAttribute("zen-glance-tab")); for (let i = 0; i < numPinned; i++) { tabs[i].style.marginInlineStart = ""; - verticalTabsContainer.appendChild(tabs[i]); + tabs[i].hasAttribute("zen-essential") ? document.getElementById("zen-essentials-container").appendChild(tabs[i]) : verticalTabsContainer.insertBefore(tabs[i], verticalTabsContainer.lastChild); } } @@ -2016,9 +2054,7 @@ } _resetVerticalPinnedTabs() { - let verticalTabsContainer = document.getElementById( - "vertical-pinned-tabs-container" - ); + let verticalTabsContainer = this.verticalPinnedTabsContainer; if (!verticalTabsContainer.children.length) { return; @@ -2031,8 +2067,8 @@ } _positionPinnedTabs() { - let tabs = this.visibleTabs; - let numPinned = gBrowser.pinnedTabCount; + let tabs = this.visibleTabs.filter(tab => !tab.hasAttribute("zen-glance-tab")); + let numPinned = gBrowser._numVisiblePinTabs; let absPositionHorizontalTabs = this.overflowing && tabs.length > numPinned && numPinned > 0; @@ -2042,6 +2078,7 @@ if (this.verticalMode) { this._updateVerticalPinnedTabs(); } else if (absPositionHorizontalTabs) { + return; let layoutData = this._pinnedTabsLayoutCache; let uiDensity = document.documentElement.getAttribute("uidensity"); if (!layoutData || layoutData.uiDensity != uiDensity) { @@ -2113,7 +2150,7 @@ return; } - let tabs = this.visibleTabs.slice(0, gBrowser.pinnedTabCount); + let tabs = this.visibleTabs.filter(tab => !tab.hasAttribute("zen-glance-tab")).slice(0, gBrowser._numZenVisibleEssentials); let directionX = screenX > dragData.animLastScreenX; let directionY = screenY > dragData.animLastScreenY; @@ -2296,10 +2333,11 @@ } let pinned = draggedTab.pinned; - let numPinned = gBrowser.pinnedTabCount; - let tabs = this.visibleTabs.slice( - pinned ? 0 : numPinned, - pinned ? numPinned : undefined + let numPinned = gBrowser._numVisiblePinTabs; + let essential = draggedTab.hasAttribute("zen-essential"); + let tabs = this.visibleTabs.filter(tab => !tab.hasAttribute("zen-glance-tab")).slice( + pinned ? (essential ? 0 : gBrowser._numZenVisibleEssentials) : numPinned, + pinned ? (essential ? gBrowser._numZenVisibleEssentials : ((numPinned - gBrowser._numZenVisibleEssentials) + 1)) : undefined ); if (this.#rtlMode) { @@ -2347,8 +2385,12 @@ (lastMovingTabScreen + tabSize); translate = Math.min(Math.max(translate, firstBound), lastBound); - for (let tab of movingTabs) { - tab.style.transform = `${translateAxis}(${translate}px)`; + if (draggedTab.group?.hasAttribute("split-view-group")) { + draggedTab.group.style.transform = `${translateAxis}(${translate}px)`; + } else { + for (let tab of movingTabs) { + tab.style.transform = `${translateAxis}(${translate}px)`; + } } dragData.translatePos = translate; @@ -2541,8 +2583,9 @@ ); } - _finishAnimateTabMove() { - if (!this.hasAttribute("movingtab")) { + _finishAnimateTabMove(always = false) { + gZenPinnedTabManager.removeTabContainersDragoverClass(); + if (!this.hasAttribute("movingtab") && !always) { return; } @@ -2553,6 +2596,7 @@ tab.style.transform = ""; if (tab.group) { tab.group.style.removeProperty("--tabgroup-dragover-transform"); + tab.group.style.transform = ""; } tab.removeAttribute("dragover-createGroup"); } @@ -2604,7 +2648,7 @@ movingTab._moveTogetherSelectedTabsData.newIndex = movingTabNewIndex; movingTab._moveTogetherSelectedTabsData.animate = false; }; - if (gReduceMotion) { + if (true || gReduceMotion) { postTransitionCleanup(); } else { let onTransitionEnd = transitionendEvent => { @@ -2707,9 +2751,9 @@ function newIndex(aTab, index) { // Don't allow mixing pinned and unpinned tabs. if (aTab.pinned) { - return Math.min(index, gBrowser.pinnedTabCount - 1); + return Math.min(index, gBrowser._numVisiblePinTabs - 1); } - return Math.max(index, gBrowser.pinnedTabCount); + return Math.max(index, gBrowser._numVisiblePinTabs); } } @@ -2793,7 +2837,7 @@ } _notifyBackgroundTab(aTab) { - if (aTab.pinned || !aTab.visible || !this.overflowing) { + if (aTab.hasAttribute("zen-essential") || !aTab.visible || !this.overflowing) { return; }