LibHTML: Show a hand cursor when hovering over a clickable link :^)

This commit is contained in:
Andreas Kling 2019-10-10 21:35:50 +02:00
parent 76266862d1
commit c294c97cdf
Notes: sideshowbarker 2024-07-19 11:44:17 +09:00

View file

@ -2,6 +2,7 @@
#include <LibGUI/GApplication.h>
#include <LibGUI/GPainter.h>
#include <LibGUI/GScrollBar.h>
#include <LibGUI/GWindow.h>
#include <LibHTML/DOM/Element.h>
#include <LibHTML/DOM/HTMLAnchorElement.h>
#include <LibHTML/Dump.h>
@ -119,19 +120,24 @@ void HtmlView::mousemove_event(GMouseEvent& event)
return GScrollableWidget::mousemove_event(event);
bool hovered_node_changed = false;
bool is_hovering_link = false;
auto result = m_layout_root->hit_test(to_content_position(event.position()));
if (result.layout_node) {
auto* node = result.layout_node->node();
hovered_node_changed = node != m_document->hovered_node();
m_document->set_hovered_node(const_cast<Node*>(node));
#ifdef HTML_DEBUG
if (node) {
if (auto* link = node->enclosing_link_element()) {
UNUSED_PARAM(link);
#ifdef HTML_DEBUG
dbg() << "HtmlView: hovering over a link to " << link->href();
#endif
is_hovering_link = true;
}
}
#endif
}
if (window())
window()->set_override_cursor(is_hovering_link ? GStandardCursor::Hand : GStandardCursor::None);
if (hovered_node_changed) {
update();
auto* hovered_html_element = m_document->hovered_node() ? m_document->hovered_node()->enclosing_html_element() : nullptr;
@ -178,6 +184,9 @@ void HtmlView::load(const URL& url)
{
dbg() << "HtmlView::load: " << url;
if (window())
window()->set_override_cursor(GStandardCursor::None);
if (on_load_start)
on_load_start(url);