From 95c511a3f62f7dd2d1a5deebc523a0898b2d8351 Mon Sep 17 00:00:00 2001 From: Grubre Date: Sat, 26 Oct 2024 11:23:34 +0200 Subject: [PATCH] LibWeb: Use the correct locale when applying titlecase Previously with lang="nl" and text-transform: capitalize, inner text "ijsland" would turn to "Ijsland" instead of "IJsland", now it's as it should be. This fixes: https://wpt.fyi/results/css/css-text/text-transform/text-transform-tailoring-001.html --- .../DOM/Element-to_titlecase-lang.txt | 2 ++ .../input/DOM/Element-to_titlecase-lang.html | 26 +++++++++++++++++++ Userland/Libraries/LibWeb/Layout/TextNode.cpp | 11 +++++--- 3 files changed, 36 insertions(+), 3 deletions(-) create mode 100644 Tests/LibWeb/Text/expected/DOM/Element-to_titlecase-lang.txt create mode 100644 Tests/LibWeb/Text/input/DOM/Element-to_titlecase-lang.html diff --git a/Tests/LibWeb/Text/expected/DOM/Element-to_titlecase-lang.txt b/Tests/LibWeb/Text/expected/DOM/Element-to_titlecase-lang.txt new file mode 100644 index 00000000000..125f04bcf44 --- /dev/null +++ b/Tests/LibWeb/Text/expected/DOM/Element-to_titlecase-lang.txt @@ -0,0 +1,2 @@ +IJsland +Ijsland diff --git a/Tests/LibWeb/Text/input/DOM/Element-to_titlecase-lang.html b/Tests/LibWeb/Text/input/DOM/Element-to_titlecase-lang.html new file mode 100644 index 00000000000..c5a0aa9fc28 --- /dev/null +++ b/Tests/LibWeb/Text/input/DOM/Element-to_titlecase-lang.html @@ -0,0 +1,26 @@ + + + + + + + + + +
ijsland
+
ijsland
+
IJsland
+ + + + + diff --git a/Userland/Libraries/LibWeb/Layout/TextNode.cpp b/Userland/Libraries/LibWeb/Layout/TextNode.cpp index 2325db0d577..b678574240b 100644 --- a/Userland/Libraries/LibWeb/Layout/TextNode.cpp +++ b/Userland/Libraries/LibWeb/Layout/TextNode.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -278,7 +279,7 @@ static String apply_math_auto_text_transform(String const& string) return MUST(builder.to_string()); } -static ErrorOr apply_text_transform(String const& string, CSS::TextTransform text_transform) +static ErrorOr apply_text_transform(String const& string, CSS::TextTransform text_transform, Optional const& locale) { switch (text_transform) { case CSS::TextTransform::Uppercase: @@ -290,7 +291,7 @@ static ErrorOr apply_text_transform(String const& string, CSS::TextTrans case CSS::TextTransform::MathAuto: return apply_math_auto_text_transform(string); case CSS::TextTransform::Capitalize: { - return string.to_titlecase({}, TrailingCodePointTransformation::PreserveExisting); + return string.to_titlecase(locale, TrailingCodePointTransformation::PreserveExisting); } case CSS::TextTransform::FullSizeKana: case CSS::TextTransform::FullWidth: @@ -333,7 +334,11 @@ void TextNode::compute_text_for_rendering() if (dom_node().is_editable() && !dom_node().is_uninteresting_whitespace_node()) collapse = false; - auto data = apply_text_transform(dom_node().data(), computed_values().text_transform()).release_value_but_fixme_should_propagate_errors(); + auto const* parent_element = dom_node().parent_element(); + auto const maybe_lang = parent_element ? parent_element->lang() : Optional {}; + auto const lang = maybe_lang.has_value() ? maybe_lang.value() : Optional {}; + + auto data = apply_text_transform(dom_node().data(), computed_values().text_transform(), lang).release_value_but_fixme_should_propagate_errors(); auto data_view = data.bytes_as_string_view();