diff options
author | Kenzie Raditya Tirtarahardja <kenzieradityatirtarahardja18@gmail.com> | 2025-05-13 18:46:27 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-05-13 10:46:27 +0000 |
commit | 91c4c7b9982556bc11a39d47081984cbdfa6280e (patch) | |
tree | fb9b593aeb3454a6e3e39a37e12afc583ddcec56 | |
parent | 6468734aea0895d8e14ca5a99f0b11b070041187 (diff) | |
download | servo-91c4c7b9982556bc11a39d47081984cbdfa6280e.tar.gz servo-91c4c7b9982556bc11a39d47081984cbdfa6280e.zip |
Fix origin relative coordinate for wheel scroll and refactoring (#36985)
- Wheel scroll action can get coordinates relative to an element origin
([previously](https://github.com/servo/servo/pull/36744) only
implemented for viewport).
- Extract the element coordinate into a function
Testing: Partially
`tests/wpt/tests/infrastructure/testdriver/actions/wheelScroll.html`,
but we still have synchronization problem. You can try to add sleep in
the test to see OK result.
cc: @xiaochengh @longvatrong111 @yezhizhen
Signed-off-by: PotatoCP <kenzieradityatirtarahardja.18@gmail.com>
Co-authored-by: PotatoCP <kenzieradityatirtarahardja.18@gmail.com>
-rw-r--r-- | components/webdriver_server/actions.rs | 45 |
1 files changed, 28 insertions, 17 deletions
diff --git a/components/webdriver_server/actions.rs b/components/webdriver_server/actions.rs index 2d49ebbea22..842d9f0dbc2 100644 --- a/components/webdriver_server/actions.rs +++ b/components/webdriver_server/actions.rs @@ -18,7 +18,7 @@ use webdriver::actions::{ }; use webdriver::error::{ErrorStatus, WebDriverError}; -use crate::{Handler, wait_for_script_response}; +use crate::{Handler, WebElement, wait_for_script_response}; // Interval between wheelScroll and pointerMove increments in ms, based on common vsync static POINTERMOVE_INTERVAL: u64 = 17; @@ -393,20 +393,8 @@ impl Handler { let (x, y) = match action.origin { PointerOrigin::Viewport => (x_offset, y_offset), PointerOrigin::Pointer => (start_x + x_offset, start_y + y_offset), - PointerOrigin::Element(ref x) => { - let (sender, receiver) = ipc::channel().unwrap(); - self.browsing_context_script_command( - WebDriverScriptCommand::GetElementInViewCenterPoint(x.to_string(), sender), - ) - .unwrap(); - let response = match wait_for_script_response(receiver) { - Ok(response) => response, - Err(WebDriverError { error, .. }) => return Err(error), - }; - let Ok(Some(point)) = response else { - return Err(ErrorStatus::UnknownError); - }; - point + PointerOrigin::Element(ref web_element) => { + self.get_element_origin_relative_coordinates(web_element)? }, }; @@ -526,10 +514,13 @@ impl Handler { }; // Step 3 - 4 - // Get coordinates relative to an origin. Origin must be viewport. + // Get coordinates relative to an origin. let (x, y) = match action.origin { PointerOrigin::Viewport => (x_offset, y_offset), - _ => return Err(ErrorStatus::InvalidArgument), + PointerOrigin::Pointer => return Err(ErrorStatus::InvalidArgument), + PointerOrigin::Element(ref web_element) => { + self.get_element_origin_relative_coordinates(web_element)? + }, }; // Step 5 - 6 @@ -659,4 +650,24 @@ impl Handler { Ok(()) } } + + fn get_element_origin_relative_coordinates( + &self, + web_element: &WebElement, + ) -> Result<(i64, i64), ErrorStatus> { + let (sender, receiver) = ipc::channel().unwrap(); + self.browsing_context_script_command(WebDriverScriptCommand::GetElementInViewCenterPoint( + web_element.to_string(), + sender, + )) + .unwrap(); + let response = match wait_for_script_response(receiver) { + Ok(response) => response, + Err(WebDriverError { error, .. }) => return Err(error), + }; + match response? { + Some(point) => Ok(point), + None => Err(ErrorStatus::UnknownError), + } + } } |