mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 14:38:11 +00:00
LibWeb: Deduplicate calc-parsing code
We had `parse_calculated_value()` which parsed the contents of `calc()`, and `parse_dynamic_value()` which parsed any math function, both of which produce a CalculatedStyleValue, but return a plain StyleValue. This was confusing, so let's combine them together, and return a CalculatedStyleValue. This also makes the other math functions work in `StyleComputer::expand_unresolved_values()`.
This commit is contained in:
parent
7bc7f376fa
commit
68dae8ab46
3 changed files with 40 additions and 89 deletions
|
@ -1074,21 +1074,18 @@ bool StyleComputer::expand_unresolved_values(DOM::Element& element, StringView p
|
|||
return false;
|
||||
}
|
||||
|
||||
// FIXME: Handle all math functions.
|
||||
if (value.function().name().equals_ignoring_ascii_case("calc"sv)) {
|
||||
auto const& calc_function = value.function();
|
||||
if (auto calc_value = Parser::Parser::parse_calculated_value({}, Parser::ParsingContext { document() }, calc_function.values()).release_value_but_fixme_should_propagate_errors()) {
|
||||
if (calc_value->resolves_to_number()) {
|
||||
auto resolved_value = calc_value->resolve_number();
|
||||
dest.empend(Parser::Token::create_number(resolved_value.value()));
|
||||
continue;
|
||||
} else if (calc_value->resolves_to_percentage()) {
|
||||
auto resolved_value = calc_value->resolve_percentage();
|
||||
dest.empend(Parser::Token::create_percentage(resolved_value.value().value()));
|
||||
continue;
|
||||
} else {
|
||||
dbgln_if(LIBWEB_CSS_DEBUG, "FIXME: Unimplemented calc() expansion: {}", calc_value->to_string());
|
||||
}
|
||||
if (auto maybe_calc_value = Parser::Parser::parse_calculated_value({}, Parser::ParsingContext { document() }, value).release_value_but_fixme_should_propagate_errors(); maybe_calc_value && maybe_calc_value->is_calculated()) {
|
||||
auto& calc_value = maybe_calc_value->as_calculated();
|
||||
if (calc_value.resolves_to_number()) {
|
||||
auto resolved_value = calc_value.resolve_number();
|
||||
dest.empend(Parser::Token::create_number(resolved_value.value()));
|
||||
continue;
|
||||
} else if (calc_value.resolves_to_percentage()) {
|
||||
auto resolved_value = calc_value.resolve_percentage();
|
||||
dest.empend(Parser::Token::create_percentage(resolved_value.value().value()));
|
||||
continue;
|
||||
} else {
|
||||
dbgln_if(LIBWEB_CSS_DEBUG, "FIXME: Unimplemented calc() expansion: {}", calc_value.to_string());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue