mirror of
https://github.com/servo/servo.git
synced 2025-08-08 06:55:31 +01:00
CSS: separate cascading from selector matching, add style attributes.
This commit is contained in:
parent
02ef301770
commit
321f56c242
2 changed files with 17 additions and 16 deletions
|
@ -8,7 +8,7 @@ use extra::sort::tim_sort;
|
||||||
use selectors::*;
|
use selectors::*;
|
||||||
use stylesheets::parse_stylesheet;
|
use stylesheets::parse_stylesheet;
|
||||||
use media_queries::{Device, Screen};
|
use media_queries::{Device, Screen};
|
||||||
use properties::{ComputedValues, cascade, PropertyDeclaration};
|
use properties::{PropertyDeclaration, PropertyDeclarationBlock};
|
||||||
use script::dom::node::{AbstractNode, ScriptView};
|
use script::dom::node::{AbstractNode, ScriptView};
|
||||||
use script::dom::element::Element;
|
use script::dom::element::Element;
|
||||||
|
|
||||||
|
@ -77,20 +77,13 @@ impl Stylist {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_computed_style(&self, element: AbstractNode<ScriptView>,
|
pub fn get_applicable_declarations(&self, element: AbstractNode<ScriptView>,
|
||||||
parent_style: Option<&ComputedValues>,
|
style_attribute: Option<&PropertyDeclarationBlock>,
|
||||||
pseudo_element: Option<PseudoElement>)
|
pseudo_element: Option<PseudoElement>)
|
||||||
-> ComputedValues {
|
-> ~[@[PropertyDeclaration]] {
|
||||||
assert!(element.is_element())
|
assert!(element.is_element())
|
||||||
// Only the root does not inherit.
|
assert!(style_attribute.is_none() || pseudo_element.is_none(),
|
||||||
// The root has no parent or a non-element parent.
|
"Style attributes do not apply to pseudo-elements")
|
||||||
assert_eq!(
|
|
||||||
parent_style.is_none(),
|
|
||||||
match element.parent_node() {
|
|
||||||
None => true,
|
|
||||||
Some(ref node) => !node.is_element()
|
|
||||||
}
|
|
||||||
);
|
|
||||||
let mut applicable_declarations = ~[]; // TODO: use an iterator?
|
let mut applicable_declarations = ~[]; // TODO: use an iterator?
|
||||||
|
|
||||||
macro_rules! append(
|
macro_rules! append(
|
||||||
|
@ -106,13 +99,18 @@ impl Stylist {
|
||||||
// In cascading order
|
// In cascading order
|
||||||
append!(self.ua_rules.normal);
|
append!(self.ua_rules.normal);
|
||||||
append!(self.user_rules.normal);
|
append!(self.user_rules.normal);
|
||||||
|
|
||||||
|
// Style attributes have author origin but higher specificity than style rules.
|
||||||
append!(self.author_rules.normal);
|
append!(self.author_rules.normal);
|
||||||
// TODO add style attribute
|
style_attribute.map(|sa| applicable_declarations.push(sa.normal));
|
||||||
|
|
||||||
append!(self.author_rules.important);
|
append!(self.author_rules.important);
|
||||||
|
style_attribute.map(|sa| applicable_declarations.push(sa.important));
|
||||||
|
|
||||||
append!(self.user_rules.important);
|
append!(self.user_rules.important);
|
||||||
append!(self.ua_rules.important);
|
append!(self.ua_rules.important);
|
||||||
|
|
||||||
cascade(applicable_declarations, parent_style)
|
applicable_declarations
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,9 @@ extern mod script;
|
||||||
|
|
||||||
// The "real" public API
|
// The "real" public API
|
||||||
pub use self::selector_matching::{Stylist, StylesheetOrigin};
|
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
|
// Things that need to be public to make the compiler happy
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue