Skip to content

Truly independent web browser

LibWeb: Don't filter the backdrop of a box that is not visible

Andreas Kling61643ac07a2c
diff --git a/Libraries/LibWeb/Rust/src/css/style/style_invalidation.rs b/Libraries/LibWeb/Rust/src/css/style/style_invalidation.rs
index 1e75d41886a..7b797a0d748 100644
--- a/Libraries/LibWeb/Rust/src/css/style/style_invalidation.rs
+++ b/Libraries/LibWeb/Rust/src/css/style/style_invalidation.rs
@@ -559,6 +559,14 @@ fn property_invalidation(property: u16, old: ComputedValuesView<'_>, new: Comput
if (old.visibility() == collapse) != (new.visibility() == collapse) {
result.ensure_level(INVALIDATION_RELAYOUT);
}
+ // Only a visible box has its backdrop filtered.
+ let visible = crate::css::css_enums::visibility::VISIBLE;
+ if (old.visibility() == visible) != (new.visibility() == visible)
+ && (old.effects().backdrop_filter.operations.length != 0
+ || new.effects().backdrop_filter.operations.length != 0)
+ {
+ result.ensure_visual_context(VISUAL_CONTEXT_UPDATE_VALUES);
+ }
result.ensure_level(INVALIDATION_REPAINT);
} else if property_metadata::property_affects_layout(property) {
result.ensure_level(INVALIDATION_RELAYOUT);
diff --git a/Libraries/LibWeb/Rust/src/painting/visual_context/node_values.rs b/Libraries/LibWeb/Rust/src/painting/visual_context/node_values.rs
index 27445f2f7e4..b5b9b116322 100644
--- a/Libraries/LibWeb/Rust/src/painting/visual_context/node_values.rs
+++ b/Libraries/LibWeb/Rust/src/painting/visual_context/node_values.rs
@@ -697,6 +697,11 @@ fn compute_backdrop_filter_data(
if backdrop_filter.operations.length == 0 {
return None;
}
+ // NB: The filtered backdrop is part of the box's own painting, so an invisible box shows none of it, even when
+ // its visible descendants still paint.
+ if style.visibility() != css_enums::visibility::VISIBLE {
+ return None;
+ }
let converter = DevicePixelConverter::new(device_pixels_per_css_pixel);
let region = converter.rounded_device_rect(paintable_geometry::absolute_border_box_rect(layout_arena, slot));
if region.is_empty() {
diff --git a/Tests/LibWeb/Ref/expected/visual-context/backdrop-filter-visibility-hidden-ref.html b/Tests/LibWeb/Ref/expected/visual-context/backdrop-filter-visibility-hidden-ref.html
new file mode 100644
index 00000000000..9ee8b5a234f
--- /dev/null
+++ b/Tests/LibWeb/Ref/expected/visual-context/backdrop-filter-visibility-hidden-ref.html
@@ -0,0 +1,25 @@
+<!DOCTYPE html>
+<style>
+body {
+ margin: 0;
+ background: white;
+}
+.backdrop {
+ position: absolute;
+ left: 0;
+ top: 0;
+ width: 400px;
+ height: 200px;
+ background: rgb(0, 255, 0);
+}
+.inverted {
+ position: absolute;
+ left: 300px;
+ top: 50px;
+ width: 100px;
+ height: 100px;
+ background: rgb(255, 0, 255);
+}
+</style>
+<div class="backdrop"></div>
+<div class="inverted"></div>
diff --git a/Tests/LibWeb/Ref/input/visual-context/backdrop-filter-visibility-hidden.html b/Tests/LibWeb/Ref/input/visual-context/backdrop-filter-visibility-hidden.html
new file mode 100644
index 00000000000..28f94e17855
--- /dev/null
+++ b/Tests/LibWeb/Ref/input/visual-context/backdrop-filter-visibility-hidden.html
@@ -0,0 +1,55 @@
+<!DOCTYPE html>
+<html class="reftest-wait">
+<link rel="match" href="../../expected/visual-context/backdrop-filter-visibility-hidden-ref.html">
+<style>
+body {
+ margin: 0;
+ background: white;
+}
+.backdrop {
+ position: absolute;
+ left: 0;
+ top: 0;
+ width: 400px;
+ height: 200px;
+ background: rgb(0, 255, 0);
+}
+.filtered {
+ position: absolute;
+ top: 50px;
+ width: 100px;
+ height: 100px;
+ backdrop-filter: invert(1);
+}
+.hidden {
+ visibility: hidden;
+}
+.masked {
+ width: 20px;
+ height: 20px;
+ mask-image: linear-gradient(black, black);
+}
+#a { left: 0; }
+#b { left: 150px; }
+#c { left: 300px; }
+</style>
+<!-- A box that is not visible paints no filtered backdrop, even when its descendants record mask
+ content inside its effect: #a starts hidden, #b becomes hidden after the first frames, and #c
+ becomes visible, so only #c inverts the green behind it. -->
+<div class="backdrop"></div>
+<div id="a" class="filtered hidden"><div class="masked"></div></div>
+<div id="b" class="filtered"><div class="masked"></div></div>
+<div id="c" class="filtered hidden"><div class="masked"></div></div>
+<script>
+ requestAnimationFrame(() => requestAnimationFrame(() => {
+ document.getElementById("b").classList.add("hidden");
+ document.getElementById("c").classList.remove("hidden");
+ requestAnimationFrame(() => requestAnimationFrame(() => {
+ if (window.internals)
+ internals.signalTestIsDone("PASS");
+ else
+ document.documentElement.classList.remove("reftest-wait");
+ }));
+ }));
+</script>
+</html>