├── .github ├── PULL_REQUEST_TEMPLATE.md └── workflows │ ├── auto-publish.yml │ └── tidy.yml ├── .pr-preview.json ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── ECHIDNA ├── LICENSE.md ├── README.md ├── W3CTRMANIFEST ├── demo └── index.html ├── index.html ├── published ├── 20120522.html ├── 20121123.html ├── 20140220.html └── 20141023.html ├── tidyconfig.txt └── w3c.json /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | Closes #??? 2 | 3 | The following tasks have been completed: 4 | 5 | * [ ] Modified Web platform tests (link to pull request) 6 | 7 | Implementation commitment: 8 | 9 | * [ ] WebKit (https://bugs.webkit.org/enter_bug.cgi) 10 | * [ ] Chromium (https://bugs.chromium.org/p/chromium/issues/detail?id=) 11 | * [ ] Gecko (https://bugzilla.mozilla.org/show_bug.cgi?id=) 12 | -------------------------------------------------------------------------------- /.github/workflows/auto-publish.yml: -------------------------------------------------------------------------------- 1 | name: Node CI 2 | 3 | on: 4 | push: 5 | branches: 6 | - gh-pages 7 | pull_request: {} 8 | 9 | jobs: 10 | validate-and-publish: 11 | name: Validate and Publish 12 | runs-on: ubuntu-latest # only linux supported at present 13 | steps: 14 | - uses: actions/checkout@v2 15 | - uses: w3c/spec-prod@v2 16 | with: 17 | TOOLCHAIN: respec 18 | W3C_ECHIDNA_TOKEN: ${{ secrets.ECHIDNA_TOKEN }} 19 | W3C_WG_DECISION_URL: "https://lists.w3.org/Archives/Public/public-webapps/2014JulSep/0627.html" 20 | W3C_NOTIFICATIONS_CC: "${{ secrets.CC }}" 21 | W3C_BUILD_OVERRIDE: | 22 | specStatus: WD 23 | -------------------------------------------------------------------------------- /.github/workflows/tidy.yml: -------------------------------------------------------------------------------- 1 | name: Tidy document 2 | on: 3 | workflow_dispatch: {} 4 | push: 5 | branches: 6 | - gh-pages 7 | 8 | jobs: 9 | tidy: 10 | name: Tidy up 11 | runs-on: macos-latest 12 | steps: 13 | - uses: actions/checkout@v2 14 | - run: brew install tidy-html5 15 | - run: tidy -config tidyconfig.txt -o index.html index.html 16 | - uses: peter-evans/create-pull-request@v3 17 | with: 18 | token: ${{ secrets.GH_TOKEN }} 19 | title: "Tidied up document using tidy-html5" 20 | commit-message: "chore(tidy): tidy up document" 21 | branch: html-tidy 22 | branch-suffix: timestamp 23 | draft: true 24 | -------------------------------------------------------------------------------- /.pr-preview.json: -------------------------------------------------------------------------------- 1 | { 2 | "src_file": "index.html", 3 | "type": "respec" 4 | } -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Code of Conduct 2 | 3 | All documentation, code and communication under this repository are covered by the [W3C Code of Ethics and Professional Conduct](https://www.w3.org/Consortium/cepc/). 4 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | Everyone is welcome to contribute to this specification. 3 | 4 | Any simple editorial contribution can simply be done with a pull request. 5 | You can even do an inline edit of the file on GitHub. 6 | 7 | For more substantial contributions, please first start a thread in the 8 | [webapps mailing list](http://lists.w3.org/Archives/Public/public-webapps/) at 9 | the W3C. 10 | 11 | Note: Contributions to this repository are intended to become part of Recommendation-track documents governed by the 12 | [W3C Patent Policy](http://www.w3.org/Consortium/Patent-Policy-20040205/) and 13 | [Software and Document License](http://www.w3.org/Consortium/Legal/copyright-software). To make substantive contributions to specifications, you must either participate 14 | in the relevant W3C Working Group or make a non-member patent licensing commitment. 15 | 16 | If you are not the sole contributor to a contribution (pull request), please identify all 17 | contributors in the pull request comment. 18 | 19 | To add a contributor (other than yourself, that's automatic), mark them one per line as follows: 20 | 21 | ``` 22 | +@github_username 23 | ``` 24 | 25 | If you added a contributor by mistake, you can remove them in a comment with: 26 | 27 | ``` 28 | -@github_username 29 | ``` 30 | 31 | If you are making a pull request on behalf of someone else but you had no part in designing the 32 | feature, you can remove yourself with the above syntax. 33 | 34 | 35 | 36 | # Style guide to contributors 37 | - the spec uses [ReSpec](http://dev.w3.org/2009/dap/ReSpec.js/documentation.html) 38 | - the spec is tidied using [HTML5 Tidy](https://github.com/w3c/tidy-html5). For 39 | instructions on running HTML5 tidy, see below. 40 | - put comments in front of sections, for better readability with 41 | syntax coloring editors 42 | 43 | 44 | # Running HTML5 Tidy 45 | Please make sure you have HTML5 tidy installed, instead of 46 | the the one that ships with *nix systems. You can comfirm this by running: 47 | 48 | ```bash 49 | tidy --version #HTML Tidy for HTML5 (experimental) for ... 50 | ``` 51 | Once you have confirmed (make sure you have committed your changes before 52 | running tidy, as the changes are destructive ... in a good way:)): 53 | 54 | ```bash 55 | tidy -config tidyconf.txt -o index.html index.html 56 | ``` 57 | -------------------------------------------------------------------------------- /ECHIDNA: -------------------------------------------------------------------------------- 1 | index.html?specStatus=WD&shortName=screen-orientation respec 2 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | All documents in this Repository are licensed by contributors 2 | under the 3 | [W3C Software and Document License](http://www.w3.org/Consortium/Legal/copyright-software). -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | This repo holds some of the sources for the [Screen Orientation API](https://w3c.github.io/screen-orientation/), an interface for Web applications to be able to: 2 | 3 | * Read the screen-orientation state of a device (portrait or landscape). 4 | * Be informed when the screen-orientation state changes. 5 | * Lock the screen orientation to a specific state. 6 | 7 | The latest editor’s draft is at https://w3c.github.io/screen-orientation/ 8 | 9 | Try it out in the [demo page](https://w3c.github.io/screen-orientation/demo/index.html). 10 | -------------------------------------------------------------------------------- /W3CTRMANIFEST: -------------------------------------------------------------------------------- 1 | index.html?specStatus=WD&shortName=screen-orientation respec 2 | -------------------------------------------------------------------------------- /demo/index.html: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | Screen Orientation Lock API Demo 10 | 66 | 67 |

Screen Orientation Lock API Demo

68 |

69 | This demo shows how to use the 70 | Screen Orientation Lock API 73 | to lock the screen orientation to portrait or landscape. 74 |

75 |
76 |
77 |
78 | 92 |

93 | Current screen orientation: 94 | unknown 95 | (angle is not available). 98 |

99 |

100 | Legacy window.orientation value: 101 | 102 | angle is not available. 103 | 104 |

105 |
106 |
107 |
108 | 109 |
110 | 111 | 238 | 239 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Screen Orientation 7 | 8 | 10 | 40 | 41 | 42 |
43 |

44 | The Screen Orientation specification standardizes the 45 | types and angles for a device's screen orientation, and provides a 46 | means for locking and unlocking it. The API, defined by this 47 | specification, exposes the current type and angle of the device's 48 | screen orientation, and dispatches events when it changes. This enables 49 | web applications to programmatically adapt the user experience for 50 | multiple screen orientations, working alongside CSS. The API also 51 | allows for the screen orientation to be locked under certain 52 | preconditions. This is particularly useful for applications such as 53 | computer games, where users physically rotate the device, but the 54 | screen orientation itself should not change. 55 |

56 |
57 |
58 |

59 | This document is a work in progress. 60 |

61 |
62 |
63 |

64 | Example of usage 65 |

66 |

67 | In this example clicking the "Lock" button requests to go into 68 | fullscreen and then locks the screen to the opposite orientation. 69 | clicking the "unlock" button unlocks the screen. 70 |

71 |
 73 |           <script>
 74 |           function updateLockButton() {
 75 |             const lockButton = document.getElementById("button");
 76 |             const newOrientation = getOppositeOrientation();
 77 |             lockButton.textContent = `Lock to ${newOrientation}`;
 78 |           }
 79 | 
 80 |           function getOppositeOrientation() {
 81 |             return screen
 82 |               .orientation
 83 |               .type
 84 |               .startsWith("portrait") ? "landscape" : "portrait";
 85 |           }
 86 | 
 87 |           async function rotate(lockButton) {
 88 |             if (!document.fullscreenElement) {
 89 |               await document.documentElement.requestFullscreen();
 90 |             }
 91 |             const newOrientation = getOppositeOrientation();
 92 |             await screen.orientation.lock(newOrientation);
 93 |             updateLockButton(lockButton);
 94 |           }
 95 | 
 96 |           screen.orientation.addEventListener("change", updateLockButton);
 97 | 
 98 |           window.addEventListener("load", updateLockButton);
 99 |           </script>
