Bug 222376

Summary: [css-grid] Replace the use of -1 with WTF::nullopt
Product: WebKit Reporter: zsun
Component: CSSAssignee: Nobody <webkit-unassigned>
Status: RESOLVED FIXED    
Severity: Normal CC: changseok, esprehn+autocc, ews-watchlist, glenn, jfernandez, kondapallykalyan, pdr, rbuis, rego, svillar, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
Patch
none
Patch
none
Patch
none
Patch
none
Patch
none
Patch
none
Patch
none
Patch
none
Patch none

Description zsun 2021-02-24 12:30:26 PST
It might make sense to replace the use of -1 with WTF::nullopt in grid item
Comment 1 zsun 2021-02-24 12:37:47 PST
Created attachment 421441 [details]
Patch
Comment 2 Javier Fernandez 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.
Comment 3 zsun 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?
Comment 4 Radar WebKit Bug Importer 2021-03-03 12:31:25 PST
<rdar://problem/74997975>
Comment 5 zsun 2021-03-08 05:21:57 PST
Created attachment 422556 [details]
Patch
Comment 6 zsun 2021-03-08 06:32:37 PST
Created attachment 422559 [details]
Patch
Comment 7 Sergio Villar Senin 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.
Comment 8 zsun 2021-03-08 11:54:25 PST
Created attachment 422597 [details]
Patch
Comment 9 zsun 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.
Comment 10 Javier Fernandez 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.
Comment 11 zsun 2021-03-09 03:29:10 PST
Created attachment 422684 [details]
Patch
Comment 12 Javier Fernandez 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.
Comment 13 zsun 2021-03-11 07:43:30 PST
Created attachment 422930 [details]
Patch
Comment 14 Sergio Villar Senin 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
Comment 15 zsun 2021-03-12 01:43:03 PST
Created attachment 423023 [details]
Patch
Comment 16 zsun 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.
Comment 17 zsun 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!
Comment 18 zsun 2021-03-12 04:05:50 PST
Created attachment 423033 [details]
Patch
Comment 19 Javier Fernandez 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()
Comment 20 zsun 2021-03-15 12:42:12 PDT
Created attachment 423222 [details]
Patch
Comment 21 zsun 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!
Comment 22 EWS 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].