mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 19:08:10 +00:00
LibHTML: Detect hovering over links
HtmlView now calls Node::enclosing_link_element() to find the nearest ancestor <a> element. This patch also adds HTMLElement and HTMLAnchorElement.
This commit is contained in:
parent
88de955073
commit
b477aff843
9 changed files with 60 additions and 0 deletions
10
Libraries/LibHTML/DOM/HTMLAnchorElement.cpp
Normal file
10
Libraries/LibHTML/DOM/HTMLAnchorElement.cpp
Normal file
|
@ -0,0 +1,10 @@
|
|||
#include <LibHTML/DOM/HTMLAnchorElement.h>
|
||||
|
||||
HTMLAnchorElement::HTMLAnchorElement(Document& document, const String& tag_name)
|
||||
: HTMLElement(document, tag_name)
|
||||
{
|
||||
}
|
||||
|
||||
HTMLAnchorElement::~HTMLAnchorElement()
|
||||
{
|
||||
}
|
11
Libraries/LibHTML/DOM/HTMLAnchorElement.h
Normal file
11
Libraries/LibHTML/DOM/HTMLAnchorElement.h
Normal file
|
@ -0,0 +1,11 @@
|
|||
#pragma once
|
||||
|
||||
#include <LibHTML/DOM/HTMLElement.h>
|
||||
|
||||
class HTMLAnchorElement : public HTMLElement {
|
||||
public:
|
||||
HTMLAnchorElement(Document&, const String& tag_name);
|
||||
virtual ~HTMLAnchorElement() override;
|
||||
|
||||
String href() const { return attribute("href"); }
|
||||
};
|
10
Libraries/LibHTML/DOM/HTMLElement.cpp
Normal file
10
Libraries/LibHTML/DOM/HTMLElement.cpp
Normal file
|
@ -0,0 +1,10 @@
|
|||
#include <LibHTML/DOM/HTMLElement.h>
|
||||
|
||||
HTMLElement::HTMLElement(Document& document, const String& tag_name)
|
||||
: Element(document, tag_name)
|
||||
{
|
||||
}
|
||||
|
||||
HTMLElement::~HTMLElement()
|
||||
{
|
||||
}
|
9
Libraries/LibHTML/DOM/HTMLElement.h
Normal file
9
Libraries/LibHTML/DOM/HTMLElement.h
Normal file
|
@ -0,0 +1,9 @@
|
|||
#pragma once
|
||||
|
||||
#include <LibHTML/DOM/Element.h>
|
||||
|
||||
class HTMLElement : public Element {
|
||||
public:
|
||||
HTMLElement(Document&, const String& tag_name);
|
||||
virtual ~HTMLElement() override;
|
||||
};
|
|
@ -1,5 +1,6 @@
|
|||
#include <LibHTML/DOM/Node.h>
|
||||
#include <LibHTML/DOM/Element.h>
|
||||
#include <LibHTML/DOM/HTMLAnchorElement.h>
|
||||
#include <LibHTML/CSS/StyleResolver.h>
|
||||
#include <LibHTML/Layout/LayoutNode.h>
|
||||
#include <LibHTML/Layout/LayoutBlock.h>
|
||||
|
@ -73,3 +74,10 @@ RefPtr<LayoutNode> Node::create_layout_tree(const StyleResolver& resolver, const
|
|||
}
|
||||
return layout_node;
|
||||
}
|
||||
|
||||
const HTMLAnchorElement* Node::enclosing_link_element() const
|
||||
{
|
||||
if (is_element() && tag_name().to_lowercase() == "a")
|
||||
return static_cast<const HTMLAnchorElement*>(this);
|
||||
return parent() ? parent()->enclosing_link_element() : nullptr;
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@ enum class NodeType : unsigned {
|
|||
};
|
||||
|
||||
class Document;
|
||||
class HTMLAnchorElement;
|
||||
class ParentNode;
|
||||
class LayoutNode;
|
||||
class StyleResolver;
|
||||
|
@ -37,6 +38,8 @@ public:
|
|||
Document& document() { return m_document; }
|
||||
const Document& document() const { return m_document; }
|
||||
|
||||
const HTMLAnchorElement* enclosing_link_element() const;
|
||||
|
||||
protected:
|
||||
Node(Document&, NodeType);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue