Bug 221030

Summary: Make closestSnapOffset a method on ScrollSnapOffsetsInfo
Product: WebKit Reporter: Martin Robinson <mrobinson>
Component: ScrollingAssignee: Martin Robinson <mrobinson>
Status: RESOLVED FIXED    
Severity: Normal CC: cmarcelo, ews-watchlist, fred.wang, jamesr, luiz, simon.fraser, tonikitoo, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
Bug Depends on:    
Bug Blocks: 145099    
Attachments:
Description Flags
Patch
ews-feeder: commit-queue-
Patch
ews-feeder: commit-queue-
Patch
none
Patch
ews-feeder: commit-queue-
Patch none

Description Martin Robinson 2021-01-27 02:55:53 PST
ScrollSnapOffsetsInfo has all the information it needs to implement this method and this will prevent callers from having to pull out the horizontal and vertical offsets and offset ranges themselves.
Comment 1 Martin Robinson 2021-01-27 03:09:37 PST
Created attachment 418521 [details]
Patch
Comment 2 Martin Robinson 2021-01-27 03:33:48 PST
Created attachment 418523 [details]
Patch
Comment 3 Martin Robinson 2021-01-27 04:07:16 PST
Created attachment 418527 [details]
Patch
Comment 4 Simon Fraser (smfr) 2021-01-27 10:47:42 PST
Comment on attachment 418527 [details]
Patch

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

> Source/WebCore/page/scrolling/ScrollSnapOffsetsInfo.cpp:369
> +template <>
> +LayoutUnit ScrollSnapOffsetsInfo<LayoutUnit>::closestSnapOffset(ScrollEventAxis axis, LayoutUnit scrollDestinationOffset, float velocity, unsigned& activeSnapIndex, Optional<LayoutUnit> originalPositionForDirectionalSnapping) const
> +{

Would be nicer if these returned a std::pair<LayoutUnit, unsigned>

> Source/WebCore/page/scrolling/ScrollSnapOffsetsInfo.cpp:370
> +    return ::WebCore::closestSnapOffset(offsetsForAxis(axis), offsetRangesForAxis(axis), scrollDestinationOffset, velocity, activeSnapIndex, originalPositionForDirectionalSnapping);

Is the leading :: really necessary?
Comment 5 Martin Robinson 2021-01-28 04:09:18 PST
Created attachment 418636 [details]
Patch
Comment 6 Martin Robinson 2021-01-28 04:12:47 PST
(In reply to Simon Fraser (smfr) from comment #4)
> Comment on attachment 418527 [details]
> Patch

Thanks for the review.

> > Source/WebCore/page/scrolling/ScrollSnapOffsetsInfo.cpp:369
> > +template <>
> > +LayoutUnit ScrollSnapOffsetsInfo<LayoutUnit>::closestSnapOffset(ScrollEventAxis axis, LayoutUnit scrollDestinationOffset, float velocity, unsigned& activeSnapIndex, Optional<LayoutUnit> originalPositionForDirectionalSnapping) const
> > +{
> 
> Would be nicer if these returned a std::pair<LayoutUnit, unsigned>

I've done this and have used c++17 structured binding at all call sites and std::tie in places that I was not able to.

> 
> > Source/WebCore/page/scrolling/ScrollSnapOffsetsInfo.cpp:370
> > +    return ::WebCore::closestSnapOffset(offsetsForAxis(axis), offsetRangesForAxis(axis), scrollDestinationOffset, velocity, activeSnapIndex, originalPositionForDirectionalSnapping);
> 
> Is the leading :: really necessary?

I'm not sure, but I went ahead and renamed the free function to closestSnapOffsetWithOffetsAndRanges so that the namespace specifier isn't necessary at all now. This also makes the code a bit clearer, I think.
Comment 7 Martin Robinson 2021-01-28 04:29:37 PST
Created attachment 418638 [details]
Patch
Comment 8 EWS 2021-01-28 10:32:33 PST
Committed r272019: <https://trac.webkit.org/changeset/272019>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 418638 [details].
Comment 9 Radar WebKit Bug Importer 2021-01-28 10:33:18 PST
<rdar://problem/73714375>