mirror of
https://github.com/servo/servo.git
synced 2025-08-04 05:00:08 +01:00
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>
This commit is contained in:
parent
6468734aea
commit
91c4c7b998
1 changed files with 28 additions and 17 deletions
|
@ -18,7 +18,7 @@ use webdriver::actions::{
|
||||||
};
|
};
|
||||||
use webdriver::error::{ErrorStatus, WebDriverError};
|
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
|
// Interval between wheelScroll and pointerMove increments in ms, based on common vsync
|
||||||
static POINTERMOVE_INTERVAL: u64 = 17;
|
static POINTERMOVE_INTERVAL: u64 = 17;
|
||||||
|
@ -393,20 +393,8 @@ impl Handler {
|
||||||
let (x, y) = match action.origin {
|
let (x, y) = match action.origin {
|
||||||
PointerOrigin::Viewport => (x_offset, y_offset),
|
PointerOrigin::Viewport => (x_offset, y_offset),
|
||||||
PointerOrigin::Pointer => (start_x + x_offset, start_y + y_offset),
|
PointerOrigin::Pointer => (start_x + x_offset, start_y + y_offset),
|
||||||
PointerOrigin::Element(ref x) => {
|
PointerOrigin::Element(ref web_element) => {
|
||||||
let (sender, receiver) = ipc::channel().unwrap();
|
self.get_element_origin_relative_coordinates(web_element)?
|
||||||
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
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -526,10 +514,13 @@ impl Handler {
|
||||||
};
|
};
|
||||||
|
|
||||||
// Step 3 - 4
|
// 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 {
|
let (x, y) = match action.origin {
|
||||||
PointerOrigin::Viewport => (x_offset, y_offset),
|
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
|
// Step 5 - 6
|
||||||
|
@ -659,4 +650,24 @@ impl Handler {
|
||||||
Ok(())
|
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),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue