Bug 1424835: Prevent inline options browsers from continuing to grow after certain rounding errors. r=aswan
authorKris Maglione <maglione.k@gmail.com>
Fri, 15 Dec 2017 11:55:52 -0600
changeset 396606 a2b87439996443fa69171fda33938c632bb1630a
parent 396605 a74d64858b70aef7b3ebe02e205a63459122f403
child 396607 e15eeb9bbf33b6f73c2a41540931354f4b4ae7df
push id33099
push userncsoregi@mozilla.com
push dateSat, 16 Dec 2017 09:38:13 +0000
treeherdermozilla-central@4780efa5f110 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersaswan
bugs1424835
milestone59.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1424835: Prevent inline options browsers from continuing to grow after certain rounding errors. r=aswan MozReview-Commit-ID: Q2DVZ7iR7N
toolkit/components/extensions/ext-browser-content.js
--- a/toolkit/components/extensions/ext-browser-content.js
+++ b/toolkit/components/extensions/ext-browser-content.js
@@ -245,19 +245,35 @@ const BrowserListener = {
       // If we're in a fixed-width area (namely a slide-in subview of the main
       // menu panel), we need to calculate the view height based on the
       // preferred height of the content document's root scrollable element at the
       // current width, rather than the complete preferred dimensions of the
       // content window.
 
       // Compensate for any offsets (margin, padding, ...) between the scroll
       // area of the body and the outer height of the document.
+      // This calculation is hard to get right for all cases, so take the lower
+      // number of the combination of all padding and margins of the document
+      // and body elements, or the difference between their heights.
       let getHeight = elem => elem.getBoundingClientRect(elem).height;
       let bodyPadding = getHeight(doc.documentElement) - getHeight(body);
 
+      if (body !== doc.documentElement) {
+        let bs = content.getComputedStyle(body);
+        let ds = content.getComputedStyle(doc.documentElement);
+
+        let p = (parseFloat(bs.marginTop) +
+                 parseFloat(bs.marginBottom) +
+                 parseFloat(ds.marginTop) +
+                 parseFloat(ds.marginBottom) +
+                 parseFloat(ds.paddingTop) +
+                 parseFloat(ds.paddingBottom));
+        bodyPadding = Math.min(p, bodyPadding);
+      }
+
       let height = Math.ceil(body.scrollHeight + bodyPadding);
 
       result = {height, detail};
     } else {
       let background = doc.defaultView.getComputedStyle(body).backgroundColor;
       if (!isOpaque(background)) {
         // Ignore non-opaque backgrounds.
         background = null;