Title: [287083] trunk/Source/WebCore
Revision
287083
Author
za...@apple.com
Date
2021-12-15 10:09:48 -0800 (Wed, 15 Dec 2021)

Log Message

[LFC][IFC] Use the physical margin/border/padding values for inline boxes when generating the display content
https://bugs.webkit.org/show_bug.cgi?id=234346

Reviewed by Antti Koivisto.

Display content is always based on visual order. When we construct the display boxes
  - we visit the line runs in visual order
  - we make space for margin/border/padding by looking at the physical sides of the content
The visually first box may very well be logically the last and this first box's left side (again, visually)
may refer to the logical start/end values depending on the inline axis direction.

E.g in case of right to left inline direction, the border-inline-end value of an inline box should be use as the
"visually first" border on the left side of the inline box content.

It means that
 - physical values are used when creating the display boxes
 - and logical values are used throughout the layout
which in practice means that isLeftToRightDirection check should only happen before and after layout
(physical -> logical and logical -> physical respectively) but never during layout.

* layout/formattingContexts/inline/InlineDisplayContentBuilder.cpp:
(WebCore::Layout::marginLeft):
(WebCore::Layout::marginRight):
(WebCore::Layout::borderLeft):
(WebCore::Layout::borderRight):
(WebCore::Layout::paddingLeft):
(WebCore::Layout::paddingRight):
(WebCore::Layout::InlineDisplayContentBuilder::adjustVisualGeometryForDisplayBox):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (287082 => 287083)


--- trunk/Source/WebCore/ChangeLog	2021-12-15 18:08:42 UTC (rev 287082)
+++ trunk/Source/WebCore/ChangeLog	2021-12-15 18:09:48 UTC (rev 287083)
@@ -1,3 +1,34 @@
+2021-12-15  Alan Bujtas  <za...@apple.com>
+
+        [LFC][IFC] Use the physical margin/border/padding values for inline boxes when generating the display content
+        https://bugs.webkit.org/show_bug.cgi?id=234346
+
+        Reviewed by Antti Koivisto.
+
+        Display content is always based on visual order. When we construct the display boxes
+          - we visit the line runs in visual order
+          - we make space for margin/border/padding by looking at the physical sides of the content 
+        The visually first box may very well be logically the last and this first box's left side (again, visually)
+        may refer to the logical start/end values depending on the inline axis direction. 
+
+        E.g in case of right to left inline direction, the border-inline-end value of an inline box should be use as the
+        "visually first" border on the left side of the inline box content.   
+
+        It means that
+         - physical values are used when creating the display boxes
+         - and logical values are used throughout the layout
+        which in practice means that isLeftToRightDirection check should only happen before and after layout
+        (physical -> logical and logical -> physical respectively) but never during layout.
+
+        * layout/formattingContexts/inline/InlineDisplayContentBuilder.cpp:
+        (WebCore::Layout::marginLeft):
+        (WebCore::Layout::marginRight):
+        (WebCore::Layout::borderLeft):
+        (WebCore::Layout::borderRight):
+        (WebCore::Layout::paddingLeft):
+        (WebCore::Layout::paddingRight):
+        (WebCore::Layout::InlineDisplayContentBuilder::adjustVisualGeometryForDisplayBox):
+
 2021-12-15  Yoshiaki Jitsukawa  <yoshiaki.jitsuk...@sony.com>
 
         JPEG XL decoder should support understand color profiles

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


--- trunk/Source/WebCore/layout/formattingContexts/inline/InlineDisplayContentBuilder.cpp	2021-12-15 18:08:42 UTC (rev 287082)
+++ trunk/Source/WebCore/layout/formattingContexts/inline/InlineDisplayContentBuilder.cpp	2021-12-15 18:09:48 UTC (rev 287083)
@@ -41,6 +41,36 @@
 namespace WebCore {
 namespace Layout {
 
+static inline LayoutUnit marginLeft(const Layout::BoxGeometry& boxGeometry, bool isLeftToRightDirection)
+{
+    return isLeftToRightDirection ? boxGeometry.marginStart() : boxGeometry.marginEnd();
+}
+
+static inline LayoutUnit marginRight(const Layout::BoxGeometry& boxGeometry, bool isLeftToRightDirection)
+{
+    return isLeftToRightDirection ? boxGeometry.marginEnd() : boxGeometry.marginStart();
+}
+
+static inline LayoutUnit borderLeft(const Layout::BoxGeometry& boxGeometry, bool isLeftToRightDirection)
+{
+    return isLeftToRightDirection ? boxGeometry.borderStart() : boxGeometry.borderEnd();
+}
+
+static inline LayoutUnit borderRight(const Layout::BoxGeometry& boxGeometry, bool isLeftToRightDirection)
+{
+    return isLeftToRightDirection ? boxGeometry.borderEnd() : boxGeometry.borderStart();
+}
+
+static inline LayoutUnit paddingLeft(const Layout::BoxGeometry& boxGeometry, bool isLeftToRightDirection)
+{
+    return isLeftToRightDirection ? boxGeometry.paddingStart().value_or(0_lu) : boxGeometry.paddingEnd().value_or(0_lu);
+}
+
+static inline LayoutUnit paddingRight(const Layout::BoxGeometry& boxGeometry, bool isLeftToRightDirection)
+{
+    return isLeftToRightDirection ? boxGeometry.paddingEnd().value_or(0_lu) : boxGeometry.paddingStart().value_or(0_lu);
+}
+
 static inline OptionSet<InlineDisplay::Box::PositionWithinInlineLevelBox> isFirstLastBox(const InlineLevelBox& inlineBox)
 {
     auto positionWithinInlineLevelBox = OptionSet<InlineDisplay::Box::PositionWithinInlineLevelBox> { };
@@ -424,6 +454,7 @@
 
 void InlineDisplayContentBuilder::adjustVisualGeometryForDisplayBox(size_t displayBoxNodeIndex, InlineLayoutUnit& contentRightInVisualOrder, InlineLayoutUnit lineBoxLogicalTop, const DisplayBoxTree& displayBoxTree, DisplayBoxes& boxes, const LineBox& lineBox)
 {
+    auto isLeftToRightDirection = root().style().isLeftToRightDirection();
     // Non-inline box display boxes just need a horizontal adjustment while
     // inline box type of display boxes need
     // 1. horizontal adjustment and margin/border/padding start offsetting on the first box
@@ -435,7 +466,7 @@
         displayBox.setLeft(contentRightInVisualOrder);
         contentRightInVisualOrder += displayBox.width();
         if (displayBox.isAtomicInlineLevelBox() || displayBox.isGenericInlineLevelBox())
-            contentRightInVisualOrder += formattingState().boxGeometry(layoutBox).marginEnd();
+            contentRightInVisualOrder += marginRight(formattingState().boxGeometry(layoutBox), isLeftToRightDirection);
         return;
     }
 
@@ -446,10 +477,10 @@
         if (!displayBox.isFirstForLayoutBox())
             return displayBox.setRect(visualRect, visualRect);
 
-        contentRightInVisualOrder += boxGeometry.marginStart();
-        auto visualRectWithMarginStart = InlineRect { visualRect.top(), contentRightInVisualOrder, visualRect.width(), visualRect.height() };
-        displayBox.setRect(visualRectWithMarginStart, visualRectWithMarginStart);
-        contentRightInVisualOrder += boxGeometry.borderAndPaddingStart();
+        contentRightInVisualOrder += marginLeft(boxGeometry, isLeftToRightDirection);
+        auto visualRectWithMarginLeft = InlineRect { visualRect.top(), contentRightInVisualOrder, visualRect.width(), visualRect.height() };
+        displayBox.setRect(visualRectWithMarginLeft, visualRectWithMarginLeft);
+        contentRightInVisualOrder += borderLeft(boxGeometry, isLeftToRightDirection) + paddingLeft(boxGeometry, isLeftToRightDirection);
     };
     beforeInlineBoxContent();
 
@@ -460,9 +491,9 @@
         if (!displayBox.isLastForLayoutBox())
             return displayBox.setRight(contentRightInVisualOrder);
 
-        contentRightInVisualOrder += boxGeometry.borderAndPaddingEnd();
+        contentRightInVisualOrder += borderRight(boxGeometry, isLeftToRightDirection) + paddingRight(boxGeometry, isLeftToRightDirection);
         displayBox.setRight(contentRightInVisualOrder);
-        contentRightInVisualOrder += boxGeometry.marginEnd();
+        contentRightInVisualOrder += marginRight(boxGeometry, isLeftToRightDirection);
     };
     afterInlineBoxContent();
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to