From 15cee5cc15d453387db2e3403ce922da22e2befd Mon Sep 17 00:00:00 2001 From: Callum Law Date: Fri, 1 Aug 2025 15:07:07 +1200 Subject: [PATCH] LibWeb: Correctly round non-integer z-indexes Previously we would just cast to an int. Gains us 3 WPT tests. --- Libraries/LibWeb/CSS/ComputedProperties.cpp | 5 +- .../css-values/calc-z-index-fractions-001.txt | 11 ++++ .../calc-z-index-fractions-001.html | 59 +++++++++++++++++++ 3 files changed, 73 insertions(+), 2 deletions(-) create mode 100644 Tests/LibWeb/Text/expected/wpt-import/css/css-values/calc-z-index-fractions-001.txt create mode 100644 Tests/LibWeb/Text/input/wpt-import/css/css-values/calc-z-index-fractions-001.html diff --git a/Libraries/LibWeb/CSS/ComputedProperties.cpp b/Libraries/LibWeb/CSS/ComputedProperties.cpp index 97b2aeb4769..5cabdb8cfa3 100644 --- a/Libraries/LibWeb/CSS/ComputedProperties.cpp +++ b/Libraries/LibWeb/CSS/ComputedProperties.cpp @@ -338,7 +338,7 @@ Optional ComputedProperties::z_index() const return {}; // Clamp z-index to the range of a signed 32-bit integer for consistency with other engines. - auto clamp = [](auto number) -> int { + auto clamp = [](long number) -> int { if (number >= NumericLimits::max()) return NumericLimits::max(); if (number <= NumericLimits::min()) @@ -352,7 +352,8 @@ Optional ComputedProperties::z_index() const if (value.is_calculated()) { auto maybe_double = value.as_calculated().resolve_number_deprecated({}); if (maybe_double.has_value()) { - return clamp(maybe_double.value()); + // Round up on half + return clamp(floor(maybe_double.value() + 0.5f)); } } return {}; diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-values/calc-z-index-fractions-001.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-values/calc-z-index-fractions-001.txt new file mode 100644 index 00000000000..69b4c06e94d --- /dev/null +++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-values/calc-z-index-fractions-001.txt @@ -0,0 +1,11 @@ +Harness status: OK + +Found 6 tests + +6 Pass +Pass testing z-index: calc(2.5 / 2) +Pass testing z-index: calc(3 / 2) +Pass testing z-index: calc(3.5 / 2) +Pass testing z-index: calc(-2.5 / 2) +Pass testing z-index: calc(-3 / 2) +Pass testing z-index: calc(-3.5 / 2) \ No newline at end of file diff --git a/Tests/LibWeb/Text/input/wpt-import/css/css-values/calc-z-index-fractions-001.html b/Tests/LibWeb/Text/input/wpt-import/css/css-values/calc-z-index-fractions-001.html new file mode 100644 index 00000000000..b6e3667357c --- /dev/null +++ b/Tests/LibWeb/Text/input/wpt-import/css/css-values/calc-z-index-fractions-001.html @@ -0,0 +1,59 @@ + + + + + CSS Values and Units Test: computed value of 'z-index' when specified with calc() function and fractional values + + + + + + + + + + +
+ +