Changeset 252189 in webkit


Ignore:
Timestamp:
Nov 7, 2019 10:03:15 AM (4 years ago)
Author:
Alan Bujtas
Message:

[LFC][MarginCollapsing] Drag anonymous block level boxes into margin collapsing
https://bugs.webkit.org/show_bug.cgi?id=203927
<rdar://problem/56963636>

Reviewed by Antti Koivisto.

We've been ignoring anonymous block level boxes in the context of margin collapsing. Now with IFC, we can't really do that anymore.
This patch removes the early bailout on anon boxes and addresses the fallout.

  • layout/MarginTypes.h:
  • layout/blockformatting/BlockMarginCollapse.cpp:

(WebCore::Layout::BlockFormattingContext::MarginCollapse::marginBeforeCollapsesWithParentMarginBefore const):
(WebCore::Layout::BlockFormattingContext::MarginCollapse::marginBeforeCollapsesWithPreviousSiblingMarginAfter const):
(WebCore::Layout::BlockFormattingContext::MarginCollapse::marginBeforeCollapsesWithFirstInFlowChildMarginBefore const):
(WebCore::Layout::BlockFormattingContext::MarginCollapse::marginAfterCollapsesWithParentMarginAfter const):
(WebCore::Layout::BlockFormattingContext::MarginCollapse::marginAfterCollapsesWithLastInFlowChildMarginAfter const):
(WebCore::Layout::BlockFormattingContext::MarginCollapse::updateMarginAfterForPreviousSibling):
(WebCore::Layout::BlockFormattingContext::MarginCollapse::positiveNegativeMarginAfter const):
(WebCore::Layout::BlockFormattingContext::MarginCollapse::estimatedMarginBefore):
(WebCore::Layout::BlockFormattingContext::MarginCollapse::marginBeforeIgnoringCollapsingThrough):
(WebCore::Layout::BlockFormattingContext::MarginCollapse::collapsedVerticalValues):

