Skip to content

Make setBaseAndExtent and other setter methods on Selection work with shadow DOM #99

Open

Description

@rniwa

Per WICG/webcomponents#79, we should make setBaseAndExtent and other methods work with shadow DOM. Namely, when a node inside a shadow tree is given to setBaseAndExtent, it shouldn't throw or adjust the end points to be in the same tree.

Activity

  1. rniwa commented on Jul 20, 2023

    @rniwa
    ContributorAuthor

    At least collapse working with shadow DOM is a web compatibility requirement at this point:
    WebKit/WebKit@c48d719

  2. annevk commented on Jul 25, 2023

    @annevk
    Member

    Hmm, so when a shadow tree child is selected it's exposed through a global API? That seems rather bad.

  3. rniwa commented on Jul 25, 2023

    @rniwa
    ContributorAuthor

    No, it's not exposed. It's just that these setter functions need to allow referencing into nodes within shadow trees. Getters will continue to return the outer most host.

  4. masayuki-nakano commented on Feb 4, 2026

    @masayuki-nakano

    Selection.extend has the similar issue and it seems that browsers work differently.

    However, I think the spec can allow to specify a point in different subtree root point with a pair of the container and the offset in it, but cannot allow to specify a point in a flattened tree specific point.

    For example, if a node is assigned to a <slot>, specifying the point should be the parent node of the node and offset of the node in the non-flattened tree rather than <slot> and index in the assigned node list. Otherwise, the implementations cannot distinguish whether the API caller intended a point in the flattened tree or the non-flattened tree.

    Similarly, the shadow host and an offset should not be treated as the shadow root and the offset in it.

    So, the spec needs to define the logic from a point in the non-flattened tree to one in the flattented tree.

    However, there is a problem, I tried to write the conversion for the internal use in Gecko, but there are probably 2 intentions about the offset. One is specifying after the previous child of the child at offset. The other is specifying the child at the offset directly. Currently, Gecko assumes the former if the point is collapsed or end boundary of a range and the latter if the point is start boundary of a range.
    https://searchfox.org/firefox-main/rev/c206271d981e72dac0fdd91625b2c0709129a7d6/dom/base/RangeBoundary.h#349-387

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions