Files
desktop/src/browser/components/customizableui/CustomizableUI-sys-mjs.patch

278 lines
12 KiB
C++

diff --git a/browser/components/customizableui/CustomizableUI.sys.mjs b/browser/components/customizableui/CustomizableUI.sys.mjs
index db617c65b89643015d91b0f6a20eab7d7a1b598f..1511b785a45ebd084de13b091f56a59e7e737b26 100644
--- a/browser/components/customizableui/CustomizableUI.sys.mjs
+++ b/browser/components/customizableui/CustomizableUI.sys.mjs
@@ -14,6 +14,7 @@ ChromeUtils.defineESModuleGetters(lazy, {
BrowserUsageTelemetry: "resource:///modules/BrowserUsageTelemetry.sys.mjs",
CustomizableWidgets:
"moz-src:///browser/components/customizableui/CustomizableWidgets.sys.mjs",
+ ZenCustomizableUI: "resource:///modules/ZenCustomizableUI.sys.mjs",
HomePage: "resource:///modules/HomePage.sys.mjs",
PanelMultiView:
"moz-src:///browser/components/customizableui/PanelMultiView.sys.mjs",
@@ -348,7 +349,7 @@ var CustomizableUIInternal = {
{
type: CustomizableUI.TYPE_PANEL,
defaultPlacements: [],
- anchor: "unified-extensions-button",
+ anchor: "zen-site-data-icon-button",
},
false
);
@@ -358,20 +359,15 @@ var CustomizableUIInternal = {
"back-button",
"forward-button",
"stop-reload-button",
- Services.policies.isAllowed("removeHomeButtonByDefault")
- ? null
- : "home-button",
"spring",
"vertical-spacer",
"urlbar-container",
"spring",
- "downloads-button",
AppConstants.MOZ_DEV_EDITION ? "developer-button" : null,
lazy.ippEnabled ? "ipprotection-button" : null,
- "fxa-toolbar-menu-button",
lazy.resetPBMToolbarButtonEnabled ? "reset-pbm-toolbar-button" : null,
].filter(name => name);
-
+ lazy.ZenCustomizableUI.startup(this);
this.registerArea(
CustomizableUI.AREA_NAVBAR,
{
@@ -379,8 +375,6 @@ var CustomizableUIInternal = {
overflowable: true,
defaultPlacements: navbarPlacements,
verticalTabsDefaultPlacements: [
- "firefox-view-button",
- "alltabs-button",
],
defaultCollapsed: false,
},
@@ -404,10 +398,7 @@ var CustomizableUIInternal = {
{
type: CustomizableUI.TYPE_TOOLBAR,
defaultPlacements: [
- "firefox-view-button",
"tabbrowser-tabs",
- "new-tab-button",
- "alltabs-button",
],
verticalTabsDefaultPlacements: [],
defaultCollapsed: null,
@@ -489,6 +480,7 @@ var CustomizableUIInternal = {
CustomizableUI.AREA_NAVBAR,
CustomizableUI.AREA_BOOKMARKS,
CustomizableUI.AREA_TABSTRIP,
+ "zen-sidebar-top-buttons",
]);
if (AppConstants.platform != "macosx") {
toolbars.add(CustomizableUI.AREA_MENUBAR);
@@ -1265,6 +1257,9 @@ var CustomizableUIInternal = {
placements = gPlacements.get(area);
}
+ // remove "zen-sidebar-top-buttons" from the placements
+ placements = placements.filter(p => p != "zen-sidebar-top-buttons");
+
// For toolbars that need it, mark as dirty.
let defaultPlacements = areaProperties.get("defaultPlacements");
if (
@@ -1772,7 +1767,6 @@ var CustomizableUIInternal = {
lazy.log.info(
"Widget " + aWidgetId + " not found, unable to remove from " + aArea
);
- continue;
}
this.notifyDOMChange(widgetNode, null, container, true, () => {
@@ -1782,7 +1776,7 @@ var CustomizableUIInternal = {
// We also need to remove the panel context menu if it's there:
this.ensureButtonContextMenu(widgetNode);
if (gPalette.has(aWidgetId) || this.isSpecialWidget(aWidgetId)) {
- container.removeChild(widgetNode);
+ widgetNode.remove();
} else {
window.gNavToolbox.palette.appendChild(widgetNode);
}
@@ -1950,16 +1944,16 @@ var CustomizableUIInternal = {
elem.setAttribute("skipintoolbarset", "true");
}
}
-
+ lazy.ZenCustomizableUI.init(aWindow);
// Now register all the toolbars
for (let area of CustomizableUI.areas) {
let type = CustomizableUI.getAreaType(area);
- if (type == CustomizableUI.TYPE_TOOLBAR) {
+ if (type == CustomizableUI.TYPE_TOOLBAR && !area.startsWith("zen-")) {
let node = document.getElementById(area);
this.registerToolbarNode(node);
}
}
-
+ lazy.ZenCustomizableUI.registerToolbarNodes(aWindow);
// Handle initial state of vertical tabs.
if (isVerticalTabs) {
// Show the vertical tabs toolbar
@@ -2201,6 +2195,10 @@ var CustomizableUIInternal = {
* The identifier string of the area that aNode is being inserted into.
*/
insertWidgetBefore(aNode, aNextNode, aContainer, aAreaId) {
+ if (aAreaId === CustomizableUI.AREA_NAVBAR && aNode.ownerGlobal.gZenVerticalTabsManager._hasSetSingleToolbar) {
+ aContainer = aNode.ownerDocument.getElementById("zen-sidebar-top-buttons-customization-target");
+ aAreaId = "zen-sidebar-top-buttons";
+ }
this.notifyDOMChange(aNode, aNextNode, aContainer, false, () => {
this.setLocationAttributes(aNode, aAreaId);
aContainer.insertBefore(aNode, aNextNode);
@@ -4565,7 +4563,7 @@ var CustomizableUIInternal = {
* For all registered areas, builds those areas to reflect the current
* placement state of all widgets.
*/
- _rebuildRegisteredAreas() {
+ _rebuildRegisteredAreas(zenDontRebuildCollapsed = false) {
for (let [areaId, areaNodes] of gBuildAreas) {
let placements = gPlacements.get(areaId);
let isFirstChangedToolbar = true;
@@ -4576,7 +4574,7 @@ var CustomizableUIInternal = {
if (area.get("type") == CustomizableUI.TYPE_TOOLBAR) {
let defaultCollapsed = area.get("defaultCollapsed");
let win = areaNode.ownerGlobal;
- if (defaultCollapsed !== null) {
+ if (defaultCollapsed !== null && !zenDontRebuildCollapsed) {
win.setToolbarVisibility(
areaNode,
typeof defaultCollapsed == "string"
@@ -5867,6 +5865,7 @@ export var CustomizableUI = {
unregisterArea(aName, aDestroyPlacements) {
CustomizableUIInternal.unregisterArea(aName, aDestroyPlacements);
},
+ get zenInternalCU() { return CustomizableUIInternal; },
/**
* Add a widget to an area.
* If the area to which you try to add is not known to CustomizableUI,
@@ -7830,7 +7829,9 @@ class OverflowableToolbar {
);
if (webExtList && CustomizableUI.isWebExtensionWidget(child.id)) {
+ if (webExtList.id !== "zen-overflow-extensions-list") {
child.setAttribute("cui-anchorid", webExtButtonID);
+ }
webExtList.insertBefore(child, webExtList.firstElementChild);
} else {
child.setAttribute("cui-anchorid", this.#defaultListButton.id);
@@ -7890,7 +7891,7 @@ class OverflowableToolbar {
) {
continue;
}
- sum += parseFloat(style.marginLeft) + parseFloat(style.marginRight);
+ sum += parseFloat(style.marginLeft) + (win.gZenVerticalTabsManager._hasSetSingleToolbar ? Math.max(0, parseFloat(style.marginRight)) : parseFloat(style.marginRight));
if (child != aExceptChild) {
sum += getInlineSize(child);
}
@@ -7914,11 +7915,11 @@ class OverflowableToolbar {
parseFloat(style.paddingLeft) -
parseFloat(style.paddingRight) -
toolbarChildrenWidth;
- targetWidth = getInlineSize(this.#target);
+ targetWidth = getInlineSize(this.#target) - ((win.gZenVerticalTabsManager._hasSetSingleToolbar && this.#target.id == 'zen-sidebar-top-buttons-customization-target') ? win.gZenVerticalTabsManager._topButtonsSeparatorElement.getBoundingClientRect().width : 0);
targetChildrenWidth =
this.#target == this.#toolbar
? toolbarChildrenWidth
- : sumChildrenInlineSize(this.#target);
+ : sumChildrenInlineSize((win.gZenVerticalTabsManager._hasSetSingleToolbar && this.#target.id == 'nav-bar-customization-target') ? win.document.getElementById("zen-sidebar-top-buttons-customization-target") : this.#target, win.gZenVerticalTabsManager._topButtonsSeparatorElement);
});
lazy.log.debug(
@@ -7933,7 +7934,36 @@ class OverflowableToolbar {
Math.max(targetWidth, targetChildrenWidth)
);
totalAvailWidth = Math.ceil(totalAvailWidth);
- let isOverflowing = targetContentWidth > totalAvailWidth;
+ if (this.#target.id == 'nav-bar-customization-target' &&
+ win.gZenVerticalTabsManager._hasSetSingleToolbar &&
+ Services.prefs.getBoolPref("zen.view.overflow-webext-toolbar", true)) {
+ const availSelectors = ":is(#page-action-buttons, #zen-copy-url-button, .unified-extensions-item)";
+ const width = [
+ ...win.gURLBar._inputContainer.querySelectorAll(availSelectors),
+ ...win.document.getElementById("zen-overflow-extensions-list").querySelectorAll(availSelectors)
+ ].length * 26;
+ const urlbarWidth = win.document.getElementById("urlbar-container").getBoundingClientRect().width;
+ let overflowing = width > urlbarWidth * 0.5;
+ let wasOverflowing = win.gURLBar._isOverflowingItems;
+ win.gURLBar._isOverflowingItems = overflowing;
+ if (wasOverflowing !== overflowing) {
+ const items = gPlacements.get("nav-bar");
+ for (let item of items) {
+ let [, node] = CustomizableUIInternal.getWidgetNode(item, win);
+ if (node?.hasAttribute("data-extensionid")) {
+ win.gZenVerticalTabsManager.appendCustomizableItem(win.document.getElementById("zen-sidebar-top-buttons-customization-target"), node);
+ }
+ }
+ }
+ }
+ if (win.gZenVerticalTabsManager._hasSetSingleToolbar && this.#toolbar.id == 'nav-bar') return { isOverflowing: false, targetContentWidth, totalAvailWidth };
+ let isOverflowing = targetContentWidth + (win.gZenVerticalTabsManager._hasSetSingleToolbar ? 0.1 : 0) > totalAvailWidth;
+ if (win.gZenVerticalTabsManager._hasSetSingleToolbar &&
+ this.#target.id == 'zen-sidebar-top-buttons-customization-target' &&
+ Array.from(this.#target.children).filter(child => child.getAttribute("overflows") != "false").length == 1 &&
+ this.#overflowedInfo.size == 0) {
+ isOverflowing = false;
+ }
return { isOverflowing, targetContentWidth, totalAvailWidth };
}
@@ -7994,7 +8024,11 @@ class OverflowableToolbar {
return;
}
}
- if (totalAvailWidth <= minSize) {
+ let isLastItem = win.gZenVerticalTabsManager._hasSetSingleToolbar &&
+ this.#target.id == 'zen-sidebar-top-buttons-customization-target' &&
+ this.#overflowedInfo.size == 1 &&
+ !child.classList.contains('unified-extensions-item');
+ if (totalAvailWidth <= minSize && !isLastItem) {
lazy.log.debug(
`Need ${minSize} but width is ${totalAvailWidth} so bailing`
);
@@ -8027,7 +8061,7 @@ class OverflowableToolbar {
}
}
if (!inserted) {
- this.#target.appendChild(child);
+ win.gZenVerticalTabsManager.appendCustomizableItem(this.#target, child, gPlacements.get(this.#toolbar.id));
}
child.removeAttribute("cui-anchorid");
child.removeAttribute("overflowedItem");
@@ -8153,6 +8187,9 @@ class OverflowableToolbar {
* if no such list exists.
*/
get #webExtList() {
+ if (this.#toolbar.getAttribute("addon-webext-overflowtarget") !== this.#webExtListRef?.id) {
+ this.#webExtListRef = null;
+ }
if (!this.#webExtListRef) {
let targetID = this.#toolbar.getAttribute("addon-webext-overflowtarget");
if (!targetID) {
@@ -8164,6 +8201,9 @@ class OverflowableToolbar {
let win = this.#toolbar.ownerGlobal;
let { panel } = win.gUnifiedExtensions;
this.#webExtListRef = panel.querySelector(`#${targetID}`);
+ if (!this.#webExtListRef) {
+ this.#webExtListRef = win.document.getElementById(targetID);
+ }
}
return this.#webExtListRef;
}
@@ -8372,7 +8412,7 @@ class OverflowableToolbar {
break;
}
case "mousedown": {
- if (aEvent.button != 0) {
+ if (aEvent.button != 0 || this.#toolbar.id == "zen-sidebar-top-buttons") { // Fix https://github.com/zen-browser/desktop/issues/7718
break;
}
if (aEvent.target == this.#defaultListButton) {