mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-06 08:10:02 +00:00
LibWeb/CSS: Add custom-ident blacklists to Properties.json
These excluded values use a similar notation to the ranges for numeric types: `![foo,bar,baz]` to exclude `foo`, `bar`, and `baz`.
This commit is contained in:
parent
c6c607884b
commit
c729c3fcee
Notes:
github-actions[bot]
2025-02-26 11:24:14 +00:00
Author: https://github.com/AtkinsSJ
Commit: c729c3fcee
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3684
Reviewed-by: https://github.com/trflynn89
3 changed files with 64 additions and 7 deletions
|
@ -250,6 +250,7 @@ enum class ValueType {
|
|||
bool property_accepts_type(PropertyID, ValueType);
|
||||
bool property_accepts_keyword(PropertyID, Keyword);
|
||||
Optional<ValueType> property_resolves_percentages_relative_to(PropertyID);
|
||||
Vector<StringView> property_custom_ident_blacklist(PropertyID);
|
||||
|
||||
// These perform range-checking, but are also safe to call with properties that don't accept that type. (They'll just return false.)
|
||||
bool property_accepts_angle(PropertyID, Angle const&);
|
||||
|
@ -938,6 +939,53 @@ Optional<ValueType> property_resolves_percentages_relative_to(PropertyID propert
|
|||
}
|
||||
}
|
||||
|
||||
Vector<StringView> property_custom_ident_blacklist(PropertyID property_id)
|
||||
{
|
||||
switch (property_id) {
|
||||
)~~~");
|
||||
|
||||
properties.for_each_member([&](auto& name, auto& value) {
|
||||
VERIFY(value.is_object());
|
||||
auto& object = value.as_object();
|
||||
if (is_legacy_alias(object))
|
||||
return;
|
||||
|
||||
// We only have a custom-ident blacklist if we accept custom idents!
|
||||
if (auto maybe_valid_types = object.get_array("valid-types"sv); maybe_valid_types.has_value() && !maybe_valid_types->is_empty()) {
|
||||
auto& valid_types = maybe_valid_types.value();
|
||||
for (auto const& valid_type : valid_types.values()) {
|
||||
auto type_and_parameters = MUST(valid_type.as_string().split(' '));
|
||||
if (type_and_parameters.first() != "custom-ident"sv || type_and_parameters.size() == 1)
|
||||
continue;
|
||||
VERIFY(type_and_parameters.size() == 2);
|
||||
|
||||
auto parameters_string = type_and_parameters[1].bytes_as_string_view();
|
||||
VERIFY(parameters_string.starts_with("!["sv) && parameters_string.ends_with(']'));
|
||||
auto blacklisted_keywords = parameters_string.substring_view(2, parameters_string.length() - 3).split_view(',');
|
||||
|
||||
auto property_generator = generator.fork();
|
||||
property_generator.set("property_name:titlecase", title_casify(name));
|
||||
property_generator.append(R"~~~(
|
||||
case PropertyID::@property_name:titlecase@:
|
||||
return Vector { )~~~");
|
||||
for (auto const& keyword : blacklisted_keywords) {
|
||||
auto value_generator = property_generator.fork();
|
||||
value_generator.set("keyword", keyword);
|
||||
|
||||
value_generator.append("\"@keyword@\"sv, ");
|
||||
}
|
||||
|
||||
property_generator.appendln("};");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
generator.append(R"~~~(
|
||||
default:
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
size_t property_maximum_value_count(PropertyID property_id)
|
||||
{
|
||||
switch (property_id) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue