Contact emails
bo...@chromium.org, yma...@chromium.org
Spec
Currently, there is no spec for exposing the visual viewport to the web. A part of the work here is to have one.
Summary
Add an API to expose visual viewport information to the Web.
The current proposal (which we will probably iterate on) is to add a viewport object on document.scrollingElement.
viewport = {
double scrollTop; // Relative to the layout viewport
double scrollLeft; // and writable.
double clientWidth; // Read-only and excludes the scrollbars
double clientHeight; // if present.
double pageScale;
}
See this doc for more details.
Motivation
In the current state of things, CSSOM scroll properties are relative to the visual viewport (see this for list). There is no spec governing this, but this is how browsers have it implemented today. With this implementation, the dimensions of the visual viewport can be easily determined (For example, window.innerHeight = visual viewport height).
Though, having CSSOM scroll properties relative to the visual viewport breaks many sites under pinch-zoom (see crbug.com/489206) . Because pinch-zoom was intended to be more for legacy websites and we had little insights as to why a developer would need to know the visual viewport dimensions, it was concluded that it would be a fairly low-risk change to make it invisible to developers. In addition to this, the failure mode of the change would be user friendly since things that would react to pinch zoom would stay static, which in many/most cases would feel like the intuitive zoom behaviour to the user.
M48 shipped a change that made these CSSOM properties relative to the layout viewport (Intent to ship). This change had to be reverted because more than anticipated sites were relying on it. For example, one legitimate use case was that of a screen casting app, that would cast the viewport content (see crbug.com/571297 for more examples).
From all the developer feedback, it’s clear that the visual viewport information needs to be exposed to developers.
Interoperability Risk
Firefox and safari have a different pinch to zoom model.
Edge follows the same model as Chrome and moving forward, we would like to get their feedback on this and have them implement it as well.
Compatibility Risk
Low because this is a new API and we’re not breaking any compatability.
Will this feature be supported on all six Blink platforms (Windows, Mac, Linux, Chrome OS, Android, and Android WebView)?
Yes.
OWP launch tracking bug
Requesting approval to ship?
No
I think it could be a good idea to send this proposal to www-...@w3.org with [cssom-view] in the subject, or file a bug[1] so the CSSWG can evaluate the proposal and give feedback and, when the timing is right, we can put it in the CSSOM View spec (and fix whatever else needs fixing in CSSOM View, like window.innerHeight).
[1] https://www.w3.org/Bugs/Public/enter_bug.cgi?product=CSS&component=CSSOM%20View
Any element can be the documentElement, that means you're extending the global interface to have a concept of viewport which doesn't seem right. Having this property on thousands of elements but only ever non-null on a single one per page (for the lifetime of the page) is very strange. Especially since if I remove the documentElement there still is a viewport.