Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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(); |
| 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; |
|
svillar
2016/07/20 08:24:00
My main doubt is, what's the criteria you have use
Manuel Rego
2016/07/21 09:46:01
Basically the idea is having a function that I can
| |
| 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 (isGridItem() && hasOverrideContainingBlockLogicalHeight()) { |
|
svillar
2016/07/20 08:24:00
Why just for grid items? What about !isOutOfFlowPo
Manuel Rego
2016/07/21 09:46:01
True the isGridItem() is not needed.
About "!isOu
| |
| 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() || (cb->isTableCell() && (cb->styleRef ().logicalHeight().isFixed() || (!skippedAutoHeightContainingBlock && cb->hasOve rrideLogicalContentHeight()))); | |
|
svillar
2016/07/20 08:24:00
I think this is not correct, for example if cb->is
Manuel Rego
2016/07/21 09:46:01
Are you sure? In the previous code we've:
else i
| |
| 2794 if (includeBorderPadding) { | 2753 if (includeBorderPadding) { |
| 2795 // TODO(rhogan) crbug.com/467378: Doing this for content inside tables c ells is wrong, it should fill | 2754 // 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. | 2755 // whatever height the cell makes available. |
| 2797 result -= borderAndPaddingLogicalHeight(); | 2756 result -= borderAndPaddingLogicalHeight(); |
| 2798 return std::max(LayoutUnit(), result); | 2757 return std::max(LayoutUnit(), result); |
| 2799 } | 2758 } |
| 2800 return result; | 2759 return result; |
| 2801 } | 2760 } |
| 2802 | 2761 |
| 2803 LayoutUnit LayoutBox::computeReplacedLogicalWidth(ShouldComputePreferred shouldC omputePreferred) const | 2762 LayoutUnit LayoutBox::computeReplacedLogicalWidth(ShouldComputePreferred shouldC omputePreferred) const |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2894 ASSERT(sizeType == MinSize || sizeType == MainOrPreferredSize || !logicalHei ght.isAuto()); | 2853 ASSERT(sizeType == MinSize || sizeType == MainOrPreferredSize || !logicalHei ght.isAuto()); |
| 2895 if (sizeType == MinSize && logicalHeight.isAuto()) | 2854 if (sizeType == MinSize && logicalHeight.isAuto()) |
| 2896 return adjustContentBoxLogicalHeightForBoxSizing(LayoutUnit()); | 2855 return adjustContentBoxLogicalHeightForBoxSizing(LayoutUnit()); |
| 2897 | 2856 |
| 2898 switch (logicalHeight.type()) { | 2857 switch (logicalHeight.type()) { |
| 2899 case Fixed: | 2858 case Fixed: |
| 2900 return adjustContentBoxLogicalHeightForBoxSizing(logicalHeight.value()); | 2859 return adjustContentBoxLogicalHeightForBoxSizing(logicalHeight.value()); |
| 2901 case Percent: | 2860 case Percent: |
| 2902 case Calculated: | 2861 case Calculated: |
| 2903 { | 2862 { |
| 2863 // TODO(rego): Check if we can somehow reuse LayoutBox::computePercentag eLogicalHeight() and/or LayoutBlock::availableLogicalHeightForPercentageComputat ion(). | |
| 2904 LayoutObject* cb = isOutOfFlowPositioned() ? container() : containingBlo ck(); | 2864 LayoutObject* cb = isOutOfFlowPositioned() ? container() : containingBlo ck(); |
| 2905 while (cb->isAnonymous()) | 2865 while (cb->isAnonymous()) |
| 2906 cb = cb->containingBlock(); | 2866 cb = cb->containingBlock(); |
| 2907 LayoutUnit stretchedHeight(-1); | 2867 LayoutUnit stretchedHeight(-1); |
| 2908 if (cb->isLayoutBlock()) { | 2868 if (cb->isLayoutBlock()) { |
| 2909 LayoutBlock* block = toLayoutBlock(cb); | 2869 LayoutBlock* block = toLayoutBlock(cb); |
| 2910 block->addPercentHeightDescendant(const_cast<LayoutBox*>(this)); | 2870 block->addPercentHeightDescendant(const_cast<LayoutBox*>(this)); |
| 2911 if (block->isFlexItem()) | 2871 if (block->isFlexItem()) |
| 2912 stretchedHeight = toLayoutFlexibleBox(block->parent())->childLog icalHeightForPercentageResolution(*block); | 2872 stretchedHeight = toLayoutFlexibleBox(block->parent())->childLog icalHeightForPercentageResolution(*block); |
| 2913 else if (block->isGridItem() && block->hasOverrideLogicalContentHeig ht()) | 2873 else if (block->isGridItem() && block->hasOverrideLogicalContentHeig ht()) |
| (...skipping 2012 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4926 m_rareData->m_snapAreas->remove(&snapArea); | 4886 m_rareData->m_snapAreas->remove(&snapArea); |
| 4927 } | 4887 } |
| 4928 } | 4888 } |
| 4929 | 4889 |
| 4930 SnapAreaSet* LayoutBox::snapAreas() const | 4890 SnapAreaSet* LayoutBox::snapAreas() const |
| 4931 { | 4891 { |
| 4932 return m_rareData ? m_rareData->m_snapAreas.get() : nullptr; | 4892 return m_rareData ? m_rareData->m_snapAreas.get() : nullptr; |
| 4933 } | 4893 } |
| 4934 | 4894 |
| 4935 } // namespace blink | 4895 } // namespace blink |
| OLD | NEW |