style: Factor out adding a rule in CascadeData::add_rule

This shouldn't have any behavior change, but is necessary because for
cascade layers we are going to need to handle the child rules / sheets
ourselves, in order to handle nested layers properly.

Differential Revision: https://phabricator.services.mozilla.com/D124334
This commit is contained in:
Emilio Cobos Álvarez 2023-05-27 06:01:30 +02:00 committed by Oriol Brufau
parent 9822db5d3c
commit 9976f9a589

View file

@ -2125,10 +2125,11 @@ impl CascadeData {
}
}
// Returns Err(..) to signify OOM
fn add_stylesheet<S>(
#[inline]
fn add_rule<S>(
&mut self,
device: &Device,
rule: &CssRule,
_device: &Device,
quirks_mode: QuirksMode,
stylesheet: &S,
guard: &SharedRwLockReadGuard,
@ -2138,18 +2139,6 @@ impl CascadeData {
where
S: StylesheetInDocument + 'static,
{
if !stylesheet.enabled() || !stylesheet.is_effective_for_device(device, guard) {
return Ok(());
}
let contents = stylesheet.contents();
let origin = contents.origin;
if rebuild_kind.should_rebuild_invalidation() {
self.effective_media_query_results.saw_effective(contents);
}
for rule in stylesheet.effective_rules(device, guard) {
match *rule {
CssRule::Style(ref locked) => {
let style_rule = locked.read_with(&guard);
@ -2162,7 +2151,7 @@ impl CascadeData {
if let Some(pseudo) = pseudo_element {
if pseudo.is_precomputed() {
debug_assert!(selector.is_universal());
debug_assert!(matches!(origin, Origin::UserAgent));
debug_assert_eq!(stylesheet.contents().origin, Origin::UserAgent);
precomputed_pseudo_element_decls
.as_mut()
@ -2306,6 +2295,43 @@ impl CascadeData {
// We don't care about any other rule.
_ => {},
}
Ok(())
}
// Returns Err(..) to signify OOM
fn add_stylesheet<S>(
&mut self,
device: &Device,
quirks_mode: QuirksMode,
stylesheet: &S,
guard: &SharedRwLockReadGuard,
rebuild_kind: SheetRebuildKind,
mut precomputed_pseudo_element_decls: Option<&mut PrecomputedPseudoElementDeclarations>,
) -> Result<(), FailedAllocationError>
where
S: StylesheetInDocument + 'static,
{
if !stylesheet.enabled() || !stylesheet.is_effective_for_device(device, guard) {
return Ok(());
}
let contents = stylesheet.contents();
if rebuild_kind.should_rebuild_invalidation() {
self.effective_media_query_results.saw_effective(contents);
}
for rule in stylesheet.effective_rules(device, guard) {
self.add_rule(
rule,
device,
quirks_mode,
stylesheet,
guard,
rebuild_kind,
precomputed_pseudo_element_decls.as_deref_mut(),
)?;
}
Ok(())