mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 15:17:36 +00:00
LibWeb: Support the :first-of-type CSS selector :^)
This commit is contained in:
parent
4f690408af
commit
0eb9a9dd13
6 changed files with 26 additions and 0 deletions
|
@ -554,6 +554,8 @@ 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("first-of-type")) {
|
||||
simple_selector.pseudo_class = CSS::Selector::SimpleSelector::PseudoClass::FirstOfType;
|
||||
} 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")) {
|
||||
|
|
|
@ -54,6 +54,7 @@ public:
|
|||
OnlyChild,
|
||||
Empty,
|
||||
Root,
|
||||
FirstOfType,
|
||||
};
|
||||
PseudoClass pseudo_class { PseudoClass::None };
|
||||
|
||||
|
|
|
@ -90,6 +90,12 @@ static bool matches(const CSS::Selector::SimpleSelector& component, const DOM::E
|
|||
if (!is<HTML::HTMLElement>(element))
|
||||
return false;
|
||||
break;
|
||||
case CSS::Selector::SimpleSelector::PseudoClass::FirstOfType:
|
||||
for (auto* sibling = element.previous_element_sibling(); sibling; sibling = sibling->previous_element_sibling()) {
|
||||
if (sibling->tag_name() == element.tag_name())
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
switch (component.attribute_match_type) {
|
||||
|
|
|
@ -359,6 +359,9 @@ void dump_selector(StringBuilder& builder, const CSS::Selector& selector)
|
|||
case CSS::Selector::SimpleSelector::PseudoClass::Root:
|
||||
pseudo_class_description = "Root";
|
||||
break;
|
||||
case CSS::Selector::SimpleSelector::PseudoClass::FirstOfType:
|
||||
pseudo_class_description = "FirstOfType";
|
||||
break;
|
||||
case CSS::Selector::SimpleSelector::PseudoClass::Focus:
|
||||
pseudo_class_description = "Focus";
|
||||
break;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue