diff options
author | Imanol Fernandez <mortimergoro@gmail.com> | 2017-05-26 14:22:02 +0200 |
---|---|---|
committer | Imanol Fernandez <mortimergoro@gmail.com> | 2017-07-05 22:38:29 +0200 |
commit | fe4ee6de2efe60948bb5cadaabd53e326209ca07 (patch) | |
tree | bf5281e560fe3d1953d9bf985786dfc3abdb5260 | |
parent | 296a215e5404eb0fd0c0a34cc1283cd0b84aaea9 (diff) | |
download | servo-fe4ee6de2efe60948bb5cadaabd53e326209ca07.tar.gz servo-fe4ee6de2efe60948bb5cadaabd53e326209ca07.zip |
WebVR 1.1 spec compatibility
-rw-r--r-- | components/script/dom/macros.rs | 15 | ||||
-rw-r--r-- | components/script/dom/navigator.rs | 21 | ||||
-rw-r--r-- | components/script/dom/vr.rs | 8 | ||||
-rw-r--r-- | components/script/dom/vrdisplay.rs | 26 | ||||
-rw-r--r-- | components/script/dom/vrdisplayevent.rs | 14 | ||||
-rw-r--r-- | components/script/dom/webidls/EventHandler.webidl | 11 | ||||
-rw-r--r-- | components/script/dom/webidls/Navigator.webidl | 4 | ||||
-rw-r--r-- | components/script/dom/webidls/VR.webidl | 4 | ||||
-rw-r--r-- | components/script/dom/webidls/VRDisplay.webidl | 2 | ||||
-rw-r--r-- | components/script/script_thread.rs | 1 | ||||
-rw-r--r-- | tests/html/webvr/advanced-mirroring.html | 10 | ||||
-rw-r--r-- | tests/html/webvr/dynamic-resolution.html | 10 | ||||
-rw-r--r-- | tests/html/webvr/room-scale.html | 10 | ||||
-rw-r--r-- | tests/html/webvr/simple-mirroring.html | 10 | ||||
-rw-r--r-- | tests/html/webvr/vr-controllers.html | 11 | ||||
-rw-r--r-- | tests/html/webvr/vr-presentation.html | 10 |
16 files changed, 112 insertions, 55 deletions
diff --git a/components/script/dom/macros.rs b/components/script/dom/macros.rs index 5bf3257d1d1..a1bb3065725 100644 --- a/components/script/dom/macros.rs +++ b/components/script/dom/macros.rs @@ -503,6 +503,13 @@ macro_rules! window_event_handlers( event_handler!(unhandledrejection, GetOnunhandledrejection, SetOnunhandledrejection); event_handler!(unload, GetOnunload, SetOnunload); + event_handler!(vrdisplayconnect, GetOnvrdisplayconnect, SetOnvrdisplayconnect); + event_handler!(vrdisplaydisconnect, GetOnvrdisplaydisconnect, SetOnvrdisplaydisconnect); + event_handler!(vrdisplayactivate, GetOnvrdisplayactivate, SetOnvrdisplayactivate); + event_handler!(vrdisplaydeactivate, GetOnvrdisplaydeactivate, SetOnvrdisplaydeactivate); + event_handler!(vrdisplayblur, GetOnvrdisplayblur, SetOnvrdisplayblur); + event_handler!(vrdisplayfocus, GetOnvrdisplayfocus, SetOnvrdisplayfocus); + event_handler!(vrdisplaypresentchange, GetOnvrdisplaypresentchange, SetOnvrdisplaypresentchange); ); (ForwardToWindow) => ( window_owned_event_handler!(afterprint, GetOnafterprint, @@ -528,6 +535,14 @@ macro_rules! window_event_handlers( window_owned_event_handler!(unhandledrejection, GetOnunhandledrejection, SetOnunhandledrejection); window_owned_event_handler!(unload, GetOnunload, SetOnunload); + + window_owned_event_handler!(vrdisplayconnect, GetOnvrdisplayconnect, SetOnvrdisplayconnect); + window_owned_event_handler!(vrdisplaydisconnect, GetOnvrdisplaydisconnect, SetOnvrdisplaydisconnect); + window_owned_event_handler!(vrdisplayactivate, GetOnvrdisplayactivate, SetOnvrdisplayactivate); + window_owned_event_handler!(vrdisplaydeactivate, GetOnvrdisplaydeactivate, SetOnvrdisplaydeactivate); + window_owned_event_handler!(vrdisplayblur, GetOnvrdisplayblur, SetOnvrdisplayblur); + window_owned_event_handler!(vrdisplayfocus, GetOnvrdisplayfocus, SetOnvrdisplayfocus); + window_owned_event_handler!(vrdisplaypresentchange, GetOnvrdisplaypresentchange, SetOnvrdisplaypresentchange); ); ); diff --git a/components/script/dom/navigator.rs b/components/script/dom/navigator.rs index 32dd2900e17..4d0b38f78b3 100644 --- a/components/script/dom/navigator.rs +++ b/components/script/dom/navigator.rs @@ -4,6 +4,7 @@ use dom::bindings::codegen::Bindings::NavigatorBinding; use dom::bindings::codegen::Bindings::NavigatorBinding::NavigatorMethods; +use dom::bindings::codegen::Bindings::VRBinding::VRBinding::VRMethods; use dom::bindings::js::{MutNullableJS, Root}; use dom::bindings::reflector::{Reflector, DomObject, reflect_dom_object}; use dom::bindings::str::DOMString; @@ -13,10 +14,12 @@ use dom::mimetypearray::MimeTypeArray; use dom::navigatorinfo; use dom::permissions::Permissions; use dom::pluginarray::PluginArray; +use dom::promise::Promise; use dom::serviceworkercontainer::ServiceWorkerContainer; use dom::vr::VR; use dom::window::Window; use dom_struct::dom_struct; +use std::rc::Rc; #[dom_struct] pub struct Navigator { @@ -124,12 +127,6 @@ impl NavigatorMethods for Navigator { true } - #[allow(unrooted_must_root)] - // https://w3c.github.io/webvr/#interface-navigator - fn Vr(&self) -> Root<VR> { - self.vr.or_init(|| VR::new(&self.global())) - } - // https://www.w3.org/TR/gamepad/#navigator-interface-extension fn GetGamepads(&self) -> Root<GamepadList> { let root = self.gamepads.or_init(|| { @@ -145,4 +142,16 @@ impl NavigatorMethods for Navigator { fn Permissions(&self) -> Root<Permissions> { self.permissions.or_init(|| Permissions::new(&self.global())) } + + // https://w3c.github.io/webvr/spec/1.1/#navigator-getvrdisplays-attribute + #[allow(unrooted_must_root)] + fn GetVRDisplays(&self) -> Rc<Promise> { + self.Vr().GetDisplays() + } +} + +impl Navigator { + pub fn Vr(&self) -> Root<VR> { + self.vr.or_init(|| VR::new(&self.global())) + } } diff --git a/components/script/dom/vr.rs b/components/script/dom/vr.rs index d906d0e9964..60edcf41050 100644 --- a/components/script/dom/vr.rs +++ b/components/script/dom/vr.rs @@ -9,7 +9,7 @@ use dom::bindings::codegen::Bindings::VRDisplayBinding::VRDisplayMethods; use dom::bindings::error::Error; use dom::bindings::inheritance::Castable; use dom::bindings::js::{JS, Root}; -use dom::bindings::reflector::{DomObject, reflect_dom_object}; +use dom::bindings::reflector::{DomObject, Reflector, reflect_dom_object}; use dom::event::Event; use dom::eventtarget::EventTarget; use dom::gamepad::Gamepad; @@ -27,7 +27,7 @@ use webvr_traits::{WebVRGamepadData, WebVRGamepadEvent, WebVRGamepadState}; #[dom_struct] pub struct VR { - eventtarget: EventTarget, + reflector_: Reflector, displays: DOMRefCell<Vec<JS<VRDisplay>>>, gamepads: DOMRefCell<Vec<JS<Gamepad>>> } @@ -35,7 +35,7 @@ pub struct VR { impl VR { fn new_inherited() -> VR { VR { - eventtarget: EventTarget::new_inherited(), + reflector_: Reflector::new(), displays: DOMRefCell::new(Vec::new()), gamepads: DOMRefCell::new(Vec::new()), } @@ -200,7 +200,7 @@ impl VR { fn notify_display_event(&self, display: &VRDisplay, event: &WebVRDisplayEvent) { let event = VRDisplayEvent::new_from_webvr(&self.global(), &display, &event); - event.upcast::<Event>().fire(self.upcast()); + event.upcast::<Event>().fire(self.global().upcast::<EventTarget>()); } } diff --git a/components/script/dom/vrdisplay.rs b/components/script/dom/vrdisplay.rs index ef611b6224f..37960ea5d6c 100644 --- a/components/script/dom/vrdisplay.rs +++ b/components/script/dom/vrdisplay.rs @@ -11,6 +11,7 @@ use dom::bindings::codegen::Bindings::VRDisplayBinding; use dom::bindings::codegen::Bindings::VRDisplayBinding::VRDisplayMethods; use dom::bindings::codegen::Bindings::VRDisplayBinding::VREye; use dom::bindings::codegen::Bindings::VRLayerBinding::VRLayer; +use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLRenderingContextMethods; use dom::bindings::codegen::Bindings::WindowBinding::FrameRequestCallback; use dom::bindings::codegen::Bindings::WindowBinding::WindowBinding::WindowMethods; use dom::bindings::inheritance::Castable; @@ -391,6 +392,22 @@ impl VRDisplayMethods for VRDisplay { let msg = VRCompositorCommand::SubmitFrame(display_id, layer.left_bounds, layer.right_bounds); api_sender.send(CanvasMsg::WebVR(msg)).unwrap(); } + + // https://w3c.github.io/webvr/spec/1.1/#dom-vrdisplay-getlayers + fn GetLayers(&self) -> Vec<VRLayer> { + // WebVR spec: MUST return an empty array if the VRDisplay is not currently presenting + if !self.presenting.get() { + return Vec::new(); + } + + let layer = self.layer.borrow(); + + vec![VRLayer { + leftBounds: Some(bounds_to_vec(&layer.left_bounds)), + rightBounds: Some(bounds_to_vec(&layer.right_bounds)), + source: self.layer_ctx.get().map(|ctx| ctx.Canvas()), + }] + } } impl VRDisplay { @@ -467,7 +484,7 @@ impl VRDisplay { fn notify_event(&self, event: &WebVRDisplayEvent) { let root = Root::from_ref(&*self); let event = VRDisplayEvent::new_from_webvr(&self.global(), &root, &event); - event.upcast::<Event>().fire(self.upcast()); + event.upcast::<Event>().fire(self.global().upcast::<EventTarget>()); } fn init_present(&self) { @@ -643,3 +660,10 @@ fn validate_layer(cx: *mut JSContext, Err("VRLayer source must be a WebGL Context") } } + +fn bounds_to_vec(src: &[f32; 4]) -> Vec<Finite<f32>> { + vec![Finite::wrap(src[0]), + Finite::wrap(src[1]), + Finite::wrap(src[2]), + Finite::wrap(src[3])] +} diff --git a/components/script/dom/vrdisplayevent.rs b/components/script/dom/vrdisplayevent.rs index 4db24687dcc..1e931f6983d 100644 --- a/components/script/dom/vrdisplayevent.rs +++ b/components/script/dom/vrdisplayevent.rs @@ -59,13 +59,13 @@ impl VRDisplayEvent { event: &WebVRDisplayEvent) -> Root<VRDisplayEvent> { let (name, reason) = match *event { - WebVRDisplayEvent::Connect(_) => ("displayconnect", None), - WebVRDisplayEvent::Disconnect(_) => ("displaydisconnect", None), - WebVRDisplayEvent::Activate(_, reason) => ("activate", Some(reason)), - WebVRDisplayEvent::Deactivate(_, reason) => ("deactivate", Some(reason)), - WebVRDisplayEvent::Blur(_) => ("blur", None), - WebVRDisplayEvent::Focus(_) => ("focus", None), - WebVRDisplayEvent::PresentChange(_, _) => ("presentchange", None), + WebVRDisplayEvent::Connect(_) => ("vrdisplayconnect", None), + WebVRDisplayEvent::Disconnect(_) => ("vrdisplaydisconnect", None), + WebVRDisplayEvent::Activate(_, reason) => ("vrdisplayactivate", Some(reason)), + WebVRDisplayEvent::Deactivate(_, reason) => ("vrdisplaydeactivate", Some(reason)), + WebVRDisplayEvent::Blur(_) => ("vrdisplayblur", None), + WebVRDisplayEvent::Focus(_) => ("vrdisplayfocus", None), + WebVRDisplayEvent::PresentChange(_, _) => ("vrdisplaypresentchange", None), WebVRDisplayEvent::Change(_) | WebVRDisplayEvent::Pause(_) | WebVRDisplayEvent::Resume(_) | diff --git a/components/script/dom/webidls/EventHandler.webidl b/components/script/dom/webidls/EventHandler.webidl index 7bd04bf9e89..7bd06db5a87 100644 --- a/components/script/dom/webidls/EventHandler.webidl +++ b/components/script/dom/webidls/EventHandler.webidl @@ -114,6 +114,17 @@ interface WindowEventHandlers { attribute EventHandler onunload; }; +// https://w3c.github.io/webvr/spec/1.1/#interface-window +partial interface WindowEventHandlers { + attribute EventHandler onvrdisplayconnect; + attribute EventHandler onvrdisplaydisconnect; + attribute EventHandler onvrdisplayactivate; + attribute EventHandler onvrdisplaydeactivate; + attribute EventHandler onvrdisplayblur; + attribute EventHandler onvrdisplayfocus; + attribute EventHandler onvrdisplaypresentchange; +}; + // https://html.spec.whatwg.org/multipage/#documentandelementeventhandlers [NoInterfaceObject, Exposed=Window] interface DocumentAndElementEventHandlers { diff --git a/components/script/dom/webidls/Navigator.webidl b/components/script/dom/webidls/Navigator.webidl index 338753d6261..32ee235c6a3 100644 --- a/components/script/dom/webidls/Navigator.webidl +++ b/components/script/dom/webidls/Navigator.webidl @@ -58,9 +58,9 @@ interface NavigatorCookies { readonly attribute boolean cookieEnabled; }; -// https://w3c.github.io/webvr/#interface-navigator +// https://w3c.github.io/webvr/spec/1.1/#interface-navigator partial interface Navigator { - [SameObject, Pref="dom.webvr.enabled"] readonly attribute VR vr; + [Pref="dom.webvr.enabled"] Promise<sequence<VRDisplay>> getVRDisplays(); }; // https://w3c.github.io/permissions/#navigator-and-workernavigator-extension diff --git a/components/script/dom/webidls/VR.webidl b/components/script/dom/webidls/VR.webidl index 0fded365be0..af256286523 100644 --- a/components/script/dom/webidls/VR.webidl +++ b/components/script/dom/webidls/VR.webidl @@ -3,8 +3,8 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ // https://w3c.github.io/webvr/#interface-navigator -[Pref="dom.webvr.enabled"] -interface VR: EventTarget { +[NoInterfaceObject] +interface VR { Promise<sequence<VRDisplay>> getDisplays(); //readonly attribute FrozenArray<VRDisplay> activeVRDisplays; }; diff --git a/components/script/dom/webidls/VRDisplay.webidl b/components/script/dom/webidls/VRDisplay.webidl index 6822a994a9b..6c8ec7c4320 100644 --- a/components/script/dom/webidls/VRDisplay.webidl +++ b/components/script/dom/webidls/VRDisplay.webidl @@ -119,7 +119,7 @@ interface VRDisplay : EventTarget { /** * Get the layers currently being presented. */ - //sequence<VRLayer> getLayers(); + sequence<VRLayer> getLayers(); /** * The VRLayer provided to the VRDisplay will be captured and presented diff --git a/components/script/script_thread.rs b/components/script/script_thread.rs index 8319ad3cba3..94318472b50 100644 --- a/components/script/script_thread.rs +++ b/components/script/script_thread.rs @@ -27,7 +27,6 @@ use dom::bindings::cell::DOMRefCell; use dom::bindings::codegen::Bindings::CSSStyleDeclarationBinding::CSSStyleDeclarationMethods; use dom::bindings::codegen::Bindings::DocumentBinding::{DocumentMethods, DocumentReadyState}; use dom::bindings::codegen::Bindings::EventBinding::EventInit; -use dom::bindings::codegen::Bindings::NavigatorBinding::NavigatorMethods; use dom::bindings::codegen::Bindings::TransitionEventBinding::TransitionEventInit; use dom::bindings::codegen::Bindings::WindowBinding::WindowMethods; use dom::bindings::conversions::{ConversionResult, FromJSValConvertible, StringificationBehavior}; diff --git a/tests/html/webvr/advanced-mirroring.html b/tests/html/webvr/advanced-mirroring.html index d29b94b66dd..ffb7ae2d3f8 100644 --- a/tests/html/webvr/advanced-mirroring.html +++ b/tests/html/webvr/advanced-mirroring.html @@ -168,10 +168,10 @@ found in the LICENSE file. var frameData; - if (navigator.vr) { + if (navigator.getVRDisplays) { frameData = new VRFrameData(); - navigator.vr.getDisplays().then(function (displays) { + navigator.getVRDisplays().then(function (displays) { if (displays.length > 0) { vrDisplay = displays[0]; vrDisplay.depthNear = 0.1; @@ -190,9 +190,9 @@ found in the LICENSE file. if (vrDisplay.capabilities.canPresent) vrPresentButton = VRSamplesUtil.addButton("Enter VR", "E", "media/icons/cardboard64.png", onVRRequestPresent); - vrDisplay.addEventListener('presentchange', onVRPresentChange, false); - //vrDisplay.addEventListener('activate', onVRRequestPresent, false); - //vrDisplay.addEventListener('deactivate', onVRExitPresent, false); + window.addEventListener('vrdisplaypresentchange', onVRPresentChange, false); + window.addEventListener('vrdisplayactivate', onVRRequestPresent, false); + window.addEventListener('vrdisplaydeactivate', onVRExitPresent, false); } else { initWebGL(); VRSamplesUtil.addInfo("WebVR supported, but no VRDisplays found.", 3000); diff --git a/tests/html/webvr/dynamic-resolution.html b/tests/html/webvr/dynamic-resolution.html index 3e071200d7c..fe421870187 100644 --- a/tests/html/webvr/dynamic-resolution.html +++ b/tests/html/webvr/dynamic-resolution.html @@ -175,10 +175,10 @@ found in the LICENSE file. onResize(); } - if (navigator.vr) { + if (navigator.getVRDisplays) { frameData = new VRFrameData(); - navigator.vr.getDisplays().then(function (displays) { + navigator.getVRDisplays().then(function (displays) { if (displays.length > 0) { vrDisplay = displays[0]; VRSamplesUtil.addButton("Reset Pose", "R", null, function () { vrDisplay.resetPose(); }); @@ -186,9 +186,9 @@ found in the LICENSE file. if (vrDisplay.capabilities.canPresent) vrPresentButton = VRSamplesUtil.addButton("Enter VR", "E", "media/icons/cardboard64.png", onVRRequestPresent); - vrDisplay.addEventListener('presentchange', onVRPresentChange, false); - //vrDisplay.addEventListener('activate', onVRRequestPresent, false); - //vrDisplay.addEventListener('deactivate', onVRExitPresent, false); + window.addEventListener('vrdisplaypresentchange', onVRPresentChange, false); + window.addEventListener('vrdisplayactivate', onVRRequestPresent, false); + window.addEventListener('vrdisplaydeactivate', onVRExitPresent, false); initWebGL(vrDisplay.capabilities.hasExternalDisplay); } else { diff --git a/tests/html/webvr/room-scale.html b/tests/html/webvr/room-scale.html index c39d4f56908..fcd35de041c 100644 --- a/tests/html/webvr/room-scale.html +++ b/tests/html/webvr/room-scale.html @@ -164,10 +164,10 @@ found in the LICENSE file. } } - if (navigator.vr) { + if (navigator.getVRDisplays) { frameData = new VRFrameData(); - navigator.vr.getDisplays().then(function (displays) { + navigator.getVRDisplays().then(function (displays) { if (displays.length > 0) { vrDisplay = displays[0]; vrDisplay.depthNear = 0.1; @@ -198,9 +198,9 @@ found in the LICENSE file. if (vrDisplay.capabilities.canPresent) vrPresentButton = VRSamplesUtil.addButton("Enter VR", "E", "media/icons/cardboard64.png", onVRRequestPresent); - vrDisplay.addEventListener('presentchange', onVRPresentChange, false); - //vrDisplay.addEventListener('activate', onVRRequestPresent, false); - //vrDisplay.addEventListener('deactivate', onVRExitPresent, false); + window.addEventListener('vrdisplaypresentchange', onVRPresentChange, false); + window.addEventListener('vrdisplayactivate', onVRRequestPresent, false); + window.addEventListener('vrdisplaydeactivate', onVRExitPresent, false); } else { initWebGL(false); VRSamplesUtil.addInfo("WebVR supported, but no VRDisplays found.", 3000); diff --git a/tests/html/webvr/simple-mirroring.html b/tests/html/webvr/simple-mirroring.html index e362e5184ff..6578ae49ea4 100644 --- a/tests/html/webvr/simple-mirroring.html +++ b/tests/html/webvr/simple-mirroring.html @@ -160,10 +160,10 @@ found in the LICENSE file. } } - if (navigator.vr) { + if (navigator.getVRDisplays) { frameData = new VRFrameData(); - navigator.vr.getDisplays().then(function (displays) { + navigator.getVRDisplays().then(function (displays) { if (displays.length > 0) { vrDisplay = displays[0]; vrDisplay.depthNear = 0.1; @@ -174,9 +174,9 @@ found in the LICENSE file. if (vrDisplay.capabilities.canPresent) vrPresentButton = VRSamplesUtil.addButton("Enter VR", "E", "media/icons/cardboard64.png", onVRRequestPresent); - vrDisplay.addEventListener('presentchange', onVRPresentChange, false); - //vrDisplay.addEventListener('activate', onVRRequestPresent, false); - //vrDisplay.addEventListener('deactivate', onVRExitPresent, false); + window.addEventListener('vrdisplaypresentchange', onVRPresentChange, false); + window.addEventListener('vrdisplayactivate', onVRRequestPresent, false); + window.addEventListener('vrdisplaydeactivate', onVRExitPresent, false); // Only use preserveDrawingBuffer if we have an external display to // mirror to. diff --git a/tests/html/webvr/vr-controllers.html b/tests/html/webvr/vr-controllers.html index 2220c04fdc6..797b4198fdc 100644 --- a/tests/html/webvr/vr-controllers.html +++ b/tests/html/webvr/vr-controllers.html @@ -192,10 +192,9 @@ found in the LICENSE file. } } - if (navigator.vr || navigator.getVRDisplays) { + if (navigator.getVRDisplays) { frameData = new VRFrameData(); - navigator.vr.getDisplays().then(function (displays) { - // navigator.getVRDisplays().then(function (displays) { + navigator.getVRDisplays().then(function (displays) { if (displays.length > 0) { vrDisplay = displays[displays.length - 1]; vrDisplay.depthNear = 0.1; @@ -214,9 +213,9 @@ found in the LICENSE file. if (vrDisplay.capabilities.canPresent) vrPresentButton = VRSamplesUtil.addButton("Enter VR", "E", "media/icons/cardboard64.png", onVRRequestPresent); - vrDisplay.addEventListener('presentchange', onVRPresentChange, false); - //vrDisplay.addEventListener('vrdisplayactivate', onVRRequestPresent, false); - //vrDisplay.addEventListener('vrdisplaydeactivate', onVRExitPresent, false); + window.addEventListener('vrdisplaypresentchange', onVRPresentChange, false); + window.addEventListener('vrdisplayactivate', onVRRequestPresent, false); + window.addEventListener('vrdisplaydeactivate', onVRExitPresent, false); console.log(navigator.getGamepads()); setTimeout(function(){ onVRRequestPresent(); diff --git a/tests/html/webvr/vr-presentation.html b/tests/html/webvr/vr-presentation.html index 3ecb848fab4..98adc9dd195 100644 --- a/tests/html/webvr/vr-presentation.html +++ b/tests/html/webvr/vr-presentation.html @@ -179,10 +179,10 @@ found in the LICENSE file. } } - if (navigator.vr) { + if (navigator.getVRDisplays) { frameData = new VRFrameData(); - navigator.vr.getDisplays().then(function (displays) { + navigator.getVRDisplays().then(function (displays) { if (displays.length > 0) { vrDisplay = displays[0]; @@ -203,7 +203,7 @@ found in the LICENSE file. // The UA may kick us out of VR present mode for any reason, so to // ensure we always know when we begin/end presenting we need to // listen for vrdisplaypresentchange events. - vrDisplay.addEventListener('presentchange', onVRPresentChange, false); + window.addEventListener('vrdisplaypresentchange', onVRPresentChange, false); // These events fire when the user agent has had some indication that // it would be appropariate to enter or exit VR presentation mode, such @@ -211,8 +211,8 @@ found in the LICENSE file. // You can inspect the `reason` property of the event to learn why the // event was fired, but in this case we're going to always trust the // event and enter or exit VR presentation mode when asked. - //vrDisplay.addEventListener('activate', onVRRequestPresent, false); - //vrDisplay.addEventListener('deactivate', onVRExitPresent, false); + window.addEventListener('vrdisplayactivate', onVRRequestPresent, false); + window.addEventListener('vrdisplaydeactivate', onVRExitPresent, false); } else { VRSamplesUtil.addInfo("WebVR supported, but no VRDisplays found.", 3000); } |