Title: [287314] trunk/Source/WebCore
Revision
287314
Author
[email protected]
Date
2021-12-21 08:01:13 -0800 (Tue, 21 Dec 2021)

Log Message

[LFC][IFC] Display content builder should take Display::Line
https://bugs.webkit.org/show_bug.cgi?id=234527

Reviewed by Antti Koivisto.

This is preparation for using Display::Line visual geometries when constructing Display::Boxes in InlineDisplayContentBuilder.

* layout/formattingContexts/inline/InlineFormattingContext.cpp:
(WebCore::Layout::InlineFormattingContext::computeGeometryForLineContent):
* layout/formattingContexts/inline/display/InlineDisplayContentBuilder.cpp:
(WebCore::Layout::InlineDisplayContentBuilder::build):
(WebCore::Layout::InlineDisplayContentBuilder::processNonBidiContent):
(WebCore::Layout::InlineDisplayContentBuilder::adjustVisualGeometryForDisplayBox):
(WebCore::Layout::InlineDisplayContentBuilder::processBidiContent):
(WebCore::Layout::InlineDisplayContentBuilder::processOverflownRunsForEllipsis):
* layout/formattingContexts/inline/display/InlineDisplayContentBuilder.h:
* layout/formattingContexts/inline/display/InlineDisplayLineBuilder.cpp:
(WebCore::Layout::InlineDisplayLineBuilder::build):
* layout/integration/LayoutIntegrationCoverage.cpp:
(WebCore::LayoutIntegration::canUseForStyle):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (287313 => 287314)


--- trunk/Source/WebCore/ChangeLog	2021-12-21 14:07:08 UTC (rev 287313)
+++ trunk/Source/WebCore/ChangeLog	2021-12-21 16:01:13 UTC (rev 287314)
@@ -1,3 +1,26 @@
+2021-12-21  Alan Bujtas  <[email protected]>
+
+        [LFC][IFC] Display content builder should take Display::Line
+        https://bugs.webkit.org/show_bug.cgi?id=234527
+
+        Reviewed by Antti Koivisto.
+
+        This is preparation for using Display::Line visual geometries when constructing Display::Boxes in InlineDisplayContentBuilder.
+
+        * layout/formattingContexts/inline/InlineFormattingContext.cpp:
+        (WebCore::Layout::InlineFormattingContext::computeGeometryForLineContent):
+        * layout/formattingContexts/inline/display/InlineDisplayContentBuilder.cpp:
+        (WebCore::Layout::InlineDisplayContentBuilder::build):
+        (WebCore::Layout::InlineDisplayContentBuilder::processNonBidiContent):
+        (WebCore::Layout::InlineDisplayContentBuilder::adjustVisualGeometryForDisplayBox):
+        (WebCore::Layout::InlineDisplayContentBuilder::processBidiContent):
+        (WebCore::Layout::InlineDisplayContentBuilder::processOverflownRunsForEllipsis):
+        * layout/formattingContexts/inline/display/InlineDisplayContentBuilder.h:
+        * layout/formattingContexts/inline/display/InlineDisplayLineBuilder.cpp:
+        (WebCore::Layout::InlineDisplayLineBuilder::build):
+        * layout/integration/LayoutIntegrationCoverage.cpp:
+        (WebCore::LayoutIntegration::canUseForStyle):
+
 2021-12-21  Sam Weinig  <[email protected]>
 
         Add support for premultiplied alpha interpolated gradients and defaulted off option to use them for CSS Gradients

Modified: trunk/Source/WebCore/layout/formattingContexts/inline/InlineFormattingContext.cpp (287313 => 287314)


--- trunk/Source/WebCore/layout/formattingContexts/inline/InlineFormattingContext.cpp	2021-12-21 14:07:08 UTC (rev 287313)
+++ trunk/Source/WebCore/layout/formattingContexts/inline/InlineFormattingContext.cpp	2021-12-21 16:01:13 UTC (rev 287314)
@@ -552,17 +552,21 @@
     auto& formattingState = this->formattingState();
     auto currentLineIndex = formattingState.lines().size();
 
-    auto lineBoxAndHeight = LineBoxBuilder(*this).build(lineContent, currentLineIndex);
-
-    auto displayLine = InlineDisplayLineBuilder(*this).build(lineContent, lineBoxAndHeight.lineBox, lineBoxAndHeight.lineBoxLogicalHeight, currentLineIndex);
-    auto displayLineBoxRect = displayLine.lineBoxRect();
-
-    auto inlineContentBuilder = InlineDisplayContentBuilder { root(), formattingState };
-    formattingState.addBoxes(inlineContentBuilder.build(lineContent, lineBoxAndHeight.lineBox, displayLineBoxRect, currentLineIndex));
+    auto lineBoxAndHeight = LineBoxBuilder { *this }.build(lineContent, currentLineIndex);
+    auto displayLine = InlineDisplayLineBuilder { *this }.build(lineContent
+        , lineBoxAndHeight.lineBox
+        , lineBoxAndHeight.lineBoxLogicalHeight
+        , currentLineIndex
+    );
+    formattingState.addBoxes(InlineDisplayContentBuilder { root(), formattingState }.build(lineContent
+        , lineBoxAndHeight.lineBox
+        , displayLine
+        , currentLineIndex)
+    );
     formattingState.addLineBox(WTFMove(lineBoxAndHeight.lineBox));
     formattingState.addLine(displayLine);
 
-    return displayLineBoxRect;
+    return formattingState.lines().last().lineBoxRect();
 }
 
 void InlineFormattingContext::invalidateFormattingState()

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


--- trunk/Source/WebCore/layout/formattingContexts/inline/display/InlineDisplayContentBuilder.cpp	2021-12-21 14:07:08 UTC (rev 287313)
+++ trunk/Source/WebCore/layout/formattingContexts/inline/display/InlineDisplayContentBuilder.cpp	2021-12-21 16:01:13 UTC (rev 287314)
@@ -87,23 +87,24 @@
 {
 }
 
-DisplayBoxes InlineDisplayContentBuilder::build(const LineBuilder::LineContent& lineContent, const LineBox& lineBox, const InlineRect& lineBoxLogicalRect, const size_t lineIndex)
+DisplayBoxes InlineDisplayContentBuilder::build(const LineBuilder::LineContent& lineContent, const LineBox& lineBox, const InlineDisplay::Line displayLine, const size_t lineIndex)
 {
     DisplayBoxes boxes;
     boxes.reserveInitialCapacity(lineContent.runs.size() + lineBox.nonRootInlineLevelBoxes().size() + 1);
 
     m_lineIndex = lineIndex;
+    auto lineBoxRect = displayLine.lineBoxRect();
     // Every line starts with a root box, even the empty ones.
     auto rootInlineBoxRect = lineBox.logicalRectForRootInlineBox();
-    rootInlineBoxRect.moveBy(lineBoxLogicalRect.topLeft());
+    rootInlineBoxRect.moveBy(lineBoxRect.topLeft());
     boxes.append({ m_lineIndex, InlineDisplay::Box::Type::RootInlineBox, root(), UBIDI_DEFAULT_LTR, rootInlineBoxRect, rootInlineBoxRect, { }, { }, lineBox.rootInlineBox().hasContent() });
 
     auto contentNeedsBidiReordering = !lineContent.visualOrderList.isEmpty();
     if (contentNeedsBidiReordering)
-        processBidiContent(lineContent, lineBox, lineBoxLogicalRect.topLeft(), boxes);
+        processBidiContent(lineContent, lineBox, lineBoxRect.topLeft(), boxes);
     else
-        processNonBidiContent(lineContent, lineBox, lineBoxLogicalRect.topLeft(), boxes);
-    processOverflownRunsForEllipsis(boxes, lineBoxLogicalRect.right());
+        processNonBidiContent(lineContent, lineBox, lineBoxRect.topLeft(), boxes);
+    processOverflownRunsForEllipsis(boxes, lineBoxRect.right());
     collectInkOverflowForInlineBoxes(boxes);
     return boxes;
 }
@@ -316,7 +317,7 @@
     });
 }
 
-void InlineDisplayContentBuilder::processNonBidiContent(const LineBuilder::LineContent& lineContent, const LineBox& lineBox, const InlineLayoutPoint& lineBoxLogicalTopLeft, DisplayBoxes& boxes)
+void InlineDisplayContentBuilder::processNonBidiContent(const LineBuilder::LineContent& lineContent, const LineBox& lineBox, const InlineLayoutPoint& lineBoxTopLeft, DisplayBoxes& boxes)
 {
     auto rootInlineBoxWidth = lineBox.logicalRectForRootInlineBox().width();
     auto rootInlineBoxAlignmentOffset = lineBox.rootInlineBoxAlignmentOffset();
@@ -328,7 +329,7 @@
         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() });
