Commit e0553dee authored by Kurt Catti-Schmidt's avatar Kurt Catti-Schmidt Committed by Commit Bot

[GridNG] Build up NGGridBlockTrackCollection in NGGridLayoutAlgorithm

This change adds grid track collections to the NGGridLayoutAlgorithm,
builds them and tests them, but does not use them.


I also changed all usage of NGGridTrackRepeater::RepeatType to the
previously existing enum AutoRepeatType.

Bug: 1045599
Change-Id: I48b77823f4368138d5c361ad7f3ec0162fd25186
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2258901
Commit-Queue: Kurt Catti-Schmidt <kschmi@microsoft.com>
Reviewed-by: default avatarChristian Biesinger <cbiesinger@chromium.org>
Reviewed-by: default avatarIan Kilpatrick <ikilpatrick@chromium.org>
Reviewed-by: default avatarEthan Jimenez <ethavar@microsoft.com>
Reviewed-by: default avatarKurt Catti-Schmidt <kschmi@microsoft.com>
Cr-Commit-Position: refs/heads/master@{#784870}
parent cd1c9f43
...@@ -26,7 +26,10 @@ NGGridLayoutAlgorithm::NGGridLayoutAlgorithm( ...@@ -26,7 +26,10 @@ NGGridLayoutAlgorithm::NGGridLayoutAlgorithm(
scoped_refptr<const NGLayoutResult> NGGridLayoutAlgorithm::Layout() { scoped_refptr<const NGLayoutResult> NGGridLayoutAlgorithm::Layout() {
switch (state_) { switch (state_) {
case GridLayoutAlgorithmState::kMeasuringItems: case GridLayoutAlgorithmState::kMeasuringItems:
BuildTrackLists();
ConstructAndAppendGridItems(); ConstructAndAppendGridItems();
row_track_collection_.FinalizeRanges();
column_track_collection_.FinalizeRanges();
break; break;
default: default:
...@@ -41,11 +44,22 @@ MinMaxSizesResult NGGridLayoutAlgorithm::ComputeMinMaxSizes( ...@@ -41,11 +44,22 @@ MinMaxSizesResult NGGridLayoutAlgorithm::ComputeMinMaxSizes(
return {MinMaxSizes(), /* depends_on_percentage_block_size */ true}; return {MinMaxSizes(), /* depends_on_percentage_block_size */ true};
} }
const NGGridBlockTrackCollection& NGGridLayoutAlgorithm::ColumnTrackCollection()
const {
return column_track_collection_;
}
const NGGridBlockTrackCollection& NGGridLayoutAlgorithm::RowTrackCollection()
const {
return row_track_collection_;
}
void NGGridLayoutAlgorithm::ConstructAndAppendGridItems() { void NGGridLayoutAlgorithm::ConstructAndAppendGridItems() {
NGGridChildIterator iterator(Node()); NGGridChildIterator iterator(Node());
for (NGBlockNode child = iterator.NextChild(); child; for (NGBlockNode child = iterator.NextChild(); child;
child = iterator.NextChild()) { child = iterator.NextChild()) {
ConstructAndAppendGridItem(child); ConstructAndAppendGridItem(child);
EnsureTrackCoverageForGridItem(child);
} }
} }
...@@ -66,11 +80,120 @@ NGConstraintSpace NGGridLayoutAlgorithm::BuildSpaceForMeasure( ...@@ -66,11 +80,120 @@ NGConstraintSpace NGGridLayoutAlgorithm::BuildSpaceForMeasure(
space_builder.SetCacheSlot(NGCacheSlot::kMeasure); space_builder.SetCacheSlot(NGCacheSlot::kMeasure);
space_builder.SetIsPaintedAtomically(true); space_builder.SetIsPaintedAtomically(true);
// TODO(kschmi) - do layout/measuring and handle non-fixed sizes here. // TODO(kschmi): - do layout/measuring and handle non-fixed sizes here.
space_builder.SetAvailableSize(ChildAvailableSize()); space_builder.SetAvailableSize(ChildAvailableSize());
space_builder.SetPercentageResolutionSize(child_percentage_size_); space_builder.SetPercentageResolutionSize(child_percentage_size_);
space_builder.SetTextDirection(child_style.Direction()); space_builder.SetTextDirection(child_style.Direction());
return space_builder.ToConstraintSpace(); return space_builder.ToConstraintSpace();
} }
void NGGridLayoutAlgorithm::BuildTrackLists() {
const ComputedStyle& grid_style = Style();
AddRepeaters(grid_style.GridTemplateColumns(),
grid_style.GridAutoRepeatColumns(),
grid_style.GridAutoRepeatColumnsInsertionPoint(),
grid_style.GridAutoRepeatColumnsType(), column_track_list_);
AddRepeaters(grid_style.GridTemplateRows(), grid_style.GridAutoRepeatRows(),
grid_style.GridAutoRepeatRowsInsertionPoint(),
grid_style.GridAutoRepeatRowsType(), row_track_list_);
// TODO(kschmi): Auto track repeat count should be based on the number of
// children, rather than specified auto-column/track.
NGGridTrackList implicit_columns;
NGGridTrackList implicit_rows;
implicit_columns.AddRepeater(
/*track_index*/ 0, /*track_count*/ 1,
/*repeat_count*/ grid_style.GridAutoColumns().size());
implicit_rows.AddRepeater(/*track_index*/ 0, 1 /*track_count*/,
/*repeat_count*/ grid_style.GridAutoRows().size());
// TODO(janewman): We need to implement calculation for track auto repeat
// count so this can be used outside of testing.
column_track_collection_.SetSpecifiedTracks(
column_track_list_, automatic_column_repetitions_for_testing,
implicit_columns);
row_track_collection_.SetSpecifiedTracks(
row_track_list_, automatic_row_repetitions_for_testing, implicit_rows);
}
void NGGridLayoutAlgorithm::EnsureTrackCoverageForGridItem(
const NGBlockNode& grid_item) {
const ComputedStyle& item_style = grid_item.Style();
EnsureTrackCoverageForGridPositions(item_style.GridColumnStart(),
item_style.GridColumnEnd(),
column_track_collection_);
EnsureTrackCoverageForGridPositions(item_style.GridRowStart(),
item_style.GridRowEnd(),
row_track_collection_);
}
void NGGridLayoutAlgorithm::EnsureTrackCoverageForGridPositions(
const GridPosition& start_position,
const GridPosition& end_position,
NGGridBlockTrackCollection& track_collection) {
// For now, we only support adding tracks if they were specified.
// TODO(janewman): Implement support for position types other than Explicit.
if (start_position.GetType() == GridPositionType::kExplicitPosition &&
end_position.GetType() == GridPositionType::kExplicitPosition) {
track_collection.EnsureTrackCoverage(
start_position.IntegerPosition(),
end_position.IntegerPosition() - start_position.IntegerPosition() + 1);
}
}
void NGGridLayoutAlgorithm::AddRepeaters(
const Vector<GridTrackSize>& template_tracks,
const Vector<GridTrackSize>& auto_tracks,
wtf_size_t auto_insertion_point,
AutoRepeatType repeat_type,
NGGridTrackList& track_list) {
wtf_size_t repeat_start = NGGridBlockTrackCollection::kInvalidRangeIndex;
wtf_size_t unique_track_count = 0;
// TODO(janewman): Track lists should live on the computed style, mirroring
// the legacy layout's template_tracks and auto tracks vectors. For now, build
// up the NG version from what already exists on the computed style.
for (wtf_size_t i = 0; i < template_tracks.size(); ++i) {
const GridTrackSize& current_track = template_tracks[i];
// If this is the insertion point for an auto repeater, add it here.
if (!auto_tracks.IsEmpty() && i == auto_insertion_point) {
track_list.AddAutoRepeater(unique_track_count, auto_tracks.size(),
repeat_type);
unique_track_count += auto_tracks.size();
repeat_start = NGGridBlockTrackCollection::kInvalidRangeIndex;
}
// As the legacy implementation expands repeaters out, compress repeated
// tracks. As this work will be removed once this is done in style, this is
// only implemented for the simple case of a single track being repeated,
// e.g. we will compress repeat(20, 100px) down into a single repeater, but
// will not compress repeat(20, 10px 20px) at all.
if (i + 1 < template_tracks.size()) {
const GridTrackSize& next_track = template_tracks[i + 1];
if (current_track == next_track && i + 1 != auto_insertion_point) {
if (repeat_start == NGGridBlockTrackCollection::kInvalidRangeIndex) {
repeat_start = i;
}
continue;
}
}
wtf_size_t repeat_count;
if (repeat_start == NGGridBlockTrackCollection::kInvalidRangeIndex)
repeat_count = 1;
else
repeat_count = i + 1 - repeat_start;
DCHECK_NE(0u, repeat_count);
DCHECK_NE(NGGridBlockTrackCollection::kInvalidRangeIndex, repeat_count);
track_list.AddRepeater(unique_track_count++, /*track_count*/ 1,
repeat_count);
repeat_start = NGGridBlockTrackCollection::kInvalidRangeIndex;
}
}
void NGGridLayoutAlgorithm::SetAutomaticTrackRepetitionsForTesting(
wtf_size_t auto_column,
wtf_size_t auto_row) {
automatic_column_repetitions_for_testing = auto_column;
automatic_row_repetitions_for_testing = auto_row;
}
} // namespace blink } // namespace blink
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#ifndef THIRD_PARTY_BLINK_RENDERER_CORE_LAYOUT_NG_GRID_NG_GRID_LAYOUT_ALGORITHM_H_ #ifndef THIRD_PARTY_BLINK_RENDERER_CORE_LAYOUT_NG_GRID_NG_GRID_LAYOUT_ALGORITHM_H_
#define THIRD_PARTY_BLINK_RENDERER_CORE_LAYOUT_NG_GRID_NG_GRID_LAYOUT_ALGORITHM_H_ #define THIRD_PARTY_BLINK_RENDERER_CORE_LAYOUT_NG_GRID_NG_GRID_LAYOUT_ALGORITHM_H_
#include "third_party/blink/renderer/core/layout/ng/grid/ng_grid_track_collection.h"
#include "third_party/blink/renderer/core/layout/ng/ng_block_break_token.h" #include "third_party/blink/renderer/core/layout/ng/ng_block_break_token.h"
#include "third_party/blink/renderer/core/layout/ng/ng_box_fragment_builder.h" #include "third_party/blink/renderer/core/layout/ng/ng_box_fragment_builder.h"
#include "third_party/blink/renderer/core/layout/ng/ng_constraint_space.h" #include "third_party/blink/renderer/core/layout/ng/ng_constraint_space.h"
...@@ -24,6 +25,9 @@ class CORE_EXPORT NGGridLayoutAlgorithm ...@@ -24,6 +25,9 @@ class CORE_EXPORT NGGridLayoutAlgorithm
MinMaxSizesResult ComputeMinMaxSizes(const MinMaxSizesInput&) const override; MinMaxSizesResult ComputeMinMaxSizes(const MinMaxSizesInput&) const override;
const NGGridBlockTrackCollection& ColumnTrackCollection() const;
const NGGridBlockTrackCollection& RowTrackCollection() const;
private: private:
friend class NGGridLayoutAlgorithmTest; friend class NGGridLayoutAlgorithmTest;
...@@ -31,6 +35,30 @@ class CORE_EXPORT NGGridLayoutAlgorithm ...@@ -31,6 +35,30 @@ class CORE_EXPORT NGGridLayoutAlgorithm
void ConstructAndAppendGridItem(const NGBlockNode& node); void ConstructAndAppendGridItem(const NGBlockNode& node);
NGConstraintSpace BuildSpaceForMeasure(const NGBlockNode& grid_item); NGConstraintSpace BuildSpaceForMeasure(const NGBlockNode& grid_item);
// Sets the specified tracks for row and column track lists.
void BuildTrackLists();
// Ensures a range boundary will exist on the start and end of the grid item.
void EnsureTrackCoverageForGridItem(const NGBlockNode& grid_item);
// Helper for EnsureTrackCoverageForGridItem.
static void EnsureTrackCoverageForGridPositions(
const GridPosition& start_position,
const GridPosition& end_position,
NGGridBlockTrackCollection& track_list);
// Allows a test to set the value for automatic track repetition.
void SetAutomaticTrackRepetitionsForTesting(wtf_size_t auto_column,
wtf_size_t auto_row);
// TODO(janewman): Track lists should live on the computed style, mirroring
// the legacy layout's template_tracks and auto tracks vectors. For now, this
// method builds a NGGridTrackList from the legacy types that are already
// computed in style.
static void AddRepeaters(const Vector<GridTrackSize>& template_tracks,
const Vector<GridTrackSize>& auto_tracks,
wtf_size_t auto_insertion_point,
AutoRepeatType repeat_type,
NGGridTrackList& track_list);
enum class GridLayoutAlgorithmState { enum class GridLayoutAlgorithmState {
kMeasuringItems, kMeasuringItems,
}; };
...@@ -39,6 +67,16 @@ class CORE_EXPORT NGGridLayoutAlgorithm ...@@ -39,6 +67,16 @@ class CORE_EXPORT NGGridLayoutAlgorithm
struct GridItem { struct GridItem {
NGConstraintSpace constraint_space; NGConstraintSpace constraint_space;
}; };
NGGridTrackList column_track_list_;
NGGridTrackList row_track_list_;
NGGridBlockTrackCollection column_track_collection_;
NGGridBlockTrackCollection row_track_collection_;
wtf_size_t automatic_column_repetitions_for_testing =
NGGridBlockTrackCollection::kInvalidRangeIndex;
wtf_size_t automatic_row_repetitions_for_testing =
NGGridBlockTrackCollection::kInvalidRangeIndex;
Vector<GridItem> items_; Vector<GridItem> items_;
LogicalSize child_percentage_size_; LogicalSize child_percentage_size_;
......
...@@ -37,6 +37,12 @@ class NGGridLayoutAlgorithmTest ...@@ -37,6 +37,12 @@ class NGGridLayoutAlgorithmTest
return constraint_spaces; return constraint_spaces;
} }
void SetAutoTrackRepeat(NGGridLayoutAlgorithm& algorithm,
wtf_size_t auto_column,
wtf_size_t auto_row) {
algorithm.SetAutomaticTrackRepetitionsForTesting(auto_column, auto_row);
}
scoped_refptr<ComputedStyle> style_; scoped_refptr<ComputedStyle> style_;
}; };
...@@ -91,6 +97,7 @@ TEST_F(NGGridLayoutAlgorithmTest, NGGridLayoutAlgorithmMeasuring) { ...@@ -91,6 +97,7 @@ TEST_F(NGGridLayoutAlgorithmTest, NGGridLayoutAlgorithmMeasuring) {
NGGridLayoutAlgorithm algorithm({node, fragment_geometry, space}); NGGridLayoutAlgorithm algorithm({node, fragment_geometry, space});
EXPECT_EQ(GridItemSize(algorithm), 0U); EXPECT_EQ(GridItemSize(algorithm), 0U);
SetAutoTrackRepeat(algorithm, 5, 5);
algorithm.Layout(); algorithm.Layout();
EXPECT_EQ(GridItemSize(algorithm), 4U); EXPECT_EQ(GridItemSize(algorithm), 4U);
...@@ -103,4 +110,215 @@ TEST_F(NGGridLayoutAlgorithmTest, NGGridLayoutAlgorithmMeasuring) { ...@@ -103,4 +110,215 @@ TEST_F(NGGridLayoutAlgorithmTest, NGGridLayoutAlgorithmMeasuring) {
} }
} }
TEST_F(NGGridLayoutAlgorithmTest, NGGridLayoutAlgorithmRanges) {
if (!RuntimeEnabledFeatures::LayoutNGGridEnabled())
return;
SetBodyInnerHTML(R"HTML(
<style>
#grid1 {
display: grid;
grid-template-columns: repeat(2, 100px 100px 200px 200px);
grid-template-rows: repeat(20, 100px);
}
</style>
<div id="grid1">
<div id="cell1">Cell 1</div>
<div id="cell2">Cell 2</div>
<div id="cell3">Cell 3</div>
<div id="cell4">Cell 4</div>
</div>
)HTML");
NGBlockNode node(ToLayoutBox(GetLayoutObjectByElementId("grid1")));
NGConstraintSpace space = ConstructBlockLayoutTestConstraintSpace(
WritingMode::kHorizontalTb, TextDirection::kLtr,
LogicalSize(LayoutUnit(100), LayoutUnit(100)), false, true);
NGFragmentGeometry fragment_geometry =
CalculateInitialFragmentGeometry(space, node);
NGGridLayoutAlgorithm algorithm({node, fragment_geometry, space});
EXPECT_EQ(GridItemSize(algorithm), 0U);
SetAutoTrackRepeat(algorithm, 5, 5);
algorithm.Layout();
EXPECT_EQ(GridItemSize(algorithm), 4U);
NGGridTrackCollectionBase::RangeRepeatIterator row_iterator(
&algorithm.RowTrackCollection(), 0u);
EXPECT_EQ(1u, row_iterator.RangeTrackStart());
EXPECT_EQ(20u, row_iterator.RangeTrackEnd());
EXPECT_EQ(20u, row_iterator.RepeatCount());
EXPECT_FALSE(row_iterator.MoveToNextRange());
NGGridTrackCollectionBase::RangeRepeatIterator column_iterator(
&algorithm.ColumnTrackCollection(), 0u);
EXPECT_EQ(1u, column_iterator.RangeTrackStart());
EXPECT_EQ(2u, column_iterator.RangeTrackEnd());
EXPECT_EQ(2u, column_iterator.RepeatCount());
EXPECT_TRUE(column_iterator.MoveToNextRange());
EXPECT_EQ(3u, column_iterator.RangeTrackStart());
EXPECT_EQ(4u, column_iterator.RangeTrackEnd());
EXPECT_EQ(2u, column_iterator.RepeatCount());
EXPECT_TRUE(column_iterator.MoveToNextRange());
EXPECT_EQ(5u, column_iterator.RangeTrackStart());
EXPECT_EQ(6u, column_iterator.RangeTrackEnd());
EXPECT_EQ(2u, column_iterator.RepeatCount());
EXPECT_TRUE(column_iterator.MoveToNextRange());
EXPECT_EQ(7u, column_iterator.RangeTrackStart());
EXPECT_EQ(8u, column_iterator.RangeTrackEnd());
EXPECT_EQ(2u, column_iterator.RepeatCount());
EXPECT_FALSE(column_iterator.MoveToNextRange());
}
TEST_F(NGGridLayoutAlgorithmTest, NGGridLayoutAlgorithmRangesWithAutoRepeater) {
if (!RuntimeEnabledFeatures::LayoutNGGridEnabled())
return;
SetBodyInnerHTML(R"HTML(
<style>
#grid1 {
display: grid;
grid-template-columns: 5px repeat(auto-fit, 150px) repeat(3, 10px);
grid-template-rows: repeat(20, 100px);
}
</style>
<div id="grid1">
<div id="cell1">Cell 1</div>
<div id="cell2">Cell 2</div>
<div id="cell3">Cell 3</div>
<div id="cell4">Cell 4</div>
</div>
)HTML");
NGBlockNode node(ToLayoutBox(GetLayoutObjectByElementId("grid1")));
NGConstraintSpace space = ConstructBlockLayoutTestConstraintSpace(
WritingMode::kHorizontalTb, TextDirection::kLtr,
LogicalSize(LayoutUnit(100), LayoutUnit(100)), false, true);
NGFragmentGeometry fragment_geometry =
CalculateInitialFragmentGeometry(space, node);
NGGridLayoutAlgorithm algorithm({node, fragment_geometry, space});
EXPECT_EQ(GridItemSize(algorithm), 0U);
SetAutoTrackRepeat(algorithm, 5, 5);
algorithm.Layout();
EXPECT_EQ(GridItemSize(algorithm), 4U);
NGGridTrackCollectionBase::RangeRepeatIterator row_iterator(
&algorithm.RowTrackCollection(), 0u);
EXPECT_EQ(1u, row_iterator.RangeTrackStart());
EXPECT_EQ(20u, row_iterator.RangeTrackEnd());
EXPECT_EQ(20u, row_iterator.RepeatCount());
EXPECT_FALSE(row_iterator.MoveToNextRange());
NGGridTrackCollectionBase::RangeRepeatIterator column_iterator(
&algorithm.ColumnTrackCollection(), 0u);
EXPECT_EQ(1u, column_iterator.RangeTrackStart());
EXPECT_EQ(1u, column_iterator.RangeTrackEnd());
EXPECT_EQ(1u, column_iterator.RepeatCount());
EXPECT_FALSE(column_iterator.IsRangeCollapsed());
EXPECT_TRUE(column_iterator.MoveToNextRange());
EXPECT_EQ(2u, column_iterator.RangeTrackStart());
EXPECT_EQ(6u, column_iterator.RangeTrackEnd());
EXPECT_EQ(5u, column_iterator.RepeatCount());
EXPECT_TRUE(column_iterator.IsRangeCollapsed());
EXPECT_TRUE(column_iterator.MoveToNextRange());
EXPECT_EQ(7u, column_iterator.RangeTrackStart());
EXPECT_EQ(9u, column_iterator.RangeTrackEnd());
EXPECT_EQ(3u, column_iterator.RepeatCount());
EXPECT_FALSE(column_iterator.IsRangeCollapsed());
EXPECT_FALSE(column_iterator.MoveToNextRange());
}
TEST_F(NGGridLayoutAlgorithmTest, NGGridLayoutAlgorithmRangesImplicit) {
if (!RuntimeEnabledFeatures::LayoutNGGridEnabled())
return;
SetBodyInnerHTML(R"HTML(
<style>
#grid1 {
display: grid;
}
#cell1 {
grid-column: 1 / 1;
grid-row: 1 / 1;
width: 50px;
}
#cell2 {
grid-column: 2 / 2;
grid-row: 1 / 1;
width: 50px;
}
#cell3 {
grid-column: 1 / 1;
grid-row: 2 / 2;
width: 50px;
}
#cell4 {
grid-column: 2 / 5;
grid-row: 2 / 2;
width: 50px;
}
</style>
<div id="grid1">
<div id="cell1">Cell 1</div>
<div id="cell2">Cell 2</div>
<div id="cell3">Cell 3</div>
<div id="cell4">Cell 4</div>
</div>
)HTML");
NGBlockNode node(ToLayoutBox(GetLayoutObjectByElementId("grid1")));
NGConstraintSpace space = ConstructBlockLayoutTestConstraintSpace(
WritingMode::kHorizontalTb, TextDirection::kLtr,
LogicalSize(LayoutUnit(100), LayoutUnit(100)), false, true);
NGFragmentGeometry fragment_geometry =
CalculateInitialFragmentGeometry(space, node);
NGGridLayoutAlgorithm algorithm({node, fragment_geometry, space});
EXPECT_EQ(GridItemSize(algorithm), 0U);
SetAutoTrackRepeat(algorithm, 5, 5);
algorithm.Layout();
EXPECT_EQ(GridItemSize(algorithm), 4U);
NGGridTrackCollectionBase::RangeRepeatIterator column_iterator(
&algorithm.ColumnTrackCollection(), 0u);
EXPECT_EQ(1u, column_iterator.RangeTrackStart());
EXPECT_EQ(1u, column_iterator.RangeTrackEnd());
EXPECT_EQ(1u, column_iterator.RepeatCount());
EXPECT_TRUE(column_iterator.MoveToNextRange());
EXPECT_EQ(2u, column_iterator.RangeTrackStart());
EXPECT_EQ(2u, column_iterator.RangeTrackEnd());
EXPECT_EQ(1u, column_iterator.RepeatCount());
EXPECT_TRUE(column_iterator.MoveToNextRange());
EXPECT_EQ(3u, column_iterator.RangeTrackStart());
EXPECT_EQ(5u, column_iterator.RangeTrackEnd());
EXPECT_EQ(3u, column_iterator.RepeatCount());
EXPECT_FALSE(column_iterator.MoveToNextRange());
NGGridTrackCollectionBase::RangeRepeatIterator row_iterator(
&algorithm.RowTrackCollection(), 0u);
EXPECT_EQ(1u, row_iterator.RangeTrackStart());
EXPECT_EQ(1u, row_iterator.RangeTrackEnd());
EXPECT_EQ(1u, row_iterator.RepeatCount());
EXPECT_TRUE(row_iterator.MoveToNextRange());
EXPECT_EQ(2u, row_iterator.RangeTrackStart());
EXPECT_EQ(2u, row_iterator.RangeTrackEnd());
EXPECT_EQ(1u, row_iterator.RepeatCount());
EXPECT_FALSE(row_iterator.MoveToNextRange());
}
} // namespace blink } // namespace blink
...@@ -125,7 +125,7 @@ bool NGGridTrackCollectionBase::RangeRepeatIterator::SetRangeIndex( ...@@ -125,7 +125,7 @@ bool NGGridTrackCollectionBase::RangeRepeatIterator::SetRangeIndex(
NGGridTrackRepeater::NGGridTrackRepeater(wtf_size_t track_index, NGGridTrackRepeater::NGGridTrackRepeater(wtf_size_t track_index,
wtf_size_t repeat_size, wtf_size_t repeat_size,
wtf_size_t repeat_count, wtf_size_t repeat_count,
RepeatType repeat_type) AutoRepeatType repeat_type)
: track_index(track_index), : track_index(track_index),
repeat_size(repeat_size), repeat_size(repeat_size),
repeat_count(repeat_count), repeat_count(repeat_count),
...@@ -139,14 +139,14 @@ String NGGridTrackRepeater::ToString() const { ...@@ -139,14 +139,14 @@ String NGGridTrackRepeater::ToString() const {
builder.AppendNumber<wtf_size_t>(repeat_size); builder.AppendNumber<wtf_size_t>(repeat_size);
builder.Append("], [RepeatCount: "); builder.Append("], [RepeatCount: ");
switch (repeat_type) { switch (repeat_type) {
case RepeatType::kCount: case AutoRepeatType::kNoAutoRepeat:
builder.AppendNumber<wtf_size_t>(repeat_count); builder.AppendNumber<wtf_size_t>(repeat_count);
builder.Append("]"); builder.Append("]");
break; break;
case RepeatType::kAutoFill: case AutoRepeatType::kAutoFill:
builder.Append("auto-fill]"); builder.Append("auto-fill]");
break; break;
case RepeatType::kAutoFit: case AutoRepeatType::kAutoFit:
builder.Append("auto-fit]"); builder.Append("auto-fit]");
break; break;
} }
...@@ -171,8 +171,7 @@ wtf_size_t NGGridTrackList::RepeatSize(wtf_size_t index) const { ...@@ -171,8 +171,7 @@ wtf_size_t NGGridTrackList::RepeatSize(wtf_size_t index) const {
return repeaters_[index].repeat_size; return repeaters_[index].repeat_size;
} }
NGGridTrackRepeater::RepeatType NGGridTrackList::RepeatType( AutoRepeatType NGGridTrackList::RepeatType(wtf_size_t index) const {
wtf_size_t index) const {
DCHECK_LT(index, RepeaterCount()); DCHECK_LT(index, RepeaterCount());
return repeaters_[index].repeat_type; return repeaters_[index].repeat_type;
} }
...@@ -189,20 +188,19 @@ bool NGGridTrackList::AddRepeater(wtf_size_t track_index, ...@@ -189,20 +188,19 @@ bool NGGridTrackList::AddRepeater(wtf_size_t track_index,
wtf_size_t track_count, wtf_size_t track_count,
wtf_size_t repeat_count) { wtf_size_t repeat_count) {
return AddRepeater(track_index, track_count, repeat_count, return AddRepeater(track_index, track_count, repeat_count,
NGGridTrackRepeater::RepeatType::kCount); AutoRepeatType::kNoAutoRepeat);
} }
bool NGGridTrackList::AddAutoRepeater( bool NGGridTrackList::AddAutoRepeater(wtf_size_t track_index,
wtf_size_t track_index, wtf_size_t track_count,
wtf_size_t track_count, AutoRepeatType repeat_type) {
NGGridTrackRepeater::RepeatType repeat_type) {
return AddRepeater(track_index, track_count, 1u, repeat_type); return AddRepeater(track_index, track_count, 1u, repeat_type);
} }
bool NGGridTrackList::AddRepeater(wtf_size_t track_index, bool NGGridTrackList::AddRepeater(wtf_size_t track_index,
wtf_size_t track_count, wtf_size_t track_count,
wtf_size_t repeat_count, wtf_size_t repeat_count,
NGGridTrackRepeater::RepeatType repeat_type) { AutoRepeatType repeat_type) {
// Ensure valid track index. // Ensure valid track index.
DCHECK_NE(NGGridTrackCollectionBase::kInvalidRangeIndex, track_index); DCHECK_NE(NGGridTrackCollectionBase::kInvalidRangeIndex, track_index);
...@@ -212,19 +210,18 @@ bool NGGridTrackList::AddRepeater(wtf_size_t track_index, ...@@ -212,19 +210,18 @@ bool NGGridTrackList::AddRepeater(wtf_size_t track_index,
#endif #endif
// If the repeater is auto, the repeat_count should be 1. // If the repeater is auto, the repeat_count should be 1.
DCHECK(repeat_type == NGGridTrackRepeater::RepeatType::kCount || DCHECK(repeat_type == AutoRepeatType::kNoAutoRepeat || repeat_count == 1u);
repeat_count == 1u);
// Ensure adding tracks will not overflow the total in this track list and // Ensure adding tracks will not overflow the total in this track list and
// that there is only one auto repeater per track list. // that there is only one auto repeater per track list.
switch (repeat_type) { switch (repeat_type) {
case NGGridTrackRepeater::RepeatType::kCount: case AutoRepeatType::kNoAutoRepeat:
if (track_count > AvailableTrackCount() / repeat_count) if (track_count > AvailableTrackCount() / repeat_count)
return false; return false;
total_track_count_ += track_count * repeat_count; total_track_count_ += track_count * repeat_count;
break; break;
case NGGridTrackRepeater::RepeatType::kAutoFill: case AutoRepeatType::kAutoFill:
case NGGridTrackRepeater::RepeatType::kAutoFit: // Intentional Fallthrough. case AutoRepeatType::kAutoFit: // Intentional Fallthrough.
if (HasAutoRepeater() || track_count > AvailableTrackCount()) if (HasAutoRepeater() || track_count > AvailableTrackCount())
return false; return false;
total_track_count_ += track_count; total_track_count_ += track_count;
...@@ -273,6 +270,7 @@ void NGGridBlockTrackCollection::SetSpecifiedTracks( ...@@ -273,6 +270,7 @@ void NGGridBlockTrackCollection::SetSpecifiedTracks(
const NGGridTrackList& implicit_tracks) { const NGGridTrackList& implicit_tracks) {
// The implicit track list should have only one repeater, if any. // The implicit track list should have only one repeater, if any.
DCHECK_LE(implicit_tracks.RepeaterCount(), 1u); DCHECK_LE(implicit_tracks.RepeaterCount(), 1u);
DCHECK_NE(NGGridTrackCollectionBase::kInvalidRangeIndex, auto_repeat_count);
specified_tracks_ = specified_tracks; specified_tracks_ = specified_tracks;
implicit_tracks_ = implicit_tracks; implicit_tracks_ = implicit_tracks;
auto_repeat_count_ = auto_repeat_count; auto_repeat_count_ = auto_repeat_count;
...@@ -368,7 +366,7 @@ void NGGridBlockTrackCollection::FinalizeRanges() { ...@@ -368,7 +366,7 @@ void NGGridBlockTrackCollection::FinalizeRanges() {
} }
is_in_auto_fit_range = specified_tracks_.RepeatType(repeater_index) == is_in_auto_fit_range = specified_tracks_.RepeatType(repeater_index) ==
NGGridTrackRepeater::RepeatType::kAutoFit; AutoRepeatType::kAutoFit;
current_repeater_track_count = current_repeater_track_count =
specified_tracks_.RepeatCount(repeater_index, auto_repeat_count_) * specified_tracks_.RepeatCount(repeater_index, auto_repeat_count_) *
specified_tracks_.RepeatSize(repeater_index); specified_tracks_.RepeatSize(repeater_index);
......
...@@ -6,8 +6,8 @@ ...@@ -6,8 +6,8 @@
#define THIRD_PARTY_BLINK_RENDERER_CORE_LAYOUT_NG_GRID_NG_GRID_TRACK_COLLECTION_H_ #define THIRD_PARTY_BLINK_RENDERER_CORE_LAYOUT_NG_GRID_NG_GRID_TRACK_COLLECTION_H_
#include "third_party/blink/renderer/core/core_export.h" #include "third_party/blink/renderer/core/core_export.h"
#include "third_party/blink/renderer/core/style/computed_style.h"
#include "third_party/blink/renderer/platform/wtf/text/wtf_string.h" #include "third_party/blink/renderer/platform/wtf/text/wtf_string.h"
namespace blink { namespace blink {
// NGGridTrackCollectionBase provides an implementation for some shared // NGGridTrackCollectionBase provides an implementation for some shared
...@@ -67,11 +67,10 @@ class CORE_EXPORT NGGridTrackCollectionBase { ...@@ -67,11 +67,10 @@ class CORE_EXPORT NGGridTrackCollectionBase {
// Stores tracks related data by compressing repeated tracks into a single node. // Stores tracks related data by compressing repeated tracks into a single node.
struct NGGridTrackRepeater { struct NGGridTrackRepeater {
enum class RepeatType { kCount, kAutoFill, kAutoFit };
NGGridTrackRepeater(wtf_size_t track_index, NGGridTrackRepeater(wtf_size_t track_index,
wtf_size_t repeat_size, wtf_size_t repeat_size,
wtf_size_t repeat_count, wtf_size_t repeat_count,
RepeatType repeat_type); AutoRepeatType repeat_type);
String ToString() const; String ToString() const;
bool operator==(const NGGridTrackRepeater& rhs) const; bool operator==(const NGGridTrackRepeater& rhs) const;
// Index of the first track being repeated. // Index of the first track being repeated.
...@@ -81,7 +80,7 @@ struct NGGridTrackRepeater { ...@@ -81,7 +80,7 @@ struct NGGridTrackRepeater {
// Amount of times the group of tracks are repeated. // Amount of times the group of tracks are repeated.
wtf_size_t repeat_count; wtf_size_t repeat_count;
// Type of repetition. // Type of repetition.
RepeatType repeat_type; AutoRepeatType repeat_type;
}; };
class CORE_EXPORT NGGridTrackList { class CORE_EXPORT NGGridTrackList {
...@@ -93,7 +92,7 @@ class CORE_EXPORT NGGridTrackList { ...@@ -93,7 +92,7 @@ class CORE_EXPORT NGGridTrackList {
// Returns the number of tracks in the repeater at |index|. // Returns the number of tracks in the repeater at |index|.
wtf_size_t RepeatSize(wtf_size_t index) const; wtf_size_t RepeatSize(wtf_size_t index) const;
// Returns the repeat type of the repeater at |index|. // Returns the repeat type of the repeater at |index|.
NGGridTrackRepeater::RepeatType RepeatType(wtf_size_t index) const; AutoRepeatType RepeatType(wtf_size_t index) const;
// Returns the count of repeaters. // Returns the count of repeaters.
wtf_size_t RepeaterCount() const; wtf_size_t RepeaterCount() const;
// Returns the total count of all the tracks in this list. // Returns the total count of all the tracks in this list.
...@@ -106,7 +105,7 @@ class CORE_EXPORT NGGridTrackList { ...@@ -106,7 +105,7 @@ class CORE_EXPORT NGGridTrackList {
// Adds an auto repeater. // Adds an auto repeater.
bool AddAutoRepeater(wtf_size_t track_index, bool AddAutoRepeater(wtf_size_t track_index,
wtf_size_t track_count, wtf_size_t track_count,
NGGridTrackRepeater::RepeatType repeat_type); AutoRepeatType repeat_type);
// Returns true if this list contains an auto repeater. // Returns true if this list contains an auto repeater.
bool HasAutoRepeater(); bool HasAutoRepeater();
...@@ -119,7 +118,7 @@ class CORE_EXPORT NGGridTrackList { ...@@ -119,7 +118,7 @@ class CORE_EXPORT NGGridTrackList {
bool AddRepeater(wtf_size_t track_index, bool AddRepeater(wtf_size_t track_index,
wtf_size_t track_count, wtf_size_t track_count,
wtf_size_t repeat_count, wtf_size_t repeat_count,
NGGridTrackRepeater::RepeatType repeat_type); AutoRepeatType repeat_type);
// Returns the amount of tracks available before overflow. // Returns the amount of tracks available before overflow.
wtf_size_t AvailableTrackCount() const; wtf_size_t AvailableTrackCount() const;
......
...@@ -127,8 +127,7 @@ TEST_F(NGGridTrackCollectionTest, TestNGGridTrackList) { ...@@ -127,8 +127,7 @@ TEST_F(NGGridTrackCollectionTest, TestNGGridTrackList) {
EXPECT_EQ(2u, track_list.RepeatSize(0)); EXPECT_EQ(2u, track_list.RepeatSize(0));
EXPECT_FALSE(track_list.HasAutoRepeater()); EXPECT_FALSE(track_list.HasAutoRepeater());
EXPECT_TRUE(track_list.AddAutoRepeater( EXPECT_TRUE(track_list.AddAutoRepeater(2, 3, AutoRepeatType::kAutoFill));
2, 3, NGGridTrackRepeater::RepeatType::kAutoFill));
ASSERT_EQ(2u, track_list.RepeaterCount()); ASSERT_EQ(2u, track_list.RepeaterCount());
EXPECT_EQ(11u, track_list.TotalTrackCount()); EXPECT_EQ(11u, track_list.TotalTrackCount());
EXPECT_EQ(77u, track_list.RepeatCount(1, 77)); EXPECT_EQ(77u, track_list.RepeatCount(1, 77));
...@@ -136,8 +135,7 @@ TEST_F(NGGridTrackCollectionTest, TestNGGridTrackList) { ...@@ -136,8 +135,7 @@ TEST_F(NGGridTrackCollectionTest, TestNGGridTrackList) {
EXPECT_TRUE(track_list.HasAutoRepeater()); EXPECT_TRUE(track_list.HasAutoRepeater());
// Can't add more than one auto repeater to a list. // Can't add more than one auto repeater to a list.
EXPECT_FALSE(track_list.AddAutoRepeater( EXPECT_FALSE(track_list.AddAutoRepeater(5, 3, AutoRepeatType::kAutoFill));
5, 3, NGGridTrackRepeater::RepeatType::kAutoFill));
EXPECT_TRUE(track_list.AddRepeater( EXPECT_TRUE(track_list.AddRepeater(
5, NGGridTrackCollectionBase::kMaxRangeIndex - 20, 1)); 5, NGGridTrackCollectionBase::kMaxRangeIndex - 20, 1));
...@@ -163,8 +161,8 @@ TEST_F(NGGridTrackCollectionTest, TestNGGridTrackList) { ...@@ -163,8 +161,8 @@ TEST_F(NGGridTrackCollectionTest, TestNGGridTrackList) {
TEST_F(NGGridTrackCollectionTest, TestNGGridBlockTrackCollection) { TEST_F(NGGridTrackCollectionTest, TestNGGridBlockTrackCollection) {
NGGridTrackList specified_tracks; NGGridTrackList specified_tracks;
ASSERT_TRUE(specified_tracks.AddRepeater(1, 2, 4)); ASSERT_TRUE(specified_tracks.AddRepeater(1, 2, 4));
ASSERT_TRUE(specified_tracks.AddAutoRepeater( ASSERT_TRUE(
3, 3, NGGridTrackRepeater::RepeatType::kAutoFill)); specified_tracks.AddAutoRepeater(3, 3, AutoRepeatType::kAutoFill));
ASSERT_EQ(2u, specified_tracks.RepeaterCount()); ASSERT_EQ(2u, specified_tracks.RepeaterCount());
NGGridBlockTrackCollection block_collection; NGGridBlockTrackCollection block_collection;
block_collection.SetSpecifiedTracks(specified_tracks, 3, NGGridTrackList()); block_collection.SetSpecifiedTracks(specified_tracks, 3, NGGridTrackList());
...@@ -183,8 +181,7 @@ TEST_F(NGGridTrackCollectionTest, TestNGGridBlockTrackCollection) { ...@@ -183,8 +181,7 @@ TEST_F(NGGridTrackCollectionTest, TestNGGridBlockTrackCollection) {
TEST_F(NGGridTrackCollectionTest, TestNGGridBlockTrackCollectionCollapsed) { TEST_F(NGGridTrackCollectionTest, TestNGGridBlockTrackCollectionCollapsed) {
NGGridTrackList specified_tracks; NGGridTrackList specified_tracks;
ASSERT_TRUE(specified_tracks.AddRepeater(1, 2, 4)); ASSERT_TRUE(specified_tracks.AddRepeater(1, 2, 4));
ASSERT_TRUE(specified_tracks.AddAutoRepeater( ASSERT_TRUE(specified_tracks.AddAutoRepeater(3, 3, AutoRepeatType::kAutoFit));
3, 3, NGGridTrackRepeater::RepeatType::kAutoFit));
ASSERT_TRUE(specified_tracks.AddRepeater(6, 3, 7)); ASSERT_TRUE(specified_tracks.AddRepeater(6, 3, 7));
ASSERT_EQ(3u, specified_tracks.RepeaterCount()); ASSERT_EQ(3u, specified_tracks.RepeaterCount());
NGGridBlockTrackCollection block_collection; NGGridBlockTrackCollection block_collection;
......
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