Commit 364fe1c6 authored by Ana SollanoKim's avatar Ana SollanoKim Committed by Chromium LUCI CQ

[GridNG] Refactor item set indices and grid lines for out of flow items

1. Previously, we were storing the set indices of each item directly in
GridItemData. This is not necessary as they can be computed on demand.
`CacheItemSetIndices` was renamed to `ComputeItemSetIndices` and was
changed to return `ItemSetIndices` instead.

2. `ResolveOutOfFlowItemGridLines` was moved to `NGGridPlacement`
addressing a TODO. Now the variables `automatic_repetitions` and
`explicit_start` can be directly obtained from the placement instance.

This change does not add nor remove any functionality.

Bug: 1045599
Change-Id: Ib0d3898f9979788cb4e9f7311ab9ad7a1c03504f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2626356
Commit-Queue: Ana Sollano Kim <ansollan@microsoft.com>
Reviewed-by: default avatarEthan Jimenez <ethavar@microsoft.com>
Reviewed-by: default avatarChristian Biesinger <cbiesinger@chromium.org>
Reviewed-by: default avatarKurt Catti-Schmidt <kschmi@microsoft.com>
Reviewed-by: default avatarIan Kilpatrick <ikilpatrick@chromium.org>
Reviewed-by: default avatarJacques Newman <janewman@microsoft.com>
Cr-Commit-Position: refs/heads/master@{#845846}
parent 4fe1d718
...@@ -40,10 +40,6 @@ scoped_refptr<const NGLayoutResult> NGGridLayoutAlgorithm::Layout() { ...@@ -40,10 +40,6 @@ scoped_refptr<const NGLayoutResult> NGGridLayoutAlgorithm::Layout() {
&grid_items, &algorithm_column_track_collection, &grid_items, &algorithm_column_track_collection,
&algorithm_row_track_collection, &grid_placement); &algorithm_row_track_collection, &grid_placement);
// Cache set indices.
CacheItemSetIndices(algorithm_column_track_collection, &grid_items);
CacheItemSetIndices(algorithm_row_track_collection, &grid_items);
// Create a vector of grid item indices using |NGGridChildIterator| order. // Create a vector of grid item indices using |NGGridChildIterator| order.
Vector<wtf_size_t> reordered_item_indices(grid_items.size()); Vector<wtf_size_t> reordered_item_indices(grid_items.size());
for (wtf_size_t i = 0; i < grid_items.size(); ++i) for (wtf_size_t i = 0; i < grid_items.size(); ++i)
...@@ -65,8 +61,8 @@ scoped_refptr<const NGLayoutResult> NGGridLayoutAlgorithm::Layout() { ...@@ -65,8 +61,8 @@ scoped_refptr<const NGLayoutResult> NGGridLayoutAlgorithm::Layout() {
// Place grid and out of flow items. // Place grid and out of flow items.
LayoutUnit intrinsic_block_size; LayoutUnit intrinsic_block_size;
LayoutUnit block_size; LayoutUnit block_size;
PlaceItems(grid_items, algorithm_column_track_collection, PlaceItems(algorithm_column_track_collection, algorithm_row_track_collection,
algorithm_row_track_collection, &out_of_flow_items, &grid_items, &out_of_flow_items, &grid_placement,
&intrinsic_block_size, &block_size); &intrinsic_block_size, &block_size);
container_builder_.SetIntrinsicBlockSize(intrinsic_block_size); container_builder_.SetIntrinsicBlockSize(intrinsic_block_size);
...@@ -95,9 +91,6 @@ MinMaxSizesResult NGGridLayoutAlgorithm::ComputeMinMaxSizes( ...@@ -95,9 +91,6 @@ MinMaxSizesResult NGGridLayoutAlgorithm::ComputeMinMaxSizes(
&grid_items, &algorithm_column_track_collection, &grid_items, &algorithm_column_track_collection,
&algorithm_row_track_collection, &grid_placement); &algorithm_row_track_collection, &grid_placement);
// Cache set indices.
CacheItemSetIndices(algorithm_column_track_collection, &grid_items);
// Create a vector of grid item indices using |NGGridChildIterator| order. // Create a vector of grid item indices using |NGGridChildIterator| order.
Vector<wtf_size_t> reordered_item_indices(grid_items.size()); Vector<wtf_size_t> reordered_item_indices(grid_items.size());
for (wtf_size_t i = 0; i < grid_items.size(); ++i) for (wtf_size_t i = 0; i < grid_items.size(); ++i)
...@@ -232,6 +225,73 @@ bool NGGridLayoutAlgorithm::GridItemData::IsSpanningIntrinsicTrack( ...@@ -232,6 +225,73 @@ bool NGGridLayoutAlgorithm::GridItemData::IsSpanningIntrinsicTrack(
.HasProperty(TrackSpanProperties::kHasIntrinsicTrack); .HasProperty(TrackSpanProperties::kHasIntrinsicTrack);
} }
NGGridLayoutAlgorithm::ItemSetIndices
NGGridLayoutAlgorithm::GridItemData::SetIndices(
const NGGridLayoutAlgorithmTrackCollection& track_collection,
NGGridPlacement* grid_placement) {
const GridTrackSizingDirection track_direction = track_collection.Direction();
// If the set indices are already computed, we can just return them.
base::Optional<ItemSetIndices>& cached_set_indices =
(track_direction == kForColumns) ? column_set_indices : row_set_indices;
if (cached_set_indices.has_value())
return cached_set_indices.value();
wtf_size_t start_line, end_line;
if (item_type == ItemType::kInGridFlow) {
start_line = StartLine(track_direction);
end_line = EndLine(track_direction);
DCHECK_NE(start_line, kNotFound);
DCHECK_NE(end_line, kNotFound);
} else {
DCHECK(grid_placement);
grid_placement->ResolveOutOfFlowItemGridLines(
track_collection, node.Style(), &start_line, &end_line);
}
// We only calculate the indexes if:
// 1. The item is in flow (it is a grid item) or
// 2. The item is out of flow, but the line was not defined as 'auto' and
// the line is within the bounds of the grid, since an out of flow item
// cannot create grid lines.
// TODO(ansollan): The start line of an out of flow item can be the last
// line of the grid. If that is the case, |set_indices.begin| has to be
// computed as |set_indices.end|. Similarly, if an end line is the first line
// of the grid, |set_indices.end| has to be computed as |set_indices.begin|.
ItemSetIndices set_indices;
set_indices.begin = kNotFound;
set_indices.end = kNotFound;
if (start_line != kNotFound) {
wtf_size_t first_spanned_range =
track_collection.RangeIndexFromTrackNumber(start_line);
set_indices.begin =
track_collection.RangeStartingSetIndex(first_spanned_range);
}
if (end_line != kNotFound) {
wtf_size_t last_spanned_range =
track_collection.RangeIndexFromTrackNumber(end_line - 1);
set_indices.end =
track_collection.RangeStartingSetIndex(last_spanned_range) +
track_collection.RangeSetCount(last_spanned_range);
}
#if DCHECK_IS_ON()
if (set_indices.begin != kNotFound && set_indices.end != kNotFound) {
DCHECK_LE(set_indices.end, track_collection.SetCount());
DCHECK_LT(set_indices.begin, set_indices.end);
} else if (set_indices.begin != kNotFound) {
DCHECK_LT(set_indices.begin, track_collection.SetCount());
} else if (set_indices.end != kNotFound) {
DCHECK_LE(set_indices.end, track_collection.SetCount());
}
#endif
cached_set_indices = set_indices;
return set_indices;
}
NGGridLayoutAlgorithm::ReorderedGridItems::Iterator::Iterator( NGGridLayoutAlgorithm::ReorderedGridItems::Iterator::Iterator(
Vector<wtf_size_t>::const_iterator current_index, Vector<wtf_size_t>::const_iterator current_index,
Vector<GridItemData>* grid_items) Vector<GridItemData>* grid_items)
...@@ -277,17 +337,20 @@ NGGridLayoutAlgorithm::ReorderedGridItems::end() { ...@@ -277,17 +337,20 @@ NGGridLayoutAlgorithm::ReorderedGridItems::end() {
return Iterator(reordered_item_indices_.end(), &grid_items_); return Iterator(reordered_item_indices_.end(), &grid_items_);
} }
NGGridLayoutAlgorithmTrackCollection::SetIterator namespace {
NGGridLayoutAlgorithm::GetSetIteratorForItem(
const GridItemData& item, // Returns an iterator for every |NGGridSet| contained within an item's span in
// the relevant track collection.
NGGridLayoutAlgorithmTrackCollection::SetIterator GetSetIteratorForItem(
NGGridLayoutAlgorithm::GridItemData& item,
NGGridLayoutAlgorithmTrackCollection& track_collection) { NGGridLayoutAlgorithmTrackCollection& track_collection) {
return track_collection.GetSetIterator( NGGridLayoutAlgorithm::ItemSetIndices set_indices =
track_collection.IsForColumns() ? item.columns_begin_set_index item.SetIndices(track_collection);
: item.rows_begin_set_index, return track_collection.GetSetIterator(set_indices.begin, set_indices.end);
track_collection.IsForColumns() ? item.columns_end_set_index
: item.rows_end_set_index);
} }
} // namespace
// TODO(ethavar): Current implementation of this method simply returns the // TODO(ethavar): Current implementation of this method simply returns the
// preferred size of the grid item in the relevant direction. We should follow // preferred size of the grid item in the relevant direction. We should follow
// the definitions from https://drafts.csswg.org/css-grid-1/#algo-spanning-items // the definitions from https://drafts.csswg.org/css-grid-1/#algo-spanning-items
...@@ -588,107 +651,6 @@ void NGGridLayoutAlgorithm::EnsureTrackCoverageForGridItems( ...@@ -588,107 +651,6 @@ void NGGridLayoutAlgorithm::EnsureTrackCoverageForGridItems(
} }
} }
void NGGridLayoutAlgorithm::CacheItemSetIndices(
const NGGridLayoutAlgorithmTrackCollection& track_collection,
Vector<GridItemData>* items) const {
DCHECK(items);
const GridTrackSizingDirection track_direction = track_collection.Direction();
for (GridItemData& item : *items) {
wtf_size_t start_line, end_line;
if (item.item_type == ItemType::kInGridFlow) {
start_line = item.StartLine(track_direction);
end_line = item.EndLine(track_direction) - 1;
DCHECK_NE(start_line, kNotFound);
DCHECK_NE(end_line, kNotFound);
} else {
ResolveOutOfFlowItemGridLines(item, track_collection, &start_line,
&end_line);
}
// We only calculate the indexes if:
// 1. The item is in flow (it is a grid item) or
// 2. The item is out of flow, but the line was not defined as 'auto' and
// the line is within the bounds of the grid, since an out of flow item
// cannot create grid lines.
// TODO(ansollan): The start line of an out of flow item can be the last
// line of the grid. If that is the case, begin_set_index has to be
// computed as end_set_index. Similarly, if an end line is the first line
// of the grid, end_set_index has to be computed as begin_set_index.
wtf_size_t begin_set_index = kNotFound;
wtf_size_t end_set_index = kNotFound;
if (start_line != kNotFound) {
wtf_size_t first_spanned_range =
track_collection.RangeIndexFromTrackNumber(start_line);
begin_set_index =
track_collection.RangeStartingSetIndex(first_spanned_range);
}
if (end_line != kNotFound) {
wtf_size_t last_spanned_range =
track_collection.RangeIndexFromTrackNumber(end_line);
end_set_index =
track_collection.RangeStartingSetIndex(last_spanned_range) +
track_collection.RangeSetCount(last_spanned_range);
}
#if DCHECK_IS_ON()
if (begin_set_index != kNotFound && end_set_index != kNotFound) {
DCHECK_LE(end_set_index, track_collection.SetCount());
DCHECK_LT(begin_set_index, end_set_index);
} else if (begin_set_index != kNotFound) {
DCHECK_LT(begin_set_index, track_collection.SetCount());
} else if (end_set_index != kNotFound) {
DCHECK_LE(end_set_index, track_collection.SetCount());
}
#endif
if (track_direction == kForColumns) {
item.columns_begin_set_index = begin_set_index;
item.columns_end_set_index = end_set_index;
} else {
item.rows_begin_set_index = begin_set_index;
item.rows_end_set_index = end_set_index;
}
}
}
// TODO(ansollan): Move ResolveOutOfFlowItemGridLines to NGGridPlacement and
// pass |automatic_repetitions| and |explicit_start| variables.
void NGGridLayoutAlgorithm::ResolveOutOfFlowItemGridLines(
const GridItemData& out_of_flow_item,
const NGGridLayoutAlgorithmTrackCollection& track_collection,
wtf_size_t* start_line,
wtf_size_t* end_line) const {
DCHECK(start_line);
DCHECK(end_line);
const ComputedStyle& out_of_flow_item_style = out_of_flow_item.node.Style();
const GridTrackSizingDirection track_direction = track_collection.Direction();
GridSpan span = GridPositionsResolver::ResolveGridPositionsFromStyle(
Style(), out_of_flow_item_style, track_direction, 0);
if (span.IsIndefinite()) {
*start_line = kNotFound;
*end_line = kNotFound;
return;
} else if (span.UntranslatedStartLine() > -1) {
// TODO(ansollan): Handle out of flow positioned items with negative
// indexes.
span.Translate(0);
}
*start_line = span.StartLine();
*end_line = span.EndLine() - 1;
if (!track_collection.IsTrackWithinBounds(*start_line) ||
(track_direction == kForColumns
? out_of_flow_item_style.GridColumnStart().IsAuto()
: out_of_flow_item_style.GridRowStart().IsAuto()))
*start_line = kNotFound;
if (!track_collection.IsTrackWithinBounds(*end_line) ||
(track_direction == kForColumns
? out_of_flow_item_style.GridColumnEnd().IsAuto()
: out_of_flow_item_style.GridRowEnd().IsAuto()))
*end_line = kNotFound;
}
void NGGridLayoutAlgorithm::CacheGridItemsTrackSpanProperties( void NGGridLayoutAlgorithm::CacheGridItemsTrackSpanProperties(
const NGGridLayoutAlgorithmTrackCollection& track_collection, const NGGridLayoutAlgorithmTrackCollection& track_collection,
Vector<GridItemData>* grid_items, Vector<GridItemData>* grid_items,
...@@ -1141,6 +1103,7 @@ void NGGridLayoutAlgorithm::IncreaseTrackSizesToAccommodateGridItems( ...@@ -1141,6 +1103,7 @@ void NGGridLayoutAlgorithm::IncreaseTrackSizesToAccommodateGridItems(
// know our block size. // know our block size.
LayoutUnit spanned_tracks_size = LayoutUnit spanned_tracks_size =
GridGap(track_direction) * (grid_item->SpanSize(track_direction) - 1); GridGap(track_direction) * (grid_item->SpanSize(track_direction) - 1);
for (auto set_iterator = for (auto set_iterator =
GetSetIteratorForItem(*grid_item, *track_collection); GetSetIteratorForItem(*grid_item, *track_collection);
!set_iterator.IsAtEnd(); set_iterator.MoveToNextSet()) { !set_iterator.IsAtEnd(); set_iterator.MoveToNextSet()) {
...@@ -1395,12 +1358,16 @@ Vector<LayoutUnit> ComputeSetOffsets( ...@@ -1395,12 +1358,16 @@ Vector<LayoutUnit> ComputeSetOffsets(
} // namespace } // namespace
void NGGridLayoutAlgorithm::PlaceItems( void NGGridLayoutAlgorithm::PlaceItems(
const Vector<GridItemData>& grid_items,
const NGGridLayoutAlgorithmTrackCollection& column_track_collection, const NGGridLayoutAlgorithmTrackCollection& column_track_collection,
const NGGridLayoutAlgorithmTrackCollection& row_track_collection, const NGGridLayoutAlgorithmTrackCollection& row_track_collection,
Vector<GridItemData>* grid_items,
Vector<GridItemData>* out_of_flow_items, Vector<GridItemData>* out_of_flow_items,
NGGridPlacement* grid_placement,
LayoutUnit* intrinsic_block_size, LayoutUnit* intrinsic_block_size,
LayoutUnit* block_size) { LayoutUnit* block_size) {
DCHECK(grid_items);
DCHECK(out_of_flow_items);
DCHECK(grid_placement);
DCHECK(intrinsic_block_size); DCHECK(intrinsic_block_size);
DCHECK(block_size); DCHECK(block_size);
const TrackAlignmentGeometry column_track_alignment_geometry = const TrackAlignmentGeometry column_track_alignment_geometry =
...@@ -1452,15 +1419,27 @@ void NGGridLayoutAlgorithm::PlaceItems( ...@@ -1452,15 +1419,27 @@ void NGGridLayoutAlgorithm::PlaceItems(
ComputeSetOffsets(row_track_collection, row_track_alignment_geometry); ComputeSetOffsets(row_track_collection, row_track_alignment_geometry);
} }
PlaceGridItems(grid_items, column_set_offsets, row_set_offsets, *block_size, // Cache set indices for grid items, as all of them will be used.
for (GridItemData& grid_item : *grid_items) {
grid_item.SetIndices(column_track_collection);
grid_item.SetIndices(row_track_collection);
}
PlaceGridItems(*grid_items, column_set_offsets, row_set_offsets, *block_size,
column_track_alignment_geometry.gutter_size, column_track_alignment_geometry.gutter_size,
row_track_alignment_geometry.gutter_size); row_track_alignment_geometry.gutter_size);
PlaceOutOfFlowItems(column_set_offsets, row_set_offsets, // TODO(ansollan): This block will probably need to be moved to include the
column_track_collection, row_track_collection, // computation of the indices of out of flow descendants.
// Cache set indices for out of flow items, as all of them will be used.
for (GridItemData& out_of_flow_item : *out_of_flow_items) {
out_of_flow_item.SetIndices(column_track_collection, grid_placement);
out_of_flow_item.SetIndices(row_track_collection, grid_placement);
}
PlaceOutOfFlowItems(*out_of_flow_items, column_set_offsets, row_set_offsets,
*block_size, column_track_alignment_geometry.gutter_size, *block_size, column_track_alignment_geometry.gutter_size,
row_track_alignment_geometry.gutter_size, row_track_alignment_geometry.gutter_size);
out_of_flow_items);
} }
LayoutUnit NGGridLayoutAlgorithm::GridGap( LayoutUnit NGGridLayoutAlgorithm::GridGap(
...@@ -1552,6 +1531,9 @@ void NGGridLayoutAlgorithm::PlaceGridItems( ...@@ -1552,6 +1531,9 @@ void NGGridLayoutAlgorithm::PlaceGridItems(
LayoutUnit column_gutter_size, LayoutUnit column_gutter_size,
LayoutUnit row_gutter_size) { LayoutUnit row_gutter_size) {
for (const GridItemData& grid_item : grid_items) { for (const GridItemData& grid_item : grid_items) {
DCHECK(grid_item.column_set_indices.has_value());
DCHECK(grid_item.row_set_indices.has_value());
LogicalOffset offset; LogicalOffset offset;
LogicalSize size; LogicalSize size;
ComputeOffsetAndSize(grid_item, column_set_offsets, column_gutter_size, ComputeOffsetAndSize(grid_item, column_set_offsets, column_gutter_size,
...@@ -1593,19 +1575,16 @@ void NGGridLayoutAlgorithm::PlaceGridItems( ...@@ -1593,19 +1575,16 @@ void NGGridLayoutAlgorithm::PlaceGridItems(
} }
void NGGridLayoutAlgorithm::PlaceOutOfFlowItems( void NGGridLayoutAlgorithm::PlaceOutOfFlowItems(
const Vector<GridItemData>& out_of_flow_items,
const Vector<LayoutUnit>& column_set_offsets, const Vector<LayoutUnit>& column_set_offsets,
const Vector<LayoutUnit>& row_set_offsets, const Vector<LayoutUnit>& row_set_offsets,
const NGGridLayoutAlgorithmTrackCollection& column_track_collection,
const NGGridLayoutAlgorithmTrackCollection& row_track_collection,
LayoutUnit block_size, LayoutUnit block_size,
LayoutUnit column_gutter_size, LayoutUnit column_gutter_size,
LayoutUnit row_gutter_size, LayoutUnit row_gutter_size) {
Vector<GridItemData>* out_of_flow_items) { for (const GridItemData& out_of_flow_item : out_of_flow_items) {
// Cache set indices for out of flow items. DCHECK(out_of_flow_item.column_set_indices.has_value());
CacheItemSetIndices(column_track_collection, out_of_flow_items); DCHECK(out_of_flow_item.row_set_indices.has_value());
CacheItemSetIndices(row_track_collection, out_of_flow_items);
for (const GridItemData& out_of_flow_item : *out_of_flow_items) {
LogicalRect containing_block_rect; LogicalRect containing_block_rect;
ComputeOffsetAndSize(out_of_flow_item, column_set_offsets, ComputeOffsetAndSize(out_of_flow_item, column_set_offsets,
column_gutter_size, column_gutter_size,
...@@ -1642,14 +1621,14 @@ void NGGridLayoutAlgorithm::ComputeOffsetAndSize( ...@@ -1642,14 +1621,14 @@ void NGGridLayoutAlgorithm::ComputeOffsetAndSize(
// The default padding box value of the |size| will only be used in out of // The default padding box value of the |size| will only be used in out of
// flow items in which both the start line and end line are defined as 'auto'. // flow items in which both the start line and end line are defined as 'auto'.
if (track_direction == kForColumns) { if (track_direction == kForColumns) {
start_index = item.columns_begin_set_index; start_index = item.column_set_indices->begin;
end_index = item.columns_end_set_index; end_index = item.column_set_indices->end;
border = container_builder_.Borders().inline_start; border = container_builder_.Borders().inline_start;
*size = *size =
border_box_size_.inline_size - container_builder_.Borders().InlineSum(); border_box_size_.inline_size - container_builder_.Borders().InlineSum();
} else { } else {
start_index = item.rows_begin_set_index; start_index = item.row_set_indices->begin;
end_index = item.rows_end_set_index; end_index = item.row_set_indices->end;
border = container_builder_.Borders().block_start; border = container_builder_.Borders().block_start;
*size = border_box_size_.block_size == kIndefiniteSize *size = border_box_size_.block_size == kIndefiniteSize
? block_size ? block_size
......
...@@ -36,6 +36,11 @@ class CORE_EXPORT NGGridLayoutAlgorithm ...@@ -36,6 +36,11 @@ class CORE_EXPORT NGGridLayoutAlgorithm
kForMaxContentMaximums kForMaxContentMaximums
}; };
struct ItemSetIndices {
wtf_size_t begin;
wtf_size_t end;
};
struct GridItemData { struct GridItemData {
explicit GridItemData(const NGBlockNode node) : node(node) {} explicit GridItemData(const NGBlockNode node) : node(node) {}
...@@ -59,6 +64,13 @@ class CORE_EXPORT NGGridLayoutAlgorithm ...@@ -59,6 +64,13 @@ class CORE_EXPORT NGGridLayoutAlgorithm
bool IsSpanningIntrinsicTrack( bool IsSpanningIntrinsicTrack(
GridTrackSizingDirection track_direction) const; GridTrackSizingDirection track_direction) const;
// For this item and track direction, computes and stores the pair of
// indices "begin" and "end" such that the item spans every set from the
// respective collection's |sets_| with an index in the range [begin, end).
ItemSetIndices SetIndices(
const NGGridLayoutAlgorithmTrackCollection& track_collection,
NGGridPlacement* grid_placement = nullptr);
const NGBlockNode node; const NGBlockNode node;
GridArea resolved_position; GridArea resolved_position;
...@@ -66,13 +78,6 @@ class CORE_EXPORT NGGridLayoutAlgorithm ...@@ -66,13 +78,6 @@ class CORE_EXPORT NGGridLayoutAlgorithm
LayoutUnit inline_size; LayoutUnit inline_size;
MinMaxSizes min_max_sizes; MinMaxSizes min_max_sizes;
// These fields are used to determine the sets this item spans in the
// respective track collection; see |CacheItemSetIndices|.
wtf_size_t columns_begin_set_index;
wtf_size_t columns_end_set_index;
wtf_size_t rows_begin_set_index;
wtf_size_t rows_end_set_index;
AxisEdge inline_axis_alignment; AxisEdge inline_axis_alignment;
AxisEdge block_axis_alignment; AxisEdge block_axis_alignment;
...@@ -83,6 +88,12 @@ class CORE_EXPORT NGGridLayoutAlgorithm ...@@ -83,6 +88,12 @@ class CORE_EXPORT NGGridLayoutAlgorithm
TrackSpanProperties column_span_properties; TrackSpanProperties column_span_properties;
TrackSpanProperties row_span_properties; TrackSpanProperties row_span_properties;
// These fields are used to determine the sets this item spans in the
// respective track collection; see |SetIndices|. We use optional since some
// scenarios don't require to compute the indices at all.
base::Optional<ItemSetIndices> column_set_indices;
base::Optional<ItemSetIndices> row_set_indices;
}; };
explicit NGGridLayoutAlgorithm(const NGLayoutAlgorithmParams& params); explicit NGGridLayoutAlgorithm(const NGLayoutAlgorithmParams& params);
...@@ -132,13 +143,6 @@ class CORE_EXPORT NGGridLayoutAlgorithm ...@@ -132,13 +143,6 @@ class CORE_EXPORT NGGridLayoutAlgorithm
Vector<GridItemData>& grid_items_; Vector<GridItemData>& grid_items_;
}; };
// Returns an iterator for every |NGGridSet| contained within an item's span
// in the relevant track collection.
static NGGridLayoutAlgorithmTrackCollection::SetIterator
GetSetIteratorForItem(const GridItemData& item,
NGGridLayoutAlgorithmTrackCollection& track_collection);
// Returns the size that a grid item will distribute across the tracks with an // Returns the size that a grid item will distribute across the tracks with an
// intrinsic sizing function it spans in the relevant track direction. // intrinsic sizing function it spans in the relevant track direction.
LayoutUnit ContributionSizeForGridItem( LayoutUnit ContributionSizeForGridItem(
...@@ -175,18 +179,6 @@ class CORE_EXPORT NGGridLayoutAlgorithm ...@@ -175,18 +179,6 @@ class CORE_EXPORT NGGridLayoutAlgorithm
const Vector<GridItemData>& grid_items, const Vector<GridItemData>& grid_items,
NGGridBlockTrackCollection* track_collection) const; NGGridBlockTrackCollection* track_collection) const;
// For every item and track direction, computes and stores the pair of indices
// "begin" and "end" such that the item spans every set from the respective
// collection's |sets_| with an index in the range [begin, end).
void CacheItemSetIndices(
const NGGridLayoutAlgorithmTrackCollection& track_collection,
Vector<GridItemData>* items) const;
// Helper function to resolve start and end lines of out of flow items.
void ResolveOutOfFlowItemGridLines(
const GridItemData& out_of_flow_item,
const NGGridLayoutAlgorithmTrackCollection& track_collection,
wtf_size_t* start_line,
wtf_size_t* end_line) const;
// For every grid item, caches properties of the track sizing functions it // For every grid item, caches properties of the track sizing functions it
// spans (i.e. whether an item spans intrinsic or flexible tracks). // spans (i.e. whether an item spans intrinsic or flexible tracks).
void CacheGridItemsTrackSpanProperties( void CacheGridItemsTrackSpanProperties(
...@@ -221,10 +213,11 @@ class CORE_EXPORT NGGridLayoutAlgorithm ...@@ -221,10 +213,11 @@ class CORE_EXPORT NGGridLayoutAlgorithm
// Lays out and computes inline and block offsets for grid items. // Lays out and computes inline and block offsets for grid items.
void PlaceItems( void PlaceItems(
const Vector<GridItemData>& grid_items,
const NGGridLayoutAlgorithmTrackCollection& column_track_collection, const NGGridLayoutAlgorithmTrackCollection& column_track_collection,
const NGGridLayoutAlgorithmTrackCollection& row_track_collection, const NGGridLayoutAlgorithmTrackCollection& row_track_collection,
Vector<GridItemData>* grid_items,
Vector<GridItemData>* out_of_flow_items, Vector<GridItemData>* out_of_flow_items,
NGGridPlacement* grid_placement,
LayoutUnit* intrinsic_block_size, LayoutUnit* intrinsic_block_size,
LayoutUnit* block_size); LayoutUnit* block_size);
...@@ -236,21 +229,18 @@ class CORE_EXPORT NGGridLayoutAlgorithm ...@@ -236,21 +229,18 @@ class CORE_EXPORT NGGridLayoutAlgorithm
void PlaceGridItems(const Vector<GridItemData>& grid_items, void PlaceGridItems(const Vector<GridItemData>& grid_items,
const Vector<LayoutUnit>& column_set_offsets, const Vector<LayoutUnit>& column_set_offsets,
const Vector<LayoutUnit>& row_set_offsets, const Vector<LayoutUnit>& row_set_offsets,
LayoutUnit intrinsic_block_size, LayoutUnit block_size,
LayoutUnit column_grid_gap, LayoutUnit column_grid_gap,
LayoutUnit row_grid_gap); LayoutUnit row_grid_gap);
// Computes the static position, grid area and its offset of out of flow // Computes the static position, grid area and its offset of out of flow
// elements in the grid. // elements in the grid.
void PlaceOutOfFlowItems( void PlaceOutOfFlowItems(const Vector<GridItemData>& out_of_flow_items,
const Vector<LayoutUnit>& column_set_offsets, const Vector<LayoutUnit>& column_set_offsets,
const Vector<LayoutUnit>& row_set_offsets, const Vector<LayoutUnit>& row_set_offsets,
const NGGridLayoutAlgorithmTrackCollection& column_track_collection, LayoutUnit block_size,
const NGGridLayoutAlgorithmTrackCollection& row_track_collection, LayoutUnit column_grid_gap,
LayoutUnit block_size, LayoutUnit row_grid_gap);
LayoutUnit column_grid_gap,
LayoutUnit row_grid_gap,
Vector<GridItemData>* out_of_flow_items);
// Helper method that computes the offset and size of an item. // Helper method that computes the offset and size of an item.
void ComputeOffsetAndSize( void ComputeOffsetAndSize(
......
...@@ -54,12 +54,6 @@ class NGGridLayoutAlgorithmTest ...@@ -54,12 +54,6 @@ class NGGridLayoutAlgorithmTest
&grid_items_, &algorithm_column_track_collection_, &grid_items_, &algorithm_column_track_collection_,
&algorithm_row_track_collection_, &grid_placement); &algorithm_row_track_collection_, &grid_placement);
// Cache set indices.
algorithm.CacheItemSetIndices(algorithm_column_track_collection_,
&grid_items_);
algorithm.CacheItemSetIndices(algorithm_row_track_collection_,
&grid_items_);
// Create a vector of grid item indices using |NGGridChildIterator| order. // Create a vector of grid item indices using |NGGridChildIterator| order.
Vector<wtf_size_t> reordered_item_indices(grid_items_.size()); Vector<wtf_size_t> reordered_item_indices(grid_items_.size());
for (wtf_size_t i = 0; i < grid_items_.size(); ++i) for (wtf_size_t i = 0; i < grid_items_.size(); ++i)
......
...@@ -328,4 +328,46 @@ bool NGGridPlacement::HasSparsePacking() const { ...@@ -328,4 +328,46 @@ bool NGGridPlacement::HasSparsePacking() const {
return packing_behavior_ == PackingBehavior::kSparse; return packing_behavior_ == PackingBehavior::kSparse;
} }
void NGGridPlacement::ResolveOutOfFlowItemGridLines(
const NGGridLayoutAlgorithmTrackCollection& track_collection,
const ComputedStyle& out_of_flow_item_style,
wtf_size_t* start_line,
wtf_size_t* end_line) const {
DCHECK(start_line);
DCHECK(end_line);
const GridTrackSizingDirection track_direction = track_collection.Direction();
GridSpan span = GridPositionsResolver::ResolveGridPositionsFromStyle(
grid_style_, out_of_flow_item_style, track_direction,
AutoRepeatTrackCount(track_direction));
if (span.IsIndefinite()) {
*start_line = kNotFound;
*end_line = kNotFound;
return;
}
if (span.UntranslatedStartLine() > -1) {
// TODO(ansollan): Handle out of flow positioned items with negative
// indexes.
span.Translate(StartOffset(track_direction));
}
*start_line = span.StartLine();
*end_line = span.EndLine();
bool is_start_line_auto =
(track_direction == kForColumns)
? out_of_flow_item_style.GridColumnStart().IsAuto()
: out_of_flow_item_style.GridRowStart().IsAuto();
if (is_start_line_auto || !track_collection.IsTrackWithinBounds(*start_line))
*start_line = kNotFound;
bool is_end_line_auto = (track_direction == kForColumns)
? out_of_flow_item_style.GridColumnEnd().IsAuto()
: out_of_flow_item_style.GridRowEnd().IsAuto();
if (is_end_line_auto || !track_collection.IsTrackWithinBounds(*end_line - 1))
*end_line = kNotFound;
}
} // namespace blink } // namespace blink
...@@ -28,6 +28,13 @@ class CORE_EXPORT NGGridPlacement { ...@@ -28,6 +28,13 @@ class CORE_EXPORT NGGridPlacement {
const wtf_size_t row_auto_repetitions); const wtf_size_t row_auto_repetitions);
void RunAutoPlacementAlgorithm(Vector<GridItemData>* grid_items); void RunAutoPlacementAlgorithm(Vector<GridItemData>* grid_items);
// Helper function to resolve start and end lines of out of flow items.
void ResolveOutOfFlowItemGridLines(
const NGGridLayoutAlgorithmTrackCollection& track_collection,
const ComputedStyle& out_of_flow_item_style,
wtf_size_t* start_line,
wtf_size_t* end_line) const;
wtf_size_t AutoRepetitions(GridTrackSizingDirection track_direction) const; wtf_size_t AutoRepetitions(GridTrackSizingDirection track_direction) const;
private: private:
......
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