diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-12-16 19:34:52 +0100 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-12-16 19:34:52 +0100 |
commit | c1474e594ebb71085782f6c10b310335d9b1b61a (patch) | |
tree | 02cb8e6a03ba7509d2f4d7654fef6f53fee20dee /Libraries | |
parent | 870df4a8c615282abe0c9fedaf9b33de641be184 (diff) | |
download | serenity-c1474e594ebb71085782f6c10b310335d9b1b61a.zip |
LibHTML: Support the :first-child and :last-child pseudo classes
Diffstat (limited to 'Libraries')
-rw-r--r-- | Libraries/LibHTML/CSS/Selector.h | 2 | ||||
-rw-r--r-- | Libraries/LibHTML/CSS/SelectorEngine.cpp | 8 | ||||
-rw-r--r-- | Libraries/LibHTML/Parser/CSSParser.cpp | 4 |
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; |