Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(199)

Side by Side Diff: third_party/WebKit/Source/core/layout/LayoutBox.cpp

Issue 2154593003: [css-grid] Fix indefinite height detection (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use 2 lines for bool includeBorderPadding Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2005 Allan Sandfeld Jensen (kde@carewolf.com) 4 * (C) 2005 Allan Sandfeld Jensen (kde@carewolf.com)
5 * (C) 2005, 2006 Samuel Weinig (sam.weinig@gmail.com) 5 * (C) 2005, 2006 Samuel Weinig (sam.weinig@gmail.com)
6 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserv ed. 6 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserv ed.
7 * Copyright (C) 2013 Adobe Systems Incorporated. All rights reserved. 7 * Copyright (C) 2013 Adobe Systems Incorporated. All rights reserved.
8 * 8 *
9 * This library is free software; you can redistribute it and/or 9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Library General Public 10 * modify it under the terms of the GNU Library General Public
(...skipping 2680 matching lines...) Expand 10 before | Expand all | Expand 10 after
2691 EDisplay display = containingBlock->styleRef().display(); 2691 EDisplay display = containingBlock->styleRef().display();
2692 return display == BLOCK || display == INLINE_BLOCK; 2692 return display == BLOCK || display == INLINE_BLOCK;
2693 } 2693 }
2694 2694
2695 // For quirks mode, we skip most auto-height containing blocks when computin g percentages. 2695 // For quirks mode, we skip most auto-height containing blocks when computin g percentages.
2696 return document().inQuirksMode() && !containingBlock->isTableCell() && !cont ainingBlock->isOutOfFlowPositioned() && !containingBlock->isLayoutGrid() && cont ainingBlock->style()->logicalHeight().isAuto(); 2696 return document().inQuirksMode() && !containingBlock->isTableCell() && !cont ainingBlock->isOutOfFlowPositioned() && !containingBlock->isLayoutGrid() && cont ainingBlock->style()->logicalHeight().isAuto();
2697 } 2697 }
2698 2698
2699 LayoutUnit LayoutBox::computePercentageLogicalHeight(const Length& height) const 2699 LayoutUnit LayoutBox::computePercentageLogicalHeight(const Length& height) const
2700 { 2700 {
2701 LayoutUnit availableHeight(-1);
2702
2703 bool skippedAutoHeightContainingBlock = false;
2704 LayoutBlock* cb = containingBlock(); 2701 LayoutBlock* cb = containingBlock();
jfernandez 2016/07/22 11:26:37 how all this logic behaves under an orthogonal flo
Manuel Rego 2016/07/22 13:05:37 It should be working fine as there's an if below:
2705 const LayoutBox* containingBlockChild = this; 2702 const LayoutBox* containingBlockChild = this;
2703 bool skippedAutoHeightContainingBlock = false;
2706 LayoutUnit rootMarginBorderPaddingHeight; 2704 LayoutUnit rootMarginBorderPaddingHeight;
2707 while (!cb->isLayoutView() && skipContainingBlockForPercentHeightCalculation (cb)) { 2705 while (!cb->isLayoutView() && skipContainingBlockForPercentHeightCalculation (cb)) {
2708 if (cb->isBody() || cb->isDocumentElement()) 2706 if (cb->isBody() || cb->isDocumentElement())
2709 rootMarginBorderPaddingHeight += cb->marginBefore() + cb->marginAfte r() + cb->borderAndPaddingLogicalHeight(); 2707 rootMarginBorderPaddingHeight += cb->marginBefore() + cb->marginAfte r() + cb->borderAndPaddingLogicalHeight();
2710 skippedAutoHeightContainingBlock = true; 2708 skippedAutoHeightContainingBlock = true;
2711 containingBlockChild = cb; 2709 containingBlockChild = cb;
2712 cb = cb->containingBlock(); 2710 cb = cb->containingBlock();
2713 } 2711 }
2714 cb->addPercentHeightDescendant(const_cast<LayoutBox*>(this)); 2712 cb->addPercentHeightDescendant(const_cast<LayoutBox*>(this));
2715 2713
2716 const ComputedStyle& cbstyle = cb->styleRef(); 2714 LayoutUnit availableHeight;
2717
2718 // A positioned element that specified both top/bottom or that specifies hei ght should be treated as though it has a height
2719 // explicitly specified that can be used for any percentage computations.
2720 bool isOutOfFlowPositionedWithSpecifiedHeight = cb->isOutOfFlowPositioned() && (!cbstyle.logicalHeight().isAuto() || (!cbstyle.logicalTop().isAuto() && !cbs tyle.logicalBottom().isAuto()));
2721
2722 bool includeBorderPadding = isTable();
2723
2724 LayoutUnit stretchedFlexHeight(-1);
2725 if (cb->isFlexItem())
2726 stretchedFlexHeight = toLayoutFlexibleBox(cb->parent())->childLogicalHei ghtForPercentageResolution(*cb);
2727
2728 if (isHorizontalWritingMode() != cb->isHorizontalWritingMode()) { 2715 if (isHorizontalWritingMode() != cb->isHorizontalWritingMode()) {
2729 availableHeight = containingBlockChild->containingBlockLogicalWidthForCo ntent(); 2716 availableHeight = containingBlockChild->containingBlockLogicalWidthForCo ntent();
2730 } else if (stretchedFlexHeight != LayoutUnit(-1)) { 2717 } else if (hasOverrideContainingBlockLogicalHeight()) {
2731 availableHeight = stretchedFlexHeight;
2732 } else if (hasOverrideContainingBlockLogicalHeight() && !isOutOfFlowPosition edWithSpecifiedHeight) {
2733 availableHeight = overrideContainingBlockContentLogicalHeight(); 2718 availableHeight = overrideContainingBlockContentLogicalHeight();
2734 } else if (cb->isGridItem() && cb->hasOverrideLogicalContentHeight()) { 2719 } else if (!cb->styleRef().logicalHeight().isFixed() && cb->isTableCell()) {
2735 availableHeight = cb->overrideLogicalContentHeight();
2736 } else if (cbstyle.logicalHeight().isFixed()) {
2737 LayoutUnit contentBoxHeight = cb->adjustContentBoxLogicalHeightForBoxSiz ing(cbstyle.logicalHeight().value());
2738 availableHeight = cb->constrainContentBoxLogicalHeightByMinMax(
2739 contentBoxHeight - cb->scrollbarLogicalHeight(), LayoutUnit(-1)).cla mpNegativeToZero();
2740 if (cb->isTableCell())
2741 includeBorderPadding = true;
2742 } else if (cb->isTableCell()) {
2743 if (!skippedAutoHeightContainingBlock) { 2720 if (!skippedAutoHeightContainingBlock) {
2744 // Table cells violate what the CSS spec says to do with heights. Ba sically we 2721 // Table cells violate what the CSS spec says to do with heights. Ba sically we
2745 // don't care if the cell specified a height or not. We just always make ourselves 2722 // don't care if the cell specified a height or not. We just always make ourselves
2746 // be a percentage of the cell's current content height. 2723 // be a percentage of the cell's current content height.
2747 if (!cb->hasOverrideLogicalContentHeight()) { 2724 if (!cb->hasOverrideLogicalContentHeight()) {
2748 // Normally we would let the cell size intrinsically, but scroll ing overflow has to be 2725 // Normally we would let the cell size intrinsically, but scroll ing overflow has to be
2749 // treated differently, since WinIE lets scrolled overflow regio ns shrink as needed. 2726 // treated differently, since WinIE lets scrolled overflow regio ns shrink as needed.
2750 // While we can't get all cases right, we can at least detect wh en the cell has a specified 2727 // While we can't get all cases right, we can at least detect wh en the cell has a specified
2751 // height or when the table has a specified height. In these cas es we want to initially have 2728 // height or when the table has a specified height. In these cas es we want to initially have
2752 // no size and allow the flexing of the table or the cell to its specified height to cause us 2729 // no size and allow the flexing of the table or the cell to its specified height to cause us
2753 // to grow to fill the space. This could end up being wrong in s ome cases, but it is 2730 // to grow to fill the space. This could end up being wrong in s ome cases, but it is
2754 // preferable to the alternative (sizing intrinsically and makin g the row end up too big). 2731 // preferable to the alternative (sizing intrinsically and makin g the row end up too big).
2755 LayoutTableCell* cell = toLayoutTableCell(cb); 2732 LayoutTableCell* cell = toLayoutTableCell(cb);
2756 if (scrollsOverflowY() && (!cell->style()->logicalHeight().isAut o() || !cell->table()->style()->logicalHeight().isAuto())) 2733 if (scrollsOverflowY() && (!cell->style()->logicalHeight().isAut o() || !cell->table()->style()->logicalHeight().isAuto()))
2757 return LayoutUnit(); 2734 return LayoutUnit();
2758 return LayoutUnit(-1); 2735 return LayoutUnit(-1);
2759 } 2736 }
2760 availableHeight = cb->overrideLogicalContentHeight(); 2737 availableHeight = cb->overrideLogicalContentHeight();
2761 includeBorderPadding = true;
2762 } 2738 }
2763 } else if (cbstyle.logicalHeight().hasPercent() && !isOutOfFlowPositionedWit hSpecifiedHeight) { 2739 } else {
2764 // We need to recur and compute the percentage height for our containing block. 2740 availableHeight = LayoutBlock::availableLogicalHeightForPercentageComput ation(*cb);
2765 LayoutUnit heightWithScrollbar = cb->computePercentageLogicalHeight(cbst yle.logicalHeight());
2766 if (heightWithScrollbar != -1) {
2767 LayoutUnit contentBoxHeightWithScrollbar = cb->adjustContentBoxLogic alHeightForBoxSizing(heightWithScrollbar);
2768 // We need to adjust for min/max height because this method does not
2769 // handle the min/max of the current block, its caller does. So the
2770 // return value from the recursive call will not have been adjusted
2771 // yet.
2772 LayoutUnit contentBoxHeight = cb->constrainContentBoxLogicalHeightBy MinMax(contentBoxHeightWithScrollbar - cb->scrollbarLogicalHeight(), LayoutUnit( -1));
2773 availableHeight = std::max(LayoutUnit(), contentBoxHeight);
2774 }
2775 } else if (isOutOfFlowPositionedWithSpecifiedHeight) {
2776 // Don't allow this to affect the block' size() member variable, since t his
2777 // can get called while the block is still laying out its kids.
2778 LogicalExtentComputedValues computedValues;
2779 cb->computeLogicalHeight(cb->logicalHeight(), LayoutUnit(), computedValu es);
2780 availableHeight = computedValues.m_extent - cb->borderAndPaddingLogicalH eight() - cb->scrollbarLogicalHeight();
2781 } else if (cb->isLayoutView()) {
2782 availableHeight = view()->viewLogicalHeightForPercentages();
2783 } 2741 }
2784 2742
2785 if (availableHeight == -1) 2743 if (availableHeight == -1)
2786 return availableHeight; 2744 return availableHeight;
2787 2745
2788 availableHeight -= rootMarginBorderPaddingHeight; 2746 availableHeight -= rootMarginBorderPaddingHeight;
2789 2747
2790 if (isTable() && isOutOfFlowPositioned()) 2748 if (isTable() && isOutOfFlowPositioned())
2791 availableHeight += cb->paddingLogicalHeight(); 2749 availableHeight += cb->paddingLogicalHeight();
2792 2750
2793 LayoutUnit result = valueForLength(height, availableHeight); 2751 LayoutUnit result = valueForLength(height, availableHeight);
2752 bool includeBorderPadding = isTable()
2753 || (cb->isTableCell() && (cb->styleRef().logicalHeight().isFixed() || (! skippedAutoHeightContainingBlock && cb->hasOverrideLogicalContentHeight())));
2794 if (includeBorderPadding) { 2754 if (includeBorderPadding) {
2795 // TODO(rhogan) crbug.com/467378: Doing this for content inside tables c ells is wrong, it should fill 2755 // TODO(rhogan) crbug.com/467378: Doing this for content inside tables c ells is wrong, it should fill
2796 // whatever height the cell makes available. 2756 // whatever height the cell makes available.
2797 result -= borderAndPaddingLogicalHeight(); 2757 result -= borderAndPaddingLogicalHeight();
2798 return std::max(LayoutUnit(), result); 2758 return std::max(LayoutUnit(), result);
2799 } 2759 }
2800 return result; 2760 return result;
2801 } 2761 }
2802 2762
2803 LayoutUnit LayoutBox::computeReplacedLogicalWidth(ShouldComputePreferred shouldC omputePreferred) const 2763 LayoutUnit LayoutBox::computeReplacedLogicalWidth(ShouldComputePreferred shouldC omputePreferred) const
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
2894 ASSERT(sizeType == MinSize || sizeType == MainOrPreferredSize || !logicalHei ght.isAuto()); 2854 ASSERT(sizeType == MinSize || sizeType == MainOrPreferredSize || !logicalHei ght.isAuto());
2895 if (sizeType == MinSize && logicalHeight.isAuto()) 2855 if (sizeType == MinSize && logicalHeight.isAuto())
2896 return adjustContentBoxLogicalHeightForBoxSizing(LayoutUnit()); 2856 return adjustContentBoxLogicalHeightForBoxSizing(LayoutUnit());
2897 2857
2898 switch (logicalHeight.type()) { 2858 switch (logicalHeight.type()) {
2899 case Fixed: 2859 case Fixed:
2900 return adjustContentBoxLogicalHeightForBoxSizing(logicalHeight.value()); 2860 return adjustContentBoxLogicalHeightForBoxSizing(logicalHeight.value());
2901 case Percent: 2861 case Percent:
2902 case Calculated: 2862 case Calculated:
2903 { 2863 {
2864 // TODO(rego): Check if we can somehow reuse LayoutBox::computePercentag eLogicalHeight() and/or LayoutBlock::availableLogicalHeightForPercentageComputat ion().
2904 LayoutObject* cb = isOutOfFlowPositioned() ? container() : containingBlo ck(); 2865 LayoutObject* cb = isOutOfFlowPositioned() ? container() : containingBlo ck();
2905 while (cb->isAnonymous()) 2866 while (cb->isAnonymous())
2906 cb = cb->containingBlock(); 2867 cb = cb->containingBlock();
2907 LayoutUnit stretchedHeight(-1); 2868 LayoutUnit stretchedHeight(-1);
2908 if (cb->isLayoutBlock()) { 2869 if (cb->isLayoutBlock()) {
2909 LayoutBlock* block = toLayoutBlock(cb); 2870 LayoutBlock* block = toLayoutBlock(cb);
2910 block->addPercentHeightDescendant(const_cast<LayoutBox*>(this)); 2871 block->addPercentHeightDescendant(const_cast<LayoutBox*>(this));
2911 if (block->isFlexItem()) 2872 if (block->isFlexItem())
2912 stretchedHeight = toLayoutFlexibleBox(block->parent())->childLog icalHeightForPercentageResolution(*block); 2873 stretchedHeight = toLayoutFlexibleBox(block->parent())->childLog icalHeightForPercentageResolution(*block);
2913 else if (block->isGridItem() && block->hasOverrideLogicalContentHeig ht()) 2874 else if (block->isGridItem() && block->hasOverrideLogicalContentHeig ht())
(...skipping 2012 matching lines...) Expand 10 before | Expand all | Expand 10 after
4926 m_rareData->m_snapAreas->remove(&snapArea); 4887 m_rareData->m_snapAreas->remove(&snapArea);
4927 } 4888 }
4928 } 4889 }
4929 4890
4930 SnapAreaSet* LayoutBox::snapAreas() const 4891 SnapAreaSet* LayoutBox::snapAreas() const
4931 { 4892 {
4932 return m_rareData ? m_rareData->m_snapAreas.get() : nullptr; 4893 return m_rareData ? m_rareData->m_snapAreas.get() : nullptr;
4933 } 4894 }
4934 4895
4935 } // namespace blink 4896 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698