Bug 220224

Summary: Support transferred min/max block size for aspect-ratio
Product: WebKit Reporter: Rob Buis <rbuis>
Component: CSSAssignee: Rob Buis <rbuis>
Status: RESOLVED FIXED    
Severity: Normal CC: changseok, darin, esprehn+autocc, ews-watchlist, glenn, kondapallykalyan, pdr, sam, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
Bug Depends on:    
Bug Blocks: 47738    
Attachments:
Description Flags
Patch
none
Patch
none
Patch
none
Patch
none
Patch
none
Patch
none
Patch
ews-feeder: commit-queue-
Patch
ews-feeder: commit-queue-
Patch
none
Patch
none
Patch
none
Patch none

Description Rob Buis 2021-01-02 02:51:10 PST
Support transferred min/max block size for aspect-ratio
Comment 1 Rob Buis 2021-01-02 02:53:39 PST
Created attachment 416893 [details]
Patch
Comment 2 Rob Buis 2021-01-08 00:50:47 PST
Created attachment 417250 [details]
Patch
Comment 3 Rob Buis 2021-01-08 01:41:02 PST
Created attachment 417257 [details]
Patch
Comment 4 Rob Buis 2021-01-09 01:13:36 PST
Created attachment 417339 [details]
Patch
Comment 5 Radar WebKit Bug Importer 2021-01-09 02:52:14 PST
<rdar://problem/72961058>
Comment 6 Rob Buis 2021-01-09 08:17:30 PST
Created attachment 417342 [details]
Patch
Comment 7 Rob Buis 2021-01-10 06:35:20 PST
Created attachment 417349 [details]
Patch
Comment 8 Rob Buis 2021-01-14 06:40:26 PST
Created attachment 417615 [details]
Patch
Comment 9 Rob Buis 2021-01-14 07:02:36 PST
Created attachment 417618 [details]
Patch
Comment 10 Rob Buis 2021-01-14 07:39:43 PST
Created attachment 417619 [details]
Patch
Comment 11 Sam Weinig 2021-01-14 15:42:42 PST
Comment on attachment 417619 [details]
Patch

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

> Source/WebCore/rendering/RenderBox.cpp:5058
> +void RenderBox::computeMinMaxLogicalWidthFromAspectRatio(LayoutUnit& transferredMinSize, LayoutUnit& transferredMaxSize) const

This should return a pair (or a bespoke struct) rather than using out parameters.
Comment 12 Rob Buis 2021-01-15 05:38:30 PST
Created attachment 417693 [details]
Patch
Comment 13 Rob Buis 2021-01-15 09:07:17 PST
Comment on attachment 417619 [details]
Patch

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

>> Source/WebCore/rendering/RenderBox.cpp:5058
>> +void RenderBox::computeMinMaxLogicalWidthFromAspectRatio(LayoutUnit& transferredMinSize, LayoutUnit& transferredMaxSize) const
> 
> This should return a pair (or a bespoke struct) rather than using out parameters.

Done.
Comment 14 Darin Adler 2021-01-15 17:31:12 PST
Comment on attachment 417693 [details]
Patch

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

> Source/WebCore/rendering/RenderBox.cpp:650
> +        logicalWidth = std::max(logicalMinWidth, std::min(logicalWidth, logicalMaxWidth));

I’m fond of using std::clamp for this sort of thing, but it’s maybe not *exactly* the same as the std::max/min combo here.
Comment 15 EWS 2021-01-15 23:58:01 PST
Committed r271554: <https://trac.webkit.org/changeset/271554>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 417693 [details].
Comment 16 Sam Weinig 2021-01-16 10:22:41 PST
Comment on attachment 417693 [details]
Patch

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

> Source/WebCore/rendering/RenderBox.cpp:649
> +        LayoutUnit logicalMinWidth, logicalMaxWidth;
> +        std::tie(logicalMinWidth, logicalMaxWidth) = computeMinMaxLogicalWidthFromAspectRatio();

No need to change this, but in the future, you can write these two lines as:

auto [logicalMinWidth, logicalMaxWidth] = computeMinMaxLogicalWidthFromAspectRatio();

You still have to use std::tie in some circumstances, like if you have existing variables, but in cases like this the structured binding approach is quite clean.

>> Source/WebCore/rendering/RenderBox.cpp:650
>> +        logicalWidth = std::max(logicalMinWidth, std::min(logicalWidth, logicalMaxWidth));
> 
> I’m fond of using std::clamp for this sort of thing, but it’s maybe not *exactly* the same as the std::max/min combo here.

It should be exactly the same I think.
Comment 17 Rob Buis 2021-01-16 10:59:31 PST
Comment on attachment 417693 [details]
Patch

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

>> Source/WebCore/rendering/RenderBox.cpp:649
>> +        std::tie(logicalMinWidth, logicalMaxWidth) = computeMinMaxLogicalWidthFromAspectRatio();
> 
> No need to change this, but in the future, you can write these two lines as:
> 
> auto [logicalMinWidth, logicalMaxWidth] = computeMinMaxLogicalWidthFromAspectRatio();
> 
> You still have to use std::tie in some circumstances, like if you have existing variables, but in cases like this the structured binding approach is quite clean.

I tried it first but I got a compile error (on Big sur) at the place where the other std::tie is used:
   if (shouldComputeLogicalHeightFromAspectRatio())
        std::tie(transferredMinSize, transferredMaxSize) = computeMinMaxLogicalWidthFromAspectRatio();

You can try for yourself if you are interested, I forgot the exact error.

>>> Source/WebCore/rendering/RenderBox.cpp:650
>>> +        logicalWidth = std::max(logicalMinWidth, std::min(logicalWidth, logicalMaxWidth));
>> 
>> I’m fond of using std::clamp for this sort of thing, but it’s maybe not *exactly* the same as the std::max/min combo here.
> 
> It should be exactly the same I think.

I am not sure, but mainly I think it would like a non-intuitive and maybe suspicious clamp, i.e. why clamp between max, min range instead of usual min, max. Maybe we need a mathematician to chime in here, Igalia has a few of them...
Comment 18 Darin Adler 2021-01-19 09:39:57 PST
Comment on attachment 417693 [details]
Patch

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

>>>> Source/WebCore/rendering/RenderBox.cpp:650
>>>> +        logicalWidth = std::max(logicalMinWidth, std::min(logicalWidth, logicalMaxWidth));
>>> 
>>> I’m fond of using std::clamp for this sort of thing, but it’s maybe not *exactly* the same as the std::max/min combo here.
>> 
>> It should be exactly the same I think.
> 
> I am not sure, but mainly I think it would like a non-intuitive and maybe suspicious clamp, i.e. why clamp between max, min range instead of usual min, max. Maybe we need a mathematician to chime in here, Igalia has a few of them...

There is a small difference, one I learned when I researched clamp. The difference is when minimum > maximum. You can carefully use std::max/min so the minimum takes precedence over the maximum. But in std::clamp, the maximum takes precedence. I have no idea what this has to do with mathematicians! I love std::clamp for its clarity, clamp a value between low and high, rather than using std::max/min where it’s harder to read.
Comment 19 Rob Buis 2021-01-19 09:45:42 PST
Reopening to attach new patch.
Comment 20 Rob Buis 2021-01-19 09:45:45 PST
Created attachment 417881 [details]
Patch
Comment 21 Rob Buis 2021-01-19 09:49:25 PST
Comment on attachment 417693 [details]
Patch

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

>>>>> Source/WebCore/rendering/RenderBox.cpp:650
>>>>> +        logicalWidth = std::max(logicalMinWidth, std::min(logicalWidth, logicalMaxWidth));
>>>> 
>>>> I’m fond of using std::clamp for this sort of thing, but it’s maybe not *exactly* the same as the std::max/min combo here.
>>> 
>>> It should be exactly the same I think.
>> 
>> I am not sure, but mainly I think it would like a non-intuitive and maybe suspicious clamp, i.e. why clamp between max, min range instead of usual min, max. Maybe we need a mathematician to chime in here, Igalia has a few of them...
> 
> There is a small difference, one I learned when I researched clamp. The difference is when minimum > maximum. You can carefully use std::max/min so the minimum takes precedence over the maximum. But in std::clamp, the maximum takes precedence. I have no idea what this has to do with mathematicians! I love std::clamp for its clarity, clamp a value between low and high, rather than using std::max/min where it’s harder to read.

I probably misinterpreted the code. Let's see if it turns up green using std:clamp, I also prefer it.
Comment 22 Darin Adler 2021-01-19 13:01:38 PST
(In reply to Rob Buis from comment #17)
> I tried it first but I got a compile error (on Big sur) at the place where
> the other std::tie is used:
>    if (shouldComputeLogicalHeightFromAspectRatio())
>         std::tie(transferredMinSize, transferredMaxSize) =
> computeMinMaxLogicalWidthFromAspectRatio();
> 
> You can try for yourself if you are interested, I forgot the exact error.

That’s exactly what Sam meant when he said, "You still have to use std::tie in some circumstances, like if you have existing variables." These are existing variables.
Comment 23 Rob Buis 2021-01-19 13:25:01 PST
(In reply to Darin Adler from comment #22)
> (In reply to Rob Buis from comment #17)
> > I tried it first but I got a compile error (on Big sur) at the place where
> > the other std::tie is used:
> >    if (shouldComputeLogicalHeightFromAspectRatio())
> >         std::tie(transferredMinSize, transferredMaxSize) =
> > computeMinMaxLogicalWidthFromAspectRatio();
> > 
> > You can try for yourself if you are interested, I forgot the exact error.
> 
> That’s exactly what Sam meant when he said, "You still have to use std::tie
> in some circumstances, like if you have existing variables." These are
> existing variables.

I see, thanks for the clarification! I think I will use the std::tie usage as-is since otherwise it feels a bit inconsistent.
Comment 24 Darin Adler 2021-01-19 13:27:13 PST
(In reply to Rob Buis from comment #23)
> I think I will use the std::tie usage
> as-is since otherwise it feels a bit inconsistent.

I’m a fan of combining both since the structured binding is so much more terse when we are both defining and initializing at once.
Comment 25 Rob Buis 2021-01-20 00:31:51 PST
Created attachment 417947 [details]
Patch
Comment 26 EWS 2021-01-20 08:02:06 PST
Committed r271648: <https://trac.webkit.org/changeset/271648>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 417947 [details].