Commit dbb4fa67 authored by Christian Biesinger's avatar Christian Biesinger Committed by Commit Bot

[css-flexbox] Return booleans for the ForPercentageResolution functions

Not all callers of ChildLogicalHeightForPercentageResolution need the actual
height, and all codepaths either return -1 or OverrideContentLogicalHeight().

To simplify all that, just return a boolean and have the caller call
OverrideContentLogicalHeight if needed. Also renames the function as
appropriate.

R=eae@chromium.org,dgrogan@chromium.org

Cq-Include-Trybots: master.tryserver.chromium.linux:linux_layout_tests_layout_ng
Change-Id: I7da546757607a94a56f835c23717284681ff1cae
Reviewed-on: https://chromium-review.googlesource.com/1050474
Commit-Queue: Christian Biesinger <cbiesinger@chromium.org>
Reviewed-by: default avatarEmil A Eklund <eae@chromium.org>
Reviewed-by: default avatarDavid Grogan <dgrogan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#557009}
parent 6dc7843c
......@@ -2148,11 +2148,11 @@ LayoutUnit LayoutBlock::AvailableLogicalHeightForPercentageComputation() const {
(!style.LogicalTop().IsAuto() && !style.LogicalBottom().IsAuto()));
LayoutUnit stretched_flex_height(-1);
if (IsFlexItem())
stretched_flex_height =
ToLayoutFlexibleBox(Parent())
->ChildLogicalHeightForPercentageResolution(*this);
if (IsFlexItem()) {
const LayoutFlexibleBox* flex_box = ToLayoutFlexibleBox(Parent());
if (flex_box->UseOverrideLogicalHeightForPerentageResolution(*this))
stretched_flex_height = OverrideContentLogicalHeight();
}
if (stretched_flex_height != LayoutUnit(-1)) {
available_height = stretched_flex_height;
} else if (IsGridItem() && HasOverrideLogicalHeight()) {
......
......@@ -3633,9 +3633,10 @@ LayoutUnit LayoutBox::ComputeReplacedLogicalHeightUsing(
LayoutBlock* block = ToLayoutBlock(cb);
block->AddPercentHeightDescendant(const_cast<LayoutBox*>(this));
if (block->IsFlexItem()) {
stretched_height =
ToLayoutFlexibleBox(block->Parent())
->ChildLogicalHeightForPercentageResolution(*block);
const LayoutFlexibleBox* flex_box =
ToLayoutFlexibleBox(block->Parent());
if (flex_box->UseOverrideLogicalHeightForPerentageResolution(*block))
stretched_height = block->OverrideContentLogicalHeight();
} else if (block->IsGridItem() && block->HasOverrideLogicalHeight() &&
!has_perpendicular_containing_block) {
stretched_height = block->OverrideContentLogicalHeight();
......@@ -3740,11 +3741,9 @@ LayoutUnit LayoutBox::AvailableLogicalHeightUsing(
}
if (IsFlexItem()) {
LayoutFlexibleBox& flex_box = ToLayoutFlexibleBox(*Parent());
LayoutUnit stretched_height =
flex_box.ChildLogicalHeightForPercentageResolution(*this);
if (stretched_height != LayoutUnit(-1))
return stretched_height;
const LayoutFlexibleBox& flex_box = ToLayoutFlexibleBox(*Parent());
if (flex_box.UseOverrideLogicalHeightForPerentageResolution(*this))
return OverrideContentLogicalHeight();
}
if (h.IsPercentOrCalc() && IsOutOfFlowPositioned()) {
......
......@@ -678,9 +678,8 @@ bool LayoutBoxModelObject::HasAutoHeightOrContainingBlockWithAutoHeight()
if (logical_height_length.IsPercentOrCalc() && cb && IsBox())
cb->AddPercentHeightDescendant(const_cast<LayoutBox*>(ToLayoutBox(this)));
if (this_box && this_box->IsFlexItem()) {
LayoutFlexibleBox& flex_box = ToLayoutFlexibleBox(*Parent());
if (flex_box.ChildLogicalHeightForPercentageResolution(*this_box) !=
LayoutUnit(-1))
const LayoutFlexibleBox& flex_box = ToLayoutFlexibleBox(*Parent());
if (flex_box.UseOverrideLogicalHeightForPerentageResolution(*this_box))
return false;
}
if (this_box && this_box->IsGridItem() &&
......
......@@ -1119,17 +1119,17 @@ MinMaxSize LayoutFlexibleBox::ComputeMinAndMaxSizesForChild(
return sizes;
}
LayoutUnit LayoutFlexibleBox::CrossSizeForPercentageResolution(
const LayoutBox& child) {
bool LayoutFlexibleBox::CrossSizeIsDefiniteForPercentageResolution(
const LayoutBox& child) const {
if (FlexLayoutAlgorithm::AlignmentForChild(StyleRef(), child.StyleRef()) !=
ItemPosition::kStretch)
return LayoutUnit(-1);
return false;
// Here we implement https://drafts.csswg.org/css-flexbox/#algo-stretch
if (HasOrthogonalFlow(child) && child.HasOverrideLogicalWidth())
return child.OverrideContentLogicalWidth();
return true;
if (!HasOrthogonalFlow(child) && child.HasOverrideLogicalHeight())
return child.OverrideContentLogicalHeight();
return true;
// We don't currently implement the optimization from
// https://drafts.csswg.org/css-flexbox/#definite-sizes case 1. While that
......@@ -1137,39 +1137,36 @@ LayoutUnit LayoutFlexibleBox::CrossSizeForPercentageResolution(
// definite size, which itself is not cheap. We can consider implementing it
// at a later time. (The correctness is ensured by redoing layout in
// applyStretchAlignmentToChild)
return LayoutUnit(-1);
return false;
}
LayoutUnit LayoutFlexibleBox::MainSizeForPercentageResolution(
const LayoutBox& child) {
bool LayoutFlexibleBox::MainSizeIsDefiniteForPercentageResolution(
const LayoutBox& child) const {
// This function implements section 9.8. Definite and Indefinite Sizes, case
// 2) of the flexbox spec.
// We need to check for the flexbox to have a definite main size, and for the
// flex item to have a definite flex basis.
const Length& flex_basis = FlexBasisForChild(child);
if (!MainAxisLengthIsDefinite(child, flex_basis))
return LayoutUnit(-1);
return false;
if (!flex_basis.IsPercentOrCalc()) {
// If flex basis had a percentage, our size is guaranteed to be definite or
// the flex item's size could not be definite. Otherwise, we make up a
// percentage to check whether we have a definite size.
if (!MainAxisLengthIsDefinite(child, Length(0, kPercent)))
return LayoutUnit(-1);
return false;
}
if (HasOrthogonalFlow(child))
return child.HasOverrideLogicalHeight()
? child.OverrideContentLogicalHeight()
: LayoutUnit(-1);
return child.HasOverrideLogicalWidth() ? child.OverrideContentLogicalWidth()
: LayoutUnit(-1);
return child.HasOverrideLogicalHeight();
return child.HasOverrideLogicalWidth();
}
LayoutUnit LayoutFlexibleBox::ChildLogicalHeightForPercentageResolution(
const LayoutBox& child) {
bool LayoutFlexibleBox::UseOverrideLogicalHeightForPerentageResolution(
const LayoutBox& child) const {
if (!HasOrthogonalFlow(child))
return CrossSizeForPercentageResolution(child);
return MainSizeForPercentageResolution(child);
return CrossSizeIsDefiniteForPercentageResolution(child);
return MainSizeIsDefiniteForPercentageResolution(child);
}
LayoutUnit LayoutFlexibleBox::AdjustChildSizeForAspectRatioCrossAxisMinAndMax(
......
......@@ -75,9 +75,14 @@ class CORE_EXPORT LayoutFlexibleBox : public LayoutBlock {
const OrderIterator& GetOrderIterator() const { return order_iterator_; }
LayoutUnit CrossSizeForPercentageResolution(const LayoutBox& child);
LayoutUnit MainSizeForPercentageResolution(const LayoutBox& child);
LayoutUnit ChildLogicalHeightForPercentageResolution(const LayoutBox& child);
// These three functions are used when resolving percentages against a
// flex item's logical height. In flexbox, sometimes a logical height
// should be considered definite even though it normally shouldn't be,
// and these functions implement that logic.
bool CrossSizeIsDefiniteForPercentageResolution(const LayoutBox& child) const;
bool MainSizeIsDefiniteForPercentageResolution(const LayoutBox& child) const;
bool UseOverrideLogicalHeightForPerentageResolution(
const LayoutBox& child) const;
void ClearCachedMainSizeForChild(const LayoutBox& child);
......
......@@ -146,16 +146,10 @@ scoped_refptr<NGConstraintSpace> NGConstraintSpace::CreateFromLayoutObject(
available_size.block_size = box.OverrideLogicalHeight();
fixed_block = true;
}
if (box.IsFlexItem()) {
LayoutUnit for_percentage =
if (box.IsFlexItem() && fixed_block) {
fixed_block_is_definite =
ToLayoutFlexibleBox(box.Parent())
->ChildLogicalHeightForPercentageResolution(box);
fixed_block_is_definite = for_percentage != LayoutUnit(-1);
if (fixed_block_is_definite) {
DCHECK_EQ(available_size.block_size,
for_percentage + box.BorderAndPaddingLogicalHeight() +
box.ScrollbarLogicalHeight());
}
->UseOverrideLogicalHeightForPerentageResolution(box);
}
bool is_new_fc = true;
......
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