diff --git a/Base/home/anon/www/only-child.html b/Base/home/anon/www/only-child.html new file mode 100644 index 0000000000..671ee285df --- /dev/null +++ b/Base/home/anon/www/only-child.html @@ -0,0 +1,28 @@ + + +:only-child test + + + +
+
I am an only child.
+
+ +
+
I am the 1st sibling.
+
I am the 2nd sibling.
+
I am the 3rd sibling,
but this is an only child.
+
+ + + diff --git a/Base/home/anon/www/welcome.html b/Base/home/anon/www/welcome.html index 7405b028c8..16563d09fc 100644 --- a/Base/home/anon/www/welcome.html +++ b/Base/home/anon/www/welcome.html @@ -26,6 +26,7 @@ h1 {
  • small
  • :first-child
  • :last-child
  • +
  • :only-child
  • :empty
  • form
  • borders
  • diff --git a/Libraries/LibHTML/CSS/Selector.h b/Libraries/LibHTML/CSS/Selector.h index ba9827550b..7170c0497a 100644 --- a/Libraries/LibHTML/CSS/Selector.h +++ b/Libraries/LibHTML/CSS/Selector.h @@ -22,6 +22,7 @@ public: Hover, FirstChild, LastChild, + OnlyChild, Empty, }; PseudoClass pseudo_class { PseudoClass::None }; diff --git a/Libraries/LibHTML/CSS/SelectorEngine.cpp b/Libraries/LibHTML/CSS/SelectorEngine.cpp index 32f20f26c2..d62728056c 100644 --- a/Libraries/LibHTML/CSS/SelectorEngine.cpp +++ b/Libraries/LibHTML/CSS/SelectorEngine.cpp @@ -36,6 +36,10 @@ bool matches(const Selector::SimpleSelector& component, const Element& element) if (element.next_element_sibling()) return false; break; + case Selector::SimpleSelector::PseudoClass::OnlyChild: + if (element.previous_element_sibling() || element.next_element_sibling()) + return false; + break; case Selector::SimpleSelector::PseudoClass::Empty: if (element.first_child_of_type() || element.first_child_of_type()) return false; diff --git a/Libraries/LibHTML/Parser/CSSParser.cpp b/Libraries/LibHTML/Parser/CSSParser.cpp index 92eeaeebbc..47f4863dcf 100644 --- a/Libraries/LibHTML/Parser/CSSParser.cpp +++ b/Libraries/LibHTML/Parser/CSSParser.cpp @@ -325,6 +325,8 @@ public: simple_selector.pseudo_class = Selector::SimpleSelector::PseudoClass::FirstChild; else if (pseudo_name == "last-child") simple_selector.pseudo_class = Selector::SimpleSelector::PseudoClass::LastChild; + else if (pseudo_name == "only-child") + simple_selector.pseudo_class = Selector::SimpleSelector::PseudoClass::OnlyChild; else if (pseudo_name == "empty") simple_selector.pseudo_class = Selector::SimpleSelector::PseudoClass::Empty; }