Skip to content

Truly independent web browser

Tests/LibWeb: Remove TestStyleValueEquality

Andreas Kling832d4adb8140
diff --git a/Libraries/LibWeb/CSS/StyleValues/CustomIdentStyleValue.h b/Libraries/LibWeb/CSS/StyleValues/CustomIdentStyleValue.h
index 612560420b2..6cf99f29217 100644
--- a/Libraries/LibWeb/CSS/StyleValues/CustomIdentStyleValue.h
+++ b/Libraries/LibWeb/CSS/StyleValues/CustomIdentStyleValue.h
@@ -15,10 +15,6 @@ namespace Web::CSS {
// https://www.w3.org/TR/css-values-4/#custom-idents
class CustomIdentStyleValue final : public StyleValueWithDefaultOperators<CustomIdentStyleValue> {
public:
- static ValueComparingNonnullRefPtr<CustomIdentStyleValue const> create(Utf16FlyString custom_ident)
- {
- return adopt_ref(*new (nothrow) CustomIdentStyleValue(move(custom_ident)));
- }
virtual ~CustomIdentStyleValue() override = default;
Utf16FlyString custom_ident() const { return css_string_from_rust(&m_value->custom_ident.custom_ident); }
@@ -30,11 +26,6 @@ private:
: StyleValueWithDefaultOperators(Type::CustomIdent, data)
{
}
-
- explicit CustomIdentStyleValue(Utf16FlyString custom_ident)
- : StyleValueWithDefaultOperators(Type::CustomIdent, StyleValueFFI::rust_style_value_create_custom_ident(custom_ident.to_raw_leaked()))
- {
- }
};
}
diff --git a/Libraries/LibWeb/CSS/StyleValues/FilterStyleValue.h b/Libraries/LibWeb/CSS/StyleValues/FilterStyleValue.h
index 09670bfd9a2..d9736346e7a 100644
--- a/Libraries/LibWeb/CSS/StyleValues/FilterStyleValue.h
+++ b/Libraries/LibWeb/CSS/StyleValues/FilterStyleValue.h
@@ -35,11 +35,6 @@ protected:
}
ValueComparingNonnullRefPtr<StyleValue const> filter_value() const { return wrap_rust_child(m_value->filter.value); }
-
- static StyleValueFFI::StyleValueData const* make_filter_data(Kind kind, u8 color_operation, StyleValue const* value)
- {
- return StyleValueFFI::rust_style_value_create_filter(to_underlying(kind), color_operation, StyleValueFFI::rust_style_value_retain(value->rust_style_value_data()));
- }
};
// https://drafts.csswg.org/filter-effects-1/#funcdef-filter-blur
@@ -60,22 +55,6 @@ private:
// https://drafts.csswg.org/filter-effects-1/#funcdef-filter-drop-shadow
class DropShadowFilterStyleValue final : public FilterStyleValue {
public:
- static ValueComparingNonnullRefPtr<DropShadowFilterStyleValue const> create(
- ValueComparingNonnullRefPtr<StyleValue const> offset_x,
- ValueComparingNonnullRefPtr<StyleValue const> offset_y,
- ValueComparingRefPtr<StyleValue const> radius,
- ValueComparingRefPtr<StyleValue const> color)
- {
- return adopt_ref(*new (nothrow) DropShadowFilterStyleValue(ShadowStyleValue::create(
- ShadowStyleValue::ShadowType::Text,
- move(color),
- move(offset_x),
- move(offset_y),
- move(radius),
- nullptr,
- ShadowPlacement::Outer)));
- }
-
ValueComparingNonnullRefPtr<ShadowStyleValue const> shadow() const { return filter_value()->as_shadow(); }
ValueComparingNonnullRefPtr<StyleValue const> offset_x() const { return shadow()->offset_x(); }
ValueComparingNonnullRefPtr<StyleValue const> offset_y() const { return shadow()->offset_y(); }
@@ -85,11 +64,6 @@ public:
private:
friend class StyleValue;
- explicit DropShadowFilterStyleValue(ValueComparingNonnullRefPtr<ShadowStyleValue const> shadow)
- : FilterStyleValue(make_filter_data(Kind::DropShadow, 0, shadow.ptr()))
- {
- }
-
explicit DropShadowFilterStyleValue(StyleValueFFI::StyleValueData const* data)
: FilterStyleValue(data)
{
diff --git a/Libraries/LibWeb/CSS/StyleValues/FlexStyleValue.h b/Libraries/LibWeb/CSS/StyleValues/FlexStyleValue.h
index a94ee8a0d79..1090ab5ffa6 100644
--- a/Libraries/LibWeb/CSS/StyleValues/FlexStyleValue.h
+++ b/Libraries/LibWeb/CSS/StyleValues/FlexStyleValue.h
@@ -13,10 +13,6 @@ namespace Web::CSS {
class FlexStyleValue final : public DimensionStyleValue {
public:
- static ValueComparingNonnullRefPtr<FlexStyleValue const> create(Flex flex)
- {
- return adopt_ref(*new (nothrow) FlexStyleValue(move(flex)));
- }
virtual ~FlexStyleValue() override = default;
Flex flex() const { return Flex(m_value->flex.value, static_cast<FlexUnit>(m_value->flex.unit)); }
@@ -30,11 +26,6 @@ private:
: DimensionStyleValue(Type::Flex, data)
{
}
-
- FlexStyleValue(Flex&& flex)
- : DimensionStyleValue(Type::Flex, StyleValueFFI::rust_style_value_create_flex(flex.raw_value(), to_underlying(flex.unit())))
- {
- }
};
}
diff --git a/Libraries/LibWeb/CSS/StyleValues/FrequencyStyleValue.h b/Libraries/LibWeb/CSS/StyleValues/FrequencyStyleValue.h
index d36f281e34a..bd306566fe1 100644
--- a/Libraries/LibWeb/CSS/StyleValues/FrequencyStyleValue.h
+++ b/Libraries/LibWeb/CSS/StyleValues/FrequencyStyleValue.h
@@ -16,10 +16,6 @@ namespace Web::CSS {
class FrequencyStyleValue final : public DimensionStyleValue {
public:
- static ValueComparingNonnullRefPtr<FrequencyStyleValue const> create(Frequency frequency)
- {
- return adopt_ref(*new (nothrow) FrequencyStyleValue(move(frequency)));
- }
virtual ~FrequencyStyleValue() override = default;
Frequency frequency() const { return Frequency(m_value->frequency.value, static_cast<FrequencyUnit>(m_value->frequency.unit)); }
@@ -33,11 +29,6 @@ private:
: DimensionStyleValue(Type::Frequency, data)
{
}
-
- explicit FrequencyStyleValue(Frequency frequency)
- : DimensionStyleValue(Type::Frequency, StyleValueFFI::rust_style_value_create_frequency(frequency.raw_value(), to_underlying(frequency.unit())))
- {
- }
};
}
diff --git a/Libraries/LibWeb/CSS/StyleValues/ResolutionStyleValue.h b/Libraries/LibWeb/CSS/StyleValues/ResolutionStyleValue.h
index 925d11c3f76..6be7f000575 100644
--- a/Libraries/LibWeb/CSS/StyleValues/ResolutionStyleValue.h
+++ b/Libraries/LibWeb/CSS/StyleValues/ResolutionStyleValue.h
@@ -13,10 +13,6 @@ namespace Web::CSS {
class ResolutionStyleValue : public DimensionStyleValue {
public:
- static ValueComparingNonnullRefPtr<ResolutionStyleValue const> create(Resolution resolution)
- {
- return adopt_ref(*new (nothrow) ResolutionStyleValue(move(resolution)));
- }
virtual ~ResolutionStyleValue() override = default;
Resolution resolution() const { return Resolution(m_value->resolution.value, static_cast<ResolutionUnit>(m_value->resolution.unit)); }
@@ -30,11 +26,6 @@ private:
: DimensionStyleValue(Type::Resolution, data)
{
}
-
- explicit ResolutionStyleValue(Resolution resolution)
- : DimensionStyleValue(Type::Resolution, StyleValueFFI::rust_style_value_create_resolution(resolution.raw_value(), to_underlying(resolution.unit())))
- {
- }
};
}
diff --git a/Libraries/LibWeb/CSS/StyleValues/ShadowStyleValue.h b/Libraries/LibWeb/CSS/StyleValues/ShadowStyleValue.h
index 13100b2ea25..aecbfd37410 100644
--- a/Libraries/LibWeb/CSS/StyleValues/ShadowStyleValue.h
+++ b/Libraries/LibWeb/CSS/StyleValues/ShadowStyleValue.h
@@ -27,17 +27,6 @@ public:
Text
};
- static ValueComparingNonnullRefPtr<ShadowStyleValue const> create(
- ShadowType shadow_type,
- ValueComparingRefPtr<StyleValue const> color,
- ValueComparingNonnullRefPtr<StyleValue const> offset_x,
- ValueComparingNonnullRefPtr<StyleValue const> offset_y,
- ValueComparingRefPtr<StyleValue const> blur_radius,
- ValueComparingRefPtr<StyleValue const> spread_distance,
- ShadowPlacement placement)
- {
- return adopt_ref(*new (nothrow) ShadowStyleValue(shadow_type, move(color), move(offset_x), move(offset_y), move(blur_radius), move(spread_distance), placement));
- }
virtual ~ShadowStyleValue() override = default;
ValueComparingRefPtr<StyleValue const> color_or_null() const { return wrap_rust_child_or_null(m_value->shadow._0->color); }
@@ -47,31 +36,11 @@ public:
ValueComparingRefPtr<StyleValue const> spread_distance_or_null() const { return wrap_rust_child_or_null(m_value->shadow._0->spread_distance); }
private:
- ShadowStyleValue(
- ShadowType shadow_type,
- ValueComparingRefPtr<StyleValue const> color,
- ValueComparingNonnullRefPtr<StyleValue const> offset_x,
- ValueComparingNonnullRefPtr<StyleValue const> offset_y,
- ValueComparingRefPtr<StyleValue const> blur_radius,
- ValueComparingRefPtr<StyleValue const> spread_distance,
- ShadowPlacement placement)
- : StyleValueWithDefaultOperators(Type::Shadow, make_shadow_data(shadow_type, color, offset_x, offset_y, blur_radius, spread_distance, placement))
- {
- }
-
explicit ShadowStyleValue(StyleValueFFI::StyleValueData const* data)
: StyleValueWithDefaultOperators(Type::Shadow, data)
{
}
- static StyleValueFFI::StyleValueData const* make_shadow_data(ShadowType shadow_type, ValueComparingRefPtr<StyleValue const> const& color, ValueComparingNonnullRefPtr<StyleValue const> const& offset_x, ValueComparingNonnullRefPtr<StyleValue const> const& offset_y, ValueComparingRefPtr<StyleValue const> const& blur_radius, ValueComparingRefPtr<StyleValue const> const& spread_distance, ShadowPlacement placement)
- {
- auto retain = [](StyleValue const* value) {
- return value ? StyleValueFFI::rust_style_value_retain(value->rust_style_value_data()) : nullptr;
- };
- return StyleValueFFI::rust_style_value_create_shadow(to_underlying(shadow_type), retain(color.ptr()), retain(offset_x.ptr()), retain(offset_y.ptr()), retain(blur_radius.ptr()), retain(spread_distance.ptr()), to_underlying(placement));
- }
-
// NB: StyleValue dispatches operations by type tag, so it may call private impls.
friend class StyleValue;
};
diff --git a/Libraries/LibWeb/CSS/StyleValues/TimeStyleValue.h b/Libraries/LibWeb/CSS/StyleValues/TimeStyleValue.h
index bea06dea51c..fb4e509aaa7 100644
--- a/Libraries/LibWeb/CSS/StyleValues/TimeStyleValue.h
+++ b/Libraries/LibWeb/CSS/StyleValues/TimeStyleValue.h
@@ -16,10 +16,6 @@ namespace Web::CSS {
class TimeStyleValue : public DimensionStyleValue {
public:
- static ValueComparingNonnullRefPtr<TimeStyleValue const> create(Time time)
- {
- return adopt_ref(*new (nothrow) TimeStyleValue(move(time)));
- }
virtual ~TimeStyleValue() override = default;
Time time() const { return Time(m_value->time.value, static_cast<TimeUnit>(m_value->time.unit)); }
@@ -33,11 +29,6 @@ private:
: DimensionStyleValue(Type::Time, data)
{
}
-
- explicit TimeStyleValue(Time time)
- : DimensionStyleValue(Type::Time, StyleValueFFI::rust_style_value_create_time(time.raw_value(), to_underlying(time.unit())))
- {
- }
};
}
diff --git a/Libraries/LibWeb/Rust/build.rs b/Libraries/LibWeb/Rust/build.rs
index 49bf9e13ca8..01d85a1a84e 100644
--- a/Libraries/LibWeb/Rust/build.rs
+++ b/Libraries/LibWeb/Rust/build.rs
@@ -2585,6 +2585,7 @@ fn main() -> Result<(), Box<dyn Error>> {
"FfiTransitionAction",
"FfiColorResolutionStyle",
"FfiLaneTransition",
+ "FfiCompositeOperation",
]
.map(String::from)
.to_vec();
@@ -3007,7 +3008,6 @@ fn main() -> Result<(), Box<dyn Error>> {
tree_builder_config.export.exclude = vec![
"ladybird_layout_code_point_category_facts".to_string(),
"ladybird_layout_node_shell_destroy".to_string(),
- "rust_calc_node_create_numeric_dimension".to_string(),
"rust_calc_resolve".to_string(),
];
expose_css_pixel_types_as_web_types(&mut tree_builder_config);
@@ -3042,7 +3042,6 @@ fn main() -> Result<(), Box<dyn Error>> {
let mut layout_config = base_config;
layout_config.namespaces = Some(vec!["Web".to_string(), "Layout".to_string(), "RustFFI".to_string()]);
layout_config.export.exclude = vec![
- "rust_calc_node_create_numeric_dimension".to_string(),
"rust_calc_resolve".to_string(),
"rust_calc_root_from_calculated".to_string(),
"rust_calc_external_resolutions".to_string(),
diff --git a/Libraries/LibWeb/Rust/src/css/animation.rs b/Libraries/LibWeb/Rust/src/css/animation.rs
index d8d7d7cd349..eac6287f2c1 100644
--- a/Libraries/LibWeb/Rust/src/css/animation.rs
+++ b/Libraries/LibWeb/Rust/src/css/animation.rs
@@ -129,13 +129,6 @@ const STROKE_DASHARRAY_RANGES: &[NumericRangeOverride] = &[
},
];
-#[repr(C)]
-pub struct FfiAnimationValueResult {
- pub value: *const StyleValueData,
- pub handled: bool,
-}
-
-/// The Rust-side form of `FfiAnimationValueResult`, which owns its value.
pub(crate) struct AnimationValueResult {
pub(crate) value: Option<RetainedStyleValueData>,
pub(crate) handled: bool,
@@ -146,16 +139,6 @@ impl AnimationValueResult {
pub(crate) fn into_value(self) -> Option<RetainedStyleValueData> {
self.value.filter(|_| self.handled)
}
-
- /// Transfers the value's reference to the C++ caller.
- fn into_ffi(self) -> FfiAnimationValueResult {
- FfiAnimationValueResult {
- value: self
- .value
- .map_or(std::ptr::null(), |value| StyleValueArc::into_raw(value.into_arc())),
- handled: self.handled,
- }
- }
}
/// Construct a CSS value from resolved animation easing parameters.
@@ -9387,29 +9370,6 @@ pub(crate) fn evaluate_animations(batch: ComputedAnimationBatch<'_>) -> Vec<(u32
custom_final_values.into_iter().collect()
}
-/// Attempt Rust-owned style value interpolation without consulting C++ or the DOM.
-#[unsafe(no_mangle)]
-pub extern "C" fn rust_interpolate_scalar_style_value(
- context: Option<&FfiAnimationContext>,
- property_id: u16,
- from: &StyleValueData,
- to: &StyleValueData,
- delta: f32,
-) -> FfiAnimationValueResult {
- interpolate_value(context, property_id, from, to, delta).into_ffi()
-}
-
-/// Test-only bridge for exercising Rust-owned style value composition without constructing an
-/// animation batch. Production animation evaluation uses `evaluate_animations`.
-#[unsafe(no_mangle)]
-pub extern "C" fn rust_test_composite_style_value(
- underlying: &StyleValueData,
- animated: &StyleValueData,
- operation: FfiCompositeOperation,
-) -> FfiAnimationValueResult {
- composite_scalar_value(underlying, animated, operation).into_ffi()
-}
-
#[cfg(test)]
mod tests {
use super::*;
diff --git a/Libraries/LibWeb/Rust/src/css/calc.rs b/Libraries/LibWeb/Rust/src/css/calc.rs
index a9e352bb475..ae74afa2954 100644
--- a/Libraries/LibWeb/Rust/src/css/calc.rs
+++ b/Libraries/LibWeb/Rust/src/css/calc.rs
@@ -1246,8 +1246,7 @@ fn shared(node: CalcNode) -> Arc<CalcNode> {
/// Creates a numeric leaf for a dimension: kind selects the dimension in the
/// order number, angle, flex, frequency, length, percentage, resolution, time.
-#[unsafe(no_mangle)]
-pub extern "C" fn rust_calc_node_create_numeric_dimension(kind: u8, value: f64, unit: u8) -> *const CalcNode {
+pub(crate) fn calc_node_create_numeric_dimension(kind: u8, value: f64, unit: u8) -> *const CalcNode {
let numeric = match kind {
0 => CalcNumericValue::Number {
value,
diff --git a/Libraries/LibWeb/Rust/src/css/style_value.rs b/Libraries/LibWeb/Rust/src/css/style_value.rs
index 3127ba05d87..71292f5c54f 100644
--- a/Libraries/LibWeb/Rust/src/css/style_value.rs
+++ b/Libraries/LibWeb/Rust/src/css/style_value.rs
@@ -4153,16 +4153,6 @@ pub extern "C" fn rust_style_value_create_angle(value: f64, unit: u8) -> *const
StyleValueArc::into_raw(StyleValueArc::new(StyleValueData::Angle { value, unit }))
}
-#[unsafe(no_mangle)]
-pub extern "C" fn rust_style_value_create_flex(value: f64, unit: u8) -> *const StyleValueData {
- StyleValueArc::into_raw(StyleValueArc::new(StyleValueData::Flex { value, unit }))
-}
-
-#[unsafe(no_mangle)]
-pub extern "C" fn rust_style_value_create_frequency(value: f64, unit: u8) -> *const StyleValueData {
- StyleValueArc::into_raw(StyleValueArc::new(StyleValueData::Frequency { value, unit }))
-}
-
#[unsafe(no_mangle)]
pub extern "C" fn rust_style_value_create_length(value: f64, unit: u8) -> *const StyleValueData {
StyleValueArc::into_raw(shared_style_value(StyleValueData::Length { value, unit }))
@@ -4173,16 +4163,6 @@ pub extern "C" fn rust_style_value_create_percentage(value: f64) -> *const Style
StyleValueArc::into_raw(shared_style_value(StyleValueData::Percentage { value }))
}
-#[unsafe(no_mangle)]
-pub extern "C" fn rust_style_value_create_resolution(value: f64, unit: u8) -> *const StyleValueData {
- StyleValueArc::into_raw(StyleValueArc::new(StyleValueData::Resolution { value, unit }))
-}
-
-#[unsafe(no_mangle)]
-pub extern "C" fn rust_style_value_create_time(value: f64, unit: u8) -> *const StyleValueData {
- StyleValueArc::into_raw(StyleValueArc::new(StyleValueData::Time { value, unit }))
-}
-
/// Takes ownership of one strong reference to each of the numerator and denominator.
#[unsafe(no_mangle)]
pub extern "C" fn rust_style_value_create_ratio(
@@ -4237,31 +4217,6 @@ pub extern "C" fn rust_style_value_create_guaranteed_invalid() -> *const StyleVa
StyleValueArc::into_raw(StyleValueArc::new(StyleValueData::GuaranteedInvalid))
}
-/// Takes ownership of one strong reference to the filter's value.
-#[unsafe(no_mangle)]
-pub extern "C" fn rust_style_value_create_filter(
- kind: u8,
- color_operation: u8,
- value: OwnedStyleValue,
-) -> *const StyleValueData {
- StyleValueArc::into_raw(StyleValueArc::new(StyleValueData::Filter {
- kind,
- color_operation,
- value: RetainedStyleValueData::from_arc(value.into_arc()),
- }))
-}
-
-/// Takes ownership of one leaked reference to the string.
-///
-/// # Safety
-/// `custom_ident` must be zero or one leaked AK::Utf16FlyString reference.
-#[unsafe(no_mangle)]
-pub unsafe extern "C" fn rust_style_value_create_custom_ident(custom_ident: usize) -> *const StyleValueData {
- StyleValueArc::into_raw(StyleValueArc::new(StyleValueData::CustomIdent {
- custom_ident: unsafe { CssString::from_leaked_raw(custom_ident) },
- }))
-}
-
/// Takes ownership of one leaked reference to the name and one strong reference to the value data.
#[unsafe(no_mangle)]
pub unsafe extern "C" fn rust_style_value_create_function(
@@ -4288,30 +4243,6 @@ pub extern "C" fn rust_style_value_create_font_style(
}))
}
-/// Takes ownership of one strong reference to each non-null style value.
-#[unsafe(no_mangle)]
-pub extern "C" fn rust_style_value_create_shadow(
- shadow_type: u8,
- color: OwnedStyleValue,
- offset_x: OwnedStyleValue,
- offset_y: OwnedStyleValue,
- blur_radius: OwnedStyleValue,
- spread_distance: OwnedStyleValue,
- placement: u8,
-) -> *const StyleValueData {
- StyleValueArc::into_raw(StyleValueArc::new(StyleValueData::Shadow(StyleValueBox::new(
- ShadowPayload {
- shadow_type,
- color: RetainedStyleValueData::from_optional_arc(color.into_option()),
- offset_x: RetainedStyleValueData::from_arc(offset_x.into_arc()),
- offset_y: RetainedStyleValueData::from_arc(offset_y.into_arc()),
- blur_radius: RetainedStyleValueData::from_optional_arc(blur_radius.into_option()),
- spread_distance: RetainedStyleValueData::from_optional_arc(spread_distance.into_option()),
- placement,
- },
- ))))
-}
-
/// Takes ownership of one strong reference to each of the `length` values.
#[unsafe(no_mangle)]
pub unsafe extern "C" fn rust_style_value_create_value_list(
diff --git a/Libraries/LibWeb/Rust/src/layout/style_values.rs b/Libraries/LibWeb/Rust/src/layout/style_values.rs
index fe13135c866..6dee978ba9f 100644
--- a/Libraries/LibWeb/Rust/src/layout/style_values.rs
+++ b/Libraries/LibWeb/Rust/src/layout/style_values.rs
@@ -699,7 +699,7 @@ fn unresolvable_anchor_size_or<'a>(size: &'a ComputedSize, initial: &'static Com
/// A px calc node, holding one reference for the external-resolution snapshot that releases it.
pub(crate) fn calc_node_create_px_dimension(value: f64) -> *const c_void {
- crate::css::calc::rust_calc_node_create_numeric_dimension(
+ crate::css::calc::calc_node_create_numeric_dimension(
formatting_context::CALC_NUMERIC_KIND_LENGTH,
value,
crate::css::style_compute::px_length_unit(),
diff --git a/Tests/LibWeb/CMakeLists.txt b/Tests/LibWeb/CMakeLists.txt
index bfc527bd72b..cfe1aa83221 100644
--- a/Tests/LibWeb/CMakeLists.txt
+++ b/Tests/LibWeb/CMakeLists.txt
@@ -62,7 +62,6 @@ if (NOT WIN32)
TestLengthAbsolutizeParity.cpp
TestStylePropertyMetadataParity.cpp
TestStyleStructRef.cpp
- TestStyleValueEquality.cpp
)
endif()
diff --git a/Tests/LibWeb/TestStyleValueEquality.cpp b/Tests/LibWeb/TestStyleValueEquality.cpp
deleted file mode 100644
index d71c1c5817c..00000000000
--- a/Tests/LibWeb/TestStyleValueEquality.cpp
+++ /dev/null
@@ -1,1429 +0,0 @@
-/*
- * Copyright (c) 2026-present, the Ladybird developers.
- *
- * SPDX-License-Identifier: BSD-2-Clause
- */
-
-#include <LibTest/TestCase.h>
-#include <LibWeb/CSS/PropertyID.h>
-#include <LibWeb/CSS/StyleValues/CalculatedStyleValue.h>
-#include <LibWeb/CSS/StyleValues/ColorFunctionStyleValue.h>
-#include <LibWeb/CSS/StyleValues/CounterDefinitionsStyleValue.h>
-#include <LibWeb/CSS/StyleValues/CustomIdentStyleValue.h>
-#include <LibWeb/CSS/StyleValues/DisplayStyleValue.h>
-#include <LibWeb/CSS/StyleValues/FilterStyleValue.h>
-#include <LibWeb/CSS/StyleValues/FontStyleStyleValue.h>
-#include <LibWeb/CSS/StyleValues/FunctionStyleValue.h>
-#include <LibWeb/CSS/StyleValues/IntegerStyleValue.h>
-#include <LibWeb/CSS/StyleValues/KeywordStyleValue.h>
-#include <LibWeb/CSS/StyleValues/LengthStyleValue.h>
-#include <LibWeb/CSS/StyleValues/NumberStyleValue.h>
-#include <LibWeb/CSS/StyleValues/PercentageStyleValue.h>
-#include <LibWeb/CSS/StyleValues/RatioStyleValue.h>
-#include <LibWeb/CSS/StyleValues/RustStyleValueHandle.h>
-#include <LibWeb/CSS/StyleValues/ShadowStyleValue.h>
-#include <LibWeb/CSS/StyleValues/ShorthandStyleValue.h>
-#include <LibWeb/CSS/StyleValues/StyleValueList.h>
-#include <LibWeb/CSS/StyleValues/TransformationStyleValue.h>
-#include <LibWeb/CSS/StyleValues/UnresolvedStyleValue.h>
-#include <LibWeb/ComputedValuesRustFFI.h>
-
-// These tests build separately-allocated style values with equal (or deliberately unequal)
-// contents and check that StyleValue::equals() compares by value, not by pointer identity.
-// Style value equality feeds restyle invalidation and transition change detection, so drift
-// here does not show up in rendering tests until it causes stale styles or spurious
-// transitions.
-
-namespace Web::CSS {
-
-static StyleValueFFI::StyleValueData const* create_test_image(StringView url)
-{
- auto url_string = MUST(String::from_utf8(url));
- auto url_bytes = url_string.bytes();
- return StyleValueFFI::rust_style_value_create_image(
- { url_bytes.data(), nullptr, url_bytes.size() }, 0, nullptr, 0,
- {}, false);
-}
-
-TEST_CASE(rust_serialization_transfers_a_native_utf16_string)
-{
- auto value = CustomIdentStyleValue::create(Utf16FlyString::from_utf8("hello😀"sv));
- auto text = StyleValueFFI::rust_style_value_serialize(
- value->rust_style_value_data(), to_underlying(SerializationMode::Normal));
-
- auto serialized = Utf16String::adopt_raw(text);
- EXPECT_EQ(serialized, u"hello😀"sv);
- EXPECT(!serialized.has_ascii_storage());
-
- auto ascii_value = CustomIdentStyleValue::create(Utf16FlyString::from_utf8("abc"sv));
- auto ascii_text = StyleValueFFI::rust_style_value_serialize(
- ascii_value->rust_style_value_data(), to_underlying(SerializationMode::Normal));
-
- auto ascii_serialized = Utf16String::adopt_raw(ascii_text);
- EXPECT_EQ(ascii_serialized, u"abc"sv);
- EXPECT(ascii_serialized.has_ascii_storage());
-}
-
-TEST_CASE(rust_composites_scalar_style_values)
-{
- auto underlying_number = NumberStyleValue::create(2);
- auto animated_number = NumberStyleValue::create(3);
- auto result = StyleValueFFI::rust_test_composite_style_value(
- underlying_number->rust_style_value_data(),
- animated_number->rust_style_value_data(),
- StyleValueFFI::FfiCompositeOperation::Add);
- EXPECT(result.handled);
- auto number = StyleValue::adopt_rust_style_value_data(result.value);
- EXPECT_EQ(number->as_number().number(), 5);
-
- auto underlying_length = LengthStyleValue::create(Length::make_px(10));
- auto animated_length = LengthStyleValue::create(Length::make_px(15));
- result = StyleValueFFI::rust_test_composite_style_value(
- underlying_length->rust_style_value_data(),
- animated_length->rust_style_value_data(),
- StyleValueFFI::FfiCompositeOperation::Accumulate);
- EXPECT(result.handled);
- auto length = StyleValue::adopt_rust_style_value_data(result.value);
- EXPECT_EQ(length->as_length().length().raw_value(), 25);
-
- result = StyleValueFFI::rust_test_composite_style_value(
- underlying_number->rust_style_value_data(),
- animated_number->rust_style_value_data(),
- StyleValueFFI::FfiCompositeOperation::Replace);
- EXPECT(result.handled);
- EXPECT_EQ(result.value, nullptr);
-
- auto underlying_ratio = RatioStyleValue::create(NumberStyleValue::create(4), NumberStyleValue::create(3));
- auto animated_ratio = RatioStyleValue::create(NumberStyleValue::create(16), NumberStyleValue::create(9));
- result = StyleValueFFI::rust_test_composite_style_value(
- underlying_ratio->rust_style_value_data(),
- animated_ratio->rust_style_value_data(),
- StyleValueFFI::FfiCompositeOperation::Add);
- EXPECT(result.handled);
- EXPECT_EQ(result.value, nullptr);
-}
-
-TEST_CASE(rust_unresolved_value_retains_cached_parsed_value)
-{
- RefPtr<StyleValue const> parsed_value = NumberStyleValue::create(42);
- auto unresolved_value = UnresolvedStyleValue::create_attr_tainted_with_parsed_value(
- {}, {}, UnresolvedStyleValue::SourceTextMode::Trim, parsed_value.release_nonnull());
-
- auto restored_parsed_value = unresolved_value->parsed_value();
- EXPECT(restored_parsed_value);
- EXPECT_EQ(restored_parsed_value->as_number().number(), 42);
-}
-
-TEST_CASE(rust_interpolates_and_composites_scalar_dimensions)
-{
- auto from_frequency = StyleValue::adopt_rust_style_value_data(StyleValueFFI::rust_style_value_create_frequency(100, 0));
- auto to_frequency = StyleValue::adopt_rust_style_value_data(StyleValueFFI::rust_style_value_create_frequency(200, 0));
- auto result = StyleValueFFI::rust_interpolate_scalar_style_value(
- nullptr,
- to_underlying(PropertyID::Width),
- from_frequency->rust_style_value_data(),
- to_frequency->rust_style_value_data(),
- 0.25f);
- EXPECT(result.handled);
- auto frequency = StyleValue::adopt_rust_style_value_data(result.value);
- EXPECT_EQ(frequency->rust_style_value_data()->frequency.value, 125);
-
- auto underlying_time = StyleValue::adopt_rust_style_value_data(StyleValueFFI::rust_style_value_create_time(2, 0));
- auto animated_time = StyleValue::adopt_rust_style_value_data(StyleValueFFI::rust_style_value_create_time(3, 0));
- result = StyleValueFFI::rust_test_composite_style_value(
- underlying_time->rust_style_value_data(),
- animated_time->rust_style_value_data(),
- StyleValueFFI::FfiCompositeOperation::Add);
- EXPECT(result.handled);
- auto time = StyleValue::adopt_rust_style_value_data(result.value);
- EXPECT_EQ(time->rust_style_value_data()->time.value, 5);
-}
-
-TEST_CASE(rust_interpolates_and_composites_value_lists)
-{
- auto from = StyleValueList::create({ NumberStyleValue::create(1), NumberStyleValue::create(3) }, StyleValueList::Separator::Space);
- auto to = StyleValueList::create({ NumberStyleValue::create(3), NumberStyleValue::create(7) }, StyleValueList::Separator::Space);
- auto result = StyleValueFFI::rust_interpolate_scalar_style_value(
- nullptr,
- to_underlying(PropertyID::Width),
- from->rust_style_value_data(),
- to->rust_style_value_data(),
- 0.5f);
- EXPECT(result.handled);
- auto interpolated = StyleValue::adopt_rust_style_value_data(result.value);
- EXPECT_EQ(interpolated->as_value_list().values()[0]->as_number().number(), 2);
- EXPECT_EQ(interpolated->as_value_list().values()[1]->as_number().number(), 5);
-
- result = StyleValueFFI::rust_test_composite_style_value(
- from->rust_style_value_data(),
- to->rust_style_value_data(),
- StyleValueFFI::FfiCompositeOperation::Add);
- EXPECT(result.handled);
- auto composited = StyleValue::adopt_rust_style_value_data(result.value);
- EXPECT_EQ(composited->as_value_list().values()[0]->as_number().number(), 4);
- EXPECT_EQ(composited->as_value_list().values()[1]->as_number().number(), 10);
-}
-
-TEST_CASE(rust_scalar_handles_create_typed_wrappers)
-{
- auto number = [] {
- auto original = NumberStyleValue::create(42);
- return StyleValue::adopt_rust_style_value_data(StyleValueFFI::rust_style_value_retain(original->rust_style_value_data()));
- }();
-
- EXPECT(number->is_number());
- EXPECT_EQ(number->as_number().number(), 42);
-
- EXPECT(StyleValue::adopt_rust_style_value_data(StyleValueFFI::rust_style_value_create_keyword(0))->is_keyword());
- EXPECT(StyleValue::adopt_rust_style_value_data(StyleValueFFI::rust_style_value_create_integer(1))->is_integer());
- EXPECT(StyleValue::adopt_rust_style_value_data(StyleValueFFI::rust_style_value_create_angle(1, 0))->is_angle());
- EXPECT(StyleValue::adopt_rust_style_value_data(StyleValueFFI::rust_style_value_create_flex(1, 0))->is_flex());
- EXPECT(StyleValue::adopt_rust_style_value_data(StyleValueFFI::rust_style_value_create_frequency(1, 0))->is_frequency());
- EXPECT(StyleValue::adopt_rust_style_value_data(StyleValueFFI::rust_style_value_create_length(1, 0))->is_length());
- EXPECT(StyleValue::adopt_rust_style_value_data(StyleValueFFI::rust_style_value_create_percentage(1))->is_percentage());
- EXPECT(StyleValue::adopt_rust_style_value_data(StyleValueFFI::rust_style_value_create_resolution(1, 0))->is_resolution());
- EXPECT(StyleValue::adopt_rust_style_value_data(StyleValueFFI::rust_style_value_create_time(1, 0))->is_time());
- EXPECT(StyleValue::adopt_rust_style_value_data(StyleValueFFI::rust_style_value_create_custom_ident(Utf16FlyString::from_utf8("foo"sv).to_raw_leaked()))->is_custom_ident());
- EXPECT(StyleValue::adopt_rust_style_value_data(StyleValueFFI::rust_style_value_create_counter_style(Utf16FlyString::from_utf8("decimal"sv).to_raw_leaked()))->is_counter_style());
-}
-
-TEST_CASE(rust_style_value_handles_outlive_original_shells)
-{
- auto handle = [] {
- auto original = NumberStyleValue::create(42);
- return RustStyleValueHandle { StyleValueFFI::rust_style_value_retain(original->rust_style_value_data()) };
- }();
- auto copied_handle = handle;
-
- auto wrapper = StyleValue::adopt_rust_style_value_data(StyleValueFFI::rust_style_value_retain(copied_handle.data()));
- EXPECT(wrapper->is_number());
- EXPECT_EQ(wrapper->as_number().number(), 42);
- EXPECT_EQ(handle, copied_handle);
-}
-
-TEST_CASE(rust_handles_create_every_remaining_typed_wrapper)
-{
- auto expect_type = [](StyleValueFFI::StyleValueData const* data, StyleValue::Type type) {
- EXPECT_EQ(StyleValue::adopt_rust_style_value_data(data)->type(), type);
- };
-
- expect_type(StyleValueFFI::rust_style_value_create_display(0), StyleValue::Type::Display);
- expect_type(StyleValueFFI::rust_style_value_create_guaranteed_invalid(), StyleValue::Type::GuaranteedInvalid);
- expect_type(StyleValueFFI::rust_style_value_create_shorthand(0, nullptr, 0, nullptr, 0), StyleValue::Type::Shorthand);
-}
-
-TEST_CASE(rust_transformation_handles_retain_child_data)
-{
- auto data = [] {
- auto original = TransformationStyleValue::create(
- PropertyID::Transform,
- TransformFunction::ScaleX,
- { NumberStyleValue::create(2) });
- return StyleValueFFI::rust_style_value_retain(original->rust_style_value_data());
- }();
-
- auto child = [&] {
- auto transformation = StyleValue::adopt_rust_style_value_data(data);
- EXPECT(transformation->is_transformation());
- auto values = transformation->as_transformation().values();
- EXPECT_EQ(values.size(), 1u);
- return values[0];
- }();
-
- EXPECT(child->is_number());
- EXPECT_EQ(child->as_number().number(), 2);
-}
-
-TEST_CASE(rust_value_list_handles_retain_child_data)
-{
- auto data = [] {
- auto original = StyleValueList::create(
- { NumberStyleValue::create(3) },
- StyleValueList::Separator::Space);
- return StyleValueFFI::rust_style_value_retain(original->rust_style_value_data());
- }();
-
- auto child = [&] {
- auto list = StyleValue::adopt_rust_style_value_data(data);
- EXPECT(list->is_value_list());
- auto values = list->as_value_list().values();
- EXPECT_EQ(values.size(), 1u);
- return values[0];
- }();
-
- EXPECT(child->is_number());
- EXPECT_EQ(child->as_number().number(), 3);
-}
-
-TEST_CASE(rust_shorthand_handles_retain_child_data)
-{
- auto data = [] {
- auto child = NumberStyleValue::create(4);
- Array properties { to_underlying(PropertyID::MarginTop) };
- Array values { StyleValueFFI::rust_style_value_retain(child->rust_style_value_data()) };
- return StyleValueFFI::rust_style_value_create_shorthand(
- to_underlying(PropertyID::Margin), properties.data(), properties.size(), values.data(), values.size());
- }();
-
- auto child = [&] {
- auto shorthand = StyleValue::adopt_rust_style_value_data(data);
- EXPECT(shorthand->is_shorthand());
- auto values = shorthand->as_shorthand().values();
- EXPECT_EQ(values.size(), 1u);
- return values[0];
- }();
-
- EXPECT(child->is_number());
- EXPECT_EQ(child->as_number().number(), 4);
-}
-
-TEST_CASE(rust_function_handles_retain_argument_data)
-{
- auto data = [] {
- auto value = NumberStyleValue::create(2);
- return StyleValueFFI::rust_style_value_create_function(
- Utf16FlyString::from_utf8("foo"sv).to_raw_leaked(),
- StyleValueFFI::rust_style_value_retain(value->rust_style_value_data()));
- }();
-
- auto function = StyleValue::adopt_rust_style_value_data(data);
- EXPECT(function->is_function());
- auto value = function->as_function().value();
- function = KeywordStyleValue::create(Keyword::None);
- EXPECT_EQ(value->to_string(SerializationMode::Normal), "2"sv);
-}
-
-TEST_CASE(rust_font_style_handles_retain_angle_data)
-{
- auto data = [] {
- auto angle = StyleValue::adopt_rust_style_value_data(StyleValueFFI::rust_style_value_create_angle(20, 0));
- return StyleValueFFI::rust_style_value_create_font_style(
- to_underlying(FontStyleKeyword::Oblique),
- StyleValueFFI::rust_style_value_retain(angle->rust_style_value_data()));
- }();
-
- auto font_style = StyleValue::adopt_rust_style_value_data(data);
- EXPECT(font_style->is_font_style());
- auto angle = font_style->as_font_style().angle();
- font_style = KeywordStyleValue::create(Keyword::None);
- EXPECT_EQ(angle->to_string(SerializationMode::Normal), "20deg"sv);
-}
-
-TEST_CASE(rust_shadow_handles_retain_child_data)
-{
- auto offset_x = LengthStyleValue::create(Length::make_px(1));
- auto offset_y = LengthStyleValue::create(Length::make_px(2));
- auto blur_radius = LengthStyleValue::create(Length::make_px(3));
- auto spread_distance = LengthStyleValue::create(Length::make_px(4));
- auto data = StyleValueFFI::rust_style_value_create_shadow(
- to_underlying(ShadowStyleValue::ShadowType::Normal),
- nullptr,
- StyleValueFFI::rust_style_value_retain(offset_x->rust_style_value_data()),
- StyleValueFFI::rust_style_value_retain(offset_y->rust_style_value_data()),
- StyleValueFFI::rust_style_value_retain(blur_radius->rust_style_value_data()),
- StyleValueFFI::rust_style_value_retain(spread_distance->rust_style_value_data()),
- to_underlying(ShadowPlacement::Outer));
-
- offset_x = LengthStyleValue::create(Length::make_px(5));
- offset_y = LengthStyleValue::create(Length::make_px(6));
- blur_radius = LengthStyleValue::create(Length::make_px(7));
- spread_distance = LengthStyleValue::create(Length::make_px(8));
- auto shadow = StyleValue::adopt_rust_style_value_data(data);
- EXPECT(shadow->is_shadow());
- auto retained_offset_x = shadow->as_shadow().offset_x();
- auto retained_offset_y = shadow->as_shadow().offset_y();
- auto retained_blur_radius = shadow->as_shadow().blur_radius_or_null();
- auto retained_spread_distance = shadow->as_shadow().spread_distance_or_null();
- shadow = KeywordStyleValue::create(Keyword::None);
- EXPECT_EQ(retained_offset_x->to_string(SerializationMode::Normal), "1px"sv);
- EXPECT_EQ(retained_offset_y->to_string(SerializationMode::Normal), "2px"sv);
- EXPECT_EQ(retained_blur_radius->to_string(SerializationMode::Normal), "3px"sv);
- EXPECT_EQ(retained_spread_distance->to_string(SerializationMode::Normal), "4px"sv);
-}
-
-TEST_CASE(rust_filter_handles_retain_child_data)
-{
- auto shadow = ShadowStyleValue::create(
- ShadowStyleValue::ShadowType::Text,
- nullptr,
- LengthStyleValue::create(Length::make_px(1)),
- LengthStyleValue::create(Length::make_px(2)),
- LengthStyleValue::create(Length::make_px(3)),
- nullptr,
- ShadowPlacement::Outer);
- auto data = StyleValueFFI::rust_style_value_create_filter(
- to_underlying(FilterStyleValue::Kind::DropShadow),
- 0,
- StyleValueFFI::rust_style_value_retain(shadow->rust_style_value_data()));
-
- shadow = ShadowStyleValue::create(
- ShadowStyleValue::ShadowType::Text,
- nullptr,
- LengthStyleValue::create(Length::make_px(4)),
- LengthStyleValue::create(Length::make_px(5)),
- LengthStyleValue::create(Length::make_px(6)),
- nullptr,
- ShadowPlacement::Outer);
- auto filter = StyleValue::adopt_rust_style_value_data(data);
- EXPECT(filter->is_filter());
- auto retained_shadow = static_cast<DropShadowFilterStyleValue const&>(filter->as_filter()).shadow();
- filter = KeywordStyleValue::create(Keyword::None);
- EXPECT_EQ(retained_shadow->to_string(SerializationMode::Normal), "1px 2px 3px"sv);
-}
-
-TEST_CASE(rust_calculated_handles_create_typed_wrappers)
-{
- StyleValueFFI::FfiNumericType resolved_type {};
- resolved_type.valid = true;
- resolved_type.has_exponent_bits |= 1u << to_underlying(NumericType::BaseType::Length);
- resolved_type.exponents[to_underlying(NumericType::BaseType::Length)] = 1;
- auto data = StyleValueFFI::rust_style_value_create_calculated(
- StyleValueFFI::rust_calc_node_create_numeric_dimension(4, 10, to_underlying(LengthUnit::Px)),
- resolved_type,
- false,
- false,
- 0,
- 0,
- false,
- nullptr,
- 0);
-
- auto calculated = StyleValue::adopt_rust_style_value_data(data);
- auto retained_data = StyleValueFFI::rust_style_value_retain(calculated->rust_style_value_data());
- calculated = KeywordStyleValue::create(Keyword::None);
-
- auto retained_calculated = StyleValue::adopt_rust_style_value_data(retained_data);
- EXPECT(retained_calculated->is_calculated());
- EXPECT_EQ(retained_calculated->to_string(SerializationMode::Normal), "calc(10px)"sv);
-}
-
-TEST_CASE(rust_counter_definition_handles_retain_value_data)
-{
- auto value = IntegerStyleValue::create(2);
- StyleValueFFI::FfiCounterDefinition definition {
- Utf16FlyString::from_utf8("item"sv).to_raw_leaked(),
- false,
- { StyleValueFFI::rust_style_value_retain(value->rust_style_value_data()) },
- };
- auto data = StyleValueFFI::rust_style_value_create_counter_definitions(&definition, 1);
-
- value = IntegerStyleValue::create(3);
- auto definitions = StyleValue::adopt_rust_style_value_data(data);
- EXPECT(definitions->is_counter_definitions());
- auto retained_value = definitions->as_counter_definitions().counter_definitions()[0].value;
- definitions = KeywordStyleValue::create(Keyword::None);
- EXPECT_EQ(retained_value->to_string(SerializationMode::Normal), "2"sv);
-}
-
-TEST_CASE(rust_color_function_handles_retain_channel_data)
-{
- auto channel_0 = NumberStyleValue::create(0.1);
- auto channel_1 = NumberStyleValue::create(0.2);
- auto channel_2 = NumberStyleValue::create(0.3);
- auto data = StyleValueFFI::rust_style_value_create_color_function(
- true, to_underlying(ColorStyleValue::ColorType::sRGB), to_underlying(ColorSyntax::Modern),
- StyleValueFFI::rust_style_value_retain(channel_0->rust_style_value_data()),
- StyleValueFFI::rust_style_value_retain(channel_1->rust_style_value_data()),
- StyleValueFFI::rust_style_value_retain(channel_2->rust_style_value_data()),
- nullptr, false, 0, nullptr);
-
- channel_0 = NumberStyleValue::create(0.4);
- channel_1 = NumberStyleValue::create(0.5);
- channel_2 = NumberStyleValue::create(0.6);
- auto color = StyleValue::adopt_rust_style_value_data(data);
- EXPECT(color->is_color_function());
- auto const* retained_channel_data = static_cast<StyleValueFFI::StyleValueData const*>(
- color->rust_style_value_data()->color_function._0->channel_0.pointer);
- auto retained_channel = StyleValue::adopt_rust_style_value_data(StyleValueFFI::rust_style_value_retain(retained_channel_data));
- color = KeywordStyleValue::create(Keyword::None);
- EXPECT_EQ(retained_channel->to_string(SerializationMode::Normal), "0.1"sv);
-}
-
-TEST_CASE(rust_image_handles_create_typed_wrappers)
-{
- auto image = StyleValue::adopt_rust_style_value_data(
- create_test_image("image.png"sv));
- EXPECT(image->is_image());
- EXPECT_EQ(image->to_string(SerializationMode::Normal), "url(\"image.png\")"sv);
-}
-
-TEST_CASE(rust_interpolates_font_style_values)
-{
- auto normal = StyleValue::adopt_rust_style_value_data(
- StyleValueFFI::rust_style_value_create_font_style(to_underlying(FontStyleKeyword::Normal), nullptr));
- auto oblique = StyleValue::adopt_rust_style_value_data(StyleValueFFI::rust_style_value_create_font_style(
- to_underlying(FontStyleKeyword::Oblique), StyleValueFFI::rust_style_value_create_angle(20, 0)));
- auto result = StyleValueFFI::rust_interpolate_scalar_style_value(
- nullptr,
- to_underlying(PropertyID::FontStyle),
- normal->rust_style_value_data(),
- oblique->rust_style_value_data(),
- 0.5f);
- EXPECT(result.handled);
- auto interpolated = StyleValue::adopt_rust_style_value_data(result.value);
- EXPECT_EQ(interpolated->to_string(SerializationMode::Normal), "oblique 10deg"sv);
-
- auto italic = StyleValue::adopt_rust_style_value_data(
- StyleValueFFI::rust_style_value_create_font_style(to_underlying(FontStyleKeyword::Italic), nullptr));
- result = StyleValueFFI::rust_interpolate_scalar_style_value(
- nullptr,
- to_underlying(PropertyID::FontStyle),
- italic->rust_style_value_data(),
- oblique->rust_style_value_data(),
- 0.25f);
- EXPECT(result.handled);
- EXPECT_EQ(result.value, nullptr);
-
- StyleValueFFI::FfiAnimationContext context {
- .allow_discrete = true,
- .allow_keyword_size_interpolation = false,
- .current_color = nullptr,
- .has_length_resolution_context = false,
- .length_resolution_context = {},
- .has_transform_reference_box = false,
- .transform_reference_box_width = 0,
- .transform_reference_box_height = 0,
- };
- result = StyleValueFFI::rust_interpolate_scalar_style_value(
- &context,
- to_underlying(PropertyID::FontStyle),
- italic->rust_style_value_data(),
- oblique->rust_style_value_data(),
- 0.25f);
- EXPECT(result.handled);
- interpolated = StyleValue::adopt_rust_style_value_data(result.value);
- EXPECT_EQ(interpolated->to_string(SerializationMode::Normal), "italic"sv);
-}
-
-TEST_CASE(rust_interpolates_visibility_values)
-{
- auto visible = KeywordStyleValue::create(Keyword::Visible);
- auto hidden = KeywordStyleValue::create(Keyword::Hidden);
- auto collapse = KeywordStyleValue::create(Keyword::Collapse);
- StyleValueFFI::FfiAnimationContext context {
- .allow_discrete = false,
- .allow_keyword_size_interpolation = false,
- .current_color = nullptr,
- .has_length_resolution_context = false,
- .length_resolution_context = {},
- .has_transform_reference_box = false,
- .transform_reference_box_width = 0,
- .transform_reference_box_height = 0,
- };
-
- auto result = StyleValueFFI::rust_interpolate_scalar_style_value(
- &context,
- to_underlying(PropertyID::Visibility),
- visible->rust_style_value_data(),
- hidden->rust_style_value_data(),
- 0.5f);
- EXPECT(result.handled);
- auto value = StyleValue::adopt_rust_style_value_data(result.value);
- EXPECT_EQ(value->to_keyword(), Keyword::Visible);
-
- result = StyleValueFFI::rust_interpolate_scalar_style_value(
- &context,
- to_underlying(PropertyID::Visibility),
- hidden->rust_style_value_data(),
- collapse->rust_style_value_data(),
- 0.75f);
- EXPECT(result.handled);
- EXPECT_EQ(result.value, nullptr);
-
- context.allow_discrete = true;
- result = StyleValueFFI::rust_interpolate_scalar_style_value(
- &context,
- to_underlying(PropertyID::Visibility),
- hidden->rust_style_value_data(),
- collapse->rust_style_value_data(),
- 0.75f);
- EXPECT(result.handled);
- value = StyleValue::adopt_rust_style_value_data(result.value);
- EXPECT_EQ(value->to_keyword(), Keyword::Collapse);
-}
-
-TEST_CASE(rust_interpolates_content_visibility_values)
-{
- auto visible = KeywordStyleValue::create(Keyword::Visible);
- auto hidden = KeywordStyleValue::create(Keyword::Hidden);
- auto auto_value = KeywordStyleValue::create(Keyword::Auto);
- StyleValueFFI::FfiAnimationContext context {
- .allow_discrete = false,
- .allow_keyword_size_interpolation = false,
- .current_color = nullptr,
- .has_length_resolution_context = false,
- .length_resolution_context = {},
- .has_transform_reference_box = false,
- .transform_reference_box_width = 0,
- .transform_reference_box_height = 0,
- };
-
- auto result = StyleValueFFI::rust_interpolate_scalar_style_value(
- &context,
- to_underlying(PropertyID::ContentVisibility),
- hidden->rust_style_value_data(),
- visible->rust_style_value_data(),
- 0.5f);
- EXPECT(result.handled);
- EXPECT_EQ(result.value, nullptr);
-
- context.allow_discrete = true;
- result = StyleValueFFI::rust_interpolate_scalar_style_value(
- &context,
- to_underlying(PropertyID::ContentVisibility),
- hidden->rust_style_value_data(),
- visible->rust_style_value_data(),
- 0.5f);
- EXPECT(result.handled);
- auto value = StyleValue::adopt_rust_style_value_data(result.value);
- EXPECT_EQ(value->to_keyword(), Keyword::Visible);
-
- result = StyleValueFFI::rust_interpolate_scalar_style_value(
- &context,
- to_underlying(PropertyID::ContentVisibility),
- visible->rust_style_value_data(),
- auto_value->rust_style_value_data(),
- 0.25f);
- EXPECT(result.handled);
- value = StyleValue::adopt_rust_style_value_data(result.value);
- EXPECT_EQ(value->to_keyword(), Keyword::Visible);
-}
-
-TEST_CASE(rust_interpolates_display_values)
-{
- Display const none_display { DisplayBox::None };
- Display const block_display { DisplayOutside::Block, DisplayInside::Flow };
- Display const inline_display { DisplayOutside::Inline, DisplayInside::Flow };
- auto none = DisplayStyleValue::create(none_display);
- auto block = DisplayStyleValue::create(block_display);
- auto inline_value = DisplayStyleValue::create(inline_display);
- StyleValueFFI::FfiAnimationContext context {
- .allow_discrete = false,
- .allow_keyword_size_interpolation = false,
- .current_color = nullptr,
- .has_length_resolution_context = false,
- .length_resolution_context = {},
- .has_transform_reference_box = false,
- .transform_reference_box_width = 0,
- .transform_reference_box_height = 0,
- };
-
- auto result = StyleValueFFI::rust_interpolate_scalar_style_value(
- &context,
- to_underlying(PropertyID::Display),
- none->rust_style_value_data(),
- block->rust_style_value_data(),
- 0.5f);
- EXPECT(result.handled);
- EXPECT_EQ(result.value, nullptr);
-
- context.allow_discrete = true;
- result = StyleValueFFI::rust_interpolate_scalar_style_value(
- &context,
- to_underlying(PropertyID::Display),
- none->rust_style_value_data(),
- block->rust_style_value_data(),
- 0.5f);
- EXPECT(result.handled);
- auto value = StyleValue::adopt_rust_style_value_data(result.value);
- EXPECT_EQ(value->as_display().display(), block_display);
-
- result = StyleValueFFI::rust_interpolate_scalar_style_value(
- &context,
- to_underlying(PropertyID::Display),
- block->rust_style_value_data(),
- inline_value->rust_style_value_data(),
- 0.75f);
- EXPECT(result.handled);
- value = StyleValue::adopt_rust_style_value_data(result.value);
- EXPECT_EQ(value->as_display().display(), inline_display);
-}
-
-TEST_CASE(cpp_function_facades_retain_argument_wrappers)
-{
- auto function = FunctionStyleValue::create(
- "foo"_utf16_fly_string,
- NumberStyleValue::create(2));
- auto value = function->value();
- function = FunctionStyleValue::create(
- "bar"_utf16_fly_string,
- NumberStyleValue::create(3));
- EXPECT_EQ(value->to_string(SerializationMode::Normal), "2"sv);
-}
-
-TEST_CASE(rust_interpolates_and_composites_function_values)
-{
- auto make_function = [](StringView name, double value) {
- return FunctionStyleValue::create(
- Utf16FlyString::from_utf8(name),
- NumberStyleValue::create(value));
- };
- auto from = make_function("foo"sv, 100);
- auto to = make_function("foo"sv, 300);
- auto result = StyleValueFFI::rust_interpolate_scalar_style_value(
- nullptr,
- to_underlying(PropertyID::FontWeight),
- from->rust_style_value_data(),
- to->rust_style_value_data(),
- 0.5f);
- EXPECT(result.handled);
- auto interpolated = StyleValue::adopt_rust_style_value_data(result.value);
- EXPECT_EQ(interpolated->to_string(SerializationMode::Normal), "foo(200)"sv);
-
- result = StyleValueFFI::rust_test_composite_style_value(
- from->rust_style_value_data(),
- to->rust_style_value_data(),
- StyleValueFFI::FfiCompositeOperation::Add);
- EXPECT(result.handled);
- auto composited = StyleValue::adopt_rust_style_value_data(result.value);
- EXPECT_EQ(composited->to_string(SerializationMode::Normal), "foo(400)"sv);
-
- auto mismatched_name = make_function("bar"sv, 300);
- result = StyleValueFFI::rust_interpolate_scalar_style_value(
- nullptr,
- to_underlying(PropertyID::FontWeight),
- from->rust_style_value_data(),
- mismatched_name->rust_style_value_data(),
- 0.5f);
- EXPECT(result.handled);
- EXPECT_EQ(result.value, nullptr);
-}
-
-TEST_CASE(rust_interpolates_matching_transform_functions)
-{
- auto make_transform = [](double degrees) {
- return StyleValueList::create(
- { TransformationStyleValue::create(
- PropertyID::Transform,
- TransformFunction::Rotate,
- { StyleValue::adopt_rust_style_value_data(StyleValueFFI::rust_style_value_create_angle(degrees, 0)) }) },
- StyleValueList::Separator::Space);
- };
- auto from = make_transform(0);
- auto to = make_transform(360);
-
- auto result = StyleValueFFI::rust_interpolate_scalar_style_value(
- nullptr,
- to_underlying(PropertyID::Transform),
- from->rust_style_value_data(),
- to->rust_style_value_data(),
- 0.25f);
- EXPECT(result.handled);
- auto interpolated = StyleValue::adopt_rust_style_value_data(result.value);
- auto transformations = interpolated->as_value_list().values();
- EXPECT_EQ(transformations.size(), 1u);
- auto arguments = transformations[0]->as_transformation().values();
- EXPECT_EQ(arguments.size(), 1u);
- EXPECT(arguments[0]->is_angle());
- EXPECT_APPROXIMATE(arguments[0]->rust_style_value_data()->angle.value, 90.0);
- EXPECT_EQ(arguments[0]->rust_style_value_data()->angle.unit, 0u);
-}
-
-TEST_CASE(rust_interpolates_perspective_transform_functions)
-{
- auto make_transform = [](double depth) {
- return StyleValueList::create(
- { TransformationStyleValue::create(
- PropertyID::Transform,
- TransformFunction::Perspective,
- { LengthStyleValue::create(Length::make_px(depth)) }) },
- StyleValueList::Separator::Space);
- };
- auto from = make_transform(400);
- auto to = make_transform(500);
-
- auto result = StyleValueFFI::rust_interpolate_scalar_style_value(
- nullptr,
- to_underlying(PropertyID::Transform),
- from->rust_style_value_data(),
- to->rust_style_value_data(),
- 0.25f);
- EXPECT(result.handled);
- auto interpolated = StyleValue::adopt_rust_style_value_data(result.value);
- auto transformations = interpolated->as_value_list().values();
- EXPECT_EQ(transformations.size(), 1u);
- auto arguments = transformations[0]->as_transformation().values();
- EXPECT_EQ(arguments.size(), 1u);
- EXPECT(arguments[0]->is_length());
- EXPECT_APPROXIMATE(arguments[0]->as_length().length().raw_value(), 421.0526315789474);
- EXPECT(arguments[0]->as_length().length().is_px());
-}
-
-TEST_CASE(rust_interpolates_rotate_3d_transform_functions)
-{
- auto make_transform = [](double x, double y, double z, double degrees) {
- return StyleValueList::create(
- { TransformationStyleValue::create(
- PropertyID::Transform,
- TransformFunction::Rotate3d,
- { NumberStyleValue::create(x),
- NumberStyleValue::create(y),
- NumberStyleValue::create(z),
- StyleValue::adopt_rust_style_value_data(StyleValueFFI::rust_style_value_create_angle(degrees, 0)) }) },
- StyleValueList::Separator::Space);
- };
- auto from = make_transform(1, 1, 0, 90);
- auto to = make_transform(0, 1, 1, 180);
-
- auto result = StyleValueFFI::rust_interpolate_scalar_style_value(
- nullptr,
- to_underlying(PropertyID::Transform),
- from->rust_style_value_data(),
- to->rust_style_value_data(),
- 0.25f);
- EXPECT(result.handled);
- auto interpolated = StyleValue::adopt_rust_style_value_data(result.value);
- auto transformations = interpolated->as_value_list().values();
- EXPECT_EQ(transformations.size(), 1u);
- auto arguments = transformations[0]->as_transformation().values();
- EXPECT_EQ(arguments.size(), 4u);
- EXPECT_APPROXIMATE(arguments[0]->as_number().number(), 0.5240828967217527);
- EXPECT_APPROXIMATE(arguments[1]->as_number().number(), 0.8042617338748014);
- EXPECT_APPROXIMATE(arguments[2]->as_number().number(), 0.28017883715304875);
- EXPECT_APPROXIMATE(arguments[3]->rust_style_value_data()->angle.value, 106.91089335915852);
-}
-
-TEST_CASE(rust_interpolates_transform_functions_with_a_common_primitive)
-{
- auto make_transform = [](TransformFunction function, double value) {
- return StyleValueList::create(
- { TransformationStyleValue::create(
- PropertyID::Transform,
- function,
- { NumberStyleValue::create(value) }) },
- StyleValueList::Separator::Space);
- };
- auto from = make_transform(TransformFunction::ScaleX, 2);
- auto to = make_transform(TransformFunction::ScaleY, 3);
-
- auto result = StyleValueFFI::rust_interpolate_scalar_style_value(
- nullptr,
- to_underlying(PropertyID::Transform),
- from->rust_style_value_data(),
- to->rust_style_value_data(),
- 0.5f);
- EXPECT(result.handled);
- auto interpolated = StyleValue::adopt_rust_style_value_data(result.value);
- auto transformations = interpolated->as_value_list().values();
- EXPECT_EQ(transformations.size(), 1u);
- EXPECT_EQ(transformations[0]->as_transformation().transform_function(), TransformFunction::Scale);
- auto arguments = transformations[0]->as_transformation().values();
- EXPECT_EQ(arguments.size(), 2u);
- EXPECT_APPROXIMATE(arguments[0]->as_number().number(), 1.5);
- EXPECT_APPROXIMATE(arguments[1]->as_number().number(), 2.0);
-}
-
-TEST_CASE(rust_extends_transform_lists_with_identity_functions)
-{
- auto from = StyleValueList::create(
- { TransformationStyleValue::create(
- PropertyID::Transform,
- TransformFunction::ScaleX,
- { NumberStyleValue::create(2) }) },
- StyleValueList::Separator::Space);
- auto to = StyleValueList::create(
- { TransformationStyleValue::create(
- PropertyID::Transform,
- TransformFunction::ScaleX,
- { NumberStyleValue::create(4) }),
- TransformationStyleValue::create(
- PropertyID::Transform,
- TransformFunction::TranslateX,
- { LengthStyleValue::create(Length::make_px(100)) }) },
- StyleValueList::Separator::Space);
-
- auto result = StyleValueFFI::rust_interpolate_scalar_style_value(
- nullptr,
- to_underlying(PropertyID::Transform),
- from->rust_style_value_data(),
- to->rust_style_value_data(),
- 0.5f);
- EXPECT(result.handled);
- auto interpolated = StyleValue::adopt_rust_style_value_data(result.value);
- auto transformations = interpolated->as_value_list().values();
- EXPECT_EQ(transformations.size(), 2u);
- EXPECT_APPROXIMATE(transformations[0]->as_transformation().values()[0]->as_number().number(), 3.0);
- EXPECT_APPROXIMATE(transformations[1]->as_transformation().values()[0]->as_length().length().raw_value(), 50.0);
-}
-
-TEST_CASE(rust_extends_transform_lists_with_identity_perspective)
-{
- auto from = StyleValueList::create(
- { TransformationStyleValue::create(
- PropertyID::Transform,
- TransformFunction::ScaleZ,
- { NumberStyleValue::create(2) }) },
- StyleValueList::Separator::Space);
- auto to = StyleValueList::create(
- { TransformationStyleValue::create(
- PropertyID::Transform,
- TransformFunction::ScaleZ,
- { NumberStyleValue::create(2) }),
- TransformationStyleValue::create(
- PropertyID::Transform,
- TransformFunction::Perspective,
- { LengthStyleValue::create(Length::make_px(500)) }) },
- StyleValueList::Separator::Space);
-
- auto result = StyleValueFFI::rust_interpolate_scalar_style_value(
- nullptr,
- to_underlying(PropertyID::Transform),
- from->rust_style_value_data(),
- to->rust_style_value_data(),
- 0.5f);
- EXPECT(result.handled);
- auto interpolated = StyleValue::adopt_rust_style_value_data(result.value);
- auto transformations = interpolated->as_value_list().values();
- EXPECT_EQ(transformations.size(), 2u);
- auto perspective = transformations[1]->as_transformation().values();
- EXPECT_EQ(perspective.size(), 1u);
- EXPECT_APPROXIMATE(perspective[0]->as_length().length().raw_value(), 1000.0);
-}
-
-TEST_CASE(rust_extends_transform_lists_with_identity_matrices)
-{
- auto none = KeywordStyleValue::create(Keyword::None);
- for (auto transform_function : { TransformFunction::Matrix, TransformFunction::Matrix3d }) {
- StyleValueVector arguments;
- auto argument_count = transform_function == TransformFunction::Matrix ? 6u : 16u;
- for (u32 index = 0; index < argument_count; ++index) {
- auto is_diagonal = transform_function == TransformFunction::Matrix
- ? index == 0 || index == 3
- : index % 5 == 0;
- arguments.append(NumberStyleValue::create(is_diagonal ? 1 : 0));
- }
- auto matrix = TransformationStyleValue::create(PropertyID::Transform, transform_function, move(arguments));
- auto to = StyleValueList::create({ matrix }, StyleValueList::Separator::Space);
- auto result = StyleValueFFI::rust_interpolate_scalar_style_value(
- nullptr,
- to_underlying(PropertyID::Transform),
- none->rust_style_value_data(),
- to->rust_style_value_data(),
- 0.5f);
- EXPECT(result.handled);
- auto interpolated = StyleValue::adopt_rust_style_value_data(result.value);
- auto transformations = interpolated->as_value_list().values();
- EXPECT_EQ(transformations.size(), 1u);
- EXPECT_EQ(transformations[0]->as_transformation().transform_function(), TransformFunction::Matrix3d);
- EXPECT_EQ(transformations[0]->as_transformation().values().size(), 16u);
- }
-}
-
-TEST_CASE(rust_expands_omitted_transform_arguments_before_interpolation)
-{
- auto from = StyleValueList::create(
- { TransformationStyleValue::create(
- PropertyID::Transform,
- TransformFunction::Translate,
- { PercentageStyleValue::create(Percentage { 50 }) }) },
- StyleValueList::Separator::Space);
- auto to = StyleValueList::create(
- { TransformationStyleValue::create(
- PropertyID::Transform,
- TransformFunction::Translate,
- { PercentageStyleValue::create(Percentage { 100 }), PercentageStyleValue::create(Percentage { 50 }) }) },
- StyleValueList::Separator::Space);
-
- auto result = StyleValueFFI::rust_interpolate_scalar_style_value(
- nullptr,
- to_underlying(PropertyID::Transform),
- from->rust_style_value_data(),
- to->rust_style_value_data(),
- 0.5f);
- EXPECT(result.handled);
- auto interpolated = StyleValue::adopt_rust_style_value_data(result.value);
- auto arguments = interpolated->as_value_list().values()[0]->as_transformation().values();
- EXPECT_EQ(arguments.size(), 2u);
- EXPECT_APPROXIMATE(arguments[0]->as_percentage().raw_value(), 75.0);
- EXPECT_APPROXIMATE(arguments[1]->as_percentage().raw_value(), 25.0);
-}
-
-TEST_CASE(rust_interpolates_mixed_length_percentage_transform_arguments)
-{
- auto make_transform = [](NonnullRefPtr<StyleValue const> x, NonnullRefPtr<StyleValue const> y) {
- return StyleValueList::create(
- { TransformationStyleValue::create(
- PropertyID::Transform,
- TransformFunction::Translate,
- { move(x), move(y) }) },
- StyleValueList::Separator::Space);
- };
- auto from = make_transform(
- LengthStyleValue::create(Length::make_px(480)),
- PercentageStyleValue::create(Percentage { 80 }));
- auto to = make_transform(
- PercentageStyleValue::create(Percentage { 240 }),
- LengthStyleValue::create(Length::make_px(400)));
-
- auto result = StyleValueFFI::rust_interpolate_scalar_style_value(
- nullptr,
- to_underlying(PropertyID::Transform),
- from->rust_style_value_data(),
- to->rust_style_value_data(),
- 0.125f);
- EXPECT(result.handled);
- auto interpolated = StyleValue::adopt_rust_style_value_data(result.value);
- EXPECT_EQ(interpolated->to_string(SerializationMode::Normal), "translate(calc(30% + 420px), calc(70% + 50px))"sv);
-}
-
-TEST_CASE(rust_interpolates_stroke_dasharray_values)
-{
- auto make_dasharray = [](std::initializer_list<double> lengths) {
- StyleValueVector values;
- for (auto length : lengths)
- values.append(LengthStyleValue::create(Length::make_px(length)));
- return StyleValueList::create(move(values), StyleValueList::Separator::Space);
- };
- auto from = make_dasharray({ 20, 40, 10 });
- auto to = make_dasharray({ 40, 20 });
-
- auto result = StyleValueFFI::rust_interpolate_scalar_style_value(
- nullptr,
- to_underlying(PropertyID::StrokeDasharray),
- from->rust_style_value_data(),
- to->rust_style_value_data(),
- 0.5f);
- EXPECT(result.handled);
- auto interpolated = StyleValue::adopt_rust_style_value_data(result.value);
- EXPECT_EQ(interpolated->to_string(SerializationMode::Normal), "30px 30px 25px 20px 40px 15px"sv);
-
- auto none = KeywordStyleValue::create(Keyword::None);
- StyleValueFFI::FfiAnimationContext context {
- .allow_discrete = true,
- .allow_keyword_size_interpolation = false,
- .current_color = nullptr,
- .has_length_resolution_context = false,
- .length_resolution_context = {},
- .has_transform_reference_box = false,
- .transform_reference_box_width = 0,
- .transform_reference_box_height = 0,
- };
- result = StyleValueFFI::rust_interpolate_scalar_style_value(
- &context,
- to_underlying(PropertyID::StrokeDasharray),
- none->rust_style_value_data(),
- to->rust_style_value_data(),
- 0.75f);
- EXPECT(result.handled);
- interpolated = StyleValue::adopt_rust_style_value_data(result.value);
- EXPECT_EQ(interpolated->to_string(SerializationMode::Normal), "40px 20px"sv);
-}
-
-TEST_CASE(rust_interpolates_ratio_values)
-{
- auto make_ratio = [](double numerator, double denominator) {
- return RatioStyleValue::create(NumberStyleValue::create(numerator), NumberStyleValue::create(denominator));
- };
- auto from = make_ratio(1, 2);
- auto to = make_ratio(2, 1);
-
- auto result = StyleValueFFI::rust_interpolate_scalar_style_value(
- nullptr,
- to_underlying(PropertyID::AspectRatio),
- from->rust_style_value_data(),
- to->rust_style_value_data(),
- 0.5f);
- EXPECT(result.handled);
- auto interpolated = StyleValue::adopt_rust_style_value_data(result.value);
- EXPECT_EQ(interpolated->to_string(SerializationMode::Normal), "1 / 1"sv);
-
- auto from_auto = StyleValueList::create(
- { KeywordStyleValue::create(Keyword::Auto), from },
- StyleValueList::Separator::Space);
- auto to_auto = StyleValueList::create(
- { KeywordStyleValue::create(Keyword::Auto), to },
- StyleValueList::Separator::Space);
- result = StyleValueFFI::rust_interpolate_scalar_style_value(
- nullptr,
- to_underlying(PropertyID::AspectRatio),
- from_auto->rust_style_value_data(),
- to_auto->rust_style_value_data(),
- 0.5f);
- EXPECT(result.handled);
- interpolated = StyleValue::adopt_rust_style_value_data(result.value);
- EXPECT_EQ(interpolated->to_string(SerializationMode::Normal), "auto 1 / 1"sv);
-
- auto degenerate = make_ratio(1, 0);
- result = StyleValueFFI::rust_interpolate_scalar_style_value(
- nullptr,
- to_underlying(PropertyID::AspectRatio),
- degenerate->rust_style_value_data(),
- to->rust_style_value_data(),
- 0.5f);
- EXPECT(result.handled);
- EXPECT_EQ(result.value, nullptr);
-}
-
-TEST_CASE(rust_interpolates_individual_scale_values)
-{
- auto none = KeywordStyleValue::create(Keyword::None);
- auto scale = TransformationStyleValue::create(
- PropertyID::Scale,
- TransformFunction::Scale3d,
- { NumberStyleValue::create(2), NumberStyleValue::create(0), NumberStyleValue::create(3) });
-
- auto result = StyleValueFFI::rust_interpolate_scalar_style_value(
- nullptr,
- to_underlying(PropertyID::Scale),
- none->rust_style_value_data(),
- scale->rust_style_value_data(),
- 0.5f);
- EXPECT(result.handled);
- auto interpolated = StyleValue::adopt_rust_style_value_data(result.value);
- EXPECT_EQ(interpolated->as_transformation().transform_function(), TransformFunction::Scale3d);
- auto arguments = interpolated->as_transformation().values();
- EXPECT_EQ(arguments.size(), 3u);
- EXPECT_APPROXIMATE(arguments[0]->as_number().number(), 1.5);
- EXPECT_APPROXIMATE(arguments[1]->as_number().number(), 0.5);
- EXPECT_APPROXIMATE(arguments[2]->as_number().number(), 2.0);
-}
-
-TEST_CASE(rust_interpolates_individual_translate_values)
-{
- auto from = TransformationStyleValue::create(
- PropertyID::Translate,
- TransformFunction::Translate3d,
- { LengthStyleValue::create(Length::make_px(480)), LengthStyleValue::create(Length::make_px(400)), LengthStyleValue::create(Length::make_px(320)) });
- auto to = TransformationStyleValue::create(
- PropertyID::Translate,
- TransformFunction::Translate,
- { PercentageStyleValue::create(Percentage { 240 }), PercentageStyleValue::create(Percentage { 160 }) });
-
- auto result = StyleValueFFI::rust_interpolate_scalar_style_value(
- nullptr,
- to_underlying(PropertyID::Translate),
- from->rust_style_value_data(),
- to->rust_style_value_data(),
- 0.125f);
- EXPECT(result.handled);
- auto interpolated = StyleValue::adopt_rust_style_value_data(result.value);
- EXPECT_EQ(interpolated->to_string(SerializationMode::Normal), "calc(30% + 420px) calc(20% + 350px) 280px"sv);
-
- auto zero = TransformationStyleValue::create(
- PropertyID::Translate,
- TransformFunction::Translate,
- { LengthStyleValue::create(Length::make_px(0)), LengthStyleValue::create(Length::make_px(0)) });
- auto three_dimensions = TransformationStyleValue::create(
- PropertyID::Translate,
- TransformFunction::Translate3d,
- { LengthStyleValue::create(Length::make_px(-100)), LengthStyleValue::create(Length::make_px(-50)), LengthStyleValue::create(Length::make_px(100)) });
- result = StyleValueFFI::rust_interpolate_scalar_style_value(
- nullptr,
- to_underlying(PropertyID::Translate),
- zero->rust_style_value_data(),
- three_dimensions->rust_style_value_data(),
- 0.25f);
- EXPECT(result.handled);
- interpolated = StyleValue::adopt_rust_style_value_data(result.value);
- EXPECT_EQ(interpolated->to_string(SerializationMode::Normal), "-25px -12.5px 25px"sv);
-}
-
-TEST_CASE(rust_interpolates_individual_rotate_values)
-{
- auto none = KeywordStyleValue::create(Keyword::None);
- auto angle = StyleValue::adopt_rust_style_value_data(StyleValueFFI::rust_style_value_create_angle(90, 0));
- auto rotate = TransformationStyleValue::create(
- PropertyID::Rotate,
- TransformFunction::Rotate3d,
- { NumberStyleValue::create(0), NumberStyleValue::create(1), NumberStyleValue::create(0), angle });
-
- auto result = StyleValueFFI::rust_interpolate_scalar_style_value(
- nullptr,
- to_underlying(PropertyID::Rotate),
- none->rust_style_value_data(),
- rotate->rust_style_value_data(),
- 0.5f);
- EXPECT(result.handled);
- auto interpolated = StyleValue::adopt_rust_style_value_data(result.value);
- EXPECT_EQ(interpolated->as_transformation().transform_function(), TransformFunction::Rotate3d);
- auto arguments = interpolated->as_transformation().values();
- EXPECT_EQ(arguments.size(), 4u);
- EXPECT_APPROXIMATE(arguments[0]->as_number().number(), 0.0);
- EXPECT_APPROXIMATE(arguments[1]->as_number().number(), 1.0);
- EXPECT_APPROXIMATE(arguments[2]->as_number().number(), 0.0);
- EXPECT_APPROXIMATE(arguments[3]->rust_style_value_data()->angle.value, 45.0);
-}
-
-TEST_CASE(rust_treats_transform_none_as_an_empty_list)
-{
- auto from = KeywordStyleValue::create(Keyword::None);
- auto to = StyleValueList::create(
- { TransformationStyleValue::create(
- PropertyID::Transform,
- TransformFunction::Rotate,
- { StyleValue::adopt_rust_style_value_data(StyleValueFFI::rust_style_value_create_angle(90, 0)) }) },
- StyleValueList::Separator::Space);
-
- auto result = StyleValueFFI::rust_interpolate_scalar_style_value(
- nullptr,
- to_underlying(PropertyID::Transform),
- from->rust_style_value_data(),
- to->rust_style_value_data(),
- 0.5f);
- EXPECT(result.handled);
- auto interpolated = StyleValue::adopt_rust_style_value_data(result.value);
- auto transformations = interpolated->as_value_list().values();
- EXPECT_EQ(transformations.size(), 1u);
- auto arguments = transformations[0]->as_transformation().values();
- EXPECT_EQ(arguments.size(), 1u);
- EXPECT_APPROXIMATE(arguments[0]->rust_style_value_data()->angle.value, 45.0);
-}
-
-TEST_CASE(rust_interpolates_terminal_matrix_transform_functions)
-{
- auto make_transform = [](double scale_x, double scale_y, double translate_x, double translate_y) {
- return StyleValueList::create(
- { TransformationStyleValue::create(
- PropertyID::Transform,
- TransformFunction::Matrix,
- { NumberStyleValue::create(scale_x),
- NumberStyleValue::create(0),
- NumberStyleValue::create(0),
- NumberStyleValue::create(scale_y),
- NumberStyleValue::create(translate_x),
- NumberStyleValue::create(translate_y) }) },
- StyleValueList::Separator::Space);
- };
- auto from = make_transform(2, 2, 10, 30);
- auto to = make_transform(4, 6, 14, 10);
-
- auto result = StyleValueFFI::rust_interpolate_scalar_style_value(
- nullptr,
- to_underlying(PropertyID::Transform),
- from->rust_style_value_data(),
- to->rust_style_value_data(),
- 0.5f);
- EXPECT(result.handled);
- auto interpolated = StyleValue::adopt_rust_style_value_data(result.value);
- auto transformations = interpolated->as_value_list().values();
- EXPECT_EQ(transformations.size(), 1u);
- EXPECT_EQ(transformations[0]->as_transformation().transform_function(), TransformFunction::Matrix3d);
- auto arguments = transformations[0]->as_transformation().values();
- EXPECT_EQ(arguments.size(), 16u);
- EXPECT_APPROXIMATE(arguments[0]->as_number().number(), 3.0);
- EXPECT_APPROXIMATE(arguments[5]->as_number().number(), 4.0);
- EXPECT_APPROXIMATE(arguments[12]->as_number().number(), 12.0);
- EXPECT_APPROXIMATE(arguments[13]->as_number().number(), 20.0);
-}
-
-static NonnullRefPtr<StyleValueList const> make_identity_matrix_and_translate_x(TransformFunction matrix_function, double translation)
-{
- StyleValueVector arguments;
- auto argument_count = matrix_function == TransformFunction::Matrix ? 6u : 16u;
- for (u32 index = 0; index < argument_count; ++index) {
- auto is_diagonal = matrix_function == TransformFunction::Matrix ? index == 0 || index == 3 : index % 5 == 0;
- arguments.append(NumberStyleValue::create(is_diagonal ? 1 : 0));
- }
- return StyleValueList::create(
- { TransformationStyleValue::create(PropertyID::Transform, matrix_function, move(arguments)),
- TransformationStyleValue::create(
- PropertyID::Transform,
- TransformFunction::TranslateX,
- { LengthStyleValue::create(Length::make_px(translation)) }) },
- StyleValueList::Separator::Space);
-}
-
-TEST_CASE(rust_post_multiplies_transform_matrix_suffixes)
-{
- // NB: matrix() and matrix3d() have no common name, so they and every function after them are post-multiplied.
- auto from = make_identity_matrix_and_translate_x(TransformFunction::Matrix, 100);
- auto to = make_identity_matrix_and_translate_x(TransformFunction::Matrix3d, 200);
-
- auto result = StyleValueFFI::rust_interpolate_scalar_style_value(
- nullptr,
- to_underlying(PropertyID::Transform),
- from->rust_style_value_data(),
- to->rust_style_value_data(),
- 0.5f);
- EXPECT(result.handled);
- auto interpolated = StyleValue::adopt_rust_style_value_data(result.value);
- auto transformations = interpolated->as_value_list().values();
- EXPECT_EQ(transformations.size(), 1u);
- auto arguments = transformations[0]->as_transformation().values();
- EXPECT_EQ(arguments.size(), 16u);
- EXPECT_APPROXIMATE(arguments[12]->as_number().number(), 150.0);
-}
-
-TEST_CASE(rust_interpolates_matrix_pairs_on_their_own)
-{
- auto from = make_identity_matrix_and_translate_x(TransformFunction::Matrix, 100);
- auto to = make_identity_matrix_and_translate_x(TransformFunction::Matrix, 200);
-
- auto result = StyleValueFFI::rust_interpolate_scalar_style_value(
- nullptr,
- to_underlying(PropertyID::Transform),
- from->rust_style_value_data(),
- to->rust_style_value_data(),
- 0.5f);
- EXPECT(result.handled);
- auto interpolated = StyleValue::adopt_rust_style_value_data(result.value);
- auto transformations = interpolated->as_value_list().values();
- EXPECT_EQ(transformations.size(), 2u);
- EXPECT_EQ(transformations[0]->as_transformation().transform_function(), TransformFunction::Matrix3d);
- auto matrix = transformations[0]->as_transformation().values();
- EXPECT_EQ(matrix.size(), 16u);
- for (size_t index = 0; index < matrix.size(); ++index)
- EXPECT_APPROXIMATE(matrix[index]->as_number().number(), index % 5 == 0 ? 1.0 : 0.0);
- EXPECT_EQ(transformations[1]->as_transformation().transform_function(), TransformFunction::Translate);
- auto translation = transformations[1]->as_transformation().values();
- EXPECT_EQ(translation.size(), 2u);
- EXPECT_APPROXIMATE(translation[0]->as_length().length().raw_value(), 150.0);
- EXPECT(translation[0]->as_length().length().is_px());
- EXPECT_APPROXIMATE(translation[1]->as_length().length().raw_value(), 0.0);
-}
-
-TEST_CASE(rust_interpolates_transform_functions_without_a_common_primitive)
-{
- auto from = StyleValueList::create(
- { TransformationStyleValue::create(
- PropertyID::Transform,
- TransformFunction::Rotate,
- { StyleValue::adopt_rust_style_value_data(StyleValueFFI::rust_style_value_create_angle(0, 0)) }) },
- StyleValueList::Separator::Space);
- auto to = StyleValueList::create(
- { TransformationStyleValue::create(
- PropertyID::Transform,
- TransformFunction::Scale,
- { NumberStyleValue::create(2) }) },
- StyleValueList::Separator::Space);
-
- auto result = StyleValueFFI::rust_interpolate_scalar_style_value(
- nullptr,
- to_underlying(PropertyID::Transform),
- from->rust_style_value_data(),
- to->rust_style_value_data(),
- 0.5f);
- EXPECT(result.handled);
- auto interpolated = StyleValue::adopt_rust_style_value_data(result.value);
- auto transformations = interpolated->as_value_list().values();
- EXPECT_EQ(transformations.size(), 1u);
- auto arguments = transformations[0]->as_transformation().values();
- EXPECT_EQ(arguments.size(), 16u);
- EXPECT_APPROXIMATE(arguments[0]->as_number().number(), 1.5);
- EXPECT_APPROXIMATE(arguments[5]->as_number().number(), 1.5);
-}
-
-TEST_CASE(rust_resolves_percentage_transforms_against_a_reference_box_snapshot)
-{
- auto from = StyleValueList::create(
- { TransformationStyleValue::create(
- PropertyID::Transform,
- TransformFunction::Rotate,
- { StyleValue::adopt_rust_style_value_data(StyleValueFFI::rust_style_value_create_angle(0, 0)) }) },
- StyleValueList::Separator::Space);
- auto to = StyleValueList::create(
- { TransformationStyleValue::create(
- PropertyID::Transform,
- TransformFunction::TranslateX,
- { StyleValue::adopt_rust_style_value_data(StyleValueFFI::rust_style_value_create_percentage(50)) }) },
- StyleValueList::Separator::Space);
- StyleValueFFI::FfiAnimationContext context {
- .allow_discrete = false,
- .allow_keyword_size_interpolation = false,
- .current_color = nullptr,
- .has_length_resolution_context = false,
- .length_resolution_context = {},
- .has_transform_reference_box = true,
- .transform_reference_box_width = 200,
- .transform_reference_box_height = 100,
- };
-
- auto result = StyleValueFFI::rust_interpolate_scalar_style_value(
- &context,
- to_underlying(PropertyID::Transform),
- from->rust_style_value_data(),
- to->rust_style_value_data(),
- 0.5f);
- EXPECT(result.handled);
- auto interpolated = StyleValue::adopt_rust_style_value_data(result.value);
- auto transformations = interpolated->as_value_list().values();
- EXPECT_EQ(transformations.size(), 1u);
- auto arguments = transformations[0]->as_transformation().values();
- EXPECT_EQ(arguments.size(), 16u);
- EXPECT_APPROXIMATE(arguments[12]->as_number().number(), 50.0);
-}
-
-TEST_CASE(rust_handles_non_invertible_transform_matrices_without_a_value)
-{
- auto make_transform = [](double scale) {
- return StyleValueList::create(
- { TransformationStyleValue::create(
- PropertyID::Transform,
- TransformFunction::Matrix,
- { NumberStyleValue::create(scale),
- NumberStyleValue::create(0),
- NumberStyleValue::create(0),
- NumberStyleValue::create(scale),
- NumberStyleValue::create(0),
- NumberStyleValue::create(0) }) },
- StyleValueList::Separator::Space);
- };
- auto from = make_transform(1);
- auto to = make_transform(0);
-
- auto result = StyleValueFFI::rust_interpolate_scalar_style_value(
- nullptr,
- to_underlying(PropertyID::Transform),
- from->rust_style_value_data(),
- to->rust_style_value_data(),
- 0.5f);
- EXPECT(result.handled);
- EXPECT_EQ(result.value, nullptr);
-
- StyleValueFFI::FfiAnimationContext context {
- .allow_discrete = true,
- .allow_keyword_size_interpolation = false,
- .current_color = nullptr,
- .has_length_resolution_context = false,
- .length_resolution_context = {},
- .has_transform_reference_box = false,
- .transform_reference_box_width = 0,
- .transform_reference_box_height = 0,
- };
- result = StyleValueFFI::rust_interpolate_scalar_style_value(
- &context,
- to_underlying(PropertyID::Transform),
- from->rust_style_value_data(),
- to->rust_style_value_data(),
- 0.5f);
- EXPECT(result.handled);
- auto discrete = StyleValue::adopt_rust_style_value_data(result.value);
- EXPECT(discrete->equals(*to));
-}
-
-TEST_CASE(counter_definitions_equality_is_deep)
-{
- auto make_definitions = [](i32 value) {
- Vector<CounterDefinition> definitions;
- definitions.append(CounterDefinition {
- .name = "chapter"_utf16_fly_string,
- .is_reversed = false,
- .value = IntegerStyleValue::create(value),
- });
- return CounterDefinitionsStyleValue::create(move(definitions));
- };
-
- auto first = make_definitions(1);
- auto same_as_first = make_definitions(1);
- auto different = make_definitions(2);
-
- EXPECT(first->equals(same_as_first));
- EXPECT(!first->equals(different));
-}
-
-TEST_CASE(unresolved_equality_trims_only_ascii_whitespace)
-{
- auto make_unresolved = [](Utf16String source_text) {
- return UnresolvedStyleValue::create(move(source_text), {});
- };
-
- // U+00A0 has the Unicode White_Space property but is not ASCII whitespace; values differing
- // by it must not compare equal, or custom-property change detection misses the update.
- auto plain = make_unresolved("foo"_utf16);
- auto with_leading_nbsp = make_unresolved("\u00A0foo"_utf16);
-
- EXPECT(plain->equals(*make_unresolved("foo"_utf16)));
- EXPECT(!plain->equals(*with_leading_nbsp));
-}
-
-}