Title: [287043] trunk/Source/WebCore
Revision
287043
Author
[email protected]
Date
2021-12-14 12:57:19 -0800 (Tue, 14 Dec 2021)

Log Message

[LFC][IFC] Take text-align offset into account when computing the RTL display box geometry
https://bugs.webkit.org/show_bug.cgi?id=234287

Reviewed by Antti Koivisto.

Use LineBox::rootInlineBoxAlignmentOffset to offset the visual start position for RTL display boxes.

* layout/formattingContexts/inline/InlineDisplayContentBuilder.cpp:
(WebCore::Layout::InlineDisplayContentBuilder::processNonBidiContent):
(WebCore::Layout::InlineDisplayContentBuilder::processBidiContent):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (287042 => 287043)


--- trunk/Source/WebCore/ChangeLog	2021-12-14 20:23:42 UTC (rev 287042)
+++ trunk/Source/WebCore/ChangeLog	2021-12-14 20:57:19 UTC (rev 287043)
@@ -1,3 +1,16 @@
+2021-12-14  Alan Bujtas  <[email protected]>
+
+        [LFC][IFC] Take text-align offset into account when computing the RTL display box geometry
+        https://bugs.webkit.org/show_bug.cgi?id=234287
+
+        Reviewed by Antti Koivisto.
+
+        Use LineBox::rootInlineBoxAlignmentOffset to offset the visual start position for RTL display boxes.
+
+        * layout/formattingContexts/inline/InlineDisplayContentBuilder.cpp:
+        (WebCore::Layout::InlineDisplayContentBuilder::processNonBidiContent):
+        (WebCore::Layout::InlineDisplayContentBuilder::processBidiContent):
+
 2021-12-14  Alex Christensen  <[email protected]>
 
         Add _WKContentRuleListAction.redirected and .modifiedHeaders

Modified: trunk/Source/WebCore/layout/formattingContexts/inline/InlineDisplayContentBuilder.cpp (287042 => 287043)


--- trunk/Source/WebCore/layout/formattingContexts/inline/InlineDisplayContentBuilder.cpp	2021-12-14 20:23:42 UTC (rev 287042)
+++ trunk/Source/WebCore/layout/formattingContexts/inline/InlineDisplayContentBuilder.cpp	2021-12-14 20:57:19 UTC (rev 287043)
@@ -288,32 +288,35 @@
 
 void InlineDisplayContentBuilder::processNonBidiContent(const LineBuilder::LineContent& lineContent, const LineBox& lineBox, const InlineLayoutPoint& lineBoxLogicalTopLeft, DisplayBoxes& boxes)
 {
-    // Create the inline boxes on the current line. This is mostly text and atomic inline boxes.
+    auto rootInlineBoxWidth = lineBox.logicalRectForRootInlineBox().width();
     auto rootInlineBoxAlignmentOffset = lineBox.rootInlineBoxAlignmentOffset();
+    auto needsDirectionAdjustment = !root().style().isLeftToRightDirection();
 
     for (auto& lineRun : lineContent.runs) {
         auto& layoutBox = lineRun.layoutBox();
 
-        auto logicalRectRelativeToRoot = [&](auto logicalRect) {
-            logicalRect.moveBy({ lineBoxLogicalTopLeft.x() + rootInlineBoxAlignmentOffset, lineBoxLogicalTopLeft.y() });
+        auto visualRectRelativeToRoot = [&](auto logicalRect) {
+            // When the logical order == visual order, RTL inline direction is just an offset.
+            auto horizontalOffset = needsDirectionAdjustment ? lineContent.lineLogicalWidth - rootInlineBoxWidth - rootInlineBoxAlignmentOffset : rootInlineBoxAlignmentOffset;
+            logicalRect.moveBy({ lineBoxLogicalTopLeft.x() + horizontalOffset, lineBoxLogicalTopLeft.y() });
             return logicalRect;
         };
 
         if (lineRun.isText()) {
-            appendTextDisplayBox(lineRun, logicalRectRelativeToRoot(lineBox.logicalRectForTextRun(lineRun)), boxes);
+            appendTextDisplayBox(lineRun, visualRectRelativeToRoot(lineBox.logicalRectForTextRun(lineRun)), boxes);
             continue;
         }
         if (lineRun.isSoftLineBreak()) {
-            appendSoftLineBreakDisplayBox(lineRun, logicalRectRelativeToRoot(lineBox.logicalRectForTextRun(lineRun)), boxes);
+            appendSoftLineBreakDisplayBox(lineRun, visualRectRelativeToRoot(lineBox.logicalRectForTextRun(lineRun)), boxes);
             continue;
         }
         if (lineRun.isHardLineBreak()) {
-            appendHardLineBreakDisplayBox(lineRun, logicalRectRelativeToRoot(lineBox.logicalRectForLineBreakBox(layoutBox)), boxes);
+            appendHardLineBreakDisplayBox(lineRun, visualRectRelativeToRoot(lineBox.logicalRectForLineBreakBox(layoutBox)), boxes);
             continue;
         }
         if (lineRun.isBox()) {
             appendAtomicInlineLevelDisplayBox(lineRun
-                , logicalRectRelativeToRoot(lineBox.logicalBorderBoxForAtomicInlineLevelBox(layoutBox, formattingState().boxGeometry(layoutBox)))
+                , visualRectRelativeToRoot(lineBox.logicalBorderBoxForAtomicInlineLevelBox(layoutBox, formattingState().boxGeometry(layoutBox)))
                 , boxes);
             continue;
         }
@@ -320,7 +323,7 @@
         if (lineRun.isInlineBoxStart()) {
             appendInlineBoxDisplayBox(lineRun
                 , lineBox.inlineLevelBoxForLayoutBox(lineRun.layoutBox())
-                , logicalRectRelativeToRoot(lineBox.logicalBorderBoxForInlineBox(layoutBox, formattingState().boxGeometry(layoutBox)))
+                , visualRectRelativeToRoot(lineBox.logicalBorderBoxForInlineBox(layoutBox, formattingState().boxGeometry(layoutBox)))
                 , lineBox.hasContent()
                 , boxes);
             continue;
@@ -334,7 +337,7 @@
             }
             appendSpanningInlineBoxDisplayBox(lineRun
                 , lineBox.inlineLevelBoxForLayoutBox(lineRun.layoutBox())
-                , logicalRectRelativeToRoot(lineBox.logicalBorderBoxForInlineBox(layoutBox, formattingState().boxGeometry(layoutBox)))
+                , visualRectRelativeToRoot(lineBox.logicalBorderBoxForInlineBox(layoutBox, formattingState().boxGeometry(layoutBox)))
                 , boxes);
             continue;
         }
@@ -484,16 +487,11 @@
     ancestorStack.push({ }, root());
 
     auto rootInlineBoxAlignmentOffset = lineBox.rootInlineBoxAlignmentOffset();
-    auto contentStartInVisualOrder = InlineLayoutUnit { };
+    auto contentStartInVisualOrder = rootInlineBoxAlignmentOffset;
     auto createDisplayBoxesInVisualOrder = [&] {
-        auto rootInlineBoxRect = lineBox.logicalRectForRootInlineBox();
         // First visual run's initial content position depends on the block's inline direction.
-        if (!root().style().isLeftToRightDirection()) {
-            // FIXME: This needs the block end position instead of the lineLogicalWidth.
-            contentStartInVisualOrder += lineContent.lineLogicalWidth - rootInlineBoxRect.width();
-        }
-        // Adjust the content start position with the (text)alignment offset (root inline box has the alignment offset and not the individual runs).
-        contentStartInVisualOrder += rootInlineBoxAlignmentOffset;
+        if (!root().style().isLeftToRightDirection())
+            contentStartInVisualOrder = lineContent.lineLogicalWidth - lineBox.logicalRectForRootInlineBox().width() - rootInlineBoxAlignmentOffset;
 
         auto contentRightInVisualOrder = contentStartInVisualOrder;
         auto& runs = lineContent.runs;
@@ -507,10 +505,10 @@
             if (!needsDisplayBox)
                 continue;
 
-            auto visualRectRelativeToRoot = [&](auto logicallRect) {
-                logicallRect.setLeft(contentRightInVisualOrder);
-                logicallRect.moveBy(lineBoxLogicalTopLeft);
-                return logicallRect;
+            auto visualRectRelativeToRoot = [&](auto logicalRect) {
+                logicalRect.setLeft(contentRightInVisualOrder);
+                logicalRect.moveBy(lineBoxLogicalTopLeft);
+                return logicalRect;
             };
 
             auto parentDisplayBoxNodeIndex = ensureDisplayBoxForContainer(layoutBox.parent(), displayBoxTree, ancestorStack, boxes);
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to