style/properties_and_values/
registry.rs1use super::rule::{Inherits, InitialValue, PropertyRuleName};
8use super::syntax::Descriptor;
9use crate::selector_map::PrecomputedHashMap;
10use crate::stylesheets::UrlExtraData;
11use crate::Atom;
12use cssparser::SourceLocation;
13
14#[derive(Debug, Clone, MallocSizeOf)]
16pub struct PropertyRegistrationData {
17 pub syntax: Descriptor,
19 pub inherits: Inherits,
21 #[ignore_malloc_size_of = "Arc"]
23 pub initial_value: Option<InitialValue>,
24}
25
26static UNREGISTERED: PropertyRegistrationData = PropertyRegistrationData {
27 syntax: Descriptor::universal(),
28 inherits: Inherits::True,
29 initial_value: None,
30};
31
32impl PropertyRegistrationData {
33 pub fn unregistered() -> &'static Self {
35 &UNREGISTERED
36 }
37
38 #[inline]
40 pub fn inherits(&self) -> bool {
41 self.inherits == Inherits::True
42 }
43}
44
45#[derive(Debug, Clone, MallocSizeOf)]
48pub struct PropertyRegistration {
49 pub name: PropertyRuleName,
51 pub data: PropertyRegistrationData,
53 pub url_data: UrlExtraData,
57 pub source_location: SourceLocation,
59}
60
61impl PropertyRegistration {
62 #[inline]
64 pub fn inherits(&self) -> bool {
65 self.data.inherits == Inherits::True
66 }
67}
68
69#[derive(Default)]
72#[cfg_attr(feature = "servo", derive(MallocSizeOf))]
73pub struct ScriptRegistry {
74 properties: PrecomputedHashMap<Atom, PropertyRegistration>,
75}
76
77impl ScriptRegistry {
78 #[inline]
80 pub fn get(&self, name: &Atom) -> Option<&PropertyRegistration> {
81 self.properties.get(name)
82 }
83
84 #[inline]
86 pub fn properties(&self) -> &PrecomputedHashMap<Atom, PropertyRegistration> {
87 &self.properties
88 }
89
90 #[inline]
94 pub fn register(&mut self, registration: PropertyRegistration) {
95 let name = registration.name.0.clone();
96 let old = self.properties.insert(name, registration);
97 debug_assert!(old.is_none(), "Already registered? Should be an error");
98 }
99
100 #[inline]
102 pub fn get_all(&self) -> &PrecomputedHashMap<Atom, PropertyRegistration> {
103 &self.properties
104 }
105}