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 2760 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2771 EDisplay display = containingBlock->styleRef().display(); | 2771 EDisplay display = containingBlock->styleRef().display(); |
2772 return display == BLOCK || display == INLINE_BLOCK; | 2772 return display == BLOCK || display == INLINE_BLOCK; |
2773 } | 2773 } |
2774 | 2774 |
2775 // For quirks mode, we skip most auto-height containing blocks when computin
g percentages. | 2775 // For quirks mode, we skip most auto-height containing blocks when computin
g percentages. |
2776 return document().inQuirksMode() && !containingBlock->isTableCell() && !cont
ainingBlock->isOutOfFlowPositioned() && !containingBlock->isLayoutGrid() && cont
ainingBlock->style()->logicalHeight().isAuto(); | 2776 return document().inQuirksMode() && !containingBlock->isTableCell() && !cont
ainingBlock->isOutOfFlowPositioned() && !containingBlock->isLayoutGrid() && cont
ainingBlock->style()->logicalHeight().isAuto(); |
2777 } | 2777 } |
2778 | 2778 |
2779 LayoutUnit LayoutBox::computePercentageLogicalHeight(const Length& height) const | 2779 LayoutUnit LayoutBox::computePercentageLogicalHeight(const Length& height) const |
2780 { | 2780 { |
2781 LayoutUnit availableHeight(-1); | |
2782 | |
2783 bool skippedAutoHeightContainingBlock = false; | |
2784 LayoutBlock* cb = containingBlock(); | 2781 LayoutBlock* cb = containingBlock(); |
2785 const LayoutBox* containingBlockChild = this; | 2782 const LayoutBox* containingBlockChild = this; |
| 2783 bool skippedAutoHeightContainingBlock = false; |
2786 LayoutUnit rootMarginBorderPaddingHeight; | 2784 LayoutUnit rootMarginBorderPaddingHeight; |
2787 while (!cb->isLayoutView() && skipContainingBlockForPercentHeightCalculation
(cb)) { | 2785 while (!cb->isLayoutView() && skipContainingBlockForPercentHeightCalculation
(cb)) { |
2788 if (cb->isBody() || cb->isDocumentElement()) | 2786 if (cb->isBody() || cb->isDocumentElement()) |
2789 rootMarginBorderPaddingHeight += cb->marginBefore() + cb->marginAfte
r() + cb->borderAndPaddingLogicalHeight(); | 2787 rootMarginBorderPaddingHeight += cb->marginBefore() + cb->marginAfte
r() + cb->borderAndPaddingLogicalHeight(); |
2790 skippedAutoHeightContainingBlock = true; | 2788 skippedAutoHeightContainingBlock = true; |
2791 containingBlockChild = cb; | 2789 containingBlockChild = cb; |
2792 cb = cb->containingBlock(); | 2790 cb = cb->containingBlock(); |
2793 } | 2791 } |
2794 cb->addPercentHeightDescendant(const_cast<LayoutBox*>(this)); | 2792 cb->addPercentHeightDescendant(const_cast<LayoutBox*>(this)); |
2795 | 2793 |
2796 const ComputedStyle& cbstyle = cb->styleRef(); | 2794 LayoutUnit availableHeight; |
2797 | |
2798 // A positioned element that specified both top/bottom or that specifies hei
ght should be treated as though it has a height | |
2799 // explicitly specified that can be used for any percentage computations. | |
2800 bool isOutOfFlowPositionedWithSpecifiedHeight = cb->isOutOfFlowPositioned()
&& (!cbstyle.logicalHeight().isAuto() || (!cbstyle.logicalTop().isAuto() && !cbs
tyle.logicalBottom().isAuto())); | |
2801 | |
2802 bool includeBorderPadding = isTable(); | |
2803 | |
2804 LayoutUnit stretchedFlexHeight(-1); | |
2805 if (cb->isFlexItem()) | |
2806 stretchedFlexHeight = toLayoutFlexibleBox(cb->parent())->childLogicalHei
ghtForPercentageResolution(*cb); | |
2807 | |
2808 if (isHorizontalWritingMode() != cb->isHorizontalWritingMode()) { | 2795 if (isHorizontalWritingMode() != cb->isHorizontalWritingMode()) { |
2809 availableHeight = containingBlockChild->containingBlockLogicalWidthForCo
ntent(); | 2796 availableHeight = containingBlockChild->containingBlockLogicalWidthForCo
ntent(); |
2810 } else if (stretchedFlexHeight != LayoutUnit(-1)) { | 2797 } else if (hasOverrideContainingBlockLogicalHeight()) { |
2811 availableHeight = stretchedFlexHeight; | |
2812 } else if (hasOverrideContainingBlockLogicalHeight() && !isOutOfFlowPosition
edWithSpecifiedHeight) { | |
2813 availableHeight = overrideContainingBlockContentLogicalHeight(); | 2798 availableHeight = overrideContainingBlockContentLogicalHeight(); |
2814 } else if (cb->isGridItem() && cb->hasOverrideLogicalContentHeight()) { | 2799 } else if (!cb->styleRef().logicalHeight().isFixed() && cb->isTableCell()) { |
2815 availableHeight = cb->overrideLogicalContentHeight(); | |
2816 } else if (cbstyle.logicalHeight().isFixed()) { | |
2817 LayoutUnit contentBoxHeight = cb->adjustContentBoxLogicalHeightForBoxSiz
ing(cbstyle.logicalHeight().value()); | |
2818 availableHeight = cb->constrainContentBoxLogicalHeightByMinMax( | |
2819 contentBoxHeight - cb->scrollbarLogicalHeight(), LayoutUnit(-1)).cla
mpNegativeToZero(); | |
2820 } else if (cb->isTableCell()) { | |
2821 if (!skippedAutoHeightContainingBlock) { | 2800 if (!skippedAutoHeightContainingBlock) { |
2822 // Table cells violate what the CSS spec says to do with heights. Ba
sically we | 2801 // Table cells violate what the CSS spec says to do with heights. Ba
sically we |
2823 // don't care if the cell specified a height or not. We just always
make ourselves | 2802 // don't care if the cell specified a height or not. We just always
make ourselves |
2824 // be a percentage of the cell's current content height. | 2803 // be a percentage of the cell's current content height. |
2825 if (!cb->hasOverrideLogicalContentHeight()) { | 2804 if (!cb->hasOverrideLogicalContentHeight()) { |
2826 // Normally we would let the cell size intrinsically, but scroll
ing overflow has to be | 2805 // Normally we would let the cell size intrinsically, but scroll
ing overflow has to be |
2827 // treated differently, since WinIE lets scrolled overflow regio
ns shrink as needed. | 2806 // treated differently, since WinIE lets scrolled overflow regio
ns shrink as needed. |
2828 // While we can't get all cases right, we can at least detect wh
en the cell has a specified | 2807 // While we can't get all cases right, we can at least detect wh
en the cell has a specified |
2829 // height or when the table has a specified height. In these cas
es we want to initially have | 2808 // height or when the table has a specified height. In these cas
es we want to initially have |
2830 // no size and allow the flexing of the table or the cell to its
specified height to cause us | 2809 // no size and allow the flexing of the table or the cell to its
specified height to cause us |
2831 // to grow to fill the space. This could end up being wrong in s
ome cases, but it is | 2810 // to grow to fill the space. This could end up being wrong in s
ome cases, but it is |
2832 // preferable to the alternative (sizing intrinsically and makin
g the row end up too big). | 2811 // preferable to the alternative (sizing intrinsically and makin
g the row end up too big). |
2833 LayoutTableCell* cell = toLayoutTableCell(cb); | 2812 LayoutTableCell* cell = toLayoutTableCell(cb); |
2834 if (scrollsOverflowY() && (!cell->style()->logicalHeight().isAut
o() || !cell->table()->style()->logicalHeight().isAuto())) | 2813 if (scrollsOverflowY() && (!cell->style()->logicalHeight().isAut
o() || !cell->table()->style()->logicalHeight().isAuto())) |
2835 return LayoutUnit(); | 2814 return LayoutUnit(); |
2836 return LayoutUnit(-1); | 2815 return LayoutUnit(-1); |
2837 } | 2816 } |
2838 availableHeight = cb->overrideLogicalContentHeight(); | 2817 availableHeight = cb->overrideLogicalContentHeight(); |
2839 includeBorderPadding = true; | |
2840 } | 2818 } |
2841 } else if (cbstyle.logicalHeight().hasPercent() && !isOutOfFlowPositionedWit
hSpecifiedHeight) { | 2819 } else { |
2842 // We need to recur and compute the percentage height for our containing
block. | 2820 availableHeight = cb->availableLogicalHeightForPercentageComputation(); |
2843 LayoutUnit heightWithScrollbar = cb->computePercentageLogicalHeight(cbst
yle.logicalHeight()); | |
2844 if (heightWithScrollbar != -1) { | |
2845 LayoutUnit contentBoxHeightWithScrollbar = cb->adjustContentBoxLogic
alHeightForBoxSizing(heightWithScrollbar); | |
2846 // We need to adjust for min/max height because this method does not | |
2847 // handle the min/max of the current block, its caller does. So the | |
2848 // return value from the recursive call will not have been adjusted | |
2849 // yet. | |
2850 LayoutUnit contentBoxHeight = cb->constrainContentBoxLogicalHeightBy
MinMax(contentBoxHeightWithScrollbar - cb->scrollbarLogicalHeight(), LayoutUnit(
-1)); | |
2851 availableHeight = std::max(LayoutUnit(), contentBoxHeight); | |
2852 } | |
2853 } else if (isOutOfFlowPositionedWithSpecifiedHeight) { | |
2854 // Don't allow this to affect the block' size() member variable, since t
his | |
2855 // can get called while the block is still laying out its kids. | |
2856 LogicalExtentComputedValues computedValues; | |
2857 cb->computeLogicalHeight(cb->logicalHeight(), LayoutUnit(), computedValu
es); | |
2858 availableHeight = computedValues.m_extent - cb->borderAndPaddingLogicalH
eight() - cb->scrollbarLogicalHeight(); | |
2859 } else if (cb->isLayoutView()) { | |
2860 availableHeight = view()->viewLogicalHeightForPercentages(); | |
2861 } | 2821 } |
2862 | 2822 |
2863 if (availableHeight == -1) | 2823 if (availableHeight == -1) |
2864 return availableHeight; | 2824 return availableHeight; |
2865 | 2825 |
2866 availableHeight -= rootMarginBorderPaddingHeight; | 2826 availableHeight -= rootMarginBorderPaddingHeight; |
2867 | 2827 |
2868 if (isTable() && isOutOfFlowPositioned()) | 2828 if (isTable() && isOutOfFlowPositioned()) |
2869 availableHeight += cb->paddingLogicalHeight(); | 2829 availableHeight += cb->paddingLogicalHeight(); |
2870 | 2830 |
2871 LayoutUnit result = valueForLength(height, availableHeight); | 2831 LayoutUnit result = valueForLength(height, availableHeight); |
| 2832 bool includeBorderPadding = isTable() |
| 2833 || (cb->isTableCell() && !cb->styleRef().logicalHeight().isFixed() && !s
kippedAutoHeightContainingBlock && cb->hasOverrideLogicalContentHeight()); |
| 2834 |
2872 if (includeBorderPadding) { | 2835 if (includeBorderPadding) { |
2873 // TODO(rhogan) crbug.com/467378: Doing this for content inside tables c
ells is wrong, it should fill | 2836 // TODO(rhogan) crbug.com/467378: Doing this for content inside tables c
ells is wrong, it should fill |
2874 // whatever height the cell makes available. | 2837 // whatever height the cell makes available. |
2875 result -= borderAndPaddingLogicalHeight(); | 2838 result -= borderAndPaddingLogicalHeight(); |
2876 return std::max(LayoutUnit(), result); | 2839 return std::max(LayoutUnit(), result); |
2877 } | 2840 } |
2878 return result; | 2841 return result; |
2879 } | 2842 } |
2880 | 2843 |
2881 LayoutUnit LayoutBox::computeReplacedLogicalWidth(ShouldComputePreferred shouldC
omputePreferred) const | 2844 LayoutUnit LayoutBox::computeReplacedLogicalWidth(ShouldComputePreferred shouldC
omputePreferred) const |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2972 ASSERT(sizeType == MinSize || sizeType == MainOrPreferredSize || !logicalHei
ght.isAuto()); | 2935 ASSERT(sizeType == MinSize || sizeType == MainOrPreferredSize || !logicalHei
ght.isAuto()); |
2973 if (sizeType == MinSize && logicalHeight.isAuto()) | 2936 if (sizeType == MinSize && logicalHeight.isAuto()) |
2974 return adjustContentBoxLogicalHeightForBoxSizing(LayoutUnit()); | 2937 return adjustContentBoxLogicalHeightForBoxSizing(LayoutUnit()); |
2975 | 2938 |
2976 switch (logicalHeight.type()) { | 2939 switch (logicalHeight.type()) { |
2977 case Fixed: | 2940 case Fixed: |
2978 return adjustContentBoxLogicalHeightForBoxSizing(logicalHeight.value()); | 2941 return adjustContentBoxLogicalHeightForBoxSizing(logicalHeight.value()); |
2979 case Percent: | 2942 case Percent: |
2980 case Calculated: | 2943 case Calculated: |
2981 { | 2944 { |
| 2945 // TODO(rego): Check if we can somehow reuse LayoutBox::computePercentag
eLogicalHeight() and/or |
| 2946 // LayoutBlock::availableLogicalHeightForPercentageComputation() (see ht
tp://crbug.com/635655). |
2982 LayoutObject* cb = isOutOfFlowPositioned() ? container() : containingBlo
ck(); | 2947 LayoutObject* cb = isOutOfFlowPositioned() ? container() : containingBlo
ck(); |
2983 while (cb->isAnonymous()) | 2948 while (cb->isAnonymous()) |
2984 cb = cb->containingBlock(); | 2949 cb = cb->containingBlock(); |
2985 LayoutUnit stretchedHeight(-1); | 2950 LayoutUnit stretchedHeight(-1); |
2986 if (cb->isLayoutBlock()) { | 2951 if (cb->isLayoutBlock()) { |
2987 LayoutBlock* block = toLayoutBlock(cb); | 2952 LayoutBlock* block = toLayoutBlock(cb); |
2988 block->addPercentHeightDescendant(const_cast<LayoutBox*>(this)); | 2953 block->addPercentHeightDescendant(const_cast<LayoutBox*>(this)); |
2989 if (block->isFlexItem()) | 2954 if (block->isFlexItem()) |
2990 stretchedHeight = toLayoutFlexibleBox(block->parent())->childLog
icalHeightForPercentageResolution(*block); | 2955 stretchedHeight = toLayoutFlexibleBox(block->parent())->childLog
icalHeightForPercentageResolution(*block); |
2991 else if (block->isGridItem() && block->hasOverrideLogicalContentHeig
ht()) | 2956 else if (block->isGridItem() && block->hasOverrideLogicalContentHeig
ht()) |
(...skipping 1833 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4825 m_rareData->m_snapAreas->remove(&snapArea); | 4790 m_rareData->m_snapAreas->remove(&snapArea); |
4826 } | 4791 } |
4827 } | 4792 } |
4828 | 4793 |
4829 SnapAreaSet* LayoutBox::snapAreas() const | 4794 SnapAreaSet* LayoutBox::snapAreas() const |
4830 { | 4795 { |
4831 return m_rareData ? m_rareData->m_snapAreas.get() : nullptr; | 4796 return m_rareData ? m_rareData->m_snapAreas.get() : nullptr; |
4832 } | 4797 } |
4833 | 4798 |
4834 } // namespace blink | 4799 } // namespace blink |
OLD | NEW |