LibWeb/CSS: Correct matching of calc() against <number-percentage>

This seems to have vanished from the spec, but in any case, we still
need it. Without this change we erroneously thought that calculations
that match <percentage> did not match <number-percentage>.
This commit is contained in:
Sam Atkins 2024-10-30 17:12:42 +00:00 committed by Alexander Kalenik
parent 797b0d0f43
commit 760943d584
Notes: github-actions[bot] 2024-10-30 19:59:14 +00:00
3 changed files with 18 additions and 3 deletions
Tests/LibWeb/Text
Userland/Libraries/LibWeb/CSS

View file

@ -0,0 +1 @@
rgb(88, 101, 242)

View file

@ -0,0 +1,13 @@
<!doctype html>
<script src="../include.js"></script>
<style>
#target {
background-color: hsl(235 calc(1 * 85.6%) 64.7% / 1);
}
</style>
<div id="target">Hello</div>
<script>
test(() => {
println(getComputedStyle(document.getElementById("target"))["background-color"]);
});
</script>

View file

@ -350,7 +350,7 @@ bool CSSNumericType::matches_percentage() const
auto base_type = static_cast<BaseType>(i);
auto type_exponent = exponent(base_type);
if (base_type == BaseType::Percent) {
if (!type_exponent.has_value() || type_exponent == 0)
if (type_exponent != 1)
return false;
} else {
if (type_exponent.has_value() && type_exponent != 0)
@ -409,8 +409,9 @@ bool CSSNumericType::matches_number_percentage() const
auto base_type = static_cast<BaseType>(i);
auto type_exponent = exponent(base_type);
if (base_type == BaseType::Percent && type_exponent.has_value() && type_exponent != 0 && type_exponent != 1) {
return false;
if (base_type == BaseType::Percent) {
if (type_exponent.has_value() && type_exponent != 0 && type_exponent != 1)
return false;
} else if (type_exponent.has_value() && type_exponent != 0) {
return false;
}