Changeset 270151 in webkit


Ignore:
Timestamp:
Nov 21, 2020 12:04:56 PM (3 years ago)
Author:
Alan Bujtas
Message:

[LFC][IFC] Treat floats as soft wrap opportunities
https://bugs.webkit.org/show_bug.cgi?id=219235

Reviewed by Antti Koivisto.

While floats are not part of the inline content and they are not supposed to introduce soft wrap opportunities,
e.g. [text][float box][float box][text][float box][text] is essentially just [text][text][text]
figuring out whether a float (or set of floats) should stay on the line or not (and handle potentially out of order inline items)
brings in unnecessary complexity (and apparently Blink works like this too).

  • layout/inlineformatting/InlineLineBuilder.cpp:

(WebCore::Layout::isAtSoftWrapOpportunity):
(WebCore::Layout::LineBuilder::nextWrapOpportunity const):

Location:
trunk/Source/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r270150 r270151  
     12020-11-21  Zalan Bujtas  <zalan@apple.com>
     2
     3        [LFC][IFC] Treat floats as soft wrap opportunities
     4        https://bugs.webkit.org/show_bug.cgi?id=219235
     5
     6        Reviewed by Antti Koivisto.
     7
     8        While floats are not part of the inline content and they are not supposed to introduce soft wrap opportunities,
     9        e.g. [text][float box][float box][text][float box][text] is essentially just [text][text][text]
     10        figuring out whether a float (or set of floats) should stay on the line or not (and handle potentially out of order inline items)
     11        brings in unnecessary complexity (and apparently Blink works like this too).
     12
     13        * layout/inlineformatting/InlineLineBuilder.cpp:
     14        (WebCore::Layout::isAtSoftWrapOpportunity):
     15        (WebCore::Layout::LineBuilder::nextWrapOpportunity const):
     16
    1172020-11-21  Antti Koivisto  <antti@apple.com>
    218
  • trunk/Source/WebCore/layout/inlineformatting/InlineLineBuilder.cpp

    r270114 r270151  
    7979    // An incoming <img> box would enable us to commit the "<span>prior_continuous_content</span>" content
    8080    // but an incoming text content would not necessarily.
    81     ASSERT(current.isText() || current.isBox());
    82     ASSERT(next.isText() || next.isBox());
     81    ASSERT(current.isText() || current.isBox() || current.isFloat());
     82    ASSERT(next.isText() || next.isBox() || next.isFloat());
    8383    if (current.isText() && next.isText()) {
    8484        auto& currentInlineTextItem = downcast<InlineTextItem>(current);
     
    102102        // [text-][text] : after [hyphen] position is a soft wrap opportunity.
    103103        return endsWithSoftWrapOpportunity(currentInlineTextItem, nextInlineTextItem);
     104    }
     105    if (current.isFloat() || next.isFloat()) {
     106        // While floats are not part of the inline content and they are not supposed to introduce soft wrap opportunities,
     107        // e.g. [text][float box][float box][text][float box][text] is essentially just [text][text][text]
     108        // figuring out whether a float (or set of floats) should stay on the line or not (and handle potentially out of order inline items)
     109        // brings in unnecessary complexity.
     110        return true;
    104111    }
    105112    if (current.isBox() || next.isBox()) {
     
    516523            return ++index;
    517524        }
    518         if (inlineItem.isFloat()) {
    519             // Floats are not part of the inline content. We ignore them as far as wrap opportunities are concerned.
    520             // [text][float box][text] is essentially just [text][text]
    521             continue;
    522         }
    523525        if (inlineItem.isInlineBoxStart() || inlineItem.isInlineBoxEnd()) {
    524526            // There's no wrapping opportunity between <span>text, <span></span> or </span>text.
    525527            continue;
    526528        }
    527         ASSERT(inlineItem.isText() || inlineItem.isBox());
     529        ASSERT(inlineItem.isText() || inlineItem.isBox() || inlineItem.isFloat());
    528530        if (!previousInlineItemIndex) {
    529531            previousInlineItemIndex = index;
    530532            continue;
    531533        }
    532         if (isAtSoftWrapOpportunity(m_inlineFormattingContext, m_inlineItems[*previousInlineItemIndex], m_inlineItems[index])) {
     534        auto& previousItem = m_inlineItems[*previousInlineItemIndex];
     535        auto& currentItem = m_inlineItems[index];
     536        if (isAtSoftWrapOpportunity(m_inlineFormattingContext, previousItem, currentItem)) {
     537            if (!previousItem.isText() || !currentItem.isText())
     538                return index;
    533539            // There's a soft wrap opportunity between 'previousInlineItemIndex' and 'index'.
    534540            // Now forward-find from the start position to see where we can actually wrap.
Note: See TracChangeset for help on using the changeset viewer.