From 935e67eb9f06063c051ab930bbd8e22db6e127f9 Mon Sep 17 00:00:00 2001 From: Norisz Fay Date: Mon, 22 Jan 2024 20:01:57 +0200 Subject: [PATCH] Backed out 2 changesets (bug 1875079) for causing bc failures on browser_menu_touch.js CLOSED TREE Backed out changeset 015e7b62138b (bug 1875079) Backed out changeset 3a62cca5ea26 (bug 1875079) --- browser/base/content/browser.js | 23 ++++++++++++++ .../customizableui/PanelMultiView.sys.mjs | 8 +---- browser/themes/windows/browser.css | 31 +++++++++++++++++++ layout/xul/nsXULPopupManager.cpp | 8 ----- toolkit/themes/shared/popup.css | 5 --- xpcom/ds/StaticAtoms.py | 1 - 6 files changed, 55 insertions(+), 21 deletions(-) diff --git a/browser/base/content/browser.js b/browser/base/content/browser.js index 9b265a39555d0..4daaa140abf80 100644 --- a/browser/base/content/browser.js +++ b/browser/base/content/browser.js @@ -1955,6 +1955,7 @@ var gBrowserInit = { } FullScreen.init(); + MenuTouchModeObserver.init(); if (AppConstants.MOZ_DATA_REPORTING) { gDataNotificationInfoBar.init(); @@ -2568,6 +2569,7 @@ var gBrowserInit = { ); Services.obs.removeObserver(gKeywordURIFixup, "keyword-uri-fixup"); + MenuTouchModeObserver.uninit(); BrowserOffline.uninit(); CanvasPermissionPromptHelper.uninit(); WebAuthnPromptHelper.uninit(); @@ -8722,6 +8724,27 @@ var RestoreLastSessionObserver = { ]), }; +/* Observes menus and adjusts their size for better + * usability when opened via a touch screen. */ +var MenuTouchModeObserver = { + init() { + window.addEventListener("popupshowing", this, true); + }, + + handleEvent(event) { + let target = event.originalTarget; + if (event.inputSource == MouseEvent.MOZ_SOURCE_TOUCH) { + target.setAttribute("touchmode", "true"); + } else { + target.removeAttribute("touchmode"); + } + }, + + uninit() { + window.removeEventListener("popupshowing", this, true); + }, +}; + // Prompt user to restart the browser in safe mode function safeModeRestart() { if (Services.appinfo.inSafeMode) { diff --git a/browser/components/customizableui/PanelMultiView.sys.mjs b/browser/components/customizableui/PanelMultiView.sys.mjs index 520060415ab2a..ba540544a232c 100644 --- a/browser/components/customizableui/PanelMultiView.sys.mjs +++ b/browser/components/customizableui/PanelMultiView.sys.mjs @@ -1219,13 +1219,7 @@ export var PanelMultiView = class extends AssociatedToNode { // this value will be easy to adjust. const EXTRA_MARGIN_PX = 20; maxHeight -= EXTRA_MARGIN_PX; - - // if zoom factor is applied by touchmode then max-height will be zoomed - // too, which we do not want. - let zoomFactor = Number( - this._panel.ownerGlobal.getComputedStyle(this._panel).zoom ?? 1 - ); - return maxHeight / zoomFactor; + return maxHeight; } handleEvent(aEvent) { diff --git a/browser/themes/windows/browser.css b/browser/themes/windows/browser.css index 70270fd5d9d8f..5698fb3d99155 100644 --- a/browser/themes/windows/browser.css +++ b/browser/themes/windows/browser.css @@ -357,6 +357,37 @@ margin-bottom: -10px; } +/* Make menu items larger when opened through touch. */ +panel[touchmode], +menupopup[touchmode] { + --arrowpanel-menuitem-padding-block: 12px; + --arrowpanel-menuitem-padding: var(--arrowpanel-menuitem-padding-block) var(--arrowpanel-menuitem-padding-inline); + /* The value for the header back icon padding is selected in a way that the + * height of the header and its separator will be equal to the panel inner + * top padding plus standard menuitem, so that the header's separator will + * be located excatly where a normal toolbarseparator would be located after + * the first menuitem, in a menu without a header. */ + --arrowpanel-header-back-icon-padding: 10px; +} + +:root[uidensity="compact"] panel[touchmode] { + --arrowpanel-header-back-icon-padding: 12px; +} + +menupopup[touchmode] :is(menu, menuitem, menucaption) { + /* Use the var set in the rule above to increase menu items height in menupopups when + * they are opened through touch. + * Panel menu items already have their padding set in panelUI-shared.css with the same var. */ + padding-block: var(--arrowpanel-menuitem-padding-block); +} + +#contentAreaContextMenu[touchmode] > #context-navigation > menuitem { + /* The navigation menuitems are bigger to begin with because of their inner padding, + * so calculate the padding-block to match normal menuitems height when in touchmode. + * 3.5em is the desired menuitem height (~42px), minus the menuitem actual height devided by 2. */ + padding-block: calc((3.5em - 32px) / 2); +} + /* Other menu separators don't extend all the way to the menu edges, but the one below the navigation buttons in the content context menu should. */ #context-sep-navigation { diff --git a/layout/xul/nsXULPopupManager.cpp b/layout/xul/nsXULPopupManager.cpp index d63d25884a11c..c47e403e48251 100644 --- a/layout/xul/nsXULPopupManager.cpp +++ b/layout/xul/nsXULPopupManager.cpp @@ -874,12 +874,6 @@ void nsXULPopupManager::ShowPopupAtScreen(Element* aPopup, int32_t aXPos, BeginShowingPopup(pendingPopup, aIsContextMenu, false); } -void ToggleTouchMode(const PendingPopup& aPopup) { - aPopup.mPopup->SetBoolAttr( - nsGkAtoms::touchmode, - aPopup.MouseInputSource() == MouseEvent_Binding::MOZ_SOURCE_TOUCH); -} - bool nsXULPopupManager::ShowPopupAsNativeMenu(Element* aPopup, int32_t aXPos, int32_t aYPos, bool aIsContextMenu, @@ -1623,8 +1617,6 @@ void nsXULPopupManager::BeginShowingPopup(const PendingPopup& aPendingPopup, PopupType popupType = popupFrame->GetPopupType(); - ToggleTouchMode(aPendingPopup); - nsEventStatus status = FirePopupShowingEvent(aPendingPopup, presContext); // if a panel, blur whatever has focus so that the panel can take the focus. diff --git a/toolkit/themes/shared/popup.css b/toolkit/themes/shared/popup.css index c0552c216d006..6f231c4e8ca85 100644 --- a/toolkit/themes/shared/popup.css +++ b/toolkit/themes/shared/popup.css @@ -94,11 +94,6 @@ panel { padding: 0; } } - - /* Make menu items larger when opened through touch. */ - &[touchmode] { - zoom: 1.3; - } } menupopup { diff --git a/xpcom/ds/StaticAtoms.py b/xpcom/ds/StaticAtoms.py index 769bf2b9d3d07..87615fcd1df76 100644 --- a/xpcom/ds/StaticAtoms.py +++ b/xpcom/ds/StaticAtoms.py @@ -621,7 +621,6 @@ Atom("listitem", "listitem"), Atom("load", "load"), Atom("loading", "loading"), - Atom("touchmode", "touchmode"), Atom("triggeringprincipal", "triggeringprincipal"), Atom("localedir", "localedir"), Atom("localName", "local-name"),