From edab67d5e83cb8a41a27ce602cb0ffb5d170d8b4 Mon Sep 17 00:00:00 2001 From: Aliaksandr Kalenik Date: Mon, 12 Feb 2024 14:58:10 +0100 Subject: [PATCH] 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). --- .../Text/expected/hit_testing/button.txt | 1 + .../LibWeb/Text/input/hit_testing/button.html | 21 +++++++++++++++++++ .../Libraries/LibWeb/Page/EventHandler.cpp | 8 +++++-- 3 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 Tests/LibWeb/Text/expected/hit_testing/button.txt create mode 100644 Tests/LibWeb/Text/input/hit_testing/button.html diff --git a/Tests/LibWeb/Text/expected/hit_testing/button.txt b/Tests/LibWeb/Text/expected/hit_testing/button.txt new file mode 100644 index 0000000000..7fc555d082 --- /dev/null +++ b/Tests/LibWeb/Text/expected/hit_testing/button.txt @@ -0,0 +1 @@ +Button Clicked! diff --git a/Tests/LibWeb/Text/input/hit_testing/button.html b/Tests/LibWeb/Text/input/hit_testing/button.html new file mode 100644 index 0000000000..39712152b5 --- /dev/null +++ b/Tests/LibWeb/Text/input/hit_testing/button.html @@ -0,0 +1,21 @@ + + + + + diff --git a/Userland/Libraries/LibWeb/Page/EventHandler.cpp b/Userland/Libraries/LibWeb/Page/EventHandler.cpp index adc8dfc1d5..2dd1de250c 100644 --- a/Userland/Libraries/LibWeb/Page/EventHandler.cpp +++ b/Userland/Libraries/LibWeb/Page/EventHandler.cpp @@ -34,8 +34,12 @@ static JS::GCPtr dom_node_for_event_dispatch(Painting::Paintable& pai return node; if (auto node = paintable.dom_node()) return node; - if (auto* layout_parent = paintable.layout_node().parent()) - return layout_parent->dom_node(); + auto* layout_parent = paintable.layout_node().parent(); + while (layout_parent) { + if (auto* node = layout_parent->dom_node()) + return node; + layout_parent = layout_parent->parent(); + } return nullptr; }