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

[css-scroll-anchoring] [css-scroll-snap] What's the optimal viewing rect on the root scroller? #4393

Closed
emilio opened this issue Oct 2, 2019 · 12 comments · Fixed by nickburris/csswg-drafts#1 or #4776
Labels
Closed Accepted by CSSWG Resolution Commenter Satisfied Commenter has indicated satisfaction with the resolution / edits. css-scroll-anchoring-1 css-scroll-snap-1 Current Work

Comments

@emilio
Copy link
Collaborator

https://drafts.csswg.org/css-scroll-snap-1/#optimal-viewing-region

Firefox uses the visual viewport. Blink (if my read of their code is correct) uses the layout viewport (I think?).

The spec is unclear. It says "the scrollport".

See https://bugzilla.mozilla.org/show_bug.cgi?id=1585317#c4 for context.

If it should use the visual viewport, then scroll-padding should in theory resolve against that, rather than the layout viewport... right?

cc: @tabatkins @fantasai @bokand @skobes

@bokand
Copy link
Contributor

+@majido

IIRC Blink does use the layout viewport. I don't really see the use case for snapping to the visual viewport and using the layout viewport makes it more intuitive and simpler to reason about for web developers, IMHO.

@bokand
Copy link
Contributor

Erm, never mind my comment above, snapping the visual viewport makes quite a bit of sense.

I think your understanding in Blink is correct and the behavior is a bit inconsistent; Blink uses the layout viewport as the optimal viewing region (at least, scroll-padding and the like is resolved against it) but it scrolls the visual viewport when snapping.

If it should use the visual viewport, then scroll-padding should in theory resolve against that, rather than the layout viewport... right?

I think that'd be more intuitive, yes, but that means that zooming in and out would have to invalidate style, right?

@emilio
Copy link
Collaborator Author

I think that'd be more intuitive, yes, but that means that zooming in and out would have to invalidate style, right?

Percentages are not resolved during styling, only during layout... So it'd have to invalidate layout, I guess.

@theres-waldo
Copy link
Contributor

Note, this came up for us in the context of scroll anchoring, which also uses the "optimal viewing region".

We have scoll anchoring choose an anchor node in the visual viewport, because otherwise content in the visual viewport could actually shift even as we keep a node that's inside the layout viewport (but outside the visual viewport) anchored.

@emilio emilio changed the title [css-scroll-anchoring] [css-scroll-anchoring] What's the optimal viewing rect on the root scroller? [css-scroll-anchoring] [css-scroll-snap] What's the optimal viewing rect on the root scroller? Oct 3, 2019
@tabatkins
Copy link
Member

I wonder if we want to define the "scrollport" to be the visual viewport when talking about the root scroller, or if it should remain the layout viewport (which I think is what the current definition says) and we should define another term which does use the visual viewport?

@fantasai
Copy link
Collaborator

I'd agree that snapping should be resolved against the visual viewport: the whole point is to get the thing in view. However, I suspect scroll-padding should resolve against the layout viewport: a lot of its use cases are around avoiding certain fixed-positioned content, for example, and that resolves against the layout viewport if I'm understanding things correctly.

@fantasai
Copy link
Collaborator

Proposal is to clarify that snapping is to the visual viewport, but percentage values resolve against the layout viewport.

@css-meeting-bot
Copy link
Member

The CSS Working Group just discussed What's the optimal viewing rect on the root scroller?, and agreed to the following:

  • RESOLVED: Use visual viewport for snapping and layout viewport for scroll-padding percentages.
