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