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