Skip to content

Commit e19d7ee

Browse files
authored
Redesign fire an event and target override
Fixes #187. Follow up work in HTML is tracked in whatwg/html#1713.
1 parent eb28710 commit e19d7ee

File tree

2 files changed

+91
-36
lines changed

2 files changed

+91
-36
lines changed

dom.bs

Lines changed: 51 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1184,18 +1184,18 @@ for discussion).
11841184
<h3 id=dispatching-events>Dispatching events</h3>
11851185

11861186
<p>To <dfn export for=Event id=concept-event-dispatch>dispatch</dfn> an <var>event</var> to a
1187-
<var>target</var>, with an optional <var>targetOverride</var>, run these steps:
1187+
<var>target</var>, with an optional <var>legacy target override flag</var>, run these steps:
11881188

11891189
<ol>
11901190
<li><p>Set <var>event</var>'s <a>dispatch flag</a>.
11911191

11921192
<li>
1193-
<p>If <var>targetOverride</var> is not given, let <var>targetOverride</var> be <var>target</var>.
1193+
<p>Let <var>targetOverride</var> be <var>target</var>, if <var>legacy target override flag</var>
1194+
is not given, and <var>target</var>'s <a>associated <code>Document</code></a> otherwise.
1195+
[[!HTML]]
11941196

1195-
<p class="note">The <var>targetOverride</var> argument is only used by HTML and only under very
1196-
specific circumstances.
1197-
<!-- We should consider refactoring it to make it have less of a scope, since we don't really want
1198-
folks to start using it for non-legacy scenarios. -->
1197+
<p class="note"><var>legacy target override flag</var> is only used by HTML and only when
1198+
<var>target</var> is a {{Window}} object.
11991199

12001200
<li>Let <var>relatedTarget</var> be the result of <a>retargeting</a> <var>event</var>'s
12011201
<a>relatedTarget</a> against <var>target</var> if <var>event</var>'s <a>relatedTarget</a> is
@@ -1377,25 +1377,53 @@ an <var>object</var> with <var>event</var>, run these steps:
13771377
<li><p>Return <var>found</var>.
13781378
</ol>
13791379

1380+
13801381
<h3 id=firing-events>Firing events</h3>
13811382

1382-
To
1383-
<dfn export id=concept-event-fire lt="fire an event">fire an event named <var>e</var></dfn>
1384-
means that a new <a>event</a> using the
1385-
{{Event}} interface, with its
1386-
{{Event/type}} attribute initialized to
1387-
<var>e</var>, and its {{Event/isTrusted}}
1388-
attribute initialized to <code>true</code>, is to be
1389-
<a>dispatched</a> to the given object.
1390-
1391-
<p class="note no-backref">Fire in the context of DOM is short for creating, initializing,
1392-
and <a>dispatching</a> an <a>event</a>.
1393-
<a>Fire an event</a> makes that process easier to write
1394-
down. If the <a>event</a> needs its {{Event/bubbles}} or
1395-
{{Event/cancelable}} attribute initialized, one could write
1396-
"<a>fire an event</a> named
1397-
<code>submit</code> with its {{Event/cancelable}} attribute
1398-
initialized to true".
1383+
<p>To <dfn export id=concept-event-fire>fire an event</dfn> named <var>e</var> at <var>target</var>,
1384+
optionally using an <var>eventConstructor</var>, with a description of how IDL attributes are to be
1385+
initialized, and a <var>legacy target override flag</var>, run these steps:
1386+
1387+
<ol>
1388+
<li><p>If <var>eventConstructor</var> is not given, then let <var>eventConstructor</var> be
1389+
{{Event}}.
1390+
1391+
<li><p>Let <var>event</var> be the result of <a for=Event lt=constructor>invoking</a> the initial
1392+
value of <var>eventConstructor</var> with the argument <var>e</var>.
1393+
1394+
<li><p>Initialize <var>event</var>'s {{Event/isTrusted}} attribute to true.
1395+
1396+
<li>
1397+
<p>Initialize any other IDL attributes of <var>event</var> as described in the invocation of this
1398+
algorithm.
1399+
1400+
<p class="note">This also allows for the {{Event/isTrusted}} attribute to be set to false.
1401+
1402+
<li><p>Return the result of <a>dispatching</a> <var>event</var> at <var>target</var>, with
1403+
<var>legacy target override flag</var> set if set.
1404+
</ol>
1405+
1406+
<p class="note no-backref">Fire in the context of DOM is short for creating, initializing, and
1407+
<a>dispatching</a> an <a>event</a>. <a>Fire an event</a> makes that process easier to write down.
1408+
1409+
<div class="example no-backref" id=firing-events-example>
1410+
<p>If the <a>event</a> needs its {{Event/bubbles}} or {{Event/cancelable}} attribute initialized,
1411+
one could write "<a>fire an event</a> named <code>submit</code> at <var>target</var> with its
1412+
{{Event/cancelable}} attribute initialized to true".
1413+
1414+
<p>Or, when a custom constructor is required, "<a>fire an event</a> named <code>click</code> at
1415+
<var>target</var> using {{MouseEvent}} with its {{Event/isTrusted}} attribute initialized to
1416+
false".
1417+
1418+
<p>Ocassionally the return value is important:
1419+
1420+
<ol>
1421+
<li><p>Let <var>doAction</var> be the result of <a lt="fire an event">firing an event</a> named
1422+
<code>like</code> at <var>target</var>.
1423+
1424+
<li><p>If <var>doAction</var> is true, then &hellip;
1425+
</ol>
1426+
</div>
13991427

14001428

14011429
<h3 id=action-versus-occurance>Action versus occurrence</h3>

dom.html

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
<p data-fill-with="logo"><a class="logo" href="https://whatwg.org/"> <img alt="WHATWG" height="100" src="https://resources.whatwg.org/logo-dom.svg"> </a> </p>
7272
<hgroup>
7373
<h1 class="p-name no-ref allcaps" id="title">DOM</h1>
74-
<h2 class="no-num no-toc no-ref heading settled" id="subtitle"><span class="content">Living Standard — Last Updated <time class="dt-updated" datetime="2016-10-11">11 October 2016</time></span></h2>
74+
<h2 class="no-num no-toc no-ref heading settled" id="subtitle"><span class="content">Living Standard — Last Updated <time class="dt-updated" datetime="2016-10-14">14 October 2016</time></span></h2>
7575
</hgroup>
7676
<div data-fill-with="spec-metadata">
7777
<dl>
@@ -871,14 +871,13 @@ <h3 class="heading settled" data-level="3.7" id="observing-event-listeners"><spa
871871
of non-<code class="idl"><a data-link-type="idl" href="#dom-addeventlisteneroptions-passive">passive</a></code> listeners, and use that to clear the <code class="idl"><a data-link-type="idl" href="#dom-event-cancelable">cancelable</a></code> property of the event being dispatched. </p>
872872
<p>Ideally, any new event APIs are defined such that they do not need this property (use <a href="https://lists.w3.org/Archives/Public/public-script-coord/">[email protected]</a> for discussion). </p>
873873
<h3 class="heading settled" data-level="3.8" id="dispatching-events"><span class="secno">3.8. </span><span class="content">Dispatching events</span><a class="self-link" href="#dispatching-events"></a></h3>
874-
<p>To <dfn data-dfn-for="Event" data-dfn-type="dfn" data-export="" id="concept-event-dispatch">dispatch<a class="self-link" href="#concept-event-dispatch"></a></dfn> an <var>event</var> to a <var>target</var>, with an optional <var>targetOverride</var>, run these steps: </p>
874+
<p>To <dfn data-dfn-for="Event" data-dfn-type="dfn" data-export="" id="concept-event-dispatch">dispatch<a class="self-link" href="#concept-event-dispatch"></a></dfn> an <var>event</var> to a <var>target</var>, with an optional <var>legacy target override flag</var>, run these steps: </p>
875875
<ol>
876876
<li>
877877
<p>Set <var>event</var>’s <a data-link-type="dfn" href="#dispatch-flag">dispatch flag</a>. </p>
878878
<li>
879-
<p>If <var>targetOverride</var> is not given, let <var>targetOverride</var> be <var>target</var>. </p>
880-
<p class="note" role="note">The <var>targetOverride</var> argument is only used by HTML and only under very
881-
specific circumstances. </p>
879+
<p>Let <var>targetOverride</var> be <var>target</var>, if <var>legacy target override flag</var> is not given, and <var>target</var>’s <a data-link-type="dfn" href="https://html.spec.whatwg.org/multipage/browsers.html#concept-document-window">associated <code>Document</code></a> otherwise. <a data-link-type="biblio" href="#biblio-html">[HTML]</a> </p>
880+
<p class="note" role="note"><var>legacy target override flag</var> is only used by HTML and only when <var>target</var> is a <code class="idl"><a data-link-type="idl" href="https://html.spec.whatwg.org/multipage/browsers.html#window">Window</a></code> object. </p>
882881
<li>Let <var>relatedTarget</var> be the result of <a data-link-type="dfn" href="#retarget">retargeting</a> <var>event</var>’s <a data-link-type="dfn" href="#event-relatedtarget">relatedTarget</a> against <var>target</var> if <var>event</var>’s <a data-link-type="dfn" href="#event-relatedtarget">relatedTarget</a> is
883882
non-null, and null otherwise.
884883
<li>
@@ -1015,7 +1014,7 @@ <h3 class="heading settled" data-level="3.8" id="dispatching-events"><span class
10151014
<li>
10161015
<p>If <var>listener</var>’s <b>passive</b> is true, set <var>event</var>’s <a data-link-type="dfn" href="#in-passive-listener-flag">in passive listener flag</a>. </p>
10171016
<li>
1018-
<p><a data-link-type="dfn">Call a user object’s operation</a> with <var>listener</var>’s <b>callback</b>,
1017+
<p><a data-link-type="dfn" href="https://heycam.github.io/webidl/#call-a-user-objects-operation">Call a user object’s operation</a> with <var>listener</var>’s <b>callback</b>,
10191018
"<code>handleEvent</code>", a list of arguments consisting of <var>event</var>, and <var>event</var>’s <code class="idl"><a data-link-type="idl" href="#dom-event-currenttarget">currentTarget</a></code> attribute value as the <a data-link-type="dfn" href="https://heycam.github.io/webidl/#dfn-callback-this-value">callback this value</a>. If
10201019
this throws an exception, <a data-link-type="dfn" href="https://html.spec.whatwg.org/multipage/webappapis.html#report-the-exception">report the exception</a>. </p>
10211020
<li>
@@ -1028,12 +1027,39 @@ <h3 class="heading settled" data-level="3.8" id="dispatching-events"><span class
10281027
<p>Return <var>found</var>. </p>
10291028
</ol>
10301029
<h3 class="heading settled" data-level="3.9" id="firing-events"><span class="secno">3.9. </span><span class="content">Firing events</span><a class="self-link" href="#firing-events"></a></h3>
1031-
<p>To <dfn data-dfn-type="dfn" data-export="" data-lt="fire an event" id="concept-event-fire">fire an event named <var>e</var><a class="self-link" href="#concept-event-fire"></a></dfn> means that a new <a data-link-type="dfn" href="#concept-event">event</a> using the <code class="idl"><a data-link-type="idl" href="#event">Event</a></code> interface, with its <code class="idl"><a data-link-type="idl" href="#dom-event-type">type</a></code> attribute initialized to <var>e</var>, and its <code class="idl"><a data-link-type="idl" href="#dom-event-istrusted">isTrusted</a></code> attribute initialized to <code>true</code>, is to be <a data-link-type="dfn" href="#concept-event-dispatch">dispatched</a> to the given object.</p>
1032-
<p class="note no-backref" role="note">Fire in the context of DOM is short for creating, initializing,
1033-
and <a data-link-type="dfn" href="#concept-event-dispatch">dispatching</a> an <a data-link-type="dfn" href="#concept-event">event</a>. <a data-link-type="dfn" href="#concept-event-fire">Fire an event</a> makes that process easier to write
1034-
down. If the <a data-link-type="dfn" href="#concept-event">event</a> needs its <code class="idl"><a data-link-type="idl" href="#dom-event-bubbles">bubbles</a></code> or <code class="idl"><a data-link-type="idl" href="#dom-event-cancelable">cancelable</a></code> attribute initialized, one could write
1035-
"<a data-link-type="dfn" href="#concept-event-fire">fire an event</a> named <code>submit</code> with its <code class="idl"><a data-link-type="idl" href="#dom-event-cancelable">cancelable</a></code> attribute
1036-
initialized to true". </p>
1030+
<p>To <dfn data-dfn-type="dfn" data-export="" id="concept-event-fire">fire an event<a class="self-link" href="#concept-event-fire"></a></dfn> named <var>e</var> at <var>target</var>,
1031+
optionally using an <var>eventConstructor</var>, with a description of how IDL attributes are to be
1032+
initialized, and a <var>legacy target override flag</var>, run these steps: </p>
1033+
<ol>
1034+
<li>
1035+
<p>If <var>eventConstructor</var> is not given, then let <var>eventConstructor</var> be <code class="idl"><a data-link-type="idl" href="#event">Event</a></code>. </p>
1036+
<li>
1037+
<p>Let <var>event</var> be the result of <a data-link-type="dfn" href="#concept-event-constructor">invoking</a> the initial
1038+
value of <var>eventConstructor</var> with the argument <var>e</var>. </p>
1039+
<li>
1040+
<p>Initialize <var>event</var>’s <code class="idl"><a data-link-type="idl" href="#dom-event-istrusted">isTrusted</a></code> attribute to true. </p>
1041+
<li>
1042+
<p>Initialize any other IDL attributes of <var>event</var> as described in the invocation of this
1043+
algorithm. </p>
1044+
<p class="note" role="note">This also allows for the <code class="idl"><a data-link-type="idl" href="#dom-event-istrusted">isTrusted</a></code> attribute to be set to false. </p>
1045+
<li>
1046+
<p>Return the result of <a data-link-type="dfn" href="#concept-event-dispatch">dispatching</a> <var>event</var> at <var>target</var>, with <var>legacy target override flag</var> set if set. </p>
1047+
</ol>
1048+
<p class="note no-backref" role="note">Fire in the context of DOM is short for creating, initializing, and <a data-link-type="dfn" href="#concept-event-dispatch">dispatching</a> an <a data-link-type="dfn" href="#concept-event">event</a>. <a data-link-type="dfn" href="#concept-event-fire">Fire an event</a> makes that process easier to write down. </p>
1049+
<div class="example no-backref" id="firing-events-example">
1050+
<a class="self-link" href="#firing-events-example"></a>
1051+
<p>If the <a data-link-type="dfn" href="#concept-event">event</a> needs its <code class="idl"><a data-link-type="idl" href="#dom-event-bubbles">bubbles</a></code> or <code class="idl"><a data-link-type="idl" href="#dom-event-cancelable">cancelable</a></code> attribute initialized,
1052+
one could write "<a data-link-type="dfn" href="#concept-event-fire">fire an event</a> named <code>submit</code> at <var>target</var> with its <code class="idl"><a data-link-type="idl" href="#dom-event-cancelable">cancelable</a></code> attribute initialized to true". </p>
1053+
<p>Or, when a custom constructor is required, "<a data-link-type="dfn" href="#concept-event-fire">fire an event</a> named <code>click</code> at <var>target</var> using <code class="idl"><a data-link-type="idl" href="https://w3c.github.io/uievents/#interface-mouseevent">MouseEvent</a></code> with its <code class="idl"><a data-link-type="idl" href="#dom-event-istrusted">isTrusted</a></code> attribute initialized to
1054+
false". </p>
1055+
<p>Ocassionally the return value is important: </p>
1056+
<ol>
1057+
<li>
1058+
<p>Let <var>doAction</var> be the result of <a data-link-type="dfn" href="#concept-event-fire">firing an event</a> named <code>like</code> at <var>target</var>. </p>
1059+
<li>
1060+
<p>If <var>doAction</var> is true, then … </p>
1061+
</ol>
1062+
</div>
10371063
<h3 class="heading settled" data-level="3.10" id="action-versus-occurance"><span class="secno">3.10. </span><span class="content">Action versus occurrence</span><a class="self-link" href="#action-versus-occurance"></a></h3>
10381064
<p>An <a data-link-type="dfn" href="#concept-event">event</a> signifies an occurrence, not an action. Phrased differently, it
10391065
represents a notification from an algorithm and can be used to influence the future course
@@ -4844,7 +4870,7 @@ <h2 class="heading settled" data-level="6" id="traversal"><span class="secno">6.
48444870
return <code class="idl"><a data-link-type="idl" href="#dom-nodefilter-filter_skip">FILTER_SKIP</a></code>.
48454871
<li>If <a data-link-type="dfn" href="#concept-traversal-filter">filter</a> is null,
48464872
return <code class="idl"><a data-link-type="idl" href="#dom-nodefilter-filter_accept">FILTER_ACCEPT</a></code>.
4847-
<li>Let <var>result</var> be the return value of <a data-link-type="dfn">call a user object’s operation</a> with <a data-link-type="dfn" href="#concept-traversal-filter">filter</a>, "<code>acceptNode</code>", and a list of arguments consisting of <var>node</var>. Rethrow any exceptions.
4873+
<li>Let <var>result</var> be the return value of <a data-link-type="dfn" href="https://heycam.github.io/webidl/#call-a-user-objects-operation">call a user object’s operation</a> with <a data-link-type="dfn" href="#concept-traversal-filter">filter</a>, "<code>acceptNode</code>", and a list of arguments consisting of <var>node</var>. Rethrow any exceptions.
48484874
<li>Return <var>result</var>.
48494875
</ol>
48504876
<h3 class="heading settled" data-level="6.1" id="interface-nodeiterator"><span class="secno">6.1. </span><span class="content">Interface <code class="idl"><a data-link-type="idl" href="#nodeiterator">NodeIterator</a></code></span><a class="self-link" href="#interface-nodeiterator"></a></h3>
@@ -6595,6 +6621,7 @@ <h3 class="no-num no-ref heading settled" id="index-defined-elsewhere"><span cla
65956621
<li><a href="https://heycam.github.io/webidl/#Unforgeable">Unforgeable</a>
65966622
<li><a href="https://heycam.github.io/webidl/#Unscopable">Unscopable</a>
65976623
<li><a href="https://heycam.github.io/webidl/#wrongdocumenterror">WrongDocumentError</a>
6624+
<li><a href="https://heycam.github.io/webidl/#call-a-user-objects-operation">call a user object's operation</a>
65986625
<li><a href="https://heycam.github.io/webidl/#dfn-callback-this-value">callback this value</a>
65996626
<li><a href="https://heycam.github.io/webidl/#dfn-dictionary-member">dictionary members</a>
66006627
<li><a href="https://heycam.github.io/webidl/#dfn-identifier">identifier</a>

0 commit comments

Comments
 (0)