mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
webdriver: Get the window position as well as the size when resolving "Get Window Rect" (#37812)
1. Rename `GetWindowSize` to `GetWindowRect` 2. Return the WindowRect in device pixels correctly. Previously, it returns `(0, 0, ScreenWidth, ScreenHeight)` which is a static value. 3. Add `fn window_rect` to `WindowPortsMethods`. Implement it for both Headless Window and Headed Window. Testing: Tested manually with powershell script. Result is now dynamic and reflects the truth. Fixes: Task 1 & 2 of https://github.com/servo/servo/issues/37804 --------- Signed-off-by: Euclid Ye <yezhizhenjiakang@gmail.com>
This commit is contained in:
parent
95d9d3a412
commit
94f35ba998
7 changed files with 35 additions and 19 deletions
|
@ -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(..) => {
|
||||
|
|
|
@ -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<Size2D<i32, DevicePixel>>),
|
||||
GetWindowRect(WebViewId, IpcSender<DeviceIntRect>),
|
||||
/// Get the viewport size.
|
||||
GetViewportSize(WebViewId, IpcSender<Size2D<u32, DevicePixel>>),
|
||||
/// Load a URL in the top-level browsing context with the given ID.
|
||||
|
|
|
@ -799,7 +799,7 @@ impl Handler {
|
|||
}
|
||||
|
||||
/// <https://w3c.github.io/webdriver/#get-window-rect>
|
||||
fn handle_window_size(
|
||||
fn handle_window_rect(
|
||||
&self,
|
||||
verify: VerifyBrowsingContextIsOpen,
|
||||
) -> WebDriverResult<WebDriverResponse> {
|
||||
|
@ -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<ServoExtensionRoute> 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),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue