Bug 228914

Summary: [css-writing-modes] Fix absolutely positioning with orthogonal writing modes
Product: WebKit Reporter: Sergio Villar Senin <svillar>
Component: Layout and RenderingAssignee: Sergio Villar Senin <svillar>
Status: RESOLVED FIXED    
Severity: Normal CC: bfulgham, changseok, darin, esprehn+autocc, ews-watchlist, ggaren, glenn, koivisto, kondapallykalyan, pdr, rbuis, rego, sihui_liu, simon.fraser, webkit-bug-importer, youennf, zalan
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
Bug Depends on:    
Bug Blocks: 209080, 229397    
Attachments:
Description Flags
Patch
none
Patch
none
Patch
none
Patch
none
Patch
none
Patch
ews-feeder: commit-queue-
Patch
none
Patch
none
Patch rego: review+

Description Sergio Villar Senin 2021-08-09 08:00:01 PDT
[css-writing-modes] Fix absolutely positioning with orthogonal writing modes
Comment 1 Sergio Villar Senin 2021-08-10 03:31:27 PDT
Created attachment 435250 [details]
Patch
Comment 2 Sergio Villar Senin 2021-08-10 09:53:46 PDT
Created attachment 435268 [details]
Patch
Comment 3 Sergio Villar Senin 2021-08-10 14:35:19 PDT
Created attachment 435295 [details]
Patch
Comment 4 Sergio Villar Senin 2021-08-11 05:22:43 PDT
Created attachment 435337 [details]
Patch
Comment 5 Darin Adler 2021-08-12 13:03:05 PDT
Need to fix these iOS-wk2 failures?
Comment 6 Sergio Villar Senin 2021-08-13 00:25:58 PDT
(In reply to Darin Adler from comment #5)
> Need to fix these iOS-wk2 failures?

Not really sure what to do with them. There is no special layout code for iOS so I'd bet it's a painting issue. The iOS port is painting the boxes 1px bigger than any other port. I'd bet it's a rounding issue.

I'll try to fix the WPT tests so that they don't generate those 1px digg issues. In the event I'm unable to, I guess I'll upload specific expectations for iOS.
Comment 7 Radar WebKit Bug Importer 2021-08-16 08:01:29 PDT
<rdar://problem/81980953>
Comment 8 Sergio Villar Senin 2021-08-18 03:01:24 PDT
Created attachment 435756 [details]
Patch
Comment 9 Sergio Villar Senin 2021-08-23 02:10:47 PDT
Created attachment 436168 [details]
Patch
Comment 10 Sergio Villar Senin 2021-08-23 07:25:00 PDT
Created attachment 436193 [details]
Patch
Comment 11 Sergio Villar Senin 2021-08-26 02:00:50 PDT
Gentle ping for reviewers
Comment 12 Rob Buis 2021-08-30 01:51:54 PDT
Comment on attachment 436193 [details]
Patch

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

Not an expert on this, but it mostly looks good to me.

> Source/WebCore/ChangeLog:12
> +        This is a two level fix. First of all we had to modify the two methods that retrieve the static distance to use

I think it may be better to put this in present tense.

> Source/WebCore/rendering/RenderBox.cpp:3719
> +        LayoutUnit staticPosition = isOrthogonal(*child, *parent) ? child->layer()->staticBlockPosition() - containerBlock.borderBefore() : child->layer()->staticInlinePosition() - containerBlock.borderLogicalLeft();

I wonder if some of these statement could be a lambda to more easily understand what is going on.

> Source/WebCore/rendering/RenderBox.cpp:4275
> +    auto haveOrthogonalWritingModes = containerBlock.style().isHorizontalWritingMode() != child->style().isHorizontalWritingMode();

Have or has?
Comment 13 Sergio Villar Senin 2021-08-31 03:08:42 PDT
Comment on attachment 436193 [details]
Patch

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

>> Source/WebCore/ChangeLog:12
>> +        This is a two level fix. First of all we had to modify the two methods that retrieve the static distance to use
> 
> I think it may be better to put this in present tense.

Ok

>> Source/WebCore/rendering/RenderBox.cpp:3719
>> +        LayoutUnit staticPosition = isOrthogonal(*child, *parent) ? child->layer()->staticBlockPosition() - containerBlock.borderBefore() : child->layer()->staticInlinePosition() - containerBlock.borderLogicalLeft();
> 
> I wonder if some of these statement could be a lambda to more easily understand what is going on.

I'll contact you offline as I am not sure how to make it easier to understand with a lambda.

>> Source/WebCore/rendering/RenderBox.cpp:4275
>> +    auto haveOrthogonalWritingModes = containerBlock.style().isHorizontalWritingMode() != child->style().isHorizontalWritingMode();
> 
> Have or has?

I used have because it refers to the container and the child, not to the _this_ object. But I don't have an strong opinion here.
Comment 14 Rob Buis 2021-08-31 12:06:54 PDT
Comment on attachment 436193 [details]
Patch

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

>>> Source/WebCore/rendering/RenderBox.cpp:3719
>>> +        LayoutUnit staticPosition = isOrthogonal(*child, *parent) ? child->layer()->staticBlockPosition() - containerBlock.borderBefore() : child->layer()->staticInlinePosition() - containerBlock.borderLogicalLeft();
>> 
>> I wonder if some of these statement could be a lambda to more easily understand what is going on.
> 
> I'll contact you offline as I am not sure how to make it easier to understand with a lambda.

Ok, as discussed, lambdas are probably overkill in these cases.
Comment 15 Manuel Rego Casasnovas 2021-09-01 03:18:42 PDT
Comment on attachment 436193 [details]
Patch

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

> Source/WebCore/rendering/RenderBox.cpp:3691
> +// FIXME: evaluate whether this should be a method of RenderObject instead.

With the current implementation it seems like a good idea to move it there.

> Source/WebCore/rendering/RenderBox.cpp:3692
> +static inline bool isOrthogonal(const RenderObject& renderer, const RenderObject& ancestor)

Why you call this "ancestor" instead of "parent"?

Maybe the proper word would be "containingBlock"?

> Source/WebCore/rendering/RenderBox.cpp:3737
> +        LayoutUnit staticPosition = isOrthogonal(*child, *parent) ? child->layer()->staticBlockPosition() + containerLogicalWidth + containerBlock.borderBefore() : child->layer()->staticInlinePosition() + containerLogicalWidth + containerBlock.borderLogicalLeft();

I don't understand this: "containerLogicalWidth + containerBlock.borderBefore()", it's like you're summing up a width with a height related stuff.
Maybe the name of the variable "containerLogicalWidth" is wrong... dunno really.

> Source/WebCore/rendering/RenderBox.cpp:3928
> +    auto haveOrthogonalWritingModes = containerBlock.style().isHorizontalWritingMode() != child->style().isHorizontalWritingMode();

Couldn't you use "isOrthogonal(*child, *containerBlock)"?

> Source/WebCore/rendering/RenderBox.cpp:3934
> +            || (logicalLeftAndRightAreAuto && !containerBlock.style().isLeftToRightDirection()))) {

I don't get what logicalLeftAndRightAreAuto has to do with all this, should we update the comment to mention something about this?

> Source/WebCore/rendering/RenderBox.cpp:4274
> +    auto logicalTopAndBottomAreAuto = child->style().logicalTop().isAuto() && child->style().logicalBottom().isAuto();

Again I don't get why we need this.

>>> Source/WebCore/rendering/RenderBox.cpp:4275
>>> +    auto haveOrthogonalWritingModes = containerBlock.style().isHorizontalWritingMode() != child->style().isHorizontalWritingMode();
>> 
>> Have or has?
> 
> I used have because it refers to the container and the child, not to the _this_ object. But I don't have an strong opinion here.

Ditto about using isOrthogonal().
Comment 16 Rob Buis 2021-09-01 03:24:27 PDT
Comment on attachment 436193 [details]
Patch

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

>> Source/WebCore/rendering/RenderBox.cpp:3928
>> +    auto haveOrthogonalWritingModes = containerBlock.style().isHorizontalWritingMode() != child->style().isHorizontalWritingMode();
> 
> Couldn't you use "isOrthogonal(*child, *containerBlock)"?

I thought the same thing, but one goes through renderer and one through style :)
Comment 17 Sergio Villar Senin 2021-09-02 00:28:49 PDT
Comment on attachment 436193 [details]
Patch

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

