script: Get the window rectangle from the WebViewDelegate instead of via the compositor (#37960)

Previously, `screenX`, `screenY`, `outerHeight`, `outerWidth`, `moveBy`,
`resizeBy` ask compositor for window rectangle, which then return
"inner" rectangle after consulting Embedder.

This PR 
1. removes `GetClientWindowRect` from compositor, and directly let
script ask embedder.
2. add `window_size` to `ScreenGeometry`
3. add a lot of docs to `ScreenGeometry`

Testing: `tests\wpt\mozilla\tests\mozilla\window_resizeTo.html` can now
pass for Headed Window.
Fixes: #37824

---------

Signed-off-by: Euclid Ye <yezhizhenjiakang@gmail.com>
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Martin Robinson <mrobinson@igalia.com>
This commit is contained in:
Euclid Ye 2025-07-12 02:31:24 +08:00 committed by GitHub
parent d40e9f82a2
commit c5aeac3cea
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
16 changed files with 59 additions and 104 deletions

View file

@ -17,7 +17,7 @@ use raw_window_handle::{HasDisplayHandle, HasWindowHandle, RawWindowHandle};
use servo::servo_config::pref;
use servo::servo_geometry::{DeviceIndependentIntRect, DeviceIndependentPixel};
use servo::webrender_api::ScrollLocation;
use servo::webrender_api::units::{DeviceIntPoint, DeviceIntSize, DevicePixel};
use servo::webrender_api::units::{DeviceIntPoint, DeviceIntRect, DeviceIntSize, DevicePixel};
use servo::{
Cursor, ImeEvent, InputEvent, Key, KeyState, KeyboardEvent, MouseButton as ServoMouseButton,
MouseButtonAction, MouseButtonEvent, MouseLeaveEvent, MouseMoveEvent,
@ -429,22 +429,22 @@ impl WindowPortsMethods for Window {
0.0,
(self.toolbar_height.get() * self.hidpi_scale_factor()).0,
);
let screen_size = self.screen_size.to_f32() * hidpi_factor;
// FIXME: In reality, this should subtract screen space used by the system interface
// elements, but it is difficult to get this value with `winit` currently. See:
// See https://github.com/rust-windowing/winit/issues/2494
let available_screen_size = screen_size - toolbar_size;
// Offset the WebView origin by the toolbar so that it reflects the actual viewport and
// not the window origin.
let window_origin = self.winit_window.outer_position().unwrap_or_default();
let offset = winit_position_to_euclid_point(window_origin);
let window_rect = DeviceIntRect::from_origin_and_size(
winit_position_to_euclid_point(self.winit_window.outer_position().unwrap_or_default()),
winit_size_to_euclid_size(self.winit_window.outer_size()).to_i32(),
);
ScreenGeometry {
size: screen_size.to_i32(),
available_size: available_screen_size.to_i32(),
offset,
window_rect,
}
}

View file

@ -68,7 +68,7 @@ impl WindowPortsMethods for Window {
ScreenGeometry {
size: self.screen_size,
available_size: self.screen_size,
offset: Default::default(),
window_rect: self.inner_size.get().into(),
}
}

View file

@ -124,13 +124,12 @@ impl ServoDelegate for ServoShellServoDelegate {
impl WebViewDelegate for RunningAppState {
fn screen_geometry(&self, _webview: WebView) -> Option<ScreenGeometry> {
let coord = self.callbacks.coordinates.borrow();
let offset = coord.origin();
let available_size = coord.size();
let screen_size = coord.size();
Some(ScreenGeometry {
size: screen_size,
available_size,
offset,
window_rect: DeviceIntRect::from_origin_and_size(coord.origin(), coord.size()),
})
}