LibWeb+WebContent: Ensure elements are in view before clicking them

This implements a couple of missing steps in the Element Click endpoint.
This commit is contained in:
Timothy Flynn 2024-10-24 16:17:55 -04:00 committed by Tim Flynn
commit e89d889219
Notes: github-actions[bot] 2024-10-24 23:00:49 +00:00
3 changed files with 54 additions and 2 deletions

View file

@ -1347,8 +1347,15 @@ Messages::WebDriverClient::ElementClickResponse WebDriverConnection::element_cli
auto element_container = container_for_element(*element);
scroll_element_into_view(*element_container);
// FIXME: 6. If elements container is still not in view, return error with error code element not interactable.
// FIXME: 7. If elements container is obscured by another element, return error with error code element click intercepted.
auto paint_tree = Web::WebDriver::pointer_interactable_tree(current_browsing_context(), *element_container);
// 6. If elements container is still not in view, return error with error code element not interactable.
if (!Web::WebDriver::is_element_in_view(paint_tree, *element_container))
return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::ElementNotInteractable, "Could not bring element into view"sv);
// 7. If elements container is obscured by another element, return error with error code element click intercepted.
if (Web::WebDriver::is_element_obscured(paint_tree, *element_container))
return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::ElementClickIntercepted, "Element is obscured by another element"sv);
auto on_complete = JS::create_heap_function(current_browsing_context().heap(), [this](Web::WebDriver::Response result) {
// 9. Wait until the user agent event loop has spun enough times to process the DOM events generated by the