Skip to main content

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;
11use uuid::Uuid;
12
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::html::htmlslotelement::SlottableData;
19use crate::dom::html::internals::elementinternals::ElementInternals;
20use crate::dom::intersectionobserver::IntersectionObserverRegistration;
21use crate::dom::mutationobserver::RegisteredObserver;
22use crate::dom::nodelist::NodeList;
23use crate::dom::range::Range;
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    #[no_trace]
42    pub(crate) unique_id: Option<Uuid>,
43
44    pub(crate) slottable_data: SlottableData,
45
46    /// The live list of children return by .childNodes.
47    pub(crate) child_list: MutNullableDom<NodeList>,
48
49    /// Whether this node represents a certain implemented pseudo-element.
50    /// An implemented pseudo-element is a real element within a UA shadow tree
51    /// that will match a certain pseudo-element selector.
52    /// An example of this is the element matching the `::placeholder` selector.
53    #[no_trace]
54    pub(crate) implemented_pseudo_element: Option<PseudoElement>,
55}
56
57#[derive(Default, JSTraceable, MallocSizeOf)]
58#[cfg_attr(crown, crown::unrooted_must_root_lint::must_root)]
59pub(crate) struct ElementRareData {
60    /// <https://dom.spec.whatwg.org/#dom-element-shadowroot>
61    /// The ShadowRoot this element is host of.
62    pub(crate) shadow_root: Option<Dom<ShadowRoot>>,
63    /// <https://html.spec.whatwg.org/multipage/#custom-element-reaction-queue>
64    pub(crate) custom_element_reaction_queue: Vec<CustomElementReaction>,
65    /// <https://dom.spec.whatwg.org/#concept-element-custom-element-definition>
66    #[conditional_malloc_size_of]
67    pub(crate) custom_element_definition: Option<Rc<CustomElementDefinition>>,
68    /// <https://dom.spec.whatwg.org/#concept-element-custom-element-state>
69    pub(crate) custom_element_state: CustomElementState,
70    /// <https://dom.spec.whatwg.org/#dom-element-customelementregistry>
71    pub(crate) custom_element_registry: Option<Dom<CustomElementRegistry>>,
72    /// The "name" content attribute; not used as frequently as id, but used
73    /// in named getter loops so it's worth looking up quickly when present
74    #[no_trace]
75    pub(crate) name_attribute: Option<Atom>,
76    /// The client rect reported by layout.
77    #[no_trace]
78    pub(crate) client_rect: Option<LayoutValue<Rect<i32, CSSPixel>>>,
79    /// <https://html.spec.whatwg.org/multipage#elementinternals>
80    pub(crate) element_internals: Option<Dom<ElementInternals>>,
81
82    /// <https://w3c.github.io/IntersectionObserver/#element-private-slots>
83    /// > Element objects have an internal [[RegisteredIntersectionObservers]] slot,
84    /// > which is initialized to an empty list. This list holds IntersectionObserverRegistration records, which have:
85    pub(crate) registered_intersection_observers: Vec<IntersectionObserverRegistration>,
86    pub(crate) cryptographic_nonce: String,
87
88    /// <https://drafts.csswg.org/css-shadow-parts/#element-forwarded-part-name-list>
89    pub(crate) forwarded_part_names: Vec<(String, String)>,
90
91    /// <https://drafts.csswg.org/css-shadow-parts/#dom-element-part>
92    pub(crate) part: MutNullableDom<DOMTokenList>,
93
94    /// <https://w3c.github.io/selection-api/#definition>
95    /// > This one selection must be shared by all the content of the document (though not by nested documents),
96    /// > including any editing hosts in the document.
97    pub(crate) contenteditable_selection_range: MutNullableDom<Range>,
98
99    /// Whether this element had duplicate attributes during tokenization.
100    /// Used for CSP nonce validation (step 3 of "is element nonceable").
101    pub(crate) had_duplicate_attributes: bool,
102
103    /// <https://html.spec.whatwg.org/multipage/#previously-focused-element>
104    pub(crate) previously_focused_element: MutNullableDom<Element>,
105}