summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb/CSS
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2021-04-06 12:23:32 +0200
committerAndreas Kling <kling@serenityos.org>2021-04-06 13:06:42 +0200
commit0eb9a9dd133fafd672d9217b4c9e06f88e653891 (patch)
tree950efd6b4a2fce25c0add64ca905dfaa4fa06bc7 /Userland/Libraries/LibWeb/CSS
parent4f690408af762c707166bc6448b459e0e16d22a2 (diff)
downloadserenity-0eb9a9dd133fafd672d9217b4c9e06f88e653891.zip
LibWeb: Support the :first-of-type CSS selector :^)
Diffstat (limited to 'Userland/Libraries/LibWeb/CSS')
-rw-r--r--Userland/Libraries/LibWeb/CSS/Parser/DeprecatedCSSParser.cpp2
-rw-r--r--Userland/Libraries/LibWeb/CSS/Selector.h1
-rw-r--r--Userland/Libraries/LibWeb/CSS/SelectorEngine.cpp6
3 files changed, 9 insertions, 0 deletions
diff --git a/Userland/Libraries/LibWeb/CSS/Parser/DeprecatedCSSParser.cpp b/Userland/Libraries/LibWeb/CSS/Parser/DeprecatedCSSParser.cpp
index 365ed0eee2..a64bcfbae8 100644
--- a/Userland/Libraries/LibWeb/CSS/Parser/DeprecatedCSSParser.cpp
+++ b/Userland/Libraries/LibWeb/CSS/Parser/DeprecatedCSSParser.cpp
@@ -554,6 +554,8 @@ public:
simple_selector.pseudo_class = CSS::Selector::SimpleSelector::PseudoClass::Empty;
} else if (pseudo_name.equals_ignoring_case("root")) {
simple_selector.pseudo_class = CSS::Selector::SimpleSelector::PseudoClass::Root;
+ } else if (pseudo_name.equals_ignoring_case("first-of-type")) {
+ simple_selector.pseudo_class = CSS::Selector::SimpleSelector::PseudoClass::FirstOfType;
} else if (pseudo_name.equals_ignoring_case("before")) {
simple_selector.pseudo_element = CSS::Selector::SimpleSelector::PseudoElement::Before;
} else if (pseudo_name.equals_ignoring_case("after")) {
diff --git a/Userland/Libraries/LibWeb/CSS/Selector.h b/Userland/Libraries/LibWeb/CSS/Selector.h
index d5dae94f98..e9d0085206 100644
--- a/Userland/Libraries/LibWeb/CSS/Selector.h
+++ b/Userland/Libraries/LibWeb/CSS/Selector.h
@@ -54,6 +54,7 @@ public:
OnlyChild,
Empty,
Root,
+ FirstOfType,
};
PseudoClass pseudo_class { PseudoClass::None };
diff --git a/Userland/Libraries/LibWeb/CSS/SelectorEngine.cpp b/Userland/Libraries/LibWeb/CSS/SelectorEngine.cpp
index a1db87f78f..96c0743f89 100644
--- a/Userland/Libraries/LibWeb/CSS/SelectorEngine.cpp
+++ b/Userland/Libraries/LibWeb/CSS/SelectorEngine.cpp
@@ -90,6 +90,12 @@ static bool matches(const CSS::Selector::SimpleSelector& component, const DOM::E
if (!is<HTML::HTMLElement>(element))
return false;
break;
+ case CSS::Selector::SimpleSelector::PseudoClass::FirstOfType:
+ for (auto* sibling = element.previous_element_sibling(); sibling; sibling = sibling->previous_element_sibling()) {
+ if (sibling->tag_name() == element.tag_name())
+ return false;
+ }
+ break;
}
switch (component.attribute_match_type) {