Impl. mouse capturing on web target (#1672)

* Impl. mouse capturing for web-sys with PointerEvent

* Impl. mouse capturing for web-sys with MouseEvent by manual tracking

* Reorganize web-sys backend mouse and pointer handling code

* Impl. mouse capturing for stdweb with PointerEvent

* Add mouse capturing for web target to changelog
This commit is contained in:
alvinhochun 2020-08-29 21:34:33 +08:00 committed by GitHub
parent bea60930b6
commit 02a34a167a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 446 additions and 129 deletions

View file

@ -2,7 +2,7 @@ use crate::dpi::LogicalPosition;
use crate::event::{ModifiersState, MouseButton, MouseScrollDelta, ScanCode, VirtualKeyCode};
use std::convert::TryInto;
use web_sys::{KeyboardEvent, MouseEvent, WheelEvent};
use web_sys::{HtmlCanvasElement, KeyboardEvent, MouseEvent, WheelEvent};
pub fn mouse_button(event: &MouseEvent) -> MouseButton {
match event.button() {
@ -29,6 +29,17 @@ pub fn mouse_position(event: &MouseEvent) -> LogicalPosition<f64> {
}
}
pub fn mouse_position_by_client(
event: &MouseEvent,
canvas: &HtmlCanvasElement,
) -> LogicalPosition<f64> {
let bounding_client_rect = canvas.get_bounding_client_rect();
LogicalPosition {
x: event.client_x() as f64 - bounding_client_rect.x(),
y: event.client_y() as f64 - bounding_client_rect.y(),
}
}
pub fn mouse_scroll_delta(event: &WheelEvent) -> Option<MouseScrollDelta> {
let x = event.delta_x();
let y = -event.delta_y();