Changeset 252143 in webkit


Ignore:
Timestamp:
Nov 6, 2019 1:02:01 PM (4 years ago)
Author:
Alan Bujtas
Message:

[LFC][MarginCollapsing] Add Line::isConsideredEmpty
https://bugs.webkit.org/show_bug.cgi?id=203800
<rdar://problem/56854192>

Reviewed by Antti Koivisto.

https://www.w3.org/TR/CSS22/visuren.html#inline-formatting
Line boxes that contain no text, no preserved white space, no inline elements with non-zero margins, padding, or borders,
and no other in-flow content (such as images, inline blocks or inline tables), and do not end with a preserved newline
must be treated as zero-height line boxes for the purposes of determining the positions of any elements inside of them,
and must be treated as not existing for any other purpose.

Note that it does not necessarily mean visually non-empty line
<span style="font-size: 0px">this is still considered non-empty</span>

  • layout/blockformatting/BlockMarginCollapse.cpp:

(WebCore::Layout::BlockFormattingContext::MarginCollapse::marginsCollapseThrough const):

  • layout/inlineformatting/InlineLine.cpp:

(WebCore::Layout::Line::appendNonBreakableSpace):
(WebCore::Layout::Line::appendTextContent):
(WebCore::Layout::Line::appendNonReplacedInlineBox):
(WebCore::Layout::Line::appendReplacedInlineBox):
(WebCore::Layout::Line::appendLineBreak):

  • layout/inlineformatting/InlineLineBox.h:

(WebCore::Layout::LineBox::isConsideredEmpty const):
(WebCore::Layout::LineBox::setIsConsideredNonEmpty):

