mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
Draw simple borders again
This commit is contained in:
parent
301070855e
commit
f6da6bed80
5 changed files with 60 additions and 24 deletions
|
@ -1 +1 @@
|
||||||
Subproject commit 79a3ddccd05742980c5e27e48755bec807d4bd46
|
Subproject commit 75aba2d0e4b1224ce55ba11423c78bc7eceaed6c
|
|
@ -1 +1 @@
|
||||||
Subproject commit 8b76c31e0d72b50630f56e5fb560eda4186c6796
|
Subproject commit 62225a3af2c4d59da0d595287570cdfd71e7a4f6
|
|
@ -4,15 +4,15 @@ 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, Length, Px};
|
use newcss::values::{CSSValue, Specified, Inherit, Length, Px, CSSBorderWidth, BdrWidthLength};
|
||||||
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_top_width(&self) -> CSSBorderWidth;
|
||||||
fn compute_border_right_width(&self) -> Length;
|
fn compute_border_right_width(&self) -> CSSBorderWidth;
|
||||||
fn compute_border_bottom_width(&self) -> Length;
|
fn compute_border_bottom_width(&self) -> CSSBorderWidth;
|
||||||
fn compute_border_left_width(&self) -> Length;
|
fn compute_border_left_width(&self) -> CSSBorderWidth;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Node: ComputeStyles {
|
impl Node: ComputeStyles {
|
||||||
|
@ -20,20 +20,20 @@ impl Node: ComputeStyles {
|
||||||
compute(self, rgba(0, 0, 0, 0.0), |cs| cs.background_color() )
|
compute(self, rgba(0, 0, 0, 0.0), |cs| cs.background_color() )
|
||||||
}
|
}
|
||||||
|
|
||||||
fn compute_border_top_width(&self) -> Length {
|
fn compute_border_top_width(&self) -> CSSBorderWidth {
|
||||||
compute(self, Px(0.0), |cs| cs.border_top_width() )
|
compute(self, BdrWidthLength(Px(0.0)), |cs| cs.border_top_width() )
|
||||||
}
|
}
|
||||||
|
|
||||||
fn compute_border_right_width(&self) -> Length {
|
fn compute_border_right_width(&self) -> CSSBorderWidth {
|
||||||
compute(self, Px(0.0), |cs| cs.border_right_width() )
|
compute(self, BdrWidthLength(Px(0.0)), |cs| cs.border_right_width() )
|
||||||
}
|
}
|
||||||
|
|
||||||
fn compute_border_bottom_width(&self) -> Length {
|
fn compute_border_bottom_width(&self) -> CSSBorderWidth {
|
||||||
compute(self, Px(0.0), |cs| cs.border_bottom_width() )
|
compute(self, BdrWidthLength(Px(0.0)), |cs| cs.border_bottom_width() )
|
||||||
}
|
}
|
||||||
|
|
||||||
fn compute_border_left_width(&self) -> Length {
|
fn compute_border_left_width(&self) -> CSSBorderWidth {
|
||||||
compute(self, Px(0.0), |cs| cs.border_left_width() )
|
compute(self, BdrWidthLength(Px(0.0)), |cs| cs.border_left_width() )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
use dom::node::{Node, Doctype, Comment, Element, Text};
|
use dom::node::{Node, NodeData, NodeTree, Doctype, Comment, Element, Text};
|
||||||
use newcss::SelectHandler;
|
use newcss::SelectHandler;
|
||||||
|
use util::tree;
|
||||||
|
|
||||||
pub struct NodeSelectHandler {
|
pub struct NodeSelectHandler {
|
||||||
node: Node
|
node: Node
|
||||||
|
@ -10,15 +11,39 @@ fn unnamed_node(name: &str) -> ~str {
|
||||||
fmt!("unnamed-%s", name)
|
fmt!("unnamed-%s", name)
|
||||||
}
|
}
|
||||||
|
|
||||||
impl NodeSelectHandler: SelectHandler<Node> {
|
fn node_name(data: &NodeData) -> ~str {
|
||||||
fn node_name(node: &Node) -> ~str {
|
|
||||||
do node.read |data| {
|
|
||||||
match *data.kind {
|
match *data.kind {
|
||||||
Doctype(*) => unnamed_node("doctype"),
|
Doctype(*) => unnamed_node("doctype"),
|
||||||
Comment(*) => unnamed_node("comment"),
|
Comment(*) => unnamed_node("comment"),
|
||||||
Element(ref data) => copy data.tag_name,
|
Element(ref data) => copy data.tag_name,
|
||||||
Text(*) => unnamed_node("text")
|
Text(*) => unnamed_node("text")
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl NodeSelectHandler: SelectHandler<Node> {
|
||||||
|
fn node_name(node: &Node) -> ~str {
|
||||||
|
do node.read |data| {
|
||||||
|
node_name(data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn named_parent_node(node: &Node, name: &str) -> Option<Node> {
|
||||||
|
let parent = tree::parent(&NodeTree, node);
|
||||||
|
match parent {
|
||||||
|
Some(parent) => {
|
||||||
|
do parent.read |data| {
|
||||||
|
if name == node_name(data) {
|
||||||
|
Some(parent)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None => None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn parent_node(node: &Node) -> Option<Node> {
|
||||||
|
tree::parent(&NodeTree, node)
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -11,6 +11,7 @@ use core::rand;
|
||||||
use css::compute::ComputeStyles;
|
use css::compute::ComputeStyles;
|
||||||
use newcss::values::{BoxSizing, Length, Px, CSSDisplay, Specified, BgColor, BgColorTransparent};
|
use newcss::values::{BoxSizing, Length, Px, CSSDisplay, Specified, BgColor, BgColorTransparent};
|
||||||
use newcss::values::{BdrColor, PosAbsolute};
|
use newcss::values::{BdrColor, PosAbsolute};
|
||||||
|
use newcss::values::{BdrWidthLength, BdrWidthMedium};
|
||||||
use newcss::color::{Color, rgba};
|
use newcss::color::{Color, rgba};
|
||||||
use dom::element::{ElementKind, HTMLDivElement, HTMLImageElement};
|
use dom::element::{ElementKind, HTMLDivElement, HTMLImageElement};
|
||||||
use dom::node::{Element, Node, NodeData, NodeKind, NodeTree};
|
use dom::node::{Element, Node, NodeData, NodeKind, NodeTree};
|
||||||
|
@ -441,7 +442,10 @@ impl RenderBox : RenderBoxMethods {
|
||||||
let left_width = self.d().node.compute_border_left_width();
|
let left_width = self.d().node.compute_border_left_width();
|
||||||
|
|
||||||
match (top_width, right_width, bottom_width, left_width) {
|
match (top_width, right_width, bottom_width, left_width) {
|
||||||
(Px(top), Px(right), Px(bottom), Px(left)) => {
|
(BdrWidthLength(Px(top)),
|
||||||
|
BdrWidthLength(Px(right)),
|
||||||
|
BdrWidthLength(Px(bottom)),
|
||||||
|
BdrWidthLength(Px(left))) => {
|
||||||
let top_au = au::from_frac_px(top);
|
let top_au = au::from_frac_px(top);
|
||||||
let right_au = au::from_frac_px(right);
|
let right_au = au::from_frac_px(right);
|
||||||
let bottom_au = au::from_frac_px(bottom);
|
let bottom_au = au::from_frac_px(bottom);
|
||||||
|
@ -462,12 +466,19 @@ impl RenderBox : RenderBoxMethods {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let color = rgb(0, 128, 255).to_gfx_color(); // FIXME
|
let color = rgb(0, 128, 255).to_gfx_color(); // FIXME
|
||||||
//list.append_item(~DisplayItem::new_Border(&bounds, border_width, color));
|
list.append_item(~DisplayItem::new_Border(&bounds, border_width, color));
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
fail ~"unimplemented border widths";
|
fail ~"unimplemented border widths";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
(BdrWidthMedium,
|
||||||
|
BdrWidthMedium,
|
||||||
|
BdrWidthMedium,
|
||||||
|
BdrWidthMedium) => {
|
||||||
|
// FIXME: This seems to be the default for non-root nodes. For now we'll ignore it
|
||||||
|
warn!("ignoring medium border widths");
|
||||||
|
}
|
||||||
_ => fail ~"unimplemented border widths"
|
_ => fail ~"unimplemented border widths"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue