mirror of
https://github.com/servo/servo.git
synced 2025-09-27 23:30:08 +01:00
servoshell: reduce duplication for conversion between physical/logical position/size (#38082)
With helper functions introduced in #38020, this is now becoming reality. Testing: No behaviour change. Fixes: #37937 Signed-off-by: Euclid Ye <euclid.ye@huawei.com>
This commit is contained in:
parent
8e2d2bde6f
commit
547ce67514
3 changed files with 26 additions and 43 deletions
|
@ -15,7 +15,9 @@ use keyboard_types::{Modifiers, ShortcutMatcher};
|
|||
use log::{debug, info};
|
||||
use raw_window_handle::{HasDisplayHandle, HasWindowHandle, RawWindowHandle};
|
||||
use servo::servo_config::pref;
|
||||
use servo::servo_geometry::{DeviceIndependentIntRect, DeviceIndependentPixel};
|
||||
use servo::servo_geometry::{
|
||||
DeviceIndependentIntRect, DeviceIndependentPixel, convert_rect_to_css_pixel,
|
||||
};
|
||||
use servo::webrender_api::ScrollLocation;
|
||||
use servo::webrender_api::units::{DeviceIntPoint, DeviceIntRect, DeviceIntSize, DevicePixel};
|
||||
use servo::{
|
||||
|
@ -495,26 +497,19 @@ impl WindowPortsMethods for Window {
|
|||
|
||||
fn window_rect(&self) -> DeviceIndependentIntRect {
|
||||
let outer_size = self.winit_window.outer_size();
|
||||
let hidpi_scale = self.hidpi_scale_factor().get() as f64;
|
||||
// TODO: Find a universal way to convert.
|
||||
// See https://github.com/servo/servo/issues/37937
|
||||
let total_size = Size2D::new(
|
||||
(outer_size.width as f64 / hidpi_scale).round() as i32,
|
||||
(outer_size.height as f64 / hidpi_scale).round() as i32,
|
||||
);
|
||||
// TODO: Find a universal way to convert.
|
||||
// See https://github.com/servo/servo/issues/37937
|
||||
let scale = self.hidpi_scale_factor();
|
||||
|
||||
let outer_size = winit_size_to_euclid_size(outer_size).to_i32();
|
||||
|
||||
let origin = self
|
||||
.winit_window
|
||||
.outer_position()
|
||||
.map(|point| {
|
||||
Point2D::new(
|
||||
(point.x as f64 / hidpi_scale).round() as i32,
|
||||
(point.y as f64 / hidpi_scale).round() as i32,
|
||||
)
|
||||
})
|
||||
.map(winit_position_to_euclid_point)
|
||||
.unwrap_or_default();
|
||||
DeviceIndependentIntRect::from_origin_and_size(origin, total_size)
|
||||
convert_rect_to_css_pixel(
|
||||
DeviceIntRect::from_origin_and_size(origin, outer_size),
|
||||
scale,
|
||||
)
|
||||
}
|
||||
|
||||
fn set_position(&self, point: DeviceIntPoint) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue