Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #25463 - Manishearth:input-mocking, r=asajeffrey
Add input mocking, input sources change event Depends on servo/webxr#118 Also fixes some bugs I found. Wanted to finish and merge this before I started on hit testing since the transient hit test stuff might have overlap. There are a bunch of missing mock pieces that I'll probably do in a separate PR. Still need to run tests. Some things I skipped: - Doing handedness/target ray setting: See immersive-web/webxr-test-api#46 , this would require making our impl support these changing - Handling button initial state: Would require some mock changes, but I ran out of time - Handling profiles/etc: We don't yet have impl support for these r? @jdm
- Loading branch information
Showing
30 changed files
with
485 additions
and
79 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
/* 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::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, MockInputMsg, SelectEvent, SelectKind}; | ||
|
||
#[dom_struct] | ||
pub struct FakeXRInputController { | ||
reflector: Reflector, | ||
#[ignore_malloc_size_of = "defined in ipc-channel"] | ||
sender: IpcSender<MockDeviceMsg>, | ||
#[ignore_malloc_size_of = "defined in webxr-api"] | ||
id: InputId, | ||
} | ||
|
||
impl FakeXRInputController { | ||
pub fn new_inherited(sender: IpcSender<MockDeviceMsg>, id: InputId) -> FakeXRInputController { | ||
FakeXRInputController { | ||
reflector: Reflector::new(), | ||
sender, | ||
id, | ||
} | ||
} | ||
|
||
pub fn new( | ||
global: &GlobalScope, | ||
sender: IpcSender<MockDeviceMsg>, | ||
id: InputId, | ||
) -> DomRoot<FakeXRInputController> { | ||
reflect_dom_object( | ||
Box::new(FakeXRInputController::new_inherited(sender, id)), | ||
global, | ||
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)) | ||
} | ||
|
||
/// https://immersive-web.github.io/webxr-test-api/#dom-fakexrinputcontroller-disconnect | ||
fn Disconnect(&self) { | ||
self.send_message(MockInputMsg::Disconnect) | ||
} | ||
|
||
/// https://immersive-web.github.io/webxr-test-api/#dom-fakexrinputcontroller-reconnect | ||
fn Reconnect(&self) { | ||
self.send_message(MockInputMsg::Reconnect) | ||
} | ||
|
||
/// https://immersive-web.github.io/webxr-test-api/#dom-fakexrinputcontroller-startselection | ||
fn StartSelection(&self) { | ||
self.send_message(MockInputMsg::TriggerSelect( | ||
SelectKind::Select, | ||
SelectEvent::Start, | ||
)) | ||
} | ||
|
||
/// https://immersive-web.github.io/webxr-test-api/#dom-fakexrinputcontroller-endselection | ||
fn EndSelection(&self) { | ||
self.send_message(MockInputMsg::TriggerSelect( | ||
SelectKind::Select, | ||
SelectEvent::End, | ||
)) | ||
} | ||
|
||
/// https://immersive-web.github.io/webxr-test-api/#dom-fakexrinputcontroller-simulateselect | ||
fn SimulateSelect(&self) { | ||
self.send_message(MockInputMsg::TriggerSelect( | ||
SelectKind::Select, | ||
SelectEvent::Select, | ||
)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
components/script/dom/webidls/FakeXRInputController.webidl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* 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-test-api/#fakexrinputcontroller | ||
|
||
[Exposed=Window, Pref="dom.webxr.test"] | ||
interface FakeXRInputController { | ||
// void setHandedness(XRHandedness handedness); | ||
// void setTargetRayMode(XRTargetRayMode targetRayMode); | ||
// 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); | ||
|
||
void disconnect(); | ||
void reconnect(); | ||
|
||
void startSelection(); | ||
void endSelection(); | ||
void simulateSelect(); | ||
|
||
// void setSupportedButtons(sequence<FakeXRButtonStateInit> supportedButtons); | ||
// void updateButtonState(FakeXRButtonStateInit buttonState); | ||
}; | ||
|
||
dictionary FakeXRInputSourceInit { | ||
required XRHandedness handedness; | ||
required XRTargetRayMode targetRayMode; | ||
required FakeXRRigidTransformInit pointerOrigin; | ||
required sequence<DOMString> profiles; | ||
boolean selectionStarted = false; | ||
boolean selectionClicked = false; | ||
sequence<FakeXRButtonStateInit> supportedButtons; | ||
FakeXRRigidTransformInit gripOrigin; | ||
}; | ||
|
||
enum FakeXRButtonType { | ||
"grip", | ||
"touchpad", | ||
"thumbstick", | ||
"optional-button", | ||
"optional-thumbstick" | ||
}; | ||
|
||
dictionary FakeXRButtonStateInit { | ||
required FakeXRButtonType buttonType; | ||
required boolean pressed; | ||
required boolean touched; | ||
required float pressedValue; | ||
float xValue = 0.0; | ||
float yValue = 0.0; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.