summaryrefslogtreecommitdiff
path: root/Userland/Libraries
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2022-09-14 13:29:07 +0200
committerAndreas Kling <kling@serenityos.org>2022-09-14 14:43:17 +0200
commit4b9c5635b36df645c83e9e2f1da269794717cbb1 (patch)
tree93c83f40fe8c46b1907a0f5cdcaf16e86d09b155 /Userland/Libraries
parentf25203f245e56f4c6aa734db5930b3220907917f (diff)
downloadserenity-4b9c5635b36df645c83e9e2f1da269794717cbb1.zip
LibWeb: Make :link selector behave according to spec
It should match any `a` or `area` element that has an `href` attribute, not any element *inside* an enclosing linked element.
Diffstat (limited to 'Userland/Libraries')
-rw-r--r--Userland/Libraries/LibWeb/CSS/SelectorEngine.cpp13
-rw-r--r--Userland/Libraries/LibWeb/DOM/Node.cpp5
-rw-r--r--Userland/Libraries/LibWeb/DOM/Node.h2
3 files changed, 12 insertions, 8 deletions
diff --git a/Userland/Libraries/LibWeb/CSS/SelectorEngine.cpp b/Userland/Libraries/LibWeb/CSS/SelectorEngine.cpp
index f2d0586af7..dfdf426bf8 100644
--- a/Userland/Libraries/LibWeb/CSS/SelectorEngine.cpp
+++ b/Userland/Libraries/LibWeb/CSS/SelectorEngine.cpp
@@ -11,6 +11,8 @@
#include <LibWeb/DOM/Element.h>
#include <LibWeb/DOM/Text.h>
#include <LibWeb/HTML/AttributeNames.h>
+#include <LibWeb/HTML/HTMLAnchorElement.h>
+#include <LibWeb/HTML/HTMLAreaElement.h>
#include <LibWeb/HTML/HTMLHtmlElement.h>
#include <LibWeb/HTML/HTMLInputElement.h>
@@ -44,6 +46,15 @@ static inline bool matches_lang_pseudo_class(DOM::Element const& element, Vector
return false;
}
+// https://html.spec.whatwg.org/multipage/semantics-other.html#selector-link
+static inline bool matches_link_pseudo_class(DOM::Element const& element)
+{
+ // All a elements that have an href attribute, and all area elements that have an href attribute, must match one of :link and :visited.
+ if (!is<HTML::HTMLAnchorElement>(element) && !is<HTML::HTMLAreaElement>(element))
+ return false;
+ return element.has_attribute(HTML::AttributeNames::href);
+}
+
static inline bool matches_hover_pseudo_class(DOM::Element const& element)
{
auto* hovered_node = element.document().hovered_node();
@@ -163,7 +174,7 @@ static inline bool matches_pseudo_class(CSS::Selector::SimpleSelector::PseudoCla
{
switch (pseudo_class.type) {
case CSS::Selector::SimpleSelector::PseudoClass::Type::Link:
- return element.is_link();
+ return matches_link_pseudo_class(element);
case CSS::Selector::SimpleSelector::PseudoClass::Type::Visited:
// FIXME: Maybe match this selector sometimes?
return false;
diff --git a/Userland/Libraries/LibWeb/DOM/Node.cpp b/Userland/Libraries/LibWeb/DOM/Node.cpp
index c68efd6e21..66fe1a0f6f 100644
--- a/Userland/Libraries/LibWeb/DOM/Node.cpp
+++ b/Userland/Libraries/LibWeb/DOM/Node.cpp
@@ -244,11 +244,6 @@ void Node::invalidate_style()
document().schedule_style_update();
}
-bool Node::is_link() const
-{
- return enclosing_link_element();
-}
-
String Node::child_text_content() const
{
if (!is<ParentNode>(*this))
diff --git a/Userland/Libraries/LibWeb/DOM/Node.h b/Userland/Libraries/LibWeb/DOM/Node.h
index 9f4383afb3..dcc1088192 100644
--- a/Userland/Libraries/LibWeb/DOM/Node.h
+++ b/Userland/Libraries/LibWeb/DOM/Node.h
@@ -170,8 +170,6 @@ public:
void invalidate_style();
- bool is_link() const;
-
void set_document(Badge<Document>, Document&);
virtual EventTarget* get_parent(Event const&) override;