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}
24
25impl LayoutResult {
26    pub(crate) fn new_inherited(
27        phases: Vec<DOMString>,
28        rebuilt_fragment_count: u32,
29        restyle_fragment_count: u32,
30    ) -> Self {
31        Self {
32            reflector_: Reflector::new(),
33            phases,
34            rebuilt_fragment_count,
35            restyle_fragment_count,
36        }
37    }
38
39    pub(crate) fn new(
40        global: &GlobalScope,
41        phases: Vec<DOMString>,
42        rebuilt_fragment_count: u32,
43        restyle_fragment_count: u32,
44        can_gc: CanGc,
45    ) -> DomRoot<Self> {
46        reflect_dom_object(
47            Box::new(Self::new_inherited(
48                phases,
49                rebuilt_fragment_count,
50                restyle_fragment_count,
51            )),
52            global,
53            can_gc,
54        )
55    }
56}
57
58impl LayoutResultMethods<crate::DomTypeHolder> for LayoutResult {
59    fn Phases(&self, cx: SafeJSContext, can_gc: CanGc, return_value: MutableHandleValue) {
60        to_frozen_array(&self.phases, cx, return_value, can_gc);
61    }
62
63    fn RebuiltFragmentCount(&self) -> u32 {
64        self.rebuilt_fragment_count
65    }
66
67    fn RestyleFragmentCount(&self) -> u32 {
68        self.restyle_fragment_count
69    }
70}