LibWeb: Match math function values to properties in correct order

If a math function resolves to `<length>` or `<percentage>`, then it
will by definition also resolve to `<length-percentage>`. (Same for any
other basic types.) Since we were checking `<length-percentage>` first
and then bailing if no given properties could accept that, math
functions would always fail to match a property that just accepts a non
`-percentage` type.
This commit is contained in:
Sam Atkins 2023-07-30 12:33:33 +01:00 committed by Andreas Kling
parent 1837e94ba4
commit 06eb4a7557
Notes: sideshowbarker 2024-07-18 22:57:59 +09:00
3 changed files with 25 additions and 12 deletions

View File

@ -0,0 +1,4 @@
Viewport <#document> at (0,0) content-size 800x600 children: not-inline
BlockContainer <html> at (0,0) content-size 800x600 [BFC] children: not-inline
BlockContainer <body> at (8,8) content-size 784x120 children: not-inline
BlockContainer <div> at (18,18) content-size 100x100 children: not-inline

View File

@ -0,0 +1,8 @@
<style>
div {
width: 100px;
height: 100px;
border: solid black;
border-width: calc(10px);
}
</style><div></div>

View File

@ -7791,40 +7791,41 @@ ErrorOr<Parser::PropertyAndValue> Parser::parse_css_value_for_properties(Readonl
if (auto maybe_dynamic = TRY(parse_dynamic_value(peek_token)); maybe_dynamic && maybe_dynamic->is_calculated()) {
(void)tokens.next_token();
auto& calculated = maybe_dynamic->as_calculated();
if (calculated.resolves_to_angle_percentage()) {
if (auto property = any_property_accepts_type_percentage(property_ids, ValueType::Angle); property.has_value())
// This is a bit sensitive to ordering: `<foo>` and `<percentage>` have to be checked before `<foo-percentage>`.
if (calculated.resolves_to_percentage()) {
if (auto property = any_property_accepts_type(property_ids, ValueType::Percentage); property.has_value())
return PropertyAndValue { *property, calculated };
} else if (calculated.resolves_to_angle()) {
if (auto property = any_property_accepts_type(property_ids, ValueType::Angle); property.has_value())
return PropertyAndValue { *property, calculated };
} else if (calculated.resolves_to_frequency_percentage()) {
if (auto property = any_property_accepts_type_percentage(property_ids, ValueType::Frequency); property.has_value())
} else if (calculated.resolves_to_angle_percentage()) {
if (auto property = any_property_accepts_type_percentage(property_ids, ValueType::Angle); property.has_value())
return PropertyAndValue { *property, calculated };
} else if (calculated.resolves_to_frequency()) {
if (auto property = any_property_accepts_type(property_ids, ValueType::Frequency); property.has_value())
return PropertyAndValue { *property, calculated };
} else if (calculated.resolves_to_number_percentage()) {
if (auto property = any_property_accepts_type_percentage(property_ids, ValueType::Number); property.has_value())
} else if (calculated.resolves_to_frequency_percentage()) {
if (auto property = any_property_accepts_type_percentage(property_ids, ValueType::Frequency); property.has_value())
return PropertyAndValue { *property, calculated };
} else if (calculated.resolves_to_number()) {
if (property_accepts_numeric) {
auto property_or_resolved = property_accepting_integer.value_or_lazy_evaluated([property_accepting_number]() { return property_accepting_number.value(); });
return PropertyAndValue { property_or_resolved, calculated };
}
} else if (calculated.resolves_to_length_percentage()) {
if (auto property = any_property_accepts_type_percentage(property_ids, ValueType::Length); property.has_value())
} else if (calculated.resolves_to_number_percentage()) {
if (auto property = any_property_accepts_type_percentage(property_ids, ValueType::Number); property.has_value())
return PropertyAndValue { *property, calculated };
} else if (calculated.resolves_to_length()) {
if (auto property = any_property_accepts_type(property_ids, ValueType::Length); property.has_value())
return PropertyAndValue { *property, calculated };
} else if (calculated.resolves_to_time_percentage()) {
if (auto property = any_property_accepts_type_percentage(property_ids, ValueType::Time); property.has_value())
} else if (calculated.resolves_to_length_percentage()) {
if (auto property = any_property_accepts_type_percentage(property_ids, ValueType::Length); property.has_value())
return PropertyAndValue { *property, calculated };
} else if (calculated.resolves_to_time()) {
if (auto property = any_property_accepts_type(property_ids, ValueType::Time); property.has_value())
return PropertyAndValue { *property, calculated };
} else if (calculated.resolves_to_percentage()) {
if (auto property = any_property_accepts_type(property_ids, ValueType::Percentage); property.has_value())
} else if (calculated.resolves_to_time_percentage()) {
if (auto property = any_property_accepts_type_percentage(property_ids, ValueType::Time); property.has_value())
return PropertyAndValue { *property, calculated };
}
}