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

Changeset 251633 in webkit


Ignore:
Timestamp:
Oct 26, 2019, 5:53:00 AM (7 years ago)
Author:
Alan Bujtas
Message:

[LFC][IFC] Completely collapsed runs should not have advance width
https://bugs.webkit.org/show_bug.cgi?id=203457
<rdar://problem/56645024>

Reviewed by Antti Koivisto.

Let's reset the advance width for completely collapsed runs (any a collapsible space immediatelly following another
collapsible space).
https://drafts.csswg.org/css-text-3/#white-space-phase-1

  • layout/inlineformatting/InlineFormattingContext.cpp:

(WebCore::Layout::InlineFormattingContext::setDisplayBoxesForLine):

  • layout/inlineformatting/InlineFormattingContextQuirks.cpp:

(WebCore::Layout::InlineFormattingContext::Quirks::lineDescentNeedsCollapsing const):

  • layout/inlineformatting/InlineLine.cpp:

(WebCore::Layout::Line::Run::canBeExtended const):
(WebCore::Layout::Line::isVisuallyEmpty const):
(WebCore::Layout::Line::removeTrailingTrimmableContent):
(WebCore::Layout::Line::trailingTrimmableWidth const):
(WebCore::Layout::Line::appendTextContent):

  • layout/inlineformatting/InlineLine.h:

(WebCore::Layout::Line::Run::expand):
(WebCore::Layout::Line::Run::isCollapsedToZeroAdvanceWidth const):
(WebCore::Layout::Line::Run::setCollapsesToZeroAdvanceWidth):
(WebCore::Layout::Line::Run::isVisuallyEmpty const): Deleted.
(WebCore::Layout::Line::Run::setVisuallyIsEmpty): Deleted.

