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