From d48831e893ecfb070cbe42d7a6892d9ee2e9817a Mon Sep 17 00:00:00 2001 From: ronak69 Date: Sat, 20 Apr 2024 10:14:31 +0000 Subject: [PATCH] LibWeb: Leave tooltip or unhover link only if page entered/hovered one Before, on a mouse-move event, if the hovered html element did not have a tooltip or it was not a link, `page_did_leave_tooltip_area()` and `page_did_unhover_link()` virtual functions would get called. Now, the page remembers if it is in a tooltip area or hovering a link and only informs of leaving or unhovering only if it was. --- Libraries/LibWeb/Page/EventHandler.cpp | 13 ++++++++++--- Libraries/LibWeb/Page/Page.h | 9 +++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/Libraries/LibWeb/Page/EventHandler.cpp b/Libraries/LibWeb/Page/EventHandler.cpp index 913968c0e58..eb00525694a 100644 --- a/Libraries/LibWeb/Page/EventHandler.cpp +++ b/Libraries/LibWeb/Page/EventHandler.cpp @@ -626,15 +626,22 @@ EventResult EventHandler::handle_mousemove(CSSPixelPoint viewport_position, CSSP if (hovered_node_changed) { GC::Ptr hovered_html_element = document.hovered_node() ? document.hovered_node()->enclosing_html_element_with_attribute(HTML::AttributeNames::title) : nullptr; + if (hovered_html_element && hovered_html_element->title().has_value()) { + page.set_is_in_tooltip_area(true); page.client().page_did_enter_tooltip_area(hovered_html_element->title()->to_byte_string()); - } else { + } else if (page.is_in_tooltip_area()) { + page.set_is_in_tooltip_area(false); page.client().page_did_leave_tooltip_area(); } - if (is_hovering_link) + + if (is_hovering_link) { + page.set_is_hovering_link(true); page.client().page_did_hover_link(document.parse_url(hovered_link_element->href())); - else + } else if (page.is_hovering_link()) { + page.set_is_hovering_link(false); page.client().page_did_unhover_link(); + } } return EventResult::Handled; diff --git a/Libraries/LibWeb/Page/Page.h b/Libraries/LibWeb/Page/Page.h index 3200c763da9..4e0f7dfa915 100644 --- a/Libraries/LibWeb/Page/Page.h +++ b/Libraries/LibWeb/Page/Page.h @@ -121,6 +121,12 @@ public: bool is_webdriver_active() const { return m_is_webdriver_active; } void set_is_webdriver_active(bool b) { m_is_webdriver_active = b; } + bool is_hovering_link() const { return m_is_hovering_link; } + void set_is_hovering_link(bool b) { m_is_hovering_link = b; } + + bool is_in_tooltip_area() const { return m_is_in_tooltip_area; } + void set_is_in_tooltip_area(bool b) { m_is_in_tooltip_area = b; } + Gfx::StandardCursor current_cursor() const { return m_current_cursor; } void set_current_cursor(Gfx::StandardCursor cursor) { m_current_cursor = cursor; } @@ -249,6 +255,9 @@ private: // The webdriver-active flag is set to true when the user agent is under remote control. It is initially false. bool m_is_webdriver_active { false }; + bool m_is_hovering_link { false }; + bool m_is_in_tooltip_area { false }; + Gfx::StandardCursor m_current_cursor { Gfx::StandardCursor::Arrow }; DevicePixelPoint m_window_position {};