mirror of
https://github.com/rust-windowing/winit.git
synced 2026-09-02 14:50:04 -04:00
On Web, fix context menu not being disabled
This commit is contained in:
committed by
Kirill Chibisov
parent
380dc4c451
commit
5289b4f206
@@ -11,6 +11,8 @@ Unreleased` header.
|
|||||||
|
|
||||||
# Unreleased
|
# Unreleased
|
||||||
|
|
||||||
|
- On Web, fix context menu not being disabled by `with_prevent_default(true)`.
|
||||||
|
|
||||||
# 0.29.5
|
# 0.29.5
|
||||||
|
|
||||||
- On macOS, remove spurious error logging when handling `Fn`.
|
- On macOS, remove spurious error logging when handling `Fn`.
|
||||||
|
|||||||
@@ -649,6 +649,8 @@ impl<T> EventLoopWindowTarget<T> {
|
|||||||
canvas.on_animation_frame(move || runner.request_redraw(RootWindowId(id)));
|
canvas.on_animation_frame(move || runner.request_redraw(RootWindowId(id)));
|
||||||
|
|
||||||
canvas.on_touch_end();
|
canvas.on_touch_end();
|
||||||
|
|
||||||
|
canvas.on_context_menu(prevent_default);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn available_monitors(&self) -> VecDequeIter<MonitorHandle> {
|
pub fn available_monitors(&self) -> VecDequeIter<MonitorHandle> {
|
||||||
|
|||||||
@@ -5,7 +5,8 @@ use std::sync::{Arc, Mutex};
|
|||||||
use smol_str::SmolStr;
|
use smol_str::SmolStr;
|
||||||
use wasm_bindgen::{closure::Closure, JsCast};
|
use wasm_bindgen::{closure::Closure, JsCast};
|
||||||
use web_sys::{
|
use web_sys::{
|
||||||
CssStyleDeclaration, Document, Event, FocusEvent, HtmlCanvasElement, KeyboardEvent, WheelEvent,
|
CssStyleDeclaration, Document, Event, FocusEvent, HtmlCanvasElement, KeyboardEvent,
|
||||||
|
PointerEvent, WheelEvent,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::dpi::{LogicalPosition, PhysicalPosition, PhysicalSize};
|
use crate::dpi::{LogicalPosition, PhysicalPosition, PhysicalSize};
|
||||||
@@ -42,6 +43,7 @@ pub struct Canvas {
|
|||||||
on_intersect: Option<IntersectionObserverHandle>,
|
on_intersect: Option<IntersectionObserverHandle>,
|
||||||
animation_frame_handler: AnimationFrameHandler,
|
animation_frame_handler: AnimationFrameHandler,
|
||||||
on_touch_end: Option<EventListenerHandle<dyn FnMut(Event)>>,
|
on_touch_end: Option<EventListenerHandle<dyn FnMut(Event)>>,
|
||||||
|
on_context_menu: Option<EventListenerHandle<dyn FnMut(PointerEvent)>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Common {
|
pub struct Common {
|
||||||
@@ -152,6 +154,7 @@ impl Canvas {
|
|||||||
on_intersect: None,
|
on_intersect: None,
|
||||||
animation_frame_handler: AnimationFrameHandler::new(window),
|
animation_frame_handler: AnimationFrameHandler::new(window),
|
||||||
on_touch_end: None,
|
on_touch_end: None,
|
||||||
|
on_context_menu: None,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -446,6 +449,17 @@ impl Canvas {
|
|||||||
self.on_touch_end = Some(self.common.add_transient_event("touchend", |_| {}));
|
self.on_touch_end = Some(self.common.add_transient_event("touchend", |_| {}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(crate) fn on_context_menu(&mut self, prevent_default: bool) {
|
||||||
|
self.on_context_menu = Some(self.common.add_event(
|
||||||
|
"contextmenu",
|
||||||
|
move |event: PointerEvent| {
|
||||||
|
if prevent_default {
|
||||||
|
event.prevent_default();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
pub fn request_fullscreen(&self) {
|
pub fn request_fullscreen(&self) {
|
||||||
self.common.fullscreen_handler.request_fullscreen()
|
self.common.fullscreen_handler.request_fullscreen()
|
||||||
}
|
}
|
||||||
@@ -524,6 +538,7 @@ impl Canvas {
|
|||||||
self.animation_frame_handler.cancel();
|
self.animation_frame_handler.cancel();
|
||||||
self.on_touch_end = None;
|
self.on_touch_end = None;
|
||||||
self.common.fullscreen_handler.cancel();
|
self.common.fullscreen_handler.cancel();
|
||||||
|
self.on_context_menu = None;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user