mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +01:00
Use Window in new methods instead of GlobalScope for interfaces with … (#36133)
…Window-only constructors <!-- Please describe your changes on the following line: --> --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: --> - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [x] These changes fix #36118 (GitHub issue number if applicable) <!-- Either: --> - [ ] There are tests for these changes OR - [ ] These changes do not require tests because ___ <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> --------- Signed-off-by: richarddushime <mudaherarich@gmail.com> Signed-off-by: Richard Dushime <45734838+richarddushime@users.noreply.github.com>
This commit is contained in:
parent
2ce306f450
commit
60baa8ce11
40 changed files with 226 additions and 240 deletions
|
@ -12,6 +12,7 @@ use crate::dom::bindings::root::{Dom, DomRoot};
|
|||
use crate::dom::bindings::utils::to_frozen_array;
|
||||
use crate::dom::dompointreadonly::DOMPointReadOnly;
|
||||
use crate::dom::globalscope::GlobalScope;
|
||||
use crate::dom::window::Window;
|
||||
use crate::dom::xrreferencespace::XRReferenceSpace;
|
||||
use crate::dom::xrrigidtransform::XRRigidTransform;
|
||||
use crate::dom::xrsession::XRSession;
|
||||
|
@ -40,12 +41,13 @@ impl XRBoundedReferenceSpace {
|
|||
|
||||
#[allow(unused)]
|
||||
pub(crate) fn new(
|
||||
global: &GlobalScope,
|
||||
window: &Window,
|
||||
session: &XRSession,
|
||||
can_gc: CanGc,
|
||||
) -> DomRoot<XRBoundedReferenceSpace> {
|
||||
let offset = XRRigidTransform::identity(global, can_gc);
|
||||
Self::new_offset(global, session, &offset, can_gc)
|
||||
let offset = XRRigidTransform::identity(window, can_gc);
|
||||
let global = window.global();
|
||||
Self::new_offset(&global, session, &offset, can_gc)
|
||||
}
|
||||
|
||||
#[allow(unused)]
|
||||
|
|
|
@ -15,7 +15,7 @@ use crate::dom::bindings::inheritance::Castable;
|
|||
use crate::dom::bindings::num::Finite;
|
||||
use crate::dom::bindings::reflector::{DomGlobal, Reflector, reflect_dom_object};
|
||||
use crate::dom::bindings::root::{Dom, DomRoot};
|
||||
use crate::dom::globalscope::GlobalScope;
|
||||
use crate::dom::window::Window;
|
||||
use crate::dom::xrhittestresult::XRHitTestResult;
|
||||
use crate::dom::xrhittestsource::XRHitTestSource;
|
||||
use crate::dom::xrjointpose::XRJointPose;
|
||||
|
@ -50,14 +50,14 @@ impl XRFrame {
|
|||
}
|
||||
|
||||
pub(crate) fn new(
|
||||
global: &GlobalScope,
|
||||
window: &Window,
|
||||
session: &XRSession,
|
||||
data: Frame,
|
||||
can_gc: CanGc,
|
||||
) -> DomRoot<XRFrame> {
|
||||
reflect_dom_object(
|
||||
Box::new(XRFrame::new_inherited(session, data)),
|
||||
global,
|
||||
window,
|
||||
can_gc,
|
||||
)
|
||||
}
|
||||
|
@ -123,7 +123,7 @@ impl XRFrameMethods<crate::DomTypeHolder> for XRFrame {
|
|||
return Ok(None);
|
||||
};
|
||||
Ok(Some(XRViewerPose::new(
|
||||
&self.global(),
|
||||
self.global().as_window(),
|
||||
&self.session,
|
||||
to_base,
|
||||
viewer_pose,
|
||||
|
@ -155,7 +155,7 @@ impl XRFrameMethods<crate::DomTypeHolder> for XRFrame {
|
|||
return Ok(None);
|
||||
};
|
||||
let pose = space.then(&base_space.inverse());
|
||||
Ok(Some(XRPose::new(&self.global(), pose, can_gc)))
|
||||
Ok(Some(XRPose::new(self.global().as_window(), pose, can_gc)))
|
||||
}
|
||||
|
||||
/// <https://immersive-web.github.io/webxr/#dom-xrframe-getpose>
|
||||
|
@ -185,7 +185,7 @@ impl XRFrameMethods<crate::DomTypeHolder> for XRFrame {
|
|||
};
|
||||
let pose = joint_frame.pose.then(&base_space.inverse());
|
||||
Ok(Some(XRJointPose::new(
|
||||
&self.global(),
|
||||
self.global().as_window(),
|
||||
pose.cast_unit(),
|
||||
Some(joint_frame.radius),
|
||||
can_gc,
|
||||
|
@ -198,7 +198,7 @@ impl XRFrameMethods<crate::DomTypeHolder> for XRFrame {
|
|||
.hit_test_results
|
||||
.iter()
|
||||
.filter(|r| r.id == source.id())
|
||||
.map(|r| XRHitTestResult::new(&self.global(), *r, self, CanGc::note()))
|
||||
.map(|r| XRHitTestResult::new(self.global().as_window(), *r, self, CanGc::note()))
|
||||
.collect()
|
||||
}
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ use webxr_api::HitTestResult;
|
|||
use crate::dom::bindings::codegen::Bindings::XRHitTestResultBinding::XRHitTestResultMethods;
|
||||
use crate::dom::bindings::reflector::{DomGlobal, Reflector, reflect_dom_object};
|
||||
use crate::dom::bindings::root::{Dom, DomRoot};
|
||||
use crate::dom::globalscope::GlobalScope;
|
||||
use crate::dom::window::Window;
|
||||
use crate::dom::xrframe::XRFrame;
|
||||
use crate::dom::xrpose::XRPose;
|
||||
use crate::dom::xrspace::XRSpace;
|
||||
|
@ -33,14 +33,14 @@ impl XRHitTestResult {
|
|||
}
|
||||
|
||||
pub(crate) fn new(
|
||||
global: &GlobalScope,
|
||||
window: &Window,
|
||||
result: HitTestResult,
|
||||
frame: &XRFrame,
|
||||
can_gc: CanGc,
|
||||
) -> DomRoot<XRHitTestResult> {
|
||||
reflect_dom_object(
|
||||
Box::new(XRHitTestResult::new_inherited(result, frame)),
|
||||
global,
|
||||
window,
|
||||
can_gc,
|
||||
)
|
||||
}
|
||||
|
@ -51,6 +51,10 @@ impl XRHitTestResultMethods<crate::DomTypeHolder> for XRHitTestResult {
|
|||
fn GetPose(&self, base: &XRSpace, can_gc: CanGc) -> Option<DomRoot<XRPose>> {
|
||||
let base = self.frame.get_pose(base)?;
|
||||
let pose = self.result.space.then(&base.inverse());
|
||||
Some(XRPose::new(&self.global(), pose.cast_unit(), can_gc))
|
||||
Some(XRPose::new(
|
||||
self.global().as_window(),
|
||||
pose.cast_unit(),
|
||||
can_gc,
|
||||
))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -46,6 +46,7 @@ impl XRInputSourceArray {
|
|||
can_gc: CanGc,
|
||||
) {
|
||||
let global = self.global();
|
||||
let window = global.as_window();
|
||||
|
||||
let mut added = vec![];
|
||||
for info in inputs {
|
||||
|
@ -65,7 +66,7 @@ impl XRInputSourceArray {
|
|||
}
|
||||
|
||||
let event = XRInputSourcesChangeEvent::new(
|
||||
&global,
|
||||
window,
|
||||
atom!("inputsourceschange"),
|
||||
false,
|
||||
true,
|
||||
|
@ -79,6 +80,7 @@ impl XRInputSourceArray {
|
|||
|
||||
pub(crate) fn remove_input_source(&self, session: &XRSession, id: InputId, can_gc: CanGc) {
|
||||
let global = self.global();
|
||||
let window = global.as_window();
|
||||
let removed = if let Some(i) = self.input_sources.borrow().iter().find(|i| i.id() == id) {
|
||||
i.gamepad().update_connected(false, false, can_gc);
|
||||
[DomRoot::from_ref(&**i)]
|
||||
|
@ -87,7 +89,7 @@ impl XRInputSourceArray {
|
|||
};
|
||||
|
||||
let event = XRInputSourcesChangeEvent::new(
|
||||
&global,
|
||||
window,
|
||||
atom!("inputsourceschange"),
|
||||
false,
|
||||
true,
|
||||
|
@ -108,6 +110,7 @@ impl XRInputSourceArray {
|
|||
can_gc: CanGc,
|
||||
) {
|
||||
let global = self.global();
|
||||
let window = global.as_window();
|
||||
let root;
|
||||
let removed = if let Some(i) = self.input_sources.borrow().iter().find(|i| i.id() == id) {
|
||||
i.gamepad().update_connected(false, false, can_gc);
|
||||
|
@ -124,7 +127,7 @@ impl XRInputSourceArray {
|
|||
let added = [input];
|
||||
|
||||
let event = XRInputSourcesChangeEvent::new(
|
||||
&global,
|
||||
window,
|
||||
atom!("inputsourceschange"),
|
||||
false,
|
||||
true,
|
||||
|
|
|
@ -12,11 +12,10 @@ use crate::dom::bindings::codegen::Bindings::XRInputSourceEventBinding::{
|
|||
};
|
||||
use crate::dom::bindings::error::Fallible;
|
||||
use crate::dom::bindings::inheritance::Castable;
|
||||
use crate::dom::bindings::reflector::{DomGlobal, reflect_dom_object_with_proto};
|
||||
use crate::dom::bindings::reflector::reflect_dom_object_with_proto;
|
||||
use crate::dom::bindings::root::{Dom, DomRoot};
|
||||
use crate::dom::bindings::str::DOMString;
|
||||
use crate::dom::event::Event;
|
||||
use crate::dom::globalscope::GlobalScope;
|
||||
use crate::dom::window::Window;
|
||||
use crate::dom::xrframe::XRFrame;
|
||||
use crate::dom::xrinputsource::XRInputSource;
|
||||
|
@ -40,7 +39,7 @@ impl XRInputSourceEvent {
|
|||
}
|
||||
|
||||
pub(crate) fn new(
|
||||
global: &GlobalScope,
|
||||
window: &Window,
|
||||
type_: Atom,
|
||||
bubbles: bool,
|
||||
cancelable: bool,
|
||||
|
@ -49,13 +48,13 @@ impl XRInputSourceEvent {
|
|||
can_gc: CanGc,
|
||||
) -> DomRoot<XRInputSourceEvent> {
|
||||
Self::new_with_proto(
|
||||
global, None, type_, bubbles, cancelable, frame, source, can_gc,
|
||||
window, None, type_, bubbles, cancelable, frame, source, can_gc,
|
||||
)
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
fn new_with_proto(
|
||||
global: &GlobalScope,
|
||||
window: &Window,
|
||||
proto: Option<HandleObject>,
|
||||
type_: Atom,
|
||||
bubbles: bool,
|
||||
|
@ -66,7 +65,7 @@ impl XRInputSourceEvent {
|
|||
) -> DomRoot<XRInputSourceEvent> {
|
||||
let trackevent = reflect_dom_object_with_proto(
|
||||
Box::new(XRInputSourceEvent::new_inherited(frame, source)),
|
||||
global,
|
||||
window,
|
||||
proto,
|
||||
can_gc,
|
||||
);
|
||||
|
@ -88,7 +87,7 @@ impl XRInputSourceEventMethods<crate::DomTypeHolder> for XRInputSourceEvent {
|
|||
init: &XRInputSourceEventBinding::XRInputSourceEventInit,
|
||||
) -> Fallible<DomRoot<XRInputSourceEvent>> {
|
||||
Ok(XRInputSourceEvent::new_with_proto(
|
||||
&window.global(),
|
||||
window,
|
||||
proto,
|
||||
Atom::from(type_),
|
||||
init.parent.bubbles,
|
||||
|
|
|
@ -13,7 +13,7 @@ use crate::dom::bindings::codegen::Bindings::XRInputSourcesChangeEventBinding::{
|
|||
self, XRInputSourcesChangeEventMethods,
|
||||
};
|
||||
use crate::dom::bindings::inheritance::Castable;
|
||||
use crate::dom::bindings::reflector::{DomGlobal, reflect_dom_object_with_proto};
|
||||
use crate::dom::bindings::reflector::reflect_dom_object_with_proto;
|
||||
use crate::dom::bindings::root::{Dom, DomRoot};
|
||||
use crate::dom::bindings::str::DOMString;
|
||||
use crate::dom::bindings::utils::to_frozen_array;
|
||||
|
@ -48,7 +48,7 @@ impl XRInputSourcesChangeEvent {
|
|||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub(crate) fn new(
|
||||
global: &GlobalScope,
|
||||
window: &Window,
|
||||
type_: Atom,
|
||||
bubbles: bool,
|
||||
cancelable: bool,
|
||||
|
@ -58,14 +58,14 @@ impl XRInputSourcesChangeEvent {
|
|||
can_gc: CanGc,
|
||||
) -> DomRoot<XRInputSourcesChangeEvent> {
|
||||
Self::new_with_proto(
|
||||
global, None, type_, bubbles, cancelable, session, added, removed, can_gc,
|
||||
window, None, type_, bubbles, cancelable, session, added, removed, can_gc,
|
||||
)
|
||||
}
|
||||
|
||||
#[allow(unsafe_code)]
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
fn new_with_proto(
|
||||
global: &GlobalScope,
|
||||
window: &Window,
|
||||
proto: Option<HandleObject>,
|
||||
type_: Atom,
|
||||
bubbles: bool,
|
||||
|
@ -77,7 +77,7 @@ impl XRInputSourcesChangeEvent {
|
|||
) -> DomRoot<XRInputSourcesChangeEvent> {
|
||||
let changeevent = reflect_dom_object_with_proto(
|
||||
Box::new(XRInputSourcesChangeEvent::new_inherited(session)),
|
||||
global,
|
||||
window,
|
||||
proto,
|
||||
can_gc,
|
||||
);
|
||||
|
@ -85,7 +85,7 @@ impl XRInputSourcesChangeEvent {
|
|||
let event = changeevent.upcast::<Event>();
|
||||
event.init_event(type_, bubbles, cancelable);
|
||||
}
|
||||
let _ac = enter_realm(global);
|
||||
let _ac = enter_realm(window);
|
||||
let cx = GlobalScope::get_cx();
|
||||
rooted!(in(*cx) let mut frozen_val: JSVal);
|
||||
to_frozen_array(added, cx, frozen_val.handle_mut(), can_gc);
|
||||
|
@ -106,7 +106,7 @@ impl XRInputSourcesChangeEventMethods<crate::DomTypeHolder> for XRInputSourcesCh
|
|||
init: &XRInputSourcesChangeEventBinding::XRInputSourcesChangeEventInit,
|
||||
) -> DomRoot<XRInputSourcesChangeEvent> {
|
||||
XRInputSourcesChangeEvent::new_with_proto(
|
||||
&window.global(),
|
||||
window,
|
||||
proto,
|
||||
Atom::from(type_),
|
||||
init.parent.bubbles,
|
||||
|
|
|
@ -8,7 +8,7 @@ use crate::dom::bindings::codegen::Bindings::XRJointPoseBinding::XRJointPoseMeth
|
|||
use crate::dom::bindings::num::Finite;
|
||||
use crate::dom::bindings::reflector::reflect_dom_object;
|
||||
use crate::dom::bindings::root::DomRoot;
|
||||
use crate::dom::globalscope::GlobalScope;
|
||||
use crate::dom::window::Window;
|
||||
use crate::dom::xrpose::XRPose;
|
||||
use crate::dom::xrrigidtransform::XRRigidTransform;
|
||||
use crate::dom::xrsession::ApiRigidTransform;
|
||||
|
@ -30,15 +30,15 @@ impl XRJointPose {
|
|||
|
||||
#[allow(unsafe_code)]
|
||||
pub(crate) fn new(
|
||||
global: &GlobalScope,
|
||||
window: &Window,
|
||||
pose: ApiRigidTransform,
|
||||
radius: Option<f32>,
|
||||
can_gc: CanGc,
|
||||
) -> DomRoot<XRJointPose> {
|
||||
let transform = XRRigidTransform::new(global, pose, can_gc);
|
||||
let transform = XRRigidTransform::new(window, pose, can_gc);
|
||||
reflect_dom_object(
|
||||
Box::new(XRJointPose::new_inherited(&transform, radius)),
|
||||
global,
|
||||
window,
|
||||
can_gc,
|
||||
)
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ use crate::dom::bindings::codegen::Bindings::XRPoseBinding::XRPoseMethods;
|
|||
use crate::dom::bindings::reflector::{Reflector, reflect_dom_object};
|
||||
use crate::dom::bindings::root::{Dom, DomRoot};
|
||||
use crate::dom::dompointreadonly::DOMPointReadOnly;
|
||||
use crate::dom::globalscope::GlobalScope;
|
||||
use crate::dom::window::Window;
|
||||
use crate::dom::xrrigidtransform::XRRigidTransform;
|
||||
use crate::dom::xrsession::ApiRigidTransform;
|
||||
use crate::script_runtime::CanGc;
|
||||
|
@ -29,12 +29,12 @@ impl XRPose {
|
|||
|
||||
#[allow(unused)]
|
||||
pub(crate) fn new(
|
||||
global: &GlobalScope,
|
||||
window: &Window,
|
||||
transform: ApiRigidTransform,
|
||||
can_gc: CanGc,
|
||||
) -> DomRoot<XRPose> {
|
||||
let transform = XRRigidTransform::new(global, transform, can_gc);
|
||||
reflect_dom_object(Box::new(XRPose::new_inherited(&transform)), global, can_gc)
|
||||
let transform = XRRigidTransform::new(window, transform, can_gc);
|
||||
reflect_dom_object(Box::new(XRPose::new_inherited(&transform)), window, can_gc)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -15,7 +15,6 @@ use crate::dom::bindings::error::{Error, Fallible};
|
|||
use crate::dom::bindings::reflector::{DomGlobal, Reflector, reflect_dom_object_with_proto};
|
||||
use crate::dom::bindings::root::DomRoot;
|
||||
use crate::dom::dompointreadonly::DOMPointReadOnly;
|
||||
use crate::dom::globalscope::GlobalScope;
|
||||
use crate::dom::window::Window;
|
||||
use crate::dom::xrrigidtransform::XRRigidTransform;
|
||||
use crate::script_runtime::{CanGc, JSContext};
|
||||
|
@ -40,12 +39,12 @@ impl XRRay {
|
|||
}
|
||||
|
||||
fn new(
|
||||
global: &GlobalScope,
|
||||
window: &Window,
|
||||
proto: Option<HandleObject>,
|
||||
ray: Ray<ApiSpace>,
|
||||
can_gc: CanGc,
|
||||
) -> DomRoot<XRRay> {
|
||||
reflect_dom_object_with_proto(Box::new(XRRay::new_inherited(ray)), global, proto, can_gc)
|
||||
reflect_dom_object_with_proto(Box::new(XRRay::new_inherited(ray)), window, proto, can_gc)
|
||||
}
|
||||
|
||||
pub(crate) fn ray(&self) -> Ray<ApiSpace> {
|
||||
|
@ -82,12 +81,7 @@ impl XRRayMethods<crate::DomTypeHolder> for XRRay {
|
|||
)
|
||||
.normalize();
|
||||
|
||||
Ok(Self::new(
|
||||
&window.global(),
|
||||
proto,
|
||||
Ray { origin, direction },
|
||||
can_gc,
|
||||
))
|
||||
Ok(Self::new(window, proto, Ray { origin, direction }, can_gc))
|
||||
}
|
||||
|
||||
/// <https://immersive-web.github.io/hit-test/#dom-xrray-xrray-transform>
|
||||
|
@ -103,12 +97,7 @@ impl XRRayMethods<crate::DomTypeHolder> for XRRay {
|
|||
.rotation
|
||||
.transform_vector3d(Vector3D::new(0., 0., -1.));
|
||||
|
||||
Ok(Self::new(
|
||||
&window.global(),
|
||||
proto,
|
||||
Ray { origin, direction },
|
||||
can_gc,
|
||||
))
|
||||
Ok(Self::new(window, proto, Ray { origin, direction }, can_gc))
|
||||
}
|
||||
|
||||
/// <https://immersive-web.github.io/hit-test/#dom-xrray-origin>
|
||||
|
|
|
@ -13,6 +13,7 @@ use crate::dom::bindings::inheritance::Castable;
|
|||
use crate::dom::bindings::reflector::{DomGlobal, reflect_dom_object};
|
||||
use crate::dom::bindings::root::{Dom, DomRoot};
|
||||
use crate::dom::globalscope::GlobalScope;
|
||||
use crate::dom::window::Window;
|
||||
use crate::dom::xrrigidtransform::XRRigidTransform;
|
||||
use crate::dom::xrsession::{ApiPose, BaseTransform, XRSession, cast_transform};
|
||||
use crate::dom::xrspace::XRSpace;
|
||||
|
@ -40,13 +41,13 @@ impl XRReferenceSpace {
|
|||
|
||||
#[allow(unused)]
|
||||
pub(crate) fn new(
|
||||
global: &GlobalScope,
|
||||
window: &Window,
|
||||
session: &XRSession,
|
||||
ty: XRReferenceSpaceType,
|
||||
can_gc: CanGc,
|
||||
) -> DomRoot<XRReferenceSpace> {
|
||||
let offset = XRRigidTransform::identity(global, can_gc);
|
||||
Self::new_offset(global, session, ty, &offset, can_gc)
|
||||
let offset = XRRigidTransform::identity(window, can_gc);
|
||||
Self::new_offset(&window.global(), session, ty, &offset, can_gc)
|
||||
}
|
||||
|
||||
#[allow(unused)]
|
||||
|
@ -85,7 +86,7 @@ impl XRReferenceSpaceMethods<crate::DomTypeHolder> for XRReferenceSpace {
|
|||
/// <https://immersive-web.github.io/webxr/#dom-xrreferencespace-getoffsetreferencespace>
|
||||
fn GetOffsetReferenceSpace(&self, new: &XRRigidTransform, can_gc: CanGc) -> DomRoot<Self> {
|
||||
let offset = new.transform().then(&self.offset.transform());
|
||||
let offset = XRRigidTransform::new(&self.global(), offset, can_gc);
|
||||
let offset = XRRigidTransform::new(self.global().as_window(), offset, can_gc);
|
||||
Self::new_offset(
|
||||
&self.global(),
|
||||
self.upcast::<XRSpace>().session(),
|
||||
|
|
|
@ -12,11 +12,10 @@ use crate::dom::bindings::codegen::Bindings::XRReferenceSpaceEventBinding::{
|
|||
};
|
||||
use crate::dom::bindings::error::Fallible;
|
||||
use crate::dom::bindings::inheritance::Castable;
|
||||
use crate::dom::bindings::reflector::{DomGlobal, reflect_dom_object_with_proto};
|
||||
use crate::dom::bindings::reflector::reflect_dom_object_with_proto;
|
||||
use crate::dom::bindings::root::{Dom, DomRoot};
|
||||
use crate::dom::bindings::str::DOMString;
|
||||
use crate::dom::event::Event;
|
||||
use crate::dom::globalscope::GlobalScope;
|
||||
use crate::dom::window::Window;
|
||||
use crate::dom::xrreferencespace::XRReferenceSpace;
|
||||
use crate::dom::xrrigidtransform::XRRigidTransform;
|
||||
|
@ -43,7 +42,7 @@ impl XRReferenceSpaceEvent {
|
|||
}
|
||||
|
||||
pub(crate) fn new(
|
||||
global: &GlobalScope,
|
||||
window: &Window,
|
||||
type_: Atom,
|
||||
bubbles: bool,
|
||||
cancelable: bool,
|
||||
|
@ -52,13 +51,13 @@ impl XRReferenceSpaceEvent {
|
|||
can_gc: CanGc,
|
||||
) -> DomRoot<XRReferenceSpaceEvent> {
|
||||
Self::new_with_proto(
|
||||
global, None, type_, bubbles, cancelable, space, transform, can_gc,
|
||||
window, None, type_, bubbles, cancelable, space, transform, can_gc,
|
||||
)
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
fn new_with_proto(
|
||||
global: &GlobalScope,
|
||||
window: &Window,
|
||||
proto: Option<HandleObject>,
|
||||
type_: Atom,
|
||||
bubbles: bool,
|
||||
|
@ -69,7 +68,7 @@ impl XRReferenceSpaceEvent {
|
|||
) -> DomRoot<XRReferenceSpaceEvent> {
|
||||
let trackevent = reflect_dom_object_with_proto(
|
||||
Box::new(XRReferenceSpaceEvent::new_inherited(space, transform)),
|
||||
global,
|
||||
window,
|
||||
proto,
|
||||
can_gc,
|
||||
);
|
||||
|
@ -91,7 +90,7 @@ impl XRReferenceSpaceEventMethods<crate::DomTypeHolder> for XRReferenceSpaceEven
|
|||
init: &XRReferenceSpaceEventInit,
|
||||
) -> Fallible<DomRoot<XRReferenceSpaceEvent>> {
|
||||
Ok(XRReferenceSpaceEvent::new_with_proto(
|
||||
&window.global(),
|
||||
window,
|
||||
proto,
|
||||
Atom::from(type_),
|
||||
init.parent.bubbles,
|
||||
|
|
|
@ -14,7 +14,6 @@ use crate::dom::bindings::error::{Error, Fallible};
|
|||
use crate::dom::bindings::reflector::{DomGlobal, Reflector, reflect_dom_object_with_proto};
|
||||
use crate::dom::bindings::root::{DomRoot, MutNullableDom};
|
||||
use crate::dom::dompointreadonly::DOMPointReadOnly;
|
||||
use crate::dom::globalscope::GlobalScope;
|
||||
use crate::dom::window::Window;
|
||||
use crate::dom::xrsession::ApiRigidTransform;
|
||||
use crate::script_runtime::{CanGc, JSContext};
|
||||
|
@ -45,28 +44,28 @@ impl XRRigidTransform {
|
|||
}
|
||||
|
||||
pub(crate) fn new(
|
||||
global: &GlobalScope,
|
||||
window: &Window,
|
||||
transform: ApiRigidTransform,
|
||||
can_gc: CanGc,
|
||||
) -> DomRoot<XRRigidTransform> {
|
||||
Self::new_with_proto(global, None, transform, can_gc)
|
||||
Self::new_with_proto(window, None, transform, can_gc)
|
||||
}
|
||||
|
||||
fn new_with_proto(
|
||||
global: &GlobalScope,
|
||||
window: &Window,
|
||||
proto: Option<HandleObject>,
|
||||
transform: ApiRigidTransform,
|
||||
can_gc: CanGc,
|
||||
) -> DomRoot<XRRigidTransform> {
|
||||
reflect_dom_object_with_proto(
|
||||
Box::new(XRRigidTransform::new_inherited(transform)),
|
||||
global,
|
||||
window,
|
||||
proto,
|
||||
can_gc,
|
||||
)
|
||||
}
|
||||
|
||||
pub(crate) fn identity(window: &GlobalScope, can_gc: CanGc) -> DomRoot<XRRigidTransform> {
|
||||
pub(crate) fn identity(window: &Window, can_gc: CanGc) -> DomRoot<XRRigidTransform> {
|
||||
let transform = RigidTransform3D::identity();
|
||||
XRRigidTransform::new(window, transform, can_gc)
|
||||
}
|
||||
|
@ -123,10 +122,7 @@ impl XRRigidTransformMethods<crate::DomTypeHolder> for XRRigidTransform {
|
|||
}
|
||||
let transform = RigidTransform3D::new(rotate, translate);
|
||||
Ok(XRRigidTransform::new_with_proto(
|
||||
&window.global(),
|
||||
proto,
|
||||
transform,
|
||||
can_gc,
|
||||
window, proto, transform, can_gc,
|
||||
))
|
||||
}
|
||||
|
||||
|
@ -161,7 +157,8 @@ impl XRRigidTransformMethods<crate::DomTypeHolder> for XRRigidTransform {
|
|||
// https://immersive-web.github.io/webxr/#dom-xrrigidtransform-inverse
|
||||
fn Inverse(&self, can_gc: CanGc) -> DomRoot<XRRigidTransform> {
|
||||
self.inverse.or_init(|| {
|
||||
let transform = XRRigidTransform::new(&self.global(), self.transform.inverse(), can_gc);
|
||||
let transform =
|
||||
XRRigidTransform::new(self.global().as_window(), self.transform.inverse(), can_gc);
|
||||
transform.inverse.set(Some(self));
|
||||
transform
|
||||
})
|
||||
|
|
|
@ -289,8 +289,14 @@ impl XRSession {
|
|||
promise.resolve_native(&(), can_gc);
|
||||
}
|
||||
// Step 7
|
||||
let event =
|
||||
XRSessionEvent::new(&self.global(), atom!("end"), false, false, self, can_gc);
|
||||
let event = XRSessionEvent::new(
|
||||
self.global().as_window(),
|
||||
atom!("end"),
|
||||
false,
|
||||
false,
|
||||
self,
|
||||
can_gc,
|
||||
);
|
||||
event.upcast::<Event>().fire(self.upcast(), can_gc);
|
||||
},
|
||||
XREvent::Select(input, kind, ty, frame) => {
|
||||
|
@ -303,11 +309,11 @@ impl XRSession {
|
|||
let source = self.input_sources.find(input);
|
||||
let atom_index = if kind == SelectKind::Squeeze { 1 } else { 0 };
|
||||
if let Some(source) = source {
|
||||
let frame = XRFrame::new(&self.global(), self, frame, can_gc);
|
||||
let frame = XRFrame::new(self.global().as_window(), self, frame, can_gc);
|
||||
frame.set_active(true);
|
||||
if ty == SelectEvent::Start {
|
||||
let event = XRInputSourceEvent::new(
|
||||
&self.global(),
|
||||
self.global().as_window(),
|
||||
START_ATOMS[atom_index].clone(),
|
||||
false,
|
||||
false,
|
||||
|
@ -319,7 +325,7 @@ impl XRSession {
|
|||
} else {
|
||||
if ty == SelectEvent::Select {
|
||||
let event = XRInputSourceEvent::new(
|
||||
&self.global(),
|
||||
self.global().as_window(),
|
||||
EVENT_ATOMS[atom_index].clone(),
|
||||
false,
|
||||
false,
|
||||
|
@ -330,7 +336,7 @@ impl XRSession {
|
|||
event.upcast::<Event>().fire(self.upcast(), can_gc);
|
||||
}
|
||||
let event = XRInputSourceEvent::new(
|
||||
&self.global(),
|
||||
self.global().as_window(),
|
||||
END_ATOMS[atom_index].clone(),
|
||||
false,
|
||||
false,
|
||||
|
@ -351,7 +357,7 @@ impl XRSession {
|
|||
};
|
||||
self.visibility_state.set(v);
|
||||
let event = XRSessionEvent::new(
|
||||
&self.global(),
|
||||
self.global().as_window(),
|
||||
atom!("visibilitychange"),
|
||||
false,
|
||||
false,
|
||||
|
@ -393,9 +399,10 @@ impl XRSession {
|
|||
base == base_space
|
||||
})
|
||||
.for_each(|space| {
|
||||
let offset = XRRigidTransform::new(&self.global(), transform, can_gc);
|
||||
let offset =
|
||||
XRRigidTransform::new(self.global().as_window(), transform, can_gc);
|
||||
let event = XRReferenceSpaceEvent::new(
|
||||
&self.global(),
|
||||
self.global().as_window(),
|
||||
atom!("reset"),
|
||||
false,
|
||||
false,
|
||||
|
@ -462,7 +469,7 @@ impl XRSession {
|
|||
}
|
||||
|
||||
let time = self.global().performance().to_dom_high_res_time_stamp(time);
|
||||
let frame = XRFrame::new(&self.global(), self, frame, CanGc::note());
|
||||
let frame = XRFrame::new(self.global().as_window(), self, frame, CanGc::note());
|
||||
|
||||
// Step 8-9
|
||||
frame.set_active(true);
|
||||
|
@ -603,7 +610,7 @@ impl XRSession {
|
|||
self.framerate.set(rate);
|
||||
|
||||
let event = XRSessionEvent::new(
|
||||
&self.global(),
|
||||
self.global().as_window(),
|
||||
Atom::from("frameratechange"),
|
||||
false,
|
||||
false,
|
||||
|
@ -862,13 +869,14 @@ impl XRSessionMethods<crate::DomTypeHolder> for XRSession {
|
|||
}
|
||||
}
|
||||
if ty == XRReferenceSpaceType::Bounded_floor {
|
||||
let space = XRBoundedReferenceSpace::new(&self.global(), self, can_gc);
|
||||
let space =
|
||||
XRBoundedReferenceSpace::new(self.global().as_window(), self, can_gc);
|
||||
self.reference_spaces
|
||||
.borrow_mut()
|
||||
.push(Dom::from_ref(space.reference_space()));
|
||||
p.resolve_native(&space, can_gc);
|
||||
} else {
|
||||
let space = XRReferenceSpace::new(&self.global(), self, ty, can_gc);
|
||||
let space = XRReferenceSpace::new(self.global().as_window(), self, ty, can_gc);
|
||||
self.reference_spaces
|
||||
.borrow_mut()
|
||||
.push(Dom::from_ref(&*space));
|
||||
|
|
|
@ -10,11 +10,10 @@ use crate::dom::bindings::codegen::Bindings::EventBinding::Event_Binding::EventM
|
|||
use crate::dom::bindings::codegen::Bindings::XRSessionEventBinding::{self, XRSessionEventMethods};
|
||||
use crate::dom::bindings::error::Fallible;
|
||||
use crate::dom::bindings::inheritance::Castable;
|
||||
use crate::dom::bindings::reflector::{DomGlobal, reflect_dom_object_with_proto};
|
||||
use crate::dom::bindings::reflector::reflect_dom_object_with_proto;
|
||||
use crate::dom::bindings::root::{Dom, DomRoot};
|
||||
use crate::dom::bindings::str::DOMString;
|
||||
use crate::dom::event::Event;
|
||||
use crate::dom::globalscope::GlobalScope;
|
||||
use crate::dom::window::Window;
|
||||
use crate::dom::xrsession::XRSession;
|
||||
use crate::script_runtime::CanGc;
|
||||
|
@ -35,18 +34,18 @@ impl XRSessionEvent {
|
|||
}
|
||||
|
||||
pub(crate) fn new(
|
||||
global: &GlobalScope,
|
||||
window: &Window,
|
||||
type_: Atom,
|
||||
bubbles: bool,
|
||||
cancelable: bool,
|
||||
session: &XRSession,
|
||||
can_gc: CanGc,
|
||||
) -> DomRoot<XRSessionEvent> {
|
||||
Self::new_with_proto(global, None, type_, bubbles, cancelable, session, can_gc)
|
||||
Self::new_with_proto(window, None, type_, bubbles, cancelable, session, can_gc)
|
||||
}
|
||||
|
||||
fn new_with_proto(
|
||||
global: &GlobalScope,
|
||||
window: &Window,
|
||||
proto: Option<HandleObject>,
|
||||
type_: Atom,
|
||||
bubbles: bool,
|
||||
|
@ -56,7 +55,7 @@ impl XRSessionEvent {
|
|||
) -> DomRoot<XRSessionEvent> {
|
||||
let trackevent = reflect_dom_object_with_proto(
|
||||
Box::new(XRSessionEvent::new_inherited(session)),
|
||||
global,
|
||||
window,
|
||||
proto,
|
||||
can_gc,
|
||||
);
|
||||
|
@ -78,7 +77,7 @@ impl XRSessionEventMethods<crate::DomTypeHolder> for XRSessionEvent {
|
|||
init: &XRSessionEventBinding::XRSessionEventInit,
|
||||
) -> Fallible<DomRoot<XRSessionEvent>> {
|
||||
Ok(XRSessionEvent::new_with_proto(
|
||||
&window.global(),
|
||||
window,
|
||||
proto,
|
||||
Atom::from(type_),
|
||||
init.parent.bubbles,
|
||||
|
|
|
@ -15,6 +15,7 @@ use crate::dom::bindings::num::Finite;
|
|||
use crate::dom::bindings::reflector::{Reflector, reflect_dom_object};
|
||||
use crate::dom::bindings::root::{Dom, DomRoot};
|
||||
use crate::dom::globalscope::GlobalScope;
|
||||
use crate::dom::window::Window;
|
||||
use crate::dom::xrrigidtransform::XRRigidTransform;
|
||||
use crate::dom::xrsession::{BaseSpace, BaseTransform, XRSession, cast_transform};
|
||||
use crate::script_runtime::{CanGc, JSContext};
|
||||
|
@ -55,7 +56,7 @@ impl XRView {
|
|||
}
|
||||
|
||||
pub(crate) fn new<V: Copy>(
|
||||
global: &GlobalScope,
|
||||
window: &Window,
|
||||
session: &XRSession,
|
||||
view: &View<V>,
|
||||
eye: XREye,
|
||||
|
@ -64,7 +65,7 @@ impl XRView {
|
|||
can_gc: CanGc,
|
||||
) -> DomRoot<XRView> {
|
||||
let transform: RigidTransform3D<f32, V, BaseSpace> = view.transform.then(to_base);
|
||||
let transform = XRRigidTransform::new(global, cast_transform(transform), can_gc);
|
||||
let transform = XRRigidTransform::new(window, cast_transform(transform), can_gc);
|
||||
|
||||
reflect_dom_object(
|
||||
Box::new(XRView::new_inherited(
|
||||
|
@ -74,7 +75,7 @@ impl XRView {
|
|||
viewport_index,
|
||||
view.cast_unit(),
|
||||
)),
|
||||
global,
|
||||
window,
|
||||
can_gc,
|
||||
)
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@ use crate::dom::bindings::codegen::Bindings::XRViewerPoseBinding::XRViewerPoseMe
|
|||
use crate::dom::bindings::reflector::reflect_dom_object;
|
||||
use crate::dom::bindings::root::DomRoot;
|
||||
use crate::dom::globalscope::GlobalScope;
|
||||
use crate::dom::window::Window;
|
||||
use crate::dom::xrpose::XRPose;
|
||||
use crate::dom::xrrigidtransform::XRRigidTransform;
|
||||
use crate::dom::xrsession::{BaseSpace, BaseTransform, XRSession, cast_transform};
|
||||
|
@ -39,17 +40,17 @@ impl XRViewerPose {
|
|||
|
||||
#[allow(unsafe_code)]
|
||||
pub(crate) fn new(
|
||||
global: &GlobalScope,
|
||||
window: &Window,
|
||||
session: &XRSession,
|
||||
to_base: BaseTransform,
|
||||
viewer_pose: &ViewerPose,
|
||||
can_gc: CanGc,
|
||||
) -> DomRoot<XRViewerPose> {
|
||||
let _ac = enter_realm(global);
|
||||
let _ac = enter_realm(window);
|
||||
rooted_vec!(let mut views);
|
||||
match &viewer_pose.views {
|
||||
Views::Inline => views.push(XRView::new(
|
||||
global,
|
||||
window,
|
||||
session,
|
||||
&session.inline_view(),
|
||||
XREye::None,
|
||||
|
@ -58,7 +59,7 @@ impl XRViewerPose {
|
|||
can_gc,
|
||||
)),
|
||||
Views::Mono(view) => views.push(XRView::new(
|
||||
global,
|
||||
window,
|
||||
session,
|
||||
view,
|
||||
XREye::None,
|
||||
|
@ -68,7 +69,7 @@ impl XRViewerPose {
|
|||
)),
|
||||
Views::Stereo(left, right) => {
|
||||
views.push(XRView::new(
|
||||
global,
|
||||
window,
|
||||
session,
|
||||
left,
|
||||
XREye::Left,
|
||||
|
@ -77,7 +78,7 @@ impl XRViewerPose {
|
|||
can_gc,
|
||||
));
|
||||
views.push(XRView::new(
|
||||
global,
|
||||
window,
|
||||
session,
|
||||
right,
|
||||
XREye::Right,
|
||||
|
@ -88,7 +89,7 @@ impl XRViewerPose {
|
|||
},
|
||||
Views::StereoCapture(left, right, third_eye) => {
|
||||
views.push(XRView::new(
|
||||
global,
|
||||
window,
|
||||
session,
|
||||
left,
|
||||
XREye::Left,
|
||||
|
@ -97,7 +98,7 @@ impl XRViewerPose {
|
|||
can_gc,
|
||||
));
|
||||
views.push(XRView::new(
|
||||
global,
|
||||
window,
|
||||
session,
|
||||
right,
|
||||
XREye::Right,
|
||||
|
@ -106,7 +107,7 @@ impl XRViewerPose {
|
|||
can_gc,
|
||||
));
|
||||
views.push(XRView::new(
|
||||
global,
|
||||
window,
|
||||
session,
|
||||
third_eye,
|
||||
XREye::None,
|
||||
|
@ -117,7 +118,7 @@ impl XRViewerPose {
|
|||
},
|
||||
Views::Cubemap(front, left, right, top, bottom, back) => {
|
||||
views.push(XRView::new(
|
||||
global,
|
||||
window,
|
||||
session,
|
||||
front,
|
||||
XREye::None,
|
||||
|
@ -126,7 +127,7 @@ impl XRViewerPose {
|
|||
can_gc,
|
||||
));
|
||||
views.push(XRView::new(
|
||||
global,
|
||||
window,
|
||||
session,
|
||||
left,
|
||||
XREye::None,
|
||||
|
@ -135,7 +136,7 @@ impl XRViewerPose {
|
|||
can_gc,
|
||||
));
|
||||
views.push(XRView::new(
|
||||
global,
|
||||
window,
|
||||
session,
|
||||
right,
|
||||
XREye::None,
|
||||
|
@ -144,7 +145,7 @@ impl XRViewerPose {
|
|||
can_gc,
|
||||
));
|
||||
views.push(XRView::new(
|
||||
global,
|
||||
window,
|
||||
session,
|
||||
top,
|
||||
XREye::None,
|
||||
|
@ -153,7 +154,7 @@ impl XRViewerPose {
|
|||
can_gc,
|
||||
));
|
||||
views.push(XRView::new(
|
||||
global,
|
||||
window,
|
||||
session,
|
||||
bottom,
|
||||
XREye::None,
|
||||
|
@ -162,7 +163,7 @@ impl XRViewerPose {
|
|||
can_gc,
|
||||
));
|
||||
views.push(XRView::new(
|
||||
global,
|
||||
window,
|
||||
session,
|
||||
back,
|
||||
XREye::None,
|
||||
|
@ -174,10 +175,10 @@ impl XRViewerPose {
|
|||
};
|
||||
let transform: RigidTransform3D<f32, Viewer, BaseSpace> =
|
||||
viewer_pose.transform.then(&to_base);
|
||||
let transform = XRRigidTransform::new(global, cast_transform(transform), can_gc);
|
||||
let transform = XRRigidTransform::new(window, cast_transform(transform), can_gc);
|
||||
let pose = reflect_dom_object(
|
||||
Box::new(XRViewerPose::new_inherited(&transform)),
|
||||
global,
|
||||
window,
|
||||
can_gc,
|
||||
);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue