@@ -318,32 +318,41 @@ fn parse_color_function(name: &str, arguments: &mut Parser) -> Result<Color, ()>
318
318
val. max ( 0. ) . min ( 1. )
319
319
}
320
320
321
- let red: f32 ;
322
- let green: f32 ;
323
- let blue: f32 ;
321
+ let mut red: f32 ;
322
+ let mut green: f32 ;
323
+ let mut blue: f32 ;
324
324
if is_rgb {
325
325
// Either integers or percentages, but all the same type.
326
326
match try!( arguments. next ( ) ) {
327
327
Token :: Number ( ref v) if v. int_value . is_some ( ) => {
328
-
329
- red = clamp ( v. value / 255. ) ;
328
+ red = v. value / 255. ;
330
329
try!( arguments. expect_comma ( ) ) ;
331
- green = clamp ( try!( arguments. expect_integer ( ) ) as f32 / 255. ) ;
330
+ green = try!( arguments. expect_integer ( ) ) as f32 / 255. ;
332
331
try!( arguments. expect_comma ( ) ) ;
333
- blue = clamp ( try!( arguments. expect_integer ( ) ) as f32 / 255. ) ;
332
+ blue = try!( arguments. expect_integer ( ) ) as f32 / 255. ;
334
333
}
335
334
Token :: Percentage ( ref v) => {
336
- red = clamp ( v. unit_value ) ;
335
+ red = v. unit_value ;
337
336
try!( arguments. expect_comma ( ) ) ;
338
- green = clamp ( try!( arguments. expect_percentage ( ) ) ) ;
337
+ green = try!( arguments. expect_percentage ( ) ) ;
339
338
try!( arguments. expect_comma ( ) ) ;
340
- blue = clamp ( try!( arguments. expect_percentage ( ) ) ) ;
339
+ blue = try!( arguments. expect_percentage ( ) ) ;
341
340
}
342
341
_ => return Err ( ( ) )
343
342
} ;
343
+ // The spec says to clamp to the device gamut which may be wider than 0% ... 100%,
344
+ // but moz2d doesn’t seem to have any support for this, so let’s not bother.
345
+ // https://drafts.csswg.org/css-color/#rgb-functions
346
+ // https://github.com/servo/rust-cssparser/issues/76
347
+ red = clamp ( red) ;
348
+ green = clamp ( green) ;
349
+ blue = clamp ( blue) ;
344
350
} else {
345
351
let hue = try!( arguments. expect_number ( ) ) / 360. ;
346
352
let hue = hue - hue. floor ( ) ;
353
+ // Saturation and lightness are clamped to 0% ... 100%
354
+ // regardless of device gamut:
355
+ // https://drafts.csswg.org/css-color/#the-hsl-notation
347
356
try!( arguments. expect_comma ( ) ) ;
348
357
let saturation = clamp ( try!( arguments. expect_percentage ( ) ) ) ;
349
358
try!( arguments. expect_comma ( ) ) ;
0 commit comments