script/dom/geolocation/
geolocationposition.rs1use dom_struct::dom_struct;
6use js::context::JSContext;
7use script_bindings::codegen::GenericBindings::GeolocationPositionBinding::GeolocationPositionMethods;
8use script_bindings::reflector::{Reflector, reflect_dom_object_with_cx};
9use script_bindings::root::{Dom, DomRoot};
10
11use crate::dom::bindings::codegen::DomTypeHolder::DomTypeHolder;
12use crate::dom::geolocationcoordinates::GeolocationCoordinates;
13use crate::dom::globalscope::GlobalScope;
14
15#[dom_struct]
16pub struct GeolocationPosition {
17 reflector_: Reflector,
18 coords: Dom<GeolocationCoordinates>,
19 timestamp: u64,
20}
21
22impl GeolocationPosition {
23 fn new_inherited(coords: &GeolocationCoordinates, timestamp: u64) -> Self {
24 GeolocationPosition {
25 reflector_: Reflector::new(),
26 coords: Dom::from_ref(coords),
27 timestamp,
28 }
29 }
30
31 #[expect(unused)]
32 pub(crate) fn new(
33 cx: &mut JSContext,
34 global: &GlobalScope,
35 coords: &GeolocationCoordinates,
36 timestamp: u64,
37 ) -> DomRoot<Self> {
38 reflect_dom_object_with_cx(Box::new(Self::new_inherited(coords, timestamp)), global, cx)
39 }
40}
41
42impl GeolocationPositionMethods<DomTypeHolder> for GeolocationPosition {
43 fn Coords(&self) -> DomRoot<GeolocationCoordinates> {
44 DomRoot::from_ref(&*self.coords.clone())
45 }
46
47 fn Timestamp(&self) -> u64 {
48 self.timestamp
49 }
50}