aboutsummaryrefslogtreecommitdiffstats
path: root/components/style/properties/declaration_block.rs
diff options
context:
space:
mode:
Diffstat (limited to 'components/style/properties/declaration_block.rs')
-rw-r--r--components/style/properties/declaration_block.rs77
1 files changed, 17 insertions, 60 deletions
diff --git a/components/style/properties/declaration_block.rs b/components/style/properties/declaration_block.rs
index ad5aa75e8f2..56aa2fde4f4 100644
--- a/components/style/properties/declaration_block.rs
+++ b/components/style/properties/declaration_block.rs
@@ -138,56 +138,9 @@ impl<'a> DoubleEndedIterator for DeclarationImportanceIterator<'a> {
}
}
-/// Iterator over `PropertyDeclaration` for Importance::Normal.
-///
-/// TODO(emilio): This should be replaced by `impl Trait`, returning a
-/// filter()ed iterator when available instead, and all the boilerplate below
-/// should go.
-pub struct NormalDeclarationIterator<'a>(DeclarationImportanceIterator<'a>);
-
-impl<'a> NormalDeclarationIterator<'a> {
- #[inline]
- fn new(declarations: &'a [PropertyDeclaration], important: &'a SmallBitVec) -> Self {
- NormalDeclarationIterator(
- DeclarationImportanceIterator::new(declarations, important)
- )
- }
-}
-
-impl<'a> Iterator for NormalDeclarationIterator<'a> {
- type Item = &'a PropertyDeclaration;
-
- #[inline]
- fn next(&mut self) -> Option<Self::Item> {
- loop {
- let (decl, importance) = self.0.iter.next()?;
- if !importance {
- return Some(decl);
- }
- }
- }
-
- #[inline]
- fn size_hint(&self) -> (usize, Option<usize>) {
- self.0.iter.size_hint()
- }
-}
-
-impl<'a> DoubleEndedIterator for NormalDeclarationIterator<'a> {
- #[inline]
- fn next_back(&mut self) -> Option<Self::Item> {
- loop {
- let (decl, importance) = self.0.iter.next_back()?;
- if !importance {
- return Some(decl);
- }
- }
- }
-}
-
/// Iterator for AnimationValue to be generated from PropertyDeclarationBlock.
pub struct AnimationValueIterator<'a, 'cx, 'cx_a:'cx> {
- iter: NormalDeclarationIterator<'a>,
+ iter: DeclarationImportanceIterator<'a>,
context: &'cx mut Context<'cx_a>,
default_values: &'a ComputedValues,
/// Custom properties in a keyframe if exists.
@@ -202,7 +155,7 @@ impl<'a, 'cx, 'cx_a:'cx> AnimationValueIterator<'a, 'cx, 'cx_a> {
extra_custom_properties: Option<&'a Arc<::custom_properties::CustomPropertiesMap>>,
) -> AnimationValueIterator<'a, 'cx, 'cx_a> {
AnimationValueIterator {
- iter: declarations.normal_declaration_iter(),
+ iter: declarations.declaration_importance_iter(),
context,
default_values,
extra_custom_properties,
@@ -215,7 +168,11 @@ impl<'a, 'cx, 'cx_a:'cx> Iterator for AnimationValueIterator<'a, 'cx, 'cx_a> {
#[inline]
fn next(&mut self) -> Option<Self::Item> {
loop {
- let decl = self.iter.next()?;
+ let (decl, importance) = self.iter.next()?;
+
+ if importance.important() {
+ continue;
+ }
let animation = AnimationValue::from_declaration(
decl,
@@ -287,8 +244,12 @@ impl PropertyDeclarationBlock {
/// Iterate over `PropertyDeclaration` for Importance::Normal
#[inline]
- pub fn normal_declaration_iter(&self) -> NormalDeclarationIterator {
- NormalDeclarationIterator::new(&self.declarations, &self.declarations_importance)
+ pub fn normal_declaration_iter<'a>(
+ &'a self,
+ ) -> impl DoubleEndedIterator<Item = &'a PropertyDeclaration> {
+ self.declaration_importance_iter()
+ .filter(|(_, importance)| !importance.important())
+ .map(|(declaration, _)| declaration)
}
/// Return an iterator of (AnimatableLonghand, AnimationValue).
@@ -344,14 +305,8 @@ impl PropertyDeclarationBlock {
}
}
- self.declarations.iter().enumerate().find(|&(_, decl)| decl.id() == property).map(|(i, decl)| {
- let importance = if self.declarations_importance[i] {
- Importance::Important
- } else {
- Importance::Normal
- };
- (decl, importance)
- })
+ self.declaration_importance_iter()
+ .find(|(declaration, _)| declaration.id() == property)
}
fn shorthand_to_css(
@@ -1248,6 +1203,7 @@ pub fn parse_style_attribute(
ParsingMode::DEFAULT,
quirks_mode,
error_reporter,
+ None,
);
let mut input = ParserInput::new(input);
@@ -1275,6 +1231,7 @@ pub fn parse_one_declaration_into(
parsing_mode,
quirks_mode,
error_reporter,
+ None,
);
let mut input = ParserInput::new(input);