use std::ops::Deref;
use base::cross_process_instant::CrossProcessInstant;
use dom_struct::dom_struct;
use time_03::Duration;
use crate::dom::bindings::codegen::Bindings::DocumentBinding::DocumentVisibilityState;
use crate::dom::bindings::codegen::Bindings::PerformanceEntryBinding::PerformanceEntryMethods;
use crate::dom::bindings::codegen::Bindings::VisibilityStateEntryBinding::VisibilityStateEntryMethods;
use crate::dom::bindings::num::Finite;
use crate::dom::bindings::reflector::reflect_dom_object;
use crate::dom::bindings::root::DomRoot;
use crate::dom::bindings::str::DOMString;
use crate::dom::globalscope::GlobalScope;
use crate::dom::performanceentry::PerformanceEntry;
#[dom_struct]
pub struct VisibilityStateEntry {
entry: PerformanceEntry,
}
impl VisibilityStateEntry {
#[allow(crown::unrooted_must_root)]
fn new_inherited(
state: DocumentVisibilityState,
timestamp: CrossProcessInstant,
) -> VisibilityStateEntry {
let name = match state {
DocumentVisibilityState::Visible => DOMString::from("visible"),
DocumentVisibilityState::Hidden => DOMString::from("hidden"),
};
VisibilityStateEntry {
entry: PerformanceEntry::new_inherited(
name,
DOMString::from("visibility-state"),
Some(timestamp),
Duration::ZERO,
),
}
}
pub fn new(
global: &GlobalScope,
state: DocumentVisibilityState,
timestamp: CrossProcessInstant,
) -> DomRoot<VisibilityStateEntry> {
reflect_dom_object(
Box::new(VisibilityStateEntry::new_inherited(state, timestamp)),
global,
)
}
}
impl VisibilityStateEntryMethods<crate::DomTypeHolder> for VisibilityStateEntry {
fn Name(&self) -> DOMString {
self.entry.Name()
}
fn EntryType(&self) -> DOMString {
self.entry.EntryType()
}
fn StartTime(&self) -> Finite<f64> {
self.entry.StartTime()
}
fn Duration(&self) -> u32 {
*self.entry.Duration().deref() as u32
}
}