mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
Clean up css::compute
This commit is contained in:
parent
daaaac7740
commit
8b2611ec90
1 changed files with 10 additions and 7 deletions
|
@ -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;
|
||||
|
@ -17,27 +20,27 @@ pub trait ComputeStyles {
|
|||
|
||||
impl Node: ComputeStyles {
|
||||
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 {
|
||||
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 {
|
||||
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 {
|
||||
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 {
|
||||
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 computed = style.computed_style();
|
||||
let value = get(computed);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue