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

LibWeb: Respect CSS z-index property while painting

To support z-ordering when painting, the layout tree now has a parallel
sparse tree of stacking contexts. The rules for which layout boxes
establish a stacking context are a bit complex, but the intent is to
encapsulate the decision making into establishes_stacking_context().

When we paint, we start from the ICB (LayoutDocument) who always has a
StackingContext and then paint the tree of StackingContexts where each
node has its children sorted by z-index.

This is pretty crude, but gets the basic job done. Note that this does
not yet support hit testing; hit testing is still done using a naive
treewalk from the root.
This commit is contained in:
Andreas Kling 2020-06-15 17:29:35 +02:00
parent ce3260c6bf
commit 96da15a8a4
11 changed files with 222 additions and 3 deletions

View file

@ -29,6 +29,7 @@
#include <LibWeb/Layout/LayoutDocument.h>
#include <LibWeb/Layout/LayoutImage.h>
#include <LibWeb/Layout/LayoutWidget.h>
#include <LibWeb/Layout/StackingContext.h>
namespace Web {
@ -41,8 +42,31 @@ LayoutDocument::~LayoutDocument()
{
}
void LayoutDocument::build_stacking_context_tree()
{
if (stacking_context())
return;
set_stacking_context(make<StackingContext>(*this, nullptr));
for_each_in_subtree_of_type<LayoutBox>([&](LayoutBox& box) {
if (&box == this)
return IterationDecision::Continue;
if (!box.establishes_stacking_context()) {
ASSERT(!box.stacking_context());
return IterationDecision::Continue;
}
auto* parent_context = box.enclosing_stacking_context();
ASSERT(parent_context);
box.set_stacking_context(make<StackingContext>(box, parent_context));
return IterationDecision::Continue;
});
}
void LayoutDocument::layout(LayoutMode layout_mode)
{
build_stacking_context_tree();
set_width(frame().size().width());
LayoutNode::layout(layout_mode);
@ -76,4 +100,9 @@ void LayoutDocument::did_set_viewport_rect(Badge<Frame>, const Gfx::IntRect& a_v
});
}
void LayoutDocument::render(RenderingContext& context)
{
stacking_context()->render(context);
}
}