1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 07:08:10 +00:00

LibWeb: Resolve unresolved CSS calc() values in StyleComputer

When mixing calc() and var(), we're forced to delay resolving them until
we're in StyleComputer. Previously we'd just skip over them.

This patch handles calc() in the same pass as attr(). We reparse the
calc() value after var() expansion, and then try to resolve it to a
constant value if possible. If it's not possible, we leave the calc()
where it is, and maybe layout can figure it out later.

Note that I've only implemented resolution to integer and percentage in
this commit. There are more things a calc() could resolve to, and we
should implement those as well.
This commit is contained in:
Andreas Kling 2022-11-02 20:26:11 +01:00
parent 8869dec5fd
commit 43888b848c

View file

@ -682,6 +682,27 @@ bool StyleComputer::expand_unresolved_values(DOM::Element& element, StringView p
return false;
}
if (value.function().name().equals_ignoring_case("calc"sv)) {
auto const& calc_function = value.function();
if (auto calc_value = CSS::Parser::Parser::parse_calculated_value({}, Parser::ParsingContext { document() }, calc_function.values())) {
switch (calc_value->resolved_type()) {
case CalculatedStyleValue::ResolvedType::Integer: {
auto resolved_value = calc_value->resolve_integer();
dest.empend(Parser::Token::create_number(resolved_value.value()));
continue;
}
case CalculatedStyleValue::ResolvedType::Percentage: {
auto resolved_value = calc_value->resolve_percentage();
dest.empend(Parser::Token::create_percentage(resolved_value.value().value()));
continue;
}
default:
dbgln("FIXME: Unimplement calc() expansion in StyleComputer");
break;
}
}
}
auto const& source_function = value.function();
Vector<Parser::ComponentValue> function_values;
Parser::TokenStream source_function_contents { source_function.values() };