Changeset 232661 in webkit


Ignore:
Timestamp:
Jun 9, 2018 12:35:33 PM (6 years ago)
Author:
Alan Bujtas
Message:

[LFC] MarginCollapse functions should be able to resolve non-fixed margin values
https://bugs.webkit.org/show_bug.cgi?id=186461

Reviewed by Antti Koivisto.

We need the containing block's computed width to resolve vertical and horizontal margins.

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

(WebCore::Layout::BlockFormattingContext::MarginCollapse::collapsedMarginTopFromFirstChild):
(WebCore::Layout::BlockFormattingContext::MarginCollapse::nonCollapsedMarginTop):
(WebCore::Layout::BlockFormattingContext::MarginCollapse::computedNonCollapsedMarginTop):
(WebCore::Layout::BlockFormattingContext::MarginCollapse::computedNonCollapsedMarginBottom):
(WebCore::Layout::BlockFormattingContext::MarginCollapse::marginTop):
(WebCore::Layout::BlockFormattingContext::MarginCollapse::marginBottom):
(WebCore::Layout::BlockFormattingContext::MarginCollapse::collapsedMarginBottomFromLastChild):
(WebCore::Layout::BlockFormattingContext::MarginCollapse::nonCollapsedMarginBottom):
(WebCore::Layout::collapsedMarginTopFromFirstChild): Deleted.
(WebCore::Layout::nonCollapsedMarginTop): Deleted.

Location:
trunk/Source/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r232660 r232661  
     12018-06-09  Zalan Bujtas  <zalan@apple.com>
     2
     3        [LFC] MarginCollapse functions should be able to resolve non-fixed margin values
     4        https://bugs.webkit.org/show_bug.cgi?id=186461
     5
     6        Reviewed by Antti Koivisto.
     7
     8        We need the containing block's computed width to resolve vertical and horizontal margins.
     9
     10        * layout/blockformatting/BlockFormattingContext.h:
     11        * layout/blockformatting/BlockMarginCollapse.cpp:
     12        (WebCore::Layout::BlockFormattingContext::MarginCollapse::collapsedMarginTopFromFirstChild):
     13        (WebCore::Layout::BlockFormattingContext::MarginCollapse::nonCollapsedMarginTop):
     14        (WebCore::Layout::BlockFormattingContext::MarginCollapse::computedNonCollapsedMarginTop):
     15        (WebCore::Layout::BlockFormattingContext::MarginCollapse::computedNonCollapsedMarginBottom):
     16        (WebCore::Layout::BlockFormattingContext::MarginCollapse::marginTop):
     17        (WebCore::Layout::BlockFormattingContext::MarginCollapse::marginBottom):
     18        (WebCore::Layout::BlockFormattingContext::MarginCollapse::collapsedMarginBottomFromLastChild):
     19        (WebCore::Layout::BlockFormattingContext::MarginCollapse::nonCollapsedMarginBottom):
     20        (WebCore::Layout::collapsedMarginTopFromFirstChild): Deleted.
     21        (WebCore::Layout::nonCollapsedMarginTop): Deleted.
     22
    1232018-06-08  Darin Adler  <darin@apple.com>
    224
  • trunk/Source/WebCore/layout/blockformatting/BlockFormattingContext.h

    r232581 r232661  
    7878    class MarginCollapse {
    7979    public:
    80         static LayoutUnit marginTop(const Box&);
    81         static LayoutUnit marginBottom(const Box&);
     80        static LayoutUnit marginTop(const LayoutContext&, const Box&);
     81        static LayoutUnit marginBottom(const LayoutContext&, const Box&);
    8282
    8383        static bool isMarginBottomCollapsedWithParent(const Box&);
     
    8585   
    8686    private:
    87         static LayoutUnit collapsedMarginBottomFromLastChild(const Box&);
    88         static LayoutUnit nonCollapsedMarginBottom(const Box&);
     87        static LayoutUnit collapsedMarginBottomFromLastChild(const LayoutContext&, const Box&);
     88        static LayoutUnit nonCollapsedMarginBottom(const LayoutContext&, const Box&);
     89
     90        static LayoutUnit computedNonCollapsedMarginTop(const LayoutContext&, const Box&);
     91        static LayoutUnit computedNonCollapsedMarginBottom(const LayoutContext&, const Box&);
     92
     93        static LayoutUnit collapsedMarginTopFromFirstChild(const LayoutContext&, const Box&);
     94        static LayoutUnit nonCollapsedMarginTop(const LayoutContext&, const Box&);
    8995    };
    9096};
  • trunk/Source/WebCore/layout/blockformatting/BlockMarginCollapse.cpp

    r232225 r232661  
    112112}
    113113
    114 static LayoutUnit collapsedMarginTopFromFirstChild(const Box& layoutBox)
     114LayoutUnit BlockFormattingContext::MarginCollapse::collapsedMarginTopFromFirstChild(const LayoutContext& layoutContext, const Box& layoutBox)
    115115{
    116116    // Check if the first child collapses its margin top.
     
    123123
    124124    // Collect collapsed margin top recursively.
    125     return marginValue(firstInFlowChild.style().marginTop().value(), collapsedMarginTopFromFirstChild(firstInFlowChild));
    126 }
    127 
    128 static LayoutUnit nonCollapsedMarginTop(const Box& layoutBox)
     125    return marginValue(computedNonCollapsedMarginTop(layoutContext, firstInFlowChild), collapsedMarginTopFromFirstChild(layoutContext, firstInFlowChild));
     126}
     127
     128LayoutUnit BlockFormattingContext::MarginCollapse::nonCollapsedMarginTop(const LayoutContext& layoutContext, const Box& layoutBox)
    129129{
    130130    // Non collapsed margin top includes collapsed margin from inflow first child.
    131     return marginValue(layoutBox.style().marginTop().value(), collapsedMarginTopFromFirstChild(layoutBox));
     131    return marginValue(computedNonCollapsedMarginTop(layoutContext, layoutBox), collapsedMarginTopFromFirstChild(layoutContext, layoutBox));
    132132}
    133133
     
    146146    return false;
    147147}*/
    148 
    149 LayoutUnit BlockFormattingContext::MarginCollapse::marginTop(const Box& layoutBox)
     148LayoutUnit BlockFormattingContext::MarginCollapse::computedNonCollapsedMarginTop(const LayoutContext& layoutContext, const Box& layoutBox)
     149{
     150    return FormattingContext::Geometry::computedNonCollapsedVerticalMarginValue(layoutContext, layoutBox).top;
     151}
     152
     153LayoutUnit BlockFormattingContext::MarginCollapse::computedNonCollapsedMarginBottom(const LayoutContext& layoutContext, const Box& layoutBox)
     154{
     155    return FormattingContext::Geometry::computedNonCollapsedVerticalMarginValue(layoutContext, layoutBox).bottom;
     156}
     157
     158LayoutUnit BlockFormattingContext::MarginCollapse::marginTop(const LayoutContext& layoutContext, const Box& layoutBox)
    150159{
    151160    if (layoutBox.isAnonymous())
     
    158167    // Floats and out of flow positioned boxes do not collapse their margins.
    159168    if (!isMarginTopCollapsedWithSibling(layoutBox))
    160         return nonCollapsedMarginTop(layoutBox);
     169        return nonCollapsedMarginTop(layoutContext, layoutBox);
    161170
    162171    // The bottom margin of an in-flow block-level element always collapses with the top margin of its next in-flow block-level sibling,
     
    164173    auto* previousInFlowSibling = layoutBox.previousInFlowSibling();
    165174    if (!previousInFlowSibling)
    166         return nonCollapsedMarginTop(layoutBox);
    167 
    168     auto previousSiblingMarginBottom = nonCollapsedMarginBottom(*previousInFlowSibling);
    169     auto marginTop = nonCollapsedMarginTop(layoutBox);
     175        return nonCollapsedMarginTop(layoutContext, layoutBox);
     176
     177    auto previousSiblingMarginBottom = nonCollapsedMarginBottom(layoutContext, *previousInFlowSibling);
     178    auto marginTop = nonCollapsedMarginTop(layoutContext, layoutBox);
    170179    return marginValue(marginTop, previousSiblingMarginBottom);
    171180}
    172181
    173 LayoutUnit BlockFormattingContext::MarginCollapse::marginBottom(const Box& layoutBox)
     182LayoutUnit BlockFormattingContext::MarginCollapse::marginBottom(const LayoutContext& layoutContext, const Box& layoutBox)
    174183{
    175184    if (layoutBox.isAnonymous())
     
    182191    // Floats and out of flow positioned boxes do not collapse their margins.
    183192    if (!isMarginBottomCollapsedWithSibling(layoutBox))
    184         return nonCollapsedMarginBottom(layoutBox);
     193        return nonCollapsedMarginBottom(layoutContext, layoutBox);
    185194
    186195    // The bottom margin of an in-flow block-level element always collapses with the top margin of its next in-flow block-level sibling,
     
    188197    if (layoutBox.nextInFlowSibling())
    189198        return 0;
    190     return nonCollapsedMarginBottom(layoutBox);
     199    return nonCollapsedMarginBottom(layoutContext, layoutBox);
    191200}
    192201
     
    232241}
    233242
    234 LayoutUnit BlockFormattingContext::MarginCollapse::collapsedMarginBottomFromLastChild(const Box& layoutBox)
     243LayoutUnit BlockFormattingContext::MarginCollapse::collapsedMarginBottomFromLastChild(const LayoutContext& layoutContext, const Box& layoutBox)
    235244{
    236245    // Check if the last child propagates its margin bottom.
     
    243252
    244253    // Collect collapsed margin bottom recursively.
    245     return marginValue(lastInFlowChild.style().marginBottom().value(), collapsedMarginBottomFromLastChild(lastInFlowChild));
    246 }
    247 
    248 LayoutUnit BlockFormattingContext::MarginCollapse::nonCollapsedMarginBottom(const Box& layoutBox)
     254    return marginValue(computedNonCollapsedMarginBottom(layoutContext, lastInFlowChild), collapsedMarginBottomFromLastChild(layoutContext, lastInFlowChild));
     255}
     256
     257LayoutUnit BlockFormattingContext::MarginCollapse::nonCollapsedMarginBottom(const LayoutContext& layoutContext, const Box& layoutBox)
    249258{
    250259    // Non collapsed margin bottom includes collapsed margin from inflow last child.
    251     return marginValue(layoutBox.style().marginBottom().value(), collapsedMarginBottomFromLastChild(layoutBox));
     260    return marginValue(computedNonCollapsedMarginBottom(layoutContext, layoutBox), collapsedMarginBottomFromLastChild(layoutContext, layoutBox));
    252261}
    253262
Note: See TracChangeset for help on using the changeset viewer.