Title: [289214] trunk/Source/WebCore
Revision
289214
Author
[email protected]
Date
2022-02-07 06:45:16 -0800 (Mon, 07 Feb 2022)

Log Message

[LFC][IFC] WritingMode::LeftToRight expects line content flipped within the line
https://bugs.webkit.org/show_bug.cgi?id=236207

Reviewed by Antti Koivisto.

Vertical writing mode requires to
1. flip the line coordinate inside the block
2. but also to flip the content coordinate inside the line box, where
   vertical-lr expects the content top (which turns into the visual left) to be relative to the bottom of the line.

In this patch we decouple the line and the line content flipping logic. It helps to reason about the
type of coordinate translations at different levels (line inside the block and content inside the line).
This patch fixes the vertical-align tests under imported/w3c/web-platform-tests/css/css-writing-modes.

* layout/formattingContexts/inline/display/InlineDisplayContentBuilder.cpp:
(WebCore::Layout::InlineDisplayContentBuilder::processNonBidiContent):
(WebCore::Layout::InlineDisplayContentBuilder::processBidiContent):
(WebCore::Layout::InlineDisplayContentBuilder::flipLogicalRectToVisualForWritingModeWithinLine const):
(WebCore::Layout::InlineDisplayContentBuilder::flipLogicalRectToVisualForWritingMode): Deleted.
* layout/formattingContexts/inline/display/InlineDisplayContentBuilder.h:
* layout/formattingContexts/inline/display/InlineDisplayLineBuilder.cpp:
(WebCore::Layout::InlineDisplayLineBuilder::build const):
(WebCore::Layout::InlineDisplayLineBuilder::flipLogicalLineRectToVisualForWritingMode const):
* layout/formattingContexts/inline/display/InlineDisplayLineBuilder.h:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (289213 => 289214)


--- trunk/Source/WebCore/ChangeLog	2022-02-07 14:23:41 UTC (rev 289213)
+++ trunk/Source/WebCore/ChangeLog	2022-02-07 14:45:16 UTC (rev 289214)
@@ -1,3 +1,30 @@
+2022-02-07  Alan Bujtas  <[email protected]>
+
+        [LFC][IFC] WritingMode::LeftToRight expects line content flipped within the line
+        https://bugs.webkit.org/show_bug.cgi?id=236207
+
+        Reviewed by Antti Koivisto.
+
+        Vertical writing mode requires to
+        1. flip the line coordinate inside the block
+        2. but also to flip the content coordinate inside the line box, where 
+           vertical-lr expects the content top (which turns into the visual left) to be relative to the bottom of the line.
+
+        In this patch we decouple the line and the line content flipping logic. It helps to reason about the
+        type of coordinate translations at different levels (line inside the block and content inside the line).
+        This patch fixes the vertical-align tests under imported/w3c/web-platform-tests/css/css-writing-modes.
+
+        * layout/formattingContexts/inline/display/InlineDisplayContentBuilder.cpp:
+        (WebCore::Layout::InlineDisplayContentBuilder::processNonBidiContent):
+        (WebCore::Layout::InlineDisplayContentBuilder::processBidiContent):
+        (WebCore::Layout::InlineDisplayContentBuilder::flipLogicalRectToVisualForWritingModeWithinLine const):
+        (WebCore::Layout::InlineDisplayContentBuilder::flipLogicalRectToVisualForWritingMode): Deleted.
+        * layout/formattingContexts/inline/display/InlineDisplayContentBuilder.h:
+        * layout/formattingContexts/inline/display/InlineDisplayLineBuilder.cpp:
+        (WebCore::Layout::InlineDisplayLineBuilder::build const):
+        (WebCore::Layout::InlineDisplayLineBuilder::flipLogicalLineRectToVisualForWritingMode const):
+        * layout/formattingContexts/inline/display/InlineDisplayLineBuilder.h:
+
 2022-02-07  Nikolas Zimmermann  <[email protected]>
 
         [LBSE] Introduce RenderSVGModelObject aware geometry-query helpers in RenderLayerBacking

