mirror of
https://github.com/servo/servo.git
synced 2025-08-02 20:20:14 +01:00
Auto merge of #23996 - georgeroman:implement_pointer_move_wd_action, r=jdm
Implement pointerMove webdriver action <!-- Please describe your changes on the following line: --> --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/23996) <!-- Reviewable:end -->
This commit is contained in:
commit
b2a7fc9046
9 changed files with 306 additions and 28 deletions
|
@ -2209,6 +2209,14 @@ impl ScriptThread {
|
|||
WebDriverScriptCommand::GetElementText(node_id, reply) => {
|
||||
webdriver_handlers::handle_get_text(&*documents, pipeline_id, node_id, reply)
|
||||
},
|
||||
WebDriverScriptCommand::GetElementInViewCenterPoint(node_id, reply) => {
|
||||
webdriver_handlers::handle_get_element_in_view_center_point(
|
||||
&*documents,
|
||||
pipeline_id,
|
||||
node_id,
|
||||
reply,
|
||||
)
|
||||
},
|
||||
WebDriverScriptCommand::GetBrowsingContextId(webdriver_frame_id, reply) => {
|
||||
webdriver_handlers::handle_get_browsing_context_id(
|
||||
&*documents,
|
||||
|
|
|
@ -53,6 +53,7 @@ use script_traits::webdriver_msg::{
|
|||
WebDriverFrameId, WebDriverJSError, WebDriverJSResult, WebDriverJSValue,
|
||||
};
|
||||
use servo_url::ServoUrl;
|
||||
use std::cmp;
|
||||
use std::collections::HashMap;
|
||||
use std::ffi::CString;
|
||||
use webdriver::common::{WebElement, WebFrame, WebWindow};
|
||||
|
@ -360,6 +361,56 @@ pub fn handle_get_browsing_context_id(
|
|||
.unwrap();
|
||||
}
|
||||
|
||||
// https://w3c.github.io/webdriver/#dfn-center-point
|
||||
fn get_element_in_view_center_point(element: &Element) -> Option<Point2D<i64>> {
|
||||
element
|
||||
.GetClientRects()
|
||||
.iter()
|
||||
// Step 1
|
||||
.next()
|
||||
.map(|rectangle| {
|
||||
let x = rectangle.X().round() as i64;
|
||||
let y = rectangle.Y().round() as i64;
|
||||
let width = rectangle.Width().round() as i64;
|
||||
let height = rectangle.Height().round() as i64;
|
||||
|
||||
let window = window_from_node(element.upcast::<Node>());
|
||||
let document = window.Document();
|
||||
let document_element = document.upcast::<Node>().downcast::<Element>().unwrap();
|
||||
let clientWidth = document_element.ClientWidth() as i64;
|
||||
let clientHeight = document_element.ClientHeight() as i64;
|
||||
|
||||
// Steps 2 - 5
|
||||
let left = cmp::max(0, cmp::min(x, x + width));
|
||||
let right = cmp::min(clientWidth, cmp::max(x, x + width));
|
||||
let top = cmp::max(0, cmp::min(y, y + height));
|
||||
let bottom = cmp::min(clientHeight, cmp::max(y, y + height));
|
||||
|
||||
// Steps 6 - 7
|
||||
let x = (left + right) / 2;
|
||||
let y = (top + bottom) / 2;
|
||||
|
||||
// Step 8
|
||||
Point2D::new(x, y)
|
||||
})
|
||||
}
|
||||
|
||||
pub fn handle_get_element_in_view_center_point(
|
||||
documents: &Documents,
|
||||
pipeline: PipelineId,
|
||||
element_id: String,
|
||||
reply: IpcSender<Result<Option<(i64, i64)>, ErrorStatus>>,
|
||||
) {
|
||||
reply
|
||||
.send(
|
||||
find_node_by_unique_id(documents, pipeline, element_id).map(|node| {
|
||||
get_element_in_view_center_point(node.downcast::<Element>().unwrap())
|
||||
.map(|point| (point.x, point.y))
|
||||
}),
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
pub fn handle_find_element_css(
|
||||
documents: &Documents,
|
||||
pipeline: PipelineId,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue