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.
This commit is contained in:
ronak69 2024-04-20 10:14:31 +00:00 committed by Tim Flynn
parent 318fc62b53
commit d48831e893
Notes: github-actions[bot] 2024-12-10 13:30:47 +00:00
2 changed files with 19 additions and 3 deletions

View file

@ -626,16 +626,23 @@ EventResult EventHandler::handle_mousemove(CSSPixelPoint viewport_position, CSSP
if (hovered_node_changed) {
GC::Ptr<HTML::HTMLElement const> 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;
}

View file

@ -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 {};