script/dom/performance/
performancepainttiming.rs

1/* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4
5use base::cross_process_instant::CrossProcessInstant;
6use dom_struct::dom_struct;
7use script_traits::ProgressiveWebMetricType;
8use time::Duration;
9
10use super::performanceentry::PerformanceEntry;
11use crate::dom::bindings::reflector::reflect_dom_object;
12use crate::dom::bindings::root::DomRoot;
13use crate::dom::bindings::str::DOMString;
14use crate::dom::globalscope::GlobalScope;
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            ProgressiveWebMetricType::LargestContentfulPaint { .. } => {
33                DOMString::from("largest-contentful-paint")
34            },
35            _ => DOMString::from(""),
36        };
37        PerformancePaintTiming {
38            entry: PerformanceEntry::new_inherited(
39                name,
40                DOMString::from("paint"),
41                Some(start_time),
42                Duration::ZERO,
43            ),
44        }
45    }
46
47    #[cfg_attr(crown, allow(crown::unrooted_must_root))]
48    pub(crate) fn new(
49        global: &GlobalScope,
50        metric_type: ProgressiveWebMetricType,
51        start_time: CrossProcessInstant,
52        can_gc: CanGc,
53    ) -> DomRoot<PerformancePaintTiming> {
54        let entry = PerformancePaintTiming::new_inherited(metric_type, start_time);
55        reflect_dom_object(Box::new(entry), global, can_gc)
56    }
57}