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