Location:
trunk/Source/WebCore
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r251632 r251633  
     12019-10-26  Zalan Bujtas  <zalan@apple.com>
     2
     3        [LFC][IFC] Completely collapsed runs should not have advance width
     4        https://bugs.webkit.org/show_bug.cgi?id=203457
     5        <rdar://problem/56645024>
     6
     7        Reviewed by Antti Koivisto.
     8
     9        Let's reset the advance width for completely collapsed runs (any a collapsible space immediatelly following another
     10        collapsible space).
     11        https://drafts.csswg.org/css-text-3/#white-space-phase-1
     12
     13        * layout/inlineformatting/InlineFormattingContext.cpp:
     14        (WebCore::Layout::InlineFormattingContext::setDisplayBoxesForLine):
     15        * layout/inlineformatting/InlineFormattingContextQuirks.cpp:
     16        (WebCore::Layout::InlineFormattingContext::Quirks::lineDescentNeedsCollapsing const):
     17        * layout/inlineformatting/InlineLine.cpp:
     18        (WebCore::Layout::Line::Run::canBeExtended const):
     19        (WebCore::Layout::Line::isVisuallyEmpty const):
     20        (WebCore::Layout::Line::removeTrailingTrimmableContent):
     21        (WebCore::Layout::Line::trailingTrimmableWidth const):
     22        (WebCore::Layout::Line::appendTextContent):
     23        * layout/inlineformatting/InlineLine.h:
     24        (WebCore::Layout::Line::Run::expand):
     25        (WebCore::Layout::Line::Run::isCollapsedToZeroAdvanceWidth const):
     26        (WebCore::Layout::Line::Run::setCollapsesToZeroAdvanceWidth):
     27        (WebCore::Layout::Line::Run::isVisuallyEmpty const): Deleted.
     28        (WebCore::Layout::Line::Run::setVisuallyIsEmpty): Deleted.
     29
    1302019-10-26  Antti Koivisto  <antti@apple.com>
    231
  • trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContext.cpp

    r251617 r251633  
    436436        if (lineRun->isContainerStart() || lineRun->isContainerEnd())
    437437            continue;
    438         // Collapsed line runs don't generate display runs.
    439         if (lineRun->isVisuallyEmpty())
     438        // Completely collapsed line runs don't generate display runs.
     439        if (lineRun->isCollapsedToZeroAdvanceWidth())
    440440            continue;
    441441        formattingState.addInlineRun(lineRun->displayRun(), currentLine);
     
    491491            // FIXME take content breaking into account when part of the layout box is on the previous line.
    492492            auto firstInlineRunForLayoutBox = !previousLineRun || &previousLineRun->layoutBox() != &layoutBox;
    493             auto logicalWidth = lineRun->isVisuallyEmpty() ? LayoutUnit() : logicalRect.width();
    494493            if (firstInlineRunForLayoutBox) {
    495494                // Setup display box for the associated layout box.
    496495                displayBox.setTopLeft(logicalRect.topLeft());
    497                 displayBox.setContentBoxWidth(logicalWidth);
     496                displayBox.setContentBoxWidth(logicalRect.width());
    498497                displayBox.setContentBoxHeight(logicalRect.height());
    499498            } else {
    500499                // FIXME fix it for multirun/multiline.
    501                 displayBox.setContentBoxWidth(displayBox.contentBoxWidth() + logicalWidth);
     500                displayBox.setContentBoxWidth(displayBox.contentBoxWidth() + logicalRect.width());
    502501            }
    503502            continue;
  • trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContextQuirks.cpp

    r251590 r251633  
    5151            return false;
    5252        if (run->isText()) {
    53             if (!run->isVisuallyEmpty())
     53            if (!run->isCollapsedToZeroAdvanceWidth())
    5454                return false;
    5555            continue;
  • trunk/Source/WebCore/layout/inlineformatting/InlineLine.cpp

    r251590 r251633  
    5656        return false;
    5757    // Non-collapsed text runs can be merged into one continuous run.
    58     if (isVisuallyEmpty())
     58    if (isCollapsedToZeroAdvanceWidth())
    5959        return false;
    6060    return !isCollapsed();
     
    121121            continue;
    122122        }
    123         if (!run->isText() || !run->isVisuallyEmpty())
     123        if (!run->isText() || !run->isCollapsedToZeroAdvanceWidth())
    124124            return false;
    125125    }
     
    273273    for (auto* trimmableRun : m_trimmableContent) {
    274274        ASSERT(trimmableRun->isText());
    275         trimmableRun->setVisuallyIsEmpty();
     275        // FIXME: We might need to be able to differentiate between trimmed and collapsed runs.
    276276        trimmableWidth += trimmableRun->logicalRect().width();
     277        trimmableRun->setCollapsesToZeroAdvanceWidth();
    277278    }
    278279    m_lineBox.shrinkHorizontally(trimmableWidth);
     
    297298{
    298299    LayoutUnit trimmableWidth;
    299     for (auto* trimmableRun : m_trimmableContent) {
    300         ASSERT(!trimmableRun->isVisuallyEmpty());
     300    for (auto* trimmableRun : m_trimmableContent)
    301301        trimmableWidth += trimmableRun->logicalRect().width();
    302     }
    303302    return trimmableWidth;
    304303}
     
    367366            if (run->isBox())
    368367                return false;
    369             // When the previous text run is collapsed, this collapsible run collapses completely.
     368            // https://drafts.csswg.org/css-text-3/#white-space-phase-1
     369            // Any collapsible space immediately following another collapsible space—even one outside the boundary of the inline containing that space,
     370            // provided both spaces are within the same inline formatting context—is collapsed to have zero advance width.
     371            // : "<span>  </span> " <- the trailing whitespace collapses completely.
     372            // Not that when the inline container has preserve whitespace style, "<span style="white-space: pre">  </span> " <- this whitespace stays around.
    370373            if (run->isText())
    371374                return run->isCollapsed();
    372             // Collapsing works across inline containers: "<span>  </span> " <- the trailing whitespace collapses completely.
    373             // Not that when the inline container has preserve whitespace style, "<span style="white-space: pre">  </span> " <- this whitespace stays around.
    374375            ASSERT(run->isContainerStart() || run->isContainerEnd());
    375376        }
     
    389390    auto contentLength =  collapseRun ? 1 : inlineItem.length();
    390391    auto textContent = inlineItem.layoutBox().textContent().substring(contentStart, contentLength);
    391     auto lineItem = makeUnique<Run>(inlineItem, Display::Run { inlineItem.style(), logicalRect, Display::Run::TextContext { contentStart, contentLength, textContent } });
    392 
    393     auto isVisuallyEmpty = willCollapseCompletely();
    394     if (collapseRun)
    395         lineItem->setIsCollapsed();
    396     if (isVisuallyEmpty)
    397         lineItem->setVisuallyIsEmpty();
    398     else if (isTrimmable)
    399         m_trimmableContent.add(lineItem.get());
    400 
    401     m_runList.append(WTFMove(lineItem));
    402     // Collapsed line items don't contribute to the line width.
    403     if (!isVisuallyEmpty)
    404         m_lineBox.expandHorizontally(logicalWidth);
     392    auto lineRun = makeUnique<Run>(inlineItem, Display::Run { inlineItem.style(), logicalRect, Display::Run::TextContext { contentStart, contentLength, textContent } });
     393
     394    auto collapsesToZeroAdvanceWidth = willCollapseCompletely();
     395    if (collapsesToZeroAdvanceWidth)
     396        lineRun->setCollapsesToZeroAdvanceWidth();
     397    else if (collapseRun)
     398        lineRun->setIsCollapsed();
     399    if (isTrimmable)
     400        m_trimmableContent.add(lineRun.get());
     401
     402    m_lineBox.expandHorizontally(lineRun->logicalRect().width());
     403    m_runList.append(WTFMove(lineRun));
    405404}
    406405
  • trunk/Source/WebCore/layout/inlineformatting/InlineLine.h

    r251590 r251633  
    7474
    7575        const Display::Rect& logicalRect() const { return m_displayRun.logicalRect(); }
    76         bool isVisuallyEmpty() const { return m_isVisuallyEmpty; }
     76        bool isCollapsedToZeroAdvanceWidth() const;
    7777        bool isCollapsed() const { return m_isCollapsed; }
    7878
     
    9191        void expand(const Run&);
    9292
    93         void setVisuallyIsEmpty() { m_isVisuallyEmpty = true; }
    9493        void setIsCollapsed() { m_isCollapsed = true; }
     94        void setCollapsesToZeroAdvanceWidth();
    9595
    9696        bool isWhitespace() const;
     
    100100        Display::Run m_displayRun;
    101101        bool m_isCollapsed { false };
    102         bool m_isVisuallyEmpty { false };
     102        bool m_collapsedToZeroAdvanceWidth { false };
    103103    };
    104104    using RunList = Vector<std::unique_ptr<Run>>;
     
    155155    ASSERT(isText());
    156156    ASSERT(other.isText());
     157    ASSERT(!isCollapsedToZeroAdvanceWidth());
    157158
    158159    auto& otherDisplayRun = other.displayRun();
     
    161162}
    162163
     164inline bool Line::Run::isCollapsedToZeroAdvanceWidth() const
     165{
     166    ASSERT(!m_collapsedToZeroAdvanceWidth || !m_displayRun.logicalWidth());
     167    return m_collapsedToZeroAdvanceWidth;
     168}
     169
     170inline void Line::Run::setCollapsesToZeroAdvanceWidth()
     171{
     172    m_collapsedToZeroAdvanceWidth = true;
     173    m_isCollapsed = true;
     174    m_displayRun.setLogicalWidth({ });
     175}
     176
    163177}
    164178}
Note: See TracChangeset for help on using the changeset viewer.