mirror of
https://github.com/servo/servo.git
synced 2025-06-24 17:14:33 +01:00
Make borders sort of work again
This commit is contained in:
parent
f06628d14e
commit
f380b8d3b3
4 changed files with 65 additions and 8 deletions
|
@ -1 +1 @@
|
||||||
Subproject commit a3b8fa6feaae8d877037c379f20826f24d8af09b
|
Subproject commit 45c54188a79c35920df145cda7295558e4956c8e
|
|
@ -1 +1 @@
|
||||||
Subproject commit 432f1260c79212458d32352255ff3b180fb22929
|
Subproject commit 7ee569d3e21ca2818f9bcc764a4abb313475e8cf
|
|
@ -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 dom::node::Node;
|
||||||
use newcss::color::{Color, rgba};
|
use newcss::color::{Color, rgba};
|
||||||
use newcss::values::{CSSValue, Specified, Inherit};
|
use newcss::values::{CSSValue, Specified, Inherit, Length, Px};
|
||||||
use newcss::ComputedStyle;
|
use newcss::ComputedStyle;
|
||||||
|
|
||||||
pub trait ComputeStyles {
|
pub trait ComputeStyles {
|
||||||
fn compute_background_color(&self) -> Color;
|
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 {
|
impl Node: ComputeStyles {
|
||||||
fn compute_background_color(&self) -> Color {
|
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<T>(node: &Node, get: &fn(cs: ComputedStyle) -> CSSValue<T>, default: T) -> T {
|
fn compute<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);
|
||||||
match move value {
|
match move value {
|
||||||
Inherit => /* FIXME */ move default,
|
Inherit => /* FIXME: need inheritance */ move default,
|
||||||
Specified(move value) => move value,
|
Specified(move value) => move value,
|
||||||
_ => fail
|
_ => fail
|
||||||
}
|
}
|
||||||
|
|
|
@ -434,7 +434,44 @@ 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>) {
|
||||||
|
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
|
// FIXME
|
||||||
/*let style = self.d().node.style();
|
/*let style = self.d().node.style();
|
||||||
match style.border_width {
|
match style.border_width {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue