diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2020-01-09 02:45:49 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-01-09 02:45:49 -0500 |
commit | dbee7f7d2764af0eb2c380f15b0bd3f4fc52920e (patch) | |
tree | 6b06769a296c068bf8ad2a76fc59988ab91b64fb /components/script/dom/xrinputsourcearray.rs | |
parent | 95e6c7157285368281c492888f1c0b92eddeec71 (diff) | |
parent | 94e8ce5739677db8bd4c0ffbe50d035b37fafe51 (diff) | |
download | servo-dbee7f7d2764af0eb2c380f15b0bd3f4fc52920e.tar.gz servo-dbee7f7d2764af0eb2c380f15b0bd3f4fc52920e.zip |
Auto merge of #25463 - Manishearth:input-mocking, r=asajeffrey
Add input mocking, input sources change event
Depends on https://github.com/servo/webxr/pull/118
Also fixes some bugs I found.
Wanted to finish and merge this before I started on hit testing since the transient hit test stuff might have overlap.
There are a bunch of missing mock pieces that I'll probably do in a separate PR.
Still need to run tests.
Some things I skipped:
- Doing handedness/target ray setting: See https://github.com/immersive-web/webxr-test-api/issues/46 , this would require making our impl support these changing
- Handling button initial state: Would require some mock changes, but I ran out of time
- Handling profiles/etc: We don't yet have impl support for these
r? @jdm
Diffstat (limited to 'components/script/dom/xrinputsourcearray.rs')
-rw-r--r-- | components/script/dom/xrinputsourcearray.rs | 55 |
1 files changed, 54 insertions, 1 deletions
diff --git a/components/script/dom/xrinputsourcearray.rs b/components/script/dom/xrinputsourcearray.rs index 48f84991db0..45e0f2851e4 100644 --- a/components/script/dom/xrinputsourcearray.rs +++ b/components/script/dom/xrinputsourcearray.rs @@ -5,13 +5,16 @@ use crate::dom::bindings::cell::DomRefCell; use crate::dom::bindings::codegen::Bindings::XRInputSourceArrayBinding; use crate::dom::bindings::codegen::Bindings::XRInputSourceArrayBinding::XRInputSourceArrayMethods; +use crate::dom::bindings::inheritance::Castable; use crate::dom::bindings::reflector::{reflect_dom_object, DomObject, Reflector}; use crate::dom::bindings::root::{Dom, DomRoot}; +use crate::dom::event::Event; use crate::dom::globalscope::GlobalScope; use crate::dom::xrinputsource::XRInputSource; +use crate::dom::xrinputsourceschangeevent::XRInputSourcesChangeEvent; use crate::dom::xrsession::XRSession; use dom_struct::dom_struct; -use webxr_api::InputId; +use webxr_api::{InputId, InputSource}; #[dom_struct] pub struct XRInputSourceArray { @@ -48,6 +51,56 @@ impl XRInputSourceArray { }); } + pub fn add_input_source(&self, session: &XRSession, info: InputSource) { + let mut input_sources = self.input_sources.borrow_mut(); + let global = self.global(); + let input = XRInputSource::new(&global, &session, info); + debug_assert!( + input_sources.iter().find(|i| i.id() == info.id).is_none(), + "Should never add a duplicate input id!" + ); + input_sources.push(Dom::from_ref(&input)); + + let added = [input]; + + let event = XRInputSourcesChangeEvent::new( + &global, + atom!("inputsourceschange"), + false, + true, + session, + &added, + &[], + ); + // Release the refcell guard + drop(input_sources); + event.upcast::<Event>().fire(session.upcast()); + } + + pub fn remove_input_source(&self, session: &XRSession, id: InputId) { + let mut input_sources = self.input_sources.borrow_mut(); + let global = self.global(); + let removed = if let Some(i) = input_sources.iter().find(|i| i.id() == id) { + [DomRoot::from_ref(&**i)] + } else { + return; + }; + + let event = XRInputSourcesChangeEvent::new( + &global, + atom!("inputsourceschange"), + false, + true, + session, + &[], + &removed, + ); + input_sources.retain(|i| i.id() != id); + // release the refcell guard + drop(input_sources); + event.upcast::<Event>().fire(session.upcast()); + } + pub fn find(&self, id: InputId) -> Option<DomRoot<XRInputSource>> { self.input_sources .borrow() |