Chromium Code Reviews| Index: third_party/WebKit/Source/core/layout/LayoutBlock.cpp |
| diff --git a/third_party/WebKit/Source/core/layout/LayoutBlock.cpp b/third_party/WebKit/Source/core/layout/LayoutBlock.cpp |
| index 04c701c370f4fcc0f87c82d3f54ac3fae6a5d6d9..00bfe5eb1b409cc07f219ae4ef42bc079fc8f84d 100644 |
| --- a/third_party/WebKit/Source/core/layout/LayoutBlock.cpp |
| +++ b/third_party/WebKit/Source/core/layout/LayoutBlock.cpp |
| @@ -1872,4 +1872,56 @@ void LayoutBlock::checkPositionedObjectsNeedLayout() |
| #endif |
| +LayoutUnit LayoutBlock::availableLogicalHeightForPercentageComputation(const LayoutBlock& block) |
| +{ |
| + LayoutUnit availableHeight = LayoutUnit(-1); |
|
svillar
2016/07/20 08:24:00
LayoutUnit availableHeight(-1);
Manuel Rego
2016/07/21 09:46:01
Acknowledged.
|
| + |
| + const ComputedStyle& style = block.styleRef(); |
| + |
| + // A positioned element that specified both top/bottom or that specifies height should be treated as though it has a height |
| + // explicitly specified that can be used for any percentage computations. |
| + bool isOutOfFlowPositionedWithSpecifiedHeight = block.isOutOfFlowPositioned() && (!style.logicalHeight().isAuto() || (!style.logicalTop().isAuto() && !style.logicalBottom().isAuto())); |
| + |
| + LayoutUnit stretchedFlexHeight(-1); |
| + if (block.isFlexItem()) |
| + stretchedFlexHeight = toLayoutFlexibleBox(block.parent())->childLogicalHeightForPercentageResolution(block); |
| + |
| + if (stretchedFlexHeight != LayoutUnit(-1)) { |
| + availableHeight = stretchedFlexHeight; |
| + } else if (block.isGridItem() && block.hasOverrideLogicalContentHeight()) { |
| + availableHeight = block.overrideLogicalContentHeight(); |
| + } else if (style.logicalHeight().isFixed()) { |
| + LayoutUnit contentBoxHeight = block.adjustContentBoxLogicalHeightForBoxSizing(style.logicalHeight().value()); |
| + availableHeight = block.constrainContentBoxLogicalHeightByMinMax( |
| + contentBoxHeight - block.scrollbarLogicalHeight(), LayoutUnit(-1)).clampNegativeToZero(); |
| + } else if (style.logicalHeight().hasPercent() && !isOutOfFlowPositionedWithSpecifiedHeight) { |
| + // We need to recur and compute the percentage height for our containing block. |
| + LayoutUnit heightWithScrollbar = block.computePercentageLogicalHeight(style.logicalHeight()); |
| + if (heightWithScrollbar != -1) { |
| + LayoutUnit contentBoxHeightWithScrollbar = block.adjustContentBoxLogicalHeightForBoxSizing(heightWithScrollbar); |
| + // We need to adjust for min/max height because this method does not |
| + // handle the min/max of the current block, its caller does. So the |
| + // return value from the recursive call will not have been adjusted |
| + // yet. |
| + LayoutUnit contentBoxHeight = block.constrainContentBoxLogicalHeightByMinMax(contentBoxHeightWithScrollbar - block.scrollbarLogicalHeight(), LayoutUnit(-1)); |
| + availableHeight = std::max(LayoutUnit(), contentBoxHeight); |
| + } |
| + } else if (isOutOfFlowPositionedWithSpecifiedHeight) { |
| + // Don't allow this to affect the block' size() member variable, since this |
| + // can get called while the block is still laying out its kids. |
| + LogicalExtentComputedValues computedValues; |
| + block.computeLogicalHeight(block.logicalHeight(), LayoutUnit(), computedValues); |
| + availableHeight = computedValues.m_extent - block.borderAndPaddingLogicalHeight() - block.scrollbarLogicalHeight(); |
| + } else if (block.isLayoutView()) { |
| + availableHeight = toLayoutView(block).viewLogicalHeightForPercentages(); |
| + } |
| + |
| + return availableHeight; |
| +} |
| + |
| +bool LayoutBlock::hasDefiniteLogicalHeight() const |
| +{ |
| + return availableLogicalHeightForPercentageComputation(*this) != LayoutUnit(-1); |
| +} |
| + |
| } // namespace blink |