Browse Source

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

Andreas Kling 5 years ago
parent
commit
c294c97cdf
1 changed files with 11 additions and 2 deletions
  1. 11 2
      Libraries/LibHTML/HtmlView.cpp

+ 11 - 2
Libraries/LibHTML/HtmlView.cpp

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