Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calculate correct documentHeight for short AMP docs #12229

Merged
merged 2 commits into from
Dec 4, 2017

Conversation

peterjosling
Copy link
Contributor

@peterjosling peterjosling commented Nov 28, 2017

Handles the edge case of AMP documents which are shorter than their
containing viewport, which causes documentHeight to be scrollHeight,
which is the height of the viewport. Should be a no-op for docs which
are already taller than the viewport.

Re-implements changes made in ac741f6, which were reverted before merging.

Fixes #12172

// Body is overflow: hidden so that the scrollHeight include the margins of
// body's first and last child.
const rect = this.win.document.body./*OK*/getBoundingClientRect();
return rect.height + rect.top + this.getScrollTop();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you confirm what this does? Why would scroll top be needed here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the comment to clarify.

I couldn't think of a better way to get the scrollTop back out of the DOM - offsetTop for the body is zero, and reading paddingTop out of the html element's style is messy. Alternatively could store paddingTop when setPaddingTop() is called and add it on here? This method is more generic though - would work with e.g. marginTop on body instead of paddingTop on html.

Peter Josling added 2 commits December 4, 2017 11:34
Handles the edge case of AMP documents which are shorter than their
containing viewport, which causes documentHeight to be scrollHeight,
which is the height of the viewport. Should be a no-op for docs which
are already taller than the viewport.

Re-implements changes made in
ampproject@ac741f6,
which were reverted before merging.
Non-HTML5 doctype has different behaviour for html/body element heights
in Safari.
@ampprojectbot ampprojectbot added this to the Pending Triage milestone Dec 4, 2017
@jridgewell jridgewell merged commit 8b59867 into ampproject:master Dec 4, 2017
@peterjosling peterjosling deleted the short_document_fix branch December 5, 2017 12:00
ghost pushed a commit that referenced this pull request Dec 6, 2017
* Use contentHeight for documentHeight messages

Handles the edge case of AMP documents which are shorter than their
containing viewport, which causes documentHeight to be scrollHeight,
which is the height of the viewport. Should be a no-op for docs which
are already taller than the viewport.

Re-implements changes made in
ac741f6,
which were reverted before merging.

* Use HTML5 doctype for RealWinFixture

Non-HTML5 doctype has different behaviour for html/body element heights
in Safari.
gzgogo pushed a commit to gzgogo/amphtml that referenced this pull request Jan 26, 2018
* Use contentHeight for documentHeight messages

Handles the edge case of AMP documents which are shorter than their
containing viewport, which causes documentHeight to be scrollHeight,
which is the height of the viewport. Should be a no-op for docs which
are already taller than the viewport.

Re-implements changes made in
ampproject@ac741f6,
which were reverted before merging.

* Use HTML5 doctype for RealWinFixture

Non-HTML5 doctype has different behaviour for html/body element heights
in Safari.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants