mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-05-30 23:12:56 +00:00
LibWeb/CSS: Handle calculated integers when expanding unresolved values
In order to know whether `calc(2.5)` is a number or an integer, we have to see what the property will accept. So, add that knowledge to `Parser::expand_unresolved_values()`. This makes `counter-increment: foo calc(2 * var(--n));` work correctly, in a test I'm working on.
This commit is contained in:
parent
aeed4921c4
commit
69d064697a
Notes:
github-actions[bot]
2024-10-16 06:35:11 +00:00
Author: https://github.com/AtkinsSJ
Commit: 69d064697a
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/1788
Reviewed-by: https://github.com/tcl3
2 changed files with 43 additions and 33 deletions
|
@ -8802,6 +8802,8 @@ bool Parser::expand_variables(DOM::Element& element, Optional<Selector::PseudoEl
|
|||
|
||||
bool Parser::expand_unresolved_values(DOM::Element& element, FlyString const& property_name, TokenStream<ComponentValue>& source, Vector<ComponentValue>& dest)
|
||||
{
|
||||
auto property = property_id_from_string(property_name);
|
||||
|
||||
while (source.has_next_token()) {
|
||||
auto const& value = source.consume_a_token();
|
||||
if (value.is_function()) {
|
||||
|
@ -8811,37 +8813,45 @@ bool Parser::expand_unresolved_values(DOM::Element& element, FlyString const& pr
|
|||
continue;
|
||||
}
|
||||
|
||||
if (auto maybe_calc_value = parse_calculated_value(value); maybe_calc_value && maybe_calc_value->is_math()) {
|
||||
auto& calc_value = maybe_calc_value->as_math();
|
||||
if (calc_value.resolves_to_angle()) {
|
||||
auto resolved_value = calc_value.resolve_angle();
|
||||
dest.empend(Token::create_dimension(resolved_value->to_degrees(), "deg"_fly_string));
|
||||
continue;
|
||||
}
|
||||
if (calc_value.resolves_to_frequency()) {
|
||||
auto resolved_value = calc_value.resolve_frequency();
|
||||
dest.empend(Token::create_dimension(resolved_value->to_hertz(), "hz"_fly_string));
|
||||
continue;
|
||||
}
|
||||
if (calc_value.resolves_to_length()) {
|
||||
// FIXME: In order to resolve lengths, we need to know the font metrics in case a font-relative unit
|
||||
// is used. So... we can't do that until style is computed?
|
||||
// This might be easier once we have calc-simplification implemented.
|
||||
}
|
||||
if (calc_value.resolves_to_percentage()) {
|
||||
auto resolved_value = calc_value.resolve_percentage();
|
||||
dest.empend(Token::create_percentage(resolved_value.value().value()));
|
||||
continue;
|
||||
}
|
||||
if (calc_value.resolves_to_time()) {
|
||||
auto resolved_value = calc_value.resolve_time();
|
||||
dest.empend(Token::create_dimension(resolved_value->to_seconds(), "s"_fly_string));
|
||||
continue;
|
||||
}
|
||||
if (calc_value.resolves_to_number()) {
|
||||
auto resolved_value = calc_value.resolve_number();
|
||||
dest.empend(Token::create_number(resolved_value.value()));
|
||||
continue;
|
||||
if (property.has_value()) {
|
||||
if (auto maybe_calc_value = parse_calculated_value(value); maybe_calc_value && maybe_calc_value->is_math()) {
|
||||
// FIXME: Run the actual simplification algorithm
|
||||
auto& calc_value = maybe_calc_value->as_math();
|
||||
if (property_accepts_type(*property, ValueType::Angle) && calc_value.resolves_to_angle()) {
|
||||
auto resolved_value = calc_value.resolve_angle();
|
||||
dest.empend(Token::create_dimension(resolved_value->to_degrees(), "deg"_fly_string));
|
||||
continue;
|
||||
}
|
||||
if (property_accepts_type(*property, ValueType::Frequency) && calc_value.resolves_to_frequency()) {
|
||||
auto resolved_value = calc_value.resolve_frequency();
|
||||
dest.empend(Token::create_dimension(resolved_value->to_hertz(), "hz"_fly_string));
|
||||
continue;
|
||||
}
|
||||
if (property_accepts_type(*property, ValueType::Length) && calc_value.resolves_to_length()) {
|
||||
// FIXME: In order to resolve lengths, we need to know the font metrics in case a font-relative unit
|
||||
// is used. So... we can't do that until style is computed?
|
||||
// This might be easier once we have calc-simplification implemented.
|
||||
}
|
||||
if (property_accepts_type(*property, ValueType::Percentage) && calc_value.resolves_to_percentage()) {
|
||||
auto resolved_value = calc_value.resolve_percentage();
|
||||
dest.empend(Token::create_percentage(resolved_value.value().value()));
|
||||
continue;
|
||||
}
|
||||
if (property_accepts_type(*property, ValueType::Time) && calc_value.resolves_to_time()) {
|
||||
auto resolved_value = calc_value.resolve_time();
|
||||
dest.empend(Token::create_dimension(resolved_value->to_seconds(), "s"_fly_string));
|
||||
continue;
|
||||
}
|
||||
if (property_accepts_type(*property, ValueType::Number) && calc_value.resolves_to_number()) {
|
||||
auto resolved_value = calc_value.resolve_number();
|
||||
dest.empend(Token::create_number(resolved_value.value(), Number::Type::Number));
|
||||
continue;
|
||||
}
|
||||
if (property_accepts_type(*property, ValueType::Integer) && calc_value.resolves_to_number()) {
|
||||
auto resolved_value = calc_value.resolve_integer();
|
||||
dest.empend(Token::create_number(resolved_value.value(), Number::Type::Integer));
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue