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};
9use servo_url::ServoUrl;
10
11/// Largest Contentful Paint Candidate, include image and block-level element containing text
12#[derive(Clone, Debug, Deserialize, Serialize)]
13pub struct LCPCandidate {
14    /// The identity of the element.
15    pub id: LCPCandidateID,
16    /// The size of the visual area
17    pub area: usize,
18    /// The candidate's request URL
19    pub url: Option<ServoUrl>,
20}
21
22impl LCPCandidate {
23    pub fn new(id: LCPCandidateID, area: usize, url: Option<ServoUrl>) -> Self {
24        Self { id, area, url }
25    }
26}
27
28#[derive(Clone, Copy, Debug, Deserialize, Serialize)]
29pub struct LCPCandidateID(pub usize);
30
31#[derive(Clone, Debug)]
32pub struct LargestContentfulPaint {
33    pub id: LCPCandidateID,
34    pub area: usize,
35    pub paint_time: CrossProcessInstant,
36    pub url: Option<ServoUrl>,
37}
38
39impl LargestContentfulPaint {
40    pub fn from(lcp_candidate: LCPCandidate, paint_time: CrossProcessInstant) -> Self {
41        Self {
42            id: lcp_candidate.id,
43            area: lcp_candidate.area,
44            paint_time,
45            url: lcp_candidate.url,
46        }
47    }
48}