Skip to content

Commit

Permalink
Update contentHeight algorithms
Browse files Browse the repository at this point in the history
  • Loading branch information
jridgewell committed Dec 21, 2018
1 parent 00c31b1 commit 900c211
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 24 deletions.
14 changes: 6 additions & 8 deletions src/service/viewport/viewport-binding-ios-embed-sd.js
Original file line number Diff line number Diff line change
Expand Up @@ -396,15 +396,13 @@ export class ViewportBindingIosEmbedShadowRoot_ {

/** @override */
getContentHeight() {
// The reparented body inside scroller will have the correct content height.
// Body is overflow: hidden so that the scrollHeight include the margins of
// body's first and last child.
// Body height doesn't include paddingTop on the parent, so we add on the
// position of the body from the top of the viewport and subtract the
// scrollTop (as position relative to the viewport changes as you scroll).
return this.wrapper_./*OK*/scrollHeight
const scrollingElement = this.wrapper_;
const style = getComputedStyle(scrollingElement);
return scrollingElement./*OK*/scrollHeight
+ this.paddingTop_
+ this.getBorderTop();
+ this.getBorderTop()
+ parseInt(style.marginTop, 10)
+ parseInt(style.marginBottom, 10);
}

/** @override */
Expand Down
14 changes: 6 additions & 8 deletions src/service/viewport/viewport-binding-ios-embed-wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,14 +234,12 @@ export class ViewportBindingIosEmbedWrapper_ {

/** @override */
getContentHeight() {
// The reparented body inside wrapper will have the correct content height.
// Body is overflow: hidden so that the scrollHeight include the margins of
// body's first and last child.
// Body height doesn't include paddingTop on the parent, so we add on the
// position of the body from the top of the viewport and subtract the
// scrollTop (as position relative to the viewport changes as you scroll).
const rect = this.win.document.body./*OK*/getBoundingClientRect();
return rect.height + rect.top + this.getScrollTop();
const scrollingElement = this.wrapper_;
const style = getComputedStyle(scrollingElement);
return scrollingElement./*OK*/scrollHeight
+ this.getBorderTop()
+ parseInt(style.marginTop, 10)
+ parseInt(style.marginBottom, 10);
}

/** @override */
Expand Down
13 changes: 5 additions & 8 deletions src/service/viewport/viewport-binding-natural.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,14 +195,11 @@ export class ViewportBindingNatural_ {

/** @override */
getContentHeight() {
// The reparented body inside wrapper will have the correct content height.
// Body is overflow: hidden so that the scrollHeight include the margins of
// body's first and last child.
// Body height doesn't include paddingTop on the parent, so we add on the
// position of the body from the top of the viewport and subtract the
// scrollTop (as position relative to the viewport changes as you scroll).
const rect = this.win.document.body./*OK*/getBoundingClientRect();
return rect.height + rect.top + this.getScrollTop();
const scrollingElement = this.getScrollingElement();
const style = getComputedStyle(scrollingElement);
return scrollingElement./*OK*/scrollHeight
+ parseInt(style.marginTop, 10)
+ parseInt(style.marginBottom, 10);
}

/** @override */
Expand Down

0 comments on commit 900c211

Please sign in to comment.