Make PropertyDeclarationBlock fields private

This commit is contained in:
Simon Sapin 2017-03-07 19:30:51 +01:00
parent da4e5146e9
commit f70a49974a
8 changed files with 31 additions and 33 deletions

View file

@ -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<DOMString> {
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() {

View file

@ -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 =

View file

@ -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<RwLock<Keyframe>>]) -> Vec<Transitio
// it here.
for keyframe in keyframes {
let keyframe = keyframe.read();
for &(ref declaration, importance) in keyframe.block.read().declarations.iter() {
for &(ref declaration, importance) in keyframe.block.read().declarations().iter() {
assert!(!importance.important());
if let Some(property) = TransitionProperty::from_declaration(declaration) {

View file

@ -40,20 +40,13 @@ impl Importance {
}
}
impl Default for Importance {
#[inline]
fn default() -> 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,

View file

@ -1817,7 +1817,7 @@ pub fn cascade(viewport_size: Size2D<Au>,
}).collect::<Vec<_>>();
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)| {

View file

@ -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

View file

@ -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>,