summaryrefslogtreecommitdiff
path: root/Libraries
diff options
context:
space:
mode:
Diffstat (limited to 'Libraries')
-rw-r--r--Libraries/LibHTML/CSS/Selector.h2
-rw-r--r--Libraries/LibHTML/CSS/SelectorEngine.cpp8
-rw-r--r--Libraries/LibHTML/Parser/CSSParser.cpp4
3 files changed, 14 insertions, 0 deletions
diff --git a/Libraries/LibHTML/CSS/Selector.h b/Libraries/LibHTML/CSS/Selector.h
index 288f16a9a5..e0e68e2be6 100644
--- a/Libraries/LibHTML/CSS/Selector.h
+++ b/Libraries/LibHTML/CSS/Selector.h
@@ -20,6 +20,8 @@ public:
None,
Link,
Hover,
+ FirstChild,
+ LastChild,
};
PseudoClass pseudo_class { PseudoClass::None };
diff --git a/Libraries/LibHTML/CSS/SelectorEngine.cpp b/Libraries/LibHTML/CSS/SelectorEngine.cpp
index f33018607d..affedd2128 100644
--- a/Libraries/LibHTML/CSS/SelectorEngine.cpp
+++ b/Libraries/LibHTML/CSS/SelectorEngine.cpp
@@ -27,6 +27,14 @@ bool matches(const Selector::SimpleSelector& component, const Element& element)
if (!matches_hover_pseudo_class(element))
return false;
break;
+ case Selector::SimpleSelector::PseudoClass::FirstChild:
+ if (element.previous_element_sibling())
+ return false;
+ break;
+ case Selector::SimpleSelector::PseudoClass::LastChild:
+ if (element.next_element_sibling())
+ return false;
+ break;
}
switch (component.attribute_match_type) {
diff --git a/Libraries/LibHTML/Parser/CSSParser.cpp b/Libraries/LibHTML/Parser/CSSParser.cpp
index 786c713591..6cfc93c75a 100644
--- a/Libraries/LibHTML/Parser/CSSParser.cpp
+++ b/Libraries/LibHTML/Parser/CSSParser.cpp
@@ -321,6 +321,10 @@ public:
simple_selector.pseudo_class = Selector::SimpleSelector::PseudoClass::Link;
else if (pseudo_name == "hover")
simple_selector.pseudo_class = Selector::SimpleSelector::PseudoClass::Hover;
+ else if (pseudo_name == "first-child")
+ simple_selector.pseudo_class = Selector::SimpleSelector::PseudoClass::FirstChild;
+ else if (pseudo_name == "last-child")
+ simple_selector.pseudo_class = Selector::SimpleSelector::PseudoClass::LastChild;
}
return simple_selector;