Repository: servo/servo
File: components/script/dom/shadowroot.rs (Rust)

Code before:

    slots: DomRefCell<HashMap<DOMString, Vec<Dom<HTMLSlotElement>>>>,

    is_user_agent_widget: bool,

    /// <https://dom.spec.whatwg.org/#shadowroot-declarative>
    declarative: Cell<bool>,

    /// <https://dom.spec.whatwg.org/#shadowroot-serializable>
    serializable: Cell<bool>,

    /// <https://dom.spec.whatwg.org/#shadowroot-delegates-focus>
    delegates_focus: Cell<bool>,

    /// The constructed stylesheet that is adopted by this [ShadowRoot].
    /// <https://drafts.csswg.org/cssom/#dom-documentorshadowroot-adoptedstylesheets>
    adopted_stylesheets: DomRefCell<Vec<Dom<CSSStyleSheet>>>,

    /// Cached frozen array of [`Self::adopted_stylesheets`]
    #[ignore_malloc_size_of = "mozjs"]
    adopted_stylesheets_frozen_types: CachedFrozenArray,

    details_name_groups: DomRefCell<Option<DetailsNameGroups>>,

    /// Entry node for fullscreen.
    fullscreen_element: MutNullableDom<Element>,
}

impl ShadowRoot {
    #[cfg_attr(crown, expect(crown::unrooted_must_root))]
    fn new_inherited(
        host: &Element,
        document: &Document,
        mode: ShadowRootMode,
        slot_assignment_mode: SlotAssignmentMode,
        clonable: bool,
        is_user_agent_widget: IsUserAgentWidget,
    ) -> ShadowRoot {
        let document_fragment = DocumentFragment::new_inherited(document);
        let node = document_fragment.upcast::<Node>();
        node.set_flag(NodeFlags::IS_IN_SHADOW_TREE, true);
        node.set_flag(
            NodeFlags::IS_CONNECTED,
            host.upcast::<Node>().is_connected(),
        );

        ShadowRoot {
            document_fragment,
            document_or_shadow_root: DocumentOrShadowRoot::new(document.window()),
            document: Dom::from_ref(document),
            host: Dom::from_ref(host),

Review comment (suggestion):
The spec doesn't really define what is the shadow root's fullscreen element. But, looking at the definition of the fullscreen element.

> The [fullscreen element](https://fullscreen.spec.whatwg.org/#fullscreen-element) is the topmost [element](https://dom.spec.whatwg.org/#concept-element) in the [document](https://dom.spec.whatwg.org/#concept-document)’s [top layer](https://drafts.csswg.org/css-position-4/#document-top-layer) whose [fullscreen flag](https://fullscreen.spec.whatwg.org/#fullscreen-flag) is set, if any, and null otherwise. 

It looks like we could refer the one in the document, instead of storing one here. 

Code after:

    slots: DomRefCell<HashMap<DOMString, Vec<Dom<HTMLSlotElement>>>>,

    is_user_agent_widget: bool,

    /// <https://dom.spec.whatwg.org/#shadowroot-declarative>
    declarative: Cell<bool>,

    /// <https://dom.spec.whatwg.org/#shadowroot-serializable>
    serializable: Cell<bool>,

    /// <https://dom.spec.whatwg.org/#shadowroot-delegates-focus>
    delegates_focus: Cell<bool>,

    /// The constructed stylesheet that is adopted by this [ShadowRoot].
    /// <https://drafts.csswg.org/cssom/#dom-documentorshadowroot-adoptedstylesheets>
    adopted_stylesheets: DomRefCell<Vec<Dom<CSSStyleSheet>>>,

    /// Cached frozen array of [`Self::adopted_stylesheets`]
    #[ignore_malloc_size_of = "mozjs"]
    adopted_stylesheets_frozen_types: CachedFrozenArray,

    details_name_groups: DomRefCell<Option<DetailsNameGroups>>,
}

impl ShadowRoot {
    #[cfg_attr(crown, expect(crown::unrooted_must_root))]
    fn new_inherited(
        host: &Element,
        document: &Document,
        mode: ShadowRootMode,
        slot_assignment_mode: SlotAssignmentMode,
        clonable: bool,
        is_user_agent_widget: IsUserAgentWidget,
    ) -> ShadowRoot {
        let document_fragment = DocumentFragment::new_inherited(document);
        let node = document_fragment.upcast::<Node>();
        node.set_flag(NodeFlags::IS_IN_SHADOW_TREE, true);
        node.set_flag(
            NodeFlags::IS_CONNECTED,
            host.upcast::<Node>().is_connected(),
        );

        ShadowRoot {
            document_fragment,
            document_or_shadow_root: DocumentOrShadowRoot::new(document.window()),
            document: Dom::from_ref(document),
            host: Dom::from_ref(host),
            author_styles: DomRefCell::new(AuthorStyles::new()),
            stylesheet_list: MutNullableDom::new(None),
            window: Dom::from_ref(document.window()),