-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.html
3838 lines (2941 loc) · 157 KB
/
index.html
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
<!DOCTYPE HTML>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=792, user-scalable=no">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<title>Getting touchy - everything you (n)ever wanted to know about touch and pointer events / Patrick H. Lauke</title>
<link rel="stylesheet" href="shower/themes/redux/styles/screen.css">
<link rel="stylesheet" href="shower/themes/redux/styles/overrides.css">
<link rel="stylesheet" href="highlight/styles/sunburst.css">
<style>
#yougotthetouch.slide { background-color: #000; }
</style>
<script src="highlight/highlight.pack.js"></script>
<script>hljs.initHighlightingOnLoad();</script>
</head>
<body class="shower list">
<header class="caption">
<h1>Getting touchy</h1>
<p>Everything you (n)ever wanted to know about <strong>touch and pointer</strong> events</p>
</header>
<!-- -->
<section class="slide cover title" id="Cover"><div>
<div class="titlestrap">
<h2>Getting <strong>touchy</strong></h2>
<p>Everything you (n)ever wanted to know about <strong>touch and pointer</strong> events</p>
</div>
<p class="info">Patrick H. Lauke / Last major changes: 2 May 2022</p>
<img src="pictures/backgrounds/background-cover.jpg" alt="" class="cover">
</div></section>
<!-- -->
<section class="slide listing"><div>
<h2>about me...</h2>
<ul>
<li>community group co-chair and co-editor <a target="_blank" rel="noopener" href="https://w3c.github.io/touch-events/">Touch Events Level 2</a></li>
<li>working group chair and co-editor <a target="_blank" rel="noopener" href="https://w3c.github.io/pointerevents/">Pointer Events Level 3</a></li>
</ul>
</div></section>
<!-- -->
<section class="slide"><div>
<img src="pictures/sites/github-patrickhlauke-getting-touchy.png" alt="">
<p><a target="_blank" rel="noopener" href="https://github.com/patrickhlauke/getting-touchy-presentation">github.com/patrickhlauke/getting-touchy-presentation</a></p>
<p>"evergreen" expanded version of this presentation<br><small>(and branches for specific conferences)</small></p>
</div></section>
<!-- -->
<section class="slide"><div>
<img src="pictures/sites/patrickhlauke.github.io.png" alt="">
<p><a target="_blank" rel="noopener" href="https://patrickhlauke.github.io/touch/">patrickhlauke.github.io/touch</a></p>
</div></section>
<!-- -->
<section class="slide"><div>
<img src="pictures/backgrounds/photo-device-testing.jpg" alt="Large number of mobile phone/tablet test devices">
</div></section>
<!-- -->
<section class="slide"><div>
<img src="pictures/sites/patrickhlauke-github-touch-results.png" alt="">
<p><a target="_blank" rel="noopener" href="https://patrickhlauke.github.io/touch/tests/results/">Touch/pointer events test results</a></p>
</div></section>
<!-- -->
<section class="slide cover impact"><div>
<div><p>my JavaScript sucks...<br><small>(but will hopefully convey the right concepts)</small></p></div>
<img src="pictures/backgrounds/background-danger-415-volts.jpg" class="cover" alt="">
</div></section>
<!-- -->
<section class="slide impact"><div>
<div>
<p>“how can I make my website<br>work on <strong>touch devices</strong>?”</p>
</div>
</div></section>
<!-- -->
<section class="slide impact"><div>
<div>
<p>you <strong>don't</strong> need <strong>touch events</strong><br>browsers <strong>emulate</strong> regular <strong>mouse events</strong></p>
</div>
</div></section>
<!-- -->
<section class="slide"><div>
<img src="pictures/ios7/event-listener-mouse-before.png" alt="">
<p><a target="_blank" rel="noopener" href="https://patrickhlauke.github.io/touch/tests/event-listener_mouse-only.html">patrickhlauke.github.io/touch/tests/event-listener_mouse-only.html</a></p>
</div></section>
<!-- -->
<section class="slide"><div>
<img src="pictures/ios7/event-listener-mouse-after.png" alt="">
<p><a target="_blank" rel="noopener" href="https://patrickhlauke.github.io/touch/tests/event-listener_mouse-only.html">patrickhlauke.github.io/touch/tests/event-listener_mouse-only.html</a></p>
</div></section>
<!-- -->
<section class="slide code"><div>
<h2>compatibility mouse events</h2>
<pre><code class="json">(mouseenter) > mouseover > mousemove* > mousedown >
(focus) > mouseup > click</code></pre>
<p><small>* only a single “sacrificial” <code>mousemove</code> event fired</small></p>
</div></section>
<!-- -->
<section class="slide code"><div>
<h2>on first tap</h2>
<pre><code class="json">(mouseenter) > mouseover > mousemove >
mousedown > (focus) > mouseup > click</code></pre>
<h2>subsequent taps</h2>
<pre><code class="json">mousemove > mousedown > mouseup > click</code></pre>
<h2>tapping away</h2>
<pre><code class="json">(mouseout) > (blur)</code></pre>
<p><small><code>focus</code>/<code>blur</code> only on focusable elements; subtle differences between browsers</small><br>
<a target="_blank" rel="noopener" href="https://patrickhlauke.github.io/touch/tests/results/#mobile-tablet-touchscreen-events">Mobile/tablet touchscreen activation/tap event order</a></p>
</div></section>
<!-- -->
<section class="slide impact"><div>
<div>
<p>emulation works,<br>but is <strong>limiting</strong>/<strong>problematic</strong></p>
</div>
</div></section>
<!-- -->
<section class="slide statement listing"><div>
<div>
<ol>
<li>delayed event dispatch</li>
<li>mousemove doesn't track</li>
</ol>
</div>
</div></section>
<!-- -->
<section class="slide statement listing"><div>
<div>
<ol>
<li><strong>delayed event dispatch</strong></li>
<li>mousemove doesn't track</li>
</ol>
</div>
</div></section>
<!-- -->
<section class="slide"><div>
<img src="pictures/ios7/event-listener-show-delay-before.png" alt="">
<p><a target="_blank" rel="noopener" href="https://patrickhlauke.github.io/touch/tests/event-listener_show-delay.html">patrickhlauke.github.io/touch/tests/event-listener_show-delay.html</a></p>
<p><small>less of a problem in modern browsers, but for <strong>iOS < 9.3 or older Androids</strong> still relevant</small></p>
</div></section>
<!-- -->
<section class="slide"><div>
<img src="pictures/ios7/event-listener-show-delay-after.png" alt="">
<p><a target="_blank" rel="noopener" href="https://patrickhlauke.github.io/touch/tests/event-listener_show-delay.html">patrickhlauke.github.io/touch/tests/event-listener_show-delay.html</a></p>
</div></section>
<!-- -->
<section class="slide statement listing"><div>
<div>
<ol>
<li>delayed event dispatch</li>
<li><strong>mousemove doesn't track</strong></li>
</ol>
</div>
</div></section>
<!-- -->
<section class="slide"><div>
<img src="pictures/win8/chrome-particle-party.png" alt="">
<p><a target="_blank" rel="noopener" href="https://patrickhlauke.github.io/touch/particle/2">patrickhlauke.github.io/touch/particle/2</a></p>
</div></section>
<!-- -->
<section class="slide"><div>
<img src="pictures/android/chrome-particle-party-mouse-only.png" alt="">
<p><a target="_blank" rel="noopener" href="https://patrickhlauke.github.io/touch/particle/2">patrickhlauke.github.io/touch/particle/2</a></p>
</div></section>
<!-- -->
<section class="slide impact"><div>
<div>
<p>“we need to go deeper...”</p>
</div>
</div></section>
<!-- -->
<section class="slide statement"><div>
<div>
<h2>touch events</h2>
<p>introduced by Apple, adopted in Chrome/Firefox/Opera</p>
<p><small>(and belatedly IE/Edge – more on that later)</small></p>
<p><a target="_blank" rel="noopener" href="https://www.w3.org/TR/touch-events">www.w3.org/TR/touch-events</a></p>
</div>
</div></section>
<!-- -->
<section class="slide"><div>
<img src="pictures/sites/caniuse-touch-events-current.png" alt="">
<p><a target="_blank" rel="noopener" href="https://caniuse.com/#search=touch%20events">caniuse.com: Can I use <strong>touch events</strong>?</a></p>
</div></section>
<!-- -->
<section class="slide statement"><div>
<div>
<p><code class="json">touchstart<br>
touchmove<br>
touchend<br>
touchcancel</code></p>
</div>
</div></section>
<!-- -->
<section class="slide"><div>
<img src="pictures/ios7/event-listener-all-no-timings-before.png" alt="">
<p><a target="_blank" rel="noopener" href="https://patrickhlauke.github.io/touch/tests/event-listener_all-no-timings.html">patrickhlauke.github.io/touch/tests/event-listener_all-no-timings.html</a></p>
</div></section>
<!-- -->
<section class="slide"><div>
<img src="pictures/ios7/event-listener-all-no-timings-after.png" alt="">
<p><a target="_blank" rel="noopener" href="https://patrickhlauke.github.io/touch/tests/event-listener_all-no-timings.html">patrickhlauke.github.io/touch/tests/event-listener_all-no-timings.html</a></p>
<p><small><del><a target="_blank" rel="noopener" href="https://bugs.webkit.org/show_bug.cgi?id=128534">Bug 128534 - 'mouseenter' mouse compat event not fired...</a></del></small></p>
</div></section>
<!-- -->
<section class="slide code"><div>
<h2>events fired on tap</h2>
<pre><code class="json">touchstart > [touchmove]+ > touchend >
(mouseenter) > mouseover > mousemove > mousedown >
(focus) > mouseup > click</code></pre>
<p><small>(mouse events only fired for single-finger tap)</small></p>
</div></section>
<!-- -->
<section class="slide code"><div>
<h2>on first tap</h2>
<pre><code class="json">touchstart > [touchmove]+ > touchend >
(mouseenter) > mouseover > mousemove > mousedown >
(focus) > mouseup > click</code></pre>
<h2>subsequent taps</h2>
<pre><code class="json">touchstart > [touchmove]+ > touchend >
mousemove > mousedown > mouseup > click</code></pre>
<h2>tapping away</h2>
<pre><code class="json">mouseout > (mouseleave) > (blur)</code></pre>
</div></section>
<!-- -->
<section class="slide listing"><div>
<ul>
<li>too many <code>touchmove</code> events prevent mouse compatibility events after <code>touchend</code> (not considered a "clean" tap)</li>
<li>too many <code>touchmove</code> events on activatable elements can lead to <code>touchcancel</code> (in old Chrome/Browser versions)</li>
<li>not all browsers consistently send <code>touchmove</code></li>
<li>differences in <code>focus</code> / <code>blur</code> and some mouse compatibility events (e.g. <code>mouseenter</code> / <code>mouseleave</code>)</li>
<li>some events may only fire when tapping away to another focusable element (e.g. <code>blur</code>)
</ul>
<p>some browsers outright weird...</p>
</div></section>
<!-- -->
<section class="slide code"><div>
<h2>Browser/Android 4.3</h2>
<pre><code class="json"><mark>mouseover</mark> > <mark>mousemove</mark> > touchstart > touchend >
mousedown > mouseup > click</code></pre>
<h2>Browser/Blackberry PlayBook 2.0</h2>
<pre><code class="json">touchstart > <mark>mouseover</mark> > <mark>mousemove</mark> > <mark>mousedown</mark> >
touchend > mouseup > click</code></pre>
<h2>UC Browser 10.8/Android 6</h2>
<pre><code class="json"><mark>mouseover</mark> > <mark>mousemove</mark> > touchstart > (touchmove)+ > touchend >
mousedown > focus > mouseup > click</code></pre>
</div></section>
<!-- -->
<section class="slide"><div>
<img src="pictures/sites/patrickhlauke-github-touch-results.png" alt="">
<p><a target="_blank" rel="noopener" href="https://patrickhlauke.github.io/touch/tests/results/">Touch/pointer events test results</a></p>
</div></section>
<!-- -->
<section class="slide statement"><div>
<div>
<p><strong>shouldn't</strong> affect your code, unless you're expecting a very <strong>specific sequence</strong>...</p>
</div>
</div></section>
<!-- -->
<section class="slide impact"><div>
<div>
<p><code><interlude ></code></p>
<p>simple <strong>feature detection</strong> for touch events</p>
</div>
</div></section>
<!-- -->
<section class="slide code"><div>
<pre><code class="js">/* feature detection for touch events */
if (<mark>'ontouchstart' in window</mark>) {
/* some clever stuff here */
}
/* older browsers have flaky support so more
hacky tests needed...use <mark>Modernizr.touch</mark> or similar */</code></pre>
</div></section>
<!-- -->
<section class="slide"><div>
<img src="pictures/sites/touch-detect-chrome-mobile.png" alt="">
<p><a target="_blank" rel="noopener" href="https://patrickhlauke.github.io/touch/tests/touch-feature-detect.html">patrickhlauke.github.io/touch/tests/touch-feature-detect.html</a></p>
</div></section>
<!-- -->
<section class="slide code"><div>
<pre><code class="js">/* conditional "touch OR mouse/keyboard" event binding */
<mark>if ('ontouchstart' in window)</mark> {
// set up event listeners for touch
...
} <mark>else</mark> {
// set up event listeners for mouse/keyboard
...
}
</code></pre>
</div></section>
<!-- -->
<section class="slide cover impact"><div>
<div><p>don't make it touch-exclusive</p></div>
<img src="pictures/backgrounds/background-danger-415-volts.jpg" class="cover" alt="">
</div></section>
<!-- -->
<section class="slide impact"><div>
<div>
<p>hybrid devices<br>touch <strong>+</strong> mouse <strong>+</strong> keyboard</p>
</div>
</div></section>
<!-- -->
<section class="slide singlepicture"><div>
<div>
<img src="pictures/backgrounds/windows-2-in-1-touch-laptop.jpg" alt="Windows 2-in-1 touchscreen laptop/tablet devices">
</div>
</div></section>
<!-- -->
<section class="slide singlepicture"><div>
<div>
<img src="pictures/backgrounds/window-touch-desktop.jpg" alt="All-in-one windows desktop device with touchscreen">
</div>
</div></section>
<!-- -->
<section class="slide"><div>
<img src="pictures/sites/twitter-patrickhlauke-flickr-touch.png" alt="Tweet: a quick video showing the issue of naive 'if touch events then simply assume touch only' in flickr">
<p><a target="_blank" rel="noopener" href="https://twitter.com/patrick_h_lauke/status/717781821468098562">@patrick_h_lauke showing a naive "touch or mouse" issue on Flickr</a><br><small>(which has since been fixed)</small></p>
</div></section>
<!-- -->
<section class="slide"><div>
<img src="pictures/sites/bugzilla-sites-with-touch.png" alt="Bugzilla">
<p><a target="_blank" rel="noopener" href="https://bugzilla.mozilla.org/show_bug.cgi?id=888304">Bug 888304 - touch-events on Firefox-desktop should be disabled until we can support them...</a>
</div></section>
<!-- -->
<section class="slide"><div>
<img src="pictures/sites/chromium-issue392584-enable-touchevent-api-all-the-time.png" alt="">
<p><a target="_blank" rel="noopener" href="https://bugs.chromium.org/p/chromium/issues/detail?id=392584">Issue 392584: TouchEvent API should be enabled consistently</a></p>
</div></section>
<!-- -->
<section class="slide"><div>
<img src="pictures/sites/touch-detect-chrome-firefox-edge-desktop.png" alt="">
<p>Chrome now returns <code>window.TouchEvent</code> on non-touch devices</p>
<p><a target="_blank" rel="noopener" href="https://patrickhlauke.github.io/touch/tests/touch-feature-detect.html">patrickhlauke.github.io/touch/tests/touch-feature-detect.html</a></p>
</div></section>
<!-- -->
<section class="slide impact"><div>
<div>
<p>even on <strong>"mobile"</strong> we can have multiple inputs...</p>
</div>
</div></section>
<!-- -->
<section class="slide singlepicture"><div>
<div>
<img src="pictures/htc-hero-android-2.1/photo-htc-hero-product-shot.jpg" alt="HTC Hero touchscreen phone with built-in trackball">
</div>
</div></section>
<!-- -->
<section class="slide singlepicture"><div>
<div>
<img src="pictures/backgrounds/htc-wildfire-mouse.jpg" alt="">
<p>HTC Wildfire with optical trackball sends mouse events...</p>
</div>
</div>
</section>
<!-- -->
<section class="slide singlepicture"><div>
<div>
<img src="pictures/android/photo-android-laptops.jpg" alt="Android tablet-based laptops">
</div>
</div></section>
<!-- -->
<section class="slide"><div>
<div>
<img src="pictures/backgrounds/windows-continuum.jpg" alt="Windows 10 Mobile phone using 'Continuum' - with a connected screen, mouse and keyboard">
<p><a target="_blank" rel="noopener" href="https://www.microsoft.com/en-us/windows/Continuum">Windows 10 "Continuum"</a> <small>(mobile device acting as desktop)</small></p>
</div>
</div></section>
<!-- -->
<section class="slide"><div>
<div>
<img src="pictures/backgrounds/samsung-dex.jpg" alt="Samsung Galaxy S8 plugged into a DeX Station - with a connected screen, mouse and keyboard">
<p><a target="_blank" rel="noopener" href="http://www.samsung.com/global/galaxy/apps/samsung-dex/">Samsung DeX</a> <small>(mobile device acting as desktop)</small></p>
<p><small><a target="_blank" rel="noopener" href="https://medium.com/samsung-internet-dev/samsung-dex-brings-a-new-dimension-to-the-mobile-web-f80d7edcab29">Samsung DeX brings a new Dimension to the Mobile Web</a></small></p>
</div>
</div></section>
<!-- -->
<section class="slide"><div>
<img src="pictures/backgrounds/photo-android-mouse.jpg" alt="">
<p>Android + mouse – <strong>like touch</strong> (mouse emulating touch)</p>
<p><code class="json">touchstart > touchend > mouseover > mousemove >
mousedown > (focus) > mouseup > click</code></p>
</div></section>
<!-- -->
<section class="slide"><div>
<img src="pictures/backgrounds/photo-android-chrome59-mouse.jpg" alt="">
<p>Android + Chrome 58 + mouse – <strong>like desktop</strong></p>
<p>mouse events (+ pointer events) + <code>click</code></p>
<p><a target="_blank" rel="noopener" href="https://groups.google.com/a/chromium.org/forum/m/#!msg/blink-dev/cNaFvMaYtNA/41Bstx8oAwAJ">blink-dev: mouse on Android stops firing TouchEvents</a></p>
</div></section>
<!-- -->
<section class="slide"><div>
<img src="pictures/backgrounds/photo-playbook-mouse.jpg" alt="">
<p>Blackberry PlayBook 2.0 + mouse – <strong>like desktop</strong></p>
<p><code class="json">mouseover > mousedown > (mousemove)+ > mouseup > click</code></p>
</div></section>
<!-- -->
<section class="slide"><div>
<img src="pictures/backgrounds/photo-blackberry-leap-mouse.jpg" alt="">
<p>Blackberry Leap (BBOS 10.1) + mouse – <strong>like desktop</strong></p>
<p><code class="json">mouseover > mousedown > (mousemove)+ > mouseup > click</code></p>
</div></section>
<!-- -->
<section class="slide"><div>
<img src="pictures/backgrounds/photo-android-keyboard.jpg" alt="">
<p>Android + keyboard – <strong>like desktop</strong></p>
<p><code class="json">focus / click / blur</code></p>
</div></section>
<!-- -->
<section class="slide statement"><div>
<div>
<p>iOS keyboard by default only works in same situations as on-screen keyboard<br>
<small>(e.g. text inputs, URL entry)</small></p>
</div>
</div></section>
<!-- -->
<section class="slide"><div>
<img src="pictures/ios13/ios-accessibility-keyboard.jpg" alt="">
<p>iOS13+ enable full keyboard access (equivalent to desktop keyboard support)</p>
<p><code>Settings > Accessibility > Keyboard > Full Keyboard Access</code></p>
</div></section>
<!-- -->
<section class="slide"><div>
<img src="pictures/ios13/ios13-keyboard-button-events.png" alt="">
<p>iOS + keyboard – keyboard, touch, pointer, and mouse events</p>
<p><small><code class="json">focus > pointerover > pointerenter > touchstart > mouseover > mouseenter > gotpointercapture > pointerup > lostpointercapture > mouseout > mouseleave > pointerout > pointerleave > touchend > mousedown > mouseup > click</code></small></p>
</div></section>
<!-- -->
<section class="slide statement"><div>
<div>
<p>mobile Assistive Technologies<br>
<small>(e.g. screen readers on touchscreen devices)</small></p>
</div>
</div></section>
<!-- -->
<section class="slide"><div>
<img src="pictures/ios7/voiceover-event-listener-all-no-timings-after.png" alt="">
<p>iOS + VoiceOver (with/without keyboard) – <strong>similar to touch</strong></p>
<p><code class="json">focus / touchstart > touchend > (mouseenter) > mouseover > mousemove > mousedown > blur > mouseup > click</code></p>
</div></section>
<!-- -->
<section class="slide"><div>
<img src="pictures/android/android4.3-chrome-talkback-activate.png" alt="">
<p>Android 4.3/Chrome + TalkBack – <strong>keyboard/mouse hybrid</strong></p>
<p><code class="json">focus / blur > mousedown > mouseup > click > focus</code></p>
</div></section>
<!-- -->
<section class="slide"><div>
<img src="pictures/android/android6.1-chrome-talkback-activate.png" alt="">
<p>Android 6.1/Chrome + TalkBack – <strong>like touch</strong></p>
<p><code class="json">touchstart > touchend > mouseover > mouseenter > mousemove > mousedown > focus > mouseup > click</code></p>
</div></section>
<!-- -->
<section class="slide"><div>
<img src="pictures/android/android6.1-firefox-talkback-activate.png" alt="">
<p>Android 6.1/Firefox + TalkBack – <strong>similar to touch</strong></p>
<p><code class="json">touchstart > mousedown > focus > <strong>touchend</strong> > mouseup > click</code></p>
</div></section>
<!-- -->
<section class="slide listing"><div>
<h2>further scenarios?</h2>
<ul>
<li>desktop with external touchscreen</li>
<li>touchscreen laptop with non-touch second screen</li>
<li>touchscreen laptop with trackpad/mouse</li>
<li>...and other permutations?</li>
</ul>
</div></section>
<!-- -->
<section class="slide listing"><div>
<h2>note on trackpad gestures</h2>
<ul>
<li>trackpads that allow multi-finger gestures (e.g. recent MacBooks, Magic Mouse/Trackpad, Windows precision trackpad, ASUS Smart Gesture, Wacom Intuos Pro gestures etc) <strong>don't fire touch events</strong> / expose touch points</li>
<li>these gestures are handled directly by the OS/driver and don't reach the browser as raw touches</li>
<li>Wacom Intuos Pro touch input exposed as mouse to OS</li>
<li>OS X/Safari 9.1+ does fire <a target="_blank" rel="noopener" href="https://developer.apple.com/library/ios/documentation/AppleApplications/Reference/SafariWebContent/HandlingEvents/HandlingEvents.html#//apple_ref/doc/uid/TP40006511-SW23">Apple's proprietary <code>gesture*</code> events</a> (for pinch-to-zoom, rotation)</li>
</ul>
</div></section>
<!-- -->
<section class="slide impact"><div>
<div>
<p>no way to detect these cases...</p>
</div>
</div></section>
<!-- -->
<section class="slide"><div>
<img src="pictures/sites/github-modernizr-detects-touch-events-not-touch-screens.png" alt="">
<p><a target="_blank" rel="noopener" href="https://github.com/modernizr/modernizr/issues/548"><code>Modernizr.touch</code> detects touch events not touch devices</a>
</div></section>
<!-- -->
<section class="slide"><div>
<img src="pictures/sites/github-modernizr-detecting-a-mouse-user.png" alt="">
<p><a target="_blank" rel="noopener" href="https://github.com/Modernizr/Modernizr/issues/869">Modernizr: Detecting a mouse user</a></p>
</div></section>
<!-- -->
<section class="slide"><div>
<img src="pictures/sites/stucox-you-cant-detect-a-touchscreen.png" alt="">
<p><a target="_blank" rel="noopener" href="http://www.stucox.com/blog/you-cant-detect-a-touchscreen/">Stu Cox: You can't detect a touchscreen</a></p>
</div></section>
<!-- -->
<section class="slide"><div>
<img src="pictures/sites/hacks-mozilla-detecting-touch-why-not-how.png" alt="">
<p><a target="_blank" rel="noopener" href="https://hacks.mozilla.org/2013/04/detecting-touch-its-the-why-not-the-how/">hacks.mozilla.org - Detecting touch [...]</a></p>
</div></section>
<!-- -->
<section class="slide code"><div>
<pre><code class="js">/* feature detection for touch events */
if ('ontouchstart' in window) {
<mark> /* browser supports touch events but user is
not necessarily using touch (exclusively) */</mark>
<mark> /* it could be a mobile, tablet, desktop, fridge ... */</mark>
}
</code></pre>
</div></section>
<!-- -->
<section class="slide impact"><div>
<div>
<p>touch <strong>or</strong> mouse <strong>or</strong> keyboard</p>
</div>
</div></section>
<!-- -->
<section class="slide impact"><div>
<div>
<p>touch <strong>and</strong> mouse <strong>and</strong> keyboard</p>
</div>
</div></section>
<!-- -->
<section class="slide statement"><div>
<div>
<p>what about<br><strong>CSS4 Media Queries</strong>?</p>
</div>
</div></section>
<!-- -->
<section class="slide"><div>
<img src="pictures/sites/w3c-media-queries-level4.png" alt="">
<p><a target="_blank" rel="noopener" href="https://drafts.csswg.org/mediaqueries-4/">W3C Media Queries Level 4 (Editor's Draft)</a></p>
</div></section>
<!-- -->
<section class="slide code"><div>
<h2>Interaction Media Features</h2>
<p><code>pointer</code> / <code>hover</code> relate to “primary” pointing device<br><code>any-pointer</code> / <code>any-hover</code> relate to all pointing devices</p>
<pre><code class="css">
/* the <mark><strong>primary input</strong></mark> is ... */
@media (pointer: fine) { /* a mouse, stylus, ... */ }
@media (pointer: coarse) { /* a touchscreen, ... */ }
@media (pointer: none) { /* not a pointer (e.g. d-pad) */ }
@media (hover: hover) { /* hover-capable */ }
@media (hover: none) { /* not hover-capable */ }
</code></pre>
<p><small><a target="_blank" rel="noopener" href="https://lists.w3.org/Archives/Public/www-style/2016Feb/0041.html"><code>hover: on-demand</code> / <code>any-hover: on-demand</code> removed in recent drafts</a></small></p>
</div></section>
<!-- -->
<section class="slide code"><div>
<h2>Interaction Media Features</h2>
<p><code>pointer</code> / <code>hover</code> relate to “primary” pointing device<br><code>any-pointer</code> / <code>any-hover</code> relate to all pointing devices</p>
<pre><code class="css">
/* across <mark><strong>all detected pointing devices</strong></mark> at least one is ... */
@media (any-pointer: fine) { /* a mouse, stylus, ... */ }
@media (any-pointer: coarse) { /* a touchscreen, ... */ }
@media (any-pointer: none) { /* <mark><strong>none of them</strong></mark> are pointers */ }
@media (any-hover: hover) { /* hover-capable */ }
@media (any-hover: none) { /* <mark><strong>none of them</strong></mark> are hover-capable */ }
</code></pre>
<p><small><a target="_blank" rel="noopener" href="https://lists.w3.org/Archives/Public/www-style/2016Feb/0041.html"><code>hover: on-demand</code> / <code>any-hover: on-demand</code> removed in recent drafts</a></small></p>
</div></section>
<!-- -->
<section class="slide"><div>
<img src="pictures/sites/caniuse-interaction-media-features.png" alt="">
<p><a target="_blank" rel="noopener" href="https://caniuse.com/#search=interaction%20media%20features">caniuse.com: Can I use <strong>interaction media features</strong>?</a></p>
<p><a target="_blank" rel="noopener" href="https://developer.mozilla.org/en-US/docs/Web/CSS/Media_Queries/Using_media_queries#-moz-touch-enabled"><code>-moz-touch-enabled</code> in Firefox</a></p>
</div></section>
<!-- -->
<section class="slide code"><div>
<h2>Media Features and JavaScript</h2>
<pre><code class="js">
if (window.matchMedia("(any-pointer:coarse)").matches) { ... }
/* listen for dynamic changes */
window.matchMedia("(any-pointer:coarse)")↵
.onchange = function(e) { ... }
window.matchMedia("(any-pointer:coarse)")↵
.addEventListener("change", function(e) { ... } , false }
window.matchMedia("(any-pointer:coarse)")↵
.removeEventListener("change", function(e) { ... } , false }
</code></pre>
</div></section>
<!-- -->
<section class="slide"><div>
<img src="pictures/sites/caniuse-matchmedia.png" alt="">
<p><a target="_blank" rel="noopener" href="https://caniuse.com/#search=matchMedia">caniuse.com: Can I use <strong><code>matchMedia</code></strong>?</a></p>
</div></section>
<!-- -->
<section class="slide"><div>
<img src="pictures/sites/css-tricks-interaction-media-features.png" alt="">
<p><a target="_blank" rel="noopener" href="https://css-tricks.com/interaction-media-features-and-their-potential-for-incorrect-assumptions/">CSS-Tricks - Interaction Media Features and their potential (for incorrect assumptions)</a></p>
</div></section>
<!-- -->
<section class="slide"><div>
<img src="pictures/sites/css4-interaction-media-features-phone-mouse.png" alt="CSS4 Interaction Media Features tests on a touchscreen phone, with and without a paired bluetooth mouse - primary input remains touchscreen (so pointer:coarse and hover:on-demand), but additional capabilities of mouse are detected (any-pointer:fine and hover:hover also evaluated to true)">
<p><a target="_blank" rel="noopener" href="https://patrickhlauke.github.io/touch/pointer-hover-any-pointer-any-hover/">patrickhlauke.github.io/touch/pointer-hover-any-pointer-any-hover</a></p>
<p><small>primary input is unchanged (and Chrome/Android required full restart – <a href="https://bugs.chromium.org/p/chromium/issues/detail?id=442418">Issue 442418</a>)</small></p>
</div></section>
<!-- -->
<section class="slide code"><div>
<pre><code class="css">/* Naive uses of Interaction Media Features */
@media (pointer: fine) {
/* primary input has fine pointer precision...
so make all buttons/controls small? */
}
@media (hover: hover) {
/* primary input has hover...so we can rely on it? */
}
/* pointer and hover only check "primary" input, but
what if there's a secondary input that lacks capabilities? */</code></pre>
</div></section>
<!-- -->
<section class="slide code"><div>
<pre><code class="css">/* Better uses of Interaction Media Features */
@media (any-pointer: coarse) {
/* at least one input has coarse pointer precision...
provide larger buttons/controls for touch */
}
/* test for *any* "least capable" inputs (primary or not) */
<del>@media (any-hover: none) {</del>
<del>/* at least one input lacks hover capability...</del>
<del>don't rely on it or avoid altogether */</del>
<del>}</del>
</code></pre>
<p><small>Limitation: <a target="_blank" rel="noopener" href="https://github.com/w3c/csswg-drafts/issues/841">[mediaqueries-4] any-hover can't be used to detect mixed hover and non-hover capable pointers</a>. Also, <code>pointer</code>/<code>hover</code>/<code>any-pointer</code>/<code>any-hover</code> don't cover non-pointer inputs (e.g. keyboards) – <strong>always assume non-hover-capable inputs</strong></small></p>
</div></section>
<!-- -->
<section class="slide statement"><div>
<div>
<p>detect which input the users is using <strong>right now</strong>...</p>
</div>
</div></section>
<!-- -->
<section class="slide"><div>
<img src="pictures/sites/github-what-input.png" alt="">
<p><a target="_blank" rel="noopener" href="https://github.com/ten1seven/what-input">GitHub: ten1seven / what-input</a></p>
</div></section>
<!-- -->
<section class="slide"><div>
<img src="pictures/sites/what-input-demo.png" alt="">
<p><a target="_blank" rel="noopener" href="http://ten1seven.github.io/what-input/">Demo: What Input?</a></p>
</div></section>
<!-- -->
<section class="slide singlepicture"><div>
<div>
<img src="pictures/win10/office-2013-mouse-touch-switch.png" alt="Office 2013 in Windows offers a 'Touch/Mouse mode' switch - shown by default on touch-capable devices, but can be accessed even on mouse-only devices; switching to touch mode increases spacing and touch target of all ribbon controls">
<p>if in doubt, offer a way to switch interfaces...<br>or just <strong>always use a touch-optimised interface</strong></p>
</div>
</div></section>
<!-- -->
<section class="slide statement"><div>
<div>
<p><code></ interlude ></code></p>
</div>
</div></section>
<!-- -->
<section class="slide impact"><div>
<div>
<p>touch events<br><strong>vs</strong><br><strong>limitations</strong>/<strong>problems</strong></p>
</div>
</div></section>
<!-- -->
<section class="slide statement listing"><div>
<div>
<ol>
<li>delayed event dispatch</li>
<li>mousemove doesn't track</li>
</ol>
</div>
</div></section>
<!-- -->
<section class="slide statement listing"><div>
<div>
<ol>
<li><strong>delayed event dispatch</strong></li>
<li>mousemove doesn't track</li>
</ol>
</div>
</div></section>
<!-- -->
<section class="slide"><div>
<img src="pictures/ios7/event-listener-show-delay-after.png" alt="">
<p><a target="_blank" rel="noopener" href="https://patrickhlauke.github.io/touch/tests/event-listener_show-delay.html">patrickhlauke.github.io/touch/tests/event-listener_show-delay.html</a></p>
<p><small>less of a problem in modern browsers, but for <strong>iOS < 9.3 or older Androids</strong> still relevant</small></p>
</div></section>
<!-- -->
<section class="slide impact"><div>
<div>
<p>why the delay?<br><strong>double-tap to zoom</strong><br><small>(mostly anyway)</small></p>
</div>
</div></section>
<!-- -->
<section class="slide impact"><div>
<div>
<p><strong>when</strong> does the delay happen?</p>
</div>
</div></section>
<!-- -->
<section class="slide"><div>
<img src="pictures/ios7/event-listener-all-before.png" alt="">
<p><a target="_blank" rel="noopener" href="https://patrickhlauke.github.io/touch/tests/event-listener.html">patrickhlauke.github.io/touch/tests/event-listener.html</a></p>
</div></section>
<!-- -->
<section class="slide"><div>
<img src="pictures/ios7/event-listener-all-after.png" alt="">
<p><a target="_blank" rel="noopener" href="https://patrickhlauke.github.io/touch/tests/event-listener.html">patrickhlauke.github.io/touch/tests/event-listener.html</a></p>
</div></section>
<!-- -->
<section class="slide code"><div>
<h2>touch / mouse events delay</h2>
<pre><code class="json">touchstart > [touchmove]+ > touchend >
<mark>[300ms delay]</mark>
(mouseenter) > mouseover > mousemove > mousedown >
(focus) > mouseup > click</code></pre>
</div></section>
<!-- -->
<section class="slide impact"><div>
<div>
<p>“how can we make it feel <strong>responsive</strong> like a native app?”</p>
</div>
</div></section>
<!-- -->
<section class="slide impact"><div>
<div>
<p>react to events fired <strong>before</strong> the 300ms delay...</p>
</div>
</div></section>
<!-- -->
<section class="slide statement"><div>
<div>
<p><code>touchstart</code> for an “immediate” control<br><small>(e.g. fire/jump button on a game)</small></p>
</div>
</div></section>
<!-- -->
<section class="slide statement"><div>
<div>
<p><code>touchend</code> for a control that fires after finger lifted</p>
<p><small>(but this can result in events firing after zoom/scroll)</small></p>
</div>
</div></section>
<!-- -->
<section class="slide cover impact"><div>
<div><p>don't make it touch-exclusive</p></div>
<img src="pictures/backgrounds/background-danger-415-volts.jpg" class="cover" alt="">
</div></section>
<!-- -->
<section class="slide code"><div>
<pre><code class="js">/* DON'T DO THIS:
conditional "touch OR mouse/keyboard" event binding */
<mark>if ('ontouchstart' in window)</mark> {
// set up event listeners for touch
foo.addEventListener('touchend', ...);
...
} <mark>else</mark> {
// set up event listeners for mouse/keyboard
foo.addEventListener('click', ...);
...
}
</code></pre>
</div></section>
<!-- -->
<section class="slide"><div>
<img src="pictures/win10/chrome-naive-touch-or-mouse-touchscreen-desktop.png" alt="">
<p><a target="_blank" rel="noopener" href="https://patrickhlauke.github.io/touch/tests/event-listener_naive-touch-or-mouse.html">patrickhlauke.github.io/touch/tests/event-listener_naive-touch-or-mouse.html</a></p>
</div></section>
<!-- -->
<section class="slide code"><div>