diff --git a/src/rust-css b/src/rust-css index a3b8fa6feaa..45c54188a79 160000 --- a/src/rust-css +++ b/src/rust-css @@ -1 +1 @@ -Subproject commit a3b8fa6feaae8d877037c379f20826f24d8af09b +Subproject commit 45c54188a79c35920df145cda7295558e4956c8e diff --git a/src/rust-netsurfcss b/src/rust-netsurfcss index 432f1260c79..7ee569d3e21 160000 --- a/src/rust-netsurfcss +++ b/src/rust-netsurfcss @@ -1 +1 @@ -Subproject commit 432f1260c79212458d32352255ff3b180fb22929 +Subproject commit 7ee569d3e21ca2818f9bcc764a4abb313475e8cf diff --git a/src/servo/css/compute.rs b/src/servo/css/compute.rs index 9ca5f7efc2c..a3262c8497b 100644 --- a/src/servo/css/compute.rs +++ b/src/servo/css/compute.rs @@ -1,28 +1,48 @@ /*! -Calculate styles for Nodes based on SelectResults +Calculate styles for Nodes based on SelectResults, resolving inherited values */ use dom::node::Node; use newcss::color::{Color, rgba}; -use newcss::values::{CSSValue, Specified, Inherit}; +use newcss::values::{CSSValue, Specified, Inherit, Length, Px}; use newcss::ComputedStyle; pub trait ComputeStyles { fn compute_background_color(&self) -> Color; + fn compute_border_top_width(&self) -> Length; + fn compute_border_right_width(&self) -> Length; + fn compute_border_bottom_width(&self) -> Length; + fn compute_border_left_width(&self) -> Length; } impl Node: ComputeStyles { fn compute_background_color(&self) -> Color { - compute(self, |cs| cs.background_color(), rgba(0, 0, 0, 0.0)) + compute(self, rgba(0, 0, 0, 0.0), |cs| cs.background_color() ) + } + + fn compute_border_top_width(&self) -> Length { + compute(self, Px(0.0), |cs| cs.border_top_width() ) + } + + fn compute_border_right_width(&self) -> Length { + compute(self, Px(0.0), |cs| cs.border_right_width() ) + } + + fn compute_border_bottom_width(&self) -> Length { + compute(self, Px(0.0), |cs| cs.border_bottom_width() ) + } + + fn compute_border_left_width(&self) -> Length { + compute(self, Px(0.0), |cs| cs.border_left_width() ) } } -fn compute(node: &Node, get: &fn(cs: ComputedStyle) -> CSSValue, default: T) -> T { +fn compute(node: &Node, default: T, get: &fn(cs: ComputedStyle) -> CSSValue) -> T { let style = node.get_style(); let computed = style.computed_style(); let value = get(computed); match move value { - Inherit => /* FIXME */ move default, + Inherit => /* FIXME: need inheritance */ move default, Specified(move value) => move value, _ => fail } diff --git a/src/servo/layout/box.rs b/src/servo/layout/box.rs index 7bef26b78ce..6adc568a230 100644 --- a/src/servo/layout/box.rs +++ b/src/servo/layout/box.rs @@ -434,7 +434,44 @@ impl RenderBox : RenderBoxMethods { } } - fn add_border_to_list(_list: &mut DisplayList, _abs_bounds: &Rect) { + fn add_border_to_list(list: &mut DisplayList, abs_bounds: &Rect) { + let top_width = self.d().node.compute_border_top_width(); + let right_width = self.d().node.compute_border_right_width(); + let bottom_width = self.d().node.compute_border_bottom_width(); + let left_width = self.d().node.compute_border_left_width(); + + match (top_width, right_width, bottom_width, left_width) { + (Px(top), Px(right), Px(bottom), Px(left)) => { + let top_au = au::from_frac_px(top); + let right_au = au::from_frac_px(right); + let bottom_au = au::from_frac_px(bottom); + let left_au = au::from_frac_px(left); + + let all_widths_equal = [top_au, right_au, bottom_au].all(|a| *a == left_au); + + if all_widths_equal { + let border_width = top_au; + error!("%? %?", top, border_width); + let bounds = Rect { + origin: Point2D { + x: abs_bounds.origin.x - border_width / Au(2), + y: abs_bounds.origin.y - border_width / Au(2), + }, + size: Size2D { + width: abs_bounds.size.width + border_width, + height: abs_bounds.size.height + border_width + } + }; + let color = rgb(0, 128, 255).to_gfx_color(); // FIXME + list.append_item(~DisplayItem::new_Border(&bounds, border_width, color)); + + } else { + fail ~"unimplemented border widths"; + } + } + _ => fail ~"unimplemented border widths" + } + // FIXME /*let style = self.d().node.style(); match style.border_width {