1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 03:07:36 +00:00

LibHTML: Support the :only-child pseudo class

This commit is contained in:
Andreas Kling 2019-12-16 19:52:11 +01:00
parent 085cafd80a
commit 91ba94fbd4
5 changed files with 36 additions and 0 deletions

View file

@ -22,6 +22,7 @@ public:
Hover,
FirstChild,
LastChild,
OnlyChild,
Empty,
};
PseudoClass pseudo_class { PseudoClass::None };

View file

@ -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>() || element.first_child_of_type<Text>())
return false;

View file

@ -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;
}