diff --git a/browser/components/tabbrowser/content/tabs.js b/browser/components/tabbrowser/content/tabs.js index c7557dad38db9ef02b981c46de9595df77cb67db..f45ecacd23179f06a436d5f3d372b536322388ea 100644 --- a/browser/components/tabbrowser/content/tabs.js +++ b/browser/components/tabbrowser/content/tabs.js @@ -44,6 +44,9 @@ * @returns {MozTabbrowserTab|vbox} */ const elementToMove = element => { + if (element.group?.hasAttribute("split-view-group")) { + return element.group; + } if (isTab(element)) { return element; } @@ -411,7 +414,7 @@ // and we're not hitting the scroll buttons. if ( event.button != 0 || - event.target != this.arrowScrollbox || + !event.target.classList.contains("zen-workspace-empty-space") || event.composedTarget.localName == "toolbarbutton" ) { return; @@ -492,7 +495,6 @@ }); } } else if (isTabGroupLabel(event.target)) { - event.target.group.saveAndClose(); } else if ( event.originalTarget.closest("scrollbox") && !Services.prefs.getBoolPref( @@ -528,6 +530,9 @@ } on_keydown(event) { + if (document.documentElement.getAttribute('zen-renaming-tab') === 'true') { + return; + } let { altKey, shiftKey } = event; let [accel, nonAccel] = AppConstants.platform == "macosx" @@ -765,7 +770,7 @@ if (this.#isContainerVerticalPinnedGrid(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.ariaFocusableItems.slice(0, gBrowser._numZenEssentials); let tabsPerRow = 0; let position = RTL_UI ? window.windowUtils.getBoundsWithoutFlushing( @@ -930,7 +935,7 @@ let dropEffect = this.getDropEffectForTabDrag(event); let isMovingInTabStrip = !fromTabList && dropEffect == "move"; let collapseTabGroupDuringDrag = - isMovingInTabStrip && isTabGroupLabel(tab) && !tab.group.collapsed; + isMovingInTabStrip && isTabGroupLabel(tab) && (!tab.group.collapsed || tab.group.hasAttribute("has-active")); tab._dragData = { offsetX: this.verticalMode @@ -940,7 +945,7 @@ ? event.screenY - window.screenY - tabOffset : event.screenY - window.screenY, scrollPos: - this.verticalMode && tab.pinned + this.verticalMode && tab.pinned && false ? this.pinnedTabsContainer.scrollPosition : this.arrowScrollbox.scrollPosition, screenX: event.screenX, @@ -969,6 +974,7 @@ if (collapseTabGroupDuringDrag) { tab.group.collapsed = true; + gZenFolders.collapseVisibleTab(tab.group); } } } @@ -1015,6 +1021,10 @@ } let draggedTab = event.dataTransfer.mozGetDataAt(TAB_DROP_TYPE, 0); + if (draggedTab && dropEffect === "move") { + gZenPinnedTabManager.applyDragoverClass(event, draggedTab); + gZenViewSplitter.onBrowserDragEndToSplit(event); + } if ( (dropEffect == "move" || dropEffect == "copy") && document == draggedTab.ownerDocument && @@ -1196,6 +1206,18 @@ this._tabDropIndicator.hidden = true; event.stopPropagation(); + if (draggedTab?.hasAttribute("zen-has-splitted")) { + draggedTab.removeAttribute("zen-has-splitted"); + draggedTab._visuallySelected = false; + } + if (draggedTab && dropEffect == "move") { + let moved = gZenPinnedTabManager.moveToAnotherTabContainerIfNecessary(event, movingTabs); + + if (moved) { + this.finishMoveTogetherSelectedTabs(draggedTab); + return; + } + } if (draggedTab && dropEffect == "copy") { let duplicatedDraggedTab; let duplicatedTabs = []; @@ -1220,8 +1242,9 @@ let translateOffsetY = oldTranslateY % tabHeight; let newTranslateX = oldTranslateX - translateOffsetX; let newTranslateY = oldTranslateY - translateOffsetY; - let isPinned = draggedTab.pinned; - let numPinned = gBrowser.pinnedTabCount; + let isPinned = draggedTab?.group ? draggedTab.group.pinned : draggedTab.pinned; + let numPinned = gBrowser._numVisiblePinTabsWithoutCollapsed; + let essential = draggedTab.hasAttribute("zen-essential"); if (this.#isContainerVerticalPinnedGrid(draggedTab)) { // Update both translate axis for pinned vertical expanded tabs @@ -1237,8 +1260,8 @@ } } else { let tabs = this.ariaFocusableItems.slice( - isPinned ? 0 : numPinned, - isPinned ? numPinned : undefined + isPinned ? (essential ? 0 : gBrowser._numZenEssentials) : numPinned, + isPinned ? (essential ? gBrowser._numZenEssentials : numPinned) : undefined ); let size = this.verticalMode ? "height" : "width"; let screenAxis = this.verticalMode ? "screenY" : "screenX"; @@ -1287,11 +1310,13 @@ this.dragToPinPromoCard, ]; let shouldPin = + false && isTab(draggedTab) && !draggedTab.pinned && (overPinnedDropIndicator || dragToPinTargets.some(el => el.contains(event.target))); let shouldUnpin = + false && isTab(draggedTab) && draggedTab.pinned && this.arrowScrollbox.contains(event.target); @@ -1309,6 +1334,7 @@ (oldTranslateY && oldTranslateY != newTranslateY); } else if (this.verticalMode) { shouldTranslate &&= oldTranslateY && oldTranslateY != newTranslateY; + shouldTranslate = false; } else { shouldTranslate &&= oldTranslateX && oldTranslateX != newTranslateX; } @@ -1503,6 +1529,7 @@ let nextItem = this.ariaFocusableItems[newIndex]; let tabGroup = isTab(nextItem) && nextItem.group; + if (gZenViewSplitter.handleTabDrop(event, urls, replace, inBackground)) return; gBrowser.loadTabs(urls, { inBackground, replace, @@ -1541,6 +1568,17 @@ } this.#resetTabsAfterDrop(draggedTab.ownerDocument); + if (!dt.mozUserCancelled && dt.dropEffect == "none" && !this._isCustomizing) { + const moved = gZenViewSplitter.moveTabToSplitView(event, draggedTab); + if (moved) { + delete draggedTab._dragData; + return; + } + } else if (dt.mozUserCancelled) { + gZenViewSplitter.onBrowserDragEndToSplit(event, true); + if (gZenViewSplitter._lastOpenedTab) gZenViewSplitter._lastOpenedTab._visuallySelected = false; + } + if ( dt.mozUserCancelled || dt.dropEffect != "none" || @@ -1707,7 +1745,6 @@ this.toggleAttribute("overflow", true); this._updateCloseButtons(); - this._handleTabSelect(true); document .getElementById("tab-preview-panel") @@ -1765,7 +1802,7 @@ } get newTabButton() { - return this.querySelector("#tabs-newtab-button"); + return gZenWorkspaces.activeWorkspaceStrip.querySelector("#tabs-newtab-button"); } get verticalMode() { @@ -1781,6 +1818,7 @@ } get overflowing() { + gZenWorkspaces.updateOverflowingTabs(); return this.hasAttribute("overflow"); } @@ -1789,31 +1827,51 @@ if (this.#allTabs) { return this.#allTabs; } - // Remove temporary periphery element added at drag start. - let pinnedChildren = Array.from(this.pinnedTabsContainer.children); - if (pinnedChildren?.at(-1)?.id == "pinned-tabs-container-periphery") { - pinnedChildren.pop(); - } - let unpinnedChildren = Array.from(this.arrowScrollbox.children); - // remove arrowScrollbox periphery element. - unpinnedChildren.pop(); - + let children = gZenWorkspaces.tabboxChildren; + children.pop(); // explode tab groups // Iterate backwards over the array to preserve indices while we modify // things in place - for (let i = unpinnedChildren.length - 1; i >= 0; i--) { - if (unpinnedChildren[i].tagName == "tab-group") { - unpinnedChildren.splice(i, 1, ...unpinnedChildren[i].tabs); + const pinnedTabs = [...gZenWorkspaces.getCurrentEssentialsContainer().children, ...this.pinnedTabsContainer.children]; + const expandTabs = (tabs) => { + for (let i = tabs.length - 1; i >= 0; i--) { + const tab = tabs[i]; + if (isTabGroup(tab)) { + // remove the group from the list + tabs.splice(i, 1); + // add the tabs in the group to the list + tabs.splice(i, 0, ...tab.tabs); + } } } - - this.#allTabs = [...pinnedChildren, ...unpinnedChildren]; + expandTabs(pinnedTabs); + expandTabs(children); + const allTabs = [ + ...pinnedTabs, + ...children, + ]; + const lastPinnedTabIdx = pinnedTabs.length - 1; + let i = 0; + for (const tab of [...allTabs]) { + // add glance tabs (tabs inside tabs) to the list + const glanceTab = tab.glanceTab; + 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 + allTabs.splice(Math.max(i++ + 1, lastPinnedTabIdx), 0, glanceTab); + } else if (tab.classList.contains("pinned-tabs-container-separator")) { + // remove the separator from the list + allTabs.splice(i, 1); + i--; + } + i++; + } + this.#allTabs = allTabs; return this.#allTabs; } get allGroups() { - let children = Array.from(this.arrowScrollbox.children); - return children.filter(node => node.tagName == "tab-group"); + return gZenWorkspaces.allTabGroups; } /** @@ -1880,29 +1938,23 @@ let elementIndex = 0; - let unpinnedChildren = Array.from(this.arrowScrollbox.children); - let pinnedChildren = Array.from(this.pinnedTabsContainer.children); + let children = gZenWorkspaces.tabboxChildrenWithoutEmpty; let focusableItems = []; - for (let child of pinnedChildren) { - if (isTab(child)) { - child.elementIndex = elementIndex++; - focusableItems.push(child); - } - } - for (let child of unpinnedChildren) { + for (let child of [...gZenWorkspaces.getCurrentEssentialsContainer().children, ...this.pinnedTabsContainer.children, ...children]) { if (isTab(child) && child.visible) { child.elementIndex = elementIndex++; focusableItems.push(child); } else if (isTabGroup(child)) { child.labelElement.elementIndex = elementIndex++; focusableItems.push(child.labelElement); - - let visibleTabsInGroup = child.tabs.filter(tab => tab.visible); - visibleTabsInGroup.forEach(tab => { - tab.elementIndex = elementIndex++; - }); - focusableItems.push(...visibleTabsInGroup); + if (!child.hasAttribute("split-view-group")) { + let visibleTabsInGroup = child.childGroupsAndTabs.filter(tab => tab.visible); + visibleTabsInGroup.forEach(tab => { + tab.elementIndex = elementIndex++; + }); + focusableItems.push(...visibleTabsInGroup); + } } } @@ -1914,6 +1966,7 @@ _invalidateCachedTabs() { this.#allTabs = null; this._invalidateCachedVisibleTabs(); + gZenWorkspaces._allStoredTabs = null; } _invalidateCachedVisibleTabs() { @@ -1929,8 +1982,8 @@ #isContainerVerticalPinnedGrid(tab) { return ( this.verticalMode && - tab.pinned && - this.hasAttribute("expanded") && + (tab.hasAttribute("zen-essential")) && + (this.hasAttribute("expanded") || document.documentElement.hasAttribute("zen-sidebar-expanded")) && !this.expandOnHover ); } @@ -1946,7 +1999,7 @@ if (node == null) { // We have a container for non-tab elements at the end of the scrollbox. - node = this.arrowScrollbox.lastChild; + node = gZenWorkspaces.activeWorkspaceStrip.lastChild; } node.before(tab); @@ -2041,7 +2094,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 = gZenWorkspaces.activeWorkspaceStrip.querySelector("#tabs-newtab-button"); const newTab2 = this.newTabButton; const newTabVertical = document.getElementById( "vertical-tabs-newtab-button" @@ -2139,8 +2192,10 @@ */ _handleTabSelect(aInstant) { let selectedTab = this.selectedItem; + if (!selectedTab) return; this.#ensureTabIsVisible(selectedTab, aInstant); + gZenCompactModeManager.flashSidebarIfNecessary(aInstant); selectedTab._notselectedsinceload = false; } @@ -2149,7 +2204,7 @@ * @param {boolean} [shouldScrollInstantly=false] */ #ensureTabIsVisible(tab, shouldScrollInstantly = false) { - let arrowScrollbox = tab.closest("arrowscrollbox"); + let arrowScrollbox = this.arrowScrollbox; if (arrowScrollbox.overflowing) { arrowScrollbox.ensureElementIsVisible(tab, shouldScrollInstantly); } @@ -2288,6 +2343,16 @@ when the tab is first selected to be dragged. */ #updateTabStylesOnDrag(tab) { + let { movingTabs: zenMovingTabs } = tab._dragData; + for (let movingTab of zenMovingTabs.slice(zenMovingTabs.findIndex(t => t._tPos == tab._tPos))) { + if (isTabGroupLabel(tab)) { + movingTab = movingTab.parentElement; + } + // "dragtarget" contains the following rules which must only be set AFTER the above + // elements have been adjusted. {z-index: 3 !important, position: absolute !important} + movingTab.setAttribute("zen-dragtarget", ""); + } + return; let isPinned = tab.pinned; let numPinned = gBrowser.pinnedTabCount; let allTabs = this.ariaFocusableItems; @@ -2540,7 +2605,7 @@ return; } - let tabs = this.visibleTabs.slice(0, gBrowser.pinnedTabCount); + let tabs = this.ariaFocusableItems.slice(0, gBrowser._numZenEssentials); let directionX = screenX > dragData.animLastScreenX; let directionY = screenY > dragData.animLastScreenY; @@ -2549,6 +2614,8 @@ let { width: tabWidth, height: tabHeight } = draggedTab.getBoundingClientRect(); + tabWidth += 4; // Add 4px to account for the gap + tabHeight += 4; let shiftSizeX = tabWidth * movingTabs.length; let shiftSizeY = tabHeight; dragData.tabWidth = tabWidth; @@ -2585,8 +2652,8 @@ let lastBoundX = lastTabInRow.screenX + lastTabInRow.getBoundingClientRect().width - - (lastMovingTabScreenX + tabWidth); - let lastBoundY = periphery.screenY - (lastMovingTabScreenY + tabHeight); + (lastMovingTabScreenX + tabWidth) + 4; + let lastBoundY = lastTab.screenY - lastMovingTabScreenY; translateX = Math.min(Math.max(translateX, firstBoundX), lastBoundX); translateY = Math.min(Math.max(translateY, firstBoundY), lastBoundY); @@ -2743,13 +2810,18 @@ this.#clearDragOverGroupingTimer(); - let isPinned = draggedTab.pinned; - let numPinned = gBrowser.pinnedTabCount; + let isPinned = draggedTab?.group ? draggedTab.group.pinned : draggedTab.pinned; + let numPinned = gBrowser._numVisiblePinTabsWithoutCollapsed; + let essential = draggedTab.hasAttribute("zen-essential"); + const isDraggingFolder = isTabGroupLabel(draggedTab) && draggedTab.group?.isZenFolder; let allTabs = this.ariaFocusableItems; let tabs = allTabs.slice( - isPinned ? 0 : numPinned, - isPinned ? numPinned : undefined + (isPinned && essential) ? 0 : gBrowser._numZenEssentials, + isPinned ? (essential ? gBrowser._numZenEssentials : (isDraggingFolder ? numPinned : undefined)) : undefined ); + if (draggedTab.group?.hasAttribute("split-view-group")) { + draggedTab = draggedTab.group.labelElement; + } if (this.#rtlMode) { tabs.reverse(); @@ -2760,7 +2832,7 @@ let screenAxis = this.verticalMode ? "screenY" : "screenX"; let size = this.verticalMode ? "height" : "width"; let translateAxis = this.verticalMode ? "translateY" : "translateX"; - let { width: tabWidth, height: tabHeight } = bounds(draggedTab); + let { width: tabWidth, height: tabHeight } = bounds(draggedTab.group?.hasAttribute("split-view-group") ? draggedTab.group : draggedTab); let tabSize = this.verticalMode ? tabHeight : tabWidth; let translateX = event.screenX - dragData.screenX; let translateY = event.screenY - dragData.screenY; @@ -2776,6 +2848,12 @@ ); let lastMovingTab = movingTabs.at(-1); let firstMovingTab = movingTabs[0]; + if (lastMovingTab.group?.hasAttribute("split-view-group")) { + lastMovingTab = lastMovingTab.group; + } + if (firstMovingTab.group?.hasAttribute("split-view-group")) { + firstMovingTab = firstMovingTab.group; + } let endEdge = ele => ele[screenAxis] + bounds(ele)[size]; let lastMovingTabScreen = endEdge(lastMovingTab); let firstMovingTabScreen = firstMovingTab[screenAxis]; @@ -2790,6 +2868,11 @@ let endBound = this.#rtlMode ? endEdge(this) - lastMovingTabScreen : periphery[screenAxis] - 1 - lastMovingTabScreen; + let firstTab = tabs.at(this.#rtlMode ? -1 : 0); + let lastTab = tabs.at(this.#rtlMode ? 0 : -1); + startBound = firstTab[screenAxis] - firstMovingTabScreen; + endBound = endEdge(lastTab) - lastMovingTabScreen; + endBound = gZenPinnedTabManager.getLastTabBound(endBound, lastTab, isDraggingFolder); translate = Math.min(Math.max(translate, startBound), endBound); // Center the tab under the cursor if the tab is not under the cursor while dragging @@ -2979,6 +3062,8 @@ }; let dropElement = getOverlappedElement(); + if (dropElement?.hasAttribute("split-view-group")) dropElement = dropElement.labelElement; + gZenPinnedTabManager.animateSeparatorMove(movingTabs, dropElement, isPinned, event); let newDropElementIndex; if (dropElement) { @@ -3060,7 +3145,7 @@ ? Services.prefs.getIntPref( "browser.tabs.dragDrop.moveOverThresholdPercent" ) / 100 - : 0.5; + : Services.prefs.getIntPref('zen.view.drag-and-drop.move-over-threshold') / 100; moveOverThreshold = Math.min(1, Math.max(0, moveOverThreshold)); let shouldMoveOver = overlapPercent > moveOverThreshold; if (logicalForward && shouldMoveOver) { @@ -3093,6 +3178,7 @@ // If dragging a group over another group, don't make it look like it is // possible to drop the dragged group inside the other group. if ( + false && isTabGroupLabel(draggedTab) && dropElement?.group && (!dropElement.group.collapsed || @@ -3119,20 +3205,13 @@ let isOutOfBounds = isPinned ? dropElement.elementIndex >= numPinned : dropElement.elementIndex < numPinned; - if (isOutOfBounds) { - // Drop after last pinned tab - dropElement = this.ariaFocusableItems[numPinned - 1]; - dropBefore = false; - } } - if ( - gBrowser._tabGroupsEnabled && - isTab(draggedTab) && - !isPinned && - (!numPinned || newDropElementIndex > numPinned) - ) { + if (isTab(draggedTab) || isTabGroupLabel(draggedTab)) { let dragOverGroupingThreshold = 1 - moveOverThreshold; + if (draggedTab && !dropElement?.group) { + gZenFolders.highlightGroupOnDragOver(null); + } let groupingDelay = Services.prefs.getIntPref( "browser.tabs.dragDrop.createGroup.delayMS" ); @@ -3140,6 +3219,7 @@ // When dragging tab(s) over an ungrouped tab, signal to the user // that dropping the tab(s) will create a new tab group. let shouldCreateGroupOnDrop = + false && !movingTabsSet.has(dropElement) && isTab(dropElement) && !dropElement?.group && @@ -3148,6 +3228,7 @@ // When dragging tab(s) over a collapsed tab group label, signal to the // user that dropping the tab(s) will add them to the group. let shouldDropIntoCollapsedTabGroup = + false && isTabGroupLabel(dropElement) && dropElement.group.collapsed && overlapPercent > dragOverGroupingThreshold; @@ -3192,19 +3273,14 @@ dropElement = dropElementGroup; colorCode = undefined; } else if (isTabGroupLabel(dropElement)) { - if (dropBefore) { - // Dropping right before the tab group. - dropElement = dropElementGroup; - colorCode = undefined; - } else if (dropElementGroup.collapsed) { - // Dropping right after the collapsed tab group. - dropElement = dropElementGroup; - colorCode = undefined; - } else { - // Dropping right before the first tab in the tab group. - dropElement = dropElementGroup.tabs[0]; - dropBefore = true; - } + ({ dropElement, colorCode, dropBefore } = gZenFolders.handleDragOverTabGroupLabel( + dropElement, + draggedTab, + overlapPercent, + movingTabs, + dropBefore, + colorCode + )); } this.#setDragOverGroupColor(colorCode); this.toggleAttribute("movingtab-addToGroup", colorCode); @@ -3223,11 +3299,11 @@ dragData.dropElement = dropElement; dragData.dropBefore = dropBefore; dragData.animDropElementIndex = newDropElementIndex; - + gZenFolders.setFolderIndentation(movingTabs, dropElement); // Shift background tabs to leave a gap where the dragged tab // would currently be dropped. for (let item of tabs) { - if (item == draggedTab) { + if (item == draggedTab || (item.group?.hasAttribute("split-view-group") && item.group == draggedTab.group)) { continue; } @@ -3346,12 +3422,14 @@ element?.removeAttribute("dragover-groupTarget"); } - finishAnimateTabMove() { - if (!this.#isMovingTab()) { + finishAnimateTabMove(always = false) { + gZenPinnedTabManager.onDragFinish(); + if (!this.#isMovingTab() && !always) { return; } this.#setMovingTabMode(false); + gZenFolders.highlightGroupOnDragOver(null); for (let item of this.ariaFocusableItems) { this.#resetGroupTarget(item); @@ -3394,16 +3472,15 @@ tab.style.left = ""; tab.style.top = ""; tab.style.maxWidth = ""; - tab.removeAttribute("dragtarget"); + tab.removeAttribute("zen-dragtarget"); } for (let label of draggedTabDocument.getElementsByClassName( "tab-group-label-container" )) { label.style.width = ""; - label.style.height = ""; label.style.left = ""; label.style.top = ""; - label.removeAttribute("dragtarget"); + label.removeAttribute("zen-dragtarget"); } let periphery = draggedTabDocument.getElementById( "tabbrowser-arrowscrollbox-periphery" @@ -3475,7 +3552,7 @@ let postTransitionCleanup = () => { movingTab._moveTogetherSelectedTabsData.animate = false; }; - if (gReduceMotion) { + if (true || gReduceMotion) { postTransitionCleanup(); } else { let onTransitionEnd = transitionendEvent => { @@ -3639,7 +3716,7 @@ } _notifyBackgroundTab(aTab) { - if (aTab.pinned || !aTab.visible || !this.overflowing) { + if (aTab.hasAttribute("zen-essential") || !aTab.visible || !this.overflowing) { return; } @@ -3748,7 +3825,10 @@ #getDragTarget(event, { ignoreSides = false } = {}) { let { target } = event; while (target) { - if (isTab(target) || isTabGroupLabel(target)) { + if (isTab(target) || isTabGroupLabel(target) || target?.classList?.contains("tab-group-label-container")) { + if (target.classList?.contains("tab-group-label-container")) { + target = target.querySelector(".tab-group-label"); + } break; } target = target.parentNode; @@ -3765,6 +3845,9 @@ return null; } } + if (target?.group?.hasAttribute("split-view-group")) { + target = target.group.labelElement; + } return target; }