Skip to content

Commit c225b05

Browse files
committed
Bug 1871515 - Let nsMenuPopupFrame constrain the panelview, and remove _calculateMaxHeight. r=dao,desktop-theme-reviewers
When I rewrote nsMenuPopupFrame, I made sure percentage sizes worked so that we could do stuff like this. This removes some complex code, and improves the behavior on platforms where screen sizes might not be 100% reliable. Differential Revision: https://phabricator.services.mozilla.com/D204754
1 parent 788781e commit c225b05

File tree

3 files changed

+1
-60
lines changed

3 files changed

+1
-60
lines changed

browser/base/content/browser.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ panelview:not([visible]) {
115115
flex-shrink: 0;
116116
min-width: 0;
117117
min-height: 0;
118+
max-height: 100%;
118119
}
119120

120121
.panel-viewcontainer[panelopen] {

browser/base/content/test/performance/browser_appmenu.js

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,6 @@ const EXPECTED_APPMENU_OPEN_REFLOWS = [
2121
"openPopup/this._openPopupPromise<@resource:///modules/PanelMultiView.sys.mjs",
2222
],
2323
},
24-
25-
{
26-
stack: [
27-
"_calculateMaxHeight@resource:///modules/PanelMultiView.sys.mjs",
28-
"handleEvent@resource:///modules/PanelMultiView.sys.mjs",
29-
],
30-
31-
maxCount: 7, // This number should only ever go down - never up.
32-
},
3324
];
3425

3526
add_task(async function () {

browser/components/customizableui/PanelMultiView.sys.mjs

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,6 @@ export var PanelMultiView = class extends AssociatedToNode {
412412
this.openViews = [];
413413

414414
this._panel.addEventListener("popupshowing", this);
415-
this._panel.addEventListener("popuppositioned", this);
416415
this._panel.addEventListener("popuphidden", this);
417416
this._panel.addEventListener("popupshown", this);
418417

@@ -434,7 +433,6 @@ export var PanelMultiView = class extends AssociatedToNode {
434433

435434
this._panel.removeEventListener("mousemove", this);
436435
this._panel.removeEventListener("popupshowing", this);
437-
this._panel.removeEventListener("popuppositioned", this);
438436
this._panel.removeEventListener("popupshown", this);
439437
this._panel.removeEventListener("popuphidden", this);
440438
this.document.documentElement.removeEventListener("keydown", this, true);
@@ -1181,47 +1179,6 @@ export var PanelMultiView = class extends AssociatedToNode {
11811179
}
11821180
}
11831181

1184-
_calculateMaxHeight(aEvent) {
1185-
// While opening the panel, we have to limit the maximum height of any
1186-
// view based on the space that will be available. We cannot just use
1187-
// window.screen.availTop and availHeight because these may return an
1188-
// incorrect value when the window spans multiple screens.
1189-
let anchor = this._panel.anchorNode;
1190-
let anchorRect = anchor.getBoundingClientRect();
1191-
let screen = anchor.screen;
1192-
1193-
// GetAvailRect returns screen-device pixels, which we can convert to CSS
1194-
// pixels here.
1195-
let availTop = {},
1196-
availHeight = {};
1197-
screen.GetAvailRect({}, availTop, {}, availHeight);
1198-
let cssAvailTop = availTop.value / screen.defaultCSSScaleFactor;
1199-
1200-
// The distance from the anchor to the available margin of the screen is
1201-
// based on whether the panel will open towards the top or the bottom.
1202-
let maxHeight;
1203-
if (aEvent.alignmentPosition.startsWith("before_")) {
1204-
maxHeight = anchor.screenY - cssAvailTop;
1205-
} else {
1206-
let anchorScreenBottom = anchor.screenY + anchorRect.height;
1207-
let cssAvailHeight = availHeight.value / screen.defaultCSSScaleFactor;
1208-
maxHeight = cssAvailTop + cssAvailHeight - anchorScreenBottom;
1209-
}
1210-
1211-
// To go from the maximum height of the panel to the maximum height of
1212-
// the view stack, we need to subtract the height of the arrow and the
1213-
// height of the opposite margin, but we cannot get their actual values
1214-
// because the panel is not visible yet. However, we know that this is
1215-
// currently 11px on Mac, 13px on Windows, and 13px on Linux. We also
1216-
// want an extra margin, both for visual reasons and to prevent glitches
1217-
// due to small rounding errors. So, we just use a value that makes
1218-
// sense for all platforms. If the arrow visuals change significantly,
1219-
// this value will be easy to adjust.
1220-
const EXTRA_MARGIN_PX = 20;
1221-
maxHeight -= EXTRA_MARGIN_PX;
1222-
return maxHeight;
1223-
}
1224-
12251182
handleEvent(aEvent) {
12261183
// Only process actual popup events from the panel or events we generate
12271184
// ourselves, but not from menus being shown from within the panel.
@@ -1262,14 +1219,6 @@ export var PanelMultiView = class extends AssociatedToNode {
12621219
}
12631220
break;
12641221
}
1265-
case "popuppositioned": {
1266-
if (this._panel.state == "showing") {
1267-
let maxHeight = this._calculateMaxHeight(aEvent);
1268-
this._viewStack.style.maxHeight = maxHeight + "px";
1269-
this._offscreenViewStack.style.maxHeight = maxHeight + "px";
1270-
}
1271-
break;
1272-
}
12731222
case "popupshown":
12741223
// The main view is always open and visible when the panel is first
12751224
// shown, so we can check the height of the description elements it

0 commit comments

Comments
 (0)