Rename MatchedProperty to DeclarationBlock

This commit is contained in:
Simon Sapin 2014-08-12 14:38:34 +01:00
parent 58ed502b7f
commit 1cbe73c583
4 changed files with 44 additions and 44 deletions

View file

@ -19,13 +19,13 @@ use servo_util::str::DOMString;
use std::mem; use std::mem;
use std::hash::{Hash, sip}; use std::hash::{Hash, sip};
use std::slice::Items; 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; use sync::Arc;
pub struct ApplicableDeclarations { pub struct ApplicableDeclarations {
pub normal: SmallVec16<MatchedProperty>, pub normal: SmallVec16<DeclarationBlock>,
pub before: Vec<MatchedProperty>, pub before: Vec<DeclarationBlock>,
pub after: Vec<MatchedProperty>, pub after: Vec<DeclarationBlock>,
/// Whether the `normal` declarations are shareable with other nodes. /// Whether the `normal` declarations are shareable with other nodes.
pub normal_shareable: bool, pub normal_shareable: bool,
@ -51,11 +51,11 @@ impl ApplicableDeclarations {
#[deriving(Clone)] #[deriving(Clone)]
pub struct ApplicableDeclarationsCacheEntry { pub struct ApplicableDeclarationsCacheEntry {
pub declarations: Vec<MatchedProperty>, pub declarations: Vec<DeclarationBlock>,
} }
impl ApplicableDeclarationsCacheEntry { impl ApplicableDeclarationsCacheEntry {
fn new(slice: &[MatchedProperty]) -> ApplicableDeclarationsCacheEntry { fn new(slice: &[DeclarationBlock]) -> ApplicableDeclarationsCacheEntry {
let mut entry_declarations = Vec::new(); let mut entry_declarations = Vec::new();
for declarations in slice.iter() { for declarations in slice.iter() {
entry_declarations.push(declarations.clone()); entry_declarations.push(declarations.clone());
@ -81,11 +81,11 @@ impl Hash for ApplicableDeclarationsCacheEntry {
} }
struct ApplicableDeclarationsCacheQuery<'a> { struct ApplicableDeclarationsCacheQuery<'a> {
declarations: &'a [MatchedProperty], declarations: &'a [DeclarationBlock],
} }
impl<'a> ApplicableDeclarationsCacheQuery<'a> { impl<'a> ApplicableDeclarationsCacheQuery<'a> {
fn new(declarations: &'a [MatchedProperty]) -> ApplicableDeclarationsCacheQuery<'a> { fn new(declarations: &'a [DeclarationBlock]) -> ApplicableDeclarationsCacheQuery<'a> {
ApplicableDeclarationsCacheQuery { ApplicableDeclarationsCacheQuery {
declarations: declarations, 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)) { match self.cache.find_equiv(&ApplicableDeclarationsCacheQuery::new(declarations)) {
None => None, None => None,
Some(ref values) => Some((*values).clone()), 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) self.cache.insert(ApplicableDeclarationsCacheEntry::new(declarations), style)
} }
} }
@ -309,7 +309,7 @@ pub trait MatchMethods {
trait PrivateMatchMethods { trait PrivateMatchMethods {
fn cascade_node_pseudo_element(&self, fn cascade_node_pseudo_element(&self,
parent_style: Option<&Arc<ComputedValues>>, parent_style: Option<&Arc<ComputedValues>>,
applicable_declarations: &[MatchedProperty], applicable_declarations: &[DeclarationBlock],
style: &mut Option<Arc<ComputedValues>>, style: &mut Option<Arc<ComputedValues>>,
applicable_declarations_cache: &mut applicable_declarations_cache: &mut
ApplicableDeclarationsCache, ApplicableDeclarationsCache,
@ -324,7 +324,7 @@ trait PrivateMatchMethods {
impl<'ln> PrivateMatchMethods for LayoutNode<'ln> { impl<'ln> PrivateMatchMethods for LayoutNode<'ln> {
fn cascade_node_pseudo_element(&self, fn cascade_node_pseudo_element(&self,
parent_style: Option<&Arc<ComputedValues>>, parent_style: Option<&Arc<ComputedValues>>,
applicable_declarations: &[MatchedProperty], applicable_declarations: &[DeclarationBlock],
style: &mut Option<Arc<ComputedValues>>, style: &mut Option<Arc<ComputedValues>>,
applicable_declarations_cache: &mut applicable_declarations_cache: &mut
ApplicableDeclarationsCache, ApplicableDeclarationsCache,

View file

@ -18,7 +18,7 @@ pub use geom::SideOffsets2D;
use errors::{ErrorLoggerIterator, log_css_error}; use errors::{ErrorLoggerIterator, log_css_error};
pub use parsing_utils::*; pub use parsing_utils::*;
pub use self::common_types::*; pub use self::common_types::*;
use selector_matching::MatchedProperty; use selector_matching::DeclarationBlock;
pub use self::property_bit_field::PropertyBitField; 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. /// 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, shareable: bool,
parent_style: &ComputedValues, parent_style: &ComputedValues,
cached_style: &ComputedValues, cached_style: &ComputedValues,
@ -1905,7 +1905,7 @@ fn cascade_with_cached_declarations(applicable_declarations: &[MatchedProperty],
/// this is ignored. /// this is ignored.
/// ///
/// Returns the computed values and a boolean indicating whether the result is cacheable. /// 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, shareable: bool,
parent_style: Option< &ComputedValues >, parent_style: Option< &ComputedValues >,
cached_style: Option< &ComputedValues >) cached_style: Option< &ComputedValues >)

View file

@ -74,7 +74,7 @@ impl SelectorMap {
/// Sort the Rules at the end to maintain cascading order. /// Sort the Rules at the end to maintain cascading order.
fn get_all_matching_rules<E:TElement, fn get_all_matching_rules<E:TElement,
N:TNode<E>, N:TNode<E>,
V:VecLike<MatchedProperty>>( V:VecLike<DeclarationBlock>>(
&self, &self,
node: &N, node: &N,
matching_rules_list: &mut V, matching_rules_list: &mut V,
@ -130,7 +130,7 @@ impl SelectorMap {
fn get_matching_rules_from_hash<E:TElement, fn get_matching_rules_from_hash<E:TElement,
N:TNode<E>, N:TNode<E>,
V:VecLike<MatchedProperty>>( V:VecLike<DeclarationBlock>>(
node: &N, node: &N,
hash: &HashMap<Atom, Vec<Rule>>, hash: &HashMap<Atom, Vec<Rule>>,
key: &Atom, key: &Atom,
@ -146,7 +146,7 @@ impl SelectorMap {
fn get_matching_rules_from_hash_ignoring_case<E:TElement, fn get_matching_rules_from_hash_ignoring_case<E:TElement,
N:TNode<E>, N:TNode<E>,
V:VecLike<MatchedProperty>>( V:VecLike<DeclarationBlock>>(
node: &N, node: &N,
hash: &HashMap<Atom, Vec<Rule>>, hash: &HashMap<Atom, Vec<Rule>>,
key: &str, key: &str,
@ -164,7 +164,7 @@ impl SelectorMap {
/// Adds rules in `rules` that match `node` to the `matching_rules` list. /// Adds rules in `rules` that match `node` to the `matching_rules` list.
fn get_matching_rules<E:TElement, fn get_matching_rules<E:TElement,
N:TNode<E>, N:TNode<E>,
V:VecLike<MatchedProperty>>( V:VecLike<DeclarationBlock>>(
node: &N, node: &N,
rules: &[Rule], rules: &[Rule],
matching_rules: &mut V, matching_rules: &mut V,
@ -172,7 +172,7 @@ impl SelectorMap {
for rule in rules.iter() { for rule in rules.iter() {
if matches_compound_selector(&*rule.selector, node, shareable) { if matches_compound_selector(&*rule.selector, node, shareable) {
// TODO(pradeep): Is the cloning inefficient? // 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 { map.$priority.insert(Rule {
selector: selector.compound_selectors.clone(), selector: selector.compound_selectors.clone(),
property: MatchedProperty { declarations: DeclarationBlock {
specificity: selector.specificity, specificity: selector.specificity,
declarations: $style_rule.declarations.$priority.clone(), declarations: $style_rule.declarations.$priority.clone(),
source_order: rules_source_order, source_order: rules_source_order,
@ -353,7 +353,7 @@ impl Stylist {
/// in `css::matching::PrivateMatchMethods::candidate_element_allows_for_style_sharing`. /// in `css::matching::PrivateMatchMethods::candidate_element_allows_for_style_sharing`.
pub fn push_applicable_declarations<E:TElement, pub fn push_applicable_declarations<E:TElement,
N:TNode<E>, N:TNode<E>,
V:VecLike<MatchedProperty>>( V:VecLike<DeclarationBlock>>(
&self, &self,
element: &N, element: &N,
style_attribute: Option<&PropertyDeclarationBlock>, style_attribute: Option<&PropertyDeclarationBlock>,
@ -382,7 +382,7 @@ impl Stylist {
// Step 2: Normal style attributes. // Step 2: Normal style attributes.
style_attribute.map(|sa| { style_attribute.map(|sa| {
shareable = false; 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. // Step 3: Author-supplied `!important` rules.
@ -393,7 +393,7 @@ impl Stylist {
// Step 4: `!important` style attributes. // Step 4: `!important` style attributes.
style_attribute.map(|sa| { style_attribute.map(|sa| {
shareable = false; 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. // Step 5: User and UA `!important` rules.
@ -446,22 +446,22 @@ struct Rule {
// that it matches. Selector contains an owned vector (through // that it matches. Selector contains an owned vector (through
// CompoundSelector) and we want to avoid the allocation. // CompoundSelector) and we want to avoid the allocation.
selector: Arc<CompoundSelector>, selector: Arc<CompoundSelector>,
property: MatchedProperty, declarations: DeclarationBlock,
} }
/// A property declaration together with its precedence among rules of equal specificity so that /// A property declaration together with its precedence among rules of equal specificity so that
/// we can sort them. /// we can sort them.
#[deriving(Clone)] #[deriving(Clone)]
pub struct MatchedProperty { pub struct DeclarationBlock {
pub declarations: Arc<Vec<PropertyDeclaration>>, pub declarations: Arc<Vec<PropertyDeclaration>>,
source_order: uint, source_order: uint,
specificity: u32, specificity: u32,
} }
impl MatchedProperty { impl DeclarationBlock {
#[inline] #[inline]
pub fn from_declarations(declarations: Arc<Vec<PropertyDeclaration>>) -> MatchedProperty { pub fn from_declarations(declarations: Arc<Vec<PropertyDeclaration>>) -> DeclarationBlock {
MatchedProperty { DeclarationBlock {
declarations: declarations, declarations: declarations,
source_order: 0, source_order: 0,
specificity: 0, specificity: 0,
@ -469,29 +469,29 @@ impl MatchedProperty {
} }
} }
impl PartialEq for MatchedProperty { impl PartialEq for DeclarationBlock {
#[inline] #[inline]
fn eq(&self, other: &MatchedProperty) -> bool { fn eq(&self, other: &DeclarationBlock) -> bool {
let this_rank = (self.specificity, self.source_order); let this_rank = (self.specificity, self.source_order);
let other_rank = (other.specificity, other.source_order); let other_rank = (other.specificity, other.source_order);
this_rank == other_rank this_rank == other_rank
} }
} }
impl Eq for MatchedProperty {} impl Eq for DeclarationBlock {}
impl PartialOrd for MatchedProperty { impl PartialOrd for DeclarationBlock {
#[inline] #[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 this_rank = (self.specificity, self.source_order);
let other_rank = (other.specificity, other.source_order); let other_rank = (other.specificity, other.source_order);
this_rank.partial_cmp(&other_rank) this_rank.partial_cmp(&other_rank)
} }
} }
impl Ord for MatchedProperty { impl Ord for DeclarationBlock {
#[inline] #[inline]
fn cmp(&self, other: &MatchedProperty) -> Ordering { fn cmp(&self, other: &DeclarationBlock) -> Ordering {
let this_rank = (self.specificity, self.source_order); let this_rank = (self.specificity, self.source_order);
let other_rank = (other.specificity, other.source_order); let other_rank = (other.specificity, other.source_order);
this_rank.cmp(&other_rank) this_rank.cmp(&other_rank)
@ -938,7 +938,7 @@ fn matches_last_child<E:TElement,N:TNode<E>>(element: &N) -> bool {
mod tests { mod tests {
use servo_util::atom::Atom; use servo_util::atom::Atom;
use sync::Arc; use sync::Arc;
use super::{MatchedProperty, Rule, SelectorMap}; use super::{DeclarationBlock, Rule, SelectorMap};
/// Helper method to get some Rules from selector strings. /// Helper method to get some Rules from selector strings.
/// Each sublist of the result contains the Rules for one StyleRule. /// Each sublist of the result contains the Rules for one StyleRule.
@ -953,7 +953,7 @@ mod tests {
.unwrap().move_iter().map(|s| { .unwrap().move_iter().map(|s| {
Rule { Rule {
selector: s.compound_selectors.clone(), selector: s.compound_selectors.clone(),
property: MatchedProperty { declarations: DeclarationBlock {
specificity: s.specificity, specificity: s.specificity,
declarations: Arc::new(vec!()), declarations: Arc::new(vec!()),
source_order: i, source_order: i,
@ -966,9 +966,9 @@ mod tests {
#[test] #[test]
fn test_rule_ordering_same_specificity(){ fn test_rule_ordering_same_specificity(){
let rules_list = get_mock_rules(["a.intro", "img.sidebar"]); let rules_list = get_mock_rules(["a.intro", "img.sidebar"]);
let rule1 = rules_list[0][0].clone(); let a = &rules_list[0][0].declarations;
let rule2 = rules_list[1][0].clone(); let b = &rules_list[1][0].declarations;
assert!(rule1.property < rule2.property, "The rule that comes later should win."); assert!(a < b, "The rule that comes later should win.");
} }
#[test] #[test]
@ -999,9 +999,9 @@ mod tests {
let rules_list = get_mock_rules([".intro.foo", "#top"]); let rules_list = get_mock_rules([".intro.foo", "#top"]);
let mut selector_map = SelectorMap::new(); let mut selector_map = SelectorMap::new();
selector_map.insert(rules_list[1][0].clone()); 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()); 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()); assert!(selector_map.class_hash.find(&Atom::from_slice("foo")).is_none());
} }
} }

View file

@ -32,7 +32,7 @@ extern crate servo_util = "util";
// Public API // Public API
pub use stylesheets::{Stylesheet, CSSRule, StyleRule, CSSFontFaceRule}; pub use stylesheets::{Stylesheet, CSSRule, StyleRule, CSSFontFaceRule};
pub use selector_matching::{Stylist, StylesheetOrigin, UserAgentOrigin, AuthorOrigin, UserOrigin}; 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::{cascade, cascade_anonymous};
pub use properties::{PropertyDeclaration, ComputedValues, computed_values, style_structs}; pub use properties::{PropertyDeclaration, ComputedValues, computed_values, style_structs};
pub use properties::{PropertyDeclarationBlock, parse_style_attribute}; // Style attributes pub use properties::{PropertyDeclarationBlock, parse_style_attribute}; // Style attributes