mirror of
https://github.com/servo/servo.git
synced 2025-08-04 05:00:08 +01:00
[NFC] servoshell: fix euclid units associated with winit geometry (#30344)
* [NFC] servoshell: fix euclid units associated with winit geometry * rename locals in headed Window::get_coordinates
This commit is contained in:
parent
2076b5d789
commit
95bf68df77
1 changed files with 20 additions and 26 deletions
|
@ -46,8 +46,8 @@ use crate::window_trait::{WindowPortsMethods, LINE_HEIGHT};
|
||||||
pub struct Window {
|
pub struct Window {
|
||||||
winit_window: winit::window::Window,
|
winit_window: winit::window::Window,
|
||||||
webrender_surfman: WebrenderSurfman,
|
webrender_surfman: WebrenderSurfman,
|
||||||
screen_size: Size2D<u32, DeviceIndependentPixel>,
|
screen_size: Size2D<u32, DevicePixel>,
|
||||||
inner_size: Cell<Size2D<u32, DeviceIndependentPixel>>,
|
inner_size: Cell<Size2D<u32, DevicePixel>>,
|
||||||
toolbar_height: Cell<f32>,
|
toolbar_height: Cell<f32>,
|
||||||
mouse_down_button: Cell<Option<winit::event::MouseButton>>,
|
mouse_down_button: Cell<Option<winit::event::MouseButton>>,
|
||||||
mouse_down_point: Cell<Point2D<i32, DevicePixel>>,
|
mouse_down_point: Cell<Point2D<i32, DevicePixel>>,
|
||||||
|
@ -119,13 +119,8 @@ impl Window {
|
||||||
.nth(0)
|
.nth(0)
|
||||||
.expect("No monitor detected");
|
.expect("No monitor detected");
|
||||||
|
|
||||||
let PhysicalSize {
|
let screen_size = winit_size_to_euclid_size(primary_monitor.size());
|
||||||
width: screen_width,
|
let inner_size = winit_size_to_euclid_size(winit_window.inner_size());
|
||||||
height: screen_height,
|
|
||||||
} = primary_monitor.size();
|
|
||||||
let screen_size = Size2D::new(screen_width, screen_height);
|
|
||||||
let PhysicalSize { width, height } = winit_window.inner_size();
|
|
||||||
let inner_size = Size2D::new(width, height);
|
|
||||||
|
|
||||||
// Initialize surfman
|
// Initialize surfman
|
||||||
let display_handle = winit_window.raw_display_handle();
|
let display_handle = winit_window.raw_display_handle();
|
||||||
|
@ -522,34 +517,33 @@ impl WindowPortsMethods for Window {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn winit_size_to_euclid_size<T>(size: PhysicalSize<T>) -> Size2D<T, DevicePixel> {
|
||||||
|
Size2D::new(size.width, size.height)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn winit_position_to_euclid_point<T>(position: PhysicalPosition<T>) -> Point2D<T, DevicePixel> {
|
||||||
|
Point2D::new(position.x, position.y)
|
||||||
|
}
|
||||||
|
|
||||||
impl WindowMethods for Window {
|
impl WindowMethods for Window {
|
||||||
fn get_coordinates(&self) -> EmbedderCoordinates {
|
fn get_coordinates(&self) -> EmbedderCoordinates {
|
||||||
// Needed to convince the type system that winit's physical pixels
|
let window_size = winit_size_to_euclid_size(self.winit_window.outer_size()).to_i32();
|
||||||
// are actually device pixels.
|
let window_origin = self.winit_window.outer_position().unwrap_or_default();
|
||||||
let dpr: Scale<f32, DeviceIndependentPixel, DevicePixel> = Scale::new(1.0);
|
let window_origin = winit_position_to_euclid_point(window_origin).to_i32();
|
||||||
let PhysicalSize { width, height } = self.winit_window.outer_size();
|
let inner_size = winit_size_to_euclid_size(self.winit_window.inner_size()).to_f32();
|
||||||
let PhysicalPosition { x, y } = self
|
|
||||||
.winit_window
|
|
||||||
.outer_position()
|
|
||||||
.unwrap_or(PhysicalPosition::new(0, 0));
|
|
||||||
let win_size = (Size2D::new(width as f32, height as f32) * dpr).to_i32();
|
|
||||||
let win_origin = (Point2D::new(x as f32, y as f32) * dpr).to_i32();
|
|
||||||
let screen = (self.screen_size.to_f32() * dpr).to_i32();
|
|
||||||
|
|
||||||
let PhysicalSize { width, height } = self.winit_window.inner_size();
|
|
||||||
|
|
||||||
// Subtract the minibrowser toolbar height if any
|
// Subtract the minibrowser toolbar height if any
|
||||||
let toolbar_height = self.toolbar_height.get();
|
let toolbar_height = self.toolbar_height.get();
|
||||||
let inner_size = Size2D::new(width as f32, height as f32) * dpr;
|
|
||||||
let viewport_size = inner_size - Size2D::new(0f32, toolbar_height);
|
let viewport_size = inner_size - Size2D::new(0f32, toolbar_height);
|
||||||
|
|
||||||
let viewport_origin = DeviceIntPoint::zero(); // bottom left
|
let viewport_origin = DeviceIntPoint::zero(); // bottom left
|
||||||
let viewport = DeviceIntRect::new(viewport_origin, viewport_size.to_i32());
|
let viewport = DeviceIntRect::new(viewport_origin, viewport_size.to_i32());
|
||||||
|
let screen = self.screen_size.to_i32();
|
||||||
|
|
||||||
let framebuffer = DeviceIntSize::from_untyped(viewport.size.to_untyped());
|
|
||||||
EmbedderCoordinates {
|
EmbedderCoordinates {
|
||||||
viewport,
|
viewport,
|
||||||
framebuffer,
|
framebuffer: viewport.size,
|
||||||
window: (win_size, win_origin),
|
window: (window_size, window_origin),
|
||||||
screen,
|
screen,
|
||||||
// FIXME: Winit doesn't have API for available size. Fallback to screen size
|
// FIXME: Winit doesn't have API for available size. Fallback to screen size
|
||||||
screen_avail: screen,
|
screen_avail: screen,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue