diff --git a/Libraries/LibHTML/DOM/Document.h b/Libraries/LibHTML/DOM/Document.h
index 66a64e92aa..1364cfb3c4 100644
--- a/Libraries/LibHTML/DOM/Document.h
+++ b/Libraries/LibHTML/DOM/Document.h
@@ -25,7 +25,12 @@ public:
virtual String tag_name() const override { return "#document"; }
+ void set_hovered_node(Node* node) { m_hovered_node = node; }
+ Node* hovered_node() { return m_hovered_node; }
+ const Node* hovered_node() const { return m_hovered_node; }
+
private:
OwnPtr m_style_resolver;
NonnullRefPtrVector m_sheets;
+ RefPtr m_hovered_node;
};
diff --git a/Libraries/LibHTML/HtmlView.cpp b/Libraries/LibHTML/HtmlView.cpp
index 23c0a2f971..69904481a7 100644
--- a/Libraries/LibHTML/HtmlView.cpp
+++ b/Libraries/LibHTML/HtmlView.cpp
@@ -85,11 +85,17 @@ void HtmlView::mousemove_event(GMouseEvent& event)
if (!m_layout_root)
return GScrollableWidget::mousemove_event(event);
+ bool hovered_node_changed = false;
auto result = m_layout_root->hit_test(event.position());
if (result.layout_node) {
- if (auto* node = result.layout_node->node()) {
+ auto* node = result.layout_node->node();
+ m_document->set_hovered_node(const_cast(node));
+ hovered_node_changed = node == m_document->hovered_node();
+ if (node) {
dbg() << "HtmlView: mousemove: " << node->tag_name() << "{" << node << "}";
}
}
+ if (hovered_node_changed)
+ update();
event.accept();
}
diff --git a/Libraries/LibHTML/Layout/LayoutNode.cpp b/Libraries/LibHTML/Layout/LayoutNode.cpp
index dea0a68cb8..ff44ed7bc6 100644
--- a/Libraries/LibHTML/Layout/LayoutNode.cpp
+++ b/Libraries/LibHTML/Layout/LayoutNode.cpp
@@ -1,9 +1,11 @@
#include
+#include
#include
#include
#include
//#define DRAW_BOXES_AROUND_LAYOUT_NODES
+//#define DRAW_BOXES_AROUND_HOVERED_NODES
LayoutNode::LayoutNode(const Node* node, StyleProperties&& style_properties)
: m_node(node)
@@ -35,6 +37,10 @@ void LayoutNode::render(RenderingContext& context)
{
#ifdef DRAW_BOXES_AROUND_LAYOUT_NODES
context.painter().draw_rect(m_rect, Color::Blue);
+#endif
+#ifdef DRAW_BOXES_AROUND_HOVERED_NODES
+ if (!is_anonymous() && node() == document().hovered_node())
+ context.painter().draw_rect(m_rect, Color::Red);
#endif
// TODO: render our background and border
for_each_child([&](auto& child) {