mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 10:38:11 +00:00
LibHTML: Have Document track its hovered Node
This gets set from HtmlView::mousemove_event() at the moment.
This commit is contained in:
parent
754e6e0f67
commit
88de955073
3 changed files with 18 additions and 1 deletions
|
@ -25,7 +25,12 @@ public:
|
||||||
|
|
||||||
virtual String tag_name() const override { return "#document"; }
|
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:
|
private:
|
||||||
OwnPtr<StyleResolver> m_style_resolver;
|
OwnPtr<StyleResolver> m_style_resolver;
|
||||||
NonnullRefPtrVector<StyleSheet> m_sheets;
|
NonnullRefPtrVector<StyleSheet> m_sheets;
|
||||||
|
RefPtr<Node> m_hovered_node;
|
||||||
};
|
};
|
||||||
|
|
|
@ -85,11 +85,17 @@ void HtmlView::mousemove_event(GMouseEvent& event)
|
||||||
if (!m_layout_root)
|
if (!m_layout_root)
|
||||||
return GScrollableWidget::mousemove_event(event);
|
return GScrollableWidget::mousemove_event(event);
|
||||||
|
|
||||||
|
bool hovered_node_changed = false;
|
||||||
auto result = m_layout_root->hit_test(event.position());
|
auto result = m_layout_root->hit_test(event.position());
|
||||||
if (result.layout_node) {
|
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*>(node));
|
||||||
|
hovered_node_changed = node == m_document->hovered_node();
|
||||||
|
if (node) {
|
||||||
dbg() << "HtmlView: mousemove: " << node->tag_name() << "{" << node << "}";
|
dbg() << "HtmlView: mousemove: " << node->tag_name() << "{" << node << "}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (hovered_node_changed)
|
||||||
|
update();
|
||||||
event.accept();
|
event.accept();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
#include <LibGUI/GPainter.h>
|
#include <LibGUI/GPainter.h>
|
||||||
|
#include <LibHTML/DOM/Document.h>
|
||||||
#include <LibHTML/DOM/Element.h>
|
#include <LibHTML/DOM/Element.h>
|
||||||
#include <LibHTML/Layout/LayoutBlock.h>
|
#include <LibHTML/Layout/LayoutBlock.h>
|
||||||
#include <LibHTML/Layout/LayoutNode.h>
|
#include <LibHTML/Layout/LayoutNode.h>
|
||||||
|
|
||||||
//#define DRAW_BOXES_AROUND_LAYOUT_NODES
|
//#define DRAW_BOXES_AROUND_LAYOUT_NODES
|
||||||
|
//#define DRAW_BOXES_AROUND_HOVERED_NODES
|
||||||
|
|
||||||
LayoutNode::LayoutNode(const Node* node, StyleProperties&& style_properties)
|
LayoutNode::LayoutNode(const Node* node, StyleProperties&& style_properties)
|
||||||
: m_node(node)
|
: m_node(node)
|
||||||
|
@ -35,6 +37,10 @@ void LayoutNode::render(RenderingContext& context)
|
||||||
{
|
{
|
||||||
#ifdef DRAW_BOXES_AROUND_LAYOUT_NODES
|
#ifdef DRAW_BOXES_AROUND_LAYOUT_NODES
|
||||||
context.painter().draw_rect(m_rect, Color::Blue);
|
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
|
#endif
|
||||||
// TODO: render our background and border
|
// TODO: render our background and border
|
||||||
for_each_child([&](auto& child) {
|
for_each_child([&](auto& child) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue