Commit 322655b4 authored by Alex Cooper's avatar Alex Cooper Committed by Commit Bot

Update order of select events to match WebXR spec

The WebXR Spec requires that select events be fired in the order:
1) SelectStart
2) Select
3) SelectEnd

The current implementation in chrome flips the order of events 2 and 3.
This change flips that order to match the spec.

Bug: 960997
Change-Id: I3a8aca683898515102999d86b7bcee6c6e74ef24
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1607180
Commit-Queue: Brandon Jones <bajones@chromium.org>
Reviewed-by: default avatarBrandon Jones <bajones@chromium.org>
Auto-Submit: Alexander Cooper <alcooper@chromium.org>
Cr-Commit-Position: refs/heads/master@{#659727}
parent a59ecdc7
...@@ -21,7 +21,7 @@ that Daydream controller input is registered when using Daydream View. ...@@ -21,7 +21,7 @@ that Daydream controller input is registered when using Daydream View.
var finishAfterEachInput = true; var finishAfterEachInput = true;
function onSelectStart() { function onSelectStart() {
// selectstart should always be fired first, so check that // selectstart should always be fired first, so check that.
assert_true(selectStartCount == selectEndCount, assert_true(selectStartCount == selectEndCount,
'selectstart fired before selectend'); 'selectstart fired before selectend');
assert_true(selectStartCount == selectCount, assert_true(selectStartCount == selectCount,
...@@ -29,22 +29,22 @@ that Daydream controller input is registered when using Daydream View. ...@@ -29,22 +29,22 @@ that Daydream controller input is registered when using Daydream View.
selectStartCount++; selectStartCount++;
} }
function onSelectEnd() {
// selectend should always be fired between selectstart and select
assert_true(selectEndCount + 1 == selectStartCount,
'selectend fired after selectstart');
assert_true(selectEndCount == selectCount,
'selectend fired before select');
selectEndCount++;
}
function onSelect() { function onSelect() {
// select should always be fired last // select should always be fired between selectstart and selectend.
selectCount++; assert_true(selectCount + 1 == selectStartCount,
assert_true(selectCount == selectStartCount,
'select fired after selectstart'); 'select fired after selectstart');
assert_true(selectCount == selectEndCount, assert_true(selectCount == selectEndCount,
'select fired after selectend'); 'select fired after selectend');
selectCount++;
}
function onSelectEnd() {
// selectend should always be fired last.
selectEndCount++;
assert_true(selectEndCount == selectStartCount,
'selectend fired after selectstart');
assert_true(selectEndCount == selectCount,
'selectend fired before select');
currentIteration++; currentIteration++;
if (currentIteration == iterations) { if (currentIteration == iterations) {
done(); done();
......
...@@ -857,9 +857,6 @@ void XRSession::OnSelect(XRInputSource* input_source) { ...@@ -857,9 +857,6 @@ void XRSession::OnSelect(XRInputSource* input_source) {
OnSelectStart(input_source); OnSelectStart(input_source);
} }
// Make sure we end the selection prior to firing the select event.
OnSelectEnd(input_source);
if (!input_source->selection_cancelled) { if (!input_source->selection_cancelled) {
XRInputSourceEvent* event = XRInputSourceEvent* event =
CreateInputSourceEvent(event_type_names::kSelect, input_source); CreateInputSourceEvent(event_type_names::kSelect, input_source);
...@@ -868,6 +865,8 @@ void XRSession::OnSelect(XRInputSource* input_source) { ...@@ -868,6 +865,8 @@ void XRSession::OnSelect(XRInputSource* input_source) {
// Ensure the frame cannot be used outside of the event handler. // Ensure the frame cannot be used outside of the event handler.
event->frame()->Deactivate(); event->frame()->Deactivate();
} }
OnSelectEnd(input_source);
} }
void XRSession::OnPoseReset() { void XRSession::OnPoseReset() {
......
...@@ -21,9 +21,9 @@ let requestSessionModes = ['immersive-vr']; ...@@ -21,9 +21,9 @@ let requestSessionModes = ['immersive-vr'];
let testFunction = function(session, t, fakeDeviceController) { let testFunction = function(session, t, fakeDeviceController) {
let eventWatcher = new EventWatcher( let eventWatcher = new EventWatcher(
t, session, ["selectstart", "selectend", "select", "watcherdone"]); t, session, ["selectstart", "select", "selectend", "watcherdone"]);
let eventPromise = eventWatcher.wait_for( let eventPromise = eventWatcher.wait_for(
["selectstart", "selectend", "select", "watcherdone"]); ["selectstart", "select", "selectend", "watcherdone"]);
// Need to have a valid pose or input event's don't process. // Need to have a valid pose or input event's don't process.
fakeDeviceController.setXRPresentationFrameData(VALID_POSE_MATRIX, [{ fakeDeviceController.setXRPresentationFrameData(VALID_POSE_MATRIX, [{
...@@ -64,6 +64,7 @@ let testFunction = function(session, t, fakeDeviceController) { ...@@ -64,6 +64,7 @@ let testFunction = function(session, t, fakeDeviceController) {
assert_equals(event.inputSource, input_sources[0]); assert_equals(event.inputSource, input_sources[0]);
tryCallingFrameMethods(event.frame); tryCallingFrameMethods(event.frame);
}); });
session.dispatchEvent(watcherDone);
} }
function onSessionSelect(event) { function onSessionSelect(event) {
...@@ -73,8 +74,8 @@ let testFunction = function(session, t, fakeDeviceController) { ...@@ -73,8 +74,8 @@ let testFunction = function(session, t, fakeDeviceController) {
assert_equals(event.inputSource, input_sources[0]); assert_equals(event.inputSource, input_sources[0]);
tryCallingFrameMethods(event.frame); tryCallingFrameMethods(event.frame);
}); });
session.dispatchEvent(watcherDone);
} }
session.addEventListener("selectstart", onSessionSelectStart, false); session.addEventListener("selectstart", onSessionSelectStart, false);
session.addEventListener("selectend", onSessionSelectEnd, false); session.addEventListener("selectend", onSessionSelectEnd, false);
session.addEventListener("select", onSessionSelect, false); session.addEventListener("select", onSessionSelect, false);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment