|
@@ -11,14 +11,15 @@
|
|
|
html_favicon_url = "https://github.com/tauri-apps/tauri/raw/dev/app-icon.png"
|
|
|
)]
|
|
|
|
|
|
+use http::Request;
|
|
|
use raw_window_handle::{DisplayHandle, HasDisplayHandle, HasWindowHandle};
|
|
|
|
|
|
use tauri_runtime::{
|
|
|
+ dpi::{LogicalPosition, LogicalSize, PhysicalPosition, PhysicalSize, Position, Size},
|
|
|
monitor::Monitor,
|
|
|
webview::{DetachedWebview, DownloadEvent, PendingWebview, WebviewIpcHandler},
|
|
|
window::{
|
|
|
- dpi::{LogicalPosition, LogicalSize, PhysicalPosition, PhysicalSize, Position, Size},
|
|
|
- CursorIcon, DetachedWindow, FileDropEvent, PendingWindow, RawWindow, WebviewEvent,
|
|
|
+ CursorIcon, DetachedWindow, DragDropEvent, PendingWindow, RawWindow, WebviewEvent,
|
|
|
WindowBuilder, WindowBuilderBase, WindowEvent, WindowId,
|
|
|
},
|
|
|
DeviceEventFilter, Error, EventLoopProxy, ExitRequestedEventAction, Icon, ProgressBarState,
|
|
@@ -62,7 +63,7 @@ use tauri_utils::TitleBarStyle;
|
|
|
use tauri_utils::{config::WindowConfig, Theme};
|
|
|
use url::Url;
|
|
|
use wry::{
|
|
|
- FileDropEvent as WryFileDropEvent, ProxyConfig, ProxyEndpoint, WebContext, WebView,
|
|
|
+ DragDropEvent as WryDragDropEvent, ProxyConfig, ProxyEndpoint, WebContext, WebView,
|
|
|
WebViewBuilder,
|
|
|
};
|
|
|
|
|
@@ -112,7 +113,7 @@ use std::{
|
|
|
};
|
|
|
|
|
|
pub type WebviewId = u32;
|
|
|
-type IpcHandler = dyn Fn(String) + 'static;
|
|
|
+type IpcHandler = dyn Fn(Request<String>) + 'static;
|
|
|
|
|
|
#[cfg(any(
|
|
|
windows,
|
|
@@ -415,6 +416,16 @@ impl From<DeviceEventFilter> for DeviceEventFilterWrapper {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+pub struct RectWrapper(pub wry::Rect);
|
|
|
+impl From<tauri_runtime::Rect> for RectWrapper {
|
|
|
+ fn from(value: tauri_runtime::Rect) -> Self {
|
|
|
+ RectWrapper(wry::Rect {
|
|
|
+ position: value.position,
|
|
|
+ size: value.size,
|
|
|
+ })
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
/// Wrapper around a [`tao::window::Icon`] that can be created from an [`Icon`].
|
|
|
pub struct TaoIcon(pub TaoWindowIcon);
|
|
|
|
|
@@ -1144,14 +1155,14 @@ pub enum WindowMessage {
|
|
|
#[derive(Debug, Clone)]
|
|
|
pub enum SynthesizedWindowEvent {
|
|
|
Focused(bool),
|
|
|
- FileDrop(FileDropEvent),
|
|
|
+ DragDrop(DragDropEvent),
|
|
|
}
|
|
|
|
|
|
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),
|
|
|
+ SynthesizedWindowEvent::DragDrop(event) => WindowEvent::DragDrop(event),
|
|
|
};
|
|
|
Self(Some(event))
|
|
|
}
|
|
@@ -1170,13 +1181,15 @@ pub enum WebviewMessage {
|
|
|
Close,
|
|
|
SetPosition(Position),
|
|
|
SetSize(Size),
|
|
|
+ SetBounds(tauri_runtime::Rect),
|
|
|
SetFocus,
|
|
|
- Reparent(WindowId),
|
|
|
+ Reparent(WindowId, Sender<Result<()>>),
|
|
|
SetAutoResize(bool),
|
|
|
// Getters
|
|
|
- Url(Sender<Url>),
|
|
|
- Position(Sender<PhysicalPosition<i32>>),
|
|
|
- Size(Sender<PhysicalSize<u32>>),
|
|
|
+ Url(Sender<Result<Url>>),
|
|
|
+ Bounds(Sender<Result<tauri_runtime::Rect>>),
|
|
|
+ Position(Sender<Result<PhysicalPosition<i32>>>),
|
|
|
+ Size(Sender<Result<PhysicalSize<u32>>>),
|
|
|
WithWebview(Box<dyn FnOnce(Webview) + Send>),
|
|
|
// Devtools
|
|
|
#[cfg(any(debug_assertions, feature = "devtools"))]
|
|
@@ -1289,15 +1302,19 @@ impl<T: UserEvent> WebviewDispatch<T> for WryWebviewDispatcher<T> {
|
|
|
// Getters
|
|
|
|
|
|
fn url(&self) -> Result<Url> {
|
|
|
- webview_getter!(self, WebviewMessage::Url)
|
|
|
+ webview_getter!(self, WebviewMessage::Url)?
|
|
|
+ }
|
|
|
+
|
|
|
+ fn bounds(&self) -> Result<tauri_runtime::Rect> {
|
|
|
+ webview_getter!(self, WebviewMessage::Bounds)?
|
|
|
}
|
|
|
|
|
|
fn position(&self) -> Result<PhysicalPosition<i32>> {
|
|
|
- webview_getter!(self, WebviewMessage::Position)
|
|
|
+ webview_getter!(self, WebviewMessage::Position)?
|
|
|
}
|
|
|
|
|
|
fn size(&self) -> Result<PhysicalSize<u32>> {
|
|
|
- webview_getter!(self, WebviewMessage::Size)
|
|
|
+ webview_getter!(self, WebviewMessage::Size)?
|
|
|
}
|
|
|
|
|
|
// Setters
|
|
@@ -1335,6 +1352,17 @@ impl<T: UserEvent> WebviewDispatch<T> for WryWebviewDispatcher<T> {
|
|
|
)
|
|
|
}
|
|
|
|
|
|
+ fn set_bounds(&self, bounds: tauri_runtime::Rect) -> Result<()> {
|
|
|
+ send_user_message(
|
|
|
+ &self.context,
|
|
|
+ Message::Webview(
|
|
|
+ *self.window_id.lock().unwrap(),
|
|
|
+ self.webview_id,
|
|
|
+ WebviewMessage::SetBounds(bounds),
|
|
|
+ ),
|
|
|
+ )
|
|
|
+ }
|
|
|
+
|
|
|
fn set_size(&self, size: Size) -> Result<()> {
|
|
|
send_user_message(
|
|
|
&self.context,
|
|
@@ -1370,15 +1398,18 @@ impl<T: UserEvent> WebviewDispatch<T> for WryWebviewDispatcher<T> {
|
|
|
|
|
|
fn reparent(&self, window_id: WindowId) -> Result<()> {
|
|
|
let mut current_window_id = self.window_id.lock().unwrap();
|
|
|
+ let (tx, rx) = channel();
|
|
|
send_user_message(
|
|
|
&self.context,
|
|
|
Message::Webview(
|
|
|
*current_window_id,
|
|
|
self.webview_id,
|
|
|
- WebviewMessage::Reparent(window_id),
|
|
|
+ WebviewMessage::Reparent(window_id, tx),
|
|
|
),
|
|
|
)?;
|
|
|
|
|
|
+ rx.recv().unwrap()?;
|
|
|
+
|
|
|
*current_window_id = window_id;
|
|
|
Ok(())
|
|
|
}
|
|
@@ -2746,7 +2777,7 @@ fn handle_user_message<T: UserEvent>(
|
|
|
target_os = "netbsd",
|
|
|
target_os = "openbsd"
|
|
|
))]
|
|
|
- if let WebviewMessage::Reparent(new_parent_window_id) = webview_message {
|
|
|
+ if let WebviewMessage::Reparent(new_parent_window_id, tx) = webview_message {
|
|
|
let webview_handle = windows.0.borrow_mut().get_mut(&window_id).and_then(|w| {
|
|
|
w.webviews
|
|
|
.iter()
|
|
@@ -2762,16 +2793,13 @@ fn handle_user_message<T: UserEvent>(
|
|
|
.map(|w| (w.inner.clone(), &mut w.webviews))
|
|
|
{
|
|
|
#[cfg(target_os = "macos")]
|
|
|
- {
|
|
|
+ let reparent_result = {
|
|
|
use wry::WebViewExtMacOS;
|
|
|
- webview.inner.reparent(new_parent_window.ns_window() as _);
|
|
|
- new_parent_window_webviews.push(webview);
|
|
|
- }
|
|
|
+ webview.inner.reparent(new_parent_window.ns_window() as _)
|
|
|
+ };
|
|
|
#[cfg(windows)]
|
|
|
- {
|
|
|
- webview.inner.reparent(new_parent_window.hwnd());
|
|
|
- new_parent_window_webviews.push(webview);
|
|
|
- }
|
|
|
+ let reparent_result = { webview.inner.reparent(new_parent_window.hwnd()) };
|
|
|
+
|
|
|
#[cfg(any(
|
|
|
target_os = "linux",
|
|
|
target_os = "dragonfly",
|
|
@@ -2779,13 +2807,27 @@ fn handle_user_message<T: UserEvent>(
|
|
|
target_os = "netbsd",
|
|
|
target_os = "openbsd"
|
|
|
))]
|
|
|
- {
|
|
|
+ let reparent_result = {
|
|
|
if let Some(container) = new_parent_window.default_vbox() {
|
|
|
- webview.inner.reparent(container);
|
|
|
+ webview.inner.reparent(container)
|
|
|
+ } else {
|
|
|
+ Err(wry::Error::MessageSender)
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ match reparent_result {
|
|
|
+ Ok(_) => {
|
|
|
new_parent_window_webviews.push(webview);
|
|
|
+ tx.send(Ok(())).unwrap();
|
|
|
+ }
|
|
|
+ Err(e) => {
|
|
|
+ log::error!("failed to reparent webview: {e}");
|
|
|
+ tx.send(Err(Error::FailedToSendMessage)).unwrap();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ } else {
|
|
|
+ tx.send(Err(Error::FailedToSendMessage)).unwrap();
|
|
|
}
|
|
|
|
|
|
return;
|
|
@@ -2801,7 +2843,7 @@ fn handle_user_message<T: UserEvent>(
|
|
|
match webview_message {
|
|
|
WebviewMessage::WebviewEvent(_) => { /* already handled */ }
|
|
|
WebviewMessage::SynthesizedWindowEvent(_) => { /* already handled */ }
|
|
|
- WebviewMessage::Reparent(_window_id) => { /* already handled */ }
|
|
|
+ WebviewMessage::Reparent(_window_id, _tx) => { /* already handled */ }
|
|
|
WebviewMessage::AddEventListener(id, listener) => {
|
|
|
webview
|
|
|
.webview_event_listeners
|
|
@@ -2824,7 +2866,11 @@ fn handle_user_message<T: UserEvent>(
|
|
|
log::error!("{}", e);
|
|
|
}
|
|
|
}
|
|
|
- WebviewMessage::Navigate(url) => webview.load_url(url.as_str()),
|
|
|
+ WebviewMessage::Navigate(url) => {
|
|
|
+ if let Err(e) = webview.load_url(url.as_str()) {
|
|
|
+ log::error!("failed to navigate to url {}: {}", url, e);
|
|
|
+ }
|
|
|
+ }
|
|
|
WebviewMessage::Print => {
|
|
|
let _ = webview.print();
|
|
|
}
|
|
@@ -2836,67 +2882,133 @@ fn handle_user_message<T: UserEvent>(
|
|
|
window
|
|
|
});
|
|
|
}
|
|
|
- WebviewMessage::SetSize(size) => {
|
|
|
- let mut bounds = webview.bounds();
|
|
|
- let size = size.to_logical(window.scale_factor());
|
|
|
- bounds.width = size.width;
|
|
|
- bounds.height = size.height;
|
|
|
+ WebviewMessage::SetBounds(bounds) => {
|
|
|
+ let bounds: RectWrapper = bounds.into();
|
|
|
+ let bounds = bounds.0;
|
|
|
|
|
|
if let Some(b) = &mut *webview.bounds.lock().unwrap() {
|
|
|
- let window_size = window.inner_size().to_logical::<f32>(window.scale_factor());
|
|
|
- b.width_rate = size.width as f32 / window_size.width;
|
|
|
- b.height_rate = size.height as f32 / window_size.height;
|
|
|
+ let scale_factor = window.scale_factor();
|
|
|
+ let size = bounds.size.to_logical::<f32>(scale_factor);
|
|
|
+ let position = bounds.position.to_logical::<f32>(scale_factor);
|
|
|
+ let window_size = window.inner_size().to_logical::<f32>(scale_factor);
|
|
|
+ b.width_rate = size.width / window_size.width;
|
|
|
+ b.height_rate = size.height / window_size.height;
|
|
|
+ b.x_rate = position.x / window_size.width;
|
|
|
+ b.y_rate = position.y / window_size.height;
|
|
|
}
|
|
|
|
|
|
- webview.set_bounds(bounds);
|
|
|
+ if let Err(e) = webview.set_bounds(bounds) {
|
|
|
+ log::error!("failed to set webview size: {e}");
|
|
|
+ }
|
|
|
}
|
|
|
- WebviewMessage::SetPosition(position) => {
|
|
|
- let mut bounds = webview.bounds();
|
|
|
- let position = position.to_logical(window.scale_factor());
|
|
|
- bounds.x = position.x;
|
|
|
- bounds.y = position.y;
|
|
|
+ WebviewMessage::SetSize(size) => match webview.bounds() {
|
|
|
+ Ok(mut bounds) => {
|
|
|
+ bounds.size = size;
|
|
|
|
|
|
- if let Some(b) = &mut *webview.bounds.lock().unwrap() {
|
|
|
- let window_size = window.inner_size().to_logical::<f32>(window.scale_factor());
|
|
|
- b.x_rate = position.x as f32 / window_size.width;
|
|
|
- b.y_rate = position.y as f32 / window_size.height;
|
|
|
+ let scale_factor = window.scale_factor();
|
|
|
+ let size = size.to_logical::<f32>(scale_factor);
|
|
|
+
|
|
|
+ if let Some(b) = &mut *webview.bounds.lock().unwrap() {
|
|
|
+ let window_size = window.inner_size().to_logical::<f32>(scale_factor);
|
|
|
+ b.width_rate = size.width / window_size.width;
|
|
|
+ b.height_rate = size.height / window_size.height;
|
|
|
+ }
|
|
|
+
|
|
|
+ if let Err(e) = webview.set_bounds(bounds) {
|
|
|
+ log::error!("failed to set webview size: {e}");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Err(e) => {
|
|
|
+ log::error!("failed to get webview bounds: {e}");
|
|
|
}
|
|
|
+ },
|
|
|
+ WebviewMessage::SetPosition(position) => match webview.bounds() {
|
|
|
+ Ok(mut bounds) => {
|
|
|
+ bounds.position = position;
|
|
|
|
|
|
- webview.set_bounds(bounds);
|
|
|
- }
|
|
|
+ let scale_factor = window.scale_factor();
|
|
|
+ let position = position.to_logical::<f32>(scale_factor);
|
|
|
+
|
|
|
+ if let Some(b) = &mut *webview.bounds.lock().unwrap() {
|
|
|
+ let window_size = window.inner_size().to_logical::<f32>(scale_factor);
|
|
|
+ b.x_rate = position.x / window_size.width;
|
|
|
+ b.y_rate = position.y / window_size.height;
|
|
|
+ }
|
|
|
+
|
|
|
+ if let Err(e) = webview.set_bounds(bounds) {
|
|
|
+ log::error!("failed to set webview position: {e}");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Err(e) => {
|
|
|
+ log::error!("failed to get webview bounds: {e}");
|
|
|
+ }
|
|
|
+ },
|
|
|
// Getters
|
|
|
WebviewMessage::Url(tx) => {
|
|
|
- tx.send(webview.url().parse().unwrap()).unwrap();
|
|
|
+ tx.send(
|
|
|
+ webview
|
|
|
+ .url()
|
|
|
+ .map(|u| u.parse().expect("invalid webview URL"))
|
|
|
+ .map_err(|_| Error::FailedToSendMessage),
|
|
|
+ )
|
|
|
+ .unwrap();
|
|
|
+ }
|
|
|
+ WebviewMessage::Bounds(tx) => {
|
|
|
+ tx.send(
|
|
|
+ webview
|
|
|
+ .bounds()
|
|
|
+ .map(|bounds| tauri_runtime::Rect {
|
|
|
+ size: bounds.size,
|
|
|
+ position: bounds.position,
|
|
|
+ })
|
|
|
+ .map_err(|_| Error::FailedToSendMessage),
|
|
|
+ )
|
|
|
+ .unwrap();
|
|
|
}
|
|
|
WebviewMessage::Position(tx) => {
|
|
|
- let bounds = webview.bounds();
|
|
|
- let position =
|
|
|
- LogicalPosition::new(bounds.x, bounds.y).to_physical(window.scale_factor());
|
|
|
- tx.send(position).unwrap();
|
|
|
+ tx.send(
|
|
|
+ webview
|
|
|
+ .bounds()
|
|
|
+ .map(|bounds| bounds.position.to_physical(window.scale_factor()))
|
|
|
+ .map_err(|_| Error::FailedToSendMessage),
|
|
|
+ )
|
|
|
+ .unwrap();
|
|
|
}
|
|
|
WebviewMessage::Size(tx) => {
|
|
|
- let bounds = webview.bounds();
|
|
|
- let size =
|
|
|
- LogicalSize::new(bounds.width, bounds.height).to_physical(window.scale_factor());
|
|
|
- tx.send(size).unwrap();
|
|
|
+ tx.send(
|
|
|
+ webview
|
|
|
+ .bounds()
|
|
|
+ .map(|bounds| bounds.size.to_physical(window.scale_factor()))
|
|
|
+ .map_err(|_| Error::FailedToSendMessage),
|
|
|
+ )
|
|
|
+ .unwrap();
|
|
|
}
|
|
|
WebviewMessage::SetFocus => {
|
|
|
- webview.focus();
|
|
|
- }
|
|
|
- WebviewMessage::SetAutoResize(auto_resize) => {
|
|
|
- let bounds = webview.bounds();
|
|
|
- let window_size = window.inner_size().to_logical::<f32>(window.scale_factor());
|
|
|
- *webview.bounds.lock().unwrap() = if auto_resize {
|
|
|
- Some(WebviewBounds {
|
|
|
- x_rate: (bounds.x as f32) / window_size.width,
|
|
|
- y_rate: (bounds.y as f32) / window_size.height,
|
|
|
- width_rate: (bounds.width as f32) / window_size.width,
|
|
|
- height_rate: (bounds.height as f32) / window_size.height,
|
|
|
- })
|
|
|
- } else {
|
|
|
- None
|
|
|
- };
|
|
|
+ if let Err(e) = webview.focus() {
|
|
|
+ log::error!("failed to focus webview: {e}");
|
|
|
+ }
|
|
|
}
|
|
|
+ WebviewMessage::SetAutoResize(auto_resize) => match webview.bounds() {
|
|
|
+ Ok(bounds) => {
|
|
|
+ let scale_factor = window.scale_factor();
|
|
|
+ let window_size = window.inner_size().to_logical::<f32>(scale_factor);
|
|
|
+ *webview.bounds.lock().unwrap() = if auto_resize {
|
|
|
+ let size = bounds.size.to_logical::<f32>(scale_factor);
|
|
|
+ let position = bounds.position.to_logical::<f32>(scale_factor);
|
|
|
+ Some(WebviewBounds {
|
|
|
+ x_rate: position.x / window_size.width,
|
|
|
+ y_rate: position.y / window_size.height,
|
|
|
+ width_rate: size.width / window_size.width,
|
|
|
+ height_rate: size.height / window_size.height,
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ None
|
|
|
+ };
|
|
|
+ }
|
|
|
+ Err(e) => {
|
|
|
+ log::error!("failed to get webview bounds: {e}");
|
|
|
+ }
|
|
|
+ },
|
|
|
WebviewMessage::WithWebview(f) => {
|
|
|
#[cfg(any(
|
|
|
target_os = "linux",
|
|
@@ -3182,7 +3294,9 @@ fn handle_event_loop<T: UserEvent>(
|
|
|
TaoTheme::Light => wry::Theme::Light,
|
|
|
_ => wry::Theme::Light,
|
|
|
};
|
|
|
- webview.set_theme(theme);
|
|
|
+ if let Err(e) = webview.set_theme(theme) {
|
|
|
+ log::error!("failed to set theme: {e}");
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -3216,12 +3330,14 @@ fn handle_event_loop<T: UserEvent>(
|
|
|
let size = size.to_logical::<f32>(window.scale_factor());
|
|
|
for webview in &webviews {
|
|
|
if let Some(b) = &*webview.bounds.lock().unwrap() {
|
|
|
- webview.set_bounds(wry::Rect {
|
|
|
- x: (size.width * b.x_rate) as i32,
|
|
|
- y: (size.height * b.y_rate) as i32,
|
|
|
- width: (size.width * b.width_rate) as u32,
|
|
|
- height: (size.height * b.height_rate) as u32,
|
|
|
- });
|
|
|
+ if let Err(e) = webview.set_bounds(wry::Rect {
|
|
|
+ position: LogicalPosition::new(size.width * b.x_rate, size.height * b.y_rate)
|
|
|
+ .into(),
|
|
|
+ size: LogicalSize::new(size.width * b.width_rate, size.height * b.height_rate)
|
|
|
+ .into(),
|
|
|
+ }) {
|
|
|
+ log::error!("failed to autoresize webview: {e}");
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
#[cfg(windows)]
|
|
@@ -3590,33 +3706,36 @@ fn create_webview<T: UserEvent>(
|
|
|
webview_builder = webview_builder.with_initialization_script(undecorated_resizing::SCRIPT);
|
|
|
}
|
|
|
|
|
|
- if webview_attributes.file_drop_handler_enabled {
|
|
|
+ if webview_attributes.drag_drop_handler_enabled {
|
|
|
let proxy = context.proxy.clone();
|
|
|
let window_id_ = window_id.clone();
|
|
|
- webview_builder = webview_builder.with_file_drop_handler(move |event| {
|
|
|
+ webview_builder = webview_builder.with_drag_drop_handler(move |event| {
|
|
|
let event = match event {
|
|
|
- WryFileDropEvent::Hovered {
|
|
|
+ WryDragDropEvent::Enter {
|
|
|
paths,
|
|
|
position: (x, y),
|
|
|
- } => FileDropEvent::Hovered {
|
|
|
+ } => DragDropEvent::Dragged {
|
|
|
paths,
|
|
|
position: PhysicalPosition::new(x as _, y as _),
|
|
|
},
|
|
|
- WryFileDropEvent::Dropped {
|
|
|
+ WryDragDropEvent::Over { position: (x, y) } => DragDropEvent::DragOver {
|
|
|
+ position: PhysicalPosition::new(x as _, y as _),
|
|
|
+ },
|
|
|
+ WryDragDropEvent::Drop {
|
|
|
paths,
|
|
|
position: (x, y),
|
|
|
- } => FileDropEvent::Dropped {
|
|
|
+ } => DragDropEvent::Dropped {
|
|
|
paths,
|
|
|
position: PhysicalPosition::new(x as _, y as _),
|
|
|
},
|
|
|
- WryFileDropEvent::Cancelled => FileDropEvent::Cancelled,
|
|
|
+ WryDragDropEvent::Leave => DragDropEvent::Cancelled,
|
|
|
_ => unimplemented!(),
|
|
|
};
|
|
|
|
|
|
let message = if kind == WebviewKind::WindowContent {
|
|
|
- WebviewMessage::SynthesizedWindowEvent(SynthesizedWindowEvent::FileDrop(event))
|
|
|
+ WebviewMessage::SynthesizedWindowEvent(SynthesizedWindowEvent::DragDrop(event))
|
|
|
} else {
|
|
|
- WebviewMessage::WebviewEvent(WebviewEvent::FileDrop(event))
|
|
|
+ WebviewMessage::WebviewEvent(WebviewEvent::DragDrop(event))
|
|
|
};
|
|
|
|
|
|
let _ = proxy.send_event(Message::Webview(*window_id_.lock().unwrap(), id, message));
|
|
@@ -3633,24 +3752,24 @@ fn create_webview<T: UserEvent>(
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- let webview_bounds = if let Some((position, size)) = webview_attributes.bounds {
|
|
|
- let size = size.to_logical(window.scale_factor());
|
|
|
- let position = position.to_logical(window.scale_factor());
|
|
|
- webview_builder = webview_builder.with_bounds(wry::Rect {
|
|
|
- x: position.x,
|
|
|
- y: position.y,
|
|
|
- width: size.width,
|
|
|
- height: size.height,
|
|
|
- });
|
|
|
+ let webview_bounds = if let Some(bounds) = webview_attributes.bounds {
|
|
|
+ let bounds: RectWrapper = bounds.into();
|
|
|
+ let bounds = bounds.0;
|
|
|
+
|
|
|
+ let scale_factor = window.scale_factor();
|
|
|
+ let position = bounds.position.to_logical::<f32>(scale_factor);
|
|
|
+ let size = bounds.size.to_logical::<f32>(scale_factor);
|
|
|
|
|
|
- let window_size = window.inner_size().to_logical::<f32>(window.scale_factor());
|
|
|
+ webview_builder = webview_builder.with_bounds(bounds);
|
|
|
+
|
|
|
+ let window_size = window.inner_size().to_logical::<f32>(scale_factor);
|
|
|
|
|
|
if webview_attributes.auto_resize {
|
|
|
Some(WebviewBounds {
|
|
|
- x_rate: (position.x as f32) / window_size.width,
|
|
|
- y_rate: (position.y as f32) / window_size.height,
|
|
|
- width_rate: (size.width as f32) / window_size.width,
|
|
|
- height_rate: (size.height as f32) / window_size.height,
|
|
|
+ x_rate: position.x / window_size.width,
|
|
|
+ y_rate: position.y / window_size.height,
|
|
|
+ width_rate: size.width / window_size.width,
|
|
|
+ height_rate: size.height / window_size.height,
|
|
|
})
|
|
|
} else {
|
|
|
None
|
|
@@ -3658,13 +3777,9 @@ fn create_webview<T: UserEvent>(
|
|
|
} else {
|
|
|
#[cfg(feature = "unstable")]
|
|
|
{
|
|
|
- let window_size = window.inner_size().to_logical::<u32>(window.scale_factor());
|
|
|
-
|
|
|
webview_builder = webview_builder.with_bounds(wry::Rect {
|
|
|
- x: 0,
|
|
|
- y: 0,
|
|
|
- width: window_size.width,
|
|
|
- height: window_size.height,
|
|
|
+ position: LogicalPosition::new(0, 0).into(),
|
|
|
+ size: window.inner_size().into(),
|
|
|
});
|
|
|
Some(WebviewBounds {
|
|
|
x_rate: 0.,
|