Commit cff3a1cc authored by Ian Kilpatrick's avatar Ian Kilpatrick Committed by Commit Bot

[LayoutNG] Add LayoutBox::PercentageResolutionLogicalHeight.

This function allows LayoutNG to correctly query the percentage
resolution block_size in quirks mode. (see test case for an example of
where this happened).

We call this as we are crossing a legacy->LayoutNG boundary while
creating the constraint space from a LayoutObject.

The function will also be used in the CSS Layout API to provide the
correct percentage resolution size.

Cq-Include-Trybots: luci.chromium.try:linux_layout_tests_layout_ng
Change-Id: I295145996f2460de1b25f85ff3784df6d6edbd30
Reviewed-on: https://chromium-review.googlesource.com/1194072
Commit-Queue: Ian Kilpatrick <ikilpatrick@chromium.org>
Reviewed-by: default avatarChristian Biesinger <cbiesinger@chromium.org>
Reviewed-by: default avatarMorten Stenshorne <mstensho@chromium.org>
Cr-Commit-Position: refs/heads/master@{#589074}
parent fcd25fc0
...@@ -1603,6 +1603,7 @@ crbug.com/591099 virtual/layout_ng_experimental/external/wpt/css/css-flexbox/per ...@@ -1603,6 +1603,7 @@ crbug.com/591099 virtual/layout_ng_experimental/external/wpt/css/css-flexbox/per
crbug.com/591099 virtual/layout_ng_experimental/external/wpt/css/css-flexbox/percentage-heights-002.html [ Skip ] crbug.com/591099 virtual/layout_ng_experimental/external/wpt/css/css-flexbox/percentage-heights-002.html [ Skip ]
crbug.com/467127 virtual/layout_ng_experimental/external/wpt/css/css-flexbox/percentage-heights-003.html [ Skip ] crbug.com/467127 virtual/layout_ng_experimental/external/wpt/css/css-flexbox/percentage-heights-003.html [ Skip ]
crbug.com/591099 virtual/layout_ng_experimental/external/wpt/css/css-flexbox/percentage-heights-004.html [ Skip ] crbug.com/591099 virtual/layout_ng_experimental/external/wpt/css/css-flexbox/percentage-heights-004.html [ Skip ]
crbug.com/591099 virtual/layout_ng_experimental/external/wpt/css/css-flexbox/percentage-heights-quirks-node.html [ Skip ]
crbug.com/591099 virtual/layout_ng_experimental/external/wpt/css/css-flexbox/percentage-size-subitems-001.html [ Skip ] crbug.com/591099 virtual/layout_ng_experimental/external/wpt/css/css-flexbox/percentage-size-subitems-001.html [ Skip ]
crbug.com/591099 virtual/layout_ng_experimental/external/wpt/css/css-flexbox/percentage-widths-001.html [ Skip ] crbug.com/591099 virtual/layout_ng_experimental/external/wpt/css/css-flexbox/percentage-widths-001.html [ Skip ]
crbug.com/591099 virtual/layout_ng_experimental/external/wpt/css/css-flexbox/position-absolute-001.html [ Skip ] crbug.com/591099 virtual/layout_ng_experimental/external/wpt/css/css-flexbox/position-absolute-001.html [ Skip ]
......
<title>In quirks mode a flex item should resolve its percentage height against its first ancestor with a defined height.</title>
<link rel="help" href="https://quirks.spec.whatwg.org/#the-percentage-height-calculation-quirk">
<link rel="match" href="../reference/ref-filled-green-100px-square-only.html">
<p style="margin-top: 1em;">Test passes if there is a filled green square.</p>
<div style="width: 200px; height: 200px;">
<div style="display: flex;">
<div style="width: 50%; height: 50%; background: green;"></div>
</div>
</div>
...@@ -304,6 +304,13 @@ class CORE_EXPORT LayoutBlock : public LayoutBox { ...@@ -304,6 +304,13 @@ class CORE_EXPORT LayoutBlock : public LayoutBox {
void CheckPositionedObjectsNeedLayout(); void CheckPositionedObjectsNeedLayout();
#endif #endif
// This method returns the size that percentage logical heights should
// resolve against *if* this LayoutBlock is the containing block for the
// percentage calculation.
//
// A version of this function without the above restriction, (that will walk
// the ancestor chain in quirks mode), see:
// LayoutBox::ContainingBlockLogicalHeightForPercentageResolution
LayoutUnit AvailableLogicalHeightForPercentageComputation() const; LayoutUnit AvailableLogicalHeightForPercentageComputation() const;
bool HasDefiniteLogicalHeight() const; bool HasDefiniteLogicalHeight() const;
......
...@@ -3402,8 +3402,9 @@ bool LayoutBox::SkipContainingBlockForPercentHeightCalculation( ...@@ -3402,8 +3402,9 @@ bool LayoutBox::SkipContainingBlockForPercentHeightCalculation(
containing_block->StyleRef().LogicalHeight().IsAuto(); containing_block->StyleRef().LogicalHeight().IsAuto();
} }
LayoutUnit LayoutBox::ComputePercentageLogicalHeight( LayoutUnit LayoutBox::ContainingBlockLogicalHeightForPercentageResolution(
const Length& height) const { LayoutBlock** out_cb,
bool* out_skipped_auto_height_containing_block) const {
LayoutBlock* cb = ContainingBlock(); LayoutBlock* cb = ContainingBlock();
const LayoutBox* containing_block_child = this; const LayoutBox* containing_block_child = this;
bool skipped_auto_height_containing_block = false; bool skipped_auto_height_containing_block = false;
...@@ -3419,7 +3420,14 @@ LayoutUnit LayoutBox::ComputePercentageLogicalHeight( ...@@ -3419,7 +3420,14 @@ LayoutUnit LayoutBox::ComputePercentageLogicalHeight(
containing_block_child = cb; containing_block_child = cb;
cb = cb->ContainingBlock(); cb = cb->ContainingBlock();
} }
cb->AddPercentHeightDescendant(const_cast<LayoutBox*>(this));
if (out_cb)
*out_cb = cb;
if (out_skipped_auto_height_containing_block) {
*out_skipped_auto_height_containing_block =
skipped_auto_height_containing_block;
}
LayoutUnit available_height(-1); LayoutUnit available_height(-1);
if (IsHorizontalWritingMode() != cb->IsHorizontalWritingMode()) { if (IsHorizontalWritingMode() != cb->IsHorizontalWritingMode()) {
...@@ -3465,7 +3473,25 @@ LayoutUnit LayoutBox::ComputePercentageLogicalHeight( ...@@ -3465,7 +3473,25 @@ LayoutUnit LayoutBox::ComputePercentageLogicalHeight(
if (IsTable() && IsOutOfFlowPositioned()) if (IsTable() && IsOutOfFlowPositioned())
available_height += cb->PaddingLogicalHeight(); available_height += cb->PaddingLogicalHeight();
return available_height;
}
LayoutUnit LayoutBox::ComputePercentageLogicalHeight(
const Length& height) const {
bool skipped_auto_height_containing_block = false;
LayoutBlock* cb = nullptr;
LayoutUnit available_height =
ContainingBlockLogicalHeightForPercentageResolution(
&cb, &skipped_auto_height_containing_block);
DCHECK(cb);
cb->AddPercentHeightDescendant(const_cast<LayoutBox*>(this));
if (available_height == -1)
return available_height;
LayoutUnit result = ValueForLength(height, available_height); LayoutUnit result = ValueForLength(height, available_height);
// |OverrideLogicalHeight| is the maximum height made available by the // |OverrideLogicalHeight| is the maximum height made available by the
// cell to its percent height children when we decide they can determine the // cell to its percent height children when we decide they can determine the
// height of the cell. If the percent height child is box-sizing:content-box // height of the cell. If the percent height child is box-sizing:content-box
......
...@@ -1012,6 +1012,16 @@ class CORE_EXPORT LayoutBox : public LayoutBoxModelObject { ...@@ -1012,6 +1012,16 @@ class CORE_EXPORT LayoutBox : public LayoutBoxModelObject {
virtual LayoutUnit ComputeReplacedLogicalHeight( virtual LayoutUnit ComputeReplacedLogicalHeight(
LayoutUnit estimated_used_width = LayoutUnit()) const; LayoutUnit estimated_used_width = LayoutUnit()) const;
// Returns the size that percentage logical heights of this box should be
// resolved against. This function will walk the ancestor chain of this
// object to determine this size.
// - out_cb returns the LayoutBlock which provided the size.
// - out_skipped_auto_height_containing_block returns if any auto height
// blocks were skipped to obtain out_cb.
LayoutUnit ContainingBlockLogicalHeightForPercentageResolution(
LayoutBlock** out_cb = nullptr,
bool* out_skipped_auto_height_containing_block = nullptr) const;
bool PercentageLogicalHeightIsResolvable() const; bool PercentageLogicalHeightIsResolvable() const;
LayoutUnit ComputePercentageLogicalHeight(const Length& height) const; LayoutUnit ComputePercentageLogicalHeight(const Length& height) const;
......
...@@ -92,8 +92,7 @@ scoped_refptr<NGConstraintSpace> NGConstraintSpace::CreateFromLayoutObject( ...@@ -92,8 +92,7 @@ scoped_refptr<NGConstraintSpace> NGConstraintSpace::CreateFromLayoutObject(
} else if (box.ContainingBlock()) { } else if (box.ContainingBlock()) {
if (parallel_containing_block) { if (parallel_containing_block) {
available_logical_height = available_logical_height =
box.ContainingBlock() box.ContainingBlockLogicalHeightForPercentageResolution();
->AvailableLogicalHeightForPercentageComputation();
} else { } else {
available_logical_height = box.ContainingBlockLogicalWidthForContent(); available_logical_height = box.ContainingBlockLogicalWidthForContent();
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment