Files
Ian Kilpatrick fb5eaf8690 Bug 2035073 [wpt PR 59457] - [layout] Remove the anonymous block before reparenting children., a=testonly
Automatic update from web-platform-tests
[layout] Remove the anonymous block before reparenting children.

There was a small functional change within:
https://chromium.googlesource.com/chromium/src/+/ca6e0f7e75fbe39b2322a5352fa10e2001671a02

We have a "full_remove_insert" parameter which is used to trigger a
safer set of invalidations, as well as invoking LayoutObject::AddChild
instead of reaching into the LayoutObjectChildList and changing it
directly.

We set this parameter to "true". When the anonymous block was attached
to its parent, and we tried to reparent the abspos to the parent
block-flow the following happened:
 - We'd invoke MoveAllChildrenTo(...., true);
 - This would try and reparent the abspos.
 - We'd invoke LayoutBlockFlow::AddChild
 - This would trigger the following line:
   "if (after_child && after_child->IsAnonymousBlockFlow())"

after_child was the thing we were tying to remove children from!

So the abspos would get re-inserted to the end of our anonymous block
child (which technically was correct as it was being placed before the
"before_child"). It'd process all the remaining children, then process
the abspos again, inserting it into the incorrect position now.

We want to leave this parameter to "true" always, so to fix this we just
need to remove "this" from its parent, then reparent all its children.
This means that the LayoutBlockFlow::AddChild logic doesn't see the
anonymous block-flow and doesn't get confused.

The layout-tree before and after this change.

Before:

```
LayoutView 0x134021009d8                #document
  LayoutBlockFlow 0x13402100b60         HTML
    LayoutBlockFlow 0x13402100c50       BODY
*     LayoutBlockFlow (relative positioned) 0x13402100cf0 DIV style="position: relative;"
        LayoutBlockFlow 0x13402101210   DIV id="target" style="display: block;"
        LayoutBlockFlow (anonymous, children-inline) 0x134021012b0
          LayoutBlockFlow (inline) 0x13402100ed0  SPAN style="display: inline-block;"
          LayoutText 0x13402100f70      #text "\n  "
          LayoutBlockFlow (positioned) 0x13402100fe0  DIV class="abspos" style="background: green;"
          LayoutBlockFlow (positioned) 0x13402100de0  DIV class="abspos" style="background: red;"
        LayoutBlockFlow 0x134021010d0   DIV
```

After:

```
LayoutView 0x134021009d8                #document
  LayoutBlockFlow 0x13402100b60         HTML
    LayoutBlockFlow 0x13402100c50       BODY
*     LayoutBlockFlow (relative positioned) 0x13402100cf0 DIV style="position: relative;"
        LayoutBlockFlow (positioned) 0x13402100de0  DIV class="abspos" style="background: red;"
        LayoutBlockFlow 0x13402101210   DIV id="target" style="display: block;"
        LayoutBlockFlow (anonymous, children-inline) 0x134021012b0
          LayoutBlockFlow (inline) 0x13402100ed0  SPAN style="display: inline-block;"
          LayoutText 0x13402100f70      #text "\n  "
          LayoutBlockFlow (positioned) 0x13402100fe0  DIV class="abspos" style="background: green;"
        LayoutBlockFlow 0x134021010d0   DIV
```

Fixed: 505179602
Change-Id: I7f229a3d670d75e4290a88671d92ad73ec1dd34f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/7791943
Auto-Submit: Ian Kilpatrick <[email protected]>
Commit-Queue: Ian Kilpatrick <[email protected]>
Reviewed-by: Morten Stenshorne <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1620382}

--

wpt-commits: 6489f94bc054e4aee18a9524e00e41474f82c2b8
wpt-pr: 59457
2026-05-05 08:42:16 +00:00
..