diff --git a/ports/servoshell/desktop/app.rs b/ports/servoshell/desktop/app.rs index 929c4ef1634..304969425ae 100644 --- a/ports/servoshell/desktop/app.rs +++ b/ports/servoshell/desktop/app.rs @@ -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}"); } }, diff --git a/ports/servoshell/desktop/headed_window.rs b/ports/servoshell/desktop/headed_window.rs index 919a63ea65c..6a33441e51d 100644 --- a/ports/servoshell/desktop/headed_window.rs +++ b/ports/servoshell/desktop/headed_window.rs @@ -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, + ), ))); } diff --git a/ports/servoshell/desktop/headless_window.rs b/ports/servoshell/desktop/headless_window.rs index bde20a6af6f..ba8e42350e9 100644 --- a/ports/servoshell/desktop/headless_window.rs +++ b/ports/servoshell/desktop/headless_window.rs @@ -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 { - // 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); } diff --git a/ports/servoshell/desktop/window_trait.rs b/ports/servoshell/desktop/window_trait.rs index 14684ec084b..ed8853e1141 100644 --- a/ports/servoshell/desktop/window_trait.rs +++ b/ports/servoshell/desktop/window_trait.rs @@ -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; + +/// +/// "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; 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 1bf0271bcd6..9d873028e65 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 @@ -7,6 +7,3 @@ [test_set_to_available_size] expected: FAIL - - [test_set_smaller_than_minimum_browser_size] - expected: FAIL