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