Bug 222100

Summary: [css-grid] Fix min/max widths of grid affected by ancestor
Product: WebKit Reporter: zsun
Component: CSSAssignee: Nobody <webkit-unassigned>
Status: REOPENED ---    
Severity: Normal CC: changseok, commit-queue, esprehn+autocc, ews-watchlist, glenn, jenner, jfernandez, kondapallykalyan, obrufau, pdr, rego, svillar, webkit-bug-importer, zalan
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
See Also: https://bugs.webkit.org/show_bug.cgi?id=229586
Bug Depends on: 222503    
Bug Blocks:    
Attachments:
Description Flags
Patch
none
Patch
none
Patch
none
Patch
none
Patch
none
Patch
none
Patch
none
Patch
none
Patch
none
Patch none

Description zsun 2021-02-18 05:25:34 PST
The following WPT tests failed in Safari 

css/css-grid/grid-items/grid-items-percentage-paddings-002.html
css/css-grid/grid-items/grid-items-percentage-paddings-vertical-lr-002.html 
css/css-grid/grid-items/grid-items-percentage-paddings-vertical-rl-002.htm
Comment 1 zsun 2021-02-18 05:40:49 PST
Created attachment 420823 [details]
Patch
Comment 2 zsun 2021-02-18 09:35:46 PST
Created attachment 420837 [details]
Patch
Comment 3 Javier Fernandez 2021-02-22 06:13:40 PST
Comment on attachment 420837 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=420837&action=review

> Source/WebCore/ChangeLog:9
> +        Before update logical-width, for element that needs prefrredWidth recalcution,

s/prefrredWidth/preferredWidth

> Source/WebCore/rendering/RenderBox.cpp:2485
> +        if (cb->needsPreferredWidthsRecalculation() && !box->preferredLogicalWidthsDirty()) {

I supposed box->preferredLogicalWidthsDirty() is false for sure, otherwise we should have entered in the branch above, right ? 

Perhaps you meant "cb->" here ? Just wondering.

> Source/WebCore/rendering/RenderBox.cpp:2498
> +        // Laying out this object means that its containing block is also being laid out. This object is special, in that its min/max widths depend on

Nit, I think it'd be clearer if we put the comment just above the if statement.
Comment 4 zsun 2021-02-23 05:36:38 PST
Created attachment 421305 [details]
Patch
Comment 5 zsun 2021-02-23 05:37:36 PST
(In reply to Javier Fernandez from comment #3)
> Comment on attachment 420837 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=420837&action=review
> 
> > Source/WebCore/ChangeLog:9
> > +        Before update logical-width, for element that needs prefrredWidth recalcution,
> 
> s/prefrredWidth/preferredWidth
> 
> > Source/WebCore/rendering/RenderBox.cpp:2485
> > +        if (cb->needsPreferredWidthsRecalculation() && !box->preferredLogicalWidthsDirty()) {
> 
> I supposed box->preferredLogicalWidthsDirty() is false for sure, otherwise
> we should have entered in the branch above, right ? 
> 
> Perhaps you meant "cb->" here ? Just wondering.
> 
> > Source/WebCore/rendering/RenderBox.cpp:2498
> > +        // Laying out this object means that its containing block is also being laid out. This object is special, in that its min/max widths depend on
> 
> Nit, I think it'd be clearer if we put the comment just above the if
> statement.

Comments have addressed. Thank you!
Comment 6 Javier Fernandez 2021-02-23 07:34:10 PST
Comment on attachment 421305 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=421305&action=review

> Source/WebCore/rendering/RenderBox.cpp:2479
> +        // If the preferred widths are already dirty at this point (during layout), it actually means that we never need to calculate them, since that should

I think we can move the comments above the if clause, and remove the brackets.

> Source/WebCore/rendering/RenderBox.cpp:2485
> +        // If our containing block also has min/max widths that are affected by the ancestry, we have already dealt with this object as well. Avoid

Ditto

> Source/WebCore/rendering/RenderBox.cpp:2496
> +        if (shouldRecalculateMinMaxWidthsAffectedByAncestor(this)) {

Why not using a composed conditional clause instead two nested if ?

> Source/WebCore/rendering/RenderBox.cpp:2497
> +        // Laying out this object means that its containing block is also being laid out. This object is special, in that its min/max widths depend on

We could move the comments here as well, as I suggested before.
Comment 7 zsun 2021-02-23 08:44:17 PST
Created attachment 421316 [details]
Patch
Comment 8 zsun 2021-02-23 08:45:10 PST
(In reply to Javier Fernandez from comment #6)
> Comment on attachment 421305 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=421305&action=review
> 
> > Source/WebCore/rendering/RenderBox.cpp:2479
> > +        // If the preferred widths are already dirty at this point (during layout), it actually means that we never need to calculate them, since that should
> 
> I think we can move the comments above the if clause, and remove the
> brackets.
> 
> > Source/WebCore/rendering/RenderBox.cpp:2485
> > +        // If our containing block also has min/max widths that are affected by the ancestry, we have already dealt with this object as well. Avoid
> 
> Ditto
> 
> > Source/WebCore/rendering/RenderBox.cpp:2496
> > +        if (shouldRecalculateMinMaxWidthsAffectedByAncestor(this)) {
> 
> Why not using a composed conditional clause instead two nested if ?
> 
> > Source/WebCore/rendering/RenderBox.cpp:2497
> > +        // Laying out this object means that its containing block is also being laid out. This object is special, in that its min/max widths depend on
> 
> We could move the comments here as well, as I suggested before.

All review comments have been addressed. Thank you!
Comment 9 Javier Fernandez 2021-02-23 13:00:32 PST
Comment on attachment 421316 [details]
Patch

r=me
Comment 10 EWS 2021-02-24 13:35:45 PST
Committed r273435: <https://commits.webkit.org/r273435>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 421316 [details].
Comment 11 Radar WebKit Bug Importer 2021-02-24 13:36:17 PST
<rdar://problem/74711256>
Comment 12 Robert Jenner 2021-02-26 14:49:45 PST
It appears this test may have broken another test:

imported/w3c/web-platform-tests/css/css-flexbox/percentage-max-height-003.html  

Reported at bug:

https://bugs.webkit.org/show_bug.cgi?id=222485
Comment 13 WebKit Commit Bot 2021-02-26 16:43:44 PST
Re-opened since this is blocked by bug 222503
Comment 14 zsun 2021-03-03 12:27:25 PST
Created attachment 422134 [details]
Patch
Comment 15 Javier Fernandez 2021-03-04 05:58:05 PST
Comment on attachment 422134 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=422134&action=review

> Source/WebCore/ChangeLog:8
> +        It's a reland of r273435, which got reverted because it broken 

nit: s/broken/broke

> Source/WebCore/rendering/RenderBox.cpp:2499
> +    if (needsPreferredWidthsRecalculation() && shouldRecalculateMinMaxWidthsAffectedByAncestor(this) && parent()->preferredLogicalWidthsDirty()) {

I think we should have a check here for parent(); I believe it's not guaranteed that it's not null.
Comment 16 Oriol Brufau 2021-03-04 06:38:50 PST
Comment on attachment 422134 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=422134&action=review

>> Source/WebCore/rendering/RenderBox.cpp:2499
>> +    if (needsPreferredWidthsRecalculation() && shouldRecalculateMinMaxWidthsAffectedByAncestor(this) && parent()->preferredLogicalWidthsDirty()) {
> 
> I think we should have a check here for parent(); I believe it's not guaranteed that it's not null.

Why does WebKit need parent()->preferredLogicalWidthsDirty() if Chromium doesn't have it?
And maybe the condition should be moved into shouldRecalculateMinMaxWidthsAffectedByAncestor() ?
Comment 17 zsun 2021-03-04 10:24:00 PST
Created attachment 422253 [details]
Patch
Comment 18 Sergio Villar Senin 2021-03-05 09:37:41 PST
Comment on attachment 422253 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=422253&action=review

What I don't exactly understand is which cases fix this and why the setPreferredLogicalWidthsDirty() is not invoked in the specific subclass RenderFlexibleBox, RenderGrid... etc

> Source/WebCore/rendering/RenderBox.cpp:2490
> +    }

You can write this in a more compact way using some C++ fancyness

if (const RenderBox* cb = box->containingBlock(); !cb->preferredLogicalWidthsDirty())
    return false;

Also I guess this function is only meant to be used from updateLogicalWidth(). If that's indeed the case it'd be better to move it to a lambda inside that method.
Comment 19 Sergio Villar Senin 2021-03-05 09:37:43 PST
Comment on attachment 422253 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=422253&action=review

What I don't exactly understand is which cases fix this and why the setPreferredLogicalWidthsDirty() is not invoked in the specific subclass RenderFlexibleBox, RenderGrid... etc

> Source/WebCore/rendering/RenderBox.cpp:2490
> +    }

You can write this in a more compact way using some C++ fancyness

if (const RenderBox* cb = box->containingBlock(); !cb->preferredLogicalWidthsDirty())
    return false;

Also I guess this function is only meant to be used from updateLogicalWidth(). If that's indeed the case it'd be better to move it to a lambda inside that method.
Comment 20 zsun 2021-04-02 03:11:02 PDT
Created attachment 425002 [details]
Patch
Comment 21 zsun 2021-04-03 03:25:19 PDT
Created attachment 425089 [details]
Patch
Comment 22 Javier Fernandez 2021-04-07 06:50:29 PDT
Comment on attachment 425089 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=425089&action=review

r=me

> Source/WebCore/rendering/RenderBlock.cpp:-639
> -    

Please, remove these empty lines
Comment 23 zsun 2021-04-07 08:16:39 PDT
Created attachment 425395 [details]
Patch
Comment 24 zsun 2021-04-08 07:44:13 PDT
Created attachment 425506 [details]
Patch
Comment 25 EWS 2021-04-09 02:18:04 PDT
Committed r275754 (236332@main): <https://commits.webkit.org/236332@main>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 425506 [details].
Comment 26 zalan 2021-08-26 15:34:48 PDT
This patch has been reverted in r281662. See https://bugs.webkit.org/show_bug.cgi?id=229586#c0 for more info.