Changeset 295478 in webkit


Ignore:
Timestamp:
Jun 12, 2022 7:45:22 AM (2 years ago)
Author:
Alan Bujtas
Message:

Incorrect sizing of elements with visually hidden text inside
https://bugs.webkit.org/show_bug.cgi?id=241459

Reviewed by Antti Koivisto.

This patch fixes the incorrect inline width computation when an inline box (e.g. <span>) with margin-inline-start (e.g. margin-left) is followed by an out-of-flow element.

<div id=container>some<span style="margin-left: 10px"><div style="position: absolute"></div>text</span></div>

In LineBreaker::nextLineBreak, while iterating through the content of [container], the margin-left of the inline box (span) is included twice; first for the out-of-flow box and second for the [text] content. This patch ensures that when we reach the [text] content, we check if we have already reserved the space for the inline box's margin (padding and border).
(While out-of-flow inline level boxes are not supposed to participate in inline layout, (in legacy line layout) in order to compute their static position we include them in line layout. A more involved fix would be to exclude all out-of-flow boxes from line layout and deal with their static positioning after completing the core line layout).

  • LayoutTests/fast/block/shrink-to-fit-with-out-of-flow-and-inline-box-margin-expected.html: Added.
  • LayoutTests/fast/block/shrink-to-fit-with-out-of-flow-and-inline-box-margin.html: Added.
  • Source/WebCore/rendering/line/BreakingContext.h: Make sure when the out-of-flow box takes the margin, we don't add it again for the text content. Also, reset this flag for subsequent content.

(WebCore::inlineLogicalWidth):

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

Location:
trunk
Files:
2 added
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/rendering/line/BreakingContext.h

    r288067 r295478  
    353353        positionedObjects.append(&box);
    354354
    355     m_width.addUncommittedWidth(inlineLogicalWidth(box));
     355    if (auto inlineBoxStartWidth = inlineLogicalWidth(box)) {
     356        m_width.addUncommittedWidth(inlineBoxStartWidth);
     357        m_appliedStartWidth = true;
     358    }
    356359    // Reset prior line break context characters.
    357360    m_renderTextInfo.lineBreakIterator.resetPriorContext();
     
    638641inline bool BreakingContext::handleText(WordMeasurements& wordMeasurements, bool& hyphenated,  unsigned& consecutiveHyphenatedLines)
    639642{
    640     if (!m_current.offset())
    641         m_appliedStartWidth = false;
    642 
    643643    auto& renderer = downcast<RenderText>(*m_current.renderer());
    644644    bool isSVGText = renderer.isSVGInlineText();
     
    10511051        }
    10521052    }
     1053    m_appliedStartWidth = false;
    10531054    return false;
    10541055}
Note: See TracChangeset for help on using the changeset viewer.