Skip to content

Commit

Permalink
LibWeb: Test nested elements in InlinePaintable::hit_test()
Browse files Browse the repository at this point in the history
Before this change we were ignoring nested paintables inside inline
paintable during hit-testing, but now we recurse into subtree.

Fixes SerenityOS#22927
  • Loading branch information
kalenikaliaksandr committed Jan 25, 2024
1 parent 7bcb560 commit 2856874
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
lang "en" <SPAN id="name" >
14 changes: 14 additions & 0 deletions Tests/LibWeb/Text/input/hit_testing/nested-inline-paintables.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<script src="../include.js"></script>
<body>
<span id="outer">
<span id="inner">
<span id="name">lang</span>
<span id="value">"en"</span>
</span>
</span>
<script type="text/javascript">
test(() => {
printElement(internals.hitTest(10, 10).node.parentNode);
});
</script>
</body>
8 changes: 8 additions & 0 deletions Tests/LibWeb/Text/input/include.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ function println(s) {
__outputElement.appendChild(document.createTextNode(s + "\n"));
}

function printElement(e) {
let element_string = `<${e.nodeName} `;
if (e.id)
element_string += `id="${e.id}" `;
element_string += ">";
println(element_string);
}

document.addEventListener("DOMContentLoaded", function () {
__outputElement = document.createElement("pre");
__outputElement.setAttribute("id", "out");
Expand Down
16 changes: 15 additions & 1 deletion Userland/Libraries/LibWeb/Painting/InlinePaintable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ void InlinePaintable::for_each_fragment(Callback callback) const

Optional<HitTestResult> InlinePaintable::hit_test(CSSPixelPoint position, HitTestType type) const
{
// dbgln(">>> InlinePaintable::hit_test({})", layout_node().debug_description());

for (auto& fragment : m_fragments) {
if (is<Layout::Box>(fragment.layout_node()) && static_cast<Layout::Box const&>(fragment.layout_node()).paintable_box()->stacking_context())
continue;
Expand All @@ -173,7 +175,19 @@ Optional<HitTestResult> InlinePaintable::hit_test(CSSPixelPoint position, HitTes
fragment.text_index_at(position.x()) };
}
}
return {};

Optional<HitTestResult> hit_test_result;
for_each_child([&](Paintable const& child) {
if (child.stacking_context())
return IterationDecision::Continue;
if (auto result = child.hit_test(position, type); result.has_value()) {
hit_test_result = result;
return IterationDecision::Break;
}
return IterationDecision::Continue;
});

return hit_test_result;
}

CSSPixelRect InlinePaintable::bounding_rect() const
Expand Down

0 comments on commit 2856874

Please sign in to comment.