Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(63)

Side by Side Diff: third_party/WebKit/Source/core/layout/LayoutGrid.cpp

Issue 2480493002: [css-grid] Use min|max-sizes to compute flex fraction (Closed)
Patch Set: Patch for landing Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/WebKit/Source/core/layout/LayoutGrid.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011 Apple Inc. All rights reserved. 2 * Copyright (C) 2011 Apple Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 855 matching lines...) Expand 10 before | Expand all | Expand 10 after
866 flexFraction = std::max( 866 flexFraction = std::max(
867 flexFraction, 867 flexFraction,
868 findFlexFactorUnitSize( 868 findFlexFactorUnitSize(
869 tracks, span, direction, 869 tracks, span, direction,
870 maxContentForChild(*gridItem, direction, sizingData))); 870 maxContentForChild(*gridItem, direction, sizingData)));
871 } 871 }
872 } 872 }
873 } 873 }
874 } 874 }
875 875
876 for (const auto& trackIndex : flexibleSizedTracksIndex) { 876 LayoutUnit totalGrowth;
877 GridTrackSize trackSize = gridTrackSize(direction, trackIndex); 877 Vector<LayoutUnit> increments;
878 increments.grow(flexibleSizedTracksIndex.size());
879 computeFlexSizedTracksGrowth(direction, tracks, flexibleSizedTracksIndex,
880 flexFraction, increments, totalGrowth);
878 881
882 // We only need to redo the flex fraction computation for indefinite heights
883 // (definite sizes are already constrained by min/max sizes). Regarding
884 // widths, they are always definite at layout time so we shouldn't ever have
885 // to do this.
886 if (!hasDefiniteFreeSpace && direction == ForRows) {
887 auto minSize = computeContentLogicalHeight(
888 MinSize, styleRef().logicalMinHeight(), LayoutUnit(-1));
889 auto maxSize = computeContentLogicalHeight(
890 MaxSize, styleRef().logicalMaxHeight(), LayoutUnit(-1));
891
892 // Redo the flex fraction computation using min|max-height as definite
893 // available space in case the total height is smaller than min-height or
894 // larger than max-height.
895 LayoutUnit rowsSize =
896 totalGrowth + computeTrackBasedLogicalHeight(sizingData);
897 bool checkMinSize = minSize && rowsSize < minSize;
898 bool checkMaxSize = maxSize != -1 && rowsSize > maxSize;
899 if (checkMinSize || checkMaxSize) {
900 LayoutUnit freeSpace = checkMaxSize ? maxSize : LayoutUnit(-1);
901 freeSpace =
902 std::max(freeSpace, minSize) -
903 guttersSize(ForRows, 0, gridRowCount(), sizingData.sizingOperation);
904
905 flexFraction = findFlexFactorUnitSize(
906 tracks, GridSpan::translatedDefiniteGridSpan(0, tracks.size()),
907 ForRows, freeSpace);
908
909 totalGrowth = LayoutUnit(0);
910 computeFlexSizedTracksGrowth(ForRows, tracks, flexibleSizedTracksIndex,
911 flexFraction, increments, totalGrowth);
912 }
913 }
914
915 size_t i = 0;
916 for (auto trackIndex : flexibleSizedTracksIndex) {
917 auto& track = tracks[trackIndex];
918 if (LayoutUnit increment = increments[i++])
919 track.setBaseSize(track.baseSize() + increment);
920 }
921 freeSpace -= totalGrowth;
922 growthLimitsWithoutMaximization += totalGrowth;
923 }
924
925 void LayoutGrid::computeFlexSizedTracksGrowth(
926 GridTrackSizingDirection direction,
927 Vector<GridTrack>& tracks,
928 const Vector<size_t>& flexibleSizedTracksIndex,
929 double flexFraction,
930 Vector<LayoutUnit>& increments,
931 LayoutUnit& totalGrowth) const {
932 size_t numFlexTracks = flexibleSizedTracksIndex.size();
933 DCHECK_EQ(increments.size(), numFlexTracks);
934 for (size_t i = 0; i < numFlexTracks; ++i) {
935 size_t trackIndex = flexibleSizedTracksIndex[i];
936 auto trackSize = gridTrackSize(direction, trackIndex);
937 DCHECK(trackSize.maxTrackBreadth().isFlex());
879 LayoutUnit oldBaseSize = tracks[trackIndex].baseSize(); 938 LayoutUnit oldBaseSize = tracks[trackIndex].baseSize();
880 LayoutUnit baseSize = 939 LayoutUnit newBaseSize =
881 std::max(oldBaseSize, 940 std::max(oldBaseSize,
882 LayoutUnit(flexFraction * trackSize.maxTrackBreadth().flex())); 941 LayoutUnit(flexFraction * trackSize.maxTrackBreadth().flex()));
883 if (LayoutUnit increment = baseSize - oldBaseSize) { 942 increments[i] = newBaseSize - oldBaseSize;
884 tracks[trackIndex].setBaseSize(baseSize); 943 totalGrowth += increments[i];
885 freeSpace -= increment;
886 growthLimitsWithoutMaximization += increment;
887 }
888 } 944 }
889 } 945 }
890 946
891 LayoutUnit LayoutGrid::computeUsedBreadthOfMinLength( 947 LayoutUnit LayoutGrid::computeUsedBreadthOfMinLength(
892 const GridTrackSize& trackSize, 948 const GridTrackSize& trackSize,
893 LayoutUnit maxSize) const { 949 LayoutUnit maxSize) const {
894 const GridLength& gridLength = trackSize.minTrackBreadth(); 950 const GridLength& gridLength = trackSize.minTrackBreadth();
895 if (gridLength.isFlex()) 951 if (gridLength.isFlex())
896 return LayoutUnit(); 952 return LayoutUnit();
897 953
(...skipping 2538 matching lines...) Expand 10 before | Expand all | Expand 10 after
3436 if (!m_gridItemArea.isEmpty()) 3492 if (!m_gridItemArea.isEmpty())
3437 GridPainter(*this).paintChildren(paintInfo, paintOffset); 3493 GridPainter(*this).paintChildren(paintInfo, paintOffset);
3438 } 3494 }
3439 3495
3440 bool LayoutGrid::cachedHasDefiniteLogicalHeight() const { 3496 bool LayoutGrid::cachedHasDefiniteLogicalHeight() const {
3441 SECURITY_DCHECK(m_hasDefiniteLogicalHeight); 3497 SECURITY_DCHECK(m_hasDefiniteLogicalHeight);
3442 return m_hasDefiniteLogicalHeight.value(); 3498 return m_hasDefiniteLogicalHeight.value();
3443 } 3499 }
3444 3500
3445 } // namespace blink 3501 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/layout/LayoutGrid.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698