paint_api/
largest_contentful_paint_candidate.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
5//! Definitions for Largest Contentful Paint Candidate and Largest Contentful Paint.
6
7use base::cross_process_instant::CrossProcessInstant;
8use serde::{Deserialize, Serialize};
9
10/// Largest Contentful Paint Candidate, include image and block-level element containing text
11#[derive(Clone, Copy, Debug, Deserialize, Serialize)]
12pub struct LCPCandidate {
13    /// The identity of the element.
14    pub id: LCPCandidateID,
15    /// The size of the visual area
16    pub area: usize,
17}
18
19impl LCPCandidate {
20    pub fn new(id: LCPCandidateID, area: usize) -> Self {
21        Self { id, area }
22    }
23}
24
25#[derive(Clone, Copy, Debug, Deserialize, Serialize)]
26pub struct LCPCandidateID(pub usize);
27
28#[derive(Clone, Copy, Debug)]
29pub struct LargestContentfulPaint {
30    pub id: LCPCandidateID,
31    pub area: usize,
32    pub paint_time: CrossProcessInstant,
33}
34
35impl LargestContentfulPaint {
36    pub fn from(lcp_candidate: LCPCandidate, paint_time: CrossProcessInstant) -> Self {
37        Self {
38            id: lcp_candidate.id,
39            area: lcp_candidate.area,
40            paint_time,
41        }
42    }
43}