Commit 982c2b3b authored by Christian Biesinger's avatar Christian Biesinger Committed by Commit Bot

[css-flex] Rename HasOrthogonalFlow to MainAxisIsInlineAxis

(This inverts the meaning)

It is hard to understand what HasOrthogonalFlow means; this new
name should be much easier to understand.

Change-Id: Id6ac0d6053a7bef43a5d175d274d28c8e66c771f
Reviewed-on: https://chromium-review.googlesource.com/c/1320932Reviewed-by: default avatarDavid Grogan <dgrogan@chromium.org>
Commit-Queue: Christian Biesinger <cbiesinger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#605915}
parent 38a6956d
......@@ -55,8 +55,8 @@ FlexItem::FlexItem(LayoutBox* box,
<< "Use LayoutUnit::Max() for no max size";
}
bool FlexItem::HasOrthogonalFlow() const {
return algorithm->IsHorizontalFlow() != box->IsHorizontalWritingMode();
bool FlexItem::MainAxisIsInlineAxis() const {
return algorithm->IsHorizontalFlow() == box->IsHorizontalWritingMode();
}
LayoutUnit FlexItem::FlowAwareMarginStart() const {
......@@ -146,13 +146,14 @@ void FlexItem::ComputeStretchedSize(LayoutUnit line_cross_axis_extent) {
// relying on legacy in this method.
DCHECK_EQ(Alignment(), ItemPosition::kStretch);
LayoutFlexibleBox* flexbox = ToLayoutFlexibleBox(box->Parent());
if (!HasOrthogonalFlow() && box->StyleRef().LogicalHeight().IsAuto()) {
if (MainAxisIsInlineAxis() && box->StyleRef().LogicalHeight().IsAuto()) {
LayoutUnit stretched_logical_height =
std::max(box->BorderAndPaddingLogicalHeight(),
line_cross_axis_extent - CrossAxisMarginExtent());
cross_axis_size = box->ConstrainLogicalHeightByMinMax(
stretched_logical_height, box->IntrinsicContentLogicalHeight());
} else if (HasOrthogonalFlow() && box->StyleRef().LogicalWidth().IsAuto()) {
} else if (!MainAxisIsInlineAxis() &&
box->StyleRef().LogicalWidth().IsAuto()) {
LayoutUnit child_width = (line_cross_axis_extent - CrossAxisMarginExtent())
.ClampNegativeToZero();
// This probably doesn't work in NG because flexbox might not yet know its
......
......@@ -97,7 +97,7 @@ class FlexItem {
ItemPosition Alignment() const;
bool HasOrthogonalFlow() const;
bool MainAxisIsInlineAxis() const;
LayoutUnit FlowAwareMarginStart() const;
LayoutUnit FlowAwareMarginEnd() const;
......
......@@ -202,12 +202,12 @@ LayoutUnit LayoutFlexibleBox::FirstLineBoxBaseline() const {
if (!baseline_child)
return LayoutUnit(-1);
if (!IsColumnFlow() && HasOrthogonalFlow(*baseline_child)) {
if (!IsColumnFlow() && !MainAxisIsInlineAxis(*baseline_child)) {
// TODO(cbiesinger): Should LogicalTop here be LogicalLeft?
return CrossAxisExtentForChild(*baseline_child) +
baseline_child->LogicalTop();
}
if (IsColumnFlow() && !HasOrthogonalFlow(*baseline_child)) {
if (IsColumnFlow() && MainAxisIsInlineAxis(*baseline_child)) {
return MainAxisExtentForChild(*baseline_child) +
baseline_child->LogicalTop();
}
......@@ -408,8 +408,14 @@ LayoutUnit LayoutFlexibleBox::ClientLogicalBottomAfterRepositioning() {
max_child_logical_bottom + PaddingAfter());
}
bool LayoutFlexibleBox::HasOrthogonalFlow(const LayoutBox& child) const {
return IsHorizontalFlow() != child.IsHorizontalWritingMode();
bool LayoutFlexibleBox::MainAxisIsInlineAxis(const LayoutBox& child) const {
// If we have a horizontal flow, that means the main size is the width.
// That's the inline size for horizontal writing modes, and the block
// size in vertical writing modes. For a vertical flow, main size is the
// height, so it's the inverse. So we need the inline size if we have a
// horizontal flow and horizontal writing mode, or vertical flow and vertical
// writing mode. Otherwise we need the block size.
return IsHorizontalFlow() == child.IsHorizontalWritingMode();
}
bool LayoutFlexibleBox::IsColumnFlow() const {
......@@ -452,7 +458,7 @@ LayoutUnit LayoutFlexibleBox::CrossAxisExtentForChild(
LayoutUnit LayoutFlexibleBox::ChildIntrinsicLogicalHeight(
const LayoutBox& child) const {
// This should only be called if the logical height is the cross size
DCHECK(!HasOrthogonalFlow(child));
DCHECK(MainAxisIsInlineAxis(child));
if (NeedToStretchChildLogicalHeight(child)) {
LayoutUnit child_intrinsic_content_logical_height;
if (!child.ShouldApplySizeContainment()) {
......@@ -472,7 +478,7 @@ DISABLE_CFI_PERF
LayoutUnit LayoutFlexibleBox::ChildIntrinsicLogicalWidth(
const LayoutBox& child) const {
// This should only be called if the logical width is the cross size
DCHECK(HasOrthogonalFlow(child));
DCHECK(!MainAxisIsInlineAxis(child));
// If our height is auto, make sure that our returned height is unaffected by
// earlier layouts by returning the max preferred logical width
if (!CrossAxisLengthIsDefinite(child, child.StyleRef().LogicalWidth()))
......@@ -483,8 +489,8 @@ LayoutUnit LayoutFlexibleBox::ChildIntrinsicLogicalWidth(
LayoutUnit LayoutFlexibleBox::CrossAxisIntrinsicExtentForChild(
const LayoutBox& child) const {
return HasOrthogonalFlow(child) ? ChildIntrinsicLogicalWidth(child)
: ChildIntrinsicLogicalHeight(child);
return MainAxisIsInlineAxis(child) ? ChildIntrinsicLogicalHeight(child)
: ChildIntrinsicLogicalWidth(child);
}
LayoutUnit LayoutFlexibleBox::MainAxisExtentForChild(
......@@ -529,13 +535,7 @@ LayoutUnit LayoutFlexibleBox::ComputeMainAxisExtentForChild(
const LayoutBox& child,
SizeType size_type,
const Length& size) const {
// If we have a horizontal flow, that means the main size is the width.
// That's the logical width for horizontal writing modes, and the logical
// height in vertical writing modes. For a vertical flow, main size is the
// height, so it's the inverse. So we need the logical width if we have a
// horizontal flow and horizontal writing mode, or vertical flow and vertical
// writing mode. Otherwise we need the logical height.
if (IsHorizontalFlow() != child.StyleRef().IsHorizontalWritingMode()) {
if (!MainAxisIsInlineAxis(child)) {
// We don't have to check for "auto" here - computeContentLogicalHeight
// will just return -1 for that case anyway. It's safe to access
// scrollbarLogicalHeight here because ComputeNextFlexLine will have
......@@ -654,10 +654,10 @@ LayoutUnit LayoutFlexibleBox::ComputeMainSizeFromAspectRatioUsing(
cross_size = LayoutUnit(cross_size_length.Value());
} else {
DCHECK(cross_size_length.IsPercentOrCalc());
cross_size = HasOrthogonalFlow(child)
? AdjustBorderBoxLogicalWidthForBoxSizing(
ValueForLength(cross_size_length, ContentWidth()))
: child.ComputePercentageLogicalHeight(cross_size_length);
cross_size = MainAxisIsInlineAxis(child)
? child.ComputePercentageLogicalHeight(cross_size_length)
: AdjustBorderBoxLogicalWidthForBoxSizing(
ValueForLength(cross_size_length, ContentWidth()));
}
const LayoutSize& child_intrinsic_size = child.IntrinsicSize();
......@@ -705,7 +705,7 @@ bool LayoutFlexibleBox::CrossAxisLengthIsDefinite(const LayoutBox& child,
if (length.IsAuto())
return false;
if (length.IsPercentOrCalc()) {
if (HasOrthogonalFlow(child) ||
if (!MainAxisIsInlineAxis(child) ||
has_definite_height_ == SizeDefiniteness::kDefinite)
return true;
if (has_definite_height_ == SizeDefiniteness::kIndefinite)
......@@ -723,10 +723,10 @@ bool LayoutFlexibleBox::CrossAxisLengthIsDefinite(const LayoutBox& child,
void LayoutFlexibleBox::CacheChildMainSize(const LayoutBox& child) {
DCHECK(!child.NeedsLayout());
LayoutUnit main_size;
if (HasOrthogonalFlow(child))
main_size = child.LogicalHeight();
else
if (MainAxisIsInlineAxis(child))
main_size = child.MaxPreferredLogicalWidth();
else
main_size = child.LogicalHeight();
intrinsic_size_along_main_axis_.Set(&child, main_size);
relaid_out_children_.insert(&child);
}
......@@ -784,7 +784,11 @@ LayoutUnit LayoutFlexibleBox::ComputeInnerFlexBaseSizeForChild(
// width of the child. For the logical width axis we just use the preferred
// width; for the height we need to lay out the child.
LayoutUnit main_axis_extent;
if (HasOrthogonalFlow(child)) {
if (MainAxisIsInlineAxis(child)) {
// We don't need to add scrollbarLogicalWidth here because the preferred
// width includes the scrollbar, even for overflow: auto.
main_axis_extent = child.MaxPreferredLogicalWidth();
} else {
if (child_layout_type == kNeverLayout)
return LayoutUnit();
......@@ -796,10 +800,6 @@ LayoutUnit LayoutFlexibleBox::ComputeInnerFlexBaseSizeForChild(
CacheChildMainSize(child);
}
main_axis_extent = intrinsic_size_along_main_axis_.at(&child);
} else {
// We don't need to add scrollbarLogicalWidth here because the preferred
// width includes the scrollbar, even for overflow: auto.
main_axis_extent = child.MaxPreferredLogicalWidth();
}
DCHECK_GE(main_axis_extent - main_axis_border_and_padding, LayoutUnit())
<< main_axis_extent << " - " << main_axis_border_and_padding;
......@@ -1046,9 +1046,9 @@ bool LayoutFlexibleBox::CrossSizeIsDefiniteForPercentageResolution(
return false;
// Here we implement https://drafts.csswg.org/css-flexbox/#algo-stretch
if (HasOrthogonalFlow(child) && child.HasOverrideLogicalWidth())
if (!MainAxisIsInlineAxis(child) && child.HasOverrideLogicalWidth())
return true;
if (!HasOrthogonalFlow(child) && child.HasOverrideLogicalHeight())
if (MainAxisIsInlineAxis(child) && child.HasOverrideLogicalHeight())
return true;
// We don't currently implement the optimization from
......@@ -1069,14 +1069,14 @@ bool LayoutFlexibleBox::MainSizeIsDefiniteForPercentageResolution(
if (!MainAxisLengthIsDefinite(child, Length(0, kPercent)))
return false;
if (HasOrthogonalFlow(child))
return child.HasOverrideLogicalHeight();
return child.HasOverrideLogicalWidth();
if (MainAxisIsInlineAxis(child))
return child.HasOverrideLogicalWidth();
return child.HasOverrideLogicalHeight();
}
bool LayoutFlexibleBox::UseOverrideLogicalHeightForPerentageResolution(
const LayoutBox& child) const {
if (!HasOrthogonalFlow(child))
if (MainAxisIsInlineAxis(child))
return CrossSizeIsDefiniteForPercentageResolution(child);
return MainSizeIsDefiniteForPercentageResolution(child);
}
......@@ -1187,11 +1187,10 @@ static LayoutUnit AlignmentOffset(LayoutUnit available_free_space,
}
void LayoutFlexibleBox::SetOverrideMainAxisContentSizeForChild(FlexItem& item) {
// child_preferred_size includes scrollbar width.
if (HasOrthogonalFlow(*item.box)) {
item.box->SetOverrideLogicalHeight(item.FlexedBorderBoxSize());
} else {
if (MainAxisIsInlineAxis(*item.box)) {
item.box->SetOverrideLogicalWidth(item.FlexedBorderBoxSize());
} else {
item.box->SetOverrideLogicalHeight(item.FlexedBorderBoxSize());
}
}
......@@ -1574,7 +1573,7 @@ void LayoutFlexibleBox::AlignChildren(Vector<FlexLine>& line_contexts) {
void LayoutFlexibleBox::ApplyStretchAlignmentToChild(FlexItem& flex_item) {
LayoutBox& child = *flex_item.box;
if (!flex_item.HasOrthogonalFlow() &&
if (flex_item.MainAxisIsInlineAxis() &&
child.StyleRef().LogicalHeight().IsAuto()) {
// FIXME: Can avoid laying out here in some cases. See
// https://webkit.org/b/87905.
......@@ -1604,7 +1603,7 @@ void LayoutFlexibleBox::ApplyStretchAlignmentToChild(FlexItem& flex_item) {
child.SetIntrinsicContentLogicalHeight(
child_intrinsic_content_logical_height);
}
} else if (flex_item.HasOrthogonalFlow() &&
} else if (!flex_item.MainAxisIsInlineAxis() &&
child.StyleRef().LogicalWidth().IsAuto()) {
if (flex_item.cross_axis_size != child.LogicalWidth()) {
child.SetOverrideLogicalWidth(flex_item.cross_axis_size);
......
......@@ -109,7 +109,7 @@ class CORE_EXPORT LayoutFlexibleBox : public LayoutBlock {
enum class SizeDefiniteness { kDefinite, kIndefinite, kUnknown };
bool HasOrthogonalFlow(const LayoutBox& child) const;
bool MainAxisIsInlineAxis(const LayoutBox& child) const;
bool IsColumnFlow() const;
bool IsLeftToRightFlow() const;
bool IsMultiline() const;
......
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