mirror of
https://github.com/servo/servo.git
synced 2025-08-16 02:45:36 +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
|
@ -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}");
|
||||
}
|
||||
},
|
||||
|
|
|
@ -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<i32>>(PhysicalPosition::new(point.x, point.y))
|
||||
|
|
|
@ -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<f32, DeviceIndependentPixel>) {
|
||||
unimplemented!("headless Window only")
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue