From 3d10bf3ae748af33e9ad281e74829ebd8f8de7d7 Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Tue, 22 Aug 2023 15:55:46 +0100 Subject: [PATCH] LibWeb: Implement the `:target-within` pseudo-class selector As noted in a9620d8784465d0b58c65a08945ee6dd7e90f75c we don't currently set the target element so this does not function, so no tests. But it should work once we have a fleshed out Navigables implementation. :^) --- Userland/Libraries/LibWeb/CSS/PseudoClasses.json | 3 +++ Userland/Libraries/LibWeb/CSS/SelectorEngine.cpp | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/Userland/Libraries/LibWeb/CSS/PseudoClasses.json b/Userland/Libraries/LibWeb/CSS/PseudoClasses.json index 25f68d921d..c74a23fb2e 100644 --- a/Userland/Libraries/LibWeb/CSS/PseudoClasses.json +++ b/Userland/Libraries/LibWeb/CSS/PseudoClasses.json @@ -113,6 +113,9 @@ "target": { "argument": "" }, + "target-within": { + "argument": "" + }, "visited": { "argument": "" }, diff --git a/Userland/Libraries/LibWeb/CSS/SelectorEngine.cpp b/Userland/Libraries/LibWeb/CSS/SelectorEngine.cpp index e7a25e9d7a..1bbf994edc 100644 --- a/Userland/Libraries/LibWeb/CSS/SelectorEngine.cpp +++ b/Userland/Libraries/LibWeb/CSS/SelectorEngine.cpp @@ -446,6 +446,12 @@ static inline bool matches_pseudo_class(CSS::Selector::SimpleSelector::PseudoCla } case CSS::PseudoClass::Target: return element.is_target(); + case CSS::PseudoClass::TargetWithin: { + auto* target_element = element.document().target_element(); + if (!target_element) + return false; + return element.is_inclusive_ancestor_of(*target_element); + } 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