CSS: separate cascading from selector matching, add style attributes.

This commit is contained in:
Simon Sapin 2013-10-15 16:02:48 +01:00
parent 02ef301770
commit 321f56c242
2 changed files with 17 additions and 16 deletions

View file

@ -8,7 +8,7 @@ use extra::sort::tim_sort;
use selectors::*;
use stylesheets::parse_stylesheet;
use media_queries::{Device, Screen};
use properties::{ComputedValues, cascade, PropertyDeclaration};
use properties::{PropertyDeclaration, PropertyDeclarationBlock};
use script::dom::node::{AbstractNode, ScriptView};
use script::dom::element::Element;
@ -77,20 +77,13 @@ impl Stylist {
}
}
pub fn get_computed_style(&self, element: AbstractNode<ScriptView>,
parent_style: Option<&ComputedValues>,
pseudo_element: Option<PseudoElement>)
-> ComputedValues {
pub fn get_applicable_declarations(&self, element: AbstractNode<ScriptView>,
style_attribute: Option<&PropertyDeclarationBlock>,
pseudo_element: Option<PseudoElement>)
-> ~[@[PropertyDeclaration]] {
assert!(element.is_element())
// Only the root does not inherit.
// The root has no parent or a non-element parent.
assert_eq!(
parent_style.is_none(),
match element.parent_node() {
None => true,
Some(ref node) => !node.is_element()
}
);
assert!(style_attribute.is_none() || pseudo_element.is_none(),
"Style attributes do not apply to pseudo-elements")
let mut applicable_declarations = ~[]; // TODO: use an iterator?
macro_rules! append(
@ -106,13 +99,18 @@ impl Stylist {
// In cascading order
append!(self.ua_rules.normal);
append!(self.user_rules.normal);
// Style attributes have author origin but higher specificity than style rules.
append!(self.author_rules.normal);
// TODO add style attribute
style_attribute.map(|sa| applicable_declarations.push(sa.normal));
append!(self.author_rules.important);
style_attribute.map(|sa| applicable_declarations.push(sa.important));
append!(self.user_rules.important);
append!(self.ua_rules.important);
cascade(applicable_declarations, parent_style)
applicable_declarations
}
}

View file

@ -19,6 +19,9 @@ extern mod script;
// The "real" public API
pub use self::selector_matching::{Stylist, StylesheetOrigin};
pub use self::properties::cascade;
pub use self::properties::{PropertyDeclarationBlock,
parse_property_declaration_list}; // Style attributes
// Things that need to be public to make the compiler happy