Przeglądaj źródła

LibWeb: Use code to size spanning tracks for non-spanning tracks in GFC

Since the specifications indicate that the algorithm for sizing tracks
without any spanning items is a simplified version of the more general
algorithm used for sizing tracks with spanning items, we can reuse the
code to size both cases.
Aliaksandr Kalenik 2 lat temu
rodzic
commit
09ef2c14e9

+ 2 - 117
Userland/Libraries/LibWeb/Layout/GridFormattingContext.cpp

@@ -695,126 +695,11 @@ void GridFormattingContext::resolve_intrinsic_track_sizes(AvailableSpace const&
     // across those tracks insofar as possible.
 
     auto& tracks_and_gaps = dimension == GridDimension::Column ? m_grid_columns_and_gaps : m_grid_rows_and_gaps;
-    auto& available_size = dimension == GridDimension::Column ? available_space.width : available_space.height;
 
     // FIXME: 1. Shim baseline-aligned items so their intrinsic size contributions reflect their baseline alignment.
 
-    // 2. Size tracks to fit non-spanning items: For each track with an intrinsic track sizing function and
-    // not a flexible sizing function, consider the items in it with a span of 1:
-
-    size_t index = 0;
-    for (auto& track : tracks_and_gaps) {
-        if (track.is_gap) {
-            ++index;
-            continue;
-        }
-
-        Vector<GridItem&> grid_items_of_track;
-        for (auto& grid_item : m_grid_items) {
-            if (dimension == GridDimension::Column) {
-                if (grid_item.gap_adjusted_column(grid_container()) == index && grid_item.raw_column_span() == 1) {
-                    grid_items_of_track.append(grid_item);
-                }
-            } else {
-                if (grid_item.gap_adjusted_row(grid_container()) == index && grid_item.raw_row_span() == 1) {
-                    grid_items_of_track.append(grid_item);
-                }
-            }
-        }
-
-        if (grid_items_of_track.size() == 0) {
-            ++index;
-            continue;
-        }
-
-        if (!track.min_track_sizing_function.is_intrinsic_track_sizing() && !track.max_track_sizing_function.is_intrinsic_track_sizing()) {
-            ++index;
-            continue;
-        }
-
-        switch (track.min_track_sizing_function.type()) {
-        case CSS::GridSize::Type::MinContent: {
-            // If the track has a min-content min track sizing function, set its base size to the maximum of the
-            // items’ min-content contributions, floored at zero.
-            CSSPixels base_size = 0;
-            for (auto& item : grid_items_of_track) {
-                base_size = max(base_size, calculate_min_content_contribution(item, dimension));
-            }
-            track.base_size = base_size;
-        } break;
-        case CSS::GridSize::Type::MaxContent: {
-            // If the track has a max-content min track sizing function, set its base size to the maximum of the
-            // items’ max-content contributions, floored at zero.
-            CSSPixels base_size = 0;
-            for (auto& item : grid_items_of_track) {
-                base_size = max(base_size, calculate_max_content_contribution(item, dimension));
-            }
-            track.base_size = base_size;
-        } break;
-        case CSS::GridSize::Type::LengthPercentage: {
-            if (track.min_track_sizing_function.is_auto() && available_size.is_intrinsic_sizing_constraint()) {
-                // If the track has an auto min track sizing function and the grid container is being sized under a
-                // min-/max-content constraint, set the track’s base size to the maximum of its items’ limited
-                // min-/max-content contributions (respectively), floored at zero.
-                if (available_size.is_min_content()) {
-                    CSSPixels base_size = 0;
-                    for (auto& item : grid_items_of_track) {
-                        base_size = max(base_size, calculate_limited_min_content_contribution(item, dimension));
-                    }
-                    track.base_size = base_size;
-                } else if (available_size.is_max_content()) {
-                    CSSPixels base_size = 0;
-                    for (auto& item : grid_items_of_track) {
-                        base_size = max(base_size, calculate_limited_max_content_contribution(item, dimension));
-                    }
-                    track.base_size = base_size;
-                }
-            } else if (track.min_track_sizing_function.is_auto()) {
-                // Otherwise, set the track’s base size to the maximum of its items’ minimum contributions, floored at zero.
-                CSSPixels base_size = 0;
-                for (auto& item : grid_items_of_track) {
-                    base_size = max(base_size, calculate_minimum_contribution(item, dimension));
-                }
-                track.base_size = base_size;
-            }
-
-            break;
-        }
-        case CSS::GridSize::Type::FlexibleLength: {
-            // do nothing
-            break;
-        }
-        default:
-            VERIFY_NOT_REACHED();
-        }
-
-        auto const& max_track_sizing_function = track.max_track_sizing_function;
-        if (max_track_sizing_function.is_min_content()) {
-            // If the track has a min-content max track sizing function, set its growth limit to the maximum of
-            // the items’ min-content contributions.
-            CSSPixels growth_limit = 0;
-            for (auto& item : grid_items_of_track) {
-                growth_limit = max(growth_limit, calculate_min_content_contribution(item, dimension));
-            }
-            track.growth_limit = growth_limit;
-        } else if (max_track_sizing_function.is_max_content() || max_track_sizing_function.is_auto()) {
-            // If the track has a max-content max track sizing function, set its growth limit to the maximum of
-            // the items’ max-content contributions. For fit-content() maximums, furthermore clamp this growth
-            // limit by the fit-content() argument.
-            CSSPixels growth_limit = 0;
-            for (auto& item : grid_items_of_track) {
-                growth_limit = max(growth_limit, calculate_max_content_contribution(item, dimension));
-            }
-            track.growth_limit = growth_limit;
-        }
-
-        // In all cases, if a track’s growth limit is now less than its base size, increase the growth limit
-        // to match the base size.
-        if (track.growth_limit < track.base_size)
-            track.growth_limit = track.base_size;
-
-        ++index;
-    }
+    // 2. Size tracks to fit non-spanning items:
+    increase_sizes_to_accommodate_spanning_items_crossing_content_sized_tracks(available_space, dimension, 1);
 
     // https://www.w3.org/TR/css-grid-2/#auto-repeat
     // The auto-fit keyword behaves the same as auto-fill, except that after grid item placement any