mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-21 03:55:24 +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
Notes:
sideshowbarker
2024-07-19 11:53:53 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/88de955073a
3 changed files with 18 additions and 1 deletions
|
@ -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<StyleResolver> m_style_resolver;
|
||||
NonnullRefPtrVector<StyleSheet> m_sheets;
|
||||
RefPtr<Node> m_hovered_node;
|
||||
};
|
||||
|
|
|
@ -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*>(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();
|
||||
}
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
#include <LibGUI/GPainter.h>
|
||||
#include <LibHTML/DOM/Document.h>
|
||||
#include <LibHTML/DOM/Element.h>
|
||||
#include <LibHTML/Layout/LayoutBlock.h>
|
||||
#include <LibHTML/Layout/LayoutNode.h>
|
||||
|
||||
//#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) {
|
||||
|
|
Loading…
Add table
Reference in a new issue