auto merge of #499 : ILyoan/servo/css_class, r=jdm

This patch implement css class selection. 

This involves update of 3 submodules

- rust-css: https://github.com/mozilla-servo/rust-css/pull/13
- rust-netsurfcss: https://github.com/mozilla-servo/rust-netsurfcss/pull/12
- libcss: https://github.com/mozilla-servo/libcss/pull/3

The commit hash number for submodules might be changed when the submodule is merged.
The update for libcss is only for debug print which is out of data and will not compiled without DEBUG_CHAIN_MATCHING flag.
This commit is contained in:
bors-servo 2013-06-11 23:42:29 -07:00
commit e5c0021299
8 changed files with 53 additions and 3 deletions

View file

@ -86,6 +86,36 @@ impl SelectHandler<AbstractNode<LayoutView>> for NodeSelectHandler {
} }
} }
fn with_node_classes<R>(&self, node: &AbstractNode<LayoutView>, f: &fn(Option<&str>) -> R) -> R {
if !node.is_element() {
fail!(~"attempting to style non-element node");
}
do node.with_imm_element() |element_n| {
f(element_n.get_attr("class"))
}
}
fn node_has_class(&self, node: &AbstractNode<LayoutView>, class: &str) -> bool {
if !node.is_element() {
fail!(~"attempting to style non-element node");
}
do node.with_imm_element |element_n| {
match element_n.get_attr("class") {
None => false,
Some(existing_classes) => {
let mut ret = false;
for str::each_split_char(existing_classes, ' ') |s| {
if s == class {
ret = true;
break;
}
}
ret
}
}
}
}
fn with_node_id<R>(&self, node: &AbstractNode<LayoutView>, f: &fn(Option<&str>) -> R) -> R { fn with_node_id<R>(&self, node: &AbstractNode<LayoutView>, f: &fn(Option<&str>) -> R) -> R {
if !node.is_element() { if !node.is_element() {
fail!(~"attempting to style non-element node"); fail!(~"attempting to style non-element node");

@ -1 +1 @@
Subproject commit 57407e5209ec95e695e17447fa7c5dfea96629b3 Subproject commit 865f539114383a021822583801e8362faf916699

@ -1 +1 @@
Subproject commit d722188de3876ed748382965eb4f300fc1b78bf8 Subproject commit da248d3f5b3ed6d9e804c543563be8e34baf1673

@ -1 +1 @@
Subproject commit 3565b32ba3d15d31b02cc76bdf76d6b13fc88451 Subproject commit 325cd5197ed953f5c7c9317111b20ec1599eaffe

View file

@ -0,0 +1,20 @@
<html>
<head>
<style type="text/css">
.c1 { color: red; }
.c2 { background: blue; }
#i1 { color: green; }
</style>
<script>
document.write("ok");
</script>
</head>
<body>
<div>
<div id='i1'>Hello</div>
<div class='c1'>World</div>
<div class='c2'>Hello</div>
<div class='c1 c2'>World</div>
</div>
</body>
</html>