Changeset 232871 in webkit


Ignore:
Timestamp:
Jun 15, 2018 9:00:56 AM (6 years ago)
Author:
Alan Bujtas
Message:

[LFC] Align compute functions styles.
https://bugs.webkit.org/show_bug.cgi?id=186649

Reviewed by Antti Koivisto.

Improve code readability.

  • layout/FormattingContext.h:
  • layout/FormattingContextGeometry.cpp:

(WebCore::Layout::contentHeightForFormattingContextRoot):
(WebCore::Layout::FormattingContext::Geometry::computedValueIfNotAuto):
(WebCore::Layout::FormattingContext::Geometry::outOfFlowReplacedVerticalGeometry):
(WebCore::Layout::FormattingContext::Geometry::outOfFlowReplacedHorizontalGeometry):
(WebCore::Layout::FormattingContext::Geometry::floatingNonReplacedWidthAndMargin):
(WebCore::Layout::FormattingContext::Geometry::floatingReplacedHeightAndMargin):
(WebCore::Layout::FormattingContext::Geometry::floatingReplacedWidthAndMargin):
(WebCore::Layout::FormattingContext::Geometry::inlineReplacedHeightAndMargin):
(WebCore::Layout::FormattingContext::Geometry::inlineReplacedWidthAndMargin):
(WebCore::Layout::FormattingContext::Geometry::computedNonCollapsedHorizontalMarginValue):
(WebCore::Layout::FormattingContext::Geometry::computedNonCollapsedVerticalMarginValue):
(WebCore::Layout::computedValueIfNotAuto): Deleted.

  • layout/blockformatting/BlockFormattingContextGeometry.cpp:

(WebCore::Layout::BlockFormattingContext::Geometry::inFlowNonReplacedHeightAndMargin):
(WebCore::Layout::BlockFormattingContext::Geometry::inFlowNonReplacedWidthAndMargin):
(WebCore::Layout::BlockFormattingContext::Geometry::inFlowReplacedWidthAndMargin):
(WebCore::Layout::BlockFormattingContext::Geometry::staticPosition):
(WebCore::Layout::BlockFormattingContext::Geometry::inFlowPositionedPosition):

Location:
trunk/Source/WebCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r232870 r232871  
     12018-06-15  Zalan Bujtas  <zalan@apple.com>
     2
     3        [LFC] Align compute functions styles.
     4        https://bugs.webkit.org/show_bug.cgi?id=186649
     5
     6        Reviewed by Antti Koivisto.
     7
     8        Improve code readability.
     9
     10        * layout/FormattingContext.h:
     11        * layout/FormattingContextGeometry.cpp:
     12        (WebCore::Layout::contentHeightForFormattingContextRoot):
     13        (WebCore::Layout::FormattingContext::Geometry::computedValueIfNotAuto):
     14        (WebCore::Layout::FormattingContext::Geometry::outOfFlowReplacedVerticalGeometry):
     15        (WebCore::Layout::FormattingContext::Geometry::outOfFlowReplacedHorizontalGeometry):
     16        (WebCore::Layout::FormattingContext::Geometry::floatingNonReplacedWidthAndMargin):
     17        (WebCore::Layout::FormattingContext::Geometry::floatingReplacedHeightAndMargin):
     18        (WebCore::Layout::FormattingContext::Geometry::floatingReplacedWidthAndMargin):
     19        (WebCore::Layout::FormattingContext::Geometry::inlineReplacedHeightAndMargin):
     20        (WebCore::Layout::FormattingContext::Geometry::inlineReplacedWidthAndMargin):
     21        (WebCore::Layout::FormattingContext::Geometry::computedNonCollapsedHorizontalMarginValue):
     22        (WebCore::Layout::FormattingContext::Geometry::computedNonCollapsedVerticalMarginValue):
     23        (WebCore::Layout::computedValueIfNotAuto): Deleted.
     24        * layout/blockformatting/BlockFormattingContextGeometry.cpp:
     25        (WebCore::Layout::BlockFormattingContext::Geometry::inFlowNonReplacedHeightAndMargin):
     26        (WebCore::Layout::BlockFormattingContext::Geometry::inFlowNonReplacedWidthAndMargin):
     27        (WebCore::Layout::BlockFormattingContext::Geometry::inFlowReplacedWidthAndMargin):
     28        (WebCore::Layout::BlockFormattingContext::Geometry::staticPosition):
     29        (WebCore::Layout::BlockFormattingContext::Geometry::inFlowPositionedPosition):
     30
    1312018-06-15  Zalan Bujtas  <zalan@apple.com>
    232
  • trunk/Source/WebCore/layout/FormattingContext.h

    r232743 r232871  
    120120        static Display::Box::VerticalEdges computedNonCollapsedVerticalMarginValue(const LayoutContext&, const Box&);
    121121
     122        static std::optional<LayoutUnit> computedValueIfNotAuto(const Length& geometryProperty, LayoutUnit containingBlockWidth);
     123
    122124    private:
    123125        static VerticalGeometry outOfFlowReplacedVerticalGeometry(LayoutContext&, const Box&);
  • trunk/Source/WebCore/layout/FormattingContextGeometry.cpp

    r232870 r232871  
    3535{
    3636    ASSERT(layoutBox.style().logicalHeight().isAuto() && layoutBox.establishesFormattingContext());
     37
    3738    // 10.6.7 'Auto' heights for block formatting context roots
    3839
     
    6869}
    6970
    70 static std::optional<LayoutUnit> computedValueIfNotAuto(const Length& geometryProperty, LayoutUnit containingBlockWidth)
     71std::optional<LayoutUnit> FormattingContext::Geometry::computedValueIfNotAuto(const Length& geometryProperty, LayoutUnit containingBlockWidth)
    7172{
    7273    if (geometryProperty.isAuto())
     
    336337{
    337338    ASSERT(layoutBox.isOutOfFlowPositioned() && layoutBox.replaced());
     339
    338340    // 10.6.5 Absolutely positioned, replaced elements
    339341    //
     
    404406{
    405407    ASSERT(layoutBox.isOutOfFlowPositioned() && layoutBox.replaced());
     408
    406409    // 10.3.8 Absolutely positioned, replaced elements
    407410    // In this case, section 10.3.7 applies up through and including the constraint equation, but the rest of section 10.3.7 is replaced by the following rules:
     
    536539    // 2. If 'width' is computed as 'auto', the used value is the "shrink-to-fit" width.
    537540
    538     auto& style = layoutBox.style();
    539     auto width = style.logicalWidth();
     541    auto& containingBlock = *layoutBox.containingBlock();
     542    auto& containingBlockDisplayBox = *layoutContext.displayBoxForLayoutBox(containingBlock);
     543
    540544    // #1
    541     auto computedNonCollapsedHorizontalMarginValues = computedNonCollapsedHorizontalMarginValue(layoutContext, layoutBox);
    542     // #2
    543     auto computedWidthValue = width.isAuto() ? shrinkToFitWidth(layoutContext, layoutBox) : LayoutUnit(width.value());
    544     LOG_WITH_STREAM(FormattingContextLayout, stream << "[Width][Margin] -> floating non-replaced -> width(" << computedWidthValue << "px) margin(" << computedNonCollapsedHorizontalMarginValues.left << "px, " << computedNonCollapsedHorizontalMarginValues.right << "px) -> layoutBox(" << &layoutBox << ")");
    545     return FormattingContext::Geometry::WidthAndMargin { computedWidthValue, computedNonCollapsedHorizontalMarginValues };
     545    auto margin = computedNonCollapsedHorizontalMarginValue(layoutContext, layoutBox);
     546      // #2
     547    auto width = computedValueIfNotAuto(layoutBox.style().logicalWidth(), containingBlockDisplayBox.width());
     548    if (!width)
     549        width = shrinkToFitWidth(layoutContext, layoutBox);
     550
     551    LOG_WITH_STREAM(FormattingContextLayout, stream << "[Width][Margin] -> floating non-replaced -> width(" << *width << "px) margin(" << margin.left << "px, " << margin.right << "px) -> layoutBox(" << &layoutBox << ")");
     552    return FormattingContext::Geometry::WidthAndMargin { *width, margin };
    546553}
    547554
     
    549556{
    550557    ASSERT(layoutBox.isFloatingPositioned() && layoutBox.replaced());
     558
    551559    // 10.6.2 Inline replaced elements, block-level replaced elements in normal flow, 'inline-block'
    552560    // replaced elements in normal flow and floating replaced elements
     
    558566{
    559567    ASSERT(layoutBox.isFloatingPositioned() && layoutBox.replaced());
     568
    560569    // 10.3.6 Floating, replaced elements
    561570    //
    562571    // 1. If 'margin-left' or 'margin-right' are computed as 'auto', their used value is '0'.
    563572    // 2. The used value of 'width' is determined as for inline replaced elements.
    564     auto computedNonCollapsedHorizontalMarginValues = computedNonCollapsedHorizontalMarginValue(layoutContext, layoutBox);
     573    auto margin = computedNonCollapsedHorizontalMarginValue(layoutContext, layoutBox);
     574
    565575    LOG_WITH_STREAM(FormattingContextLayout, stream << "[Height][Margin] -> floating replaced -> redirected to inline replaced");
    566     return inlineReplacedWidthAndMargin(layoutContext, layoutBox, computedNonCollapsedHorizontalMarginValues.left, computedNonCollapsedHorizontalMarginValues.right);
     576    return inlineReplacedWidthAndMargin(layoutContext, layoutBox, margin.left, margin.right);
    567577}
    568578
     
    606616{
    607617    ASSERT((layoutBox.isOutOfFlowPositioned() || layoutBox.isFloatingPositioned() || layoutBox.isInFlow()) && layoutBox.replaced());
     618
    608619    // 10.6.2 Inline replaced elements, block-level replaced elements in normal flow, 'inline-block' replaced elements in normal flow and floating replaced elements
    609620    //
     
    617628
    618629    // #1
    619     auto computedNonCollapsedVerticalMarginValues = computedNonCollapsedVerticalMarginValue(layoutContext, layoutBox);
    620 
    621     auto& style = layoutBox.style();
    622     auto height = style.logicalHeight();
    623     LayoutUnit computedHeightValue;
    624     if (height.isAuto()) {
    625         auto width = style.logicalWidth();
    626         auto replaced = layoutBox.replaced();
    627 
    628         if (width.isAuto() && replaced->hasIntrinsicHeight()) {
    629             // #2
    630             computedHeightValue = replaced->intrinsicHeight();
    631         } else if (replaced->hasIntrinsicRatio()) {
    632             // #3
    633             computedHeightValue = width.value() / replaced->intrinsicRatio();
    634         } else if (replaced->hasIntrinsicHeight()) {
    635             // #4
    636             computedHeightValue = replaced->intrinsicHeight();
    637         } else {
    638             // #5
    639             computedHeightValue = 150;
    640         }
    641     } else
    642         computedHeightValue = height.value();
    643 
    644     LOG_WITH_STREAM(FormattingContextLayout, stream << "[Height][Margin] -> inflow replaced -> height(" << computedHeightValue << "px) margin(" << computedNonCollapsedVerticalMarginValues.top << "px, " << computedNonCollapsedVerticalMarginValues.bottom << "px) -> layoutBox(" << &layoutBox << ")");
    645     return { computedHeightValue, computedNonCollapsedVerticalMarginValues };
     630    auto margin = computedNonCollapsedVerticalMarginValue(layoutContext, layoutBox);
     631
     632    auto& style = layoutBox.style();
     633    auto replaced = layoutBox.replaced();
     634    auto& containingBlock = *layoutBox.containingBlock();
     635    auto& containingBlockDisplayBox = *layoutContext.displayBoxForLayoutBox(containingBlock);
     636    auto height = computedValueIfNotAuto(style.logicalHeight(), containingBlockDisplayBox.height());
     637    auto width = computedValueIfNotAuto(style.logicalWidth(), containingBlockDisplayBox.width());
     638
     639    if (!height && !width && replaced->hasIntrinsicHeight()) {
     640        // #2
     641        height = replaced->intrinsicHeight();
     642    } else if (!height && replaced->hasIntrinsicRatio()) {
     643        // #3
     644        height = *width / replaced->intrinsicRatio();
     645    } else if (!height && replaced->hasIntrinsicHeight()) {
     646        // #4
     647        height = replaced->intrinsicHeight();
     648    } else if (!height) {
     649        // #5
     650        height = { 150 };
     651    }
     652
     653    ASSERT(height);
     654
     655    LOG_WITH_STREAM(FormattingContextLayout, stream << "[Height][Margin] -> inflow replaced -> height(" << *height << "px) margin(" << margin.top << "px, " << margin.bottom << "px) -> layoutBox(" << &layoutBox << ")");
     656    return { *height, margin };
    646657}
    647658
     
    650661{
    651662    ASSERT((layoutBox.isOutOfFlowPositioned() || layoutBox.isFloatingPositioned() || layoutBox.isInFlow()) && layoutBox.replaced());
     663
    652664    // 10.3.2 Inline, replaced elements
    653665    //
     
    668680    // 5. Otherwise, if 'width' has a computed value of 'auto', but none of the conditions above are met, then the used value of 'width' becomes 300px.
    669681    //    If 300px is too wide to fit the device, UAs should use the width of the largest rectangle that has a 2:1 ratio and fits the device instead.
    670     auto& style = layoutBox.style();
    671     auto containingBlockWidth = layoutContext.displayBoxForLayoutBox(*layoutBox.containingBlock())->width();
     682
     683    auto& style = layoutBox.style();
     684    auto& containingBlock = *layoutBox.containingBlock();
     685    auto& containingBlockDisplayBox = *layoutContext.displayBoxForLayoutBox(containingBlock);
    672686
    673687    auto computeMarginRight = [&]() {
    674688        if (precomputedMarginRight)
    675689            return precomputedMarginRight.value();
    676         auto marginRight = style.marginRight();
    677         return marginRight.isAuto() ? LayoutUnit { 0 } : valueForLength(marginRight, containingBlockWidth);
     690        auto marginRight = computedValueIfNotAuto(style.marginRight(), containingBlockDisplayBox.width());
     691        return marginRight.value_or(LayoutUnit { 0 });
    678692    };
    679693
     
    681695        if (precomputedMarginLeft)
    682696            return precomputedMarginLeft.value();
    683         auto marginLeft = style.marginLeft();
    684         return marginLeft.isAuto() ? LayoutUnit { 0 } : valueForLength(marginLeft, containingBlockWidth);
     697        auto marginLeft = computedValueIfNotAuto(style.marginLeft(), containingBlockDisplayBox.width());
     698        return marginLeft.value_or(LayoutUnit { 0 });
    685699    };
    686700
    687     LayoutUnit computedMarginLeftValue = computeMarginLeft();
    688     LayoutUnit computedMarginRightValue = computeMarginRight();
    689 
    690     LayoutUnit computedWidthValue;
    691     auto width = style.logicalWidth();
    692     auto height = style.logicalHeight();
     701    LayoutUnit marginLeft = computeMarginLeft();
     702    LayoutUnit marginRight = computeMarginRight();
     703
    693704    auto replaced = layoutBox.replaced();
     705    auto height = computedValueIfNotAuto(style.logicalHeight(), containingBlockDisplayBox.height());
     706    auto width = computedValueIfNotAuto(style.logicalWidth(), containingBlockDisplayBox.width());
     707
    694708    ASSERT(replaced);
    695709
    696     if (width.isAuto() && height.isAuto() && replaced->hasIntrinsicWidth()) {
     710    if (!width && !height && replaced->hasIntrinsicWidth()) {
    697711        // #1
    698         computedWidthValue = replaced->intrinsicWidth();
    699     } else if (width.isAuto() && (height.isCalculated() || replaced->hasIntrinsicHeight()) && replaced->hasIntrinsicRatio()) {
     712        width = replaced->intrinsicWidth();
     713    } else if ((!width && !height && !replaced->hasIntrinsicWidth() && replaced->hasIntrinsicHeight() && replaced->hasIntrinsicRatio())
     714        || (!width && height && replaced->hasIntrinsicRatio())) {
    700715        // #2
    701         auto usedHeight = height.isCalculated() ? LayoutUnit(height.value()) : replaced->intrinsicHeight();
    702         computedWidthValue = usedHeight * replaced->intrinsicRatio();
    703     } else if (width.isAuto() && height.isAuto() && replaced->hasIntrinsicRatio()) {
     716        auto usedHeight = height.value_or(replaced->intrinsicHeight());
     717        width = usedHeight * replaced->intrinsicRatio();
     718    } else if (!width && !height && replaced->hasIntrinsicRatio() && !replaced->hasIntrinsicWidth() && !replaced->hasIntrinsicHeight()) {
    704719        // #3
    705720        // FIXME: undefined but surely doable.
    706721        ASSERT_NOT_IMPLEMENTED_YET();
    707     } else if (width.isAuto() && replaced->hasIntrinsicWidth()) {
     722    } else if (!width && replaced->hasIntrinsicWidth()) {
    708723        // #4
    709         computedWidthValue = replaced->intrinsicWidth();
     724        width = replaced->intrinsicWidth();
    710725    } else {
    711726        // #5
    712         computedWidthValue = 300;
    713     }
    714 
    715     LOG_WITH_STREAM(FormattingContextLayout, stream << "[Width][Margin] -> inflow replaced -> width(" << computedWidthValue << "px) margin(" << computedMarginLeftValue << "px, " << computedMarginRightValue << "px) -> layoutBox(" << &layoutBox << ")");
    716     return { computedWidthValue, { computedMarginLeftValue, computedMarginRightValue } };
     727        width = { 300 };
     728    }
     729
     730    LOG_WITH_STREAM(FormattingContextLayout, stream << "[Width][Margin] -> inflow replaced -> width(" << *width << "px) margin(" << marginLeft << "px, " << marginRight << "px) -> layoutBox(" << &layoutBox << ")");
     731    return { *width, { marginLeft, marginRight } };
    717732}
    718733
     
    744759{
    745760    auto& style = layoutBox.style();
    746     auto marginLeft = style.marginLeft();
    747     auto marginRight = style.marginRight();
    748 
    749761    auto containingBlockWidth = layoutContext.displayBoxForLayoutBox(*layoutBox.containingBlock())->width();
    750     LOG_WITH_STREAM(FormattingContextLayout, stream << "[Margin] -> non collapsed horizontal -> layoutBox: " << &layoutBox);
    751     return {
    752         marginLeft.isAuto() ? LayoutUnit { 0 } : valueForLength(marginLeft, containingBlockWidth),
    753         marginRight.isAuto() ? LayoutUnit { 0 } : valueForLength(marginRight, containingBlockWidth)
    754     };
     762
     763    auto marginLeft = computedValueIfNotAuto(style.marginLeft(), containingBlockWidth).value_or(LayoutUnit { 0 });
     764    auto marginRight = computedValueIfNotAuto(style.marginRight(), containingBlockWidth).value_or(LayoutUnit { 0 });
     765
     766    LOG_WITH_STREAM(FormattingContextLayout, stream << "[Margin] -> non collapsed horizontal -> margin(" << marginLeft << "px, " << marginRight << "px) -> layoutBox: " << &layoutBox);
     767    return { marginLeft, marginRight };
    755768}
    756769
     
    758771{
    759772    auto& style = layoutBox.style();
    760     auto marginTop = style.marginTop();
    761     auto marginBottom = style.marginBottom();
    762 
    763773    auto containingBlockWidth = layoutContext.displayBoxForLayoutBox(*layoutBox.containingBlock())->width();
    764     LOG_WITH_STREAM(FormattingContextLayout, stream << "[Margin] -> non collapsed vertical -> layoutBox: " << &layoutBox);
    765     return {
    766         marginTop.isAuto() ? LayoutUnit { 0 } : valueForLength(marginTop, containingBlockWidth),
    767         marginBottom.isAuto() ? LayoutUnit { 0 } : valueForLength(marginBottom, containingBlockWidth)
    768     };
     774
     775    auto marginTop = computedValueIfNotAuto(style.marginTop(), containingBlockWidth).value_or(LayoutUnit { 0 });
     776    auto marginBottom = computedValueIfNotAuto(style.marginBottom(), containingBlockWidth).value_or(LayoutUnit { 0 });
     777
     778    LOG_WITH_STREAM(FormattingContextLayout, stream << "[Margin] -> non collapsed vertical -> margin(" << marginTop << "px, " << marginBottom << "px) -> layoutBox: " << &layoutBox);
     779    return { marginTop, marginBottom };
    769780}
    770781
  • trunk/Source/WebCore/layout/blockformatting/BlockFormattingContextGeometry.cpp

    r232870 r232871  
    7474        // Only children in the normal flow are taken into account (i.e., floating boxes and absolutely positioned boxes are ignored,
    7575        // and relatively positioned boxes are considered without their offset). Note that the child box may be an anonymous block box.
     76
    7677        if (!layoutBox.style().logicalHeight().isAuto()) {
    7778            // FIXME: Only fixed values yet.
     
    228229    };
    229230
    230     auto computedWidthAndMarginValue = compute();
     231    auto widthAndMargin = compute();
    231232    if (!isStretchedToViewport(layoutContext, layoutBox)) {
    232         LOG_WITH_STREAM(FormattingContextLayout, stream << "[Width][Margin] -> inflow non-replaced -> width(" << computedWidthAndMarginValue.width << "px) margin(" << computedWidthAndMarginValue.margin.left << "px, " << computedWidthAndMarginValue.margin.right << "px) -> layoutBox(" << &layoutBox << ")");
    233         return computedWidthAndMarginValue;
     233        LOG_WITH_STREAM(FormattingContextLayout, stream << "[Width][Margin] -> inflow non-replaced -> width(" << widthAndMargin.width << "px) margin(" << widthAndMargin.margin.left << "px, " << widthAndMargin.margin.right << "px) -> layoutBox(" << &layoutBox << ")");
     234        return widthAndMargin;
    234235    }
    235236
    236237    auto initialContainingBlockWidth = layoutContext.displayBoxForLayoutBox(initialContainingBlock(layoutBox))->contentBox().width();
    237     auto horizontalMargins = computedWidthAndMarginValue.margin.left + computedWidthAndMarginValue.margin.right;
     238    auto horizontalMargins = widthAndMargin.margin.left + widthAndMargin.margin.right;
    238239    // Stretch but never overstretch with the margins.
    239     if (computedWidthAndMarginValue.width + horizontalMargins < initialContainingBlockWidth)
    240         computedWidthAndMarginValue.width = initialContainingBlockWidth - horizontalMargins;
    241 
    242     LOG_WITH_STREAM(FormattingContextLayout, stream << "[Width][Margin] -> inflow non-replaced -> streched to viewport-> width(" << computedWidthAndMarginValue.width << "px) margin(" << computedWidthAndMarginValue.margin.left << "px, " << computedWidthAndMarginValue.margin.right << "px) -> layoutBox(" << &layoutBox << ")");
    243     return { computedWidthAndMarginValue.width, computedWidthAndMarginValue.margin };
     240    if (widthAndMargin.width + horizontalMargins < initialContainingBlockWidth)
     241        widthAndMargin.width = initialContainingBlockWidth - horizontalMargins;
     242
     243    LOG_WITH_STREAM(FormattingContextLayout, stream << "[Width][Margin] -> inflow non-replaced -> streched to viewport-> width(" << widthAndMargin.width << "px) margin(" << widthAndMargin.margin.left << "px, " << widthAndMargin.margin.right << "px) -> layoutBox(" << &layoutBox << ")");
     244    return widthAndMargin;
    244245}
    245246
     
    254255
    255256    // #1
    256     auto inlineReplacedWidthAndMargin = FormattingContext::Geometry::inlineReplacedWidthAndMargin(layoutContext, layoutBox);
     257    auto width = FormattingContext::Geometry::inlineReplacedWidthAndMargin(layoutContext, layoutBox).width;
    257258    // #2
    258     auto inlineReplacedWidthAndBlockNonReplacedMargin = inFlowNonReplacedWidthAndMargin(layoutContext, layoutBox, inlineReplacedWidthAndMargin.width);
    259     ASSERT(inlineReplacedWidthAndMargin.width == inlineReplacedWidthAndBlockNonReplacedMargin.width);
    260     LOG_WITH_STREAM(FormattingContextLayout, stream << "[Width][Margin] -> inflow replaced -> width(" << inlineReplacedWidthAndBlockNonReplacedMargin.width << "px) margin(" << inlineReplacedWidthAndBlockNonReplacedMargin.margin.left << "px, " << inlineReplacedWidthAndBlockNonReplacedMargin.margin.left << "px) -> layoutBox(" << &layoutBox << ")");
    261     return inlineReplacedWidthAndBlockNonReplacedMargin;
     259    auto margin = inFlowNonReplacedWidthAndMargin(layoutContext, layoutBox, width).margin;
     260
     261    LOG_WITH_STREAM(FormattingContextLayout, stream << "[Width][Margin] -> inflow replaced -> width(" << width << "px) margin(" << margin.left << "px, " << margin.left << "px) -> layoutBox(" << &layoutBox << ")");
     262    return { width, margin };
    262263}
    263264
     
    269270    // Vertical margins between adjacent block-level boxes in a block formatting context collapse.
    270271    // In a block formatting context, each box's left outer edge touches the left edge of the containing block (for right-to-left formatting, right edges touch).
     272
    271273    auto containingBlockContentBox = layoutContext.displayBoxForLayoutBox(*layoutBox.containingBlock())->contentBox();
    272274    // Start from the top of the container's content box.
     
    284286{
    285287    ASSERT(layoutBox.isInFlowPositioned());
     288
    286289    // 9.4.3 Relative positioning
    287290    //
     
    292295    // 2. If one of them is 'auto', it becomes the negative of the other.
    293296    // 3. If neither is 'auto', 'bottom' is ignored (i.e., the used value of 'bottom' will be minus the value of 'top').
     297
     298    auto& style = layoutBox.style();
    294299    auto& displayBox = *layoutContext.displayBoxForLayoutBox(layoutBox);
    295     auto& style = layoutBox.style();
    296 
    297     auto top = style.logicalTop();
    298     auto bottom = style.logicalBottom();
    299     LayoutUnit topDelta;
    300 
    301     if (top.isAuto() && bottom.isAuto()) {
     300    auto& containingBlock = *layoutBox.containingBlock();
     301    auto& containingBlockDisplayBox = *layoutContext.displayBoxForLayoutBox(containingBlock);
     302    auto containingBlockWidth = containingBlockDisplayBox.width();
     303
     304    auto top = FormattingContext::Geometry::computedValueIfNotAuto(style.logicalTop(), containingBlockWidth);
     305    auto bottom = FormattingContext::Geometry::computedValueIfNotAuto(style.logicalBottom(), containingBlockWidth);
     306
     307    if (!top && !bottom) {
    302308        // #1
    303         topDelta = 0;
    304     } else if (top.isAuto()) {
     309        top = bottom = { 0 };
     310    } else if (!top) {
    305311        // #2
    306         topDelta = -bottom.value();
    307     } else if (bottom.isAuto()) {
    308         // #3 #4
    309         topDelta = top.value();
     312        top = -*bottom;
     313    } else if (!bottom) {
     314        // #3
     315        bottom = -*top;
     316    } else {
     317        // #4
     318        bottom = std::nullopt;
    310319    }
    311320
     
    320329    //    If the 'direction' property of the containing block is 'ltr', the value of 'left' wins and 'right' becomes -'left'.
    321330    //    If 'direction' of the containing block is 'rtl', 'right' wins and 'left' is ignored.
    322     //
    323     auto left = style.logicalLeft();
    324     auto right = style.logicalRight();
    325     LayoutUnit leftDelta;
    326 
    327     if (left.isAuto() && right.isAuto()) {
     331
     332    auto left = FormattingContext::Geometry::computedValueIfNotAuto(style.logicalLeft(), containingBlockWidth);
     333    auto right = FormattingContext::Geometry::computedValueIfNotAuto(style.logicalRight(), containingBlockWidth);
     334
     335    if (!left && !right) {
    328336        // #1
    329         leftDelta = 0;
    330     } else if (left.isAuto()) {
     337        left = right = { 0 };
     338    } else if (!left) {
    331339        // #2
    332         leftDelta = -right.value();
    333     } else if (right.isAuto()) {
     340        left = -*right;
     341    } else if (!right) {
    334342        // #3
    335         leftDelta = left.value();
     343        right = -*left;
    336344    } else {
    337345        // #4
    338         // FIXME: take direction into account
    339         leftDelta = left.value();
    340     }
    341 
    342     auto computedLeft = displayBox.left() + leftDelta;
    343     auto computedTop = displayBox.top() + topDelta;
    344     LOG_WITH_STREAM(FormattingContextLayout, stream << "[Position] -> positioned inflow -> top(" << top << "px) left(" << left << "px) layoutBox(" << &layoutBox << ")");
    345     return { computedLeft, computedTop };
     346        auto isLeftToRightDirection = containingBlock.style().isLeftToRightDirection();
     347        if (isLeftToRightDirection)
     348            right = -*left;
     349        else
     350            left = std::nullopt;
     351    }
     352
     353    ASSERT(!bottom || *top == -*bottom);
     354    ASSERT(!left || *left == -*right);
     355
     356    auto newTopPosition = displayBox.top() + *top;
     357    auto newLeftPosition = displayBox.left() + left.value_or(-*right);
     358
     359    LOG_WITH_STREAM(FormattingContextLayout, stream << "[Position] -> positioned inflow -> top(" << newTopPosition << "px) left(" << newLeftPosition << "px) layoutBox(" << &layoutBox << ")");
     360    return { newTopPosition, newLeftPosition };
    346361}
    347362
Note: See TracChangeset for help on using the changeset viewer.