diff options
author | Oriol Brufau <obrufau@igalia.com> | 2023-11-15 21:32:34 +0100 |
---|---|---|
committer | Martin Robinson <mrobinson@igalia.com> | 2023-11-21 15:36:35 +0100 |
commit | b6db94bdf5fdb59550380a0b0b3f418afb01965f (patch) | |
tree | d1d5d360e2b001e46fe1984a1f80ee0a0de66ecf /components | |
parent | 8c1c4073e250502822604c71fcaab9c183e4372a (diff) | |
download | servo-b6db94bdf5fdb59550380a0b0b3f418afb01965f.tar.gz servo-b6db94bdf5fdb59550380a0b0b3f418afb01965f.zip |
Further changes required by Servo
Diffstat (limited to 'components')
-rw-r--r-- | components/layout/display_list/builder.rs | 8 | ||||
-rw-r--r-- | components/layout/display_list/conversions.rs | 23 | ||||
-rw-r--r-- | components/layout_2020/display_list/conversions.rs | 8 | ||||
-rw-r--r-- | components/layout_2020/display_list/mod.rs | 22 | ||||
-rw-r--r-- | components/layout_thread/lib.rs | 7 | ||||
-rw-r--r-- | components/script/canvas_state.rs | 15 | ||||
-rw-r--r-- | components/script/dom/element.rs | 12 | ||||
-rw-r--r-- | components/style/servo/media_queries.rs | 11 |
8 files changed, 63 insertions, 43 deletions
diff --git a/components/layout/display_list/builder.rs b/components/layout/display_list/builder.rs index edb8758344c..207bb16266c 100644 --- a/components/layout/display_list/builder.rs +++ b/components/layout/display_list/builder.rs @@ -29,6 +29,7 @@ use net_traits::image_cache::UsePlaceholder; use range::Range; use servo_config::opts; use servo_geometry::{self, MaxRect}; +use style::color::AbsoluteColor; use style::computed_values::border_style::T as BorderStyle; use style::computed_values::overflow_x::T as StyleOverflow; use style::computed_values::pointer_events::T as PointerEvents; @@ -43,7 +44,6 @@ use style::values::computed::{ClipRectOrAuto, Gradient}; use style::values::generics::background::BackgroundSize; use style::values::generics::image::PaintWorklet; use style::values::specified::ui::CursorKind; -use style::values::RGBA; use style_traits::{CSSPixel, ToCss}; use webrender_api::units::{LayoutRect, LayoutTransform, LayoutVector2D}; use webrender_api::{ @@ -671,7 +671,7 @@ impl Fragment { state: &mut DisplayListBuildState, style: &ComputedValues, background: &style_structs::Background, - background_color: RGBA, + background_color: AbsoluteColor, display_list_section: DisplayListSection, absolute_bounds: Rect<Au>, ) { @@ -2202,7 +2202,7 @@ impl Fragment { fn build_display_list_for_text_decoration( &self, state: &mut DisplayListBuildState, - color: &RGBA, + color: &AbsoluteColor, stacking_relative_box: &LogicalRect<Au>, clip: Rect<Au>, ) { @@ -2860,7 +2860,7 @@ impl BlockFlow { &self, state: &mut DisplayListBuildState, background: &style_structs::Background, - background_color: RGBA, + background_color: AbsoluteColor, ) { let stacking_relative_border_box = self .base diff --git a/components/layout/display_list/conversions.rs b/components/layout/display_list/conversions.rs index 112e6c00d6b..c4f6dc5f04b 100644 --- a/components/layout/display_list/conversions.rs +++ b/components/layout/display_list/conversions.rs @@ -4,12 +4,12 @@ use app_units::Au; use euclid::default::{Point2D, Rect, SideOffsets2D, Size2D, Vector2D}; +use style::color::{AbsoluteColor, ColorSpace}; use style::computed_values::image_rendering::T as ImageRendering; use style::computed_values::mix_blend_mode::T as MixBlendMode; use style::computed_values::transform_style::T as TransformStyle; use style::values::computed::{BorderStyle, Filter}; use style::values::specified::border::BorderImageRepeatKeyword; -use style::values::RGBA; use webrender_api as wr; pub trait ToLayout { @@ -19,7 +19,7 @@ pub trait ToLayout { pub trait FilterToLayout { type Type; - fn to_layout(&self, current_color: &RGBA) -> Self::Type; + fn to_layout(&self, current_color: &AbsoluteColor) -> Self::Type; } impl ToLayout for BorderStyle { @@ -42,7 +42,7 @@ impl ToLayout for BorderStyle { impl FilterToLayout for Filter { type Type = wr::FilterOp; - fn to_layout(&self, current_color: &RGBA) -> Self::Type { + fn to_layout(&self, current_color: &AbsoluteColor) -> Self::Type { match *self { Filter::Blur(radius) => wr::FilterOp::Blur(radius.px(), radius.px()), Filter::Brightness(amount) => wr::FilterOp::Brightness(amount.0), @@ -59,7 +59,11 @@ impl FilterToLayout for Filter { shadow.horizontal.px(), shadow.vertical.px(), ), - color: shadow.color.clone().into_rgba(*current_color).to_layout(), + color: shadow + .color + .clone() + .resolve_into_absolute(current_color) + .to_layout(), }), // Statically check that Url is impossible. Filter::Url(ref url) => match *url {}, @@ -112,14 +116,15 @@ impl ToLayout for TransformStyle { } } -impl ToLayout for RGBA { +impl ToLayout for AbsoluteColor { type Type = wr::ColorF; fn to_layout(&self) -> Self::Type { + let rgba = self.to_color_space(ColorSpace::Srgb); wr::ColorF::new( - self.red_f32(), - self.green_f32(), - self.blue_f32(), - self.alpha_f32(), + rgba.components.0.clamp(0.0, 1.0), + rgba.components.1.clamp(0.0, 1.0), + rgba.components.2.clamp(0.0, 1.0), + rgba.alpha, ) } } diff --git a/components/layout_2020/display_list/conversions.rs b/components/layout_2020/display_list/conversions.rs index b543d3580fc..3159fc820a2 100644 --- a/components/layout_2020/display_list/conversions.rs +++ b/components/layout_2020/display_list/conversions.rs @@ -2,11 +2,11 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ +use style::color::AbsoluteColor; use style::computed_values::mix_blend_mode::T as ComputedMixBlendMode; use style::computed_values::text_decoration_style::T as ComputedTextDecorationStyle; use style::computed_values::transform_style::T as ComputedTransformStyle; use style::values::computed::{Filter as ComputedFilter, Length}; -use style::values::RGBA; use webrender_api::{units, FilterOp, LineStyle, MixBlendMode, Shadow, TransformStyle}; use crate::geom::{PhysicalPoint, PhysicalRect, PhysicalSides, PhysicalSize}; @@ -18,12 +18,12 @@ pub trait ToWebRender { pub trait FilterToWebRender { type Type; - fn to_webrender(&self, current_color: &RGBA) -> Self::Type; + fn to_webrender(&self, current_color: &AbsoluteColor) -> Self::Type; } impl FilterToWebRender for ComputedFilter { type Type = FilterOp; - fn to_webrender(&self, current_color: &RGBA) -> Self::Type { + fn to_webrender(&self, current_color: &AbsoluteColor) -> Self::Type { match *self { ComputedFilter::Blur(radius) => FilterOp::Blur(radius.px(), radius.px()), ComputedFilter::Brightness(amount) => FilterOp::Brightness(amount.0), @@ -37,7 +37,7 @@ impl FilterToWebRender for ComputedFilter { ComputedFilter::DropShadow(ref shadow) => FilterOp::DropShadow(Shadow { blur_radius: shadow.blur.px(), offset: units::LayoutVector2D::new(shadow.horizontal.px(), shadow.vertical.px()), - color: super::rgba(shadow.color.clone().into_rgba(*current_color)), + color: super::rgba(shadow.color.clone().resolve_into_absolute(current_color)), }), // Statically check that Url is impossible. ComputedFilter::Url(ref url) => match *url {}, diff --git a/components/layout_2020/display_list/mod.rs b/components/layout_2020/display_list/mod.rs index ec8ad43b270..db8e5fcf401 100644 --- a/components/layout_2020/display_list/mod.rs +++ b/components/layout_2020/display_list/mod.rs @@ -13,6 +13,7 @@ use gfx_traits::WebRenderEpochToU16; use msg::constellation_msg::BrowsingContextId; use net_traits::image_cache::UsePlaceholder; use script_traits::compositor::{CompositorDisplayListInfo, ScrollTreeNodeId}; +use style::color::{AbsoluteColor, ColorSpace}; use style::computed_values::text_decoration_style::T as ComputedTextDecorationStyle; use style::dom::OpaqueNode; use style::properties::longhands::visibility::computed_value::T as Visibility; @@ -318,7 +319,7 @@ impl Fragment { let mut rect = rect; rect.origin.y = rect.origin.y + font_metrics.ascent - font_metrics.underline_offset; rect.size.height = round_to_nearest_device_pixel(font_metrics.underline_size); - self.build_display_list_for_text_decoration(fragment, builder, &rect, color); + self.build_display_list_for_text_decoration(fragment, builder, &rect, &color); } // Overline. @@ -328,7 +329,7 @@ impl Fragment { { let mut rect = rect; rect.size.height = round_to_nearest_device_pixel(font_metrics.underline_size); - self.build_display_list_for_text_decoration(fragment, builder, &rect, color); + self.build_display_list_for_text_decoration(fragment, builder, &rect, &color); } // Text. @@ -351,7 +352,7 @@ impl Fragment { rect.origin.y = rect.origin.y + font_metrics.ascent - font_metrics.strikeout_offset; // XXX(ferjm) This does not work on MacOS #942 rect.size.height = round_to_nearest_device_pixel(font_metrics.strikeout_size); - self.build_display_list_for_text_decoration(fragment, builder, &rect, color); + self.build_display_list_for_text_decoration(fragment, builder, &rect, &color); } } @@ -360,14 +361,14 @@ impl Fragment { fragment: &TextFragment, builder: &mut DisplayListBuilder, rect: &PhysicalRect<Length>, - color: cssparser::RGBA, + color: &AbsoluteColor, ) { let rect = rect.to_webrender(); let wavy_line_thickness = (0.33 * rect.size.height).ceil(); let text_decoration_color = fragment .parent_style .clone_text_decoration_color() - .into_rgba(color); + .resolve_into_absolute(color); let text_decoration_style = fragment.parent_style.clone_text_decoration_style(); if text_decoration_style == ComputedTextDecorationStyle::MozNone { return; @@ -748,12 +749,13 @@ impl<'a> BuilderForBoxFragment<'a> { } } -fn rgba(rgba: cssparser::RGBA) -> wr::ColorF { +fn rgba(color: AbsoluteColor) -> wr::ColorF { + let rgba = color.to_color_space(ColorSpace::Srgb); wr::ColorF::new( - rgba.red_f32(), - rgba.green_f32(), - rgba.blue_f32(), - rgba.alpha_f32(), + rgba.components.0.clamp(0.0, 1.0), + rgba.components.1.clamp(0.0, 1.0), + rgba.components.2.clamp(0.0, 1.0), + rgba.alpha, ) } diff --git a/components/layout_thread/lib.rs b/components/layout_thread/lib.rs index aa08b341ee6..9efdf7d50a9 100644 --- a/components/layout_thread/lib.rs +++ b/components/layout_thread/lib.rs @@ -1786,12 +1786,7 @@ fn get_root_flow_background_color(flow: &mut dyn Flow) -> ColorF { .background_color .clone(), ); - ColorF::new( - color.red_f32(), - color.green_f32(), - color.blue_f32(), - color.alpha_f32(), - ) + color.to_layout() } fn get_ua_stylesheets() -> Result<UserAgentStylesheets, &'static str> { diff --git a/components/script/canvas_state.rs b/components/script/canvas_state.rs index 06e80f2bb05..4af444cc272 100644 --- a/components/script/canvas_state.rs +++ b/components/script/canvas_state.rs @@ -22,6 +22,7 @@ use pixels::PixelFormat; use profile_traits::ipc as profiled_ipc; use script_traits::ScriptMsg; use servo_url::{ImmutableOrigin, ServoUrl}; +use style::color::{AbsoluteColor, ColorSpace}; use style::context::QuirksMode; use style::parser::ParserContext; use style::properties::longhands::font_variant_caps::computed_value::T as FontVariantCaps; @@ -1694,19 +1695,27 @@ pub fn parse_color(canvas: Option<&HTMLCanvasElement>, string: &str) -> Result<R // https://drafts.css-houdini.org/css-paint-api/#2d-rendering-context // Whenever "currentColor" is used as a color in the PaintRenderingContext2D API, // it is treated as opaque black. - None => RGBA::new(0, 0, 0, 1.0), + None => AbsoluteColor::black(), Some(ref canvas) => { let canvas_element = canvas.upcast::<Element>(); match canvas_element.style() { Some(ref s) if canvas_element.has_css_layout_box() => { s.get_inherited_text().color }, - _ => RGBA::new(0, 0, 0, 1.0), + _ => AbsoluteColor::black(), } }, }; - Ok(color.into_rgba(current_color)) + let rgba = color + .resolve_into_absolute(¤t_color) + .to_color_space(ColorSpace::Srgb); + Ok(RGBA::from_floats( + rgba.components.0, + rgba.components.1, + rgba.components.2, + rgba.alpha, + )) }, None => Err(()), } diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs index 64164858807..3683c56d164 100644 --- a/components/script/dom/element.rs +++ b/components/script/dom/element.rs @@ -702,9 +702,13 @@ impl<'dom> LayoutElementHelpers<'dom> for LayoutDom<'dom, Element> { }; if let Some(color) = bgcolor { + use cssparser::FromParsedColor; hints.push(from_declaration( shared_lock, - PropertyDeclaration::BackgroundColor(color.into()), + PropertyDeclaration::BackgroundColor( + specified::Color::from_rgba(color.red, color.green, color.blue, color.alpha) + .into(), + ), )); } @@ -736,9 +740,13 @@ impl<'dom> LayoutElementHelpers<'dom> for LayoutDom<'dom, Element> { }; if let Some(color) = color { + use cssparser::FromParsedColor; hints.push(from_declaration( shared_lock, - PropertyDeclaration::Color(longhands::color::SpecifiedValue(color.into())), + PropertyDeclaration::Color(longhands::color::SpecifiedValue( + specified::Color::from_rgba(color.red, color.green, color.blue, color.alpha) + .into(), + )), )); } diff --git a/components/style/servo/media_queries.rs b/components/style/servo/media_queries.rs index 21aeb1692fb..7e17e23c639 100644 --- a/components/style/servo/media_queries.rs +++ b/components/style/servo/media_queries.rs @@ -4,6 +4,7 @@ //! Servo's media-query device and expression representation. +use crate::color::AbsoluteColor; use crate::context::QuirksMode; use crate::custom_properties::CssEnvironment; use crate::font_metrics::FontMetrics; @@ -117,7 +118,7 @@ impl Device { /// Sets the body text color for the "inherit color from body" quirk. /// /// <https://quirks.spec.whatwg.org/#the-tables-inherit-color-from-body-quirk> - pub fn set_body_text_color(&self, _color: RGBA) { + pub fn set_body_text_color(&self, _color: AbsoluteColor) { // Servo doesn't implement this quirk (yet) } @@ -201,13 +202,13 @@ impl Device { } /// Returns the default background color. - pub fn default_background_color(&self) -> RGBA { - RGBA::new(255, 255, 255, 1.0) + pub fn default_background_color(&self) -> AbsoluteColor { + AbsoluteColor::white() } /// Returns the default foreground color. - pub fn default_color(&self) -> RGBA { - RGBA::new(0, 0, 0, 1.0) + pub fn default_color(&self) -> AbsoluteColor { + AbsoluteColor::black() } /// Returns safe area insets |