Bug 1377793 - Fix scrolling in the non-Photon main menu on Windows. r=Gijs
This is a follow-up to the previous patch, required because on Windows we cannot measure the full height of the main view until it is visible.
MozReview-Commit-ID: 2pfYwMLPYIb
--- a/browser/components/customizableui/PanelMultiView.jsm
+++ b/browser/components/customizableui/PanelMultiView.jsm
@@ -4,16 +4,18 @@
"use strict";
this.EXPORTED_SYMBOLS = ["PanelMultiView"];
const {classes: Cc, interfaces: Ci, utils: Cu} = Components;
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
+XPCOMUtils.defineLazyModuleGetter(this, "AppConstants",
+ "resource://gre/modules/AppConstants.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "CustomizableWidgets",
"resource:///modules/CustomizableWidgets.jsm");
/**
* Simple implementation of the sliding window pattern; panels are added to a
* linked list, in-order, and the currently shown panel is remembered using a
* marker. The marker shifts as navigation between panels is continued, where
* the panel at index 0 is always the starting point:
@@ -875,21 +877,34 @@ this.PanelMultiView = class {
// When using block-in-box layout inside a scrollable frame, like in the
// main menu contents scroller, if we allow the contents to scroll then
// it will not cause its container to expand. Thus, we layout first
// without any scrolling (using "display: flex;"), and only if the view
// exceeds the available space we set the height explicitly and enable
// scrolling.
if (this._mainView.hasAttribute("blockinboxworkaround")) {
- let mainViewHeight =
- this._dwu.getBoundsWithoutFlushing(this._mainView).height;
- if (mainViewHeight > maxHeight) {
- this._mainView.style.height = maxHeight + "px";
- this._mainView.setAttribute("exceeding", "true");
+ let blockInBoxWorkaround = () => {
+ let mainViewHeight =
+ this._dwu.getBoundsWithoutFlushing(this._mainView).height;
+ if (mainViewHeight > maxHeight) {
+ this._mainView.style.height = maxHeight + "px";
+ this._mainView.setAttribute("exceeding", "true");
+ }
+ };
+ // On Windows, we cannot measure the full height of the main view
+ // until it is visible. Unfortunately, this causes a visible jump when
+ // the view needs to scroll, but there is no easy way around this.
+ if (AppConstants.platform == "win") {
+ // We register a "once" listener so we don't need to store the value
+ // of maxHeight elsewhere on the object.
+ this._panel.addEventListener("popupshown", blockInBoxWorkaround,
+ { once: true });
+ } else {
+ blockInBoxWorkaround();
}
}
break;
case "popupshown":
// Now that the main view is visible, we can check the height of the
// description elements it contains.
this.descriptionHeightWorkaround();
break;