Skip to content

Commit 232957f

Browse files
authored
[cssom-view] scrollIntoView(undefined) to be like true; change defaults for ScrollIntoViewOptions
This aligns with the behavior of Gecko/WebKit/Chromium; EdgeHTML treats explicit undefined like false. Fixes w3c#1367. Also change defaults for ScrollIntoViewOptions. Fixes w3c#1720. Tests: web-platform-tests/wpt#6253
1 parent cc5b291 commit 232957f

File tree

1 file changed

+33
-32
lines changed

1 file changed

+33
-32
lines changed

cssom-view/Overview.bs

Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -382,14 +382,14 @@ This specification depends on the WHATWG Infra standard. [[!INFRA]]
382382
When a user agent is to <dfn>perform a scroll</dfn> of a <a>scrolling box</a> <var>box</var>,
383383
to a given position <var>position</var>,
384384
an associated element <var>element</var> and optionally a scroll behavior <var>behavior</var>
385-
(which is <code>"auto"</code> if omitted),
385+
(which is "<code>auto</code>" if omitted),
386386
the following steps must be run:
387387

388388
<ol>
389389
<li><a lt="smooth scroll aborted">Abort</a> any ongoing <a>smooth scroll</a> for <var>box</var>.
390390
<li>If the user agent honors the 'scroll-behavior' property and one of the following are true:
391391
<ul>
392-
<li><var>behavior</var> is <code>"auto"</code> and <var>element</var> is not null and its computed value of the
392+
<li><var>behavior</var> is "<code>auto</code>" and <var>element</var> is not null and its computed value of the
393393
'scroll-behavior' property is ''smooth''
394394
<li><var>behavior</var> is <code>smooth</code>
395395
</ul>
@@ -768,7 +768,7 @@ When asked to <dfn>evaluate media queries and report changes</dfn> for a {{Docum
768768
<div class='example'>
769769
A simple piece of code that detects changes in the orientation of the viewport can be written as follows:
770770

771-
<pre class='lang-javascript'>
771+
<pre highlight=javascript>
772772
function handleOrientationChange(event) {
773773
if(event.matches) // landscape
774774
&hellip;
@@ -922,7 +922,7 @@ Note: Some non-conforming implementations are known to return 32 instead of 24.
922922
<code>colorDepth</code> can be used in the context of selecting SDR/HDR in
923923
addition with other information. For example, combined with color gamut.
924924

925-
<pre class='lang-javascript'>
925+
<pre highlight=javascript>
926926
if (screen.colorDepth >= 48 && window.matchMedia('(color-gamut: p3)').matches &&
927927
/* other checks */) {
928928
// Use HDR content.
@@ -1075,15 +1075,14 @@ Note: This {{DOMRect}} object is not <a spec=html>live</a>.
10751075
<pre class=idl>
10761076
enum ScrollLogicalPosition { "start", "center", "end", "nearest" };
10771077
dictionary ScrollIntoViewOptions : ScrollOptions {
1078-
ScrollLogicalPosition block = "center";
1079-
ScrollLogicalPosition inline = "center";
1078+
ScrollLogicalPosition block = "start";
1079+
ScrollLogicalPosition inline = "nearest";
10801080
};
10811081

10821082
partial interface Element {
10831083
DOMRectList getClientRects();
10841084
[NewObject] DOMRect getBoundingClientRect();
1085-
void scrollIntoView();
1086-
void scrollIntoView((boolean or object) arg);
1085+
void scrollIntoView(optional (boolean or ScrollIntoViewOptions) arg);
10871086
void scroll(optional ScrollToOptions options);
10881087
void scroll(unrestricted double x, unrestricted double y);
10891088
void scrollTo(optional ScrollToOptions options);
@@ -1129,7 +1128,7 @@ Note: The {{DOMRect}} object returned by {{Element/getBoundingClientRect()}} is
11291128
<div class='example'>
11301129
The following snippet gets the dimensions of the first <code>div</code> element in a document:
11311130

1132-
<pre class='lang-javascript'>
1131+
<pre highlight=javascript>
11331132
var example = document.getElementsByTagName("div")[0].getBoundingClientRect();
11341133
var exampleWidth = example.width;
11351134
var exampleHeight = example.height;
@@ -1138,16 +1137,17 @@ Note: The {{DOMRect}} object returned by {{Element/getBoundingClientRect()}} is
11381137

11391138
The <dfn method for=Element caniuse=scrollintoview>scrollIntoView(<var>arg</var>)</dfn> method must run these steps:
11401139

1141-
<!-- scrollIntoView() means arg=true but scrollIntoView(undefined) means arg=false, to align with impls. -->
1142-
1143-
1. Let <var>options</var> be null.
1144-
1. If <var>arg</var> is an object, let <var>options</var> be <var>arg</var>.
1145-
1. <a lt="converted to an IDL value">Convert</a> <var>options</var> to a {{ScrollIntoViewOptions}} dictionary. [[!WEBIDL]]
1146-
1. If <var>arg</var> is not specified or is true, let the {{ScrollIntoViewOptions/block}} dictionary member of <var>options</var> have the value "<code>start</code>", and let the {{ScrollIntoViewOptions/inline}} dictionary member of <var>options</var> have the value "<code>nearest</code>".
1147-
1. If <var>arg</var> is false, let the {{ScrollIntoViewOptions/block}} dictionary member of <var>options</var> have the value "<code>end</code>", and let the {{ScrollIntoViewOptions/inline}} dictionary member of <var>options</var> have the value "<code>nearest</code>".
1148-
1. If the element does not have any associated <a>layout box</a> terminate these steps.
1140+
1. Let <var>behavior</var> be "<code>auto</code>".
1141+
1. Let <var>block</var> be "<code>start</code>".
1142+
1. Let <var>inline</var> be "<code>nearest</code>".
1143+
1. If <var>arg</var> is a {{ScrollIntoViewOptions}} dictionary, then:
1144+
1. Set <var>behavior</var> to the {{ScrollOptions/behavior}} dictionary member of <var>options</var>.
1145+
1. Set <var>block</var> to the {{ScrollIntoViewOptions/block}} dictionary member of <var>options</var>.
1146+
1. Set <var>inline</var> to the {{ScrollIntoViewOptions/inline}} dictionary member of <var>options</var>.
1147+
1. Otherwise, if <var>arg</var> is false, then set <var>block</var> to "<code>end</code>".
1148+
1. If the element does not have any associated <a>layout box</a>, then return.
11491149
1. <a lt='scroll an element into view'>Scroll the element into view</a>
1150-
with the options <var>options</var>.
1150+
with <var>behavior</var>, <var>block</var>, and <var>inline</var>.
11511151
1. Optionally perform some other action that brings the element to the user's attention.
11521152

11531153
The <dfn method for=Element lt="scroll(options)|scroll(x, y)">scroll()</dfn> method must run these steps:
@@ -1225,7 +1225,7 @@ When setting the {{Element/scrollTop}} attribute these steps must be run:
12251225
1. If the element is the root element invoke {{Window/scroll()}} on <var>window</var> with {{Window/scrollX}} on <var>window</var> as first argument and <var>y</var> as second argument, and terminate these steps.
12261226
1. If the element is <a>the HTML <code>body</code> element</a>, <var>document</var> is in <a>quirks mode</a>, and the element is not <a>potentially scrollable</a>, invoke {{Window/scroll()}} on <var>window</var> with {{Window/scrollX}} as first argument and <var>y</var> as second argument, and terminate these steps.
12271227
1. If the element does not have any associated <a>CSS layout box</a>, the element has no associated <a>scrolling box</a>, or the element has no overflow, terminate these steps.
1228-
1. <a lt='scroll an element'>Scroll the element</a> to {{Element/scrollLeft}},<var>y</var>, with the scroll behavior being <code>"auto"</code>.
1228+
1. <a lt='scroll an element'>Scroll the element</a> to {{Element/scrollLeft}},<var>y</var>, with the scroll behavior being "<code>auto</code>".
12291229

12301230
The <dfn attribute for=Element>scrollLeft</dfn> attribute, on getting, must return the result of running these steps:
12311231

@@ -1251,7 +1251,7 @@ When setting the {{Element/scrollLeft}} attribute these steps must be run:
12511251
1. If the element is the root element invoke {{Window/scroll()}} on <var>window</var> with <var>x</var> as first argument and {{Window/scrollY}} on <var>window</var> as second argument, and terminate these steps.
12521252
1. If the element is <a>the HTML <code>body</code> element</a>, <var>document</var> is in <a>quirks mode</a>, and the element is not <a>potentially scrollable</a>, invoke {{Window/scroll()}} on <var>window</var> with <var>x</var> as first argument and {{Window/scrollY}} on <var>window</var> as second argument, and terminate these steps.
12531253
1. If the element does not have any associated <a>CSS layout box</a>, the element has no associated <a>scrolling box</a>, or the element has no overflow, terminate these steps.
1254-
1. <a lt='scroll an element'>Scroll the element</a> to <var>x</var>,{{Element/scrollTop}}, with the scroll behavior being <code>"auto"</code>.
1254+
1. <a lt='scroll an element'>Scroll the element</a> to <var>x</var>,{{Element/scrollTop}}, with the scroll behavior being "<code>auto</code>".
12551255

12561256
The <dfn attribute for=Element>scrollWidth</dfn> attribute must return the result of running these steps:
12571257

@@ -1299,7 +1299,9 @@ The <dfn attribute for=Element>clientHeight</dfn> attribute must run these steps
12991299
<h3 id=element-scrolling-members>{{Element}} Scrolling Members</h3>
13001300

13011301
To <dfn>scroll an element into view</dfn> <var>element</var>,
1302-
with a {{ScrollIntoViewOptions}} dictionary <var>options</var>,
1302+
with a scroll behavior <var>behavior</var>,
1303+
a block flow direction position <var>block</var>,
1304+
and an inline base direction position <var>inline</var>,
13031305
means to run these steps for each ancestor element or <a>viewport</a> that establishes
13041306
a <a>scrolling box</a> <var>scrolling box</var>, in order of innermost to outermost <a>scrolling box</a>:
13051307

@@ -1313,10 +1315,10 @@ a <a>scrolling box</a> <var>scrolling box</var>, in order of innermost to outerm
13131315
1. Let <var>scrolling box width</var> be the distance between <var>scrolling box edge C</var> and <var>scrolling box edge D</var>.
13141316
1. Let <var>position</var> be the scroll position <var>scrolling box</var> would have by following these steps:
13151317

1316-
1. If the {{ScrollIntoViewOptions/block}} dictionary member of <var>options</var> is "start", align <var>element edge A</var> with <var>scrolling box edge A</var>.
1317-
1. Otherwise, if the {{ScrollIntoViewOptions/block}} dictionary member of <var>options</var> is "end"; align <var>element edge B</var> with <var>scrolling box edge B</var>.
1318-
1. Otherwise, if the {{ScrollIntoViewOptions/block}} dictionary member of <var>options</var> is "center"; align the center of <var>element bounding border box</var> with the center of <var>scrolling box</var> in <var>scrolling box</var>'s <a>block flow direction</a>.
1319-
1. Otherwise, it is "nearest"; follow these steps:
1318+
1. If <var>block</var> is "<code>start</code>", then align <var>element edge A</var> with <var>scrolling box edge A</var>.
1319+
1. Otherwise, if <var>block</var> is "<code>end</code>", then align <var>element edge B</var> with <var>scrolling box edge B</var>.
1320+
1. Otherwise, if <var>block</var> is "<code>center</code>", then align the center of <var>element bounding border box</var> with the center of <var>scrolling box</var> in <var>scrolling box</var>'s <a>block flow direction</a>.
1321+
1. Otherwise, <var>block</var> is "<code>nearest</code>":
13201322
<dl class=switch>
13211323
<dt>If <var>element edge A</var> and <var>element edge B</var> are both outside <var>scrolling box edge A</var> and <var>scrolling box edge B</var>
13221324
<dd>Do nothing.
@@ -1329,10 +1331,10 @@ a <a>scrolling box</a> <var>scrolling box</var>, in order of innermost to outerm
13291331
<dt>If <var>element edge B</var> is outside <var>scrolling box edge B</var> and <var>element width</var> is less than <var>scrolling box width</var>
13301332
<dd>Align <var>element edge B</var> with <var>scrolling box edge B</var>.
13311333
</dl>
1332-
1. If the {{ScrollIntoViewOptions/inline}} dictionary member of <var>options</var> is "start", align <var>element edge C</var> with <var>scrolling box edge C</var>.
1333-
1. Otherwise, if the {{ScrollIntoViewOptions/inline}} dictionary member of <var>options</var> is "end"; align <var>element edge D</var> with <var>scrolling box edge D</var>.
1334-
1. Otherwise, if the {{ScrollIntoViewOptions/inline}} dictionary member of <var>options</var> is "center", align the center of <var>element bounding border box</var> with the center of <var>scrolling box</var> in <var>scrolling box</var>'s <a>inline base direction</a>.
1335-
1. Otherwise, it is "nearest"; follow these steps:
1334+
1. If <var>inline</var> is "<code>start</code>", then align <var>element edge C</var> with <var>scrolling box edge C</var>.
1335+
1. Otherwise, if <var>inline</var> is "<code>end</code>", then align <var>element edge D</var> with <var>scrolling box edge D</var>.
1336+
1. Otherwise, if <var>inline</var> is "<code>center</code>", then align the center of <var>element bounding border box</var> with the center of <var>scrolling box</var> in <var>scrolling box</var>'s <a>inline base direction</a>.
1337+
1. Otherwise, <var>inline</var> is "<code>nearest</code>":
13361338
<dl class=switch>
13371339
<dt>If <var>element edge C</var> and <var>element edge D</var> are both outside <var>scrolling box edge C</var> and <var>scrolling box edge D</var>
13381340
<dd>Do nothing.
@@ -1346,7 +1348,7 @@ a <a>scrolling box</a> <var>scrolling box</var>, in order of innermost to outerm
13461348
<dd>Align <var>element edge D</var> with <var>scrolling box edge D</var>.
13471349
</dl>
13481350

1349-
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>, abort these steps.
1351+
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.
13501352
1. <dl class=switch>
13511353
<dt>If <var>scrolling box</var> is associated with an element
13521354
<dd>
@@ -1357,11 +1359,10 @@ a <a>scrolling box</a> <var>scrolling box</var>, in order of innermost to outerm
13571359
Let <var>document</var> be the <a>viewport’s</a> associated {{Document}}.
13581360
Let <var>associated element</var> be <var>document</var>'s root element, if there is one, or null otherwise.
13591361
</dl>
1360-
1. Let <var>behavior</var> be the {{ScrollOptions/behavior}} dictionary member of <var>options</var>.
13611362
1. <a>Perform a scroll</a> of <var>scrolling box</var> to <var>position</var>, <var>associated element</var> as the associated element and <var>behavior</var> as the scroll behavior.
13621363

13631364

1364-
To <dfn>scroll an element</dfn> <var>element</var> to <var>x</var>,<var>y</var> optionally with a scroll behavior <var>behavior</var> (which is <code>"auto"</code> if omitted) means to:
1365+
To <dfn>scroll an element</dfn> <var>element</var> to <var>x</var>,<var>y</var> optionally with a scroll behavior <var>behavior</var> (which is "<code>auto</code>" if omitted) means to:
13651366

13661367
1. Let <var>box</var> be <var>element</var>'s associated <a>scrolling box</a>.
13671368
1. <dl class=switch>

0 commit comments

Comments
 (0)