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
This commit is contained in:
Emilio Cobos Álvarez 2021-02-12 15:42:38 +00:00
parent 75d6be45f2
commit 4cb0a781d1

View file

@ -669,7 +669,7 @@ impl Stylist {
{ {
debug_assert!(pseudo.is_precomputed()); 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::<E>( self.precomputed_values_for_pseudo_with_rule_node::<E>(
guards, 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, /// If we want to include extra declarations to this precomputed
/// we can provide a vector of ApplicableDeclarationBlock to extra_declarations /// pseudo-element, we can provide a vector of ApplicableDeclarationBlocks
/// argument. This is useful for providing extra @page rules. /// to extra_declarations. This is useful for @page rules.
pub fn rule_node_for_precomputed_pseudo( pub fn rule_node_for_precomputed_pseudo(
&self, &self,
guards: &StylesheetGuards, guards: &StylesheetGuards,
pseudo: &PseudoElement, pseudo: &PseudoElement,
extra_declarations: Option<Vec<ApplicableDeclarationBlock>>, mut extra_declarations: Vec<ApplicableDeclarationBlock>,
) -> StrongRuleNode { ) -> StrongRuleNode {
let mut decl; let mut declarations_with_extra;
let declarations = match self let declarations = match self
.cascade_data .cascade_data
.user_agent .user_agent
.precomputed_pseudo_element_decls .precomputed_pseudo_element_decls
.get(pseudo) .get(pseudo)
{ {
Some(declarations) => match extra_declarations { Some(declarations) => {
Some(mut extra_decls) => { if !extra_declarations.is_empty() {
decl = declarations.clone(); declarations_with_extra = declarations.clone();
decl.append(&mut extra_decls); declarations_with_extra.append(&mut extra_declarations);
Some(&decl) &*declarations_with_extra
}, } else {
None => Some(declarations), &**declarations
}
}, },
None => extra_declarations.as_ref(), None => &[],
}; };
match declarations { self.rule_tree.insert_ordered_rules_with_important(
Some(decls) => self.rule_tree.insert_ordered_rules_with_important( declarations.into_iter().map(|a| a.clone().for_rule_tree()),
decls.into_iter().map(|a| a.clone().for_rule_tree()), guards,
guards, )
),
None => self.rule_tree.root().clone(),
}
} }
/// Returns the style for an anonymous box of the given type. /// Returns the style for an anonymous box of the given type.