LibGfx: Add Rect::unite()

The existing `::unite_horizontally()` and `::unite_vertically()` tests
did not properly test the edge cases where left/top in the Rect were
updated, so they get re-arranged a bit.
This commit is contained in:
Jelle Raaijmakers 2025-01-15 13:51:39 +01:00 committed by Jelle Raaijmakers
commit 7eb4f3da37
Notes: github-actions[bot] 2025-01-23 08:34:31 +00:00
7 changed files with 51 additions and 38 deletions

View file

@ -927,7 +927,7 @@ GC::Ref<Geometry::DOMRect> Element::get_bounding_client_rect() const
auto const& rect = list->item(i);
if (rect->width() == 0 || rect->height() == 0)
continue;
bounding_rect = bounding_rect.united({ rect->x(), rect->y(), rect->width(), rect->height() });
bounding_rect.unite({ rect->x(), rect->y(), rect->width(), rect->height() });
}
return Geometry::DOMRect::create(realm(), bounding_rect.to_type<float>());
}

View file

@ -1243,7 +1243,7 @@ GC::Ref<Geometry::DOMRect> Range::get_bounding_client_rect()
auto const& rect = list->item(i);
if (rect->width() == 0 || rect->height() == 0)
continue;
bounding_rect = bounding_rect.united({ rect->x(), rect->y(), rect->width(), rect->height() });
bounding_rect.unite({ rect->x(), rect->y(), rect->width(), rect->height() });
}
return Geometry::DOMRect::create(realm(), bounding_rect.to_type<float>());
}

View file

@ -89,9 +89,8 @@ static CSSPixelRect measure_scrollable_overflow(Box const& box)
// - All line boxes directly contained by the scroll container.
if (is<Painting::PaintableWithLines>(box.first_paintable())) {
for (auto const& fragment : static_cast<Painting::PaintableWithLines const&>(*box.first_paintable()).fragments()) {
scrollable_overflow_rect = scrollable_overflow_rect.united(fragment.absolute_rect());
}
for (auto const& fragment : static_cast<Painting::PaintableWithLines const&>(*box.first_paintable()).fragments())
scrollable_overflow_rect.unite(fragment.absolute_rect());
}
auto content_overflow_rect = scrollable_overflow_rect;
@ -117,8 +116,8 @@ static CSSPixelRect measure_scrollable_overflow(Box const& box)
if (child_border_box.bottom() < 0 || child_border_box.right() < 0)
return TraversalDecision::Continue;
scrollable_overflow_rect = scrollable_overflow_rect.united(child_border_box);
content_overflow_rect = content_overflow_rect.united(child_border_box);
scrollable_overflow_rect.unite(child_border_box);
content_overflow_rect.unite(child_border_box);
// - The scrollable overflow areas of all of the above boxes
// (including zero-area boxes and accounting for transforms as described above),

View file

@ -271,15 +271,11 @@ void paint_background(PaintContext& context, PaintableBox const& paintable_box,
// However, we must first figure out the real coverage area, taking repeat etc into account.
// FIXME: This could be written in a far more efficient way.
auto fill_rect = Optional<DevicePixelRect> {};
DevicePixelRect fill_rect;
for_each_image_device_rect([&](auto const& image_device_rect) {
if (!fill_rect.has_value()) {
fill_rect = image_device_rect;
} else {
fill_rect = fill_rect->united(image_device_rect);
}
fill_rect.unite(image_device_rect);
});
display_list_recorder.fill_rect(fill_rect->to_type<int>(), color.value());
display_list_recorder.fill_rect(fill_rect.to_type<int>(), color.value());
} else if (is<CSS::ImageStyleValue>(image) && repeat_x && repeat_y && !repeat_x_has_gap && !repeat_y_has_gap) {
// Use a dedicated painting command for repeated images instead of recording a separate command for each instance
// of a repeated background, so the painter has the opportunity to optimize the painting of repeated images.

View file

@ -209,7 +209,7 @@ CSSPixelRect PaintableBox::compute_absolute_paint_rect() const
continue;
auto inflate = shadow.spread_distance + shadow.blur_radius;
auto shadow_rect = rect.inflated(inflate, inflate, inflate, inflate).translated(shadow.offset_x, shadow.offset_y);
rect = rect.united(shadow_rect);
rect.unite(shadow_rect);
}
return rect;
}