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

Code before:
                            data.to_string(),
                        ));
                    },
                    Kind::File { .. } => {
                        // Step 1.2.2 If data is of a type listed in the mandatory data types list, then
                        // Step 1.2.2.1 Place part on clipboard with the appropriate OS clipboard format description
                        // Step 1.2.3 Else this is left to the implementation
                    },
                }
            }
        } else {
            // Step 2.1
            if drag_data_store.clear_was_called {
                // Step 2.1.1 If types-to-clear list is empty, clear the clipboard
                self.window
                    .send_to_embedder(EmbedderMsg::ClearClipboard(self.window.webview_id()));
                // Step 2.1.2 Else remove the types in the list from the clipboard
                // As of now this can't be done with Arboard, and it's possible that will be removed from the spec
            }
        }
    }

    /// Handle scroll triggered by user interactions from embedder side.
    /// <https://drafts.csswg.org/cssom-view/#scrolling-events>
    #[expect(unsafe_code)]
    pub(crate) fn handle_embedder_scroll(&self, scrolled_node: ExternalScrollId) {
        // If it is a viewport scroll.
        let document = self.window.Document();
        if scrolled_node.is_root() {
            document.handle_viewport_scroll_event();
        } else {
            // Otherwise, check whether it is for a relevant element within the document.
            let Some(node_id) = node_id_from_scroll_id(scrolled_node.0 as usize) else {
                return;
            };
            let node = unsafe {
                node::from_untrusted_node_address(UntrustedNodeAddress::from_id(node_id))
            };
            let Some(element) = node
                .inclusive_ancestors(ShadowIncluding::Yes)
                .find_map(DomRoot::downcast::<Element>)
            else {
                return;
            };

            document.handle_element_scroll_event(&element);
        }
    }

    pub(crate) fn run_default_keyboard_event_handler(&self, event: &KeyboardEvent) {
        if event.upcast::<Event>().type_() != atom!("keydown") {

Review comment (suggestion):
I don't think it makes sense to remove `event` from the name here. We aren't just generically handling the a scroll from the embedder, we are *sending the event* for this scroll.

Code after:
                            data.to_string(),
                        ));
                    },
                    Kind::File { .. } => {
                        // Step 1.2.2 If data is of a type listed in the mandatory data types list, then
                        // Step 1.2.2.1 Place part on clipboard with the appropriate OS clipboard format description
                        // Step 1.2.3 Else this is left to the implementation
                    },
                }
            }
        } else {
            // Step 2.1
            if drag_data_store.clear_was_called {
                // Step 2.1.1 If types-to-clear list is empty, clear the clipboard
                self.window
                    .send_to_embedder(EmbedderMsg::ClearClipboard(self.window.webview_id()));
                // Step 2.1.2 Else remove the types in the list from the clipboard
                // As of now this can't be done with Arboard, and it's possible that will be removed from the spec
            }
        }
    }

    /// Handle a scroll event triggered by user interactions from the embedder.
    /// <https://drafts.csswg.org/cssom-view/#scrolling-events>
    #[expect(unsafe_code)]
    pub(crate) fn handle_embedder_scroll_event(&self, scrolled_node: ExternalScrollId) {
        // If it is a viewport scroll.
        let document = self.window.Document();
        if scrolled_node.is_root() {
            document.handle_viewport_scroll_event();
        } else {
            // Otherwise, check whether it is for a relevant element within the document.
            let Some(node_id) = node_id_from_scroll_id(scrolled_node.0 as usize) else {
                return;
            };
            let node = unsafe {
                node::from_untrusted_node_address(UntrustedNodeAddress::from_id(node_id))
            };
            let Some(element) = node
                .inclusive_ancestors(ShadowIncluding::Yes)
                .find_map(DomRoot::downcast::<Element>)
            else {
                return;
            };

            document.handle_element_scroll_event(&element);
        }
    }

    pub(crate) fn run_default_keyboard_event_handler(&self, event: &KeyboardEvent) {
        if event.upcast::<Event>().type_() != atom!("keydown") {