

* 仕様書

[REFS[
- [9] [CITE@en[DeviceOrientation Event Specification]] ([TIME[2016-08-19 00:30:43 +09:00]]) <https://w3c.github.io/deviceorientation/spec-source-orientation.html>
-- [11] [CITE@en[DeviceOrientation Event Specification]] ([TIME[2016-08-19 00:30:43 +09:00]]) <https://w3c.github.io/deviceorientation/spec-source-orientation.html#deviceorientation>
-- [36] [CITE@en[DeviceOrientation Event Specification]] ([TIME[2016-08-19 00:30:43 +09:00]]) <https://w3c.github.io/deviceorientation/spec-source-orientation.html#deviceorientationabsolute>
-- [19] [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]

* イベント

[10] 次の[[イベント]]があります。
[FIG(middle list)[
- [CODE(DOMe)@en[deviceorientation]]
- [CODE(DOMe)@en[deviceorientationabsolute]]
- [CODE(DOMe)@en[devicemotion]]
- [CODE(DOMe)@en[compassneedscalibration]]
]FIG]

[15] [CODE(DOMi)@en[Window]] [[インターフェイス]]の
[DFN[[CODE(DOMa)@en[ondeviceorientation]]]] [[IDL属性]]は、
[CODE(DOMe)@en[deviceorientation]] [[イベント]]の[[イベントハンドラーIDL属性]]です
[SRC[>>11]]。

[37] [CODE(DOMi)@en[Window]] [[インターフェイス]]の
[DFN[[CODE(DOMa)@en[ondeviceorientationabsolute]]]] [[IDL属性]]は、
[CODE(DOMe)@en[deviceorientationabsolute]] [[イベント]]の[[イベントハンドラーIDL属性]]です
[SRC[>>36]]。

* [CODE(DOMi)@en[DeviceOrientationEvent]] インターフェイス

[17] [DFN[[CODE(DOMi)@en[DeviceOrientationEvent]]]] [[インターフェイス]]は、
[CODE(DOMi)@en[Event]] [[インターフェイス]]を[[継承]]しています。
[[イベント構築子]]を持ちます。
[[文書環境]]に[[晒され]]ています。
[DFN[[CODE(DOMi)@en[DeviceOrientationEventInit]]]] [[辞書]]は、
[CODE(DOMi)@en[EventInit]] [[辞書]]を[[継承]]しています。 [SRC[>>11]]

[18] 両者は、次の[[IDL属性]]/[[辞書メンバー]]を持ちます。
[FIG(short list)[
- [CODE(DOMa)@en[alpha][装置の方向]]
- [CODE(DOMa)@en[beta][装置の方向]]
- [CODE(DOMa)@en[gamma][装置の方向]]
- [CODE(DOMa)@en[absolute][装置の方向]]
]FIG]

* 処理

** イベントの発火

[12] [[DeviceOrientation Event]] に対応する[[利用者エージェント]]は、
[FIG(list)[
- [40] [[装置]]の[RUBYB[方向]@en[orientation]]が変化した時、これを通知しなければ[MUST[なりません]]。
方向が[RUBYB[大きく]@en[significant]]変化した時に通知する[SHOULD[べきです]]。
「大き」いとする基準は[[実装]]依存ですが、1°の変更を最大の[[閾値]]とする[SHOULD[べきです]]。
[SRC[>>11]]
- [41] [[Webページ]]が十分新しいデータを持っていないと判断できるときにも、
通知できます。 [SRC[>>11]]
- [42] 値が得られない場合も、その旨を通知する[SHOULD[べきです]] (>>34) [SRC[>>11, >>36]]。
]FIG]

[14] 頻度と対象となる[VAR[窓]]については、 >>24 を参照。

[38] [DFN[[CODE(DOMe)@en[deviceorientation]]]]、
[DFN[[CODE(DOMe)@en[deviceorientationabsolute]]]] の2つの[[イベント型]]について[[発火]]しなければ[MUST[なりません]] 
[SRC[>>11, >>36]]。

[21] [VAR[窓]]における[VAR[イベント型]]の[[発火]]は次のようにしなければ[MUST[なりません]] [SRC[>>11]]。
[FIG(steps)[
= [22] [VAR[α]]、[VAR[β]]、[VAR[γ]]、[VAR[絶対]]を[VAR[イベント型]]に関する[[装置の方向]]に設定します。
= [13] [[イベントを発火]]します。
[FIG(list members middle)[
: [VAR[[[インターフェイス][イベントインターフェイス]]]] : [CODE(DOMi)@en[DeviceOrientationEvent]]
: [VAR[[[名前][イベント型]]]] : [VAR[イベント型]]
: [VAR[[[対象][イベント対象]]]] : [VAR[窓]]
: [CODE(DOMa)@en[alpha][装置の方向]] : [VAR[α]]
: [CODE(DOMa)@en[beta][装置の方向]] : [VAR[β]]
: [CODE(DOMa)@en[gamma][装置の方向]] : [VAR[γ]]
: [CODE(DOMa)@en[absolute][装置の方向]] : [VAR[絶対]]
]FIG]
]FIG]

[23] [VAR[イベント型]]が [CODE(DOMe)@en[deviceorientation]] か
[CODE(DOMe)@en[deviceorientationabsolute]] かは、[[装置の方向]]の測定に用いる[[装置]]の違い
(によって得られる値の違い) となっています。

** 発火対象と頻度

[24] [CODE[deviceorientation]], [CODE[deviceorientationabsolute]],
[CODE[devicemotion]] の[[イベント]]は、[[利用者エージェント]]の定めた頻度[VAR[間隔]]で、
[[利用者エージェント]]の定めた [CODE(DOMi)@en[Window]] [VAR[窓]]において[[発火]]されます。

[25] 具体的な条件は、なぜか規定されていません。
それを規定しないことには[[相互運用性]]が保てないと思うのですが...

[26] [[仕様書]]は、[[参考]]ながら、 [[fingerprinting]] のリスクの軽減と[[省電力]]のため、
次のようにするのが良いと提示しています [SRC[>>19]]。

[FIG(steps)[
- [27] 見えない裏側にある[[ページ]]にあっては、[[発火]]しない
- [31] 対象となる[VAR[窓]]の決定に当たり、
-- [28] [[最上位閲覧文脈]]およびそれと[[同じ起源]]の[[入れ子閲覧文脈]]のみとする
-- [29] [[secure browsing context]] のみとする
- [30] [VAR[間隔]]の決定に当たり、
-- [32] 普通は 60 [[Hz]] あれば十分
]FIG]

[35] 見えるかどうかと [[Page Visibility]] との関係は明らかではありません。

[33] [[スクリプト]]からは直接観察できませんが、実装上、
[[イベントリスナー]]が登録されている場合のみ測定に必要な[[装置]]を動作させるようにするのが普通と考えられます。

-*-*-

[34] [[Windows]] 版 [[Chrome]] で、おそらく測定できない環境では、
[CODE[deviceorientation]], [CODE[deviceorientationabsolute]]、
[CODE[devicemotion]] とも、
[CODE(DOMm)@en[addEventListener]] した直後に一度[[発火]]されます。
(おそらくその後は[[発火]]されません。)
[CODE[alpha][装置の方向]]、[CODE[beta][装置の方向]]、[CODE[gamma][装置の方向]]
とも [CODE[null]] になります。
どちらの[[イベント型]]でも、 [CODE[absolute][装置の方向]] は[[偽]]になります。
[TIME[2016-11-02T09:50:53.000Z]]

* セキュリティー

[20] [[fingerprinting vector]] と考える人もいます [SRC[>>19]]。

* 歴史

[1] [CITE@en[DeviceOrientation Event Specification]]
( ([TIME[2011-06-28 16:41:24 +09:00]] 版))
<http://www.w3.org/TR/2011/WD-orientation-event-20110628/>

[2] [CITE@en[DeviceOrientation Event Specification]]
( ([TIME[2011-12-01 22:34:51 +09:00]] 版))
<http://www.w3.org/TR/2011/WD-orientation-event-20111201/>

[3] [CITE@en[DeviceOrientation Event Specification]]
( ([TIME[2012-06-14 06:21:37 +09:00]] 版))
<http://dev.w3.org/geo/api/spec-source-orientation.html>

[FIG(quote)[
[FIGCAPTION[
[4] [CITE[Intent to deprecate: Insecure usage of powerful features - Google グループ]]
([TIME[2015-02-28 11:14:59 +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]


[5] [CITE@en[DeviceOrientation Event Specification]]
([TIME[2014-08-28 19:28:23 +09:00]] 版)
<http://w3c.github.io/deviceorientation/spec-source-orientation.html>

[6] [CITE@en[DeviceOrientation: next steps?]]
([[Mandyam, Giridhar]] 著, [TIME[2015-07-07 09:08:51 +09:00]] 版)
<https://lists.w3.org/Archives/Public/public-geolocation/2015Jul/0003.html>

[7] [CITE@en-us[Detecting device orientation - MDC]]
([TIME[2010-01-21 13:30:20 +09:00]] 版)
<https://developer.mozilla.org/en/Detecting_device_orientation>

[8] [CITE@en[DeviceOrientation Event Specification]]
([TIME[2016-08-18 00:27:48 +09:00]])
<https://www.w3.org/TR/2016/CR-orientation-event-20160818/>

[16] [CITE@en[w3c/deviceorientation: W3C Device Orientation spec]]
([TIME[2016-10-30 21:03:22 +09:00]])
<https://github.com/w3c/deviceorientation>

[39] [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>