From 321f56c2425f196f0c0d321934fdde7f0c3eb337 Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Tue, 15 Oct 2013 16:02:48 +0100 Subject: [PATCH] CSS: separate cascading from selector matching, add style attributes. --- src/components/style/selector_matching.rs | 30 +++++++++++------------ src/components/style/style.rc | 3 +++ 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/src/components/style/selector_matching.rs b/src/components/style/selector_matching.rs index 9ce4325291b..1d5a5ad9375 100644 --- a/src/components/style/selector_matching.rs +++ b/src/components/style/selector_matching.rs @@ -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, - parent_style: Option<&ComputedValues>, - pseudo_element: Option) - -> ComputedValues { + pub fn get_applicable_declarations(&self, element: AbstractNode, + style_attribute: Option<&PropertyDeclarationBlock>, + pseudo_element: Option) + -> ~[@[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 } } diff --git a/src/components/style/style.rc b/src/components/style/style.rc index 2944f074402..90f59c5372e 100644 --- a/src/components/style/style.rc +++ b/src/components/style/style.rc @@ -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