From de5327477abcb2be841e793db97f13651489aec0 Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Tue, 28 Feb 2023 10:25:51 +0100 Subject: [PATCH] web: Fix position of touch events to be relative to the canvas Use the same logic as for mouse events when not captured. --- CHANGELOG.md | 1 + src/platform_impl/web/web_sys/event.rs | 8 ++------ 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 74f7045a..29d2dd80 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -49,6 +49,7 @@ And please only add new entries to the top of this list, right below the `# Unre - On Wayland, drop `WINIT_WAYLAND_CSD_THEME` variable. - Implement `PartialOrd` and `Ord` on types in the `dpi` module. - Bump MSRV from `1.60` to `1.64`. +- Web: Fix position of touch events to be relative to the canvas. # 0.28.6 diff --git a/src/platform_impl/web/web_sys/event.rs b/src/platform_impl/web/web_sys/event.rs index cdfeea2c..a1e7d6f4 100644 --- a/src/platform_impl/web/web_sys/event.rs +++ b/src/platform_impl/web/web_sys/event.rs @@ -127,10 +127,6 @@ pub fn mouse_modifiers(event: &MouseEvent) -> ModifiersState { state } -pub fn touch_position(event: &PointerEvent, _canvas: &HtmlCanvasElement) -> LogicalPosition { - // TODO: Should this handle more, like `mouse_position_by_client` does? - LogicalPosition { - x: event.client_x() as f64, - y: event.client_y() as f64, - } +pub fn touch_position(event: &PointerEvent, canvas: &HtmlCanvasElement) -> LogicalPosition { + mouse_position_by_client(event, canvas) }