WICG / visual-viewport

A proposal to add explicit APIs to the Web for querying and setting the visual viewport
https://wicg.github.io/visual-viewport/
MIT License
177 stars 28 forks source link

scale shouldn't be spec'd as relative to the ideal viewport #13

Closed ChumpChief closed 7 years ago

ChumpChief commented 8 years ago

If the developer has modified the layout viewport size (e.g. meta viewport with width=1024 on a device where device-width would have been 384), pageScale should probably reflect the ratio against that adjusted viewport rather than the ideal viewport.

So I think this should instead use "layout viewport", though I'd be interested to make sure we're on the same page with the nastier cases you called out with wide elements and min-scale.

bokand commented 8 years ago

I think our hands are kind of tied here as it'd be very confusing if the pageScale in visualViewport wasn't the same as the minimum|maximum|initial-zoom in the viewport .

bokand commented 7 years ago

I listed some counter-arguments in Issue 35 but I'll sum up my thoughts here.

There's three arguments for keeping the status quo to me:

There's use cases for "relative-to-layout" too, but given that it's easy enough to convert between the two I think it makes more sense to stick with the existing interpretation of scale. WDYT?

bokand commented 7 years ago

As another data point, see the use case in #23

bokand commented 7 years ago

@ChumpChief, WDYT about keeping it relative to ideal? I'd like to ship this in the next Chrome release to branch so I'd like to close out all the issues that would be difficult to change after shipping.

hexalys commented 7 years ago

One thought:

How would you assess what's the ideal viewport-width in split mode/view context? (e.g. iPad). Is ideal the outerWidth or the device-width? I wouldn't want an incorrect scale for that context.

bokand commented 7 years ago

The ideal viewport width in that case would be window-physical-width / window.devicePixelRatio. That is, it should work correctly even in a split mode or in a desktop window. Intuitively, it's just the window size without any pinch-zoom scaling applied (but accounting for browser-zoom and OS level UI zooming).

hexalys commented 7 years ago

I guess that works, as long as window.outerWidthand window.outerHeight are made standard across browsers, reporting the css pixel size at scale=1. At the moment, iOS still wrongly reports outerWidth/Height at 0, and both Firefox and IE include zoom scale to the window, unlike Safari & Chrome Desktop. But that's to address at spec level, and with Firefox+Edge, relating to lack of "desktop browser zoom" properties...

But FWIW, 'relative-to-layout' doesn't really change or affect the more common 'relative-to-ideal' cases. There are technically the same until the viewport is changed to other than device-width. For my use cases, I typically change the viewport dynamically after a read on initial values. So either way works. However, if an author has a static 'non-device-width' from the start, 'relative-to-ideal' could become problematic. Or even in my case, i'd prefer relying on the sub-pixel precision scale of the API in 'layout' terms as opposed to having to calculate it in a much less reliable manner (w/less sub-pixel accuracy).

bokand commented 7 years ago

However, if an author has a static 'non-device-width' from the start, 'relative-to-ideal' could become problematic. Or even in my case, i'd prefer relying on the sub-pixel precision scale of the API in 'layout' terms as opposed to having to calculate it in a much less reliable manner (w/less sub-pixel accuracy).

If you know the layout width then you can calculate the 'relative-to-layout' scale, it's easy enough to go to the 'relative-to-layout' scale: layoutScale = layoutWidth / view.width so I see this as a matter of which is more useful for the majority of use cases.

I see the main use case here as implementing position: device-fixed and other cases where you want to be independent of zoom. I think 'relative-to-layout' is strictly less useful for these cases because sizing things to the layout size is already easy to do (i.e. CSS width = 100vw).

bokand commented 7 years ago

I'm going to send out the intent-to-ship in Chrome tomorrow so I'll close this for the reasons I listed above and because it's easy to convert to relative-to-layout if desired. Please speak up ASAP if you strongly object to this.