1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 11:08:11 +00:00

LibWeb: Separate layout tree rendering into phases

CSS defines a very specific paint order. This patch starts steering us
towards respecting that by introducing the PaintPhase enum with values:

- Background
- Border
- Foreground
- Overlay (internal overlays used by inspector)

Basically, to get the right visual result, we have to render the page
multiple times, going one phase at a time.
This commit is contained in:
Andreas Kling 2020-06-18 18:57:35 +02:00
parent abe811104f
commit cfab53903f
22 changed files with 109 additions and 95 deletions

View file

@ -59,28 +59,30 @@ void LayoutFrame::layout(LayoutMode layout_mode)
LayoutReplaced::layout(layout_mode);
}
void LayoutFrame::render(RenderingContext& context)
void LayoutFrame::render(RenderingContext& context, PaintPhase phase)
{
LayoutReplaced::render(context);
LayoutReplaced::render(context, phase);
auto* hosted_document = node().hosted_document();
if (!hosted_document)
return;
auto* hosted_layout_tree = hosted_document->layout_node();
if (!hosted_layout_tree)
return;
if (phase == PaintPhase::Foreground) {
auto* hosted_document = node().hosted_document();
if (!hosted_document)
return;
auto* hosted_layout_tree = hosted_document->layout_node();
if (!hosted_layout_tree)
return;
context.painter().save();
auto old_viewport_rect = context.viewport_rect();
context.painter().save();
auto old_viewport_rect = context.viewport_rect();
context.painter().add_clip_rect(enclosing_int_rect(absolute_rect()));
context.painter().translate(absolute_x(), absolute_y());
context.painter().add_clip_rect(enclosing_int_rect(absolute_rect()));
context.painter().translate(absolute_x(), absolute_y());
context.set_viewport_rect({ {}, node().hosted_frame()->size() });
const_cast<LayoutDocument*>(hosted_layout_tree)->render(context);
context.set_viewport_rect({ {}, node().hosted_frame()->size() });
const_cast<LayoutDocument*>(hosted_layout_tree)->paint_all_phases(context);
context.set_viewport_rect(old_viewport_rect);
context.painter().restore();
context.set_viewport_rect(old_viewport_rect);
context.painter().restore();
}
}
void LayoutFrame::did_set_rect()