style: Unbox a bunch of color properties.

This builds on https://github.com/servo/rust-cssparser/pull/118.
This commit is contained in:
Emilio Cobos Álvarez 2017-02-12 15:17:45 +01:00
parent e394334739
commit 0c102e2350
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C
37 changed files with 185 additions and 195 deletions

View file

@ -90,12 +90,7 @@ struct CanvasContextState {
impl CanvasContextState {
fn new() -> CanvasContextState {
let black = RGBA {
red: 0.0,
green: 0.0,
blue: 0.0,
alpha: 1.0,
};
let black = RGBA::new(0, 0, 0, 255);
CanvasContextState {
global_alpha: 1.0,
global_composition: CompositionOrBlending::default(),
@ -110,7 +105,7 @@ impl CanvasContextState {
shadow_offset_x: 0.0,
shadow_offset_y: 0.0,
shadow_blur: 0.0,
shadow_color: RGBA { red: 0.0, green: 0.0, blue: 0.0, alpha: 0.0 }, // transparent black
shadow_color: RGBA::transparent(),
}
}
}
@ -490,12 +485,7 @@ impl CanvasRenderingContext2D {
style.GetPropertyValue(DOMString::from("display")) == "none";
if element_not_rendered {
Ok(RGBA {
red: 0.0,
green: 0.0,
blue: 0.0,
alpha: 1.0,
})
Ok(RGBA::new(0, 0, 0, 255))
} else {
self.parse_color(&style.GetPropertyValue(DOMString::from("color")))
}
@ -1349,11 +1339,11 @@ fn is_rect_valid(rect: Rect<f64>) -> bool {
fn serialize<W>(color: &RGBA, dest: &mut W) -> fmt::Result
where W: fmt::Write
{
let red = (color.red * 255.).round() as u8;
let green = (color.green * 255.).round() as u8;
let blue = (color.blue * 255.).round() as u8;
let red = color.red;
let green = color.green;
let blue = color.blue;
if color.alpha == 1f32 {
if color.alpha == 255 {
write!(dest,
"#{:x}{:x}{:x}{:x}{:x}{:x}",
red >> 4,
@ -1363,6 +1353,6 @@ fn serialize<W>(color: &RGBA, dest: &mut W) -> fmt::Result
blue >> 4,
blue & 0xF)
} else {
write!(dest, "rgba({}, {}, {}, {})", red, green, blue, color.alpha)
write!(dest, "rgba({}, {}, {}, {})", red, green, blue, color.alpha_f32())
}
}