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

@ -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 {},

View file

@ -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,
)
}