From ece22244bc20e4e8aa9194e3440260629206e736 Mon Sep 17 00:00:00 2001 From: David Awogbemila Date: Tue, 12 Nov 2024 10:45:40 -0500 Subject: [PATCH 1/8] Add initial scroll position hook to HTML spec scroll-start-target is a CSS property which affects an element's initial scroll position. A scroll container's initial scroll position determines what scroll offset that scroll container should be at before any "explicit" scrolling (e.g. user gesture, programmatic scroll API) occurs on it. This initial scroll position is affected by CSS properties such as scroll-start-target and might change as a document is loaded. This patch adds a step in the "Updating the document" section of the HTML spec to direct user agents on when to re-evaluate initial scroll positions and adjust accordingly. --- source | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/source b/source index 9d45f686ac5..75828949bda 100644 --- a/source +++ b/source @@ -3904,6 +3904,7 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
  • The 'overflow' property and its 'hidden' value
  • The 'text-overflow' property
  • The term scroll container +
  • The term initial scroll position

    The following terms and features are defined in CSS Positioned Layout: @@ -103718,6 +103719,8 @@ location.href = '#foo';

  • +
  • Update the initial scroll positions for scroll containers in document.
  • +
  • If documentIsNew is true, then: @@ -103879,6 +103882,27 @@ location.href = '#foo';

  • +

    To update the initial scroll positions for scroll containers in a + Document document, + perform the following steps:

    + +
      +
    1. Let scrollers be the list of all + scroll containers within document.

    2. + +
    3. +

      For each scroller in scrollers:

      +
        +
      1. If the user agent has reason to believe the user is no longer interested in scrolling + to scroller's initial scroll + position, then abort these steps.

      2. + +
      3. Update scroller's initial scroll + position and scroll scroller to it.

      4. +
      +
    4. +
    +

    To make document unsalvageable, given a Document document and a string reason:

    @@ -145050,6 +145074,7 @@ INSERT INTERFACES HERE Dave Singer, Dave Tapuska, Dave Townsend, + David Awogbemila, David Baron, David Bloom, David Bokan, From b5b44c811814c040008853a793b471a1e597e757 Mon Sep 17 00:00:00 2001 From: David Awogbemila Date: Thu, 14 Nov 2024 10:00:43 -0500 Subject: [PATCH 2/8] Fix indentation; improve references & links --- source | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/source b/source index 75828949bda..77279073595 100644 --- a/source +++ b/source @@ -4056,6 +4056,8 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
  • The scroll event
  • The scrollend event
  • set up browsing context features
  • +
  • The term perform a scroll
  • +
  • The term scrolling box
  • The following features and terms are defined in CSS Syntax: @@ -103883,22 +103885,26 @@ location.href = '#foo';

    To update the initial scroll positions for scroll containers in a - Document document, - perform the following steps:

    + Document document:

      -
    1. Let scrollers be the list of all - scroll containers within document.

    2. +
    3. Let scrollers be a list of all + scroll containers of document.

    4. -

      For each scroller in scrollers:

      +

      For each scroller of scrollers: +

      +
      1. If the user agent has reason to believe the user is no longer interested in scrolling - to scroller's initial scroll - position, then abort these steps.

      2. + to scroller's initial scroll position + , then abort these steps.

        + +
      3. Let position be the initial scroll + position of scroller.

      4. -
      5. Update scroller's initial scroll - position and scroll scroller to it.

      6. +
      7. Perform a scroll of scroller's scrolling box to position.

    From ae81ba793fda86b744c351fdaa5f16f1df127aa0 Mon Sep 17 00:00:00 2001 From: David Awogbemila Date: Fri, 15 Nov 2024 12:33:31 -0500 Subject: [PATCH 3/8] Fix step placement Step should happen within "If documentIsNew" block like fragment-scroll. --- source | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/source b/source index 77279073595..4b0767d3986 100644 --- a/source +++ b/source @@ -103721,12 +103721,13 @@ location.href = '#foo'; -
  • Update the initial scroll positions for scroll containers in document.
  • -
  • If documentIsNew is true, then:

      +
    1. Update the initial scroll positions for scroll containers in + document.

    2. +
    3. Try to scroll to the fragment for document.

    4. At this point scripts may run for the newly-created document From dd852fe7f1319fe05288c648bf84c9b28a69778b Mon Sep 17 00:00:00 2001 From: David Awogbemila Date: Mon, 2 Dec 2024 10:44:04 -0500 Subject: [PATCH 4/8] Poll scroll containers separately and repeatedly There might be no scroll containers the first time the algorithm runs, so we need to keep polling until the user agent believes the user is no longer interested in the initial scroll position. --- source | 39 +++++++++++++++++++++++++++++---------- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/source b/source index 4b0767d3986..327824233d4 100644 --- a/source +++ b/source @@ -103888,7 +103888,7 @@ location.href = '#foo';

      To update the initial scroll positions for scroll containers in a Document document:

      -
        +
        1. Let scrollers be a list of all scroll containers of document.

        2. @@ -103897,19 +103897,38 @@ location.href = '#foo';

            -
          1. If the user agent has reason to believe the user is no longer interested in scrolling - to scroller's initial scroll position - , then abort these steps.

          2. - -
          3. Let position be the initial scroll - position of scroller.

          4. - -
          5. Perform a scroll of scroller's scrolling box to position.

          6. +
          7. Update the initial scroll position for scroller.

        +

        To update the initial scroll position for a + scroll container scroller perform the following + steps in parallel:

        + +
          +
        1. Wait for an implementation-defined amount of time. (This is intended to allow + the user agent to optimize the user experience in the face of performance concerns.)

        2. + +
        3. +

          Queue a global task on the navigation and traversal task source + given document's relevant global object to run these steps:

          + +
            +
          1. If the user agent has reason to believe the user is no longer interested in scrolling + to scroller's initial scroll position + , then abort these steps.

          2. + +
          3. Let position be the initial scroll + position of scroller.

          4. + +
          5. Perform a scroll of scroller's scrolling box to position.

          6. + +
          7. Update the initial scroll position for scroller.

          8. +
          +
        +

        To make document unsalvageable, given a Document document and a string reason:

        From abee6231740d42e085672b57e22df81fc26cdf3f Mon Sep 17 00:00:00 2001 From: David Awogbemila Date: Fri, 6 Dec 2024 14:07:54 -0500 Subject: [PATCH 5/8] Add initial scroll position hook to html spec. A few improvements. --- source | 39 ++++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/source b/source index 327824233d4..10a2034ed65 100644 --- a/source +++ b/source @@ -3905,6 +3905,7 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
      1. The 'text-overflow' property
      2. The term scroll container
      3. The term initial scroll position +
      4. The term scrollable overflow rectangle

        The following terms and features are defined in CSS Positioned Layout: @@ -103888,23 +103889,24 @@ location.href = '#foo';

        To update the initial scroll positions for scroll containers in a Document document:

        -
          -
        1. Let scrollers be a list of all - scroll containers of document.

        2. +
            +
          1. Let scrollers be a list of every element which is a + shadow-including descendant of + document and establishes a scrolling box.

          2. -
          3. -

            For each scroller of scrollers: -

            +
          4. +

            For each scroller of + scrollers, in tree order:

            -
              -
            1. Update the initial scroll position for scroller.

            2. -
            -
          5. +
              +
            1. Update the initial scroll position for scroller.

            + +
          -

          To update the initial scroll position for a - scroll container scroller perform the following - steps in parallel:

          +

          To update the initial scroll position for an element scroller, + perform the following steps in parallel:

          1. Wait for an implementation-defined amount of time. (This is intended to allow @@ -103916,14 +103918,17 @@ location.href = '#foo';

            1. If the user agent has reason to believe the user is no longer interested in scrolling - to scroller's initial scroll position - , then abort these steps.

            2. + to the initial scroll position of the + scrollable overflow rectangle of scroller's scrolling box, + then abort these steps.

            3. Let position be the initial scroll - position of scroller.

            4. + position of the scrollable overflow rectangle of scroller's + scrolling box.

            5. Perform a scroll of scroller's scrolling box to position.

            6. + data-x="scrolling box">scrolling box to position, with scroller + as the associated element.

            7. Update the initial scroll position for scroller.

            From 2ecc9aa9c29b80f5fde51aeabe8b455cea5000ab Mon Sep 17 00:00:00 2001 From: David Awogbemila Date: Mon, 9 Dec 2024 09:20:40 -0500 Subject: [PATCH 6/8] Specify shadow-including order and note difference in scrolling goals The search for scroll containers includes shadow trees, so the list traversal order should account for shadow trees. Adds a note to clarify the recursive nature of "update initial scroll positions for scroll containers" as it differs from "try to scroll to the fragment." --- source | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/source b/source index 10a2034ed65..62613ddd55a 100644 --- a/source +++ b/source @@ -103897,7 +103897,7 @@ location.href = '#foo';
          2. For each scroller of - scrollers, in tree order:

            + scrollers, in shadow-including tree order:

            1. Update the initial scroll position for scroller.

            2. @@ -103908,6 +103908,17 @@ location.href = '#foo';

              To update the initial scroll position for an element scroller, perform the following steps in parallel:

              +

              Although try to scroll to the fragment and + update the initial scroll positions for scroll containers take place at the same + point, and both use a polling system to prediodically re-attempt the scrolling, their goals are + different. Try to scroll to the fragment polls repeatedly until the + indicated part is found since it might take a while for the element to show up during + the document load. Update the initial scroll positions for scroll containers does not + have such a finish condition; it can run indefinitely, as long as the user does not indicate + disinterest. This is necessary to achieve the desired behavior of keeping a + scroll container anchored to the position indicated by CSS properties that determine + the initial scroll position.

              +
              1. Wait for an implementation-defined amount of time. (This is intended to allow the user agent to optimize the user experience in the face of performance concerns.)

              2. From df3e49661a12b6de0e1b7349287a5fce54232724 Mon Sep 17 00:00:00 2001 From: David Awogbemila Date: Mon, 9 Dec 2024 09:31:42 -0500 Subject: [PATCH 7/8] Position note aobut recursion better --- source | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/source b/source index 62613ddd55a..d5750a954bf 100644 --- a/source +++ b/source @@ -103908,17 +103908,6 @@ location.href = '#foo';

                To update the initial scroll position for an element scroller, perform the following steps in parallel:

                -

                Although try to scroll to the fragment and - update the initial scroll positions for scroll containers take place at the same - point, and both use a polling system to prediodically re-attempt the scrolling, their goals are - different. Try to scroll to the fragment polls repeatedly until the - indicated part is found since it might take a while for the element to show up during - the document load. Update the initial scroll positions for scroll containers does not - have such a finish condition; it can run indefinitely, as long as the user does not indicate - disinterest. This is necessary to achieve the desired behavior of keeping a - scroll container anchored to the position indicated by CSS properties that determine - the initial scroll position.

                -
                1. Wait for an implementation-defined amount of time. (This is intended to allow the user agent to optimize the user experience in the face of performance concerns.)

                2. @@ -103942,6 +103931,17 @@ location.href = '#foo'; as the associated element.

                3. Update the initial scroll position for scroller.

                4. + +

                  Although try to scroll to the fragment and + update the initial scroll positions for scroll containers take place at the same + point, and both use a polling system to prediodically re-attempt the scrolling, their goals are + different. Try to scroll to the fragment polls repeatedly until the + indicated part is found since it might take a while for the element to show up during + the document load. Update the initial scroll positions for scroll containers does not + have such a finish condition; it can run indefinitely, as long as the user does not indicate + disinterest. This is necessary to achieve the desired behavior of keeping a + scroll container anchored to the position indicated by CSS properties that determine + the initial scroll position.

              From 1f28b52e8b708eea1e7e5f15f5454fde723d5896 Mon Sep 17 00:00:00 2001 From: Domenic Denicola Date: Tue, 10 Dec 2024 11:20:34 +0900 Subject: [PATCH 8/8] Tweaks, mostly wrapping --- source | 53 ++++++++++++++++++++++++++++------------------------- 1 file changed, 28 insertions(+), 25 deletions(-) diff --git a/source b/source index d5750a954bf..10298b01f46 100644 --- a/source +++ b/source @@ -103861,6 +103861,8 @@ location.href = '#foo';
            +
            +

            To try to scroll to the fragment for a Document document, perform the following steps in parallel:

            @@ -103890,14 +103892,13 @@ location.href = '#foo'; Document document:

              -
            1. Let scrollers be a list of every element which is a - shadow-including descendant of - document and establishes a scrolling box.

            2. +
            3. Let scrollers be a list of every element which is a shadow-including descendant of document + and establishes a scrolling box.

            4. -

              For each scroller of - scrollers, in shadow-including tree order:

              +

              For each scroller of scrollers, in + shadow-including tree order:

              1. Update the initial scroll position for scroller.

              2. @@ -103905,8 +103906,8 @@ location.href = '#foo';
              -

              To update the initial scroll position for an element scroller, - perform the following steps in parallel:

              +

              To update the initial scroll position for an element scroller, perform + the following steps in parallel:

              1. Wait for an implementation-defined amount of time. (This is intended to allow @@ -103916,35 +103917,37 @@ location.href = '#foo';

                Queue a global task on the navigation and traversal task source given document's relevant global object to run these steps:

                -
                  -
                1. If the user agent has reason to believe the user is no longer interested in scrolling - to the initial scroll position of the +

                    +
                  1. If the user agent has reason to believe the user is no longer interested in scrolling to + the initial scroll position of the scrollable overflow rectangle of scroller's scrolling box, then abort these steps.

                  2. Let position be the initial scroll position of the scrollable overflow rectangle of scroller's scrolling box.

                  3. - +
                  4. Perform a scroll of scroller's scrolling box to position, with scroller - as the associated element.

                  5. + data-x="scrolling box">scrolling box to position, with scroller as + the associated element.

                  6. Update the initial scroll position for scroller.

                  7. - -

                    Although try to scroll to the fragment and - update the initial scroll positions for scroll containers take place at the same - point, and both use a polling system to prediodically re-attempt the scrolling, their goals are - different. Try to scroll to the fragment polls repeatedly until the - indicated part is found since it might take a while for the element to show up during - the document load. Update the initial scroll positions for scroll containers does not - have such a finish condition; it can run indefinitely, as long as the user does not indicate - disinterest. This is necessary to achieve the desired behavior of keeping a - scroll container anchored to the position indicated by CSS properties that determine - the initial scroll position.

                  +
                +

                Although try to scroll to the fragment and update the initial + scroll positions for scroll containers take place at the same point, and both use a polling + system to prediodically re-attempt the scrolling, their goals are different. Try to scroll + to the fragment polls repeatedly until the indicated part is found since it + might take a while for the element to show up during the document load. Update the initial + scroll positions for scroll containers does not have such a finish condition; it can run + indefinitely, as long as the user does not indicate disinterest. This is necessary to achieve the + desired behavior of keeping a scroll container anchored to the position indicated by + CSS properties that determine the initial scroll position.

                + +
                +

                To make document unsalvageable, given a Document document and a string reason: