LibWeb: Simplify InlinePaintable::bounding_rect() implementation

No behavior change expected.
This commit is contained in:
Aliaksandr Kalenik 2024-01-30 13:59:31 +01:00 committed by Andreas Kling
parent 768b8415f2
commit 96d5f555e1
Notes: sideshowbarker 2024-07-16 23:44:30 +09:00

View File

@ -217,30 +217,18 @@ Optional<HitTestResult> InlinePaintable::hit_test(CSSPixelPoint position, HitTes
CSSPixelRect InlinePaintable::bounding_rect() const CSSPixelRect InlinePaintable::bounding_rect() const
{ {
auto top = CSSPixels::max(); CSSPixelRect bounding_rect;
auto left = CSSPixels::max();
auto right = CSSPixels::min();
auto bottom = CSSPixels::min();
auto has_fragments = false;
for_each_fragment([&](auto const& fragment, bool, bool) { for_each_fragment([&](auto const& fragment, bool, bool) {
has_fragments = true;
auto fragment_absolute_rect = fragment.absolute_rect(); auto fragment_absolute_rect = fragment.absolute_rect();
if (fragment_absolute_rect.top() < top) bounding_rect = bounding_rect.united(fragment_absolute_rect);
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) { if (bounding_rect.is_empty()) {
// FIXME: This is adhoc, and we should return rect of empty fragment instead. // 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(); auto containing_block_position_in_absolute_coordinates = containing_block()->paintable_box()->absolute_position();
return { containing_block_position_in_absolute_coordinates, { 0, 0 } }; return { containing_block_position_in_absolute_coordinates, { 0, 0 } };
} }
return { left, top, right - left, bottom - top }; return bounding_rect;
} }
} }