From 6bf107fc161d24b0fcf7937be255ffa9e0779b96 Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Wed, 13 Sep 2023 17:39:05 +0100 Subject: [PATCH] LibWeb: Implement the :open and :closed pseudo-classes These apply to any elements that have some kind of open/closed state. The spec suggests `
`, ``, and `. + // There may be others we want to treat as open or closed. + if (is(element) || is(element)) + return open == element.has_attribute(HTML::AttributeNames::open); + if (is(element)) + return open == static_cast(element).is_open(); + + return false; +} + static inline bool matches_pseudo_class(CSS::Selector::SimpleSelector::PseudoClassSelector const& pseudo_class, Optional style_sheet_for_rule, DOM::Element const& element, JS::GCPtr scope) { switch (pseudo_class.type) { @@ -509,6 +529,9 @@ static inline bool matches_pseudo_class(CSS::Selector::SimpleSelector::PseudoCla // - FIXME: textarea elements that have a placeholder attribute whose value is currently being presented to the user. return false; } + case CSS::PseudoClass::Open: + case CSS::PseudoClass::Closed: + return matches_open_state_pseudo_class(element, pseudo_class.type == CSS::PseudoClass::Open); } return false;