Let resolve_color() take its parameter by reference (#35247)

Bumps Stylo to https://github.com/servo/stylo/pull/116

This way the callers don't have to clone it if they don't have ownership
or want to use the value later.

Signed-off-by: Oriol Brufau <obrufau@igalia.com>
This commit is contained in:
Oriol Brufau 2025-01-31 15:34:40 -08:00 committed by GitHub
parent 7edbafb91b
commit 3122de08f3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 34 additions and 42 deletions

24
Cargo.lock generated
View file

@ -1659,7 +1659,7 @@ dependencies = [
[[package]] [[package]]
name = "dom" name = "dom"
version = "0.0.1" version = "0.0.1"
source = "git+https://github.com/servo/stylo?branch=2025-01-02#06e3f12281781e087d06f03ed506eb6c9355c3c1" source = "git+https://github.com/servo/stylo?branch=2025-01-02#816c35500ca077f88b5d38a3bcc79c8c568d307a"
dependencies = [ dependencies = [
"bitflags 2.8.0", "bitflags 2.8.0",
"malloc_size_of", "malloc_size_of",
@ -4424,7 +4424,7 @@ dependencies = [
[[package]] [[package]]
name = "malloc_size_of" name = "malloc_size_of"
version = "0.0.1" version = "0.0.1"
source = "git+https://github.com/servo/stylo?branch=2025-01-02#06e3f12281781e087d06f03ed506eb6c9355c3c1" source = "git+https://github.com/servo/stylo?branch=2025-01-02#816c35500ca077f88b5d38a3bcc79c8c568d307a"
dependencies = [ dependencies = [
"app_units", "app_units",
"cssparser", "cssparser",
@ -6437,7 +6437,7 @@ dependencies = [
[[package]] [[package]]
name = "selectors" name = "selectors"
version = "0.26.0" version = "0.26.0"
source = "git+https://github.com/servo/stylo?branch=2025-01-02#06e3f12281781e087d06f03ed506eb6c9355c3c1" source = "git+https://github.com/servo/stylo?branch=2025-01-02#816c35500ca077f88b5d38a3bcc79c8c568d307a"
dependencies = [ dependencies = [
"bitflags 2.8.0", "bitflags 2.8.0",
"cssparser", "cssparser",
@ -6722,7 +6722,7 @@ dependencies = [
[[package]] [[package]]
name = "servo_arc" name = "servo_arc"
version = "0.4.0" version = "0.4.0"
source = "git+https://github.com/servo/stylo?branch=2025-01-02#06e3f12281781e087d06f03ed506eb6c9355c3c1" source = "git+https://github.com/servo/stylo?branch=2025-01-02#816c35500ca077f88b5d38a3bcc79c8c568d307a"
dependencies = [ dependencies = [
"serde", "serde",
"stable_deref_trait", "stable_deref_trait",
@ -6731,7 +6731,7 @@ dependencies = [
[[package]] [[package]]
name = "servo_atoms" name = "servo_atoms"
version = "0.0.1" version = "0.0.1"
source = "git+https://github.com/servo/stylo?branch=2025-01-02#06e3f12281781e087d06f03ed506eb6c9355c3c1" source = "git+https://github.com/servo/stylo?branch=2025-01-02#816c35500ca077f88b5d38a3bcc79c8c568d307a"
dependencies = [ dependencies = [
"string_cache", "string_cache",
"string_cache_codegen", "string_cache_codegen",
@ -7099,7 +7099,7 @@ checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f"
[[package]] [[package]]
name = "static_prefs" name = "static_prefs"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/servo/stylo?branch=2025-01-02#06e3f12281781e087d06f03ed506eb6c9355c3c1" source = "git+https://github.com/servo/stylo?branch=2025-01-02#816c35500ca077f88b5d38a3bcc79c8c568d307a"
[[package]] [[package]]
name = "strck" name = "strck"
@ -7180,7 +7180,7 @@ dependencies = [
[[package]] [[package]]
name = "style" name = "style"
version = "0.0.1" version = "0.0.1"
source = "git+https://github.com/servo/stylo?branch=2025-01-02#06e3f12281781e087d06f03ed506eb6c9355c3c1" source = "git+https://github.com/servo/stylo?branch=2025-01-02#816c35500ca077f88b5d38a3bcc79c8c568d307a"
dependencies = [ dependencies = [
"app_units", "app_units",
"arrayvec", "arrayvec",
@ -7238,7 +7238,7 @@ dependencies = [
[[package]] [[package]]
name = "style_config" name = "style_config"
version = "0.0.1" version = "0.0.1"
source = "git+https://github.com/servo/stylo?branch=2025-01-02#06e3f12281781e087d06f03ed506eb6c9355c3c1" source = "git+https://github.com/servo/stylo?branch=2025-01-02#816c35500ca077f88b5d38a3bcc79c8c568d307a"
dependencies = [ dependencies = [
"lazy_static", "lazy_static",
] ]
@ -7246,7 +7246,7 @@ dependencies = [
[[package]] [[package]]
name = "style_derive" name = "style_derive"
version = "0.0.1" version = "0.0.1"
source = "git+https://github.com/servo/stylo?branch=2025-01-02#06e3f12281781e087d06f03ed506eb6c9355c3c1" source = "git+https://github.com/servo/stylo?branch=2025-01-02#816c35500ca077f88b5d38a3bcc79c8c568d307a"
dependencies = [ dependencies = [
"darling", "darling",
"proc-macro2", "proc-macro2",
@ -7276,7 +7276,7 @@ dependencies = [
[[package]] [[package]]
name = "style_traits" name = "style_traits"
version = "0.0.1" version = "0.0.1"
source = "git+https://github.com/servo/stylo?branch=2025-01-02#06e3f12281781e087d06f03ed506eb6c9355c3c1" source = "git+https://github.com/servo/stylo?branch=2025-01-02#816c35500ca077f88b5d38a3bcc79c8c568d307a"
dependencies = [ dependencies = [
"app_units", "app_units",
"bitflags 2.8.0", "bitflags 2.8.0",
@ -7671,7 +7671,7 @@ dependencies = [
[[package]] [[package]]
name = "to_shmem" name = "to_shmem"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/servo/stylo?branch=2025-01-02#06e3f12281781e087d06f03ed506eb6c9355c3c1" source = "git+https://github.com/servo/stylo?branch=2025-01-02#816c35500ca077f88b5d38a3bcc79c8c568d307a"
dependencies = [ dependencies = [
"cssparser", "cssparser",
"servo_arc", "servo_arc",
@ -7684,7 +7684,7 @@ dependencies = [
[[package]] [[package]]
name = "to_shmem_derive" name = "to_shmem_derive"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/servo/stylo?branch=2025-01-02#06e3f12281781e087d06f03ed506eb6c9355c3c1" source = "git+https://github.com/servo/stylo?branch=2025-01-02#816c35500ca077f88b5d38a3bcc79c8c568d307a"
dependencies = [ dependencies = [
"darling", "darling",
"proc-macro2", "proc-macro2",

View file

@ -611,7 +611,7 @@ impl Fragment {
absolute_bounds: Rect<Au>, absolute_bounds: Rect<Au>,
) { ) {
let background = style.get_background(); let background = style.get_background();
let background_color = style.resolve_color(background.background_color.clone()); let background_color = style.resolve_color(&background.background_color);
// XXXManishearth the below method should ideally use an iterator over // XXXManishearth the below method should ideally use an iterator over
// backgrounds // backgrounds
self.build_display_list_for_background_if_applicable_with_background( self.build_display_list_for_background_if_applicable_with_background(
@ -1015,9 +1015,7 @@ impl Fragment {
webrender_api::BoxShadowDisplayItem { webrender_api::BoxShadowDisplayItem {
common: items::empty_common_item_properties(), common: items::empty_common_item_properties(),
box_bounds: absolute_bounds.to_layout(), box_bounds: absolute_bounds.to_layout(),
color: style color: style.resolve_color(&box_shadow.base.color).to_layout(),
.resolve_color(box_shadow.base.color.clone())
.to_layout(),
offset: LayoutVector2D::new( offset: LayoutVector2D::new(
box_shadow.base.horizontal.px(), box_shadow.base.horizontal.px(),
box_shadow.base.vertical.px(), box_shadow.base.vertical.px(),
@ -1120,19 +1118,19 @@ impl Fragment {
} }
let details = BorderDetails::Normal(NormalBorder { let details = BorderDetails::Normal(NormalBorder {
left: BorderSide { left: BorderSide {
color: style.resolve_color(colors.left).to_layout(), color: style.resolve_color(&colors.left).to_layout(),
style: border_style.left.to_layout(), style: border_style.left.to_layout(),
}, },
right: BorderSide { right: BorderSide {
color: style.resolve_color(colors.right).to_layout(), color: style.resolve_color(&colors.right).to_layout(),
style: border_style.right.to_layout(), style: border_style.right.to_layout(),
}, },
top: BorderSide { top: BorderSide {
color: style.resolve_color(colors.top).to_layout(), color: style.resolve_color(&colors.top).to_layout(),
style: border_style.top.to_layout(), style: border_style.top.to_layout(),
}, },
bottom: BorderSide { bottom: BorderSide {
color: style.resolve_color(colors.bottom).to_layout(), color: style.resolve_color(&colors.bottom).to_layout(),
style: border_style.bottom.to_layout(), style: border_style.bottom.to_layout(),
}, },
radius: border_radius, radius: border_radius,
@ -1302,7 +1300,7 @@ impl Fragment {
// Append the outline to the display list. // Append the outline to the display list.
let color = style let color = style
.resolve_color(style.get_outline().outline_color.clone()) .resolve_color(&style.get_outline().outline_color)
.to_layout(); .to_layout();
let base = state.create_base_display_item( let base = state.create_base_display_item(
clip, clip,
@ -1343,8 +1341,7 @@ impl Fragment {
// TODO: Allow non-text fragments to be selected too. // TODO: Allow non-text fragments to be selected too.
if scanned_text_fragment_info.selected() { if scanned_text_fragment_info.selected() {
let style = self.selected_style(); let style = self.selected_style();
let background_color = let background_color = style.resolve_color(&style.get_background().background_color);
style.resolve_color(style.get_background().background_color.clone());
let base = state.create_base_display_item( let base = state.create_base_display_item(
stacking_relative_border_box, stacking_relative_border_box,
self.node, self.node,
@ -1929,7 +1926,7 @@ impl Fragment {
base: base.clone(), base: base.clone(),
shadow: webrender_api::Shadow { shadow: webrender_api::Shadow {
offset: LayoutVector2D::new(shadow.horizontal.px(), shadow.vertical.px()), offset: LayoutVector2D::new(shadow.horizontal.px(), shadow.vertical.px()),
color: self.style.resolve_color(shadow.color.clone()).to_layout(), color: self.style.resolve_color(&shadow.color).to_layout(),
blur_radius: shadow.blur.px(), blur_radius: shadow.blur.px(),
}, },
}, },

View file

@ -195,7 +195,7 @@ fn convert_gradient_stops(
assert!(offset.is_finite()); assert!(offset.is_finite());
stops.push(GradientStop { stops.push(GradientStop {
offset, offset,
color: style.resolve_color(stop.color.clone()).to_layout(), color: style.resolve_color(stop.color).to_layout(),
}) })
} }
stops stops

View file

@ -1340,7 +1340,7 @@ impl TableCellStyleInfo<'_> {
let build_dl = |sty: &ComputedValues, state: &mut &mut DisplayListBuildState| { let build_dl = |sty: &ComputedValues, state: &mut &mut DisplayListBuildState| {
let background = sty.get_background(); let background = sty.get_background();
let background_color = sty.resolve_color(background.background_color.clone()); let background_color = sty.resolve_color(&background.background_color);
cell_flow.build_display_list_for_background_if_applicable_with_background( cell_flow.build_display_list_for_background_if_applicable_with_background(
state, state,
background, background,

View file

@ -346,11 +346,11 @@ fn conic_gradient_items_to_color_stops(
.filter_map(|item| { .filter_map(|item| {
match item { match item {
GradientItem::SimpleColorStop(color) => Some(ColorStop { GradientItem::SimpleColorStop(color) => Some(ColorStop {
color: super::rgba(style.resolve_color(color.clone())), color: super::rgba(style.resolve_color(color)),
position: None, position: None,
}), }),
GradientItem::ComplexColorStop { color, position } => Some(ColorStop { GradientItem::ComplexColorStop { color, position } => Some(ColorStop {
color: super::rgba(style.resolve_color(color.clone())), color: super::rgba(style.resolve_color(color)),
position: match position { position: match position {
AngleOrPercentage::Percentage(percentage) => Some(percentage.0), AngleOrPercentage::Percentage(percentage) => Some(percentage.0),
AngleOrPercentage::Angle(angle) => Some(angle.degrees() / 360.), AngleOrPercentage::Angle(angle) => Some(angle.degrees() / 360.),
@ -384,11 +384,11 @@ fn gradient_items_to_color_stops(
.filter_map(|item| { .filter_map(|item| {
match item { match item {
GradientItem::SimpleColorStop(color) => Some(ColorStop { GradientItem::SimpleColorStop(color) => Some(ColorStop {
color: super::rgba(style.resolve_color(color.clone())), color: super::rgba(style.resolve_color(color)),
position: None, position: None,
}), }),
GradientItem::ComplexColorStop { color, position } => Some(ColorStop { GradientItem::ComplexColorStop { color, position } => Some(ColorStop {
color: super::rgba(style.resolve_color(color.clone())), color: super::rgba(style.resolve_color(color)),
position: Some(if gradient_line_length.is_zero() { position: Some(if gradient_line_length.is_zero() {
0. 0.
} else { } else {

View file

@ -708,7 +708,7 @@ impl<'a> BuilderForBoxFragment<'a> {
painter: &BackgroundPainter, painter: &BackgroundPainter,
) { ) {
let b = painter.style.get_background(); let b = painter.style.get_background();
let background_color = painter.style.resolve_color(b.background_color.clone()); let background_color = painter.style.resolve_color(&b.background_color);
if background_color.alpha > 0.0 { if background_color.alpha > 0.0 {
// https://drafts.csswg.org/css-backgrounds/#background-color // https://drafts.csswg.org/css-backgrounds/#background-color
// “The background color is clipped according to the background-clip // “The background color is clipped according to the background-clip
@ -1119,7 +1119,7 @@ impl<'a> BuilderForBoxFragment<'a> {
}; };
let side = self.build_border_side(BorderStyleColor { let side = self.build_border_side(BorderStyleColor {
style: border_style, style: border_style,
color: style.resolve_color(outline.outline_color.clone()), color: style.resolve_color(&outline.outline_color),
}); });
let details = wr::BorderDetails::Normal(wr::NormalBorder { let details = wr::BorderDetails::Normal(wr::NormalBorder {
top: side, top: side,
@ -1156,11 +1156,7 @@ impl<'a> BuilderForBoxFragment<'a> {
box_shadow.base.horizontal.px(), box_shadow.base.horizontal.px(),
box_shadow.base.vertical.px(), box_shadow.base.vertical.px(),
), ),
rgba( rgba(self.fragment.style.resolve_color(&box_shadow.base.color)),
self.fragment
.style
.resolve_color(box_shadow.base.color.clone()),
),
box_shadow.base.blur.px(), box_shadow.base.blur.px(),
box_shadow.spread.px(), box_shadow.spread.px(),
self.border_radius, self.border_radius,

View file

@ -576,7 +576,7 @@ impl StackingContext {
.union(&fragment_tree.scrollable_overflow) .union(&fragment_tree.scrollable_overflow)
.to_webrender(); .to_webrender();
let background_color = style.resolve_color(style.get_background().background_color.clone()); let background_color = style.resolve_color(&style.get_background().background_color);
if background_color.alpha > 0.0 { if background_color.alpha > 0.0 {
let common = builder.common_properties(painting_area, style); let common = builder.common_properties(painting_area, style);
let color = super::rgba(background_color); let color = super::rgba(background_color);

View file

@ -741,7 +741,7 @@ impl ComputedValuesExt for ComputedValues {
/// Whether or not this style specifies a non-transparent background. /// Whether or not this style specifies a non-transparent background.
fn background_is_transparent(&self) -> bool { fn background_is_transparent(&self) -> bool {
let background = self.get_background(); let background = self.get_background();
let color = self.resolve_color(background.background_color.clone()); let color = self.resolve_color(&background.background_color);
color.alpha == 0.0 && color.alpha == 0.0 &&
background background
.background_image .background_image

View file

@ -1308,12 +1308,11 @@ fn get_root_flow_background_color(flow: &mut dyn Flow) -> ColorF {
let kid_block_flow = kid.as_block(); let kid_block_flow = kid.as_block();
let color = kid_block_flow.fragment.style.resolve_color( let color = kid_block_flow.fragment.style.resolve_color(
kid_block_flow &kid_block_flow
.fragment .fragment
.style .style
.get_background() .get_background()
.background_color .background_color,
.clone(),
); );
color.to_layout() color.to_layout()
} }