Skip to content

Commit

Permalink
Compute everything needed for composedPath() during dispatch
Browse files Browse the repository at this point in the history
Fixes #525.
  • Loading branch information
annevk committed Nov 9, 2017
1 parent fb6638f commit 4b422dc
Showing 1 changed file with 76 additions and 30 deletions.
106 changes: 76 additions & 30 deletions dom.bs
Original file line number Diff line number Diff line change
Expand Up @@ -494,10 +494,12 @@ signaling that something has occurred, e.g., that an image has completed downloa
attribute. [[UIEVENTS]]

<p>An <a>event</a> has an associated <dfn export for=Event>path</dfn>. A <a for=Event>path</a> is a
list of tuples, each of which consists of an <b>item</b> (an {{EventTarget}} object), <b>target</b>
(null or an {{EventTarget}} object), and a <b>relatedTarget</b> (null or an {{EventTarget}}
object). A tuple is formatted as (<b>item</b>, <b>target</b>, <b>relatedTarget</b>). A <a
for=Event>path</a> is initially the empty list.</p>
<a for=/>list</a> of <a for=/>structs</a>. Each <a for=/>struct</a> consists of an
<dfn for=Event/path>item</dfn> (an {{EventTarget}} object), <dfn for=Event/path>target</dfn> (null
or an {{EventTarget}} object), a <dfn for=Event/path>relatedTarget</dfn> (null or an
{{EventTarget}} object), <dfn for=Event/path>root-of-closed-tree</dfn> (a boolean), and a
<dfn for=Event/path>slot-in-closed-tree</dfn> (a boolean). A <a for=Event>path</a> is initially the
empty list.</p>

<p><a lt="Other applicable specifications">Specifications</a> may define
<dfn export for=Event>retargeting steps</dfn> for all or some <a>events</a>.
Expand Down Expand Up @@ -526,10 +528,10 @@ algorithm below.
invoked.

<dt><code><var>event</var> . {{Event/composedPath()}}</code>
<dd>Returns the <b>item</b> objects of <var>event</var>'s <a for=Event>path</a> (objects on which
listeners will be invoked), except for any <a>nodes</a> in <a>shadow trees</a> of which the
<a for=/>shadow root</a>'s <a for=ShadowRoot>mode</a> is "<code>closed</code>" that are not
reachable from <var>event</var>'s {{Event/currentTarget}}.
<dd>Returns the <a for=Event/path>item</a> objects of <var>event</var>'s <a for=Event>path</a>
(objects on which listeners will be invoked), except for any <a>nodes</a> in
<a for=/>shadow trees</a> of which the <a for=/>shadow root</a>'s <a for=ShadowRoot>mode</a> is
"<code>closed</code>" that are not reachable from <var>event</var>'s {{Event/currentTarget}}.

<dt><code><var>event</var> . {{Event/eventPhase}}</code>
<dd>Returns the <a>event</a>'s phase, which is one of {{Event/NONE}},
Expand Down Expand Up @@ -597,35 +599,40 @@ initialized to null.
steps:

<ol>
<li><p>Let <var>composedPath</var> be a new empty list.
<li><p>Let <var>reversedComposedPath</var> be an empty <a for=/>list</a>.

<li><p>Let <var>hiddenSubtreeLevel</var> be 0.

<li><p>Let <var>hasSeenCurrentTarget</var> be false.

<li><p>Let <var>currentTarget</var> be <a>context object</a>'s {{Event/currentTarget}}
attribute value.

<li><p>Let <var>reversedPath</var> be <a>context object</a>'s <a for=Event>path</a>, in reverse
order.

<li>
<p>For each <var>tuple</var> in <a>context object</a>'s <a for=Event>path</a>:
<p><a for=list>For each</a> <var>struct</var> in <var>reversedPath</var>:

<ol>
<li>
<p>If <var>currentTarget</var> is a {{Window}} object, then:
<li><p>If <var>struct</var>'s <a for=Event/path>item</a> is <var>currentTarget</var>, then set
<var>hasSeenCurrentTarget</var> to true.

<li><p>Otherwise, if <var>hasSeenCurrentTarget</var> is true and <var>struct</var>'s
<a for=Event/path>root-of-closed-tree</a> is true, then increase <var>hiddenSubtreeLevel</var> by
1.

<ol><li><p>If <var>tuple</var>'s <b>item</b> is not a <a>node</a>, or <var>tuple</var>'s
<b>item</b> is not <a>closed-shadow-hidden</a> from <var>tuple</var>'s <b>item</b>'s
<a>shadow-including root</a>, then append <var>tuple</var>'s <b>item</b> to
<var>composedPath</var>.</p></li></ol>
<li><p>If <var>hiddenSubtreeLevel</var> is 0, then <a for=list>append</a> <var>struct</var>'s
<a for=Event/path>item</a> to <var>reversedComposedPath</var>.

<li><p>Otherwise, if <var>currentTarget</var> is a <a>node</a> and <var>tuple</var>'s <b>item</b>
is not <a>closed-shadow-hidden</a> from <var>currentTarget</var>, or <var>currentTarget</var> is
not a <a>node</a>, then append <var>tuple</var>'s <b>item</b> to <var>composedPath</var>.
<li><p>If <var>struct</var>'s <a for=Event/path>slot-in-closed-tree</a> is true and
<var>hiddenSubtreeLevel</var> is greater than 0, then decrease <var>hiddenSubtreeLevel</var> by
1.
</ol>

<li><p>Return <var>composedPath</var>.
<li><p>Return <var>reversedComposedPath</var>, in reverse order.
</ol>

