mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-04 09:22:53 +00:00
LibWeb: Fix hit-testing for button element
Change 'dom_node_for_event_dispatch' to locate the closest layout node with a DOM node instead of only checking the direct ancestor. This fixes hit-testing for buttons because they are wrapped into multiple anonymous layout nodes (internally we use flex formatting for them).
This commit is contained in:
parent
8e21bbf7bf
commit
edab67d5e8
Notes:
sideshowbarker
2024-07-17 07:20:57 +09:00
Author: https://github.com/kalenikaliaksandr
Commit: edab67d5e8
Pull-request: https://github.com/SerenityOS/serenity/pull/23166
3 changed files with 28 additions and 2 deletions
1
Tests/LibWeb/Text/expected/hit_testing/button.txt
Normal file
1
Tests/LibWeb/Text/expected/hit_testing/button.txt
Normal file
|
@ -0,0 +1 @@
|
||||||
|
Button Clicked!
|
21
Tests/LibWeb/Text/input/hit_testing/button.html
Normal file
21
Tests/LibWeb/Text/input/hit_testing/button.html
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<style>
|
||||||
|
#btn {
|
||||||
|
background-color: gold;
|
||||||
|
font-size: 100px;
|
||||||
|
width: 500px;
|
||||||
|
border: none;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
<script src="../include.js"></script>
|
||||||
|
<button type="submit" id="btn">Button</button>
|
||||||
|
<script>
|
||||||
|
asyncTest(done => {
|
||||||
|
const brn = document.getElementById("btn");
|
||||||
|
btn.onclick = () => {
|
||||||
|
println("Clicked!");
|
||||||
|
done();
|
||||||
|
};
|
||||||
|
internals.click(50, 50);
|
||||||
|
});
|
||||||
|
</script>
|
|
@ -34,8 +34,12 @@ static JS::GCPtr<DOM::Node> dom_node_for_event_dispatch(Painting::Paintable& pai
|
||||||
return node;
|
return node;
|
||||||
if (auto node = paintable.dom_node())
|
if (auto node = paintable.dom_node())
|
||||||
return node;
|
return node;
|
||||||
if (auto* layout_parent = paintable.layout_node().parent())
|
auto* layout_parent = paintable.layout_node().parent();
|
||||||
return layout_parent->dom_node();
|
while (layout_parent) {
|
||||||
|
if (auto* node = layout_parent->dom_node())
|
||||||
|
return node;
|
||||||
|
layout_parent = layout_parent->parent();
|
||||||
|
}
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue