From 5cd10b9eb7d9bb794c3f901b8acfcc0724072954 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Fri, 25 Aug 2017 13:34:36 +0200 Subject: [PATCH] style: Use consistent indentation in the stylist code. --- components/style/stylist.rs | 460 ++++++++++++++++++++---------------- 1 file changed, 256 insertions(+), 204 deletions(-) diff --git a/components/style/stylist.rs b/components/style/stylist.rs index 16301de193f..cf4eff1df56 100644 --- a/components/style/stylist.rs +++ b/components/style/stylist.rs @@ -671,13 +671,14 @@ impl Stylist { /// parent; otherwise, non-inherited properties are reset to their initial /// values. The flow constructor uses this flag when constructing anonymous /// flows. - pub fn precomputed_values_for_pseudo(&self, - guards: &StylesheetGuards, - pseudo: &PseudoElement, - parent: Option<&ComputedValues>, - cascade_flags: CascadeFlags, - font_metrics: &FontMetricsProvider) - -> Arc { + pub fn precomputed_values_for_pseudo( + &self, + guards: &StylesheetGuards, + pseudo: &PseudoElement, + parent: Option<&ComputedValues>, + cascade_flags: CascadeFlags, + font_metrics: &FontMetricsProvider + ) -> Arc { debug_assert!(pseudo.is_precomputed()); let rule_node = @@ -705,18 +706,20 @@ impl Stylist { // descendant of a display: contents element where display: contents is // the actual used value, and the computed value of it would need // blockification. - properties::cascade(&self.device, - Some(pseudo), - &rule_node, - guards, - parent, - parent, - parent, - None, - None, - font_metrics, - cascade_flags, - self.quirks_mode) + properties::cascade( + &self.device, + Some(pseudo), + &rule_node, + guards, + parent, + parent, + parent, + None, + None, + font_metrics, + cascade_flags, + self.quirks_mode, + ) } /// Returns the style for an anonymous box of the given type. @@ -769,38 +772,42 @@ impl Stylist { /// /// Check the documentation on lazy pseudo-elements in /// docs/components/style.md - pub fn lazily_compute_pseudo_element_style(&self, - guards: &StylesheetGuards, - element: &E, - pseudo: &PseudoElement, - rule_inclusion: RuleInclusion, - parent_style: &ComputedValues, - is_probe: bool, - font_metrics: &FontMetricsProvider) - -> Option> - where E: TElement, + pub fn lazily_compute_pseudo_element_style( + &self, + guards: &StylesheetGuards, + element: &E, + pseudo: &PseudoElement, + rule_inclusion: RuleInclusion, + parent_style: &ComputedValues, + is_probe: bool, + font_metrics: &FontMetricsProvider + ) -> Option> + where + E: TElement, { let cascade_inputs = self.lazy_pseudo_rules(guards, element, pseudo, is_probe, rule_inclusion); - self.compute_pseudo_element_style_with_inputs(&cascade_inputs, - pseudo, - guards, - parent_style, - font_metrics) + self.compute_pseudo_element_style_with_inputs( + &cascade_inputs, + pseudo, + guards, + parent_style, + font_metrics, + ) } /// Computes a pseudo-element style lazily using the given CascadeInputs. /// This can be used for truly lazy pseudo-elements or to avoid redoing /// selector matching for eager pseudo-elements when we need to recompute /// their style with a new parent style. - pub fn compute_pseudo_element_style_with_inputs(&self, - inputs: &CascadeInputs, - pseudo: &PseudoElement, - guards: &StylesheetGuards, - parent_style: &ComputedValues, - font_metrics: &FontMetricsProvider) - -> Option> - { + pub fn compute_pseudo_element_style_with_inputs( + &self, + inputs: &CascadeInputs, + pseudo: &PseudoElement, + guards: &StylesheetGuards, + parent_style: &ComputedValues, + font_metrics: &FontMetricsProvider + ) -> Option> { // We may have only visited rules in cases when we are actually // resolving, not probing, pseudo-element style. if inputs.rules.is_none() && inputs.visited_rules.is_none() { @@ -812,14 +819,16 @@ impl Stylist { // pseudos other than before and after, so it's probably ok. // // (Though the flags don't indicate so!) - Some(self.compute_style_with_inputs(inputs, - Some(pseudo), - guards, - parent_style, - parent_style, - parent_style, - font_metrics, - CascadeFlags::empty())) + Some(self.compute_style_with_inputs( + inputs, + Some(pseudo), + guards, + parent_style, + parent_style, + parent_style, + font_metrics, + CascadeFlags::empty(), + )) } /// Computes a style using the given CascadeInputs. This can be used to @@ -837,17 +846,17 @@ impl Stylist { /// /// is_link should be true if we're computing style for a link; that affects /// how :visited handling is done. - pub fn compute_style_with_inputs(&self, - inputs: &CascadeInputs, - pseudo: Option<&PseudoElement>, - guards: &StylesheetGuards, - parent_style: &ComputedValues, - parent_style_ignoring_first_line: &ComputedValues, - layout_parent_style: &ComputedValues, - font_metrics: &FontMetricsProvider, - cascade_flags: CascadeFlags) - -> Arc - { + pub fn compute_style_with_inputs( + &self, + inputs: &CascadeInputs, + pseudo: Option<&PseudoElement>, + guards: &StylesheetGuards, + parent_style: &ComputedValues, + parent_style_ignoring_first_line: &ComputedValues, + layout_parent_style: &ComputedValues, + font_metrics: &FontMetricsProvider, + cascade_flags: CascadeFlags + ) -> Arc { // We need to compute visited values if we have visited rules or if our // parent has visited values. let visited_values = if inputs.visited_rules.is_some() || parent_style.get_visited_style().is_some() { @@ -877,21 +886,20 @@ impl Stylist { layout_parent_style.get_visited_style().unwrap_or(layout_parent_style); } - let computed = - properties::cascade(&self.device, - pseudo, - rule_node, - guards, - Some(inherited_style), - Some(inherited_style_ignoring_first_line), - Some(layout_parent_style_for_visited), - None, - None, - font_metrics, - cascade_flags, - self.quirks_mode); - - Some(computed) + Some(properties::cascade( + &self.device, + pseudo, + rule_node, + guards, + Some(inherited_style), + Some(inherited_style_ignoring_first_line), + Some(layout_parent_style_for_visited), + None, + None, + font_metrics, + cascade_flags, + self.quirks_mode, + )) } else { None }; @@ -904,18 +912,20 @@ impl Stylist { // difficult to assert that display: contents nodes never arrive here // (tl;dr: It doesn't apply for replaced elements and such, but the // computed value is still "contents"). - properties::cascade(&self.device, - pseudo, - rules, - guards, - Some(parent_style), - Some(parent_style_ignoring_first_line), - Some(layout_parent_style), - visited_values, - None, - font_metrics, - cascade_flags, - self.quirks_mode) + properties::cascade( + &self.device, + pseudo, + rules, + guards, + Some(parent_style), + Some(parent_style_ignoring_first_line), + Some(layout_parent_style), + visited_values, + None, + font_metrics, + cascade_flags, + self.quirks_mode, + ) } fn has_rules_for_pseudo(&self, pseudo: &PseudoElement) -> bool { @@ -928,14 +938,16 @@ impl Stylist { /// /// See the documentation on lazy pseudo-elements in /// docs/components/style.md - pub fn lazy_pseudo_rules(&self, - guards: &StylesheetGuards, - element: &E, - pseudo: &PseudoElement, - is_probe: bool, - rule_inclusion: RuleInclusion) - -> CascadeInputs - where E: TElement + pub fn lazy_pseudo_rules( + &self, + guards: &StylesheetGuards, + element: &E, + pseudo: &PseudoElement, + is_probe: bool, + rule_inclusion: RuleInclusion + ) -> CascadeInputs + where + E: TElement { let pseudo = pseudo.canonical(); debug_assert!(pseudo.is_lazy()); @@ -1009,19 +1021,24 @@ impl Stylist { if matching_context.relevant_link_found { let mut declarations = ApplicableDeclarationList::new(); let mut matching_context = - MatchingContext::new_for_visited(MatchingMode::ForStatelessPseudoElement, - None, - VisitedHandlingMode::RelevantLinkVisited, - self.quirks_mode); - self.push_applicable_declarations(element, - Some(&pseudo), - None, - None, - AnimationRules(None, None), - rule_inclusion, - &mut declarations, - &mut matching_context, - &mut set_selector_flags); + MatchingContext::new_for_visited( + MatchingMode::ForStatelessPseudoElement, + None, + VisitedHandlingMode::RelevantLinkVisited, + self.quirks_mode, + ); + + self.push_applicable_declarations( + element, + Some(&pseudo), + None, + None, + AnimationRules(None, None), + rule_inclusion, + &mut declarations, + &mut matching_context, + &mut set_selector_flags + ); if !declarations.is_empty() { let rule_node = self.rule_tree.insert_ordered_rules_with_important( @@ -1215,12 +1232,15 @@ impl Stylist { /// Returns the applicable CSS declarations for the given element by /// treating us as an XBL stylesheet-only stylist. - pub fn push_applicable_declarations_as_xbl_only_stylist(&self, - element: &E, - pseudo_element: Option<&PseudoElement>, - applicable_declarations: &mut V) - where E: TElement, - V: Push + VecLike, + pub fn push_applicable_declarations_as_xbl_only_stylist( + &self, + element: &E, + pseudo_element: Option<&PseudoElement>, + applicable_declarations: &mut V + ) + where + E: TElement, + V: Push + VecLike, { let mut matching_context = MatchingContext::new(MatchingMode::Normal, None, self.quirks_mode); @@ -1231,36 +1251,37 @@ impl Stylist { // nsXBLPrototypeResources::LoadResources() loads Chrome XBL style // sheets under eAuthorSheetFeatures level. if let Some(map) = self.cascade_data.per_origin.author.borrow_for_pseudo(pseudo_element) { - map.get_all_matching_rules(element, - &rule_hash_target, - applicable_declarations, - &mut matching_context, - self.quirks_mode, - &mut dummy_flag_setter, - CascadeLevel::XBL); + map.get_all_matching_rules( + element, + &rule_hash_target, + applicable_declarations, + &mut matching_context, + self.quirks_mode, + &mut dummy_flag_setter, + CascadeLevel::XBL, + ); } } /// Returns the applicable CSS declarations for the given element. /// /// This corresponds to `ElementRuleCollector` in WebKit. - /// - /// The `StyleRelations` recorded in `MatchingContext` indicate hints about - /// which kind of rules have matched. pub fn push_applicable_declarations( - &self, - element: &E, - pseudo_element: Option<&PseudoElement>, - style_attribute: Option>>, - smil_override: Option>>, - animation_rules: AnimationRules, - rule_inclusion: RuleInclusion, - applicable_declarations: &mut V, - context: &mut MatchingContext, - flags_setter: &mut F) - where E: TElement, - V: Push + VecLike + Debug, - F: FnMut(&E, ElementSelectorFlags), + &self, + element: &E, + pseudo_element: Option<&PseudoElement>, + style_attribute: Option>>, + smil_override: Option>>, + animation_rules: AnimationRules, + rule_inclusion: RuleInclusion, + applicable_declarations: &mut V, + context: &mut MatchingContext, + flags_setter: &mut F, + ) + where + E: TElement, + V: Push + VecLike + Debug, + F: FnMut(&E, ElementSelectorFlags), { // Gecko definitely has pseudo-elements with style attributes, like // ::-moz-color-swatch. @@ -1278,13 +1299,15 @@ impl Stylist { // Step 1: Normal user-agent rules. if let Some(map) = self.cascade_data.per_origin.user_agent.borrow_for_pseudo(pseudo_element) { - map.get_all_matching_rules(element, - &rule_hash_target, - applicable_declarations, - context, - self.quirks_mode, - flags_setter, - CascadeLevel::UANormal); + map.get_all_matching_rules( + element, + &rule_hash_target, + applicable_declarations, + context, + self.quirks_mode, + flags_setter, + CascadeLevel::UANormal + ); } if pseudo_element.is_none() && !only_default_rules { @@ -1314,13 +1337,15 @@ impl Stylist { if rule_hash_target.matches_user_and_author_rules() { // Step 3a: User normal rules. if let Some(map) = self.cascade_data.per_origin.user.borrow_for_pseudo(pseudo_element) { - map.get_all_matching_rules(element, - &rule_hash_target, - applicable_declarations, - context, - self.quirks_mode, - flags_setter, - CascadeLevel::UserNormal); + map.get_all_matching_rules( + element, + &rule_hash_target, + applicable_declarations, + context, + self.quirks_mode, + flags_setter, + CascadeLevel::UserNormal, + ); } } else { debug!("skipping user rules"); @@ -1328,8 +1353,10 @@ impl Stylist { // Step 3b: XBL rules. let cut_off_inheritance = - element.get_declarations_from_xbl_bindings(pseudo_element, - applicable_declarations); + element.get_declarations_from_xbl_bindings( + pseudo_element, + applicable_declarations, + ); if rule_hash_target.matches_user_and_author_rules() && !only_default_rules { // Gecko skips author normal rules if cutting off inheritance. @@ -1337,13 +1364,15 @@ impl Stylist { if !cut_off_inheritance { // Step 3c: Author normal rules. if let Some(map) = self.cascade_data.per_origin.author.borrow_for_pseudo(pseudo_element) { - map.get_all_matching_rules(element, - &rule_hash_target, - applicable_declarations, - context, - self.quirks_mode, - flags_setter, - CascadeLevel::AuthorNormal); + map.get_all_matching_rules( + element, + &rule_hash_target, + applicable_declarations, + context, + self.quirks_mode, + flags_setter, + CascadeLevel::AuthorNormal + ); } } else { debug!("skipping author normal rules due to cut off inheritance"); @@ -1357,8 +1386,11 @@ impl Stylist { if let Some(sa) = style_attribute { Push::push( applicable_declarations, - ApplicableDeclarationBlock::from_declarations(sa.clone_arc(), - CascadeLevel::StyleAttributeNormal)); + ApplicableDeclarationBlock::from_declarations( + sa.clone_arc(), + CascadeLevel::StyleAttributeNormal + ) + ); } // Step 5: SMIL override. @@ -1366,8 +1398,11 @@ impl Stylist { if let Some(so) = smil_override { Push::push( applicable_declarations, - ApplicableDeclarationBlock::from_declarations(so.clone_arc(), - CascadeLevel::SMILOverride)); + ApplicableDeclarationBlock::from_declarations( + so.clone_arc(), + CascadeLevel::SMILOverride + ) + ); } // Step 6: Animations. @@ -1376,8 +1411,11 @@ impl Stylist { if let Some(anim) = animation_rules.0 { Push::push( applicable_declarations, - ApplicableDeclarationBlock::from_declarations(anim.clone(), - CascadeLevel::Animations)); + ApplicableDeclarationBlock::from_declarations( + anim.clone(), + CascadeLevel::Animations + ) + ); } } else { debug!("skipping style attr and SMIL & animation rules"); @@ -1394,8 +1432,11 @@ impl Stylist { if let Some(anim) = animation_rules.1 { Push::push( applicable_declarations, - ApplicableDeclarationBlock::from_declarations(anim.clone(), - CascadeLevel::Transitions)); + ApplicableDeclarationBlock::from_declarations( + anim.clone(), + CascadeLevel::Transitions + ) + ); } } else { debug!("skipping transition rules"); @@ -1422,13 +1463,15 @@ impl Stylist { /// Computes the match results of a given element against the set of /// revalidation selectors. - pub fn match_revalidation_selectors(&self, - element: &E, - bloom: Option<&BloomFilter>, - flags_setter: &mut F) - -> BitVec - where E: TElement, - F: FnMut(&E, ElementSelectorFlags), + pub fn match_revalidation_selectors( + &self, + element: &E, + bloom: Option<&BloomFilter>, + flags_setter: &mut F + ) -> BitVec + where + E: TElement, + F: FnMut(&E, ElementSelectorFlags), { // NB: `MatchingMode` doesn't really matter, given we don't share style // between pseudos. @@ -1443,13 +1486,17 @@ impl Stylist { let mut results = BitVec::new(); for (data, _) in self.cascade_data.iter_origins() { data.selectors_for_cache_revalidation.lookup( - *element, self.quirks_mode, &mut |selector_and_hashes| { - results.push(matches_selector(&selector_and_hashes.selector, - selector_and_hashes.selector_offset, - Some(&selector_and_hashes.hashes), - element, - &mut matching_context, - flags_setter)); + *element, + self.quirks_mode, + &mut |selector_and_hashes| { + results.push(matches_selector( + &selector_and_hashes.selector, + selector_and_hashes.selector_offset, + Some(&selector_and_hashes.hashes), + element, + &mut matching_context, + flags_setter + )); true } ); @@ -1459,17 +1506,19 @@ impl Stylist { } /// Computes styles for a given declaration with parent_style. - pub fn compute_for_declarations(&self, - guards: &StylesheetGuards, - parent_style: &ComputedValues, - declarations: Arc>) - -> Arc { + pub fn compute_for_declarations( + &self, + guards: &StylesheetGuards, + parent_style: &ComputedValues, + declarations: Arc>, + ) -> Arc { use font_metrics::get_metrics_provider_for_product; - let v = vec![ - ApplicableDeclarationBlock::from_declarations(declarations.clone(), - CascadeLevel::StyleAttributeNormal) - ]; + let v = vec![ApplicableDeclarationBlock::from_declarations( + declarations.clone(), + CascadeLevel::StyleAttributeNormal + )]; + let rule_node = self.rule_tree.insert_ordered_rules(v.into_iter().map(|a| a.order_and_level())); @@ -1477,19 +1526,22 @@ impl Stylist { // font styles in via Servo_StyleSet_ResolveForDeclarations. // It is unclear if visited styles are meaningful for this case. let metrics = get_metrics_provider_for_product(); + // FIXME(emilio): the pseudo bit looks quite dubious! - properties::cascade(&self.device, - /* pseudo = */ None, - &rule_node, - guards, - Some(parent_style), - Some(parent_style), - Some(parent_style), - None, - None, - &metrics, - CascadeFlags::empty(), - self.quirks_mode) + properties::cascade( + &self.device, + /* pseudo = */ None, + &rule_node, + guards, + Some(parent_style), + Some(parent_style), + Some(parent_style), + None, + None, + &metrics, + CascadeFlags::empty(), + self.quirks_mode, + ) } /// Accessor for a shared reference to the device.