aboutsummaryrefslogtreecommitdiffstats
path: root/components/script
diff options
context:
space:
mode:
authorManish Goregaokar <manishsmail@gmail.com>2019-07-19 16:02:11 -0700
committerManish Goregaokar <manishsmail@gmail.com>2019-07-22 09:32:01 -0700
commit638cc92e89e05806f69e620bf2f89772715bb1f7 (patch)
tree4050c6af57ac5f535aed698ec007bd54a3f22d0f /components/script
parentc9204375eb1f44bd8eeb697bb93a3a53766945bc (diff)
downloadservo-638cc92e89e05806f69e620bf2f89772715bb1f7.tar.gz
servo-638cc92e89e05806f69e620bf2f89772715bb1f7.zip
Add XRSessionEvent
Diffstat (limited to 'components/script')
-rw-r--r--components/script/dom/mod.rs1
-rw-r--r--components/script/dom/webidls/XRSessionEvent.webidl15
-rw-r--r--components/script/dom/xrsessionevent.rs78
3 files changed, 94 insertions, 0 deletions
diff --git a/components/script/dom/mod.rs b/components/script/dom/mod.rs
index 0a654f93c57..60701755ec8 100644
--- a/components/script/dom/mod.rs
+++ b/components/script/dom/mod.rs
@@ -552,6 +552,7 @@ pub mod xrreferencespace;
pub mod xrrenderstate;
pub mod xrrigidtransform;
pub mod xrsession;
+pub mod xrsessionevent;
pub mod xrspace;
pub mod xrtest;
pub mod xrview;
diff --git a/components/script/dom/webidls/XRSessionEvent.webidl b/components/script/dom/webidls/XRSessionEvent.webidl
new file mode 100644
index 00000000000..f48fa5eb342
--- /dev/null
+++ b/components/script/dom/webidls/XRSessionEvent.webidl
@@ -0,0 +1,15 @@
+/* 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/. */
+
+// https://immersive-web.github.io/webxr/#xrsessionevent-interface
+
+[SecureContext, Exposed=Window, Pref="dom.webxr.enabled", Constructor
+(DOMString type, XRSessionEventInit eventInitDict)]
+interface XRSessionEvent : Event {
+ [SameObject] readonly attribute XRSession session;
+};
+
+dictionary XRSessionEventInit : EventInit {
+ required XRSession session;
+};
diff --git a/components/script/dom/xrsessionevent.rs b/components/script/dom/xrsessionevent.rs
new file mode 100644
index 00000000000..6c2e8c0fb00
--- /dev/null
+++ b/components/script/dom/xrsessionevent.rs
@@ -0,0 +1,78 @@
+/* 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/. */
+
+use crate::dom::bindings::codegen::Bindings::EventBinding::EventBinding::EventMethods;
+use crate::dom::bindings::codegen::Bindings::XRSessionEventBinding::{self, XRSessionEventMethods};
+use crate::dom::bindings::error::Fallible;
+use crate::dom::bindings::inheritance::Castable;
+use crate::dom::bindings::reflector::{reflect_dom_object, DomObject};
+use crate::dom::bindings::root::{Dom, DomRoot};
+use crate::dom::bindings::str::DOMString;
+use crate::dom::event::Event;
+use crate::dom::globalscope::GlobalScope;
+use crate::dom::window::Window;
+use crate::dom::xrsession::XRSession;
+use dom_struct::dom_struct;
+use servo_atoms::Atom;
+
+#[dom_struct]
+pub struct XRSessionEvent {
+ event: Event,
+ session: Dom<XRSession>,
+}
+
+impl XRSessionEvent {
+ #[allow(unrooted_must_root)]
+ fn new_inherited(session: &XRSession) -> XRSessionEvent {
+ XRSessionEvent {
+ event: Event::new_inherited(),
+ session: Dom::from_ref(session),
+ }
+ }
+
+ pub fn new(
+ global: &GlobalScope,
+ type_: Atom,
+ bubbles: bool,
+ cancelable: bool,
+ session: &XRSession,
+ ) -> DomRoot<XRSessionEvent> {
+ let trackevent = reflect_dom_object(
+ Box::new(XRSessionEvent::new_inherited(&session)),
+ global,
+ XRSessionEventBinding::Wrap,
+ );
+ {
+ let event = trackevent.upcast::<Event>();
+ event.init_event(type_, bubbles, cancelable);
+ }
+ trackevent
+ }
+
+ pub fn Constructor(
+ window: &Window,
+ type_: DOMString,
+ init: &XRSessionEventBinding::XRSessionEventInit,
+ ) -> Fallible<DomRoot<XRSessionEvent>> {
+ Ok(XRSessionEvent::new(
+ &window.global(),
+ Atom::from(type_),
+ init.parent.bubbles,
+ init.parent.cancelable,
+ &init.session,
+ ))
+ }
+}
+
+impl XRSessionEventMethods for XRSessionEvent {
+ // https://immersive-web.github.io/webxr/#dom-xrsessioneventinit-session
+ fn Session(&self) -> DomRoot<XRSession> {
+ DomRoot::from_ref(&*self.session)
+ }
+
+ // https://dom.spec.whatwg.org/#dom-event-istrusted
+ fn IsTrusted(&self) -> bool {
+ self.event.IsTrusted()
+ }
+}