Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add input mocking, input sources change event #25463

Merged
merged 15 commits into from Jan 9, 2020

Add pointer/grip mocking

  • Loading branch information
Manishearth committed Jan 9, 2020
commit e03fd0ef1c40e8840e59c15e649c102e7f80b81d
@@ -2,13 +2,18 @@
* 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::FakeXRInputControllerBinding::{self};
use crate::dom::bindings::codegen::Bindings::FakeXRDeviceBinding::FakeXRRigidTransformInit;
use crate::dom::bindings::codegen::Bindings::FakeXRInputControllerBinding::{
self, FakeXRInputControllerMethods,
};
use crate::dom::bindings::error::Fallible;
use crate::dom::bindings::reflector::{reflect_dom_object, Reflector};
use crate::dom::bindings::root::DomRoot;
use crate::dom::fakexrdevice::get_origin;
use crate::dom::globalscope::GlobalScope;
use dom_struct::dom_struct;
use ipc_channel::ipc::IpcSender;
use webxr_api::{InputId, MockDeviceMsg};
use webxr_api::{InputId, MockDeviceMsg, MockInputMsg};

#[dom_struct]
pub struct FakeXRInputController {
@@ -39,4 +44,29 @@ impl FakeXRInputController {
FakeXRInputControllerBinding::Wrap,
)
}

fn send_message(&self, msg: MockInputMsg) {
let _ = self
.sender
.send(MockDeviceMsg::MessageInputSource(self.id, msg));
}
}

impl FakeXRInputControllerMethods for FakeXRInputController {
/// https://immersive-web.github.io/webxr-test-api/#dom-fakexrinputcontroller-setpointerorigin
fn SetPointerOrigin(&self, origin: &FakeXRRigidTransformInit, _emulated: bool) -> Fallible<()> {
self.send_message(MockInputMsg::SetPointerOrigin(Some(get_origin(origin)?)));
Ok(())
}

/// https://immersive-web.github.io/webxr-test-api/#dom-fakexrinputcontroller-setgriporigin
fn SetGripOrigin(&self, origin: &FakeXRRigidTransformInit, _emulated: bool) -> Fallible<()> {
self.send_message(MockInputMsg::SetGripOrigin(Some(get_origin(origin)?)));
Ok(())
}

/// https://immersive-web.github.io/webxr-test-api/#dom-fakexrinputcontroller-cleargriporigin
fn ClearGripOrigin(&self) {
self.send_message(MockInputMsg::SetGripOrigin(None))
}
}
@@ -9,9 +9,9 @@ interface FakeXRInputController {
// void setHandedness(XRHandedness handedness);
// void setTargetRayMode(XRTargetRayMode targetRayMode);
// void setProfiles(sequence<DOMString> profiles);
// void setGripOrigin(FakeXRRigidTransformInit gripOrigin, optional boolean emulatedPosition = false);
// void clearGripOrigin();
// void setPointerOrigin(FakeXRRigidTransformInit pointerOrigin, optional boolean emulatedPosition = false);
[Throws] void setGripOrigin(FakeXRRigidTransformInit gripOrigin, optional boolean emulatedPosition = false);
void clearGripOrigin();
[Throws] void setPointerOrigin(FakeXRRigidTransformInit pointerOrigin, optional boolean emulatedPosition = false);

// void disconnect();
// void reconnect();
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.