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 html5ever::LocalName;
9use rustc_hash::FxBuildHasher;
10use script_bindings::cell::DomRefCell;
11use style::selector_parser::PseudoElement;
12use style_traits::CSSPixel;
13use stylo_atoms::Atom;
14use uuid::Uuid;
15
16use crate::dom::bindings::root::{Dom, MutNullableDom};
17use crate::dom::bindings::trace::HashMapTracedValues;
18use crate::dom::closewatcher::internalclosewatcher::InternalCloseWatcher;
19use crate::dom::customelementregistry::{
20    CustomElementDefinition, CustomElementReaction, CustomElementRegistry, CustomElementState,
21};
22use crate::dom::domtokenlist::DOMTokenList;
23use crate::dom::html::htmlelement::{HTMLElement, PopoverState};
24use crate::dom::html::htmlslotelement::SlottableData;
25use crate::dom::html::internals::elementinternals::ElementInternals;
26use crate::dom::intersectionobserver::IntersectionObserverRegistration;
27use crate::dom::mutationobserver::RegisteredObserver;
28use crate::dom::nodelist::NodeList;
29use crate::dom::range::Range;
30use crate::dom::shadowroot::shadowroot::ShadowRoot;
31use crate::dom::types::Element;
32use crate::dom::window::LayoutValue;
33
34// XXX(ferjm) Ideally merge NodeRareData and ElementRareData so they share
35//           storage.
36
37#[derive(Default, JSTraceable, MallocSizeOf)]
38#[cfg_attr(crown, crown::unrooted_must_root_lint::must_root)]
39pub(crate) struct NodeRareData {
40    /// The shadow root the node belongs to.
41    /// This is None if the node is not in a shadow tree or
42    /// if it is a ShadowRoot.
43    pub(crate) containing_shadow_root: Option<Dom<ShadowRoot>>,
44    /// Registered observers for this node.
45    pub(crate) mutation_observers: Vec<RegisteredObserver>,
46    /// Lazily-generated Unique Id for this node.
47    #[no_trace]
48    pub(crate) unique_id: Option<Uuid>,
49
50    pub(crate) slottable_data: SlottableData,
51
52    /// The live list of children return by .childNodes.
53    pub(crate) child_list: MutNullableDom<NodeList>,
54
55    /// Whether this node represents a certain implemented pseudo-element.
56    /// An implemented pseudo-element is a real element within a UA shadow tree
57    /// that will match a certain pseudo-element selector.
58    /// An example of this is the element matching the `::placeholder` selector.
59    #[no_trace]
60    pub(crate) implemented_pseudo_element: Option<PseudoElement>,
61}
62
63#[derive(Default, JSTraceable, MallocSizeOf)]
64#[cfg_attr(crown, crown::unrooted_must_root_lint::must_root)]
65pub(crate) struct ElementRareData {
66    /// <https://dom.spec.whatwg.org/#dom-element-shadowroot>
67    /// The ShadowRoot this element is host of.
68    pub(crate) shadow_root: Option<Dom<ShadowRoot>>,
69    /// <https://html.spec.whatwg.org/multipage/#custom-element-reaction-queue>
70    pub(crate) custom_element_reaction_queue: Vec<CustomElementReaction>,
71    /// <https://dom.spec.whatwg.org/#concept-element-custom-element-definition>
72    #[conditional_malloc_size_of]
73    pub(crate) custom_element_definition: Option<Rc<CustomElementDefinition>>,
74    /// <https://dom.spec.whatwg.org/#concept-element-custom-element-state>
75    pub(crate) custom_element_state: CustomElementState,
76    /// <https://dom.spec.whatwg.org/#dom-element-customelementregistry>
77    pub(crate) custom_element_registry: Option<Dom<CustomElementRegistry>>,
78    /// The "name" content attribute; not used as frequently as id, but used
79    /// in named getter loops so it's worth looking up quickly when present
80    #[no_trace]
81    pub(crate) name_attribute: Option<Atom>,
82    /// The client rect reported by layout.
83    #[no_trace]
84    pub(crate) client_rect: Option<LayoutValue<Rect<i32, CSSPixel>>>,
85    /// <https://html.spec.whatwg.org/multipage#elementinternals>
86    pub(crate) element_internals: Option<Dom<ElementInternals>>,
87
88    /// <https://w3c.github.io/IntersectionObserver/#element-private-slots>
89    /// > Element objects have an internal [[RegisteredIntersectionObservers]] slot,
90    /// > which is initialized to an empty list. This list holds IntersectionObserverRegistration records, which have:
91    pub(crate) registered_intersection_observers: Vec<IntersectionObserverRegistration>,
92    pub(crate) cryptographic_nonce: String,
93
94    /// <https://drafts.csswg.org/css-shadow-parts/#element-forwarded-part-name-list>
95    pub(crate) forwarded_part_names: Vec<(String, String)>,
96
97    /// <https://drafts.csswg.org/css-shadow-parts/#dom-element-part>
98    pub(crate) part: MutNullableDom<DOMTokenList>,
99
100    /// <https://w3c.github.io/selection-api/#definition>
101    /// > This one selection must be shared by all the content of the document (though not by nested documents),
102    /// > including any editing hosts in the document.
103    pub(crate) contenteditable_selection_range: MutNullableDom<Range>,
104
105    /// Whether this element had duplicate attributes during tokenization.
106    /// Used for CSP nonce validation (step 3 of "is element nonceable").
107    pub(crate) had_duplicate_attributes: bool,
108
109    /// <https://html.spec.whatwg.org/multipage/#previously-focused-element>
110    pub(crate) previously_focused_element: MutNullableDom<Element>,
111
112    /// <https://dom.spec.whatwg.org/#concept-element-is-value>
113    ///
114    /// Only ever set on customized built-in elements, which are very rare.
115    #[no_trace]
116    pub(crate) is_value: Option<LocalName>,
117
118    /// <https://html.spec.whatwg.org/multipage/#popover-trigger>
119    pub(crate) popover_trigger: MutNullableDom<HTMLElement>,
120
121    /// <https://html.spec.whatwg.org/multipage/#popover-hiding>
122    pub(crate) popover_hiding: bool,
123
124    /// <https://html.spec.whatwg.org/multipage/#popover-close-watcher>
125    #[conditional_malloc_size_of]
126    pub(crate) popover_close_watcher: DomRefCell<Option<Rc<InternalCloseWatcher>>>,
127
128    /// <https://html.spec.whatwg.org/multipage/#opened-in-popover-mode>
129    ///
130    /// Only ever [`PopoverState::Auto`] or [`PopoverState::Hint`].
131    #[no_trace]
132    pub(crate) opened_in_popover_mode: Option<PopoverState>,
133
134    /// <https://html.spec.whatwg.org/multipage/#explicitly-set-attr-element>
135    ///
136    /// > Its reflected target has an explicitly set attr-element, which is a weak reference to an
137    /// > element or null. It is initially null.
138    pub(crate) explicitly_set_attr_elements:
139        HashMapTracedValues<LocalName, Dom<Element>, FxBuildHasher>,
140}