mirror of
https://github.com/servo/servo.git
synced 2025-08-04 05:00:08 +01:00
style: Hoist cascade() to CustomPropertyBuilder.
This commit is contained in:
parent
715fc9cea6
commit
4914351f2b
1 changed files with 42 additions and 59 deletions
|
@ -481,51 +481,16 @@ impl<'a> CustomPropertiesBuilder<'a> {
|
|||
name: &'a Name,
|
||||
specified_value: DeclaredValue<'a, Box<SpecifiedValue>>,
|
||||
) {
|
||||
cascade(
|
||||
&mut self.custom_properties,
|
||||
self.inherited,
|
||||
&mut self.seen,
|
||||
name,
|
||||
specified_value,
|
||||
)
|
||||
}
|
||||
|
||||
/// Returns the final map of applicable custom properties.
|
||||
///
|
||||
/// If there was any specified property, we've created a new map and now we need
|
||||
/// to remove any potential cycles, and wrap it in an arc.
|
||||
///
|
||||
/// Otherwise, just use the inherited custom properties map.
|
||||
pub fn build(mut self) -> Option<Arc<CustomPropertiesMap>> {
|
||||
let mut map = match self.custom_properties.take() {
|
||||
Some(map) => map,
|
||||
None => return self.inherited.cloned(),
|
||||
};
|
||||
|
||||
remove_cycles(&mut map);
|
||||
Some(Arc::new(substitute_all(map)))
|
||||
}
|
||||
}
|
||||
|
||||
/// Add one custom property declaration to a map, unless another with the same
|
||||
/// name was already there.
|
||||
fn cascade<'a>(
|
||||
custom_properties: &mut Option<OrderedMap<&'a Name, BorrowedSpecifiedValue<'a>>>,
|
||||
inherited: Option<&'a Arc<CustomPropertiesMap>>,
|
||||
seen: &mut PrecomputedHashSet<&'a Name>,
|
||||
name: &'a Name,
|
||||
specified_value: DeclaredValue<'a, Box<SpecifiedValue>>
|
||||
) {
|
||||
let was_already_present = !seen.insert(name);
|
||||
let was_already_present = !self.seen.insert(name);
|
||||
if was_already_present {
|
||||
return;
|
||||
}
|
||||
|
||||
let map = match *custom_properties {
|
||||
let map = match self.custom_properties {
|
||||
Some(ref mut map) => map,
|
||||
None => {
|
||||
let mut map = OrderedMap::new();
|
||||
if let Some(inherited) = inherited {
|
||||
if let Some(inherited) = self.inherited {
|
||||
for (name, inherited_value) in inherited.iter() {
|
||||
map.insert(name, BorrowedSpecifiedValue {
|
||||
css: &inherited_value.css,
|
||||
|
@ -535,10 +500,11 @@ fn cascade<'a>(
|
|||
})
|
||||
}
|
||||
}
|
||||
*custom_properties = Some(map);
|
||||
custom_properties.as_mut().unwrap()
|
||||
self.custom_properties = Some(map);
|
||||
self.custom_properties.as_mut().unwrap()
|
||||
}
|
||||
};
|
||||
|
||||
match specified_value {
|
||||
DeclaredValue::Value(ref specified_value) => {
|
||||
map.insert(name, BorrowedSpecifiedValue {
|
||||
|
@ -557,6 +523,23 @@ fn cascade<'a>(
|
|||
CSSWideKeyword::Inherit => {} // The inherited value is what we already have.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the final map of applicable custom properties.
|
||||
///
|
||||
/// If there was any specified property, we've created a new map and now we need
|
||||
/// to remove any potential cycles, and wrap it in an arc.
|
||||
///
|
||||
/// Otherwise, just use the inherited custom properties map.
|
||||
pub fn build(mut self) -> Option<Arc<CustomPropertiesMap>> {
|
||||
let mut map = match self.custom_properties.take() {
|
||||
Some(map) => map,
|
||||
None => return self.inherited.cloned(),
|
||||
};
|
||||
|
||||
remove_cycles(&mut map);
|
||||
Some(Arc::new(substitute_all(map)))
|
||||
}
|
||||
}
|
||||
|
||||
/// https://drafts.csswg.org/css-variables/#cycles
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue