Skip to content

Commit

Permalink
Begin integrating selector matching
Browse files Browse the repository at this point in the history
  • Loading branch information
brson committed Nov 1, 2012
1 parent 806517b commit b00885f
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/rust-css
Submodule rust-css updated from 8d8836 to e3d3a5
30 changes: 13 additions & 17 deletions src/servo/css/matching.rs
Expand Up @@ -6,8 +6,9 @@ use dom::node::{LayoutData, Node, Text};
use dom::element::ElementData;

use newcss::values::*;
use newcss::SelectCtx;
use newcss::{SelectCtx, SelectResults};
use styles::{SpecifiedStyle};
use select_handler::NodeSelectHandler;

/**
Check if a CSS attribute matches the attribute of an HTML element.
Expand Down Expand Up @@ -167,15 +168,15 @@ impl Node : PrivMatchingMethods {
}
trait PrivStyleMethods {
fn update_style(decl : StyleDeclaration);
fn update_style(decl : SelectResults);
}
impl Node : PrivStyleMethods {
/**
Update the computed style of an HTML element with a style specified by CSS.
*/
fn update_style(decl : StyleDeclaration) {
self.aux(|layout| {
fn update_style(decl : SelectResults) {
/*self.aux(|layout| {
match decl {
BackgroundColor(col) => layout.style.background_color = col,
Display(dis) => layout.style.display_type = dis,
Expand All @@ -191,36 +192,31 @@ impl Node : PrivStyleMethods {
Bottom(pos) => layout.style.bottom = pos,
Left(pos) => layout.style.left = pos,
};
})
})*/
}
}
trait MatchingMethods {
fn match_css_style(styles : &SelectCtx);
fn match_css_style(select_ctx : &SelectCtx);
}
impl Node : MatchingMethods {
/**
Compare an html element to a list of css rules and update its
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
// described in the rule. If it matches, update its style. As
// we don't currently have priorities of style information,
// the latest rule takes precedence over the others. So we
// just overwrite style information as we go.
/*for styles.each |sty| {
let (selectors, decls) = copy **sty;
for selectors.each |sel| {
if self.matches_selector(*sel) {
for decls.each |decl| {
self.update_style(*decl);
}
}
}
}*/
let select_handler = NodeSelectHandler {
node: self
};
let style = select_ctx.select_style(&self, &select_handler);
self.update_style(move style);
}
}
Expand Down
10 changes: 10 additions & 0 deletions src/servo/css/select_handler.rs
@@ -0,0 +1,10 @@
use dom::node::Node;
use newcss::SelectHandler;

pub struct NodeSelectHandler {
node: Node
}

impl NodeSelectHandler: SelectHandler<Node> {

}
1 change: 1 addition & 0 deletions src/servo/servo.rc
Expand Up @@ -48,6 +48,7 @@ pub mod css {
pub mod styles;
mod apply;
mod matching;
priv mod select_handler;
}

pub mod layout {
Expand Down

0 comments on commit b00885f

Please sign in to comment.