script/dom/wakelock/
wakelocksentinel.rs1use std::cell::Cell;
6
7use dom_struct::dom_struct;
8
9use crate::dom::bindings::codegen::Bindings::WakeLockBinding::{
10 WakeLockSentinelMethods, WakeLockType,
11};
12use crate::dom::bindings::reflector::reflect_dom_object_with_cx;
13use crate::dom::bindings::root::DomRoot;
14use crate::dom::eventtarget::EventTarget;
15use crate::dom::globalscope::GlobalScope;
16
17#[dom_struct]
19pub(crate) struct WakeLockSentinel {
20 eventtarget: EventTarget,
21 released: Cell<bool>,
22 type_: WakeLockType,
23}
24
25impl WakeLockSentinel {
26 pub(crate) fn new_inherited(type_: WakeLockType) -> Self {
27 Self {
28 eventtarget: EventTarget::new_inherited(),
29 released: Cell::new(false),
30 type_,
31 }
32 }
33
34 pub(crate) fn new(
35 cx: &mut js::context::JSContext,
36 global: &GlobalScope,
37 type_: WakeLockType,
38 ) -> DomRoot<Self> {
39 reflect_dom_object_with_cx(Box::new(Self::new_inherited(type_)), global, cx)
40 }
41}
42
43impl WakeLockSentinelMethods<crate::DomTypeHolder> for WakeLockSentinel {
44 fn Released(&self) -> bool {
46 self.released.get()
47 }
48
49 fn Type(&self) -> WakeLockType {
51 self.type_
52 }
53}