Skip to content

Commit e635978

Browse files
committed
move enable_web_page_scroll into prevent_default option
1 parent 6ae6207 commit e635978

File tree

4 files changed

+9
-28
lines changed

4 files changed

+9
-28
lines changed

CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ And please only add new entries to the top of this list, right below the `# Unre
1616
- On Windows, added `WindowExtWindows::set_undecorated_shadow` and `WindowBuilderExtWindows::with_undecorated_shadow` to draw the drop shadow behind a borderless window.
1717
- On Windows, fixed default window features (ie snap, animations, shake, etc.) when decorations are disabled.
1818
- **Breaking:** On macOS, add support for two-finger touchpad magnification and rotation gestures with new events `WindowEvent::TouchpadMagnify` and `WindowEvent::TouchpadRotate`.
19-
- On web, by default, when the canvas is focused, scrolling of the webpage is disabled. It can however be enabled via the `WindowBuilderExtWebSys::enable_web_page_scroll` method.
19+
- 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.
2020
- On Wayland, `wayland-csd-adwaita` now uses `ab_glyph` instead of `crossfont` to render the title for decorations.
2121
- On Wayland, a new `wayland-csd-adwaita-crossfont` feature was added to use `crossfont` instead of `ab_glyph` for decorations.
2222
- On Wayland, if not otherwise specified use upstream automatic CSD theme selection.

src/platform/web.rs

-15
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,6 @@ pub trait WindowExtWebSys {
1919
}
2020

2121
pub trait WindowBuilderExtWebSys {
22-
/// Enable scrolling of the web page the canvas is in when the canvas is focused.
23-
///
24-
/// Scrolling is disabled by default because the scroll input on many mobile devices
25-
/// is the same as click and dragging which is a very common input method for many applications.
26-
///
27-
/// So only call this method if you know that you will never need to handle mouse wheel inputs
28-
/// or click and dragging.
29-
fn enable_web_page_scroll(self) -> Self;
30-
3122
fn with_canvas(self, canvas: Option<HtmlCanvasElement>) -> Self;
3223

3324
/// Whether `event.preventDefault` should be automatically called to prevent event propagation
@@ -43,12 +34,6 @@ pub trait WindowBuilderExtWebSys {
4334
}
4435

4536
impl WindowBuilderExtWebSys for WindowBuilder {
46-
fn enable_web_page_scroll(mut self) -> Self {
47-
self.platform_specific.enable_web_page_scroll = true;
48-
49-
self
50-
}
51-
5237
fn with_canvas(mut self, canvas: Option<HtmlCanvasElement>) -> Self {
5338
self.platform_specific.canvas = canvas;
5439

src/platform_impl/web/web_sys/canvas.rs

+8-10
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ pub struct Canvas {
3232
on_fullscreen_change: Option<EventListener>,
3333
on_dark_mode: Option<MediaQueryListHandle>,
3434
mouse_state: MouseState,
35-
disable_web_scroll: Option<[EventListener; 5]>,
35+
disable_mobile_scroll: Option<[EventListener; 3]>,
3636
}
3737

3838
struct Common {
@@ -82,11 +82,8 @@ impl Canvas {
8282
wants_fullscreen: Rc::new(RefCell::new(false)),
8383
};
8484

85-
let disable_web_scroll = if !attr.enable_web_page_scroll && attr.prevent_default {
85+
let disable_mobile_scroll = if attr.prevent_default {
8686
Some([
87-
common.add_event("pointermove", move |event: Event| {
88-
event.prevent_default();
89-
}),
9087
common.add_event("pointermove", move |event: Event| {
9188
event.prevent_default();
9289
}),
@@ -96,9 +93,6 @@ impl Canvas {
9693
common.add_event("touchend", move |event: Event| {
9794
event.prevent_default();
9895
}),
99-
common.add_event("wheel", move |event: Event| {
100-
event.prevent_default();
101-
}),
10296
])
10397
} else {
10498
None
@@ -114,7 +108,7 @@ impl Canvas {
114108
on_fullscreen_change: None,
115109
on_dark_mode: None,
116110
mouse_state,
117-
disable_web_scroll,
111+
disable_mobile_scroll,
118112
common,
119113
})
120114
}
@@ -300,11 +294,15 @@ impl Canvas {
300294
}
301295
}
302296

303-
pub fn on_mouse_wheel<F>(&mut self, mut handler: F, _prevent_default: bool)
297+
pub fn on_mouse_wheel<F>(&mut self, mut handler: F, prevent_default: bool)
304298
where
305299
F: 'static + FnMut(i32, MouseScrollDelta, ModifiersState),
306300
{
307301
self.on_mouse_wheel = Some(self.common.add_event("wheel", move |event: WheelEvent| {
302+
if prevent_default {
303+
event.prevent_default();
304+
}
305+
308306
if let Some(delta) = event::mouse_scroll_delta(&event) {
309307
handler(0, delta, event::mouse_modifiers(&event));
310308
}

src/platform_impl/web/window.rs

-2
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,6 @@ pub struct PlatformSpecificWindowBuilderAttributes {
404404
pub(crate) canvas: Option<backend::RawCanvasType>,
405405
pub(crate) prevent_default: bool,
406406
pub(crate) focusable: bool,
407-
pub(crate) enable_web_page_scroll: bool,
408407
}
409408

410409
impl Default for PlatformSpecificWindowBuilderAttributes {
@@ -413,7 +412,6 @@ impl Default for PlatformSpecificWindowBuilderAttributes {
413412
canvas: None,
414413
prevent_default: true,
415414
focusable: true,
416-
enable_web_page_scroll: false,
417415
}
418416
}
419417
}

0 commit comments

Comments
 (0)