From e5716624d462d26fc840a1af124beaf482e26111 Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Mon, 29 Apr 2019 20:15:18 -0700 Subject: [PATCH] Add XRInputSource.handedness --- .../script/dom/webidls/XRInputSource.webidl | 2 +- components/script/dom/xrinputsource.rs | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/components/script/dom/webidls/XRInputSource.webidl b/components/script/dom/webidls/XRInputSource.webidl index 813d14e4615..9270ff50823 100644 --- a/components/script/dom/webidls/XRInputSource.webidl +++ b/components/script/dom/webidls/XRInputSource.webidl @@ -18,7 +18,7 @@ enum XRTargetRayMode { [SecureContext, Exposed=Window, Pref="dom.webxr.enabled"] interface XRInputSource { - // [SameObject] readonly attribute XRHandedness handedness; + readonly attribute XRHandedness handedness; // [SameObject] readonly attribute XRTargetRayMode targetRayMode; // [SameObject] readonly attribute XRSpace targetRaySpace; // [SameObject] readonly attribute XRSpace? gripSpace; diff --git a/components/script/dom/xrinputsource.rs b/components/script/dom/xrinputsource.rs index f79716028eb..dcb86a23622 100644 --- a/components/script/dom/xrinputsource.rs +++ b/components/script/dom/xrinputsource.rs @@ -4,12 +4,15 @@ use crate::dom::bindings::cell::DomRefCell; use crate::dom::bindings::codegen::Bindings::XRInputSourceBinding; +use crate::dom::bindings::codegen::Bindings::XRInputSourceBinding::{ + XRHandedness, XRInputSourceMethods, +}; use crate::dom::bindings::reflector::{reflect_dom_object, Reflector}; use crate::dom::bindings::root::{Dom, DomRoot}; use crate::dom::globalscope::GlobalScope; use crate::dom::xrsession::XRSession; use dom_struct::dom_struct; -use webvr_traits::{WebVRGamepadData, WebVRGamepadState}; +use webvr_traits::{WebVRGamepadData, WebVRGamepadHand, WebVRGamepadState}; #[dom_struct] pub struct XRInputSource { @@ -52,3 +55,14 @@ impl XRInputSource { *self.state.borrow_mut() = state; } } + +impl XRInputSourceMethods for XRInputSource { + /// https://immersive-web.github.io/webxr/#dom-xrinputsource-handedness + fn Handedness(&self) -> XRHandedness { + match self.data.hand { + WebVRGamepadHand::Unknown => XRHandedness::None, + WebVRGamepadHand::Left => XRHandedness::Left, + WebVRGamepadHand::Right => XRHandedness::Right, + } + } +}