Only element nodes have styles

This commit is contained in:
Brian Anderson 2012-11-05 16:32:40 -08:00
parent dd13a17812
commit 2daa422483
5 changed files with 21 additions and 13 deletions

View file

@ -27,10 +27,13 @@ impl Node : MatchMethods {
kid.restyle_subtree(select_ctx);
}
let select_handler = NodeSelectHandler {
node: self
};
let style = select_ctx.select_style(&self, &select_handler);
self.set_css_select_results(move style);
// Only elements have styles
if self.is_element() {
let select_handler = NodeSelectHandler {
node: self
};
let style = select_ctx.select_style(&self, &select_handler);
self.set_css_select_results(move style);
}
}
}

View file

@ -25,6 +25,7 @@ trait StyledNode {
impl Node: StyledNode {
fn style(&self) -> NodeStyle/&self {
assert self.is_element(); // Only elements can have styles
NodeStyle::new(self)
}
}

View file

@ -6,17 +6,10 @@ pub struct NodeSelectHandler {
node: Node
}
/// Placeholder names
fn unnamed_node(name: &str) -> ~str {
fmt!("unnamed-%s", name)
}
fn node_name(data: &NodeData) -> ~str {
match *data.kind {
Doctype(*) => unnamed_node("doctype"),
Comment(*) => unnamed_node("comment"),
Element(ref data) => copy data.tag_name,
Text(*) => unnamed_node("text")
_ => fail ~"attempting to style non-element node"
}
}

View file

@ -71,6 +71,12 @@ impl Node : DebugMethods {
}
}
impl Node {
fn is_element(&self) -> bool {
self.read(|n| match *n.kind { Element(*) => true, _ => false } )
}
}
pub enum NodeKind {
Doctype(DoctypeData),
Comment(~str),

View file

@ -435,6 +435,9 @@ impl RenderBox : RenderBoxMethods {
fn add_bgcolor_to_list(list: &mut DisplayList, abs_bounds: &Rect<Au>) {
use std::cmp::FuzzyEq;
if !self.d().node.is_element() { return }
let bgcolor = self.style().background_color();
if !bgcolor.alpha.fuzzy_eq(&0.0) {
list.append_item(~DisplayItem::new_SolidColor(abs_bounds, bgcolor.to_gfx_color()));
@ -442,6 +445,8 @@ impl RenderBox : RenderBoxMethods {
}
fn add_border_to_list(list: &mut DisplayList, abs_bounds: &Rect<Au>) {
if !self.d().node.is_element() { return }
let top_width = self.style().border_top_width();
let right_width = self.style().border_right_width();
let bottom_width = self.style().border_bottom_width();