LibWeb: Add a way to test if a CSS::PropertyID is animatable

This commit is contained in:
Matthew Olsson 2023-10-31 19:33:58 -07:00 committed by Andreas Kling
parent edab67d5e8
commit 212a139292
Notes: sideshowbarker 2024-07-17 02:55:44 +09:00
2 changed files with 261 additions and 4 deletions

View File

@ -17,6 +17,7 @@ void replace_logical_aliases(JsonObject& properties);
ErrorOr<void> generate_header_file(JsonObject& properties, Core::File& file);
ErrorOr<void> generate_implementation_file(JsonObject& properties, Core::File& file);
void generate_bounds_checking_function(JsonObject& properties, SourceGenerator& parent_generator, StringView css_type_name, StringView type_name, Optional<StringView> default_unit_name = {}, Optional<StringView> value_getter = {});
bool is_animatable_property(JsonObject& properties, StringView property_name);
static bool type_name_is_enum(StringView type_name)
{
@ -160,6 +161,16 @@ enum class PropertyID {
generator.append(R"~~~(
};
enum class AnimationType {
Discrete,
ByComputedValue,
RepeatableList,
Custom,
None,
};
AnimationType animation_type_from_longhand_property(PropertyID);
bool is_animatable_property(PropertyID);
Optional<PropertyID> property_id_from_camel_case_string(StringView);
Optional<PropertyID> property_id_from_string(StringView);
StringView string_from_property_id(PropertyID);
@ -412,6 +423,71 @@ StringView string_from_property_id(PropertyID property_id) {
}
}
AnimationType animation_type_from_longhand_property(PropertyID property_id)
{
switch (property_id) {
)~~~");
properties.for_each_member([&](auto& name, auto& value) {
VERIFY(value.is_object());
auto member_generator = generator.fork();
member_generator.set("name:titlecase", title_casify(name));
// Shorthand properties should have already been expanded before calling into this function
if (value.as_object().has("longhands"sv)) {
if (value.as_object().has("animation-type"sv)) {
dbgln("Property '{}' with longhands cannot specify 'animation-type'", name);
VERIFY_NOT_REACHED();
}
member_generator.append(R"~~~(
case PropertyID::@name:titlecase@:
VERIFY_NOT_REACHED();
)~~~");
return;
}
if (!value.as_object().has("animation-type"sv)) {
dbgln("No animation-type specified for property '{}'", name);
VERIFY_NOT_REACHED();
}
auto animation_type = value.as_object().get_byte_string("animation-type"sv).value();
member_generator.set("value", title_casify(animation_type));
member_generator.append(R"~~~(
case PropertyID::@name:titlecase@:
return AnimationType::@value@;
)~~~");
});
generator.append(R"~~~(
default:
return AnimationType::None;
}
}
bool is_animatable_property(PropertyID property_id)
{
switch (property_id) {
)~~~");
properties.for_each_member([&](auto& name, auto& value) {
VERIFY(value.is_object());
if (is_animatable_property(properties, name)) {
auto member_generator = generator.fork();
member_generator.set("name:titlecase", title_casify(name));
member_generator.append(R"~~~(
case PropertyID::@name:titlecase@:
)~~~");
}
});
generator.append(R"~~~(
return true;
default:
return false;
}
}
bool is_inherited_property(PropertyID property_id)
{
switch (property_id) {
@ -860,3 +936,28 @@ Vector<PropertyID> longhands_for_shorthand(PropertyID property_id)
TRY(file.write_until_depleted(generator.as_string_view().bytes()));
return {};
}
bool is_animatable_property(JsonObject& properties, StringView property_name)
{
auto property = properties.get_object(property_name);
VERIFY(property.has_value());
if (auto animation_type = property.value().get_byte_string("animation-type"sv); animation_type.has_value()) {
return animation_type != "none";
}
if (!property.value().has("longhands"sv)) {
dbgln("Property '{}' must specify either 'animation-type' or 'longhands'"sv, property_name);
VERIFY_NOT_REACHED();
}
auto longhands = property.value().get_array("longhands"sv);
VERIFY(longhands.has_value());
for (auto const& subproperty_name : longhands->values()) {
VERIFY(subproperty_name.is_string());
if (is_animatable_property(properties, subproperty_name.as_string()))
return true;
}
return false;
}

File diff suppressed because it is too large Load Diff