Title: [266462] trunk/Source/WebCore
Revision
266462
Author
za...@apple.com
Date
2020-09-02 08:37:21 -0700 (Wed, 02 Sep 2020)

Log Message

[LFC][IFC] Start constructing InlineBoxes for inline runs
https://bugs.webkit.org/show_bug.cgi?id=215168

Reviewed by Antti Koivisto.

In this transitional step we start constructing inline boxes. However at this point, each run gains a dedicated inline box.
While this is somewhat incorrect from the spec point of view, this is all internal and very tempoarary at this point.

* layout/inlineformatting/InlineFormattingContext.cpp:
(WebCore::Layout::InlineFormattingContext::setDisplayBoxesForLine):
* layout/inlineformatting/InlineLineBox.cpp:
(WebCore::Layout::LineBox::LineBox):
(WebCore::Layout::LineBox::rectForRun const):
(WebCore::Layout::LineBox::alignHorizontally):
(WebCore::Layout::LineBox::alignVertically):
(WebCore::Layout::LineBox::adjustBaselineAndLineHeight):
* layout/inlineformatting/InlineLineBox.h:
(WebCore::Layout::LineBox::InlineBox::InlineBox):
(WebCore::Layout::LineBox::inlineRectList const): Deleted.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (266461 => 266462)


--- trunk/Source/WebCore/ChangeLog	2020-09-02 15:35:57 UTC (rev 266461)
+++ trunk/Source/WebCore/ChangeLog	2020-09-02 15:37:21 UTC (rev 266462)
@@ -1,3 +1,25 @@
+2020-09-02  Zalan Bujtas  <za...@apple.com>
+
+        [LFC][IFC] Start constructing InlineBoxes for inline runs
+        https://bugs.webkit.org/show_bug.cgi?id=215168
+
+        Reviewed by Antti Koivisto.
+
+        In this transitional step we start constructing inline boxes. However at this point, each run gains a dedicated inline box.
+        While this is somewhat incorrect from the spec point of view, this is all internal and very tempoarary at this point.
+
+        * layout/inlineformatting/InlineFormattingContext.cpp:
+        (WebCore::Layout::InlineFormattingContext::setDisplayBoxesForLine):
+        * layout/inlineformatting/InlineLineBox.cpp:
+        (WebCore::Layout::LineBox::LineBox):
+        (WebCore::Layout::LineBox::rectForRun const):
+        (WebCore::Layout::LineBox::alignHorizontally):
+        (WebCore::Layout::LineBox::alignVertically):
+        (WebCore::Layout::LineBox::adjustBaselineAndLineHeight):
+        * layout/inlineformatting/InlineLineBox.h:
+        (WebCore::Layout::LineBox::InlineBox::InlineBox):
+        (WebCore::Layout::LineBox::inlineRectList const): Deleted.
+
 2020-09-02  Aditya Keerthi  <akeer...@apple.com>
 
         [macOS] Update date picker when the inner control is edited

Modified: trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContext.cpp (266461 => 266462)


--- trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContext.cpp	2020-09-02 15:35:57 UTC (rev 266461)
+++ trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContext.cpp	2020-09-02 15:37:21 UTC (rev 266462)
@@ -511,11 +511,8 @@
     auto lineIndex = inlineContent.lineBoxes.size();
     auto lineInkOverflow = lineBox.scrollableOverflow();
     // Compute box final geometry.
-    auto& runRectList = lineBox.inlineRectList();
-    auto& lineRuns = lineContent.runs;
-    for (size_t index = 0; index < lineRuns.size(); ++index) {
-        auto& lineRun = lineRuns.at(index);
-        auto logicalRect = runRectList[index];
+    for (auto& lineRun : lineContent.runs) {
+        auto& logicalRect = lineBox.rectForRun(lineRun);
         auto& layoutBox = lineRun.layoutBox();
 
         // Add final display runs to state first.

Modified: trunk/Source/WebCore/layout/inlineformatting/InlineLineBox.cpp (266461 => 266462)


--- trunk/Source/WebCore/layout/inlineformatting/InlineLineBox.cpp	2020-09-02 15:35:57 UTC (rev 266461)
+++ trunk/Source/WebCore/layout/inlineformatting/InlineLineBox.cpp	2020-09-02 15:37:21 UTC (rev 266462)
@@ -57,6 +57,7 @@
     , m_runs(runs)
     , m_rect(lineRect)
     , m_scrollableOverflow(lineRect)
+    , m_rootInlineBox(InlineBox { lineRect, { }, inlineFormattingContext.root() })
 {
 #if ASSERT_ENABLED
     m_hasValidAlignmentBaseline = true;
@@ -64,8 +65,8 @@
     auto& rootStyle = inlineFormattingContext.root().style();
     auto halfLeadingMetrics = this->halfLeadingMetrics(rootStyle.fontMetrics(), lineRect.height());
 
+    m_rootInlineBox.ascentAndDescent = halfLeadingMetrics;
     m_alignmentBaseline = halfLeadingMetrics.ascent;
-    m_rootInlineBox = InlineBox { halfLeadingMetrics };
 
     auto contentLogicalWidth = InlineLayoutUnit { };
     for (auto& run : m_runs) {
@@ -85,7 +86,9 @@
             // Non-replaced inline box (e.g. inline-block). It looks a bit misleading but their margin box is considered the content height here.
             return boxGeometry.marginBoxHeight();
         };
-        m_runRectList.append({ 0, run.logicalLeft(), run.logicalWidth(), runHeight() });
+        // FIXME: This is temporary. Do not make an inline box for each run.
+        m_inlineBoxList.append(InlineBox { { 0, run.logicalLeft(), run.logicalWidth(), runHeight() }, halfLeadingMetrics, run.layoutBox() });
+        m_runToInlineBoxMap.set(&run, m_inlineBoxList.size() - 1);
         contentLogicalWidth += run.logicalWidth();
     }
     m_scrollableOverflow.setWidth(std::max(lineRect.width(), contentLogicalWidth));
@@ -120,10 +123,10 @@
     if (computedHorizontalAlignment == TextAlignMode::Justify) {
         auto accumulatedExpansion = InlineLayoutUnit { };
         for (size_t index = 0; index < m_runs.size(); ++index) {
-            m_runRectList[index].moveHorizontally(accumulatedExpansion);
+            m_inlineBoxList[index].rect.moveHorizontally(accumulatedExpansion);
 
             auto horizontalExpansion = m_runs[index].expansion().horizontalExpansion;
-            m_runRectList[index].expandHorizontally(horizontalExpansion);
+            m_inlineBoxList[index].rect.expandHorizontally(horizontalExpansion);
             accumulatedExpansion += horizontalExpansion;
         }
         return;
@@ -153,8 +156,8 @@
     if (auto adjustment = adjustmentForAlignment(availableWidth)) {
         // FIXME: line box should not need to be moved, only the runs.
         m_rect.moveHorizontally(*adjustment);
-        for (auto& runRect : m_runRectList)
-            runRect.moveHorizontally(*adjustment);
+        for (auto& inlineBox : m_inlineBoxList)
+            inlineBox.rect.moveHorizontally(*adjustment);
     }
 }
 
@@ -161,11 +164,13 @@
 void LineBox::alignVertically()
 {
     adjustBaselineAndLineHeight();
-    for (size_t index = 0; index < m_runs.size(); ++index) {
+    for (size_t index = 0; index < m_inlineBoxList.size(); ++index) {
+        auto& inlineBox = m_inlineBoxList[index];
         auto& run = m_runs[index];
-        auto& runRect = m_runRectList[index];
+        auto& layoutBox = inlineBox.layoutBox;
+        auto inlineBoxHeight = inlineBox.rect.height();
+
         auto logicalTop = InlineLayoutUnit { };
-        auto& layoutBox = run.layoutBox();
         auto verticalAlign = layoutBox.style().verticalAlign();
         auto ascent = layoutBox.style().fontMetrics().ascent();
 
@@ -197,7 +202,7 @@
                 logicalTop = alignmentBaseline() - baselineFromMarginBox;
             } else {
                 auto& boxGeometry = formattingContext().geometryForBox(layoutBox);
-                logicalTop = alignmentBaseline() - (boxGeometry.verticalBorder() + boxGeometry.verticalPadding().valueOr(0_lu) + runRect.height() + boxGeometry.marginAfter());
+                logicalTop = alignmentBaseline() - (boxGeometry.verticalBorder() + boxGeometry.verticalPadding().valueOr(0_lu) + inlineBoxHeight + boxGeometry.marginAfter());
             }
             break;
         case VerticalAlign::Top:
@@ -204,18 +209,19 @@
             logicalTop = 0_lu;
             break;
         case VerticalAlign::Bottom:
-            logicalTop = logicalBottom() - runRect.height();
+            logicalTop = logicalBottom() - inlineBoxHeight;
             break;
         default:
             ASSERT_NOT_IMPLEMENTED_YET();
             break;
         }
-        runRect.setTop(logicalTop);
+        auto& inlineBoxRect = inlineBox.rect;
+        inlineBoxRect.setTop(logicalTop);
         // Adjust scrollable overflow if the run overflows the line.
-        m_scrollableOverflow.expandVerticallyToContain(runRect);
+        m_scrollableOverflow.expandVerticallyToContain(inlineBoxRect);
         // Convert runs from relative to the line top/left to the formatting root's border box top/left.
-        runRect.moveVertically(this->logicalTop());
-        runRect.moveHorizontally(logicalLeft());
+        inlineBoxRect.moveVertically(this->logicalTop());
+        inlineBoxRect.moveHorizontally(logicalLeft());
     }
 }
 
@@ -223,9 +229,11 @@
 {
     unsigned inlineContainerNestingLevel = 0;
     auto hasSeenDirectTextOrLineBreak = false;
-    for (auto& run : m_runs) {
-        auto& layoutBox = run.layoutBox();
+    for (size_t index = 0; index < m_inlineBoxList.size(); ++index) {
+        auto& inlineBox = m_inlineBoxList[index];
+        auto& layoutBox = inlineBox.layoutBox;
         auto& style = layoutBox.style();
+        auto& run = m_runs[index];
         if (run.isText() || run.isLineBreak()) {
             // For text content we set the baseline either through the initial strut (set by the formatting context root) or
             // through the inline container (start). Normally the text content itself does not stretch the line.

Modified: trunk/Source/WebCore/layout/inlineformatting/InlineLineBox.h (266461 => 266462)


--- trunk/Source/WebCore/layout/inlineformatting/InlineLineBox.h	2020-09-02 15:35:57 UTC (rev 266461)
+++ trunk/Source/WebCore/layout/inlineformatting/InlineLineBox.h	2020-09-02 15:37:21 UTC (rev 266462)
@@ -48,10 +48,11 @@
     WTF_MAKE_FAST_ALLOCATED;
 public:
     struct InlineBox {
-        InlineBox(const AscentAndDescent&);
-        InlineBox() = default;
+        InlineBox(const Display::InlineRect&, const AscentAndDescent&, const Box&);
 
+        Display::InlineRect rect;
         AscentAndDescent ascentAndDescent;
+        const Box& layoutBox;
     };
 
     enum class IsLastLineWithInlineContent { No, Yes };
@@ -58,9 +59,6 @@
     enum class IsLineVisuallyEmpty { No, Yes };
     LineBox(const InlineFormattingContext&, const Display::InlineRect&, const LineBuilder::RunList&, IsLineVisuallyEmpty, IsLastLineWithInlineContent);
 
-    using InlineRunRectList = Vector<Display::InlineRect, 10>;
-    const InlineRunRectList& inlineRectList() const { return m_runRectList; }
-
     InlineLayoutUnit logicalLeft() const { return m_rect.left(); }
     InlineLayoutUnit logicalRight() const { return m_rect.right(); }
     InlineLayoutUnit logicalTop() const { return m_rect.top(); }
@@ -90,6 +88,8 @@
     // -------------------    line logical bottom  -------------------
     InlineLayoutUnit alignmentBaseline() const;
 
+    const Display::InlineRect& rectForRun(const LineBuilder::Run& run) const { return m_inlineBoxList[m_runToInlineBoxMap.get(&run)].rect; }
+
 private:
     const AscentAndDescent& ascentAndDescent() const { return m_rootInlineBox.ascentAndDescent; }
 
@@ -103,7 +103,6 @@
     void alignHorizontally(InlineLayoutUnit availableWidth, IsLastLineWithInlineContent);
     void alignVertically();
     void adjustBaselineAndLineHeight();
-
     HangingContent collectHangingContent(IsLastLineWithInlineContent) const;
 
     const InlineFormattingContext& formattingContext() const { return m_inlineFormattingContext; }
@@ -119,11 +118,15 @@
     Display::InlineRect m_scrollableOverflow;
     InlineLayoutUnit m_alignmentBaseline { 0 };
     InlineBox m_rootInlineBox;
-    InlineRunRectList m_runRectList;
+    Vector<InlineBox> m_inlineBoxList;
+    // FIXME: This is temporary and will be replaced by an inline box map.
+    HashMap<const LineBuilder::Run*, size_t> m_runToInlineBoxMap;
 };
 
-inline LineBox::InlineBox::InlineBox(const AscentAndDescent& ascentAndDescent)
-    : ascentAndDescent(ascentAndDescent)
+inline LineBox::InlineBox::InlineBox(const Display::InlineRect& rect, const AscentAndDescent& ascentAndDescent, const Box& layoutBox)
+    : rect(rect)
+    , ascentAndDescent(ascentAndDescent)
+    , layoutBox(layoutBox)
 {
 }
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to