Skip to content

Truly independent web browser

LibWeb: Resolve color, shadow and filter values in Rust

Andreas Kling1aae115a9a8e
diff --git a/Libraries/LibWeb/CSS/CSSStyleProperties.cpp b/Libraries/LibWeb/CSS/CSSStyleProperties.cpp
index 61ac78f84ff..55f7a1e75d1 100644
--- a/Libraries/LibWeb/CSS/CSSStyleProperties.cpp
+++ b/Libraries/LibWeb/CSS/CSSStyleProperties.cpp
@@ -326,11 +326,6 @@ WebIDL::ExceptionOr<void> CSSStyleProperties::set_property(PropertyID property_i
return set_property_internal(PropertyNameAndID::from_id(property_id), css_text, priority);
}
-static NonnullRefPtr<StyleValue const> style_value_for_css_pixels(CSSPixels css_pixels)
-{
- return LengthStyleValue::create(Length::make_px(css_pixels));
-}
-
static NonnullRefPtr<StyleValue const> style_value_for_length_percentage(LengthPercentage const& length_percentage)
{
if (length_percentage.is_percentage())
@@ -372,74 +367,21 @@ static NonnullRefPtr<StyleValue const> style_value_for_transform_origin(Transfor
return StyleValueList::create(move(offsets), StyleValueList::Separator::Space, StyleValueList::Collapsible::No);
}
-static RefPtr<StyleValue const> style_value_for_shadow(ShadowStyleValue::ShadowType shadow_type, ReadonlySpan<ShadowData> shadow_data, Color current_color)
+static NonnullRefPtr<StyleValue const> style_value_for_shadow(ShadowStyleValue::ShadowType shadow_type, ReadonlySpan<ShadowData> shadow_data, Color current_color)
{
- if (shadow_data.is_empty())
- return KeywordStyleValue::create(Keyword::None);
-
- auto make_shadow_style_value = [shadow_type, current_color](ShadowData const& shadow) {
- return ShadowStyleValue::create(
- shadow_type,
- ColorStyleValue::create_from_color(shadow.resolved_color(current_color), ColorSyntax::Modern),
- style_value_for_css_pixels(shadow.offset_x),
- style_value_for_css_pixels(shadow.offset_y),
- style_value_for_css_pixels(shadow.blur_radius),
- style_value_for_css_pixels(shadow.spread_distance),
- shadow.placement);
- };
-
- if (shadow_data.size() == 1)
- return make_shadow_style_value(shadow_data.first());
-
- StyleValueVector style_values;
- style_values.ensure_capacity(shadow_data.size());
- for (auto& shadow : shadow_data)
- style_values.unchecked_append(make_shadow_style_value(shadow));
-
- return StyleValueList::create(move(style_values), StyleValueList::Separator::Comma);
+ static_assert(sizeof(ShadowData) == sizeof(ComputedValuesFFI::ComputedShadow));
+ return StyleValue::adopt_rust_style_value_data(StyleValueFFI::rust_resolved_shadow_value(
+ to_underlying(shadow_type), shadow_data.data(), shadow_data.size(), current_color.value()));
}
-// The stored computed filter value keeps currentcolor inside drop-shadow(); the resolved value
-// serializes it against the element's used color, like the color-valued properties.
static NonnullRefPtr<StyleValue const> resolve_filter_style_value(NonnullRefPtr<StyleValue const> value, Color current_color)
{
- if (!value->is_value_list())
- return value;
- auto const& list = value->as_value_list();
- StyleValueVector filters;
- MUST(filters.try_ensure_capacity(list.size()));
- bool resolved_any = false;
- for (auto const& filter_value : list.values()) {
- if (filter_value->is_filter() && filter_value->as_filter().kind() == FilterStyleValue::Kind::DropShadow) {
- auto const& drop_shadow = static_cast<DropShadowFilterStyleValue const&>(filter_value->as_filter());
- auto const& drop_shadow_color = drop_shadow.color();
- if (!drop_shadow_color || drop_shadow_color->to_keyword() == Keyword::Currentcolor) {
- filters.unchecked_append(DropShadowFilterStyleValue::create(
- drop_shadow.offset_x(),
- drop_shadow.offset_y(),
- drop_shadow.radius(),
- ColorStyleValue::create_from_color(current_color, ColorSyntax::Modern)));
- resolved_any = true;
- continue;
- }
- }
- filters.unchecked_append(filter_value);
- }
- if (!resolved_any)
- return value;
- return StyleValueList::create(move(filters), StyleValueList::Separator::Space, StyleValueList::Collapsible::No);
+ return StyleValue::adopt_rust_style_value_data(StyleValueFFI::rust_resolved_filter_value(value->rust_style_value_data(), current_color.value()));
}
-// Allowing exactly panning and pinch-zoom serializes as `manipulation`, whatever form specified it. The parser
-// orders a list as horizontal, vertical, pinch-zoom, with at most one of each.
static NonnullRefPtr<StyleValue const> resolve_touch_action_style_value(NonnullRefPtr<StyleValue const> value)
{
- if (value->is_value_list()) {
- auto const& values = value->as_value_list().values();
- if (values.size() == 3 && values[0]->to_keyword() == Keyword::PanX && values[1]->to_keyword() == Keyword::PanY)
- return KeywordStyleValue::create(Keyword::Manipulation);
- }
- return value;
+ return StyleValue::adopt_rust_style_value_data(StyleValueFFI::rust_resolved_touch_action_value(value->rust_style_value_data()));
}
// https://drafts.csswg.org/cssom/#dom-cssstyledeclaration-getpropertyvalue
@@ -704,7 +646,7 @@ static void ensure_pseudo_element_style_for_cssom(Layout::BegunRead const& read,
install_engine_pseudo_element_style(read, abstract_element);
}
-static RefPtr<StyleValue const> resolve_color_style_value(StyleValue const&, Color, Optional<ColorResolutionStyle> = {});
+static NonnullRefPtr<StyleValue const> resolve_color_style_value(StyleValue const&, Color, Optional<ColorResolutionStyle> = {});
static NonnullRefPtr<StyleValue const> resolve_svg_color_style_value(StyleValue const&, ColorResolutionStyle);
static bool is_min_or_max_size_property(PropertyID property_id)
@@ -954,36 +896,36 @@ Optional<StyleProperty> CSSStyleProperties::get_direct_property(PropertyNameAndI
// the style's own resolved group data since there is no layout node to ask.
switch (computed_property_id) {
case PropertyID::Color:
- return resolve_color_style_value(*computed_value, computed_values->color(), ColorResolutionStyle::for_computed_values(*computed_values)).release_nonnull();
+ return resolve_color_style_value(*computed_value, computed_values->color(), ColorResolutionStyle::for_computed_values(*computed_values));
case PropertyID::Fill:
case PropertyID::FloodColor:
case PropertyID::StopColor:
case PropertyID::Stroke:
return resolve_svg_color_style_value(*computed_value, ColorResolutionStyle::for_computed_values(*computed_values));
case PropertyID::CaretColor:
- return resolve_color_style_value(*computed_value, computed_values->caret_color()).release_nonnull();
+ return resolve_color_style_value(*computed_value, computed_values->caret_color());
case PropertyID::BackgroundColor:
- return resolve_color_style_value(*computed_value, computed_values->background_color()).release_nonnull();
+ return resolve_color_style_value(*computed_value, computed_values->background_color());
case PropertyID::BorderBottomColor:
- return resolve_color_style_value(*computed_value, computed_values->border_bottom().color).release_nonnull();
+ return resolve_color_style_value(*computed_value, computed_values->border_bottom().color);
case PropertyID::BorderLeftColor:
- return resolve_color_style_value(*computed_value, computed_values->border_left().color).release_nonnull();
+ return resolve_color_style_value(*computed_value, computed_values->border_left().color);
case PropertyID::BorderRightColor:
- return resolve_color_style_value(*computed_value, computed_values->border_right().color).release_nonnull();
+ return resolve_color_style_value(*computed_value, computed_values->border_right().color);
case PropertyID::BorderTopColor:
- return resolve_color_style_value(*computed_value, computed_values->border_top().color).release_nonnull();
+ return resolve_color_style_value(*computed_value, computed_values->border_top().color);
case PropertyID::ColumnRuleColor:
- return resolve_color_style_value(*computed_value, computed_values->column_rule_color()).release_nonnull();
+ return resolve_color_style_value(*computed_value, computed_values->column_rule_color());
case PropertyID::OutlineColor:
- return resolve_color_style_value(*computed_value, computed_values->outline_color()).release_nonnull();
+ return resolve_color_style_value(*computed_value, computed_values->outline_color());
case PropertyID::TextDecorationColor:
- return resolve_color_style_value(*computed_value, computed_values->text_decoration_color()).release_nonnull();
+ return resolve_color_style_value(*computed_value, computed_values->text_decoration_color());
case PropertyID::WebkitTextFillColor:
- return resolve_color_style_value(*computed_value, computed_values->webkit_text_fill_color()).release_nonnull();
+ return resolve_color_style_value(*computed_value, computed_values->webkit_text_fill_color());
case PropertyID::BoxShadow:
- return style_value_for_shadow(ShadowStyleValue::ShadowType::Normal, computed_values->box_shadow(), computed_values->color()).release_nonnull();
+ return style_value_for_shadow(ShadowStyleValue::ShadowType::Normal, computed_values->box_shadow(), computed_values->color());
case PropertyID::TextShadow:
- return style_value_for_shadow(ShadowStyleValue::ShadowType::Text, computed_values->text_shadow(), computed_values->color()).release_nonnull();
+ return style_value_for_shadow(ShadowStyleValue::ShadowType::Text, computed_values->text_shadow(), computed_values->color());
case PropertyID::BackdropFilter:
case PropertyID::Filter:
return resolve_filter_style_value(move(computed_value), computed_values->color());
@@ -1133,60 +1075,17 @@ Optional<Utf16String> CSSStyleProperties::serialized_computed_value_from_stored_
return serialize_style_value_handle(*handle, SerializationMode::ResolvedValue);
}
-static RefPtr<StyleValue const> resolve_color_style_value(StyleValue const& style_value, Color computed_color, Optional<ColorResolutionStyle> color_resolution_style)
+static NonnullRefPtr<StyleValue const> resolve_color_style_value(StyleValue const& style_value, Color computed_color, Optional<ColorResolutionStyle> color_resolution_style)
{
- if (color_resolution_style.has_value() && style_value.is_color_function()) {
- auto const& color_function = as<ColorFunctionStyleValue>(style_value);
- if (color_function.origin_color() && color_function.color_type().has_value()) {
- auto ffi_color_resolution_style = color_resolution_style->to_ffi();
- auto const* resolved = StyleValueFFI::rust_relative_color_resolved_value(style_value.rust_style_value_data(), &ffi_color_resolution_style);
- if (!resolved)
- return style_value;
- return StyleValue::adopt_rust_style_value_data(static_cast<StyleValueFFI::StyleValueData const*>(resolved));
- }
- }
-
- // NB: A computed color-mix() is still a mix only where it reads currentcolor, which the used value resolves.
- if (color_resolution_style.has_value() && style_value.is_color()) {
- auto ffi_color_resolution_style = color_resolution_style->to_ffi();
- if (auto const* resolved = StyleValueFFI::rust_color_mix_resolved_value(style_value.rust_style_value_data(), &ffi_color_resolution_style))
- return StyleValue::adopt_rust_style_value_data(static_cast<StyleValueFFI::StyleValueData const*>(resolved));
- }
-
- if (style_value.is_color_function() && as<ColorFunctionStyleValue>(style_value).serializes_as_color_function())
- return style_value;
- // https://drafts.csswg.org/css-color-4/#css-serialization-of-srgb
- // NB: An sRGB value with missing components serializes them as none, which the used color cannot represent.
- if (style_value.is_color_function() && StyleValueFFI::rust_color_function_has_missing_component(style_value.rust_style_value_data()))
- return style_value;
- if (style_value.is_color()) {
- auto& color_style_value = static_cast<ColorStyleValue const&>(style_value);
- if (auto color_type = color_style_value.color_type();
- color_type.has_value() && first_is_one_of(*color_type, ColorStyleValue::ColorType::Lab, ColorStyleValue::ColorType::OKLab, ColorStyleValue::ColorType::LCH, ColorStyleValue::ColorType::OKLCH))
- return style_value;
- }
-
- return ColorStyleValue::create_from_color(computed_color, ColorSyntax::Modern);
+ auto ffi_style = color_resolution_style.map([](auto const& style) { return style.to_ffi(); });
+ return StyleValue::adopt_rust_style_value_data(StyleValueFFI::rust_resolved_color_value(
+ style_value.rust_style_value_data(), computed_color.value(), ffi_style.has_value() ? &*ffi_style : nullptr));
}
-// https://drafts.csswg.org/css-color-4/#resolving-color-values
-// The resolved value of a <color> is its used value.
static NonnullRefPtr<StyleValue const> resolve_svg_color_style_value(StyleValue const& style_value, ColorResolutionStyle color_resolution_style)
{
- if (!style_value.depends_on_current_color())
- return style_value;
-
- if (style_value.is_value_list()) {
- auto const& list = style_value.as_value_list();
- auto values = list.values();
- for (auto& value : values)
- value = resolve_svg_color_style_value(*value, color_resolution_style);
- return StyleValueList::create(move(values), list.separator());
- }
-
- if (auto color = style_value.to_color(color_resolution_style); color.has_value())
- return resolve_color_style_value(style_value, *color, color_resolution_style).release_nonnull();
- return style_value;
+ auto ffi_style = color_resolution_style.to_ffi();
+ return StyleValue::adopt_rust_style_value_data(StyleValueFFI::rust_resolved_svg_color_value(style_value.rust_style_value_data(), &ffi_style));
}
// https://svgwg.org/svg2-draft/geometry.html#Sizing
diff --git a/Libraries/LibWeb/Rust/build.rs b/Libraries/LibWeb/Rust/build.rs
index 2189bf9ce8e..b9aa648c3eb 100644
--- a/Libraries/LibWeb/Rust/build.rs
+++ b/Libraries/LibWeb/Rust/build.rs
@@ -2626,6 +2626,7 @@ fn main() -> Result<(), Box<dyn Error>> {
manifest_dir.join("src/css/calc.rs"),
manifest_dir.join("src/css/serialize.rs"),
manifest_dir.join("src/css/color_resolution.rs"),
+ manifest_dir.join("src/css/resolved_value.rs"),
manifest_dir.join("src/css/absolutize.rs"),
manifest_dir.join("src/css/ffi_stats.rs"),
],
diff --git a/Libraries/LibWeb/Rust/src/css/mod.rs b/Libraries/LibWeb/Rust/src/css/mod.rs
index e88d1a4561a..bf6c90415c1 100644
--- a/Libraries/LibWeb/Rust/src/css/mod.rs
+++ b/Libraries/LibWeb/Rust/src/css/mod.rs
@@ -49,6 +49,7 @@ pub(crate) mod namespace_rule;
pub(crate) mod parser;
pub mod property_metadata;
pub(crate) mod property_rule;
+pub(crate) mod resolved_value;
pub(crate) mod retained_fly_string;
pub(crate) mod rule;
pub(crate) mod scope_selectors;
diff --git a/Libraries/LibWeb/Rust/src/css/resolved_value.rs b/Libraries/LibWeb/Rust/src/css/resolved_value.rs
new file mode 100644
index 00000000000..cef659323d3
--- /dev/null
+++ b/Libraries/LibWeb/Rust/src/css/resolved_value.rs
@@ -0,0 +1,330 @@
+/*
+ * Copyright (c) 2026-present, the Ladybird developers.
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+//! The resolved values of the properties whose resolved value is not their computed value.
+//! https://drafts.csswg.org/cssom/#resolved-values
+
+use crate::css::color_conversion::{LAB, LCH, OKLAB, OKLCH};
+use crate::css::color_resolution::{
+ ColorResolutionInput, FfiColorResolutionStyle, Rgba, SerializationBehavior, descriptor_for_color_type,
+ resolve_color_mix, resolve_relative_form, to_color,
+};
+use crate::css::computed_value_types::ComputedShadow;
+use crate::css::css_enums::keyword;
+use crate::css::css_pixels::CssPixels;
+use crate::css::serialize::color_function_has_missing_component;
+use crate::css::style_value::{
+ ColorBase, ColorFunctionPayload, CssString, FILTER_KIND_DROP_SHADOW, RetainedStyleValueData,
+ RetainedStyleValueDataList, ShadowPayload, StyleValueBox, StyleValueData, shared_style_value,
+ value_depends_on_current_color,
+};
+use crate::css::style_value_arc::StyleValueArc;
+use crate::css::value_codes::{COLOR_SYNTAX_MODERN, COLOR_TYPE_RGB};
+
+const VALUE_LIST_SEPARATOR_SPACE: u8 = 0;
+const VALUE_LIST_SEPARATOR_COMMA: u8 = 1;
+
+fn number(value: f64) -> RetainedStyleValueData {
+ RetainedStyleValueData::from_arc(shared_style_value(StyleValueData::Number { value }))
+}
+
+fn length_px(value: f64) -> RetainedStyleValueData {
+ RetainedStyleValueData::from_arc(shared_style_value(StyleValueData::Length {
+ value,
+ unit: crate::css::calc::canonical_unit_code(&crate::css::style_compute::LENGTH_UNIT_CANONICAL_PX_RATIOS),
+ }))
+}
+
+fn color_value(color: Rgba) -> StyleValueArc {
+ StyleValueArc::new(StyleValueData::ColorFunction(StyleValueBox::new(
+ ColorFunctionPayload {
+ color_base: ColorBase {
+ has_color_type: true,
+ color_type: COLOR_TYPE_RGB,
+ color_syntax: COLOR_SYNTAX_MODERN,
+ },
+ channel_0: number(f64::from(color.r)),
+ channel_1: number(f64::from(color.g)),
+ channel_2: number(f64::from(color.b)),
+ alpha: number(f64::from(color.a) / 255.0),
+ has_name: false,
+ name: CssString::none(),
+ origin_color: RetainedStyleValueData::none(),
+ },
+ )))
+}
+
+fn color_base(value: &StyleValueData) -> Option<&ColorBase> {
+ match value {
+ StyleValueData::ColorFunction(payload) => Some(&payload.color_base),
+ StyleValueData::ColorMix(payload) => Some(&payload.color_base),
+ StyleValueData::LightDark(payload) => Some(&payload.color_base),
+ StyleValueData::ContrastColor { color_base, .. } => Some(color_base),
+ _ => None,
+ }
+}
+
+/// The resolved value of a color property, whose computed value is `value` and whose used color is `computed_color`.
+/// A `style` of `None` keeps relative colors and mixes as they are.
+fn resolve_color_style_value(
+ value: &StyleValueArc,
+ computed_color: Rgba,
+ style: Option<&ColorResolutionInput>,
+) -> StyleValueArc {
+ let color_type = color_base(value)
+ .filter(|base| base.has_color_type)
+ .map(|base| base.color_type);
+
+ if let Some(style) = style {
+ if let StyleValueData::ColorFunction(color_function) = &**value
+ && color_function.origin_color.optional_data().is_some()
+ && color_type.is_some()
+ {
+ return match resolve_relative_form(value, style) {
+ Some(resolved) => StyleValueArc::new(crate::css::color_resolution::relative_color_computed_value_form(
+ resolved,
+ )),
+ None => value.clone(),
+ };
+ }
+
+ // NB: A computed color-mix() is still a mix only where it reads currentcolor, which the used value resolves.
+ if matches!(&**value, StyleValueData::ColorMix(_))
+ && let Some(resolved) = resolve_color_mix(value, style)
+ {
+ return StyleValueArc::new(resolved);
+ }
+ }
+
+ if let StyleValueData::ColorFunction(_) = &**value {
+ let serializes_as_color_function = color_type.is_some_and(|color_type| {
+ matches!(
+ descriptor_for_color_type(color_type).behavior,
+ SerializationBehavior::ColorFunction
+ )
+ });
+ if serializes_as_color_function {
+ return value.clone();
+ }
+ // https://drafts.csswg.org/css-color-4/#css-serialization-of-srgb
+ // NB: An sRGB value with missing components serializes them as none, which the used color cannot represent.
+ if color_function_has_missing_component(value) {
+ return value.clone();
+ }
+ }
+ if color_type.is_some_and(|color_type| matches!(color_type, LAB | OKLAB | LCH | OKLCH)) {
+ return value.clone();
+ }
+
+ color_value(computed_color)
+}
+
+// https://drafts.csswg.org/css-color-4/#resolving-color-values
+// The resolved value of a <color> is its used value.
+fn resolve_svg_color_style_value(value: &StyleValueArc, style: &ColorResolutionInput) -> StyleValueArc {
+ if !value_depends_on_current_color(value) {
+ return value.clone();
+ }
+
+ if let StyleValueData::ValueList {
+ values,
+ separator,
+ collapsible,
+ } = &**value
+ {
+ let values = values
+ .as_slice()
+ .iter()
+ .map(|item| {
+ RetainedStyleValueData::from_arc(resolve_svg_color_style_value(&item.clone().into_arc(), style))
+ })
+ .collect();
+ return StyleValueArc::new(StyleValueData::ValueList {
+ values: RetainedStyleValueDataList::from_retained_values(values),
+ separator: *separator,
+ collapsible: *collapsible,
+ });
+ }
+
+ match to_color(value, style) {
+ Some(color) => resolve_color_style_value(value, color, Some(style)),
+ None => value.clone(),
+ }
+}
+
+// The stored computed filter value keeps currentcolor inside drop-shadow(); the resolved value
+// serializes it against the element's used color, like the color-valued properties.
+fn resolve_filter_style_value(value: &StyleValueArc, current_color: Rgba) -> StyleValueArc {
+ let StyleValueData::ValueList { values, .. } = &**value else {
+ return value.clone();
+ };
+ let mut resolved_any = false;
+ let filters = values
+ .as_slice()
+ .iter()
+ .map(|filter_value| {
+ if let Some(StyleValueData::Filter {
+ kind: FILTER_KIND_DROP_SHADOW,
+ color_operation,
+ value: shadow,
+ }) = filter_value.optional_data()
+ && let Some(StyleValueData::Shadow(shadow)) = shadow.optional_data()
+ && shadow.color.optional_data().is_none_or(
+ |color| matches!(color, StyleValueData::Keyword { keyword } if *keyword == keyword::CURRENTCOLOR),
+ )
+ {
+ resolved_any = true;
+ let shadow = StyleValueData::Shadow(StyleValueBox::new(ShadowPayload {
+ color: RetainedStyleValueData::from_arc(color_value(current_color)),
+ ..(**shadow).clone()
+ }));
+ return RetainedStyleValueData::from_arc(StyleValueArc::new(StyleValueData::Filter {
+ kind: FILTER_KIND_DROP_SHADOW,
+ color_operation: *color_operation,
+ value: RetainedStyleValueData::from_arc(StyleValueArc::new(shadow)),
+ }));
+ }
+ filter_value.clone()
+ })
+ .collect();
+ if !resolved_any {
+ return value.clone();
+ }
+ StyleValueArc::new(StyleValueData::ValueList {
+ values: RetainedStyleValueDataList::from_retained_values(filters),
+ separator: VALUE_LIST_SEPARATOR_SPACE,
+ collapsible: false,
+ })
+}
+
+// Allowing exactly panning and pinch-zoom serializes as `manipulation`, whatever form specified it. The parser
+// orders a list as horizontal, vertical, pinch-zoom, with at most one of each.
+fn resolve_touch_action_style_value(value: &StyleValueArc) -> StyleValueArc {
+ if let StyleValueData::ValueList { values, .. } = &**value {
+ let is_keyword = |item: &RetainedStyleValueData, expected: u16| matches!(item.optional_data(), Some(StyleValueData::Keyword { keyword }) if *keyword == expected);
+ if let [horizontal, vertical, _] = values.as_slice()
+ && is_keyword(horizontal, keyword::PAN_X)
+ && is_keyword(vertical, keyword::PAN_Y)
+ {
+ return shared_style_value(StyleValueData::Keyword {
+ keyword: keyword::MANIPULATION,
+ });
+ }
+ }
+ value.clone()
+}
+
+fn style_value_for_shadow(shadow_type: u8, shadows: &[ComputedShadow], current_color: Rgba) -> StyleValueArc {
+ let pixels = |raw: i32| length_px(CssPixels::from_raw(raw).to_double());
+ let make_shadow_style_value = |shadow: &ComputedShadow| {
+ let color = if shadow.color.is_current_color {
+ current_color
+ } else {
+ Rgba::from_packed(shadow.color.rgba)
+ };
+ StyleValueArc::new(StyleValueData::Shadow(StyleValueBox::new(ShadowPayload {
+ shadow_type,
+ color: RetainedStyleValueData::from_arc(color_value(color)),
+ offset_x: pixels(shadow.offset_x),
+ offset_y: pixels(shadow.offset_y),
+ blur_radius: pixels(shadow.blur_radius),
+ spread_distance: pixels(shadow.spread_distance),
+ placement: shadow.placement as u8,
+ })))
+ };
+
+ match shadows {
+ [] => shared_style_value(StyleValueData::Keyword { keyword: keyword::NONE }),
+ [shadow] => make_shadow_style_value(shadow),
+ shadows => StyleValueArc::new(StyleValueData::ValueList {
+ values: RetainedStyleValueDataList::from_retained_values(
+ shadows
+ .iter()
+ .map(|shadow| RetainedStyleValueData::from_arc(make_shadow_style_value(shadow)))
+ .collect(),
+ ),
+ separator: VALUE_LIST_SEPARATOR_COMMA,
+ collapsible: true,
+ }),
+ }
+}
+
+/// A new reference to `value`, which the caller lends.
+fn retained(value: &StyleValueData) -> StyleValueArc {
+ // SAFETY: Every value the host lends is a counted one.
+ unsafe {
+ StyleValueArc::increment_strong_count(value);
+ StyleValueArc::from_raw(value)
+ }
+}
+
+/// The resolved value of a color property, as one strong reference. `style` may be null.
+///
+/// # Safety
+/// `style` must be null or point at a style whose group payloads outlive the call.
+#[unsafe(no_mangle)]
+pub unsafe extern "C" fn rust_resolved_color_value(
+ value: &StyleValueData,
+ computed_color: u32,
+ style: *const FfiColorResolutionStyle,
+) -> *const StyleValueData {
+ // SAFETY: Guaranteed by the caller.
+ let input = (!style.is_null()).then(|| unsafe { ColorResolutionInput::for_ffi_style(style) });
+ StyleValueArc::into_raw(resolve_color_style_value(
+ &retained(value),
+ Rgba::from_packed(computed_color),
+ input.as_ref(),
+ ))
+}
+
+/// The resolved value of a paint or color SVG property, as one strong reference.
+///
+/// # Safety
+/// `style` must point at a style whose group payloads outlive the call.
+#[unsafe(no_mangle)]
+pub unsafe extern "C" fn rust_resolved_svg_color_value(
+ value: &StyleValueData,
+ style: *const FfiColorResolutionStyle,
+) -> *const StyleValueData {
+ // SAFETY: Guaranteed by the caller.
+ let input = unsafe { ColorResolutionInput::for_ffi_style(style) };
+ StyleValueArc::into_raw(resolve_svg_color_style_value(&retained(value), &input))
+}
+
+/// The resolved value of a filter property, as one strong reference.
+#[unsafe(no_mangle)]
+pub extern "C" fn rust_resolved_filter_value(value: &StyleValueData, current_color: u32) -> *const StyleValueData {
+ StyleValueArc::into_raw(resolve_filter_style_value(
+ &retained(value),
+ Rgba::from_packed(current_color),
+ ))
+}
+
+/// The resolved value of touch-action, as one strong reference.
+#[unsafe(no_mangle)]
+pub extern "C" fn rust_resolved_touch_action_value(value: &StyleValueData) -> *const StyleValueData {
+ StyleValueArc::into_raw(resolve_touch_action_style_value(&retained(value)))
+}
+
+/// The resolved value of a shadow property, as one strong reference.
+///
+/// # Safety
+/// `shadows` must point at `shadow_count` `ComputedShadow`s, or be null with a count of 0.
+#[unsafe(no_mangle)]
+pub unsafe extern "C" fn rust_resolved_shadow_value(
+ shadow_type: u8,
+ shadows: *const core::ffi::c_void,
+ shadow_count: usize,
+ current_color: u32,
+) -> *const StyleValueData {
+ // SAFETY: Guaranteed by the caller.
+ let shadows = unsafe { ak::slice_from_raw_parts(shadows.cast::<ComputedShadow>(), shadow_count) };
+ StyleValueArc::into_raw(style_value_for_shadow(
+ shadow_type,
+ shadows,
+ Rgba::from_packed(current_color),
+ ))
+}