⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 287028 in webkit


Ignore:
Timestamp:
Dec 14, 2021, 9:20:18 AM (5 years ago)
Author:
Alan Bujtas
Message:

[LFC][IFC] Make the LineBox content (text runs and inline level boxes) relative to the root inline box.
https://bugs.webkit.org/show_bug.cgi?id=234285

Reviewed by Antti Koivisto.

Let's decouple the root inline box's logical left and the text-align based horizontal offset and
also make the content inside the root inline box relative to it.
This is in preparation for handling text-align with non-RTL content.

  • layout/formattingContexts/inline/InlineDisplayContentBuilder.cpp:

(WebCore::Layout::InlineDisplayContentBuilder::processNonBidiContent):
(WebCore::Layout::InlineDisplayContentBuilder::processBidiContent):

  • layout/formattingContexts/inline/InlineLineBox.cpp:

(WebCore::Layout::LineBox::LineBox):
(WebCore::Layout::LineBox::logicalRectForTextRun const):

  • layout/formattingContexts/inline/InlineLineBox.h:

(WebCore::Layout::LineBox::rootInlineBoxAlignmentOffset const):

  • layout/formattingContexts/inline/InlineLineBoxBuilder.cpp:

(WebCore::Layout::LineBoxBuilder::build):

Location:
trunk/Source/WebCore
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r287023 r287028  
     12021-12-14  Alan Bujtas  <zalan@apple.com>
     2
     3        [LFC][IFC] Make the LineBox content (text runs and inline level boxes) relative to the root inline box.
     4        https://bugs.webkit.org/show_bug.cgi?id=234285
     5
     6        Reviewed by Antti Koivisto.
     7
     8        Let's decouple the root inline box's logical left and the text-align based horizontal offset and
     9        also make the content inside the root inline box relative to it.
     10        This is in preparation for handling text-align with non-RTL content.
     11
     12        * layout/formattingContexts/inline/InlineDisplayContentBuilder.cpp:
     13        (WebCore::Layout::InlineDisplayContentBuilder::processNonBidiContent):
     14        (WebCore::Layout::InlineDisplayContentBuilder::processBidiContent):
     15        * layout/formattingContexts/inline/InlineLineBox.cpp:
     16        (WebCore::Layout::LineBox::LineBox):
     17        (WebCore::Layout::LineBox::logicalRectForTextRun const):
     18        * layout/formattingContexts/inline/InlineLineBox.h:
     19        (WebCore::Layout::LineBox::rootInlineBoxAlignmentOffset const):
     20        * layout/formattingContexts/inline/InlineLineBoxBuilder.cpp:
     21        (WebCore::Layout::LineBoxBuilder::build):
     22
    1232021-12-14  Rob Buis  <rbuis@igalia.com>
    224
  • trunk/Source/WebCore/layout/formattingContexts/inline/InlineDisplayContentBuilder.cpp

    r286957 r287028  
    290290{
    291291    // Create the inline boxes on the current line. This is mostly text and atomic inline boxes.
     292    auto rootInlineBoxAlignmentOffset = lineBox.rootInlineBoxAlignmentOffset();
     293
    292294    for (auto& lineRun : lineContent.runs) {
    293295        auto& layoutBox = lineRun.layoutBox();
    294296
    295297        auto logicalRectRelativeToRoot = [&](auto logicalRect) {
    296             logicalRect.moveBy(lineBoxLogicalTopLeft);
     298            logicalRect.moveBy({ lineBoxLogicalTopLeft.x() + rootInlineBoxAlignmentOffset, lineBoxLogicalTopLeft.y() });
    297299            return logicalRect;
    298300        };
     
    482484    ancestorStack.push({ }, root());
    483485
     486    auto rootInlineBoxAlignmentOffset = lineBox.rootInlineBoxAlignmentOffset();
    484487    auto contentStartInVisualOrder = InlineLayoutUnit { };
    485488    auto createDisplayBoxesInVisualOrder = [&] {
     
    491494        }
    492495        // Adjust the content start position with the (text)alignment offset (root inline box has the alignment offset and not the individual runs).
    493         contentStartInVisualOrder += rootInlineBoxRect.left();
     496        contentStartInVisualOrder += rootInlineBoxAlignmentOffset;
    494497
    495498        auto contentRightInVisualOrder = contentStartInVisualOrder;
  • trunk/Source/WebCore/layout/formattingContexts/inline/InlineLineBox.cpp

    r283715 r287028  
    3535namespace Layout {
    3636
    37 LineBox::LineBox(const Box& rootLayoutBox, InlineLayoutUnit contentLogicalLeft, InlineLayoutUnit contentLogicalWidth, size_t lineIndex, size_t nonSpanningInlineLevelBoxCount)
    38     : m_rootInlineBox({ rootLayoutBox, !lineIndex ? rootLayoutBox.firstLineStyle() : rootLayoutBox.style(), contentLogicalLeft, InlineLayoutSize { contentLogicalWidth, { } }, InlineLevelBox::Type::RootInlineBox })
     37LineBox::LineBox(const Box& rootLayoutBox, InlineLayoutUnit rootInlineBoxAlignmentOffset, InlineLayoutUnit contentLogicalWidth, size_t lineIndex, size_t nonSpanningInlineLevelBoxCount)
     38    : m_rootInlineBoxAlignmentOffset(rootInlineBoxAlignmentOffset)
     39    , m_rootInlineBox({ rootLayoutBox, !lineIndex ? rootLayoutBox.firstLineStyle() : rootLayoutBox.style(), { }, InlineLayoutSize { contentLogicalWidth, { } }, InlineLevelBox::Type::RootInlineBox })
    3940{
    4041    m_nonRootInlineLevelBoxList.reserveInitialCapacity(nonSpanningInlineLevelBoxCount);
     
    6364    }
    6465    InlineLayoutUnit logicalHeight = fontMetrics.height();
    65     return { runlogicalTop, m_rootInlineBox.logicalLeft() + run.logicalLeft(), run.logicalWidth(), logicalHeight };
     66    return { runlogicalTop, run.logicalLeft(), run.logicalWidth(), logicalHeight };
    6667}
    6768
  • trunk/Source/WebCore/layout/formattingContexts/inline/InlineLineBox.h

    r283314 r287028  
    6060    WTF_MAKE_FAST_ALLOCATED;
    6161public:
    62     LineBox(const Box& rootLayoutBox, InlineLayoutUnit contentLogicalLeft, InlineLayoutUnit contentLogicalWidth, size_t lineIndex, size_t nonSpanningInlineLevelBoxCount);
     62    LineBox(const Box& rootLayoutBox, InlineLayoutUnit rootInlineBoxAlignmentOffset, InlineLayoutUnit contentLogicalWidth, size_t lineIndex, size_t nonSpanningInlineLevelBoxCount);
    6363
    6464    // Note that the line can have many inline boxes and be "empty" the same time e.g. <div><span></span><span></span></div>
     
    8080    const InlineLevelBoxList& nonRootInlineLevelBoxes() const { return m_nonRootInlineLevelBoxList; }
    8181
     82    InlineLayoutUnit rootInlineBoxAlignmentOffset() const { return m_rootInlineBoxAlignmentOffset; }
     83
    8284private:
    8385    friend class LineBoxBuilder;
     
    98100    OptionSet<InlineLevelBox::Type> m_boxTypes;
    99101
     102    InlineLayoutUnit m_rootInlineBoxAlignmentOffset { 0 };
    100103    InlineLevelBox m_rootInlineBox;
    101104    InlineLevelBoxList m_nonRootInlineLevelBoxList;
  • trunk/Source/WebCore/layout/formattingContexts/inline/InlineLineBoxBuilder.cpp

    r284432 r287028  
    101101{
    102102    auto textAlign = !lineIndex ? rootBox().firstLineStyle().textAlign() : rootBox().style().textAlign();
    103     auto contentLogicalLeft = Layout::horizontalAlignmentOffset(textAlign, lineContent).value_or(InlineLayoutUnit { });
    104     auto lineBox = LineBox { rootBox(), contentLogicalLeft, lineContent.contentLogicalWidth, lineIndex, lineContent.nonSpanningInlineLevelBoxCount };
     103    auto rootInlineBoxAlignmentOffset = Layout::horizontalAlignmentOffset(textAlign, lineContent).value_or(InlineLayoutUnit { });
     104    auto lineBox = LineBox { rootBox(), rootInlineBoxAlignmentOffset, lineContent.contentLogicalWidth, lineIndex, lineContent.nonSpanningInlineLevelBoxCount };
    105105
    106106    auto lineBoxLogicalHeight = constructAndAlignInlineLevelBoxes(lineBox, lineContent.runs, lineIndex);
     
    141141            enclosingTopAndBottom.bottom = std::max(enclosingTopAndBottom.bottom, borderBox.bottom());
    142142        }
    143         return InlineDisplay::Line { lineBoxLogicalRect, scrollableOverflowRect, enclosingTopAndBottom, rootInlineBox.logicalTop() + rootInlineBox.baseline(), rootInlineBox.logicalLeft(), rootInlineBox.logicalWidth() };
     143        return InlineDisplay::Line { lineBoxLogicalRect, scrollableOverflowRect, enclosingTopAndBottom, rootInlineBox.logicalTop() + rootInlineBox.baseline(), rootInlineBoxAlignmentOffset + rootInlineBox.logicalLeft(), rootInlineBox.logicalWidth() };
    144144    };
    145145    return { line(), lineBox };
Note: See TracChangeset for help on using the changeset viewer.