Commit 76c20976 authored by Ana SollanoKim's avatar Ana SollanoKim Committed by Chromium LUCI CQ

Reland "[GridNG] Computation of static offsets edges and grid area for

out of flow items"

This is a reland of f08bc1d7

Original change:
https://chromium-review.googlesource.com/c/chromium/src/+/2567573

Revert of the original change:
https://chromium-review.googlesource.com/c/chromium/src/+/2613550

Marked:
virtual/layout-ng-grid/external/wpt/css/css-grid/abspos/grid-positioned
-items-gaps-001.html
virtual/layout-ng-grid/external/wpt/css/css-grid/abspos/grid-positioned
-items-gaps-rtl-001.html
virtual/layout-ng-grid/external/wpt/css/css-grid/abspos/grid-positioned
-items-within-grid-implicit-track-001.html
virtual/layout-ng-grid/external/wpt/css/css-grid/alignment/grid-column-
axis-alignment-positioned-items-[012-016].html
virtual/layout-ng-grid/external/wpt/css/css-grid/alignment/grid-row-
axis-alignment-positioned-items-[012-016].html
virtual/layout-ng-grid/external/wpt/css/css-grid/alignment/grid-self-
alignment-positioned-items-with-margin-border-padding-[011-016].html
as failing in all builders.

Original change's description:
> [GridNG] Computation of static offsets edges and grid area for out of
> flow items
>
> 1. Function ResolveOutOfFlowItemGridLines: The column and row span of
> the grid area for the out of flow item is obtained through
> GridPositionResolver, and the grid lines of the out of flow item are
> computed.
>
> 2. Refactor of CacheItemSetIndices: For in flow items, computation of
> the set indices remains the same. To compute the indices for out of flow
> items we take into account the following:
>   a. If both the start and end line of the out of flow item are not
>   'auto', then the indices are computed as if they were in flow items.
>   b. If either is 'auto', then its value is kNotFound.
>   c. If either is attempting to create a new line in the grid, then they
>   are treated as 'auto'.
>
> 3. Helper method ComputeOffsetAndSize: the computation of the offset and
> size of each item was generalized to include the cases where either or
> both of the set indices are auto in out of flow items. Additionally,
> inline and block edges are computed.
>
> Bug: 1045599
> Change-Id: I15b680d1866cdb81b42d626bcd6948ae1b7132ca
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2567573
> Commit-Queue: Ana Sollano Kim <ansollan@microsoft.com>
> Reviewed-by: Ian Kilpatrick <ikilpatrick@chromium.org>
> Reviewed-by: Kurt Catti-Schmidt <kschmi@microsoft.com>
> Reviewed-by: Stephen Chenney <schenney@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#840701}

