Title: [295239] trunk
Revision
295239
Author
[email protected]
Date
2022-06-03 15:29:47 -0700 (Fri, 03 Jun 2022)

Log Message

Properly implement text-align-last in legacy layout engine and IFC
https://bugs.webkit.org/show_bug.cgi?id=241050

Patch by Kiet Ho <[email protected]> on 2022-06-03
Reviewed by Alan Bujtas.

The alignment of the last line in a block always follows the alignment specified
by text-align-last. However, the legacy layout engine currently follows the old
spec, where text-align-last only takes effect when text-align was 'justify' (see [1]
where this was changed), and IFC does not honor text-align-last at all. Fix both the
legacy layout engine and IFC to align the last line according to text-align-last.

Manually tested by running run-webkit-tests with IFC enabled and disabled.

[1]: https://github.com/w3c/csswg-drafts/commit/c1f7023611f2c44d24d5a0647965817902651f58

* LayoutTests/TestExpectations:
* LayoutTests/fast/css3-text/css3-text-align-last/text-align-last-with-text-align-non-justify-expected.html: Removed.
* LayoutTests/fast/css3-text/css3-text-align-last/text-align-last-with-text-align-non-justify.html:
Remove obsolete test that tests the old behavior of text-align-line.
* Source/WebCore/layout/formattingContexts/inline/InlineLineBoxBuilder.cpp:
(WebCore::Layout::horizontalAlignmentOffset):
(WebCore::Layout::LineBoxBuilder::build):
* Source/WebCore/rendering/LegacyLineLayout.cpp:
(WebCore::LegacyLineLayout::textAlignmentForLine const):

Canonical link: https://commits.webkit.org/251294@main

Modified Paths

Removed Paths

Diff

Modified: trunk/LayoutTests/TestExpectations (295238 => 295239)


--- trunk/LayoutTests/TestExpectations	2022-06-03 22:21:23 UTC (rev 295238)
+++ trunk/LayoutTests/TestExpectations	2022-06-03 22:29:47 UTC (rev 295239)
@@ -2642,9 +2642,6 @@
 webkit.org/b/183258 imported/w3c/web-platform-tests/css/css-text/text-align/text-align-justifyall-004.html [ ImageOnlyFailure ]
 webkit.org/b/183258 imported/w3c/web-platform-tests/css/css-text/text-align/text-align-justifyall-005.html [ ImageOnlyFailure ]
 webkit.org/b/183258 imported/w3c/web-platform-tests/css/css-text/text-align/text-align-justifyall-006.html [ ImageOnlyFailure ]
-webkit.org/b/183258 imported/w3c/web-platform-tests/css/css-text/text-align/text-align-last-010.html [ ImageOnlyFailure ]
-webkit.org/b/183258 imported/w3c/web-platform-tests/css/css-text/text-align/text-align-last-011.html [ ImageOnlyFailure ]
-webkit.org/b/214290 imported/w3c/web-platform-tests/css/css-text/text-align/text-align-last-wins-001.html [ ImageOnlyFailure ]
 webkit.org/b/214290 imported/w3c/web-platform-tests/css/css-text/text-encoding/shaping-join-003.html [ ImageOnlyFailure ]
 webkit.org/b/214290 imported/w3c/web-platform-tests/css/css-text/text-encoding/shaping-tatweel-002.html [ ImageOnlyFailure ]
 webkit.org/b/214290 imported/w3c/web-platform-tests/css/css-text/text-encoding/shaping-tatweel-003.html [ ImageOnlyFailure ]

Deleted: trunk/LayoutTests/fast/css3-text/css3-text-align-last/text-align-last-with-text-align-non-justify-expected.html (295238 => 295239)


--- trunk/LayoutTests/fast/css3-text/css3-text-align-last/text-align-last-with-text-align-non-justify-expected.html	2022-06-03 22:21:23 UTC (rev 295238)
+++ trunk/LayoutTests/fast/css3-text/css3-text-align-last/text-align-last-with-text-align-non-justify-expected.html	2022-06-03 22:29:47 UTC (rev 295239)
@@ -1,37 +0,0 @@
-<!DOCTYPE html>
-<html>
-<head>
-<style>
-#tests div {
-    width: 100px;
-    margin-bottom: 20px;
-    border: 1px solid #000000;
-    font: 20px/1 Ahem, sans-serif;
-}
-</style>
-</head>
-<body>
-
-<div id="tests">
-    text-align : start; text-align-last : end
-    <div style='text-align: start;'>X X X XXX</div>
-
-    text-align : end; text-align-last : start
-    <div style='text-align: end;'>X X X XXX</div>
-
-    text-align : left; text-align-last : right
-    <div style='text-align: left;'>X X X XXX</div>
-
-    text-align : right; text-align-last : left
-    <div style='text-align: right;'>X X X XXX</div>
-
-    text-align : center; text-align-last : left
-    <div style='text-align: center;'>X X X XXX</div>
-</div>
-
-<p>Since text-align is not justify, text-align-last property shouldn't be respected,
-thus the alignment should be as defined by text-align.</p>
-
-
-</body>
-</html>

Deleted: trunk/LayoutTests/fast/css3-text/css3-text-align-last/text-align-last-with-text-align-non-justify.html (295238 => 295239)


--- trunk/LayoutTests/fast/css3-text/css3-text-align-last/text-align-last-with-text-align-non-justify.html	2022-06-03 22:21:23 UTC (rev 295238)
+++ trunk/LayoutTests/fast/css3-text/css3-text-align-last/text-align-last-with-text-align-non-justify.html	2022-06-03 22:29:47 UTC (rev 295239)
@@ -1,38 +0,0 @@
-<!DOCTYPE html>
-<html>
-<head>
-<style>
-#tests div {
-    width: 100px;
-    margin-bottom: 20px;
-    border: 1px solid #000000;
-    font: 20px/1 Ahem, sans-serif;
-}
-</style>
-</head>
-<body>
-
-<div id="tests">
-    text-align : start; text-align-last : end
-    <div style='text-align: start; text-align-last: end;'>X X X XXX</div>
-
-    text-align : end; text-align-last : start
-    <div style='text-align: end; text-align-last: start;'>X X X XXX</div>
-
-    text-align : left; text-align-last : right
-    <div style='text-align: left; text-align-last: right;'>X X X XXX</div>
-
-    text-align : right; text-align-last : left
-    <div style='text-align: right; text-align-last: left;'>X X X XXX</div>
-
-    text-align : center; text-align-last : left
-    <div style='text-align: center; text-align-last: left;'>X X X XXX</div>
-</div>
-
-<p>Since text-align is not justify, text-align-last property shouldn't be respected,
-thus the alignment should be as defined by text-align.</p>
-
-
-</body>
-</html>
-

Modified: trunk/Source/WebCore/layout/formattingContexts/inline/InlineLineBoxBuilder.cpp (295238 => 295239)


--- trunk/Source/WebCore/layout/formattingContexts/inline/InlineLineBoxBuilder.cpp	2022-06-03 22:21:23 UTC (rev 295238)
+++ trunk/Source/WebCore/layout/formattingContexts/inline/InlineLineBoxBuilder.cpp	2022-06-03 22:29:47 UTC (rev 295239)
@@ -36,7 +36,7 @@
 namespace WebCore {
 namespace Layout {
 
-static std::optional<InlineLayoutUnit> horizontalAlignmentOffset(TextAlignMode textAlign, const LineBuilder::LineContent& lineContent, bool isLeftToRightDirection)
+static std::optional<InlineLayoutUnit> horizontalAlignmentOffset(TextAlignMode textAlign, TextAlignLast textAlignLast, const LineBuilder::LineContent& lineContent, bool isLeftToRightDirection)
 {
     // Depending on the line’s alignment/justification, the hanging glyph can be placed outside the line box.
     auto& runs = lineContent.runs;
@@ -59,14 +59,34 @@
         return { };
 
     auto computedHorizontalAlignment = [&] {
-        if (textAlign != TextAlignMode::Justify)
-            return textAlign;
-        // Text is justified according to the method specified by the text-justify property,
-        // in order to exactly fill the line box. Unless otherwise specified by text-align-last,
-        // the last line before a forced break or the end of the block is start-aligned.
-        if (lineContent.isLastLineWithInlineContent || (!runs.isEmpty() && runs.last().isLineBreak()))
-            return TextAlignMode::Start;
-        return TextAlignMode::Justify;
+        // The last line before a forced break or the end of the block is aligned according to
+        // text-align-last.
+        if (lineContent.isLastLineWithInlineContent || (!runs.isEmpty() && runs.last().isLineBreak())) {
+            switch (textAlignLast) {
+            case TextAlignLast::Auto:
+                if (textAlign == TextAlignMode::Justify)
+                    return TextAlignMode::Start;
+                return textAlign;
+            case TextAlignLast::Start:
+                return TextAlignMode::Start;
+            case TextAlignLast::End:
+                return TextAlignMode::End;
+            case TextAlignLast::Left:
+                return TextAlignMode::Left;
+            case TextAlignLast::Right:
+                return TextAlignMode::Right;
+            case TextAlignLast::Center:
+                return TextAlignMode::Center;
+            case TextAlignLast::Justify:
+                return TextAlignMode::Justify;
+            default:
+                ASSERT_NOT_REACHED();
+                return TextAlignMode::Start;
+            }
+        }
+
+        // All other lines are aligned according to text-align.
+        return textAlign;
     };
 
     switch (computedHorizontalAlignment()) {
@@ -106,7 +126,7 @@
 LineBox LineBoxBuilder::build(const LineBuilder::LineContent& lineContent, size_t lineIndex)
 {
     auto& rootStyle = lineIndex ? rootBox().firstLineStyle() : rootBox().style();
-    auto rootInlineBoxAlignmentOffset = valueOrDefault(Layout::horizontalAlignmentOffset(rootStyle.textAlign(), lineContent, lineContent.inlineBaseDirection == TextDirection::LTR));
+    auto rootInlineBoxAlignmentOffset = valueOrDefault(Layout::horizontalAlignmentOffset(rootStyle.textAlign(), rootStyle.textAlignLast(), lineContent, lineContent.inlineBaseDirection == TextDirection::LTR));
     // FIXME: The overflowing hanging content should be part of the ink overflow.  
     auto lineBox = LineBox { rootBox(), rootInlineBoxAlignmentOffset, lineContent.contentLogicalWidth - lineContent.hangingContentWidth, lineIndex, lineContent.nonSpanningInlineLevelBoxCount };
     constructInlineLevelBoxes(lineBox, lineContent, lineIndex);

Modified: trunk/Source/WebCore/rendering/LegacyLineLayout.cpp (295238 => 295239)


--- trunk/Source/WebCore/rendering/LegacyLineLayout.cpp	2022-06-03 22:21:23 UTC (rev 295238)
+++ trunk/Source/WebCore/rendering/LegacyLineLayout.cpp	2022-06-03 22:29:47 UTC (rev 295239)
@@ -367,9 +367,6 @@
     if (endsWithSoftBreak)
         return alignment;
 
-    if (alignment != TextAlignMode::Justify)
-        return alignment;
-
     TextAlignLast alignmentLast = style().textAlignLast();
     switch (alignmentLast) {
     case TextAlignLast::Start:
@@ -385,11 +382,13 @@
     case TextAlignLast::Justify:
         return TextAlignMode::Justify;
     case TextAlignLast::Auto:
-        if (textJustify == TextJustify::InterCharacter)
-            return TextAlignMode::Justify;
-        return TextAlignMode::Start;
+        if (alignment == TextAlignMode::Justify)
+            return TextAlignMode::Start;
+        return alignment;
     }
-    return alignment;
+
+    ASSERT_NOT_REACHED();
+    return TextAlignMode::Start;
 }
 
 static void updateLogicalWidthForLeftAlignedBlock(bool isLeftToRightDirection, BidiRun* trailingSpaceRun, float& logicalLeft, float& totalLogicalWidth, float availableLogicalWidth)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to