The full IRC log of that discussion <heycam> Topic: What's the optimal viewing rect on the root scroller?
<heycam> github: https://github.com//issues/4393
<heycam> emilio: while working through some scroll anchoring issues
<heycam> ... you need to decide what rect to anchor stuff to
<heycam> ... Firefox uses visual viewport, I think Blink uses layout viewport
<heycam> ... but are kind of reasonable
<heycam> ... but for layout viewport, need to decide the effect of padding etc.
<heycam> fantasai: my proposal is to use visual viewport, but that %s on the scroll-padding reference the layout viewport
<heycam> s/of padding/of scroll-padding/
<heycam> ... that's where you're likely to block out content
<heycam> TabAtkins: if we snap in the visual viewport, and you bring up the keyboard, it has to move?
<heycam> jensimmons: it depends
<heycam> fantasai: can leave that to the UA
<heycam> TabAtkins: sounds complicated, but I think that's the best route
<heycam> emilio: I think it's pretty reasonable
<heycam> iank_: seems like David is fine with this change
<heycam> fantasai: sounds like Blink is doing that
<fantasai> https://github.com//issues/4393#issuecomment-537844295
<heycam> Rossen: currently using the layout viewport, but if you're zoomed in you're not snapped at all
<heycam> iank_: but sounds like David Bokand is fine to switch to the visual viewport?
<heycam> s/Bokand/Bokan/
<heycam> RESOLVED: Use visual viewport for snapping and layout viewport for scroll-padding percentages.

xeonchen pushed a commit to xeonchen/gecko that referenced this issue Jan 26, 2020
moz-v2v-gh pushed a commit to mozilla/gecko-dev that referenced this issue Jan 26, 2020
…choring even when visual viewport is used. r=botond

Per w3c/csswg-drafts#4393.

Differential Revision: https://phabricator.services.mozilla.com/D60693

--HG--
extra : moz-landing-system : lando
gecko-dev-updater pushed a commit to marco-c/gecko-dev-comments-removed that referenced this issue Jan 28, 2020
…choring even when visual viewport is used. r=botond

Per w3c/csswg-drafts#4393.

Differential Revision: https://phabricator.services.mozilla.com/D60693

UltraBlame original commit: c18ff86c37f78df03bbf3d590bf7c55530f2a0dc
gecko-dev-updater pushed a commit to marco-c/gecko-dev-wordified that referenced this issue Jan 28, 2020
…choring even when visual viewport is used. r=botond

Per w3c/csswg-drafts#4393.

Differential Revision: https://phabricator.services.mozilla.com/D60693

UltraBlame original commit: c18ff86c37f78df03bbf3d590bf7c55530f2a0dc
nickburris added a commit to nickburris/csswg-drafts that referenced this issue Feb 14, 2020
[css-scroll-snap] Clarify scroll-padding scrollport (w3c#4393)
@nickburris
Copy link
Member

Note that the css-overflow spec seems clear that the scrollport is the visual viewport. I opened #4776 clarifying scroll-padding for the root scroller.

chrishtr added a commit that referenced this issue Feb 14, 2020
[css-scroll-snap] Clarify scroll-padding scrollport (#4393)
fantasai added a commit that referenced this issue Dec 11, 2020
…elements and scroll-padding, since that was the goal, and UAs do fiddly things with fixedpos on mobile. #4393
@fantasai
Copy link
Collaborator

Adjusted the edits to be a bit more precise, resulting in the following text:

When applied to the root viewport, the offset is calculated and applied relative to the layout viewport (rather than the visual viewport) the same way as the corresponding inset properties on fixed-positioned boxes; the optimal viewing region is the remaining area that intersects with the visual viewport.

@emilio @bokand @theres-waldo @nickburris Does this seem clear and reasonable to you?

@theres-waldo
Copy link
Contributor

That seems clear, thanks.

I think it's also a reasonable choice. The alternative I can think of would be to calculate the offset relative to the layout viewport but apply it relative to the visual viewport, which would have the (significant) downside that the optimal viewing region could be very small or even empty at high zoom levels.

@bokand
Copy link
Contributor

+1 that looks good to me, thanks!

@fantasai fantasai added the Commenter Satisfied Commenter has indicated satisfaction with the resolution / edits. label Jan 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Closed Accepted by CSSWG Resolution Commenter Satisfied Commenter has indicated satisfaction with the resolution / edits. css-scroll-anchoring-1 css-scroll-snap-1 Current Work
Projects
None yet
7 participants