1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-06-29 03:42:07 +00:00

LibWeb: Modernize handling of the CSS flex-basis property

Instead of a custom struct, use an AK::Variant for flex-basis.
A flex-basis is either `content` or a CSS size value, so we don't need
anything custom for that.

By using a CSS size, we also avoid having to convert in and out of size
in various places, simplifying the code.

This finally gets rid of the "Unsupported main size for flex-basis"
debug spam. :^)
This commit is contained in:
Andreas Kling 2023-06-21 19:39:07 +02:00
parent 8c980cf75b
commit 8648355783
6 changed files with 44 additions and 89 deletions

View file

@ -559,18 +559,14 @@ ErrorOr<RefPtr<StyleValue const>> ResolvedCSSStyleDeclaration::style_value_for_p
return NumberStyleValue::create(layout_node.computed_values().fill_opacity());
case PropertyID::FillRule:
return IdentifierStyleValue::create(to_value_id(layout_node.computed_values().fill_rule()));
case PropertyID::FlexBasis: {
switch (layout_node.computed_values().flex_basis().type) {
case FlexBasis::Content:
return IdentifierStyleValue::create(ValueID::Content);
case FlexBasis::LengthPercentage:
return style_value_for_length_percentage(*layout_node.computed_values().flex_basis().length_percentage);
case FlexBasis::Auto:
return IdentifierStyleValue::create(ValueID::Auto);
default:
VERIFY_NOT_REACHED();
}
break;
case PropertyID::FlexBasis:
return layout_node.computed_values().flex_basis().visit(
[](CSS::FlexBasisContent const&) -> ErrorOr<RefPtr<StyleValue const>> {
return IdentifierStyleValue::create(ValueID::Content);
},
[&](CSS::Size const& size) -> ErrorOr<RefPtr<StyleValue const>> {
return style_value_for_size(size);
});
case PropertyID::FlexDirection:
return IdentifierStyleValue::create(to_value_id(layout_node.computed_values().flex_direction()));
case PropertyID::FlexGrow:
@ -838,7 +834,6 @@ ErrorOr<RefPtr<StyleValue const>> ResolvedCSSStyleDeclaration::style_value_for_p
dbgln_if(LIBWEB_CSS_DEBUG, "FIXME: Computed style for the '{}' property was requested", string_from_property_id(property_id));
return nullptr;
}
}
}
Optional<StyleProperty> ResolvedCSSStyleDeclaration::property(PropertyID property_id) const