From d1f1e7e6fa82722d9848fbb540e6f9a3d5925cdd Mon Sep 17 00:00:00 2001 From: Yasunari Fujieda Date: Wed, 10 Jul 2024 21:28:17 +0900 Subject: [PATCH] fix(windows): set physical values in bounds method (#1299) --- .changes/fix-set-physical-values-in-bounds.md | 5 +++++ src/webview2/mod.rs | 20 +++++-------------- 2 files changed, 10 insertions(+), 15 deletions(-) create mode 100644 .changes/fix-set-physical-values-in-bounds.md diff --git a/.changes/fix-set-physical-values-in-bounds.md b/.changes/fix-set-physical-values-in-bounds.md new file mode 100644 index 000000000..2c00b8a1d --- /dev/null +++ b/.changes/fix-set-physical-values-in-bounds.md @@ -0,0 +1,5 @@ +--- +"wry": patch +--- + +Fix `Webview::bounds` returning logical values where it should have been physical. diff --git a/src/webview2/mod.rs b/src/webview2/mod.rs index 661cdd97c..58e806b2d 100644 --- a/src/webview2/mod.rs +++ b/src/webview2/mod.rs @@ -9,7 +9,7 @@ use std::{ borrow::Cow, cell::RefCell, collections::HashSet, fmt::Write, path::PathBuf, rc::Rc, sync::mpsc, }; -use dpi::{LogicalPosition, LogicalSize, PhysicalPosition, PhysicalSize}; +use dpi::{PhysicalPosition, PhysicalSize}; use http::{Request, Response as HttpResponse, StatusCode}; use once_cell::sync::Lazy; use raw_window_handle::{HasWindowHandle, RawWindowHandle}; @@ -1199,9 +1199,8 @@ impl InnerWebView { pub fn bounds(&self) -> Result { let mut bounds = Rect::default(); - + let mut rect = RECT::default(); if self.is_child { - let mut rect = RECT::default(); unsafe { GetClientRect(self.hwnd, &mut rect)? }; let position_point = &mut [POINT { @@ -1210,22 +1209,13 @@ impl InnerWebView { }]; unsafe { MapWindowPoints(self.hwnd, *self.parent.borrow(), position_point) }; - bounds.position = LogicalPosition::new(position_point[0].x, position_point[0].y).into(); - bounds.size = LogicalSize::new( - (rect.right - rect.left) as u32, - (rect.bottom - rect.top) as u32, - ) - .into(); + bounds.position = PhysicalPosition::new(position_point[0].x, position_point[0].y).into(); } else { - let mut rect = RECT::default(); unsafe { self.controller.Bounds(&mut rect) }?; - bounds.size = LogicalSize::new( - (rect.right - rect.left) as u32, - (rect.bottom - rect.top) as u32, - ) - .into(); } + bounds.size = PhysicalSize::new(rect.right - rect.left, rect.bottom - rect.top).into(); + Ok(bounds) }