100 | 
101 |           <button onclick="rotate(this)" id="button">
102 |             Lock to...
103 |           </button>
104 |           <button onclick="screen.orientation.unlock()">
105 |             Unlock
106 |           </button>
107 |         
108 |
109 |
110 |

111 | Concepts 112 |

113 |

114 | To lock the 115 | screen orientation to an {{OrientationLockType}} |orientation| 116 | means that the screen can only be rotated by the user to a specific 117 | [=screen orientation=] - possibly at the exclusion of other 118 | orientations. The possible orientations to which the screen can be 119 | rotated is determined by the user agent, a user preference, the 120 | operating system's conventions, or the screen itself. For example, 121 | locking the orientation to [=landscape=] means that the screen can be 122 | rotated by the user to [=landscape-primary=] and maybe 123 | [=landscape-secondary=] if the system allows it, but won't change the 124 | orientation to [=portrait-secondary=] orientation. 125 |

126 |

127 | To unlock the screen 129 | orientation the end user is unrestricted to rotate the screen to 130 | any [=screen orientation=] that the system allows. 131 |

132 |
133 |

134 | Screen orientation types 135 |

136 |

137 | A screen can be in, or [=locked=] to, one of the following 138 | screen orientations: 139 |

140 |
141 |
142 | Natural 143 |
144 |
145 | The most natural orientation for the device's display as determined 146 | by the user agent, the user, the operating system, or the screen 147 | itself. For example, a device viewed, or held upright in the user's 148 | hand, with the screen facing the user. A computer monitor are 149 | commonly naturally [=landscape-primary=], while a mobile phones are 150 | commonly naturally [=portrait-primary=]. 151 |
152 |
153 | Landscape 154 |
155 |
156 | The screen's aspect ratio has a width greater than the height. 157 |
158 |
159 | Portrait 160 |
161 |
162 | The screen's aspect ratio has a height greater than the width. 163 |
164 |
165 | Primary 167 |
168 |
169 | The device's screen [=natural=] orientation for either [=portrait=] 170 | or [=landscape=]. 171 |
172 |
173 | Secondary 175 |
176 |
177 | The opposite of the device's screen primary orientation for 178 | [=portrait=] or [=landscape=]. 179 |
180 |
181 | Any 182 |
183 |
184 | The screen can be rotated by the user to any orientation allowed by 185 | the device's operating system or by the end-user. 186 |
187 |
188 | Default (unlocked) 190 |
191 |
192 | The device's default behavior for when the screen is [=unlocked=] 193 | (i.e., the [=Screen/active orientation lock=] is `null`). This 194 | orientation is determined by the device's operating system, or the 195 | user agent, or controlled by the end-user, or possibly set by an 196 | [=installed web application=]. For example, when the screen 197 | orientation is unlocked and the user rotates the device, some 198 | devices will limit orientation changes to [=portrait-primary=], 199 | [=landscape-primary=], and [=landscape-secondary=], but not to 200 | [=portrait-secondary=]. 201 |
202 |
203 |
204 |
205 |

206 | The current screen orientation type and angle 207 |

208 |

209 | The screen of the output device has the following associated 210 | concepts: 211 |

212 |
213 |
214 | Current orientation type 215 |
216 |
217 | The [=screen orientation=] of the screen, represented as a 218 | {{OrientationType}}. 219 |
220 |
221 | Current orientation angle 222 |
223 |
224 | The angle in degrees that the screen is rotated counter-clockwise 225 | from its [=natural=] orientation as derived by the [=screen 226 | orientation values list=]. 227 |
228 |
229 | Active orientation lock 230 |
231 |
232 | The [=screen orientation=], represented as a 233 | {{OrientationLockType}}, to which the screen is [=locked=], or 234 | `null` when [=unlocked=]. 235 |
236 |
237 |

238 | The screen orientation values lists below standardize the 239 | angles associated with each screen orientation type for screens with 240 | different [=natural=] orientations: 241 |

242 |
243 |
244 | For screens with a [=natural=] [=portrait=] orientation: 245 |
246 |
247 |
    248 |
  • [=portrait-primary=]: 0° 249 |
  • 250 |
  • [=landscape-primary=]: 90° 251 |
  • 252 |
  • [=portrait-secondary=]: 180° 253 |
  • 254 |
  • [=landscape-secondary=]: 270° 255 |
  • 256 |
257 |
258 |
259 | For screens with a [=natural=] [=landscape=] orientation: 260 |
261 |
262 |
    263 |
  • [=landscape-primary=]: 0° 264 |
  • 265 |
  • [=portrait-primary=]: 90° 266 |
  • 267 |
  • [=landscape-secondary=]: 180° 268 |
  • 269 |
  • [=portrait-secondary=]: 270° 270 |
  • 271 |
272 |
273 |
274 |
275 |
276 |
277 |

278 | Extensions to the `Document` interface 279 |

280 |
281 |

282 | Internal Slots 283 |

284 |

285 | The {{Document}} interface is extended with the following internal 286 | slots: 287 |

288 | 289 | 290 | 291 | 294 | 297 | 298 | 299 | 300 | 301 | 305 | 310 | 311 | 312 |
292 | Internal Slot 293 | 295 | Description 296 |
302 | [[\orientationPendingPromise]] 304 | 306 | Either `null` or a {{Promise}}. When assigned a {{Promise}}, 307 | that promise represents a request to lock the screen 308 | orientation. 309 |
313 |
314 |
315 |
316 |

317 | Extensions to the `Screen` interface 318 |

319 |
320 |         partial interface Screen {
321 |           [SameObject] readonly attribute ScreenOrientation orientation;
322 |         };
323 |       
324 |

325 | The {{Window}} object has an associated `ScreenOrientation`, 326 | which is a {{Screen}}'s {{Screen/orientation}} object (i.e., the 327 | {{ScreenOrientation}} instance at `window.screen.orientation`). 328 |

329 |
330 |
332 |

333 | ScreenOrientation interface 334 |

335 |
336 |         [Exposed=Window]
337 |         interface ScreenOrientation : EventTarget {
338 |           Promise<undefined> lock(OrientationLockType orientation);
339 |           undefined unlock();
340 |           readonly attribute OrientationType type;
341 |           readonly attribute unsigned short angle;
342 |           attribute EventHandler onchange;
343 |         };
344 |       
345 |
346 |

347 | Internal Slots 348 |

349 | 350 | 351 | 352 | 355 | 358 | 359 | 360 | 361 | 362 | 365 | 370 | 371 | 372 | 375 | 379 | 380 | 381 | 384 | 388 | 389 | 390 |
353 | Internal Slot 354 | 356 | Description 357 |
363 | [[\angle]] 364 | 366 | Represents the screen's last known [=Screen/current orientation 367 | angle=] in degrees as an {{unsigned short}} as derived from the 368 | [=screen orientation values lists=]. 369 |
373 | [[\initialType]] 374 | 376 | Represents the screen's [=Screen/current orientation type=] 377 | when the [=browsing context=] was created. 378 |
382 | [[\type]] 383 | 385 | Represents the screen's last known [=Screen/current orientation 386 | type=] as an {{OrientationType}} enum value. 387 |
391 |
392 |
393 |

394 | `lock()` method 395 |

396 |

397 | When the {{lock()}} method is invoked with {{OrientationLockType}} 398 | |orientation:OrientationLockType|, the [=user agent=] MUST run the 399 | following steps. 400 |

401 |

