From 32d6979b28428d1be3145f924bb0fccd54bb9d94 Mon Sep 17 00:00:00 2001 From: Zach Hoffman Date: Mon, 23 Oct 2023 17:07:47 +0000 Subject: [PATCH] Bug 1857674 - Reuse is_root_element from style builder r=emilio Depends on D191161 Differential Revision: https://phabricator.services.mozilla.com/D191615 --- servo/components/style/custom_properties.rs | 18 +++--------------- servo/components/style/properties/cascade.rs | 3 +-- .../style/properties/declaration_block.rs | 2 +- servo/components/style/values/computed/mod.rs | 5 +++++ 4 files changed, 10 insertions(+), 18 deletions(-) diff --git a/servo/components/style/custom_properties.rs b/servo/components/style/custom_properties.rs index dc7b8e0efd98..4a9320191708 100644 --- a/servo/components/style/custom_properties.rs +++ b/servo/components/style/custom_properties.rs @@ -793,18 +793,14 @@ pub struct CustomPropertiesBuilder<'a, 'b: 'a> { reverted: PrecomputedHashMap<&'a Name, (CascadePriority, bool)>, stylist: &'a Stylist, computed_context: &'a computed::Context<'b>, - is_root_element: bool, } impl<'a, 'b: 'a> CustomPropertiesBuilder<'a, 'b> { /// Create a new builder, inheriting from a given custom properties map. - pub fn new( - stylist: &'a Stylist, - computed_context: &'a computed::Context<'b>, - is_root_element: bool, - ) -> Self { + pub fn new(stylist: &'a Stylist, computed_context: &'a computed::Context<'b>) -> Self { let inherited = computed_context.inherited_custom_properties(); let initial_values = stylist.get_custom_property_initial_values(); + let is_root_element = computed_context.is_root_element(); Self { seen: PrecomputedHashSet::default(), reverted: Default::default(), @@ -820,7 +816,6 @@ impl<'a, 'b: 'a> CustomPropertiesBuilder<'a, 'b> { }, stylist, computed_context, - is_root_element, } } @@ -865,7 +860,6 @@ impl<'a, 'b: 'a> CustomPropertiesBuilder<'a, 'b> { map, self.stylist, self.computed_context, - self.is_root_element, ); return; } @@ -1033,7 +1027,6 @@ impl<'a, 'b: 'a> CustomPropertiesBuilder<'a, 'b> { &self.seen, self.stylist, self.computed_context, - self.is_root_element, ); } @@ -1075,7 +1068,6 @@ fn substitute_all( seen: &PrecomputedHashSet<&Name>, stylist: &Stylist, computed_context: &computed::Context, - is_root_element: bool, ) { // The cycle dependencies removal in this function is a variant // of Tarjan's algorithm. It is mostly based on the pseudo-code @@ -1117,8 +1109,6 @@ fn substitute_all( /// The computed context is used to get inherited custom /// properties and compute registered custom properties. computed_context: &'a computed::Context<'b>, - /// Whether this is the root element. - is_root_element: bool, } /// This function combines the traversal for cycle removal and value @@ -1264,7 +1254,6 @@ fn substitute_all( &mut context.map, context.stylist, context.computed_context, - context.is_root_element, ); // All resolved, so return the signal value. @@ -1283,7 +1272,6 @@ fn substitute_all( map: custom_properties_map, stylist, computed_context, - is_root_element, }; traverse(name, &mut context); } @@ -1329,11 +1317,11 @@ fn substitute_references_in_value_and_apply( custom_properties: &mut ComputedCustomProperties, stylist: &Stylist, computed_context: &computed::Context, - is_root_element: bool, ) { debug_assert!(value.has_references()); let inherited = computed_context.inherited_custom_properties(); + let is_root_element = computed_context.is_root_element(); let custom_registration = stylist.get_custom_property_registration(&name); let mut computed_value = ComputedValue::empty(); diff --git a/servo/components/style/properties/cascade.rs b/servo/components/style/properties/cascade.rs index d8a8e6fb27f3..25b588ee9807 100644 --- a/servo/components/style/properties/cascade.rs +++ b/servo/components/style/properties/cascade.rs @@ -321,8 +321,7 @@ where }, CascadeMode::Unvisited { visited_rules } => { cascade.context.builder.custom_properties = { - let mut builder = - CustomPropertiesBuilder::new(stylist, cascade.context, is_root_element); + let mut builder = CustomPropertiesBuilder::new(stylist, cascade.context); iter_declarations(iter, &mut declarations, Some(&mut builder)); builder.build() }; diff --git a/servo/components/style/properties/declaration_block.rs b/servo/components/style/properties/declaration_block.rs index 09e2429ff0f7..833cf47a69ee 100644 --- a/servo/components/style/properties/declaration_block.rs +++ b/servo/components/style/properties/declaration_block.rs @@ -956,7 +956,7 @@ impl PropertyDeclarationBlock { stylist: &Stylist, context: &Context, ) -> ComputedCustomProperties { - let mut builder = CustomPropertiesBuilder::new(stylist, context, false); + let mut builder = CustomPropertiesBuilder::new(stylist, context); for declaration in self.normal_declaration_iter() { if let PropertyDeclaration::Custom(ref declaration) = *declaration { diff --git a/servo/components/style/values/computed/mod.rs b/servo/components/style/values/computed/mod.rs index 76bdd233ca48..c3de65f8b05a 100644 --- a/servo/components/style/values/computed/mod.rs +++ b/servo/components/style/values/computed/mod.rs @@ -321,6 +321,11 @@ impl<'a> Context<'a> { &self.builder.inherited_custom_properties() } + /// Whether the style is for the root element. + pub fn is_root_element(&self) -> bool { + self.builder.is_root_element + } + /// Queries font metrics. pub fn query_font_metrics( &self,