[10] [[DOMイベント]]は[[木構造]]に対して定義されていますが、
実際に[[木]]として使われるのは[[節点木]]
([CODE(DOMi)@en[[[Document]]]] や [CODE(DOMi)@en[[[Element]]]] の[[木]]) だけで、
それ以外のほとんどは単一の[[オブジェクト]]です。

* 仕様書

[REFS[
- [19] '''[CITE@en[DOM Standard]] ([TIME[2016-02-18 20:04:25 +09:00]] 版) <https://dom.spec.whatwg.org/#get-the-parent>'''
- [21] [CITE@en[DOM Standard]] ([TIME[2016-07-05 18:22:22 +09:00]]) <https://dom.spec.whatwg.org/#event-path>
- [46] [CITE@en[DOM Standard]] ([TIME[2016-07-05 18:22:22 +09:00]]) <https://dom.spec.whatwg.org/#dispatching-events>
- [22] [CITE@en[DOM Standard]] ([TIME[2016-02-18 20:04:25 +09:00]] 版) <https://dom.spec.whatwg.org/#node>
- [24] [CITE@en[DOM Standard]] ([TIME[2016-02-18 20:04:25 +09:00]] 版) <https://dom.spec.whatwg.org/#document>
- [39] [CITE@en[DOM Standard]] ([TIME[2016-07-05 18:22:22 +09:00]]) <https://dom.spec.whatwg.org/#concept-shadow-root>
]REFS]

* 親の取得

[16] [CODE(DOMi)@en[[[EventTarget]]]] は、
[[イベント]][VAR[イベント]]を[[引数]]とする[DFN[[RUBYB[親の取得]@en[get the parent]]]][[アルゴリズム]]を持ちます
[SRC[>>19]]。
[VAR[イベント対象]]の[[親の取得]]は、[VAR[イベント対象]]により、次のようにします。

[FIG(switch)[
: [[文書]] : [SRC[>>24]]
[FIG(steps)[
= [26] [VAR[イベント]]の[F[[[型]]]]が [CODE[[[load]]]] か、
[VAR[イベント対象]]の[F[閲覧文脈]]が [[null]] なら、
== [27] [[null]] を返します。
= [28] それ以外なら、
== [29] [VAR[イベント対象]]の[F[[CODE(DOMi)@en[[[Window]]]]]]を返します。
]FIG]
: [[影根]] : [SRC[>>39]]
[FIG(steps)[
= [40] [VAR[イベント]]の[F[合成フラグ]]が[[偽]]なら、
== [41] [[null]] を返します。
= [42] それ以外なら、
== [43] [VAR[イベント対象]]の[F[ホスト][影ホスト]]を返します。
]FIG]
: [[要素]]、[[テキスト]] : [SRC[>>22]]
[FIG(steps)[
= [34] [VAR[イベント対象]]が[F[割り当て済み]]なら、
== [35] [VAR[イベント対象]]の[F[割り当て済みスロット]]を返します。
= [36] それ以外なら、
== [37] [VAR[イベント対象]]の[F[親][parentNode]]を返します。
]FIG]
: [[文書型]]、[[注釈]]、[[処理指令]] : 
[VAR[イベント対象]]の[F[親][parentNode]]を返します [SRC[>>22]]。
: それ以外 : [[null]] を返します [SRC[>>19]]。
]FIG]

[30] [[親の取得]]は、[[dispatch]] で参照されます。

* 木をまたぐイベントの伝播

[4] [[木]]構造を超えた[[イベント]]の伝播には次のものがあります。
[FIG(list)[
- [5] [CODE(DOMi)@en[[[Document]]]] -> [CODE(DOMi)@en[[[Window]]]] [SRC[>>8]]
- [38] [[割り当て済み節点]] -> [[スロット]]
- [7] [[影根]] -> [[影ホスト]]
-- [CODE(DOMa)@en[composed]] === [CODE(IDL)@en[false]] の場合
- [6] [DEL[[CODE(HTMLe)@en[[[iframe]]]] [CODE(HTMLa)@en[[[seamless]]]] 境界 [SRC[>>11]]]]
-- [[子閲覧文脈]]の [CODE(DOMi)@en[[[Window]]]] の[[親]]が [CODE(DOMi)@en[[[iframe]]]]
]FIG]

* イベント経路

[23] [[イベントオブジェクト]]は、[DFN[[F[[RUBYB[経路]@en[path]]][イベント経路]]]]を持ちます [SRC[>>22]]。

[44] [[仕様書]]の規定は若干わかりにくい形になっています。次の説明は、少し違う
(が等価な) 形です。

[25] [F[経路][イベント経路]]の初期値は、空です [SRC[>>22]]。

[45] [F[経路][イベント経路]]は [[dispatch]] で設定されます。
[[dispatch]] 自体の他、 [CODE(DOMm)@en[composedPath]] でも参照されます。
[[仕様書]]上は[[影根]]の[F[親の取得]]でも参照されます。

[47] [F[経路][イベント経路]]は、 [[dispatch]] 
の最初で[VAR[イベント]]と[VAR[対象]]と[VAR[遺物[[対象上書き]]フラグ]]を使って次のように構築されます [SRC[>>46]]。

[FIG(steps)[
= [77] [VAR[イベント経路]]を、[[空リスト]]に設定します。
= [52] [VAR[オブジェクト]]を、[VAR[対象]]に設定します。
= [58] [VAR[遺物[[対象上書き]]フラグ]]が設定されていれば、
== [60] [VAR[相対対象]]を、[VAR[対象]]の[F[文書]]に設定します。
= [59] それ以外なら、
== [50] [VAR[相対対象]]を、[VAR[対象]]に設定します。
= [75] [VAR[イベント]]の[VAR[オブジェクト]]における[[関連対象]]が[VAR[オブジェクト]]で、
[VAR[イベント]]の[F[関連対象]]が[VAR[オブジェクト]]でないなら、
== [76] ([VAR[イベント経路]], [CODE[null]]) を返し、ここで停止します。
= [111] [VAR[活性化イベントである]]を、[VAR[イベント]]が [CODE(DOMi)@en[MouseEvent]]
かつ[VAR[イベント]]の[F[型][イベント型]]が [CODE[click]] である、に設定します。
= [112] [VAR[活性化対象]]を、[VAR[活性化イベントである]]かつ[VAR[オブジェクト]]の[F[活性化動作]]が
[CODE[null]] でないなら[VAR[オブジェクト]]、それ以外なら [CODE[null]] に設定します。
= [73] 繰り返し、
== [53] [VAR[イベント経路]]に、新しい項目を追加します。
[FIG(list members)[
: [F[現在対象]] : [VAR[オブジェクト]]
: [F[対象][イベント対象]] : [VAR[相対対象]]
: [F[関連対象]] : [VAR[イベント]]の[VAR[オブジェクト]]における[[関連対象]]
]FIG]
== [54] [VAR[親]]を、[VAR[オブジェクト]]の[F[親の取得]]を[VAR[イベント]]について実行した結果に設定します。
== [49] [VAR[親]]が [CODE[null]] でなら、
=== [74] ([VAR[イベント経路]], [VAR[活性化対象]]) を返し、ここで停止します。
== [56] [VAR[オブジェクト]]と[VAR[親]]が違う[[木]]に属するなら、
=== [57] [VAR[相対対象]]を、[VAR[親]]に設定します。
=== [79] [VAR[親]]と[VAR[イベント]]の[VAR[親]]における[[関連対象]]が等しいなら、
==== [80] ([VAR[イベント経路]], [VAR[活性化対象]]) を返し、ここで停止します。
=== [81] [VAR[活性化対象]]が [CODE[null]] で、[VAR[活性化イベントである]]かつ[VAR[親]]の[F[活性化動作]]が [CODE[null]] でないなら、
==== [82] [VAR[活性化対象]]を、[VAR[親]]に設定します。
== [83] それ以外の場合、
=== [84] [VAR[活性化対象]]が [CODE[null]] で、[VAR[活性化イベントである]]かつ[VAR[親]]の[F[活性化動作]]が [CODE[null]] でなく、
[VAR[イベント]]の [F[bubbles]] が[[真]]なら、
==== [85] [VAR[活性化対象]]を、[VAR[親]]に設定します。
== [55] [VAR[オブジェクト]]を、[VAR[親]]に設定します。
]FIG]

[51] ここで、[VAR[イベント]]の[VAR[オブジェクト]]における[[関連対象]]とは、
[FIG(switch)[
: [VAR[イベント]]の[F[関連対象]]が [CODE[null]] : [CODE[null]]
: それ以外 :
[VAR[イベント]]の[F[関連対象]]を[VAR[オブジェクト]]について[[再対象付け]]した結果
]FIG]
... をいいます。


[48] [F[イベント経路]]は、 [[dispatch]] の最後で空に戻されます [SRC[>>46]]。

[64] [VAR[節点]]を[VAR[基準点]]について[DFN[[RUBYB[再対象付け]@en[retarget]]]]した結果とは、
[VAR[節点]]と[VAR[基準点]]が同じ[[木]]に属するか、
[VAR[基準点]]が[[影木]]に属する (など[[影を含む子孫]]である) ならば[VAR[節点]]、
そうでないなら[VAR[節点]]の[F[根]]の[F[影ホスト]]を[VAR[基準点]]について[[再対象付け]]したものです [SRC[>>46]]。

[86] これは [CODE(DOMa)@en[pointerLockElement]] から参照されています。

