From 461ff2681240abf50d1126e7a1c836f19f1b1616 Mon Sep 17 00:00:00 2001 From: Ashwin Naren Date: Wed, 27 Aug 2025 11:39:27 -0700 Subject: [PATCH] script: Move gamepad DOM interfaces to `script/dom/gamepad/` (#38900) Moves interfaces defined by the gamepad spec to the `script/dom/gamepad/` module from `script/dom/`. Testing: Just a refactor shouldn't need any testing Fixes: N/A Signed-off-by: Ashwin Naren --- components/script/dom/document_event_handler.rs | 10 +++++----- components/script/dom/{ => gamepad}/gamepad.rs | 8 ++++---- components/script/dom/{ => gamepad}/gamepadbutton.rs | 0 .../script/dom/{ => gamepad}/gamepadbuttonlist.rs | 2 +- components/script/dom/{ => gamepad}/gamepadevent.rs | 2 +- .../dom/{ => gamepad}/gamepadhapticactuator.rs | 0 components/script/dom/{ => gamepad}/gamepadpose.rs | 2 +- components/script/dom/gamepad/mod.rs | 12 ++++++++++++ components/script/dom/mod.rs | 6 +----- components/script/dom/navigator.rs | 2 +- 10 files changed, 26 insertions(+), 18 deletions(-) rename components/script/dom/{ => gamepad}/gamepad.rs (98%) rename components/script/dom/{ => gamepad}/gamepadbutton.rs (100%) rename components/script/dom/{ => gamepad}/gamepadbuttonlist.rs (98%) rename components/script/dom/{ => gamepad}/gamepadevent.rs (99%) rename components/script/dom/{ => gamepad}/gamepadhapticactuator.rs (100%) rename components/script/dom/{ => gamepad}/gamepadpose.rs (98%) create mode 100644 components/script/dom/gamepad/mod.rs diff --git a/components/script/dom/document_event_handler.rs b/components/script/dom/document_event_handler.rs index 54b3f4ba0a9..502060dd69d 100644 --- a/components/script/dom/document_event_handler.rs +++ b/components/script/dom/document_event_handler.rs @@ -44,15 +44,15 @@ use crate::dom::bindings::root::MutNullableDom; use crate::dom::clipboardevent::ClipboardEventType; use crate::dom::document::{FireMouseEventType, FocusInitiator, TouchEventResult}; use crate::dom::event::{EventBubbles, EventCancelable, EventDefault}; -use crate::dom::gamepad::contains_user_gesture; -use crate::dom::gamepadevent::GamepadEventType; +use crate::dom::gamepad::gamepad::{Gamepad, contains_user_gesture}; +use crate::dom::gamepad::gamepadevent::GamepadEventType; use crate::dom::inputevent::HitTestResult; use crate::dom::node::{self, Node, ShadowIncluding}; use crate::dom::pointerevent::PointerId; use crate::dom::types::{ - ClipboardEvent, CompositionEvent, DataTransfer, Element, Event, EventTarget, Gamepad, - GlobalScope, HTMLAnchorElement, KeyboardEvent, MouseEvent, PointerEvent, Touch, TouchEvent, - TouchList, WheelEvent, Window, + ClipboardEvent, CompositionEvent, DataTransfer, Element, Event, EventTarget, GlobalScope, + HTMLAnchorElement, KeyboardEvent, MouseEvent, PointerEvent, Touch, TouchEvent, TouchList, + WheelEvent, Window, }; use crate::drag_data_store::{DragDataStore, Kind, Mode}; use crate::realms::enter_realm; diff --git a/components/script/dom/gamepad.rs b/components/script/dom/gamepad/gamepad.rs similarity index 98% rename from components/script/dom/gamepad.rs rename to components/script/dom/gamepad/gamepad.rs index baf3af7466f..a31df7214a3 100644 --- a/components/script/dom/gamepad.rs +++ b/components/script/dom/gamepad/gamepad.rs @@ -8,7 +8,10 @@ use dom_struct::dom_struct; use embedder_traits::{GamepadSupportedHapticEffects, GamepadUpdateType}; use js::typedarray::{Float64, Float64Array}; -use super::bindings::buffer_source::HeapBufferSource; +use super::gamepadbuttonlist::GamepadButtonList; +use super::gamepadhapticactuator::GamepadHapticActuator; +use super::gamepadpose::GamepadPose; +use crate::dom::bindings::buffer_source::HeapBufferSource; use crate::dom::bindings::codegen::Bindings::GamepadBinding::{GamepadHand, GamepadMethods}; use crate::dom::bindings::codegen::Bindings::GamepadButtonListBinding::GamepadButtonListMethods; use crate::dom::bindings::inheritance::Castable; @@ -18,10 +21,7 @@ use crate::dom::bindings::root::{Dom, DomRoot}; use crate::dom::bindings::str::DOMString; use crate::dom::event::Event; use crate::dom::eventtarget::EventTarget; -use crate::dom::gamepadbuttonlist::GamepadButtonList; use crate::dom::gamepadevent::{GamepadEvent, GamepadEventType}; -use crate::dom::gamepadhapticactuator::GamepadHapticActuator; -use crate::dom::gamepadpose::GamepadPose; use crate::dom::globalscope::GlobalScope; use crate::dom::window::Window; use crate::script_runtime::{CanGc, JSContext}; diff --git a/components/script/dom/gamepadbutton.rs b/components/script/dom/gamepad/gamepadbutton.rs similarity index 100% rename from components/script/dom/gamepadbutton.rs rename to components/script/dom/gamepad/gamepadbutton.rs diff --git a/components/script/dom/gamepadbuttonlist.rs b/components/script/dom/gamepad/gamepadbuttonlist.rs similarity index 98% rename from components/script/dom/gamepadbuttonlist.rs rename to components/script/dom/gamepad/gamepadbuttonlist.rs index 7e540ab56bb..f1f807245d0 100644 --- a/components/script/dom/gamepadbuttonlist.rs +++ b/components/script/dom/gamepad/gamepadbuttonlist.rs @@ -7,7 +7,7 @@ use dom_struct::dom_struct; use crate::dom::bindings::codegen::Bindings::GamepadButtonListBinding::GamepadButtonListMethods; use crate::dom::bindings::reflector::{Reflector, reflect_dom_object}; use crate::dom::bindings::root::{Dom, DomRoot, DomSlice}; -use crate::dom::gamepadbutton::GamepadButton; +use crate::dom::gamepad::gamepadbutton::GamepadButton; use crate::dom::window::Window; use crate::script_runtime::CanGc; diff --git a/components/script/dom/gamepadevent.rs b/components/script/dom/gamepad/gamepadevent.rs similarity index 99% rename from components/script/dom/gamepadevent.rs rename to components/script/dom/gamepad/gamepadevent.rs index 5eabfd6111a..5bc88bcc0ec 100644 --- a/components/script/dom/gamepadevent.rs +++ b/components/script/dom/gamepad/gamepadevent.rs @@ -6,6 +6,7 @@ use dom_struct::dom_struct; use js::rust::HandleObject; use stylo_atoms::Atom; +use super::gamepad::Gamepad; use crate::dom::bindings::codegen::Bindings::EventBinding::Event_Binding::EventMethods; use crate::dom::bindings::codegen::Bindings::GamepadEventBinding; use crate::dom::bindings::codegen::Bindings::GamepadEventBinding::GamepadEventMethods; @@ -15,7 +16,6 @@ use crate::dom::bindings::reflector::reflect_dom_object_with_proto; use crate::dom::bindings::root::{Dom, DomRoot}; use crate::dom::bindings::str::DOMString; use crate::dom::event::Event; -use crate::dom::gamepad::Gamepad; use crate::dom::window::Window; use crate::script_runtime::CanGc; diff --git a/components/script/dom/gamepadhapticactuator.rs b/components/script/dom/gamepad/gamepadhapticactuator.rs similarity index 100% rename from components/script/dom/gamepadhapticactuator.rs rename to components/script/dom/gamepad/gamepadhapticactuator.rs diff --git a/components/script/dom/gamepadpose.rs b/components/script/dom/gamepad/gamepadpose.rs similarity index 98% rename from components/script/dom/gamepadpose.rs rename to components/script/dom/gamepad/gamepadpose.rs index 5d55288b02b..64915c07bfe 100644 --- a/components/script/dom/gamepadpose.rs +++ b/components/script/dom/gamepad/gamepadpose.rs @@ -5,7 +5,7 @@ use dom_struct::dom_struct; use js::typedarray::{Float32, Float32Array}; -use super::bindings::buffer_source::HeapBufferSource; +use crate::dom::bindings::buffer_source::HeapBufferSource; use crate::dom::bindings::codegen::Bindings::GamepadPoseBinding::GamepadPoseMethods; use crate::dom::bindings::reflector::{Reflector, reflect_dom_object}; use crate::dom::bindings::root::DomRoot; diff --git a/components/script/dom/gamepad/mod.rs b/components/script/dom/gamepad/mod.rs new file mode 100644 index 00000000000..17b026be1d3 --- /dev/null +++ b/components/script/dom/gamepad/mod.rs @@ -0,0 +1,12 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ + +#[expect(clippy::module_inception, reason = "The interface name is Gamepad")] +pub(crate) mod gamepad; +pub(crate) use gamepad::Gamepad; +pub(crate) mod gamepadbutton; +pub(crate) mod gamepadbuttonlist; +pub(crate) mod gamepadevent; +pub(crate) mod gamepadhapticactuator; +pub(crate) mod gamepadpose; diff --git a/components/script/dom/mod.rs b/components/script/dom/mod.rs index e27afd6c47e..fb472b83af8 100644 --- a/components/script/dom/mod.rs +++ b/components/script/dom/mod.rs @@ -325,11 +325,7 @@ pub(crate) mod fontfaceset; pub(crate) mod formdata; pub(crate) mod formdataevent; pub(crate) mod gamepad; -pub(crate) mod gamepadbutton; -pub(crate) mod gamepadbuttonlist; -pub(crate) mod gamepadevent; -pub(crate) mod gamepadhapticactuator; -pub(crate) mod gamepadpose; +pub(crate) use self::gamepad::*; #[allow(dead_code)] pub(crate) mod globalscope; pub(crate) mod hashchangeevent; diff --git a/components/script/dom/navigator.rs b/components/script/dom/navigator.rs index 84481b18e8c..f4eb51d6873 100644 --- a/components/script/dom/navigator.rs +++ b/components/script/dom/navigator.rs @@ -36,7 +36,7 @@ use crate::dom::bluetooth::Bluetooth; use crate::dom::clipboard::Clipboard; use crate::dom::csp::{GlobalCspReporting, Violation}; use crate::dom::gamepad::Gamepad; -use crate::dom::gamepadevent::GamepadEventType; +use crate::dom::gamepad::gamepadevent::GamepadEventType; use crate::dom::globalscope::GlobalScope; use crate::dom::mediadevices::MediaDevices; use crate::dom::mediasession::MediaSession;