diff --git a/browser/components/tabbrowser/content/tabs.js b/browser/components/tabbrowser/content/tabs.js index 1fcebe3962398ff1b7cadef657ac8b68a80e720d..1cd2e9f24b3be1717493b4e663bc41d784cc9da0 100644 --- a/browser/components/tabbrowser/content/tabs.js +++ b/browser/components/tabbrowser/content/tabs.js @@ -289,6 +289,7 @@ on_TabGroupCollapse(event) { this._invalidateCachedVisibleTabs(); this._unlockTabSizing(); + return; // If the user's selected tab is in the collapsing group, kick them off // the tab. If no tabs exist outside the group, create a new one and @@ -345,7 +346,7 @@ // and we're not hitting the scroll buttons. if ( event.button != 0 || - event.target != this.arrowScrollbox || + !event.target.classList.contains("zen-workspace-normal-tabs-section") || event.composedTarget.localName == "toolbarbutton" ) { return; @@ -695,7 +696,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( @@ -777,11 +778,12 @@ if (tab.multiselected) { this.#moveTogetherSelectedTabs(tab); - } else if (isTabGroupLabel(tab) && !tab.group.collapsed) { + } else if (isTabGroupLabel(tab)) { this._lockTabSizing(); this.#keepTabSizeLocked = true; - tab.group.collapsed = true; - expandGroupOnDrop = true; + tab.group.collapsed = !tab.group.hasAttribute("split-view-group"); + expandGroupOnDrop = !tab.group.collapsed || tab.group.hasAttribute("has-active"); + gZenFolders.collapseVisibleTab(tab.group); } } @@ -879,7 +881,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, @@ -933,6 +935,10 @@ } let draggedTab = event.dataTransfer.mozGetDataAt(TAB_DROP_TYPE, 0); + if (draggedTab && effects === "move") { + gZenPinnedTabManager.applyDragoverClass(event, draggedTab); + gZenViewSplitter.onBrowserDragEndToSplit(event); + } if ( (effects == "move" || effects == "copy") && document == draggedTab.ownerDocument && @@ -1060,7 +1066,9 @@ isTabGroupLabel(draggedTab) && draggedTab._dragData?.expandGroupOnDrop ) { - draggedTab.group.collapsed = false; + const isActive = draggedTab.group.hasAttribute("has-active"); + draggedTab.group.collapsed = isActive; + if (isActive) gZenFolders.expandVisibleTab(draggedTab.group); this.#keepTabSizeLocked = false; this._unlockTabSizing(); } @@ -1089,6 +1097,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 = []; @@ -1127,11 +1147,12 @@ newTranslateY -= tabHeight; } } else { - 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"); 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"; @@ -1181,6 +1202,7 @@ (oldTranslateY && oldTranslateY != newTranslateY); } else if (this.verticalMode) { shouldTranslate &&= oldTranslateY && oldTranslateY != newTranslateY; + shouldTranslate = false; // TODO: Find a way to animate vertical tab moves. } else { shouldTranslate &&= oldTranslateX && oldTranslateX != newTranslateX; } @@ -1349,6 +1371,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, @@ -1381,6 +1404,17 @@ this.finishMoveTogetherSelectedTabs(draggedTab); this.finishAnimateTabMove(); + + if (!dt.mozUserCancelled && dt.dropEffect == "none" && !this._isCustomizing) { + const moved = gZenViewSplitter.moveTabToSplitView(event, draggedTab); + if (moved) { + delete draggedTab._dragData; + return; + } + } else if (dt.mozUserCancelled) { + if (gZenViewSplitter._lastOpenedTab) gZenViewSplitter._lastOpenedTab._visuallySelected = false; + } + this.#expandGroupOnDrop(draggedTab); if ( @@ -1607,7 +1641,7 @@ } get newTabButton() { - return this.querySelector("#tabs-newtab-button"); + return gZenWorkspaces.activeWorkspaceStrip.querySelector("#tabs-newtab-button"); } get verticalMode() { @@ -1623,6 +1657,7 @@ } get overflowing() { + gZenWorkspaces.updateOverflowingTabs(); return this.hasAttribute("overflow"); } @@ -1631,26 +1666,54 @@ if (this.#allTabs) { return this.#allTabs; } - let children = Array.from(this.arrowScrollbox.children); + let children = gZenWorkspaces.tabboxChildren; // remove arrowScrollbox periphery element children.pop(); // explode tab groups // Iterate backwards over the array to preserve indices while we modify // things in place - for (let i = children.length - 1; i >= 0; i--) { - if (children[i].tagName == "tab-group") { - children.splice(i, 1, ...children[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 = [...this.pinnedTabsContainer.children, ...children]; + 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; } /** @@ -1717,33 +1780,27 @@ let elementIndex = 0; - for (let i = 0; i < this.pinnedTabsContainer.childElementCount; i++) { - this.pinnedTabsContainer.children[i].elementIndex = elementIndex++; - } - let children = Array.from(this.arrowScrollbox.children); + let children = gZenWorkspaces.tabboxChildrenWithoutEmpty; let focusableItems = []; - for (let child of children) { + 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); - if (!child.collapsed) { - let visibleTabsInGroup = child.tabs.filter(tab => tab.visible); - visibleTabsInGroup.forEach(tab => { + if (!child.hasAttribute("split-view-group")) { + let visibleTabsAndGroupsInGroup = child.childGroupsAndTabs.filter(tab => tab.visible); + visibleTabsAndGroupsInGroup.forEach(tab => { tab.elementIndex = elementIndex++; }); - focusableItems.push(...visibleTabsInGroup); + focusableItems.push(...visibleTabsAndGroupsInGroup); } } } - this.#focusableItems = [ - ...this.pinnedTabsContainer.children, - ...focusableItems, - ]; + this.#focusableItems = focusableItems; return this.#focusableItems; } @@ -1751,6 +1808,7 @@ _invalidateCachedTabs() { this.#allTabs = null; this._invalidateCachedVisibleTabs(); + gZenWorkspaces._allStoredTabs = null; } _invalidateCachedVisibleTabs() { @@ -1766,8 +1824,8 @@ #isContainerVerticalPinnedGrid(tab) { return ( this.verticalMode && - tab.hasAttribute("pinned") && - this.hasAttribute("expanded") && + (tab.hasAttribute("zen-essential")) && + (this.hasAttribute("expanded") || document.documentElement.hasAttribute("zen-sidebar-expanded")) && !this.expandOnHover ); } @@ -1783,7 +1841,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); @@ -1878,7 +1936,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" @@ -1973,10 +2031,12 @@ _handleTabSelect(aInstant) { let selectedTab = this.selectedItem; + if (!selectedTab) return; if (this.overflowing) { this.arrowScrollbox.ensureElementIsVisible(selectedTab, aInstant); } + gZenCompactModeManager.flashSidebarIfNecessary(aInstant); selectedTab._notselectedsinceload = false; } @@ -2130,7 +2190,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; @@ -2139,6 +2199,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; @@ -2168,7 +2230,7 @@ let translateX = screenX - dragData.screenX; let translateY = screenY - dragData.screenY; translateY += - this.pinnedTabsContainer.scrollPosition - dragData.scrollPos; + dragData.scrollPos; let firstBoundX = firstTabInRow.screenX - firstMovingTabScreenX; let firstBoundY = firstTabInRow.screenY - firstMovingTabScreenY; let lastBoundX = @@ -2294,7 +2356,7 @@ } dragData.animDropElementIndex = newIndex; - dragData.dropElement = tabs[newIndex]; + dragData.dropElement = tabs[Math.min(newIndex, tabs.length - 1)]; dragData.dropBefore = newIndex < tabs.length; // Shift background tabs to leave a gap where the dragged tab @@ -2327,12 +2389,17 @@ this.#clearDragOverCreateGroupTimer(); - 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 tabs = this.ariaFocusableItems.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(); @@ -2346,7 +2413,7 @@ let size = this.verticalMode ? "height" : "width"; let translateAxis = this.verticalMode ? "translateY" : "translateX"; let scrollDirection = this.verticalMode ? "scrollTop" : "scrollLeft"; - let { width: tabWidth, height: tabHeight } = bounds(draggedTab); + let { width: tabWidth, height: tabHeight } = bounds(draggedTab.group?.hasAttribute("split-view-group") ? draggedTab.group : draggedTab); let translateX = event.screenX - dragData.screenX; let translateY = event.screenY - dragData.screenY; @@ -2360,12 +2427,18 @@ let lastTab = tabs.at(-1); 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]; let shiftSize = lastMovingTabScreen - firstMovingTabScreen; let translate = screen - dragData[screenAxis]; - if (!isPinned) { + if (true) { translate += this.arrowScrollbox.scrollbox[scrollDirection] - dragData.scrollPos; } else if (isPinned && this.verticalMode) { @@ -2377,6 +2450,7 @@ // - for unpinned tabs, between the first and last unpinned tab let firstBound = firstTab[screenAxis] - firstMovingTabScreen; let lastBound = endEdge(lastTab) - lastMovingTabScreen; + lastBound = gZenPinnedTabManager.getLastTabBound(lastBound, lastTab, isDraggingFolder); translate = Math.min(Math.max(translate, firstBound), lastBound); for (let item of movingTabs) { @@ -2384,6 +2458,9 @@ // Shift the `.tab-group-label-container` to shift the label element. item = item.parentElement; } + if (item.parentElement?.hasAttribute("split-view-group")) { + item = item.parentElement; + } item.style.transform = `${translateAxis}(${translate}px)`; } @@ -2521,6 +2598,9 @@ break; } let element = tabs[mid]; + if (element?.group?.hasAttribute("split-view-group")) { + element = element.group.labelElement; + } let elementForSize = isTabGroupLabel(element) ? element.parentElement : element; @@ -2540,6 +2620,8 @@ }; let dropElement = getOverlappedElement(); + if (dropElement?.hasAttribute("split-view-group")) dropElement = dropElement.labelElement; + gZenPinnedTabManager.animateSeparatorMove(movingTabs, dropElement, isPinned, event); let newDropElementIndex; if (dropElement) { @@ -2604,7 +2686,7 @@ let shouldCreateGroupOnDrop; let dropBefore; if (dropElement) { - let dropElementForOverlap = isTabGroupLabel(dropElement) + let dropElementForOverlap = isTabGroupLabel(dropElement) && !dropElement.group?.hasAttribute("split-view-group") ? dropElement.parentElement : dropElement; @@ -2624,7 +2706,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) { @@ -2656,44 +2738,21 @@ // 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 ( - isTabGroupLabel(draggedTab) && - dropElement?.group && - !dropElement.group.collapsed - ) { - let overlappedGroup = dropElement.group; - - if (isTabGroupLabel(dropElement)) { - dropBefore = true; - newDropElementIndex = dropElement.elementIndex; - } else { - dropBefore = false; - newDropElementIndex = overlappedGroup.tabs.at(-1).elementIndex + 1; - } - - dropElement = overlappedGroup; - } // Constrain drop direction at the boundary between pinned and // unpinned tabs so that they don't mix together. 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); + } + // When dragging tab(s) over an ungrouped tab, signal to the user // that dropping the tab(s) will create a new tab group. shouldCreateGroupOnDrop = @@ -2703,12 +2762,6 @@ overlapPercent > dragOverGroupingThreshold; if (shouldCreateGroupOnDrop) { - this.#dragOverCreateGroupTimer = setTimeout( - () => this.#triggerDragOverCreateGroup(dragData, dropElement), - Services.prefs.getIntPref( - "browser.tabs.dragDrop.createGroup.delayMS" - ) - ); } else { this.removeAttribute("movingtab-createGroup"); document @@ -2735,19 +2788,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-ungroup", !colorCode); @@ -2765,19 +2813,28 @@ 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; } let shift = getTabShift(item, newDropElementIndex); let transform = shift ? `${translateAxis}(${shift}px)` : ""; + if (item.group?.hasAttribute("split-view-group")) { + item = item.group; + } + if (item.group?.hasAttribute("has-active") && draggedTab.group != item.group) { + item = item.group; + } if (isTabGroupLabel(item)) { // Shift the `.tab-group-label-container` to shift the label element. item = item.parentElement; + if (item.parentElement?.hasAttribute("split-view-group")) { + item = item.parentElement; + } } item.style.transform = transform; } @@ -2830,12 +2887,14 @@ ); } - 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) { if (isTabGroupLabel(item)) { @@ -2843,6 +2902,18 @@ item = item.parentElement; } item.style.transform = ""; + if (item.closest("zen-folder")?.hasAttribute("has-active")) item.closest("zen-folder").style.transform = ""; + if (item.closest("zen-folder")?.hasAttribute("has-active")) { + for (let tab of item.closest("zen-folder").tabs) { + tab.style.transform = ""; + } + } + if (item.closest("tab-group")?.hasAttribute("split-view-group")) item.closest("tab-group").style.transform = ""; + if (item.closest("tab-group")?.hasAttribute("split-view-group")) { + for (let tab of item.closest("tab-group").tabs) { + tab.style.transform = ""; + } + } item.removeAttribute("dragover-createGroup"); } this.removeAttribute("movingtab-createGroup"); @@ -2889,7 +2960,7 @@ let postTransitionCleanup = () => { movingTab._moveTogetherSelectedTabsData.animate = false; }; - if (gReduceMotion) { + if (true || gReduceMotion) { postTransitionCleanup(); } else { let onTransitionEnd = transitionendEvent => { @@ -3062,7 +3133,7 @@ } _notifyBackgroundTab(aTab) { - if (aTab.pinned || !aTab.visible || !this.overflowing) { + if (aTab.hasAttribute("zen-essential") || !aTab.visible || !this.overflowing) { return; } @@ -3171,7 +3242,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; @@ -3188,6 +3262,9 @@ return null; } } + if (target?.group?.hasAttribute("split-view-group")) { + target = target.group.labelElement; + } return target; }