RESOLVED FIXED 161379
[css-grid] Implement fit-content track size
https://bugs.webkit.org/show_bug.cgi?id=161379
Summary [css-grid] Implement fit-content track size
Sergio Villar Senin
Reported 2016-08-30 07:20:52 PDT
[css-grid] Implement fit-content track size
Attachments
Patch (89.07 KB, patch)
2016-08-30 07:43 PDT, Sergio Villar Senin
no flags
Patch (88.73 KB, patch)
2016-08-30 08:08 PDT, Sergio Villar Senin
no flags
Patch (106.85 KB, patch)
2016-08-31 09:49 PDT, Sergio Villar Senin
no flags
Patch (108.04 KB, patch)
2016-09-07 04:15 PDT, Sergio Villar Senin
no flags
Patch for landing (107.79 KB, patch)
2016-09-15 09:26 PDT, Sergio Villar Senin
no flags
Sergio Villar Senin
Comment 1 2016-08-30 07:43:24 PDT
WebKit Commit Bot
Comment 2 2016-08-30 07:44:47 PDT
Attachment 287390 [details] did not pass style-queue: ERROR: Source/WebCore/css/CSSComputedStyleDeclaration.cpp:1033: Weird number of spaces at line-start. Are you using a 4-space indent? [whitespace/indent] [3] ERROR: Source/WebCore/css/CSSComputedStyleDeclaration.cpp:1034: Weird number of spaces at line-start. Are you using a 4-space indent? [whitespace/indent] [3] ERROR: Source/WebCore/css/CSSComputedStyleDeclaration.cpp:1035: Weird number of spaces at line-start. Are you using a 4-space indent? [whitespace/indent] [3] Total errors found: 3 in 13 files If any of these errors are false positives, please file a bug against check-webkit-style.
Sergio Villar Senin
Comment 3 2016-08-30 08:08:21 PDT
Javier Fernandez
Comment 4 2016-08-30 08:43:21 PDT
Comment on attachment 287392 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=287392&action=review > Source/WebCore/rendering/RenderGrid.cpp:416 > +void RenderGrid::computeTrackSizesForDirection(GridTrackSizingDirection direction, GridSizingData& sizingData, LayoutUnit availableSpace) Perhaps it'd be a good idea to start removing the "ForDirection" suffix we have in many functions, as you have done already with the freeSpace/setFreeSpace methods. > Source/WebCore/rendering/RenderGrid.cpp:420 > + sizingData.setAvailableSpace(availableSpace); Why gutters are not subtracted from availableSpace, as we do with freeSpace ? > Source/WebCore/rendering/RenderGrid.cpp:690 > + const bool hasDefiniteFreeSpace = sizingData.sizingOperation == TrackSizing; Is this really true for both axis ? > Source/WebCore/rendering/RenderGrid.cpp:1186 > +static LayoutUnit trackSizeForTrackSizeComputationPhase(TrackSizeComputationPhase phase, GridTrack& track, TrackSizeRestriction restriction) const GridTrack& track > Source/WebCore/rendering/RenderGrid.cpp:1439 > + const LayoutUnit maxSize = sizingData.freeSpace(direction).valueOr(0); Why const ?
Javier Fernandez
Comment 5 2016-08-30 13:02:11 PDT
Comment on attachment 287392 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=287392&action=review I think the patch lacks of tests for the new parsing logic added. > Source/WebCore/css/parser/CSSParser.cpp:5936 > + auto* arguments = downcast<CSSFunctionValue>(value).arguments(); Perhaps better using a reference. auto& arguments = Otherwise we should have nullchecks afterwards. > Source/WebCore/rendering/RenderGrid.cpp:44 > +enum TrackSizeRestriction { Wouldn't be enough a boolean variable instead of such a simple enumeration ? > Source/WebCore/rendering/RenderGrid.cpp:704 > + track.setGrowthLimitCap(valueForLength(gridLength.length(), maxSize)); we may call gridLength.length() even in the case that !gridLength.isLength() Is that correct ? > LayoutTests/fast/css-grid-layout/fit-content-columns-expected.html:70 > + <div class="item">XXX</div> Wouldn't be clearer with some indentation ?
Sergio Villar Senin
Comment 6 2016-08-31 04:21:14 PDT
(In reply to comment #4) > Comment on attachment 287392 [details] > Patch > > View in context: > https://bugs.webkit.org/attachment.cgi?id=287392&action=review > > > Source/WebCore/rendering/RenderGrid.cpp:416 > > +void RenderGrid::computeTrackSizesForDirection(GridTrackSizingDirection direction, GridSizingData& sizingData, LayoutUnit availableSpace) > > Perhaps it'd be a good idea to start removing the "ForDirection" suffix we > have in many functions, as you have done already with the > freeSpace/setFreeSpace methods. Yes definitely. They make names more complex without a clear reason. > > Source/WebCore/rendering/RenderGrid.cpp:420 > > + sizingData.setAvailableSpace(availableSpace); > > Why gutters are not subtracted from availableSpace, as we do with freeSpace ? Because the available space is the one you have to put tracks and gutters. The free space on the other hand is the one that is free after sizing tracks. > > Source/WebCore/rendering/RenderGrid.cpp:690 > > + const bool hasDefiniteFreeSpace = sizingData.sizingOperation == TrackSizing; > > Is this really true for both axis ? Yes. > > Source/WebCore/rendering/RenderGrid.cpp:1186 > > +static LayoutUnit trackSizeForTrackSizeComputationPhase(TrackSizeComputationPhase phase, GridTrack& track, TrackSizeRestriction restriction) > > const GridTrack& track > > > Source/WebCore/rendering/RenderGrid.cpp:1439 > > + const LayoutUnit maxSize = sizingData.freeSpace(direction).valueOr(0); > > Why const ? Well because we do not want to modify it.
Sergio Villar Senin
Comment 7 2016-08-31 05:44:59 PDT
Comment on attachment 287392 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=287392&action=review Thanks for the review! >> Source/WebCore/css/parser/CSSParser.cpp:5936 >> + auto* arguments = downcast<CSSFunctionValue>(value).arguments(); > > Perhaps better using a reference. > auto& arguments = > > Otherwise we should have nullchecks afterwards. OK >> Source/WebCore/rendering/RenderGrid.cpp:44 >> +enum TrackSizeRestriction { > > Wouldn't be enough a boolean variable instead of such a simple enumeration ? There is literature about why enums are much better than booleans for the APIs. See for example https://blogs.msdn.microsoft.com/brada/2004/01/12/design-guidelines-update-enums-vs-boolean-arguments/ >> Source/WebCore/rendering/RenderGrid.cpp:704 >> + track.setGrowthLimitCap(valueForLength(gridLength.length(), maxSize)); > > we may call gridLength.length() even in the case that !gridLength.isLength() > Is that correct ? That's indeed a mistake, good catch. The actual condition is (!gridLength.isPercentage() || hasDefiniteFreeSpace) >>> Source/WebCore/rendering/RenderGrid.cpp:1186 >>> +static LayoutUnit trackSizeForTrackSizeComputationPhase(TrackSizeComputationPhase phase, GridTrack& track, TrackSizeRestriction restriction) >> >> const GridTrack& track > > Well because we do not want to modify it. Sorry this comment was not for this line. >> LayoutTests/fast/css-grid-layout/fit-content-columns-expected.html:70 >> + <div class="item">XXX</div> > > Wouldn't be clearer with some indentation ? Sure, I should have done something wrong before uploading...
Sergio Villar Senin
Comment 8 2016-08-31 09:49:42 PDT
Darin Adler
Comment 9 2016-09-03 12:39:39 PDT
Comment on attachment 287517 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=287517&action=review > Source/WebCore/rendering/RenderGrid.cpp:719 > ASSERT(!track.growthLimitIsInfinite()); RenderGrid.cpp:719:23: error: 'growthLimitIsInfinite' is a private member of 'WebCore::GridTrack'
Sergio Villar Senin
Comment 10 2016-09-07 04:15:00 PDT
Manuel Rego Casasnovas
Comment 11 2016-09-09 07:25:30 PDT
Comment on attachment 288128 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=288128&action=review Amazing patch! I've to admit that I don't get all the details of the track sizing algorithm though. > Source/WebCore/css/CSSComputedStyleDeclaration.cpp:1029 > + fitContentTrackSize->append(specifiedValueForGridTrackBreadth(trackSize.fitContentTrackBreadth(), style)); I guess we shouldn't allow "1fr" or things like that for fit-content. Probably we should use something different than specifiedValueForGridTrackBreadth(). And add a test to verify that this syntax is wrong. > Source/WebCore/css/parser/CSSParser.cpp:6097 > + if (!trackBreadth || trackBreadth->isFlex()) Do we need the isFlex() check here? I guess if it's "1fr" it should be already invalid in the previous if. Maybe we can move the isFlex() to an assert after. > Source/WebCore/rendering/RenderGrid.cpp:105 > + m_tempSize += tempSize; Shouldn't we use setTemptSize() to be sure that we fulfill the ASSERTs? > Source/WebCore/rendering/RenderGrid.cpp:1181 > + ASSERT(trackSize.fitContentTrackBreadth().isLength()); Is it possible it's not a length? > Source/WebCore/rendering/RenderGrid.cpp:1182 > + growthLimit = std::min(growthLimit, valueForLength(trackSize.fitContentTrackBreadth().length(), sizingData.availableSpace().valueOr(LayoutUnit()))); Nit: We've a mix of valueOr(0) vs valueOr(LayoutUnit()).
Sergio Villar Senin
Comment 12 2016-09-15 02:47:53 PDT
Ryan Haddad
Comment 13 2016-09-15 08:00:47 PDT
Sergio Villar Senin
Comment 14 2016-09-15 08:53:37 PDT
Reverted r205966 for reason: Triggered some assertions Committed r205972: <http://trac.webkit.org/changeset/205972>
Sergio Villar Senin
Comment 15 2016-09-15 09:26:37 PDT
Created attachment 288955 [details] Patch for landing I added an extra wrong assertion in the very last moment inspired by one of the review comments. The assert was wrong because the tempSize could be sometimes larger than the cap during the 'grow over the limits' phase
Sergio Villar Senin
Comment 16 2016-09-15 10:09:30 PDT
Comment on attachment 288955 [details] Patch for landing Clearing flags on attachment: 288955 Committed r205977: <http://trac.webkit.org/changeset/205977>
Sergio Villar Senin
Comment 17 2016-09-15 10:09:40 PDT
All reviewed patches have been landed. Closing bug.
Note You need to log in before you can comment on or make changes to this bug.