diff --git a/components/script/dom/cssstyledeclaration.rs b/components/script/dom/cssstyledeclaration.rs index dc53a58c8c5..8af3b3975d2 100644 --- a/components/script/dom/cssstyledeclaration.rs +++ b/components/script/dom/cssstyledeclaration.rs @@ -67,7 +67,7 @@ impl CSSStyleOwner { // Here `changed` is somewhat silly, because we know the // exact conditions under it changes. - changed = !pdb.declarations.is_empty(); + changed = !pdb.declarations().is_empty(); if changed { attr = Some(Arc::new(RwLock::new(pdb))); } @@ -274,7 +274,7 @@ impl CSSStyleDeclarationMethods for CSSStyleDeclaration { // https://dev.w3.org/csswg/cssom/#dom-cssstyledeclaration-length fn Length(&self) -> u32 { self.owner.with_block(|pdb| { - pdb.declarations.len() as u32 + pdb.declarations().len() as u32 }) } @@ -399,7 +399,7 @@ impl CSSStyleDeclarationMethods for CSSStyleDeclaration { // https://dev.w3.org/csswg/cssom/#the-cssstyledeclaration-interface fn IndexedGetter(&self, index: u32) -> Option { self.owner.with_block(|pdb| { - pdb.declarations.get(index as usize).map(|entry| { + pdb.declarations().get(index as usize).map(|entry| { let (ref declaration, importance) = *entry; let mut css = declaration.to_css_string(); if importance.important() { diff --git a/components/style/animation.rs b/components/style/animation.rs index aa115527d57..bebda0e6339 100644 --- a/components/style/animation.rs +++ b/components/style/animation.rs @@ -418,11 +418,11 @@ fn compute_style_for_animation_step(context: &SharedStyleContext, let guard = declarations.read(); // No !important in keyframes. - debug_assert!(guard.declarations.iter() + debug_assert!(guard.declarations().iter() .all(|&(_, importance)| importance == Importance::Normal)); let iter = || { - guard.declarations.iter().rev().map(|&(ref decl, _importance)| decl) + guard.declarations().iter().rev().map(|&(ref decl, _importance)| decl) }; let computed = diff --git a/components/style/keyframes.rs b/components/style/keyframes.rs index 77cf7cc814d..31ba401cddb 100644 --- a/components/style/keyframes.rs +++ b/components/style/keyframes.rs @@ -181,7 +181,7 @@ impl KeyframesStep { value: KeyframesStepValue) -> Self { let declared_timing_function = match value { KeyframesStepValue::Declarations { ref block } => { - block.read().declarations.iter().any(|&(ref prop_decl, _)| { + block.read().declarations().iter().any(|&(ref prop_decl, _)| { match *prop_decl { PropertyDeclaration::AnimationTimingFunction(..) => true, _ => false, @@ -249,7 +249,7 @@ fn get_animated_properties(keyframes: &[Arc>]) -> Vec Self { - Importance::Normal - } -} - /// Overridden declarations are skipped. #[derive(Debug, PartialEq, Clone)] pub struct PropertyDeclarationBlock { /// The group of declarations, along with their importance. /// /// Only deduplicated declarations appear here. - pub declarations: Vec<(PropertyDeclaration, Importance)>, + declarations: Vec<(PropertyDeclaration, Importance)>, /// The number of entries in `self.declaration` with `Importance::Important` important_count: usize, @@ -76,6 +69,11 @@ impl PropertyDeclarationBlock { } } + /// The declarations in this block + pub fn declarations(&self) -> &[(PropertyDeclaration, Importance)] { + &self.declarations + } + /// Returns wheather this block contains any declaration with `!important`. /// /// This is based on the `important_count` counter, diff --git a/components/style/properties/properties.mako.rs b/components/style/properties/properties.mako.rs index 74b28d25d95..849cb74e965 100644 --- a/components/style/properties/properties.mako.rs +++ b/components/style/properties/properties.mako.rs @@ -1817,7 +1817,7 @@ pub fn cascade(viewport_size: Size2D, }).collect::>(); let iter_declarations = || { lock_guards.iter().flat_map(|&(ref source, source_importance)| { - source.declarations.iter() + source.declarations().iter() // Yield declarations later in source order (with more precedence) first. .rev() .filter_map(move |&(ref declaration, declaration_importance)| { diff --git a/components/style/rule_tree/mod.rs b/components/style/rule_tree/mod.rs index 1ecd0a0cb14..9a725a19286 100644 --- a/components/style/rule_tree/mod.rs +++ b/components/style/rule_tree/mod.rs @@ -99,7 +99,7 @@ impl StyleSource { let _ = write!(writer, "{:?}", rule.read().selectors); } - let _ = write!(writer, " -> {:?}", self.read().declarations); + let _ = write!(writer, " -> {:?}", self.read().declarations()); } /// Read the style source guard, and obtain thus read access to the diff --git a/components/style/stylesheets.rs b/components/style/stylesheets.rs index 758d81125b2..cc72acd4c15 100644 --- a/components/style/stylesheets.rs +++ b/components/style/stylesheets.rs @@ -534,7 +534,7 @@ impl ToCss for StyleRule { let declaration_block = self.block.read(); try!(declaration_block.to_css(dest)); // Step 4 - if declaration_block.declarations.len() > 0 { + if declaration_block.declarations().len() > 0 { try!(write!(dest, " ")); } // Step 5 @@ -952,7 +952,7 @@ impl<'a> QualifiedRuleParser for TopLevelRuleParser<'a> { } } -#[derive(Clone)] // shallow, relatively cheap clone +#[derive(Clone)] // shallow, relatively cheap .clone struct NestedRuleParser<'a, 'b: 'a> { stylesheet_origin: Origin, context: &'a ParserContext<'b>, diff --git a/ports/geckolib/glue.rs b/ports/geckolib/glue.rs index 31bf032fc21..509e7efe316 100644 --- a/ports/geckolib/glue.rs +++ b/ports/geckolib/glue.rs @@ -765,14 +765,14 @@ pub extern "C" fn Servo_DeclarationBlock_SerializeOneValue( #[no_mangle] pub extern "C" fn Servo_DeclarationBlock_Count(declarations: RawServoDeclarationBlockBorrowed) -> u32 { let declarations = RwLock::::as_arc(&declarations); - declarations.read().declarations.len() as u32 + declarations.read().declarations().len() as u32 } #[no_mangle] pub extern "C" fn Servo_DeclarationBlock_GetNthProperty(declarations: RawServoDeclarationBlockBorrowed, index: u32, result: *mut nsAString) -> bool { let declarations = RwLock::::as_arc(&declarations); - if let Some(&(ref decl, _)) = declarations.read().declarations.get(index as usize) { + if let Some(&(ref decl, _)) = declarations.read().declarations().get(index as usize) { let result = unsafe { result.as_mut().unwrap() }; decl.id().to_css(result).unwrap(); true @@ -923,7 +923,7 @@ pub extern "C" fn Servo_DeclarationBlock_SetIdentStringValue(declarations: let prop = match_wrap_declared! { long, XLang => Lang(Atom::from(value)), }; - declarations.write().declarations.push((prop, Default::default())); + declarations.write().push(prop, Importance::Normal); } #[no_mangle] @@ -960,7 +960,7 @@ pub extern "C" fn Servo_DeclarationBlock_SetKeywordValue(declarations: BorderBottomStyle => BorderStyle::from_gecko_keyword(value), BorderLeftStyle => BorderStyle::from_gecko_keyword(value), }; - declarations.write().declarations.push((prop, Default::default())); + declarations.write().push(prop, Importance::Normal); } #[no_mangle] @@ -975,7 +975,7 @@ pub extern "C" fn Servo_DeclarationBlock_SetIntValue(declarations: RawServoDecla let prop = match_wrap_declared! { long, XSpan => Span(value), }; - declarations.write().declarations.push((prop, Default::default())); + declarations.write().push(prop, Importance::Normal); } #[no_mangle] @@ -1014,7 +1014,7 @@ pub extern "C" fn Servo_DeclarationBlock_SetPixelValue(declarations: } ), }; - declarations.write().declarations.push((prop, Default::default())); + declarations.write().push(prop, Importance::Normal); } #[no_mangle] @@ -1037,7 +1037,7 @@ pub extern "C" fn Servo_DeclarationBlock_SetPercentValue(declarations: MarginBottom => pc.into(), MarginLeft => pc.into(), }; - declarations.write().declarations.push((prop, Default::default())); + declarations.write().push(prop, Importance::Normal); } #[no_mangle] @@ -1059,7 +1059,7 @@ pub extern "C" fn Servo_DeclarationBlock_SetAutoValue(declarations: MarginBottom => auto, MarginLeft => auto, }; - declarations.write().declarations.push((prop, Default::default())); + declarations.write().push(prop, Importance::Normal); } #[no_mangle] @@ -1080,7 +1080,7 @@ pub extern "C" fn Servo_DeclarationBlock_SetCurrentColor(declarations: BorderBottomColor => cc, BorderLeftColor => cc, }; - declarations.write().declarations.push((prop, Default::default())); + declarations.write().push(prop, Importance::Normal); } #[no_mangle] @@ -1107,7 +1107,7 @@ pub extern "C" fn Servo_DeclarationBlock_SetColorValue(declarations: Color => longhands::color::SpecifiedValue(color), BackgroundColor => color, }; - declarations.write().declarations.push((prop, Default::default())); + declarations.write().push(prop, Importance::Normal); } #[no_mangle] @@ -1124,7 +1124,7 @@ pub extern "C" fn Servo_DeclarationBlock_SetFontFamily(declarations: if let Ok(family) = FontFamily::parse(&mut parser) { if parser.is_exhausted() { let decl = PropertyDeclaration::FontFamily(DeclaredValue::Value(family)); - declarations.write().declarations.push((decl, Default::default())); + declarations.write().push(decl, Importance::Normal); } } } @@ -1139,7 +1139,7 @@ pub extern "C" fn Servo_DeclarationBlock_SetTextDecorationColorOverride(declarat let mut decoration = text_decoration_line::computed_value::none; decoration |= text_decoration_line::COLOR_OVERRIDE; let decl = PropertyDeclaration::TextDecorationLine(DeclaredValue::Value(decoration)); - declarations.write().declarations.push((decl, Default::default())); + declarations.write().push(decl, Importance::Normal); } #[no_mangle] @@ -1356,7 +1356,7 @@ pub extern "C" fn Servo_GetComputedKeyframeValues(keyframes: RawGeckoKeyframeLis let declarations = RwLock::::as_arc(&declarations); let guard = declarations.read(); - let anim_iter = guard.declarations + let anim_iter = guard.declarations() .iter() .filter_map(|&(ref decl, imp)| { if imp == Importance::Normal { @@ -1463,7 +1463,7 @@ pub extern "C" fn Servo_StyleSet_FillKeyframesForName(raw_data: RawServoStyleSet let guard = block.read(); // Filter out non-animatable properties. let animatable = - guard.declarations + guard.declarations() .iter() .filter(|&&(ref declaration, _)| { declaration.is_animatable()