WindowBuilderExtWebSys::with_prevent_default disables scrolling on both mobile and desktop (previously just desktop) (#2216)

* Disable scrolling on web by default but provide method in builder to enable it

* rename enable_web_scroll -> enable_web_page_scroll

* move enable_web_page_scroll into prevent_default option

* final approach

* Mark prevent_default change as breaking

Co-authored-by: Mads Marquart <mads@marquart.dk>
This commit is contained in:
Lucas Kent 2022-09-04 13:45:30 +10:00 committed by GitHub
parent ab56e9f57d
commit 0fca8b088d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 55 additions and 19 deletions

View file

@ -18,6 +18,7 @@ And please only add new entries to the top of this list, right below the `# Unre
- On Windows, added `WindowExtWindows::set_undecorated_shadow` and `WindowBuilderExtWindows::with_undecorated_shadow` to draw the drop shadow behind a borderless window.
- On Windows, fixed default window features (ie snap, animations, shake, etc.) when decorations are disabled.
- **Breaking:** On macOS, add support for two-finger touchpad magnification and rotation gestures with new events `WindowEvent::TouchpadMagnify` and `WindowEvent::TouchpadRotate`.
- **Breaking:** On web, the `WindowBuilderExtWebSys::with_prevent_default` setting (enabled by default), now additionally prevents scrolling of the webpage in mobile browsers, previously it only disabled scrolling on desktop.
- On Wayland, `wayland-csd-adwaita` now uses `ab_glyph` instead of `crossfont` to render the title for decorations.
- On Wayland, a new `wayland-csd-adwaita-crossfont` feature was added to use `crossfont` instead of `ab_glyph` for decorations.
- On Wayland, if not otherwise specified use upstream automatic CSD theme selection.

View file

@ -63,6 +63,9 @@ impl<T> EventLoopWindowTarget<T> {
let mut canvas = canvas.borrow_mut();
canvas.set_attribute("data-raw-handle", &id.0.to_string());
canvas.on_touch_start(prevent_default);
canvas.on_touch_end(prevent_default);
let runner = self.runner.clone();
canvas.on_blur(move || {
runner.send_event(Event::WindowEvent {
@ -153,22 +156,25 @@ impl<T> EventLoopWindowTarget<T> {
});
let runner = self.runner.clone();
canvas.on_cursor_move(move |pointer_id, position, delta, modifiers| {
runner.send_event(Event::WindowEvent {
window_id: RootWindowId(id),
event: WindowEvent::CursorMoved {
canvas.on_cursor_move(
move |pointer_id, position, delta, modifiers| {
runner.send_event(Event::WindowEvent {
window_id: RootWindowId(id),
event: WindowEvent::CursorMoved {
device_id: RootDeviceId(DeviceId(pointer_id)),
position,
modifiers,
},
});
runner.send_event(Event::DeviceEvent {
device_id: RootDeviceId(DeviceId(pointer_id)),
position,
modifiers,
},
});
runner.send_event(Event::DeviceEvent {
device_id: RootDeviceId(DeviceId(pointer_id)),
event: DeviceEvent::MouseMotion {
delta: (delta.x, delta.y),
},
});
});
event: DeviceEvent::MouseMotion {
delta: (delta.x, delta.y),
},
});
},
prevent_default,
);
let runner = self.runner.clone();
canvas.on_mouse_press(move |pointer_id, position, button, modifiers| {

View file

@ -21,6 +21,8 @@ mod pointer_handler;
#[allow(dead_code)]
pub struct Canvas {
common: Common,
on_touch_start: Option<EventListenerHandle<dyn FnMut(Event)>>,
on_touch_end: Option<EventListenerHandle<dyn FnMut(Event)>>,
on_focus: Option<EventListenerHandle<dyn FnMut(FocusEvent)>>,
on_blur: Option<EventListenerHandle<dyn FnMut(FocusEvent)>>,
on_keyboard_release: Option<EventListenerHandle<dyn FnMut(KeyboardEvent)>>,
@ -79,6 +81,8 @@ impl Canvas {
raw: canvas,
wants_fullscreen: Rc::new(RefCell::new(false)),
},
on_touch_start: None,
on_touch_end: None,
on_blur: None,
on_focus: None,
on_keyboard_release: None,
@ -132,6 +136,22 @@ impl Canvas {
&self.common.raw
}
pub fn on_touch_start(&mut self, prevent_default: bool) {
self.on_touch_start = Some(self.common.add_event("touchstart", move |event: Event| {
if prevent_default {
event.prevent_default();
}
}));
}
pub fn on_touch_end(&mut self, prevent_default: bool) {
self.on_touch_end = Some(self.common.add_event("touchend", move |event: Event| {
if prevent_default {
event.prevent_default();
}
}));
}
pub fn on_blur<F>(&mut self, mut handler: F)
where
F: 'static + FnMut(),
@ -262,12 +282,14 @@ impl Canvas {
}
}
pub fn on_cursor_move<F>(&mut self, handler: F)
pub fn on_cursor_move<F>(&mut self, handler: F, prevent_default: bool)
where
F: 'static + FnMut(i32, PhysicalPosition<f64>, PhysicalPosition<f64>, ModifiersState),
{
match &mut self.mouse_state {
MouseState::HasPointerEvent(h) => h.on_cursor_move(&self.common, handler),
MouseState::HasPointerEvent(h) => {
h.on_cursor_move(&self.common, handler, prevent_default)
}
MouseState::NoPointerEvent(h) => h.on_cursor_move(&self.common, handler),
}
}

View file

@ -88,13 +88,20 @@ impl PointerHandler {
));
}
pub fn on_cursor_move<F>(&mut self, canvas_common: &super::Common, mut handler: F)
where
pub fn on_cursor_move<F>(
&mut self,
canvas_common: &super::Common,
mut handler: F,
prevent_default: bool,
) where
F: 'static + FnMut(i32, PhysicalPosition<f64>, PhysicalPosition<f64>, ModifiersState),
{
self.on_cursor_move = Some(canvas_common.add_event(
"pointermove",
move |event: PointerEvent| {
if prevent_default {
event.prevent_default();
}
handler(
event.pointer_id(),
event::mouse_position(&event).to_physical(super::super::scale_factor()),