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, ...@@ -53,35 +53,40 @@ FlexLayoutAlgorithm::FlexLayoutAlgorithm(const ComputedStyle* style,
const Vector<FlexItem>& all_items) const Vector<FlexItem>& all_items)
: style_(style), : style_(style),
line_break_length_(line_break_length), 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* FlexLayoutAlgorithm::ComputeNextFlexLine() {
FlexLine* line) { FlexLine new_line;
line->Reset();
bool line_has_in_flow_item = false; bool line_has_in_flow_item = false;
for (; *next_index < all_items_.size(); ++*next_index) { for (; next_item_index_ < all_items_.size(); ++next_item_index_) {
const FlexItem& flex_item = all_items_[*next_index]; const FlexItem& flex_item = all_items_[next_item_index_];
DCHECK(!flex_item.box->IsOutOfFlowPositioned()); DCHECK(!flex_item.box->IsOutOfFlowPositioned());
if (IsMultiline() && if (IsMultiline() &&
line->sum_hypothetical_main_size + new_line.sum_hypothetical_main_size +
flex_item.HypotheticalMainAxisMarginBoxSize() > flex_item.HypotheticalMainAxisMarginBoxSize() >
line_break_length_ && line_break_length_ &&
line_has_in_flow_item) line_has_in_flow_item)
break; break;
line->line_items.push_back(flex_item); new_line.line_items.push_back(flex_item);
line_has_in_flow_item = true; line_has_in_flow_item = true;
line->sum_flex_base_size += flex_item.FlexBaseMarginBoxSize(); new_line.sum_flex_base_size += flex_item.FlexBaseMarginBoxSize();
line->total_flex_grow += flex_item.box->Style()->FlexGrow(); new_line.total_flex_grow += flex_item.box->Style()->FlexGrow();
line->total_flex_shrink += flex_item.box->Style()->FlexShrink(); new_line.total_flex_shrink += flex_item.box->Style()->FlexShrink();
line->total_weighted_flex_shrink += new_line.total_weighted_flex_shrink +=
flex_item.box->Style()->FlexShrink() * flex_item.flex_base_content_size; 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(); flex_item.HypotheticalMainAxisMarginBoxSize();
} }
DCHECK(line->line_items.size() > 0 || *next_index == all_items_.size()); DCHECK(new_line.line_items.size() > 0 ||
return 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 } // namespace blink
...@@ -75,12 +75,8 @@ class FlexItem { ...@@ -75,12 +75,8 @@ class FlexItem {
}; };
struct FlexLine { struct FlexLine {
void Reset() { FlexLine() {
line_items.clear();
sum_flex_base_size = LayoutUnit();
total_flex_grow = total_flex_shrink = total_weighted_flex_shrink = 0; 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. // These fields get filled in by ComputeNextFlexLine.
...@@ -108,7 +104,11 @@ class FlexLayoutAlgorithm { ...@@ -108,7 +104,11 @@ class FlexLayoutAlgorithm {
LayoutUnit line_break_length, LayoutUnit line_break_length,
const Vector<FlexItem>& all_items); 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: private:
bool IsMultiline() const { return style_->FlexWrap() != EFlexWrap::kNowrap; } bool IsMultiline() const { return style_->FlexWrap() != EFlexWrap::kNowrap; }
...@@ -116,6 +116,8 @@ class FlexLayoutAlgorithm { ...@@ -116,6 +116,8 @@ class FlexLayoutAlgorithm {
const ComputedStyle* style_; const ComputedStyle* style_;
LayoutUnit line_break_length_; LayoutUnit line_break_length_;
const Vector<FlexItem>& all_items_; const Vector<FlexItem>& all_items_;
Vector<FlexLine> flex_lines_;
size_t next_item_index_;
}; };
} // namespace blink } // namespace blink
......
...@@ -198,10 +198,10 @@ class CORE_EXPORT LayoutFlexibleBox : public LayoutBlock { ...@@ -198,10 +198,10 @@ class CORE_EXPORT LayoutFlexibleBox : public LayoutBlock {
FlexItem ConstructFlexItem(LayoutBox& child, ChildLayoutType); FlexItem ConstructFlexItem(LayoutBox& child, ChildLayoutType);
void FreezeInflexibleItems(FlexSign, void FreezeInflexibleItems(FlexSign,
FlexLine&, FlexLine*,
LayoutUnit& remaining_free_space); LayoutUnit& remaining_free_space);
bool ResolveFlexibleLengths(FlexSign, bool ResolveFlexibleLengths(FlexSign,
FlexLine&, FlexLine*,
LayoutUnit initial_free_space, LayoutUnit initial_free_space,
LayoutUnit& remaining_free_space); LayoutUnit& remaining_free_space);
void FreezeViolations(Vector<FlexItem*>&, void FreezeViolations(Vector<FlexItem*>&,
...@@ -215,7 +215,7 @@ class CORE_EXPORT LayoutFlexibleBox : public LayoutBlock { ...@@ -215,7 +215,7 @@ class CORE_EXPORT LayoutFlexibleBox : public LayoutBlock {
LayoutUnit child_preferred_size); LayoutUnit child_preferred_size);
void PrepareChildForPositionedLayout(LayoutBox& child); void PrepareChildForPositionedLayout(LayoutBox& child);
void LayoutAndPlaceChildren(LayoutUnit& cross_axis_offset, void LayoutAndPlaceChildren(LayoutUnit& cross_axis_offset,
FlexLine&, FlexLine*,
LayoutUnit available_free_space, LayoutUnit available_free_space,
bool relayout_children, bool relayout_children,
SubtreeLayoutScope&); 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