From 112a45bdf20b24018568ca29812f6a03a9aeb2ec Mon Sep 17 00:00:00 2001 From: Tim Ledbetter Date: Tue, 9 Sep 2025 10:21:37 +0100 Subject: [PATCH] LibWeb: Return resolved value of `normal` if `letter-spacing` value is 0 --- Libraries/LibWeb/CSS/CSSStyleProperties.cpp | 7 ++++ .../parsing/letter-spacing-computed.txt | 14 ++++++++ .../parsing/letter-spacing-computed.html | 33 +++++++++++++++++++ 3 files changed, 54 insertions(+) create mode 100644 Tests/LibWeb/Text/expected/wpt-import/css/css-text/parsing/letter-spacing-computed.txt create mode 100644 Tests/LibWeb/Text/input/wpt-import/css/css-text/parsing/letter-spacing-computed.html diff --git a/Libraries/LibWeb/CSS/CSSStyleProperties.cpp b/Libraries/LibWeb/CSS/CSSStyleProperties.cpp index b3e4d3ac61c..bddfb360f41 100644 --- a/Libraries/LibWeb/CSS/CSSStyleProperties.cpp +++ b/Libraries/LibWeb/CSS/CSSStyleProperties.cpp @@ -815,6 +815,13 @@ RefPtr CSSStyleProperties::style_value_for_computed_property(L } case PropertyID::WebkitTextFillColor: return resolve_color_style_value(get_computed_value(property_id), layout_node.computed_values().webkit_text_fill_color()); + case PropertyID::LetterSpacing: { + // https://drafts.csswg.org/css-text-4/#letter-spacing-property + // For legacy reasons, a computed letter-spacing of zero yields a resolved value (getComputedStyle() return value) of normal. + if (layout_node.computed_values().letter_spacing() == 0) + return KeywordStyleValue::create(Keyword::Normal); + return get_computed_value(property_id); + } case PropertyID::Invalid: return KeywordStyleValue::create(Keyword::Invalid); case PropertyID::Custom: diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-text/parsing/letter-spacing-computed.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-text/parsing/letter-spacing-computed.txt new file mode 100644 index 00000000000..f9c0c6237e8 --- /dev/null +++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-text/parsing/letter-spacing-computed.txt @@ -0,0 +1,14 @@ +Harness status: OK + +Found 9 tests + +9 Pass +Pass Property letter-spacing value 'normal' +Pass Property letter-spacing value '0px' +Pass Property letter-spacing value '10px' +Pass Property letter-spacing value '-20px' +Pass Property letter-spacing value 'calc(10px - 0.5em)' +Pass Property letter-spacing value '110%' +Pass Property letter-spacing value '-5%' +Pass Property letter-spacing value 'calc(10% - 20%)' +Pass Property letter-spacing value 'calc(10px - (5% + 10%)' \ No newline at end of file diff --git a/Tests/LibWeb/Text/input/wpt-import/css/css-text/parsing/letter-spacing-computed.html b/Tests/LibWeb/Text/input/wpt-import/css/css-text/parsing/letter-spacing-computed.html new file mode 100644 index 00000000000..5ab366c3198 --- /dev/null +++ b/Tests/LibWeb/Text/input/wpt-import/css/css-text/parsing/letter-spacing-computed.html @@ -0,0 +1,33 @@ + + + + +CSS Text: getComputedStyle().letterSpacing + + + + + + + + + +
+ + +