Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 93f39b4a340fd08d92f9b267c774229ebabefeaf
      
https://github.com/WebKit/WebKit/commit/93f39b4a340fd08d92f9b267c774229ebabefeaf
  Author: Sammy Gill <[email protected]>
  Date:   2026-04-24 (Fri, 24 Apr 2026)

  Changed paths:
    A 
LayoutTests/fast/shadow-dom/slot-display-contents-composed-tree-after-display-toggle-expected.txt
    A 
LayoutTests/fast/shadow-dom/slot-display-contents-composed-tree-after-display-toggle.html
    A 
LayoutTests/imported/w3c/web-platform-tests/shadow-dom/slot-display-contents-display-toggle-expected.html
    A 
LayoutTests/imported/w3c/web-platform-tests/shadow-dom/slot-display-contents-display-toggle-ref.html
    A 
LayoutTests/imported/w3c/web-platform-tests/shadow-dom/slot-display-contents-display-toggle.html
    M Source/WebCore/dom/ComposedTreeIterator.cpp
    M Source/WebCore/dom/ComposedTreeIterator.h
    M Source/WebCore/testing/Internals.cpp
    M Source/WebCore/testing/Internals.h
    M Source/WebCore/testing/Internals.idl

  Log Message:
  -----------
  marketwatch.com: Tapping the “share” button causes the media controls to 
shift to the top of the video.
rdar://157607616
https://bugs.webkit.org/show_bug.cgi?id=313028

Reviewed by Antti Koivisto.

When an element goes from display: none to some other display we need to
find a spot in the render tree to insert it. This is done by taking said
element and its rendering parent and finding its next sibling in the
render tree. One of the things that happens is we create an iterator to
go over the composed tree in order to find this spot.

However, one problem that can arise, which seems to be the source of the
bug on MarketWatch, is when the element we are creating a renderer for is
part of some slotted content that is a descendant of elements with
display: contents.

When we try to initialize the context stack, we walk up from the target
node to the root. Initially currentContext is set to the targeted node
and gets updated as we cross different boundaries. However, one thing to
note is that if we hit a parent/ancestor that has display: contents we
do not update contextCurrent. Then by the time we hit a boundary
and need to create a Context for the slotted content we use the targeted
node to compute the iterator's start and end.

For the case of the MarketWatch bug the iterator points to the targeted
node and the end iterator points to its sibling which is the source of
the bug. When we try to traverse the iterator we reach the end (the
sibling) and that gives us an incorrect insertion point. What should
instead happen is that the end should point to the end of the slotted
content, which is the end of the display: contents subtree.

To fix this we can:
1.) Detect this case if the node and the current context is not the
same *and* the node has display: contents.
2.) Create a dedicated constructor that will take in a separate node to
compute the iterator's end from alongside the current context and root.
This can replace the existing one and we can just pass in the same node
which is what we were doing before.

* 
LayoutTests/fast/shadow-dom/slot-display-contents-composed-tree-after-display-toggle-expected.txt:
 Added.
* 
LayoutTests/fast/shadow-dom/slot-display-contents-composed-tree-after-display-toggle.html:
 Added.
* 
LayoutTests/imported/w3c/web-platform-tests/shadow-dom/slot-display-contents-display-toggle-expected.html:
 Added.
* 
LayoutTests/imported/w3c/web-platform-tests/shadow-dom/slot-display-contents-display-toggle-ref.html:
 Added.
* 
LayoutTests/imported/w3c/web-platform-tests/shadow-dom/slot-display-contents-display-toggle.html:
 Added.
<my-el>                         <!-- parent: has a shadow root -->
    <div style="display:contents">   <!-- node: the slotted element -->
      <div id="a">A</div>            <!-- contextCurrent: the target -->
      <div>B</div>
    </div>
</my-el>

* Source/WebCore/testing/Internals.cpp:
(WebCore::Internals::composedTreeAsTextFromNode):
* Source/WebCore/testing/Internals.h:
* Source/WebCore/testing/Internals.idl:
A new internal function so that we can trigger the stack initialization
logic along with a unit test for it.

Canonical link: https://commits.webkit.org/312003@main



To unsubscribe from these emails, change your notification settings at 
https://github.com/WebKit/WebKit/settings/notifications

Reply via email to