Skip to content

Commit

Permalink
fix(windows): set physical values in bounds method (#1299)
Browse files Browse the repository at this point in the history
  • Loading branch information
kanatapple committed Jul 10, 2024
1 parent 93eddc3 commit d1f1e7e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 15 deletions.
5 changes: 5 additions & 0 deletions .changes/fix-set-physical-values-in-bounds.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"wry": patch
---

Fix `Webview::bounds` returning logical values where it should have been physical.
20 changes: 5 additions & 15 deletions src/webview2/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -1199,9 +1199,8 @@ impl InnerWebView {

pub fn bounds(&self) -> Result<Rect> {
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 {
Expand All @@ -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)
}

Expand Down

0 comments on commit d1f1e7e

Please sign in to comment.