Begin integrating selector matching

This commit is contained in:
Brian Anderson 2012-10-31 01:18:48 -07:00
parent 806517b9bb
commit b00885f77a
4 changed files with 25 additions and 18 deletions

@ -1 +1 @@
Subproject commit 8d8836e5afc7afaac869e099c0ffa8f68c3b87bf Subproject commit e3d3a5d65ded9afc69a9033a5a8e609a88527476

View file

@ -6,8 +6,9 @@ use dom::node::{LayoutData, Node, Text};
use dom::element::ElementData; use dom::element::ElementData;
use newcss::values::*; use newcss::values::*;
use newcss::SelectCtx; use newcss::{SelectCtx, SelectResults};
use styles::{SpecifiedStyle}; use styles::{SpecifiedStyle};
use select_handler::NodeSelectHandler;
/** /**
Check if a CSS attribute matches the attribute of an HTML element. Check if a CSS attribute matches the attribute of an HTML element.
@ -167,15 +168,15 @@ impl Node : PrivMatchingMethods {
} }
trait PrivStyleMethods { trait PrivStyleMethods {
fn update_style(decl : StyleDeclaration); fn update_style(decl : SelectResults);
} }
impl Node : PrivStyleMethods { impl Node : PrivStyleMethods {
/** /**
Update the computed style of an HTML element with a style specified by CSS. Update the computed style of an HTML element with a style specified by CSS.
*/ */
fn update_style(decl : StyleDeclaration) { fn update_style(decl : SelectResults) {
self.aux(|layout| { /*self.aux(|layout| {
match decl { match decl {
BackgroundColor(col) => layout.style.background_color = col, BackgroundColor(col) => layout.style.background_color = col,
Display(dis) => layout.style.display_type = dis, Display(dis) => layout.style.display_type = dis,
@ -191,12 +192,12 @@ impl Node : PrivStyleMethods {
Bottom(pos) => layout.style.bottom = pos, Bottom(pos) => layout.style.bottom = pos,
Left(pos) => layout.style.left = pos, Left(pos) => layout.style.left = pos,
}; };
}) })*/
} }
} }
trait MatchingMethods { trait MatchingMethods {
fn match_css_style(styles : &SelectCtx); fn match_css_style(select_ctx : &SelectCtx);
} }
impl Node : MatchingMethods { impl Node : MatchingMethods {
@ -204,23 +205,18 @@ impl Node : MatchingMethods {
Compare an html element to a list of css rules and update its Compare an html element to a list of css rules and update its
style according to the rules matching it. style according to the rules matching it.
*/ */
fn match_css_style(styles : &SelectCtx) { fn match_css_style(select_ctx : &SelectCtx) {
// Loop over each rule, see if our node matches what is // Loop over each rule, see if our node matches what is
// described in the rule. If it matches, update its style. As // described in the rule. If it matches, update its style. As
// we don't currently have priorities of style information, // we don't currently have priorities of style information,
// the latest rule takes precedence over the others. So we // the latest rule takes precedence over the others. So we
// just overwrite style information as we go. // just overwrite style information as we go.
/*for styles.each |sty| { let select_handler = NodeSelectHandler {
let (selectors, decls) = copy **sty; node: self
for selectors.each |sel| { };
if self.matches_selector(*sel) { let style = select_ctx.select_style(&self, &select_handler);
for decls.each |decl| { self.update_style(move style);
self.update_style(*decl);
}
}
}
}*/
} }
} }

View file

@ -0,0 +1,10 @@
use dom::node::Node;
use newcss::SelectHandler;
pub struct NodeSelectHandler {
node: Node
}
impl NodeSelectHandler: SelectHandler<Node> {
}

View file

@ -48,6 +48,7 @@ pub mod css {
pub mod styles; pub mod styles;
mod apply; mod apply;
mod matching; mod matching;
priv mod select_handler;
} }
pub mod layout { pub mod layout {