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

Code before:
    pub(crate) fn is_declarative(&self) -> bool {
        self.declarative.get()
    }

    pub(crate) fn shadow_root_mode(&self) -> ShadowRootMode {
        self.mode
    }

    pub(crate) fn set_serializable(&self, serializable: bool) {
        self.serializable.set(serializable);
    }

    pub(crate) fn set_delegates_focus(&self, delegates_focus: bool) {
        self.delegates_focus.set(delegates_focus);
    }

    pub(crate) fn details_name_groups(&self) -> RefMut<'_, DetailsNameGroups> {
        RefMut::map(
            self.details_name_groups.borrow_mut(),
            |details_name_groups| details_name_groups.get_or_insert_default(),
        )
    }

    pub(crate) fn set_fullscreen_element(&self, element: Option<&Element>) {
        self.fullscreen_element.set(element);
    }
}

impl ShadowRootMethods<crate::DomTypeHolder> for ShadowRoot {
    /// <https://html.spec.whatwg.org/multipage/#dom-document-activeelement>
    fn GetActiveElement(&self) -> Option<DomRoot<Element>> {
        self.document_or_shadow_root
            .get_active_element(self.get_focused_element(), None, None)
    }

    /// <https://drafts.csswg.org/cssom-view/#dom-document-elementfrompoint>
    fn ElementFromPoint(&self, x: Finite<f64>, y: Finite<f64>) -> Option<DomRoot<Element>> {
        // Return the result of running the retargeting algorithm with context object
        // and the original result as input.
        match self.document_or_shadow_root.element_from_point(
            x,
            y,
            None,
            self.document.has_browsing_context(),
        ) {
            Some(e) => {
                let retargeted_node = e.upcast::<EventTarget>().retarget(self.upcast());
                retargeted_node.downcast::<Element>().map(DomRoot::from_ref)
            },
            None => None,
        }

Review comment (suggestion):
Maybe this is unnecessary if we define `Document::fullscreen_element` that get the raw fullscreen element of the document. Though, it need a TODO comment since fullscreen element should refer to the 

> The fullscreen element is the topmost element in the document’s top layer whose fullscreen flag is set, if any, and null otherwise.

instead of our current implementation.

Code after:
    pub(crate) fn shadow_root_mode(&self) -> ShadowRootMode {
        self.mode
    }

    pub(crate) fn set_serializable(&self, serializable: bool) {
        self.serializable.set(serializable);
    }

    pub(crate) fn set_delegates_focus(&self, delegates_focus: bool) {
        self.delegates_focus.set(delegates_focus);
    }

    pub(crate) fn details_name_groups(&self) -> RefMut<'_, DetailsNameGroups> {
        RefMut::map(
            self.details_name_groups.borrow_mut(),
            |details_name_groups| details_name_groups.get_or_insert_default(),
        )
    }
}

impl ShadowRootMethods<crate::DomTypeHolder> for ShadowRoot {
    /// <https://html.spec.whatwg.org/multipage/#dom-document-activeelement>
    fn GetActiveElement(&self) -> Option<DomRoot<Element>> {
        self.document_or_shadow_root
            .get_active_element(self.get_focused_element(), None, None)
    }

    /// <https://drafts.csswg.org/cssom-view/#dom-document-elementfrompoint>
    fn ElementFromPoint(&self, x: Finite<f64>, y: Finite<f64>) -> Option<DomRoot<Element>> {
        // Return the result of running the retargeting algorithm with context object
        // and the original result as input.
        match self.document_or_shadow_root.element_from_point(
            x,
            y,
            None,
            self.document.has_browsing_context(),
        ) {
            Some(e) => {
                let retargeted_node = e.upcast::<EventTarget>().retarget(self.upcast());
                retargeted_node.downcast::<Element>().map(DomRoot::from_ref)
            },
            None => None,
        }
    }

    /// <https://drafts.csswg.org/cssom-view/#dom-document-elementsfrompoint>
    fn ElementsFromPoint(&self, x: Finite<f64>, y: Finite<f64>) -> Vec<DomRoot<Element>> {
        // Return the result of running the retargeting algorithm with context object
        // and the original result as input
        let mut elements = Vec::new();
        for e in self