1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 17:57: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

@ -26,8 +26,10 @@
#pragma once
#include <AK/OwnPtr.h>
#include <LibGfx/FloatRect.h>
#include <LibWeb/Layout/LayoutNode.h>
#include <LibWeb/Layout/StackingContext.h>
namespace Web {
@ -60,14 +62,19 @@ public:
void set_containing_line_box_fragment(LineBoxFragment&);
bool establishes_stacking_context() const;
StackingContext* stacking_context() { return m_stacking_context; }
void set_stacking_context(NonnullOwnPtr<StackingContext> context) { m_stacking_context = move(context); }
StackingContext* enclosing_stacking_context();
virtual void render(RenderingContext&) override;
protected:
LayoutBox(const Node* node, NonnullRefPtr<StyleProperties> style)
: LayoutNodeWithStyleAndBoxModelMetrics(node, move(style))
{
}
virtual void render(RenderingContext&) override;
virtual void did_set_rect() { }
private:
@ -86,6 +93,8 @@ private:
// Some boxes hang off of line box fragments. (inline-block, inline-table, replaced, etc)
WeakPtr<LineBoxFragment> m_containing_line_box_fragment;
OwnPtr<StackingContext> m_stacking_context;
};
template<>