+            logicalRect.moveBy({ lineBoxTopLeft.x() + horizontalOffset, lineBoxTopLeft.y() });
             return logicalRect;
         };
 
@@ -457,7 +458,7 @@
     std::optional<size_t> last;
 };
 using IsFirstLastIndexesMap = HashMap<const Box*, IsFirstLastIndex>;
-void InlineDisplayContentBuilder::adjustVisualGeometryForDisplayBox(size_t displayBoxNodeIndex, InlineLayoutUnit& contentRightInVisualOrder, InlineLayoutUnit lineBoxLogicalTop, const DisplayBoxTree& displayBoxTree, DisplayBoxes& boxes, const LineBox& lineBox, const IsFirstLastIndexesMap& isFirstLastIndexesMap)
+void InlineDisplayContentBuilder::adjustVisualGeometryForDisplayBox(size_t displayBoxNodeIndex, InlineLayoutUnit& contentRightInVisualOrder, InlineLayoutUnit lineBoxTop, const DisplayBoxTree& displayBoxTree, DisplayBoxes& boxes, const LineBox& lineBox, const IsFirstLastIndexesMap& isFirstLastIndexesMap)
 {
     // Non-inline box display boxes just need a horizontal adjustment while
     // inline box type of display boxes need
@@ -492,7 +493,7 @@
     auto isLastBox = isFirstLastIndexes.last && *isFirstLastIndexes.last == displayBoxNodeIndex;
     auto beforeInlineBoxContent = [&] {
         auto logicalRect = lineBox.logicalBorderBoxForInlineBox(layoutBox, boxGeometry);
-        auto visualRect = InlineRect { lineBoxLogicalTop + logicalRect.top(), contentRightInVisualOrder, { }, logicalRect.height() };
+        auto visualRect = InlineRect { lineBoxTop + logicalRect.top(), contentRightInVisualOrder, { }, logicalRect.height() };
         auto shouldApplyLeftSide = (isLeftToRightDirection && isFirstBox) || (!isLeftToRightDirection && isLastBox);
         if (!shouldApplyLeftSide)
             return displayBox.setRect(visualRect, visualRect);
@@ -505,7 +506,7 @@
     beforeInlineBoxContent();
 
     for (auto childDisplayBoxNodeIndex : displayBoxTree.at(displayBoxNodeIndex).children)
-        adjustVisualGeometryForDisplayBox(childDisplayBoxNodeIndex, contentRightInVisualOrder, lineBoxLogicalTop, displayBoxTree, boxes, lineBox, isFirstLastIndexesMap);
+        adjustVisualGeometryForDisplayBox(childDisplayBoxNodeIndex, contentRightInVisualOrder, lineBoxTop, displayBoxTree, boxes, lineBox, isFirstLastIndexesMap);
 
     auto afterInlineBoxContent = [&] {
         auto shouldApplyRightSide = (isLeftToRightDirection && isLastBox) || (!isLeftToRightDirection && isFirstBox);
@@ -530,7 +531,7 @@
         displayBox.setHasContent();
 }
 
-void InlineDisplayContentBuilder::processBidiContent(const LineBuilder::LineContent& lineContent, const LineBox& lineBox, const InlineLayoutPoint& lineBoxLogicalTopLeft, DisplayBoxes& boxes)
+void InlineDisplayContentBuilder::processBidiContent(const LineBuilder::LineContent& lineContent, const LineBox& lineBox, const InlineLayoutPoint& lineBoxTopLeft, DisplayBoxes& boxes)
 {
     ASSERT(lineContent.visualOrderList.size() <= lineContent.runs.size());
 
@@ -559,7 +560,7 @@
 
             auto visualRectRelativeToRoot = [&](auto logicalRect) {
                 logicalRect.setLeft(contentRightInVisualOrder);
-                logicalRect.moveBy(lineBoxLogicalTopLeft);
+                logicalRect.moveBy(lineBoxTopLeft);
                 return logicalRect;
             };
 
@@ -637,16 +638,16 @@
         computeIsFirstIsLastBox();
 
         auto adjustVisualGeometryWithInlineBoxes = [&] {
-            auto contentRightInVisualOrder = lineBoxLogicalTopLeft.x() + contentStartInVisualOrder;
+            auto contentRightInVisualOrder = lineBoxTopLeft.x() + contentStartInVisualOrder;
 
             for (auto childDisplayBoxNodeIndex : displayBoxTree.root().children)
-                adjustVisualGeometryForDisplayBox(childDisplayBoxNodeIndex, contentRightInVisualOrder, lineBoxLogicalTopLeft.y(), displayBoxTree, boxes, lineBox, isFirstLastIndexesMap);
+                adjustVisualGeometryForDisplayBox(childDisplayBoxNodeIndex, contentRightInVisualOrder, lineBoxTopLeft.y(), displayBoxTree, boxes, lineBox, isFirstLastIndexesMap);
         };
         adjustVisualGeometryWithInlineBoxes();
     }
 }
 
-void InlineDisplayContentBuilder::processOverflownRunsForEllipsis(DisplayBoxes& boxes, InlineLayoutUnit lineBoxLogicalRight)
+void InlineDisplayContentBuilder::processOverflownRunsForEllipsis(DisplayBoxes& boxes, InlineLayoutUnit lineBoxRight)
 {
     if (root().style().textOverflow() != TextOverflow::Ellipsis)
         return;
@@ -654,8 +655,8 @@
     ASSERT(rootInlineBox.isRootInlineBox());
 
     auto rootInlineBoxRect = rootInlineBox.rect();
-    if (rootInlineBoxRect.right() <= lineBoxLogicalRight) {
-        ASSERT(boxes.last().right() <= lineBoxLogicalRight);
+    if (rootInlineBoxRect.right() <= lineBoxRight) {
+        ASSERT(boxes.last().right() <= lineBoxRight);
         return;
     }
 
@@ -667,7 +668,7 @@
     for (auto index = boxes.size(); index--;) {
         auto& displayBox = boxes[index];
 
-        if (displayBox.left() >= lineBoxLogicalRight) {
+        if (displayBox.left() >= lineBoxRight) {
             // Fully overflown boxes are collapsed.
             displayBox.truncate();
             continue;
@@ -676,7 +677,7 @@
         // We keep truncating content until after we can accommodate the ellipsis content
         // 1. fully truncate in case of inline level boxes (ie non-text content) or if ellipsis content is wider than the overflowing one.
         // 2. partially truncated to make room for the ellipsis box.
-        auto availableRoomForEllipsis = lineBoxLogicalRight - displayBox.left();
+        auto availableRoomForEllipsis = lineBoxRight - displayBox.left();
         if (availableRoomForEllipsis <= ellipsisWidth) {
             // Can't accommodate the ellipsis content here. We need to truncate non-overflowing boxes too.
             displayBox.truncate();

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


--- trunk/Source/WebCore/layout/formattingContexts/inline/display/InlineDisplayContentBuilder.h	2021-12-21 14:07:08 UTC (rev 287313)
+++ trunk/Source/WebCore/layout/formattingContexts/inline/display/InlineDisplayContentBuilder.h	2021-12-21 16:01:13 UTC (rev 287314)
@@ -44,14 +44,14 @@
 public:
     InlineDisplayContentBuilder(const ContainerBox& formattingContextRoot, InlineFormattingState&);
 
-    DisplayBoxes build(const LineBuilder::LineContent&, const LineBox&, const InlineRect& lineBoxLogicalRect, const size_t lineIndex);
+    DisplayBoxes build(const LineBuilder::LineContent&, const LineBox&, const InlineDisplay::Line displayLine, const size_t lineIndex);
 
     static void computeIsFirstIsLastBoxForInlineContent(DisplayBoxes&);
 
 private:
-    void processNonBidiContent(const LineBuilder::LineContent&, const LineBox&, const InlineLayoutPoint& lineBoxLogicalTopLeft, DisplayBoxes&);
-    void processBidiContent(const LineBuilder::LineContent&, const LineBox&, const InlineLayoutPoint& lineBoxLogicalTopLeft, DisplayBoxes&);
-    void processOverflownRunsForEllipsis(DisplayBoxes&, InlineLayoutUnit lineBoxLogicalRight);
+    void processNonBidiContent(const LineBuilder::LineContent&, const LineBox&, const InlineLayoutPoint& lineBoxTopLeft, DisplayBoxes&);
+    void processBidiContent(const LineBuilder::LineContent&, const LineBox&, const InlineLayoutPoint& lineBoxTopLeft, DisplayBoxes&);
+    void processOverflownRunsForEllipsis(DisplayBoxes&, InlineLayoutUnit lineBoxRight);
     void collectInkOverflowForInlineBoxes(DisplayBoxes&);
 
     void appendTextDisplayBox(const Line::Run&, const InlineRect&, DisplayBoxes&);
@@ -63,7 +63,7 @@
     void appendInlineDisplayBoxAtBidiBoundary(const Box&, DisplayBoxes&);
 
     void setInlineBoxGeometry(const Box&, const InlineRect&, bool isFirstInlineBoxFragment);
-    void adjustVisualGeometryForDisplayBox(size_t displayBoxNodeIndex, InlineLayoutUnit& accumulatedOffset, InlineLayoutUnit lineBoxLogicalTop, const DisplayBoxTree&, DisplayBoxes&, const LineBox&, const HashMap<const Box*, IsFirstLastIndex>&);
+    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&);
 
     const ContainerBox& root() const { return m_formattingContextRoot; }

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


--- trunk/Source/WebCore/layout/formattingContexts/inline/display/InlineDisplayLineBuilder.cpp	2021-12-21 14:07:08 UTC (rev 287313)
+++ trunk/Source/WebCore/layout/formattingContexts/inline/display/InlineDisplayLineBuilder.cpp	2021-12-21 16:01:13 UTC (rev 287314)
@@ -38,14 +38,14 @@
 InlineDisplay::Line InlineDisplayLineBuilder::build(const LineBuilder::LineContent& lineContent, const LineBox& lineBox, InlineLayoutUnit lineBoxLogicalHeight, size_t lineIndex)
 {
     auto& rootStyle = lineIndex ? root().firstLineStyle() : root().style();
-    auto physicalLeft = lineContent.lineLogicalTopLeft.x();
+    auto visualLeft = lineContent.lineLogicalTopLeft.x();
     if (!rootStyle.isLeftToRightDirection()) {
         // https://drafts.csswg.org/css-text/#text-indent-property
         // Since text-indent only initiates margin start, we just need to pull the linebox back to the left.
-        physicalLeft -= lineContent.lineMarginStart;
+        visualLeft -= lineContent.lineMarginStart;
     }
     // FIXME: Use physical geometry here.
-    auto lineBoxRect = InlineRect { lineContent.lineLogicalTopLeft.y(), physicalLeft, lineContent.lineLogicalWidth, lineBoxLogicalHeight };
+    auto lineBoxRect = InlineRect { lineContent.lineLogicalTopLeft.y(), visualLeft, lineContent.lineLogicalWidth, lineBoxLogicalHeight };
     auto scrollableOverflowRect = lineBoxRect;
     auto& rootInlineBox = lineBox.rootInlineBox();
     auto enclosingTopAndBottom = InlineDisplay::Line::EnclosingTopAndBottom { lineBoxRect.top() + rootInlineBox.logicalTop(), lineBoxRect.top() + rootInlineBox.logicalBottom() };
@@ -79,7 +79,13 @@
         enclosingTopAndBottom.top = std::min(enclosingTopAndBottom.top, borderBox.top());
         enclosingTopAndBottom.bottom = std::max(enclosingTopAndBottom.bottom, borderBox.bottom());
     }
-    return InlineDisplay::Line { lineBoxRect, scrollableOverflowRect, enclosingTopAndBottom, rootInlineBox.logicalTop() + rootInlineBox.baseline(), lineBox.rootInlineBoxAlignmentOffset() + rootInlineBox.logicalLeft(), rootInlineBox.logicalWidth() };
+    return InlineDisplay::Line { lineBoxRect
+        , scrollableOverflowRect
+        , enclosingTopAndBottom
+        , rootInlineBox.logicalTop() + rootInlineBox.baseline()
+        , lineBox.rootInlineBoxAlignmentOffset() + rootInlineBox.logicalLeft()
+        , rootInlineBox.logicalWidth()
+    };
 }
 
 }
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to