Skip to content

Truly independent web browser

LibWeb: Snap animated border widths

Andreas Kling37ea2e090028
diff --git a/Libraries/LibWeb/Rust/src/css/animation.rs b/Libraries/LibWeb/Rust/src/css/animation.rs
index 37f81bbf61e..c654517489a 100644
--- a/Libraries/LibWeb/Rust/src/css/animation.rs
+++ b/Libraries/LibWeb/Rust/src/css/animation.rs
@@ -347,6 +347,8 @@ pub(crate) struct AnimationPreparationInputs {
pub(crate) struct ComputedAnimationBatch<'a> {
pub(crate) context: FfiAnimationContext<'a>,
+ /// The device pixel ratio that animated border widths are snapped to.
+ pub(crate) device_pixels_per_css_pixel: f64,
pub(crate) sampled_effects: &'a [FfiSampledAnimationEffect],
/// The identities of the custom-property environments of the element and of the one it
/// inherits from, which a preparation that substituted keyframe values against the element was
@@ -8584,6 +8586,41 @@ pub(crate) fn animation_preparation_matches(
.is_some_and(|preparation| preparation.key.matches(sampled, custom_property_environments))
}
+fn snap_animated_border_width(
+ property_id: u16,
+ value: RetainedStyleValueData,
+ device_pixels_per_css_pixel: f64,
+) -> RetainedStyleValueData {
+ use crate::css::property_metadata::property_id as prop;
+ // https://drafts.csswg.org/css-backgrounds/#border-width
+ // Computed value: absolute length, snapped as a border width
+ // NB: An animated value is a computed value too, so it is snapped like one.
+ if !matches!(
+ property_id,
+ prop::BORDER_BOTTOM_WIDTH
+ | prop::BORDER_LEFT_WIDTH
+ | prop::BORDER_RIGHT_WIDTH
+ | prop::BORDER_TOP_WIDTH
+ | prop::COLUMN_RULE_WIDTH
+ | prop::OUTLINE_WIDTH
+ ) || device_pixels_per_css_pixel <= 0.0
+ {
+ return value;
+ }
+ let Some(StyleValueData::Length { value: length, unit }) = value.optional_data() else {
+ return value;
+ };
+ if *unit != crate::css::style_compute::px_length_unit() || *length < 0.0 {
+ return value;
+ }
+ let snapped = crate::css::style_compute::snap_a_length_as_a_border_width(
+ device_pixels_per_css_pixel,
+ crate::css::css_pixels::CssPixels::nearest_value_for(*length),
+ )
+ .to_double();
+ retained_length(snapped, *unit)
+}
+
/// Complete the Rust-owned animation plan and compose every interval without
/// consulting C++ or the DOM. On the first sample this consumes the declarations and keyframe
/// values the batch carries. Later samples can reuse that preparation from the animated overlay.
@@ -8593,6 +8630,7 @@ pub(crate) fn evaluate_animations(batch: ComputedAnimationBatch<'_>) -> Vec<(u32
crate::css::ffi_stats::note_animation_evaluation();
let ComputedAnimationBatch {
context: sample_context,
+ device_pixels_per_css_pixel,
sampled_effects: sampled,
custom_property_environments,
cache_preparation,
@@ -8714,6 +8752,7 @@ pub(crate) fn evaluate_animations(batch: ComputedAnimationBatch<'_>) -> Vec<(u32
}
if let Some(value) = result.value {
previous_values.push((input.property_id, input.custom_name_id, value.clone()));
+ let value = snap_animated_border_width(input.property_id, value, device_pixels_per_css_pixel);
overlay.set_owned(input.property_id, value, false, input.result_of_transition);
} else {
let value = RetainedStyleValueData::from_owned(StyleValueData::Keyword {
diff --git a/Libraries/LibWeb/Rust/src/css/style_compute.rs b/Libraries/LibWeb/Rust/src/css/style_compute.rs
index e6692f233b2..b293ddddd17 100644
--- a/Libraries/LibWeb/Rust/src/css/style_compute.rs
+++ b/Libraries/LibWeb/Rust/src/css/style_compute.rs
@@ -2115,7 +2115,7 @@ fn compute_border_or_outline_width(
}
// https://drafts.csswg.org/css-backgrounds/#compute-a-border-width
-fn snap_a_length_as_a_border_width(device_pixels_per_css_pixel: f64, length: CssPixels) -> CssPixels {
+pub(crate) fn snap_a_length_as_a_border_width(device_pixels_per_css_pixel: f64, length: CssPixels) -> CssPixels {
// 1. Assert: len is non-negative.
// NB: The caller guarantees this; negative widths are invalid at parse time.
@@ -6596,6 +6596,7 @@ fn begin_animation_sample(
if anim::animation_preparation_matches(Some(mutated_overlay), &composed, input.custom_property_environments) {
anim::evaluate_animations(anim::ComputedAnimationBatch {
context: input.animation_context(None, reference_box),
+ device_pixels_per_css_pixel: input.environment.device_pixels_per_css_pixel,
sampled_effects: &composed,
custom_property_environments: input.custom_property_environments,
cache_preparation: true,
@@ -6763,6 +6764,7 @@ fn finish_animation_sample(
&& resolved.unfixed_random_sharings.is_empty();
let custom_results = anim::evaluate_animations(anim::ComputedAnimationBatch {
context: input.animation_context(Some(&length_contexts.remaining), reference_box),
+ device_pixels_per_css_pixel: input.environment.device_pixels_per_css_pixel,
sampled_effects: &composed,
custom_property_environments: input.custom_property_environments,
cache_preparation,
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-backgrounds/animations/border-width-interpolation.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-backgrounds/animations/border-width-interpolation.txt
index 312e5c89c21..874772fbfda 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/css/css-backgrounds/animations/border-width-interpolation.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-backgrounds/animations/border-width-interpolation.txt
@@ -2,8 +2,7 @@ Harness status: OK
Found 256 tests
-252 Pass
-4 Fail
+256 Pass
Pass CSS Transitions: property <border-width> from [20px 40px 60px 80px] to [30px 50px 70px 90px] at (-0.3) should be [17px 37px 57px 77px]
Pass CSS Transitions: property <border-width> from [20px 40px 60px 80px] to [30px 50px 70px 90px] at (0) should be [20px 40px 60px 80px]
Pass CSS Transitions: property <border-width> from [20px 40px 60px 80px] to [30px 50px 70px 90px] at (0.3) should be [23px 43px 63px 83px]
@@ -177,28 +176,28 @@ Pass Web Animations: property <border-bottom-width> from [thick] to [15px] at (0
Pass Web Animations: property <border-bottom-width> from [thick] to [15px] at (1) should be [15px]
Pass Web Animations: property <border-bottom-width> from [thick] to [15px] at (1.5) should be [20px]
Pass CSS Transitions: property <border-left-width> from [medium] to [13px] at (-2) should be [0px]
-Fail CSS Transitions: property <border-left-width> from [medium] to [13px] at (-0.25) should be [0.5px]
+Pass CSS Transitions: property <border-left-width> from [medium] to [13px] at (-0.25) should be [0.5px]
Pass CSS Transitions: property <border-left-width> from [medium] to [13px] at (0) should be [3px]
Pass CSS Transitions: property <border-left-width> from [medium] to [13px] at (0.3) should be [6px]
Pass CSS Transitions: property <border-left-width> from [medium] to [13px] at (0.6) should be [9px]
Pass CSS Transitions: property <border-left-width> from [medium] to [13px] at (1) should be [13px]
Pass CSS Transitions: property <border-left-width> from [medium] to [13px] at (1.5) should be [18px]
Pass CSS Transitions with transition: all: property <border-left-width> from [medium] to [13px] at (-2) should be [0px]
-Fail CSS Transitions with transition: all: property <border-left-width> from [medium] to [13px] at (-0.25) should be [0.5px]
+Pass CSS Transitions with transition: all: property <border-left-width> from [medium] to [13px] at (-0.25) should be [0.5px]
Pass CSS Transitions with transition: all: property <border-left-width> from [medium] to [13px] at (0) should be [3px]
Pass CSS Transitions with transition: all: property <border-left-width> from [medium] to [13px] at (0.3) should be [6px]
Pass CSS Transitions with transition: all: property <border-left-width> from [medium] to [13px] at (0.6) should be [9px]
Pass CSS Transitions with transition: all: property <border-left-width> from [medium] to [13px] at (1) should be [13px]
Pass CSS Transitions with transition: all: property <border-left-width> from [medium] to [13px] at (1.5) should be [18px]
Pass CSS Animations: property <border-left-width> from [medium] to [13px] at (-2) should be [0px]
-Fail CSS Animations: property <border-left-width> from [medium] to [13px] at (-0.25) should be [0.5px]
+Pass CSS Animations: property <border-left-width> from [medium] to [13px] at (-0.25) should be [0.5px]
Pass CSS Animations: property <border-left-width> from [medium] to [13px] at (0) should be [3px]
Pass CSS Animations: property <border-left-width> from [medium] to [13px] at (0.3) should be [6px]
Pass CSS Animations: property <border-left-width> from [medium] to [13px] at (0.6) should be [9px]
Pass CSS Animations: property <border-left-width> from [medium] to [13px] at (1) should be [13px]
Pass CSS Animations: property <border-left-width> from [medium] to [13px] at (1.5) should be [18px]
Pass Web Animations: property <border-left-width> from [medium] to [13px] at (-2) should be [0px]
-Fail Web Animations: property <border-left-width> from [medium] to [13px] at (-0.25) should be [0.5px]
+Pass Web Animations: property <border-left-width> from [medium] to [13px] at (-0.25) should be [0.5px]
Pass Web Animations: property <border-left-width> from [medium] to [13px] at (0) should be [3px]
Pass Web Animations: property <border-left-width> from [medium] to [13px] at (0.3) should be [6px]
Pass Web Animations: property <border-left-width> from [medium] to [13px] at (0.6) should be [9px]
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-multicol/animation/column-rule-width-interpolation.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-multicol/animation/column-rule-width-interpolation.txt
index c22941db1ab..462507db9fa 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/css/css-multicol/animation/column-rule-width-interpolation.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-multicol/animation/column-rule-width-interpolation.txt
@@ -2,8 +2,7 @@ Harness status: OK
Found 148 tests
-124 Pass
-24 Fail
+148 Pass
Pass CSS Transitions: property <column-rule-width> from neutral to [20px] at (-0.3) should be [7px]
Pass CSS Transitions: property <column-rule-width> from neutral to [20px] at (0) should be [10px]
Pass CSS Transitions: property <column-rule-width> from neutral to [20px] at (0.3) should be [13px]
@@ -30,28 +29,28 @@ Pass Web Animations: property <column-rule-width> from neutral to [20px] at (1)
Pass Web Animations: property <column-rule-width> from neutral to [20px] at (1.5) should be [25px]
Pass CSS Transitions: property <column-rule-width> from [initial] to [20px] at (-0.3) should be [0px]
Pass CSS Transitions: property <column-rule-width> from [initial] to [20px] at (0) should be [3px]
-Fail CSS Transitions: property <column-rule-width> from [initial] to [20px] at (0.3) should be [8.1px]
-Fail CSS Transitions: property <column-rule-width> from [initial] to [20px] at (0.6) should be [13.2px]
+Pass CSS Transitions: property <column-rule-width> from [initial] to [20px] at (0.3) should be [8.1px]
+Pass CSS Transitions: property <column-rule-width> from [initial] to [20px] at (0.6) should be [13.2px]
Pass CSS Transitions: property <column-rule-width> from [initial] to [20px] at (1) should be [20px]
-Fail CSS Transitions: property <column-rule-width> from [initial] to [20px] at (1.5) should be [28.5px]
+Pass CSS Transitions: property <column-rule-width> from [initial] to [20px] at (1.5) should be [28.5px]
Pass CSS Transitions with transition: all: property <column-rule-width> from [initial] to [20px] at (-0.3) should be [0px]
Pass CSS Transitions with transition: all: property <column-rule-width> from [initial] to [20px] at (0) should be [3px]
-Fail CSS Transitions with transition: all: property <column-rule-width> from [initial] to [20px] at (0.3) should be [8.1px]
-Fail CSS Transitions with transition: all: property <column-rule-width> from [initial] to [20px] at (0.6) should be [13.2px]
+Pass CSS Transitions with transition: all: property <column-rule-width> from [initial] to [20px] at (0.3) should be [8.1px]
+Pass CSS Transitions with transition: all: property <column-rule-width> from [initial] to [20px] at (0.6) should be [13.2px]
Pass CSS Transitions with transition: all: property <column-rule-width> from [initial] to [20px] at (1) should be [20px]
-Fail CSS Transitions with transition: all: property <column-rule-width> from [initial] to [20px] at (1.5) should be [28.5px]
+Pass CSS Transitions with transition: all: property <column-rule-width> from [initial] to [20px] at (1.5) should be [28.5px]
Pass CSS Animations: property <column-rule-width> from [initial] to [20px] at (-0.3) should be [0px]
Pass CSS Animations: property <column-rule-width> from [initial] to [20px] at (0) should be [3px]
-Fail CSS Animations: property <column-rule-width> from [initial] to [20px] at (0.3) should be [8.1px]
-Fail CSS Animations: property <column-rule-width> from [initial] to [20px] at (0.6) should be [13.2px]
+Pass CSS Animations: property <column-rule-width> from [initial] to [20px] at (0.3) should be [8.1px]
+Pass CSS Animations: property <column-rule-width> from [initial] to [20px] at (0.6) should be [13.2px]
Pass CSS Animations: property <column-rule-width> from [initial] to [20px] at (1) should be [20px]
-Fail CSS Animations: property <column-rule-width> from [initial] to [20px] at (1.5) should be [28.5px]
+Pass CSS Animations: property <column-rule-width> from [initial] to [20px] at (1.5) should be [28.5px]
Pass Web Animations: property <column-rule-width> from [initial] to [20px] at (-0.3) should be [0px]
Pass Web Animations: property <column-rule-width> from [initial] to [20px] at (0) should be [3px]
-Fail Web Animations: property <column-rule-width> from [initial] to [20px] at (0.3) should be [8.1px]
-Fail Web Animations: property <column-rule-width> from [initial] to [20px] at (0.6) should be [13.2px]
+Pass Web Animations: property <column-rule-width> from [initial] to [20px] at (0.3) should be [8.1px]
+Pass Web Animations: property <column-rule-width> from [initial] to [20px] at (0.6) should be [13.2px]
Pass Web Animations: property <column-rule-width> from [initial] to [20px] at (1) should be [20px]
-Fail Web Animations: property <column-rule-width> from [initial] to [20px] at (1.5) should be [28.5px]
+Pass Web Animations: property <column-rule-width> from [initial] to [20px] at (1.5) should be [28.5px]
Pass CSS Transitions: property <column-rule-width> from [inherit] to [20px] at (-0.3) should be [33px]
Pass CSS Transitions: property <column-rule-width> from [inherit] to [20px] at (0) should be [30px]
Pass CSS Transitions: property <column-rule-width> from [inherit] to [20px] at (0.3) should be [27px]
@@ -78,28 +77,28 @@ Pass Web Animations: property <column-rule-width> from [inherit] to [20px] at (1
Pass Web Animations: property <column-rule-width> from [inherit] to [20px] at (1.5) should be [15px]
Pass CSS Transitions: property <column-rule-width> from [unset] to [20px] at (-0.3) should be [0px]
Pass CSS Transitions: property <column-rule-width> from [unset] to [20px] at (0) should be [3px]
-Fail CSS Transitions: property <column-rule-width> from [unset] to [20px] at (0.3) should be [8.1px]
-Fail CSS Transitions: property <column-rule-width> from [unset] to [20px] at (0.6) should be [13.2px]
+Pass CSS Transitions: property <column-rule-width> from [unset] to [20px] at (0.3) should be [8.1px]
+Pass CSS Transitions: property <column-rule-width> from [unset] to [20px] at (0.6) should be [13.2px]
Pass CSS Transitions: property <column-rule-width> from [unset] to [20px] at (1) should be [20px]
-Fail CSS Transitions: property <column-rule-width> from [unset] to [20px] at (1.5) should be [28.5px]
+Pass CSS Transitions: property <column-rule-width> from [unset] to [20px] at (1.5) should be [28.5px]
Pass CSS Transitions with transition: all: property <column-rule-width> from [unset] to [20px] at (-0.3) should be [0px]
Pass CSS Transitions with transition: all: property <column-rule-width> from [unset] to [20px] at (0) should be [3px]
-Fail CSS Transitions with transition: all: property <column-rule-width> from [unset] to [20px] at (0.3) should be [8.1px]
-Fail CSS Transitions with transition: all: property <column-rule-width> from [unset] to [20px] at (0.6) should be [13.2px]
+Pass CSS Transitions with transition: all: property <column-rule-width> from [unset] to [20px] at (0.3) should be [8.1px]
+Pass CSS Transitions with transition: all: property <column-rule-width> from [unset] to [20px] at (0.6) should be [13.2px]
Pass CSS Transitions with transition: all: property <column-rule-width> from [unset] to [20px] at (1) should be [20px]
-Fail CSS Transitions with transition: all: property <column-rule-width> from [unset] to [20px] at (1.5) should be [28.5px]
+Pass CSS Transitions with transition: all: property <column-rule-width> from [unset] to [20px] at (1.5) should be [28.5px]
Pass CSS Animations: property <column-rule-width> from [unset] to [20px] at (-0.3) should be [0px]
Pass CSS Animations: property <column-rule-width> from [unset] to [20px] at (0) should be [3px]
-Fail CSS Animations: property <column-rule-width> from [unset] to [20px] at (0.3) should be [8.1px]
-Fail CSS Animations: property <column-rule-width> from [unset] to [20px] at (0.6) should be [13.2px]
+Pass CSS Animations: property <column-rule-width> from [unset] to [20px] at (0.3) should be [8.1px]
+Pass CSS Animations: property <column-rule-width> from [unset] to [20px] at (0.6) should be [13.2px]
Pass CSS Animations: property <column-rule-width> from [unset] to [20px] at (1) should be [20px]
-Fail CSS Animations: property <column-rule-width> from [unset] to [20px] at (1.5) should be [28.5px]
+Pass CSS Animations: property <column-rule-width> from [unset] to [20px] at (1.5) should be [28.5px]
Pass Web Animations: property <column-rule-width> from [unset] to [20px] at (-0.3) should be [0px]
Pass Web Animations: property <column-rule-width> from [unset] to [20px] at (0) should be [3px]
-Fail Web Animations: property <column-rule-width> from [unset] to [20px] at (0.3) should be [8.1px]
-Fail Web Animations: property <column-rule-width> from [unset] to [20px] at (0.6) should be [13.2px]
+Pass Web Animations: property <column-rule-width> from [unset] to [20px] at (0.3) should be [8.1px]
+Pass Web Animations: property <column-rule-width> from [unset] to [20px] at (0.6) should be [13.2px]
Pass Web Animations: property <column-rule-width> from [unset] to [20px] at (1) should be [20px]
-Fail Web Animations: property <column-rule-width> from [unset] to [20px] at (1.5) should be [28.5px]
+Pass Web Animations: property <column-rule-width> from [unset] to [20px] at (1.5) should be [28.5px]
Pass CSS Transitions: property <column-rule-width> from [0px] to [10px] at (-0.3) should be [0px]
Pass CSS Transitions: property <column-rule-width> from [0px] to [10px] at (0) should be [0px]
Pass CSS Transitions: property <column-rule-width> from [0px] to [10px] at (0.3) should be [3px]