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 html5ever::LocalName;
9use style::selector_parser::PseudoElement;
10use style_traits::CSSPixel;
11use stylo_atoms::Atom;
12use uuid::Uuid;
13
14use crate::dom::bindings::root::{Dom, MutNullableDom};
15use crate::dom::customelementregistry::{
16 CustomElementDefinition, CustomElementReaction, CustomElementRegistry, CustomElementState,
17};
18use crate::dom::domtokenlist::DOMTokenList;
19use crate::dom::html::htmlslotelement::SlottableData;
20use crate::dom::html::internals::elementinternals::ElementInternals;
21use crate::dom::intersectionobserver::IntersectionObserverRegistration;
22use crate::dom::mutationobserver::RegisteredObserver;
23use crate::dom::nodelist::NodeList;
24use crate::dom::range::Range;
25use crate::dom::shadowroot::shadowroot::ShadowRoot;
26use crate::dom::types::Element;
27use crate::dom::window::LayoutValue;
28
29// XXX(ferjm) Ideally merge NodeRareData and ElementRareData so they share
30// storage.
31
32#[derive(Default, JSTraceable, MallocSizeOf)]
33#[cfg_attr(crown, crown::unrooted_must_root_lint::must_root)]
34pub(crate) struct NodeRareData {
35 /// The shadow root the node belongs to.
36 /// This is None if the node is not in a shadow tree or
37 /// if it is a ShadowRoot.
38 pub(crate) containing_shadow_root: Option<Dom<ShadowRoot>>,
39 /// Registered observers for this node.
40 pub(crate) mutation_observers: Vec<RegisteredObserver>,
41 /// Lazily-generated Unique Id for this node.
42 #[no_trace]
43 pub(crate) unique_id: Option<Uuid>,
44
45 pub(crate) slottable_data: SlottableData,
46
47 /// The live list of children return by .childNodes.
48 pub(crate) child_list: MutNullableDom<NodeList>,
49
50 /// Whether this node represents a certain implemented pseudo-element.
51 /// An implemented pseudo-element is a real element within a UA shadow tree
52 /// that will match a certain pseudo-element selector.
53 /// An example of this is the element matching the `::placeholder` selector.
54 #[no_trace]
55 pub(crate) implemented_pseudo_element: Option<PseudoElement>,
56}
57
58#[derive(Default, JSTraceable, MallocSizeOf)]
59#[cfg_attr(crown, crown::unrooted_must_root_lint::must_root)]
60pub(crate) struct ElementRareData {
61 /// <https://dom.spec.whatwg.org/#dom-element-shadowroot>
62 /// The ShadowRoot this element is host of.
63 pub(crate) shadow_root: Option<Dom<ShadowRoot>>,
64 /// <https://html.spec.whatwg.org/multipage/#custom-element-reaction-queue>
65 pub(crate) custom_element_reaction_queue: Vec<CustomElementReaction>,
66 /// <https://dom.spec.whatwg.org/#concept-element-custom-element-definition>
67 #[conditional_malloc_size_of]
68 pub(crate) custom_element_definition: Option<Rc<CustomElementDefinition>>,
69 /// <https://dom.spec.whatwg.org/#concept-element-custom-element-state>
70 pub(crate) custom_element_state: CustomElementState,
71 /// <https://dom.spec.whatwg.org/#dom-element-customelementregistry>
72 pub(crate) custom_element_registry: Option<Dom<CustomElementRegistry>>,
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, CSSPixel>>>,
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
95 /// <https://w3c.github.io/selection-api/#definition>
96 /// > This one selection must be shared by all the content of the document (though not by nested documents),
97 /// > including any editing hosts in the document.
98 pub(crate) contenteditable_selection_range: MutNullableDom<Range>,
99
100 /// Whether this element had duplicate attributes during tokenization.
101 /// Used for CSP nonce validation (step 3 of "is element nonceable").
102 pub(crate) had_duplicate_attributes: bool,
103
104 /// <https://html.spec.whatwg.org/multipage/#previously-focused-element>
105 pub(crate) previously_focused_element: MutNullableDom<Element>,
106
107 /// <https://dom.spec.whatwg.org/#concept-element-is-value>
108 ///
109 /// Only ever set on customized built-in elements, which are very rare.
110 #[no_trace]
111 pub(crate) is_value: Option<LocalName>,
112}