* 仕様書

[REFS[
- [4] [CITE@en[DeviceOrientation Event Specification]] ([TIME[2016-08-19 00:30:43 +09:00]]) <https://w3c.github.io/deviceorientation/spec-source-orientation.html#devicemotion>
- [20] [CITE@en[DeviceOrientation Event Specification]] ([TIME[2016-08-19 00:30:43 +09:00]]) <https://w3c.github.io/deviceorientation/spec-source-orientation.html#security-and-privacy>
]REFS]

* イベントハンドラー

[5] [CODE(DOMi)@en[Window]] [[インターフェイス]]の
[DFN[[CODE(DOMa)@en[ondevicemotion]]]] [[IDL属性]]は、
[CODE(DOMe)@en[devicemotion]] [[イベント]]の[[イベントハンドラーIDL属性]]です [SRC[>>4]]。

* [CODE(DOMi)@en[DeviceMotionEvent]] インターフェイス

[9] [DFN[[CODE(DOMi)@en[DeviceMotionEvent]]]] [[インターフェイス]]は、
[CODE(DOMi)@en[Event]] [[インターフェイス]]を[[継承]]しています。
[[イベント構築子]]を持ちます。
[[文書環境]]に[[晒され]]ています。
[DFN[[CODE(DOMi)@en[DeviceMotionEventInit]]]] [[辞書]]は、
[CODE(DOMi)@en[EventInit]] [[辞書]]を[[継承]]しています。 [SRC[>>4]]

[10] 両者は、次の[[IDL属性]]/[[辞書メンバー]]を持ちます。
[FIG(table)[
:n: 名前
:attr: [[IDL属性]]の[[型][型 (Web IDL)]]
:dict: [[辞書メンバー]]の[[型][型 (Web IDL)]]
:init: [[初期値]]

:n:[DFN[[CODE(DOMa)@en[acceleration][DeviceMotionEvent]]]]
:attr: [CODE(DOMi)@en[[[DeviceAcceleration]][[?][nullable]]]]
:dict: [CODE(DOMi)@en[[[DeviceAccelerationInit]][[?][nullable]]]]
:init: [CODE[null]]

:n:[DFN[[CODE(DOMa)@en[accelerationIncludingGravity][DeviceMotionEvent]]]]
:attr: [CODE(DOMi)@en[[[DeviceAcceleration]][[?][nullable]]]]
:dict: [CODE(DOMi)@en[[[DeviceAccelerationInit]][[?][nullable]]]]
:init: [CODE[null]]

:n:[DFN[[CODE(DOMa)@en[rotationRate][DeviceMotionEvent]]]]
:attr: [CODE(DOMi)@en[[[DeviceRotationRate]][[?][nullable]]]]
:dict: [CODE(DOMi)@en[[[DeviceRotationRateInit]][[?][nullable]]]]
:init: [CODE[null]]

:n:[DFN[[CODE(DOMa)@en[interval][DeviceMotionEvent]]]]
:attr: [CODE(DOMi)@en[[[double]][[?][nullable]]]]
:dict: [CODE(DOMi)@en[[[double]][[?][nullable]]]]
:init: [CODE[null]]

]FIG]

* 処理

[19] [[DeviceOrientation Event]] に対応した[[利用者エージェント]]は、
[CODE[devicemotion]] [[イベント]]を[[発火]]しなければ[MUST[なりません]]。
情報を提供できない場合も、 ([CODE[null]] で) [[発火]]する[SHOULD[べきです]]。 [SRC[>>4]]

[18] [VAR[取得間隔]]を、固定の [[ms]] 単位の値に設定します。
[VAR[取得間隔]]ごとに、[[ハードウェア]]からデータを取得します。
動きの情報を提供できないときは、 [VAR[取得間隔]]を [CODE[null]] に設定します。 [SRC[>>4]]

[8] [VAR[窓]]の決定、[VAR[取得間隔]]の決定、そもそもこの情報を提供するかどうかなどについては、
[[DeviceOrientation Event]] を参照。

[6] 次のようにしなければ[MUST[なりません]] [SRC[>>4]]。
[FIG(steps)[
= [11] [VAR[加速度]]を、[CODE[null]] に設定します。
= [12] [VAR[重力入り加速度]]を、 [CODE[null]] に設定します。
= [14] [VAR[測定値]]を、
[[装置]]の[[地球座標枠]]に対する[[加速度]]を、
[[本体枠]]によって表現したもの ([[単位]]は [[m/s[SUP[2]]]]) に設定します。
取得できない場合は、 [CODE[null]] に設定します。
= [13] [[重力]]の影響を排した[[加速度]]を得られない場合 ([[ジャイロスコープ]]の無い場合など) は、
== [15] [VAR[重力入り加速度]]を、 [VAR[測定値]]に設定します。
= [16] それ以外の場合、
== [17] [VAR[加速度]]を、[VAR[測定値]]に設定します。
= [7] [[イベントを発火]]します。
[FIG(list members)[
: [VAR[[[名前][イベント型]]]] : [DFN[[CODE(DOMe)@en[devicemotion]]]]
: [VAR[[[インターフェイス][イベントインターフェイス]]]] : [CODE(DOMi)@en[DeviceMotionEvent]]
: [VAR[[[対象][イベント対象]]]] : [VAR[窓]]
: [CODE[acceleration][DeviceMotionEvent]] : [VAR[加速度]]
: [CODE[accelerationIncludingGravity]] : [VAR[重力入り加速度]]
: [CODE[rotationRate][DeviceMotionEvent]] : 
[[装置]]の[[空間]]中の[[回転]]率を、
[[装置の方向]]の[[角度]]の変化率 ([[単位]] [[°]]/[[s]]) で表したもの。
取得できない場合は、 [CODE[null]] に設定します。
: [CODE[interval][DeviceMotionEvent]] : [VAR[取得間隔]]
]FIG]
]FIG]

-*-*-

[22] [[Windows]] 版の [[Chrome]] の、おそらく測定できない環境では、
[CODE[acceleration]]、[CODE[accelerationIncludingGravity]]、
[CODE[rotationRate]] とも[[オブジェクト]]になりますが、
各[[IDL属性]]は [CODE[null]] になります。
[CODE[interval][devicemotion]] は [N[0]] になります。
[TIME[2016-11-02T09:54:11.900Z]]

* セキュリティー

[21] [[fingerprinting vector]] です [SRC[>>20]]。

* 歴史

[1] [CITE@en[DeviceOrientation Event Specification]]
( ([TIME[2012-06-14 06:21:37 +09:00]] 版))
<http://dev.w3.org/geo/api/spec-source-orientation.html#devicemotion>

[2] [CITE@en-US[devicemotion - Event reference | MDN]]
( ([TIME[2014-06-19 01:32:04 +09:00]] 版))
<https://developer.mozilla.org/en-US/docs/Web/Events/devicemotion>

[FIG(quote)[
[FIGCAPTION[
[3] [CITE[Intent to deprecate: Insecure usage of powerful features - Google グループ]]
([TIME[2015-02-28 11:14:49 +09:00]] 版)
<https://groups.google.com/a/chromium.org/forum/#!topic/blink-dev/2LXKVWYkOus>
]FIGCAPTION]

> We want to start applying the concepts in https://w3c.github.io/webappsec/specs/powerfulfeatures/ to features that have already shipped and which do not meet the (new, not present at the time) requirements. 

]FIG]


[23] [CITE@en[Merge pull request #41 from w3c/timvolodine-clarify-null]]
([[timvolodine]]著, [TIME[2017-04-04 01:46:16 +09:00]])
<https://github.com/w3c/deviceorientation/commit/e37c9f2df202bc4958c4448e95814d77858a15bf>

[24] [CITE@en[Deprecations and Removals in Chrome 59  |  Web  |  Google Developers]]
([TIME[2017-05-13 04:52:02 +09:00]])
<https://developers.google.com/web/updates/2017/04/chrome-59-deprecations>

[FIG(quote)[
[FIGCAPTION[
[25] [CITE@en[Safari 12.1 Release Notes | Apple Developer Documentation]]
([TIME[2019-02-10 12:06:57 +09:00]])
<https://developer.apple.com/documentation/safari_release_notes/safari_12_1_release_notes>
]FIGCAPTION]

> Added Motion & Orientation settings on iOS to enable the DeviceMotionEvent and DeviceOrientationEvent events.

]FIG]
