mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +01:00
Enable new color functions from CSS Color 4 (#30752)
I will need to do most of the work anyways during the style updates, so by enabling this it will be easier to detect mistakes. Also, canvas colors are now parsed as <color>, precisely to support these new features. This is according to the HTML spec: https://html.spec.whatwg.org/multipage/infrastructure.html#parsed-as-a-css-color-value
This commit is contained in:
parent
868d84d8ee
commit
61af8fb56d
220 changed files with 75 additions and 4283 deletions
|
@ -5,9 +5,9 @@
|
|||
use canvas_traits::canvas::{
|
||||
CanvasGradientStop, FillOrStrokeStyle, LinearGradientStyle, RadialGradientStyle,
|
||||
};
|
||||
use cssparser::{Color as CSSColor, Parser, ParserInput, RGBA};
|
||||
use dom_struct::dom_struct;
|
||||
|
||||
use crate::canvas_state::parse_color;
|
||||
use crate::dom::bindings::cell::DomRefCell;
|
||||
use crate::dom::bindings::codegen::Bindings::CanvasRenderingContext2DBinding::CanvasGradientMethods;
|
||||
use crate::dom::bindings::error::{Error, ErrorResult};
|
||||
|
@ -53,17 +53,9 @@ impl CanvasGradientMethods for CanvasGradient {
|
|||
return Err(Error::IndexSize);
|
||||
}
|
||||
|
||||
let mut input = ParserInput::new(&color);
|
||||
let mut parser = Parser::new(&mut input);
|
||||
let color = CSSColor::parse(&mut parser);
|
||||
let color = if parser.is_exhausted() {
|
||||
match color {
|
||||
Ok(CSSColor::Rgba(rgba)) => rgba,
|
||||
Ok(CSSColor::CurrentColor) => RGBA::new(0, 0, 0, 1.0),
|
||||
_ => return Err(Error::Syntax),
|
||||
}
|
||||
} else {
|
||||
return Err(Error::Syntax);
|
||||
let color = match parse_color(None, &color) {
|
||||
Ok(color) => color,
|
||||
Err(_) => return Err(Error::Syntax),
|
||||
};
|
||||
|
||||
self.stops.borrow_mut().push(CanvasGradientStop {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue