diff --git a/browser/components/tabbrowser/content/tabs.js b/browser/components/tabbrowser/content/tabs.js index 8aeb244ffca9f48661805f5b7d860b5896055562..ef532d6b5d311cab5bc573c2d0aae6ceab5c1dcf 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; }; @@ -362,7 +362,7 @@ // and we're not hitting the scroll buttons. if ( event.button != 0 || - event.target != this.arrowScrollbox || + event.target != document.getElementById("zen-browser-tabs-wrapper") || event.composedTarget.localName == "toolbarbutton" ) { return; @@ -411,6 +411,7 @@ // Reset the "ignored click" flag target._ignoredCloseButtonClicks = false; } + gZenUIManager.saveScrollbarState(); } /* Protects from close-tab-button errant doubleclick: @@ -659,7 +660,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.slice(0, gBrowser._numVisiblePinTabs); let tabsPerRow = 0; let position = 0; for (let pinnedTab of pinnedTabs) { @@ -859,6 +860,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 && @@ -972,6 +976,14 @@ this._tabDropIndicator.hidden = true; event.stopPropagation(); + if (draggedTab && dropEffect == "move") { + let moved = gZenPinnedTabManager.moveToAnotherTabContainerIfNecessary(event, draggedTab); + + if (moved) { + this._finishMoveTogetherSelectedTabs(draggedTab); + return; + } + } if (draggedTab && dropEffect == "copy") { // copy the dropped tab (wherever it's from) let newIndex = this._getDropIndex(event); @@ -1010,8 +1022,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 ); @@ -1090,7 +1102,7 @@ let postTransitionCleanup = () => { tab.removeAttribute("tabdrop-samewindow"); - this._finishAnimateTabMove(); + this._finishAnimateTabMove(true); if (dropIndex !== false) { gBrowser.moveTabTo(tab, dropIndex); if (!directionForward) { @@ -1100,7 +1112,7 @@ gBrowser.syncThrobberAnimations(tab); }; - if (gReduceMotion) { + if (gReduceMotion || true) { postTransitionCleanup(); } else { let onTransitionEnd = transitionendEvent => { @@ -1263,7 +1275,8 @@ if ( dt.mozUserCancelled || dt.dropEffect != "none" || - this._isCustomizing + this._isCustomizing || + draggedTab.pinned ) { delete draggedTab._dragData; return; @@ -1498,7 +1511,7 @@ if (this.#allTabs) { return this.#allTabs; } - let children = Array.from(this.arrowScrollbox.children); + let children = Array.from(ZenWorkspaces.tabboxChildren); // remove arrowScrollbox periphery element children.pop(); @@ -1512,14 +1525,24 @@ } 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 + this.#allTabs.splice(Math.min(i + 1, lastPinnedTabIdx), 0, glanceTab); + i++; + } + } return this.#allTabs; } get allGroups() { - let children = Array.from(this.arrowScrollbox.children); + let children = Array.from(ZenWorkspaces.tabboxChildren); return children.filter(node => node.tagName == "tab-group"); } @@ -1577,7 +1600,7 @@ let verticalPinnedTabsContainer = document.getElementById( "vertical-pinned-tabs-container" ); - let children = Array.from(this.arrowScrollbox.children); + let children = Array.from(ZenWorkspaces.tabboxChildren); let focusableItems = []; for (let child of children) { @@ -1593,6 +1616,7 @@ } this.#focusableItems = [ + ...document.getElementById("zen-essentials-container").children, ...verticalPinnedTabsContainer.children, ...focusableItems, ]; @@ -1617,8 +1641,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")) ); } @@ -1816,7 +1840,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 { @@ -1832,6 +1856,7 @@ this.arrowScrollbox.ensureElementIsVisible(selectedTab, aInstant); } + gZenCompactModeManager.flashSidebarIfNecessary(aInstant); selectedTab._notselectedsinceload = false; } @@ -1843,7 +1868,7 @@ return; } - let tabs = this.visibleTabs; + let tabs = this.visibleTabs.filter(tab => !tab.hasAttribute("zen-glance-tab")); if (!tabs.length) { return; } @@ -1879,7 +1904,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. @@ -1894,7 +1919,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"; @@ -1965,11 +1990,11 @@ ); let numPinned = gBrowser.pinnedTabCount; - if (gBrowser.pinnedTabCount !== verticalTabsContainer.children.length) { - let tabs = this.visibleTabs; + if (gBrowser.pinnedTabCount !== (verticalTabsContainer.children.length + 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.appendChild(tabs[i]); } } @@ -1992,8 +2017,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; @@ -2074,7 +2099,7 @@ return; } - let tabs = this.visibleTabs.slice(0, gBrowser.pinnedTabCount); + let tabs = this.visibleTabs.filter(tab => !tab.hasAttribute("zen-glance-tab")).slice(0, gBrowser._numVisiblePinTabs); let directionX = screenX > dragData.animLastScreenX; let directionY = screenY > dragData.animLastScreenY; @@ -2257,9 +2282,9 @@ } let pinned = draggedTab.pinned; - let numPinned = gBrowser.pinnedTabCount; - let tabs = this.visibleTabs.slice( - pinned ? 0 : numPinned, + let numPinned = gBrowser._numVisiblePinTabs; + let tabs = this.visibleTabs.filter(tab => !tab.hasAttribute("zen-glance-tab")).slice( + pinned ? gBrowser._numZenEssentials : numPinned, pinned ? numPinned : undefined ); @@ -2502,8 +2527,9 @@ ); } - _finishAnimateTabMove() { - if (!this.hasAttribute("movingtab")) { + _finishAnimateTabMove(always = false) { + gZenPinnedTabManager.removeTabContainersDragoverClass(); + if (!this.hasAttribute("movingtab") && !always) { return; } @@ -2668,9 +2694,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); } } @@ -2754,7 +2780,7 @@ } _notifyBackgroundTab(aTab) { - if (aTab.pinned || !aTab.visible || !this.overflowing) { + if (aTab.hasAttribute("zen-essential") || !aTab.visible || !this.overflowing) { return; } @@ -2772,12 +2798,14 @@ selectedTab = { left: selectedTab.left, right: selectedTab.right, + top: selectedTab.top, + bottom: selectedTab.bottom, }; } return [ this._lastTabToScrollIntoView, this.arrowScrollbox.scrollClientRect, - { left: lastTabRect.left, right: lastTabRect.right }, + lastTabRect, selectedTab, ]; }) @@ -2794,8 +2822,11 @@ delete this._lastTabToScrollIntoView; // Is the new tab already completely visible? if ( - scrollRect.left <= tabRect.left && - tabRect.right <= scrollRect.right + this.verticalMode + ? scrollRect.top <= tabRect.top && + tabRect.bottom <= scrollRect.bottom + : scrollRect.left <= tabRect.left && + tabRect.right <= scrollRect.right ) { return; } @@ -2803,21 +2834,29 @@ if (this.arrowScrollbox.smoothScroll) { // Can we make both the new tab and the selected tab completely visible? if ( - !selectedRect || - Math.max( - tabRect.right - selectedRect.left, - selectedRect.right - tabRect.left - ) <= scrollRect.width + !selectedRect || (this.verticalMode + ? Math.max( + tabRect.bottom - selectedRect.top, + selectedRect.bottom - tabRect.top + ) <= scrollRect.height + : Math.max( + tabRect.right - selectedRect.left, + selectedRect.right - tabRect.left + ) <= scrollRect.width) ) { this.arrowScrollbox.ensureElementIsVisible(tabToScrollIntoView); return; } - this.arrowScrollbox.scrollByPixels( - this.#rtlMode - ? selectedRect.right - scrollRect.right - : selectedRect.left - scrollRect.left - ); + let scrollPixels; + if (this.verticalMode) { + scrollPixels = tabRect.top - selectedRect.top; + } else if (this.#rtlMode) { + scrollPixels = selectedRect.right - scrollRect.right; + } else { + scrollPixels = selectedRect.left - scrollRect.left; + } + this.arrowScrollbox.scrollByPixels(scrollPixels); } if (!this._animateElement.hasAttribute("highlight")) {