mirror of
https://github.com/servo/servo.git
synced 2025-06-18 13:24:29 +00:00
Make PropertyDeclarationBlock fields private
This commit is contained in:
parent
da4e5146e9
commit
f70a49974a
8 changed files with 31 additions and 33 deletions
|
@ -67,7 +67,7 @@ impl CSSStyleOwner {
|
||||||
|
|
||||||
// Here `changed` is somewhat silly, because we know the
|
// Here `changed` is somewhat silly, because we know the
|
||||||
// exact conditions under it changes.
|
// exact conditions under it changes.
|
||||||
changed = !pdb.declarations.is_empty();
|
changed = !pdb.declarations().is_empty();
|
||||||
if changed {
|
if changed {
|
||||||
attr = Some(Arc::new(RwLock::new(pdb)));
|
attr = Some(Arc::new(RwLock::new(pdb)));
|
||||||
}
|
}
|
||||||
|
@ -274,7 +274,7 @@ impl CSSStyleDeclarationMethods for CSSStyleDeclaration {
|
||||||
// https://dev.w3.org/csswg/cssom/#dom-cssstyledeclaration-length
|
// https://dev.w3.org/csswg/cssom/#dom-cssstyledeclaration-length
|
||||||
fn Length(&self) -> u32 {
|
fn Length(&self) -> u32 {
|
||||||
self.owner.with_block(|pdb| {
|
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
|
// https://dev.w3.org/csswg/cssom/#the-cssstyledeclaration-interface
|
||||||
fn IndexedGetter(&self, index: u32) -> Option<DOMString> {
|
fn IndexedGetter(&self, index: u32) -> Option<DOMString> {
|
||||||
self.owner.with_block(|pdb| {
|
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 (ref declaration, importance) = *entry;
|
||||||
let mut css = declaration.to_css_string();
|
let mut css = declaration.to_css_string();
|
||||||
if importance.important() {
|
if importance.important() {
|
||||||
|
|
|
@ -418,11 +418,11 @@ fn compute_style_for_animation_step(context: &SharedStyleContext,
|
||||||
let guard = declarations.read();
|
let guard = declarations.read();
|
||||||
|
|
||||||
// No !important in keyframes.
|
// No !important in keyframes.
|
||||||
debug_assert!(guard.declarations.iter()
|
debug_assert!(guard.declarations().iter()
|
||||||
.all(|&(_, importance)| importance == Importance::Normal));
|
.all(|&(_, importance)| importance == Importance::Normal));
|
||||||
|
|
||||||
let iter = || {
|
let iter = || {
|
||||||
guard.declarations.iter().rev().map(|&(ref decl, _importance)| decl)
|
guard.declarations().iter().rev().map(|&(ref decl, _importance)| decl)
|
||||||
};
|
};
|
||||||
|
|
||||||
let computed =
|
let computed =
|
||||||
|
|
|
@ -181,7 +181,7 @@ impl KeyframesStep {
|
||||||
value: KeyframesStepValue) -> Self {
|
value: KeyframesStepValue) -> Self {
|
||||||
let declared_timing_function = match value {
|
let declared_timing_function = match value {
|
||||||
KeyframesStepValue::Declarations { ref block } => {
|
KeyframesStepValue::Declarations { ref block } => {
|
||||||
block.read().declarations.iter().any(|&(ref prop_decl, _)| {
|
block.read().declarations().iter().any(|&(ref prop_decl, _)| {
|
||||||
match *prop_decl {
|
match *prop_decl {
|
||||||
PropertyDeclaration::AnimationTimingFunction(..) => true,
|
PropertyDeclaration::AnimationTimingFunction(..) => true,
|
||||||
_ => false,
|
_ => false,
|
||||||
|
@ -249,7 +249,7 @@ fn get_animated_properties(keyframes: &[Arc<RwLock<Keyframe>>]) -> Vec<Transitio
|
||||||
// it here.
|
// it here.
|
||||||
for keyframe in keyframes {
|
for keyframe in keyframes {
|
||||||
let keyframe = keyframe.read();
|
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());
|
assert!(!importance.important());
|
||||||
|
|
||||||
if let Some(property) = TransitionProperty::from_declaration(declaration) {
|
if let Some(property) = TransitionProperty::from_declaration(declaration) {
|
||||||
|
|
|
@ -40,20 +40,13 @@ impl Importance {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Importance {
|
|
||||||
#[inline]
|
|
||||||
fn default() -> Self {
|
|
||||||
Importance::Normal
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Overridden declarations are skipped.
|
/// Overridden declarations are skipped.
|
||||||
#[derive(Debug, PartialEq, Clone)]
|
#[derive(Debug, PartialEq, Clone)]
|
||||||
pub struct PropertyDeclarationBlock {
|
pub struct PropertyDeclarationBlock {
|
||||||
/// The group of declarations, along with their importance.
|
/// The group of declarations, along with their importance.
|
||||||
///
|
///
|
||||||
/// Only deduplicated declarations appear here.
|
/// Only deduplicated declarations appear here.
|
||||||
pub declarations: Vec<(PropertyDeclaration, Importance)>,
|
declarations: Vec<(PropertyDeclaration, Importance)>,
|
||||||
|
|
||||||
/// The number of entries in `self.declaration` with `Importance::Important`
|
/// The number of entries in `self.declaration` with `Importance::Important`
|
||||||
important_count: usize,
|
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`.
|
/// Returns wheather this block contains any declaration with `!important`.
|
||||||
///
|
///
|
||||||
/// This is based on the `important_count` counter,
|
/// This is based on the `important_count` counter,
|
||||||
|
|
|
@ -1817,7 +1817,7 @@ pub fn cascade(viewport_size: Size2D<Au>,
|
||||||
}).collect::<Vec<_>>();
|
}).collect::<Vec<_>>();
|
||||||
let iter_declarations = || {
|
let iter_declarations = || {
|
||||||
lock_guards.iter().flat_map(|&(ref source, source_importance)| {
|
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.
|
// Yield declarations later in source order (with more precedence) first.
|
||||||
.rev()
|
.rev()
|
||||||
.filter_map(move |&(ref declaration, declaration_importance)| {
|
.filter_map(move |&(ref declaration, declaration_importance)| {
|
||||||
|
|
|
@ -99,7 +99,7 @@ impl StyleSource {
|
||||||
let _ = write!(writer, "{:?}", rule.read().selectors);
|
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
|
/// Read the style source guard, and obtain thus read access to the
|
||||||
|
|
|
@ -534,7 +534,7 @@ impl ToCss for StyleRule {
|
||||||
let declaration_block = self.block.read();
|
let declaration_block = self.block.read();
|
||||||
try!(declaration_block.to_css(dest));
|
try!(declaration_block.to_css(dest));
|
||||||
// Step 4
|
// Step 4
|
||||||
if declaration_block.declarations.len() > 0 {
|
if declaration_block.declarations().len() > 0 {
|
||||||
try!(write!(dest, " "));
|
try!(write!(dest, " "));
|
||||||
}
|
}
|
||||||
// Step 5
|
// 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> {
|
struct NestedRuleParser<'a, 'b: 'a> {
|
||||||
stylesheet_origin: Origin,
|
stylesheet_origin: Origin,
|
||||||
context: &'a ParserContext<'b>,
|
context: &'a ParserContext<'b>,
|
||||||
|
|
|
@ -765,14 +765,14 @@ pub extern "C" fn Servo_DeclarationBlock_SerializeOneValue(
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn Servo_DeclarationBlock_Count(declarations: RawServoDeclarationBlockBorrowed) -> u32 {
|
pub extern "C" fn Servo_DeclarationBlock_Count(declarations: RawServoDeclarationBlockBorrowed) -> u32 {
|
||||||
let declarations = RwLock::<PropertyDeclarationBlock>::as_arc(&declarations);
|
let declarations = RwLock::<PropertyDeclarationBlock>::as_arc(&declarations);
|
||||||
declarations.read().declarations.len() as u32
|
declarations.read().declarations().len() as u32
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn Servo_DeclarationBlock_GetNthProperty(declarations: RawServoDeclarationBlockBorrowed,
|
pub extern "C" fn Servo_DeclarationBlock_GetNthProperty(declarations: RawServoDeclarationBlockBorrowed,
|
||||||
index: u32, result: *mut nsAString) -> bool {
|
index: u32, result: *mut nsAString) -> bool {
|
||||||
let declarations = RwLock::<PropertyDeclarationBlock>::as_arc(&declarations);
|
let declarations = RwLock::<PropertyDeclarationBlock>::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() };
|
let result = unsafe { result.as_mut().unwrap() };
|
||||||
decl.id().to_css(result).unwrap();
|
decl.id().to_css(result).unwrap();
|
||||||
true
|
true
|
||||||
|
@ -923,7 +923,7 @@ pub extern "C" fn Servo_DeclarationBlock_SetIdentStringValue(declarations:
|
||||||
let prop = match_wrap_declared! { long,
|
let prop = match_wrap_declared! { long,
|
||||||
XLang => Lang(Atom::from(value)),
|
XLang => Lang(Atom::from(value)),
|
||||||
};
|
};
|
||||||
declarations.write().declarations.push((prop, Default::default()));
|
declarations.write().push(prop, Importance::Normal);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
|
@ -960,7 +960,7 @@ pub extern "C" fn Servo_DeclarationBlock_SetKeywordValue(declarations:
|
||||||
BorderBottomStyle => BorderStyle::from_gecko_keyword(value),
|
BorderBottomStyle => BorderStyle::from_gecko_keyword(value),
|
||||||
BorderLeftStyle => 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]
|
#[no_mangle]
|
||||||
|
@ -975,7 +975,7 @@ pub extern "C" fn Servo_DeclarationBlock_SetIntValue(declarations: RawServoDecla
|
||||||
let prop = match_wrap_declared! { long,
|
let prop = match_wrap_declared! { long,
|
||||||
XSpan => Span(value),
|
XSpan => Span(value),
|
||||||
};
|
};
|
||||||
declarations.write().declarations.push((prop, Default::default()));
|
declarations.write().push(prop, Importance::Normal);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[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]
|
#[no_mangle]
|
||||||
|
@ -1037,7 +1037,7 @@ pub extern "C" fn Servo_DeclarationBlock_SetPercentValue(declarations:
|
||||||
MarginBottom => pc.into(),
|
MarginBottom => pc.into(),
|
||||||
MarginLeft => pc.into(),
|
MarginLeft => pc.into(),
|
||||||
};
|
};
|
||||||
declarations.write().declarations.push((prop, Default::default()));
|
declarations.write().push(prop, Importance::Normal);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
|
@ -1059,7 +1059,7 @@ pub extern "C" fn Servo_DeclarationBlock_SetAutoValue(declarations:
|
||||||
MarginBottom => auto,
|
MarginBottom => auto,
|
||||||
MarginLeft => auto,
|
MarginLeft => auto,
|
||||||
};
|
};
|
||||||
declarations.write().declarations.push((prop, Default::default()));
|
declarations.write().push(prop, Importance::Normal);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
|
@ -1080,7 +1080,7 @@ pub extern "C" fn Servo_DeclarationBlock_SetCurrentColor(declarations:
|
||||||
BorderBottomColor => cc,
|
BorderBottomColor => cc,
|
||||||
BorderLeftColor => cc,
|
BorderLeftColor => cc,
|
||||||
};
|
};
|
||||||
declarations.write().declarations.push((prop, Default::default()));
|
declarations.write().push(prop, Importance::Normal);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
|
@ -1107,7 +1107,7 @@ pub extern "C" fn Servo_DeclarationBlock_SetColorValue(declarations:
|
||||||
Color => longhands::color::SpecifiedValue(color),
|
Color => longhands::color::SpecifiedValue(color),
|
||||||
BackgroundColor => color,
|
BackgroundColor => color,
|
||||||
};
|
};
|
||||||
declarations.write().declarations.push((prop, Default::default()));
|
declarations.write().push(prop, Importance::Normal);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
|
@ -1124,7 +1124,7 @@ pub extern "C" fn Servo_DeclarationBlock_SetFontFamily(declarations:
|
||||||
if let Ok(family) = FontFamily::parse(&mut parser) {
|
if let Ok(family) = FontFamily::parse(&mut parser) {
|
||||||
if parser.is_exhausted() {
|
if parser.is_exhausted() {
|
||||||
let decl = PropertyDeclaration::FontFamily(DeclaredValue::Value(family));
|
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;
|
let mut decoration = text_decoration_line::computed_value::none;
|
||||||
decoration |= text_decoration_line::COLOR_OVERRIDE;
|
decoration |= text_decoration_line::COLOR_OVERRIDE;
|
||||||
let decl = PropertyDeclaration::TextDecorationLine(DeclaredValue::Value(decoration));
|
let decl = PropertyDeclaration::TextDecorationLine(DeclaredValue::Value(decoration));
|
||||||
declarations.write().declarations.push((decl, Default::default()));
|
declarations.write().push(decl, Importance::Normal);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
|
@ -1356,7 +1356,7 @@ pub extern "C" fn Servo_GetComputedKeyframeValues(keyframes: RawGeckoKeyframeLis
|
||||||
let declarations = RwLock::<PropertyDeclarationBlock>::as_arc(&declarations);
|
let declarations = RwLock::<PropertyDeclarationBlock>::as_arc(&declarations);
|
||||||
let guard = declarations.read();
|
let guard = declarations.read();
|
||||||
|
|
||||||
let anim_iter = guard.declarations
|
let anim_iter = guard.declarations()
|
||||||
.iter()
|
.iter()
|
||||||
.filter_map(|&(ref decl, imp)| {
|
.filter_map(|&(ref decl, imp)| {
|
||||||
if imp == Importance::Normal {
|
if imp == Importance::Normal {
|
||||||
|
@ -1463,7 +1463,7 @@ pub extern "C" fn Servo_StyleSet_FillKeyframesForName(raw_data: RawServoStyleSet
|
||||||
let guard = block.read();
|
let guard = block.read();
|
||||||
// Filter out non-animatable properties.
|
// Filter out non-animatable properties.
|
||||||
let animatable =
|
let animatable =
|
||||||
guard.declarations
|
guard.declarations()
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|&&(ref declaration, _)| {
|
.filter(|&&(ref declaration, _)| {
|
||||||
declaration.is_animatable()
|
declaration.is_animatable()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue