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::{EntryType, PerformanceEntry};
11use crate::dom::bindings::codegen::Bindings::PerformancePaintTimingBinding::PerformancePaintTimingMethods;
12use crate::dom::bindings::reflector::reflect_dom_object;
13use crate::dom::bindings::root::DomRoot;
14use crate::dom::bindings::str::DOMString;
15use crate::dom::globalscope::GlobalScope;
16use crate::script_runtime::CanGc;
17
18#[dom_struct]
19pub(crate) struct PerformancePaintTiming {
20    entry: PerformanceEntry,
21}
22
23impl PerformancePaintTiming {
24    fn new_inherited(
25        metric_type: ProgressiveWebMetricType,
26        start_time: CrossProcessInstant,
27    ) -> PerformancePaintTiming {
28        let name = match metric_type {
29            ProgressiveWebMetricType::FirstPaint => DOMString::from("first-paint"),
30            ProgressiveWebMetricType::FirstContentfulPaint => {
31                DOMString::from("first-contentful-paint")
32            },
33            _ => DOMString::from(""),
34        };
35        PerformancePaintTiming {
36            entry: PerformanceEntry::new_inherited(
37                name,
38                EntryType::Paint,
39                Some(start_time),
40                Duration::ZERO,
41            ),
42        }
43    }
44
45    #[cfg_attr(crown, expect(crown::unrooted_must_root))]
46    pub(crate) fn new(
47        global: &GlobalScope,
48        metric_type: ProgressiveWebMetricType,
49        start_time: CrossProcessInstant,
50        can_gc: CanGc,
51    ) -> DomRoot<PerformancePaintTiming> {
52        let entry = PerformancePaintTiming::new_inherited(metric_type, start_time);
53        reflect_dom_object(Box::new(entry), global, can_gc)
54    }
55}
56
57impl PerformancePaintTimingMethods<crate::DomTypeHolder> for PerformancePaintTiming {}