@@
[66] [DFN[retargeting steps]] [SRC[>>46]]

* 歴史

[17] [[dispatch]] において [CODE(DOMi)@en[[[Window]]]] は [CODE(DOMi)@en[[[Document]]]]
の[[親]]として (ほとんどの場合に) 動作するよう昔から実装されていましたが、
[[HTML5]] まで明文化されていませんでした。

[REFS[
-[1] [CITE@en[Bug 18780 – Fix event dispatching for shadow DOM and <iframe seamless>]]
( ([TIME[2013-05-05 14:48:07 +09:00]] 版))
<https://www.w3.org/Bugs/Public/show_bug.cgi?id=18780>
-[2] [CITE[IRC logs: freenode / #whatwg / 20121204]]
( ([TIME[2013-05-05 14:48:23 +09:00]] 版))
<http://krijnhoetmer.nl/irc-logs/whatwg/20121204#l-1477>
- [11] [CITE@en-GB-x-hixie[HTML Standard]] ([TIME[2015-05-06 10:42:35 +09:00]] 版) <https://html.spec.whatwg.org/#attr-iframe-seamless>
- [8] [CITE@en-US-x-hixie[HTML Standard]] ([TIME[2013-05-05 06:42:10 +09:00]] 版) <http://www.whatwg.org/specs/web-apps/current-work/#events-and-the-window-object>
]REFS]

[18] [[DOM Standard]] によって[[イベント]]の仕様が再整備されたことで、
[[HTML Standard]] もそれに基づく規定に切り替えられました。

[3] >>1 により [[HTML Standard]] は [[DOM Standard]] より [[event parent]] と
[[cross-boundary event parent]] を引用していますが、現時点で [[DOM Standard]]
に両者の定義はありません。 [TIME[2013-05-05T14:50:19.700Z]]

[HISTORY[
[9] [[閲覧文脈]]中にある [CODE(DOMi)@en[[[Document]]]] に属する[[節点]]において[[イベント]]が[[ディスパッチ]]される時、
[[イベント型]]が [CODE(DOMe)@en[[[load]]]] である時を除き、
[CODE(DOMi)@en[[[Window]]]] が [CODE(DOMi)@en[[[Document]]]] の[[親]]であるように振舞わなければ[['''なりません''']]
[SRC[>>8]]。
]HISTORY]

[13] [CODE(HTMLa)@en[[[seamless]]]] は実装されなかったため2016年2月に削除されました。

[REFS[
- [12] [CITE@en[Remove <iframe seamless> · whatwg/html@1490eba]]
([TIME[2016-02-04 19:17:43 +09:00]] 版)
<https://github.com/whatwg/html/commit/1490eba4dba5ab476f0981443a86c01acae01311>
]REFS]

[20] 2016年2月には[[イベント親]]は[[親の取得]]という形に再編されて、
[[DOM Standard]] に規定が集約されました。

[REFS[
- [14] [CITE@en[Integrate HTML's monkey patch to the event path · whatwg/dom@2d7b637]] ([TIME[2016-02-19 18:05:29 +09:00]] 版) <https://github.com/whatwg/dom/commit/2d7b637b31fc6bad8f6c4743fb61016392fac382>
- [15] [CITE@en[Remove event path monkey patch · whatwg/html@dad854e]] ([TIME[2016-02-19 18:05:36 +09:00]] 版) <https://github.com/whatwg/html/commit/dad854e4c1f5f7098a1b1ec7f33e2218796f7442>
]REFS]

[31] [CITE@en[''''''[''''''Fix #429'''''']'''''' Integrate "get the parent" model for an event path · w3c/webcomponents@0457494]]
([TIME[2016-03-11 15:38:08 +09:00]] 版)
<https://github.com/w3c/webcomponents/commit/0457494032c6668291319df843a7a62faca214c5>

[32] [CITE@en[Fix #486: Fix 'get the parent' for relatedTarget]]
( ([[hayatoito]]著, [TIME[2016-06-01 14:53:00 +09:00]]))
<https://github.com/w3c/webcomponents/commit/b1433e5f3a013ca825f02fb8f7b0e9d6217c0125>

[33] [CITE@en['''['''''']''' (0) Make the Window object support events]]
( ([[Hixie]]著, [TIME[2007-04-21 11:41:48 +09:00]]))
<https://github.com/whatwg/html/commit/16d81185f31b98ef752e036fce228199a1e8502c>

[61] [CITE@en[Shadow: define event retargeting for shadow trees]]
([[annevk]]著, [TIME[2016-04-29 21:04:07 +09:00]])
<https://github.com/whatwg/dom/commit/ed94c9f2f1850b2e6a9b357c6870186859da4c2d>

[62] [CITE@en[Shadow: define Event's composedPath()]]
([[annevk]]著, [TIME[2016-05-12 18:40:32 +09:00]])
<https://github.com/whatwg/dom/commit/58b19e4aa89ab0c6ef998daa455dcbb189423cf8>

[63] [CITE@en[Shadow: define event's relatedTarget handling]]
([[hayatoito]]著, [TIME[2016-07-22 16:39:19 +09:00]])
<https://github.com/whatwg/dom/commit/ef69a247681532e6102ced9a78aabf7f7a536108>

[65] [CITE@en[Shadow: add "retargeting steps" to the dispatch algorithm]]
([[hayatoito]]著, [TIME[2016-08-04 18:36:08 +09:00]])
<https://github.com/whatwg/dom/commit/fbc0c312c3ead6940718e3d2d7511f2b014011e1>

[67] [CITE@en[Use the definition of "retargeting" from the DOM spec. (#8)]]
([[TakayoshiKochi]]著, [TIME[2016-08-31 09:30:15 +09:00]])
<https://github.com/w3c/pointerlock/commit/03f09d37d45c33ac766c3cbe99fc8e199c64347e>

[68] [CITE@en[Editorial: drop "invoking" from "invoking retargeting"]]
([[TakayoshiKochi]]著, [TIME[2016-08-30 13:44:16 +09:00]])
<https://github.com/whatwg/dom/commit/de60f841360f5995be0b49eebe7cda1c32275be8>

[69] [CITE@en[Add TouchEvent's retargeting steps (#73)]]
([[hayatoito]]著, [TIME[2016-09-02 22:42:20 +09:00]])
<https://github.com/w3c/touch-events/commit/eeed53b305bc1c1fa35f7280aef342f16ebb230c>

[70] [CITE@en[Shadow: adjust composedPath() when currentTarget is a Window object]]
([[hayatoito]]著, [TIME[2016-09-14 13:43:55 +09:00]])
<https://github.com/whatwg/dom/commit/2153769e1ecf55f2d202fd5c6f996023b34545e5>

[71] [CITE@en[Redesign fire an event and target override]]
([[annevk]]著, [TIME[2016-10-15 00:32:41 +09:00]])
<https://github.com/whatwg/dom/commit/e19d7eef74fb83792415a4a78ed866d28f4cc543>

[72] [CITE@en[Shadow: do not dispatch an event when target is reletedTarget]]
([[hayatoito]]著, [TIME[2016-10-18 15:15:38 +09:00]])
<https://github.com/whatwg/dom/commit/afac5044c18fa871837b0a86d21f338b29f7a292>

[78] [CITE@en[Define special dispatch behavior for click events]]
([[annevk]]著, [TIME[2016-10-18 01:55:28 +09:00]])
<https://github.com/whatwg/dom/commit/cb12fd4e2db68a9d86841a13a73611e16f9f1fb4>

[87] [CITE@en[Allow constructing and subclassing EventTarget]]
([[domenic]]著, [TIME[2017-07-08 03:55:17 +09:00]])
<https://github.com/whatwg/dom/commit/c4c1c8b47340a1e5ecc1a07670927b831f240586>

[88] [CITE@en[Note retargeting usage in Fullscreen]]
([[annevk]]著, [TIME[2018-04-09 23:02:32 +09:00]])
<https://github.com/whatwg/dom/commit/7a771ad2bd086b2938340085333b6960226a27ca>

[89] [CITE@en[Consider moving "retargeting" to the dispatch section · Issue #620 · whatwg/dom]]
([TIME[2018-04-11 12:08:07 +09:00]])
<https://github.com/whatwg/dom/issues/620>

[90] [CITE@en[Note retargeting usage in Fullscreen by annevk · Pull Request #630 · whatwg/dom]]
([TIME[2018-04-11 12:08:12 +09:00]])
<https://github.com/whatwg/dom/pull/630>

[91] [CITE@en[Standardize window.event]]
([[miketaylr]]著, [TIME[2018-06-07 17:15:23 +09:00]])
<https://github.com/whatwg/dom/commit/c69d7c0fb8796de884652c517825122d12901ef5>

[92] [CITE@en[Avoid setting target to the Window object]]
([[annevk]]著, [TIME[2018-09-17 18:30:53 +09:00]])
<https://github.com/whatwg/dom/commit/0b04ae848b27f9eaf6f0bd17ecaff0bd7f833068>

[93] [CITE@en[Dispatch event always set the event.target to the global object after dispatch · Issue #697 · whatwg/dom]]
([TIME[2018-10-22 01:13:42 +09:00]])
<https://github.com/whatwg/dom/issues/697>

[94] [CITE@en[Avoid setting target to the Window object by annevk · Pull Request #698 · whatwg/dom]]
([TIME[2018-10-22 01:14:03 +09:00]])
<https://github.com/whatwg/dom/pull/698>