From 3bc104c8e4a7a93f7c285998160338a1040c0d8f Mon Sep 17 00:00:00 2001 From: Euclid Ye Date: Fri, 25 Jul 2025 01:57:58 +0800 Subject: [PATCH] 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 --- ports/servoshell/desktop/headless_window.rs | 25 ++++++++----- .../tests/classic/set_window_rect/set.py.ini | 36 ------------------- 2 files changed, 16 insertions(+), 45 deletions(-) diff --git a/ports/servoshell/desktop/headless_window.rs b/ports/servoshell/desktop/headless_window.rs index 7716e957a81..bde20a6af6f 100644 --- a/ports/servoshell/desktop/headless_window.rs +++ b/ports/servoshell/desktop/headless_window.rs @@ -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>, inner_size: Cell, screen_size: Size2D, + // virtual top-left position of the window in device pixels. + window_position: Cell>, rendering_context: Rc, } @@ -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(), ) } diff --git a/tests/wpt/meta/webdriver/tests/classic/set_window_rect/set.py.ini b/tests/wpt/meta/webdriver/tests/classic/set_window_rect/set.py.ini index d229938faee..1bf0271bcd6 100644 --- a/tests/wpt/meta/webdriver/tests/classic/set_window_rect/set.py.ini +++ b/tests/wpt/meta/webdriver/tests/classic/set_window_rect/set.py.ini @@ -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