Changeset 254402 in webkit


Ignore:
Timestamp:
Jan 11, 2020 3:47:56 PM (4 years ago)
Author:
Alan Bujtas
Message:

[LFC][IFC] Visually collapse hanging pre-wrap content.
https://bugs.webkit.org/show_bug.cgi?id=206133
<rdar://problem/58505750>

Reviewed by Antti Koivisto.

This change is to comply with other rendering engines when it comes to visually collapsing hanging pre-wrap content.

https://www.w3.org/TR/css-text-3/#white-space-phase-2
"If white-space is set to pre-wrap, the UA must (unconditionally) hang this sequence, unless the sequence
is followed by a forced line break, in which case it must conditionally hang the sequence is instead.
It _may_ also visually collapse the character advance widths of any that would otherwise overflow."

  • layout/inlineformatting/InlineLineBuilder.cpp:

(WebCore::Layout::LineBuilder::close):
(WebCore::Layout::LineBuilder::visuallyCollapsePreWrapOverflowContent):

  • layout/inlineformatting/InlineLineBuilder.h:

(WebCore::Layout::LineBuilder::InlineItemRun::adjustLogicalWidth):

Location:
trunk/Source/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r254400 r254402  
     12020-01-11  Zalan Butjtas  <zalan@apple.com>
     2
     3        [LFC][IFC] Visually collapse hanging pre-wrap content.
     4        https://bugs.webkit.org/show_bug.cgi?id=206133
     5        <rdar://problem/58505750>
     6
     7        Reviewed by Antti Koivisto.
     8
     9        This change is to comply with other rendering engines when it comes to visually collapsing hanging pre-wrap content.
     10
     11        https://www.w3.org/TR/css-text-3/#white-space-phase-2
     12        "If white-space is set to pre-wrap, the UA must (unconditionally) hang this sequence, unless the sequence
     13        is followed by a forced line break, in which case it must conditionally hang the sequence is instead.
     14        It ___may___ also visually collapse the character advance widths of any that would otherwise overflow."
     15
     16        * layout/inlineformatting/InlineLineBuilder.cpp:
     17        (WebCore::Layout::LineBuilder::close):
     18        (WebCore::Layout::LineBuilder::visuallyCollapsePreWrapOverflowContent):
     19        * layout/inlineformatting/InlineLineBuilder.h:
     20        (WebCore::Layout::LineBuilder::InlineItemRun::adjustLogicalWidth):
     21
    1222020-01-10  Dean Jackson  <dino@apple.com>
    223
  • trunk/Source/WebCore/layout/inlineformatting/InlineLineBuilder.cpp

    r254087 r254402  
    235235    // 3. Align merged runs both vertically and horizontally.
    236236    removeTrailingCollapsibleContent();
     237    visuallyCollapsePreWrapOverflowContent();
    237238    auto hangingContent = collectHangingContent(isLastLineWithInlineContent);
    238239
     
    509510}
    510511
     512void LineBuilder::visuallyCollapsePreWrapOverflowContent()
     513{
     514    ASSERT(m_collapsibleContent.isEmpty());
     515    // If white-space is set to pre-wrap, the UA must
     516    // ...
     517    // It may also visually collapse the character advance widths of any that would otherwise overflow.
     518    auto overflowWidth = -availableWidth();
     519    if (overflowWidth <= 0)
     520        return;
     521    // Let's just find the trailing pre-wrap whitespace content for now (e.g check if there are multiple trailing runs with
     522    // different set of white-space values and decide if the in-between pre-wrap content should be collapsed as well.)
     523    InlineLayoutUnit trimmedContentWidth = 0;
     524    for (auto& inlineItemRun : WTF::makeReversedRange(m_inlineItemRuns)) {
     525        if (inlineItemRun.style().whiteSpace() != WhiteSpace::PreWrap) {
     526            // We are only interested in pre-wrap trailing content.
     527            break;
     528        }
     529        auto preWrapVisuallyCollapsibleInlineItem = inlineItemRun.isContainerStart() || inlineItemRun.isContainerEnd() || inlineItemRun.isWhitespace();
     530        if (!preWrapVisuallyCollapsibleInlineItem)
     531            break;
     532        auto runLogicalWidth = inlineItemRun.logicalWidth();
     533        // Never partially collapse inline container start/end items.
     534        auto isPartialCollapsingAllowed = inlineItemRun.isText();
     535        // FIXME: We should always collapse the run at a glyph boundary as the spec indicates: "collapse the character advance widths of any that would otherwise overflow"
     536        auto runLogicalWidthAfterCollapsing = isPartialCollapsingAllowed ? std::max<InlineLayoutUnit>(0, runLogicalWidth - overflowWidth) : 0;
     537        auto trimmed = runLogicalWidth - runLogicalWidthAfterCollapsing;
     538        trimmedContentWidth += trimmed;
     539        overflowWidth -= trimmed;
     540        inlineItemRun.adjustLogicalWidth(runLogicalWidthAfterCollapsing);
     541        if (overflowWidth <= 0)
     542            break;
     543    }
     544    m_lineBox.shrinkHorizontally(trimmedContentWidth);
     545}
     546
    511547HangingContent LineBuilder::collectHangingContent(IsLastLineWithInlineContent isLastLineWithInlineContent)
    512548{
  • trunk/Source/WebCore/layout/inlineformatting/InlineLineBuilder.h

    r254032 r254402  
    143143
    144144    void removeTrailingCollapsibleContent();
     145    void visuallyCollapsePreWrapOverflowContent();
    145146    HangingContent collectHangingContent(IsLastLineWithInlineContent);
    146147    void alignHorizontally(RunList&, const HangingContent&, IsLastLineWithInlineContent);
     
    180181
    181182        void moveHorizontally(InlineLayoutUnit offset) { m_logicalLeft += offset; }
     183        void adjustLogicalWidth(InlineLayoutUnit adjustedWidth) { m_logicalWidth = adjustedWidth; }
    182184
    183185        bool isCollapsibleWhitespace() const;
Note: See TracChangeset for help on using the changeset viewer.