From 94c55d9e3707dfd2acbc3c7c48daad8cfcb69df1 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 12 Sep 2020 17:55:19 +0200 Subject: [PATCH] LibWeb: Two mouse event handling fixes - After letting a LayoutNode handle a mouseup, re-do the hit test since things may have changed. - Make sure we always update the document's hovered node. --- Libraries/LibWeb/Page/EventHandler.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Libraries/LibWeb/Page/EventHandler.cpp b/Libraries/LibWeb/Page/EventHandler.cpp index 57b73c9673..3307290e5b 100644 --- a/Libraries/LibWeb/Page/EventHandler.cpp +++ b/Libraries/LibWeb/Page/EventHandler.cpp @@ -87,6 +87,11 @@ bool EventHandler::handle_mouseup(const Gfx::IntPoint& position, unsigned button if (result.layout_node && result.layout_node->wants_mouse_events()) { result.layout_node->handle_mouseup({}, position, button, modifiers); + + // Things may have changed as a consequence of LayoutNode::handle_mouseup(). Hit test again. + if (!layout_root()) + return true; + result = layout_root()->hit_test(position, HitTestType::Exact); } if (result.layout_node && result.layout_node->node()) { @@ -125,13 +130,14 @@ bool EventHandler::handle_mousedown(const Gfx::IntPoint& position, unsigned butt if (!result.layout_node) return false; + RefPtr node = result.layout_node->node(); + document->set_hovered_node(node); + if (result.layout_node->wants_mouse_events()) { result.layout_node->handle_mousedown({}, position, button, modifiers); return true; } - RefPtr node = result.layout_node->node(); - document->set_hovered_node(node); if (!node) return false; @@ -210,6 +216,7 @@ bool EventHandler::handle_mousemove(const Gfx::IntPoint& position, unsigned butt if (result.layout_node) { if (result.layout_node->wants_mouse_events()) { + document.set_hovered_node(result.layout_node->node()); result.layout_node->handle_mousemove({}, position, buttons, modifiers); // FIXME: It feels a bit aggressive to always update the cursor like this. page_client.page_did_request_cursor_change(Gfx::StandardCursor::None);