Changeset 251848 in webkit


Ignore:
Timestamp:
Oct 31, 2019 8:40:10 AM (4 years ago)
Author:
Alan Bujtas
Message:

[LFC][IFC] Do not merge completely collapsed run with the previous run
https://bugs.webkit.org/show_bug.cgi?id=203658
<rdar://problem/56769334>

Reviewed by Antti Koivisto.

When a whitespace run is completely collapsed (and visually empty), we should not try to merge it with previous text runs.
E.g. [before \nafter] -> [before][ ][\n][after] -> [before ][][after] -> [before ][after]

content inline items line runs display runs

  • layout/inlineformatting/InlineLine.cpp:

(WebCore::Layout::Line::close):

  • layout/inlineformatting/InlineLine.h:

(WebCore::Layout::Line::Run::hasTrailingCollapsedContent const):
(WebCore::Layout::Line::Run::canBeExtended const): Deleted.

Location:
trunk/Source/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r251846 r251848  
     12019-10-31  Zalan Bujtas  <zalan@apple.com>
     2
     3        [LFC][IFC] Do not merge completely collapsed run with the previous run
     4        https://bugs.webkit.org/show_bug.cgi?id=203658
     5        <rdar://problem/56769334>
     6
     7        Reviewed by Antti Koivisto.
     8
     9        When a whitespace run is completely collapsed (and visually empty), we should not try to merge it with previous text runs.
     10        E.g. [before  \nafter] -> [before][  ][\n][after] -> [before ][][after] -> [before ][after]
     11                ^content               ^inline items             ^line runs          ^display runs
     12
     13        * layout/inlineformatting/InlineLine.cpp:
     14        (WebCore::Layout::Line::close):
     15        * layout/inlineformatting/InlineLine.h:
     16        (WebCore::Layout::Line::Run::hasTrailingCollapsedContent const):
     17        (WebCore::Layout::Line::Run::canBeExtended const): Deleted.
     18
    1192019-10-31  Zalan Bujtas  <zalan@apple.com>
    220
  • trunk/Source/WebCore/layout/inlineformatting/InlineLine.cpp

    r251846 r251848  
    116116    unsigned index = 1;
    117117    while (index < m_runList.size()) {
     118        auto canMergeRuns = [](const auto& previousRun, const auto& currentRun) {
     119            // Do not merge runs across inline boxes (<span>foo</span><span>bar</span>)
     120            if (&previousRun->layoutBox() !=  &currentRun->layoutBox())
     121                return false;
     122            // Only text content can be merged.
     123            if (!previousRun->isText() || !currentRun->isText())
     124                return false;
     125            // Merged content needs to be continuous.
     126            if (previousRun->hasTrailingCollapsedContent())
     127                return false;
     128            // Visually empty runs are ignored.
     129            if (currentRun->isCollapsedToZeroAdvanceWidth())
     130                return false;
     131            return true;
     132        };
    118133        auto& previousRun = m_runList[index - 1];
    119         if (!previousRun->canBeExtended()) {
    120             ++index;
     134        auto& currentRun = m_runList[index];
     135        if (canMergeRuns(previousRun, currentRun)) {
     136            previousRun->expand(*currentRun);
     137            m_runList.remove(index);
    121138            continue;
    122139        }
    123         auto& currentRun = m_runList[index];
    124         // Do not merge runs from different boxes (<span>foo</span><span>bar</span>)
    125         // or within the same layout box but with preserved \n
    126         // (<span>text\n<span <- both the "text" and "\" belong to the same layout box)
    127         auto canAppendToPreviousRun = currentRun->isText() && &currentRun->layoutBox() ==  &previousRun->layoutBox();
    128         if (!canAppendToPreviousRun) {
    129             ++index;
    130             continue;
    131         }
    132         // Only text content can be extended atm.
    133         ASSERT(previousRun->isText());
    134         ASSERT(currentRun->isText());
    135         previousRun->expand(*currentRun);
    136         m_runList.remove(index);
     140        ++index;
    137141    }
    138142
  • trunk/Source/WebCore/layout/inlineformatting/InlineLine.h

    r251845 r251848  
    9595
    9696        bool isCollapsible() const { return m_inlineItem.isText() && downcast<InlineTextItem>(m_inlineItem).isCollapsible(); }
     97        bool hasTrailingCollapsedContent() const { return m_hasTrailingCollapsedContent; }
    9798        bool isWhitespace() const;
    98         bool canBeExtended() const;
    9999
    100100        const InlineItem& m_inlineItem;
     
    178178}
    179179
    180 inline bool Line::Run::canBeExtended() const
    181 {
    182     return isText() && !m_hasTrailingCollapsedContent;
    183 }
    184 
    185180inline bool Line::Run::isCollapsedToZeroAdvanceWidth() const
    186181{
Note: See TracChangeset for help on using the changeset viewer.