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:
parent
1837e94ba4
commit
06eb4a7557
Notes:
sideshowbarker
2024-07-18 22:57:59 +09:00
Author: https://github.com/AtkinsSJ Commit: https://github.com/SerenityOS/serenity/commit/06eb4a7557 Pull-request: https://github.com/SerenityOS/serenity/pull/20261
3 changed files with 25 additions and 12 deletions
4
Tests/LibWeb/Layout/expected/css-calc-border-width.txt
Normal file
4
Tests/LibWeb/Layout/expected/css-calc-border-width.txt
Normal 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
|
8
Tests/LibWeb/Layout/input/css-calc-border-width.html
Normal file
8
Tests/LibWeb/Layout/input/css-calc-border-width.html
Normal file
|
@ -0,0 +1,8 @@
|
|||
<style>
|
||||
div {
|
||||
width: 100px;
|
||||
height: 100px;
|
||||
border: solid black;
|
||||
border-width: calc(10px);
|
||||
}
|
||||
</style><div></div>
|
|
@ -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 };
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue