Skip to content

Commit 2c40247

Browse files
DavMilaDavid Awogbemilatabatkins
authored
[css-scroll-snap-2] Specify scroll-start-target (w3c#10227)
* Specify scroll-start-target This adds details to the scroll-snap-2 spec[1] to specify scroll-start-target. [1] https://drafts.csswg.org/css-scroll-snap-2 * [css-scroll-snap-2]] Specify scroll-start-target * [css-scroll-snap-2] Specify scroll-start-target Define initial scroll position precedence in css-overflow-3. De-vaguify post-first layout scroll-start-target & point to document update process. Extract scroll-view position algorithm for standalone use. * [css-scroll-snap-2] Specify scroll-start-target Remove slight duplication. * [css-scroll-snap-2] Specify scroll-start-target Replace scroll-view with scroll-into-view. Mention and link css properties that change initial scroll position. --------- Co-authored-by: David Awogbemila <David Awogbemila> Co-authored-by: David Awogbemila <awogbemila@chromium.org> Co-authored-by: Tab Atkins Jr <jackalmage@gmail.com>
1 parent c021927 commit 2c40247

File tree

4 files changed

+99
-67
lines changed

4 files changed

+99
-67
lines changed

css-align-3/Overview.bs

+3
Original file line numberDiff line numberDiff line change
@@ -1173,6 +1173,9 @@ Overflow and Scroll Positions</h3>
11731173
of the <a>scroll container</a>
11741174
satisfies the [[#alignment-values|expected alignment]]
11751175
of the <a>alignment subject</a> and <a>alignment container</a>.
1176+
However, the [[css-scroll-snap-2#scroll-start-target-with-place-content|scroll-start-target]]
1177+
property, when present, overrides the <a>content-distribution properties</a>
1178+
in determining the <a>initial scroll position</a>.
11761179

11771180
Note: The presence of scrollbars can change the size of the [=scroll container’s=] content box,
11781181
and thus the size of the [=alignment container=]

css-overflow-3/Overview.bs

+2-2
Original file line numberDiff line numberDiff line change
@@ -341,8 +341,8 @@ Scrolling Overflow</h3>
341341
is typically dependent on the [=scroll container=]’s [=writing mode=],
342342
and, unless otherwise specified,
343343
coincides with its [=scroll origin position=].
344-
However, the 'align-content' and 'justify-content' properties [[!CSS-ALIGN-3]]
345-
can be used to change the [=initial scroll position=],
344+
However, the 'align-content' and 'justify-content' properties [[!CSS-ALIGN-3]] as well as the
345+
'scroll-start-target' property [[!CSS-SCROLL-SNAP-2]] can be used to change the [=initial scroll position=],
346346
see [[css-align-3#overflow-scroll-position]].
347347

348348
A <dfn export>scroll position</dfn> is a particular alignment

css-scroll-snap-2/Overview.bs

+77-60
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,13 @@ First Layout {#first-layout}
5858

5959
<!-- Big Text: examples
6060

61-
█████▌ █ █ ███▌ █ █ ████▌ █▌ █████▌ ███▌
61+
█████▌ █ █ ███▌ █ █ ████▌ █▌ █████▌ ███▌
6262
█▌ █ █ ▐█ ▐█ ██ ██ █▌ █▌ █▌ █▌ █▌ █▌
63-
█▌ █ █ █▌ █▌ █▌█ █▐█ █▌ █▌ █▌ █▌ █▌
64-
████ █ █▌ █▌ █▌ █ ▐█ ████▌ █▌ ████ ███▌
63+
█▌ █ █ █▌ █▌ █▌█ █▐█ █▌ █▌ █▌ █▌ █▌
64+
████ █ █▌ █▌ █▌ █ ▐█ ████▌ █▌ ████ ███▌
6565
█▌ █ █ █████▌ █▌ ▐█ █▌ █▌ █▌ █▌
6666
█▌ █ █ █▌ █▌ █▌ ▐█ █▌ █▌ █▌ █▌ █▌
67-
█████▌ █ █ █▌ █▌ █▌ ▐█ █▌ █████ █████▌ ███▌
67+
█████▌ █ █ █▌ █▌ █▌ ▐█ █▌ █████ █████▌ ███▌
6868
-->
6969

7070
Motivating Examples {#examples}
@@ -227,37 +227,87 @@ Interaction with RTL and LTR</h4>
227227
The 'scroll-start-target' property {#scroll-start-target}
228228
-------------------------------------------
229229

230+
<h4 dfn export id="initial-scroll-target">
231+
Initial scroll target</h4>
232+
233+
The [=initial scroll target=] of a <a>scroll container</a> |scrollcontainer|
234+
is an element or pseudo-element
235+
whose 'scroll-start-target'property is non-''scroll-start-target/none''
236+
and whose nearest <a>scroll container</a> is |scrollcontainer|.
237+
When multiple such elements or pseudo-elements exist,
238+
user-agents should select the one
239+
which comes first in [=tree order=].
240+
When no such element or pseudo-element exists,
241+
|scrollcontainer|’s <a>initial scroll target</a> is null.
242+
243+
<div algorithm="determine the initial scroll position from an initial scroll target">
244+
If the <a>initial scroll target</a> of a <a>scroll container</a> is not null,
245+
it should be used to determine the <a>initial scroll position</a> of |scrollcontainer|
246+
by running the following steps:
247+
248+
1. Let |target| be the <a>initial scroll target</a> for |scrollcontainer|.
249+
1. Let |position| be the result of running the steps to
250+
<a spec="cssom-view-1">determine the scroll-into-view position</a> of |target|
251+
with <var ignore>behavior</var> set to "auto",
252+
<var ignore>block</var> set to "start",
253+
<var ignore>inline</var> set to "nearest",
254+
and <var ignore>scrolling box</var> set to |scrollcontainer|.
255+
1. Set |scrollcontainer|'s <a>initial scroll position</a> to |position|.
256+
</div>
257+
258+
259+
<h4 id="scroll-start-target-shorthand">
260+
The scroll-start-target shorthand</h4>
261+
230262
<pre class="propdef shorthand">
231-
Name: scroll-start-target
232-
Value: [ none | auto ]{1,2}
263+
Name: scroll-start-target
264+
Value: [ none | auto ]
265+
Initial: ''none''
266+
Applies to: all elements
267+
Inherited: no
268+
Percentages: N/A
269+
Computed Value: see individual properties
270+
Animation type: none
233271
</pre>
234272

235-
This property is a shorthand property that sets all of the scroll-start-target-* longhands in one declaration.
236-
The first value defines the scroll starting point in the block axis,
237-
the second sets it in the inline axis.
238-
If the second value is omitted, it defaults to ''scroll-start-target/none''.
239-
240-
Values are defined as follows:
241-
242-
<dl dfn-type=value dfn-for="scroll-start-target, scroll-start-target-x, scroll-start-target-y, scroll-start-target-block, scroll-start-target-inline">
273+
<dl dfn-type=value dfn-for="scroll-start-target, scroll-start-target-block, scroll-start-target-inline, scroll-start-target-x, scroll-start-target-y">
243274
<dt><dfn>none</dfn>
244-
<dd>Element is not a ''scroll-start-target''.
275+
<dd>The element is not an [=initial scroll target=].
245276
<dt><dfn>auto</dfn>
246-
<dd>Element is used to calculate the 'scroll-start' position,
247-
taking into account ''scroll-padding'' or ''scroll-margin'' ,
248-
same as a ''scroll-snap'' target.
277+
<dd>The element is potentially an [=initial scroll target=]
278+
for its nearest [=scroll container=] ancestor.
249279
</dl>
250280

281+
<h4 id="scroll-start-target-with-place-content">
282+
Interaction with 'place-content'</h4>
283+
284+
If a [=scroll container's=] [=initial scroll position=]
285+
is potentially set by both a [=content-distribution property=]
286+
and by 'scroll-start-target' on a descendant,
287+
'scroll-start-target' wins.
251288

252-
<!-- Big Text: :snapped
289+
<h4 id="scroll-start-fragment-navigation">
290+
Post-first layout arrivals</h4>
253291

254-
█▌ ███▌ █ █▌ ███▌ ████▌ ████▌ █████▌ ████▌
292+
While the document is being [[html#updating-the-document|updated],
293+
a <a>scroll container's</a> [=initial scroll target=] might arrive
294+
after that <a>scroll container</a> has been laid out.
295+
If this happens,
296+
user agents should still scroll to the [=initial scroll target=]
297+
unless the user agent has reason to believe
298+
the user is no longer interested
299+
in scrolling to the <a>initial scroll position</a>.
300+
301+
302+
<!-- Big Text: :snapped
303+
304+
█▌ ███▌ █ █▌ ███▌ ████▌ ████▌ █████▌ ████▌
255305
███▌ █▌ █▌ █▌ █▌ ▐█ ▐█ █▌ █▌ █▌ █▌ █▌ █▌ █▌
256306
█▌ █▌ ██▌ █▌ █▌ █▌ █▌ █▌ █▌ █▌ █▌ █▌ █▌
257307
███▌ █▌▐█ █▌ █▌ █▌ ████▌ ████▌ ████ █▌ █▌
258308
█▌ █▌ █▌ ██▌ █████▌ █▌ █▌ █▌ █▌ █▌
259309
███▌ █▌ █▌ █▌ █▌ █▌ █▌ █▌ █▌ █▌ █▌ █▌
260-
█▌ ███▌ █▌ ▐▌ █▌ █▌ █▌ █▌ █████▌ ████▌
310+
█▌ ███▌ █▌ ▐▌ █▌ █▌ █▌ █▌ █████▌ ████▌
261311
-->
262312

263313
Styling Snapped Items {#styling-snapped}
@@ -300,13 +350,13 @@ Snap Events {#snap-events}
300350

301351
<!-- Big Text: events
302352

303-
█████▌ █▌ █▌ █████▌ █ █▌ █████▌ ███▌
353+
█████▌ █▌ █▌ █████▌ █ █▌ █████▌ ███▌
304354
█▌ █▌ █▌ █▌ █▌ █▌ █▌ █▌ █▌
305-
█▌ █▌ █▌ █▌ ██▌ █▌ █▌ █▌
306-
████ ▐▌ █ ████ █▌▐█ █▌ █▌ ███▌
355+
█▌ █▌ █▌ █▌ ██▌ █▌ █▌ █▌
356+
████ ▐▌ █ ████ █▌▐█ █▌ █▌ ███▌
307357
█▌ █ ▐▌ █▌ █▌ ██▌ █▌ █▌
308358
█▌ ▐▌ █ █▌ █▌ █▌ █▌ █▌ █▌
309-
█████▌ ▐█ █████▌ █▌ ▐▌ █▌ ███▌
359+
█████▌ ▐█ █████▌ █▌ ▐▌ █▌ ███▌
310360
-->
311361

312362
{{scrollsnapchange}} and {{scrollsnapchanging}} {#scrollsnapchange-and-scrollsnapchanging}
@@ -591,13 +641,13 @@ when the scrolling operation ends.
591641

592642
<!-- Big Text: Longhand
593643

594-
█▌ ███▌ █ █▌ ███▌ █▌ █▌ ███▌ █ █▌ ████▌
644+
█▌ ███▌ █ █▌ ███▌ █▌ █▌ ███▌ █ █▌ ████▌
595645
█▌ █▌ █▌ █▌ █▌ █▌ █▌ █▌ █▌ ▐█ ▐█ █▌ █▌ █▌ █▌
596646
█▌ █▌ █▌ ██▌ █▌ █▌ █▌ █▌ █▌ █▌ ██▌ █▌ █▌ █▌
597647
█▌ █▌ █▌ █▌▐█ █▌ █▌ ██▌ █████▌ █▌ █▌ █▌▐█ █▌ █▌ █▌
598648
█▌ █▌ █▌ █▌ ██▌ █▌ █▌ █▌ █▌ █████▌ █▌ ██▌ █▌ █▌
599649
█▌ █▌ █▌ █▌ █▌ █▌ █▌ █▌ █▌ █▌ █▌ █▌ █▌ █▌ █▌
600-
█████ ███▌ █▌ ▐▌ ███▌ █▌ █▌ █▌ █▌ █▌ ▐▌ ████▌
650+
█████ ███▌ █▌ ▐▌ ███▌ █▌ █▌ █▌ █▌ █▌ ▐▌ ████▌
601651
-->
602652

603653
Appendix A: Longhands {#longhands}
@@ -638,39 +688,6 @@ Flow-relative Longhands for 'scroll-start' {#scroll-start-longhands-logical}
638688
Animation type: by computed value type
639689
</pre>
640690

641-
...
642-
Flow-relative Longhands for 'scroll-start-target' {#scroll-start-target-longhands-logical}
643-
--------------------------------------------------------------------------
644-
645-
<pre class="propdef">
646-
Name: scroll-start-target-block, scroll-start-target-inline
647-
Value: auto | none
648-
Initial: none
649-
Applies to: all elements
650-
Inherited: no
651-
Logical property group: scroll-start-target
652-
Percentages: n/a
653-
Computed Value: either of the keywords "none" or "auto"
654-
Animation type: not animatable
655-
</pre>
656-
657-
...
658-
659-
Physical Longhands for 'scroll-start-target' {#scroll-start-target-longhands-physical}
660-
----------------------------------------------------------------------
661-
662-
<pre class="propdef">
663-
Name: scroll-start-target-x, scroll-start-target-y
664-
Value: none | auto
665-
Initial: none
666-
Applies to: all elements
667-
Inherited: no
668-
Logical property group: scroll-start-target
669-
Percentages: n/a
670-
Computed value: either of the keywords "none" or "auto"
671-
Animation type: not animatable
672-
</pre>
673-
674691
...
675692

676693
Appendix B: Event Handlers {#event-handlers}

cssom-view-1/Overview.bs

+17-5
Original file line numberDiff line numberDiff line change
@@ -1445,14 +1445,14 @@ The <dfn attribute for=Element>currentCSSZoom</dfn> attribute must return the
14451445

14461446
<h3 id=element-scrolling-members>{{Element}} Scrolling Members</h3>
14471447

1448-
To <dfn export>scroll a target into view</dfn> <var>target</var>, which is an <a for="/">Element</a> or <a>Range</a>,
1448+
1449+
To <dfn export>determine the scroll-into-view position</dfn> of a <var>target</var>, which is an <a for="/">Element</a> or <a>Range</a>,
14491450
with a scroll behavior <var>behavior</var>,
14501451
a block flow direction position <var>block</var>,
1451-
and an inline base direction position <var>inline</var>,
1452-
means to run these steps for each ancestor element or <a>viewport</a> that establishes
1453-
a <a>scrolling box</a> <var>scrolling box</var>, in order of innermost to outermost <a>scrolling box</a>:
1452+
an inline base direction position <var>inline</var>,
1453+
and a <a>scrolling box</a> <var>scrolling box</var>,
1454+
run the following steps:
14541455

1455-
1. If the {{Document}} associated with <var>target</var> is not <a>same origin</a> with the {{Document}} associated with the element or <a>viewport</a> associated with <var>scrolling box</var>, terminate these steps.
14561456
1. Let <var>target bounding border box</var> be the box represented by the return value of invoking Element's {{Element/getBoundingClientRect()}}, if <var>target</var> is an <a for="/">Element</a>, or Range's {{Range/getBoundingClientRect()}}, if <var>target</var> is a <a>Range</a>.
14571457
1. Let <var>scrolling box edge A</var> be the <a>beginning edge</a> in the <a>block flow direction</a> of <var>scrolling box</var>, and let <var>element edge A</var> be <var>target bounding border box</var>'s edge on the same physical side as that of <var>scrolling box edge A</var>.
14581458
1. Let <var>scrolling box edge B</var> be the <a>ending edge</a> in the <a>block flow direction</a> of <var>scrolling box</var>, and let <var>element edge B</var> be <var>target bounding border box</var>'s edge on the same physical side as that of <var>scrolling box edge B</var>.
@@ -1496,7 +1496,19 @@ a <a>scrolling box</a> <var>scrolling box</var>, in order of innermost to outerm
14961496
<dt>If <var>element edge D</var> is outside <var>scrolling box edge D</var> and <var>element width</var> is less than <var>scrolling box width</var>
14971497
<dd>Align <var>element edge D</var> with <var>scrolling box edge D</var>.
14981498
</dl>
1499+
1. Return <var>position</var>.
1500+
14991501

1502+
To <dfn export>scroll a target into view</dfn> <var>target</var>, which is an <a for="/">Element</a> or <a>Range</a>,
1503+
with a scroll behavior <var>behavior</var>,
1504+
a block flow direction position <var>block</var>,
1505+
and an inline base direction position <var>inline</var>,
1506+
means to run these steps for each ancestor element or <a>viewport</a> that establishes
1507+
a <a>scrolling box</a> <var>scrolling box</var>, in order of innermost to outermost <a>scrolling box</a>:
1508+
1509+
1. If the {{Document}} associated with <var>target</var> is not <a>same origin</a> with the {{Document}} associated with the element or <a>viewport</a> associated with <var>scrolling box</var>, terminate these steps.
1510+
1. Let <var>position</var> be the scroll position resulting from running the steps to <a>determine the scroll-into-view position</a> of <var>target</var> with <var>behavior</var> as the |scroll behavior|,
1511+
<var>block</var> as the |block flow position|, <var>inline</var> as the |inline base direction position| and <var>scrolling box</var> as the |scrolling box|.
15001512
1. If <var>position</var> is the same as <var>scrolling box</var>'s current scroll position, and <var>scrolling box</var> does not have an ongoing <a>smooth scroll</a>, then return.
15011513
1. <dl class=switch>
15021514
<dt>If <var>scrolling box</var> is associated with an element

0 commit comments

Comments
 (0)