mirror of
https://github.com/servo/servo.git
synced 2025-08-06 22:15:33 +01:00
servoshell: Respond resize with authentic result and Adjust minimum window size (#38258)
- We no longer pretend that resize is always successful and simplify the result computation. - Adjust minimum window size to match other browsers and the test expectation. - Restrict some unnecessary access specifier. Testing: ` ./mach test-wpt -r "tests\wpt\tests\webdriver\tests\classic\set_window_rect\set.py" --log-raw "D:\servo test log\set.txt" --product servodriver {--headless}` Fixes: #37804 as Task 8 is last task. --------- Signed-off-by: Euclid Ye <euclid.ye@huawei.com>
This commit is contained in:
parent
d39e701b46
commit
928934d4b0
5 changed files with 25 additions and 37 deletions
|
@ -21,11 +21,9 @@ use log::{info, trace, warn};
|
|||
use net::protocols::ProtocolRegistry;
|
||||
use servo::config::opts::Opts;
|
||||
use servo::config::prefs::Preferences;
|
||||
use servo::servo_geometry::convert_rect_to_css_pixel;
|
||||
use servo::servo_url::ServoUrl;
|
||||
use servo::user_content_manager::{UserContentManager, UserScript};
|
||||
use servo::webrender_api::ScrollLocation;
|
||||
use servo::webrender_api::units::DeviceIntRect;
|
||||
use servo::{
|
||||
EventLoopWaker, ImeEvent, InputEvent, KeyboardEvent, MouseButtonEvent, MouseMoveEvent,
|
||||
WebDriverCommandMsg, WebDriverScriptCommand, WebDriverUserPromptAction, WheelDelta, WheelEvent,
|
||||
|
@ -39,7 +37,6 @@ use winit::window::WindowId;
|
|||
|
||||
use super::app_state::AppState;
|
||||
use super::events_loop::{AppEvent, EventLoopProxy, EventsLoop};
|
||||
use super::geometry::winit_position_to_euclid_point;
|
||||
use super::minibrowser::{Minibrowser, MinibrowserEvent};
|
||||
use super::{headed_window, headless_window};
|
||||
use crate::desktop::app_state::RunningAppState;
|
||||
|
@ -410,32 +407,13 @@ impl App {
|
|||
let requested_physical_rect =
|
||||
(requested_rect.to_f32() * scale).round().to_i32();
|
||||
|
||||
// When None is returned, it means that the request went to the display system,
|
||||
// and the actual size will be delivered later with the WindowEvent::Resized.
|
||||
// Step 17. Set Width/Height.
|
||||
let returned_size =
|
||||
window.request_resize(&webview, requested_physical_rect.size());
|
||||
// TODO: Handle None case. For now, we assume always succeed.
|
||||
// In reality, the request may exceed available screen size.
|
||||
window.request_resize(&webview, requested_physical_rect.size());
|
||||
|
||||
// Step 18. Set position of the window.
|
||||
window.set_position(requested_physical_rect.min);
|
||||
|
||||
let result_physical_position = window
|
||||
.winit_window()
|
||||
.and_then(|window| window.outer_position().ok())
|
||||
.map(winit_position_to_euclid_point)
|
||||
.unwrap_or(requested_physical_rect.min);
|
||||
|
||||
let reply_rect = convert_rect_to_css_pixel(
|
||||
DeviceIntRect::from_origin_and_size(
|
||||
result_physical_position,
|
||||
returned_size.unwrap_or(requested_physical_rect.size()),
|
||||
),
|
||||
scale,
|
||||
);
|
||||
|
||||
if let Err(error) = size_sender.send(reply_rect) {
|
||||
if let Err(error) = size_sender.send(window.window_rect()) {
|
||||
warn!("Failed to send window size: {error}");
|
||||
}
|
||||
},
|
||||
|
|
|
@ -48,7 +48,10 @@ use {
|
|||
use super::app_state::RunningAppState;
|
||||
use super::geometry::{winit_position_to_euclid_point, winit_size_to_euclid_size};
|
||||
use super::keyutils::{CMD_OR_ALT, keyboard_event_from_winit};
|
||||
use super::window_trait::{LINE_HEIGHT, LINE_WIDTH, PIXEL_DELTA_FACTOR, WindowPortsMethods};
|
||||
use super::window_trait::{
|
||||
LINE_HEIGHT, LINE_WIDTH, MIN_INNER_HEIGHT, MIN_INNER_WIDTH, PIXEL_DELTA_FACTOR,
|
||||
WindowPortsMethods,
|
||||
};
|
||||
use crate::desktop::accelerated_gl_media::setup_gl_accelerated_media;
|
||||
use crate::desktop::keyutils::CMD_OR_CONTROL;
|
||||
use crate::prefs::ServoShellPreferences;
|
||||
|
@ -97,7 +100,7 @@ impl Window {
|
|||
.with_decorations(!no_native_titlebar)
|
||||
.with_transparent(no_native_titlebar)
|
||||
.with_inner_size(LogicalSize::new(inner_size.width, inner_size.height))
|
||||
.with_min_inner_size(LogicalSize::new(1, 1))
|
||||
.with_min_inner_size(LogicalSize::new(MIN_INNER_WIDTH, MIN_INNER_HEIGHT))
|
||||
// Must be invisible at startup; accesskit_winit setup needs to
|
||||
// happen before the window is shown for the first time.
|
||||
.with_visible(false);
|
||||
|
@ -772,8 +775,11 @@ impl WindowPortsMethods for Window {
|
|||
// Prevent the inner area from being 0 pixels wide or tall
|
||||
// this prevents a crash in the compositor due to invalid surface size
|
||||
self.winit_window.set_min_inner_size(Some(PhysicalSize::new(
|
||||
1.0,
|
||||
1.0 + (self.toolbar_height() * self.hidpi_scale_factor()).0,
|
||||
MIN_INNER_WIDTH,
|
||||
i32::max(
|
||||
MIN_INNER_HEIGHT,
|
||||
(self.toolbar_height() * self.hidpi_scale_factor()).0 as i32,
|
||||
),
|
||||
)));
|
||||
}
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ use servo::{RenderingContext, ScreenGeometry, SoftwareRenderingContext};
|
|||
use winit::dpi::PhysicalSize;
|
||||
|
||||
use super::app_state::RunningAppState;
|
||||
use crate::desktop::window_trait::WindowPortsMethods;
|
||||
use crate::desktop::window_trait::{MIN_INNER_HEIGHT, MIN_INNER_WIDTH, WindowPortsMethods};
|
||||
use crate::prefs::ServoShellPreferences;
|
||||
|
||||
pub struct Window {
|
||||
|
@ -89,8 +89,10 @@ impl WindowPortsMethods for Window {
|
|||
webview: &::servo::WebView,
|
||||
outer_size: DeviceIntSize,
|
||||
) -> Option<DeviceIntSize> {
|
||||
// Surfman doesn't support zero-sized surfaces.
|
||||
let new_size = DeviceIntSize::new(outer_size.width.max(1), outer_size.height.max(1));
|
||||
let new_size = DeviceIntSize::new(
|
||||
outer_size.width.max(MIN_INNER_WIDTH),
|
||||
outer_size.height.max(MIN_INNER_HEIGHT),
|
||||
);
|
||||
if self.inner_size.get() == new_size {
|
||||
return Some(new_size);
|
||||
}
|
||||
|
|
|
@ -15,12 +15,17 @@ use servo::{Cursor, RenderingContext, ScreenGeometry, WebView};
|
|||
use super::app_state::RunningAppState;
|
||||
|
||||
// This should vary by zoom level and maybe actual text size (focused or under cursor)
|
||||
pub const LINE_HEIGHT: f32 = 76.0;
|
||||
pub const LINE_WIDTH: f32 = 76.0;
|
||||
pub(crate) const LINE_HEIGHT: f32 = 76.0;
|
||||
pub(crate) const LINE_WIDTH: f32 = 76.0;
|
||||
// MouseScrollDelta::PixelDelta is default for MacOS, which is high precision and very slow
|
||||
// in winit. Therefore we use a factor of 4.0 to make it more usable.
|
||||
// See https://github.com/servo/servo/pull/34063#discussion_r2197729507
|
||||
pub const PIXEL_DELTA_FACTOR: f64 = 4.0;
|
||||
pub(crate) const PIXEL_DELTA_FACTOR: f64 = 4.0;
|
||||
|
||||
/// <https://github.com/web-platform-tests/wpt/blob/9320b1f724632c52929a3fdb11bdaf65eafc7611/webdriver/tests/classic/set_window_rect/set.py#L287-L290>
|
||||
/// "A window size of 10x10px shouldn't be supported by any browser."
|
||||
pub(crate) const MIN_INNER_WIDTH: i32 = 20;
|
||||
pub(crate) const MIN_INNER_HEIGHT: i32 = 20;
|
||||
|
||||
pub trait WindowPortsMethods {
|
||||
fn id(&self) -> winit::window::WindowId;
|
||||
|
|
|
@ -7,6 +7,3 @@
|
|||
|
||||
[test_set_to_available_size]
|
||||
expected: FAIL
|
||||
|
||||
[test_set_smaller_than_minimum_browser_size]
|
||||
expected: FAIL
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue