From d06d4eb388bfeb8c20c14c23d9da78c8c43ce85f Mon Sep 17 00:00:00 2001 From: Aliaksandr Kalenik Date: Wed, 23 Aug 2023 13:58:30 +0200 Subject: [PATCH] LibWeb: Apply "clip" property in `apply_clip_overflow_rect()` Fixes bug when "clip" property does not affect abspos children. This change makes "clip" property to be applied together with "overflow: hidden" in `apply_clip_overflow_rect()` that already handles abspos children correctly. --- .../LibWeb/Ref/clip-abspos-children-ref.html | 11 ++++++++++ Tests/LibWeb/Ref/clip-abspos-children.html | 17 ++++++++++++++ Tests/LibWeb/Ref/manifest.json | 1 + .../LibWeb/Painting/PaintableBox.cpp | 22 +++++++++---------- 4 files changed, 40 insertions(+), 11 deletions(-) create mode 100644 Tests/LibWeb/Ref/clip-abspos-children-ref.html create mode 100644 Tests/LibWeb/Ref/clip-abspos-children.html diff --git a/Tests/LibWeb/Ref/clip-abspos-children-ref.html b/Tests/LibWeb/Ref/clip-abspos-children-ref.html new file mode 100644 index 0000000000..321060322a --- /dev/null +++ b/Tests/LibWeb/Ref/clip-abspos-children-ref.html @@ -0,0 +1,11 @@ +
diff --git a/Tests/LibWeb/Ref/clip-abspos-children.html b/Tests/LibWeb/Ref/clip-abspos-children.html new file mode 100644 index 0000000000..7338c7d15c --- /dev/null +++ b/Tests/LibWeb/Ref/clip-abspos-children.html @@ -0,0 +1,17 @@ +
diff --git a/Tests/LibWeb/Ref/manifest.json b/Tests/LibWeb/Ref/manifest.json index 164854f8f3..b27dd88fc1 100644 --- a/Tests/LibWeb/Ref/manifest.json +++ b/Tests/LibWeb/Ref/manifest.json @@ -1,4 +1,5 @@ { + "clip-abspos-children.html": "clip-abspos-children-ref.html", "item-with-negative-z-index.html": "item-with-negative-z-index-ref.html", "img-srcset-viewport-relative-sizes.html": "img-srcset-viewport-relative-sizes-ref.html", "grid-items-painting-order.html": "grid-items-painting-order-ref.html", diff --git a/Userland/Libraries/LibWeb/Painting/PaintableBox.cpp b/Userland/Libraries/LibWeb/Painting/PaintableBox.cpp index 9be619ee09..512ccdfd6c 100644 --- a/Userland/Libraries/LibWeb/Painting/PaintableBox.cpp +++ b/Userland/Libraries/LibWeb/Painting/PaintableBox.cpp @@ -183,15 +183,7 @@ void PaintableBox::paint(PaintContext& context, PaintPhase phase) const if (!is_visible()) return; - auto clip_rect = computed_values().clip(); - auto should_clip_rect = clip_rect.is_rect() && layout_box().is_absolutely_positioned(); - if (phase == PaintPhase::Background) { - if (should_clip_rect) { - context.painter().save(); - auto border_box = absolute_border_box_rect(); - context.painter().add_clip_rect(context.rounded_device_rect(clip_rect.to_rect().resolved(Paintable::layout_node(), border_box.to_type()).to_type()).to_type()); - } paint_backdrop_filter(context); paint_background(context); paint_box_shadow(context); @@ -229,9 +221,6 @@ void PaintableBox::paint(PaintContext& context, PaintPhase phase) const } } - if (phase == PaintPhase::Overlay && should_clip_rect) - context.painter().restore(); - if (phase == PaintPhase::Overlay && layout_box().document().inspected_layout_node() == &layout_box()) { auto content_rect = absolute_rect(); @@ -437,6 +426,17 @@ void PaintableBox::apply_clip_overflow_rect(PaintContext& context, PaintPhase ph auto overflow_x = computed_values().overflow_x(); auto overflow_y = computed_values().overflow_y(); + auto clip = computed_values().clip(); + if (clip.is_rect() && layout_box().is_absolutely_positioned()) { + auto border_box = absolute_border_box_rect(); + auto resolved_clip_rect = clip.to_rect().resolved(layout_node(), border_box.to_type()).to_type(); + if (clip_rect.has_value()) { + clip_rect->intersect(resolved_clip_rect); + } else { + clip_rect = resolved_clip_rect; + } + } + if (!clip_rect.has_value()) return;