Skip to content

Truly independent web browser

LibWeb: Apply clip-path, clip and masks to an element’s filtered output

sideshowbarker51929bd7fefe
diff --git a/Libraries/LibWeb/Rust/src/painting/visual_context/build.rs b/Libraries/LibWeb/Rust/src/painting/visual_context/build.rs
index 77970bed182..fe03b2a75c2 100644
--- a/Libraries/LibWeb/Rust/src/painting/visual_context/build.rs
+++ b/Libraries/LibWeb/Rust/src/painting/visual_context/build.rs
@@ -87,10 +87,17 @@ impl BoxFacts {
})
}
+ /// Whether the box's effects layer sits under its transform, clip and mask nodes, rather than above them: for a
+ /// backdrop filter, and for a filter the box's clip-path, clip or mask has to apply to.
pub(crate) fn effects_layer_is_inside_transform_and_clips(&self) -> bool {
- self.effects
- .as_ref()
- .is_some_and(|effects| effects.backdrop_filter.is_some())
+ self.effects.as_ref().is_some_and(|effects| {
+ // https://drafts.csswg.org/filter-effects-1/#placement
+ // "The compositing model follows the SVG compositing model: first any filter effect is applied, then any
+ // clipping, masking and opacity."
+ effects.backdrop_filter.is_some()
+ || (effects.filter.is_some()
+ && (self.clip_path.is_some() || self.css_clip.is_some() || !self.mask_layers.is_empty()))
+ })
}
/// Gathers a box's facts for the visual context update, with the bounds of the SVG filter the box references,
diff --git a/Tests/LibWeb/Ref/expected/clip-path-clips-filter-output-ref.html b/Tests/LibWeb/Ref/expected/clip-path-clips-filter-output-ref.html
new file mode 100644
index 00000000000..2b5c997a7e3
--- /dev/null
+++ b/Tests/LibWeb/Ref/expected/clip-path-clips-filter-output-ref.html
@@ -0,0 +1,2 @@
+<!DOCTYPE html>
+<style>body { margin: 0; }</style>
diff --git a/Tests/LibWeb/Ref/input/clip-path-clips-filter-output.html b/Tests/LibWeb/Ref/input/clip-path-clips-filter-output.html
new file mode 100644
index 00000000000..22b1233055e
--- /dev/null
+++ b/Tests/LibWeb/Ref/input/clip-path-clips-filter-output.html
@@ -0,0 +1,20 @@
+<!DOCTYPE html>
+<link rel="match" href="../expected/clip-path-clips-filter-output-ref.html">
+<style>
+ body { margin: 0; }
+ div {
+ position: absolute;
+ width: 100px;
+ height: 100px;
+ background: green;
+ filter: blur(16px);
+ }
+ #clip-path { left: 50px; top: 50px; clip-path: inset(0px); }
+ #clip { left: 200px; top: 50px; clip: rect(0px, 100px, 100px, 0px); }
+ /* Cover the blurred inside of each box, so only what's left outside them shows. */
+ .cover { filter: none; background: white; }
+</style>
+<div id="clip-path"></div>
+<div id="clip"></div>
+<div class="cover" style="left: 50px; top: 50px"></div>
+<div class="cover" style="left: 200px; top: 50px"></div>