Changeset 139025 in webkit


Ignore:
Timestamp:
Jan 7, 2013 6:41:22 PM (11 years ago)
Author:
jchaffraix@webkit.org
Message:

[CSS Grid Layout] Implement grid items sizing for fixed minmax grid tracks
https://bugs.webkit.org/show_bug.cgi?id=104700

Reviewed by Tony Chang.

Source/WebCore:

This change implements parts of the minmax() track sizing algorithm. The chosen subset enables us
to resolve any sizing function that doesn't size based on the content (min-content, max-content).

Tests: fast/css-grid-layout/minmax-fixed-logical-height-only.html

fast/css-grid-layout/minmax-fixed-logical-width-only.html

  • rendering/RenderGrid.cpp:

(WebCore::GridTrack::GridTrack):
Added a new member to hold the maximum track breadth.

(WebCore::RenderGrid::computePreferredLogicalWidths):
(WebCore::RenderGrid::computedUsedBreadthOfGridTracks):
Updated these functions to work on both min and max track breadth. In order to match
the specification, if max track breadth < min track breadth, we ignore the max track breadth.
For computedUsedBreadthOfGridTracks, it also involves calling distributeSpaceToTracks.

(WebCore::RenderGrid::computeUsedBreadthOfLength):
New helper function that compute a single length's size.

(WebCore::sortByGridTrackGrowthPotential):
Ordering function for the sorting the track: it orders the track per increasing potential
growth (defined as the difference between max breadth and the currently used breadth).

(WebCore::RenderGrid::distributeSpaceToTracks):
Added this function that matches the specification's algorithm. Only the relevant bits from
the specification were implemented for now (for example, SubsetOfTracksForGrowthBeyondTrackGrowthConstraint
is always the empty set so it was omitted).

  • rendering/RenderGrid.h:

Added the new functions and declared GridTrack as public into the WebCore namespace.

  • rendering/style/GridTrackSize.h:

(WebCore::GridTrackSize::minTrackBreadth):
(WebCore::GridTrackSize::maxTrackBreadth):
Removed 2 ASSERTs as the layout algorithm doesn't care if the min / max were
set from a single track breadth or through minmax().

LayoutTests:

  • fast/css-grid-layout/minmax-fixed-logical-height-only-expected.txt: Added.
  • fast/css-grid-layout/minmax-fixed-logical-height-only.html: Added.
  • fast/css-grid-layout/minmax-fixed-logical-width-only-expected.txt: Added.
  • fast/css-grid-layout/minmax-fixed-logical-width-only.html: Added.
Location:
trunk
Files:
4 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r139024 r139025  
     12013-01-07  Julien Chaffraix  <jchaffraix@webkit.org>
     2
     3        [CSS Grid Layout] Implement grid items sizing for fixed minmax grid tracks
     4        https://bugs.webkit.org/show_bug.cgi?id=104700
     5
     6        Reviewed by Tony Chang.
     7
     8        * fast/css-grid-layout/minmax-fixed-logical-height-only-expected.txt: Added.
     9        * fast/css-grid-layout/minmax-fixed-logical-height-only.html: Added.
     10        * fast/css-grid-layout/minmax-fixed-logical-width-only-expected.txt: Added.
     11        * fast/css-grid-layout/minmax-fixed-logical-width-only.html: Added.
     12
    1132013-01-07  Xianzhu Wang  <wangxianzhu@chromium.org>
    214
  • trunk/Source/WebCore/ChangeLog

    r139024 r139025  
     12013-01-07  Julien Chaffraix  <jchaffraix@webkit.org>
     2
     3        [CSS Grid Layout] Implement grid items sizing for fixed minmax grid tracks
     4        https://bugs.webkit.org/show_bug.cgi?id=104700
     5
     6        Reviewed by Tony Chang.
     7
     8        This change implements parts of the minmax() track sizing algorithm. The chosen subset enables us
     9        to resolve any sizing function that doesn't size based on the content (min-content, max-content).
     10
     11        Tests: fast/css-grid-layout/minmax-fixed-logical-height-only.html
     12               fast/css-grid-layout/minmax-fixed-logical-width-only.html
     13
     14        * rendering/RenderGrid.cpp:
     15        (WebCore::GridTrack::GridTrack):
     16        Added a new member to hold the maximum track breadth.
     17
     18        (WebCore::RenderGrid::computePreferredLogicalWidths):
     19        (WebCore::RenderGrid::computedUsedBreadthOfGridTracks):
     20        Updated these functions to work on both min and max track breadth. In order to match
     21        the specification, if max track breadth < min track breadth, we ignore the max track breadth.
     22        For computedUsedBreadthOfGridTracks, it also involves calling distributeSpaceToTracks.
     23
     24        (WebCore::RenderGrid::computeUsedBreadthOfLength):
     25        New helper function that compute a single length's size.
     26
     27        (WebCore::sortByGridTrackGrowthPotential):
     28        Ordering function for the sorting the track: it orders the track per increasing potential
     29        growth (defined as the difference between max breadth and the currently used breadth).
     30
     31        (WebCore::RenderGrid::distributeSpaceToTracks):
     32        Added this function that matches the specification's algorithm. Only the relevant bits from
     33        the specification were implemented for now (for example, SubsetOfTracksForGrowthBeyondTrackGrowthConstraint
     34        is always the empty set so it was omitted).
     35
     36        * rendering/RenderGrid.h:
     37        Added the new functions and declared GridTrack as public into the WebCore namespace.
     38
     39        * rendering/style/GridTrackSize.h:
     40        (WebCore::GridTrackSize::minTrackBreadth):
     41        (WebCore::GridTrackSize::maxTrackBreadth):
     42        Removed 2 ASSERTs as the layout algorithm doesn't care if the min / max were
     43        set from a single track breadth or through minmax().
     44
    1452013-01-07  Xianzhu Wang  <wangxianzhu@chromium.org>
    246
  • trunk/Source/WebCore/rendering/RenderGrid.cpp

    r137560 r139025  
    3434namespace WebCore {
    3535
    36 class RenderGrid::GridTrack {
     36class GridTrack {
    3737public:
    3838    GridTrack()
    3939        : m_usedBreadth(0)
     40        , m_maxBreadth(0)
    4041    {
    4142    }
    4243
    4344    LayoutUnit m_usedBreadth;
     45    LayoutUnit m_maxBreadth;
    4446};
    4547
     
    120122
    121123    for (size_t i = 0; i < trackStyles.size(); ++i) {
    122         Length trackLength = trackStyles[i].length();
    123         if (!trackLength.isFixed()) {
     124        const Length& minTrackLength = trackStyles[i].minTrackBreadth();
     125        const Length& maxTrackLength = trackStyles[i].maxTrackBreadth();
     126        // FIXME: Handle only one fixed length properly (e.g minmax(100px, max-content)).
     127        if (!minTrackLength.isFixed() || !maxTrackLength.isFixed()) {
    124128            notImplemented();
    125129            continue;
    126130        }
    127131
    128         m_minPreferredLogicalWidth += trackLength.intValue();
    129         m_maxPreferredLogicalWidth += trackLength.intValue();
     132        LayoutUnit minTrackBreadth = minTrackLength.intValue();
     133        LayoutUnit maxTrackBreadth = maxTrackLength.intValue();
     134
     135        maxTrackBreadth = std::max(maxTrackBreadth, minTrackBreadth);
     136
     137        m_minPreferredLogicalWidth += minTrackBreadth;
     138        m_maxPreferredLogicalWidth += maxTrackBreadth;
    130139    }
    131140
     
    142151{
    143152    const Vector<GridTrackSize>& trackStyles = (direction == ForColumns) ? style()->gridColumns() : style()->gridRows();
     153    LayoutUnit availableLogicalSpace = (direction == ForColumns) ? availableLogicalWidth() : availableLogicalHeight(IncludeMarginBorderPadding);
    144154    for (size_t i = 0; i < trackStyles.size(); ++i) {
    145155        GridTrack track;
    146         switch (trackStyles[i].type()) {
    147         case LengthTrackSizing: {
    148             Length trackLength = trackStyles[i].length();
    149             // FIXME: We stil need to support calc() here (bug 103761).
    150             if (trackLength.isFixed() || trackLength.isPercent() || trackLength.isViewportPercentage())
    151                 track.m_usedBreadth = valueForLength(trackLength, direction == ForColumns ? logicalWidth() : computeContentLogicalHeight(MainOrPreferredSize, style()->logicalHeight()), view());
    152             else
    153                 notImplemented();
    154 
    155             break;
    156         }
    157         case MinMaxTrackSizing:
    158             // FIXME: Implement support for minmax track sizing (bug 103311).
    159             notImplemented();
    160         }
     156        const Length& minTrackBreadth = trackStyles[i].minTrackBreadth();
     157        const Length& maxTrackBreadth = trackStyles[i].maxTrackBreadth();
     158
     159        track.m_usedBreadth = computeUsedBreadthOfLength(direction, minTrackBreadth);
     160        track.m_maxBreadth = computeUsedBreadthOfLength(direction, maxTrackBreadth);
     161
     162        track.m_maxBreadth = std::max(track.m_maxBreadth, track.m_usedBreadth);
     163
     164        availableLogicalSpace -= track.m_usedBreadth;
     165
    161166        tracks.append(track);
    162167    }
     168
     169    // FIXME: Implement content-based sizing (step 2 of the algorithm).
     170
     171    if (availableLogicalSpace <= 0)
     172        return;
     173
     174    distributeSpaceToTracks(direction, tracks, availableLogicalSpace);
     175}
     176
     177LayoutUnit RenderGrid::computeUsedBreadthOfLength(TrackSizingDirection direction, const Length& trackLength)
     178{
     179    // FIXME: We still need to support calc() here (bug 103761).
     180    if (trackLength.isFixed() || trackLength.isPercent() || trackLength.isViewportPercentage())
     181        return valueForLength(trackLength, direction == ForColumns ? logicalWidth() : computeContentLogicalHeight(MainOrPreferredSize, style()->logicalHeight()), view());
     182
     183    notImplemented();
     184    return 0;
     185}
     186
     187static bool sortByGridTrackGrowthPotential(GridTrack* track1, GridTrack* track2)
     188{
     189    return (track1->m_maxBreadth - track1->m_usedBreadth) <= (track2->m_maxBreadth - track2->m_usedBreadth);
     190}
     191
     192void RenderGrid::distributeSpaceToTracks(TrackSizingDirection, Vector<GridTrack>& tracks, LayoutUnit availableLogicalSpace)
     193{
     194    const size_t tracksSize = tracks.size();
     195    Vector<GridTrack*> sortedTracks(tracksSize);
     196    for (size_t i = 0; i < tracksSize; ++i)
     197        sortedTracks[i] = tracks.data() + i;
     198
     199    std::sort(sortedTracks.begin(), sortedTracks.end(), sortByGridTrackGrowthPotential);
     200
     201    for (size_t i = 0; i < tracksSize; ++i) {
     202        GridTrack& track = *sortedTracks[i];
     203        LayoutUnit availableLogicalSpaceShare = availableLogicalSpace / (tracksSize - i);
     204        LayoutUnit growthShare = std::min(availableLogicalSpaceShare, track.m_maxBreadth - track.m_usedBreadth);
     205        track.m_usedBreadth += growthShare;
     206        availableLogicalSpace -= growthShare;
     207    }
     208
     209    // FIXME: We don't implement the last 2 steps of the algorithm as we don't implement content based sizing.
    163210}
    164211
  • trunk/Source/WebCore/rendering/RenderGrid.h

    r136465 r139025  
    3131namespace WebCore {
    3232
     33class GridTrack;
     34
    3335class RenderGrid : public RenderBlock {
    3436public:
     
    4749    virtual bool isRenderGrid() const OVERRIDE { return true; }
    4850
    49     class GridTrack;
    5051    enum TrackSizingDirection { ForColumns, ForRows };
    5152    void computedUsedBreadthOfGridTracks(TrackSizingDirection, Vector<GridTrack>&);
     53    LayoutUnit computeUsedBreadthOfLength(TrackSizingDirection, const Length&);
     54    void distributeSpaceToTracks(TrackSizingDirection, Vector<GridTrack>&, LayoutUnit availableLogicalSpace);
    5255    void layoutGridItems();
    5356
  • trunk/Source/WebCore/rendering/style/GridTrackSize.h

    r136588 r139025  
    6767    const Length& minTrackBreadth() const
    6868    {
    69         ASSERT(m_type == MinMaxTrackSizing);
    7069        ASSERT(!m_minTrackBreadth.isUndefined());
    7170        return m_minTrackBreadth;
     
    7473    const Length& maxTrackBreadth() const
    7574    {
    76         ASSERT(m_type == MinMaxTrackSizing);
    7775        ASSERT(!m_maxTrackBreadth.isUndefined());
    7876        return m_maxTrackBreadth;
Note: See TracChangeset for help on using the changeset viewer.