Files
sousa-gecko/testing/web-platform/tests/selection/shadow-dom
Masayuki Nakano 3b33428f92 Bug 2014622 - part 1: Make nsINode API for TreeKind::FlatForSelection treat nodes not a part of flattened tree correctly for Selection API r=smaug,dom-core-reviewers
Selection API accepts any DOM node in the non-flattened tree as a
container of a range boundary. Therefore, even if a node is not
formed in the flattened tree, e.g., inclusive descendants of
unassigned children of a shadow host element or a fallback content node
of `<slot>` which has some assigned nodes, the node is a valid container
of selection range boundaries and valid argument of Selection API and
Range API.

Therefore, when climbing up the flattened tree for selection, the
internal APIs should treat the non-flattened nodes are also connected
to the flattened tree. In this patch, the non-flattened children are
connected at end of the corresponding shadow root or `<slot>. The former
is defined as so in the shadow-including tree order [1]. However, I've
not found the definition for the latter. Therefore, I align the behavior
to the former behavior for making the code simpler.

When comparing the range boundaries in the flattened tree for selection
with the non-flattened nodes, we may need to use the position in the end
of the flattened node. However, setting
`nsRange::mCrossShadowBoundaryRange` boundaries to the nodes formed in
the flattened tree does not work well with `getComposedRange()`.
Therefore, this patch does not touch around that.

On the other hand, Chrome returns `false` from `Selection.containsNode`
if the node parameter is set to a non-flattened node. The spec [2]
defines with a fuzzy word, "visually". It's possible to understand that
non-flattened nodes never visually appear. And I tried to make it
compare with treating the positions of non-flattened nodes as end of
the corresponding shadow root or `<slot>`. However, it needs
complicated code and causes regressions in some tests, and anyway it's
incompatible with Chrome. Therefore, this patch makes
`Selection::ContainsNode` returns `false` if the given node is a
non-flattened node. I.e., the behavior is compatible with Chrome.

1. https://dom.spec.whatwg.org/#concept-shadow-including-tree-order
2. https://w3c.github.io/selection-api/#dom-selection-containsnode

Differential Revision: https://phabricator.services.mozilla.com/D307949
2026-07-05 23:40:41 +00:00
..