Bug 145099 - [css-scroll-snap] Support masonry layouts and more advanced snappoint selection
Summary: [css-scroll-snap] Support masonry layouts and more advanced snappoint selection
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: Layout and Rendering (show other bugs)
Version: 528+ (Nightly build)
Hardware: All All
: P2 Normal
Assignee: Nobody
URL:
Keywords: InRadar
: 145157 (view as bug list)
Depends on: 219345 220765 220915 221030 227949
Blocks: 218115
  Show dependency treegraph
 
Reported: 2015-05-16 15:58 PDT by Brent Fulgham
Modified: 2021-07-22 01:41 PDT (History)
6 users (show)

See Also:


Attachments
Example Masonry Grid (10.71 KB, application/pdf)
2015-06-15 22:12 PDT, Brent Fulgham
no flags Details
Simple masonry example using overflow div (2.42 KB, text/html)
2015-06-16 14:22 PDT, Wenson Hsieh
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Brent Fulgham 2015-05-16 15:58:17 PDT
The existing two-axis scroll snap implementation works fine for a regular 2-dimensional grid, but fails if we want to support irregularly-shaped containers of elements (e.g., "Masonry-style layout").

To better accommodate this type of layout, we need to switch from disparate vectors of x and y snap points, and instead consider snap points as 2-dimensional entities.

The downside of this approach is that very large grids would consume much more memory (i.e, we go from 2N memory use to N^2). However, I doubt that we will encounter scroll snap documents of sufficient size for this to be a problem.
Comment 1 Radar WebKit Bug Importer 2015-05-16 15:58:54 PDT
<rdar://problem/20989900>
Comment 2 Sam Weinig 2015-05-17 12:06:17 PDT
(In reply to comment #0)
> The downside of this approach is that very large grids would consume much
> more memory (i.e, we go from 2N memory use to N^2). However, I doubt that we
> will encounter scroll snap documents of sufficient size for this to be a
> problem.

Scary statement! What does the N used above represent?
Comment 3 Brent Fulgham 2015-05-18 21:03:21 PDT
(In reply to comment #2)
> (In reply to comment #0)
> > The downside of this approach is that very large grids would consume much
> > more memory (i.e, we go from 2N memory use to N^2). However, I doubt that we
> > will encounter scroll snap documents of sufficient size for this to be a
> > problem.
> 
> Scary statement! What does the N used above represent?

N would be the number of elements contained inside the scroll region. E.g., if we had a grid of photos or something, N would be the number of images.
Comment 4 Brent Fulgham 2015-05-18 21:04:36 PDT
(In reply to comment #3)
> (In reply to comment #2)
> > (In reply to comment #0)
> > > The downside of this approach is that very large grids would consume much
> > > more memory (i.e, we go from 2N memory use to N^2). However, I doubt that we
> > > will encounter scroll snap documents of sufficient size for this to be a
> > > problem.
> > 
> > Scary statement! What does the N used above represent?
> 
> N would be the number of elements contained inside the scroll region. E.g.,
> if we had a grid of photos or something, N would be the number of images.

Just to be more precise, each 'N' would probably represent a pair of float values representing the "scroll-snap-coordinate" of the element.
Comment 5 Brent Fulgham 2015-05-19 09:06:38 PDT
Sam dropped by and helped me understand that my proposed data structure change would be at worst N, while our existing implementation is some smaller value proportional to the number of horizontal elements plus the number of vertical elements.
Comment 6 Brent Fulgham 2015-05-19 09:27:01 PDT
Note: The wording in the CSS Scroll Snap specification <http://dev.w3.org/csswg/css-snappoints/#propdef-scroll-snap-coordinate> indicates that we should support having multiple snap coordinates in a single element. To properly achieve this (without affecting other elements in the container) we will need to implement a data structure like I am proposing here.
Comment 7 Brent Fulgham 2015-06-15 22:12:23 PDT
Created attachment 254933 [details]
Example Masonry Grid
Comment 8 Wenson Hsieh 2015-06-16 14:22:15 PDT
Created attachment 254968 [details]
Simple masonry example using overflow div

HTML page resembling Brent's picture above. The current implementation computes snap offsets instead of actual points, producing extra snap points.
Comment 9 Martin Robinson 2021-07-07 07:17:02 PDT
Renaming this bug to reference handling masonry layouts. There are two pieces to this:

 * Not selecting snap points when a scroll wouldn't bring its snap area onscreen.
 * When a bidirectional scroll chooses two incompatible snap points for the x and y axis, choosing the snap point that is the shortest distance away from the original scroll position.
Comment 10 Martin Robinson 2021-07-07 07:18:13 PDT
*** Bug 145157 has been marked as a duplicate of this bug. ***