<p class="note no-backref">This algorithm assumes that when the <var>target</var> argument to the
<a>dispatch</a> algorithm is not a <a>node</a>, none of the tuples in <var>event</var> argument's
eventual <a for=Event>path</a> will contain a <a>node</a> either.

The <dfn attribute for=Event><code>eventPhase</code></dfn>
attribute must return the value it was initialized to, which must be one of
the following:
Expand Down Expand Up @@ -1151,22 +1158,42 @@ for discussion).
<li><p>If <var>target</var> is <var>relatedTarget</var> and <var>target</var> is not
<var>event</var>'s <a>relatedTarget</a>, then return true.

<li><p>Append (<var>target</var>, <var>targetOverride</var>, <var>relatedTarget</var>) to
<var>event</var>'s <a for=Event>path</a>.
<li><p><a>Append to an event path</a> with <var>event</var>, <var>target</var>,
<var>targetOverride</var>, <var>relatedTarget</var>, and false.

<li><p>Let <var>isActivationEvent</var> be true, if <var>event</var> is a {{MouseEvent}} object and
<var>event</var>'s {{Event/type}} attribute is "<code>click</code>", and false otherwise.

<li><p>Let <var>activationTarget</var> be <var>target</var>, if <var>isActivationEvent</var> is
true and <var>target</var> has <a for=EventTarget>activation behavior</a>, and null otherwise.

<li><p>Let <var>slotable</var> be null.

<li><p>Let <var>slot-in-closed-tree</var> be false.

<li><p>Let <var>parent</var> be the result of invoking <var>target</var>'s <a>get the parent</a>
with <var>event</var>.

<li>
<p>While <var>parent</var> is non-null:</p>

<ol>
<li>
<p>If <var>slotable</var> is non-null:

<ol>
<li><p>Assert: <var>parent</var> is a <a for=/>slot</a>.

<li><p>Set <var>slotable</var> to null.

<li><p>If <var>parent</var>'s <a for=tree>root</a> is a <a for=/>shadow root</a> whose
<a for=ShadowRoot>mode</a> is "<code>closed</code>", then set <var>slot-in-closed-tree</var> to
true.
</ol>

<li><p>If <var>parent</var> is <a for=slotable>assigned</a>, then set <var>slotable</var> to
<var>parent</var>.

<li><p>Let <var>relatedTarget</var> be the result of <a>retargeting</a> <var>event</var>'s
<a>relatedTarget</a> against <var>parent</var> if <var>event</var>'s <a>relatedTarget</a> is
non-null, and null otherwise.
Expand All @@ -1181,8 +1208,8 @@ for discussion).
<a for=EventTarget>activation behavior</a>, then set <var>activationTarget</var> to
<var>parent</var>.

<li><p>Append (<var>parent</var>, null, <var>relatedTarget</var>) to <var>event</var>'s
<a for=Event>path</a>.
<li><p><a>Append to an event path</a> with <var>event</var>, <var>parent</var>, null,
<var>relatedTarget</var>, and <var>slot-in-closed-tree</var>.
</ol>

<li><p>Otherwise, if <var>parent</var> and <var>relatedTarget</var> are identical, then set
Expand All @@ -1196,12 +1223,14 @@ for discussion).
<var>target</var> has <a for=EventTarget>activation behavior</a>, then set
<var>activationTarget</var> to <var>target</var>.

<li><p>Append (<var>parent</var>, <var>target</var>, <var>relatedTarget</var>) to
<var>event</var>'s <a for=Event>path</a>.
<li><p><a>Append to an event path</a> with <var>event</var>, <var>parent</var>,
<var>target</var>, <var>relatedTarget</var>, and <var>slot-in-closed-tree</var>.
</ol>

<li><p>If <var>parent</var> is non-null, then set <var>parent</var> to the result of invoking
<var>parent</var>'s <a>get the parent</a> with <var>event</var>.

<li><p>Set <var><var>slot-in-closed-tree</var> to false.
</ol>

<li><p>Set <var>event</var>'s {{Event/eventPhase}} attribute to {{Event/CAPTURING_PHASE}}.
Expand Down Expand Up @@ -1277,6 +1306,23 @@ for discussion).
<li><p>Return false if <var>event</var>'s <a>canceled flag</a> is set, and true otherwise.
</ol>

<p>To <dfn noexport id=concept-event-path-append>append to an event path</dfn>, given an
<var>event</var>, <var>target</var>, <var>targetOverride</var>, <var>relatedTarget</var>, and a
<var>slot-in-closed-tree</var>, run these steps:</p>

<ol>
<li><p>Let <var>root-of-closed-tree</var> be false.

<li><p>If <var>target</var> is a <a for=/>shadow root</a> whose <a for=ShadowRoot>mode</a> is
"<code>closed</code>", then set <var>root-of-closed-tree</var> to true.

<li><p><a for=list>Append</a> a new <a for=/>struct</a> to <var>event</var>'s <a for=Event>path</a>
whose <a for=Event/path>item</a> is <var>target</var>, <a for=Event/path>target</a> is
<var>targetOverride</var>, <a for=Event/path>relatedTarget</a> is <var>relatedTarget</var>,
<a for=Event/path>root-of-closed-tree</a> is <var>root-of-closed-tree</var>, and
<a for=Event/path>slot-in-closed-tree</a> is <var>slot-in-closed-tree</var>.
</ol>

<p>To <dfn noexport id=concept-event-listener-invoke>invoke</dfn> an <var>object</var> with
<var>event</var> and an optional <var>legacyOutputDidListenersThrowFlag</var>, run these steps:

Expand Down

0 comments on commit 4b422dc

Please sign in to comment.