1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 12:38:12 +00:00

LibWeb: Implement the :dir() selector pseudo-class

This commit is contained in:
Sam Atkins 2023-08-16 12:11:14 +01:00 committed by Andreas Kling
parent 5b125811f1
commit b8e694c0f2
4 changed files with 152 additions and 0 deletions

View file

@ -7,6 +7,7 @@
#include <LibWeb/CSS/Parser/Parser.h>
#include <LibWeb/CSS/SelectorEngine.h>
#include <LibWeb/CSS/ValueID.h>
#include <LibWeb/DOM/Document.h>
#include <LibWeb/DOM/Element.h>
#include <LibWeb/DOM/Text.h>
@ -428,6 +429,19 @@ static inline bool matches_pseudo_class(CSS::Selector::SimpleSelector::PseudoCla
}
case CSS::PseudoClass::Target:
return element.is_target();
case CSS::PseudoClass::Dir: {
// "Values other than ltr and rtl are not invalid, but do not match anything."
// - https://www.w3.org/TR/selectors-4/#the-dir-pseudo
if (!first_is_one_of(pseudo_class.identifier, CSS::ValueID::Ltr, CSS::ValueID::Rtl))
return false;
switch (element.directionality()) {
case DOM::Element::Directionality::Ltr:
return pseudo_class.identifier == CSS::ValueID::Ltr;
case DOM::Element::Directionality::Rtl:
return pseudo_class.identifier == CSS::ValueID::Rtl;
}
VERIFY_NOT_REACHED();
}
}
return false;