Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add initial scroll position hook to HTML spec #10759

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
69 changes: 69 additions & 0 deletions source
Original file line number Diff line number Diff line change
Expand Up @@ -3909,6 +3909,8 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
<li>The <dfn data-x-href="https://drafts.csswg.org/css-overflow/#propdef-overflow">'overflow'</dfn> property and its <dfn data-x-href="https://drafts.csswg.org/css-overflow/#valdef-overflow-hidden">'hidden'</dfn> value</li>
<li>The <dfn data-x-href="https://drafts.csswg.org/css-overflow/#propdef-text-overflow">'text-overflow'</dfn> property</li>
<li>The term <dfn data-x-href="https://drafts.csswg.org/css-overflow/#scroll-container">scroll container</dfn>
<li>The term <dfn data-x-href="https://drafts.csswg.org/css-overflow/#initial-scroll-position">initial scroll position</dfn>
<li>The term <dfn data-x-href="https://drafts.csswg.org/css-overflow/#scrollable-overflow-rectangle">scrollable overflow rectangle</dfn>
</ul>

<p>The following terms and features are defined in <cite>CSS Positioned Layout</cite>:
Expand Down Expand Up @@ -4061,6 +4063,8 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
<li>The <dfn data-x="event-scrollend" data-x-href="https://drafts.csswg.org/cssom-view/#eventdef-document-scrollend"><code>scrollend</code></dfn> event</li>
<li><dfn data-x-href="https://drafts.csswg.org/cssom-view/#set-up-browsing-context-features">set up browsing context features</dfn></li>
<li>The <dfn data-x="mouseevent-clientx" data-x-href="https://drafts.csswg.org/cssom-view/#dom-mouseevent-clientx">clientX</dfn> and <dfn data-x="mouseevent-clienty" data-x-href="https://drafts.csswg.org/cssom-view/#dom-mouseevent-clienty">clientY</dfn> extension attributes of the <span>MouseEvent</span> interface</li>
<li>The term <dfn data-x-href="https://drafts.csswg.org/cssom-view/#perform-a-scroll">perform a scroll</dfn></li>
<li>The term <dfn data-x-href="https://drafts.csswg.org/cssom-view/#scrolling-box">scrolling box</dfn></li>
</ul>

<p>The following features and terms are defined in <cite>CSS Syntax</cite>:
Expand Down Expand Up @@ -104568,6 +104572,9 @@ location.href = '#foo';</code></pre>
<p>If <var>documentIsNew</var> is true, then:

<ol>
<li><p><span>Update the initial scroll positions for scroll containers</span> in
<var>document</var>.</p></li>

<li><p><span>Try to scroll to the fragment</span> for <var>document</var>.</p></li>

<li><p>At this point <dfn>scripts may run for the newly-created document</dfn>
Expand Down Expand Up @@ -104700,6 +104707,8 @@ location.href = '#foo';</code></pre>
</li>
</ol>

<hr>

<p>To <dfn>try to scroll to the fragment</dfn> for a <code>Document</code> <var>document</var>,
perform the following steps <span>in parallel</span>:</p>

Expand All @@ -104725,6 +104734,65 @@ location.href = '#foo';</code></pre>
</li>
</ol>

<p>To <dfn>update the initial scroll positions for scroll containers</dfn> in a
<code>Document</code> <var>document</var>:</p>

<ol>
<li><p>Let <var>scrollers</var> be the <span>list</span> obtained by performing a
<span>tree order</span> traversal of <var>document</var>'s <span>flat tree</span>, and filtering
to keep only the elements that establish a <span>scrolling box</span>.</p></li>

<li>
<p><span data-x="list iterate">For each</span> <var>scroller</var> of <var>scrollers</var>:</p>

<ol>
<li><p><span>Update the initial scroll position</span> for <var>scroller</var>.</p></li>
</ol>
</li>
</ol>

<p>To <dfn>update the initial scroll position</dfn> for an element <var>scroller</var>, perform
the following steps <span>in parallel</span>:</p>

<ol>
<li><p>Wait for an <span>implementation-defined</span> amount of time. (This is intended to allow
the user agent to optimize the user experience in the face of performance concerns.)</p></li>

<li>
<p><span>Queue a global task</span> on the <span>navigation and traversal task source</span>
given <var>document</var>'s <span>relevant global object</span> to run these steps:</p>

<ol>
<li><p>If the user agent has reason to believe the user is no longer interested in scrolling to
the <span data-x="initial scroll position">initial scroll position</span> of the
<span>scrollable overflow rectangle</span> of <var>scroller</var>'s <span>scrolling box</span>,
then abort these steps.</p></li>

<li><p>Let <var>position</var> be the <span data-x="initial scroll position">initial scroll
position</span> of the <span>scrollable overflow rectangle</span> of <var>scroller</var>'s
<span>scrolling box</span>.</p></li>

<li><p><span data-x="perform a scroll">Perform a scroll</span> of <var>scroller</var>'s <span
data-x="scrolling box">scrolling box</span> to <var>position</var>, with <var>scroller</var> as
the associated element.</p></li>

<li><p><span>Update the initial scroll position</span> for <var>scroller</var>.</p></li>
</ol>
</li>
</ol>

<p class="note">Although <span>try to scroll to the fragment</span> and <span>update the initial
scroll positions for scroll containers</span> take place at the same point, and both use a polling
system to prediodically re-attempt the scrolling, their goals are different. <span>Try to scroll
to the fragment</span> polls repeatedly until the <span>indicated part</span> is found since it
might take a while for the element to show up during the document load. <span>Update the initial
scroll positions for scroll containers</span> 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 <span>scroll container</span> anchored to the position indicated by
CSS properties that determine the <span>initial scroll position</span>.</p>

<hr>

<p>To <dfn export>make document unsalvageable</dfn>, given a <code>Document</code>
<var>document</var> and a string <var>reason</var>:</p>

Expand Down Expand Up @@ -146275,6 +146343,7 @@ INSERT INTERFACES HERE
Dave Singer,
Dave Tapuska,
Dave Townsend<!-- Mossop on moz irc -->,
David Awogbemila,
David Baron,
David Bloom,
David Bokan,
Expand Down