Bug 1424835: Prevent inline options browsers from continuing to grow after certain rounding errors. r?aswan
MozReview-Commit-ID: Q2DVZ7iR7N
--- 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;