Skip to content

Commit 06eb4a7

Browse files
AtkinsSJawesomekling
authored andcommitted
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.
1 parent 1837e94 commit 06eb4a7

File tree

3 files changed

+25
-12
lines changed

3 files changed

+25
-12
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Viewport <#document> at (0,0) content-size 800x600 children: not-inline
2+
BlockContainer <html> at (0,0) content-size 800x600 [BFC] children: not-inline
3+
BlockContainer <body> at (8,8) content-size 784x120 children: not-inline
4+
BlockContainer <div> at (18,18) content-size 100x100 children: not-inline
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<style>
2+
div {
3+
width: 100px;
4+
height: 100px;
5+
border: solid black;
6+
border-width: calc(10px);
7+
}
8+
</style><div></div>

Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7791,40 +7791,41 @@ ErrorOr<Parser::PropertyAndValue> Parser::parse_css_value_for_properties(Readonl
77917791
if (auto maybe_dynamic = TRY(parse_dynamic_value(peek_token)); maybe_dynamic && maybe_dynamic->is_calculated()) {
77927792
(void)tokens.next_token();
77937793
auto& calculated = maybe_dynamic->as_calculated();
7794-
if (calculated.resolves_to_angle_percentage()) {
7795-
if (auto property = any_property_accepts_type_percentage(property_ids, ValueType::Angle); property.has_value())
7794+
// This is a bit sensitive to ordering: `<foo>` and `<percentage>` have to be checked before `<foo-percentage>`.
7795+
if (calculated.resolves_to_percentage()) {
7796+
if (auto property = any_property_accepts_type(property_ids, ValueType::Percentage); property.has_value())
77967797
return PropertyAndValue { *property, calculated };
77977798
} else if (calculated.resolves_to_angle()) {
77987799
if (auto property = any_property_accepts_type(property_ids, ValueType::Angle); property.has_value())
77997800
return PropertyAndValue { *property, calculated };
7800-
} else if (calculated.resolves_to_frequency_percentage()) {
7801-
if (auto property = any_property_accepts_type_percentage(property_ids, ValueType::Frequency); property.has_value())
7801+
} else if (calculated.resolves_to_angle_percentage()) {
7802+
if (auto property = any_property_accepts_type_percentage(property_ids, ValueType::Angle); property.has_value())
78027803
return PropertyAndValue { *property, calculated };
78037804
} else if (calculated.resolves_to_frequency()) {
78047805
if (auto property = any_property_accepts_type(property_ids, ValueType::Frequency); property.has_value())
78057806
return PropertyAndValue { *property, calculated };
7806-
} else if (calculated.resolves_to_number_percentage()) {
7807-
if (auto property = any_property_accepts_type_percentage(property_ids, ValueType::Number); property.has_value())
7807+
} else if (calculated.resolves_to_frequency_percentage()) {
7808+
if (auto property = any_property_accepts_type_percentage(property_ids, ValueType::Frequency); property.has_value())
78087809
return PropertyAndValue { *property, calculated };
78097810
} else if (calculated.resolves_to_number()) {
78107811
if (property_accepts_numeric) {
78117812
auto property_or_resolved = property_accepting_integer.value_or_lazy_evaluated([property_accepting_number]() { return property_accepting_number.value(); });
78127813
return PropertyAndValue { property_or_resolved, calculated };
78137814
}
7814-
} else if (calculated.resolves_to_length_percentage()) {
7815-
if (auto property = any_property_accepts_type_percentage(property_ids, ValueType::Length); property.has_value())
7815+
} else if (calculated.resolves_to_number_percentage()) {
7816+
if (auto property = any_property_accepts_type_percentage(property_ids, ValueType::Number); property.has_value())
78167817
return PropertyAndValue { *property, calculated };
78177818
} else if (calculated.resolves_to_length()) {
78187819
if (auto property = any_property_accepts_type(property_ids, ValueType::Length); property.has_value())
78197820
return PropertyAndValue { *property, calculated };
7820-
} else if (calculated.resolves_to_time_percentage()) {
7821-
if (auto property = any_property_accepts_type_percentage(property_ids, ValueType::Time); property.has_value())
7821+
} else if (calculated.resolves_to_length_percentage()) {
7822+
if (auto property = any_property_accepts_type_percentage(property_ids, ValueType::Length); property.has_value())
78227823
return PropertyAndValue { *property, calculated };
78237824
} else if (calculated.resolves_to_time()) {
78247825
if (auto property = any_property_accepts_type(property_ids, ValueType::Time); property.has_value())
78257826
return PropertyAndValue { *property, calculated };
7826-
} else if (calculated.resolves_to_percentage()) {
7827-
if (auto property = any_property_accepts_type(property_ids, ValueType::Percentage); property.has_value())
7827+
} else if (calculated.resolves_to_time_percentage()) {
7828+
if (auto property = any_property_accepts_type_percentage(property_ids, ValueType::Time); property.has_value())
78287829
return PropertyAndValue { *property, calculated };
78297830
}
78307831
}

0 commit comments

Comments
 (0)