From 4de3449ad693a0daeb6490de5df385f07ad3b7df Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Thu, 3 Nov 2022 18:43:20 +0100 Subject: [PATCH] LibWeb: Recurse into block-level children when hit testing a box Otherwise, we always say you hit the parent, even when you're really clicking on a child that's visually above the parent. --- .../Libraries/LibWeb/Painting/PaintableBox.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/Userland/Libraries/LibWeb/Painting/PaintableBox.cpp b/Userland/Libraries/LibWeb/Painting/PaintableBox.cpp index c9326e047eb..12e19ea2fd7 100644 --- a/Userland/Libraries/LibWeb/Painting/PaintableBox.cpp +++ b/Userland/Libraries/LibWeb/Painting/PaintableBox.cpp @@ -649,9 +649,18 @@ Optional PaintableBox::hit_test(Gfx::FloatPoint const& position, return stacking_context()->hit_test(position, type); } - if (absolute_border_box_rect().contains(position.x(), position.y())) - return HitTestResult { *this }; - return {}; + if (!absolute_border_box_rect().contains(position.x(), position.y())) + return {}; + + for (auto* child = first_child(); child; child = child->next_sibling()) { + auto result = child->hit_test(position, type); + if (!result.has_value()) + continue; + if (!result->paintable->visible_for_hit_testing()) + continue; + return result; + } + return HitTestResult { *this }; } Optional PaintableWithLines::hit_test(Gfx::FloatPoint const& position, HitTestType type) const