Commit a446db84 authored by Morten Stenshorne's avatar Morten Stenshorne Committed by Commit Bot

Add underscore suffix to all FlexItem and FlexLine members.

Compiling with -Wshadow

FlexLine::ComputeLineItemsPosition() had a cross_axis_offset parameter
that shadowed a member with the same name.

FlexLine::ComputeLineItemsPosition() had a local variable
main_axis_offset that shadowed a member with the same name.

Bug: 294205
Change-Id: I777375412e160ad276300af26d3e979f8a6085bd
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2461106Reviewed-by: default avatarChristian Biesinger <cbiesinger@chromium.org>
Commit-Queue: Morten Stenshorne <mstensho@chromium.org>
Cr-Commit-Position: refs/heads/master@{#815257}
parent b62e2e5d
......@@ -85,120 +85,120 @@ FlexItem::FlexItem(const FlexLayoutAlgorithm* algorithm,
NGPhysicalBoxStrut physical_margins,
NGBoxStrut scrollbars,
bool depends_on_min_max_sizes)
: algorithm(algorithm),
line_number(0),
box(box),
style(style),
flex_base_content_size(flex_base_content_size),
min_max_main_sizes(min_max_main_sizes),
min_max_cross_sizes(min_max_cross_sizes),
hypothetical_main_content_size(
: algorithm_(algorithm),
line_number_(0),
box_(box),
style_(style),
flex_base_content_size_(flex_base_content_size),
min_max_main_sizes_(min_max_main_sizes),
min_max_cross_sizes_(min_max_cross_sizes),
hypothetical_main_content_size_(
min_max_main_sizes.ClampSizeToMinAndMax(flex_base_content_size)),
main_axis_border_padding(main_axis_border_padding),
cross_axis_border_padding(cross_axis_border_padding),
physical_margins(physical_margins),
scrollbars(scrollbars),
depends_on_min_max_sizes(depends_on_min_max_sizes),
frozen(false),
needs_relayout_for_stretch(false),
ng_input_node(/* LayoutBox* */ nullptr) {
main_axis_border_padding_(main_axis_border_padding),
cross_axis_border_padding_(cross_axis_border_padding),
physical_margins_(physical_margins),
scrollbars_(scrollbars),
depends_on_min_max_sizes_(depends_on_min_max_sizes),
frozen_(false),
needs_relayout_for_stretch_(false),
ng_input_node_(/* LayoutBox* */ nullptr) {
DCHECK_GE(min_max_main_sizes.max_size, LayoutUnit())
<< "Use LayoutUnit::Max() for no max size";
}
bool FlexItem::MainAxisIsInlineAxis() const {
return algorithm->IsHorizontalFlow() == style.IsHorizontalWritingMode();
return algorithm_->IsHorizontalFlow() == style_.IsHorizontalWritingMode();
}
LayoutUnit FlexItem::FlowAwareMarginStart() const {
if (algorithm->IsHorizontalFlow()) {
return algorithm->IsLeftToRightFlow() ? physical_margins.left
: physical_margins.right;
if (algorithm_->IsHorizontalFlow()) {
return algorithm_->IsLeftToRightFlow() ? physical_margins_.left
: physical_margins_.right;
}
return algorithm->IsLeftToRightFlow() ? physical_margins.top
: physical_margins.bottom;
return algorithm_->IsLeftToRightFlow() ? physical_margins_.top
: physical_margins_.bottom;
}
LayoutUnit FlexItem::FlowAwareMarginEnd() const {
if (algorithm->IsHorizontalFlow()) {
return algorithm->IsLeftToRightFlow() ? physical_margins.right
: physical_margins.left;
if (algorithm_->IsHorizontalFlow()) {
return algorithm_->IsLeftToRightFlow() ? physical_margins_.right
: physical_margins_.left;
}
return algorithm->IsLeftToRightFlow() ? physical_margins.bottom
: physical_margins.top;
return algorithm_->IsLeftToRightFlow() ? physical_margins_.bottom
: physical_margins_.top;
}
LayoutUnit FlexItem::FlowAwareMarginBefore() const {
switch (algorithm->GetTransformedWritingMode()) {
switch (algorithm_->GetTransformedWritingMode()) {
case TransformedWritingMode::kTopToBottomWritingMode:
return physical_margins.top;
return physical_margins_.top;
case TransformedWritingMode::kBottomToTopWritingMode:
return physical_margins.bottom;
return physical_margins_.bottom;
case TransformedWritingMode::kLeftToRightWritingMode:
return physical_margins.left;
return physical_margins_.left;
case TransformedWritingMode::kRightToLeftWritingMode:
return physical_margins.right;
return physical_margins_.right;
}
NOTREACHED();
return LayoutUnit();
}
LayoutUnit FlexItem::MainAxisMarginExtent() const {
return algorithm->IsHorizontalFlow() ? physical_margins.HorizontalSum()
: physical_margins.VerticalSum();
return algorithm_->IsHorizontalFlow() ? physical_margins_.HorizontalSum()
: physical_margins_.VerticalSum();
}
LayoutUnit FlexItem::CrossAxisMarginExtent() const {
return algorithm->IsHorizontalFlow() ? physical_margins.VerticalSum()
: physical_margins.HorizontalSum();
return algorithm_->IsHorizontalFlow() ? physical_margins_.VerticalSum()
: physical_margins_.HorizontalSum();
}
LayoutUnit FlexItem::MarginBoxAscent() const {
if (box) {
LayoutUnit ascent(box->FirstLineBoxBaseline());
if (box_) {
LayoutUnit ascent(box_->FirstLineBoxBaseline());
if (ascent == -1)
ascent = cross_axis_size;
ascent = cross_axis_size_;
return ascent + FlowAwareMarginBefore();
}
DCHECK(layout_result);
DCHECK(layout_result_);
return FlowAwareMarginBefore() +
NGBoxFragment(
algorithm->StyleRef().GetWritingMode(),
algorithm->StyleRef().Direction(),
To<NGPhysicalBoxFragment>(layout_result->PhysicalFragment()))
algorithm_->StyleRef().GetWritingMode(),
algorithm_->StyleRef().Direction(),
To<NGPhysicalBoxFragment>(layout_result_->PhysicalFragment()))
.BaselineOrSynthesize();
}
LayoutUnit FlexItem::AvailableAlignmentSpace() const {
LayoutUnit cross_extent = CrossAxisMarginExtent() + cross_axis_size;
return Line()->cross_axis_extent - cross_extent;
LayoutUnit cross_extent = CrossAxisMarginExtent() + cross_axis_size_;
return Line()->cross_axis_extent_ - cross_extent;
}
bool FlexItem::HasAutoMarginsInCrossAxis() const {
if (algorithm->IsHorizontalFlow()) {
return style.MarginTop().IsAuto() || style.MarginBottom().IsAuto();
if (algorithm_->IsHorizontalFlow()) {
return style_.MarginTop().IsAuto() || style_.MarginBottom().IsAuto();
}
return style.MarginLeft().IsAuto() || style.MarginRight().IsAuto();
return style_.MarginLeft().IsAuto() || style_.MarginRight().IsAuto();
}
ItemPosition FlexItem::Alignment() const {
return FlexLayoutAlgorithm::AlignmentForChild(*algorithm->Style(), style);
return FlexLayoutAlgorithm::AlignmentForChild(*algorithm_->Style(), style_);
}
void FlexItem::UpdateAutoMarginsInMainAxis(LayoutUnit auto_margin_offset) {
DCHECK_GE(auto_margin_offset, LayoutUnit());
if (algorithm->IsHorizontalFlow()) {
if (style.MarginLeft().IsAuto())
physical_margins.left = auto_margin_offset;
if (style.MarginRight().IsAuto())
physical_margins.right = auto_margin_offset;
if (algorithm_->IsHorizontalFlow()) {
if (style_.MarginLeft().IsAuto())
physical_margins_.left = auto_margin_offset;
if (style_.MarginRight().IsAuto())
physical_margins_.right = auto_margin_offset;
} else {
if (style.MarginTop().IsAuto())
physical_margins.top = auto_margin_offset;
if (style.MarginBottom().IsAuto())
physical_margins.bottom = auto_margin_offset;
if (style_.MarginTop().IsAuto())
physical_margins_.top = auto_margin_offset;
if (style_.MarginBottom().IsAuto())
physical_margins_.bottom = auto_margin_offset;
}
}
......@@ -206,30 +206,30 @@ bool FlexItem::UpdateAutoMarginsInCrossAxis(
LayoutUnit available_alignment_space) {
DCHECK_GE(available_alignment_space, LayoutUnit());
bool is_horizontal = algorithm->IsHorizontalFlow();
bool is_horizontal = algorithm_->IsHorizontalFlow();
const Length& top_or_left =
is_horizontal ? style.MarginTop() : style.MarginLeft();
is_horizontal ? style_.MarginTop() : style_.MarginLeft();
const Length& bottom_or_right =
is_horizontal ? style.MarginBottom() : style.MarginRight();
is_horizontal ? style_.MarginBottom() : style_.MarginRight();
if (top_or_left.IsAuto() && bottom_or_right.IsAuto()) {
desired_location.Move(LayoutUnit(), available_alignment_space / 2);
desired_location_.Move(LayoutUnit(), available_alignment_space / 2);
if (is_horizontal) {
physical_margins.top = available_alignment_space / 2;
physical_margins.bottom = available_alignment_space / 2;
physical_margins_.top = available_alignment_space / 2;
physical_margins_.bottom = available_alignment_space / 2;
} else {
physical_margins.left = available_alignment_space / 2;
physical_margins.right = available_alignment_space / 2;
physical_margins_.left = available_alignment_space / 2;
physical_margins_.right = available_alignment_space / 2;
}
return true;
}
bool should_adjust_top_or_left = true;
if (algorithm->IsColumnFlow() && !style.IsLeftToRightDirection()) {
if (algorithm_->IsColumnFlow() && !style_.IsLeftToRightDirection()) {
// For column flows, only make this adjustment if topOrLeft corresponds to
// the "before" margin, so that flipForRightToLeftColumn will do the right
// thing.
should_adjust_top_or_left = false;
}
if (!algorithm->IsColumnFlow() && style.IsFlippedBlocksWritingMode()) {
if (!algorithm_->IsColumnFlow() && style_.IsFlippedBlocksWritingMode()) {
// If we are a flipped writing mode, we need to adjust the opposite side.
// This is only needed for row flows because this only affects the
// block-direction axis.
......@@ -238,22 +238,22 @@ bool FlexItem::UpdateAutoMarginsInCrossAxis(
if (top_or_left.IsAuto()) {
if (should_adjust_top_or_left)
desired_location.Move(LayoutUnit(), available_alignment_space);
desired_location_.Move(LayoutUnit(), available_alignment_space);
if (is_horizontal)
physical_margins.top = available_alignment_space;
physical_margins_.top = available_alignment_space;
else
physical_margins.left = available_alignment_space;
physical_margins_.left = available_alignment_space;
return true;
}
if (bottom_or_right.IsAuto()) {
if (!should_adjust_top_or_left)
desired_location.Move(LayoutUnit(), available_alignment_space);
desired_location_.Move(LayoutUnit(), available_alignment_space);
if (is_horizontal)
physical_margins.bottom = available_alignment_space;
physical_margins_.bottom = available_alignment_space;
else
physical_margins.right = available_alignment_space;
physical_margins_.right = available_alignment_space;
return true;
}
return false;
......@@ -262,23 +262,25 @@ bool FlexItem::UpdateAutoMarginsInCrossAxis(
void FlexItem::ComputeStretchedSize() {
DCHECK_EQ(Alignment(), ItemPosition::kStretch);
LayoutUnit stretched_size =
std::max(cross_axis_border_padding,
Line()->cross_axis_extent - CrossAxisMarginExtent());
if (box) {
if (MainAxisIsInlineAxis() && style.LogicalHeight().IsAuto()) {
cross_axis_size = box->ConstrainLogicalHeightByMinMax(
stretched_size, box->IntrinsicContentLogicalHeight());
} else if (!MainAxisIsInlineAxis() && style.LogicalWidth().IsAuto()) {
const LayoutFlexibleBox* flexbox = ToLayoutFlexibleBox(box->Parent());
cross_axis_size = box->ConstrainLogicalWidthByMinMax(
std::max(cross_axis_border_padding_,
Line()->cross_axis_extent_ - CrossAxisMarginExtent());
if (box_) {
if (MainAxisIsInlineAxis() && style_.LogicalHeight().IsAuto()) {
cross_axis_size_ = box_->ConstrainLogicalHeightByMinMax(
stretched_size, box_->IntrinsicContentLogicalHeight());
} else if (!MainAxisIsInlineAxis() && style_.LogicalWidth().IsAuto()) {
const LayoutFlexibleBox* flexbox = ToLayoutFlexibleBox(box_->Parent());
cross_axis_size_ = box_->ConstrainLogicalWidthByMinMax(
stretched_size, flexbox->CrossAxisContentExtent(), flexbox);
}
return;
}
if ((MainAxisIsInlineAxis() && style.LogicalHeight().IsAuto()) ||
(!MainAxisIsInlineAxis() && style.LogicalWidth().IsAuto()))
cross_axis_size = min_max_cross_sizes->ClampSizeToMinAndMax(stretched_size);
if ((MainAxisIsInlineAxis() && style_.LogicalHeight().IsAuto()) ||
(!MainAxisIsInlineAxis() && style_.LogicalWidth().IsAuto())) {
cross_axis_size_ =
min_max_cross_sizes_->ClampSizeToMinAndMax(stretched_size);
}
}
// static
......@@ -330,24 +332,25 @@ LayoutUnit FlexItem::AlignmentOffset(LayoutUnit available_free_space,
return LayoutUnit();
}
void FlexLine::FreezeViolations(ViolationsVector& violations) {
const ComputedStyle& flex_box_style = algorithm->StyleRef();
const ComputedStyle& flex_box_style = algorithm_->StyleRef();
for (size_t i = 0; i < violations.size(); ++i) {
DCHECK(!violations[i]->frozen) << i;
const ComputedStyle& child_style = violations[i]->style;
LayoutUnit child_size = violations[i]->flexed_content_size;
remaining_free_space -= child_size - violations[i]->flex_base_content_size;
total_flex_grow -= child_style.ResolvedFlexGrow(flex_box_style);
DCHECK(!violations[i]->frozen_) << i;
const ComputedStyle& child_style = violations[i]->style_;
LayoutUnit child_size = violations[i]->flexed_content_size_;
remaining_free_space_ -=
child_size - violations[i]->flex_base_content_size_;
total_flex_grow_ -= child_style.ResolvedFlexGrow(flex_box_style);
const float flex_shrink = child_style.ResolvedFlexShrink(flex_box_style);
total_flex_shrink -= flex_shrink;
total_weighted_flex_shrink -=
flex_shrink * violations[i]->flex_base_content_size;
total_flex_shrink_ -= flex_shrink;
total_weighted_flex_shrink_ -=
flex_shrink * violations[i]->flex_base_content_size_;
// total_weighted_flex_shrink can be negative when we exceed the precision
// of a double when we initially calculate total_weighted_flex_shrink. We
// then subtract each child's weighted flex shrink with full precision, now
// leading to a negative result. See
// css3/flexbox/large-flex-shrink-assert.html
total_weighted_flex_shrink = std::max(total_weighted_flex_shrink, 0.0);
violations[i]->frozen = true;
total_weighted_flex_shrink_ = std::max(total_weighted_flex_shrink_, 0.0);
violations[i]->frozen_ = true;
}
}
......@@ -356,30 +359,31 @@ void FlexLine::FreezeInflexibleItems() {
// we freeze all items with a flex factor of 0 as well as those with a min/max
// size violation.
FlexSign flex_sign = Sign();
remaining_free_space = container_main_inner_size - sum_flex_base_size;
remaining_free_space_ = container_main_inner_size_ - sum_flex_base_size_;
ViolationsVector new_inflexible_items;
const ComputedStyle& flex_box_style = algorithm->StyleRef();
for (size_t i = 0; i < line_items.size(); ++i) {
FlexItem& flex_item = line_items[i];
DCHECK(!flex_item.frozen) << i;
const ComputedStyle& flex_box_style = algorithm_->StyleRef();
for (size_t i = 0; i < line_items_.size(); ++i) {
FlexItem& flex_item = line_items_[i];
DCHECK(!flex_item.frozen_) << i;
float flex_factor =
(flex_sign == kPositiveFlexibility)
? flex_item.style.ResolvedFlexGrow(flex_box_style)
: flex_item.style.ResolvedFlexShrink(flex_box_style);
? flex_item.style_.ResolvedFlexGrow(flex_box_style)
: flex_item.style_.ResolvedFlexShrink(flex_box_style);
if (flex_factor == 0 ||
(flex_sign == kPositiveFlexibility &&
flex_item.flex_base_content_size >
flex_item.hypothetical_main_content_size) ||
flex_item.flex_base_content_size_ >
flex_item.hypothetical_main_content_size_) ||
(flex_sign == kNegativeFlexibility &&
flex_item.flex_base_content_size <
flex_item.hypothetical_main_content_size)) {
flex_item.flexed_content_size = flex_item.hypothetical_main_content_size;
flex_item.flex_base_content_size_ <
flex_item.hypothetical_main_content_size_)) {
flex_item.flexed_content_size_ =
flex_item.hypothetical_main_content_size_;
new_inflexible_items.push_back(&flex_item);
}
}
FreezeViolations(new_inflexible_items);
initial_free_space = remaining_free_space;
initial_free_space_ = remaining_free_space_;
}
bool FlexLine::ResolveFlexibleLengths() {
......@@ -389,45 +393,46 @@ bool FlexLine::ResolveFlexibleLengths() {
ViolationsVector max_violations;
FlexSign flex_sign = Sign();
double sum_flex_factors =
(flex_sign == kPositiveFlexibility) ? total_flex_grow : total_flex_shrink;
double sum_flex_factors = (flex_sign == kPositiveFlexibility)
? total_flex_grow_
: total_flex_shrink_;
if (sum_flex_factors > 0 && sum_flex_factors < 1) {
LayoutUnit fractional(initial_free_space * sum_flex_factors);
if (fractional.Abs() < remaining_free_space.Abs())
remaining_free_space = fractional;
LayoutUnit fractional(initial_free_space_ * sum_flex_factors);
if (fractional.Abs() < remaining_free_space_.Abs())
remaining_free_space_ = fractional;
}
const ComputedStyle& flex_box_style = algorithm->StyleRef();
for (size_t i = 0; i < line_items.size(); ++i) {
FlexItem& flex_item = line_items[i];
const ComputedStyle& flex_box_style = algorithm_->StyleRef();
for (size_t i = 0; i < line_items_.size(); ++i) {
FlexItem& flex_item = line_items_[i];
// This check also covers out-of-flow children.
if (flex_item.frozen)
if (flex_item.frozen_)
continue;
LayoutUnit child_size = flex_item.flex_base_content_size;
LayoutUnit child_size = flex_item.flex_base_content_size_;
double extra_space = 0;
if (remaining_free_space > 0 && total_flex_grow > 0 &&
flex_sign == kPositiveFlexibility && std::isfinite(total_flex_grow)) {
extra_space = remaining_free_space *
flex_item.style.ResolvedFlexGrow(flex_box_style) /
total_flex_grow;
} else if (remaining_free_space < 0 && total_weighted_flex_shrink > 0 &&
if (remaining_free_space_ > 0 && total_flex_grow_ > 0 &&
flex_sign == kPositiveFlexibility && std::isfinite(total_flex_grow_)) {
extra_space = remaining_free_space_ *
flex_item.style_.ResolvedFlexGrow(flex_box_style) /
total_flex_grow_;
} else if (remaining_free_space_ < 0 && total_weighted_flex_shrink_ > 0 &&
flex_sign == kNegativeFlexibility &&
std::isfinite(total_weighted_flex_shrink) &&
flex_item.style.ResolvedFlexShrink(flex_box_style)) {
extra_space = remaining_free_space *
flex_item.style.ResolvedFlexShrink(flex_box_style) *
flex_item.flex_base_content_size /
total_weighted_flex_shrink;
std::isfinite(total_weighted_flex_shrink_) &&
flex_item.style_.ResolvedFlexShrink(flex_box_style)) {
extra_space = remaining_free_space_ *
flex_item.style_.ResolvedFlexShrink(flex_box_style) *
flex_item.flex_base_content_size_ /
total_weighted_flex_shrink_;
}
if (std::isfinite(extra_space))
child_size += LayoutUnit::FromFloatRound(extra_space);
LayoutUnit adjusted_child_size = flex_item.ClampSizeToMinAndMax(child_size);
DCHECK_GE(adjusted_child_size, 0);
flex_item.flexed_content_size = adjusted_child_size;
used_free_space += adjusted_child_size - flex_item.flex_base_content_size;
flex_item.flexed_content_size_ = adjusted_child_size;
used_free_space += adjusted_child_size - flex_item.flex_base_content_size_;
LayoutUnit violation = adjusted_child_size - child_size;
if (violation > 0)
......@@ -440,20 +445,20 @@ bool FlexLine::ResolveFlexibleLengths() {
if (total_violation) {
FreezeViolations(total_violation < 0 ? max_violations : min_violations);
} else {
remaining_free_space -= used_free_space;
remaining_free_space_ -= used_free_space;
}
return !total_violation;
}
LayoutUnit FlexLine::ApplyMainAxisAutoMarginAdjustment() {
if (remaining_free_space <= LayoutUnit())
if (remaining_free_space_ <= LayoutUnit())
return LayoutUnit();
int number_of_auto_margins = 0;
bool is_horizontal = algorithm->IsHorizontalFlow();
for (size_t i = 0; i < line_items.size(); ++i) {
const ComputedStyle& style = line_items[i].style;
bool is_horizontal = algorithm_->IsHorizontalFlow();
for (size_t i = 0; i < line_items_.size(); ++i) {
const ComputedStyle& style = line_items_[i].style_;
if (is_horizontal) {
if (style.MarginLeft().IsAuto())
++number_of_auto_margins;
......@@ -470,55 +475,55 @@ LayoutUnit FlexLine::ApplyMainAxisAutoMarginAdjustment() {
return LayoutUnit();
LayoutUnit size_of_auto_margin =
remaining_free_space / number_of_auto_margins;
remaining_free_space = LayoutUnit();
remaining_free_space_ / number_of_auto_margins;
remaining_free_space_ = LayoutUnit();
return size_of_auto_margin;
}
void FlexLine::ComputeLineItemsPosition(LayoutUnit main_axis_start_offset,
LayoutUnit main_axis_end_offset,
LayoutUnit& cross_axis_offset) {
this->main_axis_offset = main_axis_start_offset;
main_axis_offset_ = main_axis_start_offset;
// Recalculate the remaining free space. The adjustment for flex factors
// between 0..1 means we can't just use remainingFreeSpace here.
LayoutUnit total_item_size;
for (size_t i = 0; i < line_items.size(); ++i)
total_item_size += line_items[i].FlexedMarginBoxSize();
remaining_free_space =
container_main_inner_size - total_item_size -
(line_items.size() - 1) * algorithm->gap_between_items_;
for (size_t i = 0; i < line_items_.size(); ++i)
total_item_size += line_items_[i].FlexedMarginBoxSize();
remaining_free_space_ =
container_main_inner_size_ - total_item_size -
(line_items_.size() - 1) * algorithm_->gap_between_items_;
const StyleContentAlignmentData justify_content =
FlexLayoutAlgorithm::ResolvedJustifyContent(*algorithm->Style());
FlexLayoutAlgorithm::ResolvedJustifyContent(*algorithm_->Style());
LayoutUnit auto_margin_offset = ApplyMainAxisAutoMarginAdjustment();
const LayoutUnit available_free_space = remaining_free_space;
const LayoutUnit available_free_space = remaining_free_space_;
LayoutUnit initial_position =
FlexLayoutAlgorithm::InitialContentPositionOffset(
algorithm->StyleRef(), available_free_space, justify_content,
line_items.size());
algorithm_->StyleRef(), available_free_space, justify_content,
line_items_.size());
LayoutUnit main_axis_offset = initial_position;
sum_justify_adjustments += initial_position;
sum_justify_adjustments_ += initial_position;
LayoutUnit max_descent; // Used when align-items: baseline.
LayoutUnit max_child_cross_axis_extent;
bool should_flip_main_axis;
if (algorithm->IsNGFlexBox()) {
if (algorithm_->IsNGFlexBox()) {
should_flip_main_axis =
algorithm->StyleRef().ResolvedIsRowReverseFlexDirection();
algorithm_->StyleRef().ResolvedIsRowReverseFlexDirection();
} else {
should_flip_main_axis =
!algorithm->StyleRef().ResolvedIsColumnFlexDirection() &&
!algorithm->IsLeftToRightFlow();
!algorithm_->StyleRef().ResolvedIsColumnFlexDirection() &&
!algorithm_->IsLeftToRightFlow();
}
LayoutUnit width_when_flipped = container_logical_width;
LayoutUnit width_when_flipped = container_logical_width_;
LayoutUnit flipped_offset;
// -webkit-box, always did layout starting at 0. ltr and reverse were handled
// by reversing the order of iteration. OTOH, flex always iterates in order
// and flips the main coordinate. The following gives the same behavior for
// -webkit-box while using the same iteration order as flex does by changing
// how the flipped coordinate is calculated.
if (should_flip_main_axis && algorithm->StyleRef().IsDeprecatedWebkitBox()) {
if (should_flip_main_axis && algorithm_->StyleRef().IsDeprecatedWebkitBox()) {
// -webkit-box only distributed space when > 0.
width_when_flipped =
total_item_size + available_free_space.ClampNegativeToZero();
......@@ -526,8 +531,8 @@ void FlexLine::ComputeLineItemsPosition(LayoutUnit main_axis_start_offset,
} else {
main_axis_offset += main_axis_start_offset;
}
for (size_t i = 0; i < line_items.size(); ++i) {
FlexItem& flex_item = line_items[i];
for (size_t i = 0; i < line_items_.size(); ++i) {
FlexItem& flex_item = line_items_[i];
flex_item.UpdateAutoMarginsInMainAxis(auto_margin_offset);
......@@ -536,16 +541,16 @@ void FlexLine::ComputeLineItemsPosition(LayoutUnit main_axis_start_offset,
!flex_item.HasAutoMarginsInCrossAxis()) {
LayoutUnit ascent = flex_item.MarginBoxAscent();
LayoutUnit descent =
(flex_item.CrossAxisMarginExtent() + flex_item.cross_axis_size) -
(flex_item.CrossAxisMarginExtent() + flex_item.cross_axis_size_) -
ascent;
max_ascent = std::max(max_ascent, ascent);
max_ascent_ = std::max(max_ascent_, ascent);
max_descent = std::max(max_descent, descent);
child_cross_axis_margin_box_extent = max_ascent + max_descent;
child_cross_axis_margin_box_extent = max_ascent_ + max_descent;
} else {
child_cross_axis_margin_box_extent =
flex_item.cross_axis_size + flex_item.CrossAxisMarginExtent();
flex_item.cross_axis_size_ + flex_item.CrossAxisMarginExtent();
}
max_child_cross_axis_extent = std::max(max_child_cross_axis_extent,
child_cross_axis_margin_box_extent);
......@@ -556,29 +561,29 @@ void FlexLine::ComputeLineItemsPosition(LayoutUnit main_axis_start_offset,
// In an RTL column situation, this will apply the margin-right/margin-end
// on the left. This will be fixed later in
// LayoutFlexibleBox::FlipForRightToLeftColumn.
flex_item.desired_location = LayoutPoint(
flex_item.desired_location_ = LayoutPoint(
should_flip_main_axis ? width_when_flipped - main_axis_offset -
child_main_extent + flipped_offset
: main_axis_offset,
cross_axis_offset + flex_item.FlowAwareMarginBefore());
main_axis_offset += child_main_extent + flex_item.FlowAwareMarginEnd();
if (i != line_items.size() - 1) {
if (i != line_items_.size() - 1) {
// The last item does not get extra space added.
LayoutUnit space_between =
FlexLayoutAlgorithm::ContentDistributionSpaceBetweenChildren(
available_free_space, justify_content, line_items.size());
main_axis_offset += space_between + algorithm->gap_between_items_;
available_free_space, justify_content, line_items_.size());
main_axis_offset += space_between + algorithm_->gap_between_items_;
// The gap is included in the intrinsic content block size, so don't add
// it to sum_justify_adjustments.
sum_justify_adjustments += space_between;
sum_justify_adjustments_ += space_between;
}
}
main_axis_extent = main_axis_offset;
main_axis_extent_ = main_axis_offset;
this->cross_axis_offset = cross_axis_offset;
cross_axis_extent = max_child_cross_axis_extent;
cross_axis_offset_ = cross_axis_offset;
cross_axis_extent_ = max_child_cross_axis_extent;
cross_axis_offset += max_child_cross_axis_extent;
}
......@@ -671,14 +676,14 @@ FlexLine* FlexLayoutAlgorithm::ComputeNextFlexLine(
line_has_in_flow_item = true;
sum_flex_base_size +=
flex_item.FlexBaseMarginBoxSize() + gap_between_items_;
total_flex_grow += flex_item.style.ResolvedFlexGrow(StyleRef());
const float flex_shrink = flex_item.style.ResolvedFlexShrink(StyleRef());
total_flex_grow += flex_item.style_.ResolvedFlexGrow(StyleRef());
const float flex_shrink = flex_item.style_.ResolvedFlexShrink(StyleRef());
total_flex_shrink += flex_shrink;
total_weighted_flex_shrink +=
flex_shrink * flex_item.flex_base_content_size;
flex_shrink * flex_item.flex_base_content_size_;
sum_hypothetical_main_size +=
flex_item.HypotheticalMainAxisMarginBoxSize() + gap_between_items_;
flex_item.line_number = flex_lines_.size();
flex_item.line_number_ = flex_lines_.size();
}
if (line_has_in_flow_item) {
// We added a gap after every item but there shouldn't be one after the last
......@@ -773,8 +778,9 @@ LayoutUnit FlexLayoutAlgorithm::IntrinsicContentBlockSize() const {
LayoutUnit max_size;
for (const FlexLine& line : flex_lines_) {
// Subtract main_axis_offset to remove border/padding
max_size = std::max(line.main_axis_extent - line.sum_justify_adjustments -
line.main_axis_offset,
max_size =
std::max(line.main_axis_extent_ - line.sum_justify_adjustments_ -
line.main_axis_offset_,
max_size);
}
return max_size;
......@@ -782,8 +788,8 @@ LayoutUnit FlexLayoutAlgorithm::IntrinsicContentBlockSize() const {
const FlexLine& last_line = flex_lines_.back();
// Subtract the first line's offset to remove border/padding
return last_line.cross_axis_offset + last_line.cross_axis_extent -
flex_lines_.front().cross_axis_offset +
return last_line.cross_axis_offset_ + last_line.cross_axis_extent_ -
flex_lines_.front().cross_axis_offset_ +
(flex_lines_.size() - 1) * gap_between_lines_;
}
......@@ -798,21 +804,21 @@ void FlexLayoutAlgorithm::AlignFlexLines(LayoutUnit cross_axis_content_extent) {
LayoutUnit available_cross_axis_space =
cross_axis_content_extent - (flex_lines_.size() - 1) * gap_between_lines_;
for (const FlexLine& line : flex_lines_)
available_cross_axis_space -= line.cross_axis_extent;
available_cross_axis_space -= line.cross_axis_extent_;
LayoutUnit line_offset =
InitialContentPositionOffset(StyleRef(), available_cross_axis_space,
align_content, flex_lines_.size());
for (FlexLine& line_context : flex_lines_) {
line_context.cross_axis_offset += line_offset;
line_context.cross_axis_offset_ += line_offset;
for (FlexItem& flex_item : line_context.line_items) {
flex_item.desired_location.SetY(flex_item.desired_location.Y() +
for (FlexItem& flex_item : line_context.line_items_) {
flex_item.desired_location_.SetY(flex_item.desired_location_.Y() +
line_offset);
}
if (align_content.Distribution() == ContentDistributionType::kStretch &&
available_cross_axis_space > 0) {
line_context.cross_axis_extent +=
line_context.cross_axis_extent_ +=
available_cross_axis_space /
static_cast<unsigned>(flex_lines_.size());
}
......@@ -831,9 +837,9 @@ void FlexLayoutAlgorithm::AlignChildren() {
for (FlexLine& line_context : flex_lines_) {
LayoutUnit min_margin_after_baseline = LayoutUnit::Max();
LayoutUnit max_ascent = line_context.max_ascent;
LayoutUnit max_ascent = line_context.max_ascent_;
for (FlexItem& flex_item : line_context.line_items) {
for (FlexItem& flex_item : line_context.line_items_) {
if (flex_item.UpdateAutoMarginsInCrossAxis(
flex_item.AvailableAlignmentSpace().ClampNegativeToZero()))
continue;
......@@ -841,14 +847,14 @@ void FlexLayoutAlgorithm::AlignChildren() {
ItemPosition position = flex_item.Alignment();
if (position == ItemPosition::kStretch) {
flex_item.ComputeStretchedSize();
flex_item.needs_relayout_for_stretch = true;
flex_item.needs_relayout_for_stretch_ = true;
}
LayoutUnit available_space = flex_item.AvailableAlignmentSpace();
LayoutUnit offset = FlexItem::AlignmentOffset(
available_space, position, flex_item.MarginBoxAscent(), max_ascent,
StyleRef().FlexWrap() == EFlexWrap::kWrapReverse,
StyleRef().IsDeprecatedWebkitBox());
flex_item.desired_location.Move(LayoutUnit(), offset);
flex_item.desired_location_.Move(LayoutUnit(), offset);
if (position == ItemPosition::kBaseline &&
StyleRef().FlexWrap() == EFlexWrap::kWrapReverse) {
min_margin_after_baseline =
......@@ -869,10 +875,10 @@ void FlexLayoutAlgorithm::AlignChildren() {
for (FlexLine& line_context : flex_lines_) {
LayoutUnit min_margin_after_baseline =
min_margin_after_baselines[line_number++];
for (FlexItem& flex_item : line_context.line_items) {
for (FlexItem& flex_item : line_context.line_items_) {
if (flex_item.Alignment() == ItemPosition::kBaseline &&
!flex_item.HasAutoMarginsInCrossAxis() && min_margin_after_baseline) {
flex_item.desired_location.Move(LayoutUnit(),
flex_item.desired_location_.Move(LayoutUnit(),
min_margin_after_baseline);
}
}
......@@ -885,12 +891,12 @@ void FlexLayoutAlgorithm::FlipForWrapReverse(
DCHECK_EQ(Style()->FlexWrap(), EFlexWrap::kWrapReverse);
for (FlexLine& line_context : flex_lines_) {
LayoutUnit original_offset =
line_context.cross_axis_offset - cross_axis_start_edge;
line_context.cross_axis_offset_ - cross_axis_start_edge;
LayoutUnit new_offset = cross_axis_content_size - original_offset -
line_context.cross_axis_extent;
line_context.cross_axis_extent_;
LayoutUnit wrap_reverse_difference = new_offset - original_offset;
for (FlexItem& flex_item : line_context.line_items)
flex_item.desired_location.Move(LayoutUnit(), wrap_reverse_difference);
for (FlexItem& flex_item : line_context.line_items_)
flex_item.desired_location_.Move(LayoutUnit(), wrap_reverse_difference);
}
}
......@@ -1071,19 +1077,19 @@ void FlexLayoutAlgorithm::LayoutColumnReverse(
"method is to be used in legacy.";
for (FlexLine& line_context : FlexLines()) {
for (wtf_size_t child_number = 0;
child_number < line_context.line_items.size(); ++child_number) {
FlexItem& flex_item = line_context.line_items[child_number];
child_number < line_context.line_items_.size(); ++child_number) {
FlexItem& flex_item = line_context.line_items_[child_number];
LayoutUnit item_main_size = flex_item.FlexedBorderBoxSize();
NGBoxStrut margins = flex_item.physical_margins.ConvertToLogical(
NGBoxStrut margins = flex_item.physical_margins_.ConvertToLogical(
Style()->GetWritingMode(), Style()->Direction());
// We passed 0 as the initial main_axis offset to ComputeLineItemsPosition
// for ColumnReverse containers so here we have to add the
// border_scrollbar_padding of the container.
flex_item.desired_location.SetX(
flex_item.desired_location_.SetX(
main_axis_content_size + border_scrollbar_padding_before -
flex_item.desired_location.X() - item_main_size - margins.block_end +
flex_item.desired_location_.X() - item_main_size - margins.block_end +
margins.block_start);
}
}
......@@ -1094,7 +1100,7 @@ bool FlexLayoutAlgorithm::IsNGFlexBox() const {
<< "You can't call IsNGFlexBox before adding items.";
// The FlexItems created by legacy will have an empty ng_input_node. An NG
// FlexItem's ng_input_node will have a LayoutBox.
return all_items_.at(0).ng_input_node.GetLayoutBox();
return all_items_.at(0).ng_input_node_.GetLayoutBox();
}
} // namespace blink
......@@ -132,26 +132,26 @@ class FlexItem {
bool depends_on_min_max_sizes = false);
LayoutUnit HypotheticalMainAxisMarginBoxSize() const {
return hypothetical_main_content_size + main_axis_border_padding +
return hypothetical_main_content_size_ + main_axis_border_padding_ +
MainAxisMarginExtent();
}
LayoutUnit FlexBaseMarginBoxSize() const {
return flex_base_content_size + main_axis_border_padding +
return flex_base_content_size_ + main_axis_border_padding_ +
MainAxisMarginExtent();
}
LayoutUnit FlexedBorderBoxSize() const {
return flexed_content_size + main_axis_border_padding;
return flexed_content_size_ + main_axis_border_padding_;
}
LayoutUnit FlexedMarginBoxSize() const {
return flexed_content_size + main_axis_border_padding +
return flexed_content_size_ + main_axis_border_padding_ +
MainAxisMarginExtent();
}
LayoutUnit ClampSizeToMinAndMax(LayoutUnit size) const {
return min_max_main_sizes.ClampSizeToMinAndMax(size);
return min_max_main_sizes_.ClampSizeToMinAndMax(size);
}
ItemPosition Alignment() const;
......@@ -189,36 +189,36 @@ class FlexItem {
bool is_wrap_reverse,
bool is_deprecated_webkit_box);
const FlexLayoutAlgorithm* algorithm;
wtf_size_t line_number;
LayoutBox* box;
const ComputedStyle& style;
const LayoutUnit flex_base_content_size;
const MinMaxSizes min_max_main_sizes;
const base::Optional<MinMaxSizes> min_max_cross_sizes;
const LayoutUnit hypothetical_main_content_size;
const LayoutUnit main_axis_border_padding;
const LayoutUnit cross_axis_border_padding;
NGPhysicalBoxStrut physical_margins;
const NGBoxStrut scrollbars;
LayoutUnit flexed_content_size;
const FlexLayoutAlgorithm* algorithm_;
wtf_size_t line_number_;
LayoutBox* box_;
const ComputedStyle& style_;
const LayoutUnit flex_base_content_size_;
const MinMaxSizes min_max_main_sizes_;
const base::Optional<MinMaxSizes> min_max_cross_sizes_;
const LayoutUnit hypothetical_main_content_size_;
const LayoutUnit main_axis_border_padding_;
const LayoutUnit cross_axis_border_padding_;
NGPhysicalBoxStrut physical_margins_;
const NGBoxStrut scrollbars_;
LayoutUnit flexed_content_size_;
// When set by the caller, this should be the size pre-stretching.
LayoutUnit cross_axis_size;
LayoutUnit cross_axis_size_;
// The algorithm stores the main axis offset in X and cross axis offset in Y.
LayoutPoint desired_location;
LayoutPoint desired_location_;
const bool depends_on_min_max_sizes;
bool frozen;
const bool depends_on_min_max_sizes_;
bool frozen_;
// Legacy partially relies on FlexLayoutAlgorithm::AlignChildren to determine
// if the child is eligible for stretching (specifically, checking for auto
// margins). FlexLayoutAlgorithm uses this flag to report back to legacy.
bool needs_relayout_for_stretch;
bool needs_relayout_for_stretch_;
NGBlockNode ng_input_node;
scoped_refptr<const NGLayoutResult> layout_result;
NGBlockNode ng_input_node_;
scoped_refptr<const NGLayoutResult> layout_result_;
};
class FlexItemVectorView {
......@@ -265,23 +265,23 @@ class FlexLine {
double total_flex_shrink,
double total_weighted_flex_shrink,
LayoutUnit sum_hypothetical_main_size)
: algorithm(algorithm),
line_items(std::move(line_items)),
container_logical_width(container_logical_width),
sum_flex_base_size(sum_flex_base_size),
total_flex_grow(total_flex_grow),
total_flex_shrink(total_flex_shrink),
total_weighted_flex_shrink(total_weighted_flex_shrink),
sum_hypothetical_main_size(sum_hypothetical_main_size) {}
: algorithm_(algorithm),
line_items_(std::move(line_items)),
container_logical_width_(container_logical_width),
sum_flex_base_size_(sum_flex_base_size),
total_flex_grow_(total_flex_grow),
total_flex_shrink_(total_flex_shrink),
total_weighted_flex_shrink_(total_weighted_flex_shrink),
sum_hypothetical_main_size_(sum_hypothetical_main_size) {}
FlexSign Sign() const {
return sum_hypothetical_main_size < container_main_inner_size
return sum_hypothetical_main_size_ < container_main_inner_size_
? kPositiveFlexibility
: kNegativeFlexibility;
}
void SetContainerMainInnerSize(LayoutUnit size) {
container_main_inner_size = size;
container_main_inner_size_ = size;
}
void FreezeInflexibleItems();
......@@ -308,35 +308,35 @@ class FlexLine {
LayoutUnit main_axis_end_offset,
LayoutUnit& cross_axis_offset);
FlexLayoutAlgorithm* algorithm;
FlexItemVectorView line_items;
const LayoutUnit container_logical_width;
const LayoutUnit sum_flex_base_size;
double total_flex_grow;
double total_flex_shrink;
double total_weighted_flex_shrink;
FlexLayoutAlgorithm* algorithm_;
FlexItemVectorView line_items_;
const LayoutUnit container_logical_width_;
const LayoutUnit sum_flex_base_size_;
double total_flex_grow_;
double total_flex_shrink_;
double total_weighted_flex_shrink_;
// The hypothetical main size of an item is the flex base size clamped
// according to its min and max main size properties
const LayoutUnit sum_hypothetical_main_size;
const LayoutUnit sum_hypothetical_main_size_;
// This gets set by SetContainerMainInnerSize
LayoutUnit container_main_inner_size;
LayoutUnit container_main_inner_size_;
// initial_free_space is the initial amount of free space in this flexbox.
// remaining_free_space starts out at the same value but as we place and lay
// out flex items we subtract from it. Note that both values can be
// negative.
// These get set by FreezeInflexibleItems, see spec:
// https://drafts.csswg.org/css-flexbox/#resolve-flexible-lengths step 3
LayoutUnit initial_free_space;
LayoutUnit remaining_free_space;
LayoutUnit initial_free_space_;
LayoutUnit remaining_free_space_;
// These get filled in by ComputeLineItemsPosition
LayoutUnit main_axis_offset;
LayoutUnit main_axis_extent;
LayoutUnit cross_axis_offset;
LayoutUnit cross_axis_extent;
LayoutUnit max_ascent;
LayoutUnit sum_justify_adjustments;
LayoutUnit main_axis_offset_;
LayoutUnit main_axis_extent_;
LayoutUnit cross_axis_offset_;
LayoutUnit cross_axis_extent_;
LayoutUnit max_ascent_;
LayoutUnit sum_justify_adjustments_;
};
// This class implements the CSS Flexbox layout algorithm:
......@@ -459,7 +459,7 @@ class FlexLayoutAlgorithm {
};
inline const FlexLine* FlexItem::Line() const {
return &algorithm->FlexLines()[line_number];
return &algorithm_->FlexLines()[line_number_];
}
} // namespace blink
......
......@@ -475,12 +475,12 @@ void LayoutFlexibleBox::RepositionLogicalHeightDependentFlexItems(
Vector<FlexLine>& line_contexts = algorithm.FlexLines();
LayoutUnit cross_axis_start_edge = line_contexts.IsEmpty()
? LayoutUnit()
: line_contexts[0].cross_axis_offset;
: line_contexts[0].cross_axis_offset_;
// If we have a single line flexbox, the line height is all the available
// space. For flex-direction: row, this means we need to use the height, so
// we do this after calling updateLogicalHeight.
if (!IsMultiline() && !line_contexts.IsEmpty()) {
line_contexts[0].cross_axis_extent = CrossAxisContentExtent();
line_contexts[0].cross_axis_extent_ = CrossAxisContentExtent();
}
AlignFlexLines(algorithm);
......@@ -491,8 +491,10 @@ void LayoutFlexibleBox::RepositionLogicalHeightDependentFlexItems(
algorithm.FlipForWrapReverse(cross_axis_start_edge,
CrossAxisContentExtent());
for (FlexLine& line_context : line_contexts) {
for (FlexItem& flex_item : line_context.line_items)
ResetAlignmentForChild(*flex_item.box, flex_item.desired_location.Y());
for (FlexItem& flex_item : line_context.line_items_) {
ResetAlignmentForChild(*flex_item.box_,
flex_item.desired_location_.Y());
}
}
}
......@@ -1062,14 +1064,14 @@ void LayoutFlexibleBox::LayoutFlexItems(bool relayout_children,
LayoutUnit logical_width = LogicalWidth();
FlexLine* current_line;
while ((current_line = flex_algorithm.ComputeNextFlexLine(logical_width))) {
DCHECK_GE(current_line->line_items.size(), 0ULL);
DCHECK_GE(current_line->line_items_.size(), 0ULL);
current_line->SetContainerMainInnerSize(
MainAxisContentExtent(current_line->sum_hypothetical_main_size));
MainAxisContentExtent(current_line->sum_hypothetical_main_size_));
current_line->FreezeInflexibleItems();
while (!current_line->ResolveFlexibleLengths()) {
DCHECK_GE(current_line->total_flex_grow, 0);
DCHECK_GE(current_line->total_weighted_flex_shrink, 0);
DCHECK_GE(current_line->total_flex_grow_, 0);
DCHECK_GE(current_line->total_weighted_flex_shrink_, 0);
}
LayoutLineItems(current_line, relayout_children, layout_scope);
......@@ -1080,7 +1082,7 @@ void LayoutFlexibleBox::LayoutFlexItems(bool relayout_children,
ApplyLineItemsPosition(current_line);
if (number_of_in_flow_children_on_first_line_ == -1) {
number_of_in_flow_children_on_first_line_ =
current_line->line_items.size();
current_line->line_items_.size();
}
}
if (HasLineIfEmpty()) {
......@@ -1342,10 +1344,10 @@ void LayoutFlexibleBox::ConstructAndAppendFlexItem(
void LayoutFlexibleBox::SetOverrideMainAxisContentSizeForChild(FlexItem& item) {
NOT_DESTROYED();
if (MainAxisIsInlineAxis(*item.box)) {
item.box->SetOverrideLogicalWidth(item.FlexedBorderBoxSize());
if (MainAxisIsInlineAxis(*item.box_)) {
item.box_->SetOverrideLogicalWidth(item.FlexedBorderBoxSize());
} else {
item.box->SetOverrideLogicalHeight(item.FlexedBorderBoxSize());
item.box_->SetOverrideLogicalHeight(item.FlexedBorderBoxSize());
}
}
......@@ -1598,18 +1600,18 @@ void LayoutFlexibleBox::LayoutLineItems(FlexLine* current_line,
bool relayout_children,
SubtreeLayoutScope& layout_scope) {
NOT_DESTROYED();
for (wtf_size_t i = 0; i < current_line->line_items.size(); ++i) {
FlexItem& flex_item = current_line->line_items[i];
LayoutBox* child = flex_item.box;
for (wtf_size_t i = 0; i < current_line->line_items_.size(); ++i) {
FlexItem& flex_item = current_line->line_items_[i];
LayoutBox* child = flex_item.box_;
DCHECK(!flex_item.box->IsOutOfFlowPositioned());
DCHECK(!flex_item.box_->IsOutOfFlowPositioned());
child->SetShouldCheckForPaintInvalidation();
SetOverrideMainAxisContentSizeForChild(flex_item);
// The flexed content size and the override size include the scrollbar
// width, so we need to compare to the size including the scrollbar.
if (flex_item.flexed_content_size !=
if (flex_item.flexed_content_size_ !=
MainAxisContentExtentForChildIncludingScrollbar(*child)) {
child->SetSelfNeedsLayoutForAvailableSpace(true);
} else {
......@@ -1655,33 +1657,33 @@ void LayoutFlexibleBox::LayoutLineItems(FlexLine* current_line,
// the flexed_content_size and so the result should in fact be that size.
// But it turns out that tables ignore the override size, and so we have
// to re-check the size so that we place the flex item correctly.
flex_item.flexed_content_size =
MainAxisExtentForChild(*child) - flex_item.main_axis_border_padding;
flex_item.cross_axis_size = CrossAxisUnstretchedExtentForChild(*child);
flex_item.flexed_content_size_ =
MainAxisExtentForChild(*child) - flex_item.main_axis_border_padding_;
flex_item.cross_axis_size_ = CrossAxisUnstretchedExtentForChild(*child);
}
}
void LayoutFlexibleBox::ApplyLineItemsPosition(FlexLine* current_line) {
NOT_DESTROYED();
bool is_paginated = View()->GetLayoutState()->IsPaginated();
for (wtf_size_t i = 0; i < current_line->line_items.size(); ++i) {
const FlexItem& flex_item = current_line->line_items[i];
LayoutBox* child = flex_item.box;
SetFlowAwareLocationForChild(*child, flex_item.desired_location);
child->SetMargin(flex_item.physical_margins);
for (wtf_size_t i = 0; i < current_line->line_items_.size(); ++i) {
const FlexItem& flex_item = current_line->line_items_[i];
LayoutBox* child = flex_item.box_;
SetFlowAwareLocationForChild(*child, flex_item.desired_location_);
child->SetMargin(flex_item.physical_margins_);
if (is_paginated)
UpdateFragmentationInfoForChild(*child);
}
if (IsColumnFlow()) {
SetLogicalHeight(std::max(LogicalHeight(), current_line->main_axis_extent +
SetLogicalHeight(std::max(LogicalHeight(), current_line->main_axis_extent_ +
FlowAwareContentInsetEnd()));
} else {
SetLogicalHeight(
std::max(LogicalHeight(), current_line->cross_axis_offset +
std::max(LogicalHeight(), current_line->cross_axis_offset_ +
FlowAwareContentInsetAfter() +
current_line->cross_axis_extent));
current_line->cross_axis_extent_));
}
if (StyleRef().ResolvedIsColumnReverseFlexDirection()) {
......@@ -1689,9 +1691,9 @@ void LayoutFlexibleBox::ApplyLineItemsPosition(FlexLine* current_line) {
// items since the start depends on the height of the flexbox, which we
// only know after we've positioned all the flex items.
UpdateLogicalHeight();
LayoutColumnReverse(current_line->line_items,
current_line->cross_axis_offset,
current_line->remaining_free_space);
LayoutColumnReverse(current_line->line_items_,
current_line->cross_axis_offset_,
current_line->remaining_free_space_);
}
}
......@@ -1710,7 +1712,7 @@ void LayoutFlexibleBox::LayoutColumnReverse(FlexItemVectorView& children,
for (wtf_size_t i = 0; i < children.size(); ++i) {
FlexItem& flex_item = children[i];
LayoutBox* child = flex_item.box;
LayoutBox* child = flex_item.box_;
DCHECK(!child->IsOutOfFlowPositioned());
......@@ -1749,8 +1751,8 @@ void LayoutFlexibleBox::AlignFlexLines(FlexLayoutAlgorithm& algorithm) {
for (unsigned line_number = 0; line_number < line_contexts.size();
++line_number) {
FlexLine& line_context = line_contexts[line_number];
for (FlexItem& flex_item : line_context.line_items) {
ResetAlignmentForChild(*flex_item.box, flex_item.desired_location.Y());
for (FlexItem& flex_item : line_context.line_items_) {
ResetAlignmentForChild(*flex_item.box_, flex_item.desired_location_.Y());
}
}
}
......@@ -1771,28 +1773,28 @@ void LayoutFlexibleBox::AlignChildren(FlexLayoutAlgorithm& algorithm) {
for (unsigned line_number = 0; line_number < line_contexts.size();
++line_number) {
FlexLine& line_context = line_contexts[line_number];
for (FlexItem& flex_item : line_context.line_items) {
if (flex_item.needs_relayout_for_stretch) {
for (FlexItem& flex_item : line_context.line_items_) {
if (flex_item.needs_relayout_for_stretch_) {
DCHECK(flex_item.Alignment() == ItemPosition::kStretch);
ApplyStretchAlignmentToChild(flex_item);
flex_item.needs_relayout_for_stretch = false;
flex_item.needs_relayout_for_stretch_ = false;
}
ResetAlignmentForChild(*flex_item.box, flex_item.desired_location.Y());
flex_item.box->SetMargin(flex_item.physical_margins);
ResetAlignmentForChild(*flex_item.box_, flex_item.desired_location_.Y());
flex_item.box_->SetMargin(flex_item.physical_margins_);
}
}
}
void LayoutFlexibleBox::ApplyStretchAlignmentToChild(FlexItem& flex_item) {
NOT_DESTROYED();
LayoutBox& child = *flex_item.box;
LayoutBox& child = *flex_item.box_;
if (flex_item.MainAxisIsInlineAxis() &&
child.StyleRef().LogicalHeight().IsAuto()) {
// FIXME: Can avoid laying out here in some cases. See
// https://webkit.org/b/87905.
bool child_needs_relayout =
flex_item.cross_axis_size != child.LogicalHeight();
child.SetOverrideLogicalHeight(flex_item.cross_axis_size);
flex_item.cross_axis_size_ != child.LogicalHeight();
child.SetOverrideLogicalHeight(flex_item.cross_axis_size_);
auto* child_block = DynamicTo<LayoutBlock>(child);
if (child_block && child_block->HasPercentHeightDescendants() &&
......@@ -1807,8 +1809,8 @@ void LayoutFlexibleBox::ApplyStretchAlignmentToChild(FlexItem& flex_item) {
child.ForceLayout();
} else if (!flex_item.MainAxisIsInlineAxis() &&
child.StyleRef().LogicalWidth().IsAuto()) {
if (flex_item.cross_axis_size != child.LogicalWidth()) {
child.SetOverrideLogicalWidth(flex_item.cross_axis_size);
if (flex_item.cross_axis_size_ != child.LogicalWidth()) {
child.SetOverrideLogicalWidth(flex_item.cross_axis_size_);
child.ForceLayout();
}
}
......@@ -1822,14 +1824,14 @@ void LayoutFlexibleBox::FlipForRightToLeftColumn(
LayoutUnit cross_extent = CrossAxisExtent();
for (const FlexLine& line_context : line_contexts) {
for (const FlexItem& flex_item : line_context.line_items) {
DCHECK(!flex_item.box->IsOutOfFlowPositioned());
for (const FlexItem& flex_item : line_context.line_items_) {
DCHECK(!flex_item.box_->IsOutOfFlowPositioned());
LayoutPoint location = FlowAwareLocationForChild(*flex_item.box);
LayoutPoint location = FlowAwareLocationForChild(*flex_item.box_);
// For vertical flows, setFlowAwareLocationForChild will transpose x and
// y, so using the y axis for a column cross axis extent is correct.
location.SetY(cross_extent - flex_item.cross_axis_size - location.Y());
SetFlowAwareLocationForChild(*flex_item.box, location);
location.SetY(cross_extent - flex_item.cross_axis_size_ - location.Y());
SetFlowAwareLocationForChild(*flex_item.box_, location);
}
}
}
......
......@@ -897,7 +897,7 @@ void NGFlexLayoutAlgorithm::ConstructAndAppendFlexItems() {
main_axis_border_padding, cross_axis_border_padding,
physical_child_margins, scrollbars,
min_max_sizes.has_value())
.ng_input_node = child;
.ng_input_node_ = child;
}
}
......@@ -993,35 +993,35 @@ scoped_refptr<const NGLayoutResult> NGFlexLayoutAlgorithm::LayoutInternal() {
while (
(line = algorithm_->ComputeNextFlexLine(border_box_size_.inline_size))) {
line->SetContainerMainInnerSize(
MainAxisContentExtent(line->sum_hypothetical_main_size));
MainAxisContentExtent(line->sum_hypothetical_main_size_));
line->FreezeInflexibleItems();
while (!line->ResolveFlexibleLengths()) {
continue;
}
for (wtf_size_t i = 0; i < line->line_items.size(); ++i) {
FlexItem& flex_item = line->line_items[i];
for (wtf_size_t i = 0; i < line->line_items_.size(); ++i) {
FlexItem& flex_item = line->line_items_[i];
const ComputedStyle& child_style = flex_item.ng_input_node.Style();
const ComputedStyle& child_style = flex_item.ng_input_node_.Style();
NGConstraintSpaceBuilder space_builder(ConstraintSpace(),
child_style.GetWritingMode(),
/* is_new_fc */ true);
SetOrthogonalFallbackInlineSizeIfNeeded(Style(), flex_item.ng_input_node,
SetOrthogonalFallbackInlineSizeIfNeeded(Style(), flex_item.ng_input_node_,
&space_builder);
space_builder.SetTextDirection(child_style.Direction());
space_builder.SetIsPaintedAtomically(true);
LogicalSize available_size;
NGBoxStrut margins = flex_item.physical_margins.ConvertToLogical(
NGBoxStrut margins = flex_item.physical_margins_.ConvertToLogical(
ConstraintSpace().GetWritingMode(), Style().Direction());
LayoutUnit fixed_aspect_ratio_cross_size = kIndefiniteSize;
if (RuntimeEnabledFeatures::FlexAspectRatioEnabled() &&
flex_item.ng_input_node.HasAspectRatio() &&
flex_item.ng_input_node.IsReplaced()) {
flex_item.ng_input_node_.HasAspectRatio() &&
flex_item.ng_input_node_.IsReplaced()) {
// This code derives the cross axis size from the flexed main size and
// the aspect ratio. We can delete this code when
// NGReplacedLayoutAlgorithm exists, because it will do this for us.
NGConstraintSpace flex_basis_space =
BuildSpaceForFlexBasis(flex_item.ng_input_node);
BuildSpaceForFlexBasis(flex_item.ng_input_node_);
const Length& cross_axis_length =
is_horizontal_flow_ ? child_style.Height() : child_style.Width();
// Only derive the cross axis size from the aspect ratio if the computed
......@@ -1029,26 +1029,26 @@ scoped_refptr<const NGLayoutResult> NGFlexLayoutAlgorithm::LayoutInternal() {
// might still be definite if it is stretched, but that is checked in
// the |WillChildCrossSizeBeContainerCrossSize| calls below.
if (cross_axis_length.IsAuto() ||
(MainAxisIsInlineAxis(flex_item.ng_input_node) &&
(MainAxisIsInlineAxis(flex_item.ng_input_node_) &&
BlockLengthUnresolvable(flex_basis_space, cross_axis_length,
LengthResolvePhase::kLayout))) {
fixed_aspect_ratio_cross_size =
flex_item.min_max_cross_sizes->ClampSizeToMinAndMax(
flex_item.cross_axis_border_padding +
flex_item.min_max_cross_sizes_->ClampSizeToMinAndMax(
flex_item.cross_axis_border_padding_ +
LayoutUnit(
flex_item.flexed_content_size /
GetMainOverCrossAspectRatio(flex_item.ng_input_node)));
flex_item.flexed_content_size_ /
GetMainOverCrossAspectRatio(flex_item.ng_input_node_)));
}
}
if (is_column_) {
available_size.inline_size = ChildAvailableSize().inline_size;
available_size.block_size =
flex_item.flexed_content_size + flex_item.main_axis_border_padding;
available_size.block_size = flex_item.flexed_content_size_ +
flex_item.main_axis_border_padding_;
space_builder.SetIsFixedBlockSize(true);
if (WillChildCrossSizeBeContainerCrossSize(flex_item.ng_input_node)) {
if (WillChildCrossSizeBeContainerCrossSize(flex_item.ng_input_node_)) {
space_builder.SetIsFixedInlineSize(true);
available_size.inline_size = CalculateFixedCrossSize(
flex_item.min_max_cross_sizes.value(), margins);
flex_item.min_max_cross_sizes_.value(), margins);
} else if (fixed_aspect_ratio_cross_size != kIndefiniteSize) {
space_builder.SetIsFixedInlineSize(true);
available_size.inline_size = fixed_aspect_ratio_cross_size;
......@@ -1058,22 +1058,22 @@ scoped_refptr<const NGLayoutResult> NGFlexLayoutAlgorithm::LayoutInternal() {
// post-flexing main size is treated as definite, even though it can
// rely on the indefinite sizes of any flex items in the same line.
if (!IsColumnContainerMainSizeDefinite() &&
!IsItemMainSizeDefinite(flex_item.ng_input_node)) {
!IsItemMainSizeDefinite(flex_item.ng_input_node_)) {
space_builder.SetIsFixedBlockSizeIndefinite(true);
}
} else {
available_size.inline_size =
flex_item.flexed_content_size + flex_item.main_axis_border_padding;
available_size.inline_size = flex_item.flexed_content_size_ +
flex_item.main_axis_border_padding_;
available_size.block_size = ChildAvailableSize().block_size;
space_builder.SetIsFixedInlineSize(true);
if (WillChildCrossSizeBeContainerCrossSize(flex_item.ng_input_node)) {
if (WillChildCrossSizeBeContainerCrossSize(flex_item.ng_input_node_)) {
space_builder.SetIsFixedBlockSize(true);
available_size.block_size = CalculateFixedCrossSize(
flex_item.min_max_cross_sizes.value(), margins);
flex_item.min_max_cross_sizes_.value(), margins);
} else if (fixed_aspect_ratio_cross_size != kIndefiniteSize) {
space_builder.SetIsFixedBlockSize(true);
available_size.block_size = fixed_aspect_ratio_cross_size;
} else if (DoesItemStretch(flex_item.ng_input_node)) {
} else if (DoesItemStretch(flex_item.ng_input_node_)) {
// If we are in a row flexbox, and we don't have a fixed block-size
// (yet), use the "measure" cache slot. This will be the first
// layout, and we will use the "layout" cache slot if this gets
......@@ -1099,7 +1099,7 @@ scoped_refptr<const NGLayoutResult> NGFlexLayoutAlgorithm::LayoutInternal() {
// Determine the hypothetical cross size of each item by performing layout
// with the used main size and the available space, treating auto as
// fit-content.
if (ShouldItemShrinkToFit(flex_item.ng_input_node))
if (ShouldItemShrinkToFit(flex_item.ng_input_node_))
space_builder.SetIsShrinkToFit(true);
// For a button child, we need the baseline type same as the container's
......@@ -1112,16 +1112,16 @@ scoped_refptr<const NGLayoutResult> NGFlexLayoutAlgorithm::LayoutInternal() {
}
NGConstraintSpace child_space = space_builder.ToConstraintSpace();
flex_item.layout_result =
flex_item.ng_input_node.Layout(child_space, nullptr /*break token*/);
flex_item.layout_result_ =
flex_item.ng_input_node_.Layout(child_space, nullptr /*break token*/);
// TODO(layout-dev): Handle abortions caused by block fragmentation.
DCHECK_EQ(flex_item.layout_result->Status(), NGLayoutResult::kSuccess);
DCHECK_EQ(flex_item.layout_result_->Status(), NGLayoutResult::kSuccess);
flex_item.cross_axis_size =
flex_item.cross_axis_size_ =
is_horizontal_flow_
? flex_item.layout_result->PhysicalFragment().Size().height
: flex_item.layout_result->PhysicalFragment().Size().width;
? flex_item.layout_result_->PhysicalFragment().Size().height
: flex_item.layout_result_->PhysicalFragment().Size().width;
}
// cross_axis_offset is updated in each iteration of the loop, for passing
// in to the next iteration.
......@@ -1157,21 +1157,21 @@ scoped_refptr<const NGLayoutResult> NGFlexLayoutAlgorithm::LayoutInternal() {
}
void NGFlexLayoutAlgorithm::ApplyStretchAlignmentToChild(FlexItem& flex_item) {
const ComputedStyle& child_style = flex_item.ng_input_node.Style();
const ComputedStyle& child_style = flex_item.ng_input_node_.Style();
NGConstraintSpaceBuilder space_builder(ConstraintSpace(),
child_style.GetWritingMode(),
/* is_new_fc */ true);
SetOrthogonalFallbackInlineSizeIfNeeded(Style(), flex_item.ng_input_node,
SetOrthogonalFallbackInlineSizeIfNeeded(Style(), flex_item.ng_input_node_,
&space_builder);
space_builder.SetIsPaintedAtomically(true);
LogicalSize available_size(
flex_item.flexed_content_size + flex_item.main_axis_border_padding,
flex_item.cross_axis_size);
flex_item.flexed_content_size_ + flex_item.main_axis_border_padding_,
flex_item.cross_axis_size_);
if (is_column_) {
available_size.Transpose();
if (!IsColumnContainerMainSizeDefinite() &&
!IsItemMainSizeDefinite(flex_item.ng_input_node)) {
!IsItemMainSizeDefinite(flex_item.ng_input_node_)) {
space_builder.SetIsFixedBlockSizeIndefinite(true);
}
}
......@@ -1188,15 +1188,15 @@ void NGFlexLayoutAlgorithm::ApplyStretchAlignmentToChild(FlexItem& flex_item) {
space_builder.SetIsFixedInlineSize(true);
space_builder.SetIsFixedBlockSize(true);
NGConstraintSpace child_space = space_builder.ToConstraintSpace();
flex_item.layout_result =
flex_item.ng_input_node.Layout(child_space, /* break_token */ nullptr);
flex_item.layout_result_ =
flex_item.ng_input_node_.Layout(child_space, /* break_token */ nullptr);
}
bool NGFlexLayoutAlgorithm::GiveLinesAndItemsFinalPositionAndSize() {
Vector<FlexLine>& line_contexts = algorithm_->FlexLines();
const LayoutUnit cross_axis_start_edge =
line_contexts.IsEmpty() ? LayoutUnit()
: line_contexts[0].cross_axis_offset;
: line_contexts[0].cross_axis_offset_;
LayoutUnit final_content_main_size =
container_builder_.InlineSize() - BorderScrollbarPadding().InlineSum();
......@@ -1206,7 +1206,7 @@ bool NGFlexLayoutAlgorithm::GiveLinesAndItemsFinalPositionAndSize() {
std::swap(final_content_main_size, final_content_cross_size);
if (!algorithm_->IsMultiline() && !line_contexts.IsEmpty())
line_contexts[0].cross_axis_extent = final_content_cross_size;
line_contexts[0].cross_axis_extent_ = final_content_cross_size;
algorithm_->AlignFlexLines(final_content_cross_size);
......@@ -1231,22 +1231,22 @@ bool NGFlexLayoutAlgorithm::GiveLinesAndItemsFinalPositionAndSize() {
LayoutUnit overflow_block_size;
for (FlexLine& line_context : line_contexts) {
for (wtf_size_t child_number = 0;
child_number < line_context.line_items.size(); ++child_number) {
FlexItem& flex_item = line_context.line_items[child_number];
child_number < line_context.line_items_.size(); ++child_number) {
FlexItem& flex_item = line_context.line_items_[child_number];
if (DoesItemStretch(flex_item.ng_input_node))
if (DoesItemStretch(flex_item.ng_input_node_))
ApplyStretchAlignmentToChild(flex_item);
const auto& physical_fragment = To<NGPhysicalBoxFragment>(
flex_item.layout_result->PhysicalFragment());
flex_item.layout_result_->PhysicalFragment());
// flex_item.desired_location stores the main axis offset in X and the
// flex_item.desired_location_ stores the main axis offset in X and the
// cross axis offset in Y. But AddChild wants offset from parent
// rectangle, so we have to transpose for columns. AddChild takes care of
// any writing mode differences though.
LayoutPoint location = is_column_
? flex_item.desired_location.TransposedPoint()
: flex_item.desired_location;
? flex_item.desired_location_.TransposedPoint()
: flex_item.desired_location_;
NGBoxFragment fragment(ConstraintSpace().GetWritingMode(),
ConstraintSpace().Direction(), physical_fragment);
......@@ -1259,10 +1259,10 @@ bool NGFlexLayoutAlgorithm::GiveLinesAndItemsFinalPositionAndSize() {
container_builder_.AddChild(physical_fragment,
{location.X(), location.Y()});
flex_item.ng_input_node.StoreMargins(flex_item.physical_margins);
flex_item.ng_input_node_.StoreMargins(flex_item.physical_margins_);
LayoutUnit margin_block_end =
flex_item.physical_margins
flex_item.physical_margins_
.ConvertToLogical(ConstraintSpace().GetWritingMode(),
ConstraintSpace().Direction())
.block_end;
......@@ -1273,19 +1273,19 @@ bool NGFlexLayoutAlgorithm::GiveLinesAndItemsFinalPositionAndSize() {
// Detect if the flex-item had its scrollbar state change. If so we need
// to relayout as the input to the flex algorithm is incorrect.
if (!ignore_child_scrollbar_changes_) {
if (flex_item.scrollbars !=
ComputeScrollbarsForNonAnonymous(flex_item.ng_input_node))
if (flex_item.scrollbars_ !=
ComputeScrollbarsForNonAnonymous(flex_item.ng_input_node_))
success = false;
// The flex-item scrollbars may not have changed, but an descendant's
// scrollbars might have causing the min/max sizes to be incorrect.
if (flex_item.depends_on_min_max_sizes &&
flex_item.ng_input_node.GetLayoutBox()
if (flex_item.depends_on_min_max_sizes_ &&
flex_item.ng_input_node_.GetLayoutBox()
->IntrinsicLogicalWidthsDirty())
success = false;
} else {
DCHECK_EQ(flex_item.scrollbars,
ComputeScrollbarsForNonAnonymous(flex_item.ng_input_node));
DCHECK_EQ(flex_item.scrollbars_,
ComputeScrollbarsForNonAnonymous(flex_item.ng_input_node_));
}
}
}
......@@ -1382,7 +1382,7 @@ void NGFlexLayoutAlgorithm::PropagateBaselineFromChild(
// We prefer a baseline from a child with baseline alignment, and no
// auto-margins in the cross axis (even if we have to synthesize the
// baseline).
if (FlexLayoutAlgorithm::AlignmentForChild(Style(), flex_item.style) ==
if (FlexLayoutAlgorithm::AlignmentForChild(Style(), flex_item.style_) ==
ItemPosition::kBaseline &&
!flex_item.HasAutoMarginsInCrossAxis()) {
container_builder_.SetBaseline(baseline_offset);
......
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