-
Notifications
You must be signed in to change notification settings - Fork 29
/
index.html
967 lines (962 loc) · 35.1 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
962
963
964
965
966
967
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>
The Screen Orientation API
</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,
},
],
formeEditors: [
{
name: "Mounir Lamouri",
company: "Google Inc.",
},
{
name: "Johanna Herman",
company: "Invited Expert",
}
],
testSuiteURI:
"https://w3c-test.org/screen-orientation/",
github: "w3c/screen-orientation",
group: "webapps",
caniuse: "screen-orientation",
xref: "web-platform",
};
</script>
</head>
<body data-cite="web-animations CSSOM-VIEW">
<section id="abstract">
<p>
For web applications, the <cite>Screen Orientation API</cite> exposes
the type and angle of a device's current screen orientation, and
dispatches events if the device's screen orientation changes. This
allows web applications to programmatically adapt the user experience
for many possible screen orientations in concert with CSS. If supported
and if certain preconditions are met, the API also provides the ability
to lock the screen orientation. This is useful in applications such as
computer games where users physically rotate the device but the screen
orientation itself mustn't change.
</p>
</section>
<section id="sotd">
<p>
This document is a work in progress.
</p>
</section>
<section class="informative">
<h2>
Examples
</h2>
<section>
<h2>
Locking to a specific orientation and unlocking
</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'>
<script>
function updateLockButton() {
const lockButton = document.getElementById("button");
const buttonOrientation = getOppositeOrientation();
lockButton.textContent = `Lock to ${buttonOrientation}`;
}
function getOppositeOrientation() {
const { type } = screen.orientation;
return 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
</button>
<button onclick="screen.orientation.unlock()">
Unlock
</button>
</pre>
</section>
</section>
<section>
<h2>
Concepts
</h2>
<p>
The {{Window}} object has an <dfn>associated `Screen`</dfn>, which is a
{{Screen}} object.
</p>
<p>
A [=browsing context=] |A| is called a <dfn>descendant browsing
context</dfn> of a [=browsing context=] |B| if and only if |B| is an
[=ancestor browsing context=] of |A|.
</p>
<section>
<h2>
Screen orientation types and locks
</h2>
<p>
To <dfn data-local-lt="locking the screen orientation">lock the
screen orientation</dfn> to an |orientation| means that the screen
can only be rotated by the user to specific orientations (possibly at
the exclusion of other orientations). For example, locking the
orientation to [=landscape=] means that the screen can be rotated by
the user to [=landscape-primary=] and [=landscape-secondary=], and
not to any [=portrait=] orientation.
</p>
<p>
A screen can be in or locked to one of the following <dfn>screen
orientations</dfn>:
</p>
<dl>
<dt>
<dfn>Natural</dfn>:
</dt>
<dd>
The most natural orientation of the device if it was viewed or held
by the user, as determined by the underlying operating system. For
example, a device viewed, or held upright in the user's hand, with
the screen facing the user.
</dd>
<dt>
<dfn>Landscape</dfn>:
</dt>
<dd>
The screen's width is greater than the height.
</dd>
<dt>
<dfn>Portrait</dfn>:
</dt>
<dd>
The screen's height is 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>
The <dfn data-export="">default screen orientation</dfn>:
</dt>
<dd>
The orientation to which the screen is locked when there is no
[=Document/active orientation lock=] (i.e., the orientation is
"unlocked"). This orientation is determined by the device's
operating system, or the user agent (e.g., <a href=
"#interaction-with-web-application-manifest"></a>), or controlled
by the end-user.
</dd>
</dl>
</section>
<section>
<h2>
The current screen orientation type and angle
</h2>
<p>
The screen of the output device has a <dfn>current orientation
type</dfn> and a <dfn>current orientation angle</dfn>. To derive
these values, the <a>user agent</a> MUST <a>update the orientation
information</a> when a [=browsing context=] is created. The
relationship between the <a>current orientation type</a> and the
<a>current orientation angle</a> MUST be kept consistent.
</p>
<p>
The <a>screen orientation values table</a> presents the possible
value for the [=current orientation type=] and [=current orientation
angle=]. The table specifies the primary and secondary values that
are determined by the device's <a>natural</a> orientation and the
possibilities available to the <a>user agent</a> for setting the
other primary and secondary orientation values.
</p>
<table class="simple">
<caption>
The <dfn>screen orientation values table</dfn>
</caption>
<thead>
<tr>
<th>
In the natural orientation is...
</th>
<th>
Primary Orientation 1
</th>
<th>
Secondary Orientation 1
</th>
<th>
Primary Orientation 2
</th>
<th>
Secondary Orientation 2
</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<a>Portrait</a>
</td>
<td>
<a>portrait-primary</a><br>
angle `0`
</td>
<td>
<a>portrait-secondary</a><br>
angle `180`
</td>
<td>
<a>landscape-primary</a><br>
angle `90` or angle `270`
</td>
<td>
<a>landscape-secondary</a><br>
Set at the angle not used for landscape-primary
</td>
</tr>
<tr>
<td>
<a>Landscape</a>
</td>
<td>
<a>landscape-primary</a><br>
angle `0`
</td>
<td>
<a>landscape-secondary</a><br>
angle `180`
</td>
<td>
<a>portrait-primary</a><br>
angle `90` or angle `270`
</td>
<td>
<a>portrait-secondary</a><br>
The angle not used for portrait-primary.
</td>
</tr>
</tbody>
</table>
<div class='practice'>
<p class='practicedesc'>
<span class='practicelab'>{{ScreenOrientation/angle}} and
{{ScreenOrientation/type}} relationship</span> Never assume any
cross-devices relationship between the screen orientation type and
the screen orientation angle. Any assumption would be wrong given
that a device might have `90` and `270` as the angles for
`landscape` types but another device will have `0` and `180`,
depending on its <a>natural</a> orientation. Instead, it is
recommended to check during runtime the relationship between angle
and type.
</p>
</div>
</section>
<section data-dfn-for='OrientationLockType'>
<h2>
Locking the screen orientation
</h2>
<p>
The <a>user agent</a> 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 in order to
allow an <a>orientation lock</a>. See, for example, <a href=
'#interaction-with-fullscreen-api'></a>).
</p>
<p>
The <a>user agent</a> MAY reject all attempts to lock the screen
orientation if the platform conventions do not expect applications to
be able to change the screen orientation. For example, on most
desktop platforms, applications can not change the screen
orientation.
</p>
</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>
</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>
The [=current orientation angle=] in degrees as an {{unsigned
short}}.
</td>
</tr>
<tr>
<td>
<dfn>[[\type]]</dfn>
</td>
<td>
The [=current orientation type=] of the screen, represented as
an {{OrientationType}} enum value.
</td>
</tr>
</tbody>
</table>
</section>
<section>
<h2>
<dfn>lock()</dfn> method
</h2>
<p data-tests="lock-bad-argument.html, lock-basic.html">
When the {{lock()}} method is invoked, the <a>user agent</a> MUST run
the the following steps.
</p>
<ol class="algorithm">
<li>Let |document:Document| be [=this=]'s [=relevant global
object=]'s [=associated `Document`=].
</li>
<li>If |document| is not [=Document/fully active=], return [=a
promise rejected with=] an "{{InvalidStateError}}" {{DOMException}}.
</li>
<li>If the <a>user agent</a> does not support locking the screen
orientation due to previously-established user preference, security
risk, or platform limitation, return [=a promise rejected with=] a
{{"NotSupportedError"}} {{DOMException}} and abort these steps.
</li>
<li data-tests="lock-sandboxed-iframe.html">If |document| has the <a>
sandboxed orientation lock browsing context flag</a> set, or
doesn't meet the [=pre-lock conditions=], return [=a promise
rejected with=] a `"SecurityError"` {{DOMException}} and abort
these steps.
</li>
<li data-tests="lock-basic.html">If |document|'s
{{Document/[[orientationPendingPromise]]}} is not `null`:
<ol>
<li>Let |currentLockPromise:Promise| be |document|'s
{{Document/[[orientationPendingPromise]]}}.
</li>
<li>[=Queue a global task=] on the [=DOM manipulation task
source=] with |this|'s [=relevant global object=] to [=reject=]
|currentLockPromise| with an {{"AbortError"}} {{DOMException}}.
</li>
</ol>
</li>
<li data-tests="lock-basic.html">Set |document|'s
{{Document/[[orientationPendingPromise]]}} to [=a new promise=].
</li>
<li>Return |document|'s {{Document/[[orientationPendingPromise]]}}
and [=in parallel=]:
<ol>
<li>Let |descendantDocs| be an [=ordered set=] consisting of
|documents|'s [=descendant browsing contexts=]' [=active
documents=], if any, in tree order.
</li>
<li>[=Set/For each=] |doc:Document| in |descendantDocs|:
<ol>
<li>If |doc| {{Document/[[orientationPendingPromise]]}} is
`null`, continue.
</li>
<li>[=Queue a global task=] on the [=DOM manipulation task
source=] with |doc|'s [=relevant global object=] to:
<ol>
<li>[=Reject=] |doc|'s
{{Document/[[orientationPendingPromise]]}} with
`"AbortError"` {{DOMException}}.
</li>
<li>Set |doc|'s
{{Document/[[orientationPendingPromise]]}} to `null`.
</li>
</ol>
</li>
</ol>
</li>
<li>
<a>Lock the orientation</a> of |document| to |orientation|.
</li>
</ol>
</li>
<li>If |document| stops being [=Document/fully active=], [=queue a
global task=] on the [=DOM manipulation task source=] with |this|'s
[=relevant global object=] to [=reject=]
{{Document/[[orientationPendingPromise]]}} with an {{"AbortError"}}
{{DOMException}}.
</li>
</ol>
<div class='note'>
If locking the orientation results in an orientation change, the
promise will be resolved when the orientation changes.
</div>
</section>
<section>
<h2>
<dfn>unlock()</dfn> method
</h2>
<p>
When the {{unlock()}} method is invoked, the <a>user agent</a> MUST
run the following steps:
</p>
<ol>
<li>If |document| is not [=Document/fully active=],
[=exception/throw=] an "{{InvalidStateError}}" {{DOMException}}.
</li>
<li>[=Lock the screen orientation=] of [=this=]'s [=relevant global
object=]'s [=associated `Document`=] to the [=default screen
orientation=].
</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 <a>default screen orientation</a> which might or might
not be known by the <a>user agent</a>. Hence, the <a>user agent</a>
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>
<dfn>type</dfn> attribute
</h2>
<p>
When getting, return [=this=]'s {{ScreenOrientation/[[type]]}}.
</p>
</section>
<section>
<h2>
<dfn>angle</dfn> attribute
</h2>
<p>
When getting, return [=this=]'s {{ScreenOrientation/[[angle]]}}.
</p>
<div class='note' title=
"What does the value given for angle represent?">
<p>
{{angle}} represents how far the user has turned the device
counterclockwise from the natural orientation. When the device is
rotated 90° counterclockwise, the screen compensates by rotating
90° clockwise, so {{angle}} returns `90`.
</p>
<p>
The <a>screen orientation values table</a> shows how the angle
changes depending on the how the device is rotated.
</p>
</div>
</section>
<section>
<h2>
<dfn>onchange</dfn> attribute
</h2>
</section>
<p>
The {{onchange}} attribute is an <a>event handler</a> whose
corresponding <a>event handler event type</a> is `"change"`.
</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 <dfn>OrientationLockType</dfn> enum represents the screen
orientations to which a screen can be rotated.
</p>
<ul>
<li>"<dfn>any</dfn>" enum value represents the <a>any</a> orientation,
</li>
<li>"<dfn>natural</dfn>" enum represents the <a>natural</a>
orientation,
</li>
<li>"<dfn>landscape</dfn>" enum represents the <a>landscape</a>
orientation,
</li>
<li>"<dfn>portrait</dfn>" enum represents the <a>portrait</a>
orientation,
</li>
<li>"<dfn>portrait-primary</dfn>" enum represents the
<a>portrait-primary</a> orientation,
</li>
<li>"<dfn>portrait-secondary</dfn>" enum represents the
<a>portrait-secondary</a> orientation,
</li>
<li>"<dfn>landscape-primary</dfn>" enum represents the
<a>landscape-primary</a> orientation,
</li>
<li>"<dfn>landscape-secondary</dfn>" enum represents the
<a>landscape-secondary</a> orientation.
</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 <dfn>OrientationType</dfn> enum represents the actual current
screen orientation that the screen is in irrespective of which lock is
applied.
</p>
<ul>
<li>"<dfn>portrait-primary</dfn>" enum represents the
<a>portrait-primary</a> orientation,
</li>
<li>"<dfn>portrait-secondary</dfn>" enum represents the
<a>portrait-secondary</a> orientation,
</li>
<li>"<dfn>landscape-primary</dfn>" enum represents the
<a>landscape-primary</a> orientation,
</li>
<li>and the "<dfn>landscape-secondary</dfn>" enum represents the
<a>landscape-secondary</a> orientation.
</li>
</ul>
</section>
<section>
<h2>
Extensions to the `Document` interface
</h2>
<section>
<h2>
Internal Slots
</h2>
<table class="simple">
<thead>
<tr>
<th>
Internal Slot
</th>
<th>
Description
</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<dfn data-dfn-for="Document">[[\orientationLock]]</dfn>
</td>
<td>
The {{Document/[[orientationLock]]}} is the [=Document/active
orientation lock=] as a {{OrientationLockType}} or `null`.
</td>
</tr>
<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>
<h2>
Algorithms
</h2>
<section data-link-for="OrientationType">
<h2>
Updating the orientation information
</h2>
<p data-tests="orientation-reading.html">
The steps to <dfn>update the orientation information</dfn> of a
[=browsing context=] |context|:
</p>
<ol class="algorithm">
<li>Let |orientation| be the {{OrientationType}} enum that matches
the [=screen orientation=] of |context|.
</li>
<li data-tests="orientation-reading.html">Let |angle| be the angle
that matches the |orientation| from the <a>screen orientation values
table</a>.
</li>
<li>Set [=associated `Screen`=]'s {{ScreenOrientation}}'s'
{{ScreenOrientation/[[type]]}} internal slot to |orientation|.
</li>
<li>Set [=associated `Screen`=]'s {{ScreenOrientation}}'s'
{{ScreenOrientation/[[angle]]}} internal slot to |angle|.
</li>
</ol>
</section>
<section>
<h2>
Locking the orientation
</h2>
<p>
The steps to <dfn>lock the orientation</dfn> of |document| to
|orientation| are as follows.
</p>
<ol class="algorithm">
<li class="algorithm" data-tests="lock-basic.html">Set the
{{Document}}'s {{Document/[[orientationLock]]}} to |orientation|.
</li>
<li>If the [=Document/active orientation lock=] is not the
|document|'s {{Document/[[orientationLock]]}}, abort these steps.
</li>
<li>If the [=Document/active orientation lock=] value is equal to
|orientation| value, abort these steps.
</li>
<li>If |orientations| contains only one value, run the following
sub-steps:
<ol>
<li>Let |orientation| be the value contained in |orientations|.
</li>
<li>Change how the viewport is drawn so that the {{Document}}'s
<a>current orientation type</a> will be equal to |orientation|.
</li>
<li>After the change has happened, prevent the {{Document}}'s <a>
top-level browsing context</a>'s screen orientation from
changing until those steps are run again.
</li>
<li>Abort these steps.
</li>
</ol>
</li>
<li>If the {{Document}}'s <a>current orientation type</a> is not part
of |orientations|, change how the viewport is drawn such as the
{{Document}}'s <a>current orientation type</a> will be equal to one
of |orientations|' values.
</li>
<li>Otherwise, depending on platform conventions, change how the
viewport is drawn in order to make it match another screen
orientation type.
</li>
<li>Allow the user to change the screen orientation to any value part
of |orientations| and only those values until those steps are run
again. The method to define the current screen orientation has to
match the platform conventions.
</li>
</ol>
</section>
<section>
<h2>
Determining the active orientation lock
</h2>
<p>
An <dfn>orientation lock</dfn> is in place when a [=document=] has an
[=Document/active orientation lock=].
</p>
<p>
The steps to determine the <dfn data-dfn-for="Document">active
orientation lock</dfn> are as follows:
</p>
<ol class="algorithm">
<li>If there is only one <a>top-level browsing context</a> with a <a>
document</a> whose [=Document/visibility state=] is "visible", the
[=Document/active orientation lock=] is the [=document=]'s
{{Document/[[orientationLock]]}}.
</li>
<li>Otherwise, if there are more than one <a>top-level browsing
context</a> with a [=document=] that has a [=Document/visibility
state=] is "visible" but only one of those [=documents=] is focused,
the [=Document/active orientation lock is the focused [=document=]'s
{{Document/[[orientationLock]]}}.
</li>
<li>Otherwise, the [=Document/active orientation lock=] SHOULD be the
latest focused [=document=]'s {{Document/[[orientationLock]]}},
unless stated otherwise by the active platform conventions.
</li>
</ol>
<p>
Whenever the [=Document/active orientation lock=] changes, the
<a>user agent</a> MUST run the steps to <a>lock the orientation</a>
of the {{Document}} to the {{Document}}'s
{{Document/[[orientationLock]]}}.
</p>
<p>
Whenever a <a>top-level browsing context</a> is <a>navigated</a>, the
<a>user agent</a> MUST return the screen to the [=default screen
orientation=].
</p>
<h2>
Screen orientation change
</h2>
<p data-tests="onchange-event.html">
Whenever the viewport's angle changes, the <a>user agent</a> MUST run
the following steps as part of the next <a>animation frame</a>:
</p>
<ol class="algorithm">
<li>Let |descendantDocs| be an [=ordered set=] consisting of
|documents|'s [=descendant browsing contexts=]' [=active documents=],
if any, in tree order.
</li>
<li>[=Set/For each=] |doc:Document| in |descendantDocs|:
<ol>
<li>If |doc|'s [=Document/visibility state=] is "hidden", abort
these steps.
</li>
<li>
<a>Update the orientation information</a> of |doc|'s [=browsing
context=].
</li>
<li>If the orientation change was triggered by a user gesture
such as the user turning the device, as opposed to a call to
{{ScreenOrientation/lock()}}, the <a>task</a> MUST be annotated
with `process user orientation change` when running the next
step.
</li>
<li>[=Queue a task=] to on the [=DOM manipulation task source=]
to:
<ol>
<li>
<a>Fire an event</a> named `change` at |doc|'s [=relevant
global object=]'s [=associated `Screen`=]'s
{{Screen/orientation}} attribute.
</li>
<li>If |doc|'s {{Document/[[orientationPendingPromise]]}} is
not `null`:
<ol>
<li>Resolve |doc|'s
{{Document/[[orientationPendingPromise]]}} with
`undefined`.
</li>
<li>Set |doc|'s
{{Document/[[orientationPendingPromise]]}} to `null`.
</li>
</ol>
</li>
</ol>
</li>
</ol>
</li>
</ol>
<p>
An algorithm is <dfn class="export">triggered by a user generated
orientation change</dfn> if the <a>task</a> in which the algorithm is
running is annotated with `process user orientation change`.
</p>
<p>
Whenever a [=Document=]'s [=Document/visibility state=] becomes
"visible", the <a>user agent</a> MUST run the following sub-steps as
part of the next <a>animation frame</a>:
</p>
<ol class="algorithm">
<li>Let |type| and |angle| be the <a>current orientation type</a> and
<a>current orientation angle</a>, respectively.
</li>
<li>
<a>Update the orientation information</a> of the [=document=]'s
[=browsing context=].
</li>
<li>If |type| is different from the <a>current orientation type</a>
or |angle| from the <a>current orientation angle</a>, run the
following sub-steps:
<ol>
<li>If the orientation change was triggered by a user gesture
such as the user turning the device, as opposed to a call to
{{ScreenOrientation/lock()}}, the <a>task</a> MUST be annotated
with `process user orientation change` when running the next
step.
</li>
<li>
<a>Fire an event</a> named `"change"` at |doc|'s [=relevant
global object=]'s [=associated `Screen`=]'s
{{Screen/orientation}} attribute.
</li>
<li>If the {{Document}}'s
{{Document/[[orientationPendingPromise]]}} is not `null`:
<ol>
<li>Resolve the {{Document}}'s
{{Document/[[orientationPendingPromise]]}} with `undefined`.
</li>
<li>Set the {{Document}}'s
{{Document/[[orientationPendingPromise]]}} to `null`.
</li>
</ol>
</li>
</ol>
</li>
</ol>
<div class="note">
<p>
Developers need to be aware that a {{Screen/orientation}} object
from a {{Document}} with a "hidden" [=Document/visibility state=]
will not receive an orientation change event. This is to prevent
unnecessary changes to layout, etc. in the non-visible web
application.
</p>
</div>
</section>
</section>
<section>
<h2>
Interactions with other specifications
</h2>
<p>
This section explains how this specification interacts with other
related specifications of the platform.
</p>
<section>
<h2>
Interaction with Fullscreen API
</h2>
<p>
As a <a>pre-lock condition</a>, a user agent SHOULD restrict locking
the screen orientation to simple fullscreen documents.
</p>
</section>
<section class="informative">
<h2>
Interaction with Web Application Manifest
</h2>
<p>
The [[[appmanifest]]] allows web applications to set the
{{Document}}'s <a>default screen orientation</a>.
</p>
</section>
<section class="informative">
<h2>
Interaction with Web Content Accessibility Guidelines
</h2>
<p>
The [[[WCAG21]]] includes a <a data-cite="WCAG21#orientation">Success
Criterion related to screen orientation</a>.
</p>
<p>
The intent of this Success Criterion is to ensure that all
<a data-cite="WCAG21#dfn-essential">essential</a> content and
functionality is available regardless of the display orientation
(portrait or landscape). Some websites and applications automatically
set the screen to a particular display orientation and expect that
users will respond by rotating their device to match.
</p>
<p>
However, some users may have their devices mounted in a fixed
orientation (e.g. on the arm of a wheelchair). Therefore, websites
and applications need to support both orientations by making sure
<a data-cite="WCAG21#dfn-essential">essential</a> content and
functionality is available in each orientation. While the order of
content and method of functionality may have differences the content
and functionality must always be available. When a particular
orientation is <a data-cite="WCAG21#dfn-essential">essential</a>, the
user needs to be advised of the orientation requirements.
</p>
</section>
</section>
<section class="informative">
<h2>
Privacy and Security Considerations
</h2>
<section>
<h3>
Access to aspects of a user's local computing environment
</h3>
<p>
The screen orientation type and angle of the device can be accessed
with the API specified in this document, and can be a potential
fingerprinting vector.
</p>
</section>
</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>