From bbcc71fec42b991c638e0917be874c01107faf53 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Tue, 1 Dec 2020 15:40:20 +0100 Subject: [PATCH] LibWeb: Parse :before and :after pseudo-elements Note that this is the old CSS2 syntax, we don't support the CSS3 syntax just yet. Also we don't actually implement the pseudo-elements, this is really just to make the selectors distinct from the same ones without these pseudo-elements. --- Libraries/LibWeb/CSS/Parser/CSSParser.cpp | 6 ++++++ Libraries/LibWeb/CSS/Selector.h | 7 +++++++ Libraries/LibWeb/CSS/SelectorEngine.cpp | 8 ++++++++ 3 files changed, 21 insertions(+) diff --git a/Libraries/LibWeb/CSS/Parser/CSSParser.cpp b/Libraries/LibWeb/CSS/Parser/CSSParser.cpp index e5c024d768..ef1884e720 100644 --- a/Libraries/LibWeb/CSS/Parser/CSSParser.cpp +++ b/Libraries/LibWeb/CSS/Parser/CSSParser.cpp @@ -502,6 +502,7 @@ public: return CSS::Selector::SimpleSelector { type, CSS::Selector::SimpleSelector::PseudoClass::None, + CSS::Selector::SimpleSelector::PseudoElement::None, String(), CSS::Selector::SimpleSelector::AttributeMatchType::None, String(), @@ -537,6 +538,7 @@ public: CSS::Selector::SimpleSelector simple_selector { type, CSS::Selector::SimpleSelector::PseudoClass::None, + CSS::Selector::SimpleSelector::PseudoElement::None, value, CSS::Selector::SimpleSelector::AttributeMatchType::None, String(), @@ -639,6 +641,10 @@ 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("before")) + simple_selector.pseudo_element = CSS::Selector::SimpleSelector::PseudoElement::Before; + else if (pseudo_name.equals_ignoring_case("after")) + simple_selector.pseudo_element = CSS::Selector::SimpleSelector::PseudoElement::After; } if (index == index_at_start) { diff --git a/Libraries/LibWeb/CSS/Selector.h b/Libraries/LibWeb/CSS/Selector.h index 463aa013eb..d5dae94f98 100644 --- a/Libraries/LibWeb/CSS/Selector.h +++ b/Libraries/LibWeb/CSS/Selector.h @@ -57,6 +57,13 @@ public: }; PseudoClass pseudo_class { PseudoClass::None }; + enum class PseudoElement { + None, + Before, + After, + }; + PseudoElement pseudo_element { PseudoElement::None }; + FlyString value; enum class AttributeMatchType { diff --git a/Libraries/LibWeb/CSS/SelectorEngine.cpp b/Libraries/LibWeb/CSS/SelectorEngine.cpp index 942fccf0cd..306356ff57 100644 --- a/Libraries/LibWeb/CSS/SelectorEngine.cpp +++ b/Libraries/LibWeb/CSS/SelectorEngine.cpp @@ -44,6 +44,14 @@ static bool matches_hover_pseudo_class(const DOM::Element& element) static bool matches(const CSS::Selector::SimpleSelector& component, const DOM::Element& element) { + switch (component.pseudo_element) { + case CSS::Selector::SimpleSelector::PseudoElement::None: + break; + default: + // FIXME: Implement pseudo-elements. + return false; + } + switch (component.pseudo_class) { case CSS::Selector::SimpleSelector::PseudoClass::None: break;