Bug 46496

Summary: calcReplacedWidthUsing has wrong containing block width.
Product: WebKit Reporter: Dave Hyatt <hyatt>
Component: Layout and RenderingAssignee: Dave Hyatt <hyatt>
Status: RESOLVED FIXED    
Severity: Normal CC: changseok, commit-queue, darin, d-r, esprehn+autocc, ews-watchlist, fmalita, glenn, gyuyoung.kim, hyatt, kondapallykalyan, pdr, rbuis, schenney, svillar, webkit-bug-importer, zalan
Priority: P2 Keywords: InRadar
Version: 528+ (Nightly build)   
Hardware: PC   
OS: OS X 10.5   
Bug Depends on:    
Bug Blocks: 46123    
Attachments:
Description Flags
Patch
none
Patch
none
Patch
none
Patch none

Description Dave Hyatt 2010-09-24 12:25:11 PDT
calcReplacedWidthUsing has wrong containing block width.  The width used has to match the block-flow directionality of the replaced element and not of the containing block.
Comment 1 Yuki Sekiguchi 2014-02-04 00:40:20 PST
Created attachment 223081 [details]
Patch
Comment 2 Darin Adler 2016-03-09 09:16:39 PST
Dave, would you review+ or review- please?
Comment 3 David Kilzer (:ddkilzer) 2016-06-21 11:38:07 PDT
Comment on attachment 223081 [details]
Patch

Clearing review? flag on old patch that no longer applies to trunk.
Comment 4 Rob Buis 2021-10-16 04:30:17 PDT
Created attachment 441486 [details]
Patch
Comment 5 Rob Buis 2021-10-16 13:22:05 PDT
Created attachment 441503 [details]
Patch
Comment 6 Rob Buis 2021-10-19 09:08:25 PDT
Created attachment 441735 [details]
Patch
Comment 7 Darin Adler 2021-10-19 09:28:08 PDT
Comment on attachment 441735 [details]
Patch

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

> Source/WebCore/rendering/RenderBox.cpp:3334
> +        LayoutUnit containerWidth;
> +        if (isOutOfFlowPositioned())
> +            containerWidth = containingBlockLogicalWidthForPositioned(downcast<RenderBoxModelObject>(*container()));
> +        else if (isHorizontalWritingMode() == containingBlock()->isHorizontalWritingMode())
> +            containerWidth = containingBlockLogicalWidthForContent();
> +        else
> +            containerWidth = perpendicularContainingBlockLogicalHeight();

I’ve been noticing something like this, perhaps if not exactly the same, as a repeated idiom in patches recently correcting orthogonal flow behavior. Is there a way to add another function to help us get the repeated pattern right, without the code having an if statement like this in the middle or hurting efficiency? Or maybe it’s not repeated often enough.
Comment 8 Rob Buis 2021-10-19 12:23:20 PDT
Comment on attachment 441735 [details]
Patch

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

>> Source/WebCore/rendering/RenderBox.cpp:3334
>> +            containerWidth = perpendicularContainingBlockLogicalHeight();
> 
> I’ve been noticing something like this, perhaps if not exactly the same, as a repeated idiom in patches recently correcting orthogonal flow behavior. Is there a way to add another function to help us get the repeated pattern right, without the code having an if statement like this in the middle or hurting efficiency? Or maybe it’s not repeated often enough.

I checked but I do not see it repeated enough. I do think we can provide something for the frequent "isHorizontalWritingMode() == containingBlock()->isHorizontalWritingMode()" like checks, but that sounds like a different bug.
Comment 9 zalan 2021-10-19 13:57:30 PDT
Comment on attachment 441735 [details]
Patch

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

>>> Source/WebCore/rendering/RenderBox.cpp:3334
>>> +            containerWidth = perpendicularContainingBlockLogicalHeight();
>> 
>> I’ve been noticing something like this, perhaps if not exactly the same, as a repeated idiom in patches recently correcting orthogonal flow behavior. Is there a way to add another function to help us get the repeated pattern right, without the code having an if statement like this in the middle or hurting efficiency? Or maybe it’s not repeated often enough.
> 
> I checked but I do not see it repeated enough. I do think we can provide something for the frequent "isHorizontalWritingMode() == containingBlock()->isHorizontalWritingMode()" like checks, but that sounds like a different bug.

I always get confused when I see code like this sine the writing-direction defines (at least the part that's relevant here) the block direction for the content. 
Now the block level child box's writing direction (replaced box in this case) should have nothing to do with how we get the available width constraint from the containing block. It's only the containing block's writing direction that rules the logical width/height for its content (again, replaced box in this case). 
When the containing block has horizontal writing mode, the available width for its block level boxes matches its "physical" width, while with vertical direction the available width becomes its "physical" height so that the box level child boxes grow vertically with their widths. i.e. when you call containingBlockLogicalWidthForContent() it shouldn't matter whether _this_ box is horizontal or vertical in the context of finding the available width for the child box. I know this code copies the logic from computeReplacedLogicalHeightUsing, but we either do yet another flip somewhere to have correct final values or simply the functions/variable names don't mean logical values.
Comment 10 zalan 2021-10-19 14:28:48 PDT
or put it simply:
when the child box ask “how much I can grow (logical)horizontally in this containing block”, the child box's writing direction is irrelevant.
Comment 11 Sergio Villar Senin 2021-10-20 04:21:28 PDT
Comment on attachment 441735 [details]
Patch

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

>>>> Source/WebCore/rendering/RenderBox.cpp:3334
>>>> +            containerWidth = perpendicularContainingBlockLogicalHeight();
>>> 
>>> I’ve been noticing something like this, perhaps if not exactly the same, as a repeated idiom in patches recently correcting orthogonal flow behavior. Is there a way to add another function to help us get the repeated pattern right, without the code having an if statement like this in the middle or hurting efficiency? Or maybe it’s not repeated often enough.
>> 
>> I checked but I do not see it repeated enough. I do think we can provide something for the frequent "isHorizontalWritingMode() == containingBlock()->isHorizontalWritingMode()" like checks, but that sounds like a different bug.
> 
> I always get confused when I see code like this sine the writing-direction defines (at least the part that's relevant here) the block direction for the content. 
> Now the block level child box's writing direction (replaced box in this case) should have nothing to do with how we get the available width constraint from the containing block. It's only the containing block's writing direction that rules the logical width/height for its content (again, replaced box in this case). 
> When the containing block has horizontal writing mode, the available width for its block level boxes matches its "physical" width, while with vertical direction the available width becomes its "physical" height so that the box level child boxes grow vertically with their widths. i.e. when you call containingBlockLogicalWidthForContent() it shouldn't matter whether _this_ box is horizontal or vertical in the context of finding the available width for the child box. I know this code copies the logic from computeReplacedLogicalHeightUsing, but we either do yet another flip somewhere to have correct final values or simply the functions/variable names don't mean logical values.

I agree it's confusing but I don't think there is a problem with the code. In this case we're interested in the size of the container in the inline size of the child. If both are parallel then we need the inline size of the container, otherwise we are looking for the block size of the container. So we do need to check whether or not they're orthogonal. The question is I guess whether we do it in the caller does or the callee.

BTW orthogonal to this bug, should we push for using Inline/Block instead of LogicalWidth/LogicalHeight ?
Comment 12 EWS 2021-10-20 10:35:25 PDT
Committed r284548 (243290@main): <https://commits.webkit.org/243290@main>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 441735 [details].
Comment 13 Radar WebKit Bug Importer 2021-10-20 10:36:20 PDT
<rdar://problem/84468824>