Further changes required by Servo

This commit is contained in:
Oriol Brufau 2023-11-02 22:34:38 +01:00 committed by Martin Robinson
parent 4559546fbb
commit bb55e923bb
15 changed files with 76 additions and 38 deletions

View file

@ -41,7 +41,7 @@ arrayvec = "0.7"
atomic_refcell = "0.1"
bitflags = "1.0"
byteorder = "1.0"
cssparser = "0.30"
cssparser = { workspace = true }
derive_more = { version = "0.99", default-features = false, features = ["add", "add_assign", "deref", "from"] }
encoding_rs = { version = "0.8", optional = true }
euclid = "0.22"

View file

@ -15,7 +15,7 @@ use crate::values::specified::Length;
use crate::values::AtomString;
use crate::{Atom, LocalName, Namespace, Prefix};
use app_units::Au;
use cssparser::{self, Color, RGBA};
use cssparser::{self, AbsoluteColor, Color, RGBA};
use euclid::num::Zero;
use num_traits::ToPrimitive;
use selectors::attr::AttrSelectorOperation;
@ -419,7 +419,7 @@ pub fn parse_legacy_color(mut input: &str) -> Result<RGBA, ()> {
}
// Step 5.
if let Ok(Color::RGBA(rgba)) = cssparser::parse_color_keyword(input) {
if let Ok(Color::Absolute(AbsoluteColor::Rgba(rgba))) = cssparser::parse_color_keyword(input) {
return Ok(rgba);
}
@ -431,7 +431,7 @@ pub fn parse_legacy_color(mut input: &str) -> Result<RGBA, ()> {
hex(input.as_bytes()[2] as char),
hex(input.as_bytes()[3] as char),
) {
return Ok(RGBA::new(r * 17, g * 17, b * 17, 255));
return Ok(RGBA::new(r * 17, g * 17, b * 17, 1.0));
}
}
@ -504,7 +504,7 @@ pub fn parse_legacy_color(mut input: &str) -> Result<RGBA, ()> {
hex_string(red).unwrap(),
hex_string(green).unwrap(),
hex_string(blue).unwrap(),
255,
1.0,
));
fn hex(ch: char) -> Result<u8, ()> {

View file

@ -197,12 +197,12 @@ impl Device {
/// Returns the default background color.
pub fn default_background_color(&self) -> RGBA {
RGBA::new(255, 255, 255, 255)
RGBA::new(255, 255, 255, 1.0)
}
/// Returns the default foreground color.
pub fn default_color(&self) -> RGBA {
RGBA::new(0, 0, 0, 255)
RGBA::new(0, 0, 0, 1.0)
}
/// Returns safe area insets

View file

@ -33,6 +33,14 @@ fn allow_color_mix() -> bool {
return false;
}
#[inline]
fn allow_more_color_4() -> bool {
#[cfg(feature = "gecko")]
return static_prefs::pref!("layout.css.more_color_4.enabled");
#[cfg(feature = "servo")]
return false;
}
impl ColorMix {
fn parse<'i, 't>(
context: &ParserContext,
@ -759,7 +767,7 @@ impl Color {
CSSParserColor::CurrentColor => Color::CurrentColor,
CSSParserColor::Absolute(absolute) => {
let enabled = matches!(absolute, cssparser::AbsoluteColor::Rgba(_)) ||
static_prefs::pref!("layout.css.more_color_4.enabled");
allow_more_color_4();
if !enabled {
return Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError));
}