Changeset 239330 in webkit


Ignore:
Timestamp:
Dec 18, 2018 7:19:21 AM (5 years ago)
Author:
Alan Bujtas
Message:

[LFC][BFC][MarginCollapsing] Expand marginAfterCollapsesWithParentMarginAfter and marginBeforeCollapsesWithParentMarginBefore collapsing logic
https://bugs.webkit.org/show_bug.cgi?id=192787

Reviewed by Antti Koivisto.

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

(WebCore::Layout::hasClearance):
(WebCore::Layout::BlockFormattingContext::Geometry::MarginCollapse::marginBeforeCollapsesWithParentMarginBefore):
(WebCore::Layout::BlockFormattingContext::Geometry::MarginCollapse::marginAfterCollapsesWithSiblingMarginBeforeWithClearance):
(WebCore::Layout::BlockFormattingContext::Geometry::MarginCollapse::marginAfterCollapsesWithParentMarginBefore):
(WebCore::Layout::BlockFormattingContext::Geometry::MarginCollapse::marginAfterCollapsesWithParentMarginAfter):

Location:
trunk/Source/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r239320 r239330  
     12018-12-18  Zalan Bujtas  <zalan@apple.com>
     2
     3        [LFC][BFC][MarginCollapsing] Expand marginAfterCollapsesWithParentMarginAfter and marginBeforeCollapsesWithParentMarginBefore collapsing logic
     4        https://bugs.webkit.org/show_bug.cgi?id=192787
     5
     6        Reviewed by Antti Koivisto.
     7
     8        * layout/blockformatting/BlockFormattingContext.h:
     9        * layout/blockformatting/BlockMarginCollapse.cpp:
     10        (WebCore::Layout::hasClearance):
     11        (WebCore::Layout::BlockFormattingContext::Geometry::MarginCollapse::marginBeforeCollapsesWithParentMarginBefore):
     12        (WebCore::Layout::BlockFormattingContext::Geometry::MarginCollapse::marginAfterCollapsesWithSiblingMarginBeforeWithClearance):
     13        (WebCore::Layout::BlockFormattingContext::Geometry::MarginCollapse::marginAfterCollapsesWithParentMarginBefore):
     14        (WebCore::Layout::BlockFormattingContext::Geometry::MarginCollapse::marginAfterCollapsesWithParentMarginAfter):
     15
    1162018-12-17  Fujii Hironori  <Hironori.Fujii@sony.com>
    217
  • trunk/Source/WebCore/layout/blockformatting/BlockFormattingContext.h

    r239267 r239330  
    106106            static bool marginBeforeCollapsesWithPreviousSibling(const Box&);
    107107            static bool marginAfterCollapsesWithNextSibling(const Box&);
     108            static bool marginAfterCollapsesWithSiblingMarginBeforeWithClearance(const Box&);
     109            static bool marginAfterCollapsesWithParentMarginBefore(const Box&);
    108110            static bool marginsCollapseThrough(const Box&);
    109111        };
  • trunk/Source/WebCore/layout/blockformatting/BlockMarginCollapse.cpp

    r239267 r239330  
    7070}
    7171
     72static bool hasClearance(const Box& layoutBox)
     73{
     74    if (!layoutBox.hasFloatClear())
     75        return false;
     76    // FIXME
     77    return false;
     78}
     79
    7280static bool establishesBlockFormattingContext(const Box& layoutBox)
    7381{
     
    180188    ASSERT(layoutBox.isBlockLevelBox());
    181189
    182     if (layoutBox.isFloatingOrOutOfFlowPositioned())
     190    // Margins between a floated box and any other box do not collapse.
     191    if (layoutBox.isFloatingPositioned())
     192        return false;
     193
     194    // Margins of absolutely positioned boxes do not collapse.
     195    if (layoutBox.isOutOfFlowPositioned())
     196        return false;
     197
     198    // Margins of inline-block boxes do not collapse.
     199    if (layoutBox.isInlineBlockBox())
    183200        return false;
    184201
     
    198215        return false;
    199216
     217    // ...and the child has no clearance.
     218    if (hasClearance(layoutBox))
     219        return false;
     220
    200221    if (BlockFormattingContext::Quirks::shouldIgnoreMarginBefore(layoutState, layoutBox))
    201222        return false;
     
    204225}
    205226
     227bool BlockFormattingContext::Geometry::MarginCollapse::marginAfterCollapsesWithSiblingMarginBeforeWithClearance(const Box&)
     228{
     229    return false;
     230}
     231
     232bool BlockFormattingContext::Geometry::MarginCollapse::marginAfterCollapsesWithParentMarginBefore(const Box&)
     233{
     234    return false;
     235}
     236
    206237bool BlockFormattingContext::Geometry::MarginCollapse::marginAfterCollapsesWithParentMarginAfter(const Box& layoutBox)
    207238{
    208     // last inflow box to parent.
    209     // https://www.w3.org/TR/CSS21/box.html#collapsing-margins
    210239    if (layoutBox.isAnonymous())
    211240        return false;
     
    213242    ASSERT(layoutBox.isBlockLevelBox());
    214243
    215     if (layoutBox.isFloatingOrOutOfFlowPositioned())
    216         return false;
    217 
    218     if (marginsCollapseThrough(layoutBox))
     244    // Margins between a floated box and any other box do not collapse.
     245    if (layoutBox.isFloatingPositioned())
     246        return false;
     247
     248    // Margins of absolutely positioned boxes do not collapse.
     249    if (layoutBox.isOutOfFlowPositioned())
     250        return false;
     251
     252    // Margins of inline-block boxes do not collapse.
     253    if (layoutBox.isInlineBlockBox())
    219254        return false;
    220255
     
    224259
    225260    auto& parent = *layoutBox.parent();
    226     // Margins of elements that establish new block formatting contexts do not collapse with their in-flow children
     261    // Margins of elements that establish new block formatting contexts do not collapse with their in-flow children.
    227262    if (establishesBlockFormattingContext(parent))
    228263        return false;
    229264
     265    // The bottom margin of an in-flow block box with a 'height' of 'auto' collapses with its last in-flow block-level child's bottom margin, if:
     266    if (!parent.style().height().isAuto())
     267        return false;
     268
     269    // the box has no bottom padding, and
     270    if (hasPaddingBefore(parent))
     271        return false;
     272
     273    // the box has no bottom border, and
    230274    if (hasBorderBefore(parent))
    231275        return false;
    232276
    233     if (hasPaddingBefore(parent))
    234         return false;
    235 
    236     if (!parent.style().height().isAuto())
     277    // the child's bottom margin neither collapses with a top margin that has clearance...
     278    if (marginAfterCollapsesWithSiblingMarginBeforeWithClearance(layoutBox))
     279        return false;
     280
     281    // nor (if the box's min-height is non-zero) with the box's top margin.
     282    auto computedMinHeight = parent.style().logicalMinHeight();
     283    if (!computedMinHeight.isAuto() && computedMinHeight.value() && marginAfterCollapsesWithParentMarginBefore(layoutBox))
    237284        return false;
    238285
Note: See TracChangeset for help on using the changeset viewer.