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

[css-flexbox] More refactor: Store lines in the FlexibleBoxAlgorithm

R=eae@chromium.org

Change-Id: Ib267b515d4620ffa31de2ade2cdd4739c99027b9
Reviewed-on: https://chromium-review.googlesource.com/578391
Commit-Queue: Christian Biesinger <cbiesinger@chromium.org>
Commit-Queue: Emil A Eklund <eae@chromium.org>
Reviewed-by: default avatarEmil A Eklund <eae@chromium.org>
Cr-Commit-Position: refs/heads/master@{#488091}
parent bbd51398
......@@ -53,35 +53,40 @@ FlexLayoutAlgorithm::FlexLayoutAlgorithm(const ComputedStyle* style,
const Vector<FlexItem>& all_items)
: style_(style),
line_break_length_(line_break_length),
all_items_(all_items) {}
all_items_(all_items),
next_item_index_(0) {}
bool FlexLayoutAlgorithm::ComputeNextFlexLine(size_t* next_index,
FlexLine* line) {
line->Reset();
FlexLine* FlexLayoutAlgorithm::ComputeNextFlexLine() {
FlexLine new_line;
bool line_has_in_flow_item = false;
for (; *next_index < all_items_.size(); ++*next_index) {
const FlexItem& flex_item = all_items_[*next_index];
for (; next_item_index_ < all_items_.size(); ++next_item_index_) {
const FlexItem& flex_item = all_items_[next_item_index_];
DCHECK(!flex_item.box->IsOutOfFlowPositioned());
if (IsMultiline() &&
line->sum_hypothetical_main_size +
new_line.sum_hypothetical_main_size +
flex_item.HypotheticalMainAxisMarginBoxSize() >
line_break_length_ &&
line_has_in_flow_item)
break;
line->line_items.push_back(flex_item);
new_line.line_items.push_back(flex_item);
line_has_in_flow_item = true;
line->sum_flex_base_size += flex_item.FlexBaseMarginBoxSize();
line->total_flex_grow += flex_item.box->Style()->FlexGrow();
line->total_flex_shrink += flex_item.box->Style()->FlexShrink();
line->total_weighted_flex_shrink +=
new_line.sum_flex_base_size += flex_item.FlexBaseMarginBoxSize();
new_line.total_flex_grow += flex_item.box->Style()->FlexGrow();
new_line.total_flex_shrink += flex_item.box->Style()->FlexShrink();
new_line.total_weighted_flex_shrink +=
flex_item.box->Style()->FlexShrink() * flex_item.flex_base_content_size;
line->sum_hypothetical_main_size +=
new_line.sum_hypothetical_main_size +=
flex_item.HypotheticalMainAxisMarginBoxSize();
}
DCHECK(line->line_items.size() > 0 || *next_index == all_items_.size());
return line->line_items.size() > 0;
DCHECK(new_line.line_items.size() > 0 ||
next_item_index_ == all_items_.size());
if (new_line.line_items.size() > 0) {
flex_lines_.push_back(std::move(new_line));
return &flex_lines_.back();
}
return nullptr;
}
} // namespace blink
......@@ -75,12 +75,8 @@ class FlexItem {
};
struct FlexLine {
void Reset() {
line_items.clear();
sum_flex_base_size = LayoutUnit();
FlexLine() {
total_flex_grow = total_flex_shrink = total_weighted_flex_shrink = 0;
sum_hypothetical_main_size = LayoutUnit();
cross_axis_offset = cross_axis_extent = max_ascent = LayoutUnit();
}
// These fields get filled in by ComputeNextFlexLine.
......@@ -108,7 +104,11 @@ class FlexLayoutAlgorithm {
LayoutUnit line_break_length,
const Vector<FlexItem>& all_items);
bool ComputeNextFlexLine(size_t* next_index, FlexLine*);
Vector<FlexLine>& FlexLines() { return flex_lines_; }
// Computes the next flex line, stores it in FlexLines(), and returns a
// pointer to it. Returns nullptr if there are no more lines.
FlexLine* ComputeNextFlexLine();
private:
bool IsMultiline() const { return style_->FlexWrap() != EFlexWrap::kNowrap; }
......@@ -116,6 +116,8 @@ class FlexLayoutAlgorithm {
const ComputedStyle* style_;
LayoutUnit line_break_length_;
const Vector<FlexItem>& all_items_;
Vector<FlexLine> flex_lines_;
size_t next_item_index_;
};
} // namespace blink
......
......@@ -198,10 +198,10 @@ class CORE_EXPORT LayoutFlexibleBox : public LayoutBlock {
FlexItem ConstructFlexItem(LayoutBox& child, ChildLayoutType);
void FreezeInflexibleItems(FlexSign,
FlexLine&,
FlexLine*,
LayoutUnit& remaining_free_space);
bool ResolveFlexibleLengths(FlexSign,
FlexLine&,
FlexLine*,
LayoutUnit initial_free_space,
LayoutUnit& remaining_free_space);
void FreezeViolations(Vector<FlexItem*>&,
......@@ -215,7 +215,7 @@ class CORE_EXPORT LayoutFlexibleBox : public LayoutBlock {
LayoutUnit child_preferred_size);
void PrepareChildForPositionedLayout(LayoutBox& child);
void LayoutAndPlaceChildren(LayoutUnit& cross_axis_offset,
FlexLine&,
FlexLine*,
LayoutUnit available_free_space,
bool relayout_children,
SubtreeLayoutScope&);
......
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