script/dom/
performancepainttiming.rs1use base::cross_process_instant::CrossProcessInstant;
6use dom_struct::dom_struct;
7use script_traits::ProgressiveWebMetricType;
8use time::Duration;
9
10use crate::dom::bindings::reflector::reflect_dom_object;
11use crate::dom::bindings::root::DomRoot;
12use crate::dom::bindings::str::DOMString;
13use crate::dom::globalscope::GlobalScope;
14use crate::dom::performanceentry::PerformanceEntry;
15use crate::script_runtime::CanGc;
16
17#[dom_struct]
18pub(crate) struct PerformancePaintTiming {
19 entry: PerformanceEntry,
20}
21
22impl PerformancePaintTiming {
23 fn new_inherited(
24 metric_type: ProgressiveWebMetricType,
25 start_time: CrossProcessInstant,
26 ) -> PerformancePaintTiming {
27 let name = match metric_type {
28 ProgressiveWebMetricType::FirstPaint => DOMString::from("first-paint"),
29 ProgressiveWebMetricType::FirstContentfulPaint => {
30 DOMString::from("first-contentful-paint")
31 },
32 _ => DOMString::from(""),
33 };
34 PerformancePaintTiming {
35 entry: PerformanceEntry::new_inherited(
36 name,
37 DOMString::from("paint"),
38 Some(start_time),
39 Duration::ZERO,
40 ),
41 }
42 }
43
44 #[cfg_attr(crown, allow(crown::unrooted_must_root))]
45 pub(crate) fn new(
46 global: &GlobalScope,
47 metric_type: ProgressiveWebMetricType,
48 start_time: CrossProcessInstant,
49 can_gc: CanGc,
50 ) -> DomRoot<PerformancePaintTiming> {
51 let entry = PerformancePaintTiming::new_inherited(metric_type, start_time);
52 reflect_dom_object(Box::new(entry), global, can_gc)
53 }
54}