├── .github ├── PULL_REQUEST_TEMPLATE.md └── workflows │ └── auto-publish.yml ├── .gitignore ├── .pr-preview.json ├── CONTRIBUTING.md ├── LICENSE.md ├── README.md ├── a-rotation.png ├── b-rotation.png ├── c-rotation.png ├── equation1.png ├── equation1.xhtml ├── equation13a.png ├── equation13a.xhtml ├── equation14.png ├── equation14.xhtml ├── equation18.png ├── equation18.xhtml ├── equation2.png ├── equation2.xhtml ├── equation3.png ├── equation3.xhtml ├── equation4.png ├── equation4.xhtml ├── equation5a.png ├── equation5a.xhtml ├── equation5e.png ├── equation5e.xhtml ├── equation6.png ├── equation6.xhtml ├── equation7.png ├── equation7.xhtml ├── equation8a.png ├── equation8a.xhtml ├── equation8b.png ├── equation8b.xhtml ├── index.bs ├── security-privacy-self-assessment.md ├── spec-source-orientation.html ├── start.png └── 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 | * [ ] Gecko (https://bugzilla.mozilla.org/show_bug.cgi?id=) 10 | * [ ] WebKit (https://bugs.webkit.org/show_bug.cgi?id=) 11 | * [ ] Chromium (https://bugs.chromium.org/p/chromium/issues/detail?id=) 12 | -------------------------------------------------------------------------------- /.github/workflows/auto-publish.yml: -------------------------------------------------------------------------------- 1 | # Workflow based on the w3c/spec-prod action example to deploy to W3C using Echidna: 2 | # https://github.com/w3c/spec-prod/blob/main/docs/examples.md#deploy-to-w3c-using-echidna 3 | 4 | name: CI 5 | 6 | on: 7 | pull_request: {} 8 | push: 9 | branches: [main] 10 | 11 | jobs: 12 | main: 13 | name: Build, Validate and Deploy 14 | runs-on: ubuntu-latest 15 | steps: 16 | - uses: actions/checkout@v2 17 | - uses: w3c/spec-prod@v2 18 | with: 19 | GH_PAGES_BRANCH: gh-pages 20 | W3C_ECHIDNA_TOKEN: ${{ secrets.ECHIDNA_TOKEN }} 21 | # Replace following with appropriate value. See options.md for details. 22 | W3C_WG_DECISION_URL: https://lists.w3.org/Archives/Public/public-device-apis/2021May/0008.html 23 | W3C_BUILD_OVERRIDE: | 24 | status: CRD 25 | shortname: orientation-event 26 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | deploy_key 2 | -------------------------------------------------------------------------------- /.pr-preview.json: -------------------------------------------------------------------------------- 1 | { 2 | "src_file": "index.bs", 3 | "type": "bikeshed", 4 | "params": { 5 | "force": 1 6 | } 7 | } -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | Contributions to this repository are intended to become part of Recommendation-track documents governed by the 2 | [W3C Patent Policy](https://www.w3.org/Consortium/Patent-Policy/) and 3 | [Software and Document License](https://www.w3.org/Consortium/Legal/copyright-software). 4 | To make substantive contributions to specifications, you must either participate 5 | in the relevant W3C Working Group or make a non-member patent licensing commitment. 6 | 7 | If you are not the sole contributor to a contribution (pull request), please identify all 8 | contributors in the pull request comment. 9 | 10 | To add a contributor (other than yourself, that's automatic), mark them one per line as follows: 11 | 12 | ``` 13 | +@github_username 14 | ``` 15 | 16 | If you added a contributor by mistake, you can remove them in a comment with: 17 | 18 | ``` 19 | -@github_username 20 | ``` 21 | 22 | If you are making a pull request on behalf of someone else but you had no part in designing the 23 | feature, you can remove yourself with the above syntax. 24 | 25 | # Tests 26 | 27 | For normative changes, a corresponding 28 | [web-platform-tests](https://github.com/web-platform-tests/wpt) PR is highly appreciated. Typically, 29 | both PRs will be merged at the same time. Note that a test change that contradicts the spec should 30 | not be merged before the corresponding spec change. If testing is not practical, please explain why 31 | and if appropriate [file a web-platform-tests issue](https://github.com/web-platform-tests/wpt/issues/new) 32 | to follow up later. Add the `type:untestable` or `type:missing-coverage` label as appropriate. 33 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | All documents in this Repository are licensed by contributors 2 | under the 3 | [W3C Software and Document License](https://www.w3.org/Consortium/Legal/copyright-software). 4 | 5 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Device Orientation and Motion Specification 2 | 3 | This is the repository in which the W3C's [Device Orientation and Motion](https://www.w3.org/TR/orientation-event/) specification is jointly maintained by the [Devices and Sensors Working Group](https://www.w3.org/groups/wg/das/) and the [Web Applications Working Group](https://www.w3.org/groups/wg/webapps/). 4 | 5 | ## Contributing to this specification 6 | 7 | Please see [CONTRIBUTING.md](CONTRIBUTING.md) 8 | -------------------------------------------------------------------------------- /a-rotation.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/w3c/deviceorientation/70d42d5484db7fd1646e48cc17caa5ff1c9d92cb/a-rotation.png -------------------------------------------------------------------------------- /b-rotation.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/w3c/deviceorientation/70d42d5484db7fd1646e48cc17caa5ff1c9d92cb/b-rotation.png -------------------------------------------------------------------------------- /c-rotation.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/w3c/deviceorientation/70d42d5484db7fd1646e48cc17caa5ff1c9d92cb/c-rotation.png -------------------------------------------------------------------------------- /equation1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/w3c/deviceorientation/70d42d5484db7fd1646e48cc17caa5ff1c9d92cb/equation1.png -------------------------------------------------------------------------------- /equation1.xhtml: -------------------------------------------------------------------------------- 1 | 2 | 15 | -------------------------------------------------------------------------------- /equation13a.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/w3c/deviceorientation/70d42d5484db7fd1646e48cc17caa5ff1c9d92cb/equation13a.png -------------------------------------------------------------------------------- /equation13a.xhtml: -------------------------------------------------------------------------------- 1 | 2 | 280 | -------------------------------------------------------------------------------- /equation14.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/w3c/deviceorientation/70d42d5484db7fd1646e48cc17caa5ff1c9d92cb/equation14.png -------------------------------------------------------------------------------- /equation14.xhtml: -------------------------------------------------------------------------------- 1 | 2 | 337 | -------------------------------------------------------------------------------- /equation18.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/w3c/deviceorientation/70d42d5484db7fd1646e48cc17caa5ff1c9d92cb/equation18.png -------------------------------------------------------------------------------- /equation18.xhtml: -------------------------------------------------------------------------------- 1 | 2 | 39 | -------------------------------------------------------------------------------- /equation2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/w3c/deviceorientation/70d42d5484db7fd1646e48cc17caa5ff1c9d92cb/equation2.png -------------------------------------------------------------------------------- /equation2.xhtml: -------------------------------------------------------------------------------- 1 | 2 | 27 | -------------------------------------------------------------------------------- /equation3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/w3c/deviceorientation/70d42d5484db7fd1646e48cc17caa5ff1c9d92cb/equation3.png -------------------------------------------------------------------------------- /equation3.xhtml: -------------------------------------------------------------------------------- 1 | 2 | 27 | -------------------------------------------------------------------------------- /equation4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/w3c/deviceorientation/70d42d5484db7fd1646e48cc17caa5ff1c9d92cb/equation4.png -------------------------------------------------------------------------------- /equation4.xhtml: -------------------------------------------------------------------------------- 1 | 2 | 27 | -------------------------------------------------------------------------------- /equation5a.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/w3c/deviceorientation/70d42d5484db7fd1646e48cc17caa5ff1c9d92cb/equation5a.png -------------------------------------------------------------------------------- /equation5a.xhtml: -------------------------------------------------------------------------------- 1 | 2 | 5 | -------------------------------------------------------------------------------- /equation5e.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/w3c/deviceorientation/70d42d5484db7fd1646e48cc17caa5ff1c9d92cb/equation5e.png -------------------------------------------------------------------------------- /equation5e.xhtml: -------------------------------------------------------------------------------- 1 | 2 | 34 | -------------------------------------------------------------------------------- /equation6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/w3c/deviceorientation/70d42d5484db7fd1646e48cc17caa5ff1c9d92cb/equation6.png -------------------------------------------------------------------------------- /equation6.xhtml: -------------------------------------------------------------------------------- 1 | 2 | 37 | -------------------------------------------------------------------------------- /equation7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/w3c/deviceorientation/70d42d5484db7fd1646e48cc17caa5ff1c9d92cb/equation7.png -------------------------------------------------------------------------------- /equation7.xhtml: -------------------------------------------------------------------------------- 1 | 2 | 22 | -------------------------------------------------------------------------------- /equation8a.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/w3c/deviceorientation/70d42d5484db7fd1646e48cc17caa5ff1c9d92cb/equation8a.png -------------------------------------------------------------------------------- /equation8a.xhtml: -------------------------------------------------------------------------------- 1 | 2 | 27 | -------------------------------------------------------------------------------- /equation8b.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/w3c/deviceorientation/70d42d5484db7fd1646e48cc17caa5ff1c9d92cb/equation8b.png -------------------------------------------------------------------------------- /equation8b.xhtml: -------------------------------------------------------------------------------- 1 | 2 | 20 | -------------------------------------------------------------------------------- /index.bs: -------------------------------------------------------------------------------- 1 |
2 | Title: Device Orientation and Motion 3 | Shortname: orientation-event 4 | Level: none 5 | Status: ED 6 | Group: dap 7 | TR: https://www.w3.org/TR/orientation-event/ 8 | ED: https://w3c.github.io/deviceorientation/ 9 | Repository: w3c/deviceorientation 10 | Editor: Reilly Grant 83788, Google LLC https://www.google.com 11 | Editor: Marcos Cáceres 39125, Apple Inc. https://www.apple.com 12 | Former Editor: Raphael Kubo da Costa 95850, Intel Corporation https://intel.com 13 | Former Editor: Rich Tibbett, Opera Software ASA 14 | Former Editor: Tim Volodine, Google Inc 15 | Former Editor: Steve Block, Google Inc until July 2012 16 | Former Editor: Andrei Popescu, Google Inc until July 2012 17 | Abstract: This specification defines events that represent the physical orientation and motion of a hosting device. These events provide web applications with access to orientation and motion data. The specification is designed to be agnostic to the underlying sources of this data, aiming to achieve interoperability across different environments. 18 | Boilerplate: omit issues-index, repository-issue-tracking no 19 | Include MDN Panels: if possible 20 | Implementation Report: https://wpt.fyi/results/orientation-event 21 | Issue Tracking: Device Orientation and Motion Repository https://github.com/w3c/deviceorientation/issues 22 | Status Text: New features since publication as a [Candidate Recommendation](https://www.w3.org/TR/2016/CR-orientation-event-20160818/) include integration of Permissions Policy and API, which now requires explicit user consent through {{DeviceOrientationEvent/requestPermission()}} for accessing device orientation data. Updates have been made to the coordinate system explanations and precision requirements to mitigate passive fingerprinting risks. The introduction of the deviceorientationabsolute event enhances applications requiring absolute orientation data (marked [=at risk=]). Interfaces are now only available in [=secure contexts=], and security and privacy considerations have been made normative. The specification now also provides a means to [[#automation|automate testing]] of this API (marked [=at risk=]). See [[#changes]] section for more information. 23 | Markup Shorthands: css no 24 | Markup Shorthands: markdown yes 25 | text macro: JOINT yes 26 | text macro: JOINTWEBAPPS yes 27 |28 |
29 | urlPrefix: https://w3c.github.io/sensors/; spec: GENERIC-SENSOR 30 | type: dfn 31 | text: can provide readings flag; url: virtual-sensor-can-provide-readings-flag 32 | text: virtual sensor mapping; url: virtual-sensor-mapping 33 | urlPrefix: https://w3c.github.io/webdriver/; spec: WEBDRIVER2 34 | type: dfn 35 | text: get a property; url: dfn-getting-properties 36 |37 | 38 | Introduction {#introduction} 39 | ============================ 40 | 41 | This section is non-normative. 42 | 43 | This specification provides two new DOM events for obtaining information about the physical orientation and movement of the hosting device. The information provided by the events is not raw sensor data, but rather high-level data which is agnostic to the underlying source of information. Common sources of information include gyroscopes, compasses and accelerometers. 44 | 45 | The {{deviceorientation}} event represents the physical orientation of the device, expressed as a series of rotations from a local coordinate frame. 46 | 47 | The {{devicemotion}} event represents the acceleration of the device, expressed in Cartesian coordinates in a coordinate frame defined in the device. It also supplies the rotation rate of the device about a local coordinate frame. Where practically possible, the event should provide the acceleration of the device's center of mass. 48 | 49 | The following code extracts illustrate basic use of the events. 50 | 51 |
54 | window.addEventListener("deviceorientation", event => { 55 | // process event.alpha, event.beta and event.gamma 56 | }); 57 | 58 | // Alternatively... 59 | window.ondeviceorientation = event => { 60 | // process event.alpha, event.beta and event.gamma 61 | }; 62 |63 |
68 | { 69 | alpha: 90, 70 | beta: 0, 71 | gamma: 0 72 | }; 73 |74 | To get the compass heading, one would simply subtract {{DeviceOrientationEvent/alpha}} from 360 degrees. As the device is turned on the horizontal surface, the compass heading is (360 - alpha). 75 |
84 | { 85 | alpha: 270 - alpha, 86 | beta: 0, 87 | gamma: 90 88 | }; 89 |90 |
95 | window.addEventListener("devicemotion", (event) => { 96 | // Process event.acceleration, event.accelerationIncludingGravity, 97 | // event.rotationRate and event.interval 98 | }); 99 | 100 | // Alternatively... 101 | window.ondevicemotion = (event) => { 102 | // Process event.acceleration, event.accelerationIncludingGravity, 103 | // event.rotationRate and event.interval 104 | }; 105 |106 |
111 | { 112 | x: 0, 113 | y: 0, 114 | z: 9.8 115 | }; 116 |117 |
122 | { 123 | x: 0, 124 | y: 0, 125 | z: -9.8 126 | }; 127 |128 |
133 | { 134 | acceleration: {x: v^2/r, y: 0, z: 0}, 135 | accelerationIncludingGravity: {x: v^2/r, y: 9.8, z: 0}, 136 | rotationRate: {alpha: 0, beta: 0, gamma: -v/r*180/pi} 137 | }; 138 |139 |
DeviceMotionEvent.requestPermission()
and DeviceOrientationEvent.requestPermission()
tests.
233 | 260 | partial interface Window { 261 | [SecureContext] attribute EventHandler ondeviceorientation; 262 | }; 263 | 264 | [Exposed=Window, SecureContext] 265 | interface DeviceOrientationEvent : Event { 266 | constructor(DOMString type, optional DeviceOrientationEventInit eventInitDict = {}); 267 | readonly attribute double? alpha; 268 | readonly attribute double? beta; 269 | readonly attribute double? gamma; 270 | readonly attribute boolean absolute; 271 | 272 | static Promise<PermissionState> requestPermission(optional boolean absolute = false); 273 | }; 274 | 275 | dictionary DeviceOrientationEventInit : EventInit { 276 | double? alpha = null; 277 | double? beta = null; 278 | double? gamma = null; 279 | boolean absolute = false; 280 | }; 281 |282 | 283 | The ondeviceorientation attribute is an [=event handler IDL attribute=] for the
ondeviceorientation
[=event handler=], whose [=event handler event type=] is deviceorientation
.
284 |
285 | The alpha attribute must return the value it was initialized to. It represents the rotation around the Z axis in the Z - X' - Y'' intrinsic Tait-Bryan angles described in [[#device-orientation-model]].
286 |
287 | The beta attribute must return the value it was initialized to. It represents the rotation around the X' axis (produced after the rotation around the Z axis has been applied) axis in the Z - X' - Y'' intrinsic Tait-Bryan angles described in [[#device-orientation-model]].
288 |
289 | The gamma attribute must return the value it was initialized to. It represents the rotation around the Y'' axis (produced after the rotation around the Z and X' axes have been applied in this order) in the Z - X' - Y'' intrinsic Tait-Bryan angles described in [[#device-orientation-model]].
290 |
291 | The absolute attribute must return the value it was initialized to. It indicates whether [=relative orientation=] or [=absolute orientation=] data is being provided.
292 |
293 | relative-orientation
" if |absolute| is false, and "absolute-orientation
" otherwise.
325 | 1. If |topLevelTraversable|'s virtual sensor mapping contains |virtualSensorType|:
326 | 1. Let |virtualSensor| be |topLevelTraversable|'s virtual sensor mapping[|virtualSensorType|].
327 | 1. If |virtualSensor|'s can provide readings flag is true:
328 | 1. Set |orientation| to the latest readings provided to |virtualSensor| with the "alpha
", "beta
", and "gamma
" keys.
329 | 1. Otherwise:
330 | 1. If |absolute| is false:
331 | 1. Set |orientation| to the device's [=relative orientation=] in the tridimensional plane.
332 | 1. Otherwise:
333 | 1. Set |orientation| to the device's [=absolute orientation=] in the tridimensional plane.
334 | 1. Let |permissions| be null.
335 | 1. If |absolute| is false:
336 | 1. Set |permissions| to « "accelerometer", "gyroscope" ».
337 | 1. Otherwise:
338 | 1. Set |permissions| to « "accelerometer", "gyroscope", "magnetometer" ».
339 | 1. Let |environment| be |window|'s relevant settings object.
340 | 1. Run these steps in parallel:
341 | 1. [=list/For each=] |permission| in |permissions|:
342 | 1. Let |state| be the result of getting the current permission state with |permission| and |environment|.
343 | 1. If |state| is not "{{PermissionState/granted}}", return.
344 | 1. [=Queue a global task=] on the [=device motion and orientation task source=] given |window| to run the following steps:
345 | 1. Let |z| be |orientation|'s representation as intrinsic Tait-Bryan angles Z - X' - Y'' along the Z axis, or null if the implementation cannot provide an angle value.
346 | 1. If |z| is not null, limit |z|'s precision to 0.1 degrees.
347 | 1. Let |x| be |orientation|'s representation as intrinsic Tait-Bryan angles Z - X' - Y'' along the X' axis, or null if the implementation cannot provide an angle value.
348 | 1. If |x| is not null, limit |x|'s precision to 0.1 degrees.
349 | 1. Let |y| be |orientation|'s representation as intrinsic Tait-Bryan angles Z - X' - Y'' along the Y'' axis, or null if the implementation cannot provide an angle value.
350 | 1. If |y| is not null, limit |y|'s precision to 0.1 degrees.
351 | 1. [=Fire an event=] named |event| at |window|, using {{DeviceOrientationEvent}}, with the {{DeviceOrientationEvent/alpha}} attribute initialized to |z|, the {{DeviceOrientationEvent/beta}} attribute initialized to |x|, the {{DeviceOrientationEvent/gamma}} attribute initialized to |y|, and the {{DeviceOrientationEvent/absolute}} attribute initialized to |absolute|.
352 |
353 | 388 | partial interface Window { 389 | [SecureContext] attribute EventHandler ondeviceorientationabsolute; 390 | }; 391 |392 | 393 | The ondeviceorientationabsolute attribute is an [=event handler IDL attribute=] for the
ondeviceorientationabsolute
[=event handler=], whose [=event handler event type=] is deviceorientationabsolute
.
394 |
395 | A deviceorientationabsolute event is completely analogous to the deviceorientation event, except that it must always provide [=absolute orientation=] data.
396 |
397 | 415 | [Exposed=Window, SecureContext] 416 | interface DeviceMotionEventAcceleration { 417 | readonly attribute double? x; 418 | readonly attribute double? y; 419 | readonly attribute double? z; 420 | }; 421 |422 | 423 | The {{DeviceMotionEventAcceleration}} interface represents the device's acceleration as described in [[#device-motion-model]]. It has the following associated data: 424 | 425 | : x axis acceleration 426 | :: The device's acceleration rate along the X axis, or null. It is initially null. 427 | : y axis acceleration 428 | :: The device's acceleration rate along the Y axis, or null. It is initially null. 429 | : z axis acceleration 430 | :: The device's acceleration rate along the Z axis, or null. It is initially null. 431 | 432 | The x getter steps are to return the value of [=this=]'s [=DeviceMotionEventAcceleration/x axis acceleration=]. 433 | 434 | The y getter steps are to return the value of [=this=]'s [=DeviceMotionEventAcceleration/y axis acceleration=]. 435 | 436 | The z getter steps are to return the value of [=this=]'s [=DeviceMotionEventAcceleration/z axis acceleration=]. 437 | 438 | ### The DeviceMotionEventRotationRate interface ### {#device-motion-event-rotation-rate-api} 439 | 440 |
441 | [Exposed=Window, SecureContext] 442 | interface DeviceMotionEventRotationRate { 443 | readonly attribute double? alpha; 444 | readonly attribute double? beta; 445 | readonly attribute double? gamma; 446 | }; 447 |448 | 449 | The {{DeviceMotionEventRotationRate}} interface represents the device's [=rotation rate=] as described in [[#device-motion-model]]. It has the following associated data: 450 | 451 | : x axis rotation rate 452 | :: The device's rotation rate about the X axis, or null. It is initially null. 453 | : y axis rotation rate 454 | :: The device's rotation rate about the Y axis, or null. It is initially null. 455 | : z axis rotation rate 456 | :: The device's rotation rate about the Z axis, or null. It is initially null. 457 | 458 | The alpha getter steps are to return the value of [=this=]'s x axis rotation rate. 459 | 460 | The beta getter steps are to return the value of [=this=]'s y axis rotation rate. 461 | 462 | The gamma getter steps are to return the value of [=this=]'s z axis rotation rate. 463 | 464 | ### The DeviceMotionEvent interface ### {#device-motion-event-api} 465 | 466 |
467 | partial interface Window { 468 | [SecureContext] attribute EventHandler ondevicemotion; 469 | }; 470 | 471 | [Exposed=Window, SecureContext] 472 | interface DeviceMotionEvent : Event { 473 | constructor(DOMString type, optional DeviceMotionEventInit eventInitDict = {}); 474 | readonly attribute DeviceMotionEventAcceleration? acceleration; 475 | readonly attribute DeviceMotionEventAcceleration? accelerationIncludingGravity; 476 | readonly attribute DeviceMotionEventRotationRate? rotationRate; 477 | readonly attribute double interval; 478 | 479 | static Promise<PermissionState> requestPermission(); 480 | }; 481 | 482 | dictionary DeviceMotionEventAccelerationInit { 483 | double? x = null; 484 | double? y = null; 485 | double? z = null; 486 | }; 487 | 488 | dictionary DeviceMotionEventRotationRateInit { 489 | double? alpha = null; 490 | double? beta = null; 491 | double? gamma = null; 492 | }; 493 | 494 | dictionary DeviceMotionEventInit : EventInit { 495 | DeviceMotionEventAccelerationInit acceleration; 496 | DeviceMotionEventAccelerationInit accelerationIncludingGravity; 497 | DeviceMotionEventRotationRateInit rotationRate; 498 | double interval = 0; 499 | }; 500 |501 | 502 | The ondevicemotion attribute is an [=event handler IDL attribute=] for the
ondevicemotion
[=event handler=], whose [=event handler event type=] is devicemotion
.
503 |
504 |
507 |
508 | The acceleration attribute must return the value it was initialized to. When the object is created, this attribute must be initialized to null. It represents the device's linear acceleration.
509 |
510 | The accelerationIncludingGravity attribute must return the value it was initialized to. When the object is created, this attribute must be initialized to null. It represents the device's acceleration with gravity.
511 |
512 | The rotationRate attribute must return the value it was initialized to. When the object is created, this attribute must be initialized to null. It represents the device's [=rotation rate=].
513 |
514 | The interval attribute must return the value it was initialized to. It represents the interval at which data is obtained from the underlying hardware and must be expressed in milliseconds (ms). It is constant to simplify filtering of the data by the Web application.
515 |
516 | requestPermission()
API calls.
620 |
621 | Furthermore, to minimize privacy risks, the chance of fingerprinting and other attacks the implementations must:
622 |
623 | * fire events only when a [=/navigable=]'s [=navigable/active document=]'s [=visibility state=] is "visible
",
624 | * implement [[#permissions-integration]] so that events are fired on [=child navigables=] (including but not restricted to cross-origin ones) only if allowed by the [=/top-level traversable=],
625 | * fire events on a [=/navigable=]'s [=navigable/active windows=] only when its [=relevant settings object=] is a [=secure context=],
626 | * limit precision of attribute values as described in the previous sections.
627 |
628 | Additionally, implementing these items may also have a beneficial impact on the battery life of mobile devices.
629 |
630 | Issue: Further implementation experience is being gathered to inform the limit for the maximum sampling frequency cap.
631 |
632 | Accessibility considerations {#a11y}
633 | ===========================================================
634 |
635 | DeviceOrientation events provide opportunities for novel forms of input, which can open up novel interactions for users. In order to ensure that as many people as possible will be able to interact with the experiences you build, please consider the following:
636 |
637 | * It is important for alternative means of providing input to be available, so that people who cannot make the required gestures have another way to interact. Examples may include people with dexterity-related disabilities, or people who use eye gaze, or head-tracking input.
638 | - For games, consider supporting either game controller, keyboard or mouse input as alternative interaction methods.
639 | - For web apps, consider providing UI, such as a button, menu command, and/or keyboard shortcut, to perform the function.
640 |
641 | * It is essential that users can undo any accidental input - this may be particularly relevant for people with tremors.
642 |
643 | There are two user needs that can arise, which would likely be managed by the user agent, or underlying operating system. However, it can be helpful to bear these considerations in mind, as they represent ways that your content or app may be used.
644 |
645 | * It is important that the user is able to disable the use of gesture or motion-based input. The web app should provide an appropriate accessible means for the user to supply this input, such as a button.
646 | - For example: whilst the shake-to-undo feature can provide a natural and thoughtful interaction for some, for people with tremors, it may present a barrier. This could be managed by declining permission, or more likely by changing a browser or OS setting, coupled with the web app providing alternative input means.
647 | * It is also important that the device's orientation can be locked - a primary use case being someone who is interacting with a touch device, such as a phone, non-visually. They may have built up 'muscle memory' as to where elements are on the screen in a given orientation, and having the layout shift would break their ability to navigate. Again, this would most likely be done at the operating system level.
648 |
649 | Automation {#automation}
650 | ==========
651 |
652 | deviceorientation
event is built upon virtual sensors that represent accelerometers, gyroscopes and, optionally, magnetometers.
666 |
667 | Orientation data retrieved from the platform by the user agent comes from accelerometers, gyroscopes and, optionally, magnetometers. Contrary to motion data, however, these lower-level readings must be transformed into Euler angles in the formation described in [[#device-orientation-model]]. Furthermore, the platform might provide extra APIs to the user agent that already perform some of those conversions from raw acceleration and rotation data.
668 |
669 | Therefore, instead of requiring implementations (and automation users) to provide orientation readings via lower-level virtual sensors which use different units of measurement, this specification defines extra virtual sensor types for relative and orientation data in the format used by this specification.
670 |
671 | ### Parse orientation reading data algorithm ### {#parse-orientation-data-reading-algorithm}
672 |
673 | absolute-orientation
"
697 | : [=map/Value=]
698 | :: A virtual sensor metadata whose reading parsing algorithm is parse orientation data reading.
699 |
700 | ### The "relative-orientation" virtual sensor type ### {#relative-orientation-virtual-sensors}
701 |
702 | The [=per-type virtual sensor metadata=] [=map=] must have the following [=map/entry=]:
703 | :
704 | : [=map/Key=]
705 | :: "relative-orientation
"
706 | : [=map/Value=]
707 | :: A virtual sensor metadata whose reading parsing algorithm is parse orientation data reading.
708 |
709 | Device Motion Automation {#device-motion-automation}
710 | ------------------------
711 |
712 | The motion data retrieved from the platform by the user agent comes from accelerometers and gyroscopes. This specification defines certain [=per-type virtual sensor metadata=] entries that are shared with the [[ACCELEROMETER]] and [[GYROSCOPE]] specifications.
713 |
714 | Accelerometer virtual sensors are used to provide acceleration with gravity data to the platform. Linear Acceleration virtual sensors are used to provide linear acceleration data to the platform. Gyroscope virtual sensors are used to provide [=rotation rate=] data to the platform.
715 |
716 | ### The "accelerometer" virtual sensor type ### {#accelerometer-virtual-sensors}
717 |
718 | The [=per-type virtual sensor metadata=] [=map=] must have the following [=map/entry=]:
719 |
720 | : [=map/Key=]
721 | :: "accelerometer
"
722 | : [=map/Value=]
723 | :: A virtual sensor metadata whose reading parsing algorithm is parse xyz reading.
724 |
725 | ### The "linear-acceleration" virtual sensor type ### {#linear-acceleration-virtual-sensors}
726 |
727 | The [=per-type virtual sensor metadata=] [=map=] must have the following [=map/entry=]:
728 |
729 | : [=map/Key=]
730 | :: "linear-acceleration
"
731 | : [=map/Value=]
732 | :: A virtual sensor metadata whose reading parsing algorithm is parse xyz reading.
733 |
734 | ### The "gyroscope" virtual sensor type ### {#gyroscope-virtual-sensors}
735 |
736 | The [=per-type virtual sensor metadata=] [=map=] must have the following [=map/entry=]:
737 |
738 | : [=map/Key=]
739 | :: "gyroscope
"
740 | : [=map/Value=]
741 | :: A virtual sensor metadata whose reading parsing algorithm is parse xyz reading.
742 |
743 | 808 | var degtorad = Math.PI / 180; // Degree-to-Radian conversion 809 | 810 | function compassHeading( alpha, beta, gamma ) { 811 | 812 | var _x = beta ? beta * degtorad : 0; // beta value 813 | var _y = gamma ? gamma * degtorad : 0; // gamma value 814 | var _z = alpha ? alpha * degtorad : 0; // alpha value 815 | 816 | var cX = Math.cos( _x ); 817 | var cY = Math.cos( _y ); 818 | var cZ = Math.cos( _z ); 819 | var sX = Math.sin( _x ); 820 | var sY = Math.sin( _y ); 821 | var sZ = Math.sin( _z ); 822 | 823 | // Calculate Vx and Vy components 824 | var Vx = - cZ * sY - sZ * sX * cY; 825 | var Vy = - sZ * sY + cZ * sX * cY; 826 | 827 | // Calculate compass heading 828 | var compassHeading = Math.atan( Vx / Vy ); 829 | 830 | // Convert compass heading to use whole unit circle 831 | if( Vy < 0 ) { 832 | compassHeading += Math.PI; 833 | } else if( Vx < 0 ) { 834 | compassHeading += 2 * Math.PI; 835 | } 836 | 837 | return compassHeading * ( 180 / Math.PI ); // Compass Heading (in degrees) 838 | 839 | } 840 |841 |
879 | var degtorad = Math.PI / 180; // Degree-to-Radian conversion 880 | 881 | function getRotationMatrix( alpha, beta, gamma ) { 882 | 883 | var _x = beta ? beta * degtorad : 0; // beta value 884 | var _y = gamma ? gamma * degtorad : 0; // gamma value 885 | var _z = alpha ? alpha * degtorad : 0; // alpha value 886 | 887 | var cX = Math.cos( _x ); 888 | var cY = Math.cos( _y ); 889 | var cZ = Math.cos( _z ); 890 | var sX = Math.sin( _x ); 891 | var sY = Math.sin( _y ); 892 | var sZ = Math.sin( _z ); 893 | 894 | // 895 | // ZXY rotation matrix construction. 896 | // 897 | 898 | var m11 = cZ * cY - sZ * sX * sY; 899 | var m12 = - cX * sZ; 900 | var m13 = cY * sZ * sX + cZ * sY; 901 | 902 | var m21 = cY * sZ + cZ * sX * sY; 903 | var m22 = cZ * cX; 904 | var m23 = sZ * sY - cZ * cY * sX; 905 | 906 | var m31 = - cX * sY; 907 | var m32 = sX; 908 | var m33 = cX * cY; 909 | 910 | return [ 911 | m11, m12, m13, 912 | m21, m22, m23, 913 | m31, m32, m33 914 | ]; 915 | 916 | }; 917 |918 |
931 | var degtorad = Math.PI / 180; // Degree-to-Radian conversion 932 | 933 | function getQuaternion( alpha, beta, gamma ) { 934 | 935 | var _x = beta ? beta * degtorad : 0; // beta value 936 | var _y = gamma ? gamma * degtorad : 0; // gamma value 937 | var _z = alpha ? alpha * degtorad : 0; // alpha value 938 | 939 | var cX = Math.cos( _x/2 ); 940 | var cY = Math.cos( _y/2 ); 941 | var cZ = Math.cos( _z/2 ); 942 | var sX = Math.sin( _x/2 ); 943 | var sY = Math.sin( _y/2 ); 944 | var sZ = Math.sin( _z/2 ); 945 | 946 | // 947 | // ZXY quaternion construction. 948 | // 949 | 950 | var w = cX * cY * cZ - sX * sY * sZ; 951 | var x = sX * cY * cZ - cX * sY * sZ; 952 | var y = cX * sY * cZ + sX * cY * sZ; 953 | var z = cX * cY * sZ + sX * sY * cZ; 954 | 955 | return [ w, x, y, z ]; 956 | 957 | } 958 |959 |
978 | urlPrefix: https://html.spec.whatwg.org/multipage/ 979 | urlPrefix: webappapis.html; type: dfn 980 | text: relevant settings object 981 |982 | 983 |
984 | { 985 | "EULERANGLES": { 986 | "href": "https://en.wikipedia.org/wiki/Euler_angles", 987 | "title": "Euler Angles" 988 | }, 989 | "TOUCH": { 990 | "href": "https://arxiv.org/abs/1602.04115", 991 | "title": "TouchSignatures: Identification of User Touch Actions and PINs Based on Mobile Sensor Data via JavaScript", 992 | "date": "12 Feb 2016" 993 | }, 994 | "INDOORPOS": { 995 | "authors": [ 996 | "Shala, Ubejd", 997 | "Angel Rodriguez" 998 | ], 999 | "href": "http://www.diva-portal.org/smash/record.jsf?pid=diva2%3A475619&dswid=9050", 1000 | "title": "Indoor positioning using sensor-fusion in android devices", 1001 | "date": "2011" 1002 | }, 1003 | "FINGERPRINT": { 1004 | "href": "https://arxiv.org/abs/1408.1416", 1005 | "title": "Mobile Device Identification via Sensor Fingerprinting", 1006 | "date": "6 Aug 2014" 1007 | }, 1008 | "GIMBALLOCK": { 1009 | "href": "https://en.wikipedia.org/wiki/Gimbal_Lock", 1010 | "title": "Gimbal Lock" 1011 | }, 1012 | "PROPERACCELERATION": { 1013 | "href": "https://en.wikipedia.org/wiki/Proper_acceleration", 1014 | "title": "Proper acceleration" 1015 | }, 1016 | "QUATERNIONS": { 1017 | "href": "https://en.wikipedia.org/wiki/Quaternion", 1018 | "title": " Quaternions" 1019 | }, 1020 | "SENSORID": { 1021 | "href": "https://doi.org/10.1109/SP.2019.00072", 1022 | "title": "SensorID: Sensor Calibration Fingerprinting for Smartphones", 1023 | "date": "2019", 1024 | "authors": [ 1025 | "Zhang, Jiexin", 1026 | "Beresford, Alastair R.", 1027 | "Sheret, Ian" 1028 | ], 1029 | "publisher": "IEEE Symposium on Security and Privacy" 1030 | }, 1031 | "G-FORCE": { 1032 | "href": "https://en.wikipedia.org/wiki/G-force", 1033 | "title": "G-Force" 1034 | } 1035 | } 1036 |1037 | 1038 | Changes {#changes} 1039 | =========== 1040 | 1041 | This section summarizes substantial changes and notable editorial improvements to guide review. Full details are available from the commit log. Changes since the Candidate Recommendation 2016-08-18: 1042 | 1043 | - Add Permissions Policy integration, which supersedes the previous requirement of only firing events on iframes that were same-origin with the top-level frame 1044 | - Add note to implementers about bundling permission requests 1045 | - Export powerful features Accelerometer, Gyroscope and Magnetometer 1046 | - Add Permissions API integration, start requiring requestPermission() usage 1047 | - editorial: Define API section more normatively and with more dfns 1048 | - editorial: Reorder acceleration explanation in Device Motion Model section 1049 | - editorial: Update explanations of the device rotation and motion references 1050 | - editorial: Use more precise event handling terms, modernize others 1051 | - editorial: Refer to [[SCREEN-ORIENTATION]] instead of the orientation change event 1052 | - editorial: Reword requirements in "Security and privacy considerations" 1053 | - Mark use cases and requirements and examples sections non-normative 1054 | - Remove the oncompassneedscalibration event 1055 | - Update references to "triggered by user activation", now referred to as "transient activation" 1056 | - Align with DOM phrasing on firing events 1057 | - Add a note about acceleration properties for DeviceMotionEvent 1058 | - Add a note explaining how the coordinate system differs from the CSS coordinate system 1059 | - Require no more precise than 0.1 degrees, 0.1 degrees per second, 0.1 meters per second squared to mitigate a passive fingerprinting issue 1060 | - Update constructor definition in IDL with the Web IDL 1061 | - Add explicit [Exposed] to interfaces 1062 | - Update IDL dictionaries with new dictionary defaulting setup 1063 | - Note the deviceorientationabsolute event and its ondeviceorientationabsolute event handler IDL attribute have limited implementation experience 1064 | - Add requestPermission() API static operation to both DeviceOrientationEvent and DeviceMotionEvent 1065 | - Add [SecureContext] to event handlers ondeviceorientation, ondevicemotion and ondeviceorientationabsolute 1066 | - Restrict all interfaces to secure contexts 1067 | - Remove [NoInterfaceObject] from DeviceAcceleration and DeviceRotationRate 1068 | - Make security and privacy considerations normative 1069 | - Add the ondeviceorientationabsolute event handler attribute into the IDL block (was only in prose) 1070 | - Remove '?' from dictionary members of DeviceMotionEventInit 1071 | - Use [Exposed=Window] extended attribute 1072 | -------------------------------------------------------------------------------- /security-privacy-self-assessment.md: -------------------------------------------------------------------------------- 1 | # Security and Privacy Self-Review Questionnaire for DeviceOrientation Event 2 | 3 | [Self-Review Questionnaire](https://www.w3.org/TR/security-privacy-questionnaire/) 4 | responses for the [DeviceOrientation Event](https://www.w3.org/TR/orientation-event/) specification. 5 | 6 | Related Self-Review Questionnaires: 7 | - [Generic Sensor API](https://github.com/w3c/sensors/blob/main/security-questionnaire.md) 8 | - [Orientation Sensor API](https://github.com/w3c/orientation-sensor/blob/main/security-questionnaire.md) 9 | 10 | ### 2.1 What information might this feature expose to Web sites or other parties, and for what purposes is that exposure necessary? 11 | 12 | Information about the physical orientation and movement of the hosting device. See [use cases](https://www.w3.org/TR/orientation-event/#use-cases). 13 | 14 | ### 2.2 Do features in your specification expose the minimum amount of information necessary to enable their intended uses? 15 | 16 | This specification allows developers to request access to only the set of sensor data necessary, either a "device motion" event for motion-controlled applications or a "device orientation" event for orientation control. Since absolute orientation exposes more information, a "relative orientation" option is available if the compass heading is unnecessary. 17 | 18 | The data precision is normatively limited to resist fingerprinting (see 2.6). 19 | 20 | ### 2.3 How do the features in your specification deal with personal information, personally-identifiable information (PII), or information derived from them? 21 | 22 | This specification does not deal with PII directly, however identifiable information such as gait can be determined from monitoring sensor readings over time. The specification requires users to give express permission for the user agent to provide device motion and/or orientation data. Furthermore, all interfaces are restricted to secure contexts to protect against both active and passive network attackers. 23 | 24 | ### 2.4 How do the features in your specification deal with sensitive information? 25 | 26 | See 2.3. 27 | 28 | ### 2.5 Do the features in your specification introduce new state for an origin that persists across browsing sessions? 29 | 30 | This specification defines new [permissions](https://www.w3.org/TR/orientation-event/#permissions-api-integration) for which user agents may persist the user's decision to grant access to a site between browsing sessions. Otherwise, sensors are completely stateless. 31 | 32 | ### 2.6 Do the features in your specification expose information about the underlying platform to origins? 33 | 34 | Minor manufacturing imperfections and differences unique to the underlying platform and the sensor hardware in the hosting device might be detected through readings over time. 35 | 36 | The specification mitigates this type of passive fingerprinting by normatively limiting rotation and acceleration precision to at most 0.1 degrees, 0.1 degrees per second or 0.1 meters per second squared as appropriate. More context is available in a [paper](https://github.com/JensenPaul/sensor-fingerprint-mitigation). 37 | 38 | ### 2.7 Does this specification allow an origin to send data to the underlying platform? 39 | 40 | No. 41 | 42 | ### 2.8 Do features in this specification enable access to device sensors? 43 | 44 | Yes. See 2.1 and 2.2. 45 | 46 | ### 2.9 Do features in this specification enable new script execution/loading mechanisms? 47 | 48 | No. 49 | 50 | ### 2.10 Do features in this specification allow an origin to access other devices? 51 | 52 | No. 53 | 54 | ### 2.11 Do features in this specification allow an origin some measure of control over a user agent’s native UI? 55 | 56 | The specification includes a method to request the user agent display a permission prompt, the contents of which are implementation-defined. 57 | 58 | ### 2.12 What temporary identifiers do the features in this specification create or expose to the web? 59 | 60 | None. 61 | 62 | ### 2.13 How does this specification distinguish between behavior in first-party and third-party contexts? 63 | 64 | The Permissions Policy integration controls whether third-party contexts are able to receive the events defined by this specification: 65 | 66 | - The "deviceorientation" event requires the "accelerometer" and "gyroscope" features when providing relative orientation data. For the implementation to fall back to absolute orientation data, the "magnetometer" feature is also required. 67 | - The "deviceorientationabsolute" event requires the "accelerometer", "gyroscope" and "magnetometer" features. 68 | - The "devicemotion" event requires the "accelerometer" and "gyroscope" features. 69 | 70 | The default allowlist for all policy-controlled features defined by this specification ("accelerometer", "gyroscope", and "magnetometer") is `"self"`, which does not allow third-party contexts to receive the events above and have access to the corresponding sensor readings. 71 | 72 | ### 2.14 How do the features in this specification work in the context of a browser’s Private Browsing or Incognito mode? 73 | 74 | No difference to the browser's 'normal' state. 75 | 76 | ### 2.15 Does this specification have both "Security Considerations" and "Privacy Considerations" sections? 77 | 78 | Yes, combined together. 79 | 80 | ### 2.16 Do features in your specification enable origins to downgrade default security protections? 81 | 82 | No. 83 | 84 | ### 2.17 How does your feature handle non-"fully active" documents? 85 | 86 | Events are fired on active windows only. 87 | 88 | ### 2.18 What should this questionnaire have asked? 89 | 90 | That's all. Thank you for your review. 91 | -------------------------------------------------------------------------------- /spec-source-orientation.html: -------------------------------------------------------------------------------- 1 | index.html -------------------------------------------------------------------------------- /start.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/w3c/deviceorientation/70d42d5484db7fd1646e48cc17caa5ff1c9d92cb/start.png -------------------------------------------------------------------------------- /w3c.json: -------------------------------------------------------------------------------- 1 | { 2 | "group": 43696, 3 | "contacts": [ 4 | "himorin" 5 | ], 6 | "shortName": "orientation-event", 7 | "repo-type": "rec-track", 8 | "policy": "open" 9 | } 10 | --------------------------------------------------------------------------------