Bug 176620 - In regular block layout, the width of a child's margin box should always be equal to that of its containing block
Summary: In regular block layout, the width of a child's margin box should always be e...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Layout and Rendering (show other bugs)
Version: Safari 10
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL:
Keywords: BlinkMergeCandidate, InRadar
Depends on:
Blocks:
 
Reported: 2017-09-08 11:25 PDT by Zhifei Fang
Modified: 2017-09-29 11:50 PDT (History)
9 users (show)

See Also:


Attachments
Patch (4.45 KB, patch)
2017-09-18 19:54 PDT, Zhifei Fang
no flags Details | Formatted Diff | Diff
Patch (4.31 KB, patch)
2017-09-20 21:46 PDT, Zhifei Fang
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Zhifei Fang 2017-09-08 11:25:58 PDT
Hi,

Orignally, I have filed a bug in blink here:
https://bugs.chromium.org/p/chromium/issues/detail?id=708751

Today I find I repoduce it on my safari.


After checking the code, it looks we have same root cause here

        LayoutUnit newMargin = containerLogicalWidth - computedValues.m_extent - cb.marginStartForChild(*this);
        bool hasInvertedDirection = cb.style().isLeftToRightDirection() != style().isLeftToRightDirection();
        if (hasInvertedDirection)
            computedValues.m_margins.m_start = newMargin;
        else
            computedValues.m_margins.m_end = newMargin;


Simply because at this time marginStartForChild have not been set yet.

if you saw here:

void RenderBox::updateLogicalWidth()
{
    LogicalExtentComputedValues computedValues;
    computeLogicalWidthInRegion(computedValues);

    setLogicalWidth(computedValues.m_extent);
    setLogicalLeft(computedValues.m_position);
    setMarginStart(computedValues.m_margins.m_start);
    setMarginEnd(computedValues.m_margins.m_end);
}

we are calling computeLogicalWidthInRegion first, then use the result to update the margin.

Therefore below path will fix it as I did for blink:

        LayoutUnit newMarginTotal = containerLogicalWidth - computedValues.m_extent;
        bool hasInvertedDirection = cb.style().isLeftToRightDirection() != style().isLeftToRightDirection();
        if (hasInvertedDirection)
            computedValues.m_margins.m_start = 
                 newMarginTotal - computedValues..m_margins.m_end;
        else
            computedValues.m_margins.m_end = 
                 newMarginTotal - computedValues..m_margins.m_start;
