Skip to content

Commit

Permalink
Cherry-pick b2ec60c. rdar://124784190
Browse files Browse the repository at this point in the history
    [IFC][Intrinsic width] Incorrect shrink-to-fit box logical width when negative text-indent is present
    https://bugs.webkit.org/show_bug.cgi?id=271113
    <rdar://problem/124784190>

    Reviewed by Antti Koivisto.

    Negative text-indent value could confuse the min/max inline size computation as running layout with 0 constraint
    may produce wider content than running layout with infinite constraint.

    Consider the following case:

    <div style="text-indent: -100px;">some content</div>

    With infinite constraint this content produce only one line with the line box width of 0 (assume the measured content width of "some content" is < 100px)
    It simply means that [some content] visually overflows on the left due to this implicit negative content margin.
                  _
    some content |_|

    However when computing the minimum content size we have to take into account all the possible soft wrap opportunities with the constraint value of 0.
    Now we end up constructing 2 lines where the second line has 0px used text-indent.
                  _
    some         |_|
                  ________
                 |content |
                  --------
    which clearly computes a content value > 0px.

    Let's fix this by making sure minimum width is never larger than maximum width. This behavior also seems to match with other rendering engines.

    * LayoutTests/fast/text/min-max-content-negative-text-indent-expected.html: Added.
    * LayoutTests/fast/text/min-max-content-negative-text-indent.html: Added.
    * Source/WebCore/layout/formattingContexts/inline/InlineFormattingContext.cpp:
    (WebCore::Layout::InlineFormattingContext::minimumMaximumContentSize):
    (WebCore::Layout::InlineFormattingContext::minimumContentSize):

    Canonical link: https://commits.webkit.org/276246@main

Identifier: 272448.828@safari-7618-branch
  • Loading branch information
alanbaradlay authored and Dan Robson committed Mar 29, 2024
1 parent 90e974b commit f67193f
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<style>
div {
width: min-content;
height: 50px;
background-color: green;
color: transparent;
font-family: Ahem;
font-size: 20px;
}
</style>
<div>X</div>
<div>XX</div>
<div>XXX</div>
<div>XXXX</div>
<div>XXXXX</div>
<div>XXXXX</div>
<div>XXXXX</div>
<div>XXXXX</div>
<div>XXXXXXX</div>
19 changes: 19 additions & 0 deletions LayoutTests/fast/text/min-max-content-negative-text-indent.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<style>
div {
width: min-content;
height: 50px;
background-color: green;
color: transparent;
font-family: Ahem;
font-size: 20px;
}
</style>
<div style="text-indent: -180px;">XXXX XXXXX</div>
<div style="text-indent: -160px;">XXXX XXXXX</div>
<div style="text-indent: -140px;">XXXX XXXXX</div>
<div style="text-indent: -120px;">XXXX XXXXX</div>
<div style="text-indent: -100px;">XXXX XXXXX</div>
<div style="text-indent: -80px;">XXXX XXXXX</div>
<div style="text-indent: -60px;">XXXX XXXXX</div>
<div style="text-indent: 0px;">XXXX XXXXX</div>
<div style="text-indent: 60px;">XXXX XXXXX</div>
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ std::pair<LayoutUnit, LayoutUnit> LineLayout::computeIntrinsicWidthConstraints()
// FIXME: This is where we need to switch between minimum and maximum box geometries.
auto minimumContentSize = inlineFormattingContext.minimumContentSize(m_lineDamage.get());
auto maximumContentSize = inlineFormattingContext.maximumContentSize();
minimumContentSize = std::min(minimumContentSize, maximumContentSize);
return { minimumContentSize, maximumContentSize };
}

Expand Down

0 comments on commit f67193f

Please sign in to comment.