-
Notifications
You must be signed in to change notification settings - Fork 51
/
event-algo.bs
2221 lines (1494 loc) · 75.2 KB
/
event-algo.bs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<h1>UI Events Algorithms</h1>
<pre class="metadata">
Shortname: uievents-algo
Level:
Group:
Status: DREAM
Editor: Gary Kacmarcik, Google, garykac@google.com
Abstract:
This document attempts to describe, in an algorithmic manner, how UIEvents
should be handled by User Agents. Because this functionality has been shipping
in UAs for many years, the primary goal is to document the existing behaviors
and identify areas where implementations disagree. The intent is to fold this
information into the main UIEvents spec (and other specs) once there is
consensus that this process described here is adequate.
</pre>
<pre class="anchors">
urlPrefix: https://www.w3.org/TR/uievents/#; type: dfn; spec: uievents;
text: compositionend
text: compositionstart
urlPrefix: https://html.spec.whatwg.org/#; type: dfn; spec: html;
text: click focusable
text: focusable area
text: focusing steps
url: https://www.w3.org/TR/uievents-key/#keys-modifier; type: dfn; spec: uievents-key;
text: modifier key
url: https://www.w3.org/TR/CSS2/visuren.html#viewport; type: dfn; spec: css2;
text: viewport
url: https://www.w3.org/TR/cssom-view-1/#dom-document-elementfrompoint; type: dfn; spec: cssom-view;
text: elementFromPoint
text: elementsFromPoint
url: https://dom.spec.whatwg.org/#concept-event-dispatch; type: dfn; spec: html;
text: dispatch
</pre>
<pre class="link-defaults">
spec:cssom-view; type:attribute; for:MouseEvent; text:x
spec:cssom-view; type:attribute; for:MouseEvent; text:y
spec:dom; type:attribute; for:Event; text:bubbles
spec:dom; type:attribute; for:Event; text:cancelable
spec:dom; type:attribute; for:Event; text:composed
spec:dom; type:attribute; for:Event; text:target
spec:dom; type:attribute; for:Event; text:type
spec:dom; type:const; text:NONE
spec:ui-events; type:attribute; for:InputEvent; text:inputType
spec:ui-events; type:attribute; for:KeyboardEvent; text:code
spec:ui-events; type:attribute; for:MouseEvent; text:button
spec:ui-events; type:attribute; for:MouseEvent; text:buttons
spec:ui-events; type:attribute; for:MouseEvent; text:clientX
spec:ui-events; type:attribute; for:MouseEvent; text:clientY
spec:ui-events; type:attribute; for:MouseEvent; text:screenX
spec:ui-events; type:attribute; for:MouseEvent; text:screenY
spec:ui-events; type:attribute; for:UIEvent; text:detail
spec:ui-events; type:attribute; for:UIEvent; text:view
spec:ui-events; type:attribute; for:UIEvent; text:which
</pre>
<section>
<h2 id="intro">Why?</h2>
The description of events in the current UIEvents spec is woefully underspecified.
This has led to different User Agents (UAs) implementing the same feature with
different behaviors.
The intent with this document is to:
* Describe the current behaviors that are shared by existing UAs
* Identify behaviors where they differ
* Initiate discussions to resolve the differences
Part of this process will necessarily require that we describe processes that
rightfully belong in other specifications (e.g., Pointer Events or Input Events).
The intent is to eventually move those portions into their appropriate home,
but they are kept here while drafting this document to make it easier to discuss.
</section>
<!--
N N AAA TTTTT IIIII V V EEEEE
NN N A A T I V V E
N N N AAAAA T I V V EEE
N NN A A T I V V E
N N A A T IIIII V EEEEE
-->
<section>
<h2 id="native-os">Native OS Requirements</h2>
The following is the set of assumptions that this specification makes about the
underlying native operating system. It is expected that the native OS will
provide these basic services for the UA.
In the event that the native OS does not provide these services, then the
UA will need to implement them.
<h3 id="req-mouse">MouseEvent Requirements</h3>
The native OS platform will provide:
* An event when the mouse is moved
* An event when a mouse button is pressed
* An event when a mouse button is released
* A way to identify when a mouse button press should be interpreted as a "click"
* For example, as a flag or as a separate event
* If a separate "click" event is fired, then the native OS will fire it
immediately after the corresponding "mouse up" event, with no
intervening mouse-related events
* A way to identify when a mouse click is a "double click"
For these events, the OS will be able to provide the following info:
* The x,y mouse coordinates relative to the native OS desktop
* The x,y mouse coordinates relative to the UA's window viewport
* Which keyboard modifiers are currently being held
<h3 id="req-touch">PointerEvent Requirements</h3>
TODO: Specify native requirements here.
<h3 id="req-keyboard">KeyboardEvent Requirements</h3>
The native OS platform will provide:
* An event when a key is pressed
Note: On Windows: WM_KEYDOWN, WM_SYSKEYDOWN
Note: On macOS: NSKeyDown, NSFlagsChanged (for modifiers without other keys)
* An event when a key is released
Note: On Windows: WM_KEYUP, WM_SYSKEYUP
Note: On macOS: NSKeyUp, NSFlagsChanged (for modifiers without other keys)
* An event when a character should be generated as a result of a keypress
* This may be a separate event, or it may be combined with the keydown event
* If a separate event, then there are no intervening key events between keydown and char
Note: On Windows: WM_CHAR, WM_SYSCHAR
Note: On macOS: Combined with keydown
* An event when text should be inserted
* These are commonly used for alternate input devices like chordal keyboards or speech input
* This may be the same event as for when a key is pressed
Note: On Windows: WM_CHAR (without associated keydown/keyup)
Note: On macOS: NSTextInputClient with insertText
* A way to identify key events that are "repeat"s from the key being held down
* The platform will maintain a key repeat threshold
* A way to identify the modifier keys that are held in combination with a key press
* Either via flags in the messages, or via a separate call
Note: On Windows: included with WM_ messages
Note: On macOS: included with NSKey messages and NSFlagChanged
Note: On Linux (GTK): not provided with messages. need to request separately
<h3 id="req-ime">IME Requirements</h3>
Issue: IMEs differ wildly on different platforms, and often have different capabilities
(such as whether or not they can be "canceled") even on the same platform.
What is the common set of requirements that we can rely on?
Issue: For example, on Windows, Win+'.' opens an emoji window that will generate
composition events. But there is not indication from the OS that composition
is about to take place. A similar problem exists with "shape writing" using the
virtual keyboard.
<h3 id="native-entry-points">Native Entry Points</h3>
<h4 id="native-mouse">Mouse</h4>
* <a>handle native mouse down</a>
* <a>handle native mouse up</a>
* <a>handle native mouse click</a>
* <a>handle native mouse double click</a>
* <a>handle native mouse move</a>
<h4 id="native-touch">Touch</h4>
TODO: Include native touch events and resolve with native mouse events. How do these two
event types interact on the common platforms? When are mouse events generated from
touch events?
<h4 id="native-keyboard">Keyboard</h4>
* <a>handle native key down</a>
* <a>handle native key press</a>
* <a>handle native key up</a>
<h4 id="native-clipboard">Clipboard</h4>
* <a>handle native cut</a>
* <a>handle native copy</a>
* <a>handle native paste</a>
</section>
<!--
EEEEE V V EEEEE N N TTTTT
E V V E NN N T
EEE V V EEE N N N T
E V V E N NN T
EEEEE V EEEEE N N T
-->
<section>
<h2 id="event">Event</h2>
Issue: Move to/merge with [[DOM]] spec {{Event}} interface.
<h3 id="event-interface">Event Interface</h3>
A {{Event}} has the following additional internal state:
<dl dfn-for="UIEvent">
<li><dfn>due to user interaction flag</dfn>
Issue: This is a proposal.
See <a href="https://github.com/w3c/uievents/issues/270">uievents/270</a>
</li>
</dl>
<div class="algorithm" data-algorithm="initialize-an-event">
<h3 id="initialize an event"><dfn>initialize an Event</dfn></h3>
: Input
:: |event|, the {{Event}} to initialize
:: |eventType|, a DOMString containing the event type
:: |eventTarget|, the {{EventTarget}} of the event
: Output
:: None
For reference, see
<a href="https://dom.spec.whatwg.org/#concept-event-initialize">initialize an event</a>,
<a href="https://dom.spec.whatwg.org/#stop-propagation-flag">list of event flags</a>.
1. Initialize the following public attributes
1. Set |event|.{{type}} = |eventType|
1. Set |event|.{{target}} = |eventTarget|
1. Set |event|.{{currentTarget}} = null (This will be set appropriately during dispatch)
1. Set |event|.{{eventPhase}} = {{NONE}} (This will be set appropriately during dispatch)
1. Set |event|.{{bubbles}} = true
1. Set |event|.{{cancelable}} = true
1. Set |event|.{{defaultPrevented}} = false
1. Set |event|.{{composed}} = false // See COMPAT note for mouseenter and mouseleave
1. Set |event|.{{isTrusted}} = false
1. Set |event|.{{timeStamp}} = Number of milliseconds relative to the time origin
1. Initialize the following historical attributes
1. Set |event|.srcElement = |eventTarget|
1. Set |event|.cancelBubble = alias for stopPropagation
1. Set |event|.returnValue = alias for !canceled_flag
1. Initialize the following internal state
1. Unset |event|'s <a>stop propagation flag</a>
1. Unset |event|'s <a>stop immediate propagation flag</a>
1. Unset |event|'s <a>canceled flag</a>
1. Unset |event|'s <a>in passive listener flag</a>
1. Unset |event|'s <a>composed flag</a>
1. Unset |event|'s <a>initialized flag</a>
1. Unset |event|'s <a>dispatch flag</a>
1. Initialize the following proposed internal state
1. Unset |event|'s <a>due to user interaction flag</a>
</div><!-- algorithm -->
</section>
<!--
U U IIIII EEEEE V V EEEEE N N TTTTT
U U I E V V E NN N T
U U I EEE V V EEE N N N T
U U I E V V E N NN T
UUU IIIII EEEEE V EEEEE N N T
-->
<section>
<h2 id="ui event">UI Event</h2>
<h3 id="uievent-interface">UIEvent Interface</h3>
A {{UIEvent}} has the following:
<dl dfn-for="UIEvent">
<li><dfn attribute>view</dfn></li>
<li><dfn attribute>detail</dfn></li>
</dl>
Along with the following historical attribute:
<dl dfn-for="KeyboardEvent">
<li><dfn attribute>which</dfn></li>
</dl>
Issue: Add definition for UIEventInit
<div class="algorithm" data-algorithm="initialize-a-uievent">
<h3 id="initialize a uievent"><dfn>initialize a UIEvent</dfn></h3>
: Input
:: |event|, the {{UIEvent}} to initialize
:: |eventType|, a DOMString containing the event type
:: |eventTarget|, the {{EventTarget}} of the event
: Output
:: None
1. <a>Initialize an Event</a> with |event|, |eventType| and |eventTarget|
1. Initialize the following public attributes
1. Set |event|.{{view}} = the |eventTarget|'s <a>node document</a>'s {{Window}} object
1. Set |event|.{{detail}} = 0
1. Initialize the following historical attributes
1. Set |event|.{{which}} = 0 (used by both {{MouseEvent}} and {{KeyboardEvent}})
1. If this event is the result of user interaction, then
1. Set |event|'s <a>due to user interaction flag</a>
Note: See <a href="https://github.com/w3c/uievents/issues/270">uievents/270</a>
1. Set |event|.{{isTrusted}} = false
</div><!-- algorithm -->
Issue: Event firing for load, unload, abort, error, select. Should those be covered here
or are they handled elsewhere already?
</section>
<!--
FFFFF OOO CCC U U SSSS EEEEE V V EEEEE N N TTTTT
F O O C C U U S E V V E NN N T
FFFF O O C U U SSS EEE V V EEE N N N T
F O O C C U U S E V V E N NN T
F OOO CCC UUU SSSS EEEEE V EEEEE N N T
-->
<section>
<h2 id="focus event">Focus Event</h2>
Issue: TODO
</section>
<!--
M M OOO U U SSSS EEEEE EEEEE V V EEEEE N N TTTTT
MM MM O O U U S E E V V E NN N T
M M M O O U U SSS EEE EEE V V EEE N N N T
M M O O U U S E E V V E N NN T
M M OOO UUU SSSS EEEEE EEEEE V EEEEE N N T
-->
<section>
<h2 id="mouse event">Mouse Event</h2>
<h3 id="mouseevent-interface">MouseEvent Interface</h3>
A {{MouseEvent}} has the following:
<dl dfn-for="MouseEvent">
<li><dfn attribute>screenX</dfn></li>
<li><dfn attribute>screenY</dfn></li>
<li><dfn attribute>clientX</dfn></li>
<li><dfn attribute>clientY</dfn></li>
<li><dfn attribute>ctrlKey</dfn></li>
<li><dfn attribute>shiftKey</dfn></li>
<li><dfn attribute>altKey</dfn></li>
<li><dfn attribute>metaKey</dfn></li>
<li><dfn attribute>button</dfn></li>
<li><dfn attribute>buttons</dfn></li>
<li><dfn attribute>relatedTarget</dfn></li>
<li>getModifierState(keyArg)</li>
</dl>
<h3 id="mouseevent-global-state">Global State for MouseEvent</h3>
<h4 id="mouseevent-global-ua">User Agent-Level State</h4>
The UA must maintain the following values that are shared for the entire
User Agent.
A <dfn>mouse button bitmask</dfn> that tracks the current state of the
mouse buttons.
<h4 id="mouseevent-global-window">Window-Level State</h4>
The UA must maintain the following values that are shared for the Window.
A <dfn>last mouse element</dfn> value (initially undefined) that keeps track
of the last {{Element}} that we sent a MouseEvent to.
A <dfn>last mouse DOM path</dfn> value (initially empty) that contains a snapshot
of the ancestors {{Element}}s of the <a>last mouse element</a> when the most recent mouse
event was sent.
<div class="algorithm" data-algorithm="initialize-a-mouseevent">
<h3 id="initialize a mouseevent"><dfn>initialize a MouseEvent</dfn></h3>
: Input
:: |event|, the {{MouseEvent}} to initialize
:: |eventType|, a DOMString containing the event type
:: |eventTarget|, the {{EventTarget}} of the event
: Output
:: None
1. <a>Initialize a UIEvent</a> with |event|, |eventType| and |eventTarget|
2. Initialize the following public attributes
1. Set |event|.{{screenX}} = the x-coordinate of the position where the event occurred
relative to the origin of the desktop
1. Set |event|.{{screenY}} = the y-coordinate of the position where the event occurred
relative to the origin of the desktop
1. Set |event|.{{clientX}} = the x-coordinate of the position where the event occurred
relative to the origin of the viewport
1. Set |event|.{{clientY}} = the y-coordinate of the position where the event occurred
relative to the origin of the <a>viewport</a>
1. <a>Set event modifiers</a> with |event|
1. Set |event|.{{button}} = 0
1. Set |event|.{{buttons}} = <a>mouse button bitmask</a>
1. <a>Initialize PointerLock attributes for MouseEvent</a> with |event|
1. <a>Initialize CSSOM attributes for MouseEvent</a> with |event|
</div><!-- algorithm -->
<div class="algorithm" data-algorithm="create-a-mouseevent">
<h3 id="create a mouseevent"><dfn>create a MouseEvent</dfn></h3>
: Input
:: |eventType|, a DOMString containing the event type
:: |eventTarget|, the {{EventTarget}} of the event
: Output
:: None
1. Let |event| = the result of
<a href="https://dom.spec.whatwg.org/#concept-event-create">creating a new event</a> using {{MouseEvent}}
1. <a>Initialize a MouseEvent</a> with |event|, |eventType| and |eventTarget|
1. Return |event|
</div><!-- algorithm -->
<div class="algorithm" data-algorithm="calculate-mouseevent-button-attribute">
<h3 id="calculate mouseevent button attribute"><dfn>calculate MouseEvent button attribute</dfn></h3>
: Input
:: |mbutton|, an ID that identifies a mouse button
: Output
:: A button ID suitable for storing in the {{MouseEvent}}'s {{button}} attribute
1. If |mbutton| is the primary mouse button, then return 0
1. If |mbutton| is the auxiliary (middle) mouse button, then return 1
1. If |mbutton| is the secondary mouse button, then return 2
1. If |mbutton| is the X1 (back) button, then return 3
1. If |mbutton| is the X2 (forward) button, then return 4
</div><!-- algorithm -->
<div class="algorithm" data-algorithm="set-mouseevent-attributes-from-native">
<h3 id="set mouseevent attributes from native"><dfn>set MouseEvent attributes from native</dfn></h3>
: Input
:: |event|, the {{MouseEvent}} to initialize
:: |native|, the native mouse event
: Output
:: None
Issue: TODO
1. If |event|.{{type}} is one of [ mousedown, mouseup ], then
1. Let |mbutton| be an ID from |native| that identifies which mouse button was pressed
1. Set |event|.{{button}} = <a>calculate MouseEvent button attribute</a> with |mbutton|
</div><!-- algorithm -->
<div class="algorithm" data-algorithm="handle-native-mouse-down">
<h3 id="handle native mouse down"><dfn>handle native mouse down</dfn></h3>
: Input
:: |native|, the native mousedown
: Output
:: None
1. Let |mbutton| be an ID from |native| that identifies which mouse button was pressed
1. Update the <a>mouse button bitmask</a> as follows:
1. If |mbutton| is the primary mouse button, then set the 0x01 bit
1. If |mbutton| is the secondary mouse button, then set the 0x02 bit
1. If |mbutton| is the auxiliary (middle) mouse button, then set the 0x04 bit
Issue: Other buttons can be added starting with 0x08
1. Let |target| = <a>hit test</a> with viewport-relative coordinates from |native|
1. Let |event| = <a>create a MouseEvent</a> with "mousedown", |target|
1. <a>Set MouseEvent attributes from native</a> with |native|
1. <a>Maybe send pointerdown event</a> with |event|
1. Let |result| = <a>dispatch</a> |event| at |target|
1. If |result| is true and |target| is a <a>focusable area</a> that is <a>click focusable</a>, then
1. Run the <a>focusing steps</a> at |target|
1. if |mbutton| is the secondary mouse button, then
1. <a>Maybe show context menu</a> with |native|, |target|
</div><!-- algorithm -->
<div class="algorithm" data-algorithm="handle-native-mouse-up">
<h3 id="handle native mouse up"><dfn>handle native mouse up</dfn></h3>
: Input
:: |native|, the native mouseup
: Output
:: None
Note: Other mouse events can occur between the mousedown and mouseup.
1. Let |mbutton| be an ID from |native| that identifies which mouse button was pressed
1. Update the <a>mouse button bitmask</a> as follows:
1. If |mbutton| is the primary mouse button, then clear the 0x01 bit
1. If |mbutton| is the secondary mouse button, then clear the 0x02 bit
1. If |mbutton| is the auxiliary (middle) mouse button, then clear the 0x04 bit
1. Let |target| = <a>hit test</a> with viewport-relative coordinates from |native|
1. Let |event| = <a>create a MouseEvent</a> with "mouseup", |target|
1. <a>Set MouseEvent attributes from native</a> with |native|
1. <a>Maybe send pointerup event</a> with |event|
1. <a>dispatch</a> |event| at |target|
</div><!-- algorithm -->
<div class="algorithm" data-algorithm="handle-native-mouse-click">
<h3 id="handle native mouse click"><dfn>handle native mouse click</dfn></h3>
: Input
:: |native|, the native mouse click
: Output
:: None
Note: The platform should call this immediately after <a>handle native mouse up</a> for
mouseups that generate clicks.
1. Let |target| = <a>hit test</a> with viewport-relative coordinates from |native|
1. <a>Send click event</a> with |native| and |target|.
</div><!-- algorithm -->
<div class="algorithm" data-algorithm="send-click-event">
<h3 id="send click event"><dfn>send click event</dfn></h3>
: Input
:: |native|, the native mousedown
:: |target|, the {{EventTarget}} of the event
: Output
:: None
1. Let |mbutton| = 1 (primary mouse button by default)
1. If |native| is valid, then
1. Let |mbutton| be an ID from |native| that identifies which mouse button was pressed
1. Let |eventType| = "auxclick"
1. If |mbutton| is the primary mouse button, then
1. Set |eventType| = "click"
1. Let |event| = <a>create a PointerEvent</a> with |eventType| and |target|
1. If |native| is valid, then
1. <a>Set MouseEvent attributes from native</a> with |event|, |native|
1. If |event|.{{screenX}} is not an integer value, then round it.
1. If |event|.{{screenY}} is not an integer value, then round it.
1. <a>dispatch</a> |event| at |target|
Note: See <a href="https://github.com/w3c/pointerevents/issues/100">pointerevents/100</a>
for info about browsers using PointerEvents and rounded coordinates.
Note: Any "default action" is handled during dispatch by triggering the
<a href="https://dom.spec.whatwg.org/#eventtarget-activation-behavior">activation behavior</a>
algorithm for the target. So there is no need for handle that here.
However, need to verify that the existing spec handles disabled/css-pointer-events/inert/...
Note: To handle `HTMLelement.click()`, call this algorithm with |native| = null and
|target| = `HTMLelement`.
Note: To handle keyboard-initiated clicks, call this algorithm with |native| = null and
|target| = currently focused element.
</div><!-- algorithm -->
<div class="algorithm" data-algorithm="handle-native-mouse-double-click">
<h3 id="handle native mouse double click"><dfn>handle native mouse double click</dfn></h3>
: Input
:: |native|, the native mouse double click
: Output
:: None
Note: This should be called immediately after handle native mouse click for
mouse clicks that generate double clicks.
1. Let |mbutton| be an ID from |native| that identifies which mouse button was pressed
1. If |mbutton| is not the primary mouse button, then return
1. Let |target| = <a>hit test</a> with viewport-relative coordinates from |native|
1. Let |event| = <a>create a PointerEvent</a> with "dblclick" and |target|
1. <a>Set MouseEvent attributes from native</a> with |event|, |native|
1. If |event|.{{screenX}} is not an integer value, then round it.
1. If |event|.{{screenY}} is not an integer value, then round it.
1. <a>dispatch</a> |event| at |target|
</div><!-- algorithm -->
<div class="algorithm" data-algorithm="handle-native-mouse-move">
<h3 id="handle native mouse move"><dfn>handle native mouse move</dfn></h3>
: Input
:: |native|, the native mouse move
: Output
:: None
Issue: This algorithm makes assumptions about the dispatch of PointerEvents because they
are not currently specified explicitly. Once
<a href="https://github.com/w3c/pointerevents/issues/285">pointerevents/285</a> is resolved
this may need to be updated.
1. Let |target| = <a>hit test</a> with viewport-relative coordinates from |native|
1. Let |targetDomPath| = <a>calculate DOM path</a>
1. Generate events for leaving the current element:
1. If <a>last mouse element</a> is defined and not equal to |target|, then
1. Let |mouseout| = <a>create a MouseEvent</a> with "mouseout" and <a>last mouse element</a>
Issue: TODO: Set |mouseout| attributes from |native|. +CSSOM attributes
1. <a>Maybe send pointerout event</a> with |mouseout|
1. <a>Dispatch</a> |mouseout| at |target|
Issue: Verify behavior when canceled (appears to have no effect).
1. Let |leaveElements| be a copy of <a>last mouse DOM path</a> with all
elements common to |targetDomPath| removed.
1. For each |element| in |leaveElements|, do
Issue: Handle case where |element| has been deleted.
Also case where it has been moved: Should the DOM mutation have triggered
a mouseleave event? Should we sent it now? Should it be dropped?
Need to verify what current browsers do.
1. Let |mouseleave| = <a>create a MouseEvent</a> with "mouseleave" and |element|
1. Set |mouseleave|.{{bubbles}} = false
1. Set |mouseleave|.{{cancelable}} = false
1. Set |mouseleave|.{{composed}} = false
Issue: Compat: Value of event.composed. Spec says false.
Chrome/Linux = true
Firefox/Linux = false
1. <a>Maybe send pointerleave event</a> with |mouseleave|
1. Let |result| = <a>dispatch</a> |mouseleave| at |element|
1. Generate events for entering the new element:
1. If |target| is not <a>last mouse element</a>, then
1. Let |mouseover| = <a>create a MouseEvent</a> with "mouseover" and |target|
Issue: TODO: Set |mouseout| attributes from |native|. +CSSOM attributes
1. <a>Maybe send pointerover event</a> with |mouseover|
1. <a>Dispatch</a> |mouseout| at |target|
Issue: Verify behavior when canceled (appears to have no effect).
1. Let |enterElements| be a copy of |targetDomPath| with all
elements common to <a>last mouse DOM path</a> removed.
1. For each |element| in |enterElements|, do
Issue: Handle case where |element| has been deleted or moved.
1. Let |mouseenter| = <a>create a MouseEvent</a> with "mouseenter" and |element|
1. Set |mouseenter|.{{bubbles}} = false
1. Set |mouseenter|.{{cancelable}} = false
1. Set |mouseenter|.{{composed}} = false
Issue: Compat: Value of event.composed. Spec says false.
Chrome/Linux = true
Firefox/Linux = false
1. <a>Maybe send pointerenter event</a> with |mouseenter|
Issue: Compat for shadow DOM elements
Chrome/Linux fires this event at the element and the shadow root
1. Let |result| = <a>dispatch</a> |mouseenter| at |element|
1. Set <a>last mouse element</a> to |target|
1. Set <a>last mouse DOM path</a> to |targetDomPath|
1. Let |mousemove| = <a>create a MouseEvent</a> with "mousemove" and |element|
1. <a>Set PointerLock attributes for mousemove</a>
1. <a>Maybe send pointermove event</a> with |mousemove|
1. <a>Dispatch</a> |mousemove| at |element|
</div><!-- algorithm -->
<div class="algorithm" data-algorithm="maybe-show-context-menu">
<h3 id="maybe show context menu"><dfn>maybe show context menu</dfn></h3>
: Input
:: |native|, the native mousedown or pointer event
:: |target|, the {{EventTarget}} of the event
: Output
:: None
1. Let |menuevent| = <a>create a PointerEvent</a> with "contextmenu", |target|
1. If |native| is valid, then
1. <a>Set MouseEvent attributes from native</a> with |native|
1. Let |result| = <a>dispatch</a> |menuevent| at |target|
1. If |result| is true, then show the UA context menu
Note: To handle a context menu triggered by the keyboard, call this algorithm with
|native| = null and |target| = currently focused element.
</section>
<!--
W W H H EEEEE EEEEE L EEEEE V V EEEEE N N TTTTT
W W H H E E L E V V E NN N T
W W W HHHHH EEEE EEEE L EEE V V EEE N N N T
WW WW H H E E L E V V E N NN T
W W H H EEEEE EEEEE LLLLL EEEEE V EEEEE N N T
-->
<section>
<h2 id="wheel event">Wheel Event</h2>
Issue: TODO
</section>
<!--
IIIII N N PPPP U U TTTTT EEEEE V V EEEEE N N TTTTT
I NN N P P U U T E V V E NN N T
I N N N PPPP U U T EEE V V EEE N N N T
I N NN P U U T E V V E N NN T
IIIII N N P UUU T EEEEE V EEEEE N N T
-->
<section>
<h2 id="input event">Input Event</h2>
<div class="algorithm" data-algorithm="initialize-an-inputevent">
<h3 id="initialize an Inputevent"><dfn>initialize an InputEvent</dfn></h3>
: Input
:: |e|, the {{Event}} to initialize
:: |eventType|, a DOMString containing the event type
:: |eventTarget|, the {{EventTarget}} of the event
: Output
:: None
1. <a>Initialize a UIEvent</a> with |e|, |eventType| and |eventTarget|
1. Initialize the following public attributes
1. Set event.data = null
1. Set event.isComposing = false
1. Set event.inputType = ""
1. Set event.composed = true
Note: Setting composed to true matches current UA behavior, but it makes more sense
for this to be false.
See <a href="https://github.com/whatwg/html/issues/5453">whatwg/html/5453</a>
for discussion.
1. Initialize the additional editing attributes from [[Input Events]]
Issue: Move the following into InputEvents spec
(<a href="https://www.w3.org/TR/input-events-1/">level 1</a>
or
<a href="https://www.w3.org/TR/input-events-2/">level 2</a>)
since that's where these attributes are defined.
1. Set |e|.dataTransfer = false
1. Set |e|.targetRanges = []
</div><!-- algorithm -->
<div class="algorithm" data-algorithm="create-an-inputevent">
<h3 id="create an inputevent"><dfn>create an InputEvent</dfn></h3>
: Input
:: |eventType|, a DOMString containing the event type
:: |eventTarget|, the {{EventTarget}} of the event
: Output
:: None
1. Let |e| = the result of
<a href="https://dom.spec.whatwg.org/#concept-event-create">creating a new event</a> using {{InputEvent}}
1. <a>Initialize an InputEvent</a> with |e|, |eventType| and |eventTarget|
1. Return |e|
</div><!-- algorithm -->
<div class="algorithm" data-algorithm="fire-key-input-events">
<h3 id="fire key input events"><dfn>fire key input events</dfn></h3>
: Input
:: |key|, a DOMString containing the string corresponding to the key
:: |target|, the {{EventTarget}} of the event
: Output
:: None
1. If <a>suppress key input events flag</a> is set, then
1. Exit (since the keydown was canceled)
Issue: Handle historical keypress event here. Return if cancelled.
1. Let |inputType| = null
1. Let |data| = null
Issue: How much of this can be moved into the [[Input Events]] spec?
Issue: List more keys here
1. If |key| is "Backspace", then |inputType| = "deleteContentBackward"
1. If |key| is "Delete", then |inputType| = "deleteContentForward"
1. Otherwise,
1. |inputType| = "insertText"
Issue: |inputType| should be "insertParagraph" or "insertLineBreak" when pressing Enter.
1. |data| = |key|
1. If |inputType| is not null, then
Note: Need to verify Firefox behavior.
Can be enabled by changing the "dom.input_events.beforeinput_enabled" pref in "about:config"
1. Let |result| = <a>fire an InputEvent</a> with "beforeinput", |inputType| and |data|
1. If |result| is false, then return.
1. Let |textInputData| be |data|.
1. Let |shouldFireTextInput| to true.
1. If |inputType| is either "insertParagraph" or "insertLineBreak", then:
1. Set |textInputData| to "\n".
1. If |target| is an {{HTMLInputElement}}, then set |shouldFireTextInput| to false.
1. If |inputType| is not one of "insertText", "insertParagraph" or "insertLineBreak", then set |shouldFireTextInput| to false.
1. If |shouldFireTextInput| is true, then:
1. Set |result| = <a>fire a TextEvent</a> with "textInput", and |textInputData|
Note: The "textInput" event is obsolete.
1. If |result| is false, then return.
Note: Perform DOM update here. Insert key into |target| element
Note: Compat:
For insertFromPaste, Chrome has data = null, Firefox has data = same as beforeinput.
1. <a>Fire an InputEvent</a> with "input", |inputType| and |data|
</div><!-- algorithm -->
<div class="algorithm" data-algorithm="fire-an-inputevent">
<h3 id="fire an inputevent"><dfn>fire an InputEvent</dfn></h3>
: Input
:: |eventType|, a DOMString containing the event type
:: |inputType|, a DOMString containing the input event type
:: |data|, a DOMString containing event data
: Output
:: None
Issue: What about target ranges? Need to add support here.
Issue: The target for input events should consider focus, but should also ensure that
the element is editable and being modified.
Compare: <a>fire a compositionevent</a>
1. Let target =
<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>
1. Let |event| = result of <a>create an InputEvent</a> with |eventType|, |target|
1. Set |event|.{{inputType}} = |inputType|
1. Set |event|.{{InputEvent/data}} = |data|
1. Return the result of <a>dispatch</a> |event| at |target|
</div><!-- algorithm -->
</section>
<!-- Big Text: Text Event -->
<section>
<h2 id="textevent">Text Event</h2>
Note: {{TextEvent}} is obsolete.
<h3 id="textevent-interface">TextEvent Interface</h3>
<p class="note">See <a href="https://w3c.github.io/uievents/#legacy-textevent-events">IDL definition</a> in UI Events.</p>
The <dfn attribute for=TextEvent><code>data</code></dfn> attribute must return the value it was initialized to.
<div algorithm>
<p>The
<dfn method for=TextEvent><code>initTextEvent(<var>type</var>, <var>bubbles</var>, <var>cancelable</var>, <var>view</var>, <var>data</var>)</code></dfn>
method steps are:
<ol>
<li><p>If <a>this</a>'s <a>dispatch flag</a> is set, then return.
<li><p><a>Initialize a UIEvent</a> with <a>this</a>, |type| and |eventTarget|
<li><p>Set <a>this</a>.{{bubbles}} = |bubbles|
<li><p>Set <a>this</a>.{{cancelable}} = |cancelable|
<li>
<p>Set <a>this</a>.{{view}} = |view|
<p class="note">The bubbles/cancelable/view should be parameters to "Initialize a UIEvent" instead of being set twice.
<li><p>Set <a>this</a>.{{TextEvent/data}} = |data|
</ol>
</div>
<div class="algorithm" data-algorithm="initialize-a-textevent">
<h3 id="initialize-a-textevent"><dfn>initialize a TextEvent</dfn></h3>
: Input
:: |e|, the {{Event}} to initialize
:: |eventType|, a DOMString containing the event type
:: |eventTarget|, the {{EventTarget}} of the event
: Output
:: None