Skip to content

Commit 871876c

Browse files
author
Simon Pieters
committed
[cssom-view] Make scroll() et al be able to request smooth or instant scrolling
1 parent 9852369 commit 871876c

2 files changed

Lines changed: 104 additions & 60 deletions

File tree

cssom-view/Overview.html

Lines changed: 52 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -272,12 +272,17 @@ <h2 id="common-infrastructure"><span class="secno">4 </span>Common Infrastructur
272272
<h3 id="scrolling"><span class="secno">4.1 </span>Scrolling</h3>
273273

274274
<p>When a user agent is to <dfn id="perform-a-scroll">perform a scroll</dfn> of a scrolling box <var title="">box</var>, to a given position <var title="">position</var>, with a set of
275-
steps <var title="">task</var>, and an associated element <var title="">element</var> the following steps must be run:
275+
steps <var title="">task</var>, an associated element <var title="">element</var> and a scroll behavior <var title="">behavior</var>, the following steps must be run:
276276

277277
<ol>
278278
<li><p><a href="#concept-smooth-scroll-aborted" title="concept-smooth-scroll-aborted">Abort</a> any ongoing <a href="#concept-smooth-scroll" title="concept-smooth-scroll">smooth scroll</a> for <var title="">box</var>.
279-
<li><p>If <var title="">element</var> is not null and its computed value of the '<code><a href="#scroll-behavior">scroll-behavior</a></code>' property is
280-
'<code title="scroll-behavior-smooth"><a href="#scroll-behavior-smooth">smooth</a></code>', and the user agent honors the '<code><a href="#scroll-behavior">scroll-behavior</a></code>' property, then follow these substeps:
279+
<li><p>If the user agent honors the '<code><a href="#scroll-behavior">scroll-behavior</a></code>' property and one of the following are true:
280+
<ul>
281+
<li><p><var title="">behavior</var> is <code title="">auto</code> and <var title="">element</var> is not null and its computed value of the '<code><a href="#scroll-behavior">scroll-behavior</a></code>'
282+
property is '<code title="scroll-behavior-smooth"><a href="#scroll-behavior-smooth">smooth</a></code>'
283+
<li><p><var title="">behavior</var> is <code title="">smooth</code>
284+
</ul>
285+
<p>...then follow these substeps:
281286
<ol>
282287
<li><p>Perform a <a href="#concept-smooth-scroll" title="concept-smooth-scroll">smooth scroll</a> of <var title="">box</var> to <var title="">position</var>.
283288
<li><p><a class="external" href="http://www.whatwg.org/specs/web-apps/current-work/multipage/webappapis.html#queue-a-task">Queue a task</a> to run <var title="">task</var>, unless a <a class="external" href="http://www.whatwg.org/specs/web-apps/current-work/multipage/webappapis.html#concept-task" title="concept-task">task</a> to
@@ -305,7 +310,15 @@ <h3 id="scrolling"><span class="secno">4.1 </span>Scrolling</h3>
305310

306311
<h2 id="extensions-to-the-window-interface"><span class="secno">5 </span>Extensions to the <code title="">Window</code> Interface</h2>
307312

