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

Changeset 287043 in webkit


Ignore:
Timestamp:
Dec 14, 2021, 12:57:19 PM (5 years ago)
Author:
Alan Bujtas
Message:

[LFC][IFC] Take text-align offset into account when computing the RTL display box geometry
https://bugs.webkit.org/show_bug.cgi?id=234287

Reviewed by Antti Koivisto.

Use LineBox::rootInlineBoxAlignmentOffset to offset the visual start position for RTL display boxes.

  • layout/formattingContexts/inline/InlineDisplayContentBuilder.cpp:

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

Location:
trunk/Source/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r287040 r287043  
     12021-12-14  Alan Bujtas  <zalan@apple.com>
     2
     3        [LFC][IFC] Take text-align offset into account when computing the RTL display box geometry
     4        https://bugs.webkit.org/show_bug.cgi?id=234287
     5
     6        Reviewed by Antti Koivisto.
     7
     8        Use LineBox::rootInlineBoxAlignmentOffset to offset the visual start position for RTL display boxes.
     9
     10        * layout/formattingContexts/inline/InlineDisplayContentBuilder.cpp:
     11        (WebCore::Layout::InlineDisplayContentBuilder::processNonBidiContent):
     12        (WebCore::Layout::InlineDisplayContentBuilder::processBidiContent):
     13
    1142021-12-14  Alex Christensen  <achristensen@webkit.org>
    215
  • trunk/Source/WebCore/layout/formattingContexts/inline/InlineDisplayContentBuilder.cpp

    r287028 r287043  
    289289void InlineDisplayContentBuilder::processNonBidiContent(const LineBuilder::LineContent& lineContent, const LineBox& lineBox, const InlineLayoutPoint& lineBoxLogicalTopLeft, DisplayBoxes& boxes)
    290290{
    291     // Create the inline boxes on the current line. This is mostly text and atomic inline boxes.
     291    auto rootInlineBoxWidth = lineBox.logicalRectForRootInlineBox().width();
    292292    auto rootInlineBoxAlignmentOffset = lineBox.rootInlineBoxAlignmentOffset();
     293    auto needsDirectionAdjustment = !root().style().isLeftToRightDirection();
    293294
    294295    for (auto& lineRun : lineContent.runs) {
    295296        auto& layoutBox = lineRun.layoutBox();
    296297
    297         auto logicalRectRelativeToRoot = [&](auto logicalRect) {
    298             logicalRect.moveBy({ lineBoxLogicalTopLeft.x() + rootInlineBoxAlignmentOffset, lineBoxLogicalTopLeft.y() });
     298        auto visualRectRelativeToRoot = [&](auto logicalRect) {
     299            // When the logical order == visual order, RTL inline direction is just an offset.
     300            auto horizontalOffset = needsDirectionAdjustment ? lineContent.lineLogicalWidth - rootInlineBoxWidth - rootInlineBoxAlignmentOffset : rootInlineBoxAlignmentOffset;
     301            logicalRect.moveBy({ lineBoxLogicalTopLeft.x() + horizontalOffset, lineBoxLogicalTopLeft.y() });
    299302            return logicalRect;
    300303        };
    301304
    302305        if (lineRun.isText()) {
    303             appendTextDisplayBox(lineRun, logicalRectRelativeToRoot(lineBox.logicalRectForTextRun(lineRun)), boxes);
     306            appendTextDisplayBox(lineRun, visualRectRelativeToRoot(lineBox.logicalRectForTextRun(lineRun)), boxes);
    304307            continue;
    305308        }
    306309        if (lineRun.isSoftLineBreak()) {
    307             appendSoftLineBreakDisplayBox(lineRun, logicalRectRelativeToRoot(lineBox.logicalRectForTextRun(lineRun)), boxes);
     310            appendSoftLineBreakDisplayBox(lineRun, visualRectRelativeToRoot(lineBox.logicalRectForTextRun(lineRun)), boxes);
    308311            continue;
    309312        }
    310313        if (lineRun.isHardLineBreak()) {
    311             appendHardLineBreakDisplayBox(lineRun, logicalRectRelativeToRoot(lineBox.logicalRectForLineBreakBox(layoutBox)), boxes);
     314            appendHardLineBreakDisplayBox(lineRun, visualRectRelativeToRoot(lineBox.logicalRectForLineBreakBox(layoutBox)), boxes);
    312315            continue;
    313316        }
    314317        if (lineRun.isBox()) {
    315318            appendAtomicInlineLevelDisplayBox(lineRun
    316                 , logicalRectRelativeToRoot(lineBox.logicalBorderBoxForAtomicInlineLevelBox(layoutBox, formattingState().boxGeometry(layoutBox)))
     319                , visualRectRelativeToRoot(lineBox.logicalBorderBoxForAtomicInlineLevelBox(layoutBox, formattingState().boxGeometry(layoutBox)))
    317320                , boxes);
    318321            continue;
     
    321324            appendInlineBoxDisplayBox(lineRun
    322325                , lineBox.inlineLevelBoxForLayoutBox(lineRun.layoutBox())
    323                 , logicalRectRelativeToRoot(lineBox.logicalBorderBoxForInlineBox(layoutBox, formattingState().boxGeometry(layoutBox)))
     326                , visualRectRelativeToRoot(lineBox.logicalBorderBoxForInlineBox(layoutBox, formattingState().boxGeometry(layoutBox)))
    324327                , lineBox.hasContent()
    325328                , boxes);
     
    335338            appendSpanningInlineBoxDisplayBox(lineRun
    336339                , lineBox.inlineLevelBoxForLayoutBox(lineRun.layoutBox())
    337                 , logicalRectRelativeToRoot(lineBox.logicalBorderBoxForInlineBox(layoutBox, formattingState().boxGeometry(layoutBox)))
     340                , visualRectRelativeToRoot(lineBox.logicalBorderBoxForInlineBox(layoutBox, formattingState().boxGeometry(layoutBox)))
    338341                , boxes);
    339342            continue;
     
    485488
    486489    auto rootInlineBoxAlignmentOffset = lineBox.rootInlineBoxAlignmentOffset();
    487     auto contentStartInVisualOrder = InlineLayoutUnit { };
     490    auto contentStartInVisualOrder = rootInlineBoxAlignmentOffset;
    488491    auto createDisplayBoxesInVisualOrder = [&] {
    489         auto rootInlineBoxRect = lineBox.logicalRectForRootInlineBox();
    490492        // First visual run's initial content position depends on the block's inline direction.
    491         if (!root().style().isLeftToRightDirection()) {
    492             // FIXME: This needs the block end position instead of the lineLogicalWidth.
    493             contentStartInVisualOrder += lineContent.lineLogicalWidth - rootInlineBoxRect.width();
    494         }
    495         // Adjust the content start position with the (text)alignment offset (root inline box has the alignment offset and not the individual runs).
    496         contentStartInVisualOrder += rootInlineBoxAlignmentOffset;
     493        if (!root().style().isLeftToRightDirection())
     494            contentStartInVisualOrder = lineContent.lineLogicalWidth - lineBox.logicalRectForRootInlineBox().width() - rootInlineBoxAlignmentOffset;
    497495
    498496        auto contentRightInVisualOrder = contentStartInVisualOrder;
     
    508506                continue;
    509507
    510             auto visualRectRelativeToRoot = [&](auto logicallRect) {
    511                 logicallRect.setLeft(contentRightInVisualOrder);
    512                 logicallRect.moveBy(lineBoxLogicalTopLeft);
    513                 return logicallRect;
     508            auto visualRectRelativeToRoot = [&](auto logicalRect) {
     509                logicalRect.setLeft(contentRightInVisualOrder);
     510                logicalRect.moveBy(lineBoxLogicalTopLeft);
     511                return logicalRect;
    514512            };
    515513
Note: See TracChangeset for help on using the changeset viewer.