Skip to content
Permalink
Browse files

Fire selection events from XR input sources

  • Loading branch information...
Manishearth committed Oct 3, 2019
1 parent 50b1ddf commit 2e577f7eec01ad0d5056fcaf89a1b80f0f81867e
Showing with 50 additions and 1 deletion.
  1. +2 −0 components/atoms/static_atoms.txt
  2. +48 −1 components/script/dom/xrsession.rs
@@ -102,6 +102,8 @@ search
seeked
seeking
select
selectend
selectstart
serif
signalingstatechange
srclang
@@ -33,6 +33,7 @@ use crate::dom::promise::Promise;
use crate::dom::webglframebuffer::WebGLFramebufferAttachmentRoot;
use crate::dom::xrframe::XRFrame;
use crate::dom::xrinputsource::XRInputSource;
use crate::dom::xrinputsourceevent::XRInputSourceEvent;
use crate::dom::xrreferencespace::XRReferenceSpace;
use crate::dom::xrrenderstate::XRRenderState;
use crate::dom::xrsessionevent::XRSessionEvent;
@@ -48,7 +49,7 @@ use profile_traits::ipc;
use std::cell::Cell;
use std::mem;
use std::rc::Rc;
use webxr_api::{self, Event as XREvent, Frame, Session};
use webxr_api::{self, Event as XREvent, Frame, SelectEvent, Session};

#[dom_struct]
pub struct XRSession {
@@ -170,6 +171,52 @@ impl XRSession {
let event = XRSessionEvent::new(&self.global(), atom!("end"), false, false, self);
event.upcast::<Event>().fire(self.upcast());
},
XREvent::Select(input, kind, frame) => {
// https://immersive-web.github.io/webxr/#primary-action
let source = self
.input_sources
.borrow_mut()
.iter()
.find(|s| s.id() == input)
.map(|x| DomRoot::from_ref(&**x));
if let Some(source) = source {
let frame = XRFrame::new(&self.global(), self, frame);
frame.set_active(true);
if kind == SelectEvent::Start {
let event = XRInputSourceEvent::new(
&self.global(),
atom!("selectstart"),
false,
false,
&frame,
&source,
);
event.upcast::<Event>().fire(self.upcast());
} else {
if kind == SelectEvent::Select {
let event = XRInputSourceEvent::new(
&self.global(),
atom!("select"),
false,
false,
&frame,
&source,
);
event.upcast::<Event>().fire(self.upcast());
}
let event = XRInputSourceEvent::new(
&self.global(),
atom!("selectend"),
false,
false,
&frame,
&source,
);
event.upcast::<Event>().fire(self.upcast());
}
frame.set_active(false);
}
},
_ => (), // XXXManishearth TBD
}
}

0 comments on commit 2e577f7

Please sign in to comment.
You can’t perform that action at this time.