script/dom/
paintsize.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
5use dom_struct::dom_struct;
6use euclid::Size2D;
7use style_traits::CSSPixel;
8
9use crate::dom::bindings::codegen::Bindings::PaintSizeBinding::PaintSizeMethods;
10use crate::dom::bindings::num::Finite;
11use crate::dom::bindings::reflector::{Reflector, reflect_dom_object};
12use crate::dom::bindings::root::DomRoot;
13use crate::dom::paintworkletglobalscope::PaintWorkletGlobalScope;
14use crate::script_runtime::CanGc;
15
16#[dom_struct]
17pub(crate) struct PaintSize {
18    reflector: Reflector,
19    width: Finite<f64>,
20    height: Finite<f64>,
21}
22
23impl PaintSize {
24    fn new_inherited(size: Size2D<f32, CSSPixel>) -> PaintSize {
25        PaintSize {
26            reflector: Reflector::new(),
27            width: Finite::wrap(size.width as f64),
28            height: Finite::wrap(size.height as f64),
29        }
30    }
31
32    pub(crate) fn new(
33        global: &PaintWorkletGlobalScope,
34        size: Size2D<f32, CSSPixel>,
35        can_gc: CanGc,
36    ) -> DomRoot<PaintSize> {
37        reflect_dom_object(Box::new(PaintSize::new_inherited(size)), global, can_gc)
38    }
39}
40
41impl PaintSizeMethods<crate::DomTypeHolder> for PaintSize {
42    /// <https://drafts.css-houdini.org/css-paint-api/#paintsize>
43    fn Width(&self) -> Finite<f64> {
44        self.width
45    }
46
47    /// <https://drafts.css-houdini.org/css-paint-api/#paintsize>
48    fn Height(&self) -> Finite<f64> {
49        self.height
50    }
51}