Bug 1424835: Prevent inline options browsers from continuing to grow after certain rounding errors. r?aswan draft
authorKris Maglione <maglione.k@gmail.com>
Fri, 15 Dec 2017 11:55:52 -0600
changeset 712088 d984d4769a581326fd30e9b7ad21a92b877b7706
parent 712087 0f4d988bd1c16bcea919d3d368b3e49d1a70b3f5
child 743976 de0a8895155db944130f98fc41836047e8417909
push id93252
push usermaglione.k@gmail.com
push dateFri, 15 Dec 2017 17:56:29 +0000
reviewersaswan
bugs1424835
milestone59.0a1
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;