@@ -998,120 +998,66 @@ LayoutUnit GridLayoutAlgorithm::ContributionSizeForGridItem(
998998 : BlockContributionSize ();
999999 break ;
10001000 case GridItemContributionType::kForIntrinsicMinimums : {
1001- // TODO(ikilpatrick): All of the below is incorrect for replaced elements.
1002- const auto & main_length = is_parallel_with_track_direction
1003- ? item_style.LogicalWidth ()
1004- : item_style.LogicalHeight ();
1005- const auto & min_length = is_parallel_with_track_direction
1006- ? item_style.LogicalMinWidth ()
1007- : item_style.LogicalMinHeight ();
1008-
1009- // We could be clever is and make this an if-stmt, but each type has
1010- // subtle consequences. This forces us in the future when we add a new
1011- // length type to consider what the best thing is for grid.
1012- switch (main_length.GetType ()) {
1013- case Length::kAuto :
1014- case Length::kFitContent :
1015- case Length::kStretch :
1016- case Length::kPercent :
1017- case Length::kCalculated : {
1018- const auto border_padding =
1019- ComputeBorders (space, node) + ComputePadding (space, item_style);
1020-
1021- // All of the above lengths are considered 'auto' if we are querying a
1022- // minimum contribution. They all require definite track sizes to
1023- // determine their final size.
1024- //
1025- // From https://drafts.csswg.org/css-grid/#min-size-auto:
1026- // To provide a more reasonable default minimum size for grid items,
1027- // the used value of its automatic minimum size in a given axis is
1028- // the content-based minimum size if all of the following are true:
1029- // - it is not a scroll container
1030- // - it spans at least one track in that axis whose min track
1031- // sizing function is 'auto'
1032- // - if it spans more than one track in that axis, none of those
1033- // tracks are flexible
1034- // Otherwise, the automatic minimum size is zero, as usual.
1035- //
1036- // Start by resolving the cases where |min_length| is non-auto or its
1037- // automatic minimum size should be zero.
1038- if (!min_length.HasAuto () || item_style.IsScrollContainer () ||
1039- !grid_item->IsSpanningAutoMinimumTrack (track_direction) ||
1040- (grid_item->IsSpanningFlexibleTrack (track_direction) &&
1041- grid_item->SpanSize (track_direction) > 1 )) {
1042- // TODO(ikilpatrick): This block needs to respect the aspect-ratio,
1043- // and apply the transferred min/max sizes when appropriate. We do
1044- // this sometimes elsewhere so should unify and simplify this code.
1045- if (is_parallel_with_track_direction) {
1046- contribution =
1047- ResolveMinInlineLength (space, item_style, border_padding,
1048- MinMaxSizesFunc, min_length);
1049- } else {
1050- contribution = ResolveInitialMinBlockLength (
1051- space, item_style, border_padding, min_length);
1052- }
1053- break ;
1054- }
1055-
1056- // Resolve the content-based minimum size.
1057- contribution = is_parallel_with_track_direction
1058- ? MinContentSize ()
1059- : BlockContributionSize ();
1060-
1061- auto spanned_tracks_definite_max_size =
1062- track_collection.CalculateSetSpanSize (begin_set_index,
1063- end_set_index);
1064-
1065- if (spanned_tracks_definite_max_size != kIndefiniteSize ) {
1066- // Further clamp the minimum size to less than or equal to the
1067- // stretch fit into the grid area’s maximum size in that dimension,
1068- // as represented by the sum of those grid tracks’ max track sizing
1069- // functions plus any intervening fixed gutters.
1070- const auto border_padding_sum = is_parallel_with_track_direction
1071- ? border_padding.InlineSum ()
1072- : border_padding.BlockSum ();
1073- DCHECK_GE (contribution, baseline_shim + border_padding_sum);
1074-
1075- // The stretch fit into a given size is that size, minus the box’s
1076- // computed margins, border, and padding in the given dimension,
1077- // flooring at zero so that the inner size is not negative.
1078- spanned_tracks_definite_max_size =
1079- (spanned_tracks_definite_max_size - baseline_shim - margin_sum -
1080- border_padding_sum)
1081- .ClampNegativeToZero ();
1082-
1083- // Add the baseline shim, border, and padding (margins will be added
1084- // later) back to the contribution, since we don't want the outer
1085- // size of the minimum size to overflow its grid area; these are
1086- // already accounted for in the current value of `contribution`.
1087- contribution =
1088- std::min (contribution, spanned_tracks_definite_max_size +
1089- baseline_shim + border_padding_sum);
1090- }
1091- break ;
1092- }
1093- case Length::kMinContent :
1094- case Length::kMaxContent :
1095- case Length::kFixed : {
1096- // All of the above lengths are "definite" (non-auto), and don't need
1097- // the special min-size treatment above. (They will all end up being
1098- // the specified size).
1099- if (is_parallel_with_track_direction) {
1100- contribution = main_length.IsMaxContent () ? MaxContentSize ()
1101- : MinContentSize ();
1102- } else {
1103- contribution = BlockContributionSize ();
1104- }
1105- break ;
1001+ // See https://drafts.csswg.org/css-grid/#min-size-auto for more details
1002+ // on the special logic applied for intrinsic minimums.
1003+ //
1004+ // Per the spec link above, we apply the automatic min when:
1005+ // - it spans at least one track in that axis whose min track sizing
1006+ // function is auto.
1007+ // - if it spans more than one track in that axis, none of those tracks
1008+ // are flexible.
1009+ const bool special_spanning_criteria =
1010+ !grid_item->IsSpanningAutoMinimumTrack (track_direction) ||
1011+ (grid_item->IsSpanningFlexibleTrack (track_direction) &&
1012+ grid_item->SpanSize (track_direction) > 1 );
1013+
1014+ const LayoutUnit min_content_contribution =
1015+ is_parallel_with_track_direction ? MinContentSize ()
1016+ : BlockContributionSize ();
1017+ const LayoutUnit max_content_contribution =
1018+ is_parallel_with_track_direction ? MaxContentSize ()
1019+ : min_content_contribution;
1020+
1021+ MinMaxSizesResult subgrid_minmax_sizes;
1022+ if (grid_item->IsSubgrid ()) {
1023+ const GridSizingSubtree& subgrid_sizing_subtree =
1024+ sizing_subtree.SubgridSizingSubtree (*grid_item);
1025+ if (subgrid_sizing_subtree.LayoutData ().IsSubgridWithStandaloneAxis (
1026+ kForColumns )) {
1027+ subgrid_minmax_sizes = To<GridNode>(node).ComputeSubgridMinMaxSizes (
1028+ subgrid_sizing_subtree, space);
11061029 }
1107- case Length::kMinIntrinsic :
1108- case Length::kFlex :
1109- case Length::kExtendToZoom :
1110- case Length::kDeviceWidth :
1111- case Length::kDeviceHeight :
1112- case Length::kNone :
1113- case Length::kContent :
1114- NOTREACHED ();
1030+ }
1031+
1032+ bool maybe_clamp = false ;
1033+ contribution = CalculateIntrinsicMinimumContribution (
1034+ is_parallel_with_track_direction, special_spanning_criteria,
1035+ min_content_contribution, max_content_contribution, space,
1036+ subgrid_minmax_sizes, grid_item, maybe_clamp);
1037+
1038+ if (!maybe_clamp) {
1039+ break ;
1040+ }
1041+
1042+ // Further clamp the minimum size to less than or equal to the
1043+ // stretch fit into the grid area’s maximum size in that dimension,
1044+ // as represented by the sum of those grid tracks’ max track sizing
1045+ // functions plus any intervening fixed gutters.
1046+ auto spanned_tracks_definite_max_size =
1047+ track_collection.CalculateSetSpanSize (begin_set_index, end_set_index);
1048+ if (spanned_tracks_definite_max_size != kIndefiniteSize ) {
1049+ contribution += margin_sum;
1050+ const auto border_padding =
1051+ ComputeBorders (space, node) + ComputePadding (space, item_style);
1052+ const auto border_padding_sum = is_parallel_with_track_direction
1053+ ? border_padding.InlineSum ()
1054+ : border_padding.BlockSum ();
1055+
1056+ contribution = ClampIntrinsicMinSize (
1057+ contribution,
1058+ /* min_clamp_size=*/ margin_sum + baseline_shim + border_padding_sum,
1059+ spanned_tracks_definite_max_size);
1060+ contribution -= margin_sum;
11151061 }
11161062 break ;
11171063 }
0 commit comments