Bug 218076

Summary: Make scroll-margin independent of scroll snapping and have it apply when scrolling to anchors
Product: WebKit Reporter: Martin Robinson <mrobinson>
Component: CSSAssignee: Martin Robinson <mrobinson>
Status: RESOLVED FIXED    
Severity: Normal CC: cdumez, changseok, cmarcelo, dev, esprehn+autocc, ews-watchlist, fred.wang, glenn, kangil.han, kondapallykalyan, pdr, rego, simon.fraser, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
See Also: https://bugs.webkit.org/show_bug.cgi?id=218358
Bug Depends on:    
Bug Blocks: 189265    
Attachments:
Description Flags
Patch
none
Patch
ews-feeder: commit-queue-
Patch
none
Patch
none
Patch none

Description Martin Robinson 2020-10-22 03:45:35 PDT
The latest version of the CSS Scroll Snap specification says that scroll-margin should be available independently of scroll snap and it should apply when scrolling to anchors and targets of scrollIntoView(). See https://drafts.csswg.org/css-scroll-snap-1/#scroll-margin.
Comment 1 Martin Robinson 2020-10-28 04:50:15 PDT
Created attachment 412517 [details]
Patch
Comment 2 Martin Robinson 2020-10-28 05:07:33 PDT
Created attachment 412519 [details]
Patch
Comment 3 Martin Robinson 2020-10-28 06:26:51 PDT
Created attachment 412524 [details]
Patch
Comment 4 Simon Fraser (smfr) 2020-10-28 09:29:14 PDT
Comment on attachment 412524 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=412524&action=review

> Source/WebCore/rendering/RenderBox.cpp:5070
> +    const LayoutSize boxSize = size();
> +    const LayoutBoxExtent margin(
> +        valueForLength(scrollMargin.top(), boxSize.height()),
> +        valueForLength(scrollMargin.right(), boxSize.width()),
> +        valueForLength(scrollMargin.bottom(), boxSize.height()),
> +        valueForLength(scrollMargin.left(), boxSize.width()));
> +    anchorRect.expand(margin);

This doesn't take into account transforms in the ancestor chain. Seems like you need to take margins into account before the localToAbsolute computation, I think? What's the expected behavior with transforms?
Comment 5 Martin Robinson 2020-10-28 09:33:17 PDT
(In reply to Simon Fraser (smfr) from comment #4)
> Comment on attachment 412524 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=412524&action=review
> 
> > Source/WebCore/rendering/RenderBox.cpp:5070
> > +    const LayoutSize boxSize = size();
> > +    const LayoutBoxExtent margin(
> > +        valueForLength(scrollMargin.top(), boxSize.height()),
> > +        valueForLength(scrollMargin.right(), boxSize.width()),
> > +        valueForLength(scrollMargin.bottom(), boxSize.height()),
> > +        valueForLength(scrollMargin.left(), boxSize.width()));
> > +    anchorRect.expand(margin);
> 
> This doesn't take into account transforms in the ancestor chain. Seems like
> you need to take margins into account before the localToAbsolute
> computation, I think? What's the expected behavior with transforms?

I was a bit surprised by this at first, but, unless I am misunderstanding, it seems like this margin should be added in the coordinate system of the scroll container. The scroll-margin spec [1] says:

"Values represent outsets defining the scroll snap area that is used for snapping this box to the snapport. The scroll snap area is determined by taking the transformed border box, finding its rectangular bounding box (axis-aligned in the scroll container’s coordinate space), then adding the specified outsets."

1. https://drafts.csswg.org/css-scroll-snap-1/#scroll-margin
Comment 6 Simon Fraser (smfr) 2020-10-28 09:47:06 PDT
Comment on attachment 412524 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=412524&action=review

>>> Source/WebCore/rendering/RenderBox.cpp:5070
>>> +    anchorRect.expand(margin);
>> 
>> This doesn't take into account transforms in the ancestor chain. Seems like you need to take margins into account before the localToAbsolute computation, I think? What's the expected behavior with transforms?
> 
> I was a bit surprised by this at first, but, unless I am misunderstanding, it seems like this margin should be added in the coordinate system of the scroll container. The scroll-margin spec [1] says:
> 
> "Values represent outsets defining the scroll snap area that is used for snapping this box to the snapport. The scroll snap area is determined by taking the transformed border box, finding its rectangular bounding box (axis-aligned in the scroll container’s coordinate space), then adding the specified outsets."
> 
> 1. https://drafts.csswg.org/css-scroll-snap-1/#scroll-margin

Huh, I guess that's clear. Probably add a comment linking to that then.
Comment 7 Martin Robinson 2020-10-29 01:40:57 PDT
Created attachment 412625 [details]
Patch
Comment 8 Radar WebKit Bug Importer 2020-10-29 03:46:16 PDT
<rdar://problem/70803885>
Comment 9 Martin Robinson 2020-10-29 03:51:45 PDT
Created attachment 412631 [details]
Patch
Comment 10 EWS 2020-10-29 04:02:16 PDT
mrobinson@webkit.org does not have committer permissions according to https://svn.webkit.org/repository/webkit/trunk/Tools/Scripts/webkitpy/common/config/contributors.json.

Rejecting attachment 412631 [details] from commit queue.
Comment 11 EWS 2020-10-29 04:37:25 PDT
Committed r269144: <https://trac.webkit.org/changeset/269144>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 412631 [details].
Comment 12 dakur 2020-10-29 05:16:29 PDT
Thank you guys very much for finally quick fix! Any ideas when it may land in user lands?