mirror of
https://github.com/servo/servo.git
synced 2025-08-07 14:35:33 +01:00
Auto merge of #21302 - paulrouget:res, r=mbrubeck
Fix page size when device-pixel-ratio is set manually Fix #21277 We were using the user-define pixel ratio to get the device values of the winit coordinates. <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/21302) <!-- Reviewable:end -->
This commit is contained in:
commit
e363d579fa
1 changed files with 26 additions and 21 deletions
|
@ -305,7 +305,7 @@ impl Window {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn page_height(&self) -> f32 {
|
pub fn page_height(&self) -> f32 {
|
||||||
let dpr = self.hidpi_factor();
|
let dpr = self.servo_hidpi_factor();
|
||||||
match self.kind {
|
match self.kind {
|
||||||
WindowKind::Window(ref window, _) => {
|
WindowKind::Window(ref window, _) => {
|
||||||
let size = window.get_inner_size().expect("Failed to get window inner size.");
|
let size = window.get_inner_size().expect("Failed to get window inner size.");
|
||||||
|
@ -325,14 +325,14 @@ impl Window {
|
||||||
|
|
||||||
pub fn set_inner_size(&self, size: DeviceUintSize) {
|
pub fn set_inner_size(&self, size: DeviceUintSize) {
|
||||||
if let WindowKind::Window(ref window, _) = self.kind {
|
if let WindowKind::Window(ref window, _) = self.kind {
|
||||||
let size = size.to_f32() / self.hidpi_factor();
|
let size = size.to_f32() / self.device_hidpi_factor();
|
||||||
window.set_inner_size(LogicalSize::new(size.width.into(), size.height.into()))
|
window.set_inner_size(LogicalSize::new(size.width.into(), size.height.into()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_position(&self, point: DeviceIntPoint) {
|
pub fn set_position(&self, point: DeviceIntPoint) {
|
||||||
if let WindowKind::Window(ref window, _) = self.kind {
|
if let WindowKind::Window(ref window, _) = self.kind {
|
||||||
let point = point.to_f32() / self.hidpi_factor();
|
let point = point.to_f32() / self.device_hidpi_factor();
|
||||||
window.set_position(LogicalPosition::new(point.x.into(), point.y.into()))
|
window.set_position(LogicalPosition::new(point.x.into(), point.y.into()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -486,7 +486,7 @@ impl Window {
|
||||||
},
|
},
|
||||||
..
|
..
|
||||||
} => {
|
} => {
|
||||||
let pos = position.to_physical(self.hidpi_factor().get() as f64);
|
let pos = position.to_physical(self.device_hidpi_factor().get() as f64);
|
||||||
let (x, y): (i32, i32) = pos.into();
|
let (x, y): (i32, i32) = pos.into();
|
||||||
self.mouse_pos.set(TypedPoint2D::new(x, y));
|
self.mouse_pos.set(TypedPoint2D::new(x, y));
|
||||||
self.event_queue.borrow_mut().push(
|
self.event_queue.borrow_mut().push(
|
||||||
|
@ -499,7 +499,7 @@ impl Window {
|
||||||
let (mut dx, mut dy) = match delta {
|
let (mut dx, mut dy) = match delta {
|
||||||
MouseScrollDelta::LineDelta(dx, dy) => (dx, dy * LINE_HEIGHT),
|
MouseScrollDelta::LineDelta(dx, dy) => (dx, dy * LINE_HEIGHT),
|
||||||
MouseScrollDelta::PixelDelta(position) => {
|
MouseScrollDelta::PixelDelta(position) => {
|
||||||
let position = position.to_physical(self.hidpi_factor().get() as f64);
|
let position = position.to_physical(self.device_hidpi_factor().get() as f64);
|
||||||
(position.x as f32, position.y as f32)
|
(position.x as f32, position.y as f32)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -524,7 +524,7 @@ impl Window {
|
||||||
|
|
||||||
let phase = winit_phase_to_touch_event_type(touch.phase);
|
let phase = winit_phase_to_touch_event_type(touch.phase);
|
||||||
let id = TouchId(touch.id as i32);
|
let id = TouchId(touch.id as i32);
|
||||||
let position = touch.location.to_physical(self.hidpi_factor().get() as f64);
|
let position = touch.location.to_physical(self.device_hidpi_factor().get() as f64);
|
||||||
let point = TypedPoint2D::new(position.x as f32, position.y as f32);
|
let point = TypedPoint2D::new(position.x as f32, position.y as f32);
|
||||||
self.event_queue.borrow_mut().push(WindowEvent::Touch(phase, id, point));
|
self.event_queue.borrow_mut().push(WindowEvent::Touch(phase, id, point));
|
||||||
}
|
}
|
||||||
|
@ -542,10 +542,10 @@ impl Window {
|
||||||
event: winit::WindowEvent::Resized(size),
|
event: winit::WindowEvent::Resized(size),
|
||||||
..
|
..
|
||||||
} => {
|
} => {
|
||||||
// width and height are DeviceIndependentPixel.
|
// size is DeviceIndependentPixel.
|
||||||
// window.resize() takes DevicePixel.
|
// window.resize() takes DevicePixel.
|
||||||
if let WindowKind::Window(ref window, _) = self.kind {
|
if let WindowKind::Window(ref window, _) = self.kind {
|
||||||
let size = size.to_physical(self.hidpi_factor().get() as f64);
|
let size = size.to_physical(self.device_hidpi_factor().get() as f64);
|
||||||
window.resize(size);
|
window.resize(size);
|
||||||
}
|
}
|
||||||
// window.set_inner_size() takes DeviceIndependentPixel.
|
// window.set_inner_size() takes DeviceIndependentPixel.
|
||||||
|
@ -585,7 +585,7 @@ impl Window {
|
||||||
coords: TypedPoint2D<i32, DevicePixel>) {
|
coords: TypedPoint2D<i32, DevicePixel>) {
|
||||||
use servo::script_traits::MouseButton;
|
use servo::script_traits::MouseButton;
|
||||||
|
|
||||||
let max_pixel_dist = 10.0 * self.hidpi_factor().get();
|
let max_pixel_dist = 10.0 * self.servo_hidpi_factor().get();
|
||||||
let event = match action {
|
let event = match action {
|
||||||
ElementState::Pressed => {
|
ElementState::Pressed => {
|
||||||
self.mouse_down_point.set(coords);
|
self.mouse_down_point.set(coords);
|
||||||
|
@ -614,19 +614,23 @@ impl Window {
|
||||||
self.event_queue.borrow_mut().push(WindowEvent::MouseWindowEventClass(event));
|
self.event_queue.borrow_mut().push(WindowEvent::MouseWindowEventClass(event));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn hidpi_factor(&self) -> TypedScale<f32, DeviceIndependentPixel, DevicePixel> {
|
fn device_hidpi_factor(&self) -> TypedScale<f32, DeviceIndependentPixel, DevicePixel> {
|
||||||
|
match self.kind {
|
||||||
|
WindowKind::Window(ref window, ..) => {
|
||||||
|
TypedScale::new(window.get_hidpi_factor() as f32)
|
||||||
|
}
|
||||||
|
WindowKind::Headless(..) => {
|
||||||
|
TypedScale::new(1.0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn servo_hidpi_factor(&self) -> TypedScale<f32, DeviceIndependentPixel, DevicePixel> {
|
||||||
match opts::get().device_pixels_per_px {
|
match opts::get().device_pixels_per_px {
|
||||||
Some(device_pixels_per_px) => TypedScale::new(device_pixels_per_px),
|
Some(device_pixels_per_px) => TypedScale::new(device_pixels_per_px),
|
||||||
None => match opts::get().output_file {
|
_ => match opts::get().output_file {
|
||||||
Some(_) => TypedScale::new(1.0),
|
Some(_) => TypedScale::new(1.0),
|
||||||
None => match self.kind {
|
None => self.device_hidpi_factor()
|
||||||
WindowKind::Window(ref window, ..) => {
|
|
||||||
TypedScale::new(window.get_hidpi_factor() as f32)
|
|
||||||
}
|
|
||||||
WindowKind::Headless(..) => {
|
|
||||||
TypedScale::new(1.0)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -687,10 +691,10 @@ impl WindowMethods for Window {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_coordinates(&self) -> EmbedderCoordinates {
|
fn get_coordinates(&self) -> EmbedderCoordinates {
|
||||||
let dpr = self.hidpi_factor();
|
|
||||||
match self.kind {
|
match self.kind {
|
||||||
WindowKind::Window(ref window, _) => {
|
WindowKind::Window(ref window, _) => {
|
||||||
// TODO(ajeffrey): can this fail?
|
// TODO(ajeffrey): can this fail?
|
||||||
|
let dpr = self.device_hidpi_factor();
|
||||||
let LogicalSize { width, height } = window.get_outer_size().expect("Failed to get window outer size.");
|
let LogicalSize { width, height } = window.get_outer_size().expect("Failed to get window outer size.");
|
||||||
let LogicalPosition { x, y } = window.get_position().unwrap_or(LogicalPosition::new(0., 0.));
|
let LogicalPosition { x, y } = window.get_position().unwrap_or(LogicalPosition::new(0., 0.));
|
||||||
let win_size = (TypedSize2D::new(width as f32, height as f32) * dpr).to_u32();
|
let win_size = (TypedSize2D::new(width as f32, height as f32) * dpr).to_u32();
|
||||||
|
@ -709,10 +713,11 @@ impl WindowMethods for Window {
|
||||||
screen: screen,
|
screen: screen,
|
||||||
// FIXME: Glutin doesn't have API for available size. Fallback to screen size
|
// FIXME: Glutin doesn't have API for available size. Fallback to screen size
|
||||||
screen_avail: screen,
|
screen_avail: screen,
|
||||||
hidpi_factor: dpr,
|
hidpi_factor: self.servo_hidpi_factor(),
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
WindowKind::Headless(ref context) => {
|
WindowKind::Headless(ref context) => {
|
||||||
|
let dpr = self.servo_hidpi_factor();
|
||||||
let size = (TypedSize2D::new(context.width, context.height).to_f32() * dpr).to_u32();
|
let size = (TypedSize2D::new(context.width, context.height).to_f32() * dpr).to_u32();
|
||||||
EmbedderCoordinates {
|
EmbedderCoordinates {
|
||||||
viewport: DeviceUintRect::new(TypedPoint2D::zero(), size),
|
viewport: DeviceUintRect::new(TypedPoint2D::zero(), size),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue