Skip to content

Commit 579c178

Browse files
authored
Specify the textInput event (#362)
* Specify the textInput event Fixes #353 * void -> undefined in IDL * Move textInput spec into event-algo.bs * Try to fix build errors * Second attempt with build errors * Third attempt with build errors, remove slashes * Fourth attempt, slash more slashes * Don't fire textInput for delete. Fire it on paste. * Fire textInput before compositionend * Set .data for insertParagraph/insertLineBreak * Don't set data to null Also fix a typo (and infinite recursion) in initialize a TextEvent. * Move IDL back to the main spec so that wpt will pick it up * Don't fire textInput when pressing Enter in <input>
1 parent 7f00f6a commit 579c178

File tree

8 files changed

+2362
-1895
lines changed

8 files changed

+2362
-1895
lines changed

event-algo.bs

Lines changed: 133 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -876,7 +876,7 @@ Issue: TODO
876876
1. If <a>suppress key input events flag</a> is set, then
877877
1. Exit (since the keydown was canceled)
878878

879-
Issue: Handle historical keypress event here
879+
Issue: Handle historical keypress event here. Return if cancelled.
880880

881881
1. Let |inputType| = null
882882
1. Let |data| = null
@@ -888,6 +888,9 @@ Issue: TODO
888888
1. If |key| is "Delete", then |inputType| = "deleteContentForward"
889889
1. Otherwise,
890890
1. |inputType| = "insertText"
891+
892+
Issue: |inputType| should be "insertParagraph" or "insertLineBreak" when pressing Enter.
893+
891894
1. |data| = |key|
892895

893896
1. If |inputType| is not null, then
@@ -896,12 +899,25 @@ Issue: TODO
896899
Can be enabled by changing the "dom.input_events.beforeinput_enabled" pref in "about:config"
897900

898901
1. Let |result| = <a>fire an InputEvent</a> with "beforeinput", |inputType| and |data|
899-
1. If |result| is true
902+
1. If |result| is false, then return.
903+
1. Let |textInputData| be |data|.
904+
1. Let |shouldFireTextInput| to true.
905+
1. If |inputType| is either "insertParagraph" or "insertLineBreak", then:
906+
1. Set |textInputData| to "\n".
907+
1. If |target| is an {{HTMLInputElement}}, then set |shouldFireTextInput| to false.
908+
1. If |inputType| is not one of "insertText", "insertParagraph" or "insertLineBreak", then set |shouldFireTextInput| to false.
909+
1. If |shouldFireTextInput| is true, then:
910+
911+
1. Set |result| = <a>fire a TextEvent</a> with "textInput", and |textInputData|
912+
913+
Note: The "textInput" event is obsolete.
914+
915+
1. If |result| is false, then return.
900916

901-
Note: Perform DOM update here. Insert key into |target| element
917+
Note: Perform DOM update here. Insert key into |target| element
902918

903-
Note: Compat:
904-
For insertFromPaste, Chrome has data = null, Firefox has data = same as beforeinput.
919+
Note: Compat:
920+
For insertFromPaste, Chrome has data = null, Firefox has data = same as beforeinput.
905921

906922
1. <a>Fire an InputEvent</a> with "input", |inputType| and |data|
907923

@@ -935,6 +951,100 @@ Issue: TODO
935951

936952
</section>
937953

954+
<!-- Big Text: Text Event -->
955+
956+
<section>
957+
<h2 id="textevent">Text Event</h2>
958+
959+
Note: {{TextEvent}} is obsolete.
960+
961+
<h3 id="textevent-interface">TextEvent Interface</h3>
962+
963+
<p class="note">See <a href="https://w3c.github.io/uievents/#legacy-textevent-events">IDL definition</a> in UI Events.</p>
964+
965+
The <dfn attribute for=TextEvent><code>data</code></dfn> attribute must return the value it was initialized to.
966+
967+
<div algorithm>
968+
<p>The
969+
<dfn method for=TextEvent><code>initTextEvent(<var>type</var>, <var>bubbles</var>, <var>cancelable</var>, <var>view</var>, <var>data</var>)</code></dfn>
970+
method steps are:
971+
972+
<ol>
973+
<li><p>If <a>this</a>'s <a>dispatch flag</a> is set, then return.
974+
975+
<li><p><a>Initialize a UIEvent</a> with <a>this</a>, |type| and |eventTarget|
976+
977+
<li><p>Set <a>this</a>.{{bubbles}} = |bubbles|
978+
979+
<li><p>Set <a>this</a>.{{cancelable}} = |cancelable|
980+
981+
<li>
982+
<p>Set <a>this</a>.{{view}} = |view|
983+
984+
<p class="note">The bubbles/cancelable/view should be parameters to "Initialize a UIEvent" instead of being set twice.
985+
986+
<li><p>Set <a>this</a>.{{TextEvent/data}} = |data|
987+
</ol>
988+
</div>
989+
990+
<div class="algorithm" data-algorithm="initialize-a-textevent">
991+
<h3 id="initialize-a-textevent"><dfn>initialize a TextEvent</dfn></h3>
992+
993+
: Input
994+
:: |e|, the {{Event}} to initialize
995+
:: |eventType|, a DOMString containing the event type
996+
:: |eventTarget|, the {{EventTarget}} of the event
997+
998+
: Output
999+
:: None
1000+
1001+
1. <a>Initialize a UIEvent</a> with |e|, |eventType| and |eventTarget|
1002+
1003+
1. Initialize the following public attributes
1004+
1005+
1. Set event.data = ""
1006+
1007+
</div><!-- algorithm -->
1008+
1009+
<div class="algorithm" data-algorithm="create-a-textevent">
1010+
<h3 id="create-a-textevent"><dfn>create a TextEvent</dfn></h3>
1011+
1012+
: Input
1013+
:: |eventType|, a DOMString containing the event type
1014+
:: |eventTarget|, the {{EventTarget}} of the event
1015+
1016+
: Output
1017+
:: None
1018+
1019+
1. Let |e| = the result of
1020+
<a href="https://dom.spec.whatwg.org/#concept-event-create">creating a new event</a> using {{TextEvent}}
1021+
1. <a>Initialize a TextEvent</a> with |e|, |eventType| and |eventTarget|
1022+
1023+
1. Return |e|
1024+
1025+
</div><!-- algorithm -->
1026+
1027+
<div class="algorithm" data-algorithm="fire-a-textevent">
1028+
<h3 id="fire-a-textevent"><dfn>fire a TextEvent</dfn></h3>
1029+
1030+
: Input
1031+
:: |eventType|, a DOMString containing the event type
1032+
:: |data|, a DOMString containing event data, or null
1033+
1034+
: Output
1035+
:: None
1036+
1037+
1. Let target =
1038+
<a href="https://html.spec.whatwg.org/#currently-focused-area-of-a-top-level-browsing-context">currently focused area of a top-level browsing context</a>
1039+
1. Let |event| = result of <a>create a TextEvent</a> with |eventType|, |target|
1040+
1. If |data| is null, set |data| to the empty string.
1041+
1. Set |event|.{{TextEvent/data}} = |data|
1042+
1. Return the result of <a>dispatch</a> |event| at |target|
1043+
1044+
</div><!-- algorithm -->
1045+
1046+
</section>
1047+
9381048
<!--
9391049
K K EEEEE Y Y BBBB OOO AAA RRRR DDDD EEEEE V V EEEEE N N TTTTT
9401050
K K E Y Y B B O O A A R R D D E V V E NN N T
@@ -1549,9 +1659,17 @@ And the following internal state:
15491659

15501660
1. If <a>in composition flag</a> is not set, then exit
15511661

1552-
Issue: Compat: Chrome sends out beforeinput/compositionupdate/input sequence before
1662+
Issue: Compat: Chrome sends out beforeinput/compositionupdate/textInput/input sequence before
15531663
compositionend (tested on macOS). Compare with Firefox.
15541664

1665+
1. Set |result| = <a>fire a TextEvent</a> with "textInput", and |data|
1666+
1667+
Note: The "textInput" event is obsolete.
1668+
1669+
1. If |result| is false, then return.
1670+
1671+
1. Issue: fire an input event here.
1672+
15551673
1. Let |data| = the current composition candidate string
15561674
1. <a>fire a CompositionEvent</a> with "compositionend" and |data|
15571675

@@ -2073,10 +2191,16 @@ Issue: Should these be moved into the Clipboard spec?
20732191
1. Let |data| = the text on the clipboard being pasted
20742192
1. Let |result| = <a>fire an InputEvent</a> with "beforeinput", "insertFromPaste" and |data|
20752193

2076-
1. If |result| is true, then
2194+
1. If |result| is false, then return.
2195+
2196+
1. Set |result| = <a>fire a TextEvent</a> with "textInput", and |data|
2197+
2198+
Note: The "textInput" event is obsolete.
2199+
2200+
1. If |result| is false, then return.
20772201

2078-
1. Paste clipboard contents into DOM target element
2079-
1. <a>Fire an InputEvent</a> with "input", "insertFromPaste" and |data|
2202+
1. Paste clipboard contents into DOM target element
2203+
1. <a>Fire an InputEvent</a> with "input", "insertFromPaste" and |data|
20802204

20812205
</div><!-- algorithm -->
20822206

0 commit comments

Comments
 (0)