From 4cb0a781d14c942bde404d669b1e8de20731122c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Fri, 12 Feb 2021 15:42:38 +0000 Subject: [PATCH] style: Minor cleanup of our @page rule setup. Actually, there's not so much we can improve right now, in the sense that: * We need the ::-moz-page-content pseudo-element to be able to set `display` on the page, since that's a style rule rather than a @page rule. We could get away without it. * Keeping the current code-path (slightly cleaned up) is less code, for now at least. We can have a separate code-path or what not that actually performs the @page rule selector-matching and what not if needed when we get to named pages or other page selectors. Selectors like :first should be pretty trivial to implement, actually. We make some paged mode anon boxes non-inheriting anon boxes. This allows us to share the styles and is generally nicer. They don't need to inherit from anywhere. We could remove the origin handling and don't look at UA rules or what not, but it seems pretty harmless to do that. We also fix the name of the pseudo-elements to match the capitalization. Differential Revision: https://phabricator.services.mozilla.com/D104772 --- components/style/stylist.rs | 42 ++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 22 deletions(-) diff --git a/components/style/stylist.rs b/components/style/stylist.rs index 418a86bc5e0..9a2134450de 100644 --- a/components/style/stylist.rs +++ b/components/style/stylist.rs @@ -669,7 +669,7 @@ impl Stylist { { debug_assert!(pseudo.is_precomputed()); - let rule_node = self.rule_node_for_precomputed_pseudo(guards, pseudo, None); + let rule_node = self.rule_node_for_precomputed_pseudo(guards, pseudo, vec![]); self.precomputed_values_for_pseudo_with_rule_node::( guards, @@ -709,42 +709,40 @@ impl Stylist { ) } - /// Returns the rule node for given precomputed pseudo-element. + /// Returns the rule node for a given precomputed pseudo-element. /// - /// If we want to include extra declarations to this precomputed pseudo-element, - /// we can provide a vector of ApplicableDeclarationBlock to extra_declarations - /// argument. This is useful for providing extra @page rules. + /// If we want to include extra declarations to this precomputed + /// pseudo-element, we can provide a vector of ApplicableDeclarationBlocks + /// to extra_declarations. This is useful for @page rules. pub fn rule_node_for_precomputed_pseudo( &self, guards: &StylesheetGuards, pseudo: &PseudoElement, - extra_declarations: Option>, + mut extra_declarations: Vec, ) -> StrongRuleNode { - let mut decl; + let mut declarations_with_extra; let declarations = match self .cascade_data .user_agent .precomputed_pseudo_element_decls .get(pseudo) { - Some(declarations) => match extra_declarations { - Some(mut extra_decls) => { - decl = declarations.clone(); - decl.append(&mut extra_decls); - Some(&decl) - }, - None => Some(declarations), + Some(declarations) => { + if !extra_declarations.is_empty() { + declarations_with_extra = declarations.clone(); + declarations_with_extra.append(&mut extra_declarations); + &*declarations_with_extra + } else { + &**declarations + } }, - None => extra_declarations.as_ref(), + None => &[], }; - match declarations { - Some(decls) => self.rule_tree.insert_ordered_rules_with_important( - decls.into_iter().map(|a| a.clone().for_rule_tree()), - guards, - ), - None => self.rule_tree.root().clone(), - } + self.rule_tree.insert_ordered_rules_with_important( + declarations.into_iter().map(|a| a.clone().for_rule_tree()), + guards, + ) } /// Returns the style for an anonymous box of the given type.