-
Notifications
You must be signed in to change notification settings - Fork 673
/
Overview.bs
1866 lines (1510 loc) · 102 KB
/
Overview.bs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<pre class='metadata'>
Title: CSSOM View Module
ED: https://drafts.csswg.org/cssom-view/
TR: https://www.w3.org/TR/cssom-view-1/
Previous Version: https://www.w3.org/TR/2016/WD-cssom-view-1-20160317/
Previous Version: https://www.w3.org/TR/2013/WD-cssom-view-20131217/
Previous Version: https://www.w3.org/TR/2011/WD-cssom-view-20110804/
Previous Version: https://www.w3.org/TR/2009/WD-cssom-view-20090804/
Previous Version: https://www.w3.org/TR/2008/WD-cssom-view-20080222/
Previous Version: https://www.w3.org/TR/2000/REC-DOM-Level-2-Style-20001113/
Group: CSSWG
Status: ED
Work Status: Revising
Shortname: cssom-view
Level: 1
Editor: Simon Pieters, Opera Software AS http://www.opera.com, [email protected]
Former Editor: Glenn Adams, Cox Communications, Inc. http://www.cox.com, [email protected], http://www.w3.org/wiki/User:Gadams
Former Editor: Anne van Kesteren, Opera Software ASA http://www.opera.com, [email protected], https://annevankesteren.nl/
!Legacy issues list: <a href="https://www.w3.org/Bugs/Public/buglist.cgi?product=CSS&component=CSSOM%20View&resolution=---">Bugzilla</a>
Abstract: The APIs introduced by this specification provide authors with a way to inspect and manipulate the visual view of a document. This includes getting the position of element layout boxes, obtaining the width of the viewport through script, and also scrolling an element.
Ignored Terms: open(), EventTarget, EventListener, Event, EventInit, Element, Range, Node, Text
Ignored Vars: rect, point, quad
Include Can I Use Panels: true
Can I Use URL: https://drafts.csswg.org/cssom-view/
Can I Use URL: https://www.w3.org/TR/cssom-view-1/
</pre>
<pre class='anchors'>
urlPrefix: https://html.spec.whatwg.org/multipage/
urlPrefix: infrastructure.html
type: dfn; text: html elements
urlPrefix: browsers.html
type: interface; text: WindowProxy
type: dfn
text: browsing context
text: auxiliary browsing context
text: familiar with
text: associated Document; url: concept-document-window
text: same origin
text: active document
urlPrefix: webappapis.html
type: dfn
text: responsible browsing context
text: incumbent settings object
text: event handlers
text: event handler event type
text: event handler IDL attributes
urlPrefix: infrastructure.html
type: dfn
text: split a string on commas
text: skip whitespace
text: collect a sequence of characters
text: space character
text: converted to ascii lowercase
text: rules for parsing integers
urlPrefix: https://drafts.csswg.org/cssom/
type: dfn
text: parse a media query list
text: serialize a media query list
urlPrefix: https://dom.spec.whatwg.org/#
type: dfn
text: context object
urlPrefix: https://dom.spec.whatwg.org/#concept-
type: dfn
text: event
text: event listener
text: quirks mode; url: document-quirks
text: fire an event; url: event-fire
text: node document
urlPrefix: https://dom.spec.whatwg.org/
type: attribute;
for: Event; urlPrefix: #dom-event-
text: type
text: isTrusted
for: Range; urlPrefix: #dom-range-
text: startContainer
text: startOffset
type: dfn; text: dispatch flag
urlPrefix: https://www.w3.org/TR/CSS21/visuren.html
type: dfn; text: anonymous block box; url: #anonymous-block-level
urlPrefix: http://heycam.github.io/webidl/
type: interface; urlPrefix: #idl-
text: double
text: long
type: dfn; text: converted to an IDL value; url: dfn-convert-ecmascript-to-idl-value
url: https://www.w3.org/TR/DOM-Level-3-Events/#interface-MouseEvent; type: interface; text: MouseEvent
url: https://drafts.csswg.org/mediaqueries-4/#mf-colors; type: dfn; text: color media query
</pre>
<pre class='link-defaults'>
spec:css-display-3; type:value; for:display; text:table
spec:css-position-3; type:property; text:position
spec:dom; type:interface; text:Document
spec:html; type:dfn; text:case-sensitive
</pre>
<script src=https://resources.whatwg.org/file-issue.js async data-file-issue-url="https://github.com/w3c/csswg-drafts/issues/new?title=%5Bcssom-view%5D%20"></script>
Background {#background}
========================
Many of the features defined in this specification have been supported
by browsers for a long period of time. The goal of this specification is
to define these features in such a way that they can be implemented by all
browsers in an interoperable manner. The specification also defines a
couple of new features that will hopefully be useful to authors. (If they
are not you can bug us!)
Terminology {#terminology}
==========================
Terminology used in this specification is from
DOM,
CSSOM and
HTML.
[[!DOM]]
[[!CSSOM]]
[[!HTML]]
<dfn>The HTML <code>body</code> element</dfn> is the first
<code>body</code>
<a>HTML element</a> child of the root
<a>HTML element</a> <code>html</code>.
<dfn>Content edge</dfn>, <dfn>padding edge</dfn>, <dfn>border edge</dfn>, <dfn>margin edge</dfn>, and <dfn>viewport</dfn> are defined by CSS.
<!-- These *should* just link to CSS2.1, but it doesn't have actual anchors to link to, because it's THE WORST. -->
Elements and <a>viewports</a> have an associated <dfn>scrolling box</dfn> if has a scrolling mechanism<!--XXX xref--> or it overflows
its content area<!--XXX xref--> and the used value of the 'overflow-x' or 'overflow-y' property is ''overflow/hidden''. [[!CSS3-BOX]]
An element is <dfn>potentially scrollable</dfn> if all of the following conditions are true:
* The element has an associated <a>CSS layout box</a>.
* The element is not <a>the HTML <code>body</code> element</a>, or it is and
the root element's used value of the 'overflow-x' or 'overflow-y' properties is not ''overflow/visible''.
* The element's used value of the 'overflow-x' or 'overflow-y' properties is not ''overflow/visible''.
Note: An element that is <a>potentially scrollable</a> might not have a <a>scrolling box</a>.
For instance, it could have 'overflow' set to ''overflow/auto'' but not have its content overflowing its content area.
A <a>scrolling box</a> of a <a>viewport</a> or element has two <dfn>overflow directions</dfn>, depending on the <a>viewport’s</a> or
element's <a>block flow direction</a> and <a>inline base direction</a>, as follows:
<dl class=switch>
<dt>If the <a>block flow direction</a> is top-to-bottom and the <a>inline base direction</a> is left-to-right
<dt>If the <a>block flow direction</a> is left-to-right and the <a>inline base direction</a> is left-to-right
<dd>Rightward and downward.
<dt>If the <a>block flow direction</a> is top-to-bottom and the <a>inline base direction</a> is right-to-left
<dt>If the <a>block flow direction</a> is right-to-left and the <a>inline base direction</a> is left-to-right
<dd>Leftward and downward.
<dt>If the <a>block flow direction</a> is right-to-left and the <a>inline base direction</a> is right-to-left
<dd>Leftward and upward.
<dt>If the <a>block flow direction</a> is left-to-right and the <a>inline base direction</a> is right-to-left
<dd>Rightward and upward.
</dl>
The term <dfn>scrolling area</dfn> refers to a box of a <a>viewport</a> or an element that has the following edges, depending on the
<a>viewport’s</a> or element's <a>scrolling box’s</a> <a>overflow directions</a>.
<table class="complex data">
<thead>
<tr>
<th>If the <a>overflow directions</a> are…
<th>For a <a>viewport</a>
<th>For an element
<tbody>
<tr>
<td>rightward and downward
<td class=long>
<dl>
<dt>top edge
<dd>The top edge of the <a>initial containing block</a>.
<dt>right edge
<dd>The right-most edge of the right edge of the <a>initial containing block</a> and the right
<a>margin edge</a> of all of the <a>viewport’s</a> descendants' boxes.
<dt>bottom edge
<dd>The bottom-most edge of the bottom edge of the <a>initial containing block</a> and the
bottom <a>margin edge</a> of all of the <a>viewport’s</a> descendants' boxes.
<dt>left edge
<dd>The left edge of the <a>initial containing block</a>.
</dl>
<td class=long>
<dl>
<dt>top edge
<dd>The element's top <a>padding edge</a>.
<dt>right edge
<dd>The right-most edge of the element's right <a>padding edge</a> and the right <a>margin
edge</a> of all of the element's descendants' boxes,
excluding boxes that have an ancestor of the element as their containing block.
<dt>bottom edge
<dd>The bottom-most edge of the element's bottom <a>padding edge</a> and the bottom <a>margin
edge</a> of all of the element's descendants'
boxes, excluding boxes that have an ancestor of the element as their containing block.
<dt>left edge
<dd>The element's left <a>padding edge</a>.
</dl>
<tr>
<td>leftward and downward
<td class=long>
<dl>
<dt>top edge
<dd>The top edge of the <a>initial containing block</a>.
<dt>right edge
<dd>The right edge of the <a>initial containing block</a>.
<dt>bottom edge
<dd>The bottom-most edge of the bottom edge of the <a>initial containing block</a> and the
bottom <a>margin edge</a> of all of the <a>viewport’s</a> descendants' boxes.
<dt>left edge
<dd>The left-most edge of the left edge of the <a>initial containing block</a> and the left
<a>margin edge</a> of all of the <a>viewport’s</a> descendants' boxes.
</dl>
<td class=long>
<dl>
<dt>top edge
<dd>The element's top <a>padding edge</a>.
<dt>right edge
<dd>The element's right <a>padding edge</a>.
<dt>bottom edge
<dd>The bottom-most edge of the element's bottom <a>padding edge</a> and the bottom <a>margin
edge</a> of all of the element's descendants' boxes, excluding boxes that have an ancestor of
the element as their containing block.
<dt>left edge
<dd>The left-most edge of the element's left <a>padding edge</a> and the left <a>margin
edge</a> of all of the element's descendants' boxes, excluding boxes that have an ancestor of
the element as their containing block.
</dl>
<tr>
<td>leftward and upward
<td class=long>
<dl>
<dt>top edge
<dd>The top-most edge of the top edge of the <a>initial containing block</a> and the top
<a>margin edge</a> of all of the <a>viewport’s</a> descendants' boxes.
<dt>right edge
<dd>The right edge of the <a>initial containing block</a>.
<dt>bottom edge
<dd>The bottom edge of the <a>initial containing block</a>.
<dt>left edge
<dd>The left-most edge of the left edge of the <a>initial containing block</a> and the left
<a>margin edge</a> of all of the <a>viewport’s</a> descendants' boxes.
</dl>
<td class=long>
<dl>
<dt>top edge
<dd>The top-most edge of the element's top <a>padding edge</a> and the top <a>margin edge</a>
of all of the element's descendants' boxes, excluding boxes that have an ancestor of the
element as their containing block.
<dt>right edge
<dd>The element's right <a>padding edge</a>.
<dt>bottom edge
<dd>The element's bottom <a>padding edge</a>.
<dt>left edge
<dd>The left-most edge of the element's left <a>padding edge</a> and the left <a>margin
edge</a> of all of the element's descendants' boxes, excluding boxes that have an ancestor of
the element as their containing block.
</dl>
<tr>
<td>rightward and upward
<td class=long>
<dl>
<dt>top edge
<dd>The top-most edge of the top edge of the <a>initial containing block</a> and the top
<a>margin edge</a> of all of the <a>viewport’s</a> descendants' boxes.
<dt>right edge
<dd>The right-most edge of the right edge of the <a>initial containing block</a> and the right
<a>margin edge</a> of all of the <a>viewport’s</a> descendants' boxes.
<dt>bottom edge
<dd>The bottom edge of the <a>initial containing block</a>.
<dt>left edge
<dd>The left edge of the <a>initial containing block</a>.
</dl>
<td class=long>
<dl>
<dt>top edge
<dd>The top-most edge of the element's top <a>padding edge</a> and the top <a>margin edge</a>
of all of the element's descendants' boxes, excluding boxes that have an ancestor of the
element as their containing block.
<dt>right edge
<dd>The right-most edge of the element's right <a>padding edge</a> and the right <a>margin
edge</a> of all of the element's descendants' boxes, excluding boxes that have an ancestor of
the element as their containing block.
<dt>bottom edge
<dd>The element's bottom <a>padding edge</a>.
<dt>left edge
<dd>The element's left <a>padding edge</a>.
</dl>
</table>
The <dfn lt="scrolling area origin">origin</dfn> of a <a>scrolling area</a> is
the origin of the <a>initial containing block</a> if the <a>scrolling area</a> is a <a>viewport</a>,
and otherwise the top left padding edge of the element when the element has its default scroll position.
The x-coordinate increases rightwards, and the y-coordinate increases downwards.
The <dfn>beginning edges</dfn> of a particular set of edges of a box or element are the following edges:
<dl class=switch>
<dt>If the <a>overflow directions</a> are rightward and downward
<dd>The top and left edges.
<dt>If the <a>overflow directions</a> are leftward and downward
<dd>The top and right edges.
<dt>If the <a>overflow directions</a> are leftward and upward
<dd>The bottom and right edges.
<dt>If the <a>overflow directions</a> are rightward and upward
<dd>The bottom and left edges.
</dl>
The <dfn>ending edges</dfn> of a particular set of edges of a box or element are the following edges:
<dl class=switch>
<dt>If the <a>overflow directions</a> are rightward and downward
<dd>The bottom and right edges.
<dt>If the <a>overflow directions</a> are leftward and downward
<dd>The bottom and left edges.
<dt>If the <a>overflow directions</a> are leftward and upward
<dd>The top and left edges.
<dt>If the <a>overflow directions</a> are rightward and upward
<dd>The top and right edges.
</dl>
The term <dfn>CSS layout box</dfn> refers to the same term in CSS. For the purpose
of the requirements in this specification, elements that have a computed value of the
'display' property that is ''table-column'' or
''table-column-group'' must be considered to have an associated <a>CSS layout box</a> (the column or column group, respectively).
The term <dfn>SVG layout box</dfn> refers to the same term in SVG.
<p class=issue>The terms <a>CSS layout box</a> and <a>SVG layout box</a> are not currently defined by CSS or SVG.
The term <dfn>layout box</dfn> refers to either a <a>CSS layout box</a> or an <a>SVG layout box</a>.
The term <dfn>transforms</dfn> refers to SVG transforms and CSS transforms. [[!SVG]] [[!CSS-TRANSFORMS-1]]
When a method or an attribute is said to call another method or attribute, the user agent must invoke its internal API for that attribute or method so that
e.g. the author can't change the behavior by overriding attributes or methods with custom properties or functions in ECMAScript.
Unless otherwise stated, string comparisons are done in a <a>case-sensitive</a> manner.
CSS pixels {#css-pixels}
------------------------
All coordinates and dimensions for the APIs defined in this
specification are in <a lt=px value>CSS pixels</a>, unless otherwise specified. [[!CSS-VALUES]]
Note: This does not apply to e.g. {{matchMedia()}} as the units are explicitly given there.
Zooming {#zooming}
------------------
There are two kinds of zoom, <dfn>page zoom</dfn> which affects the size of the initial viewport<!-- XXX ref -->, and <dfn>pinch zoom</dfn> which acts like
a magnifying glass and does not affect the initial viewport<!-- XXX ref --> or actual viewport<!-- XXX ref -->. [[!CSS-DEVICE-ADAPT]]
Web-exposed screen information {#web-exposed-screen-information}
----------------------------------------------------------------
User agents may choose to hide information about the screen of the output device, in order to
protect the user's privacy. In order to do so in a consistent manner across APIs, this specification
defines the following terms, each having a width and a height, the origin being the top left
corner, and the x- and y-coordinates increase rightwards and downwards, respectively.
The <dfn export>Web-exposed screen area</dfn> is one of the following:
* The area of the output device, in <a lt=px value>CSS pixels</a>.
* The area of the <a>viewport</a>, in <a lt=px value>CSS pixels</a>.
The <dfn export>Web-exposed available screen area</dfn> is one of the following:
* The available area of the rendering surface of the output device, in <a lt=px value>CSS pixels</a>.
* The area of the output device, in <a lt=px value>CSS pixels</a>.
* The area of the <a>viewport</a>, in <a lt=px value>CSS pixels</a>.
Common Infrastructure {#common-infrastructure}
==============================================
This specification depends on the WHATWG Infra standard. [[!INFRA]]
Scrolling {#scrolling}
----------------------
When a user agent is to <dfn>perform a scroll</dfn> of a <a>scrolling box</a> <var>box</var>,
to a given position <var>position</var>,
an associated element <var>element</var> and optionally a scroll behavior <var>behavior</var>
(which is <code>"auto"</code> if omitted),
the following steps must be run:
<ol>
<li><a lt="smooth scroll aborted">Abort</a> any ongoing <a>smooth scroll</a> for <var>box</var>.
<li>If the user agent honors the 'scroll-behavior' property and one of the following are true:
<ul>
<li><var>behavior</var> is <code>"auto"</code> and <var>element</var> is not null and its computed value of the
'scroll-behavior' property is ''smooth''
<li><var>behavior</var> is <code>smooth</code>
</ul>
...then perform a <a>smooth scroll</a> of <var>box</var> to <var>position</var>.
Otherwise, perform an <a>instant scroll</a> of <var>box</var> to <var>position</var>.
</ol>
When a user agent is to perform a <dfn id=concept-smooth-scroll>smooth scroll</dfn> of a <a>scrolling box</a> <var>box</var> to <var>position</var>,
it must update the scroll position of <var>box</var> in a user-agent-defined fashion over a user-agent-defined amount of time. When the scroll is
<dfn lt="smooth scroll completed">completed</dfn>, the scroll position of <var>box</var> must be <var>position</var>. The scroll can also
be <dfn lt="smooth scroll aborted">aborted</dfn>, either by an algorithm or by the user. <!--fingerprint-->
When a user agent is to perform an <dfn id=concept-instant-scroll>instant scroll</dfn> of a <a>scrolling box</a> <var>box</var> to
<var>position</var>, it must update the scroll position of <var>box</var> to <var>position</var>.
To <dfn>scroll to the beginning of the document</dfn> for a document <var>document</var>, follow these steps:
<ol>
<li>Let <var>viewport</var> be the <a>viewport</a> that is associated with <var>document</var>. <!-- This assumes that there is a viewport, since
it is only invoked when navigating -->
<li>Let <var>position</var> be the the scroll position <var>viewport</var> would have by aligning the <a>beginning edges</a> of the
<a>scrolling area</a> with the <a>beginning edges</a> of <var>viewport</var>.
<li>If <var>position</var> is the same as <var>viewport</var>'s current scroll position, and <var>viewport</var> does not have an ongoing
<a>smooth scroll</a>, abort these steps.
<li><a>Perform a scroll</a> of <var>viewport</var> to <var>position</var>,
and <var>document</var>'s root element as the associated element, if there is one, or null otherwise.
</ol>
Note: This algorithm is used when navigating to the <code>#top</code> fragment identifier, as defined in HTML. [[!HTML]]
WebIDL values {#webidl-values}
------------------------------
When asked to <dfn>normalize non-finite values</dfn> for a value <var>x</var>,
if <var>x</var> is one of the three special floating point literal values
(<code>Infinity</code>, <code>-Infinity</code> or <code>NaN</code>),
then <var>x</var> must be changed to the value <code>0</code>. [[!WEBIDL]]
Extensions to the {{Window}} Interface {#extensions-to-the-window-interface}
============================================================================
<pre class=idl>
enum ScrollBehavior { "auto", "instant", "smooth" };
dictionary ScrollOptions {
ScrollBehavior behavior = "auto";
};
dictionary ScrollToOptions : ScrollOptions {
unrestricted double left;
unrestricted double top;
};
partial interface Window {
[NewObject] MediaQueryList matchMedia(DOMString query);
[SameObject, Replaceable] readonly attribute Screen screen;
// browsing context
void moveTo(long x, long y);
void moveBy(long x, long y);
void resizeTo(long x, long y);
void resizeBy(long x, long y);
// viewport
[Replaceable] readonly attribute long innerWidth;
[Replaceable] readonly attribute long innerHeight;
// viewport scrolling
[Replaceable] readonly attribute double scrollX;
[Replaceable] readonly attribute double pageXOffset;
[Replaceable] readonly attribute double scrollY;
[Replaceable] readonly attribute double pageYOffset;
void scroll(optional ScrollToOptions options);
void scroll(unrestricted double x, unrestricted double y);
void scrollTo(optional ScrollToOptions options);
void scrollTo(unrestricted double x, unrestricted double y);
void scrollBy(optional ScrollToOptions options);
void scrollBy(unrestricted double x, unrestricted double y);
// client
[Replaceable] readonly attribute long screenX;
[Replaceable] readonly attribute long screenY;
[Replaceable] readonly attribute long outerWidth;
[Replaceable] readonly attribute long outerHeight;
[Replaceable] readonly attribute double devicePixelRatio;
};
</pre>
When the <dfn method for=Window caniuse=matchmedia>matchMedia(<var>query</var>)</dfn> method is invoked these steps must be run:
<ol>
<li>Let <var>parsed media query list</var> be the result of
<a lt='parse a media query list'>parsing</a>
<var>query</var>.
<li>Return a new {{MediaQueryList}} object,
with the <a>context object’s</a>
<a>associated <code>Document</code></a>
as the <a for=MediaQueryList>document</a>,
with <var>parsed media query list</var> as its associated <a>media query list</a>.
</ol>
The <dfn attribute for=Window>screen</dfn> attribute must return the {{Screen}} object
associated with the {{Window}} object.
Note: Accessing {{Window/screen}} through a {{WindowProxy}} object might yield different
results when the {{Document}} is navigated.
The <dfn method for=Window>moveTo(<var>x</var>, <var>y</var>)</dfn> method must follow these steps:
1. Optionally, terminate these steps.
1. Let <var>target</var> be the <a>browsing context</a> of the <a>context object</a>.
1. Let <var>source</var> be the <a>responsible browsing context</a> of the <a>incumbent settings object</a>.
1. If <var>source</var> is not <a>allowed to resize and move</a> <var>target</var>, terminate these steps.
1. Optionally, clamp <var>x</var> and <var>y</var> in a user-agent-defined manner so that the window does not move outside the available space.
1. Move <var>target</var>’s window such that the window’s top left corner is at coordinates (<var>x</var>, <var>y</var>) relative to the top left corner of the output device, measured in <a lt=px value>CSS pixels</a> of <var>target</var>. The positive axes are rightward and downward.
The <dfn method for=Window>moveBy(<var>x</var>, <var>y</var>)</dfn> method must follow these steps:
1. Optionally, terminate these steps.
1. Let <var>target</var> be the <a>browsing context</a> of the <a>context object</a>.
1. Let <var>source</var> be the <a>responsible browsing context</a> of the <a>incumbent settings object</a>.
1. If <var>source</var> is not <a>allowed to resize and move</a> <var>target</var>, terminate these steps.
1. Optionally, clamp <var>x</var> and <var>y</var> in a user-agent-defined manner so that the window does not move outside the available space.
1. Move <var>target</var>'s window <var>x</var> <a lt=px value>CSS pixels</a> of <var>target</var> rightward and <var>y</var> <a lt=px value>CSS pixels</a> of <var>target</var> downward.
The <dfn method for=Window>resizeTo(<var>x</var>, <var>y</var>)</dfn> method must follow these steps:
1. Optionally, terminate these steps.
1. Let <var>target</var> be the <a>browsing context</a> of the <a>context object</a>.
1. Let <var>source</var> be the <a>responsible browsing context</a> of the <a>incumbent settings object</a>.
1. If <var>source</var> is not <a>allowed to resize and move</a> <var>target</var>, terminate these steps.
1. Optionally, clamp <var>x</var> and <var>y</var> in a user-agent-defined manner so that the window does not get too small or bigger than the available space.
1. Resize <var>target</var>'s window by moving its right and bottom edges such that the distance between the left and right edges of the viewport are <var>x</var> <a lt=px value>CSS pixels</a> of <var>target</var> and the distance between the top and bottom edges of the viewport are <var>y</var> <a lt=px value>CSS pixels</a> of <var>target</var>.
1. Optionally, move <var>target</var>'s window in a user-agent-defined manner so that it does not grow outside the available space.
The <dfn method for=Window>resizeBy(<var>x</var>, <var>y</var>)</dfn> method must follow these steps:
1. Optionally, terminate these steps.
1. Let <var>target</var> be the <a>browsing context</a> of the <a>context object</a>.
1. Let <var>source</var> be the <a>responsible browsing context</a> of the <a>incumbent settings object</a>.
1. If <var>source</var> is not <a>allowed to resize and move</a> <var>target</var>, terminate these steps.
1. Optionally, clamp <var>x</var> and <var>y</var> in a user-agent-defined manner so that the window does not get too small or bigger than the available space.
1. Resize <var>target</var>'s window by moving its right edge <var>x</var> <a lt=px value>CSS pixels</a> of <var>target</var> rightward and its bottom edge <var>y</var> <a lt=px value>CSS pixels</a> of <var>target</var> downward.
1. Optionally, move <var>target</var>'s window in a user-agent-defined manner so that it does not grow outside the available space.
A <a>browsing context</a> <var>A</var> is <dfn>allowed to resize and move</dfn> a <a>browsing context</a> <var>B</var> if all the following conditions are met:
* <var>B</var> is an <a>auxiliary browsing context</a> that was created by a script (as opposed to by an action of the user).
* <var>A</var> is <a>familiar with</a> <var>B</var>.
The <dfn attribute for=Window>innerWidth</dfn> attribute must return the <a>viewport</a> width including the size of a rendered
scroll bar (if any), or zero if there is no <a>viewport</a>. <!--fingerprint-->
<div class='example'>
The following snippet shows how to obtain the width of the viewport:
<pre>var viewportWidth = innerWidth</pre>
</div>
The <dfn attribute for=Window>innerHeight</dfn> attribute must return the <a>viewport</a> height including the size of a rendered
scroll bar (if any), or zero if there is no <a>viewport</a>. <!--fingerprint-->
The <dfn attribute for=Window>scrollX</dfn> attribute attribute must return the x-coordinate,
relative to the <a>initial containing block</a> origin,
of the left of the <a>viewport</a>,
or zero if there is no <a>viewport</a>. <!--fingerprint-->
The <dfn attribute for=Window>pageXOffset</dfn> attribute must return the value returned by the {{scrollX}} attribute.
The <dfn attribute for=Window>scrollY</dfn> attribute attribute must return the y-coordinate,
relative to the <a>initial containing block</a> origin,
of the top of the <a>viewport</a>,
or zero if there is no <a>viewport</a>. <!--fingerprint-->
The <dfn attribute for=Window>pageYOffset</dfn> attribute must return the value returned by the {{scrollY}} attribute.
When the <dfn method for=Window lt="scroll(options)|scroll(x, y)">scroll()</dfn> method is invoked these
steps must be run:
1. If invoked with one argument, follow these substeps:
1. Let <var>options</var> be the argument.
1. Let <var>x</var> be the value of the {{ScrollToOptions/left}} dictionary member of <var>options</var>, if present,
or the <a>viewport’s</a> current scroll position on the x axis otherwise.
1. Let <var>y</var> be the value of the {{ScrollToOptions/top}} dictionary member of <var>options</var>, if present,
or the <a>viewport’s</a> current scroll position on the y axis otherwise.
1. If invoked with two arguments, follow these substeps:
1. Let <var>options</var> be null <a lt="converted to an IDL value">converted</a> to a {{ScrollToOptions}} dictionary. [[!WEBIDL]]
1. Let <var>x</var> and <var>y</var> be the arguments, respectively.
1. <a>Normalize non-finite values</a> for <var>x</var> and <var>y</var>.
1. If there is no <a>viewport</a>, abort these steps.
1. Let <var>viewport width</var> be the width of the <a>viewport</a> excluding the width of the scroll bar, if any.
1. Let <var>viewport height</var> be the height of the <a>viewport</a> excluding the height of the scroll bar, if any.
1.
<dl class=switch>
<dt>If the <a>viewport</a> has rightward <a>overflow direction</a>
<dd>Let <var>x</var> be max(0, min(<var>x</var>, <a>viewport</a> <a>scrolling area</a> width - <var>viewport width</var>)).
<dt>If the <a>viewport</a> has leftward <a>overflow direction</a>
<dd>Let <var>x</var> be min(0, max(<var>x</var>, <var>viewport width</var> - <a>viewport</a> <a>scrolling area</a> width)).
</dl>
1.
<dl class=switch>
<dt>If the <a>viewport</a> has downward <a>overflow direction</a>
<dd>Let <var>y</var> be max(0, min(<var>y</var>, <a>viewport</a> <a>scrolling area</a> height - <var>viewport height</var>)).
<dt>If the <a>viewport</a> has upward <a>overflow direction</a>
<dd>Let <var>y</var> be min(0, max(<var>y</var>, <var>viewport height</var> - <a>viewport</a> <a>scrolling area</a> height)).
</dl>
1. Let <var>position</var> be the scroll position the <a>viewport</a> would have
by aligning the x-coordinate <var>x</var> of the <a>viewport</a> <a>scrolling area</a>
with the left of the <a>viewport</a>
and aligning the y-coordinate <var>y</var> of the <a>viewport</a> <a>scrolling area</a>
with the top of the <a>viewport</a>.
1. If <var>position</var> is the same as the <a>viewport’s</a> current scroll position,
and the <a>viewport</a> does not have an ongoing <a>smooth scroll</a>, abort these steps.
1. Let <var>document</var> be the <a>viewport’s</a> associated {{Document}}.
1. <a>Perform a scroll</a> of the <a>viewport</a> to <var>position</var>,
<var>document</var>'s root element as the associated element, if there is one, or null otherwise,
and the scroll behavior being the value of the {{ScrollOptions/behavior}} dictionary member of <var>options</var>.
When the <dfn method for=Window lt="scrollTo(options)|scrollTo(x, y)">scrollTo()</dfn> method is invoked, the
user agent must act as if the {{Window/scroll()}} method was invoked with the same arguments.
When the <dfn method for=Window lt="scrollBy(options)|scrollBy(x, y)">scrollBy()</dfn> method is invoked, the
user agent must run these steps:
1. If invoked with two arguments, follow these substeps:
1. Let <var>options</var> be null <a lt="converted to an IDL value">converted</a> to a {{ScrollToOptions}} dictionary. [[!WEBIDL]]
1. Let <var>x</var> and <var>y</var> be the arguments, respectively.
1. Let the {{ScrollToOptions/left}} dictionary member of <var>options</var> have the value <var>x</var>.
1. Let the {{ScrollToOptions/top}} dictionary member of <var>options</var> have the value <var>y</var>.
1. <a>Normalize non-finite values</a> for the {{ScrollToOptions/left}} and {{ScrollToOptions/top}} dictionary members of <var>options</var>.
1. Add the value of {{scrollX}} to the {{ScrollToOptions/left}} dictionary member.
1. Add the value of {{scrollY}} to the {{ScrollToOptions/top}} dictionary member.
1. Act as if the {{Window/scroll()}} method was invoked with <var>options</var> as the only argument.
The <dfn attribute for=Window>screenX</dfn> attribute must return the x-coordinate,
relative to the origin of the <a>Web-exposed screen area</a>, of the left of
the client window as number of pixels, or zero if there is no such
thing. <!--fingerprint-->
The <dfn attribute for=Window>screenY</dfn> attribute must return the y-coordinate,
relative to the origin of the screen of the <a>Web-exposed screen area</a>, of the top of
the client window as number of pixels, or zero if there is no such
thing. <!--fingerprint-->
The <dfn attribute for=Window>outerWidth</dfn> attribute must return the width of the
client window. If there is no client window this
attribute must return zero. <!--fingerprint-->
The <dfn attribute for=Window>outerHeight</dfn> attribute must return the height of the
client window. If there is no client window this
attribute must return zero. <!--fingerprint-->
The <dfn attribute for=Window caniuse=devicepixelratio>devicePixelRatio</dfn> attribute must return the result of the following algorithm:
1. If there is no output device, return 1 and abort these steps.
1. Let <var>CSS pixel size</var> be the size of a <a lt=px value>CSS pixel</a> at the current <a>page zoom</a> scale factor and at a <a>pinch zoom</a> scale factor of 1.0.
1. Let <var>device pixel size</var> be the vertical size of a device pixel of the output device.
1. Return the result of dividing <var>CSS pixel size</var> by <var>device pixel size</var>.
The <var ignore>features</var> argument to the {{Window/open()}} method {#the-features-argument-to-the-open()-method}
--------------------------------------------------------------------------------------------------------------
HTML defines the {{Window/open()}} method. This section defines behavior for position and size given
in the <var ignore>features</var> argument. [[!HTML]]
To <dfn export>set up browsing context features</dfn> for a browsing context <var>target</var> given a
<a>map</a> <var>tokenizedFeatures</var>:
1. Let <var>x</var> be null.
1. Let <var>y</var> be null.
1. Let <var>width</var> be null.
1. Let <var>height</var> be null.
1. If <var>tokenizedFeatures</var>["<a for="supported open() feature name">left</a>"]
<a for=map>exists</a>:
1. Set <var>x</var> to the result of invoking the <a>rules for parsing integers</a> on
<var>tokenizedFeatures</var>["<a for="supported open() feature name">left</a>"].
1. If <var>x</var> is an error, set <var>x</var> to 0.
1. Optionally, clamp <var>x</var> in a user-agent-defined manner so that the window does not
move outside the <a>Web-exposed available screen area</a>.
1. Optionally, move <var>target</var>'s window such that the window's left edge is at the
horizontal coordinate <var>x</var> relative to the left edge of the <a>Web-exposed screen
area</a>, measured in <a lt=px value>CSS pixels</a> of <var>target</var>. The positive axis is rightward.
1. If <var>tokenizedFeatures</var>["<a for="supported open() feature name">top</a>"]
<a for=map>exists</a>:
1. Set <var>y</var> to the result of invoking the <a>rules for parsing integers</a> on
<var>tokenizedFeatures</var>["<a for="supported open() feature name">top</a>"].
1. If <var>y</var> is an error, set <var>y</var> to 0.
1. Optionally, clamp <var>y</var> in a user-agent-defined manner so that the window does not
move outside the <a>Web-exposed available screen area</a>.
1. Optionally, move <var>target</var>'s window such that the window's top edge is at the
vertical coordinate <var>y</var> relative to the top edge of the <a>Web-exposed screen
area</a>, measured in <a lt=px value>CSS pixels</a> of <var>target</var>. The positive axis is downward.
1. If <var>tokenizedFeatures</var>["<a for="supported open() feature name">width</a>"]
<a for=map>exists</a>:
1. Set <var>width</var> to the result of invoking the <a>rules for parsing integers</a> on
<var>tokenizedFeatures</var>["<a for="supported open() feature name">width</a>"].
1. If <var>width</var> is an error, set <var>width</var> to 0.
1. If <var>width</var> is not 0:
1. Optionally, clamp <var>width</var> in a user-agent-defined manner so that the window does
not get too small or bigger than the <a>Web-exposed available screen area</a>.
1. Optionally, size <var>target</var>'s window by moving its right edge such that the
distance between the left and right edges of the viewport are <var>width</var> CSS
pixels of <var>target</var>.
1. Optionally, move <var>target</var>'s window in a user-agent-defined manner so that it
does not grow outside the <a>Web-exposed available screen area</a>.
1. If <var>tokenizedFeatures</var>["<a for="supported open() feature name">height</a>"]
<a for=map>exists</a>:
1. Set <var>height</var> to the result of invoking the <a>rules for parsing integers</a> on
<var>tokenizedFeatures</var>["<a for="supported open() feature name">height</a>"].
1. If <var>height</var> is an error, set <var>height</var> to 0.
1. If <var>height</var> is not 0:
1. Optionally, clamp <var>height</var> in a user-agent-defined manner so that the window
does not get too small or bigger than the <a>Web-exposed available screen area</a>.
1. Optionally, size <var>target</var>'s window by moving its bottom edge such that the
distance between the top and bottom edges of the viewport are <var>height</var> CSS
pixels of <var>target</var>.
1. Optionally, move <var>target</var>'s window in a user-agent-defined manner so that it
does not grow outside the <a>Web-exposed available screen area</a>.
A <dfn export>supported <code>open()</code> feature name</dfn> is one of the following:
<dl dfn-for="supported open() feature name" export>
<dt><dfn>width</dfn>
<dd>The width of the viewport.
<dt><dfn>height</dfn>
<dd>The height of the viewport.
<dt><dfn>left</dfn>
<dd>The left position of the window.
<dt><dfn>top</dfn>
<dd>The top position of the window.
</dl>
The {{MediaQueryList}} Interface {#the-mediaquerylist-interface}
----------------------------------------------------------------
This section integrates with the <a spec=html>event loop</a> defined in HTML. [[!HTML]]
A {{MediaQueryList}} object has an associated <dfn>media query list</dfn>
and an associated <dfn for=MediaQueryList>document</dfn> set on creation.
A {{MediaQueryList}} object has an associated <dfn for=MediaQueryList>media</dfn> which is the
<a lt='serialize a media query list'>serialized</a> form of the associated <a>media query list</a>.
A {{MediaQueryList}} object has an associated <dfn for=MediaQueryList>matches state</dfn> which is
true if the associated <a>media query list</a> matches the state of the <a for=MediaQueryList>document</a>, and false otherwise.
<!--XXX update the matches state when flushing layout (offsetWidth et al), without firing a change event. -->
When asked to <dfn>evaluate media queries and report changes</dfn> for a {{Document}} <var>doc</var>, run these steps:
<ol>
<li>
For each {{MediaQueryList}} object <var>target</var> that has <var>doc</var> as its <a for=MediaQueryList>document</a>,
in the order they were created, oldest first, run these substeps:
<ol>
<li>If <var>target</var>'s <a>matches state</a> has changed since the last time these steps were run,
<a>fire an event</a> at <var>target</var>
using the {{MediaQueryListEvent}} constructor,
with its {{Event/type}} attribute initialized to <a event>change</a>,
its {{Event/isTrusted}} attribute initialized to true,
its {{MediaQueryList/media}} attribute initialized to <var>target</var>'s <a>media</a>,
and its {{MediaQueryListEvent/matches}} attribute initialized to <var>target</var>'s <a>matches state</a>. <!--fingerprint-->
</ol>
</ol>
<div class='example'>
A simple piece of code that detects changes in the orientation of the viewport can be written as follows:
<pre class='lang-javascript'>
function handleOrientationChange(event) {
if(event.matches) // landscape
…
else
…
}
var mql = matchMedia("(orientation:landscape)");
mql.onchange = handleOrientationChange;
</pre>
</div>
<pre class=idl>
interface MediaQueryList : EventTarget {
readonly attribute DOMString media;
readonly attribute boolean matches;
void addListener(EventListener? listener);
void removeListener(EventListener? listener);
attribute EventHandler onchange;
};
</pre>
The <dfn attribute for=MediaQueryList>media</dfn> attribute must return
the associated <a>media</a>.
The <dfn attribute for=MediaQueryList>matches</dfn> attribute must return
the associated <a>matches state</a>. <!--fingerprint-->
The <dfn method for=MediaQueryList>addListener(<var>listener</var>)</dfn> method must run these steps:
1. If <var>listener</var> is null, terminate these steps.
1. Append an <a>event listener</a> to the associated list of <a>event listeners</a>
with <b>type</b> set to <code>change</code>,
<b>callback</b> set to <var>listener</var>,
and <b>capture</b> set to false,
unless there already is an <a>event listener</a> in that list
with the same <b>type</b>, <b>callback</b>, and <b>capture</b>.
The <dfn method for=MediaQueryList>removeListener(<var>listener</var>)</dfn> method must run these steps:
1. Remove an <a>event listener</a> from the associated list of <a>event listeners</a>,
whose <b>type</b> is <code>change</code>,
<b>callback</b> is <var>listener</var>,
and <b>capture</b> is false.
Note: This specification initially had a custom callback mechanism with {{addListener()}} and
{{removeListener()}}, and the callback was invoked with the associated media query list as argument.
Now the normal event mechanism is used instead.
For backwards compatibility, the {{addListener()}} and {{removeListener()}} methods
are basically aliases for {{addEventListener()}} and {{removeEventListener()}}, respectively,
and the <code>change</code> event masquerades as a {{MediaQueryList}}.
The following are the <a>event handlers</a>
(and their corresponding <a>event handler event types</a>) that must be supported,
as <a>event handler IDL attributes</a>, by all objects implementing the {{MediaQueryList}} interface:
<table class="complex data">
<thead>
<tr>
<th><a>Event handler</a>
<th><a>Event handler event type</a>
<tbody>
<tr>
<td><dfn attribute for=MediaQueryList>onchange</dfn>
<td><a event>change</a>
</table>
<pre class=idl>
[Constructor(DOMString type, optional MediaQueryListEventInit eventInitDict)]
interface MediaQueryListEvent : Event {
readonly attribute DOMString media;
readonly attribute boolean matches;
};
dictionary MediaQueryListEventInit : EventInit {
DOMString media = "";
boolean matches = false;
};
</pre>
The <dfn attribute for=MediaQueryListEvent>media</dfn> attribute must return the value it was initialized to.
The <dfn attribute for=MediaQueryListEvent>matches</dfn> attribute must return the value it was initialized to.
<h4 id=mediaquerylist-event-summary>Event summary</h4>
<i>This section is non-normative.</i>
<table class="complex data">
<thead>
<tr>
<th>Event
<th>Interface
<th>Interesting targets
<th>Description
<tbody>
<tr>
<td><dfn event for=MediaQueryList>change</dfn>
<td>{{Event}}
<td>{{MediaQueryList}}
<td>Fired at the {{MediaQueryList}} when the <a>matches state</a> changes.
</table>
The {{Screen}} Interface {#the-screen-interface}
------------------------------------------------
As its name suggests, the {{Screen}} interface represents information about the screen of the output device.
<pre class=idl>
interface Screen {
readonly attribute long availWidth;
readonly attribute long availHeight;
readonly attribute long width;
readonly attribute long height;
readonly attribute unsigned long colorDepth;
readonly attribute unsigned long pixelDepth;
};
</pre>
The <dfn attribute for=Screen>availWidth</dfn> attribute must return the width of the <a>Web-exposed
available screen area</a>. <!--fingerprint-->
The <dfn attribute for=Screen>availHeight</dfn> attribute must return the height of the
<a>Web-exposed available screen area</a>. <!--fingerprint-->
The <dfn attribute for=Screen>width</dfn> attribute must return the width of the <a>Web-exposed
screen area</a>. <!--fingerprint-->
The <dfn attribute for=Screen>height</dfn> attribute must return the height of the <a>Web-exposed
screen area</a>. <!--fingerprint-->
The <dfn attribute for=Screen>colorDepth</dfn> and <dfn attribute
for=Screen>pixelDepth</dfn> attributes should return the number of bits
allocated to colors for a pixel in the output device, excluding the alpha
channel. If the user agent is not able to return the number of bits used by the
output device, it should return the closest estimation such as, for example, the
number of bits used by the frame buffer sent to the display or any internal
representation that would be the closest to the value the output device would
use. The user agent must return a value for these attributes at least equal to
the value of <a>color media query</a> multiplied by three. If the different
color components are not represented with the same number of bits, the returned
value may be greater than three times <a>color media query</a>. If the user
agent does not know the color depth or does not want to return it for privacy
considerations, it should return 24.
Note: The {{colorDepth}} and {{pixelDepth}} attributes return the same value for
compatibility reasons.
Note: Some non-conforming implementations are known to return 32 instead of 24.
<div class='example'>
<code>colorDepth</code> can be used in the context of selecting SDR/HDR in
addition with other information. For example, combined with color gamut.
<pre class='lang-javascript'>
if (screen.colorDepth >= 48 && window.matchMedia('(color-gamut: p3)').matches &&
/* other checks */) {
// Use HDR content.
} else {
// Use SDR content.
}
</pre>
</div>
Extensions to the {{Document}} Interface {#extensions-to-the-document-interface}
================================================================================
<pre class=idl>
partial interface Document {
Element? elementFromPoint(double x, double y);
sequence<Element> elementsFromPoint(double x, double y);
CaretPosition? caretPositionFromPoint(double x, double y);
readonly attribute Element? scrollingElement;
};
</pre>
The <dfn method for=Document caniuse=element-from-point>elementFromPoint(<var>x</var>, <var>y</var>)</dfn> method must follow these steps:
1. If either argument is negative, <var>x</var> is greater than the <a>viewport</a> width excluding the size of a rendered scroll bar (if any), or
<var>y</var> is greater than the <a>viewport</a> height excluding the size of a rendered scroll bar (if any), or there is no <a>viewport</a>
associated with the document, return null and terminate these steps.
1. If there is a <a>layout box</a> in the <a>viewport</a> that would be a target for hit testing at coordinates <var>x</var>,<var>y</var>,
when applying the <a>transforms</a> that apply to the descendants of the <a>viewport</a>, return the associated element and terminate these steps.
1. If the document has a root element, return the root element and terminate these steps.
1. Return null.
Note: The {{elementFromPoint()}} method does not necessarily return the top-most painted element. For
instance, an element can be excluded from being a target for hit testing by using the 'pointer-events' CSS property.
<p>
The <dfn method for=Document>elementsFromPoint(<var>x</var>, <var>y</var>)</dfn> method must follow these steps:
1. Let <var>sequence</var> be a new empty sequence.
1. If either argument is negative, <var>x</var> is greater than the <a>viewport</a> width excluding the size of a rendered scroll bar (if any), or
<var>y</var> is greater than the <a>viewport</a> height excluding the size of a rendered scroll bar (if any), or there is no <a>viewport</a>
associated with the document, return <var>sequence</var> and terminate these steps.
1. For each <a>layout box</a> in the <a>viewport</a>, in paint order, starting with the topmost box, that would be a target for hit testing at
coordinates <var>x</var>,<var>y</var> even if nothing would be overlapping it, when applying the <a>transforms</a> that apply to the descendants of the
<a>viewport</a>, append the associated element to <var>sequence</var>.
1. If the document has a root element, and the last item in <var>sequence</var> is not the root element, append the root element to <var>sequence</var>.
1. Return <var>sequence</var>.
The <dfn method for=Document>caretPositionFromPoint(<var>x</var>, <var>y</var>)</dfn> method must return the
result of running these steps:
1. If there is no <a>viewport</a> associated with the document, return null.
1. If either argument is negative, <var>x</var> is greater
than the <a>viewport</a> width excluding the size of a rendered
scroll bar (if any), <var>y</var> is greater than the
<a>viewport</a> height excluding the size of a rendered scroll bar
(if any) return null.
1. If at the coordinates <var>x</var>,<var>y</var>
in the <a>viewport</a> no text insertion point indicator would have
been inserted when applying the <a>transforms</a> that apply to the descendants of the <a>viewport</a>, return null.
1. If at the coordinates <var>x</var>,<var>y</var>
in the <a>viewport</a> a text insertion point indicator would have
been inserted in a text entry widget which is also a replaced element, when applying the <a>transforms</a> that apply to the descendants of the