// Copyright 2020 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef THIRD_PARTY_BLINK_RENDERER_CORE_LAYOUT_GRID_GRID_TRACK_COLLECTION_H_ #define THIRD_PARTY_BLINK_RENDERER_CORE_LAYOUT_GRID_GRID_TRACK_COLLECTION_H_ #include "base/check_op.h" #include "third_party/blink/renderer/core/core_export.h" #include "third_party/blink/renderer/core/style/computed_style.h" #include "third_party/blink/renderer/platform/wtf/text/wtf_string.h" namespace blink { class GridLineResolver; // |GridTrackCollectionBase| provides an implementation for some shared // functionality on grid collections, specifically binary search on the // collection to get the range that contains a specific grid line. class CORE_EXPORT GridTrackCollectionBase { … }; class CORE_EXPORT TrackSpanProperties { … }; struct CORE_EXPORT GridRange { … }; GridRangeVector; class CORE_EXPORT GridRangeBuilder { … }; class CORE_EXPORT GridLayoutTrackCollection : public GridTrackCollectionBase { … }; // |GridRangeBuilder::EnsureTrackCoverage| may introduce a range start and/or // end at the middle of any repeater from the block collection. This will affect // how some repeated tracks within the same repeater group resolve their track // sizes; e.g. consider the track list 'repeat(10, auto)' with a grid item // spanning from the 3rd to the 7th track in the repeater, every track within // the item's range will grow to fit the content of that item first. // // For the track sizing algorithm we want to have separate data (e.g. base size, // growth limit, etc.) between tracks in different ranges; instead of trivially // expanding the repeaters, which will limit our implementation to support // relatively small track counts, we introduce the concept of a "set". // // A "set" is a collection of distinct track definitions that compose a range in // |GridSizingTrackCollection|; each set element stores the number of tracks // within the range that share its definition. The |GridSet| class represents // a single element from a set. // // As an example, consider the following grid definition: // - 'grid-template-columns: repeat(4, 5px 1fr)' // - Grid item 1 with 'grid-column: 1 / span 5' // - Grid item 2 with 'grid-column: 2 / span 1' // - Grid item 3 with 'grid-column: 6 / span 8' // // Expanding the track definitions above we would look at the explicit grid: // | 5px | 1fr | 5px | 1fr | 5px | 1fr | 5px | 1fr | // // This example would produce the following ranges and their respective sets: // Range 1: [1-1], Set 1: { 5px (1) } // Range 2: [2-2], Set 2: { 1fr (1) } // Range 3: [3-5], Set 3: { 5px (2) , 1fr (1) } // Range 4: [6-8], Set 4: { 1fr (2) , 5px (1) } // Range 5: [9-13], Set 5: { auto (5) } // // Note that, since |GridRangeBuilder|'s ranges are assured to span a single // repeater and to not cross any grid item's boundary in the respective // dimension, tracks within a set are "commutative" and can be sized evenly. struct CORE_EXPORT GridSet { … }; class CORE_EXPORT GridSizingTrackCollection final : public GridLayoutTrackCollection { … }; template <> struct DowncastTraits<GridSizingTrackCollection> { … }; } // namespace blink WTF_ALLOW_MOVE_INIT_AND_COMPARE_WITH_MEM_FUNCTIONS(…) WTF_ALLOW_MOVE_INIT_AND_COMPARE_WITH_MEM_FUNCTIONS(…) #endif // THIRD_PARTY_BLINK_RENDERER_CORE_LAYOUT_GRID_GRID_TRACK_COLLECTION_H_