- Whenever a [=scroll container=] is scrolled, or layout changes the scroll position, the user agent must run these steps to determine the active marker:
+ Whenever a [=scroll container=] participating in one or more [=scroll marker groups=] is scrolled, or layout changes the eventual scroll position,
+ the user agent should determine and update the active marker for each [=scroll marker group=]
+ based on the section of content most likely to be of interest given the target scroll position.
+
+
+ Example algorithm to determine the active marker for a given scroll marker
group.
+
+ 1. Let |scroller| be the nearest common ancestor [=scroll container=] of all of the [=scroll marker=] elements in |group|.
+ 1. Let |active| be scroller.
+ 1. While |active| is a [=scroll container=] containing [=scroll target=] elements targeted by |group|:
+ 1. Let
scroller be |active|.
+ 1. Let
targets be the set of the [=scroll target=] elements whose nearest ancestor [=scroll container=] is |scroller|
+ and the [=scroll container=] elements which contain [=scroll target=] elements targeted by the [=scroll marker group=] whose nearest ancestor [=scroll container=] is |scroller|.
+ 1. Let
primary be the primary scrolling axis, assumed to be the block direction of the container's writing-mode.
+ 1. Let
secondary be the scrolling axis perpendicular to primary.
+ 1. Let
position be the 'eventual scroll position' considering ongoing scrolling operations.
+ 1. For each
axis of |primary|, followed by |secondary|:
+ 1. Let
scrollport size be the client size of |scroller| in the dimension |axis|.
+ 1. For each |target| in |targets|,
determine the scroll-into-view position of |target| in |axis|, storing this as the associated |target position| of |target|.
+ 1. Let |selected position| be the largest |target position|
+ where |target position| is equal to or before |position| in the |axis|,
+ or whose nearest smaller |target position| < |position| - |scrollport size| / 2 and whose |target position| < |position| + |scrollport size| / 2.
+
+ 1. : If there is no such position,
+ ::
+ Set the |selected position| to the first one.
- 1. Let
position be the 'eventual scroll position' for the scrolling operation.
- 1. For each focusgroup
group containing one or more [=scroll marker control=] elements whose [=scroll target=] is a descendant of [=scroll container=]:
+ 1. Let |active| be the all of the |targets| whose associated |target position| is |selected position|.
+ 1. Let |active| be the first item in |active| if it has more than one potential target.
- 1. Let
markers be all of the [=scroll marker control=] elements which are a part of the [=scroll marker group=] for the [=scroll container=].
- 1. Let
targets be the [=scroll target=]s of |markers|, associated with the item of |markers| they came from, and sorted in [=tree order=].
- 1. For each |target| in |targets|,
determine the scroll-into-view position of |target|, storing this as the associated |target position| of |target|.
- 1. Let |selected target| be the largest-indexed item of |targets|
- whose associated |target position| is equal to or before |position| in both the block and inline axises in the current writing mode direction of the [=scroll container=].
+ 1. Let |selected marker| be the [=scroll marker=] associated with |active|.
+ If multiple [=scroll marker=] elements are associated with |active|,
+ set |selected marker| to be the marker that is earliest in tree order among them.
+ 1. Return |selected marker|
+
- Issue: When the next marker is closer to being aligned than the previous we should use the next marker, in a manner similar to mandatory snap point selection.
+
+ Whenever the UA determines that a new marker is the
active marker for a [=scroll marker group=]
group it must run the following steps:
- 1. : If there is no such item,
+ 1. Set the active state of |active marker| to true.
+ 1. : If |active marker| was the
last-focused element of the |group|,
::
- Set the active state of all |markers| in the |group| to false and return.
-
- 1. Let |selected marker| be the marker associated with |selected target|.
- If multiple items of |markers| are associated with |selected target|,
- set |selected marker| to be the marker that is earliest in tree order.
- 1. Set the active state of |selected marker| to true.
- 1. : If the active element was the
last-focused element of the |group|,
- ::
- Focus |selected marker|
- 1. Set the
last-focused element of the |group| to |selected marker|.
- 1. Set the active state of all other |markers| in the |group| to false.
+ Focus |active marker|
+ 1. Set the
last-focused element of the |group| to |active marker|.
+ 1. Set the active state of all other [=scroll marker=] elements in |group| to false.