mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 09:17:35 +00:00
WebContent: Abstract calculating an element's absolute rect to a helper
This commit is contained in:
parent
c79e8aab0a
commit
3510fbbea8
1 changed files with 14 additions and 4 deletions
|
@ -629,16 +629,26 @@ static Gfx::IntPoint calculate_absolute_position_of_element(Web::Page const& pag
|
|||
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)
|
||||
{
|
||||
auto element = find_element_by_id(element_id);
|
||||
if (!element.has_value())
|
||||
return { {} };
|
||||
|
||||
auto bounding_rect = element->get_bounding_client_rect();
|
||||
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()) } };
|
||||
return { calculate_absolute_rect_of_element(page(), *element) };
|
||||
}
|
||||
|
||||
Messages::WebContentServer::IsElementEnabledResponse ConnectionFromClient::is_element_enabled(i32 element_id)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue