|
@@ -17,12 +17,12 @@ use tauri_runtime::{
|
|
|
webview::{DetachedWebview, DownloadEvent, PendingWebview, WebviewIpcHandler},
|
|
|
window::{
|
|
|
dpi::{LogicalPosition, LogicalSize, PhysicalPosition, PhysicalSize, Position, Size},
|
|
|
- CursorIcon, DetachedWindow, FileDropEvent, PendingWindow, RawWindow, WindowBuilder,
|
|
|
- WindowBuilderBase, WindowEvent, WindowId,
|
|
|
+ CursorIcon, DetachedWindow, FileDropEvent, PendingWindow, RawWindow, WebviewEvent,
|
|
|
+ WindowBuilder, WindowBuilderBase, WindowEvent, WindowId,
|
|
|
},
|
|
|
DeviceEventFilter, Error, EventLoopProxy, ExitRequestedEventAction, Icon, Result, RunEvent,
|
|
|
Runtime, RuntimeHandle, RuntimeInitArgs, UserAttentionType, UserEvent, WebviewDispatch,
|
|
|
- WindowDispatch, WindowEventId,
|
|
|
+ WebviewEventId, WindowDispatch, WindowEventId,
|
|
|
};
|
|
|
|
|
|
#[cfg(target_os = "macos")]
|
|
@@ -121,6 +121,8 @@ pub type WebContextStore = Arc<Mutex<HashMap<Option<PathBuf>, WebContext>>>;
|
|
|
// window
|
|
|
pub type WindowEventHandler = Box<dyn Fn(&WindowEvent) + Send>;
|
|
|
pub type WindowEventListeners = Arc<Mutex<HashMap<WindowEventId, WindowEventHandler>>>;
|
|
|
+pub type WebviewEventHandler = Box<dyn Fn(&WebviewEvent) + Send>;
|
|
|
+pub type WebviewEventListeners = Arc<Mutex<HashMap<WebviewEventId, WebviewEventHandler>>>;
|
|
|
|
|
|
#[derive(Debug, Clone, Default)]
|
|
|
pub struct WindowIdStore(Arc<Mutex<HashMap<TaoWindowId, WindowId>>>);
|
|
@@ -172,7 +174,7 @@ pub(crate) fn send_user_message<T: UserEvent>(
|
|
|
&context.main_thread.window_target,
|
|
|
message,
|
|
|
UserMessageContext {
|
|
|
- webview_id_map: context.webview_id_map.clone(),
|
|
|
+ window_id_map: context.window_id_map.clone(),
|
|
|
windows: context.main_thread.windows.clone(),
|
|
|
},
|
|
|
);
|
|
@@ -187,7 +189,7 @@ pub(crate) fn send_user_message<T: UserEvent>(
|
|
|
|
|
|
#[derive(Clone)]
|
|
|
pub struct Context<T: UserEvent> {
|
|
|
- pub webview_id_map: WindowIdStore,
|
|
|
+ pub window_id_map: WindowIdStore,
|
|
|
main_thread_id: ThreadId,
|
|
|
pub proxy: TaoEventLoopProxy<Message<T>>,
|
|
|
main_thread: DispatcherMainThreadContext<T>,
|
|
@@ -195,6 +197,7 @@ pub struct Context<T: UserEvent> {
|
|
|
next_window_id: Arc<AtomicU32>,
|
|
|
next_webview_id: Arc<AtomicU32>,
|
|
|
next_window_event_id: Arc<AtomicU32>,
|
|
|
+ next_webview_event_id: Arc<AtomicU32>,
|
|
|
next_webcontext_id: Arc<AtomicU32>,
|
|
|
}
|
|
|
|
|
@@ -222,6 +225,10 @@ impl<T: UserEvent> Context<T> {
|
|
|
self.next_window_event_id.fetch_add(1, Ordering::Relaxed)
|
|
|
}
|
|
|
|
|
|
+ fn next_webview_event_id(&self) -> u32 {
|
|
|
+ self.next_webview_event_id.fetch_add(1, Ordering::Relaxed)
|
|
|
+ }
|
|
|
+
|
|
|
fn next_webcontext_id(&self) -> u32 {
|
|
|
self.next_webcontext_id.fetch_add(1, Ordering::Relaxed)
|
|
|
}
|
|
@@ -463,16 +470,6 @@ impl<'a> From<&TaoWindowEvent<'a>> for WindowEventWrapper {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-impl From<WebviewEvent> for WindowEventWrapper {
|
|
|
- fn from(event: WebviewEvent) -> Self {
|
|
|
- let event = match event {
|
|
|
- WebviewEvent::Focused(focused) => WindowEvent::Focused(focused),
|
|
|
- WebviewEvent::FileDrop(event) => WindowEvent::FileDrop(event),
|
|
|
- };
|
|
|
- Self(Some(event))
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
pub struct MonitorHandleWrapper(pub MonitorHandle);
|
|
|
|
|
|
impl From<MonitorHandleWrapper> for Monitor {
|
|
@@ -994,53 +991,6 @@ impl WindowBuilder for WindowBuilderWrapper {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-pub struct FileDropEventWrapper(WryFileDropEvent);
|
|
|
-
|
|
|
-// on Linux, the paths are percent-encoded
|
|
|
-#[cfg(any(
|
|
|
- target_os = "linux",
|
|
|
- target_os = "dragonfly",
|
|
|
- target_os = "freebsd",
|
|
|
- target_os = "netbsd",
|
|
|
- target_os = "openbsd"
|
|
|
-))]
|
|
|
-fn decode_path(path: PathBuf) -> PathBuf {
|
|
|
- percent_encoding::percent_decode(path.display().to_string().as_bytes())
|
|
|
- .decode_utf8_lossy()
|
|
|
- .into_owned()
|
|
|
- .into()
|
|
|
-}
|
|
|
-
|
|
|
-// on Windows and macOS, we do not need to decode the path
|
|
|
-#[cfg(not(any(
|
|
|
- target_os = "linux",
|
|
|
- target_os = "dragonfly",
|
|
|
- target_os = "freebsd",
|
|
|
- target_os = "netbsd",
|
|
|
- target_os = "openbsd"
|
|
|
-)))]
|
|
|
-fn decode_path(path: PathBuf) -> PathBuf {
|
|
|
- path
|
|
|
-}
|
|
|
-
|
|
|
-impl From<FileDropEventWrapper> for FileDropEvent {
|
|
|
- fn from(event: FileDropEventWrapper) -> Self {
|
|
|
- match event.0 {
|
|
|
- WryFileDropEvent::Hovered { paths, position } => FileDropEvent::Hovered {
|
|
|
- paths: paths.into_iter().map(decode_path).collect(),
|
|
|
- position: PhysicalPosition::new(position.0 as f64, position.1 as f64),
|
|
|
- },
|
|
|
- WryFileDropEvent::Dropped { paths, position } => FileDropEvent::Dropped {
|
|
|
- paths: paths.into_iter().map(decode_path).collect(),
|
|
|
- position: PhysicalPosition::new(position.0 as f64, position.1 as f64),
|
|
|
- },
|
|
|
- // default to cancelled
|
|
|
- // FIXME(maybe): Add `FileDropEvent::Unknown` event?
|
|
|
- _ => FileDropEvent::Cancelled,
|
|
|
- }
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
#[cfg(any(
|
|
|
target_os = "linux",
|
|
|
target_os = "dragonfly",
|
|
@@ -1168,13 +1118,30 @@ pub enum WindowMessage {
|
|
|
RequestRedraw,
|
|
|
}
|
|
|
|
|
|
+#[derive(Debug, Clone)]
|
|
|
+pub enum SynthesizedWindowEvent {
|
|
|
+ Focused(bool),
|
|
|
+ FileDrop(FileDropEvent),
|
|
|
+}
|
|
|
+
|
|
|
+impl From<SynthesizedWindowEvent> for WindowEventWrapper {
|
|
|
+ fn from(event: SynthesizedWindowEvent) -> Self {
|
|
|
+ let event = match event {
|
|
|
+ SynthesizedWindowEvent::Focused(focused) => WindowEvent::Focused(focused),
|
|
|
+ SynthesizedWindowEvent::FileDrop(event) => WindowEvent::FileDrop(event),
|
|
|
+ };
|
|
|
+ Self(Some(event))
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
pub enum WebviewMessage {
|
|
|
+ AddEventListener(WebviewEventId, Box<dyn Fn(&WebviewEvent) + Send>),
|
|
|
#[cfg(not(all(feature = "tracing", not(target_os = "android"))))]
|
|
|
EvaluateScript(String),
|
|
|
#[cfg(all(feature = "tracing", not(target_os = "android")))]
|
|
|
EvaluateScript(String, Sender<()>, tracing::Span),
|
|
|
- #[allow(dead_code)]
|
|
|
WebviewEvent(WebviewEvent),
|
|
|
+ SynthesizedWindowEvent(SynthesizedWindowEvent),
|
|
|
Navigate(Url),
|
|
|
Print,
|
|
|
Close,
|
|
@@ -1195,13 +1162,6 @@ pub enum WebviewMessage {
|
|
|
IsDevToolsOpen(Sender<bool>),
|
|
|
}
|
|
|
|
|
|
-#[allow(dead_code)]
|
|
|
-#[derive(Debug, Clone)]
|
|
|
-pub enum WebviewEvent {
|
|
|
- FileDrop(FileDropEvent),
|
|
|
- Focused(bool),
|
|
|
-}
|
|
|
-
|
|
|
pub type CreateWindowClosure<T> =
|
|
|
Box<dyn FnOnce(&EventLoopWindowTarget<Message<T>>) -> Result<WindowWrapper> + Send>;
|
|
|
|
|
@@ -1250,6 +1210,16 @@ impl<T: UserEvent> WebviewDispatch<T> for WryWebviewDispatcher<T> {
|
|
|
send_user_message(&self.context, Message::Task(Box::new(f)))
|
|
|
}
|
|
|
|
|
|
+ fn on_webview_event<F: Fn(&WebviewEvent) + Send + 'static>(&self, f: F) -> WindowEventId {
|
|
|
+ let id = self.context.next_webview_event_id();
|
|
|
+ let _ = self.context.proxy.send_event(Message::Webview(
|
|
|
+ self.window_id,
|
|
|
+ self.webview_id,
|
|
|
+ WebviewMessage::AddEventListener(id, Box::new(f)),
|
|
|
+ ));
|
|
|
+ id
|
|
|
+ }
|
|
|
+
|
|
|
fn with_webview<F: FnOnce(Box<dyn std::any::Any>) + Send + 'static>(&self, f: F) -> Result<()> {
|
|
|
send_user_message(
|
|
|
&self.context,
|
|
@@ -1853,9 +1823,11 @@ impl<T: UserEvent> WindowDispatch<T> for WryWindowDispatcher<T> {
|
|
|
|
|
|
#[derive(Clone)]
|
|
|
pub struct WebviewWrapper {
|
|
|
+ label: String,
|
|
|
id: WebviewId,
|
|
|
inner: Rc<WebView>,
|
|
|
context_store: WebContextStore,
|
|
|
+ webview_event_listeners: WebviewEventListeners,
|
|
|
// the key of the WebContext if it's not shared
|
|
|
context_key: Option<PathBuf>,
|
|
|
bounds: Option<Arc<Mutex<WebviewBounds>>>,
|
|
@@ -1977,7 +1949,7 @@ impl<T: UserEvent> WryHandle<T> {
|
|
|
pub fn window_id(&self, window_id: TaoWindowId) -> WindowId {
|
|
|
*self
|
|
|
.context
|
|
|
- .webview_id_map
|
|
|
+ .window_id_map
|
|
|
.0
|
|
|
.lock()
|
|
|
.unwrap()
|
|
@@ -2132,10 +2104,10 @@ impl<T: UserEvent> Wry<T> {
|
|
|
let web_context = WebContextStore::default();
|
|
|
|
|
|
let windows = Rc::new(RefCell::new(HashMap::default()));
|
|
|
- let webview_id_map = WindowIdStore::default();
|
|
|
+ let window_id_map = WindowIdStore::default();
|
|
|
|
|
|
let context = Context {
|
|
|
- webview_id_map,
|
|
|
+ window_id_map,
|
|
|
main_thread_id,
|
|
|
proxy: event_loop.create_proxy(),
|
|
|
main_thread: DispatcherMainThreadContext {
|
|
@@ -2149,6 +2121,7 @@ impl<T: UserEvent> Wry<T> {
|
|
|
next_window_id: Default::default(),
|
|
|
next_webview_id: Default::default(),
|
|
|
next_window_event_id: Default::default(),
|
|
|
+ next_webview_event_id: Default::default(),
|
|
|
next_webcontext_id: Default::default(),
|
|
|
};
|
|
|
|
|
@@ -2347,7 +2320,7 @@ impl<T: UserEvent> Runtime<T> for Wry<T> {
|
|
|
fn run_iteration<F: FnMut(RunEvent<T>)>(&mut self, mut callback: F) {
|
|
|
use tao::platform::run_return::EventLoopExtRunReturn;
|
|
|
let windows = self.context.main_thread.windows.clone();
|
|
|
- let webview_id_map = self.context.webview_id_map.clone();
|
|
|
+ let window_id_map = self.context.window_id_map.clone();
|
|
|
let web_context = &self.context.main_thread.web_context;
|
|
|
let plugins = self.context.plugins.clone();
|
|
|
|
|
@@ -2372,7 +2345,7 @@ impl<T: UserEvent> Runtime<T> for Wry<T> {
|
|
|
control_flow,
|
|
|
EventLoopIterationContext {
|
|
|
callback: &mut callback,
|
|
|
- webview_id_map: webview_id_map.clone(),
|
|
|
+ window_id_map: window_id_map.clone(),
|
|
|
windows: windows.clone(),
|
|
|
#[cfg(feature = "tracing")]
|
|
|
active_tracing_spans: active_tracing_spans.clone(),
|
|
@@ -2391,7 +2364,7 @@ impl<T: UserEvent> Runtime<T> for Wry<T> {
|
|
|
EventLoopIterationContext {
|
|
|
callback: &mut callback,
|
|
|
windows: windows.clone(),
|
|
|
- webview_id_map: webview_id_map.clone(),
|
|
|
+ window_id_map: window_id_map.clone(),
|
|
|
#[cfg(feature = "tracing")]
|
|
|
active_tracing_spans: active_tracing_spans.clone(),
|
|
|
},
|
|
@@ -2401,7 +2374,7 @@ impl<T: UserEvent> Runtime<T> for Wry<T> {
|
|
|
|
|
|
fn run<F: FnMut(RunEvent<T>) + 'static>(self, mut callback: F) {
|
|
|
let windows = self.context.main_thread.windows.clone();
|
|
|
- let webview_id_map = self.context.webview_id_map.clone();
|
|
|
+ let window_id_map = self.context.window_id_map.clone();
|
|
|
let web_context = self.context.main_thread.web_context;
|
|
|
let plugins = self.context.plugins.clone();
|
|
|
|
|
@@ -2418,7 +2391,7 @@ impl<T: UserEvent> Runtime<T> for Wry<T> {
|
|
|
control_flow,
|
|
|
EventLoopIterationContext {
|
|
|
callback: &mut callback,
|
|
|
- webview_id_map: webview_id_map.clone(),
|
|
|
+ window_id_map: window_id_map.clone(),
|
|
|
windows: windows.clone(),
|
|
|
#[cfg(feature = "tracing")]
|
|
|
active_tracing_spans: active_tracing_spans.clone(),
|
|
@@ -2435,7 +2408,7 @@ impl<T: UserEvent> Runtime<T> for Wry<T> {
|
|
|
control_flow,
|
|
|
EventLoopIterationContext {
|
|
|
callback: &mut callback,
|
|
|
- webview_id_map: webview_id_map.clone(),
|
|
|
+ window_id_map: window_id_map.clone(),
|
|
|
windows: windows.clone(),
|
|
|
#[cfg(feature = "tracing")]
|
|
|
active_tracing_spans: active_tracing_spans.clone(),
|
|
@@ -2447,7 +2420,7 @@ impl<T: UserEvent> Runtime<T> for Wry<T> {
|
|
|
|
|
|
pub struct EventLoopIterationContext<'a, T: UserEvent> {
|
|
|
pub callback: &'a mut (dyn FnMut(RunEvent<T>)),
|
|
|
- pub webview_id_map: WindowIdStore,
|
|
|
+ pub window_id_map: WindowIdStore,
|
|
|
pub windows: Rc<RefCell<HashMap<WindowId, WindowWrapper>>>,
|
|
|
#[cfg(feature = "tracing")]
|
|
|
pub active_tracing_spans: ActiveTraceSpanStore,
|
|
@@ -2455,7 +2428,7 @@ pub struct EventLoopIterationContext<'a, T: UserEvent> {
|
|
|
|
|
|
struct UserMessageContext {
|
|
|
windows: Rc<RefCell<HashMap<WindowId, WindowWrapper>>>,
|
|
|
- webview_id_map: WindowIdStore,
|
|
|
+ window_id_map: WindowIdStore,
|
|
|
}
|
|
|
|
|
|
fn handle_user_message<T: UserEvent>(
|
|
@@ -2464,7 +2437,7 @@ fn handle_user_message<T: UserEvent>(
|
|
|
context: UserMessageContext,
|
|
|
) {
|
|
|
let UserMessageContext {
|
|
|
- webview_id_map,
|
|
|
+ window_id_map,
|
|
|
windows,
|
|
|
} = context;
|
|
|
match message {
|
|
@@ -2684,6 +2657,17 @@ fn handle_user_message<T: UserEvent>(
|
|
|
});
|
|
|
if let Some((Some(window), Some(webview))) = webview_handle {
|
|
|
match webview_message {
|
|
|
+ WebviewMessage::WebviewEvent(_) => { /* already handled */ }
|
|
|
+ WebviewMessage::SynthesizedWindowEvent(_) => { /* already handled */ }
|
|
|
+
|
|
|
+ WebviewMessage::AddEventListener(id, listener) => {
|
|
|
+ webview
|
|
|
+ .webview_event_listeners
|
|
|
+ .lock()
|
|
|
+ .unwrap()
|
|
|
+ .insert(id, listener);
|
|
|
+ }
|
|
|
+
|
|
|
#[cfg(all(feature = "tracing", not(target_os = "android")))]
|
|
|
WebviewMessage::EvaluateScript(script, tx, span) => {
|
|
|
let _span = span.entered();
|
|
@@ -2743,7 +2727,6 @@ fn handle_user_message<T: UserEvent>(
|
|
|
WebviewMessage::SetFocus => {
|
|
|
webview.focus();
|
|
|
}
|
|
|
- WebviewMessage::WebviewEvent(_event) => { /* already handled */ }
|
|
|
WebviewMessage::WithWebview(f) => {
|
|
|
#[cfg(any(
|
|
|
target_os = "linux",
|
|
@@ -2850,7 +2833,7 @@ fn handle_user_message<T: UserEvent>(
|
|
|
let (label, builder) = handler();
|
|
|
let is_window_transparent = builder.window.transparent;
|
|
|
if let Ok(window) = builder.build(event_loop) {
|
|
|
- webview_id_map.insert(window.id(), window_id);
|
|
|
+ window_id_map.insert(window.id(), window_id);
|
|
|
|
|
|
let window = Arc::new(window);
|
|
|
|
|
@@ -2901,7 +2884,7 @@ fn handle_event_loop<T: UserEvent>(
|
|
|
) {
|
|
|
let EventLoopIterationContext {
|
|
|
callback,
|
|
|
- webview_id_map,
|
|
|
+ window_id_map,
|
|
|
windows,
|
|
|
#[cfg(feature = "tracing")]
|
|
|
active_tracing_spans,
|
|
@@ -2930,7 +2913,7 @@ fn handle_event_loop<T: UserEvent>(
|
|
|
#[cfg(any(feature = "tracing", windows))]
|
|
|
Event::RedrawRequested(id) => {
|
|
|
#[cfg(windows)]
|
|
|
- if let Some(window_id) = webview_id_map.get(&id) {
|
|
|
+ if let Some(window_id) = window_id_map.get(&id) {
|
|
|
let mut windows_ref = windows.borrow_mut();
|
|
|
if let Some(window) = windows_ref.get_mut(&window_id) {
|
|
|
if window.is_window_transparent {
|
|
@@ -2949,19 +2932,50 @@ fn handle_event_loop<T: UserEvent>(
|
|
|
|
|
|
Event::UserEvent(Message::Webview(
|
|
|
window_id,
|
|
|
- _webview_id,
|
|
|
+ webview_id,
|
|
|
WebviewMessage::WebviewEvent(event),
|
|
|
+ )) => {
|
|
|
+ let windows_ref = windows.borrow();
|
|
|
+ if let Some(window) = windows_ref.get(&window_id) {
|
|
|
+ if let Some(webview) = window.webviews.iter().find(|w| w.id == webview_id) {
|
|
|
+ let label = webview.label.clone();
|
|
|
+ let webview_event_listeners = webview.webview_event_listeners.clone();
|
|
|
+
|
|
|
+ drop(windows_ref);
|
|
|
+
|
|
|
+ callback(RunEvent::WebviewEvent {
|
|
|
+ label,
|
|
|
+ event: event.clone(),
|
|
|
+ });
|
|
|
+ let listeners = webview_event_listeners.lock().unwrap();
|
|
|
+ let handlers = listeners.values();
|
|
|
+ for handler in handlers {
|
|
|
+ handler(&event);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ Event::UserEvent(Message::Webview(
|
|
|
+ window_id,
|
|
|
+ _webview_id,
|
|
|
+ WebviewMessage::SynthesizedWindowEvent(event),
|
|
|
)) => {
|
|
|
if let Some(event) = WindowEventWrapper::from(event).0 {
|
|
|
- let windows = windows.borrow();
|
|
|
- let window = windows.get(&window_id);
|
|
|
+ let windows_ref = windows.borrow();
|
|
|
+ let window = windows_ref.get(&window_id);
|
|
|
if let Some(window) = window {
|
|
|
+ let label = window.label.clone();
|
|
|
+ let window_event_listeners = window.window_event_listeners.clone();
|
|
|
+
|
|
|
+ drop(windows_ref);
|
|
|
+
|
|
|
callback(RunEvent::WindowEvent {
|
|
|
- label: window.label.clone(),
|
|
|
+ label,
|
|
|
event: event.clone(),
|
|
|
});
|
|
|
|
|
|
- let listeners = window.window_event_listeners.lock().unwrap();
|
|
|
+ let listeners = window_event_listeners.lock().unwrap();
|
|
|
let handlers = listeners.values();
|
|
|
for handler in handlers {
|
|
|
handler(&event);
|
|
@@ -2973,7 +2987,7 @@ fn handle_event_loop<T: UserEvent>(
|
|
|
Event::WindowEvent {
|
|
|
event, window_id, ..
|
|
|
} => {
|
|
|
- if let Some(window_id) = webview_id_map.get(&window_id) {
|
|
|
+ if let Some(window_id) = window_id_map.get(&window_id) {
|
|
|
{
|
|
|
let windows_ref = windows.borrow();
|
|
|
if let Some(window) = windows_ref.get(&window_id) {
|
|
@@ -3076,7 +3090,7 @@ fn handle_event_loop<T: UserEvent>(
|
|
|
event_loop,
|
|
|
message,
|
|
|
UserMessageContext {
|
|
|
- webview_id_map,
|
|
|
+ window_id_map,
|
|
|
windows,
|
|
|
},
|
|
|
);
|
|
@@ -3216,7 +3230,7 @@ fn create_window<T: UserEvent, F: Fn(RawWindow) + Send + 'static>(
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- context.webview_id_map.insert(window.id(), window_id);
|
|
|
+ context.window_id_map.insert(window.id(), window_id);
|
|
|
|
|
|
if window_builder.center {
|
|
|
let _ = center_window(&window, window.inner_size());
|
|
@@ -3290,7 +3304,8 @@ fn create_window<T: UserEvent, F: Fn(RawWindow) + Send + 'static>(
|
|
|
})
|
|
|
}
|
|
|
|
|
|
-// the kind of the webview
|
|
|
+/// the kind of the webview
|
|
|
+#[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Copy)]
|
|
|
enum WebviewKind {
|
|
|
// webview is the entire window content
|
|
|
WindowContent,
|
|
@@ -3375,12 +3390,32 @@ fn create_webview<T: UserEvent>(
|
|
|
if webview_attributes.file_drop_handler_enabled {
|
|
|
let proxy = context.proxy.clone();
|
|
|
webview_builder = webview_builder.with_file_drop_handler(move |event| {
|
|
|
- let event: FileDropEvent = FileDropEventWrapper(event).into();
|
|
|
- let _ = proxy.send_event(Message::Webview(
|
|
|
- window_id,
|
|
|
- id,
|
|
|
- WebviewMessage::WebviewEvent(WebviewEvent::FileDrop(event)),
|
|
|
- ));
|
|
|
+ let event = match event {
|
|
|
+ WryFileDropEvent::Hovered {
|
|
|
+ paths,
|
|
|
+ position: (x, y),
|
|
|
+ } => FileDropEvent::Hovered {
|
|
|
+ paths,
|
|
|
+ position: PhysicalPosition::new(x as _, y as _),
|
|
|
+ },
|
|
|
+ WryFileDropEvent::Dropped {
|
|
|
+ paths,
|
|
|
+ position: (x, y),
|
|
|
+ } => FileDropEvent::Dropped {
|
|
|
+ paths,
|
|
|
+ position: PhysicalPosition::new(x as _, y as _),
|
|
|
+ },
|
|
|
+ WryFileDropEvent::Cancelled => FileDropEvent::Cancelled,
|
|
|
+ _ => unimplemented!(),
|
|
|
+ };
|
|
|
+
|
|
|
+ let message = if kind == WebviewKind::WindowContent {
|
|
|
+ WebviewMessage::SynthesizedWindowEvent(SynthesizedWindowEvent::FileDrop(event))
|
|
|
+ } else {
|
|
|
+ WebviewMessage::WebviewEvent(WebviewEvent::FileDrop(event))
|
|
|
+ };
|
|
|
+
|
|
|
+ let _ = proxy.send_event(Message::Webview(window_id, id, message));
|
|
|
true
|
|
|
});
|
|
|
}
|
|
@@ -3566,7 +3601,7 @@ fn create_webview<T: UserEvent>(
|
|
|
.map_err(|e| Error::CreateWebview(Box::new(e)))?;
|
|
|
|
|
|
#[cfg(windows)]
|
|
|
- {
|
|
|
+ if kind == WebviewKind::WindowContent {
|
|
|
let controller = webview.controller();
|
|
|
let proxy = context.proxy.clone();
|
|
|
let proxy_ = proxy.clone();
|
|
@@ -3574,10 +3609,10 @@ fn create_webview<T: UserEvent>(
|
|
|
unsafe {
|
|
|
controller.add_GotFocus(
|
|
|
&FocusChangedEventHandler::create(Box::new(move |_, _| {
|
|
|
- let _ = proxy.send_event(Message::Webview(
|
|
|
+ let _ = proxy_.send_event(Message::Webview(
|
|
|
window_id,
|
|
|
id,
|
|
|
- WebviewMessage::WebviewEvent(WebviewEvent::Focused(true)),
|
|
|
+ WebviewMessage::SynthesizedWindowEvent(SynthesizedWindowEvent::Focused(true)),
|
|
|
));
|
|
|
Ok(())
|
|
|
})),
|
|
@@ -3588,10 +3623,10 @@ fn create_webview<T: UserEvent>(
|
|
|
unsafe {
|
|
|
controller.add_LostFocus(
|
|
|
&FocusChangedEventHandler::create(Box::new(move |_, _| {
|
|
|
- let _ = proxy_.send_event(Message::Webview(
|
|
|
+ let _ = proxy.send_event(Message::Webview(
|
|
|
window_id,
|
|
|
id,
|
|
|
- WebviewMessage::WebviewEvent(WebviewEvent::Focused(false)),
|
|
|
+ WebviewMessage::SynthesizedWindowEvent(SynthesizedWindowEvent::Focused(false)),
|
|
|
));
|
|
|
Ok(())
|
|
|
})),
|
|
@@ -3602,9 +3637,11 @@ fn create_webview<T: UserEvent>(
|
|
|
}
|
|
|
|
|
|
Ok(WebviewWrapper {
|
|
|
+ label,
|
|
|
id,
|
|
|
inner: Rc::new(webview),
|
|
|
context_store: context.main_thread.web_context.clone(),
|
|
|
+ webview_event_listeners: Default::default(),
|
|
|
context_key: if automation_enabled {
|
|
|
None
|
|
|
} else {
|