Modified: trunk/Source/WebCore/layout/formattingContexts/inline/display/InlineDisplayContentBuilder.cpp (289213 => 289214)


--- trunk/Source/WebCore/layout/formattingContexts/inline/display/InlineDisplayContentBuilder.cpp	2022-02-07 14:23:41 UTC (rev 289213)
+++ trunk/Source/WebCore/layout/formattingContexts/inline/display/InlineDisplayContentBuilder.cpp	2022-02-07 14:45:16 UTC (rev 289214)
@@ -333,7 +333,7 @@
         auto& layoutBox = lineRun.layoutBox();
 
         auto visualRectRelativeToRoot = [&](auto logicalRect) {
-            auto visualRect = flipLogicalRectToVisualForWritingMode(logicalRect, writingMode);
+            auto visualRect = flipLogicalRectToVisualForWritingModeWithinLine(logicalRect, lineBox.logicalRect(), writingMode);
             visualRect.moveBy(contentStartInVisualOrder);
             return visualRect;
         };
@@ -562,7 +562,7 @@
                 continue;
 
             auto visualRectRelativeToRoot = [&](auto logicalRect) {
-                auto visualRect = flipLogicalRectToVisualForWritingMode(logicalRect, writingMode);
+                auto visualRect = flipLogicalRectToVisualForWritingModeWithinLine(logicalRect, lineBox.logicalRect(), writingMode);
                 if (WebCore::isHorizontalWritingMode(writingMode))
                     visualRect.setLeft(contentRightInVisualOrder);
                 else
@@ -781,16 +781,19 @@
     boxes[lastRootInlineBoxIndex].setIsLastForLayoutBox(true);
 }
 
-InlineRect InlineDisplayContentBuilder::flipLogicalRectToVisualForWritingMode(const InlineRect& logicalRect, WritingMode writingMode)
+InlineRect InlineDisplayContentBuilder::flipLogicalRectToVisualForWritingModeWithinLine(const InlineRect& logicalRect, const InlineRect& lineLogicalRect, WritingMode writingMode) const
 {
     switch (writingMode) {
     case WritingMode::TopToBottom:
         return logicalRect;
-    case WritingMode::LeftToRight:
-    case WritingMode::RightToLeft: {
+    case WritingMode::LeftToRight: {
+        // Flip content such that the top (visual left) is now relative to the line bottom instead of the line top.
+        auto bottomOffset = lineLogicalRect.height() - logicalRect.bottom();
+        return { logicalRect.left(), bottomOffset, logicalRect.height(), logicalRect.width() };
+    }
+    case WritingMode::RightToLeft:
         // See InlineFormattingGeometry for more info.
         return { logicalRect.left(), logicalRect.top(), logicalRect.height(), logicalRect.width() };
-    }
     default:
         ASSERT_NOT_REACHED();
         break;

Modified: trunk/Source/WebCore/layout/formattingContexts/inline/display/InlineDisplayContentBuilder.h (289213 => 289214)


--- trunk/Source/WebCore/layout/formattingContexts/inline/display/InlineDisplayContentBuilder.h	2022-02-07 14:23:41 UTC (rev 289213)
+++ trunk/Source/WebCore/layout/formattingContexts/inline/display/InlineDisplayContentBuilder.h	2022-02-07 14:45:16 UTC (rev 289214)
@@ -47,7 +47,6 @@
     DisplayBoxes build(const LineBuilder::LineContent&, const LineBox&, const InlineDisplay::Line&, const size_t lineIndex);
 
     static void computeIsFirstIsLastBoxForInlineContent(DisplayBoxes&);
-    static InlineRect flipLogicalRectToVisualForWritingMode(const InlineRect& logicalRect, WritingMode);
 
 private:
     void processNonBidiContent(const LineBuilder::LineContent&, const LineBox&, const InlineDisplay::Line&, DisplayBoxes&);
@@ -67,6 +66,7 @@
     void adjustVisualGeometryForDisplayBox(size_t displayBoxNodeIndex, InlineLayoutUnit& accumulatedOffset, InlineLayoutUnit lineBoxTop, const DisplayBoxTree&, DisplayBoxes&, const LineBox&, const HashMap<const Box*, IsFirstLastIndex>&);
     size_t ensureDisplayBoxForContainer(const ContainerBox&, DisplayBoxTree&, AncestorStack&, DisplayBoxes&);
 
+    InlineRect flipLogicalRectToVisualForWritingModeWithinLine(const InlineRect& logicalRect, const InlineRect& lineLogicalRect, WritingMode) const;
     InlineLayoutPoint movePointHorizontallyForWritingMode(const InlineLayoutPoint& topLeft, InlineLayoutUnit horizontalOffset, WritingMode) const;
 
     const ContainerBox& root() const { return m_formattingContextRoot; }

Modified: trunk/Source/WebCore/layout/formattingContexts/inline/display/InlineDisplayLineBuilder.cpp (289213 => 289214)


--- trunk/Source/WebCore/layout/formattingContexts/inline/display/InlineDisplayLineBuilder.cpp	2022-02-07 14:23:41 UTC (rev 289213)
+++ trunk/Source/WebCore/layout/formattingContexts/inline/display/InlineDisplayLineBuilder.cpp	2022-02-07 14:45:16 UTC (rev 289214)
@@ -96,8 +96,8 @@
 
     // FIXME: Figure out if properties like enclosingLineGeometry top and bottom needs to be flipped as well.
     auto writingMode = root().style().writingMode();
-    return InlineDisplay::Line { InlineDisplayContentBuilder::flipLogicalRectToVisualForWritingMode(lineBoxRect, writingMode)
-        , InlineDisplayContentBuilder::flipLogicalRectToVisualForWritingMode(enclosingLineGeometry.scrollableOverflowRect, writingMode)
+    return InlineDisplay::Line { flipLogicalLineRectToVisualForWritingMode(lineBoxRect, writingMode)
+        , flipLogicalLineRectToVisualForWritingMode(enclosingLineGeometry.scrollableOverflowRect, writingMode)
         , enclosingLineGeometry.enclosingTopAndBottom
         , rootInlineBox.logicalTop() + rootInlineBox.ascent()
         , contentVisualLeft
@@ -105,7 +105,23 @@
     };
 }
 
+InlineRect InlineDisplayLineBuilder::flipLogicalLineRectToVisualForWritingMode(const InlineRect& lineLogicalRect, WritingMode writingMode) const
+{
+    switch (writingMode) {
+    case WritingMode::TopToBottom:
+        return lineLogicalRect;
+    case WritingMode::LeftToRight:
+    case WritingMode::RightToLeft:
+        // See InlineFormattingGeometry for more info.
+        return { lineLogicalRect.left(), lineLogicalRect.top(), lineLogicalRect.height(), lineLogicalRect.width() };
+    default:
+        ASSERT_NOT_REACHED();
+        break;
+    }
+    return lineLogicalRect;
 }
+
 }
+}
 
 #endif

Modified: trunk/Source/WebCore/layout/formattingContexts/inline/display/InlineDisplayLineBuilder.h (289213 => 289214)


--- trunk/Source/WebCore/layout/formattingContexts/inline/display/InlineDisplayLineBuilder.h	2022-02-07 14:23:41 UTC (rev 289213)
+++ trunk/Source/WebCore/layout/formattingContexts/inline/display/InlineDisplayLineBuilder.h	2022-02-07 14:45:16 UTC (rev 289214)
@@ -48,6 +48,7 @@
         InlineRect scrollableOverflowRect;
     };
     EnclosingLineGeometry collectEnclosingLineGeometry(const LineBox&, const InlineRect& lineBoxRect) const;
+    InlineRect flipLogicalLineRectToVisualForWritingMode(const InlineRect&, WritingMode) const;
 
     const InlineFormattingContext& formattingContext() const { return m_inlineFormattingContext; }
     const Box& root() const { return formattingContext().root(); }
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to