diff options
author | Linus Groh <mail@linusgroh.de> | 2020-05-13 22:38:12 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-05-14 08:49:51 +0200 |
commit | 7bfd24ca76e5f5832b1d1111ceae5fe839788d08 (patch) | |
tree | 6b4314b45c1f1804774497a3f1713f0f496c5c50 | |
parent | 2f29e6120389a0752e26d4033d64fbd76bcc88c9 (diff) | |
download | serenity-7bfd24ca76e5f5832b1d1111ceae5fe839788d08.zip |
LibWeb: Support the :root pseudo class
-rw-r--r-- | Base/home/anon/www/root.html | 14 | ||||
-rw-r--r-- | Base/home/anon/www/welcome.html | 1 | ||||
-rw-r--r-- | Libraries/LibWeb/CSS/Selector.h | 1 | ||||
-rw-r--r-- | Libraries/LibWeb/CSS/SelectorEngine.cpp | 4 | ||||
-rw-r--r-- | Libraries/LibWeb/Parser/CSSParser.cpp | 2 |
5 files changed, 22 insertions, 0 deletions
diff --git a/Base/home/anon/www/root.html b/Base/home/anon/www/root.html new file mode 100644 index 0000000000..331ee74880 --- /dev/null +++ b/Base/home/anon/www/root.html @@ -0,0 +1,14 @@ +<!DOCTYPE html> +<html> + <head> + <title>:root test</title> + <style> + :root { + background-color: red; + } + </style> + </head> + <body> + Background will be red. + </body> +</html> diff --git a/Base/home/anon/www/welcome.html b/Base/home/anon/www/welcome.html index 9ee1bac2c9..48f42c30df 100644 --- a/Base/home/anon/www/welcome.html +++ b/Base/home/anon/www/welcome.html @@ -50,6 +50,7 @@ span#ua { <li><a href="last-child.html">:last-child</a></li> <li><a href="only-child.html">:only-child</a></li> <li><a href="empty.html">:empty</a></li> + <li><a href="root.html">:root</a></li> <li><a href="form.html">form</a></li> <li><a href="borders.html">borders</a></li> <li><a href="css.html">css</a></li> diff --git a/Libraries/LibWeb/CSS/Selector.h b/Libraries/LibWeb/CSS/Selector.h index 3b6f7c1552..f1ff146582 100644 --- a/Libraries/LibWeb/CSS/Selector.h +++ b/Libraries/LibWeb/CSS/Selector.h @@ -53,6 +53,7 @@ public: LastChild, OnlyChild, Empty, + Root, }; PseudoClass pseudo_class { PseudoClass::None }; diff --git a/Libraries/LibWeb/CSS/SelectorEngine.cpp b/Libraries/LibWeb/CSS/SelectorEngine.cpp index e250896784..8b26beff74 100644 --- a/Libraries/LibWeb/CSS/SelectorEngine.cpp +++ b/Libraries/LibWeb/CSS/SelectorEngine.cpp @@ -75,6 +75,10 @@ bool matches(const Selector::SimpleSelector& component, const Element& element) if (element.first_child_of_type<Element>() || element.first_child_of_type<Text>()) return false; break; + case Selector::SimpleSelector::PseudoClass::Root: + if (!element.is_html_element()) + return false; + break; } switch (component.attribute_match_type) { diff --git a/Libraries/LibWeb/Parser/CSSParser.cpp b/Libraries/LibWeb/Parser/CSSParser.cpp index 5af4284381..84d7160520 100644 --- a/Libraries/LibWeb/Parser/CSSParser.cpp +++ b/Libraries/LibWeb/Parser/CSSParser.cpp @@ -414,6 +414,8 @@ public: simple_selector.pseudo_class = Selector::SimpleSelector::PseudoClass::OnlyChild; else if (pseudo_name.equals_ignoring_case("empty")) simple_selector.pseudo_class = Selector::SimpleSelector::PseudoClass::Empty; + else if (pseudo_name.equals_ignoring_case("root")) + simple_selector.pseudo_class = Selector::SimpleSelector::PseudoClass::Root; } if (index == index_at_start) { |