mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00: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
28
Cargo.lock
generated
28
Cargo.lock
generated
|
@ -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"
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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"}
|
||||
|
|
|
@ -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())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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"}
|
||||
|
|
|
@ -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>() {
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -394,12 +394,7 @@ pub fn parse_legacy_color(mut input: &str) -> Result<RGBA, ()> {
|
|||
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<RGBA, ()> {
|
|||
}
|
||||
|
||||
// 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<u8, ()> {
|
||||
match ch {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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,
|
||||
};
|
||||
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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<DeclaredValue<Box<SpecifiedValue>>, ()> {
|
||||
-> Result<DeclaredValue<SpecifiedValue>, ()> {
|
||||
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,
|
||||
})))
|
||||
}))
|
||||
}
|
||||
</%helpers:raw_longhand>
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
pub enum Side {
|
||||
Clip,
|
||||
Ellipsis,
|
||||
String(String),
|
||||
String(Box<str>),
|
||||
}
|
||||
|
||||
#[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")}
|
||||
|
|
|
@ -61,7 +61,7 @@ pub fn serialize_four_sides<W, I>(dest: &mut W,
|
|||
fn serialize_directional_border<W, I,>(dest: &mut W,
|
||||
width: &DeclaredValue<I>,
|
||||
style: &DeclaredValue<BorderStyle>,
|
||||
color: &DeclaredValue<Box<CSSColor>>)
|
||||
color: &DeclaredValue<CSSColor>)
|
||||
-> fmt::Result where W: fmt::Write, I: ToCss {
|
||||
match *width {
|
||||
DeclaredValue::Value(ref width) => {
|
||||
|
|
|
@ -43,14 +43,14 @@ no_viewport_percentage!(i32); // For PropertyDeclaration::Order
|
|||
#[allow(missing_docs)]
|
||||
pub struct CSSColor {
|
||||
pub parsed: cssparser::Color,
|
||||
pub authored: Option<String>,
|
||||
pub authored: Option<Box<str>>,
|
||||
}
|
||||
|
||||
impl Parse for CSSColor {
|
||||
fn parse(_context: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
|
||||
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<String>,
|
||||
pub authored: Option<Box<str>>,
|
||||
}
|
||||
|
||||
no_viewport_percentage!(CSSRGBA);
|
||||
|
|
|
@ -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}
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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)));
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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"));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue