/* 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::media_queries::Device; usecrate::shared_lock::SharedRwLockReadGuard; usecrate::stylesheets::{CssRule, DocumentRule, ImportRule, MediaRule, SupportsRule}; use smallvec::SmallVec; use std::slice;
/// An iterator over a list of rules. pubstruct RulesIterator<'a, 'b, C> where 'b: 'a,
C: NestedRuleIterationCondition + 'static,
{
device: &'a Device,
quirks_mode: QuirksMode,
guard: &'a SharedRwLockReadGuard<'b>,
stack: SmallVec<[slice::Iter<'a, CssRule>; 3]>,
_phantom: ::std::marker::PhantomData<C>,
}
impl<'a, 'b, C> Iterator for RulesIterator<'a, 'b, C> where 'b: 'a,
C: NestedRuleIterationCondition + 'static,
{ type Item = &'a CssRule;
fn next(&mutself) -> Option<Self::Item> { 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.guard,
&mut effective,
); if !effective { continue;
}
iflet Some(children) = children { // NOTE: It's important that `children` gets pushed even if // empty, so that `skip_children()` works as expected. self.stack.push(children);
}
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,
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,
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> = RulesIterator<'a, 'b, EffectiveRules>;
impl<'a, 'b> EffectiveRulesIterator<'a, 'b> { /// 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,
guard: &'a SharedRwLockReadGuard<'b>,
rule: &'a CssRule,
) -> Self { let children =
RulesIterator::<AllRules>::children(rule, device, quirks_mode, guard, &mutfalse);
EffectiveRulesIterator::new(device, quirks_mode, guard, children.unwrap_or([].iter()))
}
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.12 Sekunden
(vorverarbeitet am 2026-06-18)
¤
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.