-
Notifications
You must be signed in to change notification settings - Fork 28
Description
This surfaced from the conversation at TPAC 2024 about whether we should use a Flat Tree Traversal (Meeting notes) for comparing Selection positions that cross shadow trees.
Composed Tree
With the Composed Tree, we do the normal DOM tree traversal, but consider the owner document to be the common ancestor.
Why this is good:
- Currently, most Selection API uses the Composed Tree, including setStart/setEnd/setBaseAndExtent/isPointInRange. There might be many compat risks to change these APIs.
- Doesn’t require updating Style and Layout. Easier to implement.
Flat Tree
With the Flat Tree, we traverse a flattened tree where the shadow trees are flattened to all be contained within one tree.
Why this is good:
- This is what the user sees when the selection is painted.
- Would take care of re-ordered slotted contents.
- Would make IsPointInRange() and toString() more useful to web users, as what the user sees is what’s selected in the flat tree.
- It avoids the problem of multiple range objects to manage, but looks visually contiguous to the user
Open questions
- Should we change existing Selection APIs to use flat trees? This information can be stored internally and only be accessed by getComposedRanges(), keeping the rest of the behaviors unchanged.
- Else, should we have new APIs which definitely do use Flat Tree?
- Should we support discontiguous ranges?
Examples:
Selection where start and end are in the same tree, but slotted to be in reverse order.
Selection start from the sibling of shadow host, end inside the slotted content.
https://github.com/mfreed7/shadow-dom-selection?tab=readme-ov-file#3-slotted-content
Some use cases
Bidi, tables, flex/grid layout maybe.
Related issues
Need spec changes to Range and StaticRange to support nodes in different tree? #169
Serialization of the current selection, when that selection crosses shadow roots #163