diff options
author | Simon Sapin <simon.sapin@exyr.org> | 2014-08-12 14:38:34 +0100 |
---|---|---|
committer | Simon Sapin <simon.sapin@exyr.org> | 2014-08-16 08:31:22 +0100 |
commit | 1cbe73c5833943d1f7704d784d7b83b5ed6aef8e (patch) | |
tree | 4d4a320778d7bb99c8ea1743165f7666430c576b | |
parent | 58ed502b7f4de990ab00d7feaf4df5547948f23f (diff) | |
download | servo-1cbe73c5833943d1f7704d784d7b83b5ed6aef8e.tar.gz servo-1cbe73c5833943d1f7704d784d7b83b5ed6aef8e.zip |
Rename MatchedProperty to DeclarationBlock
-rw-r--r-- | src/components/layout/css/matching.rs | 24 | ||||
-rw-r--r-- | src/components/style/properties/mod.rs.mako | 6 | ||||
-rw-r--r-- | src/components/style/selector_matching.rs | 56 | ||||
-rw-r--r-- | src/components/style/style.rs | 2 |
4 files changed, 44 insertions, 44 deletions
diff --git a/src/components/layout/css/matching.rs b/src/components/layout/css/matching.rs index 3c7ee0d9a4c..c1d766c32ca 100644 --- a/src/components/layout/css/matching.rs +++ b/src/components/layout/css/matching.rs @@ -19,13 +19,13 @@ use servo_util::str::DOMString; use std::mem; use std::hash::{Hash, sip}; use std::slice::Items; -use style::{After, Before, ComputedValues, MatchedProperty, Stylist, TElement, TNode, cascade}; +use style::{After, Before, ComputedValues, DeclarationBlock, Stylist, TElement, TNode, cascade}; use sync::Arc; pub struct ApplicableDeclarations { - pub normal: SmallVec16<MatchedProperty>, - pub before: Vec<MatchedProperty>, - pub after: Vec<MatchedProperty>, + pub normal: SmallVec16<DeclarationBlock>, + pub before: Vec<DeclarationBlock>, + pub after: Vec<DeclarationBlock>, /// Whether the `normal` declarations are shareable with other nodes. pub normal_shareable: bool, @@ -51,11 +51,11 @@ impl ApplicableDeclarations { #[deriving(Clone)] pub struct ApplicableDeclarationsCacheEntry { - pub declarations: Vec<MatchedProperty>, + pub declarations: Vec<DeclarationBlock>, } impl ApplicableDeclarationsCacheEntry { - fn new(slice: &[MatchedProperty]) -> ApplicableDeclarationsCacheEntry { + fn new(slice: &[DeclarationBlock]) -> ApplicableDeclarationsCacheEntry { let mut entry_declarations = Vec::new(); for declarations in slice.iter() { entry_declarations.push(declarations.clone()); @@ -81,11 +81,11 @@ impl Hash for ApplicableDeclarationsCacheEntry { } struct ApplicableDeclarationsCacheQuery<'a> { - declarations: &'a [MatchedProperty], + declarations: &'a [DeclarationBlock], } impl<'a> ApplicableDeclarationsCacheQuery<'a> { - fn new(declarations: &'a [MatchedProperty]) -> ApplicableDeclarationsCacheQuery<'a> { + fn new(declarations: &'a [DeclarationBlock]) -> ApplicableDeclarationsCacheQuery<'a> { ApplicableDeclarationsCacheQuery { declarations: declarations, } @@ -141,14 +141,14 @@ impl ApplicableDeclarationsCache { } } - fn find(&self, declarations: &[MatchedProperty]) -> Option<Arc<ComputedValues>> { + fn find(&self, declarations: &[DeclarationBlock]) -> Option<Arc<ComputedValues>> { match self.cache.find_equiv(&ApplicableDeclarationsCacheQuery::new(declarations)) { None => None, Some(ref values) => Some((*values).clone()), } } - fn insert(&mut self, declarations: &[MatchedProperty], style: Arc<ComputedValues>) { + fn insert(&mut self, declarations: &[DeclarationBlock], style: Arc<ComputedValues>) { self.cache.insert(ApplicableDeclarationsCacheEntry::new(declarations), style) } } @@ -309,7 +309,7 @@ pub trait MatchMethods { trait PrivateMatchMethods { fn cascade_node_pseudo_element(&self, parent_style: Option<&Arc<ComputedValues>>, - applicable_declarations: &[MatchedProperty], + applicable_declarations: &[DeclarationBlock], style: &mut Option<Arc<ComputedValues>>, applicable_declarations_cache: &mut ApplicableDeclarationsCache, @@ -324,7 +324,7 @@ trait PrivateMatchMethods { impl<'ln> PrivateMatchMethods for LayoutNode<'ln> { fn cascade_node_pseudo_element(&self, parent_style: Option<&Arc<ComputedValues>>, - applicable_declarations: &[MatchedProperty], + applicable_declarations: &[DeclarationBlock], style: &mut Option<Arc<ComputedValues>>, applicable_declarations_cache: &mut ApplicableDeclarationsCache, diff --git a/src/components/style/properties/mod.rs.mako b/src/components/style/properties/mod.rs.mako index f5fc43eb34f..60cf11270d8 100644 --- a/src/components/style/properties/mod.rs.mako +++ b/src/components/style/properties/mod.rs.mako @@ -18,7 +18,7 @@ pub use geom::SideOffsets2D; use errors::{ErrorLoggerIterator, log_css_error}; pub use parsing_utils::*; pub use self::common_types::*; -use selector_matching::MatchedProperty; +use selector_matching::DeclarationBlock; pub use self::property_bit_field::PropertyBitField; @@ -1800,7 +1800,7 @@ impl<T: Send + Share + Clone> ArcExperimental<T> for Arc<T> { } /// Fast path for the function below. Only computes new inherited styles. -fn cascade_with_cached_declarations(applicable_declarations: &[MatchedProperty], +fn cascade_with_cached_declarations(applicable_declarations: &[DeclarationBlock], shareable: bool, parent_style: &ComputedValues, cached_style: &ComputedValues, @@ -1905,7 +1905,7 @@ fn cascade_with_cached_declarations(applicable_declarations: &[MatchedProperty], /// this is ignored. /// /// Returns the computed values and a boolean indicating whether the result is cacheable. -pub fn cascade(applicable_declarations: &[MatchedProperty], +pub fn cascade(applicable_declarations: &[DeclarationBlock], shareable: bool, parent_style: Option< &ComputedValues >, cached_style: Option< &ComputedValues >) diff --git a/src/components/style/selector_matching.rs b/src/components/style/selector_matching.rs index 86b3cd9e058..f63bc47eff1 100644 --- a/src/components/style/selector_matching.rs +++ b/src/components/style/selector_matching.rs @@ -74,7 +74,7 @@ impl SelectorMap { /// Sort the Rules at the end to maintain cascading order. fn get_all_matching_rules<E:TElement, N:TNode<E>, - V:VecLike<MatchedProperty>>( + V:VecLike<DeclarationBlock>>( &self, node: &N, matching_rules_list: &mut V, @@ -130,7 +130,7 @@ impl SelectorMap { fn get_matching_rules_from_hash<E:TElement, N:TNode<E>, - V:VecLike<MatchedProperty>>( + V:VecLike<DeclarationBlock>>( node: &N, hash: &HashMap<Atom, Vec<Rule>>, key: &Atom, @@ -146,7 +146,7 @@ impl SelectorMap { fn get_matching_rules_from_hash_ignoring_case<E:TElement, N:TNode<E>, - V:VecLike<MatchedProperty>>( + V:VecLike<DeclarationBlock>>( node: &N, hash: &HashMap<Atom, Vec<Rule>>, key: &str, @@ -164,7 +164,7 @@ impl SelectorMap { /// Adds rules in `rules` that match `node` to the `matching_rules` list. fn get_matching_rules<E:TElement, N:TNode<E>, - V:VecLike<MatchedProperty>>( + V:VecLike<DeclarationBlock>>( node: &N, rules: &[Rule], matching_rules: &mut V, @@ -172,7 +172,7 @@ impl SelectorMap { for rule in rules.iter() { if matches_compound_selector(&*rule.selector, node, shareable) { // TODO(pradeep): Is the cloning inefficient? - matching_rules.vec_push(rule.property.clone()); + matching_rules.vec_push(rule.declarations.clone()); } } } @@ -325,7 +325,7 @@ impl Stylist { }; map.$priority.insert(Rule { selector: selector.compound_selectors.clone(), - property: MatchedProperty { + declarations: DeclarationBlock { specificity: selector.specificity, declarations: $style_rule.declarations.$priority.clone(), source_order: rules_source_order, @@ -353,7 +353,7 @@ impl Stylist { /// in `css::matching::PrivateMatchMethods::candidate_element_allows_for_style_sharing`. pub fn push_applicable_declarations<E:TElement, N:TNode<E>, - V:VecLike<MatchedProperty>>( + V:VecLike<DeclarationBlock>>( &self, element: &N, style_attribute: Option<&PropertyDeclarationBlock>, @@ -382,7 +382,7 @@ impl Stylist { // Step 2: Normal style attributes. style_attribute.map(|sa| { shareable = false; - applicable_declarations.vec_push(MatchedProperty::from_declarations(sa.normal.clone())) + applicable_declarations.vec_push(DeclarationBlock::from_declarations(sa.normal.clone())) }); // Step 3: Author-supplied `!important` rules. @@ -393,7 +393,7 @@ impl Stylist { // Step 4: `!important` style attributes. style_attribute.map(|sa| { shareable = false; - applicable_declarations.vec_push(MatchedProperty::from_declarations(sa.important.clone())) + applicable_declarations.vec_push(DeclarationBlock::from_declarations(sa.important.clone())) }); // Step 5: User and UA `!important` rules. @@ -446,22 +446,22 @@ struct Rule { // that it matches. Selector contains an owned vector (through // CompoundSelector) and we want to avoid the allocation. selector: Arc<CompoundSelector>, - property: MatchedProperty, + declarations: DeclarationBlock, } /// A property declaration together with its precedence among rules of equal specificity so that /// we can sort them. #[deriving(Clone)] -pub struct MatchedProperty { +pub struct DeclarationBlock { pub declarations: Arc<Vec<PropertyDeclaration>>, source_order: uint, specificity: u32, } -impl MatchedProperty { +impl DeclarationBlock { #[inline] - pub fn from_declarations(declarations: Arc<Vec<PropertyDeclaration>>) -> MatchedProperty { - MatchedProperty { + pub fn from_declarations(declarations: Arc<Vec<PropertyDeclaration>>) -> DeclarationBlock { + DeclarationBlock { declarations: declarations, source_order: 0, specificity: 0, @@ -469,29 +469,29 @@ impl MatchedProperty { } } -impl PartialEq for MatchedProperty { +impl PartialEq for DeclarationBlock { #[inline] - fn eq(&self, other: &MatchedProperty) -> bool { + fn eq(&self, other: &DeclarationBlock) -> bool { let this_rank = (self.specificity, self.source_order); let other_rank = (other.specificity, other.source_order); this_rank == other_rank } } -impl Eq for MatchedProperty {} +impl Eq for DeclarationBlock {} -impl PartialOrd for MatchedProperty { +impl PartialOrd for DeclarationBlock { #[inline] - fn partial_cmp(&self, other: &MatchedProperty) -> Option<Ordering> { + fn partial_cmp(&self, other: &DeclarationBlock) -> Option<Ordering> { let this_rank = (self.specificity, self.source_order); let other_rank = (other.specificity, other.source_order); this_rank.partial_cmp(&other_rank) } } -impl Ord for MatchedProperty { +impl Ord for DeclarationBlock { #[inline] - fn cmp(&self, other: &MatchedProperty) -> Ordering { + fn cmp(&self, other: &DeclarationBlock) -> Ordering { let this_rank = (self.specificity, self.source_order); let other_rank = (other.specificity, other.source_order); this_rank.cmp(&other_rank) @@ -938,7 +938,7 @@ fn matches_last_child<E:TElement,N:TNode<E>>(element: &N) -> bool { mod tests { use servo_util::atom::Atom; use sync::Arc; - use super::{MatchedProperty, Rule, SelectorMap}; + use super::{DeclarationBlock, Rule, SelectorMap}; /// Helper method to get some Rules from selector strings. /// Each sublist of the result contains the Rules for one StyleRule. @@ -953,7 +953,7 @@ mod tests { .unwrap().move_iter().map(|s| { Rule { selector: s.compound_selectors.clone(), - property: MatchedProperty { + declarations: DeclarationBlock { specificity: s.specificity, declarations: Arc::new(vec!()), source_order: i, @@ -966,9 +966,9 @@ mod tests { #[test] fn test_rule_ordering_same_specificity(){ let rules_list = get_mock_rules(["a.intro", "img.sidebar"]); - let rule1 = rules_list[0][0].clone(); - let rule2 = rules_list[1][0].clone(); - assert!(rule1.property < rule2.property, "The rule that comes later should win."); + let a = &rules_list[0][0].declarations; + let b = &rules_list[1][0].declarations; + assert!(a < b, "The rule that comes later should win."); } #[test] @@ -999,9 +999,9 @@ mod tests { let rules_list = get_mock_rules([".intro.foo", "#top"]); let mut selector_map = SelectorMap::new(); selector_map.insert(rules_list[1][0].clone()); - assert_eq!(1, selector_map.id_hash.find(&Atom::from_slice("top")).unwrap()[0].property.source_order); + assert_eq!(1, selector_map.id_hash.find(&Atom::from_slice("top")).unwrap()[0].declarations.source_order); selector_map.insert(rules_list[0][0].clone()); - assert_eq!(0, selector_map.class_hash.find(&Atom::from_slice("intro")).unwrap()[0].property.source_order); + assert_eq!(0, selector_map.class_hash.find(&Atom::from_slice("intro")).unwrap()[0].declarations.source_order); assert!(selector_map.class_hash.find(&Atom::from_slice("foo")).is_none()); } } diff --git a/src/components/style/style.rs b/src/components/style/style.rs index 1c52bbb2771..5b203d54345 100644 --- a/src/components/style/style.rs +++ b/src/components/style/style.rs @@ -32,7 +32,7 @@ extern crate servo_util = "util"; // Public API pub use stylesheets::{Stylesheet, CSSRule, StyleRule, CSSFontFaceRule}; pub use selector_matching::{Stylist, StylesheetOrigin, UserAgentOrigin, AuthorOrigin, UserOrigin}; -pub use selector_matching::{MatchedProperty, matches_compound_selector}; +pub use selector_matching::{DeclarationBlock, matches_compound_selector}; pub use properties::{cascade, cascade_anonymous}; pub use properties::{PropertyDeclaration, ComputedValues, computed_values, style_structs}; pub use properties::{PropertyDeclarationBlock, parse_style_attribute}; // Style attributes |