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,
line_break_length_(line_break_length),
all_items_(all_items) {}
bool FlexLayoutAlgorithm::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) {
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 FlexLayoutAlgorithm::ComputeNextFlexLine(size_t* next_index,
FlexLine* line) {
line->Reset();
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_index < all_items_.size(); ++*next_index) {
const FlexItem& flex_item = all_items_[*next_index];
DCHECK(!flex_item.box->IsOutOfFlowPositioned());
if (IsMultiline() &&
sum_hypothetical_main_size +
line->sum_hypothetical_main_size +
flex_item.HypotheticalMainAxisMarginBoxSize() >
line_break_length_ &&
line_has_in_flow_item)
break;
line_items.push_back(flex_item);
line->line_items.push_back(flex_item);
line_has_in_flow_item = true;
sum_flex_base_size += flex_item.FlexBaseMarginBoxSize();
total_flex_grow += flex_item.box->Style()->FlexGrow();
total_flex_shrink += flex_item.box->Style()->FlexShrink();
total_weighted_flex_shrink +=
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 +=
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());
return line_items.size() > 0;
DCHECK(line->line_items.size() > 0 || *next_index == all_items_.size());
return line->line_items.size() > 0;
}
} // namespace blink
......@@ -74,6 +74,32 @@ class FlexItem {
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 {
WTF_MAKE_NONCOPYABLE(FlexLayoutAlgorithm);
......@@ -82,15 +108,7 @@ class FlexLayoutAlgorithm {
LayoutUnit line_break_length,
const Vector<FlexItem>& all_items);
// The hypothetical main size of an item is the flex base size clamped
// 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);
bool ComputeNextFlexLine(size_t* next_index, FlexLine*);
private:
bool IsMultiline() const { return style_->FlexWrap() != EFlexWrap::kNowrap; }
......
......@@ -38,6 +38,7 @@
namespace blink {
class FlexItem;
struct FlexLine;
class CORE_EXPORT LayoutFlexibleBox : public LayoutBlock {
public:
......@@ -114,8 +115,6 @@ class CORE_EXPORT LayoutFlexibleBox : public LayoutBlock {
enum class SizeDefiniteness { kDefinite, kIndefinite, kUnknown };
struct LineContext;
bool HasOrthogonalFlow(const LayoutBox& child) const;
bool IsColumnFlow() const;
bool IsLeftToRightFlow() const;
......@@ -182,7 +181,7 @@ class CORE_EXPORT LayoutFlexibleBox : public LayoutBlock {
bool HasAutoMarginsInCrossAxis(const LayoutBox& child) const;
bool UpdateAutoMarginsInCrossAxis(LayoutBox& child,
LayoutUnit available_alignment_space);
void RepositionLogicalHeightDependentFlexItems(Vector<LineContext>&);
void RepositionLogicalHeightDependentFlexItems(Vector<FlexLine>&);
LayoutUnit ClientLogicalBottomAfterRepositioning();
LayoutUnit AvailableAlignmentSpaceForChild(LayoutUnit line_cross_axis_extent,
......@@ -199,18 +198,12 @@ class CORE_EXPORT LayoutFlexibleBox : public LayoutBlock {
FlexItem ConstructFlexItem(LayoutBox& child, ChildLayoutType);
void FreezeInflexibleItems(FlexSign,
Vector<FlexItem>& children,
LayoutUnit& remaining_free_space,
double& total_flex_grow,
double& total_flex_shrink,
double& total_weighted_flex_shrink);
FlexLine&,
LayoutUnit& remaining_free_space);
bool ResolveFlexibleLengths(FlexSign,
Vector<FlexItem>&,
FlexLine&,
LayoutUnit initial_free_space,
LayoutUnit& remaining_free_space,
double& total_flex_grow,
double& total_flex_shrink,
double& total_weighted_flex_shrink);
LayoutUnit& remaining_free_space);
void FreezeViolations(Vector<FlexItem*>&,
LayoutUnit& available_free_space,
double& total_flex_grow,
......@@ -222,20 +215,19 @@ class CORE_EXPORT LayoutFlexibleBox : public LayoutBlock {
LayoutUnit child_preferred_size);
void PrepareChildForPositionedLayout(LayoutBox& child);
void LayoutAndPlaceChildren(LayoutUnit& cross_axis_offset,
Vector<FlexItem>&,
FlexLine&,
LayoutUnit available_free_space,
bool relayout_children,
SubtreeLayoutScope&,
Vector<LineContext>&);
SubtreeLayoutScope&);
void LayoutColumnReverse(const Vector<FlexItem>&,
LayoutUnit cross_axis_offset,
LayoutUnit available_free_space);
void AlignFlexLines(Vector<LineContext>&);
void AlignChildren(const Vector<LineContext>&);
void AlignFlexLines(Vector<FlexLine>&);
void AlignChildren(const Vector<FlexLine>&);
void ApplyStretchAlignmentToChild(LayoutBox& child,
LayoutUnit line_cross_axis_extent);
void FlipForRightToLeftColumn(const Vector<LineContext>& line_contexts);
void FlipForWrapReverse(const Vector<LineContext>&,
void FlipForRightToLeftColumn(const Vector<FlexLine>& line_contexts);
void FlipForWrapReverse(const Vector<FlexLine>&,
LayoutUnit cross_axis_start_edge);
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