Commit 53715db6 authored by Ian Kilpatrick's avatar Ian Kilpatrick Committed by Commit Bot

[cleanup] Refactor FlexLine::ComputeLineItemsPosition.

In preparation for:
https://chromium-review.googlesource.com/c/chromium/src/+/2490323

There should be no behaviour change - just moving things around to
reduce deltas of subsequent behaviour changing patches.

Change-Id: Iac5714cb492cfaf7b2dc5117cb39d4f1b7b9b452
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2507336
Commit-Queue: David Grogan <dgrogan@chromium.org>
Reviewed-by: default avatarDavid Grogan <dgrogan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#822550}
parent 8b98537a
......@@ -482,6 +482,9 @@ LayoutUnit FlexLine::ApplyMainAxisAutoMarginAdjustment() {
void FlexLine::ComputeLineItemsPosition(LayoutUnit main_axis_start_offset,
LayoutUnit main_axis_end_offset,
LayoutUnit& cross_axis_offset) {
const auto& style = algorithm_->StyleRef();
const bool is_webkit_box = style.IsDeprecatedWebkitBox();
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.
......@@ -493,43 +496,41 @@ void FlexLine::ComputeLineItemsPosition(LayoutUnit main_axis_start_offset,
(line_items_.size() - 1) * algorithm_->gap_between_items_;
const StyleContentAlignmentData justify_content =
FlexLayoutAlgorithm::ResolvedJustifyContent(*algorithm_->Style());
FlexLayoutAlgorithm::ResolvedJustifyContent(style);
LayoutUnit auto_margin_offset = ApplyMainAxisAutoMarginAdjustment();
const LayoutUnit auto_margin_offset = ApplyMainAxisAutoMarginAdjustment();
const LayoutUnit available_free_space = remaining_free_space_;
LayoutUnit initial_position =
const LayoutUnit initial_position =
FlexLayoutAlgorithm::InitialContentPositionOffset(
algorithm_->StyleRef(), available_free_space, justify_content,
line_items_.size());
LayoutUnit main_axis_offset = initial_position;
style, available_free_space, justify_content, line_items_.size());
sum_justify_adjustments_ += initial_position;
LayoutUnit max_descent; // Used when align-items: baseline.
LayoutUnit max_child_cross_axis_extent;
LayoutUnit main_axis_offset = initial_position + main_axis_start_offset;
LayoutUnit logical_width_when_flipped = container_logical_width_;
LayoutUnit flipped_offset;
bool should_flip_main_axis;
if (algorithm_->IsNGFlexBox()) {
should_flip_main_axis =
algorithm_->StyleRef().ResolvedIsRowReverseFlexDirection();
should_flip_main_axis = style.ResolvedIsRowReverseFlexDirection();
} else {
should_flip_main_axis =
!algorithm_->StyleRef().ResolvedIsColumnFlexDirection() &&
!algorithm_->IsLeftToRightFlow();
}
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()) {
// -webkit-box only distributed space when > 0.
width_when_flipped =
total_item_size + available_free_space.ClampNegativeToZero();
flipped_offset = main_axis_end_offset;
} else {
main_axis_offset += main_axis_start_offset;
should_flip_main_axis = !style.ResolvedIsColumnFlexDirection() &&
!algorithm_->IsLeftToRightFlow();
// -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 && is_webkit_box) {
// -webkit-box only distributed space when > 0.
logical_width_when_flipped =
total_item_size + available_free_space.ClampNegativeToZero();
flipped_offset = main_axis_end_offset;
main_axis_offset -= main_axis_start_offset;
}
}
LayoutUnit max_descent; // Used when align-items: baseline.
LayoutUnit max_child_cross_axis_extent;
for (size_t i = 0; i < line_items_.size(); ++i) {
FlexItem& flex_item = line_items_[i];
......@@ -561,7 +562,7 @@ void FlexLine::ComputeLineItemsPosition(LayoutUnit main_axis_start_offset,
// on the left. This will be fixed later in
// LayoutFlexibleBox::FlipForRightToLeftColumn.
flex_item.desired_location_ = LayoutPoint(
should_flip_main_axis ? width_when_flipped - main_axis_offset -
should_flip_main_axis ? logical_width_when_flipped - main_axis_offset -
child_main_extent + flipped_offset
: main_axis_offset,
cross_axis_offset + flex_item.FlowAwareMarginBefore());
......
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