[LFC][IFC] Add support for text-transform: uppercase/lowercase
https://bugs.webkit.org/show_bug.cgi?id=202968
<rdar://problem/56278141>

Reviewed by Antti Koivisto.

The text content on the layout box should be in its final state (This might change if we actually need the original content for some reason though).

* layout/layouttree/LayoutTreeBuilder.cpp:
(WebCore::Layout::applyTextTransform):
(WebCore::Layout::TreeBuilder::createLayoutBox):


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@251133 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog
index 0b4d5d3..8b3ae3d 100644
--- a/Source/WebCore/ChangeLog
+++ b/Source/WebCore/ChangeLog
@@ -1,3 +1,17 @@
+2019-10-15  Zalan Bujtas  <zalan@apple.com>
+
+        [LFC][IFC] Add support for text-transform: uppercase/lowercase
+        https://bugs.webkit.org/show_bug.cgi?id=202968
+        <rdar://problem/56278141>
+
+        Reviewed by Antti Koivisto.
+
+        The text content on the layout box should be in its final state (This might change if we actually need the original content for some reason though).
+
+        * layout/layouttree/LayoutTreeBuilder.cpp:
+        (WebCore::Layout::applyTextTransform):
+        (WebCore::Layout::TreeBuilder::createLayoutBox):
+
 2019-10-14  Youenn Fablet  <youenn@apple.com>
 
         Handle service worker loads through NetworkResourceLoader
diff --git a/Source/WebCore/layout/layouttree/LayoutTreeBuilder.cpp b/Source/WebCore/layout/layouttree/LayoutTreeBuilder.cpp
index dba6388..49e6f78 100644
--- a/Source/WebCore/layout/layouttree/LayoutTreeBuilder.cpp
+++ b/Source/WebCore/layout/layouttree/LayoutTreeBuilder.cpp
@@ -93,6 +93,24 @@
     return block.relativePositionOffset();
 }
 
+static String applyTextTransform(const String& text, const RenderStyle& style)
+{
+    switch (style.textTransform()) {
+    case TextTransform::None:
+        return text;
+    case TextTransform::Capitalize: {
+        ASSERT_NOT_IMPLEMENTED_YET();
+        return text;
+    }
+    case TextTransform::Uppercase:
+        return text.convertToUppercaseWithLocale(style.locale());
+    case TextTransform::Lowercase:
+        return text.convertToLowercaseWithLocale(style.locale());
+    }
+    ASSERT_NOT_REACHED();
+    return text;
+}
+
 std::unique_ptr<Box> TreeBuilder::createLayoutBox(const RenderElement& parentRenderer, const RenderObject& childRenderer)
 {
     auto elementAttributes = [] (const RenderElement& renderer) -> Optional<Box::ElementAttributes> {
@@ -115,11 +133,13 @@
 
     std::unique_ptr<Box> childLayoutBox;
     if (is<RenderText>(childRenderer)) {
+        auto& textRenderer = downcast<RenderText>(childRenderer);
+        auto textContent = applyTextTransform(textRenderer.originalText(), parentRenderer.style());
         // FIXME: Clearly there must be a helper function for this.
         if (parentRenderer.style().display() == DisplayType::Inline)
-            childLayoutBox = makeUnique<Box>(downcast<RenderText>(childRenderer).originalText(), RenderStyle::clone(parentRenderer.style()));
+            childLayoutBox = makeUnique<Box>(textContent, RenderStyle::clone(parentRenderer.style()));
         else
-            childLayoutBox = makeUnique<Box>(downcast<RenderText>(childRenderer).originalText(), RenderStyle::createAnonymousStyleWithDisplay(parentRenderer.style(), DisplayType::Inline));
+            childLayoutBox = makeUnique<Box>(textContent, RenderStyle::createAnonymousStyleWithDisplay(parentRenderer.style(), DisplayType::Inline));
         childLayoutBox->setIsAnonymous();
         return childLayoutBox;
     }