Location:
trunk/Source/WebCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r252136 r252143  
     12019-11-06  Zalan Bujtas  <zalan@apple.com>
     2
     3        [LFC][MarginCollapsing] Add Line::isConsideredEmpty
     4        https://bugs.webkit.org/show_bug.cgi?id=203800
     5        <rdar://problem/56854192>
     6
     7        Reviewed by Antti Koivisto.
     8
     9        https://www.w3.org/TR/CSS22/visuren.html#inline-formatting
     10        Line boxes that contain no text, no preserved white space, no inline elements with non-zero margins, padding, or borders,
     11        and no other in-flow content (such as images, inline blocks or inline tables), and do not end with a preserved newline
     12        must be treated as zero-height line boxes for the purposes of determining the positions of any elements inside of them,
     13        and must be treated as not existing for any other purpose.
     14
     15        Note that it does not necessarily mean visually non-empty line
     16        <span style="font-size: 0px">this is still considered non-empty</span>
     17
     18        * layout/blockformatting/BlockMarginCollapse.cpp:
     19        (WebCore::Layout::BlockFormattingContext::MarginCollapse::marginsCollapseThrough const):
     20        * layout/inlineformatting/InlineLine.cpp:
     21        (WebCore::Layout::Line::appendNonBreakableSpace):
     22        (WebCore::Layout::Line::appendTextContent):
     23        (WebCore::Layout::Line::appendNonReplacedInlineBox):
     24        (WebCore::Layout::Line::appendReplacedInlineBox):
     25        (WebCore::Layout::Line::appendLineBreak):
     26        * layout/inlineformatting/InlineLineBox.h:
     27        (WebCore::Layout::LineBox::isConsideredEmpty const):
     28        (WebCore::Layout::LineBox::setIsConsideredNonEmpty):
     29
    1302019-11-06  Chris Lord  <clord@igalia.com>
    231
  • trunk/Source/WebCore/layout/blockformatting/BlockMarginCollapse.cpp

    r250064 r252143  
    403403            if (!layoutState.hasFormattingState(layoutContainer))
    404404                return false;
    405             auto& formattingState = downcast<InlineFormattingState>(layoutState.establishedFormattingState(layoutContainer));
    406             if (!formattingState.inlineRuns().isEmpty())
    407                 return false;
    408             // Any float box in this formatting context prevents collapsing through.
    409             auto& floats = formattingState.floatingState().floats();
    410             for (auto& floatItem : floats) {
    411                 if (floatItem.isDescendantOfFormattingRoot(layoutContainer))
    412                     return false;
    413             }
    414             return true;
     405
     406            auto isConsideredEmpty = [&] {
     407                auto& formattingState = downcast<InlineFormattingState>(layoutState.establishedFormattingState(layoutContainer));
     408                for (auto& lineBox : formattingState.lineBoxes()) {
     409                    if (!lineBox->isConsideredEmpty())
     410                        return false;
     411                }
     412                // Any float box in this formatting context prevents collapsing through.
     413                auto& floats = formattingState.floatingState().floats();
     414                for (auto& floatItem : floats) {
     415                    if (floatItem.isDescendantOfFormattingRoot(layoutContainer))
     416                        return false;
     417                }
     418                return true;
     419            };
     420            return isConsideredEmpty();
    415421        }
    416422
  • trunk/Source/WebCore/layout/inlineformatting/InlineLine.cpp

    r251973 r252143  
    385385    m_runList.append(makeUnique<Run>(inlineItem, Display::Run { inlineItem.style(), logicalRect }));
    386386    m_lineBox.expandHorizontally(logicalRect.width());
     387    if (logicalRect.width())
     388        m_lineBox.setIsConsideredNonEmpty();
    387389}
    388390
     
    464466    if (collapsesToZeroAdvanceWidth)
    465467        lineRun->setCollapsesToZeroAdvanceWidth();
     468    else
     469        m_lineBox.setIsConsideredNonEmpty();
     470
    466471    if (collapsedRun)
    467472        lineRun->setIsCollapsed();
     
    489494    m_runList.append(makeUnique<Run>(inlineItem, Display::Run { inlineItem.style(), logicalRect }));
    490495    m_lineBox.expandHorizontally(logicalWidth + horizontalMargin.start + horizontalMargin.end);
     496    m_lineBox.setIsConsideredNonEmpty();
    491497    m_trimmableContent.clear();
    492498}
     
    497503    // FIXME: Surely replaced boxes behave differently.
    498504    appendNonReplacedInlineBox(inlineItem, logicalWidth);
     505    m_lineBox.setIsConsideredNonEmpty();
    499506    if (auto* replaced = inlineItem.layoutBox().replaced(); replaced && replaced->cachedImage())
    500507        m_runList.last()->m_displayRun.setImage(*replaced->cachedImage());
     
    510517        logicalRect.setHeight(logicalHeight());
    511518    }
     519    m_lineBox.setIsConsideredNonEmpty();
    512520    m_runList.append(makeUnique<Run>(inlineItem, Display::Run { inlineItem.style(), logicalRect }));
    513521}
  • trunk/Source/WebCore/layout/inlineformatting/InlineLineBox.h

    r251238 r252143  
    109109    void shrinkVertically(LayoutUnit delta) { expandVertically(-delta); }
    110110
     111    // https://www.w3.org/TR/CSS22/visuren.html#inline-formatting
     112    // Line boxes that contain no text, no preserved white space, no inline elements with non-zero margins, padding, or borders,
     113    // and no other in-flow content (such as images, inline blocks or inline tables), and do not end with a preserved newline
     114    // must be treated as zero-height line boxes for the purposes of determining the positions of any elements inside of them,
     115    // and must be treated as not existing for any other purpose.
     116    // Note that it does not necessarily mean visually non-empty line. <span style="font-size: 0px">this is still considered non-empty</span>
     117    bool isConsideredEmpty() const { return m_isConsideredEmpty; }
     118    void setIsConsideredNonEmpty() { m_isConsideredEmpty = false; }
     119
    111120private:
    112121#if !ASSERT_DISABLED
     
    117126    Baseline m_baseline;
    118127    LayoutUnit m_baselineOffset;
     128    bool m_isConsideredEmpty { true };
    119129};
    120130
Note: See TracChangeset for help on using the changeset viewer.