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

Changeset 288497 in webkit


Ignore:
Timestamp:
Jan 24, 2022, 5:54:47 PM (5 years ago)
Author:
Russell Epstein
Message:

Cherry-pick r287922. rdar://problem/87455957

[LFC][IFC] Incorrect negative margin handling (both left/right) with RTL inline base direction
​https://bugs.webkit.org/show_bug.cgi?id=235095

Reviewed by Antti Koivisto.

Source/WebCore:

The simplified negative margin handling on inline boxes does not work well with RTL inline base direction.
With LTR direction, we could just treat the negative left margin value (which pulls content to the left)
as part the "logical width" (may resulting in negative width values) and let this shorter width pull
the the adjoining content.
However this setup produces incorrect box positions when the inline base direction is RTL.
In this patch, we switch over to a more correct inline box positioning where the negative margin
affects the logical left while it does not make the run shorter anymore.

Test: fast/inline/rtl-negative-margins.html

  • layout/formattingContexts/inline/InlineLine.cpp: (WebCore::Layout::Line::appendInlineBoxStart): (WebCore::Layout::Line::appendNonReplacedInlineLevelBox):
  • layout/formattingContexts/inline/InlineLineBoxBuilder.cpp: (WebCore::Layout::LineBoxBuilder::constructAndAlignInlineLevelBoxes):
  • layout/formattingContexts/inline/InlineLineBuilder.cpp: (WebCore::Layout::LineBuilder::layoutInlineContent):
  • layout/formattingContexts/inline/InlineLineBuilder.h:
  • layout/formattingContexts/inline/display/InlineDisplayLineBuilder.cpp: (WebCore::Layout::InlineDisplayLineBuilder::build const):

LayoutTests:

  • fast/inline/rtl-negative-margins-expected.html: Added.
  • fast/inline/rtl-negative-margins.html: Added.

git-svn-id: ​https://svn.webkit.org/repository/webkit/trunk@287922 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Location:
branches/safari-613-branch
Files:
2 added
7 edited

Legend:

Unmodified
Added
Removed
  • branches/safari-613-branch/LayoutTests/ChangeLog

    r288496 r288497  
     12022-01-24  Alan Coon  <alancoon@apple.com>
     2
     3        Cherry-pick r287922. rdar://problem/87455957
     4
     5    [LFC][IFC] Incorrect negative margin handling (both left/right) with RTL inline base direction
     6    https://bugs.webkit.org/show_bug.cgi?id=235095
     7   
     8    Reviewed by Antti Koivisto.
     9   
     10    Source/WebCore:
     11   
     12    The simplified negative margin handling on inline boxes does not work well with RTL inline base direction.
     13    With LTR direction, we could just treat the negative left margin value (which pulls content to the left)
     14    as part the "logical width" (may resulting in negative width values) and let this shorter width pull
     15    the the adjoining content.
     16    However this setup produces incorrect box positions when the inline base direction is RTL.
     17    In this patch, we switch over to a more correct inline box positioning where the negative margin
     18    affects the logical left while it does not make the run shorter anymore.
     19   
     20    Test: fast/inline/rtl-negative-margins.html
     21   
     22    * layout/formattingContexts/inline/InlineLine.cpp:
     23    (WebCore::Layout::Line::appendInlineBoxStart):
     24    (WebCore::Layout::Line::appendNonReplacedInlineLevelBox):
     25    * layout/formattingContexts/inline/InlineLineBoxBuilder.cpp:
     26    (WebCore::Layout::LineBoxBuilder::constructAndAlignInlineLevelBoxes):
     27    * layout/formattingContexts/inline/InlineLineBuilder.cpp:
     28    (WebCore::Layout::LineBuilder::layoutInlineContent):
     29    * layout/formattingContexts/inline/InlineLineBuilder.h:
     30    * layout/formattingContexts/inline/display/InlineDisplayLineBuilder.cpp:
     31    (WebCore::Layout::InlineDisplayLineBuilder::build const):
     32   
     33    LayoutTests:
     34   
     35    * fast/inline/rtl-negative-margins-expected.html: Added.
     36    * fast/inline/rtl-negative-margins.html: Added.
     37   
     38   
     39    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@287922 268f45cc-cd09-0410-ab3c-d52691b4dbfc
     40
     41    2022-01-12  Alan Bujtas  <zalan@apple.com>
     42
     43            [LFC][IFC] Incorrect negative margin handling (both left/right) with RTL inline base direction
     44            https://bugs.webkit.org/show_bug.cgi?id=235095
     45
     46            Reviewed by Antti Koivisto.
     47
     48            * fast/inline/rtl-negative-margins-expected.html: Added.
     49            * fast/inline/rtl-negative-margins.html: Added.
     50
    1512022-01-24  Alan Coon  <alancoon@apple.com>
    252
  • branches/safari-613-branch/Source/WebCore/ChangeLog

    r288496 r288497  
     12022-01-24  Alan Coon  <alancoon@apple.com>
     2
     3        Cherry-pick r287922. rdar://problem/87455957
     4
     5    [LFC][IFC] Incorrect negative margin handling (both left/right) with RTL inline base direction
     6    https://bugs.webkit.org/show_bug.cgi?id=235095
     7   
     8    Reviewed by Antti Koivisto.
     9   
     10    Source/WebCore:
     11   
     12    The simplified negative margin handling on inline boxes does not work well with RTL inline base direction.
     13    With LTR direction, we could just treat the negative left margin value (which pulls content to the left)
     14    as part the "logical width" (may resulting in negative width values) and let this shorter width pull
     15    the the adjoining content.
     16    However this setup produces incorrect box positions when the inline base direction is RTL.
     17    In this patch, we switch over to a more correct inline box positioning where the negative margin
     18    affects the logical left while it does not make the run shorter anymore.
     19   
     20    Test: fast/inline/rtl-negative-margins.html
     21   
     22    * layout/formattingContexts/inline/InlineLine.cpp:
     23    (WebCore::Layout::Line::appendInlineBoxStart):
     24    (WebCore::Layout::Line::appendNonReplacedInlineLevelBox):
     25    * layout/formattingContexts/inline/InlineLineBoxBuilder.cpp:
     26    (WebCore::Layout::LineBoxBuilder::constructAndAlignInlineLevelBoxes):
     27    * layout/formattingContexts/inline/InlineLineBuilder.cpp:
     28    (WebCore::Layout::LineBuilder::layoutInlineContent):
     29    * layout/formattingContexts/inline/InlineLineBuilder.h:
     30    * layout/formattingContexts/inline/display/InlineDisplayLineBuilder.cpp:
     31    (WebCore::Layout::InlineDisplayLineBuilder::build const):
     32   
     33    LayoutTests:
     34   
     35    * fast/inline/rtl-negative-margins-expected.html: Added.
     36    * fast/inline/rtl-negative-margins.html: Added.
     37   
     38   
     39    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@287922 268f45cc-cd09-0410-ab3c-d52691b4dbfc
     40
     41    2022-01-12  Alan Bujtas  <zalan@apple.com>
     42
     43            [LFC][IFC] Incorrect negative margin handling (both left/right) with RTL inline base direction
     44            https://bugs.webkit.org/show_bug.cgi?id=235095
     45
     46            Reviewed by Antti Koivisto.
     47
     48            The simplified negative margin handling on inline boxes does not work well with RTL inline base direction.
     49            With LTR direction, we could just treat the negative left margin value (which pulls content to the left)
     50            as part the "logical width" (may resulting in negative width values) and let this shorter width pull
     51            the the adjoining content.
     52            However this setup produces incorrect box positions when the inline base direction is RTL.
     53            In this patch, we switch over to a more correct inline box positioning where the negative margin
     54            affects the logical left while it does not make the run shorter anymore.
     55
     56            Test: fast/inline/rtl-negative-margins.html
     57
     58            * layout/formattingContexts/inline/InlineLine.cpp:
     59            (WebCore::Layout::Line::appendInlineBoxStart):
     60            (WebCore::Layout::Line::appendNonReplacedInlineLevelBox):
     61            * layout/formattingContexts/inline/InlineLineBoxBuilder.cpp:
     62            (WebCore::Layout::LineBoxBuilder::constructAndAlignInlineLevelBoxes):
     63            * layout/formattingContexts/inline/InlineLineBuilder.cpp:
     64            (WebCore::Layout::LineBuilder::layoutInlineContent):
     65            * layout/formattingContexts/inline/InlineLineBuilder.h:
     66            * layout/formattingContexts/inline/display/InlineDisplayLineBuilder.cpp:
     67            (WebCore::Layout::InlineDisplayLineBuilder::build const):
     68
    1692022-01-24  Alan Coon  <alancoon@apple.com>
    270
  • branches/safari-613-branch/Source/WebCore/layout/formattingContexts/inline/InlineLine.cpp

    r287824 r288497  
    229229    // Incoming logical width includes the cloned decoration end to be able to do line breaking.
    230230    auto borderAndPaddingEndForDecorationClone = addBorderAndPaddingEndForInlineBoxDecorationClone(inlineItem);
    231     m_runs.append({ inlineItem, style, logicalLeft, logicalWidth - borderAndPaddingEndForDecorationClone });
    232231    // Do not let negative margin make the content shorter than it already is.
    233232    m_contentLogicalWidth = std::max(m_contentLogicalWidth, logicalLeft + logicalWidth);
     233
     234    auto marginStart = formattingContext().geometryForBox(inlineItem.layoutBox()).marginStart();
     235    if (marginStart >= 0) {
     236        m_runs.append({ inlineItem, style, logicalLeft, logicalWidth - borderAndPaddingEndForDecorationClone });
     237        return;
     238    }
     239    // Negative margin-start pulls the content to the logical left direction.
     240    m_runs.append({ inlineItem, style, logicalLeft + marginStart, logicalWidth - marginStart - borderAndPaddingEndForDecorationClone });
    234241}
    235242
    … …  
    352359{
    353360    resetTrailingContent();
    354     m_contentLogicalWidth += marginBoxLogicalWidth;
     361    // Do not let negative margin make the content shorter than it already is.
     362    m_contentLogicalWidth = std::max(m_contentLogicalWidth, lastRunLogicalRight() + marginBoxLogicalWidth);
    355363    ++m_nonSpanningInlineLevelBoxCount;
    356364    auto marginStart = formattingContext().geometryForBox(inlineItem.layoutBox()).marginStart();
  • branches/safari-613-branch/Source/WebCore/layout/formattingContexts/inline/InlineLineBoxBuilder.cpp

    r287731 r288497  
    284284                marginStart = formattingContext().geometryForBox(layoutBox).marginStart();
    285285#endif
    286             auto adjustedLogicalStart = logicalLeft + marginStart;
     286            auto adjustedLogicalStart = logicalLeft + std::max(0.0f, marginStart);
    287287            auto logicalWidth = rootInlineBox.logicalWidth() - adjustedLogicalStart;
    288288            auto inlineBox = InlineLevelBox::createInlineBox(layoutBox, style, adjustedLogicalStart, logicalWidth, InlineLevelBox::LineSpanningInlineBox::Yes);
    … …  
    297297            // Inline box run is based on margin box. Let's convert it to border box.
    298298            auto marginStart = formattingContext().geometryForBox(layoutBox).marginStart();
    299             auto initialLogicalWidth = rootInlineBox.logicalWidth() - (run.logicalLeft() + marginStart);
     299            logicalLeft += std::max(0_lu, marginStart);
     300            auto initialLogicalWidth = rootInlineBox.logicalWidth() - (logicalLeft - rootInlineBox.logicalLeft());
    300301            ASSERT(initialLogicalWidth >= 0 || lineContent.hangingContentWidth);
    301302            initialLogicalWidth = std::max(initialLogicalWidth, 0.f);
    302             auto inlineBox = InlineLevelBox::createInlineBox(layoutBox, style, logicalLeft + marginStart, initialLogicalWidth);
     303            auto inlineBox = InlineLevelBox::createInlineBox(layoutBox, style, logicalLeft, initialLogicalWidth);
    303304            inlineBox.setIsFirstBox();
    304305            setInitialVerticalGeometryForInlineBox(inlineBox);
  • branches/safari-613-branch/Source/WebCore/layout/formattingContexts/inline/InlineLineBuilder.cpp

    r287482 r288497  
    354354        , m_lineLogicalRect.width()
    355355        , m_line.contentLogicalWidth()
     356        , m_line.contentLogicalRight()
    356357        , m_line.hangingTrailingContentWidth()
    357358        , isLastLine
  • branches/safari-613-branch/Source/WebCore/layout/formattingContexts/inline/InlineLineBuilder.h

    r287471 r288497  
    6262        InlineLayoutUnit lineLogicalWidth { 0 };
    6363        InlineLayoutUnit contentLogicalWidth { 0 };
     64        InlineLayoutUnit contentLogicalRight { 0 };
    6465        InlineLayoutUnit hangingContentWidth { 0 };
    6566        bool isLastLineWithInlineContent { true };
  • branches/safari-613-branch/Source/WebCore/layout/formattingContexts/inline/display/InlineDisplayLineBuilder.cpp

    r287486 r288497  
    9090    auto contentVisualLeft = isLeftToRightDirection
    9191        ? lineBox.rootInlineBoxAlignmentOffset()
    92         : rootGeometry.contentBoxWidth() - lineOffsetFromContentBox -  lineBox.rootInlineBoxAlignmentOffset() - rootInlineBox.logicalWidth() - lineContent.hangingContentWidth;
     92        : rootGeometry.contentBoxWidth() - lineOffsetFromContentBox -  lineBox.rootInlineBoxAlignmentOffset() - lineContent.contentLogicalRight;
    9393
    9494    auto lineBoxRect = InlineRect { lineContent.lineLogicalTopLeft.y(), lineBoxVisualLeft, lineContent.lineLogicalWidth, lineBoxLogicalHeight };
Note: See TracChangeset for help on using the changeset viewer.