diff options
author | Andreas Kling <kling@serenityos.org> | 2022-11-02 20:26:11 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-11-02 22:42:48 +0100 |
commit | 43888b848c169a0672fa712a4485af034754effe (patch) | |
tree | 1d6bf49632e27a0cc1dbee67b9283378a203c400 /Userland/Libraries/LibWeb/CSS/StyleComputer.cpp | |
parent | 8869dec5fd7d776d25d451c54a603af497178821 (diff) | |
download | serenity-43888b848c169a0672fa712a4485af034754effe.zip |
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.
Diffstat (limited to 'Userland/Libraries/LibWeb/CSS/StyleComputer.cpp')
-rw-r--r-- | Userland/Libraries/LibWeb/CSS/StyleComputer.cpp | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp b/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp index c3ee482b1e..e870817ec5 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp +++ b/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp @@ -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() }; |