Clean up css::compute

This commit is contained in:
Brian Anderson 2012-11-03 00:19:50 -07:00
parent daaaac7740
commit 8b2611ec90

View file

@ -1,5 +1,8 @@
/*! /*!
Calculate styles for Nodes based on SelectResults, resolving inherited values Calculates computed Node styles, based on CSS SelectResults.
These methods mostly defer to the Node's ComputedStyle object.
The only exception is that this is where inheritance is resolved.
*/ */
use dom::node::Node; use dom::node::Node;
@ -17,27 +20,27 @@ pub trait ComputeStyles {
impl Node: ComputeStyles { impl Node: ComputeStyles {
fn compute_background_color(&self) -> Color { fn compute_background_color(&self) -> Color {
compute(self, rgba(0, 0, 0, 0.0), |cs| cs.background_color() ) resolve(self, rgba(0, 0, 0, 0.0), |cs| cs.background_color() )
} }
fn compute_border_top_width(&self) -> CSSBorderWidth { fn compute_border_top_width(&self) -> CSSBorderWidth {
compute(self, BdrWidthLength(Px(0.0)), |cs| cs.border_top_width() ) resolve(self, BdrWidthLength(Px(0.0)), |cs| cs.border_top_width() )
} }
fn compute_border_right_width(&self) -> CSSBorderWidth { fn compute_border_right_width(&self) -> CSSBorderWidth {
compute(self, BdrWidthLength(Px(0.0)), |cs| cs.border_right_width() ) resolve(self, BdrWidthLength(Px(0.0)), |cs| cs.border_right_width() )
} }
fn compute_border_bottom_width(&self) -> CSSBorderWidth { fn compute_border_bottom_width(&self) -> CSSBorderWidth {
compute(self, BdrWidthLength(Px(0.0)), |cs| cs.border_bottom_width() ) resolve(self, BdrWidthLength(Px(0.0)), |cs| cs.border_bottom_width() )
} }
fn compute_border_left_width(&self) -> CSSBorderWidth { fn compute_border_left_width(&self) -> CSSBorderWidth {
compute(self, BdrWidthLength(Px(0.0)), |cs| cs.border_left_width() ) resolve(self, BdrWidthLength(Px(0.0)), |cs| cs.border_left_width() )
} }
} }
fn compute<T>(node: &Node, default: T, get: &fn(cs: ComputedStyle) -> CSSValue<T>) -> T { fn resolve<T>(node: &Node, default: T, get: &fn(cs: ComputedStyle) -> CSSValue<T>) -> T {
let style = node.get_style(); let style = node.get_style();
let computed = style.computed_style(); let computed = style.computed_style();
let value = get(computed); let value = get(computed);