RESOLVED FIXED 222376
[css-grid] Replace the use of -1 with WTF::nullopt
https://bugs.webkit.org/show_bug.cgi?id=222376
Summary [css-grid] Replace the use of -1 with WTF::nullopt
zsun
Reported 2021-02-24 12:30:26 PST
It might make sense to replace the use of -1 with WTF::nullopt in grid item
Attachments
Patch (2.52 KB, patch)
2021-02-24 12:37 PST, zsun
no flags
Patch (6.24 KB, patch)
2021-03-08 05:21 PST, zsun
no flags
Patch (7.36 KB, patch)
2021-03-08 06:32 PST, zsun
no flags
Patch (7.18 KB, patch)
2021-03-08 11:54 PST, zsun
no flags
Patch (16.75 KB, patch)
2021-03-09 03:29 PST, zsun
no flags
Patch (17.10 KB, patch)
2021-03-11 07:43 PST, zsun
no flags
Patch (23.71 KB, patch)
2021-03-12 01:43 PST, zsun
no flags
Patch (21.62 KB, patch)
2021-03-12 04:05 PST, zsun
no flags
Patch (21.74 KB, patch)
2021-03-15 12:42 PDT, zsun
no flags
zsun
Comment 1 2021-02-24 12:37:47 PST
Javier Fernandez
Comment 2 2021-02-25 05:31:38 PST
Comment on attachment 421441 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=421441&action=review I bealive there are other functions using -1 as indefinite; I think this patch should address all of them. See GridTrackSizingAlgorithm::estimatedGridAreaBreadthForChild for instance. > Source/WebCore/ChangeLog:7 > + We should explain for each change why we need nullopt instead; those functions return an Optional type and we consider nullopt as indefinite, as we did before with the -1 value. It's also need to mention why this change doesn't need new tests, or changes on the already existing ones. In this case, since we don't expect a behavior change, we don't need to provide tests.
zsun
Comment 3 2021-02-25 06:17:19 PST
https://bugs.webkit.org/show_bug.cgi?id=221439 has addressed and fixed issue mentioned here. Maybe we can close this one?
Radar WebKit Bug Importer
Comment 4 2021-03-03 12:31:25 PST
zsun
Comment 5 2021-03-08 05:21:57 PST
zsun
Comment 6 2021-03-08 06:32:37 PST
Sergio Villar Senin
Comment 7 2021-03-08 07:52:29 PST
Comment on attachment 422559 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=422559&action=review Definitely a step in the right direction. There are some changes that need to be done though > Source/WebCore/ChangeLog:6 > + This change replaces -1 with nullopt in grid to indicate indefinte for funtions that nit: indefinite > Source/WebCore/rendering/GridTrackSizingAlgorithm.cpp:912 > + overrideSize = WTF::nullopt; Instead of doing this, change estimatedGridAreaBreadthForChild() so that it returns an Optional<LayoutUnit> and make it return nullopt instead of -1_lu > Source/WebCore/rendering/GridTrackSizingAlgorithm.cpp:1064 > + overridingSize = WTF::nullopt; You can do it with a ternary operator: auto overridingSize = direction() == childInlineDirection ? makeOptional(0_lu) : WTF::nullopt; In that case maybe you don't even need the overridingSize variable and pass the value directly as argument to setOverriding... > Source/WebCore/rendering/RenderGrid.cpp:928 > } If we change estimatedGridAreaBreadthForChild() as I suggested above then we don't need this change.
zsun
Comment 8 2021-03-08 11:54:25 PST
zsun
Comment 9 2021-03-08 12:00:47 PST
(In reply to Sergio Villar Senin from comment #7) > Comment on attachment 422559 [details] > Patch > > View in context: > https://bugs.webkit.org/attachment.cgi?id=422559&action=review > > Definitely a step in the right direction. There are some changes that need > to be done though > > > Source/WebCore/ChangeLog:6 > > + This change replaces -1 with nullopt in grid to indicate indefinte for funtions that > > nit: indefinite > Corrected. > > Source/WebCore/rendering/GridTrackSizingAlgorithm.cpp:912 > > + overrideSize = WTF::nullopt; > > Instead of doing this, change estimatedGridAreaBreadthForChild() so that it > returns an Optional<LayoutUnit> and make it return nullopt instead of -1_lu > I tried this approach. The main issue is that LayoutUnit GridTrackSizingAlgorithm::estimatedGridAreaBreadthForChild(const RenderBox& child, GridTrackSizingDirection direction) is called by LayoutSize GridTrackSizingAlgorithm::estimatedGridAreaBreadthForChild(const RenderBox& child) const. LayoutSize doesn't like Optional<LayoutUnit>, especially when it's WTF::nullopt. I'm not sure how feasible this approach is. Any suggestions? > > Source/WebCore/rendering/GridTrackSizingAlgorithm.cpp:1064 > > + overridingSize = WTF::nullopt; > > You can do it with a ternary operator: > auto overridingSize = direction() == childInlineDirection ? > makeOptional(0_lu) : WTF::nullopt; > > In that case maybe you don't even need the overridingSize variable and pass > the value directly as argument to setOverriding... > Updated. Thanks very much for the suggestion! > > Source/WebCore/rendering/RenderGrid.cpp:928 > > } > > If we change estimatedGridAreaBreadthForChild() as I suggested above then we > don't need this change.
Javier Fernandez
Comment 10 2021-03-08 12:59:50 PST
Comment on attachment 422559 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=422559&action=review >>> Source/WebCore/rendering/GridTrackSizingAlgorithm.cpp:912 >>> + overrideSize = WTF::nullopt; >> >> Instead of doing this, change estimatedGridAreaBreadthForChild() so that it returns an Optional<LayoutUnit> and make it return nullopt instead of -1_lu > > I tried this approach. The main issue is that LayoutUnit GridTrackSizingAlgorithm::estimatedGridAreaBreadthForChild(const RenderBox& child, GridTrackSizingDirection direction) is called by LayoutSize GridTrackSizingAlgorithm::estimatedGridAreaBreadthForChild(const RenderBox& child) const. LayoutSize doesn't like Optional<LayoutUnit>, especially when it's WTF::nullopt. I'm not sure how feasible this approach is. Any suggestions? Umm, the only solution I see now is that we remove the estimatedGridAreaBreadthForChild(child), and the caller takes the responsibility of building the LayoutSize instance, based on the results of the function; this should also be the responsible of handling the nullopt. I'm not sure how big would be the change, though.
zsun
Comment 11 2021-03-09 03:29:10 PST
Javier Fernandez
Comment 12 2021-03-09 06:50:02 PST
Comment on attachment 422684 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=422684&action=review > Source/WebCore/rendering/GridTrackSizingAlgorithm.cpp:554 > +Optional<LayoutUnit> GridTrackSizingAlgorithm::estimatedGridAreaBreadthForChildForColumns(const RenderBox& child) const Perhaps we don't need this function; we can just calling the generic function with the appropriated argument when needed. > Source/WebCore/rendering/GridTrackSizingAlgorithm.cpp:558 > +Optional<LayoutUnit> GridTrackSizingAlgorithm::estimatedGridAreaBreadthForChildForRows(const RenderBox& child) const Ditto > Source/WebCore/rendering/GridTrackSizingAlgorithm.cpp:839 > + return minLogicalSizeForChild(child, childMinSize, gridAreaSize.valueOr(0_lu)) + baselineShim; I'm not sure about this valurOr(0); it might be the root cause of the layout tests failures we have in the baseline alignment related tests. I think this might be wrong when dealing with orthogonal grid items, so that we need nullopt here to detect indefinite size.
zsun
Comment 13 2021-03-11 07:43:30 PST
Sergio Villar Senin
Comment 14 2021-03-11 10:55:10 PST
Comment on attachment 422930 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=422930&action=review Seems like you have to update the failed expectations of a test that is failing. Looking great, I'm happy that we get rid of the -1's. It's a pitty that we cannot use LayoutSize and have to use width and height separatedely but it isn't a big deal. > Source/WebCore/ChangeLog:7 > + returns an Optional type. This change has exposed an issue when resolving repalced elemnt Nit: replaced element > Source/WebCore/ChangeLog:11 > + Extra line here. BTW this paragraph should go bellow the "Reviewed by" line
zsun
Comment 15 2021-03-12 01:43:03 PST
zsun
Comment 16 2021-03-12 01:45:01 PST
(In reply to Javier Fernandez from comment #12) > Comment on attachment 422684 [details] > Patch > > View in context: > https://bugs.webkit.org/attachment.cgi?id=422684&action=review > > > Source/WebCore/rendering/GridTrackSizingAlgorithm.cpp:554 > > +Optional<LayoutUnit> GridTrackSizingAlgorithm::estimatedGridAreaBreadthForChildForColumns(const RenderBox& child) const > > Perhaps we don't need this function; we can just calling the generic > function with the appropriated argument when needed. > > > Source/WebCore/rendering/GridTrackSizingAlgorithm.cpp:558 > > +Optional<LayoutUnit> GridTrackSizingAlgorithm::estimatedGridAreaBreadthForChildForRows(const RenderBox& child) const > > Ditto > > > Source/WebCore/rendering/GridTrackSizingAlgorithm.cpp:839 > > + return minLogicalSizeForChild(child, childMinSize, gridAreaSize.valueOr(0_lu)) + baselineShim; > > I'm not sure about this valurOr(0); it might be the root cause of the layout > tests failures we have in the baseline alignment related tests. > I think this might be wrong when dealing with orthogonal grid items, so that > we need nullopt here to detect indefinite size. Updated. Change the type to Optional.
zsun
Comment 17 2021-03-12 01:46:19 PST
(In reply to Sergio Villar Senin from comment #14) > Comment on attachment 422930 [details] > Patch > > View in context: > https://bugs.webkit.org/attachment.cgi?id=422930&action=review > > Seems like you have to update the failed expectations of a test that is > failing. > Updated. This test is fixing at https://bugs.webkit.org/show_bug.cgi?id=191627. > Looking great, I'm happy that we get rid of the -1's. It's a pitty that we > cannot use LayoutSize and have to use width and height separatedely but it > isn't a big deal. > > > Source/WebCore/ChangeLog:7 > > + returns an Optional type. This change has exposed an issue when resolving repalced elemnt > > Nit: replaced element > > > Source/WebCore/ChangeLog:11 > > + > > Extra line here. BTW this paragraph should go bellow the "Reviewed by" line Updated. Thank you!
zsun
Comment 18 2021-03-12 04:05:50 PST
Javier Fernandez
Comment 19 2021-03-15 10:46:10 PDT
Comment on attachment 423033 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=423033&action=review r=me > Source/WebCore/ChangeLog:8 > + This change replaces -1 with nullopt in grid to indicate indefinite for funtions that s/funtions/functions > Source/WebCore/ChangeLog:9 > + returns an Optional type. This change has exposed an issue when resolving replaced elemnt s/elemnt/element > Source/WebCore/rendering/RenderReplaced.cpp:357 > if (hasAutoHeightOrContainingBlockWithAutoHeight()) Nit: Maybe we can change this as well, something like this: return !hasAutoHeightOrContainingBlockWithAutoHeight()
zsun
Comment 20 2021-03-15 12:42:12 PDT
zsun
Comment 21 2021-03-15 12:43:05 PDT
(In reply to Javier Fernandez from comment #19) > Comment on attachment 423033 [details] > Patch > > View in context: > https://bugs.webkit.org/attachment.cgi?id=423033&action=review > > r=me > > > Source/WebCore/ChangeLog:8 > > + This change replaces -1 with nullopt in grid to indicate indefinite for funtions that > > s/funtions/functions > > > Source/WebCore/ChangeLog:9 > > + returns an Optional type. This change has exposed an issue when resolving replaced elemnt > > s/elemnt/element > > > Source/WebCore/rendering/RenderReplaced.cpp:357 > > if (hasAutoHeightOrContainingBlockWithAutoHeight()) > > Nit: Maybe we can change this as well, something like this: > > return !hasAutoHeightOrContainingBlockWithAutoHeight() Updated. Thanks!
EWS
Comment 22 2021-03-16 07:38:58 PDT
Committed r274477: <https://commits.webkit.org/r274477> All reviewed patches have been landed. Closing bug and clearing flags on attachment 423222 [details].
Note You need to log in before you can comment on or make changes to this bug.