Comment 1 Zhifei Fang 2017-09-08 11:29:32 PDT
Please confirm, then I can start the commit process.
Comment 2 Alexey Proskuryakov 2017-09-15 09:02:10 PDT
Please see <https://webkit.org/contributing-code/>. It is unlikely that anyone will have a lot of comments about a code snippet, so the best way to proceed is to make a patch as described in this document, and once all tests pass, someone can review.
Comment 3 Zhifei Fang 2017-09-15 09:03:24 PDT
Woring on it.
Comment 4 Zhifei Fang 2017-09-15 09:16:16 PDT
(In reply to Alexey Proskuryakov from comment #2)
> Please see <https://webkit.org/contributing-code/>. It is unlikely that
> anyone will have a lot of comments about a code snippet, so the best way to
> proceed is to make a patch as described in this document, and once all tests
> pass, someone can review.

I just wonder should this bug firstly assign to me, not sure if it is not assign to me I can upload the code or not.

Thanks!
Comment 5 Alexey Proskuryakov 2017-09-15 09:25:25 PDT
You can attach patches without having the bug assigned to you.
Comment 6 Zhifei Fang 2017-09-18 19:54:32 PDT
Created attachment 321174 [details]
Patch
Comment 7 Zhifei Fang 2017-09-20 11:08:14 PDT
Need a reviewer
Comment 8 Dave Hyatt 2017-09-20 11:21:40 PDT
Comment on attachment 321174 [details]
Patch

I see that this is a port of a Blink patch. It might be good to reference that, since this is actually a Blink merge and not an original patch.
Comment 9 Simon Fraser (smfr) 2017-09-20 11:22:45 PDT
Comment on attachment 321174 [details]
Patch

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

> Source/WebCore/rendering/RenderBox.cpp:2453
> +            computedValues.m_margins.m_start = 
> +                newMarginTotal - computedValues.m_margins.m_end;

Don't wrap these lines.

> Source/WebCore/rendering/RenderBox.cpp:2456
> +            computedValues.m_margins.m_end = 
> +                newMarginTotal - computedValues.m_margins.m_start;

Ditto.

> LayoutTests/fast/block/over-constrained-auto-margin.html:21
> +        <script>

I think this test could just dump the render tree, and not run any script.
Comment 10 zalan 2017-09-20 11:24:35 PDT
Comment on attachment 321174 [details]
Patch

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

> Source/WebCore/rendering/RenderBox.cpp:2448
> +        // We should not use the cb.marginStartForChild here, it has not been set yet

This comment is confusing as it refers to something that's not there anymore. It should rather be part of the Changlog entry.
Comment 11 Zhifei Fang 2017-09-20 11:58:24 PDT
Comment on attachment 321174 [details]
Patch

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

>> LayoutTests/fast/block/over-constrained-auto-margin.html:21
>> +        <script>
> 
> I think this test could just dump the render tree, and not run any script.

I am not sure about "dump the render tree", do we dump it as a picture? if so, the margin right will not been show in the picture, the error happened with the computed style it is should be -116px instead of -106px, we cannot tell it on the picture.
Comment 12 Zhifei Fang 2017-09-20 11:59:23 PDT
(In reply to Dave Hyatt from comment #8)
> Comment on attachment 321174 [details]
> Patch
> 
> I see that this is a port of a Blink patch. It might be good to reference
> that, since this is actually a Blink merge and not an original patch.

Add it in the change log ?
Comment 13 zalan 2017-09-20 12:06:01 PDT
Comment on attachment 321174 [details]
Patch

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

>>> LayoutTests/fast/block/over-constrained-auto-margin.html:21
>>> +        <script>
>> 
>> I think this test could just dump the render tree, and not run any script.
> 
> I am not sure about "dump the render tree", do we dump it as a picture? if so, the margin right will not been show in the picture, the error happened with the computed style it is should be -116px instead of -106px, we cannot tell it on the picture.

Dumping the render tree means something like this ->
layer at (0,0) size 943x600
  RenderView at (0,0) size 800x600
layer at (0,0) size 800x528
  RenderBlock {HTML} at (0,0) size 800x528
    RenderBody {BODY} at (8,8) size 784x0
      RenderBlock {DIV} at (0,0) size 935x0
        RenderBlock (floating) {DIV} at (0,0) size 935x500 [bgcolor=#EEEEEE]
          RenderBlock {DIV} at (0,0) size 935x500 [bgcolor=#ADD8E6]
        RenderBlock (floating) {DIV} at (0,0) size 146x300 [bgcolor=#A9A9A9]
        RenderBlock (floating) {DIV} at (635,0) size 300x300 [bgcolor=#A9A9A9]

But I think running script is fine, it's just I don't see why you remove the child at the end. Shouldn't it be something like instead?
document.body.offsetHeight; 
shouldBe("getComputedStyle(target1).marginRight", "'-116px'");
shouldBe("getComputedStyle(target2).marginLeft", "'-116px'");
(no need to do getElementById)
Comment 14 zalan 2017-09-20 12:06:34 PDT
(In reply to Zhifei Fang from comment #12)
> (In reply to Dave Hyatt from comment #8)
> > Comment on attachment 321174 [details]
> > Patch
> > 
> > I see that this is a port of a Blink patch. It might be good to reference
> > that, since this is actually a Blink merge and not an original patch.
> 
> Add it in the change log ?
Yes, please.
Comment 15 Zhifei Fang 2017-09-20 13:24:52 PDT
(In reply to zalan from comment #13)
> Comment on attachment 321174 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=321174&action=review
> 
> >>> LayoutTests/fast/block/over-constrained-auto-margin.html:21
> >>> +        <script>
> >> 
> >> I think this test could just dump the render tree, and not run any script.
> > 
> > I am not sure about "dump the render tree", do we dump it as a picture? if so, the margin right will not been show in the picture, the error happened with the computed style it is should be -116px instead of -106px, we cannot tell it on the picture.
> 
> Dumping the render tree means something like this ->
> layer at (0,0) size 943x600
>   RenderView at (0,0) size 800x600
> layer at (0,0) size 800x528
>   RenderBlock {HTML} at (0,0) size 800x528
>     RenderBody {BODY} at (8,8) size 784x0
>       RenderBlock {DIV} at (0,0) size 935x0
>         RenderBlock (floating) {DIV} at (0,0) size 935x500 [bgcolor=#EEEEEE]
>           RenderBlock {DIV} at (0,0) size 935x500 [bgcolor=#ADD8E6]
>         RenderBlock (floating) {DIV} at (0,0) size 146x300 [bgcolor=#A9A9A9]
>         RenderBlock (floating) {DIV} at (635,0) size 300x300
> [bgcolor=#A9A9A9]
> 
> But I think running script is fine, it's just I don't see why you remove the
> child at the end. Shouldn't it be something like instead?
> document.body.offsetHeight; 
> shouldBe("getComputedStyle(target1).marginRight", "'-116px'");
> shouldBe("getComputedStyle(target2).marginLeft", "'-116px'");
> (no need to do getElementById)

Got it, thanks !
Comment 16 Zhifei Fang 2017-09-20 13:25:07 PDT
(In reply to zalan from comment #14)
> (In reply to Zhifei Fang from comment #12)
> > (In reply to Dave Hyatt from comment #8)
> > > Comment on attachment 321174 [details]
> > > Patch
> > > 
> > > I see that this is a port of a Blink patch. It might be good to reference
> > > that, since this is actually a Blink merge and not an original patch.
> > 
> > Add it in the change log ?
> Yes, please.

No problem, will do it.
Comment 17 Dave Hyatt 2017-09-20 15:19:45 PDT
Comment on attachment 321174 [details]
Patch

r=me, just throw the link to the crbug in the changeling, so that all the history/discussion can be easily seen. Thanks.
Comment 18 Dave Hyatt 2017-09-20 15:20:20 PDT
ChangeLog. Stupid autocomplete. :)
Comment 19 Zhifei Fang 2017-09-20 18:26:20 PDT
(In reply to Dave Hyatt from comment #18)
> ChangeLog. Stupid autocomplete. :)

sure thing, will do
Comment 20 Zhifei Fang 2017-09-20 21:46:44 PDT
Created attachment 321408 [details]
Patch
Comment 21 Zhifei Fang 2017-09-20 21:47:35 PDT
(In reply to Zhifei Fang from comment #20)
> Created attachment 321408 [details]
> Patch

New patch!
Comment 22 WebKit Commit Bot 2017-09-21 09:28:38 PDT
Comment on attachment 321408 [details]
Patch

Clearing flags on attachment: 321408

Committed r222321: <http://trac.webkit.org/changeset/222321>
Comment 23 WebKit Commit Bot 2017-09-21 09:28:40 PDT
All reviewed patches have been landed.  Closing bug.
Comment 24 Radar WebKit Bug Importer 2017-09-27 12:32:38 PDT
<rdar://problem/34693454>