/* This Source Code Form is subject to the terms of the Mozilla Public *License,v.2.0.IfacopyoftheMPLwasnotdistributedwiththis
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
//! An iterator over a list of rules.
usecrate::context::QuirksMode; usecrate::device::Device; usecrate::shared_lock::SharedRwLockReadGuard; usecrate::stylesheets::{
CssRule, CssRuleRef, CustomMediaEvaluator, CustomMediaMap, DocumentRule, ImportRule, MediaRule,
SupportsRule,
}; use smallvec::SmallVec; use std::ops::Deref; use std::slice;
/// An iterator over a list of rules. pubstruct RulesIterator<'a, 'b, C, CMM> where 'b: 'a,
C: NestedRuleIterationCondition + 'static,
CMM: Deref<Target = CustomMediaMap>,
{
device: &'a Device,
quirks_mode: QuirksMode,
custom_media: CMM,
guard: &'a SharedRwLockReadGuard<'b>,
stack: SmallVec<[slice::Iter<'a, CssRule>; 3]>,
last_rule_had_children: bool,
_phantom: ::std::marker::PhantomData<C>,
}
impl<'a, 'b, C, CMM> RulesIterator<'a, 'b, C, CMM> where 'b: 'a,
C: NestedRuleIterationCondition + 'static,
CMM: Deref<Target = CustomMediaMap>,
{ /// Returns the custom media map passed at construction. pubfn custom_media(&mutself) -> &mut CMM {
&mutself.custom_media
}
/// Skips all the remaining children of the last nested rule processed. pubfn skip_children(&mutself) { ifself.last_rule_had_children { self.stack.pop(); self.last_rule_had_children = false;
}
}
impl<'a, 'b, C, CMM> Iterator for RulesIterator<'a, 'b, C, CMM> where 'b: 'a,
C: NestedRuleIterationCondition + 'static,
CMM: Deref<Target = CustomMediaMap>,
{ type Item = &'a CssRule;
fn next(&mutself) -> Option<Self::Item> { self.last_rule_had_children = false; while !self.stack.is_empty() { let rule = { let nested_iter = self.stack.last_mut().unwrap(); match nested_iter.next() {
Some(r) => r,
None => { self.stack.pop(); continue;
},
}
};
letmut effective = true; let children = Self::children(
rule, self.device, self.quirks_mode,
&self.custom_media, self.guard,
&mut effective,
); if !effective { continue;
} if !children.is_empty() {
debug_assert_eq!(
rule.children(self.guard).len(),
children.len(), "Should agree with CssRule::children if effective"
); self.last_rule_had_children = true; self.stack.push(children.iter());
} return Some(rule);
}
None
}
}
/// RulesIterator. pubtrait NestedRuleIterationCondition { /// Whether we should process the nested rules in a given `@import` rule. fn process_import(
guard: &SharedRwLockReadGuard,
device: &Device,
quirks_mode: QuirksMode,
custom_media_map: &CustomMediaMap,
rule: &ImportRule,
) -> bool;
/// Whether we should process the nested rules in a given `@media` rule. fn process_media(
guard: &SharedRwLockReadGuard,
device: &Device,
quirks_mode: QuirksMode,
custom_media_map: &CustomMediaMap,
rule: &MediaRule,
) -> bool;
/// Whether we should process the nested rules in a given `@-moz-document` /// rule. fn process_document(
guard: &SharedRwLockReadGuard,
device: &Device,
quirks_mode: QuirksMode,
rule: &DocumentRule,
) -> bool;
/// Whether we should process the nested rules in a given `@supports` rule. fn process_supports(
guard: &SharedRwLockReadGuard,
device: &Device,
quirks_mode: QuirksMode,
rule: &SupportsRule,
) -> bool;
}
/// A struct that represents the condition that a rule applies to the document. pubstruct EffectiveRules;
/// An iterator over all the effective rules of a stylesheet. /// /// NOTE: This iterator recurses into `@import` rules. pubtype EffectiveRulesIterator<'a, 'b, CMM> = RulesIterator<'a, 'b, EffectiveRules, CMM>;
impl<'a, 'b, CMM> EffectiveRulesIterator<'a, 'b, CMM> where
CMM: Deref<Target = CustomMediaMap>,
{ /// Returns an iterator over the effective children of a rule, even if /// `rule` itself is not effective. pubfn effective_children(
device: &'a Device,
quirks_mode: QuirksMode,
custom_media_map: CMM,
guard: &'a SharedRwLockReadGuard<'b>,
rule: &'a CssRule,
) -> Self { let children = RulesIterator::<AllRules, CMM>::children(
rule,
device,
quirks_mode,
&custom_media_map,
guard,
&mutfalse,
);
EffectiveRulesIterator::new(
device,
quirks_mode,
custom_media_map,
guard,
children.iter(),
)
}
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.17 Sekunden
(vorverarbeitet am 2026-08-25)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.