aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom
diff options
context:
space:
mode:
Diffstat (limited to 'components/script/dom')
-rw-r--r--components/script/dom/macros.rs15
-rw-r--r--components/script/dom/navigator.rs21
-rw-r--r--components/script/dom/vr.rs8
-rw-r--r--components/script/dom/vrdisplay.rs26
-rw-r--r--components/script/dom/vrdisplayevent.rs14
-rw-r--r--components/script/dom/webidls/EventHandler.webidl11
-rw-r--r--components/script/dom/webidls/Navigator.webidl4
-rw-r--r--components/script/dom/webidls/VR.webidl4
-rw-r--r--components/script/dom/webidls/VRDisplay.webidl2
9 files changed, 82 insertions, 23 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