summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Libraries/LibHTML/DOM/HTMLAnchorElement.cpp10
-rw-r--r--Libraries/LibHTML/DOM/HTMLAnchorElement.h11
-rw-r--r--Libraries/LibHTML/DOM/HTMLElement.cpp10
-rw-r--r--Libraries/LibHTML/DOM/HTMLElement.h9
-rw-r--r--Libraries/LibHTML/DOM/Node.cpp8
-rw-r--r--Libraries/LibHTML/DOM/Node.h3
-rw-r--r--Libraries/LibHTML/HtmlView.cpp4
-rw-r--r--Libraries/LibHTML/Makefile.shared2
-rw-r--r--Libraries/LibHTML/Parser/HTMLParser.cpp3
9 files changed, 60 insertions, 0 deletions
diff --git a/Libraries/LibHTML/DOM/HTMLAnchorElement.cpp b/Libraries/LibHTML/DOM/HTMLAnchorElement.cpp
new file mode 100644
index 0000000000..32033811b8
--- /dev/null
+++ b/Libraries/LibHTML/DOM/HTMLAnchorElement.cpp
@@ -0,0 +1,10 @@
+#include <LibHTML/DOM/HTMLAnchorElement.h>
+
+HTMLAnchorElement::HTMLAnchorElement(Document& document, const String& tag_name)
+ : HTMLElement(document, tag_name)
+{
+}
+
+HTMLAnchorElement::~HTMLAnchorElement()
+{
+}
diff --git a/Libraries/LibHTML/DOM/HTMLAnchorElement.h b/Libraries/LibHTML/DOM/HTMLAnchorElement.h
new file mode 100644
index 0000000000..588e89ca28
--- /dev/null
+++ b/Libraries/LibHTML/DOM/HTMLAnchorElement.h
@@ -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"); }
+};
diff --git a/Libraries/LibHTML/DOM/HTMLElement.cpp b/Libraries/LibHTML/DOM/HTMLElement.cpp
new file mode 100644
index 0000000000..8743019b15
--- /dev/null
+++ b/Libraries/LibHTML/DOM/HTMLElement.cpp
@@ -0,0 +1,10 @@
+#include <LibHTML/DOM/HTMLElement.h>
+
+HTMLElement::HTMLElement(Document& document, const String& tag_name)
+ : Element(document, tag_name)
+{
+}
+
+HTMLElement::~HTMLElement()
+{
+}
diff --git a/Libraries/LibHTML/DOM/HTMLElement.h b/Libraries/LibHTML/DOM/HTMLElement.h
new file mode 100644
index 0000000000..4e0c56beff
--- /dev/null
+++ b/Libraries/LibHTML/DOM/HTMLElement.h
@@ -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;
+};
diff --git a/Libraries/LibHTML/DOM/Node.cpp b/Libraries/LibHTML/DOM/Node.cpp
index b337cb1b90..5f527020b8 100644
--- a/Libraries/LibHTML/DOM/Node.cpp
+++ b/Libraries/LibHTML/DOM/Node.cpp
@@ -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;
+}
diff --git a/Libraries/LibHTML/DOM/Node.h b/Libraries/LibHTML/DOM/Node.h
index 3838efdfa0..2096b0dafb 100644
--- a/Libraries/LibHTML/DOM/Node.h
+++ b/Libraries/LibHTML/DOM/Node.h
@@ -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);
diff --git a/Libraries/LibHTML/HtmlView.cpp b/Libraries/LibHTML/HtmlView.cpp
index 69904481a7..c845d05135 100644
--- a/Libraries/LibHTML/HtmlView.cpp
+++ b/Libraries/LibHTML/HtmlView.cpp
@@ -1,6 +1,7 @@
#include <LibGUI/GPainter.h>
#include <LibGUI/GScrollBar.h>
#include <LibHTML/DOM/Element.h>
+#include <LibHTML/DOM/HTMLAnchorElement.h>
#include <LibHTML/Dump.h>
#include <LibHTML/HtmlView.h>
#include <LibHTML/Layout/LayoutNode.h>
@@ -93,6 +94,9 @@ void HtmlView::mousemove_event(GMouseEvent& event)
hovered_node_changed = node == m_document->hovered_node();
if (node) {
dbg() << "HtmlView: mousemove: " << node->tag_name() << "{" << node << "}";
+ if (auto* link = node->enclosing_link_element()) {
+ dbg() << "HtmlView: hovering over a link to " << link->href();
+ }
}
}
if (hovered_node_changed)
diff --git a/Libraries/LibHTML/Makefile.shared b/Libraries/LibHTML/Makefile.shared
index 96d38dd0fc..bb2e2ed0b4 100644
--- a/Libraries/LibHTML/Makefile.shared
+++ b/Libraries/LibHTML/Makefile.shared
@@ -2,6 +2,8 @@ LIBHTML_OBJS = \
DOM/Node.o \
DOM/ParentNode.o \
DOM/Element.o \
+ DOM/HTMLElement.o \
+ DOM/HTMLAnchorElement.o \
DOM/Document.o \
DOM/Text.o \
CSS/Selector.o \
diff --git a/Libraries/LibHTML/Parser/HTMLParser.cpp b/Libraries/LibHTML/Parser/HTMLParser.cpp
index a7c39692b2..0e31bda194 100644
--- a/Libraries/LibHTML/Parser/HTMLParser.cpp
+++ b/Libraries/LibHTML/Parser/HTMLParser.cpp
@@ -1,6 +1,7 @@
#include <AK/NonnullRefPtrVector.h>
#include <AK/StringBuilder.h>
#include <LibHTML/DOM/Element.h>
+#include <LibHTML/DOM/HTMLAnchorElement.h>
#include <LibHTML/DOM/Text.h>
#include <LibHTML/Parser/HTMLParser.h>
#include <ctype.h>
@@ -8,6 +9,8 @@
static NonnullRefPtr<Element> create_element(Document& document, const String& tag_name)
{
+ if (tag_name.to_lowercase() == "a")
+ return adopt(*new HTMLAnchorElement(document, tag_name));
return adopt(*new Element(document, tag_name));
}