Skip to content

Should "click", "dblclick" and "contextmenu" events be PointerEvents? #100

Closed

Description

@RByers

@dtapuska just noticed that Edge sends click as an instance of PointerEvent, not just MouseEvent. I think we've agreed before that this was a good idea, but I don't think we've talked about speccing it.

I think we can just add a short section to the PE spec "upgrading" click to PointerEvent. Also dblclick and contextmenu. @teddink, that's it right? I didn't check drag events or anything.

Activity

  1. changed the title [-]Specify that `click` is a `PointerEvent`?[/-] [+]Specify that "click" is a PointerEvent?[/+] on Jul 7, 2016
  2. RByers commented on Jul 7, 2016

    @RByers
    ContributorAuthor

    By the way, for context: The main reason we've said this is desirable it that sometimes it's useful to know the pointerType of a click / contextmenu. This is similar to, but subtly distinct from, wanting to know whether the source devices also fires touch events (sourceCapabilities.firesTouchEvents).

  3. dtapuska commented on Jul 7, 2016

    @dtapuska

    In Edge I tested dragstart and the event fired has a drag prototype and the drag prototype is a mouse event prototype.

  4. NekR commented on Jul 7, 2016

    @NekR

    I agree, it sounds good to have click as a PointerEvent. It'll provide only benefits to web devs.

  5. smaug---- commented on Jul 7, 2016

    @smaug----
    Contributor

    contextmenu can be triggered also using keyboard, and click can be the default action for certain key events and click() dispatches MouseEvent click.
    So need to define what pointerType should be in each of those cases. Default is "", I guess we could use that for now.

    And HTML spec needs a change for click(), somewhere https://html.spec.whatwg.org/multipage/webappapis.html#fire-a-click-event or https://html.spec.whatwg.org/multipage/webappapis.html#fire-a-synthetic-mouse-event

  6. smaug---- commented on Jul 7, 2016

    @smaug----
    Contributor

    Changing HTML spec might be a tiny bit controversial. Other option is to add a hook to the HTML spec where other specs could extends/re-define what kinds of events should be fired for click.

  7. patrickhlauke commented on Jul 7, 2016

    @patrickhlauke
    Member

    Does Edge only "upgrade" click to a PointerEvent if it was the result of a pointer interaction? And if so, can it perhaps be defined in PE as an extension to the regular click event (leaving the HTML spec untouched)?

  8. smaug---- commented on Jul 7, 2016

    @smaug----
    Contributor

    Would be rather odd to have platform dispatching 'click' as MouseEvent in some cases but as PointerEvent in some other cases. And error prone - event listeners couldn't trust the event to have the same properties each time.

  9. changed the title [-]Specify that "click" is a PointerEvent?[/-] [+]Specify that "click", "dblclick" and "contextmenu" events are PointerEvents?[/+] on Jul 13, 2016
  10. RByers commented on Jul 13, 2016

    @RByers
    ContributorAuthor

    Looks like IE has had some version of this back to IE11. After some discussion it sounds like the design we think makes the most sense is:

    • All UA-generated click, dblclick, contextmenu events would be of type PointerEvent, with properties that match the corresponding pointer events (eg. pointerType, isPrimary).
    • click() and keyboard-initiated click/contextmenu events will have all PointerEvent properties set to their defaults (eg. pointerType="").
    • we'll treat DragEvent as a separate (low priority) issue (filed Should DragEvent be upgraded to a PointerEvent? #106).

    Next step is to check to see to what extent Edge already matches this design. @teddink says he'll do this. As @smaug---- says, specing this properly will be hard. But perhaps we can just start with something partly hacky here in the PE spec and then try to get it integrated into the correct places.

  11. jacobrossi commented on Jul 14, 2016

    @jacobrossi
    Member

    I think this is roughly what we implemented yes. I think we also want PointerEvent for your "auxclick" proposal which currently uses MouseEvent (e.g. WICG/auxclick#6).

  12. jacobrossi commented on Jul 14, 2016

    @jacobrossi
    Member
  13. RByers commented on Jul 14, 2016

    @RByers
    ContributorAuthor

    Nice, thanks! I thought this was just something we chatted about. I assume you never took that step of proposing spec changes?

  14. mustaqahmed commented on Jul 20, 2016

    @mustaqahmed
    Member

    Any chance click coordinates could be an issue if PointerEvent coordinates are all fractional (#107)? Any idea how frequent is coordinate-equality-checks with integers, like if (e.clientX == 20) ...?

  15. 38 remaining items

  16. BoCupp-Microsoft commented on Jun 12, 2019

    @BoCupp-Microsoft

    The open question on this thread seems to be about what use cases would require click, dblclick, and contextmenu to become a PointerEvent instead of a MouseEvent.

    The use cases I know of involve detecting pointerType, but I don't think its fair to say that any of these cases actually "require" these events to be PointerEvents. A developer could remember the pointerType of the last primary pointerup and use that during the click event handler to differentiate behavior. So AFAICT the value of any change seems to be simplicity, i.e. developers can write less code to get differentiated behavior based on pointerType.

    Two use cases to consider:
    Video elements commonly show controls on the first touch so that the user can then tap the pause button, adjust volume, drag the scrubber, etc. Any move of the mouse can reveal the same controls so the click anywhere on the video can just directly toggle play/pause.

    The select element of edgehtml-based Edge has touch-specific spacing for its select popup, i.e. opening the UI with your finger on a touchscreen device versus the mouse on the same device will lead to options that are spaced further apart for touch. While this UI is triggered on pointerdown I don't think its a stretch to say that any UI triggered on click or contextmenu could benefit from similar treatment.

    Some (old) evidence I found that devs want this behavior: MSDN question

    AFAICT YouTube has the differentiated behavior I describe for touch versus mouse when it comes to toggling play/pause for a video.

    Lastly, this (also old) article talks about the same pattern of turning UI that requires hover and then click into a two-touch UI:

    Make the UI take two single touch events to complete the click - the first click will show the hover information, the second will complete the action.

  17. patrickhlauke commented on Jun 12, 2019

    @patrickhlauke
    Member

    discussed on PEWG call today https://www.w3.org/2019/06/12-pointerevents-minutes.html

    concerns about potential compat problems (including switch from integer to fractional coordinates in PE), and how to treat keyboard-generated events (invent new pointerType? just leave it empty/null?). historical issue of click etc being mouse event but triggered by keyboard too, more a generic activate event...

    Chrome might make an experimental web feature where click etc are upgraded to PE and see what the potential compat impact actually is. at same time, discuss with UIEvents folks about best way forward.

  18. mustaqahmed commented on Aug 31, 2020

    @mustaqahmed
    Member

    I just realized that Chrome Experimental has click, auxclick and dblclick as PointerEvents for about a year now, without any issue. @liviutinta is currently running a trail on Canary now, we will post the outcomes when available.

    @NavidZ Wondering why the UI event change above didn't include context menu and dblclick. Did we plan to cover them later or not?

  19. NavidZ commented on Aug 31, 2020

    @NavidZ
    Member

    UI event doesn't define contextmenu event. As a matter of fact no spec defines it. WHATWG dom spec briefly mentions its existence with no actual definition. I believe I have a pull request to update that and left it unmerged until we are sure this change is okay and is here to remain.

    As for the dblclick event it is already a legacy event. People should not rely on dblclick event and instead should look into detail field of the click event for double/triple/... clicks. So we thought it was not worth the effort going after that.

  20. liviutinta commented on Oct 30, 2020

    @liviutinta
    Contributor

    Clarification for @mustaqahmed's comment on Aug 31 [4] above.

    When using [1] for testing in Chrome with ClickPointerEvent flag enabled, contextmenu is a pointer event. This is corroborated by code [2] as well as by the pointerevents spec pull request [3].

    Testing with [1] in Chrome with ClickPointerEvent flag enabled shows dblclick is a mouse event.

    [1] https://rbyers.github.io/eventTest.html
    [2] https://source.chromium.org/chromium/chromium/src/+/master:third_party/blink/renderer/core/input/mouse_event_manager.cc;drc=87a63ed093790f8c2d1751e5a3914dfb03352d21;l=307
    [3] #317 (comment)
    [4] #100 (comment)

  21. garykac commented on Nov 4, 2020

    @garykac
    Member

    Back in August, I started rewriting [1] parts of the UIEvent spec and included info about contextmenu along with hooks for PointerEvents in general.

    [1] https://w3c.github.io/uievents/event-algo.html

  22. mustaqahmed commented on Apr 13, 2021

    @mustaqahmed
    Member

    In Chrome we encountered a few regressions in the wild in the last few weeks (while slowly ramping up our experiment on Stable channel since January this year). All of the regressions are with fractional coordinates in click where the event's clientX/Y are compared directly with those of the last mousedown event to detect/ignore "dragged clicks".

    • In some cases (like crbug.com/1182909) the developer was able to update their code with our suggested workaround.
    • But we need to avoid compat problems like crbug.com/1192449.

    We decided in Chrome to ship the feature but without any change in coordinates. More precisely, click, auxclick and contextmenu events will be instances of PointerEvents but their coordinates will be integers (like MousEvents).

    Reopening the issue because I think we need to update relevant specs accordingly.

  23. patrickhlauke commented on May 15, 2021

    @patrickhlauke
    Member

    @mustaqahmed suggest we tackle this as a priority for v3 - let's discuss at the next meeting.

  24. patrickhlauke commented on May 14, 2023

    @patrickhlauke
    Member

    from a very basic check recently https://codepen.io/patrickhlauke/pen/XWxYRpv it seems that, at time of writing, only Chromium (Chrome/Win, Chrome/Android, Edge/Win, etc) has "upgraded" the click event to an actual PointerEvent.

    Gecko (Firefox/Win, Firefox/Android) and WebKit (Safari/macOS, Safari/iOS) still haven't...which is a shame, because personally as a dev, I'd be excited to know "was this click caused by mouse, stylus, touch, or something else - most likely keyboard"

  25. mustaqahmed commented on May 17, 2023

    @mustaqahmed
    Member

    We have added WPTs of the form pointerevents/.*is_a_pointerevent.* to test this: dashboard.

  26. added this to the V3 milestone on Jan 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions