Skip to main content

script/dom/testing/
layoutresult.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/. */
4use dom_struct::dom_struct;
5use js::gc::MutableHandleValue;
6use script_bindings::domstring::DOMString;
7use script_bindings::reflector::{Reflector, reflect_dom_object};
8
9use crate::dom::bindings::codegen::Bindings::ServoTestUtilsBinding::LayoutResultMethods;
10use crate::dom::bindings::import::base::SafeJSContext;
11use crate::dom::bindings::root::DomRoot;
12use crate::dom::bindings::utils::to_frozen_array;
13use crate::dom::globalscope::GlobalScope;
14use crate::script_runtime::CanGc;
15
16#[dom_struct]
17pub(crate) struct LayoutResult {
18    reflector_: Reflector,
19    phases: Vec<DOMString>,
20    rebuilt_fragment_count: u32,
21    restyle_fragment_count: u32,
22    only_descendants_changed_count: u32,
23}
24
25impl LayoutResult {
26    pub(crate) fn new_inherited(
27        phases: Vec<DOMString>,
28        rebuilt_fragment_count: u32,
29        restyle_fragment_count: u32,
30        only_descendants_changed_count: u32,
31    ) -> Self {
32        Self {
33            reflector_: Reflector::new(),
34            phases,
35            rebuilt_fragment_count,
36            restyle_fragment_count,
37            only_descendants_changed_count,
38        }
39    }
40
41    pub(crate) fn new(
42        global: &GlobalScope,
43        phases: Vec<DOMString>,
44        rebuilt_fragment_count: u32,
45        restyle_fragment_count: u32,
46        only_descendants_changed_count: u32,
47        can_gc: CanGc,
48    ) -> DomRoot<Self> {
49        reflect_dom_object(
50            Box::new(Self::new_inherited(
51                phases,
52                rebuilt_fragment_count,
53                restyle_fragment_count,
54                only_descendants_changed_count,
55            )),
56            global,
57            can_gc,
58        )
59    }
60}
61
62impl LayoutResultMethods<crate::DomTypeHolder> for LayoutResult {
63    fn Phases(&self, cx: SafeJSContext, can_gc: CanGc, return_value: MutableHandleValue) {
64        to_frozen_array(&self.phases, cx, return_value, can_gc);
65    }
66
67    fn RebuiltFragmentCount(&self) -> u32 {
68        self.rebuilt_fragment_count
69    }
70
71    fn RestyleFragmentCount(&self) -> u32 {
72        self.restyle_fragment_count
73    }
74
75    fn OnlyDescendantsChangedCount(&self) -> u32 {
76        self.only_descendants_changed_count
77    }
78}