Bug 1402845 - Fix panelview sizing when customRectGetter is used. r=paolo draft
authorSam Foster <sfoster@mozilla.com>
Thu, 05 Oct 2017 10:23:53 -0700
changeset 763749 ef91dd66a22b5d7d76b22bab745f042e40bcda22
parent 763748 a4ef1082c51d5b4508882c22487f6c8de5b35e2a
push id101549
push userbmo:sfoster@mozilla.com
push dateTue, 06 Mar 2018 17:17:44 +0000
reviewerspaolo
bugs1402845
milestone60.0a1
Bug 1402845 - Fix panelview sizing when customRectGetter is used. r=paolo * The extension content drives the sizing of the browser and popup that contains it via the Extension:BrowserResized message. The ignoreResizes property throttles/debounces this initially, stashing the dimensions received rather than triggering resize of the popup for every message. When the popup is a subview and fixedWidth, we ignore width but *do* want to use the stashed height value. * Until the panel is given visibility, it has 0 height, so after setting visibility, wait until the next refresh-driver tick before measuring any header which should get added to the overall view height MozReview-Commit-ID: AgcruVb9QPA
browser/components/customizableui/PanelMultiView.jsm
browser/components/extensions/ExtensionPopups.jsm
--- a/browser/components/customizableui/PanelMultiView.jsm
+++ b/browser/components/customizableui/PanelMultiView.jsm
@@ -870,21 +870,25 @@ var PanelMultiView = class extends Assoc
     } else if (viewNode.customRectGetter) {
       // We use a customRectGetter for WebExtensions panels, because they need
       // to query the size from an embedded browser. The presence of this
       // getter also provides an indication that the view node shouldn't be
       // moved around, otherwise the state of the browser would get disrupted.
       let width = prevPanelView.knownWidth;
       let height = prevPanelView.knownHeight;
       viewRect = Object.assign({height, width}, viewNode.customRectGetter());
+      nextPanelView.visible = true;
+      // Until the header is visible, it has 0 height.
+      // Wait for layout before measuring it
       let header = viewNode.firstChild;
       if (header && header.classList.contains("panel-header")) {
-        viewRect.height += this._dwu.getBoundsWithoutFlushing(header).height;
+        viewRect.height += await window.promiseDocumentFlushed(() => {
+          return this._dwu.getBoundsWithoutFlushing(header).height;
+        });
       }
-      nextPanelView.visible = true;
       await nextPanelView.descriptionHeightWorkaround();
     } else {
       this._offscreenViewStack.style.minHeight = olderView.knownHeight + "px";
       this._offscreenViewStack.appendChild(viewNode);
       nextPanelView.visible = true;
 
       // Now that the subview is visible, we can check the height of the
       // description elements it contains.
--- a/browser/components/extensions/ExtensionPopups.jsm
+++ b/browser/components/extensions/ExtensionPopups.jsm
@@ -507,17 +507,20 @@ class ViewPopup extends BasePopup {
     let browser = this.browser;
     await this.createBrowser(this.viewNode);
 
     this.ignoreResizes = false;
 
     this.browser.swapDocShells(browser);
     this.destroyBrowser(browser);
 
-    if (this.dimensions && !this.fixedWidth) {
+    if (this.dimensions) {
+      if (this.fixedWidth) {
+        delete this.dimensions.width;
+      }
       this.resizeBrowser(this.dimensions);
     }
 
     this.viewNode.customRectGetter = () => {
       return {height: this.lastCalculatedInViewHeight || this.viewHeight};
     };
 
     this.tempPanel.remove();