diff --git a/components/constellation/constellation.rs b/components/constellation/constellation.rs index 616fb10b288..14c52df80fa 100644 --- a/components/constellation/constellation.rs +++ b/components/constellation/constellation.rs @@ -4534,7 +4534,7 @@ where let is_open = self.browsing_contexts.contains_key(&browsing_context_id); let _ = response_sender.send(is_open); }, - WebDriverCommandMsg::GetWindowSize(..) => { + WebDriverCommandMsg::GetWindowRect(..) => { unreachable!("This command should be send directly to the embedder."); }, WebDriverCommandMsg::GetViewportSize(..) => { diff --git a/components/shared/embedder/webdriver.rs b/components/shared/embedder/webdriver.rs index 58fdcdcb4c9..8a29cabb5df 100644 --- a/components/shared/embedder/webdriver.rs +++ b/components/shared/embedder/webdriver.rs @@ -20,7 +20,7 @@ use servo_url::ServoUrl; use style_traits::CSSPixel; use webdriver::common::{WebElement, WebFrame, WebWindow}; use webdriver::error::ErrorStatus; -use webrender_api::units::{DeviceIntSize, DevicePixel}; +use webrender_api::units::{DeviceIntRect, DeviceIntSize, DevicePixel}; use crate::{MouseButton, MouseButtonAction}; @@ -31,7 +31,7 @@ pub struct WebDriverMessageId(pub usize); #[derive(Debug, Deserialize, Serialize)] pub enum WebDriverCommandMsg { /// Get the window size. - GetWindowSize(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. diff --git a/components/webdriver_server/lib.rs b/components/webdriver_server/lib.rs index 5038ebd2ac0..e06879cab60 100644 --- a/components/webdriver_server/lib.rs +++ b/components/webdriver_server/lib.rs @@ -799,7 +799,7 @@ impl Handler { } /// - fn handle_window_size( + fn handle_window_rect( &self, verify: VerifyBrowsingContextIsOpen, ) -> WebDriverResult { @@ -810,14 +810,14 @@ impl Handler { if let VerifyBrowsingContextIsOpen::Yes = verify { self.verify_top_level_browsing_context_is_open(webview_id)?; } - self.send_message_to_embedder(WebDriverCommandMsg::GetWindowSize(webview_id, sender))?; + self.send_message_to_embedder(WebDriverCommandMsg::GetWindowRect(webview_id, sender))?; - let window_size = wait_for_script_response(receiver)?; + let window_rect = wait_for_script_response(receiver)?; let window_size_response = WindowRectResponse { - x: 0, - y: 0, - width: window_size.width, - height: window_size.height, + x: window_rect.min.x, + y: window_rect.min.y, + width: window_rect.width(), + height: window_rect.height(), }; Ok(WebDriverResponse::WindowRect(window_size_response)) } @@ -842,7 +842,7 @@ impl Handler { // We don't current allow modifying the window x/y positions, so we can just // return the current window rectangle if not changing dimension. if params.width.is_none() && params.height.is_none() { - return self.handle_window_size(VerifyBrowsingContextIsOpen::No); + return self.handle_window_rect(VerifyBrowsingContextIsOpen::No); } // (TODO) Step 14. Fully exit fullscreen. // (TODO) Step 15. Restore the window. @@ -853,7 +853,7 @@ impl Handler { let current = LazyCell::new(|| { let WebDriverResponse::WindowRect(current) = self - .handle_window_size(VerifyBrowsingContextIsOpen::No) + .handle_window_rect(VerifyBrowsingContextIsOpen::No) .unwrap() else { unreachable!("handle_window_size() must return WindowRect"); @@ -2160,7 +2160,7 @@ impl WebDriverHandler for Handler { WebDriverCommand::Get(ref parameters) => self.handle_get(parameters), WebDriverCommand::GetCurrentUrl => self.handle_current_url(), WebDriverCommand::GetWindowRect => { - self.handle_window_size(VerifyBrowsingContextIsOpen::Yes) + self.handle_window_rect(VerifyBrowsingContextIsOpen::Yes) }, WebDriverCommand::SetWindowRect(ref size) => self.handle_set_window_size(size), WebDriverCommand::IsEnabled(ref element) => self.handle_is_enabled(element), diff --git a/ports/servoshell/desktop/app.rs b/ports/servoshell/desktop/app.rs index 1735545fe57..00f3b7f846e 100644 --- a/ports/servoshell/desktop/app.rs +++ b/ports/servoshell/desktop/app.rs @@ -362,14 +362,14 @@ impl App { // TODO: send a response to the WebDriver // so it knows when the focus has finished. }, - WebDriverCommandMsg::GetWindowSize(_webview_id, response_sender) => { + WebDriverCommandMsg::GetWindowRect(_webview_id, response_sender) => { let window = self .windows .values() .next() .expect("Should have at least one window in servoshell"); - if let Err(error) = response_sender.send(window.screen_geometry().size) { + if let Err(error) = response_sender.send(window.window_rect()) { warn!("Failed to send response of GetWindowSize: {error}"); } }, diff --git a/ports/servoshell/desktop/headed_window.rs b/ports/servoshell/desktop/headed_window.rs index a4ebb4463e7..3769a43629c 100644 --- a/ports/servoshell/desktop/headed_window.rs +++ b/ports/servoshell/desktop/headed_window.rs @@ -17,7 +17,7 @@ use raw_window_handle::{HasDisplayHandle, HasWindowHandle, RawWindowHandle}; use servo::servo_config::pref; use servo::servo_geometry::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, @@ -483,6 +483,17 @@ impl WindowPortsMethods for Window { }) } + fn window_rect(&self) -> DeviceIntRect { + let outer_size = self.winit_window.outer_size(); + let total_size = Size2D::new(outer_size.width as i32, outer_size.height as i32); + let origin = self + .winit_window + .outer_position() + .map(|point| Point2D::new(point.x, point.y)) + .unwrap_or_default(); + DeviceIntRect::from_origin_and_size(origin, total_size) + } + fn set_position(&self, point: DeviceIntPoint) { self.winit_window .set_outer_position::>(PhysicalPosition::new(point.x, point.y)) diff --git a/ports/servoshell/desktop/headless_window.rs b/ports/servoshell/desktop/headless_window.rs index bf99b400349..4853a2fd68c 100644 --- a/ports/servoshell/desktop/headless_window.rs +++ b/ports/servoshell/desktop/headless_window.rs @@ -8,9 +8,9 @@ use std::cell::Cell; use std::rc::Rc; use euclid::num::Zero; -use euclid::{Length, Scale, Size2D}; +use euclid::{Length, Point2D, Scale, Size2D}; use servo::servo_geometry::DeviceIndependentPixel; -use servo::webrender_api::units::{DeviceIntSize, DevicePixel}; +use servo::webrender_api::units::{DeviceIntRect, DeviceIntSize, DevicePixel}; use servo::{RenderingContext, ScreenGeometry, SoftwareRenderingContext}; use winit::dpi::PhysicalSize; @@ -135,6 +135,10 @@ impl WindowPortsMethods for Window { Length::zero() } + fn window_rect(&self) -> DeviceIntRect { + DeviceIntRect::from_origin_and_size(Point2D::zero(), self.inner_size.get()) + } + fn set_toolbar_height(&self, _height: Length) { unimplemented!("headless Window only") } diff --git a/ports/servoshell/desktop/window_trait.rs b/ports/servoshell/desktop/window_trait.rs index f20acfd03ce..233c90cb5a5 100644 --- a/ports/servoshell/desktop/window_trait.rs +++ b/ports/servoshell/desktop/window_trait.rs @@ -9,7 +9,7 @@ use std::rc::Rc; use euclid::{Length, Scale}; use servo::servo_geometry::DeviceIndependentPixel; -use servo::webrender_api::units::{DeviceIntPoint, DeviceIntSize, DevicePixel}; +use servo::webrender_api::units::{DeviceIntPoint, DeviceIntRect, DeviceIntSize, DevicePixel}; use servo::{Cursor, RenderingContext, ScreenGeometry, WebView}; use super::app_state::RunningAppState; @@ -52,4 +52,5 @@ pub trait WindowPortsMethods { fn theme(&self) -> servo::Theme { servo::Theme::Light } + fn window_rect(&self) -> DeviceIntRect; }