Commit 334c2f75 authored by Ethan Jimenez's avatar Ethan Jimenez Committed by Commit Bot

[GridNG] Move specific enums for grid inside NGGridLayoutAlgorithm

Previously,`NGGridItemContributionType` and `AutoPlacementType` were
moved outside of `NGGridLayoutAlgorithm` to improve readibility of
several helper functions, as referencing such enums from functions
outside of the class resulted in much longer lines.

This change returns these enums inside `NGGridLayoutAlgorithm` following
the same pattern as `AxisEdge` to use them in external helper functions.

Bug: 1045599
Change-Id: Iab68d75778858ba2f6d0a61329f56d49db6c6455
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2543205Reviewed-by: default avatarIan Kilpatrick <ikilpatrick@chromium.org>
Reviewed-by: default avatarChristian Biesinger <cbiesinger@chromium.org>
Reviewed-by: default avatarJacques Newman <janewman@microsoft.com>
Reviewed-by: default avatarKurt Catti-Schmidt <kschmi@microsoft.com>
Commit-Queue: Ethan Jimenez <ethavar@microsoft.com>
Cr-Commit-Position: refs/heads/master@{#829001}
parent cf9e009d
...@@ -121,7 +121,8 @@ NGGridLayoutAlgorithm::RowTrackCollection() const { ...@@ -121,7 +121,8 @@ NGGridLayoutAlgorithm::RowTrackCollection() const {
NGGridLayoutAlgorithm::GridItemData::GridItemData(const NGBlockNode node) NGGridLayoutAlgorithm::GridItemData::GridItemData(const NGBlockNode node)
: node(node) {} : node(node) {}
AutoPlacementType NGGridLayoutAlgorithm::GridItemData::AutoPlacement( NGGridLayoutAlgorithm::AutoPlacementType
NGGridLayoutAlgorithm::GridItemData::AutoPlacement(
GridTrackSizingDirection flow_direction) const { GridTrackSizingDirection flow_direction) const {
bool is_major_indefinite = Span(flow_direction).IsIndefinite(); bool is_major_indefinite = Span(flow_direction).IsIndefinite();
bool is_minor_indefinite = bool is_minor_indefinite =
...@@ -259,7 +260,7 @@ NGGridLayoutAlgorithm::GetSetIteratorForItem( ...@@ -259,7 +260,7 @@ NGGridLayoutAlgorithm::GetSetIteratorForItem(
LayoutUnit NGGridLayoutAlgorithm::ContributionSizeForGridItem( LayoutUnit NGGridLayoutAlgorithm::ContributionSizeForGridItem(
const GridItemData& grid_item, const GridItemData& grid_item,
GridTrackSizingDirection track_direction, GridTrackSizingDirection track_direction,
NGGridItemContributionType contribution_type) const { GridItemContributionType contribution_type) const {
const ComputedStyle& grid_item_style = grid_item.node.Style(); const ComputedStyle& grid_item_style = grid_item.node.Style();
GridTrackSizingDirection grid_item_track_direction = track_direction; GridTrackSizingDirection grid_item_track_direction = track_direction;
...@@ -669,19 +670,22 @@ void NGGridLayoutAlgorithm::ComputeUsedTrackSizes( ...@@ -669,19 +670,22 @@ void NGGridLayoutAlgorithm::ComputeUsedTrackSizes(
// Helpers for the track sizing algorithm. // Helpers for the track sizing algorithm.
namespace { namespace {
using GridItemContributionType =
NGGridLayoutAlgorithm::GridItemContributionType;
// Returns the corresponding size to be increased by accommodating a grid item's // Returns the corresponding size to be increased by accommodating a grid item's
// contribution; for intrinsic min track sizing functions, return the base size. // contribution; for intrinsic min track sizing functions, return the base size.
// For intrinsic max track sizing functions, return the growth limit. // For intrinsic max track sizing functions, return the growth limit.
static LayoutUnit AffectedSizeForContribution( static LayoutUnit AffectedSizeForContribution(
const NGGridSet& set, const NGGridSet& set,
NGGridItemContributionType contribution_type) { GridItemContributionType contribution_type) {
switch (contribution_type) { switch (contribution_type) {
case NGGridItemContributionType::kForIntrinsicMinimums: case GridItemContributionType::kForIntrinsicMinimums:
case NGGridItemContributionType::kForContentBasedMinimums: case GridItemContributionType::kForContentBasedMinimums:
case NGGridItemContributionType::kForMaxContentMinimums: case GridItemContributionType::kForMaxContentMinimums:
return set.BaseSize(); return set.BaseSize();
case NGGridItemContributionType::kForIntrinsicMaximums: case GridItemContributionType::kForIntrinsicMaximums:
case NGGridItemContributionType::kForMaxContentMaximums: case GridItemContributionType::kForMaxContentMaximums:
LayoutUnit growth_limit = set.GrowthLimit(); LayoutUnit growth_limit = set.GrowthLimit();
// For infinite growth limits, substitute with the track's base size. // For infinite growth limits, substitute with the track's base size.
if (growth_limit == kIndefiniteSize) if (growth_limit == kIndefiniteSize)
...@@ -692,15 +696,15 @@ static LayoutUnit AffectedSizeForContribution( ...@@ -692,15 +696,15 @@ static LayoutUnit AffectedSizeForContribution(
static void GrowAffectedSizeByPlannedIncrease( static void GrowAffectedSizeByPlannedIncrease(
NGGridSet& set, NGGridSet& set,
NGGridItemContributionType contribution_type) { GridItemContributionType contribution_type) {
switch (contribution_type) { switch (contribution_type) {
case NGGridItemContributionType::kForIntrinsicMinimums: case GridItemContributionType::kForIntrinsicMinimums:
case NGGridItemContributionType::kForContentBasedMinimums: case GridItemContributionType::kForContentBasedMinimums:
case NGGridItemContributionType::kForMaxContentMinimums: case GridItemContributionType::kForMaxContentMinimums:
set.SetBaseSize(set.BaseSize() + set.PlannedIncrease()); set.SetBaseSize(set.BaseSize() + set.PlannedIncrease());
break; break;
case NGGridItemContributionType::kForIntrinsicMaximums: case GridItemContributionType::kForIntrinsicMaximums:
case NGGridItemContributionType::kForMaxContentMaximums: case GridItemContributionType::kForMaxContentMaximums:
LayoutUnit growth_limit = set.GrowthLimit(); LayoutUnit growth_limit = set.GrowthLimit();
// If the affected size to grow is an infinite growth limit, set it to the // If the affected size to grow is an infinite growth limit, set it to the
// track's base size plus the planned increase. // track's base size plus the planned increase.
...@@ -716,20 +720,20 @@ static void GrowAffectedSizeByPlannedIncrease( ...@@ -716,20 +720,20 @@ static void GrowAffectedSizeByPlannedIncrease(
// https://drafts.csswg.org/css-grid-1/#algo-spanning-items; false otherwise. // https://drafts.csswg.org/css-grid-1/#algo-spanning-items; false otherwise.
static bool IsContributionAppliedToSet( static bool IsContributionAppliedToSet(
const NGGridSet& set, const NGGridSet& set,
NGGridItemContributionType contribution_type) { GridItemContributionType contribution_type) {
switch (contribution_type) { switch (contribution_type) {
case NGGridItemContributionType::kForIntrinsicMinimums: case GridItemContributionType::kForIntrinsicMinimums:
return set.TrackSize().HasIntrinsicMinTrackBreadth(); return set.TrackSize().HasIntrinsicMinTrackBreadth();
case NGGridItemContributionType::kForContentBasedMinimums: case GridItemContributionType::kForContentBasedMinimums:
return set.TrackSize().HasMinOrMaxContentMinTrackBreadth(); return set.TrackSize().HasMinOrMaxContentMinTrackBreadth();
case NGGridItemContributionType::kForMaxContentMinimums: case GridItemContributionType::kForMaxContentMinimums:
// TODO(ethavar): Check if the grid container is being sized under a // TODO(ethavar): Check if the grid container is being sized under a
// 'max-content' constraint to consider 'auto' min track sizing functions, // 'max-content' constraint to consider 'auto' min track sizing functions,
// see https://drafts.csswg.org/css-grid-1/#track-size-max-content-min. // see https://drafts.csswg.org/css-grid-1/#track-size-max-content-min.
return set.TrackSize().HasMaxContentMinTrackBreadth(); return set.TrackSize().HasMaxContentMinTrackBreadth();
case NGGridItemContributionType::kForIntrinsicMaximums: case GridItemContributionType::kForIntrinsicMaximums:
return set.TrackSize().HasIntrinsicMaxTrackBreadth(); return set.TrackSize().HasIntrinsicMaxTrackBreadth();
case NGGridItemContributionType::kForMaxContentMaximums: case GridItemContributionType::kForMaxContentMaximums:
return set.TrackSize().HasMaxContentOrAutoMaxTrackBreadth(); return set.TrackSize().HasMaxContentOrAutoMaxTrackBreadth();
} }
} }
...@@ -741,32 +745,32 @@ static bool IsContributionAppliedToSet( ...@@ -741,32 +745,32 @@ static bool IsContributionAppliedToSet(
// collection of tracks different than "all affected tracks". // collection of tracks different than "all affected tracks".
static bool ShouldUsedSizeGrowBeyondLimit( static bool ShouldUsedSizeGrowBeyondLimit(
const NGGridSet& set, const NGGridSet& set,
NGGridItemContributionType contribution_type) { GridItemContributionType contribution_type) {
// This function assumes that we already determined that extra space // This function assumes that we already determined that extra space
// distribution will be applied to the specified set. // distribution will be applied to the specified set.
DCHECK(IsContributionAppliedToSet(set, contribution_type)); DCHECK(IsContributionAppliedToSet(set, contribution_type));
switch (contribution_type) { switch (contribution_type) {
case NGGridItemContributionType::kForIntrinsicMinimums: case GridItemContributionType::kForIntrinsicMinimums:
case NGGridItemContributionType::kForContentBasedMinimums: case GridItemContributionType::kForContentBasedMinimums:
return set.TrackSize().HasIntrinsicMaxTrackBreadth(); return set.TrackSize().HasIntrinsicMaxTrackBreadth();
case NGGridItemContributionType::kForMaxContentMinimums: case GridItemContributionType::kForMaxContentMinimums:
return set.TrackSize().HasMaxContentMaxTrackBreadth(); return set.TrackSize().HasMaxContentMaxTrackBreadth();
case NGGridItemContributionType::kForIntrinsicMaximums: case GridItemContributionType::kForIntrinsicMaximums:
case NGGridItemContributionType::kForMaxContentMaximums: case GridItemContributionType::kForMaxContentMaximums:
return false; return false;
} }
} }
static bool IsDistributionForGrowthLimits( static bool IsDistributionForGrowthLimits(
NGGridItemContributionType contribution_type) { GridItemContributionType contribution_type) {
switch (contribution_type) { switch (contribution_type) {
case NGGridItemContributionType::kForIntrinsicMinimums: case GridItemContributionType::kForIntrinsicMinimums:
case NGGridItemContributionType::kForContentBasedMinimums: case GridItemContributionType::kForContentBasedMinimums:
case NGGridItemContributionType::kForMaxContentMinimums: case GridItemContributionType::kForMaxContentMinimums:
return false; return false;
case NGGridItemContributionType::kForIntrinsicMaximums: case GridItemContributionType::kForIntrinsicMaximums:
case NGGridItemContributionType::kForMaxContentMaximums: case GridItemContributionType::kForMaxContentMaximums:
return true; return true;
} }
} }
...@@ -778,19 +782,19 @@ enum class InfinitelyGrowableBehavior { kEnforce, kIgnore }; ...@@ -778,19 +782,19 @@ enum class InfinitelyGrowableBehavior { kEnforce, kIgnore };
// as "infinitely growable", and equal to the growth limit otherwise. // as "infinitely growable", and equal to the growth limit otherwise.
static LayoutUnit GrowthPotentialForSet( static LayoutUnit GrowthPotentialForSet(
const NGGridSet& set, const NGGridSet& set,
NGGridItemContributionType contribution_type, GridItemContributionType contribution_type,
InfinitelyGrowableBehavior infinitely_growable_behavior = InfinitelyGrowableBehavior infinitely_growable_behavior =
InfinitelyGrowableBehavior::kEnforce) { InfinitelyGrowableBehavior::kEnforce) {
switch (contribution_type) { switch (contribution_type) {
case NGGridItemContributionType::kForIntrinsicMinimums: case GridItemContributionType::kForIntrinsicMinimums:
case NGGridItemContributionType::kForContentBasedMinimums: case GridItemContributionType::kForContentBasedMinimums:
case NGGridItemContributionType::kForMaxContentMinimums: { case GridItemContributionType::kForMaxContentMinimums: {
LayoutUnit growth_limit = set.GrowthLimit(); LayoutUnit growth_limit = set.GrowthLimit();
return (growth_limit == kIndefiniteSize) ? kIndefiniteSize return (growth_limit == kIndefiniteSize) ? kIndefiniteSize
: growth_limit - set.BaseSize(); : growth_limit - set.BaseSize();
} }
case NGGridItemContributionType::kForIntrinsicMaximums: case GridItemContributionType::kForIntrinsicMaximums:
case NGGridItemContributionType::kForMaxContentMaximums: { case GridItemContributionType::kForMaxContentMaximums: {
if (infinitely_growable_behavior == if (infinitely_growable_behavior ==
InfinitelyGrowableBehavior::kEnforce && InfinitelyGrowableBehavior::kEnforce &&
!set.IsInfinitelyGrowable()) { !set.IsInfinitelyGrowable()) {
...@@ -826,7 +830,7 @@ static LayoutUnit GrowthPotentialForSet( ...@@ -826,7 +830,7 @@ static LayoutUnit GrowthPotentialForSet(
// notice that this method replaces the notion of "tracks" with "sets". // notice that this method replaces the notion of "tracks" with "sets".
void NGGridLayoutAlgorithm::DistributeExtraSpaceToSets( void NGGridLayoutAlgorithm::DistributeExtraSpaceToSets(
LayoutUnit extra_space, LayoutUnit extra_space,
NGGridItemContributionType contribution_type, GridItemContributionType contribution_type,
NGGridSetVector* sets_to_grow, NGGridSetVector* sets_to_grow,
NGGridSetVector* sets_to_grow_beyond_limit) { NGGridSetVector* sets_to_grow_beyond_limit) {
DCHECK(sets_to_grow && extra_space >= 0); DCHECK(sets_to_grow && extra_space >= 0);
...@@ -968,7 +972,7 @@ void NGGridLayoutAlgorithm::IncreaseTrackSizesToAccommodateGridItems( ...@@ -968,7 +972,7 @@ void NGGridLayoutAlgorithm::IncreaseTrackSizesToAccommodateGridItems(
GridTrackSizingDirection track_direction, GridTrackSizingDirection track_direction,
ReorderedGridItems::Iterator group_begin, ReorderedGridItems::Iterator group_begin,
ReorderedGridItems::Iterator group_end, ReorderedGridItems::Iterator group_end,
NGGridItemContributionType contribution_type) { GridItemContributionType contribution_type) {
auto& track_collection = TrackCollection(track_direction); auto& track_collection = TrackCollection(track_direction);
for (auto set_iterator = track_collection.GetSetIterator(); for (auto set_iterator = track_collection.GetSetIterator();
!set_iterator.IsAtEnd(); set_iterator.MoveToNextSet()) { !set_iterator.IsAtEnd(); set_iterator.MoveToNextSet()) {
...@@ -1075,7 +1079,7 @@ void NGGridLayoutAlgorithm::ResolveIntrinsicTrackSizes( ...@@ -1075,7 +1079,7 @@ void NGGridLayoutAlgorithm::ResolveIntrinsicTrackSizes(
IncreaseTrackSizesToAccommodateGridItems( IncreaseTrackSizesToAccommodateGridItems(
track_direction, current_group_begin, current_group_end, track_direction, current_group_begin, current_group_end,
NGGridItemContributionType::kForIntrinsicMinimums); GridItemContributionType::kForIntrinsicMinimums);
// TODO(ethavar): Add remaining stages, mark infinitely growable sets... // TODO(ethavar): Add remaining stages, mark infinitely growable sets...
current_group_begin = current_group_end; current_group_begin = current_group_end;
......
...@@ -14,26 +14,25 @@ ...@@ -14,26 +14,25 @@
namespace blink { namespace blink {
// This enum corresponds to each step used to accommodate grid items across
// intrinsic tracks according to their min and max track sizing functions, as
// defined in https://drafts.csswg.org/css-grid-1/#algo-spanning-items.
enum class NGGridItemContributionType {
kForIntrinsicMinimums,
kForContentBasedMinimums,
kForMaxContentMinimums,
kForIntrinsicMaximums,
kForMaxContentMaximums
};
enum class AutoPlacementType { kNotNeeded, kMajor, kMinor, kBoth };
class CORE_EXPORT NGGridLayoutAlgorithm class CORE_EXPORT NGGridLayoutAlgorithm
: public NGLayoutAlgorithm<NGBlockNode, : public NGLayoutAlgorithm<NGBlockNode,
NGBoxFragmentBuilder, NGBoxFragmentBuilder,
NGBlockBreakToken> { NGBlockBreakToken> {
public: public:
enum class AutoPlacementType { kNotNeeded, kMajor, kMinor, kBoth };
enum class AxisEdge { kStart, kCenter, kEnd, kBaseline }; enum class AxisEdge { kStart, kCenter, kEnd, kBaseline };
// This enum corresponds to each step used to accommodate grid items across
// intrinsic tracks according to their min and max track sizing functions, as
// defined in https://drafts.csswg.org/css-grid-1/#algo-spanning-items.
enum class GridItemContributionType {
kForIntrinsicMinimums,
kForContentBasedMinimums,
kForMaxContentMinimums,
kForIntrinsicMaximums,
kForMaxContentMaximums
};
struct GridItemData { struct GridItemData {
explicit GridItemData(const NGBlockNode node); explicit GridItemData(const NGBlockNode node);
...@@ -136,7 +135,7 @@ class CORE_EXPORT NGGridLayoutAlgorithm ...@@ -136,7 +135,7 @@ class CORE_EXPORT NGGridLayoutAlgorithm
LayoutUnit ContributionSizeForGridItem( LayoutUnit ContributionSizeForGridItem(
const GridItemData& grid_item, const GridItemData& grid_item,
GridTrackSizingDirection track_direction, GridTrackSizingDirection track_direction,
NGGridItemContributionType contribution_type) const; GridItemContributionType contribution_type) const;
void ConstructAndAppendGridItems(); void ConstructAndAppendGridItems();
GridItemData MeasureGridItem(const NGBlockNode node); GridItemData MeasureGridItem(const NGBlockNode node);
...@@ -166,9 +165,9 @@ class CORE_EXPORT NGGridLayoutAlgorithm ...@@ -166,9 +165,9 @@ class CORE_EXPORT NGGridLayoutAlgorithm
GridTrackSizingDirection track_direction, GridTrackSizingDirection track_direction,
ReorderedGridItems::Iterator group_begin, ReorderedGridItems::Iterator group_begin,
ReorderedGridItems::Iterator group_end, ReorderedGridItems::Iterator group_end,
NGGridItemContributionType contribution_type); GridItemContributionType contribution_type);
void DistributeExtraSpaceToSets(LayoutUnit extra_space, void DistributeExtraSpaceToSets(LayoutUnit extra_space,
NGGridItemContributionType contribution_type, GridItemContributionType contribution_type,
NGGridSetVector* sets_to_grow, NGGridSetVector* sets_to_grow,
NGGridSetVector* sets_to_grow_beyond_limit); NGGridSetVector* sets_to_grow_beyond_limit);
......
...@@ -58,12 +58,16 @@ void NGGridPlacement::RunAutoPlacementAlgorithm() { ...@@ -58,12 +58,16 @@ void NGGridPlacement::RunAutoPlacementAlgorithm() {
for (NGGridLayoutAlgorithm::GridItemData* grid_item : for (NGGridLayoutAlgorithm::GridItemData* grid_item :
items_not_locked_to_major_axis_) { items_not_locked_to_major_axis_) {
DCHECK(grid_item); DCHECK(grid_item);
const AutoPlacementType item_placement_type = switch (grid_item->AutoPlacement(major_direction_)) {
grid_item->AutoPlacement(major_direction_); case NGGridLayoutAlgorithm::AutoPlacementType::kBoth:
if (item_placement_type == AutoPlacementType::kMajor) { PlaceAutoBothAxisGridItem(*grid_item);
PlaceAutoMajorAxisGridItem(*grid_item); break;
} else if (item_placement_type == AutoPlacementType::kBoth) { case NGGridLayoutAlgorithm::AutoPlacementType::kMajor:
PlaceAutoBothAxisGridItem(*grid_item); PlaceAutoMajorAxisGridItem(*grid_item);
break;
case NGGridLayoutAlgorithm::AutoPlacementType::kMinor:
case NGGridLayoutAlgorithm::AutoPlacementType::kNotNeeded:
break;
} }
} }
} }
...@@ -99,7 +103,7 @@ void NGGridPlacement::PlaceGridItemsLockedToMajorAxis() { ...@@ -99,7 +103,7 @@ void NGGridPlacement::PlaceGridItemsLockedToMajorAxis() {
items_locked_to_major_axis_) { items_locked_to_major_axis_) {
DCHECK(grid_item); DCHECK(grid_item);
DCHECK_EQ(grid_item->AutoPlacement(major_direction_), DCHECK_EQ(grid_item->AutoPlacement(major_direction_),
AutoPlacementType::kMinor); NGGridLayoutAlgorithm::AutoPlacementType::kMinor);
wtf_size_t minor_start; wtf_size_t minor_start;
if (packing_behavior_ == PackingBehavior::kSparse && if (packing_behavior_ == PackingBehavior::kSparse &&
minor_cursors.Contains(grid_item->StartLine(major_direction_) + 1)) { minor_cursors.Contains(grid_item->StartLine(major_direction_) + 1)) {
......
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