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