Skip to content

Lightpanda: the headless browser designed for AI and automation

update isHitTestable to use the new generatesBox

Karl Seguine5d24beaa27a
diff --git a/src/browser/StyleManager.zig b/src/browser/StyleManager.zig
index e6342ad62..9a565b615 100644
--- a/src/browser/StyleManager.zig
+++ b/src/browser/StyleManager.zig
@@ -730,7 +730,7 @@ pub fn isHitTestable(self: *StyleManager, el: *Element) bool {
self.assertOwns(el);
self.rebuildIfDirty() catch return true;
const p = self.visibilityProps(el);
- return !p.visibility_hidden and !p.pointer_events_none and p.box != .contents;
+ return !p.visibility_hidden and !p.pointer_events_none and self.generatesBox(el);
}
/// Computed text-transform, which inherits: the nearest of `el` and its
diff --git a/src/browser/tests/document/element_from_point_hit_testing.html b/src/browser/tests/document/element_from_point_hit_testing.html
index 2d1f2c55b..c7910414c 100644
--- a/src/browser/tests/document/element_from_point_hit_testing.html
+++ b/src/browser/tests/document/element_from_point_hit_testing.html
@@ -78,3 +78,26 @@
testing.expectFalse(stack.includes(document.getElementById('hidden_wrap')));
}
</script>
+
+<script id="hit_skips_display_contents">
+{
+ const contents = document.createElement('div');
+ contents.style.display = 'contents';
+ contents.innerHTML = '<div style="width:100px;height:40px">inside</div>';
+ document.body.appendChild(contents);
+ const inside = contents.firstChild;
+ const r = inside.getBoundingClientRect();
+ const [x, y] = [r.x + 1, r.y + 1];
+ testing.expectEqual(inside, document.elementFromPoint(x, y));
+ testing.expectFalse(document.elementsFromPoint(x, y).includes(contents));
+
+ // display:contents on the root computes to block, so it can still be hit
+ const html = document.documentElement;
+ html.style.display = 'contents';
+ document.body.style.pointerEvents = 'none';
+ testing.expectEqual(html, document.elementFromPoint(x, y));
+ html.style.display = '';
+ document.body.style.pointerEvents = '';
+ contents.remove();
+}
+</script>