Support profiles

This commit is contained in:
Manish Goregaokar 2020-01-13 15:31:31 +05:30
parent 9c34a6585b
commit e0135fe783
10 changed files with 40 additions and 17 deletions

View file

@ -205,13 +205,16 @@ impl FakeXRDeviceMethods for FakeXRDevice {
None
};
// XXXManishearth deal with profiles, supportedButtons, selection*
let profiles = init.profiles.iter().cloned().map(String::from).collect();
// XXXManishearth deal with supportedButtons and selection*
let source = InputSource {
handedness,
target_ray_mode,
id,
supports_grip: true,
profiles,
};
let init = MockInputInit {

View file

@ -12,6 +12,7 @@ use crate::dom::bindings::codegen::Bindings::XRInputSourceBinding::{
use crate::dom::bindings::error::Fallible;
use crate::dom::bindings::reflector::{reflect_dom_object, Reflector};
use crate::dom::bindings::root::DomRoot;
use crate::dom::bindings::str::DOMString;
use crate::dom::fakexrdevice::get_origin;
use crate::dom::globalscope::GlobalScope;
use dom_struct::dom_struct;
@ -128,4 +129,10 @@ impl FakeXRInputControllerMethods for FakeXRInputController {
};
let _ = self.send_message(MockInputMsg::SetTargetRayMode(t));
}
/// https://immersive-web.github.io/webxr-test-api/#dom-fakexrinputcontroller-setprofiles
fn SetProfiles(&self, profiles: Vec<DOMString>) {
let t = profiles.into_iter().map(String::from).collect();
let _ = self.send_message(MockInputMsg::SetProfiles(t));
}
}

View file

@ -8,7 +8,7 @@
interface FakeXRInputController {
void setHandedness(XRHandedness handedness);
void setTargetRayMode(XRTargetRayMode targetRayMode);
// void setProfiles(sequence<DOMString> profiles);
void setProfiles(sequence<DOMString> profiles);
[Throws] void setGripOrigin(FakeXRRigidTransformInit gripOrigin, optional boolean emulatedPosition = false);
void clearGripOrigin();
[Throws] void setPointerOrigin(FakeXRRigidTransformInit pointerOrigin, optional boolean emulatedPosition = false);

View file

@ -23,4 +23,5 @@ interface XRInputSource {
[SameObject] readonly attribute XRSpace targetRaySpace;
[SameObject] readonly attribute XRSpace? gripSpace;
// [SameObject] readonly attribute Gamepad? gamepad;
/* [SameObject] */ readonly attribute /* FrozenArray<DOMString> */ any profiles;
};

View file

@ -2,6 +2,7 @@
* 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::compartments::enter_realm;
use crate::dom::bindings::codegen::Bindings::XRInputSourceBinding;
use crate::dom::bindings::codegen::Bindings::XRInputSourceBinding::{
XRHandedness, XRInputSourceMethods, XRTargetRayMode,
@ -11,7 +12,11 @@ use crate::dom::bindings::root::{Dom, DomRoot, MutNullableDom};
use crate::dom::globalscope::GlobalScope;
use crate::dom::xrsession::XRSession;
use crate::dom::xrspace::XRSpace;
use crate::script_runtime::JSContext;
use dom_struct::dom_struct;
use js::conversions::ToJSValConvertible;
use js::jsapi::Heap;
use js::jsval::{JSVal, UndefinedValue};
use webxr_api::{Handedness, InputId, InputSource, TargetRayMode};
#[dom_struct]
@ -24,6 +29,8 @@ pub struct XRInputSource {
target_ray_space: MutNullableDom<XRSpace>,
#[ignore_malloc_size_of = "Defined in rust-webxr"]
grip_space: MutNullableDom<XRSpace>,
#[ignore_malloc_size_of = "mozjs"]
profiles: Heap<JSVal>,
}
impl XRInputSource {
@ -34,19 +41,30 @@ impl XRInputSource {
info,
target_ray_space: Default::default(),
grip_space: Default::default(),
profiles: Heap::default(),
}
}
#[allow(unsafe_code)]
pub fn new(
global: &GlobalScope,
session: &XRSession,
info: InputSource,
) -> DomRoot<XRInputSource> {
reflect_dom_object(
let source = reflect_dom_object(
Box::new(XRInputSource::new_inherited(session, info)),
global,
XRInputSourceBinding::Wrap,
)
);
let _ac = enter_realm(&*global);
let cx = global.get_cx();
unsafe {
rooted!(in(*cx) let mut profiles = UndefinedValue());
source.info.profiles.to_jsval(*cx, profiles.handle_mut());
source.profiles.set(profiles.get());
}
source
}
pub fn id(&self) -> InputId {
@ -92,4 +110,8 @@ impl XRInputSourceMethods for XRInputSource {
None
}
}
// https://immersive-web.github.io/webxr/#dom-xrinputsource-profiles
fn Profiles(&self, _cx: JSContext) -> JSVal {
self.profiles.get()
}
}

View file

@ -45,7 +45,7 @@ impl XRInputSourceArray {
for info in sess.initial_inputs() {
// XXXManishearth we should be able to listen for updates
// to the input sources
let input = XRInputSource::new(&global, &session, *info);
let input = XRInputSource::new(&global, &session, info.clone());
input_sources.push(Dom::from_ref(&input));
}
});
@ -54,11 +54,11 @@ 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!"
);
let input = XRInputSource::new(&global, &session, info);
input_sources.push(Dom::from_ref(&input));
let added = [input];

View file

@ -1,4 +0,0 @@
[events_input_source_recreation.https.html]
[Input sources are re-created when handedness or target ray mode changes]
expected: FAIL

View file

@ -95,9 +95,6 @@
[XRReferenceSpaceEvent interface: existence and properties of interface prototype object's "constructor" property]
expected: FAIL
[XRInputSource interface: attribute profiles]
expected: FAIL
[XR interface: operation requestSession(XRSessionMode, XRSessionInit)]
expected: FAIL

View file

@ -1,4 +0,0 @@
[xrInputSource_profiles.https.html]
[WebXR InputSource's profiles list can be set]
expected: FAIL

View file

@ -1,4 +1,5 @@
[xrSession_input_events_end.https.html]
expected: TIMEOUT
[Calling end during an input callback stops processing at the right time]
expected: FAIL