Skip to content

Commit 36f0586

Browse files
emiliont1m
authored andcommitted
[css-scroll-snap] [cssom-view] Use a single scroll queue for all events
Fixes #11164
1 parent b735329 commit 36f0586

File tree

2 files changed

+53
-78
lines changed

2 files changed

+53
-78
lines changed

css-scroll-snap-2/Overview.bs

Lines changed: 12 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -345,9 +345,6 @@ Snap Targets</h4>
345345
scrolling operation also results in a {{scrollsnapchange}} event being fired, the
346346
{{scrollsnapchange}} event should be fired before the {{scrollend}} event.
347347

348-
Each {{Document}} has an associated list of
349-
<dfn export for=Document>pending scrollsnapchange event targets</dfn>, initially empty.
350-
351348
Each
352349
<a spec=css-scroll-snap lt="scroll snap container">snap container</a> has
353350
one <dfn export>scrollsnapchangeTargetBlock</dfn> and one
@@ -378,32 +375,17 @@ Snap Targets</h4>
378375
<var>inlineScrollSnapchangingTarget</var>.
379376
1. Set <var>snap targets changed</var> to true.
380377
1. If <var>snap targets changed</var> is true:
381-
1. If |snapcontainer| is not already in <var>doc</var>'s
382-
<a>pending scrollsnapchange event targets</a>:
383-
1. Append |snapcontainer| to <var>doc</var>'s
384-
<a>pending scrollsnapchange event targets</a>.
378+
1. If (|snapcontainer|, <code>"scrollsnapchange"</code>) is not already in <var>doc</var>'s
379+
<a>pending scroll events</a>:
380+
1. Append (|snapcontainer|, <code>"scrollsnapchange"</code>) to <var>doc</var>'s
381+
<a>pending scroll events</a>.
385382

386383
Note: When snapping occurs on a scroller (either due to a layout change or a
387384
scrolling operation) the <a>scrollsnapchanging block-axis target</a> and <a>scrollsnapchanging inline-axis target</a>
388385
associated with that scroller are updated and represent the current snap targets
389386
of that scroller. This allows the <a>update scrollsnapchange targets</a> algorithm
390387
to use these [=snap targets=] to determine whether a {{scrollsnapchange}} event should be fired.
391388

392-
When asked to <dfn export for=Document>dispatch pending scrollsnapchange events</dfn> for a {{Document}},
393-
<var>doc</var>, run these steps:
394-
1. For each item <var>target</var> in |doc|'s <a>pending scrollsnapchange event targets</a>:
395-
1. Let |blockTarget| and |inlineTarget| be null initially.
396-
1. If the <a>scrollsnapchangeTargetBlock</a> associated with <var>target</var> is a pseudo-element,
397-
set |blockTarget| to the owning element of that <a>scrollsnapchangeTargetBlock</a>.
398-
1. Otherwise, set |blockTarget| to that <a>scrollsnapchangeTargetBlock</a>.
399-
1. If the <a>scrollsnapchangeTargetInline</a> associated with <var>target</var> is a pseudo-element,
400-
set |inlineTarget| to the owning element of that <a>scrollsnapchangeTargetInline</a>.
401-
1. Otherwise, Set |inlineTarget| to that <a>scrollsnapchangeTargetInline</a>.
402-
1. Fire a {{SnapEvent}}, |snapevent|, named {{scrollsnapchange}} at <var>target</var>
403-
and let |snapevent|'s {{SnapEvent/snapTargetBlock}} and
404-
{{SnapEvent/snapTargetInline}} attributes be |blockTarget| and |inlineTarget| respectively.
405-
1. Empty <var>doc</var>'s <a>pending scrollsnapchange event targets</a>.
406-
407389
<h4 id="scrollsnapchanging"> scrollsnapchanging </h4>
408390
{{scrollsnapchanging}} is dispatched:
409391
* during a scrolling operation, if the [=snap targets=] to which a
@@ -437,12 +419,6 @@ Snap Targets</h4>
437419
will be possible for subsequent scrolling input to further alter the snap
438420
container's scroll position and result in a different eventual snap target.
439421

440-
441-
{{scrollsnapchanging}} events are fired before {{scroll!!event}} events.
442-
443-
Each {{Document}} has an associated list of
444-
<dfn export for=Document>pending scrollsnapchanging event targets</dfn>, initially empty.
445-
446422
Each
447423
<a spec=css-scroll-snap lt="scroll snap container">snap container</a> has
448424
one <dfn>scrollsnapchanging block-axis target</dfn>
@@ -463,32 +439,17 @@ Snap Targets</h4>
463439
1. If <var>newBlockTarget</var> is not the same [=snap target=] as <var>blockTarget</var>:
464440
1. Set the <a>scrollsnapchanging block-axis target</a> associated with |snapcontainer| to
465441
<var>newBlockTarget</var>.
466-
1. If |snapcontainer| is not already in <var>doc</var>'s
467-
<a>pending scrollsnapchanging event targets</a>,
468-
1. Append |snapcontainer| to <var>doc</var>'s
469-
<a>pending scrollsnapchanging event targets</a>
442+
1. If (|snapcontainer|, <code>"scrollsnapchanging"</code>) is not already in <var>doc</var>'s
443+
<a>pending scroll events</a>,
444+
1. Append (|snapcontainer|, <code>"scrollsnapchanging"</code>) to <var>doc</var>'s
445+
<a>pending scroll events</a>
470446
1. If <var>newInlineTarget</var> is not the same [=snap target=] as <var>inlineTarget</var>:
471447
1. Set the <a>scrollsnapchanging inline-axis target</a> associated with |snapcontainer| to
472448
<var>newInlineTarget</var>.
473-
1. If |snapcontainer| is not already in <var>doc</var>'s
474-
<a>pending scrollsnapchanging event targets</a>,
475-
1. Append |snapcontainer| to <var>doc</var>'s
476-
<a>pending scrollsnapchanging event targets</a>.
477-
478-
When asked to <dfn export for=Document>dispatch pending scrollsnapchanging events</dfn> for a {{Document}},
479-
<var>doc</var>, run these steps:
480-
1. For each item <var>target</var> in |doc|'s <a>pending scrollsnapchanging event targets</a>:
481-
1. Let |blockTarget| and |inlineTarget| be null initially.
482-
1. If the <a>scrollsnapchanging block-axis target</a> associated with <var>target</var> is a pseudo-element,
483-
set |blockTarget| to the owning element of that <a>scrollsnapchanging block-axis target</a>.
484-
1. Otherwise, set |blockTarget| to that <a>scrollsnapchanging block-axis target</a>.
485-
1. If the <a>scrollsnapchanging inline-axis target</a> associated with <var>target</var> is a pseudo-element,
486-
set |inlineTarget| to the owning element of that <a>scrollsnapchanging inline-axis target</a>.
487-
1. Otherwise, set |inlineTarget| to that <a>scrollsnapchanging inline-axis target</a>.
488-
1. Fire a {{SnapEvent}}, |snapevent|, named {{scrollsnapchanging}} at <var>target</var>
489-
and let |snapevent|'s {{SnapEvent/snapTargetBlock}} and
490-
{{SnapEvent/snapTargetInline}} attributes be |blockTarget| and |inlineTarget|, respectively.
491-
1. Empty <var>doc</var>'s <a>pending scrollsnapchanging event targets</a>.
449+
1. If (|snapcontainer|, <code>"scrollsnapchanging"</code>) is not already in <var>doc</var>'s
450+
<a>pending scroll events</a>,
451+
1. Append (|snapcontainer|, <code>"scrollsnapchanging"</code>) to <var>doc</var>'s
452+
<a>pending scroll events</a>
492453

493454
<h4 id="snap-events-on-layout-changes">Snap Events due to Layout Changes </h4>
494455
When a <a spec=css-scroll-snap lt="scroll snap container">snap container</a>,

cssom-view-1/Overview.bs

Lines changed: 41 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2304,9 +2304,7 @@ When asked to <dfn export for=Document>run the resize steps</dfn> for a {{Docume
23042304

23052305
This section integrates with the <a for=/>event loop</a> defined in HTML. [[!HTML]]
23062306

2307-
Each {{Document}} has an associated list of <dfn for=Document>pending scroll event targets</dfn>, initially empty.
2308-
2309-
Each {{Document}} has an associated list of <dfn for=Document>pending scrollend event targets</dfn>, initially empty.
2307+
Each {{Document}} has an associated list of <dfn for=Document>pending scroll events</dfn>, which stores pairs of ({{EventTarget}}, {{DOMString}}), initially empty.
23102308

23112309
Whenever a <a>viewport</a> gets scrolled (whether in response to user interaction or by an API), the user agent must run these steps:
23122310

@@ -2316,8 +2314,8 @@ Whenever a <a>viewport</a> gets scrolled (whether in response to user interactio
23162314
for <var>doc</var> with <var>doc</var>'s <a spec="css-scroll-snap-2">eventual snap target</a> in the block axis
23172315
as newBlockTarget and <var>doc</var>'s <a spec="css-scroll-snap-2">eventual snap target</a> in the inline axis
23182316
as newInlineTarget.
2319-
1. If <var>doc</var> is already in <var>doc</var>'s <a>pending scroll event targets</a>, abort these steps.
2320-
1. Append <var>doc</var> to <var>doc</var>'s <a>pending scroll event targets</a>.
2317+
1. If (<var>doc</var>, <code>"scroll"</code>) is already in <var>doc</var>'s <a>pending scroll events</a>, abort these steps.
2318+
1. Append (<var>doc</var>, <code>"scroll"</code>) to <var>doc</var>'s <a>pending scroll events</a>.
23212319

23222320
Whenever an element gets scrolled (whether in response to user interaction or by an API), the user agent must run these steps:
23232321

@@ -2327,29 +2325,18 @@ Whenever an element gets scrolled (whether in response to user interaction or by
23272325
for the element with the element's <a spec="css-scroll-snap-2">eventual snap target</a> in the block axis
23282326
as newBlockTarget and the element's <a spec="css-scroll-snap-2">eventual snap target</a> in the inline axis
23292327
as newInlineTarget.
2330-
1. If the element is already in <var>doc</var>'s <a>pending scroll event targets</a>, abort these steps.
2331-
1. Append the element to <var>doc</var>'s <a>pending scroll event targets</a>.
2328+
1. If the element is already in <var>doc</var>'s <a>pending scroll events</a>, abort these steps.
2329+
1. Append the element to <var>doc</var>'s <a>pending scroll events</a>.
23322330

23332331
Whenever a <a>visual viewport</a> gets scrolled (whether in response to user interaction or by an API), the user agent must run these steps:
23342332

23352333
1. Let <var>vv</var> be the {{VisualViewport}} object that was scrolled.
23362334
1. Let <var>doc</var> be <var>vv</var>'s <a for=visualviewport>associated document</a>.
2337-
1. If <var>vv</var> is already in <var>doc</var>'s <a>pending scroll event targets</a>, abort these steps.
2338-
1. Append <var>vv</var> to <var>doc</var>'s <a>pending scroll event targets</a>.
2335+
1. If (<var>vv</var>, <code>"scroll"</code>) is already in <var>doc</var>'s <a>pending scroll events</a>, abort these steps.
2336+
1. Append (<var>vv</var>, <code>"scroll"</code>) to <var>doc</var>'s <a>pending scroll events</a>.
23392337

23402338
When asked to <dfn export for=Document>run the scroll steps</dfn> for a {{Document}} <var>doc</var>, run these steps:
23412339

2342-
1. Run the steps to <a spec="css-scroll-snap-2">dispatch pending scrollsnapchanging events</a> for <var>doc</var>.
2343-
1. For each item <var>target</var> in <var>doc</var>'s <a>pending scroll event targets</a>,
2344-
in the order they were added to the list, run these substeps:
2345-
2346-
1. If <var>target</var> is a {{Document}}, <a>fire an event</a> named <a event>scroll</a> that bubbles at <var>target</var>.
2347-
1. Otherwise, <a>fire an event</a> named <a event>scroll</a> at <var>target</var>.
2348-
1. Empty <var>doc</var>'s <a>pending scroll event targets</a>.
2349-
1. Run the steps to <a spec="css-scroll-snap-2">dispatch pending scrollsnapchange events</a> for <var>doc</var>.
2350-
2351-
Whenever scrolling is <a lt="scroll completed">completed</a>, the user agent must run these steps:
2352-
23532340
Issue: In what order are scrollend events dispatched? Ordered based on scroll start or scroll completion?
23542341

23552342
1. For each scrolling box <var>box</var> that was scrolled:
@@ -2358,13 +2345,40 @@ Issue: In what order are scrollend events dispatched? Ordered based on scroll st
23582345
be the {{VisualViewport}}. Otherwise, <var>box</var> belongs to an element and let <var>doc</var> be the element's <a>node document</a> and <var>target</var> be the element.
23592346
1. If <var>box</var> belongs to a <a spec=css-scroll-snap lt="scroll snap container">snap container</a>, |snapcontainer|,
23602347
run the <a spec=css-scroll-snap-2 lt="update scrollsnapchange targets">update scrollsnapchange targets</a> steps for |snapcontainer|.
2361-
1. If <var>target</var> is already in <var>doc</var>'s <a>pending scrollend event targets</a>, abort these steps.
2362-
1. Append <var>target</var> to <var>doc</var>'s <a>pending scrollend event targets</a>.
2363-
1. Run the steps to <a spec="css-scroll-snap-2">dispatch pending scrollsnapchange targets</a> for <var>doc</var>.
2364-
1. For each item <var>target</var> in <var>doc</var>'s <a>pending scrollend event targets</a>, in the order they were added to the list, run these substeps:
2365-
1. If <var>target</var> is a {{Document}}, <a>fire an event</a> named <a event>scrollend</a> that bubbles at <var>target</var>.
2366-
1. Otherwise, <a>fire an event</a> named <a event>scrollend</a> at <var>target</var>.
2367-
1. Empty <var>doc</var>'s <a>pending scrollend event targets</a>.
2348+
1. If (<var>target</var>, <code>"scrollend"</code>) is already in <var>doc</var>'s <a>pending scroll events</a>, abort these steps.
2349+
1. Append (<var>target</var>, <code>"scrollend"</code>) to <var>doc</var>'s <a>pending scroll events</a>.
2350+
2351+
1. For each item (<var>target</var>, <var>type</var>) in <var>doc</var>'s <a>pending scroll events</a>,
2352+
in the order they were added to the list, run these substeps:
2353+
2354+
1. If <var>target</var> is a {{Document}}, and <var>type</var> is <code>"scroll"</code> or <code>"scrollend"</code>,
2355+
<a>fire an event</a> named <a event>scroll</a> that bubbles at <var>target</var>.
2356+
1. Otherwise, if <var>type</var> is <code>"scrollsnapchange"</code>, then:
2357+
1. Let |blockTarget| and |inlineTarget| be null initially.
2358+
1. If the <a>scrollsnapchangeTargetBlock</a> associated with <var>target</var> is a pseudo-element,
2359+
set |blockTarget| to the owning element of that <a>scrollsnapchangeTargetBlock</a>.
2360+
1. Otherwise, set |blockTarget| to that <a>scrollsnapchangeTargetBlock</a>.
2361+
1. If the <a>scrollsnapchangeTargetInline</a> associated with <var>target</var> is a pseudo-element,
2362+
set |inlineTarget| to the owning element of that <a>scrollsnapchangeTargetInline</a>.
2363+
1. Otherwise, Set |inlineTarget| to that <a>scrollsnapchangeTargetInline</a>.
2364+
1. Fire a {{SnapEvent}}, |snapevent|, named {{scrollsnapchange}} at <var>target</var>
2365+
and let |snapevent|'s {{SnapEvent/snapTargetBlock}} and
2366+
{{SnapEvent/snapTargetInline}} attributes be |blockTarget| and |inlineTarget| respectively.
2367+
1. Otherwise, if <var>type</var> is <code>"scrollsnapchanging"</code>, then:
2368+
1. Let |blockTarget| and |inlineTarget| be null initially.
2369+
1. If the <a>scrollsnapchanging block-axis target</a> associated with <var>target</var> is a pseudo-element,
2370+
set |blockTarget| to the owning element of that <a>scrollsnapchanging block-axis target</a>.
2371+
1. Otherwise, set |blockTarget| to that <a>scrollsnapchanging block-axis target</a>.
2372+
1. If the <a>scrollsnapchanging inline-axis target</a> associated with <var>target</var> is a pseudo-element,
2373+
set |inlineTarget| to the owning element of that <a>scrollsnapchanging inline-axis target</a>.
2374+
1. Otherwise, set |inlineTarget| to that <a>scrollsnapchanging inline-axis target</a>.
2375+
1. Fire a {{SnapEvent}}, |snapevent|, named {{scrollsnapchanging}} at <var>target</var>
2376+
and let |snapevent|'s {{SnapEvent/snapTargetBlock}} and
2377+
{{SnapEvent/snapTargetInline}} attributes be |blockTarget| and |inlineTarget|, respectively.
2378+
1. Otherwise, <a>fire an event</a> named <var>type</var> at <var>target</var>.
2379+
1. Empty <var>doc</var>'s <a>pending scroll events</a>.
2380+
2381+
Whenever scrolling is <a lt="scroll completed">completed</a>, the user agent must run these steps:
23682382

23692383
<h3 id=event-summary>Event summary</h3>
23702384

0 commit comments

Comments
 (0)