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