servoshell: Add window position for headless window (#38249)

Add virtual `window_position` to headless window so that `moveTo` and
WebDriver window command can work properly.

Testing: `./mach test-wpt -r
"tests\wpt\tests\webdriver\tests\classic\set_window_rect\set.py"
--product servodriver --headless`
Fixes: Task 7 of #37804.

---------

Signed-off-by: Euclid Ye <euclid.ye@huawei.com>
This commit is contained in:
Euclid Ye 2025-07-25 01:57:58 +08:00 committed by GitHub
parent 4c7797a7ab
commit 3bc104c8e4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 16 additions and 45 deletions

View file

@ -10,9 +10,9 @@ use std::rc::Rc;
use euclid::num::Zero;
use euclid::{Length, Point2D, Scale, Size2D};
use servo::servo_geometry::{
DeviceIndependentIntRect, DeviceIndependentPixel, convert_size_to_css_pixel,
DeviceIndependentIntRect, DeviceIndependentPixel, convert_rect_to_css_pixel,
};
use servo::webrender_api::units::{DeviceIntSize, DevicePixel};
use servo::webrender_api::units::{DeviceIntPoint, DeviceIntRect, DeviceIntSize, DevicePixel};
use servo::{RenderingContext, ScreenGeometry, SoftwareRenderingContext};
use winit::dpi::PhysicalSize;
@ -25,6 +25,8 @@ pub struct Window {
device_pixel_ratio_override: Option<Scale<f32, DeviceIndependentPixel, DevicePixel>>,
inner_size: Cell<DeviceIntSize>,
screen_size: Size2D<i32, DevicePixel>,
// virtual top-left position of the window in device pixels.
window_position: Cell<Point2D<i32, DevicePixel>>,
rendering_context: Rc<SoftwareRenderingContext>,
}
@ -54,6 +56,7 @@ impl Window {
device_pixel_ratio_override,
inner_size: Cell::new(inner_size),
screen_size,
window_position: Cell::new(Point2D::zero()),
rendering_context: Rc::new(rendering_context),
};
@ -70,10 +73,17 @@ impl WindowPortsMethods for Window {
ScreenGeometry {
size: self.screen_size,
available_size: self.screen_size,
window_rect: self.inner_size.get().into(),
window_rect: DeviceIntRect::from_origin_and_size(
self.window_position.get(),
self.inner_size.get(),
),
}
}
fn set_position(&self, point: DeviceIntPoint) {
self.window_position.set(point);
}
fn request_resize(
&self,
webview: &::servo::WebView,
@ -142,12 +152,9 @@ impl WindowPortsMethods for Window {
}
fn window_rect(&self) -> DeviceIndependentIntRect {
let inner_size = self.inner_size.get();
let scale = self.hidpi_scale_factor();
DeviceIndependentIntRect::from_origin_and_size(
Point2D::zero(),
convert_size_to_css_pixel(inner_size, scale),
convert_rect_to_css_pixel(
DeviceIntRect::from_origin_and_size(self.window_position.get(), self.inner_size.get()),
self.hidpi_scale_factor(),
)
}

View file

@ -5,44 +5,8 @@
[test_restore_from_maximized]
expected: FAIL
[test_x_y_floats]
expected: FAIL
[test_partial_input[rect2\]]
expected: FAIL
[test_partial_input[rect3\]]
expected: FAIL
[test_partial_input[rect4\]]
expected: FAIL
[test_partial_input[rect5\]]
expected: FAIL
[test_partial_input[rect6\]]
expected: FAIL
[test_partial_input[rect7\]]
expected: FAIL
[test_set_to_available_size]
expected: FAIL
[test_set_smaller_than_minimum_browser_size]
expected: FAIL
[test_x_y]
expected: FAIL
[test_x_as_current]
expected: FAIL
[test_y_as_current]
expected: FAIL
[test_negative_x_y]
expected: FAIL
[test_response_payload]
expected: FAIL