Skip to content

Commit c028207

Browse files
kalenikaliaksandrawesomekling
authored andcommitted
LibWeb: Test nested elements in InlinePaintable::hit_test()
Before this change we were ignoring nested paintables inside inline paintable during hit-testing, but now we recurse into subtree. Fixes #22927
1 parent 1583e6c commit c028207

File tree

4 files changed

+37
-1
lines changed

4 files changed

+37
-1
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
lang "en" <SPAN id="name" >
2+
<SPAN id="value" >
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<script src="../include.js"></script>
2+
<body>
3+
<span id="outer">
4+
<span id="inner">
5+
<span id="name">lang</span>
6+
<span id="value">"en"</span>
7+
</span>
8+
</span>
9+
<script type="text/javascript">
10+
test(() => {
11+
printElement(internals.hitTest(10, 10).node.parentNode);
12+
printElement(internals.hitTest(50, 10).node.parentNode);
13+
});
14+
</script>
15+
</body>

Tests/LibWeb/Text/input/include.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ function println(s) {
1717
__outputElement.appendChild(document.createTextNode(s + "\n"));
1818
}
1919

20+
function printElement(e) {
21+
let element_string = `<${e.nodeName} `;
22+
if (e.id) element_string += `id="${e.id}" `;
23+
element_string += ">";
24+
println(element_string);
25+
}
26+
2027
document.addEventListener("DOMContentLoaded", function () {
2128
__outputElement = document.createElement("pre");
2229
__outputElement.setAttribute("id", "out");

Userland/Libraries/LibWeb/Painting/InlinePaintable.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,19 @@ Optional<HitTestResult> InlinePaintable::hit_test(CSSPixelPoint position, HitTes
173173
fragment.text_index_at(position.x()) };
174174
}
175175
}
176-
return {};
176+
177+
Optional<HitTestResult> hit_test_result;
178+
for_each_child([&](Paintable const& child) {
179+
if (child.stacking_context())
180+
return IterationDecision::Continue;
181+
if (auto result = child.hit_test(position, type); result.has_value()) {
182+
hit_test_result = result;
183+
return IterationDecision::Break;
184+
}
185+
return IterationDecision::Continue;
186+
});
187+
188+
return hit_test_result;
177189
}
178190

179191
CSSPixelRect InlinePaintable::bounding_rect() const

0 commit comments

Comments
 (0)