Bug 1597210 - For preference subdialog sizing, read scrollHeight from the body if it exists instead of the documentElement r=Gijs
authorBrian Grinstead <bgrinstead@mozilla.com>
Mon, 18 Nov 2019 20:44:33 +0000
changeset 502521 53ca0eff415ed67f2d735f8f81588db69dd7d8c6
parent 502520 6a9a26055f9c47058638838305867c87e86eddec
child 502522 841580134756b1671f056a4e1e7d847436ea3aa5
push id114172
push userdluca@mozilla.com
push dateTue, 19 Nov 2019 11:31:10 +0000
treeherdermozilla-inbound@b5c5ba07d3db [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersGijs
bugs1597210, 1588142
milestone72.0a1
Bug 1597210 - For preference subdialog sizing, read scrollHeight from the body if it exists instead of the documentElement r=Gijs We were already doing this for scrollWidth, but after we started setting height: 100% on root nodes in Bug 1588142, the scrollHeight computation was too small for <html> elements. Differential Revision: https://phabricator.services.mozilla.com/D53690
browser/components/preferences/in-content/subdialogs.js
--- a/browser/components/preferences/in-content/subdialogs.js
+++ b/browser/components/preferences/in-content/subdialogs.js
@@ -315,26 +315,18 @@ SubDialog.prototype = {
 
     // These are deduced from styles which we don't change, so it's safe to get them now:
     let boxHorizontalBorder =
       2 * parseFloat(getComputedStyle(this._box).borderLeftWidth);
     let frameHorizontalMargin =
       2 * parseFloat(getComputedStyle(this._frame).marginLeft);
 
     // Then determine and set a bunch of width stuff:
-    let frameMinWidth = docEl.style.width;
-    if (!frameMinWidth) {
-      if (docEl.ownerDocument.body) {
-        // HTML documents have a body but XUL documents don't
-        frameMinWidth = docEl.ownerDocument.body.scrollWidth;
-      } else {
-        frameMinWidth = docEl.scrollWidth;
-      }
-      frameMinWidth += "px";
-    }
+    let { scrollWidth } = docEl.ownerDocument.body || docEl;
+    let frameMinWidth = docEl.style.width || scrollWidth + "px";
     let frameWidth = docEl.getAttribute("width")
       ? docEl.getAttribute("width") + "px"
       : frameMinWidth;
     this._frame.style.width = frameWidth;
     this._box.style.minWidth =
       "calc(" +
       (boxHorizontalBorder + frameHorizontalMargin) +
       "px + " +
@@ -395,17 +387,18 @@ SubDialog.prototype = {
     let boxRect = this._box.getBoundingClientRect();
     let frameRect = this._frame.getBoundingClientRect();
     let frameSizeDifference =
       frameRect.top - boxRect.top + (boxRect.bottom - frameRect.bottom);
 
     // Now do the same but for the height. We need to do this afterwards because otherwise
     // XUL assumes we'll optimize for height and gives us "wrong" values which then are no
     // longer correct after we set the width:
-    let frameMinHeight = docEl.style.height || docEl.scrollHeight + "px";
+    let { scrollHeight } = docEl.ownerDocument.body || docEl;
+    let frameMinHeight = docEl.style.height || scrollHeight + "px";
     let frameHeight = docEl.getAttribute("height")
       ? docEl.getAttribute("height") + "px"
       : frameMinHeight;
 
     // Now check if the frame height we calculated is possible at this window size,
     // accounting for titlebar, padding/border and some spacing.
     let maxHeight = window.innerHeight - frameSizeDifference - 30;
     // Do this with a frame height in pixels...