From 892186d0585e18ad636a157e82f6f89f753dedcd Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Mon, 7 Nov 2022 18:22:33 +0100 Subject: [PATCH] LibWeb: Pick the correct DOM node for mouse-move events This makes hovering over the link in the following HTML snippet work, i.e. the tooltip is shown and the link target is shown at the bottom of the browser window: --- Userland/Libraries/LibWeb/Page/EventHandler.cpp | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/Userland/Libraries/LibWeb/Page/EventHandler.cpp b/Userland/Libraries/LibWeb/Page/EventHandler.cpp index 73163c8c43..7c36ee6066 100644 --- a/Userland/Libraries/LibWeb/Page/EventHandler.cpp +++ b/Userland/Libraries/LibWeb/Page/EventHandler.cpp @@ -453,9 +453,14 @@ bool EventHandler::handle_mousemove(Gfx::IntPoint const& position, unsigned butt // FIXME: Handle other values for pointer-events. VERIFY(pointer_events != CSS::PointerEvents::None); + // Search for the first parent of the hit target that's an element. + // "The click event type MUST be dispatched on the topmost event target indicated by the pointer." (https://www.w3.org/TR/uievents/#event-type-click) + // "The topmost event target MUST be the element highest in the rendering order which is capable of being an event target." (https://www.w3.org/TR/uievents/#topmost-event-target) + Layout::Node const* layout_node; + bool found_parent_element = parent_element_for_event_dispatch(*paintable, node, layout_node); hovered_node_changed = node.ptr() != document.hovered_node(); document.set_hovered_node(node); - if (node) { + if (found_parent_element) { hovered_link_element = node->enclosing_link_element(); if (hovered_link_element) is_hovering_link = true; @@ -474,22 +479,12 @@ bool EventHandler::handle_mousemove(Gfx::IntPoint const& position, unsigned butt hovered_node_cursor = cursor_css_to_gfx(cursor); } - // Search for the first parent of the hit target that's an element. - // "The click event type MUST be dispatched on the topmost event target indicated by the pointer." (https://www.w3.org/TR/uievents/#event-type-click) - // "The topmost event target MUST be the element highest in the rendering order which is capable of being an event target." (https://www.w3.org/TR/uievents/#topmost-event-target) - Layout::Node const* layout_node; - if (!parent_element_for_event_dispatch(*paintable, node, layout_node)) { - // FIXME: This is pretty ugly but we need to bail out here. - goto after_node_use; - } - auto offset = compute_mouse_event_offset(position, *layout_node); node->dispatch_event(*UIEvents::MouseEvent::create_from_platform_event(node->realm(), UIEvents::EventNames::mousemove, offset.x(), offset.y(), position.x(), position.y(), buttons)); // NOTE: Dispatching an event may have disturbed the world. if (!paint_root() || paint_root() != node->document().paint_box()) return true; } - after_node_use: if (m_in_mouse_selection) { auto hit = paint_root()->hit_test(position.to_type(), Painting::HitTestType::TextCursor); if (start_index.has_value() && hit.has_value() && hit->dom_node()) {