Upgrade Stylo to 2024-03-01 (#32089)

* Upgrade Stylo to 2024-03-01

* Fixup for https://bugzil.la/1882754

* Update test expectations
This commit is contained in:
Oriol Brufau 2024-04-16 14:27:51 +02:00 committed by GitHub
parent 0678136b17
commit f5bdfdfe94
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
33 changed files with 290 additions and 302 deletions

View file

@ -12,6 +12,7 @@ use canvas_traits::canvas::{
FillRule, LineCapStyle, LineJoinStyle, LinearGradientStyle, RadialGradientStyle,
RepetitionStyle, TextAlign, TextBaseline,
};
use cssparser::color::clamp_unit_f32;
use cssparser::{Parser, ParserInput};
use euclid::default::{Point2D, Rect, Size2D, Transform2D};
use euclid::vec2;
@ -22,8 +23,7 @@ use pixels::PixelFormat;
use profile_traits::ipc as profiled_ipc;
use script_traits::ScriptMsg;
use servo_url::{ImmutableOrigin, ServoUrl};
use style::color::parsing::RgbaLegacy;
use style::color::{AbsoluteColor, ColorSpace};
use style::color::{AbsoluteColor, ColorFlags, ColorSpace};
use style::context::QuirksMode;
use style::parser::ParserContext;
use style::properties::longhands::font_variant_caps::computed_value::T as FontVariantCaps;
@ -32,7 +32,7 @@ use style::stylesheets::{CssRuleType, Origin};
use style::values::computed::font::FontStyle;
use style::values::specified::color::Color;
use style_traits::values::ToCss;
use style_traits::ParsingMode;
use style_traits::{CssWriter, ParsingMode};
use url::Url;
use crate::dom::bindings::cell::DomRefCell;
@ -63,7 +63,7 @@ use crate::unpremultiplytable::UNPREMULTIPLY_TABLE;
#[derive(Clone, JSTraceable, MallocSizeOf)]
#[allow(dead_code)]
pub(crate) enum CanvasFillOrStrokeStyle {
Color(#[no_trace] RgbaLegacy),
Color(#[no_trace] AbsoluteColor),
Gradient(Dom<CanvasGradient>),
Pattern(Dom<CanvasPattern>),
}
@ -99,7 +99,7 @@ pub(crate) struct CanvasContextState {
shadow_offset_y: f64,
shadow_blur: f64,
#[no_trace]
shadow_color: RgbaLegacy,
shadow_color: AbsoluteColor,
#[no_trace]
font_style: Option<Font>,
#[no_trace]
@ -114,13 +114,12 @@ impl CanvasContextState {
const DEFAULT_FONT_STYLE: &'static str = "10px sans-serif";
pub(crate) fn new() -> CanvasContextState {
let black = RgbaLegacy::new(0, 0, 0, 1.0);
CanvasContextState {
global_alpha: 1.0,
global_composition: CompositionOrBlending::default(),
image_smoothing_enabled: true,
fill_style: CanvasFillOrStrokeStyle::Color(black),
stroke_style: CanvasFillOrStrokeStyle::Color(black),
fill_style: CanvasFillOrStrokeStyle::Color(AbsoluteColor::BLACK),
stroke_style: CanvasFillOrStrokeStyle::Color(AbsoluteColor::BLACK),
line_width: 1.0,
line_cap: LineCapStyle::Butt,
line_join: LineJoinStyle::Miter,
@ -129,7 +128,7 @@ impl CanvasContextState {
shadow_offset_x: 0.0,
shadow_offset_y: 0.0,
shadow_blur: 0.0,
shadow_color: RgbaLegacy::new(0, 0, 0, 0.0),
shadow_color: AbsoluteColor::TRANSPARENT_BLACK,
font_style: None,
text_align: Default::default(),
text_baseline: Default::default(),
@ -1689,7 +1688,7 @@ impl CanvasState {
}
}
pub fn parse_color(canvas: Option<&HTMLCanvasElement>, string: &str) -> Result<RgbaLegacy, ()> {
pub fn parse_color(canvas: Option<&HTMLCanvasElement>, string: &str) -> Result<AbsoluteColor, ()> {
let mut input = ParserInput::new(string);
let mut parser = Parser::new(&mut input);
let url = Url::parse("about:blank").unwrap().into();
@ -1726,15 +1725,7 @@ pub fn parse_color(canvas: Option<&HTMLCanvasElement>, string: &str) -> Result<R
},
};
let rgba = color
.resolve_to_absolute(&current_color)
.to_color_space(ColorSpace::Srgb);
Ok(RgbaLegacy::from_floats(
rgba.components.0,
rgba.components.1,
rgba.components.2,
rgba.alpha,
))
Ok(color.resolve_to_absolute(&current_color))
},
None => Err(()),
}
@ -1747,17 +1738,21 @@ pub fn is_rect_valid(rect: Rect<f64>) -> bool {
}
// https://html.spec.whatwg.org/multipage/#serialisation-of-a-color
pub fn serialize<W>(color: &RgbaLegacy, dest: &mut W) -> fmt::Result
pub fn serialize<W>(color: &AbsoluteColor, dest: &mut W) -> fmt::Result
where
W: fmt::Write,
{
let RgbaLegacy {
red,
green,
blue,
alpha,
} = color;
if *alpha == 1.0 {
let srgb = match color.color_space {
ColorSpace::Srgb if color.flags.contains(ColorFlags::IS_LEGACY_SRGB) => *color,
ColorSpace::Hsl | ColorSpace::Hwb => color.into_srgb_legacy(),
_ => return color.to_css(&mut CssWriter::new(dest)),
};
debug_assert!(srgb.flags.contains(ColorFlags::IS_LEGACY_SRGB));
let red = clamp_unit_f32(srgb.components.0);
let green = clamp_unit_f32(srgb.components.1);
let blue = clamp_unit_f32(srgb.components.2);
let alpha = srgb.alpha;
if alpha == 1.0 {
write!(
dest,
"#{:x}{:x}{:x}{:x}{:x}{:x}",

View file

@ -709,15 +709,9 @@ impl<'dom> LayoutElementHelpers<'dom> for LayoutDom<'dom, Element> {
};
if let Some(color) = bgcolor {
use style::color::parsing::FromParsedColor;
hints.push(from_declaration(
shared_lock,
PropertyDeclaration::BackgroundColor(specified::Color::from_rgba(
color.red,
color.green,
color.blue,
color.alpha,
)),
PropertyDeclaration::BackgroundColor(specified::Color::from_absolute_color(color)),
));
}
@ -749,11 +743,10 @@ impl<'dom> LayoutElementHelpers<'dom> for LayoutDom<'dom, Element> {
};
if let Some(color) = color {
use style::color::parsing::FromParsedColor;
hints.push(from_declaration(
shared_lock,
PropertyDeclaration::Color(longhands::color::SpecifiedValue(
specified::Color::from_rgba(color.red, color.green, color.blue, color.alpha),
specified::Color::from_absolute_color(color),
)),
));
}

View file

@ -8,7 +8,7 @@ use html5ever::{local_name, namespace_url, ns, LocalName, Prefix};
use js::rust::HandleObject;
use servo_url::ServoUrl;
use style::attr::AttrValue;
use style::color::parsing::RgbaLegacy;
use style::color::AbsoluteColor;
use crate::dom::attr::Attr;
use crate::dom::bindings::codegen::Bindings::HTMLBodyElementBinding::HTMLBodyElementMethods;
@ -100,20 +100,20 @@ impl HTMLBodyElementMethods for HTMLBodyElement {
}
pub trait HTMLBodyElementLayoutHelpers {
fn get_background_color(self) -> Option<RgbaLegacy>;
fn get_color(self) -> Option<RgbaLegacy>;
fn get_background_color(self) -> Option<AbsoluteColor>;
fn get_color(self) -> Option<AbsoluteColor>;
fn get_background(self) -> Option<ServoUrl>;
}
impl HTMLBodyElementLayoutHelpers for LayoutDom<'_, HTMLBodyElement> {
fn get_background_color(self) -> Option<RgbaLegacy> {
fn get_background_color(self) -> Option<AbsoluteColor> {
self.upcast::<Element>()
.get_attr_for_layout(&ns!(), &local_name!("bgcolor"))
.and_then(AttrValue::as_color)
.cloned()
}
fn get_color(self) -> Option<RgbaLegacy> {
fn get_color(self) -> Option<AbsoluteColor> {
self.upcast::<Element>()
.get_attr_for_layout(&ns!(), &local_name!("text"))
.and_then(AttrValue::as_color)

View file

@ -7,7 +7,7 @@ use html5ever::{local_name, namespace_url, ns, LocalName, Prefix};
use js::rust::HandleObject;
use servo_atoms::Atom;
use style::attr::AttrValue;
use style::color::parsing::RgbaLegacy;
use style::color::AbsoluteColor;
use style::str::{read_numbers, HTML_SPACE_CHARACTERS};
use crate::dom::attr::Attr;
@ -107,13 +107,13 @@ impl VirtualMethods for HTMLFontElement {
}
pub trait HTMLFontElementLayoutHelpers {
fn get_color(self) -> Option<RgbaLegacy>;
fn get_color(self) -> Option<AbsoluteColor>;
fn get_face(self) -> Option<Atom>;
fn get_size(self) -> Option<u32>;
}
impl HTMLFontElementLayoutHelpers for LayoutDom<'_, HTMLFontElement> {
fn get_color(self) -> Option<RgbaLegacy> {
fn get_color(self) -> Option<AbsoluteColor> {
self.upcast::<Element>()
.get_attr_for_layout(&ns!(), &local_name!("color"))
.and_then(AttrValue::as_color)

View file

@ -6,7 +6,7 @@ use dom_struct::dom_struct;
use html5ever::{local_name, namespace_url, ns, LocalName, Prefix};
use js::rust::HandleObject;
use style::attr::{AttrValue, LengthOrPercentageOrAuto};
use style::color::parsing::RgbaLegacy;
use style::color::AbsoluteColor;
use crate::dom::bindings::codegen::Bindings::HTMLHRElementBinding::HTMLHRElementMethods;
use crate::dom::bindings::inheritance::Castable;
@ -70,12 +70,12 @@ impl HTMLHRElementMethods for HTMLHRElement {
}
pub trait HTMLHRLayoutHelpers {
fn get_color(self) -> Option<RgbaLegacy>;
fn get_color(self) -> Option<AbsoluteColor>;
fn get_width(self) -> LengthOrPercentageOrAuto;
}
impl HTMLHRLayoutHelpers for LayoutDom<'_, HTMLHRElement> {
fn get_color(self) -> Option<RgbaLegacy> {
fn get_color(self) -> Option<AbsoluteColor> {
self.upcast::<Element>()
.get_attr_for_layout(&ns!(), &local_name!("color"))
.and_then(AttrValue::as_color)

View file

@ -6,7 +6,7 @@ use dom_struct::dom_struct;
use html5ever::{local_name, namespace_url, ns, LocalName, Prefix};
use js::rust::HandleObject;
use style::attr::{AttrValue, LengthOrPercentageOrAuto};
use style::color::parsing::RgbaLegacy;
use style::color::AbsoluteColor;
use style::context::QuirksMode;
use crate::dom::bindings::codegen::Bindings::HTMLTableCellElementBinding::HTMLTableCellElementMethods;
@ -106,7 +106,7 @@ impl HTMLTableCellElementMethods for HTMLTableCellElement {
}
pub trait HTMLTableCellElementLayoutHelpers<'dom> {
fn get_background_color(self) -> Option<RgbaLegacy>;
fn get_background_color(self) -> Option<AbsoluteColor>;
fn get_colspan(self) -> Option<u32>;
fn get_rowspan(self) -> Option<u32>;
fn get_table(self) -> Option<LayoutDom<'dom, HTMLTableElement>>;
@ -114,7 +114,7 @@ pub trait HTMLTableCellElementLayoutHelpers<'dom> {
}
impl<'dom> HTMLTableCellElementLayoutHelpers<'dom> for LayoutDom<'dom, HTMLTableCellElement> {
fn get_background_color(self) -> Option<RgbaLegacy> {
fn get_background_color(self) -> Option<AbsoluteColor> {
self.upcast::<Element>()
.get_attr_for_layout(&ns!(), &local_name!("bgcolor"))
.and_then(AttrValue::as_color)

View file

@ -8,7 +8,7 @@ use dom_struct::dom_struct;
use html5ever::{local_name, namespace_url, ns, LocalName, Prefix};
use js::rust::HandleObject;
use style::attr::{parse_unsigned_integer, AttrValue, LengthOrPercentageOrAuto};
use style::color::parsing::RgbaLegacy;
use style::color::AbsoluteColor;
use crate::dom::attr::Attr;
use crate::dom::bindings::codegen::Bindings::HTMLCollectionBinding::HTMLCollectionMethods;
@ -438,7 +438,7 @@ impl HTMLTableElementMethods for HTMLTableElement {
}
pub trait HTMLTableElementLayoutHelpers {
fn get_background_color(self) -> Option<RgbaLegacy>;
fn get_background_color(self) -> Option<AbsoluteColor>;
fn get_border(self) -> Option<u32>;
fn get_cellpadding(self) -> Option<u32>;
fn get_cellspacing(self) -> Option<u32>;
@ -446,7 +446,7 @@ pub trait HTMLTableElementLayoutHelpers {
}
impl HTMLTableElementLayoutHelpers for LayoutDom<'_, HTMLTableElement> {
fn get_background_color(self) -> Option<RgbaLegacy> {
fn get_background_color(self) -> Option<AbsoluteColor> {
self.upcast::<Element>()
.get_attr_for_layout(&ns!(), &local_name!("bgcolor"))
.and_then(AttrValue::as_color)

View file

@ -6,7 +6,7 @@ use dom_struct::dom_struct;
use html5ever::{local_name, namespace_url, ns, LocalName, Prefix};
use js::rust::HandleObject;
use style::attr::AttrValue;
use style::color::parsing::RgbaLegacy;
use style::color::AbsoluteColor;
use crate::dom::bindings::codegen::Bindings::HTMLTableElementBinding::HTMLTableElementMethods;
use crate::dom::bindings::codegen::Bindings::HTMLTableRowElementBinding::HTMLTableRowElementMethods;
@ -153,11 +153,11 @@ impl HTMLTableRowElementMethods for HTMLTableRowElement {
}
pub trait HTMLTableRowElementLayoutHelpers {
fn get_background_color(self) -> Option<RgbaLegacy>;
fn get_background_color(self) -> Option<AbsoluteColor>;
}
impl HTMLTableRowElementLayoutHelpers for LayoutDom<'_, HTMLTableRowElement> {
fn get_background_color(self) -> Option<RgbaLegacy> {
fn get_background_color(self) -> Option<AbsoluteColor> {
self.upcast::<Element>()
.get_attr_for_layout(&ns!(), &local_name!("bgcolor"))
.and_then(AttrValue::as_color)

View file

@ -6,7 +6,7 @@ use dom_struct::dom_struct;
use html5ever::{local_name, namespace_url, ns, LocalName, Prefix};
use js::rust::HandleObject;
use style::attr::AttrValue;
use style::color::parsing::RgbaLegacy;
use style::color::AbsoluteColor;
use crate::dom::bindings::codegen::Bindings::HTMLTableSectionElementBinding::HTMLTableSectionElementMethods;
use crate::dom::bindings::codegen::Bindings::NodeBinding::NodeMethods;
@ -91,11 +91,11 @@ impl HTMLTableSectionElementMethods for HTMLTableSectionElement {
}
pub trait HTMLTableSectionElementLayoutHelpers {
fn get_background_color(self) -> Option<RgbaLegacy>;
fn get_background_color(self) -> Option<AbsoluteColor>;
}
impl HTMLTableSectionElementLayoutHelpers for LayoutDom<'_, HTMLTableSectionElement> {
fn get_background_color(self) -> Option<RgbaLegacy> {
fn get_background_color(self) -> Option<AbsoluteColor> {
self.upcast::<Element>()
.get_attr_for_layout(&ns!(), &local_name!("bgcolor"))
.and_then(AttrValue::as_color)