mirror of
https://github.com/servo/servo.git
synced 2025-08-02 20:20:14 +01:00
style: Unbox a bunch of color properties.
This builds on https://github.com/servo/rust-cssparser/pull/118.
This commit is contained in:
parent
e394334739
commit
0c102e2350
37 changed files with 185 additions and 195 deletions
|
@ -34,7 +34,7 @@ byteorder = "1.0"
|
|||
canvas_traits = {path = "../canvas_traits"}
|
||||
caseless = "0.1.0"
|
||||
cookie = {version = "0.2.5", features = ["serialize-rustc"]}
|
||||
cssparser = {version = "0.7", features = ["heap_size", "serde-serialization"]}
|
||||
cssparser = {version = "0.8", features = ["heap_size", "serde-serialization"]}
|
||||
devtools_traits = {path = "../devtools_traits"}
|
||||
encoding = "0.2"
|
||||
euclid = "0.10.1"
|
||||
|
|
|
@ -57,7 +57,7 @@ impl CanvasGradientMethods for CanvasGradient {
|
|||
let color = if parser.is_exhausted() {
|
||||
match color {
|
||||
Ok(CSSColor::RGBA(rgba)) => rgba,
|
||||
Ok(CSSColor::CurrentColor) => RGBA { red: 0.0, green: 0.0, blue: 0.0, alpha: 1.0 },
|
||||
Ok(CSSColor::CurrentColor) => RGBA::new(0, 0, 0, 255),
|
||||
_ => return Err(Error::Syntax)
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -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())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -407,7 +407,7 @@ impl LayoutElementHelpers for LayoutJS<Element> {
|
|||
if let Some(color) = bgcolor {
|
||||
hints.push(from_declaration(
|
||||
PropertyDeclaration::BackgroundColor(DeclaredValue::Value(
|
||||
Box::new(CSSColor { parsed: Color::RGBA(color), authored: None })))));
|
||||
CSSColor { parsed: Color::RGBA(color), authored: None }))));
|
||||
}
|
||||
|
||||
let background = if let Some(this) = self.downcast::<HTMLBodyElement>() {
|
||||
|
@ -440,10 +440,10 @@ impl LayoutElementHelpers for LayoutJS<Element> {
|
|||
|
||||
if let Some(color) = color {
|
||||
hints.push(from_declaration(
|
||||
PropertyDeclaration::Color(DeclaredValue::Value(Box::new(CSSRGBA {
|
||||
PropertyDeclaration::Color(DeclaredValue::Value(CSSRGBA {
|
||||
parsed: color,
|
||||
authored: None,
|
||||
})))));
|
||||
}))));
|
||||
}
|
||||
|
||||
let font_family = if let Some(this) = self.downcast::<HTMLFontElement>() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue