Truly independent web browser
LibWeb: Bound basic-shape clips by their actual paths
Andreas Kling9f5338b2e9fd
diff --git a/Libraries/LibCompositing/Rust/src/visual_context/queries.rs b/Libraries/LibCompositing/Rust/src/visual_context/queries.rsindex 84286234160..c0c1367b90c 100644--- a/Libraries/LibCompositing/Rust/src/visual_context/queries.rs+++ b/Libraries/LibCompositing/Rust/src/visual_context/queries.rs@@ -334,8 +334,8 @@ impl VisualContextTree {// NOTE: The clip path is in absolute device-pixel coordinates. After inverse-transforming, `point`// is also in device-pixel coordinates, so we compare them directly.if !clip_path.bounding_rect.contains_point(IntPoint {- x: point.x as i32,- y: point.y as i32,+ x: point.x.floor() as i32,+ y: point.y.floor() as i32,}) {return false;}diff --git a/Libraries/LibWeb/Rust/src/painting/visual_context/basic_shapes.rs b/Libraries/LibWeb/Rust/src/painting/visual_context/basic_shapes.rsindex 2a97790c24a..d362869f636 100644--- a/Libraries/LibWeb/Rust/src/painting/visual_context/basic_shapes.rs+++ b/Libraries/LibWeb/Rust/src/painting/visual_context/basic_shapes.rs@@ -11,7 +11,6 @@ use crate::css::css_pixels::{CssPixelPoint, CssPixelRect, CssPixelSize};use crate::css::style_value::{BasicShapeData, RetainedStyleValueData, StyleValueData};use crate::layout::node_data::NodeSlotId;use crate::painting::border_radii::{BorderRadii, normalize_border_radii_data};-use crate::painting::display_list::device_pixels::DevicePixelConverter;use crate::painting::paint_read::PaintRead;use crate::painting::{paintable_geometry, style_queries};use libgfx_rust::path::Path;@@ -947,7 +946,8 @@ pub(crate) fn compute_basic_shape_clip_path_data(WindingRule::Nonzero,),};- let converter = DevicePixelConverter::new(pixel_ratio);- let device_bounding_rect = converter.rounded_device_rect(masking_area);+ // NB: The shape can extend outside its reference box. Hit testing must use bounds that enclose the actual path.+ let device_bounding_rect =+ libgfx_rust::enclosing_int_rect(libgfx_rust::FloatRect::from_array(device_path.bounding_box()));Some((device_path, device_bounding_rect, resolved_fill_rule))}diff --git a/Tests/LibWeb/Text/expected/display_list/animated-clip-path-visual-context-update.txt b/Tests/LibWeb/Text/expected/display_list/animated-clip-path-visual-context-update.txtindex c5138c37446..b7f78082e92 100644--- a/Tests/LibWeb/Text/expected/display_list/animated-clip-path-visual-context-update.txt+++ b/Tests/LibWeb/Text/expected/display_list/animated-clip-path-visual-context-update.txt@@ -6,7 +6,7 @@ AccumulatedVisualContext Tree:[s0] transform=[1,0,0,1,0,0] origin=(0,0) (Viewport<#document>)[s1] scroll (Viewport<#document>)clips:- [c0 in s1] clip_path=[bounds: 8,8 100x100, path: M58 58L58 58L58 58L58 58Z] (BlockContainer<DIV>#box)+ [c0 in s1] clip_path=[bounds: 58,58 0x0, path: M58 58L58 58L58 58L58 58Z] (BlockContainer<DIV>#box)effects:[e0 in s0] effects=[]diff --git a/Tests/LibWeb/Text/expected/display_list/backdrop-filter-effect-node.txt b/Tests/LibWeb/Text/expected/display_list/backdrop-filter-effect-node.txtindex 9fe4bd52df0..e6c994807b2 100644--- a/Tests/LibWeb/Text/expected/display_list/backdrop-filter-effect-node.txt+++ b/Tests/LibWeb/Text/expected/display_list/backdrop-filter-effect-node.txt@@ -5,7 +5,7 @@ AccumulatedVisualContext Tree:[s2] transform=[1,0,0,1,5,5] origin=(70,70) (BlockContainer<DIV>#transformed)[s3] transform=[1,0,0,1,5,5] origin=(250,70) (BlockContainer<DIV>#plain)clips:- [c0 in s2] clip_path=[bounds: 20,20 100x100, path: M20 20L70 20L70 120L20 120L20 20Z] (BlockContainer<DIV>#transformed)+ [c0 in s2] clip_path=[bounds: 20,20 50x100, path: M20 20L70 20L70 120L20 120L20 20Z] (BlockContainer<DIV>#transformed)effects:[e0 in s0] effects=[][e1 in s2 out=c0] effects=[opacity=0.5 backdrop-filter=[20,20 100x100]] (BlockContainer<DIV>#transformed)diff --git a/Tests/LibWeb/Text/expected/display_list/clip-path-empty-invalidation.txt b/Tests/LibWeb/Text/expected/display_list/clip-path-empty-invalidation.txtindex 282cb8ec792..901058278b9 100644--- a/Tests/LibWeb/Text/expected/display_list/clip-path-empty-invalidation.txt+++ b/Tests/LibWeb/Text/expected/display_list/clip-path-empty-invalidation.txt@@ -17,7 +17,7 @@ AccumulatedVisualContext Tree:[s0] transform=[1,0,0,1,0,0] origin=(0,0) (Viewport<#document>)[s1] scroll (Viewport<#document>)clips:- [c0 in s1] clip_path=[bounds: 8,8 100x100, path: M58 58L58 58L58 58L58 58Z] (BlockContainer<DIV>#box)+ [c0 in s1] clip_path=[bounds: 58,58 0x0, path: M58 58L58 58L58 58L58 58Z] (BlockContainer<DIV>#box)effects:[e0 in s0] effects=[]diff --git a/Tests/LibWeb/Text/expected/display_list/clip-positioned-descendants.txt b/Tests/LibWeb/Text/expected/display_list/clip-positioned-descendants.txtindex 752f1910038..b74da4323ee 100644--- a/Tests/LibWeb/Text/expected/display_list/clip-positioned-descendants.txt+++ b/Tests/LibWeb/Text/expected/display_list/clip-positioned-descendants.txt@@ -3,7 +3,7 @@ AccumulatedVisualContext Tree:[s0] transform=[1,0,0,1,0,0] origin=(0,0) (Viewport<#document>)[s1] scroll (Viewport<#document>)clips:- [c0 in s1] clip_path=[bounds: 0,0 200x200, path: M50 50L150 50L150 150L50 150L50 50Z] (BlockContainer<DIV>.clip-path-ancestor)+ [c0 in s1] clip_path=[bounds: 50,50 100x100, path: M50 50L150 50L150 150L50 150L50 50Z] (BlockContainer<DIV>.clip-path-ancestor)[c3 in s0] clip=[220,0 100x100] (BlockContainer<DIV>.clip-ancestor)effects:[e0 in s0] effects=[]diff --git a/Tests/LibWeb/Text/expected/hit_testing/clip-path-negative-fractional-coordinates.txt b/Tests/LibWeb/Text/expected/hit_testing/clip-path-negative-fractional-coordinates.txtnew file mode 100644index 00000000000..0441573ad14--- /dev/null+++ b/Tests/LibWeb/Text/expected/hit_testing/clip-path-negative-fractional-coordinates.txt@@ -0,0 +1,7 @@+Inside negative fractional path at (93, 93): target+Inside negative fractional path at (95, 95): target+Inside negative fractional path at (98, 98): target+Outside negative fractional path at (91, 95): HTML+Outside negative fractional path at (95, 91): HTML+Outside negative fractional path at (99.5, 95): HTML+Outside negative fractional path at (95, 99.5): HTMLdiff --git a/Tests/LibWeb/Text/expected/hit_testing/clip-path-outside-reference-box.txt b/Tests/LibWeb/Text/expected/hit_testing/clip-path-outside-reference-box.txtnew file mode 100644index 00000000000..da2e1e2b94a--- /dev/null+++ b/Tests/LibWeb/Text/expected/hit_testing/clip-path-outside-reference-box.txt@@ -0,0 +1,49 @@+inset(-20px)+Outside reference box, inside clip: target+Outside reference box, inside clip: target+Outside reference box, inside clip: target+Outside reference box, inside clip: target+Outside clip: HTML+rect(-20px 120px 120px -20px)+Outside reference box, inside clip: target+Outside reference box, inside clip: target+Outside reference box, inside clip: target+Outside reference box, inside clip: target+Outside clip: HTML+xywh(-20px -20px 140px 140px)+Outside reference box, inside clip: target+Outside reference box, inside clip: target+Outside reference box, inside clip: target+Outside reference box, inside clip: target+Outside clip: HTML+circle(70px)+Outside reference box, inside clip: target+Outside reference box, inside clip: target+Outside reference box, inside clip: target+Outside reference box, inside clip: target+Outside clip: HTML+ellipse(70px 70px)+Outside reference box, inside clip: target+Outside reference box, inside clip: target+Outside reference box, inside clip: target+Outside reference box, inside clip: target+Outside clip: HTML+polygon(-20px -20px, 120px -20px, 120px 120px, -20px 120px)+Outside reference box, inside clip: target+Outside reference box, inside clip: target+Outside reference box, inside clip: target+Outside reference box, inside clip: target+Outside clip: HTML+path("M -20 -20 H 120 V 120 H -20 Z")+Outside reference box, inside clip: target+Outside reference box, inside clip: target+Outside reference box, inside clip: target+Outside reference box, inside clip: target+Outside clip: HTML+shape(from -20px -20px, hline to 120px, vline to 120px, hline to -20px, close)+Outside reference box, inside clip: target+Outside reference box, inside clip: target+Outside reference box, inside clip: target+Outside reference box, inside clip: target+Outside clip: HTML+Inside path bounds, outside circle: HTMLdiff --git a/Tests/LibWeb/Text/input/hit_testing/clip-path-negative-fractional-coordinates.html b/Tests/LibWeb/Text/input/hit_testing/clip-path-negative-fractional-coordinates.htmlnew file mode 100644index 00000000000..2a271065391--- /dev/null+++ b/Tests/LibWeb/Text/input/hit_testing/clip-path-negative-fractional-coordinates.html@@ -0,0 +1,49 @@+<!doctype html>+<script src="../include.js"></script>+<style>+ body {+ margin: 0;+ }+ #out {+ position: absolute;+ top: 400px;+ }+ #clipped {+ position: absolute;+ left: 0;+ top: 0;+ width: 10px;+ height: 10px;+ transform-origin: 0 0;+ transform: translate(100px, 100px) scale(10);+ clip-path: path("M -0.8 -0.8 H -0.1 V -0.1 H -0.8 Z");+ }+ #target {+ position: absolute;+ left: -1px;+ top: -1px;+ width: 1px;+ height: 1px;+ background: green;+ }+</style>+<div id="clipped"><div id="target"></div></div>+<script>+ test(() => {+ for (const [x, y] of [+ [93, 93],+ [95, 95],+ [98, 98],+ ]) {+ println(`Inside negative fractional path at (${x}, ${y}): ${document.elementFromPoint(x, y).id}`);+ }+ for (const [x, y] of [+ [91, 95],+ [95, 91],+ [99.5, 95],+ [95, 99.5],+ ]) {+ println(`Outside negative fractional path at (${x}, ${y}): ${document.elementFromPoint(x, y).tagName}`);+ }+ });+</script>diff --git a/Tests/LibWeb/Text/input/hit_testing/clip-path-outside-reference-box.html b/Tests/LibWeb/Text/input/hit_testing/clip-path-outside-reference-box.htmlnew file mode 100644index 00000000000..84ae0de393c--- /dev/null+++ b/Tests/LibWeb/Text/input/hit_testing/clip-path-outside-reference-box.html@@ -0,0 +1,52 @@+<!doctype html>+<script src="../include.js"></script>+<style>+ body {+ margin: 0;+ }+ #out {+ position: absolute;+ top: 400px;+ }+ #clipped {+ position: absolute;+ left: 100px;+ top: 100px;+ width: 100px;+ height: 100px;+ }+ #target {+ position: absolute;+ inset: -40px;+ background: green;+ }+</style>+<div id="clipped"><div id="target"></div></div>+<script>+ test(() => {+ const clipped = document.getElementById("clipped");+ for (const shape of [+ "inset(-20px)",+ "rect(-20px 120px 120px -20px)",+ "xywh(-20px -20px 140px 140px)",+ "circle(70px)",+ "ellipse(70px 70px)",+ "polygon(-20px -20px, 120px -20px, 120px 120px, -20px 120px)",+ 'path("M -20 -20 H 120 V 120 H -20 Z")',+ "shape(from -20px -20px, hline to 120px, vline to 120px, hline to -20px, close)",+ ]) {+ clipped.style.clipPath = shape;+ println(shape);+ for (const [x, y] of [+ [90, 150],+ [210, 150],+ [150, 90],+ [150, 210],+ ])+ println(`Outside reference box, inside clip: ${document.elementFromPoint(x, y).id}`);+ println(`Outside clip: ${document.elementFromPoint(70, 150).tagName}`);+ }+ clipped.style.clipPath = "circle(70px)";+ println(`Inside path bounds, outside circle: ${document.elementFromPoint(85, 85).tagName}`);+ });+</script>