1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-28 04:17:34 +00:00

LibWeb: Implement getBoundingClientRect() for inline paintables

This fixes the issue that occurred when, after clicking an inline
paintable page would always scroll to the top. The problem was that
`scroll_an_element_into_view()` relies on `get_bounding_client_rect()`
to produce the correct scroll position and for inline paintables we
were always returning zero rect before this change.
This commit is contained in:
Aliaksandr Kalenik 2023-12-14 08:16:45 +01:00 committed by Andreas Kling
parent 874af6048f
commit e464d484c4
5 changed files with 54 additions and 8 deletions

View file

@ -173,4 +173,32 @@ void InlinePaintable::for_each_fragment(Callback callback) const
}
}
CSSPixelRect InlinePaintable::bounding_rect() const
{
auto top = CSSPixels::max();
auto left = CSSPixels::max();
auto right = CSSPixels::min();
auto bottom = CSSPixels::min();
auto has_fragments = false;
for_each_fragment([&](auto const& fragment, bool, bool) {
has_fragments = true;
auto fragment_absolute_rect = fragment.absolute_rect();
if (fragment_absolute_rect.top() < top)
top = fragment_absolute_rect.top();
if (fragment_absolute_rect.left() < left)
left = fragment_absolute_rect.left();
if (fragment_absolute_rect.right() > right)
right = fragment_absolute_rect.right();
if (fragment_absolute_rect.bottom() > bottom)
bottom = fragment_absolute_rect.bottom();
});
if (!has_fragments) {
// FIXME: This is adhoc, and we should return rect of empty fragment instead.
auto containing_block_position_in_absolute_coordinates = containing_block()->paintable_box()->absolute_position();
return { containing_block_position_in_absolute_coordinates, { 0, 0 } };
}
return { left, top, right - left, bottom - top };
}
}

View file

@ -22,6 +22,8 @@ public:
Layout::InlineNode const& layout_node() const;
auto const& box_model() const { return layout_node().box_model(); }
CSSPixelRect bounding_rect() const;
private:
InlinePaintable(Layout::InlineNode const&);