Skip to content

Truly independent web browser

LibWeb: Attach CSS animations to their animation-range

Andreas Klingcaa1389c4b9b
diff --git a/Libraries/LibWeb/Animations/Animation.cpp b/Libraries/LibWeb/Animations/Animation.cpp
index d194b0035dc..b35792253d9 100644
--- a/Libraries/LibWeb/Animations/Animation.cpp
+++ b/Libraries/LibWeb/Animations/Animation.cpp
@@ -169,6 +169,7 @@ void Animation::set_timeline(GC::Ptr<AnimationTimeline> new_timeline)
// AD-HOC: The normalization of the specified timing of the associated effect depends on the associated timeline.
// This must be done before calling set_current_time_for_bindings() to ensure consistent units
+ m_normalized_attachment_interval = attachment_interval();
if (m_effect)
m_effect->normalize_specified_timing();
@@ -344,6 +345,19 @@ WebIDL::ExceptionOr<void> Animation::set_start_time_for_bindings(NullableCSSNumb
}
// https://drafts.csswg.org/web-animations-2/#auto-aligning-start-time
+// NB: The effect's timing is normalized against the attachment interval, which moves with the timeline's scroll
+// container and subject. That holds whether or not the start time is auto-aligned, e.g. for a paused animation.
+void Animation::normalize_timing_against_attachment_interval()
+{
+ auto interval = attachment_interval();
+ if (!interval.has_value() || m_normalized_attachment_interval == *interval)
+ return;
+ m_normalized_attachment_interval = *interval;
+ if (m_effect)
+ m_effect->normalize_specified_timing();
+ invalidate_effect();
+}
+
void Animation::calculate_auto_aligned_start_time()
{
VERIFY(m_timeline && m_timeline->is_progress_based());
@@ -364,15 +378,16 @@ void Animation::calculate_auto_aligned_start_time()
if (play_state() == AnimationPlayState::Paused && m_hold_time.has_value())
return;
- // 5. FIXME: Let start offset be the resolved timeline time corresponding to the start of the animation attachment
- // range. In the case of view timelines, it requires a calculation based on the proportion of the cover
- // range.
- auto start_offset = TimeValue { TimeValue::Type::Percentage, 0 };
+ normalize_timing_against_attachment_interval();
+ auto interval = attachment_interval().value();
+
+ // 5. Let start offset be the resolved timeline time corresponding to the start of the animation attachment range.
+ // In the case of view timelines, it requires a calculation based on the proportion of the cover range.
+ auto start_offset = interval.start;
- // 6. FIXME: Let end offset be the resolved timeline time corresponding to the end of the animation attachment
- // range. In the case of view timelines, it requires a calculation based on the proportion of the cover
- // range.
- auto end_offset = TimeValue { TimeValue::Type::Percentage, 100 };
+ // 6. Let end offset be the resolved timeline time corresponding to the end of the animation attachment range. In
+ // the case of view timelines, it requires a calculation based on the proportion of the cover range.
+ auto end_offset = interval.end;
// 7. Set start time to start offset if effective playback rate ≥ 0, and end offset otherwise.
if (effective_playback_rate() >= 0.0)
@@ -384,6 +399,27 @@ void Animation::calculate_auto_aligned_start_time()
m_hold_time = {};
}
+void Animation::set_range(AnimationAttachmentRange const& range)
+{
+ if (m_range == range)
+ return;
+ m_range = range;
+ if (!m_timeline || !m_timeline->is_progress_based())
+ return;
+ m_normalized_attachment_interval = attachment_interval();
+ if (m_effect)
+ m_effect->normalize_specified_timing();
+ calculate_auto_aligned_start_time();
+ invalidate_effect();
+}
+
+Optional<AttachmentInterval> Animation::attachment_interval() const
+{
+ if (!m_timeline || !m_timeline->is_progress_based())
+ return {};
+ return m_timeline->interval_for_attachment_range(m_range);
+}
+
// https://www.w3.org/TR/web-animations-1/#animation-current-time
Optional<TimeValue> Animation::current_time() const
{
@@ -1218,8 +1254,10 @@ void Animation::update()
// https://drafts.csswg.org/scroll-animations-1/#event-loop
// When updating timeline current time, the start time of any attached animation is conditionally updated. For each
// attached animation, run the procedure for calculating an auto-aligned start time.
- if (m_timeline && m_timeline->is_progress_based())
+ if (m_timeline && m_timeline->is_progress_based()) {
+ normalize_timing_against_attachment_interval();
calculate_auto_aligned_start_time();
+ }
// Prevent unnecessary work if the animation is already finished and can't exit the finished state due to timeline
// changes
diff --git a/Libraries/LibWeb/Animations/Animation.h b/Libraries/LibWeb/Animations/Animation.h
index eaa8f8da998..174a66b0fbc 100644
--- a/Libraries/LibWeb/Animations/Animation.h
+++ b/Libraries/LibWeb/Animations/Animation.h
@@ -9,6 +9,7 @@
#include <LibJS/Forward.h>
#include <LibJS/Runtime/PromiseCapability.h>
#include <LibWeb/Animations/TimeValue.h>
+#include <LibWeb/Animations/TimelineRange.h>
#include <LibWeb/Bindings/Animation.h>
#include <LibWeb/DOM/AbstractElement.h>
#include <LibWeb/DOM/EventTarget.h>
@@ -66,6 +67,13 @@ public:
virtual WebIDL::ExceptionOr<void> set_start_time_for_bindings(NullableCSSNumberish const&);
void calculate_auto_aligned_start_time();
+ void normalize_timing_against_attachment_interval();
+
+ // https://drafts.csswg.org/scroll-animations-1/#animation-attachment-range
+ AnimationAttachmentRange const& range() const { return m_range; }
+ void set_range(AnimationAttachmentRange const&);
+ // The start and the end of the attachment range on a progress-based timeline, as timeline times.
+ Optional<AttachmentInterval> attachment_interval() const;
// https://drafts.csswg.org/web-animations-2/#dom-animation-currenttime
NullableCSSNumberish current_time_for_bindings() const;
@@ -236,6 +244,11 @@ private:
bool m_auto_align_start_time { false };
+ AnimationAttachmentRange m_range;
+
+ // The attachment interval the effect's timing was last normalized against.
+ Optional<AttachmentInterval> m_normalized_attachment_interval;
+
// https://www.w3.org/TR/web-animations-1/#animation-hold-time
Optional<TimeValue> m_hold_time {};
diff --git a/Libraries/LibWeb/Animations/AnimationEffect.cpp b/Libraries/LibWeb/Animations/AnimationEffect.cpp
index 21c03cce510..294f33a68f7 100644
--- a/Libraries/LibWeb/Animations/AnimationEffect.cpp
+++ b/Libraries/LibWeb/Animations/AnimationEffect.cpp
@@ -195,9 +195,9 @@ TimeValue AnimationEffect::intrinsic_iteration_duration() const
else {
// Return(100% - start delay - end delay) / iteration count
// Note : Presently start and end delays are zero until such time as percentage based delays are supported.
- auto one_hundred_percent = TimeValue { TimeValue::Type::Percentage, 100.0 };
-
- return (one_hundred_percent - m_start_delay - m_end_delay) / m_iteration_count;
+ // AD-HOC: An effect fills its animation's attachment range rather than the whole timeline, which is what the
+ // timeline duration is here. This matches WebKit.
+ return (timeline_duration().value() - m_start_delay - m_end_delay) / m_iteration_count;
}
}
@@ -215,6 +215,12 @@ Optional<TimeValue> AnimationEffect::timeline_duration() const
if (!timeline)
return {};
+ // AD-HOC: The duration of a progress-based timeline, as an animation attached to a range of it sees it, is the
+ // length of its attachment range. This matches WebKit.
+ // An attachment range whose end comes before its start is empty.
+ if (auto interval = m_associated_animation->attachment_interval(); interval.has_value())
+ return max(interval->end - interval->start, TimeValue { TimeValue::Type::Percentage, 0 });
+
return timeline->duration();
}
diff --git a/Libraries/LibWeb/Animations/AnimationTimeline.h b/Libraries/LibWeb/Animations/AnimationTimeline.h
index 557ff381ea2..23d0e7ad20f 100644
--- a/Libraries/LibWeb/Animations/AnimationTimeline.h
+++ b/Libraries/LibWeb/Animations/AnimationTimeline.h
@@ -50,6 +50,13 @@ public:
bool is_monotonically_increasing() const { return m_is_monotonically_increasing; }
virtual bool is_progress_based() const { return false; }
+ // The timeline times of the start and the end of an attachment range on a progress-based timeline.
+ // https://drafts.csswg.org/scroll-animations-1/#animation-attachment-range
+ virtual AttachmentInterval interval_for_attachment_range(AnimationAttachmentRange const&) const
+ {
+ return { { TimeValue::Type::Percentage, 0 }, { TimeValue::Type::Percentage, 100 } };
+ }
+
// https://www.w3.org/TR/web-animations-1/#timeline-time-to-origin-relative-time
virtual Optional<double> convert_a_timeline_time_to_an_origin_relative_time(Optional<TimeValue>) { VERIFY_NOT_REACHED(); }
virtual bool can_convert_a_timeline_time_to_an_origin_relative_time() const { return false; }
diff --git a/Libraries/LibWeb/Animations/ScrollTimeline.cpp b/Libraries/LibWeb/Animations/ScrollTimeline.cpp
index df0eeae39ed..de94617e3ec 100644
--- a/Libraries/LibWeb/Animations/ScrollTimeline.cpp
+++ b/Libraries/LibWeb/Animations/ScrollTimeline.cpp
@@ -214,6 +214,20 @@ void ScrollTimeline::update_current_time(double)
set_current_time(TimeValue { TimeValue::Type::Percentage, progress * 100 });
}
+AttachmentInterval ScrollTimeline::interval_for_attachment_range(AnimationAttachmentRange const& range) const
+{
+ // NB: A scroll progress timeline has no named timeline ranges, so each edge is measured along the entire timeline,
+ // whose length is the maximum scroll offset. This matches WebKit.
+ auto max_scroll_offset = m_last_max_scroll_offset.value_or(0);
+ auto time_of = [&](TimelineRangeEdge const& edge) {
+ auto percentage = edge.offset_percentage;
+ if (max_scroll_offset != 0)
+ percentage += edge.offset_px / max_scroll_offset * 100;
+ return TimeValue { TimeValue::Type::Percentage, percentage };
+ };
+ return { time_of(range.start), time_of(range.end) };
+}
+
ScrollTimeline::ScrollTimeline(DOM::Document& document, Source source, ScrollAxis axis)
: AnimationTimeline(document)
, m_source(source)
diff --git a/Libraries/LibWeb/Animations/ScrollTimeline.h b/Libraries/LibWeb/Animations/ScrollTimeline.h
index cd6a15cea7b..c6e159ef5e5 100644
--- a/Libraries/LibWeb/Animations/ScrollTimeline.h
+++ b/Libraries/LibWeb/Animations/ScrollTimeline.h
@@ -60,6 +60,7 @@ public:
Optional<FollowedScroller> const& followed_scroller() const { return m_followed_scroller; }
virtual bool is_progress_based() const override { return true; }
+ virtual AttachmentInterval interval_for_attachment_range(AnimationAttachmentRange const&) const override;
virtual bool can_convert_a_timeline_time_to_an_origin_relative_time() const override { return false; }
private:
diff --git a/Libraries/LibWeb/Animations/TimelineRange.h b/Libraries/LibWeb/Animations/TimelineRange.h
new file mode 100644
index 00000000000..8013d99fff4
--- /dev/null
+++ b/Libraries/LibWeb/Animations/TimelineRange.h
@@ -0,0 +1,55 @@
+/*
+ * Copyright (c) 2026-present, the Ladybird developers.
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#pragma once
+
+#include <AK/Types.h>
+#include <LibWeb/Animations/TimeValue.h>
+
+namespace Web::Animations {
+
+// https://drafts.csswg.org/scroll-animations-1/#named-ranges
+enum class TimelineRangeName : u8 {
+ // NB: An edge given without a range name is measured along the entire timeline.
+ None,
+ Cover,
+ Contain,
+ Entry,
+ Exit,
+ EntryCrossing,
+ ExitCrossing,
+ Scroll,
+};
+
+// One edge of an animation attachment range: a point measured from the start of a named timeline range, as a length
+// plus a percentage of the range.
+// https://drafts.csswg.org/scroll-animations-1/#animation-range-start
+struct TimelineRangeEdge {
+ TimelineRangeName name { TimelineRangeName::None };
+ double offset_px { 0 };
+ double offset_percentage { 0 };
+
+ bool operator==(TimelineRangeEdge const&) const = default;
+};
+
+// https://drafts.csswg.org/scroll-animations-1/#animation-attachment-range
+struct AnimationAttachmentRange {
+ // NB: The initial edges, normal, are the start and the end of the entire timeline.
+ TimelineRangeEdge start { TimelineRangeName::None, 0, 0 };
+ TimelineRangeEdge end { TimelineRangeName::None, 0, 100 };
+
+ bool operator==(AnimationAttachmentRange const&) const = default;
+};
+
+// The timeline times of the start and the end of an attachment range.
+struct AttachmentInterval {
+ TimeValue start;
+ TimeValue end;
+
+ bool operator==(AttachmentInterval const&) const = default;
+};
+
+}
diff --git a/Libraries/LibWeb/CSS/CSSAnimation.cpp b/Libraries/LibWeb/CSS/CSSAnimation.cpp
index 26fb7807016..14720d0e40b 100644
--- a/Libraries/LibWeb/CSS/CSSAnimation.cpp
+++ b/Libraries/LibWeb/CSS/CSSAnimation.cpp
@@ -158,6 +158,12 @@ void CSSAnimation::apply_css_properties(AnimationProperties const& animation_pro
.timeline_kind = to_underlying(animation_properties.timeline.kind),
.scroll_scroller = to_underlying(animation_properties.timeline.scroller),
.scroll_axis = to_underlying(animation_properties.timeline.axis),
+ .range_start_name = to_underlying(animation_properties.range.start.name),
+ .range_start_px = animation_properties.range.start.offset_px,
+ .range_start_percentage = animation_properties.range.start.offset_percentage,
+ .range_end_name = to_underlying(animation_properties.range.end.name),
+ .range_end_px = animation_properties.range.end.offset_px,
+ .range_end_percentage = animation_properties.range.end.offset_percentage,
},
.keyframe_set = m_applied_keyframe_set.ptr(),
.timing_function = m_applied_timing_function_value.data(),
@@ -174,6 +180,7 @@ void CSSAnimation::apply_css_properties(AnimationProperties const& animation_pro
.delay = animation_properties.delay,
.fill_mode = animation_properties.fill_mode,
.composition = animation_properties.composition,
+ .range = animation_properties.range,
};
// NB: Style feedback can recompute an animation's owning element. Reapplying unchanged
// properties would invalidate the effect and turn that feedback into an endless cycle.
@@ -185,6 +192,7 @@ void CSSAnimation::apply_css_properties(AnimationProperties const& animation_pro
HTML::TemporaryExecutionContext context(relevant_settings_object());
set_timeline(materialize_timeline(animation_properties.timeline, timeline_target));
}
+ set_range(animation_properties.range);
effect.set_specified_iteration_duration(animation_properties.duration);
effect.set_specified_start_delay(animation_properties.delay);
diff --git a/Libraries/LibWeb/CSS/CSSAnimation.h b/Libraries/LibWeb/CSS/CSSAnimation.h
index 9e5b8be6184..a54b2a1d38c 100644
--- a/Libraries/LibWeb/CSS/CSSAnimation.h
+++ b/Libraries/LibWeb/CSS/CSSAnimation.h
@@ -65,6 +65,7 @@ private:
double delay;
AnimationFillMode fill_mode;
AnimationComposition composition;
+ Animations::AnimationAttachmentRange range;
bool operator==(AppliedCSSProperties const&) const = default;
};
diff --git a/Libraries/LibWeb/CSS/CSSAnimationProperties.h b/Libraries/LibWeb/CSS/CSSAnimationProperties.h
index 8e09458123d..da192832cc5 100644
--- a/Libraries/LibWeb/CSS/CSSAnimationProperties.h
+++ b/Libraries/LibWeb/CSS/CSSAnimationProperties.h
@@ -10,6 +10,7 @@
#include <AK/Utf16String.h>
#include <AK/Variant.h>
#include <LibGC/Ptr.h>
+#include <LibWeb/Animations/TimelineRange.h>
#include <LibWeb/CSS/ComputedValues.h>
#include <LibWeb/CSS/EasingFunction.h>
#include <LibWeb/CSS/StyleValues/RustStyleValueHandle.h>
@@ -46,6 +47,7 @@ struct AnimationProperties {
AnimationComposition composition;
Utf16FlyString name;
AnimationTimelineSource timeline;
+ Animations::AnimationAttachmentRange range;
// The computed `animation-timing-function` the easing was parsed out of, which the style engine
// compares the next computation's against.
RustStyleValueHandle timing_function_value;
diff --git a/Libraries/LibWeb/CSS/StyleComputer.cpp b/Libraries/LibWeb/CSS/StyleComputer.cpp
index 08e9e93f12e..df647049641 100644
--- a/Libraries/LibWeb/CSS/StyleComputer.cpp
+++ b/Libraries/LibWeb/CSS/StyleComputer.cpp
@@ -945,6 +945,10 @@ static AnimationProperties animation_properties_from_ffi(ComputedValuesFFI::FfiC
.scroller = static_cast<Scroller>(animation.scroll_scroller),
.axis = static_cast<Axis>(animation.scroll_axis),
},
+ .range = {
+ .start = { static_cast<Animations::TimelineRangeName>(animation.range_start_name), animation.range_start_px, animation.range_start_percentage },
+ .end = { static_cast<Animations::TimelineRangeName>(animation.range_end_name), animation.range_end_px, animation.range_end_percentage },
+ },
.timing_function_value = move(timing_function_value),
};
}
diff --git a/Libraries/LibWeb/Rust/src/css/style/animations.rs b/Libraries/LibWeb/Rust/src/css/style/animations.rs
index 3d3f0ba00a8..c3dcb176f3b 100644
--- a/Libraries/LibWeb/Rust/src/css/style/animations.rs
+++ b/Libraries/LibWeb/Rust/src/css/style/animations.rs
@@ -50,6 +50,12 @@ impl FfiAppliedAnimationDefinition {
timeline_kind: animation.timeline_kind as u8,
scroll_scroller: animation.scroll_scroller,
scroll_axis: animation.scroll_axis,
+ range_start_name: animation.range_start_name,
+ range_start_px: animation.range_start_px,
+ range_start_percentage: animation.range_start_percentage,
+ range_end_name: animation.range_end_name,
+ range_end_px: animation.range_end_px,
+ range_end_percentage: animation.range_end_percentage,
},
keyframe_set: animation.keyframe_set,
timing_function: animation.timing_function,
@@ -618,6 +624,12 @@ mod tests {
timeline_kind: 0,
scroll_scroller: 0,
scroll_axis: 0,
+ range_start_name: 0,
+ range_start_px: 0.0,
+ range_start_percentage: 0.0,
+ range_end_name: 0,
+ range_end_px: 0.0,
+ range_end_percentage: 0.0,
},
keyframe_set: std::ptr::null(),
timing_function: std::ptr::null(),
diff --git a/Libraries/LibWeb/Rust/src/css/style/bridge.rs b/Libraries/LibWeb/Rust/src/css/style/bridge.rs
index 02068a67268..014d02ea914 100644
--- a/Libraries/LibWeb/Rust/src/css/style/bridge.rs
+++ b/Libraries/LibWeb/Rust/src/css/style/bridge.rs
@@ -1194,6 +1194,12 @@ pub struct FfiAppliedAnimationValues {
pub timeline_kind: u8,
pub scroll_scroller: u8,
pub scroll_axis: u8,
+ pub range_start_name: u8,
+ pub range_start_px: f64,
+ pub range_start_percentage: f64,
+ pub range_end_name: u8,
+ pub range_end_px: f64,
+ pub range_end_percentage: f64,
}
// SAFETY: the keyframe set is only compared by address, and the timing function is immutable style
diff --git a/Libraries/LibWeb/Rust/src/css/style_compute.rs b/Libraries/LibWeb/Rust/src/css/style_compute.rs
index 82a23541f53..99fd817e8cb 100644
--- a/Libraries/LibWeb/Rust/src/css/style_compute.rs
+++ b/Libraries/LibWeb/Rust/src/css/style_compute.rs
@@ -2834,6 +2834,14 @@ pub struct FfiComputedAnimation {
pub timeline_kind: FfiAnimationTimelineKind,
pub scroll_scroller: u8,
pub scroll_axis: u8,
+ /// The edges of the animation attachment range, each a `TimelineRangeName` in the host's numbering and an offset
+ /// from the start of that range: a length plus a percentage of the range.
+ pub range_start_name: u8,
+ pub range_start_px: f64,
+ pub range_start_percentage: f64,
+ pub range_end_name: u8,
+ pub range_end_px: f64,
+ pub range_end_percentage: f64,
/// The index, in the list of CSS animations the host already holds for this element or
/// pseudo-element, of the animation this definition claims, or -1 where it asks for a new one.
pub matched_existing_index: i32,
@@ -4832,6 +4840,48 @@ fn animation_timeline_descriptor(value: &StyleValueData) -> (FfiAnimationTimelin
}
}
+/// One edge of a computed animation attachment range, as the host takes it: the `TimelineRangeName` it is measured in,
+/// and its offset from the start of that range as a length plus a percentage of the range. `normal` is the start or the
+/// end of the entire timeline.
+/// https://drafts.csswg.org/scroll-animations-1/#animation-range-start
+fn animation_range_edge(value: &StyleValueData, default_percentage: f64) -> (u8, f64, f64) {
+ let range_name = |keyword: u16| match keyword {
+ keyword::COVER => 1,
+ keyword::CONTAIN => 2,
+ keyword::ENTRY => 3,
+ keyword::EXIT => 4,
+ keyword::ENTRY_CROSSING => 5,
+ keyword::EXIT_CROSSING => 6,
+ keyword::SCROLL => 7,
+ _ => 0,
+ };
+ let offset = |value: &StyleValueData| match value {
+ StyleValueData::Percentage { value } => (0.0, *value),
+ value => {
+ let offset = crate::css::computed_value_views::LengthPercentageRef::over(value);
+ let px = offset.to_px(CssPixels::default()).to_double();
+ (px, offset.to_px(CssPixels::from_integer(100)).to_double() - px)
+ }
+ };
+ match value {
+ StyleValueData::Keyword { keyword } => (range_name(*keyword), 0.0, default_percentage),
+ StyleValueData::ValueList { values, .. } => {
+ let [name, length_percentage] = values.as_slice() else {
+ unreachable!("computed animation range edge must be a range name and an offset")
+ };
+ let StyleValueData::Keyword { keyword } = name.data() else {
+ unreachable!("computed animation range edge must start with a range name")
+ };
+ let (px, percentage) = offset(length_percentage.data());
+ (range_name(*keyword), px, percentage)
+ }
+ value => {
+ let (px, percentage) = offset(value);
+ (0, px, percentage)
+ }
+ }
+}
+
/// Which of an element's animation lists a computation belongs to, in the host's own numbering:
/// zero for the element itself, and the pseudo-element's value plus one for each pseudo-element.
fn animation_slot(pseudo_kind: u8) -> crate::css::style::animations::AnimationSlot {
@@ -4990,6 +5040,8 @@ fn build_computed_animation_list(
let fill_mode_values = computed_value_list(table, prop::ANIMATION_FILL_MODE);
let composition_values = computed_value_list(table, prop::ANIMATION_COMPOSITION);
let timeline_values = computed_value_list(table, prop::ANIMATION_TIMELINE);
+ let range_start_values = computed_value_list(table, prop::ANIMATION_RANGE_START);
+ let range_end_values = computed_value_list(table, prop::ANIMATION_RANGE_END);
// The name of each definition, for matching against the animations the host holds.
let mut definition_names = smallvec::SmallVec::<[&crate::css::css_string::CssString; 1]>::new();
@@ -5019,6 +5071,10 @@ fn build_computed_animation_list(
};
let (timeline_kind, scroll_scroller, scroll_axis) =
animation_timeline_descriptor(timeline_values[index % timeline_values.len()].data());
+ let (range_start_name, range_start_px, range_start_percentage) =
+ animation_range_edge(range_start_values[index % range_start_values.len()].data(), 0.0);
+ let (range_end_name, range_end_px, range_end_percentage) =
+ animation_range_edge(range_end_values[index % range_end_values.len()].data(), 100.0);
animations.push(FfiComputedAnimation {
duration_is_auto,
duration,
@@ -5035,6 +5091,12 @@ fn build_computed_animation_list(
timeline_kind,
scroll_scroller,
scroll_axis,
+ range_start_name,
+ range_start_px,
+ range_start_percentage,
+ range_end_name,
+ range_end_px,
+ range_end_percentage,
matched_existing_index: crate::css::style::animations::NO_MATCHED_ANIMATION,
keyframe_set: resolve_keyframes(name.units()).map_or(std::ptr::null(), |set| set as *const c_void),
});
diff --git a/Tests/LibWeb/Text/expected/wpt-import/scroll-animations/css/animation-range-scroll-timeline.txt b/Tests/LibWeb/Text/expected/wpt-import/scroll-animations/css/animation-range-scroll-timeline.txt
new file mode 100644
index 00000000000..12ad00ca1eb
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/scroll-animations/css/animation-range-scroll-timeline.txt
@@ -0,0 +1,10 @@
+Harness status: OK
+
+Found 4 tests
+
+2 Pass
+2 Fail
+Fail The animation-range-start CSS property maps to Animation's 'rangeStart' property
+Fail The animation-range-end CSS property maps to Animation's 'rangeEnd' property
+Pass The auto-aligned start time accounts for the animation-range-start property
+Pass The effect duration accounts for the animation-range-* properties
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/input/wpt-import/scroll-animations/css/animation-range-scroll-timeline.html b/Tests/LibWeb/Text/input/wpt-import/scroll-animations/css/animation-range-scroll-timeline.html
new file mode 100644
index 00000000000..ae5dc52eb9f
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/scroll-animations/css/animation-range-scroll-timeline.html
@@ -0,0 +1,62 @@
+<!DOCTYPE html>
+<html>
+<head>
+<meta charset="utf-8">
+<link rel="help" src="https://drafts.csswg.org/scroll-animations-1/#named-range-animation-declaration">
+<script src="../../resources/testharness.js"></script>
+<script src="../../resources/testharnessreport.js"></script>
+<script src="../../scroll-animations/scroll-timelines/testcommon.js"></script>
+<title>The animation-range-* CSS properties for an animation associated with a scroll timeline</title>
+</head>
+<style>
+
+ @keyframes anim {
+ from { opacity: 0 }
+ }
+
+ #scroller {
+ overflow-y: scroll;
+ width: 100px;
+ height: 100px;
+ }
+
+ #target {
+ width: 100%;
+ height: 200%;
+
+ animation: anim auto linear;
+ animation-timeline: scroll();
+ animation-range-start: 10px;
+ animation-range-end: 80px;
+ }
+</style>
+<body>
+ <div id="scroller">
+ <div id="target"></div>
+ </div>
+</body>
+<script>
+
+const animation = document.getAnimations()[0];
+
+test(t => {
+ assert_equals(animation.rangeStart.offset.value, 10);
+ assert_equals(animation.rangeStart.offset.unit, "px");
+}, "The animation-range-start CSS property maps to Animation's 'rangeStart' property");
+
+test(t => {
+ assert_equals(animation.rangeEnd.offset.value, 80);
+ assert_equals(animation.rangeEnd.offset.unit, "px");
+}, "The animation-range-end CSS property maps to Animation's 'rangeEnd' property");
+
+promise_test(async t => {
+ await animation.ready;
+ assert_percents_equal(animation.startTime, 10);
+}, "The auto-aligned start time accounts for the animation-range-start property");
+
+promise_test(async t => {
+ await animation.ready;
+ assert_percents_equal(animation.effect.getComputedTiming().duration, 70);
+}, "The effect duration accounts for the animation-range-* properties");
+
+</script>