script/dom/geolocation/
geolocationposition.rs1use dom_struct::dom_struct;
6use embedder_traits::GeolocationPositionData;
7use js::context::JSContext;
8use script_bindings::codegen::GenericBindings::GeolocationPositionBinding::GeolocationPositionMethods;
9use script_bindings::reflector::{Reflector, reflect_dom_object};
10use script_bindings::root::{Dom, DomRoot};
11
12use crate::dom::bindings::codegen::DomTypeHolder::DomTypeHolder;
13use crate::dom::geolocationcoordinates::GeolocationCoordinates;
14use crate::dom::globalscope::GlobalScope;
15
16#[dom_struct]
17pub struct GeolocationPosition {
18 reflector_: Reflector,
19 coords: Dom<GeolocationCoordinates>,
20 timestamp: u64,
21 is_high_accuracy: bool,
23}
24
25impl GeolocationPosition {
26 fn new_inherited(
27 coords: &GeolocationCoordinates,
28 timestamp: u64,
29 is_high_accuracy: bool,
30 ) -> Self {
31 GeolocationPosition {
32 reflector_: Reflector::new(),
33 coords: Dom::from_ref(coords),
34 timestamp,
35 is_high_accuracy,
36 }
37 }
38
39 pub(crate) fn from_position_data(
44 cx: &mut JSContext,
45 global: &GlobalScope,
46 data: &GeolocationPositionData,
47 timestamp: u64,
48 is_high_accuracy: bool,
49 ) -> Option<DomRoot<Self>> {
50 let coords = GeolocationCoordinates::from_position_data(cx, global, data)?;
52 Some(reflect_dom_object(
54 cx,
55 Box::new(Self::new_inherited(&coords, timestamp, is_high_accuracy)),
56 global,
57 ))
58 }
59
60 pub(crate) fn is_high_accuracy(&self) -> bool {
62 self.is_high_accuracy
63 }
64
65 pub(crate) fn timestamp(&self) -> u64 {
67 self.timestamp
68 }
69}
70
71impl GeolocationPositionMethods<DomTypeHolder> for GeolocationPosition {
72 fn Coords(&self) -> DomRoot<GeolocationCoordinates> {
73 DomRoot::from_ref(&*self.coords.clone())
74 }
75
76 fn Timestamp(&self) -> u64 {
77 self.timestamp
78 }
79}