>> Source/WebCore/rendering/RenderBox.cpp:3691
>> +// FIXME: evaluate whether this should be a method of RenderObject instead.
> 
> With the current implementation it seems like a good idea to move it there.

Sure but if you don't mind I'd leave it for a follow up as there are currently several other pieces of code checking exactly the same, so I guess it'd be better to migrate them all at once.

>> Source/WebCore/rendering/RenderBox.cpp:3692
>> +static inline bool isOrthogonal(const RenderObject& renderer, const RenderObject& ancestor)
> 
> Why you call this "ancestor" instead of "parent"?
> 
> Maybe the proper word would be "containingBlock"?

Because I don't want to make any assumption about the relationship between both of them. It doesn't have to be the containing block or the parent. Actually it does not even have to be an ancestor, we just compare the writing modes.

>> Source/WebCore/rendering/RenderBox.cpp:3737
>> +        LayoutUnit staticPosition = isOrthogonal(*child, *parent) ? child->layer()->staticBlockPosition() + containerLogicalWidth + containerBlock.borderBefore() : child->layer()->staticInlinePosition() + containerLogicalWidth + containerBlock.borderLogicalLeft();
> 
> I don't understand this: "containerLogicalWidth + containerBlock.borderBefore()", it's like you're summing up a width with a height related stuff.
> Maybe the name of the variable "containerLogicalWidth" is wrong... dunno really.

I'm starting to think this is not correct and is forcing us to add extra conditions to computeLogicalLeftPositionedOffset(). I'll double check

>>> Source/WebCore/rendering/RenderBox.cpp:3928
>>> +    auto haveOrthogonalWritingModes = containerBlock.style().isHorizontalWritingMode() != child->style().isHorizontalWritingMode();
>> 
>> Couldn't you use "isOrthogonal(*child, *containerBlock)"?
> 
> I thought the same thing, but one goes through renderer and one through style :)

Right, I'll unify those.

>> Source/WebCore/rendering/RenderBox.cpp:3934
>> +            || (logicalLeftAndRightAreAuto && !containerBlock.style().isLeftToRightDirection()))) {
> 
> I don't get what logicalLeftAndRightAreAuto has to do with all this, should we update the comment to mention something about this?

That's to check whether or not the item is auto positioned. When any of those properties are not auto then computeInlineStaticDistance() or computeBlockStaticDistance() early return. This means that orthogonal flow corrections are not applied in those cases and we have to do it now. That said I think we can get rid off of one of the branches if we adjust properly computeInlinStaticPosition(). Will provide a new patch.

>> Source/WebCore/rendering/RenderBox.cpp:4274
>> +    auto logicalTopAndBottomAreAuto = child->style().logicalTop().isAuto() && child->style().logicalBottom().isAuto();
> 
> Again I don't get why we need this.

Same comment as before

>>>> Source/WebCore/rendering/RenderBox.cpp:4275
>>>> +    auto haveOrthogonalWritingModes = containerBlock.style().isHorizontalWritingMode() != child->style().isHorizontalWritingMode();
>>> 
>>> Have or has?
>> 
>> I used have because it refers to the container and the child, not to the _this_ object. But I don't have an strong opinion here.
> 
> Ditto about using isOrthogonal().

Sure.
Comment 18 Sergio Villar Senin 2021-09-02 02:04:15 PDT
Created attachment 437127 [details]
Patch
Comment 19 Sergio Villar Senin 2021-09-02 11:12:04 PDT
Created attachment 437168 [details]
Patch
Comment 20 Manuel Rego Casasnovas 2021-09-03 01:06:16 PDT
Comment on attachment 437168 [details]
Patch

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

Awesome patch, that improves a lot of cases. r=me

> Source/WebCore/rendering/RenderBox.cpp:3693
> +static inline bool isOrthogonal(const RenderObject& renderer, const RenderObject& ancestor)

Nit: If it doesn't have to be an ancestor, then maybe use "other" or something like that.
Comment 21 Sergio Villar Senin 2021-09-03 08:27:01 PDT
Committed r281995 (241302@main): <https://commits.webkit.org/241302@main>