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

Code before:
            .take()
            .iter_mut()
            .map(|entry| entry.as_rooted())
            .collect();

        // Step 4-5
        let _ = self.callback.Call_(
            self,
            queued_entries,
            self,
            ExceptionHandling::Report,
            can_gc,
        );
    }

    /// Connect the observer itself into owner doc if it is unconnected.
    /// We check if we are already connected
    fn connect_to_owner(&self) {
        if !self.is_connected.get() {
            self.owner_doc.add_intersection_observer(self);
            self.is_connected.set(true);
        }
    }

    /// Disconnect the observer itself from owner doc.
    /// We we were already disconnected from the observer
    fn disconnect_from_owner(&self) {
        if self.is_connected.get() {
            self.owner_doc.remove_intersection_observer(self);
        }
    }

    /// > The root intersection rectangle for an IntersectionObserver is
    /// > the rectangle we’ll use to check against the targets.
    ///
    /// <https://w3c.github.io/IntersectionObserver/#intersectionobserver-root-intersection-rectangle>
    pub(crate) fn root_intersection_rectangle(
        &self,
        document: &Document,
    ) -> Option<Rect<Au, CSSPixel>> {
        let window = document.window();
        let intersection_rectangle = match &self.root {
            // Handle if root is an element.
            Some(ElementOrDocument::Element(element)) => {
                // TODO: recheck scrollbar approach and clip-path clipping from Chromium implementation.
                if element.style().is_some_and(|style| {
                    style.clone_overflow_x() != Overflow::Visible ||
                        style.clone_overflow_y() != Overflow::Visible
                }) {
                    // > Otherwise, if the intersection root has a content clip, it’s the element’s padding area.
                    window.box_area_query_without_reflow(

Review comment (suggestion):
```suggestion
    /// If not connected to a [`Document`], do nothing.
```

Code after:
            .take()
            .iter_mut()
            .map(|entry| entry.as_rooted())
            .collect();

        // Step 4-5
        let _ = self.callback.Call_(
            self,
            queued_entries,
            self,
            ExceptionHandling::Report,
            can_gc,
        );
    }

    /// Connect the observer itself into owner doc if it is unconnected.
    /// If the [`IntersectionObserver`] is already connected, do nothing.
    fn connect_to_owner(&self) {
        if !self.connected_to_document.get() {
            self.owner_doc.add_intersection_observer(self);
            self.connected_to_document.set(true);
        }
    }

    /// Disconnect the observer itself from owner doc.
    /// If not connected to a [`Document`], do nothing.
    fn disconnect_from_owner(&self) {
        if self.connected_to_document.get() {
            self.owner_doc.remove_intersection_observer(self);
        }
    }

    /// > The root intersection rectangle for an IntersectionObserver is
    /// > the rectangle we’ll use to check against the targets.
    ///
    /// <https://w3c.github.io/IntersectionObserver/#intersectionobserver-root-intersection-rectangle>
    pub(crate) fn root_intersection_rectangle(
        &self,
        document: &Document,
    ) -> Option<Rect<Au, CSSPixel>> {
        let window = document.window();
        let intersection_rectangle = match &self.root {
            // Handle if root is an element.
            Some(ElementOrDocument::Element(element)) => {
                // TODO: recheck scrollbar approach and clip-path clipping from Chromium implementation.
                if element.style().is_some_and(|style| {
                    style.clone_overflow_x() != Overflow::Visible ||
                        style.clone_overflow_y() != Overflow::Visible
                }) {
                    // > Otherwise, if the intersection root has a content clip, it’s the element’s padding area.
                    window.box_area_query_without_reflow(