Skip to content

Implement touch handling on web target(s) #1673

Description

@alvinhochun

Adding touch event handling shouldn't be too hard, but it is tightly coupled with mouse handling due to the web using a unified Pointer Event model. Here are my thoughts:

  • Grabbing touch input from PointerEvent is simple enough. However, I would be concerned about correctly mapping the pointerType :
    • "mouse" - obviously should be mapped to CursorMove, CursorEntered, CursorLeft and MouseInput. In addition, I believe that only pointers with isPrimary === true should be reported.
    • "touch" - obviously should be mapped to Touch.
    • "pen" - this is tricky, as winit does not have an event for pen/stylus. I suggest that for now we just map pen input the same way as mouse input until winit finally supports pen events properly.
    • Empty strings or unknown values - the same as mouse.
  • Supporting browsers without PointerEvent - I suggest we do not add support for TouchEvent, because:
    • PointerEvent is getting widespread support.
    • Adding TouchEvent handling will likely make the code quite complicated.
    • If the user really care about supporting older browsers, they can use a JavaScript polyfill. Turns out the polyfill does not provide offsetX/offsetY which winit is currently using...
  • Should touch input also synthesize mouse input?
    • My idea would be that, since some users may not want to go through the trouble of implementing explicit touch handling there should be an option to allow user code to disable touch support and automatically treat the primary touch input as mouse input. Otherwise, touch input will only generate touch events and not mouse events.
    • However, it seems that this is not an option for other platforms. Perhaps it makes more sense to just provide one behaviour, which is for touch input to only generate touch events and not mouse events.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DS - webAffects the Web backend (WebAssembly/WASM)S - platform parityUnintended platform differences

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions