Title: [286518] trunk/Source/WebCore
Revision
286518
Author
[email protected]
Date
2021-12-03 15:42:45 -0800 (Fri, 03 Dec 2021)

Log Message

[LFC][IFC] Move the (bidi)display boxes horizontally by the inline box margin, border and padding end as needed
https://bugs.webkit.org/show_bug.cgi?id=233744

Reviewed by Antti Koivisto.

Keep track of the inline box range in the context of display boxes so that we can adjust the content horizontally
with the margin/border/padding end of the "last" inline box.
We also set the width of the (fragmented inline box type of) display boxes here based on their content right position.

* layout/formattingContexts/inline/InlineDisplayContentBuilder.cpp:
(WebCore::Layout::InlineDisplayContentBuilder::processBidiContent):
* layout/formattingContexts/inline/display/InlineDisplayBox.h:
(WebCore::InlineDisplay::Box::setLogicalRight):
* layout/layouttree/LayoutBoxGeometry.h:
(WebCore::Layout::BoxGeometry::borderAndPaddingEnd const):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (286517 => 286518)


--- trunk/Source/WebCore/ChangeLog	2021-12-03 23:21:12 UTC (rev 286517)
+++ trunk/Source/WebCore/ChangeLog	2021-12-03 23:42:45 UTC (rev 286518)
@@ -1,3 +1,21 @@
+2021-12-03  Alan Bujtas  <[email protected]>
+
+        [LFC][IFC] Move the (bidi)display boxes horizontally by the inline box margin, border and padding end as needed
+        https://bugs.webkit.org/show_bug.cgi?id=233744
+
+        Reviewed by Antti Koivisto.
+
+        Keep track of the inline box range in the context of display boxes so that we can adjust the content horizontally
+        with the margin/border/padding end of the "last" inline box.
+        We also set the width of the (fragmented inline box type of) display boxes here based on their content right position.
+
+        * layout/formattingContexts/inline/InlineDisplayContentBuilder.cpp:
+        (WebCore::Layout::InlineDisplayContentBuilder::processBidiContent):
+        * layout/formattingContexts/inline/display/InlineDisplayBox.h:
+        (WebCore::InlineDisplay::Box::setLogicalRight):
+        * layout/layouttree/LayoutBoxGeometry.h:
+        (WebCore::Layout::BoxGeometry::borderAndPaddingEnd const):
+
 2021-12-03  Myles C. Maxfield  <[email protected]>
 
         Fix internal Apple builds

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


--- trunk/Source/WebCore/layout/formattingContexts/inline/InlineDisplayContentBuilder.cpp	2021-12-03 23:21:12 UTC (rev 286517)
+++ trunk/Source/WebCore/layout/formattingContexts/inline/InlineDisplayContentBuilder.cpp	2021-12-03 23:42:45 UTC (rev 286518)
@@ -34,7 +34,10 @@
 #include "RuntimeEnabledFeatures.h"
 #include "TextUtil.h"
 #include <wtf/ListHashSet.h>
+#include <wtf/Range.h>
 
