-
Notifications
You must be signed in to change notification settings - Fork 29
/
index.html
961 lines (956 loc) · 34.8 KB
/
index.html
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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>
Screen Orientation
</title>
<script src="https://www.w3.org/Tools/respec/respec-w3c" class=
"remove"></script>
<script class="remove">
var respecConfig = {
specStatus: "ED",
shortName: "screen-orientation",
previousPublishDate: "2019-05-30",
previousMaturity: "WD",
editors: [
{
name: "Marcos Cáceres",
company: "Apple Inc.",
w3cid: 39125,
},
],
formerEditors: [
{
name: "Mounir Lamouri",
company: "Google Inc.",
},
{
name: "Johanna Herman",
company: "Invited Expert",
},
],
testSuiteURI: "https://wpt.live/screen-orientation/",
github: "w3c/screen-orientation",
group: "webapps",
caniuse: "screen-orientation",
xref: "web-platform",
};
</script>
</head>
<body data-cite="CSSOM-VIEW mediaqueries-5 appmanifest">
<section id="abstract">
<p>
The <cite>Screen Orientation</cite> specification standardizes the
types and angles for a device's screen orientation, and provides a
means for locking and unlocking it. The API, defined by this
specification, exposes the current type and angle of the device's
screen orientation, and dispatches events when it changes. This enables
web applications to programmatically adapt the user experience for
multiple screen orientations, working alongside CSS. The API also
allows for the screen orientation to be locked under certain
preconditions. This is particularly useful for applications such as
computer games, where users physically rotate the device, but the
screen orientation itself should not change.
</p>
</section>
<section id="sotd">
<p>
This document is a work in progress.
</p>
</section>
<section class="informative">
<h2>
Example of usage
</h2>
<p>
In this example clicking the "Lock" button requests to go into
fullscreen and then locks the screen to the opposite orientation.
clicking the "unlock" button unlocks the screen.
</p>
<pre class="example html" title=
"Locking to a specific orientation and unlocking">
<script>
function updateLockButton() {
const lockButton = document.getElementById("button");
const newOrientation = getOppositeOrientation();
lockButton.textContent = `Lock to ${newOrientation}`;
}
function getOppositeOrientation() {
return screen
.orientation
.type
.startsWith("portrait") ? "landscape" : "portrait";
}
async function rotate(lockButton) {
if (!document.fullscreenElement) {
await document.documentElement.requestFullscreen();
}
const newOrientation = getOppositeOrientation();
await screen.orientation.lock(newOrientation);
updateLockButton(lockButton);
}
screen.orientation.addEventListener("change", updateLockButton);
window.addEventListener("load", updateLockButton);
</script>
<button onclick="rotate(this)" id="button">
Lock to...
</button>
<button onclick="screen.orientation.unlock()">
Unlock
</button>
</pre>
</section>
<section>
<h2>
Concepts
</h2>
<p>
To <dfn data-local-lt="locking the screen orientation|locked">lock the
screen orientation</dfn> to an {{OrientationLockType}} |orientation|
means that the screen can only be rotated by the user to a specific
[=screen orientation=] - possibly at the exclusion of other
orientations. The possible orientations to which the screen can be
rotated is determined by the user agent, a user preference, the
operating system's conventions, or the screen itself. For example,
locking the orientation to [=landscape=] means that the screen can be
rotated by the user to [=landscape-primary=] and maybe
[=landscape-secondary=] if the system allows it, but won't change the
orientation to [=portrait-secondary=] orientation.
</p>
<p>
To <dfn data-local-lt=
"unlocking the screen orientation|unlocked">unlock the screen
orientation</dfn> the end user is unrestricted to rotate the screen to
any [=screen orientation=] that the system allows.
</p>
<section>
<h2>
Screen orientation types
</h2>
<p>
A screen can be in, or [=locked=] to, one of the following
<dfn>screen orientations</dfn>:
</p>
<dl data-sort="ascending">
<dt>
<dfn>Natural</dfn>
</dt>
<dd>
The most natural orientation for the device's display as determined
by the user agent, the user, the operating system, or the screen
itself. For example, a device viewed, or held upright in the user's
hand, with the screen facing the user. A computer monitor are
commonly naturally [=landscape-primary=], while a mobile phones are
commonly naturally [=portrait-primary=].
</dd>
<dt>
<dfn>Landscape</dfn>
</dt>
<dd>
The screen's aspect ratio has a width greater than the height.
</dd>
<dt>
<dfn>Portrait</dfn>
</dt>
<dd>
The screen's aspect ratio has a height greater than the width.
</dd>
<dt>
<dfn data-local-lt=
"landscape-primary|portrait-primary">Primary</dfn>
</dt>
<dd>
The device's screen [=natural=] orientation for either [=portrait=]
or [=landscape=].
</dd>
<dt>
<dfn data-local-lt=
"landscape-secondary|portrait-secondary">Secondary</dfn>
</dt>
<dd>
The opposite of the device's screen <a>primary</a> orientation for
[=portrait=] or [=landscape=].
</dd>
<dt>
<dfn>Any</dfn>
</dt>
<dd>
The screen can be rotated by the user to any orientation allowed by
the device's operating system or by the end-user.
</dd>
<dt>
<dfn data-lt="default screen orientation" data-export=
"">Default</dfn> (unlocked)
</dt>
<dd data-cite="appmanifest">
The device's default behavior for when the screen is [=unlocked=]
(i.e., the [=Screen/active orientation lock=] is `null`). This
orientation is determined by the device's operating system, or the
user agent, or controlled by the end-user, or possibly set by an
[=installed web application=]. For example, when the screen
orientation is unlocked and the user rotates the device, some
devices will limit orientation changes to [=portrait-primary=],
[=landscape-primary=], and [=landscape-secondary=], but not to
[=portrait-secondary=].
</dd>
</dl>
</section>
<section>
<h2>
The current screen orientation type and angle
</h2>
<p>
The screen of the output device has the following associated
concepts:
</p>
<dl data-sort="ascending">
<dt>
<dfn data-dfn-for="Screen">Current orientation type</dfn>
</dt>
<dd>
The [=screen orientation=] of the screen, represented as a
{{OrientationType}}.
</dd>
<dt>
<dfn data-dfn-for="Screen">Current orientation angle</dfn>
</dt>
<dd>
The angle in degrees that the screen is rotated counter-clockwise
from its [=natural=] orientation as derived by the [=screen
orientation values list=].
</dd>
<dt>
<dfn data-dfn-for="Screen">Active orientation lock</dfn>
</dt>
<dd>
The [=screen orientation=], represented as a
{{OrientationLockType}}, to which the screen is [=locked=], or
`null` when [=unlocked=].
</dd>
</dl>
<p>
The <dfn>screen orientation values lists</dfn> below standardize the
angles associated with each screen orientation type for screens with
different [=natural=] orientations:
</p>
<dl>
<dt>
For screens with a [=natural=] [=portrait=] orientation:
</dt>
<dd>
<ul>
<li>[=portrait-primary=]: 0°
</li>
<li>[=landscape-primary=]: 90°
</li>
<li>[=portrait-secondary=]: 180°
</li>
<li>[=landscape-secondary=]: 270°
</li>
</ul>
</dd>
<dt>
For screens with a [=natural=] [=landscape=] orientation:
</dt>
<dd>
<ul>
<li>[=landscape-primary=]: 0°
</li>
<li>[=portrait-primary=]: 90°
</li>
<li>[=landscape-secondary=]: 180°
</li>
<li>[=portrait-secondary=]: 270°
</li>
</ul>
</dd>
</dl>
</section>
</section>
<section>
<h2>
Extensions to the `Document` interface
</h2>
<section>
<h2>
Internal Slots
</h2>
<p>
The {{Document}} interface is extended with the following internal
slots:
</p>
<table class="simple">
<thead>
<tr>
<th>
Internal Slot
</th>
<th>
Description
</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<dfn data-dfn-for=
"Document">[[\orientationPendingPromise]]</dfn>
</td>
<td>
Either `null` or a {{Promise}}. When assigned a {{Promise}},
that promise represents a request to lock the screen
orientation.
</td>
</tr>
</tbody>
</table>
</section>
</section>
<section data-dfn-for="Screen">
<h2>
Extensions to the `Screen` interface
</h2>
<pre class="idl">
partial interface Screen {
[SameObject] readonly attribute ScreenOrientation orientation;
};
</pre>
<p>
The {{Window}} object has an <dfn>associated `ScreenOrientation`</dfn>,
which is a {{Screen}}'s {{Screen/orientation}} object (i.e., the
{{ScreenOrientation}} instance at `window.screen.orientation`).
</p>
</section>
<section data-dfn-for="ScreenOrientation" data-link-for=
"ScreenOrientation">
<h2>
<dfn>ScreenOrientation</dfn> interface
</h2>
<pre class="idl">
[Exposed=Window]
interface ScreenOrientation : EventTarget {
Promise<undefined> lock(OrientationLockType orientation);
undefined unlock();
readonly attribute OrientationType type;
readonly attribute unsigned short angle;
attribute EventHandler onchange;
};
</pre>
<section>
<h2>
Internal Slots
</h2>
<table class="simple">
<thead>
<tr>
<th>
Internal Slot
</th>
<th>
Description
</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<dfn>[[\angle]]</dfn>
</td>
<td>
Represents the screen's last known [=Screen/current orientation
angle=] in degrees as an {{unsigned short}} as derived from the
[=screen orientation values lists=].
</td>
</tr>
<tr>
<td>
<dfn>[[\initialType]]</dfn>
</td>
<td>
Represents the screen's [=Screen/current orientation type=]
when the [=browsing context=] was created.
</td>
</tr>
<tr>
<td>
<dfn>[[\type]]</dfn>
</td>
<td>
Represents the screen's last known [=Screen/current orientation
type=] as an {{OrientationType}} enum value.
</td>
</tr>
</tbody>
</table>
</section>
<section>
<h2>
`lock()` method
</h2>
<p>
When the {{lock()}} method is invoked with {{OrientationLockType}}
|orientation:OrientationLockType|, the [=user agent=] MUST run the
following steps.
</p>
<p>
The [=user agent=] MAY require a [=document=] and its associated
[=Document/browsing context=] to meet one or more <dfn>pre-lock
conditions</dfn> in order to [=lock the screen orientation=]. See
[[[#appmanifest-interaction]]] and [[[#fullscreen-interaction]]].
</p>
<ol class="algorithm">
<li>Let |document:Document| be [=this=]'s [=relevant global
object=]'s [=associated `Document`=].
</li>
<li>Run the [=common safety checks=] with |document|. If an
[=exception=] is [=exception/throw|thrown=], return [=a promise
rejected with=] that exception and abort these steps.
</li>
<li>If the [=user agent=] does not support locking the screen
orientation to |orientation|, return [=a promise rejected with=] a
{{"NotSupportedError"}} {{DOMException}} and abort these steps.
</li>
<li data-tests="lock-basic.html">If |document|'s
{{Document/[[orientationPendingPromise]]}} is not `null`, [=reject
and nullify the current lock promise=] of |document| with an
{{"AbortError"}}.
</li>
<li data-tests="lock-basic.html">Set |document|'s
{{Document/[[orientationPendingPromise]]}} to [=a new promise=].
</li>
<li>[=Apply orientation lock=] |orientation| to |document|.
</li>
<li>Return |document|'s {{Document/[[orientationPendingPromise]]}}.
</li>
</ol>
</section>
<section>
<h2>
`unlock()` method
</h2>
<p>
When the {{unlock()}} method is invoked, the [=user agent=] MUST run
the following steps:
</p>
<ol class="algorithm">
<li>Let |document:Document| be [=this=]'s [=relevant global
object=]'s [=associated `Document`=].
</li>
<li>Run the [=common safety checks=] with |document|. If an
[=exception=] is [=exception/throw|thrown=], re-throw that exception
and abort these steps.
</li>
<li>If screen's [=Screen/active orientation lock=] is `null`, return
`undefined`.
</li>
<li>If |document|'s {{Document/[[orientationPendingPromise]]}} is not
`null`, [=reject and nullify the current lock promise=] of |document|
with an {{"AbortError"}}.
</li>
<li>[=Apply orientation lock=] `null` to |document|.
</li>
</ol>
<p class="note" title="Why does unlock() not return a promise?">
{{unlock()}} does not return a promise because it is equivalent to
locking to the [=default screen orientation=] which might or might
not be known by the [=user agent=]. Hence, the [=user agent=] can not
predict what the new orientation is going to be and even if it is
going to change at all.
</p>
</section>
<section>
<h2>
Common Safety Checks
</h2>
<p>
The <dfn>common safety checks</dfn> for a {{Document}}
|document:Document| are the following steps:
</p>
<ol class="algorithm">
<li data-tests="non-fully-active.html">If |document| is not
[=Document/fully active=], [=exception/throw=] an
{{"InvalidStateError"}} {{DOMException}}.
</li>
<li data-tests="lock-sandboxed-iframe.html">If |document| has the
[=sandboxed orientation lock browsing context flag=] set,
[=exception/throw=] {{"SecurityError"}} {{DOMException}}.
</li>
<li data-tests="hidden_document.html">If |document|'s
[=Document/visibility state=] is "hidden", [=exception/throw=]
{{"SecurityError"}} {{DOMException}}.
</li>
</ol>
</section>
<section>
<h2>
`type` attribute
</h2>
<p>
When getting, the {{type}} attribute returns [=this=]'s
{{ScreenOrientation/[[type]]}}.
</p>
</section>
<section>
<h2>
`angle` attribute
</h2>
<p>
When getting, the {{angle}} attribute returns [=this=]'s
{{ScreenOrientation/[[angle]]}}.
</p>
<aside class="note" title=
"What does the value given for angle represent?">
<p>
The {{ScreenOrientation/angle}} attribute represents how far the
screen has rotated from it [=natural=] orientation. The <a>screen
orientation values list</a> specifies how the angle changes
depending on the how screen is rotated.
</p>
</aside>
</section>
<section>
<h2>
`onchange` event handler attribute
</h2>
</section>
<p>
The {{onchange}} attribute is an [=event handler IDL attribute=] for
the {{onchange}} [=event handler=], whose [=event handler event type=]
is <dfn class="event" data-dfn-for="ScreenOrientation">change</dfn>.
</p>
</section>
<section data-dfn-for="OrientationLockType">
<h2>
<dfn>OrientationLockType</dfn> enum
</h2>
<pre class="idl">
enum OrientationLockType {
"any",
"natural",
"landscape",
"portrait",
"portrait-primary",
"portrait-secondary",
"landscape-primary",
"landscape-secondary"
};
</pre>
<p>
The {{OrientationLockType}} enum represents the screen orientations to
which a screen can be potentially [=locked=].
</p>
<aside class="note" title="Orientation support">
<p>
User agents might only support a subset of the possible
{{OrientationLockType}} values. For example, a user agent might not
support locking to the `"portrait-secondary"` or
`"landscape-secondary"` orientations.
</p>
</aside>
<ul>
<li>"<dfn>any</dfn>" represents [=any=].
</li>
<li>"<dfn>natural</dfn>" represents [=natural=].
</li>
<li>"<dfn>landscape</dfn>" represents [=landscape=].
</li>
<li>"<dfn>portrait</dfn>" represents [=portrait=].
</li>
<li>"<dfn>portrait-primary</dfn>" represents [=portrait-primary=],
</li>
<li>"<dfn>portrait-secondary</dfn>" represents [=portrait-secondary=].
</li>
<li>"<dfn>landscape-primary</dfn>" represents [=landscape-primary=].
</li>
<li>"<dfn>landscape-secondary</dfn>" represents
[=landscape-secondary=].
</li>
</ul>
</section>
<section data-dfn-for="OrientationType">
<h2>
<dfn>OrientationType</dfn> enum
</h2>
<pre class="idl">
enum OrientationType {
"portrait-primary",
"portrait-secondary",
"landscape-primary",
"landscape-secondary"
};
</pre>
<p>
The {{OrientationType}} enum values are used to represent the screen's
[=Screen/current orientation type=].
</p>
<ul>
<li>"<dfn>portrait-primary</dfn>" represents [=portrait-primary=].
</li>
<li>"<dfn>portrait-secondary</dfn>" represents [=portrait-secondary=].
</li>
<li>"<dfn>landscape-primary</dfn>" represents [=landscape-primary=].
</li>
<li>"<dfn>landscape-secondary</dfn>" represents
[=landscape-secondary=].
</li>
</ul>
</section>
<section>
<h2>
Algorithms
</h2>
<section>
<h2>
Initializing the `ScreenOrientation` object
</h2>
<p>
When a [=browsing context=] |context| is created, the [=user agent=]
MUST:
</p>
<ol class="algorithm" data-tests="orientation-reading.html">
<li>Let |screenOrientation| be |context|'s [=associated
`ScreenOrientation`=].
</li>
<li>Initialize |screenOrientation|'s
{{ScreenOrientation/[[initialType]]}} internal slot to the screen's
[=Screen/current orientation type=].
</li>
<li>Initialize |screenOrientation|'s {{ScreenOrientation/[[type]]}}
internal slot to the screen's [=Screen/current orientation type=].
</li>
<li>Initialize |screenOrientation|'s {{ScreenOrientation/[[angle]]}}
internal slot to the screen's [=Screen/current orientation angle=].
</li>
</ol>
</section>
<section>
<h2>
Rejecting a document's current lock promise
</h2>
<p>
When steps require to <dfn>reject and nullify the current lock
promise</dfn> of {{Document}} |document| with a {{DOMString}}
|exceptionName|, the [=user agent=] MUST:
</p>
<ol class="algorithm" data-tests="orientation-locking.html">
<li>[=/Assert=]: {{Document/[[orientationPendingPromise]]}} is not
`null`.
</li>
<li>Let |promise:Promise| be |document|'s
{{Document/[[orientationPendingPromise]]}}.
</li>
<li>[=Queue a global task=] on the [=DOM manipulation task source=]
with |document|'s [=relevant global object=] to [=reject=] |promise|
with a new |exceptionName| {{DOMException}}.
</li>
<li>Set |document|'s {{Document/[[orientationPendingPromise]]}} to
`null`.
</li>
</ol>
</section>
<h2>
Applying an orientation lock
</h2>
<p>
When steps require to <dfn>apply orientation lock</dfn> of
{{OrientationLockType?}} |orientation| to {{Document}} |document|, the
[=user agent=] MUST perform do the following steps:
</p>
<ol class="algorithm">
<li>If |document| stops being [=Document/fully active=] while [=in
parallel=], and {{Document/[[orientationPendingPromise]]}} is not
`null`, [=reject and nullify the current lock promise=] of |document|
with an {{"AbortError"}}.
</li>
<li>Let |topDocument| be |document|'s [=top-level browsing context=]'s
[=navigable/active document=].
</li>
<li>Let |descendantDocs| be an [=ordered set=] consisting of
|topDocument|'s [=Document/descendant navigables=]'s [=navigable/active
documents=], if any, in tree order.
</li>
<li>[=Set/For each=] |doc:Document| in |descendantDocs|:
<ol>
<li>If |doc| is |document|, continue.
</li>
<li>If |doc| {{Document/[[orientationPendingPromise]]}} is `null`,
continue.
</li>
<li>[=Reject and nullify the current lock promise=] of |doc| with
an {{"AbortError"}}.
</li>
</ol>
</li>
<li>Run the following sub-steps [=in parallel=]:
<ol>
<li>If |document| has stopped being [=Document/fully active=], and
if the |document|'s {{Document/[[orientationPendingPromise]]}} is
not `null`, [=reject and nullify the current lock promise=] of
|document| with an {{"AbortError"}} and abort these steps.
</li>
<li>If |orientation| is `null`, [=unlock the screen orientation=].
</li>
<li>Otherwise, attempt to [=lock the screen orientation=] to
|orientation|. Depending on platform conventions, change how the
viewport is drawn to match |orientation|.
</li>
<li>If the attempt fails due to previously-established user
preference, or platform limitation, or any other reason:
<ol>
<li>Set the screen's [=Screen/active orientation lock=] to
`null`.
</li>
<li>[=Queue a task=] on the [=DOM manipulation task source=]
with |document|'s [=relevant global object=] to:
<ol>
<li>If the |document|'s
{{Document/[[orientationPendingPromise]]}} is not `null`,
[=reject and nullify the current lock promise=] of
|document| with a {{"NotSupportedError"}}.
</li>
<li>Abort these steps.
</li>
</ol>
</li>
</ol>
<p class="note">
This can happen if the user has set a preference that prevents
web applications from changing the screen orientation, or if
the underlying platform, rather than the user agent, does not
allow locking the screen orientation to the given
|orientation|.
</p>
</li>
<li>Set the screen's [=Screen/active orientation lock=] to
|orientation| and update the [=Screen/current orientation type=]
and [=Screen/current orientation angle=] to reflect any changes to
the [=screen orientation=].
</li>
</ol>
</li>
<li>[=Queue a global task=] on the [=DOM manipulation task source=]
with |document|'s [=relevant global object=] to:
<ol>
<li>Let |promise:Promise?| be |document|'s
{{Document/[[orientationPendingPromise]]}}.
<aside class="note">
<p>
As the promise needs to resolve after a "<a data-link-for=
"ScreenOrientation">change</a>" event is fired, we keep a
reference to prevent it from being aborted by an event's
handler function calling {{ScreenOrientation/lock()}}.
</p>
</aside>
</li>
<li>Set |document|'s {{Document/[[orientationPendingPromise]]}} to
`null`.
</li>
<li>Run the [=screen orientation change steps=] with |topDocument|.
</li>
<li>If |promise| is not `null`, [=resolve=] |promise| with
`undefined`.
</li>
</ol>
</li>
</ol>
<h2>
Screen orientation change
</h2>
<p data-tests="onchange-event.html">
When a user-agent determines that the screen's orientation has changed
for a [=top-level browsing context=], or the user moves the [=top-level
browsing context=] to a different screen, then run the [=screen
orientation change steps=] with the [=top-level browsing context=]'s
[=navigable/active document=].
</p>
<p>
The <dfn class="export">screen orientation change steps</dfn> for
{{Document}} |document:Document| are as follows:
</p>
<ol class="algorithm">
<li>If |document|'s [=Document/visibility state=] is "hidden", abort
these steps.
</li>
<li>Let |type| and |angle| be the screen's [=Screen/current orientation
type=] and [=Screen/current orientation angle=].
</li>
<li>Let |screenOrientation| be |document|'s [=relevant global
object=]'s [=associated `ScreenOrientation`=].
</li>
<li>If |type| is equal to |screenOrientation|'s
{{ScreenOrientation/[[type]]}} and |angle| is equal to
|screenOrientation|'s {{ScreenOrientation/[[angle]]}}, abort these
steps.
</li>
<li>[=Queue a global task=] on the [=user interaction task source=]
with |document|'s [=relevant global object=] to perform the following
steps:
<ol>
<li>Set |screenOrientation|'s {{ScreenOrientation/[[angle]]}} to
|angle|.
</li>
<li>Set |screenOrientation|'s {{ScreenOrientation/[[type]]}} to
|type|.
</li>
<li>[=Fire an event=] named "<a data-link-for=
"ScreenOrientation">change</a>" at |screenOrientation|.
</li>
</ol>
</li>
<li>Let |descendantDocs| be an [=ordered set=] consisting of
|document|'s [=Document/descendant navigables=]'s [=navigable/active
documents=], if any, in tree order.
</li>
<li>[=Set/For each=] |doc:Document| in |descendantDocs|, run the
[=screen orientation change steps=] with |doc|.
</li>
</ol>
<h2>
Handling page visibility changes
</h2>
<p>
[[HTML]]'s update the visibility state runs the [=screen orientation
change steps=].
</p>
<aside class="note">
<p>
Developers need to be aware that [=documents=] with a "hidden"
[=Document/visibility state=] will not receive an orientation change
event. However, once the [=document=] becomes visible again, it will
receive the change event.
</p>
</aside>
<h2>
Handling unloading documents
</h2>
<p>
Whenever the [=unloading document cleanup steps=] run with a
|document|, the user agent MUST run the following steps:
</p>
<ol class="algorithm">
<li>If |document| is not a [=top-level browsing context=]'s
[=navigable/active document=], abort these steps.
</li>
<li>Run the [=fully unlock the screen orientation steps=] with
|document|.
</li>
</ol>
<h2>
Fully unlocking the orientation
</h2>
<p>
The <dfn class="export">fully unlock the screen orientation steps</dfn>
for {{Document}} |document:Document| are as follows:
</p>
<ol class="algorithm">
<li>If |document|'s {{Document/[[orientationPendingPromise]]}} is not
`null`, [=reject and nullify the current lock promise=] of |document|
with an {{"AbortError"}}.
</li>
<li>Let |topDocument| be |document|'s [=top-level browsing context=]'s
[=navigable/active document=].
</li>
<li>[=Apply orientation lock=] `null` to |topDocument|.
</li>
</ol>
</section>
<section id="fullscreen-interaction">
<h2>
Interaction with Fullscreen API
</h2>
<p>
A user agent SHOULD restrict the use of {{ScreenOrientation/lock()}} to
simple fullscreen documents as a [=pre-lock condition=]. [[fullscreen]]
</p>
<p>
When a [=document=] exits fullscreen, it also runs the [=fully unlock
the screen orientation steps=]. [[fullscreen]]
</p>
</section>
<section id="appmanifest-interaction">
<h2>
Interaction with Web Application Manifest
</h2>
<p>
The [[[appmanifest]]] specification allows web applications to set the
[=default screen orientation=] via the the [=manifest/orientation=]
member.
</p>
<p>
A user agent SHOULD require [=installed web applications=] to be
presented in the "fullscreen" [=display mode=] as a [=pre-lock
condition=].
</p>
</section>
<section>
<h2>
Accessibility considerations
</h2>
<p>
As users can have their devices mounted in a fixed orientation (e.g. on
the arm of a wheelchair), developers that expect users to rotate their
device when [=locking the screen orientation=] need to be aware of the
[[[WCAG21]]]'s <a data-cite="WCAG21#orientation">Orientation Success
Criterion</a>. The criterion makes it <a data-cite=
"WCAG21#dfn-essential">essential</a> that content and functionality is
available regardless of the [=screen orientation=]. When a particular
orientation is <a data-cite="WCAG21#dfn-essential">essential</a>, web
applications must advise the user of the orientation requirements.
</p>
</section>
<section>
<h2>
Privacy and Security Considerations
</h2>
<p>
A screen's [=Screen/current orientation type|type=] and
[=Screen/current orientation angle|angle=] are a potential
fingerprinting vector. The following mitigation help protect a user's
privacy by not revealing how a device is being held, and also prevents
the [=secondary=] orientation type and associated angles from being
user for fingerprinting purposes.
</p>
<p>
To resist fingerprinting (e.g., in private browsing), user agents MAY:
</p>
<ol>
<li>For the life of a [=top-level browsing context=], behave as as if
screen's [=natural=] orientation is
{{ScreenOrientation/[[initialType]]}}.
</li>
<li>Restrict the possible return values of the
{{ScreenOrientation/type}} getter to
{{OrientationType/"portrait-primary"}} or
{{OrientationType/"landscape-primary"}}. The screen aspect ratio
determines which is returned.
</li>
<li>If the [=Screen/current orientation type=] matches
{{ScreenOrientation/[[initialType]]}}, return `0` for the
{{ScreenOrientation/angle}} getter. Otherwise, return `90`.
</li>
<li>If the screen orientation changes, only fire the
<a data-link-for="ScreenOrientation">change</a> event when the
[=Screen/current orientation type=] changes from [=portrait=] to
[=landscape=], or vice versa.
</li>
</ol>
</section>
<section id="conformance"></section>
<section id="idl-index" class="appendix"></section>
<section id="index"></section>
<section class="appendix">
<h2>
Acknowledgments
</h2>
<p>
Thanks Christophe Dumez, Anne van Kesteren, Chundong Wang, Fuqiao Xue,
and Chaals McCathie Nevile for their useful comments.
</p>
<p>
Special thanks to Chris Jones and Jonas Sicking for their contributions
to the initial design of this API.
</p>
</section>
</body>
</html>