From 0c102e2350a637869cee2bc479ea4665f95e0ddd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Sun, 12 Feb 2017 15:17:45 +0100 Subject: [PATCH] style: Unbox a bunch of color properties. This builds on https://github.com/servo/rust-cssparser/pull/118. --- Cargo.lock | 28 ++++----- components/canvas/Cargo.toml | 2 +- components/canvas/canvas_paint_thread.rs | 8 +-- components/canvas_traits/Cargo.toml | 2 +- components/layout/Cargo.toml | 2 +- components/layout/display_list_builder.rs | 2 +- components/layout/table_row.rs | 7 +-- components/msg/Cargo.toml | 2 +- components/script/Cargo.toml | 2 +- components/script/dom/canvasgradient.rs | 2 +- .../script/dom/canvasrenderingcontext2d.rs | 26 +++----- components/script/dom/element.rs | 6 +- components/script_layout_interface/Cargo.toml | 2 +- components/selectors/Cargo.toml | 2 +- components/style/Cargo.toml | 2 +- components/style/attr.rs | 17 ++---- components/style/gecko/values.rs | 18 +++--- .../helpers/animated_properties.mako.rs | 31 +++++----- .../properties/longhand/background.mako.rs | 4 +- .../style/properties/longhand/border.mako.rs | 2 +- .../style/properties/longhand/color.mako.rs | 10 ++-- .../style/properties/longhand/column.mako.rs | 2 +- .../longhand/inherited_text.mako.rs | 9 ++- .../style/properties/longhand/outline.mako.rs | 2 +- .../style/properties/longhand/svg.mako.rs | 9 +-- .../style/properties/longhand/text.mako.rs | 7 +-- .../properties/shorthand/serialize.mako.rs | 2 +- components/style/values/specified/mod.rs | 6 +- components/style_traits/Cargo.toml | 2 +- ports/geckolib/Cargo.toml | 2 +- ports/geckolib/glue.rs | 4 +- tests/unit/style/Cargo.toml | 2 +- tests/unit/style/animated_properties.rs | 60 ++++++++++++------- tests/unit/style/properties/serialization.rs | 60 +++++++++---------- tests/unit/style/size_of.rs | 24 +++++--- tests/unit/style/stylesheets.rs | 10 ++-- tests/unit/stylo/Cargo.toml | 2 +- 37 files changed, 185 insertions(+), 195 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 226f46d37f5..72aff1b1b73 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -285,7 +285,7 @@ version = "0.0.1" dependencies = [ "azure 0.11.0 (git+https://github.com/servo/rust-azure)", "canvas_traits 0.0.1", - "cssparser 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)", + "cssparser 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "euclid 0.10.5 (registry+https://github.com/rust-lang/crates.io-index)", "gleam 0.2.32 (registry+https://github.com/rust-lang/crates.io-index)", "ipc-channel 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -301,7 +301,7 @@ dependencies = [ name = "canvas_traits" version = "0.0.1" dependencies = [ - "cssparser 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)", + "cssparser 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "euclid 0.10.5 (registry+https://github.com/rust-lang/crates.io-index)", "heapsize 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", "heapsize_derive 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", @@ -543,7 +543,7 @@ dependencies = [ [[package]] name = "cssparser" -version = "0.7.4" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "encoding 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)", @@ -926,7 +926,7 @@ version = "0.0.1" dependencies = [ "app_units 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "atomic_refcell 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "cssparser 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)", + "cssparser 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "env_logger 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "euclid 0.10.5 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1335,7 +1335,7 @@ dependencies = [ "atomic_refcell 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "canvas_traits 0.0.1", - "cssparser 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)", + "cssparser 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "euclid 0.10.5 (registry+https://github.com/rust-lang/crates.io-index)", "fnv 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", "gfx 0.0.1", @@ -1652,7 +1652,7 @@ name = "msg" version = "0.0.1" dependencies = [ "bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", - "cssparser 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)", + "cssparser 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "heapsize 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", "heapsize_derive 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "plugins 0.0.1", @@ -2253,7 +2253,7 @@ dependencies = [ "caseless 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "cmake 0.1.20 (registry+https://github.com/rust-lang/crates.io-index)", "cookie 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", - "cssparser 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)", + "cssparser 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "devtools_traits 0.0.1", "encoding 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)", "euclid 0.10.5 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2320,7 +2320,7 @@ dependencies = [ "app_units 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "atomic_refcell 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "canvas_traits 0.0.1", - "cssparser 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)", + "cssparser 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "euclid 0.10.5 (registry+https://github.com/rust-lang/crates.io-index)", "gfx_traits 0.0.1", "heapsize 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2388,7 +2388,7 @@ name = "selectors" version = "0.18.0" dependencies = [ "bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", - "cssparser 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)", + "cssparser 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "fnv 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", "matches 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -2741,7 +2741,7 @@ dependencies = [ "bindgen 0.21.1 (registry+https://github.com/rust-lang/crates.io-index)", "bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "cfg-if 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "cssparser 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)", + "cssparser 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "encoding 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)", "euclid 0.10.5 (registry+https://github.com/rust-lang/crates.io-index)", "fnv 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2783,7 +2783,7 @@ name = "style_tests" version = "0.0.1" dependencies = [ "app_units 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "cssparser 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)", + "cssparser 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "euclid 0.10.5 (registry+https://github.com/rust-lang/crates.io-index)", "html5ever-atoms 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "matches 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2804,7 +2804,7 @@ name = "style_traits" version = "0.0.1" dependencies = [ "app_units 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "cssparser 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)", + "cssparser 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "euclid 0.10.5 (registry+https://github.com/rust-lang/crates.io-index)", "heapsize 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", "heapsize_derive 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2819,7 +2819,7 @@ version = "0.0.1" dependencies = [ "app_units 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "atomic_refcell 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "cssparser 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)", + "cssparser 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "env_logger 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "euclid 0.10.5 (registry+https://github.com/rust-lang/crates.io-index)", "geckoservo 0.0.1", @@ -3378,7 +3378,7 @@ dependencies = [ "checksum core-foundation-sys 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "41115a6aa5d3e1e5ef98148373f25971d1fad53818553f216495f9e67e90a624" "checksum core-graphics 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7b205856aba54bfd36e69a1058f45fbe0d3c37be7375309dcff4a22a2a631fea" "checksum core-text 3.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9703f459a41e622b15ca612dbc5fa4b30b6545a32864a83e0fdc538cfa08969c" -"checksum cssparser 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)" = "d8e562cb0d6ee9d8c367d3801d4dbaa0a0a94807745f710803b4ec4cf723ddd4" +"checksum cssparser 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "03414777f8f1b026d920f7f96e4a19d0237456a0485fb6135847b7699c258ec2" "checksum dbghelp-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "97590ba53bcb8ac28279161ca943a924d1fd4a8fb3fa63302591647c4fc5b850" "checksum dbus 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "94d266a872aaf68b50d02083c429a3686935ab6ab54824290509cdc422673eaf" "checksum debug_unreachable 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9a032eac705ca39214d169f83e3d3da290af06d8d1d344d1baad2fd002dca4b3" diff --git a/components/canvas/Cargo.toml b/components/canvas/Cargo.toml index 141bf72644e..f964e0cab10 100644 --- a/components/canvas/Cargo.toml +++ b/components/canvas/Cargo.toml @@ -12,7 +12,7 @@ path = "lib.rs" [dependencies] azure = {git = "https://github.com/servo/rust-azure", features = ["plugins"]} canvas_traits = {path = "../canvas_traits"} -cssparser = {version = "0.7", features = ["heap_size", "serde-serialization"]} +cssparser = {version = "0.8", features = ["heap_size", "serde-serialization"]} euclid = "0.10.1" gleam = "0.2.8" ipc-channel = "0.5" diff --git a/components/canvas/canvas_paint_thread.rs b/components/canvas/canvas_paint_thread.rs index 43778555736..831b5a161fe 100644 --- a/components/canvas/canvas_paint_thread.rs +++ b/components/canvas/canvas_paint_thread.rs @@ -1016,9 +1016,9 @@ impl ToAzureStyle for RGBA { type Target = Color; fn to_azure_style(self) -> Color { - Color::rgba(self.red as AzFloat, - self.green as AzFloat, - self.blue as AzFloat, - self.alpha as AzFloat) + Color::rgba(self.red_f32() as AzFloat, + self.green_f32() as AzFloat, + self.blue_f32() as AzFloat, + self.alpha_f32() as AzFloat) } } diff --git a/components/canvas_traits/Cargo.toml b/components/canvas_traits/Cargo.toml index 3edd00113a7..ac67df0e81e 100644 --- a/components/canvas_traits/Cargo.toml +++ b/components/canvas_traits/Cargo.toml @@ -10,7 +10,7 @@ name = "canvas_traits" path = "lib.rs" [dependencies] -cssparser = {version = "0.7", features = ["heap_size", "serde-serialization"]} +cssparser = {version = "0.8", features = ["heap_size", "serde-serialization"]} euclid = "0.10.1" heapsize = "0.3.0" heapsize_derive = "0.1" diff --git a/components/layout/Cargo.toml b/components/layout/Cargo.toml index 7072372aeb0..bb837bff962 100644 --- a/components/layout/Cargo.toml +++ b/components/layout/Cargo.toml @@ -14,7 +14,7 @@ app_units = "0.3" atomic_refcell = "0.1" bitflags = "0.7" canvas_traits = {path = "../canvas_traits"} -cssparser = {version = "0.7", features = ["heap_size", "serde-serialization"]} +cssparser = {version = "0.8", features = ["heap_size", "serde-serialization"]} euclid = "0.10.1" fnv = "1.0" gfx = {path = "../gfx"} diff --git a/components/layout/display_list_builder.rs b/components/layout/display_list_builder.rs index 4dc72f20301..848188d14a0 100644 --- a/components/layout/display_list_builder.rs +++ b/components/layout/display_list_builder.rs @@ -2188,7 +2188,7 @@ pub trait ToGfxColor { impl ToGfxColor for RGBA { fn to_gfx_color(&self) -> ColorF { - ColorF::new(self.red, self.green, self.blue, self.alpha) + ColorF::new(self.red_f32(), self.green_f32(), self.blue_f32(), self.alpha_f32()) } } diff --git a/components/layout/table_row.rs b/components/layout/table_row.rs index 6423e56cbeb..0370d785e15 100644 --- a/components/layout/table_row.rs +++ b/components/layout/table_row.rs @@ -607,12 +607,7 @@ impl CollapsedBorder { CollapsedBorder { style: border_top_style::T::none, width: Au(0), - color: Color::RGBA(RGBA { - red: 0.0, - green: 0.0, - blue: 0.0, - alpha: 0.0, - }), + color: Color::RGBA(RGBA::transparent()), provenance: CollapsedBorderProvenance::FromTable, } } diff --git a/components/msg/Cargo.toml b/components/msg/Cargo.toml index dc1ec78bbb9..6300a7a0587 100644 --- a/components/msg/Cargo.toml +++ b/components/msg/Cargo.toml @@ -11,7 +11,7 @@ path = "lib.rs" [dependencies] bitflags = "0.7" -cssparser = {version = "0.7", features = ["heap_size", "serde-serialization"]} +cssparser = {version = "0.8", features = ["heap_size", "serde-serialization"]} heapsize = "0.3.0" heapsize_derive = "0.1" plugins = {path = "../plugins"} diff --git a/components/script/Cargo.toml b/components/script/Cargo.toml index 57ea9b4b648..f3b37aab950 100644 --- a/components/script/Cargo.toml +++ b/components/script/Cargo.toml @@ -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" diff --git a/components/script/dom/canvasgradient.rs b/components/script/dom/canvasgradient.rs index 0fafc1c6f0f..6491148e5aa 100644 --- a/components/script/dom/canvasgradient.rs +++ b/components/script/dom/canvasgradient.rs @@ -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 { diff --git a/components/script/dom/canvasrenderingcontext2d.rs b/components/script/dom/canvasrenderingcontext2d.rs index 80de3610e89..fff339e1cc7 100644 --- a/components/script/dom/canvasrenderingcontext2d.rs +++ b/components/script/dom/canvasrenderingcontext2d.rs @@ -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) -> bool { fn serialize(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(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()) } } diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs index cf4373fbeb6..0c681f9759c 100644 --- a/components/script/dom/element.rs +++ b/components/script/dom/element.rs @@ -407,7 +407,7 @@ impl LayoutElementHelpers for LayoutJS { 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::() { @@ -440,10 +440,10 @@ impl LayoutElementHelpers for LayoutJS { 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::() { diff --git a/components/script_layout_interface/Cargo.toml b/components/script_layout_interface/Cargo.toml index d7892f4962d..aded2413ff1 100644 --- a/components/script_layout_interface/Cargo.toml +++ b/components/script_layout_interface/Cargo.toml @@ -13,7 +13,7 @@ path = "lib.rs" app_units = "0.3" atomic_refcell = "0.1" canvas_traits = {path = "../canvas_traits"} -cssparser = {version = "0.7", features = ["heap_size", "serde-serialization"]} +cssparser = {version = "0.8", features = ["heap_size", "serde-serialization"]} euclid = "0.10.1" gfx_traits = {path = "../gfx_traits"} heapsize = "0.3.0" diff --git a/components/selectors/Cargo.toml b/components/selectors/Cargo.toml index 03c8ced7e72..c62ac79a7fa 100644 --- a/components/selectors/Cargo.toml +++ b/components/selectors/Cargo.toml @@ -18,5 +18,5 @@ path = "lib.rs" [dependencies] bitflags = "0.7" matches = "0.1" -cssparser = ">=0.6, <0.8" +cssparser = ">=0.6, <0.9" fnv = "1.0" diff --git a/components/style/Cargo.toml b/components/style/Cargo.toml index 312c40099f5..54fb28e7dde 100644 --- a/components/style/Cargo.toml +++ b/components/style/Cargo.toml @@ -26,7 +26,7 @@ app_units = "0.3" atomic_refcell = "0.1" bitflags = "0.7" cfg-if = "0.1.0" -cssparser = "0.7.3" +cssparser = "0.8" encoding = "0.2" euclid = "0.10.1" fnv = "1.0" diff --git a/components/style/attr.rs b/components/style/attr.rs index ab3097d5ae7..0d07a35e828 100644 --- a/components/style/attr.rs +++ b/components/style/attr.rs @@ -394,12 +394,7 @@ pub fn parse_legacy_color(mut input: &str) -> Result { hex(input.as_bytes()[1] as char), hex(input.as_bytes()[2] as char), hex(input.as_bytes()[3] as char)) { - return Ok(RGBA { - red: (r as f32) * 17.0 / 255.0, - green: (g as f32) * 17.0 / 255.0, - blue: (b as f32) * 17.0 / 255.0, - alpha: 1.0, - }) + return Ok(RGBA::new(r * 17, g * 17, b * 17, 255)) } } @@ -466,12 +461,10 @@ pub fn parse_legacy_color(mut input: &str) -> Result { } // Steps 15-20. - return Ok(RGBA { - red: hex_string(red).unwrap() as f32 / 255.0, - green: hex_string(green).unwrap() as f32 / 255.0, - blue: hex_string(blue).unwrap() as f32 / 255.0, - alpha: 1.0, - }); + return Ok(RGBA::new(hex_string(red).unwrap(), + hex_string(green).unwrap(), + hex_string(blue).unwrap(), + 255)); fn hex(ch: char) -> Result { match ch { diff --git a/components/style/gecko/values.rs b/components/style/gecko/values.rs index a187f2f78c6..5e9f6dabd45 100644 --- a/components/style/gecko/values.rs +++ b/components/style/gecko/values.rs @@ -225,20 +225,18 @@ impl GeckoStyleCoordConvertible for None_ { /// Convert a given RGBA value to `nscolor`. pub fn convert_rgba_to_nscolor(rgba: &RGBA) -> u32 { - (((rgba.alpha * 255.0).round() as u32) << 24) | - (((rgba.blue * 255.0).round() as u32) << 16) | - (((rgba.green * 255.0).round() as u32) << 8) | - ((rgba.red * 255.0).round() as u32) + ((rgba.alpha as u32) << 24) | + ((rgba.blue as u32) << 16) | + ((rgba.green as u32) << 8) | + (rgba.red as u32) } /// Convert a given `nscolor` to a Servo RGBA value. pub fn convert_nscolor_to_rgba(color: u32) -> RGBA { - RGBA { - red: ((color & 0xff) as f32) / 255.0, - green: (((color >> 8) & 0xff) as f32) / 255.0, - blue: (((color >> 16) & 0xff) as f32) / 255.0, - alpha: (((color >> 24) & 0xff) as f32) / 255.0, - } + RGBA::new((color & 0xff) as u8, + (color >> 8 & 0xff) as u8, + (color >> 16 & 0xff) as u8, + (color >> 24 & 0xff) as u8) } /// Round `width` down to the nearest device pixel, but any non-zero value that diff --git a/components/style/properties/helpers/animated_properties.mako.rs b/components/style/properties/helpers/animated_properties.mako.rs index fae2c82e54d..3c05fc06e31 100644 --- a/components/style/properties/helpers/animated_properties.mako.rs +++ b/components/style/properties/helpers/animated_properties.mako.rs @@ -510,18 +510,21 @@ impl Interpolate for RGBA { val.max(0.).min(1.) } - let alpha = clamp(try!(self.alpha.interpolate(&other.alpha, progress))); + let alpha = clamp(try!(self.alpha_f32().interpolate(&other.alpha_f32(), progress))); if alpha == 0. { - Ok(RGBA { red: 0., green: 0., blue: 0., alpha: 0. }) + Ok(RGBA::transparent()) } else { - Ok(RGBA { red: clamp(try!((self.red * self.alpha).interpolate(&(other.red * other.alpha), progress)) - * 1. / alpha), - green: clamp(try!((self.green * self.alpha).interpolate(&(other.green * other.alpha), progress)) - * 1. / alpha), - blue: clamp(try!((self.blue * self.alpha).interpolate(&(other.blue * other.alpha), progress)) - * 1. / alpha), - alpha: alpha - }) + // NB: We rely on RGBA::from_floats clamping already. + let red = try!((self.red_f32() * self.alpha_f32()) + .interpolate(&(other.red_f32() * other.alpha_f32()), progress)) + * 1. / alpha; + let green = try!((self.green_f32() * self.alpha_f32()) + .interpolate(&(other.green_f32() * other.alpha_f32()), progress)) + * 1. / alpha; + let blue = try!((self.blue_f32() * self.alpha_f32()) + .interpolate(&(other.blue_f32() * other.alpha_f32()), progress)) + * 1. / alpha; + Ok(RGBA::from_floats(red, green, blue, alpha)) } } } @@ -756,9 +759,7 @@ impl Interpolate for TextShadowList { offset_x: Au(0), offset_y: Au(0), blur_radius: Au(0), - color: CSSParserColor::RGBA(RGBA { - red: 0.0, green: 0.0, blue: 0.0, alpha: 0.0 - }) + color: CSSParserColor::RGBA(RGBA::transparent()), }; let max_len = cmp::max(self.0.len(), other.0.len()); @@ -793,9 +794,7 @@ impl Interpolate for BoxShadowList { offset_y: Au(0), spread_radius: Au(0), blur_radius: Au(0), - color: CSSParserColor::RGBA(RGBA { - red: 0.0, green: 0.0, blue: 0.0, alpha: 0.0 - }), + color: CSSParserColor::RGBA(RGBA::transparent()), inset: false, }; diff --git a/components/style/properties/longhand/background.mako.rs b/components/style/properties/longhand/background.mako.rs index f8622e75d29..6aa537b269a 100644 --- a/components/style/properties/longhand/background.mako.rs +++ b/components/style/properties/longhand/background.mako.rs @@ -7,9 +7,9 @@ <% data.new_style_struct("Background", inherited=False) %> ${helpers.predefined_type("background-color", "CSSColor", - "::cssparser::Color::RGBA(::cssparser::RGBA { red: 0., green: 0., blue: 0., alpha: 0. }) /* transparent */", + "::cssparser::Color::RGBA(::cssparser::RGBA::transparent())", spec="https://drafts.csswg.org/css-backgrounds/#background-color", - animatable=True, complex_color=True, boxed=True)} + animatable=True, complex_color=True)} <%helpers:vector_longhand name="background-image" animatable="False" spec="https://drafts.csswg.org/css-backgrounds/#the-background-image" diff --git a/components/style/properties/longhand/border.mako.rs b/components/style/properties/longhand/border.mako.rs index 8a85377febb..8de98c8f527 100644 --- a/components/style/properties/longhand/border.mako.rs +++ b/components/style/properties/longhand/border.mako.rs @@ -20,7 +20,7 @@ "::cssparser::Color::CurrentColor", alias=maybe_moz_logical_alias(product, side, "-moz-border-%s-color"), spec=maybe_logical_spec(side, "color"), - animatable=True, logical = side[1], boxed=True)} + animatable=True, logical = side[1])} % endfor % for side in ALL_SIDES: diff --git a/components/style/properties/longhand/color.mako.rs b/components/style/properties/longhand/color.mako.rs index a2d9c8975cd..6062db455be 100644 --- a/components/style/properties/longhand/color.mako.rs +++ b/components/style/properties/longhand/color.mako.rs @@ -6,7 +6,7 @@ <% data.new_style_struct("Color", inherited=True) %> -<%helpers:raw_longhand name="color" need_clone="True" animatable="True" boxed="True" +<%helpers:raw_longhand name="color" need_clone="True" animatable="True" spec="https://drafts.csswg.org/css-color/#color"> use cssparser::Color as CSSParserColor; use cssparser::RGBA; @@ -36,18 +36,18 @@ } #[inline] pub fn get_initial_value() -> computed_value::T { - RGBA { red: 0., green: 0., blue: 0., alpha: 1. } /* black */ + RGBA::new(0, 0, 0, 255) // black } pub fn parse_specified(context: &ParserContext, input: &mut Parser) - -> Result>, ()> { + -> Result, ()> { let value = try!(CSSColor::parse(context, input)); let rgba = match value.parsed { CSSParserColor::RGBA(rgba) => rgba, CSSParserColor::CurrentColor => return Ok(DeclaredValue::Inherit) }; - Ok(DeclaredValue::Value(Box::new(CSSRGBA { + Ok(DeclaredValue::Value(CSSRGBA { parsed: rgba, authored: value.authored, - }))) + })) } diff --git a/components/style/properties/longhand/column.mako.rs b/components/style/properties/longhand/column.mako.rs index f06ea2b51f7..f55524f5201 100644 --- a/components/style/properties/longhand/column.mako.rs +++ b/components/style/properties/longhand/column.mako.rs @@ -147,7 +147,7 @@ ${helpers.single_keyword("column-fill", "auto balance", extra_prefixes="moz", ${helpers.predefined_type("column-rule-color", "CSSColor", "::cssparser::Color::CurrentColor", products="gecko", animatable=True, extra_prefixes="moz", - complex_color=True, need_clone=True, boxed=True, + complex_color=True, need_clone=True, spec="https://drafts.csswg.org/css-multicol/#propdef-column-rule-color")} // It's not implemented in servo or gecko yet. diff --git a/components/style/properties/longhand/inherited_text.mako.rs b/components/style/properties/longhand/inherited_text.mako.rs index dc3e32f99b3..3d5430aee3e 100644 --- a/components/style/properties/longhand/inherited_text.mako.rs +++ b/components/style/properties/longhand/inherited_text.mako.rs @@ -429,7 +429,7 @@ ${helpers.single_keyword("text-align-last", <%helpers:longhand name="-servo-text-decorations-in-effect" derived_from="display text-decoration" need_clone="True" products="servo" - animatable="False" boxed="True" + animatable="False" spec="Nonstandard (Internal property used by Servo)"> use cssparser::RGBA; use std::fmt; @@ -1025,9 +1025,8 @@ ${helpers.single_keyword("text-align-last", ${helpers.predefined_type("text-emphasis-color", "CSSColor", "::cssparser::Color::CurrentColor", - products="gecko",animatable=True, + products="gecko", animatable=True, complex_color=True, need_clone=True, - boxed=True, spec="https://drafts.csswg.org/css-text-decor/#propdef-text-emphasis-color")} @@ -1045,14 +1044,14 @@ ${helpers.predefined_type( "-webkit-text-fill-color", "CSSColor", "CSSParserColor::CurrentColor", products="gecko", animatable=True, - complex_color=True, need_clone=True, boxed=True, + complex_color=True, need_clone=True, spec="https://compat.spec.whatwg.org/#the-webkit-text-fill-color")} ${helpers.predefined_type( "-webkit-text-stroke-color", "CSSColor", "CSSParserColor::CurrentColor", products="gecko", animatable=True, - complex_color=True, need_clone=True, boxed=True, + complex_color=True, need_clone=True, spec="https://compat.spec.whatwg.org/#the-webkit-text-stroke-color")} <%helpers:longhand products="gecko" name="-webkit-text-stroke-width" animatable="False" diff --git a/components/style/properties/longhand/outline.mako.rs b/components/style/properties/longhand/outline.mako.rs index cd242797f0d..8b2f51ef2ed 100644 --- a/components/style/properties/longhand/outline.mako.rs +++ b/components/style/properties/longhand/outline.mako.rs @@ -11,7 +11,7 @@ // TODO(pcwalton): `invert` ${helpers.predefined_type("outline-color", "CSSColor", "::cssparser::Color::CurrentColor", - animatable=True, complex_color=True, need_clone=True, boxed=True, + animatable=True, complex_color=True, need_clone=True, spec="https://drafts.csswg.org/css-ui/#propdef-outline-color")} <%helpers:longhand name="outline-style" need_clone="True" animatable="False" diff --git a/components/style/properties/longhand/svg.mako.rs b/components/style/properties/longhand/svg.mako.rs index f4ea79eb5ae..de8ac632495 100644 --- a/components/style/properties/longhand/svg.mako.rs +++ b/components/style/properties/longhand/svg.mako.rs @@ -22,10 +22,9 @@ ${helpers.single_keyword("vector-effect", "none non-scaling-stroke", ${helpers.predefined_type( "stop-color", "CSSColor", - "CSSParserColor::RGBA(RGBA { red: 0.0, green: 0.0, blue: 0.0, alpha: 1.0 })", + "CSSParserColor::RGBA(RGBA::new(0, 0, 0, 255))", products="gecko", animatable=False, - boxed=True, spec="https://www.w3.org/TR/SVGTiny12/painting.html#StopColorProperty")} ${helpers.predefined_type("stop-opacity", "Opacity", "1.0", @@ -37,10 +36,9 @@ ${helpers.predefined_type("stop-opacity", "Opacity", "1.0", ${helpers.predefined_type( "flood-color", "CSSColor", - "CSSParserColor::RGBA(RGBA { red: 0.0, green: 0.0, blue: 0.0, alpha: 1.0 })", + "CSSParserColor::RGBA(RGBA::new(0, 0, 0, 255))", products="gecko", animatable=False, - boxed=True, spec="https://www.w3.org/TR/SVG/filters.html#FloodColorProperty")} ${helpers.predefined_type("flood-opacity", "Opacity", @@ -49,10 +47,9 @@ ${helpers.predefined_type("flood-opacity", "Opacity", ${helpers.predefined_type( "lighting-color", "CSSColor", - "CSSParserColor::RGBA(RGBA { red: 1.0, green: 1.0, blue: 1.0, alpha: 1.0 })", + "CSSParserColor::RGBA(RGBA::new(255, 255, 255, 255))", products="gecko", animatable=False, - boxed=True, spec="https://www.w3.org/TR/SVG/filters.html#LightingColorProperty")} // CSS Masking Module Level 1 diff --git a/components/style/properties/longhand/text.mako.rs b/components/style/properties/longhand/text.mako.rs index 2ea249924d5..56c57760518 100644 --- a/components/style/properties/longhand/text.mako.rs +++ b/components/style/properties/longhand/text.mako.rs @@ -28,7 +28,7 @@ pub enum Side { Clip, Ellipsis, - String(String), + String(Box), } #[derive(PartialEq, Eq, Clone, Debug)] @@ -66,7 +66,7 @@ _ => Err(()) } } else { - Ok(Side::String(try!(input.expect_string()).into_owned())) + Ok(Side::String(try!(input.expect_string()).into_owned().into_boxed_str())) } } } @@ -210,9 +210,8 @@ ${helpers.single_keyword("text-decoration-style", ${helpers.predefined_type( "text-decoration-color", "CSSColor", - "CSSParserColor::RGBA(RGBA { red: 0.0, green: 0.0, blue: 0.0, alpha: 1.0 })", + "CSSParserColor::RGBA(RGBA::new(0, 0, 0, 255))", complex_color=True, products="gecko", animatable=True, - boxed=True, spec="https://drafts.csswg.org/css-text-decor/#propdef-text-decoration-color")} diff --git a/components/style/properties/shorthand/serialize.mako.rs b/components/style/properties/shorthand/serialize.mako.rs index a9913165e2c..467542356c6 100644 --- a/components/style/properties/shorthand/serialize.mako.rs +++ b/components/style/properties/shorthand/serialize.mako.rs @@ -61,7 +61,7 @@ pub fn serialize_four_sides(dest: &mut W, fn serialize_directional_border(dest: &mut W, width: &DeclaredValue, style: &DeclaredValue, - color: &DeclaredValue>) + color: &DeclaredValue) -> fmt::Result where W: fmt::Write, I: ToCss { match *width { DeclaredValue::Value(ref width) => { diff --git a/components/style/values/specified/mod.rs b/components/style/values/specified/mod.rs index 8e3315f0ea6..e2c95b391d1 100644 --- a/components/style/values/specified/mod.rs +++ b/components/style/values/specified/mod.rs @@ -43,14 +43,14 @@ no_viewport_percentage!(i32); // For PropertyDeclaration::Order #[allow(missing_docs)] pub struct CSSColor { pub parsed: cssparser::Color, - pub authored: Option, + pub authored: Option>, } impl Parse for CSSColor { fn parse(_context: &ParserContext, input: &mut Parser) -> Result { let start_position = input.position(); let authored = match input.next() { - Ok(Token::Ident(s)) => Some(s.into_owned()), + Ok(Token::Ident(s)) => Some(s.into_owned().into_boxed_str()), _ => None, }; input.reset(start_position); @@ -77,7 +77,7 @@ impl ToCss for CSSColor { #[allow(missing_docs)] pub struct CSSRGBA { pub parsed: cssparser::RGBA, - pub authored: Option, + pub authored: Option>, } no_viewport_percentage!(CSSRGBA); diff --git a/components/style_traits/Cargo.toml b/components/style_traits/Cargo.toml index af4c9314381..1466f8e5923 100644 --- a/components/style_traits/Cargo.toml +++ b/components/style_traits/Cargo.toml @@ -15,7 +15,7 @@ servo = ["heapsize", "heapsize_derive", "serde", "serde_derive", [dependencies] app_units = "0.3" -cssparser = "0.7" +cssparser = "0.8" euclid = "0.10.1" heapsize = {version = "0.3.0", optional = true} heapsize_derive = {version = "0.1", optional = true} diff --git a/ports/geckolib/Cargo.toml b/ports/geckolib/Cargo.toml index 377710171ac..f0671cb4c2f 100644 --- a/ports/geckolib/Cargo.toml +++ b/ports/geckolib/Cargo.toml @@ -15,7 +15,7 @@ bindgen = ["style/use_bindgen"] [dependencies] app_units = "0.3" atomic_refcell = "0.1" -cssparser = {version = "0.7"} +cssparser = {version = "0.8"} env_logger = {version = "0.4", default-features = false} # disable `regex` to reduce code size euclid = "0.10.1" lazy_static = "0.2" diff --git a/ports/geckolib/glue.rs b/ports/geckolib/glue.rs index 7a3fb5832ae..582ee69c727 100644 --- a/ports/geckolib/glue.rs +++ b/ports/geckolib/glue.rs @@ -980,12 +980,12 @@ pub extern "C" fn Servo_DeclarationBlock_AddPresValue(declarations: RawServoDecl } LonghandId::Color => { if let Some(color) = css_value.color_value() { - PropertyDeclaration::Color(DeclaredValue::Value(Box::new( + PropertyDeclaration::Color(DeclaredValue::Value( specified::CSSRGBA { parsed: convert_nscolor_to_rgba(color), authored: None } - ))) + )) } else { error!("stylo: got unexpected non-integer value for color presentation attribute"); return diff --git a/tests/unit/style/Cargo.toml b/tests/unit/style/Cargo.toml index 28ef6b55065..c134cfb5579 100644 --- a/tests/unit/style/Cargo.toml +++ b/tests/unit/style/Cargo.toml @@ -14,7 +14,7 @@ testing = ["style/testing"] [dependencies] app_units = "0.3" -cssparser = {version = "0.7", features = ["heap_size"]} +cssparser = {version = "0.8", features = ["heap_size"]} euclid = "0.10.1" html5ever-atoms = "0.1" matches = "0.1" diff --git a/tests/unit/style/animated_properties.rs b/tests/unit/style/animated_properties.rs index af9d1461787..e486f0f1474 100644 --- a/tests/unit/style/animated_properties.rs +++ b/tests/unit/style/animated_properties.rs @@ -6,31 +6,45 @@ use cssparser::{Color, RGBA}; use style::properties::animated_properties::Interpolate; #[test] -fn test_rgba_color_interepolation() { - assert_eq!(Color::RGBA(RGBA { red: 0.0, green: 0.0, blue: 0.0, alpha: 0.0 }).interpolate( - &Color::RGBA(RGBA { red: 0.0, green: 0.0, blue: 0.0, alpha: 0.0 }), 1.0).unwrap(), - Color::RGBA(RGBA { red: 0.0, green: 0.0, blue: 0.0, alpha: 0.0 })); +fn test_rgba_color_interepolation_preserves_transparent() { + assert_eq!(Color::RGBA(RGBA::transparent()) + .interpolate(&Color::RGBA(RGBA::transparent()), 0.5).unwrap(), + Color::RGBA(RGBA::transparent())); +} - assert_eq!(Color::RGBA(RGBA { red: 1.0, green: 0.0, blue: 0.0, alpha: 0.6 }).interpolate( - &Color::RGBA(RGBA { red: 0.0, green: 1.0, blue: 0.0, alpha: 0.4 }), 0.5).unwrap(), - Color::RGBA(RGBA { red: 0.6, green: 0.4, blue: 0.0, alpha: 0.5 })); +#[test] +fn test_rgba_color_interepolation_alpha() { + assert_eq!(Color::RGBA(RGBA::new(200, 0, 0, 100)) + .interpolate(&Color::RGBA(RGBA::new(0, 200, 0, 200)), 0.5).unwrap(), + Color::RGBA(RGBA::new(66, 133, 0, 150))); +} +#[test] +fn test_rgba_color_interepolation_out_of_range_1() { // Some cubic-bezier functions produce values that are out of range [0, 1]. // Unclamped cases. - assert_eq!(Color::RGBA(RGBA { red: 0.3, green: 0.0, blue: 0.0, alpha: 0.4 }).interpolate( - &Color::RGBA(RGBA { red: 0.0, green: 1.0, blue: 0.0, alpha: 0.6 }), -0.5).unwrap(), - Color::RGBA(RGBA { red: 0.6, green: 0.0, blue: 0.0, alpha: 0.3 })); - - assert_eq!(Color::RGBA(RGBA { red: 1.0, green: 0.0, blue: 0.0, alpha: 0.6 }).interpolate( - &Color::RGBA(RGBA { red: 0.0, green: 0.3, blue: 0.0, alpha: 0.4 }), 1.5).unwrap(), - Color::RGBA(RGBA { red: 0.0, green: 0.6, blue: 0.0, alpha: 0.3 })); - - // Clamped cases. - assert_eq!(Color::RGBA(RGBA { red: 1.0, green: 0.0, blue: 0.0, alpha: 0.8 }).interpolate( - &Color::RGBA(RGBA { red: 0.0, green: 1.0, blue: 0.0, alpha: 0.2 }), -0.5).unwrap(), - Color::RGBA(RGBA { red: 1.0, green: 0.0, blue: 0.0, alpha: 1.0 })); - - assert_eq!(Color::RGBA(RGBA { red: 1.0, green: 0.0, blue: 0.0, alpha: 0.8 }).interpolate( - &Color::RGBA(RGBA { red: 0.0, green: 1.0, blue: 0.0, alpha: 0.2 }), 1.5).unwrap(), - Color::RGBA(RGBA { red: 0.0, green: 0.0, blue: 0.0, alpha: 0.0 })); + assert_eq!(Color::RGBA(RGBA::from_floats(0.3, 0.0, 0.0, 0.4)).interpolate( + &Color::RGBA(RGBA::from_floats(0.0, 1.0, 0.0, 0.6)), -0.5).unwrap(), + Color::RGBA(RGBA::new(152, 0, 0, 76))); +} + +#[test] +fn test_rgba_color_interepolation_out_of_range_2() { + assert_eq!(Color::RGBA(RGBA::from_floats(1.0, 0.0, 0.0, 0.6)).interpolate( + &Color::RGBA(RGBA::from_floats(0.0, 0.3, 0.0, 0.4)), 1.5).unwrap(), + Color::RGBA(RGBA::new(0, 152, 0, 76))); +} + +#[test] +fn test_rgba_color_interepolation_out_of_range_clamped_1() { + assert_eq!(Color::RGBA(RGBA::from_floats(1.0, 0.0, 0.0, 0.8)).interpolate( + &Color::RGBA(RGBA::from_floats(0.0, 1.0, 0.0, 0.2)), -0.5).unwrap(), + Color::RGBA(RGBA::from_floats(1.0, 0.0, 0.0, 1.0))); +} + +#[test] +fn test_rgba_color_interepolation_out_of_range_clamped_2() { + assert_eq!(Color::RGBA(RGBA::from_floats(1.0, 0.0, 0.0, 0.8)).interpolate( + &Color::RGBA(RGBA::from_floats(0.0, 1.0, 0.0, 0.2)), 1.5).unwrap(), + Color::RGBA(RGBA::from_floats(0.0, 0.0, 0.0, 0.0))); } diff --git a/tests/unit/style/properties/serialization.rs b/tests/unit/style/properties/serialization.rs index da2574a575d..46046908d8d 100644 --- a/tests/unit/style/properties/serialization.rs +++ b/tests/unit/style/properties/serialization.rs @@ -231,15 +231,15 @@ mod shorthand_serialization { fn border_color_should_serialize_correctly() { let mut properties = Vec::new(); - let red = DeclaredValue::Value(Box::new(CSSColor { - parsed: ComputedColor::RGBA(RGBA { red: 1f32, green: 0f32, blue: 0f32, alpha: 1f32 }), + let red = DeclaredValue::Value(CSSColor { + parsed: ComputedColor::RGBA(RGBA::new(255, 0, 0, 255)), authored: None - })); + }); - let blue = DeclaredValue::Value(Box::new(CSSColor { - parsed: ComputedColor::RGBA(RGBA { red: 0f32, green: 0f32, blue: 1f32, alpha: 1f32 }), + let blue = DeclaredValue::Value(CSSColor { + parsed: ComputedColor::RGBA(RGBA::new(0, 0, 255, 255)), authored: None - })); + }); properties.push(PropertyDeclaration::BorderTopColor(blue.clone())); properties.push(PropertyDeclaration::BorderRightColor(red.clone())); @@ -281,10 +281,10 @@ mod shorthand_serialization { let width = DeclaredValue::Value(BorderWidth::from_length(Length::from_px(4f32))); let style = DeclaredValue::Value(BorderStyle::solid); - let color = DeclaredValue::Value(Box::new(CSSColor { - parsed: ComputedColor::RGBA(RGBA { red: 1f32, green: 0f32, blue: 0f32, alpha: 1f32 }), + let color = DeclaredValue::Value(CSSColor { + parsed: ComputedColor::RGBA(RGBA::new(255, 0, 0, 255)), authored: None - })); + }); properties.push(PropertyDeclaration::BorderTopWidth(width)); properties.push(PropertyDeclaration::BorderTopStyle(style)); @@ -300,10 +300,10 @@ mod shorthand_serialization { let width = DeclaredValue::Value(BorderWidth::from_length(Length::from_px(4f32))); let style = DeclaredValue::Initial; - let color = DeclaredValue::Value(Box::new(CSSColor { - parsed: ComputedColor::RGBA(RGBA { red: 1f32, green: 0f32, blue: 0f32, alpha: 1f32 }), + let color = DeclaredValue::Value(CSSColor { + parsed: ComputedColor::RGBA(RGBA::new(255, 0, 0, 255)), authored: None - })); + }); properties.push(PropertyDeclaration::BorderTopWidth(width)); properties.push(PropertyDeclaration::BorderTopStyle(style)); @@ -469,10 +469,10 @@ mod shorthand_serialization { let width = DeclaredValue::Value(WidthContainer(Length::from_px(4f32))); let style = DeclaredValue::Value(Either::Second(BorderStyle::solid)); - let color = DeclaredValue::Value(Box::new(CSSColor { - parsed: ComputedColor::RGBA(RGBA { red: 1f32, green: 0f32, blue: 0f32, alpha: 1f32 }), + let color = DeclaredValue::Value(CSSColor { + parsed: ComputedColor::RGBA(RGBA::new(255, 0, 0, 255)), authored: None - })); + }); properties.push(PropertyDeclaration::OutlineWidth(width)); properties.push(PropertyDeclaration::OutlineStyle(style)); @@ -504,10 +504,10 @@ mod shorthand_serialization { let width = DeclaredValue::Value(WidthContainer(Length::from_px(4f32))); let style = DeclaredValue::Initial; - let color = DeclaredValue::Value(Box::new(CSSColor { - parsed: ComputedColor::RGBA(RGBA { red: 1f32, green: 0f32, blue: 0f32, alpha: 1f32 }), + let color = DeclaredValue::Value(CSSColor { + parsed: ComputedColor::RGBA(RGBA::new(255, 0, 0, 255)), authored: None - })); + }); properties.push(PropertyDeclaration::OutlineWidth(width)); properties.push(PropertyDeclaration::OutlineStyle(style)); properties.push(PropertyDeclaration::OutlineColor(color)); @@ -522,10 +522,10 @@ mod shorthand_serialization { let width = DeclaredValue::Value(WidthContainer(Length::from_px(4f32))); let style = DeclaredValue::Value(Either::First(Auto)); - let color = DeclaredValue::Value(Box::new(CSSColor { - parsed: ComputedColor::RGBA(RGBA { red: 1f32, green: 0f32, blue: 0f32, alpha: 1f32 }), + let color = DeclaredValue::Value(CSSColor { + parsed: ComputedColor::RGBA(RGBA::new(255, 0, 0, 255)), authored: None - })); + }); properties.push(PropertyDeclaration::OutlineWidth(width)); properties.push(PropertyDeclaration::OutlineStyle(style)); properties.push(PropertyDeclaration::OutlineColor(color)); @@ -730,10 +730,10 @@ mod shorthand_serialization { fn background_should_serialize_all_available_properties_when_specified() { let mut properties = Vec::new(); - let color = DeclaredValue::Value(Box::new(CSSColor { - parsed: ComputedColor::RGBA(RGBA { red: 1f32, green: 0f32, blue: 0f32, alpha: 1f32 }), + let color = DeclaredValue::Value(CSSColor { + parsed: ComputedColor::RGBA(RGBA::new(255, 0, 0, 255)), authored: None - })); + }); let position_x = single_vec_value_typedef!(position_x, HorizontalPosition { @@ -790,10 +790,10 @@ mod shorthand_serialization { fn background_should_combine_origin_and_clip_properties_when_equal() { let mut properties = Vec::new(); - let color = DeclaredValue::Value(Box::new(CSSColor { - parsed: ComputedColor::RGBA(RGBA { red: 1f32, green: 0f32, blue: 0f32, alpha: 1f32 }), + let color = DeclaredValue::Value(CSSColor { + parsed: ComputedColor::RGBA(RGBA::new(255, 0, 0, 255)), authored: None - })); + }); let position_x = single_vec_value_typedef!(position_x, HorizontalPosition { @@ -849,10 +849,10 @@ mod shorthand_serialization { fn background_should_always_print_color_and_url_and_repeat_and_attachment_and_position() { let mut properties = Vec::new(); - let color = DeclaredValue::Value(Box::new(CSSColor { - parsed: ComputedColor::RGBA(RGBA { red: 1f32, green: 0f32, blue: 0f32, alpha: 1f32 }), + let color = DeclaredValue::Value(CSSColor { + parsed: ComputedColor::RGBA(RGBA::new(255, 0, 0, 255)), authored: None - })); + }); let position_x = single_vec_value_typedef!(position_x, HorizontalPosition { diff --git a/tests/unit/style/size_of.rs b/tests/unit/style/size_of.rs index fb001763be4..f50b853e827 100644 --- a/tests/unit/style/size_of.rs +++ b/tests/unit/style/size_of.rs @@ -28,17 +28,25 @@ fn size_of_specified_values() { let threshold = 40; let longhands = specified_value_sizes(); + let mut failing_messages = vec![]; + for specified_value in longhands { if specified_value.1 >= threshold && !specified_value.2 { - panic!("Your changes have increased the size of {} SpecifiedValue to {}. The threshold is \ - currently {}. SpecifiedValues are affect size of PropertyDeclaration enum and \ - increasing the size may dramatically affect our memory footprint. Please consider \ - using `boxed=\"True\"` in this longhand.", - specified_value.0, specified_value.1, threshold) + failing_messages.push( + format!("Your changes have increased the size of {} SpecifiedValue to {}. The threshold is \ + currently {}. SpecifiedValues are affect size of PropertyDeclaration enum and \ + increasing the size may dramatically affect our memory footprint. Please consider \ + using `boxed=\"True\"` in this longhand.", + specified_value.0, specified_value.1, threshold)); } else if specified_value.1 < threshold && specified_value.2 { - panic!("Your changes have decreased the size of {} SpecifiedValue to {}. Good work! \ - The threshold is currently {}. Please consider removing `boxed=\"True\"` from this longhand.", - specified_value.0, specified_value.1, threshold) + failing_messages.push( + format!("Your changes have decreased the size of {} SpecifiedValue to {}. Good work! \ + The threshold is currently {}. Please consider removing `boxed=\"True\"` from this longhand.", + specified_value.0, specified_value.1, threshold)); } } + + if !failing_messages.is_empty() { + panic!("{}", failing_messages.join("\n\n")); + } } diff --git a/tests/unit/style/stylesheets.rs b/tests/unit/style/stylesheets.rs index f2ff5d0163b..f391b7d429f 100644 --- a/tests/unit/style/stylesheets.rs +++ b/tests/unit/style/stylesheets.rs @@ -183,12 +183,10 @@ fn test_parse_stylesheet() { block: Arc::new(RwLock::new(PropertyDeclarationBlock { declarations: vec![ (PropertyDeclaration::BackgroundColor(DeclaredValue::Value( - Box::new(longhands::background_color::SpecifiedValue { - authored: Some("blue".to_owned()), - parsed: cssparser::Color::RGBA(cssparser::RGBA { - red: 0., green: 0., blue: 1., alpha: 1. - }), - }) + longhands::background_color::SpecifiedValue { + authored: Some("blue".to_owned().into_boxed_str()), + parsed: cssparser::Color::RGBA(cssparser::RGBA::new(0, 0, 255, 255)), + } )), Importance::Normal), (PropertyDeclaration::BackgroundPositionX(DeclaredValue::Value( diff --git a/tests/unit/stylo/Cargo.toml b/tests/unit/stylo/Cargo.toml index c53df85dc79..556c5652c29 100644 --- a/tests/unit/stylo/Cargo.toml +++ b/tests/unit/stylo/Cargo.toml @@ -14,7 +14,7 @@ doctest = false [dependencies] app_units = "0.3" atomic_refcell = "0.1" -cssparser = {version = "0.7"} +cssparser = {version = "0.8"} env_logger = "0.4" euclid = "0.10.1" lazy_static = "0.2"