Changeset 239334 in webkit


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

[LFC][BFC][MarginCollapsing] Implement marginAfterCollapsesWithParentMarginBefore
https://bugs.webkit.org/show_bug.cgi?id=192798

Reviewed by Antti Koivisto.

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

(WebCore::Layout::BlockFormattingContext::Geometry::inFlowNonReplacedHeightAndMargin):

  • layout/blockformatting/BlockMarginCollapse.cpp:

(WebCore::Layout::BlockFormattingContext::Geometry::MarginCollapse::collapsedMarginAfterFromLastChild):
(WebCore::Layout::BlockFormattingContext::Geometry::MarginCollapse::marginAfterCollapsesWithParentMarginBefore):
(WebCore::Layout::BlockFormattingContext::Geometry::MarginCollapse::marginAfterCollapsesWithParentMarginAfter):
(WebCore::Layout::BlockFormattingContext::Geometry::MarginCollapse::marginAfter):

Location:
trunk/Source/WebCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r239332 r239334  
     12018-12-18  Zalan Bujtas  <zalan@apple.com>
     2
     3        [LFC][BFC][MarginCollapsing] Implement marginAfterCollapsesWithParentMarginBefore
     4        https://bugs.webkit.org/show_bug.cgi?id=192798
     5
     6        Reviewed by Antti Koivisto.
     7
     8        * layout/blockformatting/BlockFormattingContext.h:
     9        * layout/blockformatting/BlockFormattingContextGeometry.cpp:
     10        (WebCore::Layout::BlockFormattingContext::Geometry::inFlowNonReplacedHeightAndMargin):
     11        * layout/blockformatting/BlockMarginCollapse.cpp:
     12        (WebCore::Layout::BlockFormattingContext::Geometry::MarginCollapse::collapsedMarginAfterFromLastChild):
     13        (WebCore::Layout::BlockFormattingContext::Geometry::MarginCollapse::marginAfterCollapsesWithParentMarginBefore):
     14        (WebCore::Layout::BlockFormattingContext::Geometry::MarginCollapse::marginAfterCollapsesWithParentMarginAfter):
     15        (WebCore::Layout::BlockFormattingContext::Geometry::MarginCollapse::marginAfter):
     16
    1172018-12-18  Zalan Bujtas  <zalan@apple.com>
    218
  • trunk/Source/WebCore/layout/blockformatting/BlockFormattingContext.h

    r239332 r239334  
    9191
    9292            static bool marginBeforeCollapsesWithParentMarginAfter(const Box&);
    93             static bool marginAfterCollapsesWithParentMarginAfter(const Box&);
     93            static bool marginAfterCollapsesWithParentMarginAfter(const LayoutState&, const Box&);
    9494
    9595        private:
     
    107107            static bool marginAfterCollapsesWithNextSibling(const Box&);
    108108            static bool marginAfterCollapsesWithSiblingMarginBeforeWithClearance(const Box&);
    109             static bool marginAfterCollapsesWithParentMarginBefore(const Box&);
     109            static bool marginAfterCollapsesWithParentMarginBefore(const LayoutState&, const Box&);
    110110            static bool marginsCollapseThrough(const LayoutState&, const Box&);
    111111        };
  • trunk/Source/WebCore/layout/blockformatting/BlockFormattingContextGeometry.cpp

    r239267 r239334  
    8585        auto* lastInFlowChild = downcast<Container>(layoutBox).lastInFlowChild();
    8686        ASSERT(lastInFlowChild);
    87         if (!MarginCollapse::marginAfterCollapsesWithParentMarginAfter(*lastInFlowChild)) {
     87        if (!MarginCollapse::marginAfterCollapsesWithParentMarginAfter(layoutState, *lastInFlowChild)) {
    8888            auto& lastInFlowDisplayBox = layoutState.displayBoxForLayoutBox(*lastInFlowChild);
    8989            return { lastInFlowDisplayBox.bottom() + lastInFlowDisplayBox.marginAfter() - borderAndPaddingTop, { nonCollapsedMargin, collapsedMargin } };
  • trunk/Source/WebCore/layout/blockformatting/BlockMarginCollapse.cpp

    r239332 r239334  
    168168    // FIXME: Check for collapsed through margin.
    169169    auto& lastInFlowChild = *downcast<Container>(layoutBox).lastInFlowChild();
    170     if (!marginAfterCollapsesWithParentMarginAfter(lastInFlowChild))
     170    if (!marginAfterCollapsesWithParentMarginAfter(layoutState, lastInFlowChild))
    171171        return 0;
    172172
     
    231231}
    232232
    233 bool BlockFormattingContext::Geometry::MarginCollapse::marginAfterCollapsesWithParentMarginBefore(const Box&)
    234 {
     233bool BlockFormattingContext::Geometry::MarginCollapse::marginAfterCollapsesWithParentMarginBefore(const LayoutState& layoutState, const Box& layoutBox)
     234{
     235    // 1. This is the first in-flow child and its margins collapse through and the margin before collapses with parent's margin before or
     236    // 2. This box's margin before collapses with the previous sibling's margin after and that sibling collapses through and
     237    // we can get to the first in-flow child like that.
     238    auto* firstInFlowChild = layoutBox.parent()->firstInFlowChild();
     239    for (auto* currentBox = &layoutBox; currentBox; currentBox = currentBox->previousInFlowSibling()) {
     240        if (!marginsCollapseThrough(layoutState, *currentBox))
     241            return false;
     242        if (currentBox == firstInFlowChild)
     243            return marginBeforeCollapsesWithParentMarginBefore(layoutState, *currentBox);
     244        if (!marginBeforeCollapsesWithPreviousSibling(*currentBox))
     245            return false;
     246    }
     247    ASSERT_NOT_REACHED();
    235248    return false;
    236249}
    237250
    238 bool BlockFormattingContext::Geometry::MarginCollapse::marginAfterCollapsesWithParentMarginAfter(const Box& layoutBox)
     251bool BlockFormattingContext::Geometry::MarginCollapse::marginAfterCollapsesWithParentMarginAfter(const LayoutState& layoutState, const Box& layoutBox)
    239252{
    240253    if (layoutBox.isAnonymous())
     
    282295    // nor (if the box's min-height is non-zero) with the box's top margin.
    283296    auto computedMinHeight = parent.style().logicalMinHeight();
    284     if (!computedMinHeight.isAuto() && computedMinHeight.value() && marginAfterCollapsesWithParentMarginBefore(layoutBox))
     297    if (!computedMinHeight.isAuto() && computedMinHeight.value() && marginAfterCollapsesWithParentMarginBefore(layoutState, layoutBox))
    285298        return false;
    286299
     
    407420
    408421    // TODO: take _hasAdjoiningMarginBeforeAndBottom() into account.
    409     if (marginAfterCollapsesWithParentMarginAfter(layoutBox))
     422    if (marginAfterCollapsesWithParentMarginAfter(layoutState, layoutBox))
    410423        return 0;
    411424
Note: See TracChangeset for help on using the changeset viewer.