308-
<pre class="idl">partial interface <a class="external" href="http://www.whatwg.org/specs/web-apps/current-work/multipage/browsers.html#window">Window</a> {
313+
<pre class="idl">enum <dfn id="scrollbehavior">ScrollBehavior</dfn> { "auto", "instant", "smooth" };
314+
315+
dictionary <dfn id="scrolloptions">ScrollOptions</dfn> {
316+
double x;
317+
double y;
318+
<a href="#scrollbehavior">ScrollBehavior</a> behavior = "auto";
319+
};
320+
321+
partial interface <a class="external" href="http://www.whatwg.org/specs/web-apps/current-work/multipage/browsers.html#window">Window</a> {
309322
<a href="#mediaquerylist">MediaQueryList</a> <a href="#dom-window-matchmedia" title="dom-Window-matchMedia">matchMedia</a>(DOMString query);
310323
readonly attribute <a href="#screen">Screen</a> <a href="#dom-window-screen" title="dom-Window-screen">screen</a>;
311324

@@ -318,9 +331,9 @@ <h2 id="extensions-to-the-window-interface"><span class="secno">5 </span>Extensi
318331
readonly attribute double <a href="#dom-window-pagexoffset" title="dom-Window-pageXOffset">pageXOffset</a>;
319332
readonly attribute double <a href="#dom-window-scrolly" title="dom-Window-scrollY">scrollY</a>;
320333
readonly attribute double p<a href="#dom-window-pageyoffset" title="dom-Window-pageYOffset">pageYOffset</a>;
321-
void <a href="#dom-window-scroll" title="dom-Window-scroll">scroll(double x, double y)</a>;
322-
void <a href="#dom-window-scrollto" title="dom-Window-scrollTo">scrollTo(double x, double y)</a>;
323-
void <a href="#dom-window-scrollby" title="dom-Window-scrollBy">scrollBy(double x, double y)</a>;
334+
void <a href="#dom-window-scroll" title="dom-Window-scroll">scroll</a>(double x, double y, optional <a href="#scrolloptions">ScrollOptions</a> options);
335+
void <a href="#dom-window-scrollto" title="dom-Window-scrollTo">scrollTo</a>(double x, double y, optional <a href="#scrolloptions">ScrollOptions</a> options);
336+
void <a href="#dom-window-scrollby" title="dom-Window-scrollBy">scrollBy</a>(double x, double y, optional <a href="#scrolloptions">ScrollOptions</a> options);
324337

325338
// client
326339
readonly attribute double <a href="#dom-window-screenx" title="dom-Window-screenX">screenX</a>;
@@ -368,7 +381,7 @@ <h2 id="extensions-to-the-window-interface"><span class="secno">5 </span>Extensi
368381

369382
<p>The <dfn id="dom-window-pageyoffset" title="dom-Window-pageYOffset"><code>pageYOffset</code></dfn> attribute must return the value returned by the <code>scrollY</code> attribute.</p>
370383

371-
<p>When the <dfn id="dom-window-scroll" title="dom-Window-scroll"><code>scroll(<var title="">x</var>, <var title="">y</var>)</code></dfn> method is invoked these steps must be run:</p>
384+
<p>When the <dfn id="dom-window-scroll" title="dom-Window-scroll"><code>scroll(<var title="">x</var>, <var title="">y</var>, <var title="">options</var>)</code></dfn> method is invoked these steps must be run:</p>
372385
<ol>
373386
<li><p>If there is no <a href="#viewport">viewport</a>, abort these steps.
374387
<dl>
@@ -397,13 +410,13 @@ <h2 id="extensions-to-the-window-interface"><span class="secno">5 </span>Extensi
397410
<code class="external"><a href="http://dom.spec.whatwg.org/#document">Document</a></code> object.
398411
</ol>
399412
<li><p><a href="#perform-a-scroll">Perform a scroll</a> of the <a href="#viewport">viewport</a> to <var title="">position</var>, with the set of steps <var title="">task</var>, and the
400-
<code class="external"><a href="http://dom.spec.whatwg.org/#document">Document</a></code>'s root element as the associated element, if there is one, or <code>null</code> otherwise.
413+
<code class="external"><a href="http://dom.spec.whatwg.org/#document">Document</a></code>'s root element as the associated element, if there is one, or <code>null</code> otherwise, and the scroll behavior being the value of the <code title="">behavior</code> dictionary member of <var title="">options</var>.
401414
</ol>
402415

403-
<p>When the <dfn id="dom-window-scrollto" title="dom-Window-scrollTo"><code>scrollTo(<var title="">x</var>, <var title="">y</var>)</code></dfn> method is invoked, the user agent must act as if
416+
<p>When the <dfn id="dom-window-scrollto" title="dom-Window-scrollTo"><code>scrollTo(<var title="">x</var>, <var title="">y</var>, <var title="">options</var>)</code></dfn> method is invoked, the user agent must act as if
404417
the <code title="dom-Window-scroll"><a href="#dom-window-scroll">scroll()</a></code> method was invoked with the same arguments.</p>
405418

406-
<p>When the <dfn id="dom-window-scrollby" title="dom-Window-scrollBy"><code>scrollBy(<var title="">x</var>, <var title="">y</var>)</code></dfn> method is invoked, the user agent must act as if
419+
<p>When the <dfn id="dom-window-scrollby" title="dom-Window-scrollBy"><code>scrollBy(<var title="">x</var>, <var title="">y</var>, <var title="">options</var>)</code></dfn> method is invoked, the user agent must act as if
407420
the <code title="dom-Window-scroll"><a href="#dom-window-scroll">scroll()</a></code> method was invoked with
408421
<var title="">x</var> plus <code title="dom-Window-scrollX"><a href="#dom-window-scrollx">scrollX</a></code>
409422
as first argument and <var title="">y</var> plus
@@ -604,9 +617,9 @@ <h2 id="extensions-to-the-element-interface"><span class="secno">7 </span>Extens
604617
<pre class="idl">partial interface <a class="external" href="http://dom.spec.whatwg.org/#element">Element</a> {
605618
<a href="#clientrectlist">ClientRectList</a> <a href="#dom-element-getclientrects" title="dom-Element-getClientRects">getClientRects</a>();
606619
<a href="#clientrect">ClientRect</a> <a href="#dom-element-getboundingclientrect" title="dom-Element-getBoundingClientRect">getBoundingClientRect</a>();
607-
void <span title="dom-Element-scrollIntoView">scrollIntoView</span>(optional boolean top);
608-
attribute double <a href="#dom-element-scrolltop" title="dom-Element-scrollTop">scrollTop</a>;
609-
attribute double <a href="#dom-element-scrollleft" title="dom-Element-scrollLeft">scrollLeft</a>;
620+
void <span title="dom-Element-scrollIntoView">scrollIntoView</span>(optional boolean top, optional <a href="#scrolloptions">ScrollOptions</a> options);
621+
attribute (double or <a href="#scrolloptions">ScrollOptions</a>) <a href="#dom-element-scrolltop" title="dom-Element-scrollTop">scrollTop</a>;
622+
attribute (double or <a href="#scrolloptions">ScrollOptions</a>) <a href="#dom-element-scrollleft" title="dom-Element-scrollLeft">scrollLeft</a>;
610623
readonly attribute double <a href="#dom-element-scrollwidth" title="dom-Element-scrollWidth">scrollWidth</a>;
611624
readonly attribute double <a href="#dom-element-scrollheight" title="dom-Element-scrollHeight">scrollHeight</a>;
612625
readonly attribute double <a href="#dom-element-clienttop" title="dom-Element-clientTop">clientTop</a>;
@@ -671,11 +684,12 @@ <h2 id="extensions-to-the-element-interface"><span class="secno">7 </span>Extens
671684
var exampleHeight = example.height;</code></pre>
672685
</div>
673686

674-
<p>The <dfn id="dom-element-scrollintroview" title="dom-Element-scrollIntroView"><code>scrollIntoView(<var title="">top</var>)</code></dfn> method must run these steps:</p>
687+
<p>The <dfn id="dom-element-scrollintroview" title="dom-Element-scrollIntroView"><code>scrollIntoView(<var title="">top</var>, <var title="">options</var>)</code></dfn> method must run these steps:</p>
675688
<ol>
676689
<li><p>If the element does not have any associated <a href="#css-layout-box">CSS layout box</a> terminate these steps.</li>
677690
<li><p><a href="#scroll-an-element-into-view" title="scroll an element into view">Scroll the element into view</a> with the
678-
<i title="">align to top flag</i> set if <var title="">top</var> is true or omitted.</li>
691+
<i title="">align to top flag</i> set if <var title="">top</var> is true or omitted, and the scroll behavior being the value of the <code title="">behavior</code>
692+
dictionary member of <var title="">options</var>.</li>
679693
</ol>
680694

681695
<p>The <dfn id="dom-element-scrolltop" title="dom-Element-scrollTop"><code>scrollTop</code></dfn> attribute must return the result of running these steps:</p>
@@ -695,22 +709,25 @@ <h2 id="extensions-to-the-element-interface"><span class="secno">7 </span>Extens
695709
</ol>
696710
<p>When setting the <code title="dom-Element-scrollTop"><a href="#dom-element-scrolltop">scrollTop</a></code> attribute these steps must be run:</p>
697711
<ol>
698-
<li><p>Let <var title="">y</var> be the given value.</li>
712+
<li><p>If the given value is a <code><a href="#scrolloptions">ScrollOptions</a></code> object, and the <code title="">y</code> dictionary member is not present, abort these steps.
713+
<li><p>If the given value is a <code><a href="#scrolloptions">ScrollOptions</a></code> object, let <var title="">y</var> be the value of the <code title="">y</code> dictionary member. Otherwise,
714+
let <var title="">y</var> be the given value.</li>
699715
<li><p>If the element does not have any associated <a href="#css-layout-box">CSS layout box</a>, the
700716
element is the root element and the <code class="external"><a href="http://dom.spec.whatwg.org/#document">Document</a></code> is in
701717
<a class="external" href="http://dom.spec.whatwg.org/#concept-document-quirks" title="concept-document-quirks">quirks mode</a>, or the element has no overflow, terminate these
702718
steps.</li>
703719
<li><p>If the element is the root element invoke
704720
<code title="dom-Window-scroll"><a href="#dom-window-scroll">scroll()</a></code> with zero as first
705-
argument and <var title="">y</var> as second.</li>
721+
argument and <var title="">y</var> as second, and, if the given value is a <code><a href="#scrolloptions">ScrollOptions</a></code> object, the given value as the third argument.</li>
706722
<li><p>If the element is <a href="#the-html-body-element">the HTML <code>body</code> element</a>,
707723
the <code class="external"><a href="http://dom.spec.whatwg.org/#document">Document</a></code> is in <a class="external" href="http://dom.spec.whatwg.org/#concept-document-quirks" title="concept-document-quirks">quirks mode</a>, and the element
708724
does not have any vertical overflow, invoke
709725
<code title="dom-Window-scroll"><a href="#dom-window-scroll">scroll()</a></code> with
710726
<code title="dom-Window-scrollX"><a href="#dom-window-scrollx">scrollX</a></code> as first
711-
argument and <var title="">y</var> as second.</li>
727+
argument and <var title="">y</var> as second, and, if the given value is a <code><a href="#scrolloptions">ScrollOptions</a></code> object, the given value as the third argument.</li>
712728
<li><p><a href="#scroll-an-element" title="scroll an element">Scroll the element</a> to
713-
<code title="dom-Element-scrollLeft"><a href="#dom-element-scrollleft">scrollLeft</a></code>,<var title="">y</var>.
729+
<code title="dom-Element-scrollLeft"><a href="#dom-element-scrollleft">scrollLeft</a></code>,<var title="">y</var>, with the scroll behavior being the value of the <code title="">behavior</code> dictionary
730+
member if the given value is a <code><a href="#scrolloptions">ScrollOptions</a></code> object, or <code title="">auto</code> otherwise.
714731
</ol>
715732

716733
<p>The <dfn id="dom-element-scrollleft" title="dom-Element-scrollLeft"><code>scrollLeft</code></dfn> attribute must return the result of running these steps:</p>
@@ -730,22 +747,27 @@ <h2 id="extensions-to-the-element-interface"><span class="secno">7 </span>Extens
730747
</ol>
731748
<p>When setting the <code title="dom-Element-scrollLeft"><a href="#dom-element-scrollleft">scrollLeft</a></code> attribute these steps must be run:</p>
732749
<ol>
733-
<li><p>Let <var title="">x</var> be the given value.</li>
750+
<li><p>If the given value is a <code><a href="#scrolloptions">ScrollOptions</a></code> object, and the <code title="">x</code> dictionary member is not present, abort these steps.
751+
<li><p>If the given value is a <code><a href="#scrolloptions">ScrollOptions</a></code> object, let <var title="">x</var> be the value of the <code title="">x</code> dictionary member. Otherwise,
752+
let <var title="">x</var> be the given value.</li>
734753
<li><p>If the element does not have any associated <a href="#css-layout-box">CSS layout box</a>, the
735754
element is the root element and the <code class="external"><a href="http://dom.spec.whatwg.org/#document">Document</a></code> is in
736755
<a class="external" href="http://dom.spec.whatwg.org/#concept-document-quirks" title="concept-document-quirks">quirks mode</a>, or the element has no overflow, terminate these
737756
steps.</li>
738757
<li><p>If the element is the root element invoke
739758
<code title="dom-Window-scroll"><a href="#dom-window-scroll">scroll()</a></code> with
740-
<var title="">x</var> as first argument and zero as second.</li>
759+
<var title="">x</var> as first argument and zero as second, and, if the given value is a <code><a href="#scrolloptions">ScrollOptions</a></code> object, the given value as the third
760+
argument.</li>
741761
<li><p>If the element is <a href="#the-html-body-element">the HTML <code>body</code> element</a>,
742762
the <code class="external"><a href="http://dom.spec.whatwg.org/#document">Document</a></code> is in <a class="external" href="http://dom.spec.whatwg.org/#concept-document-quirks" title="concept-document-quirks">quirks mode</a>, and the element
743763
does not have any vertical overflow, invoke
744764
<code title="dom-Window-scroll"><a href="#dom-window-scroll">scroll()</a></code> with
745765
<var title="">x</var> as first argument and
746-
<code title="dom-Window-scrollY"><a href="#dom-window-scrolly">scrollY</a></code> as second.</li>
766+
<code title="dom-Window-scrollY"><a href="#dom-window-scrolly">scrollY</a></code> as second, and, if the given value is a <code><a href="#scrolloptions">ScrollOptions</a></code> object, the given value as the third
767+
argument.</li>
747768
<li><p><a href="#scroll-an-element" title="Scroll an element">Scroll the element</a> to
748-
<var title="">x</var>,<code title="dom-Element-scrollTop"><a href="#dom-element-scrolltop">scrollTop</a></code>.
769+
<var title="">x</var>,<code title="dom-Element-scrollTop"><a href="#dom-element-scrolltop">scrollTop</a></code>, with the scroll behavior being the value of the <code title="">behavior</code> dictionary
770+
member if the given value is a <code><a href="#scrolloptions">ScrollOptions</a></code> object, or <code title="">auto</code> otherwise.
749771
</ol>
750772

751773
<p>The <dfn id="dom-element-scrollwidth" title="dom-Element-scrollWidth"><code>scrollWidth</code></dfn> attribute must return the result of running these steps:</p>
@@ -827,7 +849,7 @@ <h3 id="the-getclientrects-and-getboundingclientrect-methods"><span class="secno
827849
<h3 id="element-scrolling-members"><span class="secno">7.2 </span><code title="">Element</code> Scrolling Members</h3>
828850

829851
<p>To <dfn id="scroll-an-element-into-view">scroll an element into view</dfn>, optionally with an
830-
<i title="">align to top flag</i> set, means to run these steps for each
852+
<i title="">align to top flag</i> set, and with a scroll behavior <var title="">behavior</var>, means to run these steps for each
831853
ancestor element or <a href="#viewport">viewport</a> that establishes a
832854
scrolling box <var title="">box</var>, in order of innermost to outermost scrolling box:</p>
833855

@@ -884,12 +906,12 @@ <h3 id="element-scrolling-members"><span class="secno">7.2 </span><code title=""
884906
</dd>
885907
</dl>
886908
</li>
887-
<li><p><a href="#perform-a-scroll">Perform a scroll</a> of <var title="">box</var> to <var title="">position</var>, with the set of steps <var title="">task</var>, and
888-
<var title="">element</var> as the associated element.
909+
<li><p><a href="#perform-a-scroll">Perform a scroll</a> of <var title="">box</var> to <var title="">position</var>, with the set of steps <var title="">task</var>,
910+
<var title="">element</var> as the associated element and <var title="">behavior</var> as the scroll behavior.
889911

890912
</ol>
891913

892-
<p>To <dfn id="scroll-an-element">scroll an element</dfn> to <var title="">x</var>,<var title="">y</var> means to:</p>
914+
<p>To <dfn id="scroll-an-element">scroll an element</dfn> to <var title="">x</var>,<var title="">y</var> with a scroll behavior <var title="">behavior</var> means to:</p>
893915

894916
<ol>
895917
<li><p>Let <var title="">element</var> be the element.
@@ -927,8 +949,8 @@ <h3 id="element-scrolling-members"><span class="secno">7.2 </span><code title=""
927949
<code title="event-scroll">scroll</code> at the element.</li>
928950
</ol>
929951

930-
<li><p><a href="#perform-a-scroll">Perform a scroll</a> of <var title="">box</var> to <var title="">position</var>, with the set of steps <var title="">task</var>, and
931-
<var title="">element</var> as the associated element.
952+
<li><p><a href="#perform-a-scroll">Perform a scroll</a> of <var title="">box</var> to <var title="">position</var>, with the set of steps <var title="">task</var>,
953+
<var title="">element</var> as the associated element and <var title="">behavior</var> as the scroll behavior.
932954

933955
</ol>
934956

0 commit comments

Comments
 (0)