402 | The [=user agent=] MAY require a [=document=] and its associated 403 | [=Document/browsing context=] to meet one or more pre-lock 404 | conditions in order to [=lock the screen orientation=]. See 405 | [[[#appmanifest-interaction]]] and [[[#fullscreen-interaction]]]. 406 |

407 |
    408 |
  1. Let |document:Document| be [=this=]'s [=relevant global 409 | object=]'s [=associated `Document`=]. 410 |
  2. 411 |
  3. Run the [=common safety checks=] with |document|. If an 412 | [=exception=] is [=exception/throw|thrown=], return [=a promise 413 | rejected with=] that exception and abort these steps. 414 |
  4. 415 |
  5. If the [=user agent=] does not support locking the screen 416 | orientation to |orientation|, return [=a promise rejected with=] a 417 | {{"NotSupportedError"}} {{DOMException}} and abort these steps. 418 |
  6. 419 |
  7. If |document|'s 420 | {{Document/[[orientationPendingPromise]]}} is not `null`, [=reject 421 | and nullify the current lock promise=] of |document| with an 422 | {{"AbortError"}}. 423 |
  8. 424 |
  9. Set |document|'s 425 | {{Document/[[orientationPendingPromise]]}} to [=a new promise=]. 426 |
  10. 427 |
  11. [=Apply orientation lock=] |orientation| to |document|. 428 |
  12. 429 |
  13. Return |document|'s {{Document/[[orientationPendingPromise]]}}. 430 |
  14. 431 |
432 |
433 |
434 |

435 | `unlock()` method 436 |

437 |

438 | When the {{unlock()}} method is invoked, the [=user agent=] MUST run 439 | the following steps: 440 |

441 |
    442 |
  1. Let |document:Document| be [=this=]'s [=relevant global 443 | object=]'s [=associated `Document`=]. 444 |
  2. 445 |
  3. Run the [=common safety checks=] with |document|. If an 446 | [=exception=] is [=exception/throw|thrown=], re-throw that exception 447 | and abort these steps. 448 |
  4. 449 |
  5. If screen's [=Screen/active orientation lock=] is `null`, return 450 | `undefined`. 451 |
  6. 452 |
  7. If |document|'s {{Document/[[orientationPendingPromise]]}} is not 453 | `null`, [=reject and nullify the current lock promise=] of |document| 454 | with an {{"AbortError"}}. 455 |
  8. 456 |
  9. [=Apply orientation lock=] `null` to |document|. 457 |
  10. 458 |
459 |

460 | {{unlock()}} does not return a promise because it is equivalent to 461 | locking to the [=default screen orientation=] which might or might 462 | not be known by the [=user agent=]. Hence, the [=user agent=] can not 463 | predict what the new orientation is going to be and even if it is 464 | going to change at all. 465 |

466 |
467 |
468 |

469 | Common Safety Checks 470 |

471 |

472 | The common safety checks for a {{Document}} 473 | |document:Document| are the following steps: 474 |

475 |
    476 |
  1. If |document| is not 477 | [=Document/fully active=], [=exception/throw=] an 478 | {{"InvalidStateError"}} {{DOMException}}. 479 |
  2. 480 |
  3. If |document| has the 481 | [=sandboxed orientation lock browsing context flag=] set, 482 | [=exception/throw=] {{"SecurityError"}} {{DOMException}}. 483 |
  4. 484 |
  5. If |document|'s 485 | [=Document/visibility state=] is "hidden", [=exception/throw=] 486 | {{"SecurityError"}} {{DOMException}}. 487 |
  6. 488 |
489 |
490 |
491 |

492 | `type` attribute 493 |

494 |

495 | When getting, the {{type}} attribute returns [=this=]'s 496 | {{ScreenOrientation/[[type]]}}. 497 |

498 |
499 |
500 |

501 | `angle` attribute 502 |

503 |

504 | When getting, the {{angle}} attribute returns [=this=]'s 505 | {{ScreenOrientation/[[angle]]}}. 506 |

507 | 516 |
517 |
518 |

519 | `onchange` event handler attribute 520 |

521 |
522 |

523 | The {{onchange}} attribute is an [=event handler IDL attribute=] for 524 | the {{onchange}} [=event handler=], whose [=event handler event type=] 525 | is change. 526 |

527 |
528 |
529 |

530 | OrientationLockType enum 531 |

532 |
533 |         enum OrientationLockType {
534 |           "any",
535 |           "natural",
536 |           "landscape",
537 |           "portrait",
538 |           "portrait-primary",
539 |           "portrait-secondary",
540 |           "landscape-primary",
541 |           "landscape-secondary"
542 |         };
543 |       
544 |

545 | The {{OrientationLockType}} enum represents the screen orientations to 546 | which a screen can be potentially [=locked=]. 547 |

548 | 556 | 575 |
576 |
577 |

578 | OrientationType enum 579 |

580 |
581 |         enum OrientationType {
582 |           "portrait-primary",
583 |           "portrait-secondary",
584 |           "landscape-primary",
585 |           "landscape-secondary"
586 |         };
587 |       
588 |

589 | The {{OrientationType}} enum values are used to represent the screen's 590 | [=Screen/current orientation type=]. 591 |

592 | 603 |
604 |
605 |

606 | Algorithms 607 |

608 |
609 |

610 | Initializing the `ScreenOrientation` object 611 |

612 |

613 | When a [=browsing context=] |context| is created, the [=user agent=] 614 | MUST: 615 |

616 |
    617 |
  1. Let |screenOrientation| be |context|'s [=associated 618 | `ScreenOrientation`=]. 619 |
  2. 620 |
  3. Initialize |screenOrientation|'s 621 | {{ScreenOrientation/[[initialType]]}} internal slot to the screen's 622 | [=Screen/current orientation type=]. 623 |
  4. 624 |
  5. Initialize |screenOrientation|'s {{ScreenOrientation/[[type]]}} 625 | internal slot to the screen's [=Screen/current orientation type=]. 626 |
  6. 627 |
  7. Initialize |screenOrientation|'s {{ScreenOrientation/[[angle]]}} 628 | internal slot to the screen's [=Screen/current orientation angle=]. 629 |
  8. 630 |
631 |
632 |
633 |

634 | Rejecting a document's current lock promise 635 |

636 |

637 | When steps require to reject and nullify the current lock 638 | promise of {{Document}} |document| with a {{DOMString}} 639 | |exceptionName|, the [=user agent=] MUST: 640 |

641 |
    642 |
  1. [=/Assert=]: {{Document/[[orientationPendingPromise]]}} is not 643 | `null`. 644 |
  2. 645 |
  3. Let |promise:Promise| be |document|'s 646 | {{Document/[[orientationPendingPromise]]}}. 647 |
  4. 648 |
  5. [=Queue a global task=] on the [=DOM manipulation task source=] 649 | with |document|'s [=relevant global object=] to [=reject=] |promise| 650 | with a new |exceptionName| {{DOMException}}. 651 |
  6. 652 |
  7. Set |document|'s {{Document/[[orientationPendingPromise]]}} to 653 | `null`. 654 |
  8. 655 |
656 |
657 |

658 | Applying an orientation lock 659 |

660 |

661 | When steps require to apply orientation lock of 662 | {{OrientationLockType?}} |orientation| to {{Document}} |document|, the 663 | [=user agent=] MUST perform do the following steps: 664 |

665 |
    666 |
  1. If |document| stops being [=Document/fully active=] while [=in 667 | parallel=], and {{Document/[[orientationPendingPromise]]}} is not 668 | `null`, [=reject and nullify the current lock promise=] of |document| 669 | with an {{"AbortError"}}. 670 |
  2. 671 |
  3. Let |topDocument| be |document|'s [=top-level browsing context=]'s 672 | [=navigable/active document=]. 673 |
  4. 674 |
  5. Let |descendantDocs| be an [=ordered set=] consisting of 675 | |topDocument|'s [=Document/descendant navigables=]'s [=navigable/active 676 | documents=], if any, in tree order. 677 |
  6. 678 |
  7. [=Set/For each=] |doc:Document| in |descendantDocs|: 679 |
      680 |
    1. If |doc| is |document|, continue. 681 |
    2. 682 |
    3. If |doc| {{Document/[[orientationPendingPromise]]}} is `null`, 683 | continue. 684 |
    4. 685 |
    5. [=Reject and nullify the current lock promise=] of |doc| with 686 | an {{"AbortError"}}. 687 |
    6. 688 |
    689 |
  8. 690 |
  9. Run the following sub-steps [=in parallel=]: 691 |
      692 |
    1. If |document| has stopped being [=Document/fully active=], and 693 | if the |document|'s {{Document/[[orientationPendingPromise]]}} is 694 | not `null`, [=reject and nullify the current lock promise=] of 695 | |document| with an {{"AbortError"}} and abort these steps. 696 |
    2. 697 |
    3. If |orientation| is `null`, [=unlock the screen orientation=]. 698 |
    4. 699 |
    5. Otherwise, attempt to [=lock the screen orientation=] to 700 | |orientation|. Depending on platform conventions, change how the 701 | viewport is drawn to match |orientation|. 702 |
    6. 703 |
    7. If the attempt fails due to previously-established user 704 | preference, or platform limitation, or any other reason: 705 |
        706 |
      1. Set the screen's [=Screen/active orientation lock=] to 707 | `null`. 708 |
      2. 709 |
      3. [=Queue a task=] on the [=DOM manipulation task source=] 710 | with |document|'s [=relevant global object=] to: 711 |
          712 |
        1. If the |document|'s 713 | {{Document/[[orientationPendingPromise]]}} is not `null`, 714 | [=reject and nullify the current lock promise=] of 715 | |document| with a {{"NotSupportedError"}}. 716 |
        2. 717 |
        3. Abort these steps. 718 |
        4. 719 |
        720 |
      4. 721 |
      722 |

      723 | This can happen if the user has set a preference that prevents 724 | web applications from changing the screen orientation, or if 725 | the underlying platform, rather than the user agent, does not 726 | allow locking the screen orientation to the given 727 | |orientation|. 728 |

      729 |
    8. 730 |
    9. Set the screen's [=Screen/active orientation lock=] to 731 | |orientation| and update the [=Screen/current orientation type=] 732 | and [=Screen/current orientation angle=] to reflect any changes to 733 | the [=screen orientation=]. 734 |
    10. 735 |
    736 |
  10. 737 |
  11. [=Queue a global task=] on the [=DOM manipulation task source=] 738 | with |document|'s [=relevant global object=] to: 739 |
      740 |
    1. Let |promise:Promise?| be |document|'s 741 | {{Document/[[orientationPendingPromise]]}}. 742 | 750 |
    2. 751 |
    3. Set |document|'s {{Document/[[orientationPendingPromise]]}} to 752 | `null`. 753 |
    4. 754 |
    5. Run the [=screen orientation change steps=] with |topDocument|. 755 |
    6. 756 |
    7. If |promise| is not `null`, [=resolve=] |promise| with 757 | `undefined`. 758 |
    8. 759 |
    760 |
  12. 761 |
762 |

763 | Screen orientation change 764 |

765 |

766 | When a user-agent determines that the screen's orientation has changed 767 | for a [=top-level browsing context=], or the user moves the [=top-level 768 | browsing context=] to a different screen, then run the [=screen 769 | orientation change steps=] with the [=top-level browsing context=]'s 770 | [=navigable/active document=]. 771 |

772 |

773 | The screen orientation change steps for 774 | {{Document}} |document:Document| are as follows: 775 |

776 |
    777 |
  1. If |document|'s [=Document/visibility state=] is "hidden", abort 778 | these steps. 779 |
  2. 780 |
  3. Let |type| and |angle| be the screen's [=Screen/current orientation 781 | type=] and [=Screen/current orientation angle=]. 782 |
  4. 783 |
  5. Let |screenOrientation| be |document|'s [=relevant global 784 | object=]'s [=associated `ScreenOrientation`=]. 785 |
  6. 786 |
  7. If |type| is equal to |screenOrientation|'s 787 | {{ScreenOrientation/[[type]]}} and |angle| is equal to 788 | |screenOrientation|'s {{ScreenOrientation/[[angle]]}}, abort these 789 | steps. 790 |
  8. 791 |
  9. [=Queue a global task=] on the [=user interaction task source=] 792 | with |document|'s [=relevant global object=] to perform the following 793 | steps: 794 |
      795 |
    1. Set |screenOrientation|'s {{ScreenOrientation/[[angle]]}} to 796 | |angle|. 797 |
    2. 798 |
    3. Set |screenOrientation|'s {{ScreenOrientation/[[type]]}} to 799 | |type|. 800 |
    4. 801 |
    5. [=Fire an event=] named "change" at |screenOrientation|. 803 |
    6. 804 |
    805 |
  10. 806 |
  11. Let |descendantDocs| be an [=ordered set=] consisting of 807 | |document|'s [=Document/descendant navigables=]'s [=navigable/active 808 | documents=], if any, in tree order. 809 |
  12. 810 |
  13. [=Set/For each=] |doc:Document| in |descendantDocs|, run the 811 | [=screen orientation change steps=] with |doc|. 812 |
  14. 813 |
814 |

815 | Handling page visibility changes 816 |

817 |

818 | [[HTML]]'s update the visibility state runs the [=screen orientation 819 | change steps=]. 820 |

821 | 829 |

830 | Handling unloading documents 831 |

832 |

833 | Whenever the [=unloading document cleanup steps=] run with a 834 | |document|, the user agent MUST run the following steps: 835 |

836 |
    837 |
  1. If |document| is not a [=top-level browsing context=]'s 838 | [=navigable/active document=], abort these steps. 839 |
  2. 840 |
  3. Run the [=fully unlock the screen orientation steps=] with 841 | |document|. 842 |
  4. 843 |
844 |

845 | Fully unlocking the orientation 846 |

847 |

848 | The fully unlock the screen orientation steps 849 | for {{Document}} |document:Document| are as follows: 850 |

851 |
    852 |
  1. If |document|'s {{Document/[[orientationPendingPromise]]}} is not 853 | `null`, [=reject and nullify the current lock promise=] of |document| 854 | with an {{"AbortError"}}. 855 |
  2. 856 |
  3. Let |topDocument| be |document|'s [=top-level browsing context=]'s 857 | [=navigable/active document=]. 858 |
  4. 859 |
  5. [=Apply orientation lock=] `null` to |topDocument|. 860 |
  6. 861 |
862 |
863 |
864 |

865 | Interaction with Fullscreen API 866 |

867 |

868 | A user agent SHOULD restrict the use of {{ScreenOrientation/lock()}} to 869 | simple fullscreen documents as a [=pre-lock condition=]. [[fullscreen]] 870 |

871 |

872 | When a [=document=] exits fullscreen, it also runs the [=fully unlock 873 | the screen orientation steps=]. [[fullscreen]] 874 |

875 |
876 |
877 |

878 | Interaction with Web Application Manifest 879 |

880 |

881 | The [[[appmanifest]]] specification allows web applications to set the 882 | [=default screen orientation=] via the the [=manifest/orientation=] 883 | member. 884 |

885 |

886 | A user agent SHOULD require [=installed web applications=] to be 887 | presented in the "fullscreen" [=display mode=] as a [=pre-lock 888 | condition=]. 889 |

890 |
891 |
892 |

893 | Accessibility considerations 894 |

895 |

896 | As users can have their devices mounted in a fixed orientation (e.g. on 897 | the arm of a wheelchair), developers that expect users to rotate their 898 | device when [=locking the screen orientation=] need to be aware of the 899 | [[[WCAG21]]]'s Orientation Success 900 | Criterion. The criterion makes it essential that content and functionality is 902 | available regardless of the [=screen orientation=]. When a particular 903 | orientation is essential, web 904 | applications must advise the user of the orientation requirements. 905 |

906 |
907 |
908 |

909 | Privacy and Security Considerations 910 |

911 |

912 | A screen's [=Screen/current orientation type|type=] and 913 | [=Screen/current orientation angle|angle=] are a potential 914 | fingerprinting vector. The following mitigation help protect a user's 915 | privacy by not revealing how a device is being held, and also prevents 916 | the [=secondary=] orientation type and associated angles from being 917 | user for fingerprinting purposes. 918 |

919 |

920 | To resist fingerprinting (e.g., in private browsing), user agents MAY: 921 |

922 |
    923 |
  1. For the life of a [=top-level browsing context=], behave as as if 924 | screen's [=natural=] orientation is 925 | {{ScreenOrientation/[[initialType]]}}. 926 |
  2. 927 |
  3. Restrict the possible return values of the 928 | {{ScreenOrientation/type}} getter to 929 | {{OrientationType/"portrait-primary"}} or 930 | {{OrientationType/"landscape-primary"}}. The screen aspect ratio 931 | determines which is returned. 932 |
  4. 933 |
  5. If the [=Screen/current orientation type=] matches 934 | {{ScreenOrientation/[[initialType]]}}, return `0` for the 935 | {{ScreenOrientation/angle}} getter. Otherwise, return `90`. 936 |
  6. 937 |
  7. If the screen orientation changes, only fire the 938 | change event when the 939 | [=Screen/current orientation type=] changes from [=portrait=] to 940 | [=landscape=], or vice versa. 941 |
  8. 942 |
943 |
944 |
945 |
946 |
947 |
948 |

949 | Acknowledgments 950 |

951 |

952 | Thanks Christophe Dumez, Anne van Kesteren, Chundong Wang, Fuqiao Xue, 953 | and Chaals McCathie Nevile for their useful comments. 954 |

955 |

956 | Special thanks to Chris Jones and Jonas Sicking for their contributions 957 | to the initial design of this API. 958 |

959 |
960 | 961 | 962 | -------------------------------------------------------------------------------- /published/20120522.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | The Screen Orientation API 5 | 6 | 472 | 473 |

W3C

The Screen Orientation API

W3C Working Draft 22 May 2012

This version:
http://www.w3.org/TR/2012/WD-screen-orientation-20120522/
Latest published version:
http://www.w3.org/TR/screen-orientation/
Latest editor's draft:
http://dvcs.w3.org/hg/screen-orientation/raw-file/tip/Overview.html
Editor:
Mounir Lamouri, Mozilla
474 |

475 | 476 |

Abstract

477 | The Screen Orientation API's goal is to provide an interface for web applications 478 | to be able to read the screen orientation state, to be informed when this state 479 | changes and to be able to lock the screen orientation to a specific state. 480 |

Status of This Document

This section describes the status of this document at the time of its publication. Other documents may supersede this document. A list of current W3C publications and the latest revision of this technical report can be found in the W3C technical reports index at http://www.w3.org/TR/.

This document was published by the Web Applications Working Group as a First Public Working Draft. This document is intended to become a W3C Recommendation. If you wish to make comments regarding this document, please send them to public-webapps@w3.org (subscribe, archives) with [screen-orient] at the start of the subject header. All feedback is welcome.

Publication as a Working Draft does not imply endorsement by the W3C Membership. This is a draft document and may be updated, replaced or obsoleted by other documents at any time. It is inappropriate to cite this document as other than work in progress.

This document was produced by a group operating under the 5 February 2004 W3C Patent Policy. W3C maintains a public list of any patent disclosures made in connection with the deliverables of the group; that page also includes instructions for disclosing a patent. An individual who has actual knowledge of a patent which the individual believes contains Essential Claim(s) must disclose the information in accordance with section 6 of the W3C Patent Policy.

Table of Contents

481 | 482 |
483 |

1. Introduction

This section is non-normative.

484 |

485 | The Screen Orientation API provides an interface for web applications to 486 | access and lock the user's device's screen orientation state. 487 |

488 |

489 | This examples is an application that shows the current screen orientation 490 | to the user every time the screen orientation state changes: 491 |

492 |
<!DOCTYPE html>
493 | <html>
494 |   <script>
495 |     function show() {
496 |       alert("Screen orientation state is " + screen.orientation);
497 |     }
498 | 
499 |     screen.addEventListener("orientationchange", show, false);
500 | 
501 |     show();
502 |   </script>
503 | </html>
504 |
505 | 506 |

2. Conformance

As well as sections marked as non-normative, all authoring guidelines, diagrams, examples, and notes in this specification are non-normative. Everything else in this specification is normative.

507 |

The key words must, must not, required, should, should not, recommended, may, and optional in this specification are to be interpreted as described in [RFC2119].

508 | 509 |

510 | This specification defines conformance criteria that apply to a single product: the user agent that 511 | implements the interfaces that it contains. 512 |

513 |

514 | Implementations that use ECMAScript to expose the APIs defined in this specification must implement them in a manner 515 | consistent with the ECMAScript Bindings defined in the Web IDL specification [WEBIDL]. 516 |

517 |
518 | 519 |
520 |

3. Terminology

521 | 522 |

523 | The 524 | Function interface represents a function in the scripting 525 | language being used as defined in [HTML5]. 526 |

527 |

528 | The concepts 529 | queue a task and 530 | 531 | fire a simple event are defined in [HTML5]. 532 |

533 |

534 | The terms 535 | event handlers and 536 | 537 | event handler event types are defined in [HTML5]. 538 |

539 |

540 | The concepts of 541 | browsing context and 542 | 543 | active document are defined in [HTML5]. 544 |

545 | 546 |
547 |

3.1 Current orientation

548 | 549 |

550 | The current orientation should be an orientation amongst those values: 551 |

557 |

558 | 559 |
560 |

561 | The notion of primary and secondary depends on the device and the platform. Usually, platforms have a way to distinguish 562 | the two portrait and landscape orientations.
563 | For example, on most phones, portrait-primary is going to be the orientation that is used when the phone 564 | is in hand and secondary will be upside-down orientation. Also, landscape-primary will be the landscape orientation 565 | that is a 90 degree orientation counter-clock and secondary the other one.
566 | On tablets, landscape-primary will be the orientation used when the tablet is in hands. 567 |

568 |
569 |
570 | 571 |
572 |

3.2 Allowed orientations

573 | 574 |

575 | The allowed orientations should be orientations amongst the current orientation list 576 | or amongst those values: 577 |

581 |

582 |
583 |
584 | 585 |
586 |

4. Extensions to the Screen Interface

587 | The CSSOM View specification defines a Screen interface [CSSOM-VIEW], which this specification extends: 588 |
partial interface Screen {
589 |     readonly attribute DOMString orientation;
590 |     boolean lockOrientation (DOMtring orientation);
591 |     void    unlockOrientation ();
592 |     [TreatNonCallableAsNull]
593 |              attribute Function? onorientationchange;
594 | };
595 | 

4.1 Attributes

onorientationchange of type Function, nullable
orientation of type DOMString, readonly
596 |

597 | The user agent must return the value of the orientation of the output device. 598 |

599 |

600 | The returned orientation must be in the current orientation list. 601 |

602 |

4.2 Methods

lockOrientation
603 | The user agent must run these steps: 604 |
    605 |
  1. If the orientation isn't part of the allowed orientations, the method must return false.
  2. 606 |
  3. If locking to orientation isn't currently allowed, the method must return false. 607 |
  4. Otherwise, the method must return true and the screen orientation should be locked to orientation.
  5. 608 |
609 | When the lock is done, if the orientation did change, the user agent must fire a simple event 610 | named orientationnchange at the Screen object. 611 |
ParameterTypeNullableOptionalDescription
orientationDOMtring
Return type: boolean
unlockOrientation
612 |

613 | The user agent must disable the current lock applied on the screen with lockOrientation. 614 | If the current browsing context has a default orientation, the screen orientation should revert to that. 615 |

616 |
No parameters.
Return type: void
617 | 618 |

619 | When the screen orientation changes in the current browsing context, the user agent must queue a task 620 | which updates the orientation attribute and fire a simple event named orientationchange 621 | at the Screen object. 622 | 623 |

624 |

625 | For example, that means if an application A is locked to landscape-primary 626 | and application B is locked to portrait-primary, switching from 627 | application A to B or B to A will not fire an orientationchange 628 | event because both application will keep the orientation they had. 629 |

630 |

631 | However, locking the application can fire an orientationchange if the 632 | application wasn't in the specified type before being locked. 633 |

634 |
635 |

636 |
637 | 638 |
639 |

5. Event handlers

640 |

641 | The following are the event handlers (and their corresponding 642 | event handler event types) that must be supported as attributes 643 | by the Screen object: 644 |

645 | 646 | 647 | 648 | 649 | 650 | 651 | 652 | 653 | 654 | 655 | 656 | 657 | 658 | 659 |
event handlerevent handler event type
onorientationchangeorientationchange
660 |
661 | 662 |
663 |

A. Acknowledgements

664 | Many thanks to Jonas Sicking and Chris Jones for their contributions to the design of this specification. 665 |
666 | 667 | 668 |

B. References

B.1 Normative references

[CSSOM-VIEW]
Anne van Kesteren. CSSOM View Module. 22 February 2008. W3C Working Draft. (Work in progress.) URL: http://www.w3.org/TR/2008/WD-cssom-view-20080222 669 |
[HTML5]
Ian Hickson; David Hyatt. HTML5. 25 May 2011. W3C Working Draft. (Work in progress.) URL: http://www.w3.org/TR/html5 670 |
[RFC2119]
S. Bradner. Key words for use in RFCs to Indicate Requirement Levels. March 1997. Internet RFC 2119. URL: http://www.ietf.org/rfc/rfc2119.txt 671 |
[WEBIDL]
Cameron McCormack. Web IDL. 27 September 2011. W3C Working Draft. (Work in progress.) URL: http://www.w3.org/TR/2011/WD-WebIDL-20110927/ 672 |

B.2 Informative references

No informative references.

673 | -------------------------------------------------------------------------------- /published/20121123.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | The Screen Orientation API 5 | 6 | 7 | 8 | 407 | 408 |
409 |

410 | 411 | W3C 412 | 413 |

414 |

The Screen Orientation API

415 | 416 |

W3C Working Draft 06 December 2012

417 |
418 | 419 |
This version:
420 |
http://www.w3.org/TR/2012/WD-screen-orientation-20121206/
421 |
Latest published version:
422 |
http://www.w3.org/TR/screen-orientation/
423 | 424 | 425 |
Latest editor's draft:
426 |
http://dvcs.w3.org/hg/screen-orientation/raw-file/tip/Overview.html
427 | 428 | 429 | 430 | 431 | 432 |
Previous version:
433 |
http://www.w3.org/TR/2012/WD-screen-orientation-20120522/
434 | 435 | 436 |
Editor:
437 |
Mounir Lamouri, Mozilla
438 | 439 | 440 |
441 | 442 | 443 | 444 | 445 | 446 | 458 | 459 | 460 |
461 |
462 | 463 |

Abstract

464 | The Screen Orientation API's goal is to provide an interface for web applications 465 | to be able to read the screen orientation state, to be informed when this state 466 | changes and to be able to lock the screen orientation to a specific state. 467 |

Status of This Document

468 | 469 | 470 | 471 |

472 | This section describes the status of this document at the time of its publication. Other 473 | documents may supersede this document. A list of current W3C publications and the latest revision 474 | of this technical report can be found in the W3C technical reports 475 | index at http://www.w3.org/TR/. 476 |

477 | 478 |

479 | This document was published by the Web Applications Working Group as a Working Draft. 480 | 481 | This document is intended to become a W3C Recommendation. 482 | 483 | If you wish to make comments regarding this document, please send them to 484 | public-webapps@w3.org 485 | (subscribe, 486 | archives) with [screen-orient] at the start of the subject header. 487 | 488 | A bug list for this document is available. 489 | 490 | All feedback is welcome. 491 |

492 | 493 |

494 | Publication as a Working Draft does not imply endorsement by the W3C Membership. 495 | This is a draft document and may be updated, replaced or obsoleted by other documents at 496 | any time. It is inappropriate to cite this document as other than work in progress. 497 |

498 | 499 | 500 |

501 | 502 | This document was produced by a group operating under the 503 | 5 February 2004 W3C Patent Policy. 504 | 505 | 506 | 507 | 508 | W3C maintains a public list of any patent disclosures 509 | 510 | made in connection with the deliverables of the group; that page also includes instructions for 511 | disclosing a patent. An individual who has actual knowledge of a patent which the individual believes contains 512 | Essential Claim(s) must disclose the 513 | information in accordance with section 514 | 6 of the W3C Patent Policy. 515 | 516 | 517 |

518 | 519 | 520 | 521 | 522 |

Table of Contents

523 | 524 |
525 |

1. Introduction

This section is non-normative.

526 |

527 | The Screen Orientation API provides an interface for web applications to 528 | access and lock the user's device's screen orientation state. 529 |

530 |

531 | This examples is an application that shows the current screen orientation 532 | to the user every time the screen orientation state changes: 533 |

534 |
Example 1
<!DOCTYPE html>
535 | <html>
536 |   <script>
537 |     function show() {
538 |       alert("Screen orientation state is " + screen.orientation);
539 |     }
540 | 
541 |     screen.addEventListener("orientationchange", show, false);
542 | 
543 |     show();
544 |   </script>
545 | </html>
546 |
547 | 548 |

2. Conformance

549 |

550 | As well as sections marked as non-normative, all authoring guidelines, diagrams, examples, 551 | and notes in this specification are non-normative. Everything else in this specification is 552 | normative. 553 |

554 |

555 | The key words must, must not, required, should, should not, recommended, may, 556 | and optional in this specification are to be interpreted as described in [RFC2119]. 557 |

558 | 559 |

560 | This specification defines conformance criteria that apply to a single product: the user agent that 561 | implements the interfaces that it contains. 562 |

563 |

564 | Implementations that use ECMAScript to expose the APIs defined in this specification must implement them in a manner 565 | consistent with the ECMAScript Bindings defined in the Web IDL specification [WEBIDL]. 566 |

567 |
568 | 569 |
570 |

3. Terminology

571 | 572 |

573 | The 574 | EventHandler interface represents a callback used for event 575 | handlers as defined in [HTML5]. 576 |

577 |

578 | The concepts 579 | queue a task and 580 | 581 | fire a simple event are defined in [HTML5]. 582 |

583 |

584 | The terms 585 | event handlers and 586 | 587 | event handler event types are defined in [HTML5]. 588 |

589 |

590 | The concepts of 591 | browsing context and 592 | 593 | active document are defined in [HTML5]. 594 |

595 | 596 |
597 |

3.1 Current orientation

598 | 599 |

600 | The current orientation should be an orientation amongst those values: 601 |

607 |

608 | 609 |

610 | The notion of primary and secondary depends on the device and the 611 | platform. Some devices are in portrait mode when the user holds the 612 | device in the normal orientation, other devices are in landscape 613 | mode when the user holds the device in its normal orientation. For 614 | devices whose normal orientation is a landscape mode, that normal 615 | orientation should be represented as landscape-primary. 616 | For devices whose normal orientation is a portrait mode, that normal 617 | orientation should be represented as portrait-primary. 618 | In both if the device is in landscape-primary and is 619 | rotated 90 degrees clockwise, that should be represented as 620 | portrait-primary. 621 |

622 | 623 |
624 | 625 |
626 |

3.2 Allowed orientations

627 | 628 |

629 | The allowed orientations should be orientations amongst those values: 630 |

638 |

639 |
640 | 641 |
642 |

3.3 Lock the orientation

643 | 644 |

645 | The action to lock the orientation consists of forcing the rendering of the current browsing context 646 | to be shown as if the screen was oriented in one or many of the current orientation.
647 | If the lock is done on only one orientation, the screen orientation should stay on the given orientation and never change 648 | until the screen orientation is unlocked. Otherwise, the screen orientation should be able to change from an orientation 649 | to another as long as the orientations are amongst an orientation it has been locked to. 650 |

651 |
652 | 653 |
654 |

3.4 Supported orientations

655 | 656 |

657 | A set of orientations is said to be a supported orientation set if the user agent 658 | can lock the orientation to that set. 659 |

660 |
661 |
662 | 663 | 664 |
665 |

4. Extensions to the Screen Interface

666 | The CSSOM View specification defines a Screen interface [CSSOM-VIEW], which this specification extends: 667 |
partial interface Screen {
668 |     readonly attribute DOMString orientation;
669 |     boolean lockOrientation (DOMString orientation);
670 |     boolean lockOrientation (sequence<DOMString> orientations);
671 |     void    unlockOrientation ();
672 |     [TreatNonCallableAsNull]
673 |              attribute EventHandler onorientationchange;
674 | };

4.1 Attributes

onorientationchange of type EventHandler, nullable
orientation of type DOMString, readonly
675 |

676 | The user agent must return the value representing the orientation of the screen. 677 |

678 |

679 | The returned orientation must be in the current orientation list. 680 |

681 |

4.2 Methods

lockOrientation
682 | The method must run these steps for locking the screen orientation with 683 | orientation 684 | being the only locking orientation and return the value returned from those steps. 685 |
ParameterTypeNullableOptionalDescription
orientationDOMString
Return type: boolean
lockOrientation
686 | The method must run these steps for locking the screen orientation with 687 | orientations 688 | being the only locking orientation and return the value returned from those steps. 689 |
ParameterTypeNullableOptionalDescription
orientationssequence<DOMString>
Return type: boolean
unlockOrientation
690 |

691 | The user agent must disable the current lock applied on the screen with lockOrientation. 692 | If the current browsing context has a default orientation, the screen orientation should revert to that. 693 | Otherwise, the screen orientation should revert to any value the user agent believes appropriate. 694 |

695 |

696 | When the unlock is done, if the orientation actually changed, the user agent must fire a simple event 697 | named orientationnchange at the Screen object. 698 |

699 |
No parameters.
Return type: void
700 | 701 |

702 | When the screen orientation changes in the current browsing context, the user agent must queue a task 703 | which updates the orientation attribute and fire a simple event named orientationchange 704 | at the Screen object. 705 | 706 |

Note
707 |

708 | For example, that means if an application A is locked to landscape-primary 709 | and application B is locked to portrait-primary, switching from 710 | application A to B or B to A will not fire an orientationchange 711 | event because both applications will keep the orientation they had. 712 |

713 |

714 | However, locking the orientation can fire an orientationchange if the 715 | orientation had to be changed to satisfy the lock requirements. 716 |

717 |
718 |

719 |
720 |

4.3 Locking the screen orientation

721 |

722 | The steps for locking the screen orientation are the following: 723 |

    724 |
  1. Let orientations be the list of locking orientations.
  2. 725 |
  3. For each orientation in the orientations list, run the following sub steps: 726 |
      727 |
    1. If orientation isn't part of the allowed orientations, the steps must stop here and return false.
    2. 728 |
    3. If orientation is portrait or landscape the value should be removed from the list and the values 729 | it is representing must be inserted instead.
    4. 730 |
    731 |
  4. 732 |
  5. If orientations isn't a supported orientation set, the steps must stop here and return false.
  6. 733 |
  7. Return true and run the remaining steps asynchronously.
  8. 734 |
  9. The user agent must lock the orientation to orientations.
  10. 735 |
  11. When the lock is done, if the orientation actually changed, the user agent must fire a simple event 736 | named orientationnchange at the Screen object.
  12. 737 |
738 |

739 |
740 |
741 | 742 |
743 |

5. Declarative orientation locking

This section is non-normative.

744 |

745 | This specification doesn't intend to specify a declarative orientation locking. However, other specifications specify ways to do that. 746 |

747 |

748 | The Web Application Manifest Format and Management APIs [WEBAPPS-MANIFEST-API] specifies a way to declare a default orientation 749 | for a web application inside the manifest file.
750 | That specification tries to follow this specification regarding orientation keywords. 751 |

752 |

753 | The CSS Device Adaptation specification [CSS-ADAPTATION] specifies a way to declare a default orientation for a web page.
754 | That specification isn't yet in sync with this specification. 755 |

756 |
757 | 758 |
759 |

6. Event handlers

760 |

761 | The following are the event handlers (and their corresponding 762 | event handler event types) that must be supported as attributes 763 | by the Screen object: 764 |

765 | 766 | 767 | 768 | 769 | 770 | 771 | 772 | 773 | 774 | 775 | 776 | 777 | 778 | 779 |
event handlerevent handler event type
onorientationchangeorientationchange
780 |
781 | 782 |
783 |

A. Acknowledgments

784 | Many thanks to Jonas Sicking and Chris Jones for their contributions to the design of this specification. 785 |
786 | 787 | 788 | 789 |

B. References

B.1 Normative references

[CSS-ADAPTATION]
Rune Lillesveen. CSS Device Adaptation. 23 January 2012. Editor's Draft. (Work in progress.) URL: http://dev.w3.org/csswg/css-device-adapt/ 790 |
[CSSOM-VIEW]
Anne van Kesteren. CSSOM View Module. 22 February 2008. W3C Working Draft. (Work in progress.) URL: http://www.w3.org/TR/2008/WD-cssom-view-20080222 791 |
[HTML5]
Ian Hickson; David Hyatt. HTML5. 29 March 2012. W3C Working Draft. (Work in progress.) URL: http://www.w3.org/TR/html5 792 |
[RFC2119]
S. Bradner. Key words for use in RFCs to Indicate Requirement Levels. March 1997. Internet RFC 2119. URL: http://www.ietf.org/rfc/rfc2119.txt 793 |
[WEBAPPS-MANIFEST-API]
Anant Narayanan. Web Application Manifest Format and Management APIs. W3C Editor's Draft. (Work in progress.) URL: http://dvcs.w3.org/hg/app-manifest/raw-file/tip/index.html 794 |
[WEBIDL]
Cameron McCormack. Web IDL. 27 September 2011. W3C Working Draft. (Work in progress.) URL: http://www.w3.org/TR/2011/WD-WebIDL-20110927/ 795 |
796 | -------------------------------------------------------------------------------- /published/20140220.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | The Screen Orientation API 6 | 7 | 8 | 9 | 10 | 433 | 496 |

Abstract

497 | The Screen Orientation API provides the ability to read the 498 | screen orientation state, to be informed when this state changes, and to 499 | be able to lock the screen orientation to a specific state. 500 |

Status of This Document

501 | 502 | 503 | 504 |

505 | This section describes the status of this document at the time of its publication. 506 | Other documents may supersede this document. A list of current W3C publications and the 507 | latest revision of this technical report can be found in the W3C technical reports index at 508 | http://www.w3.org/TR/. 509 |

510 | 511 | This document is still in a work in progress state. You can have a look at 512 | the 513 | opened bugs. If you see any problem that is not in that list, feel 514 | free to discuss it in the mailing list (see below) or 515 | open a new bug. 516 | 517 |

518 | This document was published by the Web Applications Working Group as a Working Draft. 519 | 520 | This document is intended to become a W3C Recommendation. 521 | 522 | 523 | If you wish to make comments regarding this document, please send them to 524 | public-webapps@w3.org 525 | (subscribe, 526 | archives). 527 | 528 | 529 | 530 | 531 | All comments are welcome. 532 | 533 |

534 | 535 | 536 |

537 | Publication as a Working Draft does not imply endorsement by the W3C 538 | Membership. This is a draft document and may be updated, replaced or obsoleted by other 539 | documents at any time. It is inappropriate to cite this document as other than work in 540 | progress. 541 |

542 | 543 | 544 | 545 |

546 | 547 | This document was produced by a group operating under the 548 | 5 February 2004 W3C Patent 549 | Policy. 550 | 551 | 552 | 553 | 554 | W3C maintains a public list of any patent 555 | disclosures 556 | 557 | made in connection with the deliverables of the group; that page also includes 558 | instructions for disclosing a patent. An individual who has actual knowledge of a patent 559 | which the individual believes contains 560 | Essential 561 | Claim(s) must disclose the information in accordance with 562 | section 563 | 6 of the W3C Patent Policy. 564 | 565 | 566 |

567 | 568 | 569 | 570 | 571 |

Table of Contents

596 | 597 |
598 |

1. 599 | Introduction 600 |

This section is non-normative.

601 |

602 | The Screen Orientation API provides an interface for web applications 603 | to access and lock the device's screen orientation state. 604 |

605 |

606 | This examples is an application that shows the current screen 607 | orientation to the user every time the screen orientation state 608 | changes: 609 |

610 |
Example 1
<!DOCTYPE html>
611 | <html>
612 |   <head>
613 |     <title>Screen Orientation API Example 1</title>
614 |     <script>
615 |       function show() {
616 |         alert("Screen orientation state is now " + screen.orientation);
617 |       }
618 | 
619 |       screen.addEventListener("orientationchange", show);
620 |       window.addEventListener("load", show);
621 |     </script>
622 |   </head>
623 |   <body>
624 |     <input type='button' value='Unlock'
625 |       onclick='screen.unlockOrientation();'>
626 |     <input type='button' value='Lock to portrait'
627 |       onclick="screen.lockOrientation('portrait');">
628 |     <input type='button' value='Lock to landscape'
629 |       onclick="screen.lockOrientation('landscape');">
630 |   </body>
631 | </html>
632 |
633 |

2. Conformance

634 |

635 | As well as sections marked as non-normative, all authoring guidelines, diagrams, examples, 636 | and notes in this specification are non-normative. Everything else in this specification is 637 | normative. 638 |

639 |

640 | The key words MUST, MUST NOT, REQUIRED, SHOULD, SHOULD NOT, RECOMMENDED, MAY, 641 | and OPTIONAL in this specification are to be interpreted as described in [RFC2119]. 642 |

643 | 644 |

645 | This specification defines conformance criteria that apply to a single 646 | product: the user agent that implements the interfaces that 647 | it contains. 648 |

649 |

650 | Implementations that use ECMAScript to expose the APIs defined in this 651 | specification MUST implement them in a manner consistent with the 652 | ECMAScript Bindings defined in the Web IDL specification [WEBIDL]. 653 |

654 |
655 |
656 |

3. 657 | Terminology 658 |

659 |

660 | The EventHandler 661 | interface represents a callback used for event handlers as defined in 662 | [HTML5]. 663 |

664 |

665 | The concepts queue a 666 | task and fire 667 | a simple event are defined in [HTML5].
668 | Unless specified otherwise, when queuing a task, the screen 669 | orientation task source is used. 670 |

671 |

672 | The terms event 673 | handlers and 674 | event handler event types are defined in [HTML5]. 675 |

676 |

677 | The concepts of browsing 678 | context and active 679 | document are defined in [HTML5]. 680 |

681 |
682 |

3.1 683 | Current orientation 684 |

685 |

686 | The current orientation is represented by one of the 687 | following values: 688 |

689 |
690 |
691 | portrait-primary 692 |
693 |
694 | The orientation is in the primary portrait mode. 695 |
696 |
697 | portrait-secondary 698 |
699 |
700 | The orientation is in the secondary portrait mode. 701 |
702 |
703 | landscape-primary 704 |
705 |
706 | The orientation is in the primary landscape mode. 707 |
708 |
709 | landscape-secondary 710 |
711 |
712 | The orientation is in the secondary landscape mode. 713 |
714 |
715 |

716 | The concepts of primary orientation and secondary orientation depends 717 | on the device and the platform. Some devices are in portrait mode when 718 | the user holds the device in the normal orientation, other devices are 719 | in landscape mode when the user holds the device in its normal 720 | orientation. For devices whose normal orientation is a landscape mode, 721 | that normal orientation SHOULD be represented as 722 | landscape-primary. For devices whose normal orientation 723 | is a portrait mode, that normal orientation SHOULD be represented as 724 | portrait-primary. In both if the device is in 725 | landscape-primary and is rotated 90 degrees clockwise, 726 | that SHOULD be represented as portrait-primary. 727 |

728 |
729 |
730 |

3.2 731 | Allowed orientations 732 |

733 |

734 | The allowed orientations are represented by the following 735 | values: 736 |

737 |
738 |
739 | portrait-primary 740 |
741 |
742 | The orientation is in the primary portrait mode. 743 |
744 |
745 | portrait-secondary 746 |
747 |
748 | The orientation is in the secondary portrait mode. 749 |
750 |
751 | landscape-primary 752 |
753 |
754 | The orientation is in the primary landscape mode. 755 |
756 |
757 | landscape-secondary 758 |
759 |
760 | The orientation is in the secondary landscape mode. 761 |
762 |
763 | portrait 764 |
765 |
766 | The orientation is either portrait-primary or 767 | portrait-secondary. 768 |
769 |
770 | landscape 771 |
772 |
773 | The orientation is either landscape-primary or 774 | landscape-secondary. 775 |
776 |
777 | 779 |
780 |
781 |

3.3 782 | Locking the orientation 783 |

784 |

785 | To lock the orientation means forcing the rendering of the 786 | current browsing context to behave as if the screen was 787 | naturally orientated in a given orientation and will only change 788 | orientation to a given set of allowed orientations, regardless 789 | of the actual screen orientation relative to the user or the previous 790 | locks. 791 |

792 |

793 | If the lock is done on only one orientation, the screen orientation 794 | MUST stay on the given orientation and never change until the 795 | screen orientation is locked again. Otherwise, the screen orientation 796 | MUST be able to change from an orientation to another as long as 797 | the orientations are amongst an orientation it has been locked to. 798 |

799 |

800 | When the lock is done, if the orientation actually changed, the 801 | user agent MUST fire a simple event named 802 | orientationnchange at the Screen object. 803 |

804 |
805 |
806 |

3.4 807 | Supported orientations 808 |

809 |

810 | The supported orientations is a set of orientations that a 811 | user agent can lock the orientation to. 812 |

813 |
814 |
815 |

3.5 816 | Default orientation 817 |

818 |

819 | The browsing context's default orientation is the 820 | set of orientations to which the screen orientation would be locked 821 | when it is not explicitly locked by the current browsing 822 | context. 823 |

824 |
825 |
826 |
827 |

4. 828 | Extensions to the Screen Interface 829 |

The CSSOM View specification defines a Screen interface 830 | [CSSOM-VIEW], which this specification extends: 831 |
partial interface Screen : EventTarget {
832 |     readonly    attribute DOMString    orientation;
833 |     boolean lockOrientation ((DOMString or sequence<DOMString>) orientations);
834 |     void    unlockOrientation ();
835 |                 attribute EventHandler onorientationchange;
836 | };
837 |

838 | The orientation attribute MUST return the value 839 | representing the orientation of the screen. The returned orientation 840 | MUST be in the current orientation list. 841 |

842 |

843 | The lockOrientation() method, when invoked, MUST run the 844 | steps for locking the screen orientation. If 845 | lockOrientation was called with a sequence of strings, the 846 | sequence MUST be used as orientation in the mentioned steps. 847 | Otherwise, the passed string MUST be the only element in 848 | orientations. The method MUST return the result returned from 849 | running previous steps. 850 |

851 |

852 | The unlockOrientation() method, when invoked, MUST 853 | asynchronously lock the orientation to the default 854 | orientation. The user agent MAY ignore this call if the 855 | screen is already locked to the default orientation. 856 |

857 |

858 | When the screen orientation changes in the current browsing 859 | context, the user agent MUST queue a task which 860 | updates the orientation attribute and fire a simple 861 | event named orientationchange at the 862 | Screen object. 863 |

864 |
Note
865 |

866 | For example, that means if an application A is locked to 867 | landscape-primary and application B is locked to 868 | portrait-primary, switching from application A to B or B 869 | to A will not fire an orientationchange event because 870 | both applications will keep the orientation they had. 871 |

872 |

873 | However, locking the orientation can fire an 874 | orientationchange if the orientation had to be changed 875 | to satisfy the lock requirements. 876 |

877 |
878 |
879 |

4.1 880 | Locking the screen orientation 881 |

882 |

883 | The steps for locking the screen orientation are as 884 | follows: 885 |

886 |
    887 |
  1. If the user agent does not allow the current browsing 888 | context to lock the screen orientation, the steps MUST stop here 889 | and return false. For example, a user agent might only allow 890 | browsing context in a fullscreen state to lock the screen 891 | orientation or browsing context with elevated privileges.
  2. 892 |
  3. Let orientations be the list of locking orientations. 893 |
  4. 894 |
  5. For each orientation in the orientations list, run 895 | the following sub steps: 896 |
      897 |
    1. If orientation isn't part of the allowed 898 | orientations, the steps MUST stop here and return false. 899 |
    2. 900 |
    3. If orientation is portrait or landscape 901 | the value MUST be removed from orientations and every 902 | allowed orientations it is representing MUST be inserted 903 | in orientations. 904 |
    4. 905 |
    906 |
  6. 907 |
  7. If orientations isn't a supported orientations set, 908 | the steps MUST stop here and return false. 909 |
  8. 910 |
  9. Return true and run the remaining steps asynchronously. 911 |
  10. 912 |
  11. The user agent MUST lock the orientation to 913 | orientations. 914 |
  12. 915 |
916 |
917 |
918 |
919 |

5. 920 | Declarative orientation locking 921 |

This section is non-normative.

922 |

923 | This specification doesn't intend to specify a declarative orientation 924 | locking. However, other specifications specify ways to do that. 925 |

926 |

927 | The Web Application Manifest Format and Management APIs 928 | [WEBAPPS-MANIFEST-API] specifies a way to declare a default 929 | orientation for a web application inside the manifest file. That 930 | specification tries to follow this specification regarding orientation 931 | keywords. 932 |

933 |

934 | The CSS Device Adaptation specification [CSS-ADAPTATION] specifies a 935 | way to declare a default orientation for a web page. That specification 936 | isn't yet in sync with this specification. 937 |

938 |
939 |
940 |

6. 941 | Event handlers 942 |

943 |

944 | The following are the event handlers (and their corresponding 945 | event handler event types) that MUST be supported as attributes 946 | by the Screen object: 947 |

948 | 949 | 950 | 951 | 954 | 957 | 958 | 959 | 960 | 961 | 964 | 967 | 968 | 969 |
952 | event handler 953 | 955 | event handler event type 956 |
962 | onorientationchange 963 | 965 | orientationchange 966 |
970 |
971 |
972 |

A. 973 | Acknowledgments 974 |

975 |

976 | Thanks to Marcos Cáceres, Christophe Dumez, Anne van Kesteren and 977 | Chundong Wang for their useful comments. 978 |

979 |

980 | Special thanks to Chris Jones and Jonas Sicking for their contributions 981 | to the initial design of this API. 982 |

983 |
984 | 985 | 986 |

B. References

B.1 Normative references

[CSS-ADAPTATION]
Rune Lillesveen. CSS Device Adaptation. 15 September 2011. W3C Working Draft. URL: http://www.w3.org/TR/css-device-adapt/ 987 |
[CSSOM-VIEW]
Simon Pieters; Glenn Adams. CSSOM View Module. 17 December 2013. W3C Working Draft. URL: http://www.w3.org/TR/cssom-view/ 988 |
[HTML5]
Robin Berjon; Steve Faulkner; Travis Leithead; Erika Doyle Navara; Edward O'Connor; Silvia Pfeiffer. HTML5. 4 February 2014. W3C Candidate Recommendation. URL: http://www.w3.org/TR/html5/ 989 |
[RFC2119]
S. Bradner. Key words for use in RFCs to Indicate Requirement Levels. March 1997. Internet RFC 2119. URL: http://www.ietf.org/rfc/rfc2119.txt 990 |
[WEBAPPS-MANIFEST-API]
Anant Narayanan. Web Application Manifest Format and Management APIs. 30 January 2013. W3C Editor's Draft. URL: https://dvcs.w3.org/hg/app-manifest/raw-file/tip/index.html 991 |
[WEBIDL]
Cameron McCormack. Web IDL. 19 April 2012. W3C Candidate Recommendation. URL: http://www.w3.org/TR/WebIDL/ 992 |
993 | -------------------------------------------------------------------------------- /tidyconfig.txt: -------------------------------------------------------------------------------- 1 | char-encoding: utf8 2 | indent: yes 3 | wrap: 80 4 | tidy-mark: no 5 | -------------------------------------------------------------------------------- /w3c.json: -------------------------------------------------------------------------------- 1 | { 2 | "group": [ 3 | "114929" 4 | ], 5 | "contacts": [ 6 | "siusin" 7 | ], 8 | "shortName": "screen-orientation", 9 | "repo-type": "rec-track" 10 | } 11 | --------------------------------------------------------------------------------