1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 12:47:35 +00:00

WebContent: Abstract calculating an element's absolute rect to a helper

This commit is contained in:
Timothy Flynn 2022-11-04 19:57:12 -04:00 committed by Linus Groh
parent c79e8aab0a
commit 3510fbbea8

View file

@ -629,16 +629,26 @@ static Gfx::IntPoint calculate_absolute_position_of_element(Web::Page const& pag
return { x, y }; return { x, y };
} }
static Gfx::IntRect calculate_absolute_rect_of_element(Web::Page const& page, Web::DOM::Element const& element)
{
auto bounding_rect = element.get_bounding_client_rect();
auto coordinates = calculate_absolute_position_of_element(page, bounding_rect);
return Gfx::IntRect {
coordinates.x(),
coordinates.y(),
static_cast<int>(bounding_rect->width()),
static_cast<int>(bounding_rect->height())
};
}
Messages::WebContentServer::GetElementRectResponse ConnectionFromClient::get_element_rect(i32 element_id) Messages::WebContentServer::GetElementRectResponse ConnectionFromClient::get_element_rect(i32 element_id)
{ {
auto element = find_element_by_id(element_id); auto element = find_element_by_id(element_id);
if (!element.has_value()) if (!element.has_value())
return { {} }; return { {} };
auto bounding_rect = element->get_bounding_client_rect(); return { calculate_absolute_rect_of_element(page(), *element) };
auto coordinates = calculate_absolute_position_of_element(page(), bounding_rect);
return { { coordinates.x(), coordinates.y(), static_cast<int>(bounding_rect->width()), static_cast<int>(bounding_rect->height()) } };
} }
Messages::WebContentServer::IsElementEnabledResponse ConnectionFromClient::is_element_enabled(i32 element_id) Messages::WebContentServer::IsElementEnabledResponse ConnectionFromClient::is_element_enabled(i32 element_id)