LibWeb: Add method to map from physical to logical property

This will be required in later commit.

The implementation could do with some optimization
This commit is contained in:
Callum Law
2026-03-15 23:18:29 +13:00
committed by Sam Atkins
parent d284ff96fe
commit d0a868dcfb
Notes: github-actions[bot] 2026-03-25 12:54:43 +00:00
3 changed files with 127 additions and 26 deletions

View File

@@ -325,6 +325,7 @@ struct LogicalAliasMappingContext {
};
bool property_is_logical_alias(PropertyID);
PropertyID map_logical_alias_to_physical_property(PropertyID logical_property_id, LogicalAliasMappingContext const&);
PropertyID map_physical_property_to_logical_alias(PropertyID physical_property_id, LogicalAliasMappingContext const&);
enum class LogicalPropertyGroup : @logical_property_group_underlying_type@ {
)~~~");
@@ -2000,6 +2001,40 @@ PropertyID map_logical_alias_to_physical_property(PropertyID property_id, Logica
)~~~");
generator.append(R"~~~(
PropertyID map_physical_property_to_logical_alias(PropertyID property_id, LogicalAliasMappingContext const& mapping_context)
{
switch (property_id) {
)~~~");
logical_property_groups.for_each_member([&](auto const&, JsonValue const& logical_property_group) {
auto const& physical_properties = logical_property_group.as_object().get_object("physical"sv).value();
auto const& logical_properties = logical_property_group.as_object().get_object("logical"sv).value();
physical_properties.for_each_member([&](auto&, auto& physical_property_name) {
auto property_generator = generator.fork();
property_generator.set("physical_property_name:titlecase", title_casify(physical_property_name.as_string()));
property_generator.appendln(" case PropertyID::@physical_property_name:titlecase@:");
// FIXME: Checking each logical property isn't very efficient, we should instead inverse the logic of map_logical_alias_to_physical_property
logical_properties.for_each_member([&](auto&, auto& logical_property_name) {
property_generator.set("logical_property_name:titlecase", title_casify(logical_property_name.as_string()));
property_generator.append(R"~~~(
if (map_logical_alias_to_physical_property(PropertyID::@logical_property_name:titlecase@, mapping_context) == property_id)
return PropertyID::@logical_property_name:titlecase@;
)~~~");
});
property_generator.appendln(" VERIFY_NOT_REACHED();");
});
});
generator.append(R"~~~(
default:
VERIFY(!logical_property_group_for_property(property_id).has_value() || property_is_logical_alias(property_id));
return property_id;
}
}
Optional<LogicalPropertyGroup> logical_property_group_for_property(PropertyID property_id)
{
switch(property_id) {
@@ -2013,14 +2048,10 @@ Optional<LogicalPropertyGroup> logical_property_group_for_property(PropertyID pr
mapping.as_object().get_object("physical"sv)->for_each_member([&](auto&, auto& physical_property) {
group_members.append(physical_property.as_string());
});
});
properties.for_each_member([&](auto& property_name, auto& value) {
if (auto maybe_logical_property_group = value.as_object().get_object("logical-alias-for"sv); maybe_logical_property_group.has_value()) {
auto group = maybe_logical_property_group.value().get_string("group"sv).value();
logical_property_group_members.get(group).value().append(property_name);
}
mapping.as_object().get_object("logical"sv)->for_each_member([&](auto&, auto& logical_property) {
group_members.append(logical_property.as_string());
});
});
for (auto const& logical_property_group : logical_property_group_members.keys()) {