mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
Gamepad: Implement GamepadHapticActuator (#32046)
* Implement Servo side of GamepadHapticActuator Signed-off-by: Daniel Adams <msub2official@gmail.com> * Get build working Signed-off-by: Daniel Adams <msub2official@gmail.com> * Create effect handling on embedder side Signed-off-by: Daniel Adams <msub2official@gmail.com> * Update tracing for GamepadHapticEffect Signed-off-by: Daniel Adams <msub2official@gmail.com> * Update gilrs to point to commit with effect complete event Signed-off-by: Daniel Adams <msub2official@gmail.com> * Implement playing and preempting haptic effects Signed-off-by: Daniel Adams <msub2official@gmail.com> * Update IDL to add trigger rumble Signed-off-by: Daniel Adams <msub2official@gmail.com> * Update WPT expectations Signed-off-by: Daniel Adams <msub2official@gmail.com> * Handle stopping haptic effects from reset() Signed-off-by: Daniel Adams <msub2official@gmail.com> * ./mach fmt, fix test-tidy issues Signed-off-by: Daniel Adams <msub2official@gmail.com> * Add extra validity checks for trigger rumble Signed-off-by: Daniel Adams <msub2official@gmail.com> * Retrieve supported haptic effects from embedder Signed-off-by: Daniel Adams <msub2official@gmail.com> * Fix test expectations Signed-off-by: Daniel Adams <msub2official@gmail.com> * Add missing spec link, pin gilrs commit Signed-off-by: Daniel Adams <msub2official@gmail.com> * servoshell cargo formatting Signed-off-by: Daniel Adams <msub2official@gmail.com> * Fix Cargo.toml Signed-off-by: Daniel Adams <msub2official@gmail.com> * Additional comments, realm proof, naming Signed-off-by: Daniel Adams <msub2official@gmail.com> * ./mach fmt Signed-off-by: Daniel Adams <msub2official@gmail.com> * Update gilrs rev to gilrs-core 0.5.12 release Signed-off-by: Daniel Adams <msub2official@gmail.com> * Implement sequence ids for gamepad haptic promises Signed-off-by: Daniel Adams <msub2official@gmail.com> * Take playing effect promise instead of cloning Signed-off-by: Daniel Adams <msub2official@gmail.com> * Implement listener for reset function Signed-off-by: Daniel Adams <msub2official@gmail.com> * Fix Cargo.lock Signed-off-by: Daniel Adams <msub2official@gmail.com> * Restructure IPC listeners, add comments, handle visibility change Signed-off-by: Daniel Adams <msub2official@gmail.com> * Check that haptic effect still exists before handling ff completion event Signed-off-by: Daniel Adams <msub2official@gmail.com> * Visibility steps, add InRealm bindings for promises Signed-off-by: Daniel Adams <msub2official@gmail.com> * Add Gamepad EmbedderMsg arms to egl servo_glue Signed-off-by: Daniel Adams <msub2official@gmail.com> --------- Signed-off-by: Daniel Adams <msub2official@gmail.com>
This commit is contained in:
parent
9212ed203a
commit
2c17de7fa7
18 changed files with 652 additions and 68 deletions
|
@ -6,7 +6,7 @@ use std::cell::Cell;
|
|||
|
||||
use dom_struct::dom_struct;
|
||||
use js::typedarray::{Float64, Float64Array};
|
||||
use script_traits::GamepadUpdateType;
|
||||
use script_traits::{GamepadSupportedHapticEffects, GamepadUpdateType};
|
||||
|
||||
use super::bindings::buffer_source::HeapBufferSource;
|
||||
use crate::dom::bindings::codegen::Bindings::GamepadBinding::{GamepadHand, GamepadMethods};
|
||||
|
@ -20,6 +20,7 @@ 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::script_runtime::JSContext;
|
||||
|
@ -49,6 +50,7 @@ pub struct Gamepad {
|
|||
axis_bounds: (f64, f64),
|
||||
button_bounds: (f64, f64),
|
||||
exposed: Cell<bool>,
|
||||
vibration_actuator: Dom<GamepadHapticActuator>,
|
||||
}
|
||||
|
||||
impl Gamepad {
|
||||
|
@ -65,6 +67,7 @@ impl Gamepad {
|
|||
hand: GamepadHand,
|
||||
axis_bounds: (f64, f64),
|
||||
button_bounds: (f64, f64),
|
||||
vibration_actuator: &GamepadHapticActuator,
|
||||
) -> Gamepad {
|
||||
Self {
|
||||
reflector_: Reflector::new(),
|
||||
|
@ -81,6 +84,7 @@ impl Gamepad {
|
|||
axis_bounds,
|
||||
button_bounds,
|
||||
exposed: Cell::new(false),
|
||||
vibration_actuator: Dom::from_ref(vibration_actuator),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -90,8 +94,16 @@ impl Gamepad {
|
|||
id: String,
|
||||
axis_bounds: (f64, f64),
|
||||
button_bounds: (f64, f64),
|
||||
supported_haptic_effects: GamepadSupportedHapticEffects,
|
||||
) -> DomRoot<Gamepad> {
|
||||
Self::new_with_proto(global, gamepad_id, id, axis_bounds, button_bounds)
|
||||
Self::new_with_proto(
|
||||
global,
|
||||
gamepad_id,
|
||||
id,
|
||||
axis_bounds,
|
||||
button_bounds,
|
||||
supported_haptic_effects,
|
||||
)
|
||||
}
|
||||
|
||||
/// When we construct a new gamepad, we initialize the number of buttons and
|
||||
|
@ -105,8 +117,11 @@ impl Gamepad {
|
|||
id: String,
|
||||
axis_bounds: (f64, f64),
|
||||
button_bounds: (f64, f64),
|
||||
supported_haptic_effects: GamepadSupportedHapticEffects,
|
||||
) -> DomRoot<Gamepad> {
|
||||
let button_list = GamepadButtonList::init_buttons(global);
|
||||
let vibration_actuator =
|
||||
GamepadHapticActuator::new(global, gamepad_id, supported_haptic_effects);
|
||||
let gamepad = reflect_dom_object_with_proto(
|
||||
Box::new(Gamepad::new_inherited(
|
||||
gamepad_id,
|
||||
|
@ -120,6 +135,7 @@ impl Gamepad {
|
|||
GamepadHand::_empty,
|
||||
axis_bounds,
|
||||
button_bounds,
|
||||
&vibration_actuator,
|
||||
)),
|
||||
global,
|
||||
None,
|
||||
|
@ -165,6 +181,11 @@ impl GamepadMethods for Gamepad {
|
|||
DomRoot::from_ref(&*self.buttons)
|
||||
}
|
||||
|
||||
// https://w3c.github.io/gamepad/#dom-gamepad-vibrationactuator
|
||||
fn VibrationActuator(&self) -> DomRoot<GamepadHapticActuator> {
|
||||
DomRoot::from_ref(&*self.vibration_actuator)
|
||||
}
|
||||
|
||||
// https://w3c.github.io/gamepad/extensions.html#gamepadhand-enum
|
||||
fn Hand(&self) -> GamepadHand {
|
||||
self.hand
|
||||
|
@ -286,6 +307,10 @@ impl Gamepad {
|
|||
pub fn set_exposed(&self, exposed: bool) {
|
||||
self.exposed.set(exposed);
|
||||
}
|
||||
|
||||
pub fn vibration_actuator(&self) -> &GamepadHapticActuator {
|
||||
&*self.vibration_actuator
|
||||
}
|
||||
}
|
||||
|
||||
/// <https://www.w3.org/TR/gamepad/#dfn-gamepad-user-gesture>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue