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

LibWeb: Make Painting::Box virtual and add Painting::BoxWithLines

BlockContainer paint boxes are the only ones that have line boxes
associated, so let's not waste memory on line boxes in all the other
types of boxes.

This also adds Layout::Box::paint_box() and the more tightly typed
Layout::BlockContainer::paint_box() to get at the paint box from the
corresponding layout box.
This commit is contained in:
Andreas Kling 2022-03-10 11:12:06 +01:00
parent 9f5cbcaad3
commit 7af03df4c3
11 changed files with 79 additions and 26 deletions

View file

@ -51,11 +51,11 @@ void BlockContainer::paint(PaintContext& context, Painting::PaintPhase phase)
context.painter().translate(-m_scroll_offset.to_type<int>());
}
for (auto& line_box : m_paint_box->m_line_boxes) {
for (auto& line_box : paint_box()->line_boxes()) {
for (auto& fragment : line_box.fragments()) {
if (context.should_show_line_box_borders())
context.painter().draw_rect(enclosing_int_rect(fragment.absolute_rect()), Color::Green);
fragment.paint(context, phase);
const_cast<LineBoxFragment&>(fragment).paint(context, phase);
}
}
@ -65,7 +65,7 @@ void BlockContainer::paint(PaintContext& context, Painting::PaintPhase phase)
// FIXME: Merge this loop with the above somehow..
if (phase == Painting::PaintPhase::FocusOutline) {
for (auto& line_box : m_paint_box->m_line_boxes) {
for (auto& line_box : paint_box()->line_boxes()) {
for (auto& fragment : line_box.fragments()) {
auto* node = fragment.layout_node().dom_node();
if (!node)
@ -86,7 +86,7 @@ HitTestResult BlockContainer::hit_test(const Gfx::IntPoint& position, HitTestTyp
return Box::hit_test(position, type);
HitTestResult last_good_candidate;
for (auto& line_box : m_paint_box->m_line_boxes) {
for (auto& line_box : paint_box()->line_boxes()) {
for (auto& fragment : line_box.fragments()) {
if (is<Box>(fragment.layout_node()) && verify_cast<Box>(fragment.layout_node()).m_paint_box->stacking_context())
continue;
@ -131,4 +131,9 @@ bool BlockContainer::handle_mousewheel(Badge<EventHandler>, const Gfx::IntPoint&
return true;
}
Painting::BoxWithLines const* BlockContainer::paint_box() const
{
return static_cast<Painting::BoxWithLines const*>(Box::paint_box());
}
}