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

Order of pointerover/enter/move and corresponding mouse events is different on browsers #454

Closed
saschanaz opened this issue Jul 6, 2022 · 8 comments · Fixed by #458 or #459
Closed
Assignees
Labels

Comments

@saschanaz
Copy link
Member

saschanaz commented Jul 6, 2022

data:text/html,<input id=input><script>input.onpointerenter = input.onmouseenter = input.onpointerleave = input.onmouseleave = input.onpointerover = input.onmouseover = input.onpointerout = input.onmouseout = input.onpointermove = input.onmousemove = ev =>console.log(ev.type)</script>

When hovering over the input, the console output is:

Chrome: pointerover->pointerenter->mouseover->mouseenter->pointermove->mousemove->pointerout->pointerleave->mouseout->mouseleave
Firefox: pointerover->pointerenter->pointermove->mouseover->mouseenter->mousemove->pointerout->pointerleave->mouseout->mouseleave
Safari: pointerover->mouseover->pointerenter->mouseenter->pointermove->mousemove->pointerout->mouseout->pointerleave->mouseleave

Somehow the timing that pointermove and mousemove appear is different.

  • The pointer/mousemove happens immediately on pointerenter on all browsers
  • Events are somehow grouped on Firefox and Chrome (pointerover+pointerenter always happen together without a compatibility event between it, for example)
  • And the grouping behaviors are different.

I'm not quite sure this grouping is specced. https://w3c.github.io/pointerevents/#mapping-for-devices-that-support-hover looks like it doesn't even give the mapping for over/enter/out/leave.

@saschanaz saschanaz changed the title Order of pointerover/enter/move and corresponding mouse events is different on Firefox/Chrome Order of pointerover/enter/move and corresponding mouse events is different on browsers Jul 6, 2022
@patrickhlauke
Copy link
Member

@flackr @smaug---- @mustaqahmed would be interested in your thoughts on this. i don't think there was a rationale for omitting the over/enter/out/leave from the mapping for hover-capable pointers ... was it just an oversight?

on the question of exact timing, I think the spec leaves that generally unspecified, only suggesting the order in that large note in https://w3c.github.io/pointerevents/#mapping-for-devices-that-do-not-support-hover ... maybe we could do with a matching note in https://w3c.github.io/pointerevents/#mapping-for-devices-that-support-hover as well? it would still be non-normative, but could at least give an indication - or the note that's currently there could be generalised to apply to both cases, with some tweaks

@mustaqahmed
Copy link
Member

The spec deliberately leaves out a direct mapping between pointer/mouse pointers for over/enter/out/leave events because the compat mouseover/enter/out/leave events must appear consistent to a mouse-events based app (that doesn't listen to Pointer Events) even when we have simultaneous primary pointers of different types ("mouse", "touch" and "pen"). The core requirement here is that the compat event sequence must consistently represent the movement of a single legacy mouse when multiple pointer-types are active at the same time. Let's look closely at an example.

Consider a mouse-press on button A followed by a touch-down a button B, before neither the mouse nor the touch is released. If we ignore the compat mouse events for a moment, the outcome is obvious:

  • the first action would fire pointerover, pointerenter and pointerdown at A with pointerType="mouse", and
  • the second action would fire pointerover, pointerenter and pointerdown at B with pointerType="touch".

Now the compat mouse events seen by buttons A and B must include the transition of a single legacy mouse pointer from A to B before the second action, so:

  • the first action would fire mouseover, mouseenter and mousedown at A, and
  • the second action would fire mouseout and mouseleave at A, followed by mouseover, mouseenter and mousedown at B.

Section 11.1 was added to clarify this idea but the discussion in this issue suggests that a textual description is not enough to explain the complexity here! Perhaps we need to add an example with a diagram?

@mustaqahmed mustaqahmed self-assigned this Aug 3, 2022
@mustaqahmed
Copy link
Member

To attempt to clarify the spec, @kevers-google helped me create this CSS animation:
https://mustaqahmed.github.io/web/pe-legacy-pointer-animation/legacy-pointer-animation.html

I am proposing to add this to the spec as a helpful note. If the spec text doesn't "like" CSS animations, we can add an animated GIF instead.

@mustaqahmed
Copy link
Member

@flackr @patrickhlauke I just updated the tap timing of the above animation as per our PEWG discussion today.

patrickhlauke added a commit that referenced this issue Oct 24, 2022
…re recognition

Related to the discussion started in #454
patrickhlauke added a commit that referenced this issue Oct 24, 2022
…re recognition

Related to the discussion started in #454
patrickhlauke added a commit that referenced this issue Oct 24, 2022
…re recognition

Related to the discussion started in #454
patrickhlauke added a commit that referenced this issue Oct 24, 2022
* Explain the rationale/thinking behind compat events (to represent a consistent legacy mouse pointer)
* Add note about high level "interleaved" events, and the reality of what user agents may do, especially on touchscreens, as long as the relative order is consistent

Closes #454
patrickhlauke added a commit that referenced this issue Oct 24, 2022
* Explain the rationale/thinking behind compat events (to represent a consistent legacy mouse pointer)
* Add note about high level "interleaved" events, and the reality of what user agents may do, especially on touchscreens, as long as the relative order is consistent

Closes #454
patrickhlauke added a commit that referenced this issue Oct 24, 2022
* Add note about high level "interleaved" events, and the reality of what user agents may do, especially on touchscreens, as long as the relative order is consistent

Closes #454
mustaqahmed pushed a commit that referenced this issue Oct 27, 2022
Expand explanation for compatibility mouse events

Add note about high level "interleaved" events, and the reality of what user agents may do while maintaining a consistent the relative order.

Closes #454

based on @mustaqahmed's suggestion
@saschanaz
Copy link
Member Author

@mustaqahmed So #458 added the explanation why pointerout does not directly match to mouseout, but does it actually resolve the original post?

@patrickhlauke
Copy link
Member

@saschanaz see also #459 which I think more directly addresses the original post?

@saschanaz
Copy link
Member Author

Ah, missed that one. Thank you!

@patrickhlauke
Copy link
Member

No worries, we managed to confuse ourselves while working on these two related aspects ;)
I assume then that #459 answers the OP to your satisfaction?

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