summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Wilde <lukew@serenityos.org>2023-03-29 23:48:40 +0100
committerAndreas Kling <kling@serenityos.org>2023-04-06 11:36:56 +0200
commita744ae79ff6db5dee5287127e5ac15471f3e955d (patch)
tree41942a40555b7bbdbe3ed0fc0872bed6ba44a8c7
parent6ebdb9f824dc772b43cbb1a148dd681c63e69fb4 (diff)
downloadserenity-a744ae79ff6db5dee5287127e5ac15471f3e955d.zip
LibWeb: Implement the `:defined` pseudo class
This selects an element if it is either a built-in element, or an upgraded custom element.
-rw-r--r--Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp2
-rw-r--r--Userland/Libraries/LibWeb/CSS/Selector.cpp1
-rw-r--r--Userland/Libraries/LibWeb/CSS/Selector.h3
-rw-r--r--Userland/Libraries/LibWeb/CSS/SelectorEngine.cpp2
-rw-r--r--Userland/Libraries/LibWeb/Dump.cpp3
5 files changed, 11 insertions, 0 deletions
diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp
index d513f66b17..10923271be 100644
--- a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp
+++ b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp
@@ -494,6 +494,8 @@ Parser::ParseErrorOr<Selector::SimpleSelector> Parser::parse_pseudo_simple_selec
return make_pseudo_class_selector(Selector::SimpleSelector::PseudoClass::Type::Checked);
if (pseudo_name.equals_ignoring_ascii_case("indeterminate"sv))
return make_pseudo_class_selector(Selector::SimpleSelector::PseudoClass::Type::Indeterminate);
+ if (pseudo_name.equals_ignoring_ascii_case("defined"sv))
+ return make_pseudo_class_selector(Selector::SimpleSelector::PseudoClass::Type::Defined);
if (pseudo_name.equals_ignoring_ascii_case("disabled"sv))
return make_pseudo_class_selector(Selector::SimpleSelector::PseudoClass::Type::Disabled);
if (pseudo_name.equals_ignoring_ascii_case("empty"sv))
diff --git a/Userland/Libraries/LibWeb/CSS/Selector.cpp b/Userland/Libraries/LibWeb/CSS/Selector.cpp
index d0c6636218..9fb5d880c7 100644
--- a/Userland/Libraries/LibWeb/CSS/Selector.cpp
+++ b/Userland/Libraries/LibWeb/CSS/Selector.cpp
@@ -228,6 +228,7 @@ ErrorOr<String> Selector::SimpleSelector::serialize() const
case Selector::SimpleSelector::PseudoClass::Type::Checked:
case Selector::SimpleSelector::PseudoClass::Type::Active:
case Selector::SimpleSelector::PseudoClass::Type::Scope:
+ case Selector::SimpleSelector::PseudoClass::Type::Defined:
// If the pseudo-class does not accept arguments append ":" (U+003A), followed by the name of the pseudo-class, to s.
TRY(s.try_append(':'));
TRY(s.try_append(pseudo_class_name(pseudo_class.type)));
diff --git a/Userland/Libraries/LibWeb/CSS/Selector.h b/Userland/Libraries/LibWeb/CSS/Selector.h
index eef67017ee..bd20ad111f 100644
--- a/Userland/Libraries/LibWeb/CSS/Selector.h
+++ b/Userland/Libraries/LibWeb/CSS/Selector.h
@@ -112,6 +112,7 @@ public:
Active,
Lang,
Scope,
+ Defined,
};
Type type;
@@ -295,6 +296,8 @@ constexpr StringView pseudo_class_name(Selector::SimpleSelector::PseudoClass::Ty
return "lang"sv;
case Selector::SimpleSelector::PseudoClass::Type::Scope:
return "scope"sv;
+ case Selector::SimpleSelector::PseudoClass::Type::Defined:
+ return "defined"sv;
}
VERIFY_NOT_REACHED();
}
diff --git a/Userland/Libraries/LibWeb/CSS/SelectorEngine.cpp b/Userland/Libraries/LibWeb/CSS/SelectorEngine.cpp
index 8c8505c2c9..6881a403d9 100644
--- a/Userland/Libraries/LibWeb/CSS/SelectorEngine.cpp
+++ b/Userland/Libraries/LibWeb/CSS/SelectorEngine.cpp
@@ -268,6 +268,8 @@ static inline bool matches_pseudo_class(CSS::Selector::SimpleSelector::PseudoCla
return matches_checked_pseudo_class(element);
case CSS::Selector::SimpleSelector::PseudoClass::Type::Indeterminate:
return matches_indeterminate_pseudo_class(element);
+ case CSS::Selector::SimpleSelector::PseudoClass::Type::Defined:
+ return element.is_defined();
case CSS::Selector::SimpleSelector::PseudoClass::Type::Is:
case CSS::Selector::SimpleSelector::PseudoClass::Type::Where:
for (auto& selector : pseudo_class.argument_selector_list) {
diff --git a/Userland/Libraries/LibWeb/Dump.cpp b/Userland/Libraries/LibWeb/Dump.cpp
index 147e0491c1..56b00f4546 100644
--- a/Userland/Libraries/LibWeb/Dump.cpp
+++ b/Userland/Libraries/LibWeb/Dump.cpp
@@ -459,6 +459,9 @@ void dump_selector(StringBuilder& builder, CSS::Selector const& selector)
case CSS::Selector::SimpleSelector::PseudoClass::Type::Scope:
pseudo_class_description = "Scope";
break;
+ case CSS::Selector::SimpleSelector::PseudoClass::Type::Defined:
+ pseudo_class_description = "Defined";
+ break;
}
builder.appendff(" pseudo_class={}", pseudo_class_description);