From 085cafd80a0183b0ef6c0a658d6505493e6d8b1e Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Mon, 16 Dec 2019 19:45:50 +0100 Subject: [PATCH] LibHTML: Support the :empty pseudo class --- Base/home/anon/www/empty.html | 26 ++++++++++++++++++++++++ Base/home/anon/www/welcome.html | 1 + Libraries/LibHTML/CSS/Selector.h | 1 + Libraries/LibHTML/CSS/SelectorEngine.cpp | 5 +++++ Libraries/LibHTML/Parser/CSSParser.cpp | 2 ++ 5 files changed, 35 insertions(+) create mode 100644 Base/home/anon/www/empty.html diff --git a/Base/home/anon/www/empty.html b/Base/home/anon/www/empty.html new file mode 100644 index 00000000000..dbdfe62a6aa --- /dev/null +++ b/Base/home/anon/www/empty.html @@ -0,0 +1,26 @@ + + +:empty test + + + +
+
I will be pink.
+
+ +
+
+

+
+ + diff --git a/Base/home/anon/www/welcome.html b/Base/home/anon/www/welcome.html index 1fbecdd0ca9..7405b028c80 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
  • +
  • :empty
  • form
  • borders
  • css
  • diff --git a/Libraries/LibHTML/CSS/Selector.h b/Libraries/LibHTML/CSS/Selector.h index e0e68e2be66..ba9827550ba 100644 --- a/Libraries/LibHTML/CSS/Selector.h +++ b/Libraries/LibHTML/CSS/Selector.h @@ -22,6 +22,7 @@ public: Hover, FirstChild, LastChild, + Empty, }; PseudoClass pseudo_class { PseudoClass::None }; diff --git a/Libraries/LibHTML/CSS/SelectorEngine.cpp b/Libraries/LibHTML/CSS/SelectorEngine.cpp index affedd2128c..32f20f26c2d 100644 --- a/Libraries/LibHTML/CSS/SelectorEngine.cpp +++ b/Libraries/LibHTML/CSS/SelectorEngine.cpp @@ -1,6 +1,7 @@ #include #include #include +#include namespace SelectorEngine { @@ -35,6 +36,10 @@ bool matches(const Selector::SimpleSelector& component, const Element& element) if (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; + break; } switch (component.attribute_match_type) { diff --git a/Libraries/LibHTML/Parser/CSSParser.cpp b/Libraries/LibHTML/Parser/CSSParser.cpp index 6cfc93c75a3..92eeaeebbcb 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 == "empty") + simple_selector.pseudo_class = Selector::SimpleSelector::PseudoClass::Empty; } return simple_selector;