servoshell: Make fn request_resize resize window w.r.t. outer_size accurately (#37848)

`toolbar_height` is already part of `inner_size`, caused wrongly
calculated `outer_size`. Even worse, it tried to `request_inner_size`
with the already wrong `outer_size`.

This PR make sure resize is accurate by first calculate the title/border
height, and then compute the `inner_size` for `request_inner_size`. This
is necessary because no direct `request_outer_size` is available.

Testing: As manually tested, set window size WebDriver command no longer
overshoot. This is also shared by
[window.resizeTo](https://drafts.csswg.org/cssom-view/#dom-window-resizeto)
JS method. WPT test would be necessary. (But that one is intermittent
TIMEOUT. So created new one in
https://github.com/servo/servo/pull/37856)
 
WebDriver test will be postponed after
https://github.com/web-platform-tests/wpt/pull/53421 is merged and
synced to Servo.

Fixes: Task 3 of https://github.com/servo/servo/issues/37804

---------

Signed-off-by: Euclid Ye <yezhizhenjiakang@gmail.com>
This commit is contained in:
Euclid Ye 2025-07-04 16:10:58 +08:00 committed by GitHub
parent a990ff82b9
commit aaf04883dd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 11 additions and 11 deletions

View file

@ -466,14 +466,13 @@ impl WindowPortsMethods for Window {
self.winit_window.set_title(title);
}
fn request_resize(&self, _: &WebView, size: DeviceIntSize) -> Option<DeviceIntSize> {
let toolbar_height = self.toolbar_height() * self.hidpi_scale_factor();
let toolbar_height = toolbar_height.get().ceil() as i32;
let total_size = PhysicalSize::new(size.width, size.height + toolbar_height);
fn request_resize(&self, _: &WebView, new_outer_size: DeviceIntSize) -> Option<DeviceIntSize> {
let title_height =
self.winit_window.outer_size().height - self.winit_window.inner_size().height;
self.winit_window
.request_inner_size::<PhysicalSize<i32>>(PhysicalSize::new(
total_size.width,
total_size.height,
new_outer_size.width,
new_outer_size.height - title_height as i32,
))
.and_then(|size| {
Some(DeviceIntSize::new(