+using WTF::Range;
+
 namespace WebCore {
 namespace Layout {
 
@@ -357,6 +360,7 @@
 {
     ASSERT(lineContent.visualOrderList.size() == lineContent.runs.size());
 
+    Vector<Range<size_t>> inlineBoxRangeList;
     auto needsNonRootInlineBoxDisplayBox = false;
     auto createDisplayBoxesInVisualOrderForContentRuns = [&] {
         auto rootInlineBoxRect = lineBox.logicalRectForRootInlineBox();
@@ -457,6 +461,8 @@
 
                     for (auto* inlineBox : makeReversedRange(inlineBoxFragmentsToClose)) {
                         ASSERT(inlineBox->isInlineBox());
+                        ASSERT(inlineBoxDisplayBoxMap.contains(inlineBox));
+                        inlineBoxRangeList.append({ inlineBoxDisplayBoxMap.get(inlineBox), index });
                         parentBoxStack.remove(inlineBox);
                     }
 
@@ -498,11 +504,18 @@
                 inlineBoxNeedingDisplayBoxList.append(ancestor);
             }
         }
+        // "Close" the remaining inline boxes on the stack (excluding the root).
+        while (parentBoxStack.size() > 1) {
+            auto* parentInlineBox = parentBoxStack.takeLast();
+            ASSERT(inlineBoxDisplayBoxMap.contains(parentInlineBox));
+            inlineBoxRangeList.append({ inlineBoxDisplayBoxMap.get(parentInlineBox), boxes.size() });
+        }
     };
     if (needsNonRootInlineBoxDisplayBox)
         createDisplayBoxesInVisualOrderForInlineBoxes();
 
     auto adjustVisualGeometryWithInlineBoxes = [&] {
+        size_t currentInlineBox = 0;
         auto accumulatedOffset = InlineLayoutUnit { };
 
         ASSERT(boxes[0].isRootInlineBox());
@@ -510,8 +523,22 @@
             auto& displayBox = boxes[index];
             displayBox.moveHorizontally(accumulatedOffset);
 
+            while (currentInlineBox < inlineBoxRangeList.size() && index == inlineBoxRangeList[currentInlineBox].end() - 1) {
+                // We are at the end of the inline box content.
+                // Let's compute the inline box width and offset the rest of the content with padding/border/margin end.
+                auto inlineBoxRange = inlineBoxRangeList[currentInlineBox++];
+                auto& inlineBoxDisplayBox = boxes[inlineBoxRange.begin()];
+                ASSERT(inlineBoxDisplayBox.isNonRootInlineBox());
+
+                auto& boxGeometry = formattingState().boxGeometry(inlineBoxDisplayBox.layoutBox());
+                auto contentRight = displayBox.logicalRight();
+                if (inlineBoxDisplayBox.isLastBox()) {
+                    accumulatedOffset += boxGeometry.borderAndPaddingEnd() + boxGeometry.marginEnd();
+                    inlineBoxDisplayBox.setLogicalRight(contentRight + boxGeometry.borderAndPaddingEnd());
+                } else
+                    inlineBoxDisplayBox.setLogicalRight(contentRight);
+            }
             if (displayBox.isNonRootInlineBox() && displayBox.isFirstBox()) {
-                // FIXME: Add support for the 'end' side of the inline box.
                 auto& layoutBox = displayBox.layoutBox();
                 auto& boxGeometry = formattingState().boxGeometry(layoutBox);
 

Modified: trunk/Source/WebCore/layout/formattingContexts/inline/display/InlineDisplayBox.h (286517 => 286518)


--- trunk/Source/WebCore/layout/formattingContexts/inline/display/InlineDisplayBox.h	2021-12-03 23:21:12 UTC (rev 286517)
+++ trunk/Source/WebCore/layout/formattingContexts/inline/display/InlineDisplayBox.h	2021-12-03 23:42:45 UTC (rev 286518)
@@ -109,6 +109,7 @@
     void moveHorizontally(Layout::InlineLayoutUnit offset) { m_logicalRect.moveHorizontally(offset); }
     void adjustInkOverflow(const Layout::InlineRect& childBorderBox) { return m_inkOverflow.expandToContain(childBorderBox); }
     void truncate(Layout::InlineLayoutUnit truncatedwidth = 0.f);
+    void setLogicalRight(Layout::InlineLayoutUnit right) { m_logicalRect.setRight(right); }
 
     std::optional<Text>& text() { return m_text; }
     const std::optional<Text>& text() const { return m_text; }

Modified: trunk/Source/WebCore/layout/layouttree/LayoutBoxGeometry.h (286517 => 286518)


--- trunk/Source/WebCore/layout/layouttree/LayoutBoxGeometry.h	2021-12-03 23:21:12 UTC (rev 286517)
+++ trunk/Source/WebCore/layout/layouttree/LayoutBoxGeometry.h	2021-12-03 23:42:45 UTC (rev 286518)
@@ -78,6 +78,7 @@
     std::optional<LayoutUnit> horizontalPadding() const;
 
     LayoutUnit borderAndPaddingStart() const { return borderLeft() + paddingLeft().value_or(0); }
+    LayoutUnit borderAndPaddingEnd() const { return borderRight() + paddingRight().value_or(0); }
 
     LayoutUnit contentBoxTop() const { return paddingBoxTop() + paddingTop().value_or(0); }
     LayoutUnit contentBoxLeft() const { return paddingBoxLeft() + paddingLeft().value_or(0); }
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to