diff --git a/Cargo.lock b/Cargo.lock index d8b22030bbb..ebf5e46c4e9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1171,7 +1171,7 @@ dependencies = [ [[package]] name = "cssparser" version = "0.30.0" -source = "git+https://github.com/servo/rust-cssparser?rev=b196a164dcbb317016d4aa6c58c13147e6045ebb#b196a164dcbb317016d4aa6c58c13147e6045ebb" +source = "git+https://github.com/servo/rust-cssparser?rev=45bc47e2bcb846f1efb5aea156be5fe7d18624bf#45bc47e2bcb846f1efb5aea156be5fe7d18624bf" dependencies = [ "cssparser-macros", "dtoa-short", @@ -1187,7 +1187,7 @@ dependencies = [ [[package]] name = "cssparser-macros" version = "0.6.0" -source = "git+https://github.com/servo/rust-cssparser?rev=b196a164dcbb317016d4aa6c58c13147e6045ebb#b196a164dcbb317016d4aa6c58c13147e6045ebb" +source = "git+https://github.com/servo/rust-cssparser?rev=45bc47e2bcb846f1efb5aea156be5fe7d18624bf#45bc47e2bcb846f1efb5aea156be5fe7d18624bf" dependencies = [ "quote", "syn 1.0.103", diff --git a/Cargo.toml b/Cargo.toml index bd88e2dec7a..f2633635e04 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,7 +27,7 @@ compositing_traits = { path = "components/shared/compositing" } content-security-policy = { version = "0.5", features = ["serde"] } cookie = "0.12" crossbeam-channel = "0.5" -cssparser = { version = "0.30", git = "https://github.com/servo/rust-cssparser", rev = "b196a164dcbb317016d4aa6c58c13147e6045ebb" } +cssparser = { version = "0.30", git = "https://github.com/servo/rust-cssparser", rev = "45bc47e2bcb846f1efb5aea156be5fe7d18624bf" } darling = { version = "0.14", default-features = false } data-url = "0.1.0" devtools_traits = { path = "components/shared/devtools" } diff --git a/components/canvas/raqote_backend.rs b/components/canvas/raqote_backend.rs index ab4bab11c8d..36e0de9351b 100644 --- a/components/canvas/raqote_backend.rs +++ b/components/canvas/raqote_backend.rs @@ -885,10 +885,10 @@ pub fn clamp_floor_256_f32(val: f32) -> u8 { impl ToRaqoteGradientStop for CanvasGradientStop { fn to_raqote(&self) -> raqote::GradientStop { let color = raqote::Color::new( - clamp_unit_f32(self.color.alpha), - self.color.red, - self.color.green, - self.color.blue, + self.color.alpha.map(clamp_unit_f32).unwrap_or(0), + self.color.red.unwrap_or(0), + self.color.green.unwrap_or(0), + self.color.blue.unwrap_or(0), ); let position = self.offset as f32; raqote::GradientStop { position, color } @@ -902,10 +902,10 @@ impl<'a> ToRaqotePattern<'_> for FillOrStrokeStyle { match self { Color(color) => Some(Pattern::Color( - clamp_unit_f32(color.alpha), - color.red, - color.green, - color.blue, + color.alpha.map(clamp_unit_f32).unwrap_or(0), + color.red.unwrap_or(0), + color.green.unwrap_or(0), + color.blue.unwrap_or(0), )), LinearGradient(style) => { let start = Point2D::new(style.x0 as f32, style.y0 as f32); @@ -961,10 +961,10 @@ impl ToRaqoteStyle for RGBA { fn to_raqote_style(self) -> Self::Target { raqote::SolidSource::from_unpremultiplied_argb( - clamp_unit_f32(self.alpha), - self.red, - self.green, - self.blue, + self.alpha.map(clamp_unit_f32).unwrap_or(0), + self.red.unwrap_or(0), + self.green.unwrap_or(0), + self.blue.unwrap_or(0), ) } } diff --git a/components/script/canvas_state.rs b/components/script/canvas_state.rs index 4af444cc272..31dee618d4a 100644 --- a/components/script/canvas_state.rs +++ b/components/script/canvas_state.rs @@ -112,7 +112,7 @@ impl CanvasContextState { const DEFAULT_FONT_STYLE: &'static str = "10px sans-serif"; pub(crate) fn new() -> CanvasContextState { - let black = RGBA::new(0, 0, 0, 1.0); + let black = RGBA::new(Some(0), Some(0), Some(0), Some(1.0)); CanvasContextState { global_alpha: 1.0, global_composition: CompositionOrBlending::default(), @@ -127,7 +127,7 @@ impl CanvasContextState { shadow_offset_x: 0.0, shadow_offset_y: 0.0, shadow_blur: 0.0, - shadow_color: RGBA::transparent(), + shadow_color: RGBA::new(Some(0), Some(0), Some(0), Some(0.0)), font_style: None, text_align: Default::default(), text_baseline: Default::default(), @@ -1711,10 +1711,10 @@ pub fn parse_color(canvas: Option<&HTMLCanvasElement>, string: &str) -> Result Err(()), @@ -1732,11 +1732,12 @@ pub fn serialize(color: &RGBA, dest: &mut W) -> fmt::Result where W: fmt::Write, { - let red = color.red; - let green = color.green; - let blue = color.blue; + let red = color.red.unwrap_or(0); + let green = color.green.unwrap_or(0); + let blue = color.blue.unwrap_or(0); + let alpha = color.alpha.unwrap_or(0.0); - if color.alpha == 1.0 { + if alpha == 1.0 { write!( dest, "#{:x}{:x}{:x}{:x}{:x}{:x}", @@ -1748,14 +1749,7 @@ where blue & 0xF ) } else { - write!( - dest, - "rgba({}, {}, {}, {})", - red, - green, - blue, - color.alpha_f32() - ) + write!(dest, "rgba({}, {}, {}, {})", red, green, blue, alpha) } } diff --git a/components/style/attr.rs b/components/style/attr.rs index 4924cbf13ce..c4526f25b3f 100644 --- a/components/style/attr.rs +++ b/components/style/attr.rs @@ -431,7 +431,7 @@ pub fn parse_legacy_color(mut input: &str) -> Result { hex(input.as_bytes()[2] as char), hex(input.as_bytes()[3] as char), ) { - return Ok(RGBA::new(r * 17, g * 17, b * 17, 1.0)); + return Ok(RGBA::new(Some(r * 17), Some(g * 17), Some(b * 17), Some(1.0))); } } @@ -501,10 +501,10 @@ pub fn parse_legacy_color(mut input: &str) -> Result { // Steps 15-20. return Ok(RGBA::new( - hex_string(red).unwrap(), - hex_string(green).unwrap(), - hex_string(blue).unwrap(), - 1.0, + Some(hex_string(red).unwrap()), + Some(hex_string(green).unwrap()), + Some(hex_string(blue).unwrap()), + Some(1.0), )); fn hex(ch: char) -> Result {