Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Event sequence when long tapping an image #503

Open
lpd-au opened this issue May 6, 2024 · 1 comment
Open

Event sequence when long tapping an image #503

lpd-au opened this issue May 6, 2024 · 1 comment
Labels

Comments

@lpd-au
Copy link

lpd-au commented May 6, 2024

I wrote a quick demo to see which pointer events and compatibility mouse events are fired in each mobile browser when long tapping on an <img>: https://output.jsbin.com/zeroqih

Below is what I found:

Desktop (FF mouse) Firefox Chrome Safari (wtc: none) Safari (wtc: default)
pointerover pointerover pointerover pointerover pointerover
pointerenter pointerenter pointerenter pointerenter pointerenter
pointerdown pointerdown pointerdown pointerdown
pointermove (pause) pointermove (pause) (pause)
... (approx 20-50x)
pointermove
mouseover mouseover mouseover mouseover mouseover
mouseenter mouseenter mouseenter mouseenter mouseenter
mousemove mousemove mousemove
(RMB depressed)
pointerdown
mousedown mousedown mousedown
(pause until release) (pause until release) (pause)
pointerup pointerup
mouseup
auxclick
contextmenu contextmenu contextmenu
pointercancel pointercancel pointercancel
pointerout pointerout pointerout pointerout
pointerleave pointerleave pointerleave pointerleave
mouseout
mouseleave

The notable differences from my pov are:

  1. Safari for iOS never fires a contextmenu event, despite opening a very similar image-specific menu to the Android browsers (when -webkit-touch-callout is absent).
  2. Both Android browsers fire a mousemove event but Safari for iOS always fires a mousedown event instead (although without a mouseup).
  3. No matter how precisely you lower and raise your finger, Chrome for Android fires a bunch of pointermove events (I guess for pressure changes?), whereas Firefox for Android and Safari for iOS typically fire none unless you jiggle around your finger.

Are 1 and 2 in particular currently allowed by the spec, and in the working group's opinion, should they be?

I have a legacy site that for mouse input, currently shows a html tooltip when hovering over a custom button. To provide more reasonable behaviour for touch input, I figured I'd show the tooltip when the button is either panned over or long tapped. With the differences above, this proved way more difficult than I expected:

  • Cancelling the native context menu is handled by preventing the default action of an event or adding a CSS property in different browsers.
  • The events fired when the tap has been held long enough to become a long tap are different in different browsers.
  • Even after accounting for the above two factors, some browsers will then show the tooltip almost immediately at the start of the tap because they fire pointermove events that others don't, even when the user's finger is stationary and lifting it would trigger a click event on the button. Resolving this requires listening for a 4th event type and tracking state.
@patrickhlauke
Copy link
Member

The behavior of long-tapping (and how user agents choose to map it/implement it) is not directly defined in the PE specification itself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants