Skip to main content

layout_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 the largest-contentful-paint candidate.
6
7use malloc_size_of_derive::MallocSizeOf;
8use serde::{Deserialize, Serialize};
9use servo_base::cross_process_instant::CrossProcessInstant;
10use servo_base::id::LCPCandidateID;
11use servo_url::ServoUrl;
12use style::dom::OpaqueNode;
13
14/// A largest-contentful-paint candidate
15///
16/// <https://www.w3.org/TR/largest-contentful-paint/#largest-contentful-paint-candidate>
17#[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize)]
18pub struct LCPCandidate {
19    /// A unique identifier for this candidate.
20    pub id: LCPCandidateID,
21    /// The size of the visual area.
22    pub area: usize,
23    /// The candidate's request URL.
24    pub url: Option<ServoUrl>,
25    /// The time at which image finished loading, None for text candidates.
26    pub load_time: Option<CrossProcessInstant>,
27    /// The DOM node of the candidate's element, if any.
28    pub node: Option<OpaqueNode>,
29}
30
31impl LCPCandidate {
32    pub fn new(
33        id: LCPCandidateID,
34        area: usize,
35        url: Option<ServoUrl>,
36        node: Option<OpaqueNode>,
37        load_time: Option<CrossProcessInstant>,
38    ) -> Self {
39        Self {
40            id,
41            area,
42            url,
43            node,
44            load_time,
45        }
46    }
47}