diff --git a/Cargo.lock b/Cargo.lock index 354a7cd78a7..f81940092aa 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2252,6 +2252,7 @@ dependencies = [ "num-traits", "pixels", "serde", + "servo_geometry", "servo_malloc_size_of", "servo_url", "strum_macros", diff --git a/components/shared/embedder/Cargo.toml b/components/shared/embedder/Cargo.toml index 801a300bad4..77734043b0c 100644 --- a/components/shared/embedder/Cargo.toml +++ b/components/shared/embedder/Cargo.toml @@ -39,3 +39,4 @@ stylo = { workspace = true } url = { workspace = true } webdriver = { workspace = true } webrender_api = { workspace = true } +servo_geometry = { path = "../../geometry" } diff --git a/components/shared/embedder/webdriver.rs b/components/shared/embedder/webdriver.rs index be19e6a2855..224f319fa90 100644 --- a/components/shared/embedder/webdriver.rs +++ b/components/shared/embedder/webdriver.rs @@ -16,11 +16,12 @@ use keyboard_types::KeyboardEvent; use keyboard_types::webdriver::Event as WebDriverInputEvent; use pixels::RasterImage; use serde::{Deserialize, Serialize}; +use servo_geometry::{DeviceIndependentIntRect, DeviceIndependentIntSize, DeviceIndependentPixel}; use servo_url::ServoUrl; use style_traits::CSSPixel; use webdriver::common::{WebElement, WebFrame, WebWindow}; use webdriver::error::ErrorStatus; -use webrender_api::units::{DeviceIntRect, DeviceIntSize, DevicePixel}; +use webrender_api::units::DevicePixel; use crate::{MouseButton, MouseButtonAction}; @@ -34,7 +35,7 @@ pub enum WebDriverCommandMsg { /// back to the WebDriver client. It is set to constellation for now SetWebDriverResponseSender(IpcSender), /// Get the window size. - GetWindowRect(WebViewId, IpcSender), + GetWindowRect(WebViewId, IpcSender), /// Get the viewport size. GetViewportSize(WebViewId, IpcSender>), /// Load a URL in the top-level browsing context with the given ID. @@ -90,8 +91,8 @@ pub enum WebDriverCommandMsg { /// Set the window size. SetWindowSize( WebViewId, - DeviceIntSize, - IpcSender>, + DeviceIndependentIntSize, + IpcSender>, ), /// Take a screenshot of the window. TakeScreenshot( diff --git a/ports/servoshell/desktop/app.rs b/ports/servoshell/desktop/app.rs index 75a24e5059f..72050f78e94 100644 --- a/ports/servoshell/desktop/app.rs +++ b/ports/servoshell/desktop/app.rs @@ -20,9 +20,11 @@ use log::{info, trace, warn}; use net::protocols::ProtocolRegistry; use servo::config::opts::Opts; use servo::config::prefs::Preferences; +use servo::servo_geometry::DeviceIndependentIntSize; use servo::servo_url::ServoUrl; use servo::user_content_manager::{UserContentManager, UserScript}; use servo::webrender_api::ScrollLocation; +use servo::webrender_api::units::DeviceIntSize; use servo::{ EventLoopWaker, InputEvent, KeyboardEvent, MouseButtonEvent, MouseMoveEvent, WebDriverCommandMsg, WheelDelta, WheelEvent, WheelMode, @@ -403,13 +405,31 @@ impl App { .values() .next() .expect("Should have at least one window in servoshell"); - + let scale = window.hidpi_scale_factor().get() as f64; + // TODO: Find a universal way to convert. + // See https://github.com/servo/servo/issues/37937 + let requested_physical_size = DeviceIntSize::new( + (requested_size.width as f64 * scale).round() as i32, + (requested_size.height as f64 * scale).round() as 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. - let returned_size = window.request_resize(&webview, requested_size); + let returned_size = window.request_resize(&webview, requested_physical_size); // TODO: Handle None case. For now, we assume always succeed. // In reality, the request may exceed available screen size. - if let Err(error) = size_sender.send(returned_size.unwrap_or(requested_size)) { + + // TODO: Find a universal way to convert. + // See https://github.com/servo/servo/issues/37937 + if let Err(error) = size_sender.send( + returned_size + .map(|size| { + DeviceIndependentIntSize::new( + (size.width as f64 / scale).round() as i32, + (size.height as f64 / scale).round() as i32, + ) + }) + .unwrap_or(requested_size), + ) { warn!("Failed to send window size: {error}"); } }, diff --git a/ports/servoshell/desktop/headed_window.rs b/ports/servoshell/desktop/headed_window.rs index 7637bf91ecd..a3825de6a2f 100644 --- a/ports/servoshell/desktop/headed_window.rs +++ b/ports/servoshell/desktop/headed_window.rs @@ -15,9 +15,9 @@ use keyboard_types::{Modifiers, ShortcutMatcher}; use log::{debug, info}; use raw_window_handle::{HasDisplayHandle, HasWindowHandle, RawWindowHandle}; use servo::servo_config::pref; -use servo::servo_geometry::DeviceIndependentPixel; +use servo::servo_geometry::{DeviceIndependentIntRect, DeviceIndependentPixel}; use servo::webrender_api::ScrollLocation; -use servo::webrender_api::units::{DeviceIntPoint, DeviceIntRect, DeviceIntSize, DevicePixel}; +use servo::webrender_api::units::{DeviceIntPoint, DeviceIntSize, DevicePixel}; use servo::{ Cursor, ImeEvent, InputEvent, Key, KeyState, KeyboardEvent, MouseButton as ServoMouseButton, MouseButtonAction, MouseButtonEvent, MouseLeaveEvent, MouseMoveEvent, @@ -484,15 +484,28 @@ impl WindowPortsMethods for Window { }) } - fn window_rect(&self) -> DeviceIntRect { + fn window_rect(&self) -> DeviceIndependentIntRect { let outer_size = self.winit_window.outer_size(); - let total_size = Size2D::new(outer_size.width as i32, outer_size.height as i32); + let hidpi_scale = self.hidpi_scale_factor().get() as f64; + // TODO: Find a universal way to convert. + // See https://github.com/servo/servo/issues/37937 + let total_size = Size2D::new( + (outer_size.width as f64 / hidpi_scale).round() as i32, + (outer_size.height as f64 / hidpi_scale).round() as i32, + ); + // TODO: Find a universal way to convert. + // See https://github.com/servo/servo/issues/37937 let origin = self .winit_window .outer_position() - .map(|point| Point2D::new(point.x, point.y)) + .map(|point| { + Point2D::new( + (point.x as f64 / hidpi_scale).round() as i32, + (point.y as f64 / hidpi_scale).round() as i32, + ) + }) .unwrap_or_default(); - DeviceIntRect::from_origin_and_size(origin, total_size) + DeviceIndependentIntRect::from_origin_and_size(origin, total_size) } fn set_position(&self, point: DeviceIntPoint) { diff --git a/ports/servoshell/desktop/headless_window.rs b/ports/servoshell/desktop/headless_window.rs index 4853a2fd68c..604644383a1 100644 --- a/ports/servoshell/desktop/headless_window.rs +++ b/ports/servoshell/desktop/headless_window.rs @@ -9,8 +9,8 @@ use std::rc::Rc; use euclid::num::Zero; use euclid::{Length, Point2D, Scale, Size2D}; -use servo::servo_geometry::DeviceIndependentPixel; -use servo::webrender_api::units::{DeviceIntRect, DeviceIntSize, DevicePixel}; +use servo::servo_geometry::{DeviceIndependentIntRect, DeviceIndependentPixel}; +use servo::webrender_api::units::{DeviceIntSize, DevicePixel}; use servo::{RenderingContext, ScreenGeometry, SoftwareRenderingContext}; use winit::dpi::PhysicalSize; @@ -135,8 +135,18 @@ impl WindowPortsMethods for Window { Length::zero() } - fn window_rect(&self) -> DeviceIntRect { - DeviceIntRect::from_origin_and_size(Point2D::zero(), self.inner_size.get()) + fn window_rect(&self) -> DeviceIndependentIntRect { + let inner_size = self.inner_size.get().to_f64(); + let scale = self.hidpi_scale_factor().get() as f64; + // TODO: Find a universal way to convert. + // See https://github.com/servo/servo/issues/37937 + DeviceIndependentIntRect::from_origin_and_size( + Point2D::zero(), + Size2D::new( + (inner_size.width / scale).round() as i32, + (inner_size.height / scale).round() as i32, + ), + ) } fn set_toolbar_height(&self, _height: Length) { diff --git a/ports/servoshell/desktop/window_trait.rs b/ports/servoshell/desktop/window_trait.rs index 1ef83443adf..2c9f508b728 100644 --- a/ports/servoshell/desktop/window_trait.rs +++ b/ports/servoshell/desktop/window_trait.rs @@ -8,8 +8,8 @@ use std::rc::Rc; use euclid::{Length, Scale}; -use servo::servo_geometry::DeviceIndependentPixel; -use servo::webrender_api::units::{DeviceIntPoint, DeviceIntRect, DeviceIntSize, DevicePixel}; +use servo::servo_geometry::{DeviceIndependentIntRect, DeviceIndependentPixel}; +use servo::webrender_api::units::{DeviceIntPoint, DeviceIntSize, DevicePixel}; use servo::{Cursor, RenderingContext, ScreenGeometry, WebView}; use super::app_state::RunningAppState; @@ -53,5 +53,5 @@ pub trait WindowPortsMethods { fn theme(&self) -> servo::Theme { servo::Theme::Light } - fn window_rect(&self) -> DeviceIntRect; + fn window_rect(&self) -> DeviceIndependentIntRect; } diff --git a/tests/wpt/meta/webdriver/tests/classic/perform_actions/key_events.py.ini b/tests/wpt/meta/webdriver/tests/classic/perform_actions/key_events.py.ini index 84f25b1d168..bc95c663ec8 100644 --- a/tests/wpt/meta/webdriver/tests/classic/perform_actions/key_events.py.ini +++ b/tests/wpt/meta/webdriver/tests/classic/perform_actions/key_events.py.ini @@ -22,252 +22,3 @@ [test_modifier_key_sends_correct_events[\\ue052-R_ALT\]] expected: FAIL - - [test_modifier_key_sends_correct_events[\\ue051-R_CONTROL\]] - expected: FAIL - - [test_modifier_key_sends_correct_events[\\ue053-R_META\]] - expected: FAIL - - [test_modifier_key_sends_correct_events[\\ue050-R_SHIFT\]] - expected: FAIL - - [test_non_printable_key_sends_events[\\ue014-RIGHT\]] - expected: FAIL - - [test_printable_key_sends_correct_events[a-KeyA0\]] - expected: FAIL - - [test_printable_key_sends_correct_events[a-KeyA1\]] - expected: FAIL - - [test_printable_key_sends_correct_events["-Quote\]] - expected: FAIL - - [test_printable_key_sends_correct_events[,-Comma\]] - expected: FAIL - - [test_printable_key_sends_correct_events[\\xe0-\]] - expected: FAIL - - [test_printable_key_sends_correct_events[\\u0416-\]] - expected: FAIL - - [test_printable_key_sends_correct_events[@-Digit2\]] - expected: FAIL - - [test_printable_key_sends_correct_events[\\u2603-\]] - expected: FAIL - - [test_printable_key_sends_correct_events[\\uf6c2-\]] - expected: FAIL - - [test_sequence_of_keydown_printable_keys_sends_events] - expected: FAIL - - [test_sequence_of_keydown_printable_characters_sends_events] - expected: FAIL - - [test_special_key_sends_keydown[ADD-expected0\]] - expected: FAIL - - [test_special_key_sends_keydown[ALT-expected1\]] - expected: FAIL - - [test_special_key_sends_keydown[BACKSPACE-expected2\]] - expected: FAIL - - [test_special_key_sends_keydown[CANCEL-expected3\]] - expected: FAIL - - [test_special_key_sends_keydown[CLEAR-expected4\]] - expected: FAIL - - [test_special_key_sends_keydown[CONTROL-expected5\]] - expected: FAIL - - [test_special_key_sends_keydown[DECIMAL-expected6\]] - expected: FAIL - - [test_special_key_sends_keydown[DELETE-expected7\]] - expected: FAIL - - [test_special_key_sends_keydown[DIVIDE-expected8\]] - expected: FAIL - - [test_special_key_sends_keydown[DOWN-expected9\]] - expected: FAIL - - [test_special_key_sends_keydown[END-expected10\]] - expected: FAIL - - [test_special_key_sends_keydown[ENTER-expected11\]] - expected: FAIL - - [test_special_key_sends_keydown[ESCAPE-expected13\]] - expected: FAIL - - [test_special_key_sends_keydown[F1-expected14\]] - expected: FAIL - - [test_special_key_sends_keydown[F10-expected15\]] - expected: FAIL - - [test_special_key_sends_keydown[F11-expected16\]] - expected: FAIL - - [test_special_key_sends_keydown[F12-expected17\]] - expected: FAIL - - [test_special_key_sends_keydown[F2-expected18\]] - expected: FAIL - - [test_special_key_sends_keydown[F3-expected19\]] - expected: FAIL - - [test_special_key_sends_keydown[F4-expected20\]] - expected: FAIL - - [test_special_key_sends_keydown[F5-expected21\]] - expected: FAIL - - [test_special_key_sends_keydown[F6-expected22\]] - expected: FAIL - - [test_special_key_sends_keydown[F7-expected23\]] - expected: FAIL - - [test_special_key_sends_keydown[F8-expected24\]] - expected: FAIL - - [test_special_key_sends_keydown[F9-expected25\]] - expected: FAIL - - [test_special_key_sends_keydown[HELP-expected26\]] - expected: FAIL - - [test_special_key_sends_keydown[HOME-expected27\]] - expected: FAIL - - [test_special_key_sends_keydown[INSERT-expected28\]] - expected: FAIL - - [test_special_key_sends_keydown[LEFT-expected29\]] - expected: FAIL - - [test_special_key_sends_keydown[META-expected30\]] - expected: FAIL - - [test_special_key_sends_keydown[MULTIPLY-expected31\]] - expected: FAIL - - [test_special_key_sends_keydown[NULL-expected32\]] - expected: FAIL - - [test_special_key_sends_keydown[NUMPAD0-expected33\]] - expected: FAIL - - [test_special_key_sends_keydown[NUMPAD1-expected34\]] - expected: FAIL - - [test_special_key_sends_keydown[NUMPAD2-expected35\]] - expected: FAIL - - [test_special_key_sends_keydown[NUMPAD3-expected36\]] - expected: FAIL - - [test_special_key_sends_keydown[NUMPAD4-expected37\]] - expected: FAIL - - [test_special_key_sends_keydown[NUMPAD5-expected38\]] - expected: FAIL - - [test_special_key_sends_keydown[NUMPAD6-expected39\]] - expected: FAIL - - [test_special_key_sends_keydown[NUMPAD7-expected40\]] - expected: FAIL - - [test_special_key_sends_keydown[NUMPAD8-expected41\]] - expected: FAIL - - [test_special_key_sends_keydown[NUMPAD9-expected42\]] - expected: FAIL - - [test_special_key_sends_keydown[PAGE_DOWN-expected43\]] - expected: FAIL - - [test_special_key_sends_keydown[PAGE_UP-expected44\]] - expected: FAIL - - [test_special_key_sends_keydown[RETURN-expected46\]] - expected: FAIL - - [test_special_key_sends_keydown[RIGHT-expected47\]] - expected: FAIL - - [test_special_key_sends_keydown[R_ALT-expected48\]] - expected: FAIL - - [test_special_key_sends_keydown[R_ARROWDOWN-expected49\]] - expected: FAIL - - [test_special_key_sends_keydown[R_ARROWLEFT-expected50\]] - expected: FAIL - - [test_special_key_sends_keydown[R_ARROWRIGHT-expected51\]] - expected: FAIL - - [test_special_key_sends_keydown[R_ARROWUP-expected52\]] - expected: FAIL - - [test_special_key_sends_keydown[R_CONTROL-expected53\]] - expected: FAIL - - [test_special_key_sends_keydown[R_DELETE-expected54\]] - expected: FAIL - - [test_special_key_sends_keydown[R_END-expected55\]] - expected: FAIL - - [test_special_key_sends_keydown[R_HOME-expected56\]] - expected: FAIL - - [test_special_key_sends_keydown[R_INSERT-expected57\]] - expected: FAIL - - [test_special_key_sends_keydown[R_META-expected58\]] - expected: FAIL - - [test_special_key_sends_keydown[R_PAGEDOWN-expected59\]] - expected: FAIL - - [test_special_key_sends_keydown[R_PAGEUP-expected60\]] - expected: FAIL - - [test_special_key_sends_keydown[R_SHIFT-expected61\]] - expected: FAIL - - [test_special_key_sends_keydown[SEMICOLON-expected62\]] - expected: FAIL - - [test_special_key_sends_keydown[SEPARATOR-expected63\]] - expected: FAIL - - [test_special_key_sends_keydown[SHIFT-expected64\]] - expected: FAIL - - [test_special_key_sends_keydown[SPACE-expected65\]] - expected: FAIL - - [test_special_key_sends_keydown[SUBTRACT-expected66\]] - expected: FAIL - - [test_special_key_sends_keydown[TAB-expected67\]] - expected: FAIL - - [test_special_key_sends_keydown[UP-expected68\]] - expected: FAIL - - [test_special_key_sends_keydown[ZENKAKUHANKAKU-expected69\]] - expected: FAIL