Changeset 240436 in webkit


Ignore:
Timestamp:
Jan 24, 2019 9:15:46 AM (5 years ago)
Author:
Alan Bujtas
Message:

[LFC][BFC][MarginCollapsing] MarginCollapse::collapsedVerticalValues should not return computed non-collapsed values.
https://bugs.webkit.org/show_bug.cgi?id=193768

Reviewed by Antti Koivisto.

When it comes to the actual used values it does not really matter, only from correctness point of view.
(This patch also moves some checks to their correct place.)

  • layout/blockformatting/BlockMarginCollapse.cpp:

(WebCore::Layout::BlockFormattingContext::MarginCollapse::marginBeforeCollapsesWithPreviousSiblingMarginAfter):
(WebCore::Layout::BlockFormattingContext::MarginCollapse::marginBeforeCollapsesWithFirstInFlowChildMarginBefore):
(WebCore::Layout::BlockFormattingContext::MarginCollapse::marginAfterCollapsesWithLastInFlowChildMarginAfter):
(WebCore::Layout::BlockFormattingContext::MarginCollapse::positiveNegativeMarginBefore):
(WebCore::Layout::BlockFormattingContext::MarginCollapse::positiveNegativeMarginAfter):
(WebCore::Layout::BlockFormattingContext::MarginCollapse::collapsedVerticalValues):

Location:
trunk/Source/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r240435 r240436  
     12019-01-24  Zalan Bujtas  <zalan@apple.com>
     2
     3        [LFC][BFC][MarginCollapsing] MarginCollapse::collapsedVerticalValues should not return computed non-collapsed values.
     4        https://bugs.webkit.org/show_bug.cgi?id=193768
     5
     6        Reviewed by Antti Koivisto.
     7
     8        When it comes to the actual used values it does not really matter, only from correctness point of view.
     9        (This patch also moves some checks to their correct place.)
     10
     11        * layout/blockformatting/BlockMarginCollapse.cpp:
     12        (WebCore::Layout::BlockFormattingContext::MarginCollapse::marginBeforeCollapsesWithPreviousSiblingMarginAfter):
     13        (WebCore::Layout::BlockFormattingContext::MarginCollapse::marginBeforeCollapsesWithFirstInFlowChildMarginBefore):
     14        (WebCore::Layout::BlockFormattingContext::MarginCollapse::marginAfterCollapsesWithLastInFlowChildMarginAfter):
     15        (WebCore::Layout::BlockFormattingContext::MarginCollapse::positiveNegativeMarginBefore):
     16        (WebCore::Layout::BlockFormattingContext::MarginCollapse::positiveNegativeMarginAfter):
     17        (WebCore::Layout::BlockFormattingContext::MarginCollapse::collapsedVerticalValues):
     18
    1192019-01-23  Simon Fraser  <simon.fraser@apple.com>
    220
  • trunk/Source/WebCore/layout/blockformatting/BlockMarginCollapse.cpp

    r240337 r240436  
    157157    auto& previousInFlowSibling = *layoutBox.previousInFlowSibling();
    158158
     159    if (Quirks::shouldIgnoreMarginAfter(layoutState, previousInFlowSibling))
     160        return false;
     161
    159162    // Margins between a floated box and any other box do not collapse.
    160163    if (layoutBox.isFloatingPositioned() || previousInFlowSibling.isFloatingPositioned())
     
    201204
    202205    auto& firstInFlowChild = *downcast<Container>(layoutBox).firstInFlowChild();
     206    if (Quirks::shouldIgnoreMarginBefore(layoutState, firstInFlowChild))
     207        return false;
     208
    203209    if (!firstInFlowChild.isBlockLevelBox())
    204210        return false;
     
    321327
    322328    auto& lastInFlowChild = *downcast<Container>(layoutBox).lastInFlowChild();
     329    if (Quirks::shouldIgnoreMarginAfter(layoutState, lastInFlowChild))
     330        return false;
     331
    323332    if (!lastInFlowChild.isBlockLevelBox())
    324333        return false;
     
    536545{
    537546    auto firstChildCollapsedMarginBefore = [&]() -> PositiveAndNegativeVerticalMargin::Values {
    538         if (!is<Container>(layoutBox))
    539             return { };
    540         auto* firstInFlowChild = downcast<Container>(layoutBox).firstInFlowChild();
    541         if (!firstInFlowChild)
    542             return { };
    543547        if (!marginBeforeCollapsesWithFirstInFlowChildMarginBefore(layoutState, layoutBox))
    544548            return { };
    545         if (Quirks::shouldIgnoreMarginBefore(layoutState, *firstInFlowChild))
    546             return { };
    547         return positiveNegativeValues(layoutState, *firstInFlowChild, MarginType::Before);
     549        return positiveNegativeValues(layoutState, *downcast<Container>(layoutBox).firstInFlowChild(), MarginType::Before);
    548550    };
    549551
    550552    auto previouSiblingCollapsedMarginAfter = [&]() -> PositiveAndNegativeVerticalMargin::Values {
    551         auto* previousInFlowSibling = layoutBox.previousInFlowSibling();
    552         if (!previousInFlowSibling)
    553             return { };
    554553        if (!marginBeforeCollapsesWithPreviousSiblingMarginAfter(layoutState, layoutBox))
    555554            return { };
    556         if (Quirks::shouldIgnoreMarginAfter(layoutState, *previousInFlowSibling))
    557             return { };
    558         return positiveNegativeValues(layoutState, *previousInFlowSibling, MarginType::After);
     555        return positiveNegativeValues(layoutState, *downcast<Container>(layoutBox).previousInFlowSibling(), MarginType::After);
    559556    };
    560557
     
    569566{
    570567    auto lastChildCollapsedMarginAfter = [&]() -> PositiveAndNegativeVerticalMargin::Values {
    571         if (!is<Container>(layoutBox))
    572             return { };
    573         auto* lastInFlowChild = downcast<Container>(layoutBox).lastInFlowChild();
    574         if (!lastInFlowChild)
    575             return { };
    576568        if (!marginAfterCollapsesWithLastInFlowChildMarginAfter(layoutState, layoutBox))
    577569            return { };
    578         if (Quirks::shouldIgnoreMarginAfter(layoutState, *lastInFlowChild))
    579             return { };
    580         return positiveNegativeValues(layoutState, *lastInFlowChild, MarginType::After);
     570        return positiveNegativeValues(layoutState, *downcast<Container>(layoutBox).lastInFlowChild(), MarginType::After);
    581571    };
    582572
     
    625615    // 2. Get min/max margin top values from the previous in-flow sibling, if we are collapsing margin top with it.
    626616    // 3. Get this layout box's computed margin top value.
    627     // 4. Update the min/max value and compute the final margin. 
     617    // 4. Update the min/max value and compute the final margin.
    628618    auto positiveNegativeMarginBefore = MarginCollapse::positiveNegativeMarginBefore(layoutState, layoutBox, nonCollapsedValues);
    629619    auto positiveNegativeMarginAfter = MarginCollapse::positiveNegativeMarginAfter(layoutState, layoutBox, nonCollapsedValues);
    630620
    631     auto marginsCollapseThrough = MarginCollapse::marginsCollapseThrough(layoutState, layoutBox); 
     621    auto marginsCollapseThrough = MarginCollapse::marginsCollapseThrough(layoutState, layoutBox);
    632622    if (marginsCollapseThrough) {
    633623        positiveNegativeMarginBefore = computedPositiveAndNegativeMargin(positiveNegativeMarginBefore, positiveNegativeMarginAfter);
    634         positiveNegativeMarginAfter = positiveNegativeMarginBefore;         
    635     }
    636 
     624        positiveNegativeMarginAfter = positiveNegativeMarginBefore;
     625    }
     626
     627    // FIXME: Move state saving out of this function.
    637628    auto& blockFormattingState = downcast<BlockFormattingState>(layoutState.formattingStateForBox(layoutBox));
    638629    blockFormattingState.setPositiveAndNegativeVerticalMargin(layoutBox, { positiveNegativeMarginBefore, positiveNegativeMarginAfter });
    639630
    640     return { marginValue(positiveNegativeMarginBefore), marginValue(positiveNegativeMarginAfter), marginsCollapseThrough };
     631    auto beforeMarginIsCollapsedValue = marginBeforeCollapsesWithFirstInFlowChildMarginBefore(layoutState, layoutBox) || marginBeforeCollapsesWithPreviousSiblingMarginAfter(layoutState, layoutBox);
     632    auto afterMarginIsCollapsedValue = marginAfterCollapsesWithLastInFlowChildMarginAfter(layoutState, layoutBox);
     633
     634    if ((beforeMarginIsCollapsedValue && afterMarginIsCollapsedValue) || marginsCollapseThrough)
     635        return { marginValue(positiveNegativeMarginBefore), marginValue(positiveNegativeMarginAfter), marginsCollapseThrough };
     636    if (beforeMarginIsCollapsedValue)
     637        return { marginValue(positiveNegativeMarginBefore), { }, false };
     638    return { { }, marginValue(positiveNegativeMarginAfter), false };
    641639}
    642640
Note: See TracChangeset for help on using the changeset viewer.