compositing_traits/
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#[derive(Clone, Copy, Debug, Deserialize, Serialize)]
11pub enum LargestContentfulPaintType {
12    BackgroundImage,
13    Image,
14}
15
16/// Largest Contentful Paint Candidate, include image and block-level element containing text
17#[derive(Clone, Copy, Debug, Deserialize, Serialize)]
18pub struct LCPCandidate {
19    /// The identity of the element.
20    pub id: LCPCandidateID,
21    /// The size of the visual area
22    pub area: usize,
23    /// The type of LCP candidate
24    pub lcp_type: LargestContentfulPaintType,
25}
26
27impl LCPCandidate {
28    pub fn new(id: LCPCandidateID, lcp_type: LargestContentfulPaintType, area: usize) -> Self {
29        Self { id, lcp_type, area }
30    }
31}
32
33#[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)]
34pub struct LCPCandidateID(pub usize);
35
36#[derive(Clone, Copy, Debug)]
37pub struct LargestContentfulPaint {
38    pub id: LCPCandidateID,
39    pub area: usize,
40    pub lcp_type: LargestContentfulPaintType,
41    pub paint_time: CrossProcessInstant,
42}
43
44impl LargestContentfulPaint {
45    pub fn from(lcp_candidate: LCPCandidate, paint_time: CrossProcessInstant) -> Self {
46        Self {
47            id: lcp_candidate.id,
48            lcp_type: lcp_candidate.lcp_type,
49            area: lcp_candidate.area,
50            paint_time,
51        }
52    }
53}