Bug 972359 - Australis - use margins and border for measuring panel heights to avoid unnecessary scrollbars, r=mconley

--HG--
extra : rebase_source : b43a21a0008c5c6270cb7a8b2c2fefacbb590703
This commit is contained in:
Gijs Kruitbosch 2014-02-24 17:29:02 +00:00
parent eef885e2af
commit 11897b4d14

View File

@ -217,7 +217,7 @@
this._transitioning = false;
}.bind(this));
let newHeight = this._heightOfSubview(viewNode);
let newHeight = this._heightOfSubview(viewNode, this._subViews);
this._viewContainer.style.height = newHeight + "px";
this._subViewObserver.observe(viewNode, {
@ -324,7 +324,7 @@
<method name="_syncContainerWithSubView">
<body><![CDATA[
if (!this.ignoreMutations && this.showingSubView) {
let newHeight = this._heightOfSubview(this._currentSubView);
let newHeight = this._heightOfSubview(this._currentSubView, this._subViews);
this._viewContainer.style.height = newHeight + "px";
}
]]></body>
@ -345,16 +345,50 @@
<method name="_heightOfSubview">
<parameter name="aSubview"/>
<parameter name="aContainerToCheck"/>
<body><![CDATA[
function getFullHeight(element) {
//XXXgijs: unfortunately, scrollHeight rounds values, and there's no alternative
// that works with overflow: auto elements. Fortunately for us,
// we have exactly 1 (potentially) scrolling element in here (the subview body),
// and rounding 1 value is OK - rounding more than 1 and adding them means we get
// off-by-1 errors. Now we might be off by a subpixel, but we care less about that.
// So, use scrollHeight *only* if the element is vertically scrollable.
let height;
let elementCS;
if (element.scrollTopMax) {
height = element.scrollHeight;
// Bounding client rects include borders, scrollHeight doesn't:
elementCS = win.getComputedStyle(element);
height += parseFloat(elementCS.borderTopWidth) +
parseFloat(elementCS.borderBottomWidth);
} else {
height = element.getBoundingClientRect().height;
if (height > 0) {
elementCS = win.getComputedStyle(element);
}
}
if (elementCS) {
// Include margins - but not borders or paddings because they
// were dealt with above.
height += parseFloat(elementCS.marginTop) + parseFloat(elementCS.marginBottom);
}
return height;
}
let win = aSubview.ownerDocument.defaultView;
let body = aSubview.querySelector(".panel-subview-body");
let height = body ? body.scrollHeight : aSubview.scrollHeight;
let height = getFullHeight(body || aSubview);
if (body) {
let header = aSubview.querySelector(".panel-subview-header");
let footer = aSubview.querySelector(".panel-subview-footer");
height += (header ? header.scrollHeight : 0) +
(footer ? footer.scrollHeight : 0);
height += (header ? getFullHeight(header) : 0) +
(footer ? getFullHeight(footer) : 0);
}
return height;
if (aContainerToCheck) {
let containerCS = win.getComputedStyle(aContainerToCheck);
height += parseFloat(containerCS.paddingTop) + parseFloat(containerCS.paddingBottom);
}
return Math.round(height);
]]></body>
</method>