mirror of
https://github.com/servo/servo.git
synced 2025-06-25 01:24:37 +01:00
Only element nodes have styles
This commit is contained in:
parent
dd13a17812
commit
2daa422483
5 changed files with 21 additions and 13 deletions
|
@ -27,10 +27,13 @@ impl Node : MatchMethods {
|
||||||
kid.restyle_subtree(select_ctx);
|
kid.restyle_subtree(select_ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
let select_handler = NodeSelectHandler {
|
// Only elements have styles
|
||||||
node: self
|
if self.is_element() {
|
||||||
};
|
let select_handler = NodeSelectHandler {
|
||||||
let style = select_ctx.select_style(&self, &select_handler);
|
node: self
|
||||||
self.set_css_select_results(move style);
|
};
|
||||||
|
let style = select_ctx.select_style(&self, &select_handler);
|
||||||
|
self.set_css_select_results(move style);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,6 +25,7 @@ trait StyledNode {
|
||||||
|
|
||||||
impl Node: StyledNode {
|
impl Node: StyledNode {
|
||||||
fn style(&self) -> NodeStyle/&self {
|
fn style(&self) -> NodeStyle/&self {
|
||||||
|
assert self.is_element(); // Only elements can have styles
|
||||||
NodeStyle::new(self)
|
NodeStyle::new(self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,17 +6,10 @@ pub struct NodeSelectHandler {
|
||||||
node: Node
|
node: Node
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Placeholder names
|
|
||||||
fn unnamed_node(name: &str) -> ~str {
|
|
||||||
fmt!("unnamed-%s", name)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn node_name(data: &NodeData) -> ~str {
|
fn node_name(data: &NodeData) -> ~str {
|
||||||
match *data.kind {
|
match *data.kind {
|
||||||
Doctype(*) => unnamed_node("doctype"),
|
|
||||||
Comment(*) => unnamed_node("comment"),
|
|
||||||
Element(ref data) => copy data.tag_name,
|
Element(ref data) => copy data.tag_name,
|
||||||
Text(*) => unnamed_node("text")
|
_ => fail ~"attempting to style non-element node"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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 {
|
pub enum NodeKind {
|
||||||
Doctype(DoctypeData),
|
Doctype(DoctypeData),
|
||||||
Comment(~str),
|
Comment(~str),
|
||||||
|
|
|
@ -435,6 +435,9 @@ impl RenderBox : RenderBoxMethods {
|
||||||
|
|
||||||
fn add_bgcolor_to_list(list: &mut DisplayList, abs_bounds: &Rect<Au>) {
|
fn add_bgcolor_to_list(list: &mut DisplayList, abs_bounds: &Rect<Au>) {
|
||||||
use std::cmp::FuzzyEq;
|
use std::cmp::FuzzyEq;
|
||||||
|
|
||||||
|
if !self.d().node.is_element() { return }
|
||||||
|
|
||||||
let bgcolor = self.style().background_color();
|
let bgcolor = self.style().background_color();
|
||||||
if !bgcolor.alpha.fuzzy_eq(&0.0) {
|
if !bgcolor.alpha.fuzzy_eq(&0.0) {
|
||||||
list.append_item(~DisplayItem::new_SolidColor(abs_bounds, bgcolor.to_gfx_color()));
|
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>) {
|
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 top_width = self.style().border_top_width();
|
||||||
let right_width = self.style().border_right_width();
|
let right_width = self.style().border_right_width();
|
||||||
let bottom_width = self.style().border_bottom_width();
|
let bottom_width = self.style().border_bottom_width();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue