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:
Andreas Kling 2019-10-19 21:21:29 +02:00
parent 73af2f8d02
commit 884ae80699
Notes: sideshowbarker 2024-07-19 11:37:36 +09:00
6 changed files with 31 additions and 4 deletions

View file

@ -31,6 +31,7 @@ public:
virtual String tag_name() const final { return m_tag_name; }
bool has_attribute(const String& name) const { return !attribute(name).is_null(); }
String attribute(const String& name) const;
void set_attribute(const String& name, const String& value);

View file

@ -21,7 +21,11 @@ Node::~Node()
const HTMLAnchorElement* Node::enclosing_link_element() const
{
return first_ancestor_of_type<HTMLAnchorElement>();
for (auto* node = this; node; node = node->parent()) {
if (is<HTMLAnchorElement>(*node) && to<HTMLAnchorElement>(*node).has_attribute("href"))
return to<HTMLAnchorElement>(node);
}
return nullptr;
}
const HTMLElement* Node::enclosing_html_element() const
@ -76,3 +80,11 @@ void Node::invalidate_style()
});
document().schedule_style_update();
}
bool Node::is_link() const
{
auto* enclosing_link = enclosing_link_element();
if (!enclosing_link)
return false;
return enclosing_link->has_attribute("href");
}

View file

@ -75,6 +75,8 @@ public:
void invalidate_style();
bool is_link() const;
protected:
Node(Document&, NodeType);