Further changes required by Servo

This commit is contained in:
Oriol Brufau 2023-11-15 21:32:34 +01:00 committed by Martin Robinson
parent 8c1c4073e2
commit b6db94bdf5
9 changed files with 94 additions and 66 deletions

View file

@ -29,6 +29,7 @@ use net_traits::image_cache::UsePlaceholder;
use range::Range; use range::Range;
use servo_config::opts; use servo_config::opts;
use servo_geometry::{self, MaxRect}; use servo_geometry::{self, MaxRect};
use style::color::AbsoluteColor;
use style::computed_values::border_style::T as BorderStyle; use style::computed_values::border_style::T as BorderStyle;
use style::computed_values::overflow_x::T as StyleOverflow; use style::computed_values::overflow_x::T as StyleOverflow;
use style::computed_values::pointer_events::T as PointerEvents; 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::background::BackgroundSize;
use style::values::generics::image::PaintWorklet; use style::values::generics::image::PaintWorklet;
use style::values::specified::ui::CursorKind; use style::values::specified::ui::CursorKind;
use style::values::RGBA;
use style_traits::{CSSPixel, ToCss}; use style_traits::{CSSPixel, ToCss};
use webrender_api::units::{LayoutRect, LayoutTransform, LayoutVector2D}; use webrender_api::units::{LayoutRect, LayoutTransform, LayoutVector2D};
use webrender_api::{ use webrender_api::{
@ -671,7 +671,7 @@ impl Fragment {
state: &mut DisplayListBuildState, state: &mut DisplayListBuildState,
style: &ComputedValues, style: &ComputedValues,
background: &style_structs::Background, background: &style_structs::Background,
background_color: RGBA, background_color: AbsoluteColor,
display_list_section: DisplayListSection, display_list_section: DisplayListSection,
absolute_bounds: Rect<Au>, absolute_bounds: Rect<Au>,
) { ) {
@ -2202,7 +2202,7 @@ impl Fragment {
fn build_display_list_for_text_decoration( fn build_display_list_for_text_decoration(
&self, &self,
state: &mut DisplayListBuildState, state: &mut DisplayListBuildState,
color: &RGBA, color: &AbsoluteColor,
stacking_relative_box: &LogicalRect<Au>, stacking_relative_box: &LogicalRect<Au>,
clip: Rect<Au>, clip: Rect<Au>,
) { ) {
@ -2860,7 +2860,7 @@ impl BlockFlow {
&self, &self,
state: &mut DisplayListBuildState, state: &mut DisplayListBuildState,
background: &style_structs::Background, background: &style_structs::Background,
background_color: RGBA, background_color: AbsoluteColor,
) { ) {
let stacking_relative_border_box = self let stacking_relative_border_box = self
.base .base

View file

@ -4,12 +4,12 @@
use app_units::Au; use app_units::Au;
use euclid::default::{Point2D, Rect, SideOffsets2D, Size2D, Vector2D}; 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::image_rendering::T as ImageRendering;
use style::computed_values::mix_blend_mode::T as MixBlendMode; use style::computed_values::mix_blend_mode::T as MixBlendMode;
use style::computed_values::transform_style::T as TransformStyle; use style::computed_values::transform_style::T as TransformStyle;
use style::values::computed::{BorderStyle, Filter}; use style::values::computed::{BorderStyle, Filter};
use style::values::specified::border::BorderImageRepeatKeyword; use style::values::specified::border::BorderImageRepeatKeyword;
use style::values::RGBA;
use webrender_api as wr; use webrender_api as wr;
pub trait ToLayout { pub trait ToLayout {
@ -19,7 +19,7 @@ pub trait ToLayout {
pub trait FilterToLayout { pub trait FilterToLayout {
type Type; type Type;
fn to_layout(&self, current_color: &RGBA) -> Self::Type; fn to_layout(&self, current_color: &AbsoluteColor) -> Self::Type;
} }
impl ToLayout for BorderStyle { impl ToLayout for BorderStyle {
@ -42,7 +42,7 @@ impl ToLayout for BorderStyle {
impl FilterToLayout for Filter { impl FilterToLayout for Filter {
type Type = wr::FilterOp; type Type = wr::FilterOp;
fn to_layout(&self, current_color: &RGBA) -> Self::Type { fn to_layout(&self, current_color: &AbsoluteColor) -> Self::Type {
match *self { match *self {
Filter::Blur(radius) => wr::FilterOp::Blur(radius.px(), radius.px()), Filter::Blur(radius) => wr::FilterOp::Blur(radius.px(), radius.px()),
Filter::Brightness(amount) => wr::FilterOp::Brightness(amount.0), Filter::Brightness(amount) => wr::FilterOp::Brightness(amount.0),
@ -59,7 +59,11 @@ impl FilterToLayout for Filter {
shadow.horizontal.px(), shadow.horizontal.px(),
shadow.vertical.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. // Statically check that Url is impossible.
Filter::Url(ref url) => match *url {}, 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; type Type = wr::ColorF;
fn to_layout(&self) -> Self::Type { fn to_layout(&self) -> Self::Type {
let rgba = self.to_color_space(ColorSpace::Srgb);
wr::ColorF::new( wr::ColorF::new(
self.red_f32(), rgba.components.0.clamp(0.0, 1.0),
self.green_f32(), rgba.components.1.clamp(0.0, 1.0),
self.blue_f32(), rgba.components.2.clamp(0.0, 1.0),
self.alpha_f32(), rgba.alpha,
) )
} }
} }

View file

@ -2,11 +2,11 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * 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/. */ * 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::mix_blend_mode::T as ComputedMixBlendMode;
use style::computed_values::text_decoration_style::T as ComputedTextDecorationStyle; use style::computed_values::text_decoration_style::T as ComputedTextDecorationStyle;
use style::computed_values::transform_style::T as ComputedTransformStyle; use style::computed_values::transform_style::T as ComputedTransformStyle;
use style::values::computed::{Filter as ComputedFilter, Length}; use style::values::computed::{Filter as ComputedFilter, Length};
use style::values::RGBA;
use webrender_api::{units, FilterOp, LineStyle, MixBlendMode, Shadow, TransformStyle}; use webrender_api::{units, FilterOp, LineStyle, MixBlendMode, Shadow, TransformStyle};
use crate::geom::{PhysicalPoint, PhysicalRect, PhysicalSides, PhysicalSize}; use crate::geom::{PhysicalPoint, PhysicalRect, PhysicalSides, PhysicalSize};
@ -18,12 +18,12 @@ pub trait ToWebRender {
pub trait FilterToWebRender { pub trait FilterToWebRender {
type Type; type Type;
fn to_webrender(&self, current_color: &RGBA) -> Self::Type; fn to_webrender(&self, current_color: &AbsoluteColor) -> Self::Type;
} }
impl FilterToWebRender for ComputedFilter { impl FilterToWebRender for ComputedFilter {
type Type = FilterOp; type Type = FilterOp;
fn to_webrender(&self, current_color: &RGBA) -> Self::Type { fn to_webrender(&self, current_color: &AbsoluteColor) -> Self::Type {
match *self { match *self {
ComputedFilter::Blur(radius) => FilterOp::Blur(radius.px(), radius.px()), ComputedFilter::Blur(radius) => FilterOp::Blur(radius.px(), radius.px()),
ComputedFilter::Brightness(amount) => FilterOp::Brightness(amount.0), ComputedFilter::Brightness(amount) => FilterOp::Brightness(amount.0),
@ -37,7 +37,7 @@ impl FilterToWebRender for ComputedFilter {
ComputedFilter::DropShadow(ref shadow) => FilterOp::DropShadow(Shadow { ComputedFilter::DropShadow(ref shadow) => FilterOp::DropShadow(Shadow {
blur_radius: shadow.blur.px(), blur_radius: shadow.blur.px(),
offset: units::LayoutVector2D::new(shadow.horizontal.px(), shadow.vertical.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. // Statically check that Url is impossible.
ComputedFilter::Url(ref url) => match *url {}, ComputedFilter::Url(ref url) => match *url {},

View file

@ -13,6 +13,7 @@ use gfx_traits::WebRenderEpochToU16;
use msg::constellation_msg::BrowsingContextId; use msg::constellation_msg::BrowsingContextId;
use net_traits::image_cache::UsePlaceholder; use net_traits::image_cache::UsePlaceholder;
use script_traits::compositor::{CompositorDisplayListInfo, ScrollTreeNodeId}; use script_traits::compositor::{CompositorDisplayListInfo, ScrollTreeNodeId};
use style::color::{AbsoluteColor, ColorSpace};
use style::computed_values::text_decoration_style::T as ComputedTextDecorationStyle; use style::computed_values::text_decoration_style::T as ComputedTextDecorationStyle;
use style::dom::OpaqueNode; use style::dom::OpaqueNode;
use style::properties::longhands::visibility::computed_value::T as Visibility; use style::properties::longhands::visibility::computed_value::T as Visibility;
@ -318,7 +319,7 @@ impl Fragment {
let mut rect = rect; let mut rect = rect;
rect.origin.y = rect.origin.y + font_metrics.ascent - font_metrics.underline_offset; 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); 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. // Overline.
@ -328,7 +329,7 @@ impl Fragment {
{ {
let mut rect = rect; let mut rect = rect;
rect.size.height = round_to_nearest_device_pixel(font_metrics.underline_size); 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. // Text.
@ -351,7 +352,7 @@ impl Fragment {
rect.origin.y = rect.origin.y + font_metrics.ascent - font_metrics.strikeout_offset; rect.origin.y = rect.origin.y + font_metrics.ascent - font_metrics.strikeout_offset;
// XXX(ferjm) This does not work on MacOS #942 // XXX(ferjm) This does not work on MacOS #942
rect.size.height = round_to_nearest_device_pixel(font_metrics.strikeout_size); 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, fragment: &TextFragment,
builder: &mut DisplayListBuilder, builder: &mut DisplayListBuilder,
rect: &PhysicalRect<Length>, rect: &PhysicalRect<Length>,
color: cssparser::RGBA, color: &AbsoluteColor,
) { ) {
let rect = rect.to_webrender(); let rect = rect.to_webrender();
let wavy_line_thickness = (0.33 * rect.size.height).ceil(); let wavy_line_thickness = (0.33 * rect.size.height).ceil();
let text_decoration_color = fragment let text_decoration_color = fragment
.parent_style .parent_style
.clone_text_decoration_color() .clone_text_decoration_color()
.into_rgba(color); .resolve_into_absolute(color);
let text_decoration_style = fragment.parent_style.clone_text_decoration_style(); let text_decoration_style = fragment.parent_style.clone_text_decoration_style();
if text_decoration_style == ComputedTextDecorationStyle::MozNone { if text_decoration_style == ComputedTextDecorationStyle::MozNone {
return; 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( wr::ColorF::new(
rgba.red_f32(), rgba.components.0.clamp(0.0, 1.0),
rgba.green_f32(), rgba.components.1.clamp(0.0, 1.0),
rgba.blue_f32(), rgba.components.2.clamp(0.0, 1.0),
rgba.alpha_f32(), rgba.alpha,
) )
} }

View file

@ -1786,12 +1786,7 @@ fn get_root_flow_background_color(flow: &mut dyn Flow) -> ColorF {
.background_color .background_color
.clone(), .clone(),
); );
ColorF::new( color.to_layout()
color.red_f32(),
color.green_f32(),
color.blue_f32(),
color.alpha_f32(),
)
} }
fn get_ua_stylesheets() -> Result<UserAgentStylesheets, &'static str> { fn get_ua_stylesheets() -> Result<UserAgentStylesheets, &'static str> {

View file

@ -22,6 +22,7 @@ use pixels::PixelFormat;
use profile_traits::ipc as profiled_ipc; use profile_traits::ipc as profiled_ipc;
use script_traits::ScriptMsg; use script_traits::ScriptMsg;
use servo_url::{ImmutableOrigin, ServoUrl}; use servo_url::{ImmutableOrigin, ServoUrl};
use style::color::{AbsoluteColor, ColorSpace};
use style::context::QuirksMode; use style::context::QuirksMode;
use style::parser::ParserContext; use style::parser::ParserContext;
use style::properties::longhands::font_variant_caps::computed_value::T as FontVariantCaps; 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 // https://drafts.css-houdini.org/css-paint-api/#2d-rendering-context
// Whenever "currentColor" is used as a color in the PaintRenderingContext2D API, // Whenever "currentColor" is used as a color in the PaintRenderingContext2D API,
// it is treated as opaque black. // it is treated as opaque black.
None => RGBA::new(0, 0, 0, 1.0), None => AbsoluteColor::black(),
Some(ref canvas) => { Some(ref canvas) => {
let canvas_element = canvas.upcast::<Element>(); let canvas_element = canvas.upcast::<Element>();
match canvas_element.style() { match canvas_element.style() {
Some(ref s) if canvas_element.has_css_layout_box() => { Some(ref s) if canvas_element.has_css_layout_box() => {
s.get_inherited_text().color 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(&current_color)
.to_color_space(ColorSpace::Srgb);
Ok(RGBA::from_floats(
rgba.components.0,
rgba.components.1,
rgba.components.2,
rgba.alpha,
))
}, },
None => Err(()), None => Err(()),
} }

View file

@ -702,9 +702,13 @@ impl<'dom> LayoutElementHelpers<'dom> for LayoutDom<'dom, Element> {
}; };
if let Some(color) = bgcolor { if let Some(color) = bgcolor {
use cssparser::FromParsedColor;
hints.push(from_declaration( hints.push(from_declaration(
shared_lock, 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 { if let Some(color) = color {
use cssparser::FromParsedColor;
hints.push(from_declaration( hints.push(from_declaration(
shared_lock, 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(),
)),
)); ));
} }

View file

@ -4,6 +4,7 @@
//! Servo's media-query device and expression representation. //! Servo's media-query device and expression representation.
use crate::color::AbsoluteColor;
use crate::context::QuirksMode; use crate::context::QuirksMode;
use crate::custom_properties::CssEnvironment; use crate::custom_properties::CssEnvironment;
use crate::font_metrics::FontMetrics; use crate::font_metrics::FontMetrics;
@ -117,7 +118,7 @@ impl Device {
/// Sets the body text color for the "inherit color from body" quirk. /// Sets the body text color for the "inherit color from body" quirk.
/// ///
/// <https://quirks.spec.whatwg.org/#the-tables-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) // Servo doesn't implement this quirk (yet)
} }
@ -201,13 +202,13 @@ impl Device {
} }
/// Returns the default background color. /// Returns the default background color.
pub fn default_background_color(&self) -> RGBA { pub fn default_background_color(&self) -> AbsoluteColor {
RGBA::new(255, 255, 255, 1.0) AbsoluteColor::white()
} }
/// Returns the default foreground color. /// Returns the default foreground color.
pub fn default_color(&self) -> RGBA { pub fn default_color(&self) -> AbsoluteColor {
RGBA::new(0, 0, 0, 1.0) AbsoluteColor::black()
} }
/// Returns safe area insets /// Returns safe area insets

View file

@ -2,13 +2,13 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * 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/. */ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
use cssparser::RGBA; use style::color::AbsoluteColor;
use style::values::animated::{Animate, Procedure, ToAnimatedValue}; use style::values::animated::{Animate, Procedure, ToAnimatedValue};
fn interpolate_rgba(from: RGBA, to: RGBA, progress: f64) -> RGBA { fn interpolate_color(from: AbsoluteColor, to: AbsoluteColor, progress: f64) -> AbsoluteColor {
let from = from.to_animated_value(); let from = from.to_animated_value();
let to = to.to_animated_value(); let to = to.to_animated_value();
RGBA::from_animated_value( AbsoluteColor::from_animated_value(
from.animate(&to, Procedure::Interpolate { progress }) from.animate(&to, Procedure::Interpolate { progress })
.unwrap(), .unwrap(),
) )
@ -18,16 +18,24 @@ fn interpolate_rgba(from: RGBA, to: RGBA, progress: f64) -> RGBA {
#[test] #[test]
fn test_rgba_color_interepolation_preserves_transparent() { fn test_rgba_color_interepolation_preserves_transparent() {
assert_eq!( assert_eq!(
interpolate_rgba(RGBA::transparent(), RGBA::transparent(), 0.5), interpolate_color(
RGBA::transparent() AbsoluteColor::transparent(),
AbsoluteColor::transparent(),
0.5
),
AbsoluteColor::transparent()
); );
} }
#[test] #[test]
fn test_rgba_color_interepolation_alpha() { fn test_rgba_color_interepolation_alpha() {
assert_eq!( assert_eq!(
interpolate_rgba(RGBA::new(200, 0, 0, 0.4), RGBA::new(0, 200, 0, 0.8), 0.5), interpolate_color(
RGBA::new(67, 133, 0, 0.6) AbsoluteColor::srgb(0.6, 0.0, 0.0, 0.4),
AbsoluteColor::srgb(0.0, 0.6, 0.0, 0.8),
0.5
),
AbsoluteColor::srgb(0.2, 0.4, 0.0, 0.6)
); );
} }
@ -36,47 +44,47 @@ fn test_rgba_color_interepolation_out_of_range_1() {
// Some cubic-bezier functions produce values that are out of range [0, 1]. // Some cubic-bezier functions produce values that are out of range [0, 1].
// Unclamped cases. // Unclamped cases.
assert_eq!( assert_eq!(
interpolate_rgba( interpolate_color(
RGBA::from_floats(0.3, 0.0, 0.0, 0.4), AbsoluteColor::srgb(0.3, 0.0, 0.0, 0.4),
RGBA::from_floats(0.0, 1.0, 0.0, 0.6), AbsoluteColor::srgb(0.0, 1.0, 0.0, 0.6),
-0.5 -0.5
), ),
RGBA::new(154, 0, 0, 0.3) AbsoluteColor::srgb(0.6, -1.0, 0.0, 0.3)
); );
} }
#[test] #[test]
fn test_rgba_color_interepolation_out_of_range_2() { fn test_rgba_color_interepolation_out_of_range_2() {
assert_eq!( assert_eq!(
interpolate_rgba( interpolate_color(
RGBA::from_floats(1.0, 0.0, 0.0, 0.6), AbsoluteColor::srgb(1.0, 0.0, 0.0, 0.6),
RGBA::from_floats(0.0, 0.3, 0.0, 0.4), AbsoluteColor::srgb(0.0, 0.3, 0.0, 0.4),
1.5 1.5
), ),
RGBA::new(0, 154, 0, 0.3) AbsoluteColor::srgb(-1.0, 0.6, 0.0, 0.3)
); );
} }
#[test] #[test]
fn test_rgba_color_interepolation_out_of_range_clamped_1() { fn test_rgba_color_interepolation_out_of_range_clamped_1() {
assert_eq!( assert_eq!(
interpolate_rgba( interpolate_color(
RGBA::from_floats(1.0, 0.0, 0.0, 0.8), AbsoluteColor::srgb(1.0, 0.0, 0.0, 0.8),
RGBA::from_floats(0.0, 1.0, 0.0, 0.2), AbsoluteColor::srgb(0.0, 1.0, 0.0, 0.2),
-0.5 -0.5
), ),
RGBA::from_floats(1.0, 0.0, 0.0, 1.0) AbsoluteColor::srgb(1.2, -0.1, 0.0, 1.0)
); );
} }
#[test] #[test]
fn test_rgba_color_interepolation_out_of_range_clamped_2() { fn test_rgba_color_interepolation_out_of_range_clamped_2() {
assert_eq!( assert_eq!(
interpolate_rgba( interpolate_color(
RGBA::from_floats(1.0, 0.0, 0.0, 0.8), AbsoluteColor::srgb(1.0, 0.0, 0.0, 0.8),
RGBA::from_floats(0.0, 1.0, 0.0, 0.2), AbsoluteColor::srgb(0.0, 1.0, 0.0, 0.2),
1.5 1.5
), ),
RGBA::from_floats(0.0, 0.0, 0.0, 0.0) AbsoluteColor::srgb(0.0, 0.0, 0.0, 0.0)
); );
} }