Changeset 252923 in webkit


Ignore:
Timestamp:
Nov 28, 2019 6:44:32 AM (4 years ago)
Author:
Alan Bujtas
Message:

[LFC][IFC] Re-introduce LineBuilder::isVisuallyNonEmpty function
https://bugs.webkit.org/show_bug.cgi?id=204658
<rdar://problem/57512248>

Reviewed by Antti Koivisto.

LineBuilder::isVisuallyNonEmpty() used to loop through the runs an check if the runs are visually empty or not.
This time it takes the run as the parameter and decides whether this particular run is visually empty or not.
This patch is in preparation for fixing the line's visually-empty state after trimming the trailing runs.

  • layout/inlineformatting/InlineLineBuilder.cpp:

(WebCore::Layout::LineBuilder::append):
(WebCore::Layout::LineBuilder::appendNonBreakableSpace):
(WebCore::Layout::LineBuilder::appendTextContent):
(WebCore::Layout::LineBuilder::appendNonReplacedInlineBox):
(WebCore::Layout::LineBuilder::appendReplacedInlineBox):
(WebCore::Layout::LineBuilder::appendLineBreak):
(WebCore::Layout::LineBuilder::isVisuallyNonEmpty const):

  • layout/inlineformatting/InlineLineBuilder.h:
