From a0ee86db0453de5a2330955235667fcc43cd11b4 Mon Sep 17 00:00:00 2001 From: Jelle Raaijmakers Date: Wed, 30 Oct 2024 23:48:34 +0100 Subject: [PATCH] LibWeb: Prevent painting grid items twice as a stacking context We paint grid item nodes as a stacking context when they have no `z-index` style set. However, a grid item could already have a stacking context established - for example, when the `filter` style is applied. This causes these nodes to be drawn twice. Skip painting grid item nodes if a stacking context is already present. --- Tests/LibWeb/Ref/grid-item-and-css-filter.html | 16 ++++++++++++++++ .../reference/grid-item-and-css-filter-ref.html | 14 ++++++++++++++ .../LibWeb/Painting/StackingContext.cpp | 5 +++-- 3 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 Tests/LibWeb/Ref/grid-item-and-css-filter.html create mode 100644 Tests/LibWeb/Ref/reference/grid-item-and-css-filter-ref.html diff --git a/Tests/LibWeb/Ref/grid-item-and-css-filter.html b/Tests/LibWeb/Ref/grid-item-and-css-filter.html new file mode 100644 index 00000000000..367bee8d945 --- /dev/null +++ b/Tests/LibWeb/Ref/grid-item-and-css-filter.html @@ -0,0 +1,16 @@ + + + +
+
+ Ladybird diff --git a/Tests/LibWeb/Ref/reference/grid-item-and-css-filter-ref.html b/Tests/LibWeb/Ref/reference/grid-item-and-css-filter-ref.html new file mode 100644 index 00000000000..eddd2b187b6 --- /dev/null +++ b/Tests/LibWeb/Ref/reference/grid-item-and-css-filter-ref.html @@ -0,0 +1,14 @@ + + +
+
+ Ladybird diff --git a/Userland/Libraries/LibWeb/Painting/StackingContext.cpp b/Userland/Libraries/LibWeb/Painting/StackingContext.cpp index ddf73026172..485d53e9559 100644 --- a/Userland/Libraries/LibWeb/Painting/StackingContext.cpp +++ b/Userland/Libraries/LibWeb/Painting/StackingContext.cpp @@ -120,6 +120,9 @@ void StackingContext::paint_descendants(PaintContext& context, Paintable const& return IterationDecision::Continue; } + if (stacking_context) + return IterationDecision::Continue; + // NOTE: Grid specification https://www.w3.org/TR/css-grid-2/#z-order says that grid items should be treated // the same way as CSS2 defines for inline-blocks: // "For each one of these, treat the element as if it created a new stacking context, but any positioned @@ -133,8 +136,6 @@ void StackingContext::paint_descendants(PaintContext& context, Paintable const& return IterationDecision::Continue; } - if (stacking_context) - return IterationDecision::Continue; if (child.is_positioned() && z_index.value_or(0) == 0) return IterationDecision::Continue;