Location:
trunk/Source/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r252185 r252189  
     12019-11-07  Zalan Bujtas  <zalan@apple.com>
     2
     3        [LFC][MarginCollapsing] Drag anonymous block level boxes into margin collapsing
     4        https://bugs.webkit.org/show_bug.cgi?id=203927
     5        <rdar://problem/56963636>
     6
     7        Reviewed by Antti Koivisto.
     8
     9        We've been ignoring anonymous block level boxes in the context of margin collapsing. Now with IFC, we can't really do that anymore.
     10        This patch removes the early bailout on anon boxes and addresses the fallout.
     11
     12        * layout/MarginTypes.h:
     13        * layout/blockformatting/BlockMarginCollapse.cpp:
     14        (WebCore::Layout::BlockFormattingContext::MarginCollapse::marginBeforeCollapsesWithParentMarginBefore const):
     15        (WebCore::Layout::BlockFormattingContext::MarginCollapse::marginBeforeCollapsesWithPreviousSiblingMarginAfter const):
     16        (WebCore::Layout::BlockFormattingContext::MarginCollapse::marginBeforeCollapsesWithFirstInFlowChildMarginBefore const):
     17        (WebCore::Layout::BlockFormattingContext::MarginCollapse::marginAfterCollapsesWithParentMarginAfter const):
     18        (WebCore::Layout::BlockFormattingContext::MarginCollapse::marginAfterCollapsesWithLastInFlowChildMarginAfter const):
     19        (WebCore::Layout::BlockFormattingContext::MarginCollapse::updateMarginAfterForPreviousSibling):
     20        (WebCore::Layout::BlockFormattingContext::MarginCollapse::positiveNegativeMarginAfter const):
     21        (WebCore::Layout::BlockFormattingContext::MarginCollapse::estimatedMarginBefore):
     22        (WebCore::Layout::BlockFormattingContext::MarginCollapse::marginBeforeIgnoringCollapsingThrough):
     23        (WebCore::Layout::BlockFormattingContext::MarginCollapse::collapsedVerticalValues):
     24
    1252019-11-07  Alex Christensen  <achristensen@webkit.org>
    226
  • trunk/Source/WebCore/layout/MarginTypes.h

    r240583 r252189  
    8383};
    8484
     85// FIXME: This structure might need to change to indicate that the cached value is not necessarily the same as the box's computed margin value.
     86// This only matters in case of collapse through margins when they collapse into another sibling box.
     87// <div style="margin: 1px"></div><div style="margin: 10px"></div> <- the second div's before/after marings collapse through and the same time they collapse into
     88// the first div. When the parent computes its before margin, it should see the second div's collapsed through margin as the value to collapse width (adjoining margin value).
     89// So while the first div's before margin is not 10px, the cached value is 10px so that when we compute the parent's margin we just need to check the fist
     90// inflow child's cached margin value.
    8591struct PositiveAndNegativeVerticalMargin {
    8692    struct Values {
  • trunk/Source/WebCore/layout/blockformatting/BlockMarginCollapse.cpp

    r252143 r252189  
    113113    // The first inflow child could propagate its top margin to parent.
    114114    // https://www.w3.org/TR/CSS21/box.html#collapsing-margins
    115     if (layoutBox.isAnonymous())
    116         return false;
    117 
    118115    ASSERT(layoutBox.isBlockLevelBox());
    119116
     
    156153    ASSERT(layoutBox.isBlockLevelBox());
    157154
    158     if (layoutBox.isAnonymous())
    159         return false;
    160 
    161155    if (!layoutBox.previousInFlowSibling())
    162156        return false;
    163157
    164158    auto& previousInFlowSibling = *layoutBox.previousInFlowSibling();
    165     if (previousInFlowSibling.isAnonymous())
    166         return false;
    167 
    168159    // Margins between a floated box and any other box do not collapse.
    169160    if (layoutBox.isFloatingPositioned() || previousInFlowSibling.isFloatingPositioned())
     
    189180bool BlockFormattingContext::MarginCollapse::marginBeforeCollapsesWithFirstInFlowChildMarginBefore(const Box& layoutBox) const
    190181{
    191     if (layoutBox.isAnonymous())
    192         return false;
    193 
    194182    ASSERT(layoutBox.isBlockLevelBox());
    195183    // Margins of elements that establish new block formatting contexts do not collapse with their in-flow children.
     
    260248bool BlockFormattingContext::MarginCollapse::marginAfterCollapsesWithParentMarginAfter(const Box& layoutBox) const
    261249{
    262     if (layoutBox.isAnonymous())
    263         return false;
    264 
    265250    ASSERT(layoutBox.isBlockLevelBox());
    266251
     
    349334    // Margins of inline-block boxes do not collapse.
    350335    if (lastInFlowChild.isInlineBlockBox())
     336        return false;
     337
     338    // This is a quirk behavior: When the margin after of the last inflow child (or a previous sibling with collapsed through margins)
     339    // collapses with a quirk parent's the margin before, then the same margin after does not collapses with the parent's margin after.
     340    if (formattingContext().quirks().shouldIgnoreCollapsedQuirkMargin(layoutBox) && marginAfterCollapsesWithParentMarginBefore(lastInFlowChild))
    351341        return false;
    352342
     
    476466    // 2. Update the collapsed margin after value as well as the positive/negative cache.
    477467    // 3. Check if the box's margins collapse through.
    478     // 4. If so, update the collapsed margin before value as well as the positive/negative cache.
     468    // 4. If so, update the positive/negative cache.
    479469    // 5. In case of collapsed through margins check if the before margin collapes with the previous inflow sibling's after margin.
    480470    // 6. If so, jump to #2.
     
    494484            collapsedVerticalMarginBefore = collapsedVerticalMarginAfter;
    495485
    496         // Update collapsed vertical margin values.
    497         previousSiblingVerticalMargin.setCollapsedValues({ collapsedVerticalMarginBefore, collapsedVerticalMarginAfter });
    498         previousSiblingDisplayBox.setVerticalMargin(previousSiblingVerticalMargin);
    499 
    500486        // Update positive/negative cache.
    501487        auto previousSiblingPositiveNegativeMargin = blockFormattingState.positiveAndNegativeVerticalMargin(previousSibling);
     
    573559
    574560    // We don't know yet the margin before value of the next sibling. Let's just pretend it does not have one and
    575     // update it later when we compute the next sibling's margin before. See updateCollapsedMarginAfter.
     561    // update it later when we compute the next sibling's margin before. See updateMarginAfterForPreviousSibling.
    576562    PositiveAndNegativeVerticalMargin::Values nonCollapsedAfter;
    577563    if (nonCollapsedValues.after > 0)
     
    585571EstimatedMarginBefore BlockFormattingContext::MarginCollapse::estimatedMarginBefore(const Box& layoutBox, UsedVerticalMargin::NonCollapsedValues usedNonCollapsedMargin)
    586572{
    587     if (layoutBox.isAnonymous())
    588         return { };
    589 
    590573    ASSERT(layoutBox.isBlockLevelBox());
    591574    // Don't estimate vertical margins for out of flow boxes.
     
    604587LayoutUnit BlockFormattingContext::MarginCollapse::marginBeforeIgnoringCollapsingThrough(const Box& layoutBox, UsedVerticalMargin::NonCollapsedValues nonCollapsedValues)
    605588{
    606     ASSERT(!layoutBox.isAnonymous());
    607589    ASSERT(layoutBox.isBlockLevelBox());
    608590    return marginValue(positiveNegativeMarginBefore(layoutBox, nonCollapsedValues)).valueOr(nonCollapsedValues.before);
     
    626608UsedVerticalMargin::CollapsedValues BlockFormattingContext::MarginCollapse::collapsedVerticalValues(const Box& layoutBox, UsedVerticalMargin::NonCollapsedValues nonCollapsedValues)
    627609{
    628     if (layoutBox.isAnonymous())
    629         return { };
    630 
    631610    ASSERT(layoutBox.isBlockLevelBox());
    632611    // 1. Get min/max margin top values from the first in-flow child if we are collapsing margin top with it.
Note: See TracChangeset for help on using the changeset viewer.