From a4d1892c6193c9a24d54e879b5768f4c26866137 Mon Sep 17 00:00:00 2001 From: Brandon Jones Date: Fri, 14 Oct 2016 10:10:31 -0700 Subject: [PATCH 1/3] Update navigator interface and event targets This updates the VR interfaces to remove dependencies on the `window` object and enable use of the API in contexts other than the main page thread, such as workers. (Note that the WorkerNavigator interface and worker exposure meta tags will be added in a follow-up PR) --- index.bs | 107 +++++++++------- index.html | 367 ++++++++++++++++++++++++++++------------------------- 2 files changed, 250 insertions(+), 224 deletions(-) diff --git a/index.bs b/index.bs index 9643f44f..8d247205 100644 --- a/index.bs +++ b/index.bs @@ -169,6 +169,12 @@ interface VRDisplay : EventTarget { * created without preserveDrawingBuffer set to true will be cleared. */ void submitFrame(); + + attribute EventHandler onactivate; + attribute EventHandler ondeactivate; + attribute EventHandler onblur; + attribute EventHandler onfocus; + attribute EventHandler onpresentchange; }; @@ -215,6 +221,24 @@ Returns an array with the {{VRLayer}} currently being presented. MUST return an submitFrame() Captures the current state of the {{VRLayer}} currently being presented and displays it on the {{VRDisplay}}. It is assumed that the frame was rendered using the {{VRPose}} and matrices provided by the last call to {{getFrameData()}}. If {{getFrameData()}} was not called prior to calling {{submitFrame()}} the user agent MAY warn the user of potentially malformed visuals or prevent the frame from being shown at all. +### Events ### {#vrdisplay-events} + +The UA MUST provide the following new events. The corresponding events must be of type {{VRDisplayEvent}} and must fire on a {{VRDisplay}} object. Registration for and firing of the events must follow the usual behavior of DOM4 Events. + +onactivate +A user agent MAY dispatch this event type to indicate that something has occured which suggests the {{VRDisplay}} should be presented to. For example, if the {{VRDisplay}} is capable of detecting when the user has put it on, this event SHOULD fire when they do so with the reason "mounted". + +ondeactivate +A user agent MAY dispatch this event type to indicate that something has occured which suggests the {{VRDisplay}} should exit presentation. For example, if the {{VRDisplay}} is capable of detecting when the user has taken it off, this event SHOULD fire when they do so with the reason "unmounted". + +onblur +A user agent MAY dispatch this event type to indicate that presentation to the {{VRDisplay}} by the page is paused by the user agent, OS, or VR hardware. While a {{VRDisplay}} is blurred it does not lose it's presenting status ({{isPresenting}} continues to report true) but {{getFrameData()}} returns false without updating the provided {{VRFrameData}} and {{getPose()}} returns null. This is to prevent tracking while the user interacts with potentially sensitive UI. For example: A user agent SHOULD blur the presenting application when the user is typing a URL into the browser with a virtual keyboard, otherwise the presenting page may be able to guess the URL the user is entering by tracking their head motions. + +onfocus +A user agent MAY dispatch this event type to indicate that presentation to the {{VRDisplay}} by the page has resumed after being blurred. + +onpresentchange +A user agent MUST dispatch this event type to indicate that the {{VRDisplay}} has begun or ended VR presentation. This event should not fire on subsequent calls to {{requestPresent()}} after the {{VRDisplay}} has already begun VR presentation.
The following code demonstrates presenting a simple rendering loop to a {{VRDisplay}}. @@ -559,23 +583,48 @@ Width of the play-area bounds in meters. The bounds are defined as an axis-align sizeZ Depth of the play-area bounds in meters. The bounds are defined as an axis-aligned rectangle on the floor. The center of the rectangle is at (0,0,0) in standing-space coordinates. These bounds are defined for safety purposes. Content should not require the user to move beyond these bounds; however, it is possible for the user to ignore the bounds resulting in position values outside of this rectangle. - -## Navigator Interface extension ## {#interface-navigator} +## VR Interface ## {#interface-vr}
-partial interface Navigator {
-  Promise<sequence<VRDisplay>> getVRDisplays();
-  readonly attribute FrozenArray<VRDisplay> activeVRDisplays;
+interface VR : EventTarget {
+  Promise<sequence<VRDisplay>> getDisplays();
+  readonly attribute FrozenArray<VRDisplay> activeDisplays;
+
+  attribute EventHandler ondisplayconnect;
+  attribute EventHandler ondisplaydisconnect;
+  attribute EventHandler onnavigate;
 };
 
-### Attributes ### {#navigator-attributes} +### Attributes ### {#vr-attributes} -getVRDisplays() +getDisplays() Return a Promise which resolves to a list of available {{VRDisplay}}s. -activeVRDisplays -{{activeVRDisplays}} includes every {{VRDisplay}} that is currently presenting. +activeDisplays +{{activeDisplays}} includes every {{VRDisplay}} that is currently presenting. + +### Events ### {#vr-events} + +The UA MUST provide the following new events. The corresponding events must be of type {{VRDisplayEvent}} and must fire on the {{VR}} object. Registration for and firing of the events must follow the usual behavior of DOM4 Events. + +ondisplayconnect +A user agent MAY dispatch this event type to indicate that a {{VRDisplay}} has been connected. + +ondisplaydisconnect +A user agent MAY dispatch this event type to indicate that a {{VRDisplay}} has been disconnected. + +onnavigate +A user agent MAY dispatch this event type to indicate that the current page has been navigated to from a page that was actively presenting VR content. The current page can call {{requestPresent()}} in response to this event in order to stay in VR presentation mode. + + +## Navigator Interface extension ## {#interface-navigator} + +
+partial interface Navigator {
+  readonly attribute VR vr;
+};
+
The following code finds the first available {{VRDisplay}}. @@ -583,7 +632,7 @@ The following code finds the first available {{VRDisplay}}.
 var vrDisplay;
 
-navigator.getVRDisplays().then(function (displays) {
+navigator.vr.getDisplays().then(function (displays) {
   // Use the first display in the array if one is available. If multiple
   // displays are present, you may want to present the user with a way to
   // select which display to use.
@@ -642,44 +691,6 @@ The {{VRDisplay}} associated with this event.
 reason
 {{VRDisplayEventReason}} describing why this event has has been fired.
 
-
-## Window Interface extension ## {#interface-window}
-
-
-partial interface Window {
-  attribute EventHandler onvrdisplayconnect;
-  attribute EventHandler onvrdisplaydisconnect;
-  attribute EventHandler onvrdisplayactivate;
-  attribute EventHandler onvrdisplaydeactivate;
-  attribute EventHandler onvrdisplayblur;
-  attribute EventHandler onvrdisplayfocus;
-  attribute EventHandler onvrdisplaypresentchange;
-};
-
- -User agents implementing this specification MUST provide the following new DOM events. The corresponding events must be of type {{VRDisplayEvent}} and must fire on the window object. Registration for and firing of the events must follow the usual behavior of DOM4 Events. - -onvrdisplayconnect -A user agent MAY dispatch this event type to indicate that a {{VRDisplay}} has been connected. - -onvrdisplaydisconnect -A user agent MAY dispatch this event type to indicate that a {{VRDisplay}} has been disconnected. - -onvrdisplayactivate -A user agent MAY dispatch this event type to indicate that something has occured which suggests the {{VRDisplay}} should be presented to. For example, if the {{VRDisplay}} is capable of detecting when the user has put it on, this event SHOULD fire when they do so with the reason "mounted". - -onvrdisplaydeactivate -A user agent MAY dispatch this event type to indicate that something has occured which suggests the {{VRDisplay}} should exit presentation. For example, if the {{VRDisplay}} is capable of detecting when the user has taken it off, this event SHOULD fire when they do so with the reason "unmounted". - -onvrdisplayblur -A user agent MAY dispatch this event type to indicate that presentation to the display by the page is paused by the user agent, OS, or VR hardware. While a {{VRDisplay}} is blurred it does not lose it's presenting status ({{isPresenting}} continues to report true) but {{getFrameData()}} returns false without updating the provided {{VRFrameData}} and {{getPose()}} returns null. This is to prevent tracking while the user interacts with potentially sensitive UI. For example: A user agent SHOULD blur the presenting application when the user is typing a URL into the browser with a virtual keyboard, otherwise the presenting page may be able to guess the URL the user is entering by tracking their head motions. - -onvrdisplayfocus -A user agent MAY dispatch this event type to indicate that presentation to the display by the page has resumed after being blurred. - -onvrdisplaypresentchange -A user agent MUST dispatch this event type to indicate that a {{VRDisplay}} has begun or ended VR presentation. This event should not fire on subsequent calls to {{requestPresent()}} after the {{VRDisplay}} has already begun VR presentation. - ## Gamepad Interface extension ## {#interface-gamepad}
diff --git a/index.html b/index.html
index f4eb47ec..09767ef0 100644
--- a/index.html
+++ b/index.html
@@ -1176,7 +1176,7 @@
 		}
 	}
 
-  
+  
 
-  
+  
 
-  
+