From 1a9dd707920e1e5a7b3c3859802bee5cbf2521e0 Mon Sep 17 00:00:00 2001 From: Callum Law Date: Sun, 3 Aug 2025 22:46:50 +1200 Subject: [PATCH] LibWeb: Serialize NumberStyleValue with 6 decimal places of precision --- .../LibWeb/CSS/StyleValues/NumberStyleValue.cpp | 8 +++++++- .../expected/css/getComputedStyle-transform.txt | 16 ++++++++-------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/Libraries/LibWeb/CSS/StyleValues/NumberStyleValue.cpp b/Libraries/LibWeb/CSS/StyleValues/NumberStyleValue.cpp index 08cccd065c9..5e8d106bd98 100644 --- a/Libraries/LibWeb/CSS/StyleValues/NumberStyleValue.cpp +++ b/Libraries/LibWeb/CSS/StyleValues/NumberStyleValue.cpp @@ -14,7 +14,13 @@ namespace Web::CSS { String NumberStyleValue::to_string(SerializationMode) const { - return String::number(m_value); + // FIXME: This should be moved into Serialize.cpp and used by applicable dimensions as well. + // https://drafts.csswg.org/cssom/#serialize-a-css-value + // + // A base-ten number using digits 0-9 (U+0030 to U+0039) in the shortest form possible, using "." to separate + // decimals (if any), rounding the value if necessary to not produce more than 6 decimals, preceded by "-" (U+002D) + // if it is negative. + return MUST(String::formatted("{:.6}", m_value)); } Vector NumberStyleValue::tokenize() const diff --git a/Tests/LibWeb/Text/expected/css/getComputedStyle-transform.txt b/Tests/LibWeb/Text/expected/css/getComputedStyle-transform.txt index f12173da748..de78c90e2ad 100644 --- a/Tests/LibWeb/Text/expected/css/getComputedStyle-transform.txt +++ b/Tests/LibWeb/Text/expected/css/getComputedStyle-transform.txt @@ -3,7 +3,7 @@ matrix(1, 2, 3, 4, 5, 6) => matrix(1, 2, 3, 4, 5, 6) matrix3d(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16) => matrix3d(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16) perspective(none) => matrix(1, 0, 0, 1, 0, 0) perspective(0) => matrix3d(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, -1, 0, 0, 0, 1) -perspective(4cm) => matrix3d(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, -0.006614303216338158, 0, 0, 0, 1) +perspective(4cm) => matrix3d(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, -0.006614, 0, 0, 0, 1) translate(1%, 2px) => matrix(1, 0, 0, 1, 7.828125, 2) translate3d(1%, 2px, 3em) => matrix3d(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 7.828125, 2, 48, 1) translateX(1px) => matrix(1, 0, 0, 1, 1, 0) @@ -21,11 +21,11 @@ scaleZ(1.5) => matrix3d(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1.5, 0, 0, 0, 0, 1) scaleZ(150%) => matrix3d(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1.5, 0, 0, 0, 0, 1) scale3d(1, 2, 1.5) => matrix3d(1, 0, 0, 0, 0, 2, 0, 0, 0, 0, 1.5, 0, 0, 0, 0, 1) scale3d(100%, 200%, 150%) => matrix3d(1, 0, 0, 0, 0, 2, 0, 0, 0, 0, 1.5, 0, 0, 0, 0, 1) -rotate(1deg) => matrix(0.9998477101325989, 0.017452405765652657, -0.017452405765652657, 0.9998477101325989, 0, 0) -rotateX(1rad) => matrix3d(1, 0, 0, 0, 0, 0.5403022766113281, 0.8414709568023682, 0, 0, -0.8414709568023682, 0.5403022766113281, 0, 0, 0, 0, 1) -rotateY(1grad) => matrix3d(0.9998766183853149, 0, -0.015707317739725113, 0, 0, 1, 0, 0, 0.015707317739725113, 0, 0.9998766183853149, 0, 0, 0, 0, 1) +rotate(1deg) => matrix(0.999848, 0.017452, -0.017452, 0.999848, 0, 0) +rotateX(1rad) => matrix3d(1, 0, 0, 0, 0, 0.540302, 0.841471, 0, 0, -0.841471, 0.540302, 0, 0, 0, 0, 1) +rotateY(1grad) => matrix3d(0.999877, 0, -0.015707, 0, 0, 1, 0, 0, 0.015707, 0, 0.999877, 0, 0, 0, 0, 1) rotateZ(1turn) => matrix(1, 0, 0, 1, 0, 0) -rotate3d(0, 1, 0, 45rad) => matrix3d(0.5253220200538635, 0, -0.8509035110473633, 0, 0, 1, 0, 0, 0.8509035110473633, 0, 0.5253220200538635, 0, 0, 0, 0, 1) -skew(1deg, 1rad) => matrix(1, 1.5574077367782593, 0.01745506562292576, 1, 0, 0) -skewX(1deg) => matrix(1, 0, 0.01745506562292576, 1, 0, 0) -skewY(1rad) => matrix(1, 1.5574077367782593, 0, 1, 0, 0) +rotate3d(0, 1, 0, 45rad) => matrix3d(0.525322, 0, -0.850904, 0, 0, 1, 0, 0, 0.850904, 0, 0.525322, 0, 0, 0, 0, 1) +skew(1deg, 1rad) => matrix(1, 1.557408, 0.017455, 1, 0, 0) +skewX(1deg) => matrix(1, 0, 0.017455, 1, 0, 0) +skewY(1rad) => matrix(1, 1.557408, 0, 1, 0, 0)