Bug: 1045599
Change-Id: Ie2fee60c6717740fc70f5b0d285919b47f521bed
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2616242
Commit-Queue: Ian Kilpatrick <ikilpatrick@chromium.org>
Reviewed-by: default avatarIan Kilpatrick <ikilpatrick@chromium.org>
Cr-Commit-Position: refs/heads/master@{#842065}
parent 6bfc721c
...@@ -23,6 +23,7 @@ class CORE_EXPORT NGGridLayoutAlgorithm ...@@ -23,6 +23,7 @@ class CORE_EXPORT NGGridLayoutAlgorithm
public: public:
enum class AutoPlacementType { kNotNeeded, kMajor, kMinor, kBoth }; enum class AutoPlacementType { kNotNeeded, kMajor, kMinor, kBoth };
enum class AxisEdge { kStart, kCenter, kEnd, kBaseline }; enum class AxisEdge { kStart, kCenter, kEnd, kBaseline };
enum class ItemType { kInGridFlow, kOutOfFlow };
// This enum corresponds to each step used to accommodate grid items across // This enum corresponds to each step used to accommodate grid items across
// intrinsic tracks according to their min and max track sizing functions, as // intrinsic tracks according to their min and max track sizing functions, as
...@@ -75,6 +76,8 @@ class CORE_EXPORT NGGridLayoutAlgorithm ...@@ -75,6 +76,8 @@ class CORE_EXPORT NGGridLayoutAlgorithm
AxisEdge inline_axis_alignment; AxisEdge inline_axis_alignment;
AxisEdge block_axis_alignment; AxisEdge block_axis_alignment;
ItemType item_type;
bool is_inline_axis_stretched; bool is_inline_axis_stretched;
bool is_block_axis_stretched; bool is_block_axis_stretched;
...@@ -177,7 +180,13 @@ class CORE_EXPORT NGGridLayoutAlgorithm ...@@ -177,7 +180,13 @@ class CORE_EXPORT NGGridLayoutAlgorithm
// collection's |sets_| with an index in the range [begin, end). // collection's |sets_| with an index in the range [begin, end).
void CacheItemSetIndices( void CacheItemSetIndices(
const NGGridLayoutAlgorithmTrackCollection& track_collection, const NGGridLayoutAlgorithmTrackCollection& track_collection,
Vector<GridItemData>* grid_items) const; 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(
...@@ -211,18 +220,13 @@ class CORE_EXPORT NGGridLayoutAlgorithm ...@@ -211,18 +220,13 @@ class CORE_EXPORT NGGridLayoutAlgorithm
NGGridSetVector* sets_to_grow_beyond_limit); NGGridSetVector* sets_to_grow_beyond_limit);
// Lays out and computes inline and block offsets for grid items. // Lays out and computes inline and block offsets for grid items.
void PlaceGridItems( void PlaceItems(
const Vector<GridItemData>& grid_items, const Vector<GridItemData>& grid_items,
const Vector<GridItemData>& out_of_flow_items, const NGGridLayoutAlgorithmTrackCollection& column_track_collection,
NGGridLayoutAlgorithmTrackCollection& column_track_collection, const NGGridLayoutAlgorithmTrackCollection& row_track_collection,
NGGridLayoutAlgorithmTrackCollection& row_track_collection, Vector<GridItemData>* out_of_flow_items,
LayoutUnit* intrinsic_block_size); LayoutUnit* intrinsic_block_size);
// Lays out |grid_item| based on the offsets and sizes provided.
void PlaceGridItem(const GridItemData& grid_item,
LogicalOffset offset,
LogicalSize size);
// Gets the row or column gap of the grid. // Gets the row or column gap of the grid.
LayoutUnit GridGap(GridTrackSizingDirection track_direction, LayoutUnit GridGap(GridTrackSizingDirection track_direction,
LayoutUnit available_size = kIndefiniteSize) const; LayoutUnit available_size = kIndefiniteSize) const;
...@@ -236,6 +240,43 @@ class CORE_EXPORT NGGridLayoutAlgorithm ...@@ -236,6 +240,43 @@ class CORE_EXPORT NGGridLayoutAlgorithm
// available size. // available size.
bool IsRowGridGapUnresolvable(LayoutUnit available_size) const; bool IsRowGridGapUnresolvable(LayoutUnit available_size) const;
// Layout the |grid_items| based on the offsets provided.
void PlaceGridItems(const Vector<GridItemData>& grid_items,
const Vector<LayoutUnit>& column_set_offsets,
const Vector<LayoutUnit>& row_set_offsets,
LayoutUnit intrinsic_block_size,
LayoutUnit column_grid_gap,
LayoutUnit row_grid_gap);
// Computes the static position, grid area and its offset of out of flow
// elements in the grid.
void PlaceOutOfFlowItems(
const Vector<LayoutUnit>& column_set_offsets,
const Vector<LayoutUnit>& row_set_offsets,
const NGGridLayoutAlgorithmTrackCollection& column_track_collection,
const NGGridLayoutAlgorithmTrackCollection& row_track_collection,
LayoutUnit intrinsic_block_size,
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.
void ComputeOffsetAndSize(
const GridItemData& item,
const Vector<LayoutUnit>& set_offsets,
LayoutUnit grid_gap,
LayoutUnit* start_offset,
LayoutUnit* size,
GridTrackSizingDirection track_direction = kForColumns,
const LayoutUnit intrinsic_block_size = LayoutUnit()) const;
// Determines the position of the out of flow item's container.
void DeterminePositionOfOutOfFlowContainer(
Vector<GridItemData>* out_of_flow_items,
const GridTrackSizingDirection track_direction) const;
GridTrackSizingDirection AutoFlowDirection() const;
LogicalSize border_box_size_; LogicalSize border_box_size_;
LogicalSize child_percentage_size_; LogicalSize child_percentage_size_;
}; };
......
...@@ -1594,13 +1594,8 @@ TEST_F(NGGridLayoutAlgorithmTest, AutoSizedGridWithPercentageGap) { ...@@ -1594,13 +1594,8 @@ TEST_F(NGGridLayoutAlgorithmTest, AutoSizedGridWithPercentageGap) {
if (!RuntimeEnabledFeatures::LayoutNGGridEnabled()) if (!RuntimeEnabledFeatures::LayoutNGGridEnabled())
return; return;
LoadAhem();
SetBodyInnerHTML(R"HTML( SetBodyInnerHTML(R"HTML(
<style> <style>
body {
font: 10px/1 Ahem;
}
#grid { #grid {
display: grid; display: grid;
width: auto; width: auto;
...@@ -1707,76 +1702,99 @@ TEST_F(NGGridLayoutAlgorithmTest, ItemsSizeWithGap) { ...@@ -1707,76 +1702,99 @@ TEST_F(NGGridLayoutAlgorithmTest, ItemsSizeWithGap) {
EXPECT_EQ(expectation, dump); EXPECT_EQ(expectation, dump);
} }
TEST_F(NGGridLayoutAlgorithmTest, OutOfFlowGridItems) { TEST_F(NGGridLayoutAlgorithmTest, PositionedOutOfFlowItems) {
if (!RuntimeEnabledFeatures::LayoutNGGridEnabled()) if (!RuntimeEnabledFeatures::LayoutNGGridEnabled())
return; return;
LoadAhem();
SetBodyInnerHTML(R"HTML( SetBodyInnerHTML(R"HTML(
<style> <style>
body {
font: 10px/1 Ahem;
}
#grid { #grid {
display: grid; display: grid;
width: 100px; grid: 100px 100px 100px / 100px 100px 100px;
height: 300px; width: 300px;
grid-auto-columns: 100px; height: auto;
grid-auto-rows: 100px; background-color: gray;
padding: 5px;
border: 5px solid black;
position: relative; position: relative;
} }
.grid_item { .absolute {
width: 100px; position: absolute;
height: 100px; width: 50px;
background-color: gray; height: 50px;
} }
#cell2 { .item {
position: absolute; background-color: gainsboro;
left: 25%;
top: 10%;
width: 100px;
height: 100px;
background-color: blue;
} }
#cell4 { #firstItem {
position: absolute; background: magenta;
top: 150px; grid-column-start: 2;
left: 25px; grid-column-end: 3;
width: 100%; grid-row-start: 2;
height: 35%; grid-row-end: 3;
background-color: yellow; align-self: center;
justify-self: end;
}
#secondItem {
background: cyan;
grid-column-start: auto;
grid-column-end: 2;
grid-row-start: 3;
grid-row-end: auto;
bottom: 30px;
}
#thirdItem {
background: yellow;
left: 200px;
} }
#fourthItem {
background: lime;
grid-column-start: 5;
grid-column-end: 6;
}
</style> </style>
<div id="wrapper"> <div id="wrapper">
<div id="grid"> <div id="grid">
<div class="grid_item" style="background: orange;">1</div> <div class="absolute" id="firstItem"></div>
<div id="cell2">2</div> <div class="absolute" id="secondItem"></div>
<div class="grid_item" style="background: green;">3</div> <div class="absolute" id="thirdItem"></div>
<div id="cell4">4</div> <div class="absolute" id="fourthItem"></div>
<div class="grid_item" style="background: blueviolet;">5</div> <div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
</div> </div>
</div> </div>
)HTML"); )HTML");
String dump = DumpFragmentTree(GetElementById("wrapper")); String dump = DumpFragmentTree(GetElementById("wrapper"));
String expectation = R"DUMP(.:: LayoutNG Physical Fragment Tree ::. String expectation = R"DUMP(.:: LayoutNG Physical Fragment Tree ::.
offset:unplaced size:1000x300 offset:unplaced size:1000x320
offset:0,0 size:100x300 offset:0,0 size:320x320
offset:0,0 size:100x100 offset:10,10 size:100x100
offset:0,0 size:10x10 offset:110,10 size:100x100
offset:0,100 size:100x100 offset:210,10 size:100x100
offset:0,0 size:10x10 offset:10,110 size:100x100
offset:0,200 size:100x100 offset:110,110 size:100x100
offset:0,0 size:10x10 offset:210,110 size:100x100
offset:25,30 size:100x100 offset:10,210 size:100x100
offset:0,0 size:10x10 offset:110,210 size:100x100
offset:25,150 size:100x105 offset:210,210 size:100x100
offset:0,0 size:10x10 offset:160,135 size:50x50
offset:5,235 size:50x50
offset:205,5 size:50x50
offset:5,5 size:50x50
)DUMP"; )DUMP";
EXPECT_EQ(expectation, dump); EXPECT_EQ(expectation, dump);
} }
......
...@@ -11,6 +11,14 @@ namespace blink { ...@@ -11,6 +11,14 @@ namespace blink {
constexpr wtf_size_t NGGridTrackCollectionBase::kInvalidRangeIndex; constexpr wtf_size_t NGGridTrackCollectionBase::kInvalidRangeIndex;
bool NGGridTrackCollectionBase::IsTrackWithinBounds(
wtf_size_t track_number) const {
DCHECK_NE(track_number, kInvalidRangeIndex);
wtf_size_t last_range_index = RangeCount() - 1;
return track_number <
RangeTrackNumber(last_range_index) + RangeTrackCount(last_range_index);
}
wtf_size_t NGGridTrackCollectionBase::RangeIndexFromTrackNumber( wtf_size_t NGGridTrackCollectionBase::RangeIndexFromTrackNumber(
wtf_size_t track_number) const { wtf_size_t track_number) const {
wtf_size_t upper = RangeCount(); wtf_size_t upper = RangeCount();
...@@ -19,9 +27,7 @@ wtf_size_t NGGridTrackCollectionBase::RangeIndexFromTrackNumber( ...@@ -19,9 +27,7 @@ wtf_size_t NGGridTrackCollectionBase::RangeIndexFromTrackNumber(
// We can't look for a range in a collection with no ranges. // We can't look for a range in a collection with no ranges.
DCHECK_NE(upper, 0u); DCHECK_NE(upper, 0u);
// We don't expect a |track_number| outside of the bounds of the collection. // We don't expect a |track_number| outside of the bounds of the collection.
DCHECK_NE(track_number, kInvalidRangeIndex); DCHECK(IsTrackWithinBounds(track_number));
DCHECK_LT(track_number,
RangeTrackNumber(upper - 1u) + RangeTrackCount(upper - 1u));
// Do a binary search on the tracks. // Do a binary search on the tracks.
wtf_size_t range = upper - lower; wtf_size_t range = upper - lower;
......
...@@ -49,6 +49,8 @@ class CORE_EXPORT NGGridTrackCollectionBase { ...@@ -49,6 +49,8 @@ class CORE_EXPORT NGGridTrackCollectionBase {
wtf_size_t range_track_count_; wtf_size_t range_track_count_;
}; };
bool IsTrackWithinBounds(wtf_size_t track_number) const;
// Gets the range index for the range that contains the given track number. // Gets the range index for the range that contains the given track number.
wtf_size_t RangeIndexFromTrackNumber(wtf_size_t track_number) const; wtf_size_t RangeIndexFromTrackNumber(wtf_size_t track_number) const;
......
...@@ -183,7 +183,7 @@ void NGContainerFragmentBuilder::AddOutOfFlowChildCandidate( ...@@ -183,7 +183,7 @@ void NGContainerFragmentBuilder::AddOutOfFlowChildCandidate(
oof_positioned_candidates_.emplace_back( oof_positioned_candidates_.emplace_back(
child, NGLogicalStaticPosition{child_offset, inline_edge, block_edge}, child, NGLogicalStaticPosition{child_offset, inline_edge, block_edge},
/* inline_container */ nullptr, needs_block_offset_adjustment, /* inline_container */ nullptr, needs_block_offset_adjustment,
/*containing_block_offset */ LogicalOffset(), /* containing_block_offset */ LogicalOffset(),
/* containing_block_fragment */ nullptr, containing_block_rect); /* containing_block_fragment */ nullptr, containing_block_rect);
} }
......
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