Location:
trunk/Source/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r252922 r252923  
     12019-11-28  Zalan Bujtas  <zalan@apple.com>
     2
     3        [LFC][IFC] Re-introduce LineBuilder::isVisuallyNonEmpty function
     4        https://bugs.webkit.org/show_bug.cgi?id=204658
     5        <rdar://problem/57512248>
     6
     7        Reviewed by Antti Koivisto.
     8
     9        LineBuilder::isVisuallyNonEmpty() used to loop through the runs an check if the runs are visually empty or not.
     10        This time it takes the run as the parameter and decides whether this particular run is visually empty or not.
     11        This patch is in preparation for fixing the line's visually-empty state after trimming the trailing runs.
     12
     13        * layout/inlineformatting/InlineLineBuilder.cpp:
     14        (WebCore::Layout::LineBuilder::append):
     15        (WebCore::Layout::LineBuilder::appendNonBreakableSpace):
     16        (WebCore::Layout::LineBuilder::appendTextContent):
     17        (WebCore::Layout::LineBuilder::appendNonReplacedInlineBox):
     18        (WebCore::Layout::LineBuilder::appendReplacedInlineBox):
     19        (WebCore::Layout::LineBuilder::appendLineBreak):
     20        (WebCore::Layout::LineBuilder::isVisuallyNonEmpty const):
     21        * layout/inlineformatting/InlineLineBuilder.h:
     22
    1232019-11-28  Zalan Bujtas  <zalan@apple.com>
    224
  • trunk/Source/WebCore/layout/inlineformatting/InlineLineBuilder.cpp

    r252922 r252923  
    456456{
    457457    if (inlineItem.isText())
    458         return appendTextContent(downcast<InlineTextItem>(inlineItem), logicalWidth);
    459     if (inlineItem.isForcedLineBreak())
    460         return appendLineBreak(inlineItem);
    461     if (inlineItem.isContainerStart())
    462         return appendInlineContainerStart(inlineItem, logicalWidth);
    463     if (inlineItem.isContainerEnd())
    464         return appendInlineContainerEnd(inlineItem, logicalWidth);
    465     if (inlineItem.layoutBox().replaced())
    466         return appendReplacedInlineBox(inlineItem, logicalWidth);
    467     appendNonReplacedInlineBox(inlineItem, logicalWidth);
     458        appendTextContent(downcast<InlineTextItem>(inlineItem), logicalWidth);
     459    else if (inlineItem.isForcedLineBreak())
     460        appendLineBreak(inlineItem);
     461    else if (inlineItem.isContainerStart())
     462        appendInlineContainerStart(inlineItem, logicalWidth);
     463    else if (inlineItem.isContainerEnd())
     464        appendInlineContainerEnd(inlineItem, logicalWidth);
     465    else if (inlineItem.layoutBox().replaced())
     466        appendReplacedInlineBox(inlineItem, logicalWidth);
     467    else if (inlineItem.isBox())
     468        appendNonReplacedInlineBox(inlineItem, logicalWidth);
     469    else
     470        ASSERT_NOT_REACHED();
     471
     472    // Check if this freshly appended content makes the line visually non-empty.
     473    ASSERT(!m_inlineItemRuns.isEmpty());
     474    if (m_lineBox.isConsideredEmpty() && isVisuallyNonEmpty(*m_inlineItemRuns.last()))
     475        m_lineBox.setIsConsideredNonEmpty();
    468476}
    469477
     
    472480    m_inlineItemRuns.append(makeUnique<InlineItemRun>(inlineItem, logicalRect));
    473481    m_lineBox.expandHorizontally(logicalRect.width());
    474     if (logicalRect.width())
    475         m_lineBox.setIsConsideredNonEmpty();
    476482}
    477483
     
    532538    if (collapsesToZeroAdvanceWidth)
    533539        lineRun->setCollapsesToZeroAdvanceWidth();
    534     else
    535         m_lineBox.setIsConsideredNonEmpty();
    536540
    537541    if (collapsedRun)
     
    551555    m_inlineItemRuns.append(makeUnique<InlineItemRun>(inlineItem, Display::Rect { 0, contentLogicalWidth() + horizontalMargin.start, logicalWidth, { } }));
    552556    m_lineBox.expandHorizontally(logicalWidth + horizontalMargin.start + horizontalMargin.end);
    553     m_lineBox.setIsConsideredNonEmpty();
    554557    m_trimmableContent.clear();
    555     if (!layoutBox.establishesFormattingContext() || !boxGeometry.isEmpty())
    556         m_lineBox.setIsConsideredNonEmpty();
    557558}
    558559
     
    562563    // FIXME: Surely replaced boxes behave differently.
    563564    appendNonReplacedInlineBox(inlineItem, logicalWidth);
    564     m_lineBox.setIsConsideredNonEmpty();
    565565}
    566566
    567567void LineBuilder::appendLineBreak(const InlineItem& inlineItem)
    568568{
    569     m_lineBox.setIsConsideredNonEmpty();
    570569    m_inlineItemRuns.append(makeUnique<InlineItemRun>(inlineItem, Display::Rect { 0, contentLogicalWidth(), { }, { } }));
    571570}
     
    678677}
    679678
     679bool LineBuilder::isVisuallyNonEmpty(const InlineItemRun& run) const
     680{
     681    if (run.isText())
     682        return !run.isCollapsedToZeroAdvanceWidth();
     683
     684    // Note that this does not check whether the inline container has content. It simply checks if the container itself is considered non-empty.
     685    if (run.isContainerStart() || run.isContainerEnd()) {
     686        if (!run.logicalRect().width())
     687            return false;
     688        // Margin does not make the container visually non-empty. Check if it has border or padding.
     689        auto& boxGeometry = formattingContext().geometryForBox(run.layoutBox());
     690        if (run.isContainerStart())
     691            return boxGeometry.borderLeft() || (boxGeometry.paddingLeft() && boxGeometry.paddingLeft().value());
     692        return boxGeometry.borderRight() || (boxGeometry.paddingRight() && boxGeometry.paddingRight().value());
     693    }
     694
     695    if (run.isForcedLineBreak())
     696        return true;
     697
     698    if (run.isBox()) {
     699        if (!run.layoutBox().establishesFormattingContext())
     700            return true;
     701        ASSERT(run.layoutBox().isInlineBlockBox());
     702        if (!run.logicalRect().width())
     703            return false;
     704        if (m_skipAlignment || formattingContext().geometryForBox(run.layoutBox()).height())
     705            return true;
     706        return false;
     707    }
     708
     709    ASSERT_NOT_REACHED();
     710    return false;
     711}
     712
    680713void LineBuilder::TrimmableContent::append(InlineItemRun& inlineItemRun)
    681714{
  • trunk/Source/WebCore/layout/inlineformatting/InlineLineBuilder.h

    r252905 r252923  
    146146    void justifyRuns(RunList&) const;
    147147
     148    bool isVisuallyNonEmpty(const InlineItemRun&) const;
     149
    148150    LayoutState& layoutState() const;
    149151    const InlineFormattingContext& formattingContext() const;
Note: See TracChangeset for help on using the changeset viewer.