mirror of
https://github.com/RGBCube/serenity
synced 2025-05-16 00:34:59 +00:00
LibHTML+Browser: Show target URL of hovered links in Browser statusbar
HtmlView will now invoke the on_link_hover hook when the cursor enters or leaves a DOM node that has an enclosing link element. This patch also updates the meaning of Node::enclosing_link_element() to find the nearest HTMLAnchorElementAncestor *with an href attribute*.
This commit is contained in:
parent
73af2f8d02
commit
884ae80699
6 changed files with 31 additions and 4 deletions
|
@ -142,16 +142,18 @@ void HtmlView::mousemove_event(GMouseEvent& event)
|
|||
|
||||
bool hovered_node_changed = false;
|
||||
bool is_hovering_link = false;
|
||||
bool was_hovering_link = m_document->hovered_node() && m_document->hovered_node()->is_link();
|
||||
auto result = layout_root()->hit_test(to_content_position(event.position()));
|
||||
const HTMLAnchorElement* hovered_link_element = nullptr;
|
||||
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));
|
||||
if (node) {
|
||||
if (auto* link = node->enclosing_link_element()) {
|
||||
UNUSED_PARAM(link);
|
||||
hovered_link_element = node->enclosing_link_element();
|
||||
if (hovered_link_element) {
|
||||
#ifdef HTML_DEBUG
|
||||
dbg() << "HtmlView: hovering over a link to " << link->href();
|
||||
dbg() << "HtmlView: hovering over a link to " << hovered_link_element->href();
|
||||
#endif
|
||||
is_hovering_link = true;
|
||||
}
|
||||
|
@ -169,6 +171,11 @@ void HtmlView::mousemove_event(GMouseEvent& event)
|
|||
GApplication::the().hide_tooltip();
|
||||
}
|
||||
}
|
||||
if (is_hovering_link != was_hovering_link) {
|
||||
if (on_link_hover) {
|
||||
on_link_hover(hovered_link_element ? m_document->complete_url(hovered_link_element->href()).to_string() : String());
|
||||
}
|
||||
}
|
||||
event.accept();
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue