Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(windows): set physical values in bounds method #1299

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -1179,9 +1179,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 @@ -1190,22 +1189,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
Loading