Commit 7d391a34 authored by Christian Biesinger's avatar Christian Biesinger Committed by Commit Bot

[css-flexbox] Continue refactoring flexbox layout

Move LineContext to FlexLayoutAlgorithm.h and rename it to FlexLine
to be more clear on what it represents. This change also now uses
that struct as the out parameter for ComputeNextFlexLine, replacing
several individual variables.

This will enable moving more functionality to FlexLayoutAlgorithm with
the ultimate goal (besides making the code easier to understand) of
reusing it for LayoutNG.

R=eae@chromium.org

Change-Id: I1cc1f9a9090fbb7d3a3c10537133c698f875a01d
Reviewed-on: https://chromium-review.googlesource.com/576893
Commit-Queue: Christian Biesinger <cbiesinger@chromium.org>
Reviewed-by: default avatarEmil A Eklund <eae@chromium.org>
Cr-Commit-Position: refs/heads/master@{#488036}
parent d503ac60
...@@ -55,41 +55,33 @@ FlexLayoutAlgorithm::FlexLayoutAlgorithm(const ComputedStyle* style, ...@@ -55,41 +55,33 @@ FlexLayoutAlgorithm::FlexLayoutAlgorithm(const ComputedStyle* style,
line_break_length_(line_break_length), line_break_length_(line_break_length),
all_items_(all_items) {} all_items_(all_items) {}
bool FlexLayoutAlgorithm::ComputeNextFlexLine( bool FlexLayoutAlgorithm::ComputeNextFlexLine(size_t* next_index,
size_t& next_index, FlexLine* line) {
Vector<FlexItem>& line_items, line->Reset();
LayoutUnit& sum_flex_base_size,
double& total_flex_grow,
double& total_flex_shrink,
double& total_weighted_flex_shrink,
LayoutUnit& sum_hypothetical_main_size) {
line_items.clear();
sum_flex_base_size = LayoutUnit();
total_flex_grow = total_flex_shrink = total_weighted_flex_shrink = 0;
sum_hypothetical_main_size = LayoutUnit();
bool line_has_in_flow_item = false; bool line_has_in_flow_item = false;
for (; next_index < all_items_.size(); ++next_index) { for (; *next_index < all_items_.size(); ++*next_index) {
const FlexItem& flex_item = all_items_[next_index]; const FlexItem& flex_item = all_items_[*next_index];
DCHECK(!flex_item.box->IsOutOfFlowPositioned()); DCHECK(!flex_item.box->IsOutOfFlowPositioned());
if (IsMultiline() && if (IsMultiline() &&
sum_hypothetical_main_size + 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_items.push_back(flex_item); line->line_items.push_back(flex_item);
line_has_in_flow_item = true; line_has_in_flow_item = true;
sum_flex_base_size += flex_item.FlexBaseMarginBoxSize(); line->sum_flex_base_size += flex_item.FlexBaseMarginBoxSize();
total_flex_grow += flex_item.box->Style()->FlexGrow(); line->total_flex_grow += flex_item.box->Style()->FlexGrow();
total_flex_shrink += flex_item.box->Style()->FlexShrink(); line->total_flex_shrink += flex_item.box->Style()->FlexShrink();
total_weighted_flex_shrink += 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;
sum_hypothetical_main_size += flex_item.HypotheticalMainAxisMarginBoxSize(); line->sum_hypothetical_main_size +=
flex_item.HypotheticalMainAxisMarginBoxSize();
} }
DCHECK(line_items.size() > 0 || next_index == all_items_.size()); DCHECK(line->line_items.size() > 0 || *next_index == all_items_.size());
return line_items.size() > 0; return line->line_items.size() > 0;
} }
} // namespace blink } // namespace blink
...@@ -74,6 +74,32 @@ class FlexItem { ...@@ -74,6 +74,32 @@ class FlexItem {
bool frozen; bool frozen;
}; };
struct FlexLine {
void Reset() {
line_items.clear();
sum_flex_base_size = LayoutUnit();
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.
Vector<FlexItem> line_items;
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
LayoutUnit sum_hypothetical_main_size;
// These get filled in by LayoutAndPlaceChildren (for now)
// TODO(cbiesinger): Move that to FlexibleBoxAlgorithm.
LayoutUnit cross_axis_offset;
LayoutUnit cross_axis_extent;
LayoutUnit max_ascent;
};
class FlexLayoutAlgorithm { class FlexLayoutAlgorithm {
WTF_MAKE_NONCOPYABLE(FlexLayoutAlgorithm); WTF_MAKE_NONCOPYABLE(FlexLayoutAlgorithm);
...@@ -82,15 +108,7 @@ class FlexLayoutAlgorithm { ...@@ -82,15 +108,7 @@ class FlexLayoutAlgorithm {
LayoutUnit line_break_length, LayoutUnit line_break_length,
const Vector<FlexItem>& all_items); const Vector<FlexItem>& all_items);
// The hypothetical main size of an item is the flex base size clamped bool ComputeNextFlexLine(size_t* next_index, FlexLine*);
// according to its min and max main size properties
bool ComputeNextFlexLine(size_t& next_index,
Vector<FlexItem>& line_items,
LayoutUnit& sum_flex_base_size,
double& total_flex_grow,
double& total_flex_shrink,
double& total_weighted_flex_shrink,
LayoutUnit& sum_hypothetical_main_size);
private: private:
bool IsMultiline() const { return style_->FlexWrap() != EFlexWrap::kNowrap; } bool IsMultiline() const { return style_->FlexWrap() != EFlexWrap::kNowrap; }
......
...@@ -38,6 +38,7 @@ ...@@ -38,6 +38,7 @@
namespace blink { namespace blink {
class FlexItem; class FlexItem;
struct FlexLine;
class CORE_EXPORT LayoutFlexibleBox : public LayoutBlock { class CORE_EXPORT LayoutFlexibleBox : public LayoutBlock {
public: public:
...@@ -114,8 +115,6 @@ class CORE_EXPORT LayoutFlexibleBox : public LayoutBlock { ...@@ -114,8 +115,6 @@ class CORE_EXPORT LayoutFlexibleBox : public LayoutBlock {
enum class SizeDefiniteness { kDefinite, kIndefinite, kUnknown }; enum class SizeDefiniteness { kDefinite, kIndefinite, kUnknown };
struct LineContext;
bool HasOrthogonalFlow(const LayoutBox& child) const; bool HasOrthogonalFlow(const LayoutBox& child) const;
bool IsColumnFlow() const; bool IsColumnFlow() const;
bool IsLeftToRightFlow() const; bool IsLeftToRightFlow() const;
...@@ -182,7 +181,7 @@ class CORE_EXPORT LayoutFlexibleBox : public LayoutBlock { ...@@ -182,7 +181,7 @@ class CORE_EXPORT LayoutFlexibleBox : public LayoutBlock {
bool HasAutoMarginsInCrossAxis(const LayoutBox& child) const; bool HasAutoMarginsInCrossAxis(const LayoutBox& child) const;
bool UpdateAutoMarginsInCrossAxis(LayoutBox& child, bool UpdateAutoMarginsInCrossAxis(LayoutBox& child,
LayoutUnit available_alignment_space); LayoutUnit available_alignment_space);
void RepositionLogicalHeightDependentFlexItems(Vector<LineContext>&); void RepositionLogicalHeightDependentFlexItems(Vector<FlexLine>&);
LayoutUnit ClientLogicalBottomAfterRepositioning(); LayoutUnit ClientLogicalBottomAfterRepositioning();
LayoutUnit AvailableAlignmentSpaceForChild(LayoutUnit line_cross_axis_extent, LayoutUnit AvailableAlignmentSpaceForChild(LayoutUnit line_cross_axis_extent,
...@@ -199,18 +198,12 @@ class CORE_EXPORT LayoutFlexibleBox : public LayoutBlock { ...@@ -199,18 +198,12 @@ class CORE_EXPORT LayoutFlexibleBox : public LayoutBlock {
FlexItem ConstructFlexItem(LayoutBox& child, ChildLayoutType); FlexItem ConstructFlexItem(LayoutBox& child, ChildLayoutType);
void FreezeInflexibleItems(FlexSign, void FreezeInflexibleItems(FlexSign,
Vector<FlexItem>& children, FlexLine&,
LayoutUnit& remaining_free_space, LayoutUnit& remaining_free_space);
double& total_flex_grow,
double& total_flex_shrink,
double& total_weighted_flex_shrink);
bool ResolveFlexibleLengths(FlexSign, bool ResolveFlexibleLengths(FlexSign,
Vector<FlexItem>&, FlexLine&,
LayoutUnit initial_free_space, LayoutUnit initial_free_space,
LayoutUnit& remaining_free_space, LayoutUnit& remaining_free_space);
double& total_flex_grow,
double& total_flex_shrink,
double& total_weighted_flex_shrink);
void FreezeViolations(Vector<FlexItem*>&, void FreezeViolations(Vector<FlexItem*>&,
LayoutUnit& available_free_space, LayoutUnit& available_free_space,
double& total_flex_grow, double& total_flex_grow,
...@@ -222,20 +215,19 @@ class CORE_EXPORT LayoutFlexibleBox : public LayoutBlock { ...@@ -222,20 +215,19 @@ 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,
Vector<FlexItem>&, FlexLine&,
LayoutUnit available_free_space, LayoutUnit available_free_space,
bool relayout_children, bool relayout_children,
SubtreeLayoutScope&, SubtreeLayoutScope&);
Vector<LineContext>&);
void LayoutColumnReverse(const Vector<FlexItem>&, void LayoutColumnReverse(const Vector<FlexItem>&,
LayoutUnit cross_axis_offset, LayoutUnit cross_axis_offset,
LayoutUnit available_free_space); LayoutUnit available_free_space);
void AlignFlexLines(Vector<LineContext>&); void AlignFlexLines(Vector<FlexLine>&);
void AlignChildren(const Vector<LineContext>&); void AlignChildren(const Vector<FlexLine>&);
void ApplyStretchAlignmentToChild(LayoutBox& child, void ApplyStretchAlignmentToChild(LayoutBox& child,
LayoutUnit line_cross_axis_extent); LayoutUnit line_cross_axis_extent);
void FlipForRightToLeftColumn(const Vector<LineContext>& line_contexts); void FlipForRightToLeftColumn(const Vector<FlexLine>& line_contexts);
void FlipForWrapReverse(const Vector<LineContext>&, void FlipForWrapReverse(const Vector<FlexLine>&,
LayoutUnit cross_axis_start_edge); LayoutUnit cross_axis_start_edge);
float CountIntrinsicSizeForAlgorithmChange( float CountIntrinsicSizeForAlgorithmChange(
......
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