Skip to content

Commit

Permalink
Support profiles
Browse files Browse the repository at this point in the history
  • Loading branch information
Manishearth committed Jan 21, 2020
1 parent 9c34a65 commit e0135fe
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 17 deletions.
5 changes: 4 additions & 1 deletion components/script/dom/fakexrdevice.rs
Expand Up @@ -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 {
Expand Down
7 changes: 7 additions & 0 deletions components/script/dom/fakexrinputcontroller.rs
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
}
}
2 changes: 1 addition & 1 deletion components/script/dom/webidls/FakeXRInputController.webidl
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions components/script/dom/webidls/XRInputSource.webidl
Expand Up @@ -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;
};
26 changes: 24 additions & 2 deletions components/script/dom/xrinputsource.rs
Expand Up @@ -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,
Expand All @@ -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]
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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()
}
}
4 changes: 2 additions & 2 deletions components/script/dom/xrinputsourcearray.rs
Expand Up @@ -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));
}
});
Expand All @@ -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];
Expand Down

This file was deleted.

3 changes: 0 additions & 3 deletions tests/wpt/metadata/webxr/idlharness.https.window.js.ini
Expand Up @@ -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

Expand Down

This file was deleted.

@@ -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

0 comments on commit e0135fe

Please sign in to comment.