script/dom/raredata.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 std::rc::Rc;
6
7use euclid::Rect;
8use style::selector_parser::PseudoElement;
9use style_traits::CSSPixel;
10use stylo_atoms::Atom;
11
12use crate::dom::bindings::root::{Dom, MutNullableDom};
13use crate::dom::customelementregistry::{
14 CustomElementDefinition, CustomElementReaction, CustomElementRegistry, CustomElementState,
15};
16use crate::dom::domtokenlist::DOMTokenList;
17use crate::dom::elementinternals::ElementInternals;
18use crate::dom::html::htmlslotelement::SlottableData;
19use crate::dom::intersectionobserver::IntersectionObserverRegistration;
20use crate::dom::mutationobserver::RegisteredObserver;
21use crate::dom::node::UniqueId;
22use crate::dom::nodelist::NodeList;
23use crate::dom::range::WeakRangeVec;
24use crate::dom::shadowroot::ShadowRoot;
25use crate::dom::window::LayoutValue;
26
27// XXX(ferjm) Ideally merge NodeRareData and ElementRareData so they share
28// storage.
29
30#[derive(Default, JSTraceable, MallocSizeOf)]
31#[cfg_attr(crown, crown::unrooted_must_root_lint::must_root)]
32pub(crate) struct NodeRareData {
33 /// The shadow root the node belongs to.
34 /// This is None if the node is not in a shadow tree or
35 /// if it is a ShadowRoot.
36 pub(crate) containing_shadow_root: Option<Dom<ShadowRoot>>,
37 /// Registered observers for this node.
38 pub(crate) mutation_observers: Vec<RegisteredObserver>,
39 /// Lazily-generated Unique Id for this node.
40 pub(crate) unique_id: Option<UniqueId>,
41
42 pub(crate) slottable_data: SlottableData,
43
44 /// A vector of weak references to Range instances of which the start
45 /// or end containers are this node. No range should ever be found
46 /// twice in this vector, even if both the start and end containers
47 /// are this node.
48 pub(crate) ranges: WeakRangeVec,
49
50 /// The live list of children return by .childNodes.
51 pub(crate) child_list: MutNullableDom<NodeList>,
52
53 /// Whether this node represents a certain implemented pseudo-element.
54 /// An implemented pseudo-element is a real element within a UA shadow tree
55 /// that will match a certain pseudo-element selector.
56 /// An example of this is the element matching the `::placeholder` selector.
57 #[no_trace]
58 pub(crate) implemented_pseudo_element: Option<PseudoElement>,
59}
60
61#[derive(Default, JSTraceable, MallocSizeOf)]
62#[cfg_attr(crown, crown::unrooted_must_root_lint::must_root)]
63pub(crate) struct ElementRareData {
64 /// <https://dom.spec.whatwg.org/#dom-element-shadowroot>
65 /// The ShadowRoot this element is host of.
66 pub(crate) shadow_root: Option<Dom<ShadowRoot>>,
67 /// <https://html.spec.whatwg.org/multipage/#custom-element-reaction-queue>
68 pub(crate) custom_element_reaction_queue: Vec<CustomElementReaction>,
69 /// <https://dom.spec.whatwg.org/#concept-element-custom-element-definition>
70 #[conditional_malloc_size_of]
71 pub(crate) custom_element_definition: Option<Rc<CustomElementDefinition>>,
72 /// <https://dom.spec.whatwg.org/#concept-element-custom-element-state>
73 pub(crate) custom_element_state: CustomElementState,
74 /// <https://dom.spec.whatwg.org/#dom-element-customelementregistry>
75 pub(crate) custom_element_registry: Option<Dom<CustomElementRegistry>>,
76 /// The "name" content attribute; not used as frequently as id, but used
77 /// in named getter loops so it's worth looking up quickly when present
78 #[no_trace]
79 pub(crate) name_attribute: Option<Atom>,
80 /// The client rect reported by layout.
81 #[no_trace]
82 pub(crate) client_rect: Option<LayoutValue<Rect<i32, CSSPixel>>>,
83 /// <https://html.spec.whatwg.org/multipage#elementinternals>
84 pub(crate) element_internals: Option<Dom<ElementInternals>>,
85
86 /// <https://w3c.github.io/IntersectionObserver/#element-private-slots>
87 /// > Element objects have an internal [[RegisteredIntersectionObservers]] slot,
88 /// > which is initialized to an empty list. This list holds IntersectionObserverRegistration records, which have:
89 pub(crate) registered_intersection_observers: Vec<IntersectionObserverRegistration>,
90 pub(crate) cryptographic_nonce: String,
91
92 /// <https://drafts.csswg.org/css-shadow-parts/#element-forwarded-part-name-list>
93 pub(crate) forwarded_part_names: Vec<(String, String)>,
94
95 /// <https://drafts.csswg.org/css-shadow-parts/#dom-element-part>
96 pub(crate) part: MutNullableDom<DOMTokenList>,
97}