Skip to content

Truly independent web browser

LibWeb: Resolve calculated timeline offsets against their range

Andreas Klingc577a2ef6eb0
diff --git a/Libraries/LibWeb/Animations/Animation.cpp b/Libraries/LibWeb/Animations/Animation.cpp
index 42449f010c5..0e94edca694 100644
--- a/Libraries/LibWeb/Animations/Animation.cpp
+++ b/Libraries/LibWeb/Animations/Animation.cpp
@@ -25,6 +25,7 @@
#include <LibWeb/CSS/CSSUnitValue.h>
#include <LibWeb/CSS/Length.h>
#include <LibWeb/CSS/Parser/Parser.h>
+#include <LibWeb/CSS/StyleValues/CalculatedStyleValue.h>
#include <LibWeb/CSS/StyleValues/ComputationContext.h>
#include <LibWeb/DOM/Document.h>
#include <LibWeb/HTML/Scripting/Environments.h>
@@ -429,7 +430,7 @@ WebIDL::ExceptionOr<TimelineRangeEdge> parse_timeline_range_edge(DOM::Document&
CSS::ComputedValuesFFI::FfiAnimationRangeEdge edge {};
if (!CSS::ComputedValuesFFI::rust_animation_range_edge(computed->rust_style_value_data(), side == TimelineRangeEdgeSide::End, &edge))
return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, "Invalid timeline range"_utf16 };
- return TimelineRangeEdge { static_cast<TimelineRangeName>(edge.name), edge.offset_px, edge.offset_percentage };
+ return TimelineRangeEdge { static_cast<TimelineRangeName>(edge.name), edge.offset_px, edge.offset_percentage, retain_calculated_offset(edge.offset_calculated) };
};
return value.visit(
[&](Bindings::TimelineRangeOffset const& offset) -> WebIDL::ExceptionOr<TimelineRangeEdge> {
@@ -467,6 +468,10 @@ static TimelineRangeBindingValue timeline_range_edge_to_bindings(TimelineRangeEd
GC::Ref<CSS::CSSNumericValue> offset = edge.offset_px == 0 ? GC::Ref<CSS::CSSNumericValue> { percentage } : GC::Ref<CSS::CSSNumericValue> { px };
if (edge.offset_px != 0 && edge.offset_percentage != 0)
offset = MUST(CSS::CSSMathSum::create_for_constructor(Vector<CSS::CSSNumberish> { GC::Ref<CSS::CSSNumericValue> { px }, GC::Ref<CSS::CSSNumericValue> { percentage } }));
+ if (edge.calculated_offset) {
+ auto calculated = CSS::StyleValue::adopt_rust_style_value_data(CSS::StyleValueFFI::rust_style_value_retain(edge.calculated_offset.data()));
+ offset = as<CSS::CSSNumericValue>(*calculated->as_calculated().reify({}));
+ }
Bindings::TimelineRangeOffset range_offset {};
range_offset.range_name = edge.name == TimelineRangeName::None ? Optional<Utf16String> {} : Utf16String::from_utf8_without_validation(timeline_range_name_to_string(edge.name).bytes());
diff --git a/Libraries/LibWeb/Animations/ScrollTimeline.cpp b/Libraries/LibWeb/Animations/ScrollTimeline.cpp
index 9a880e26917..edcab600dd0 100644
--- a/Libraries/LibWeb/Animations/ScrollTimeline.cpp
+++ b/Libraries/LibWeb/Animations/ScrollTimeline.cpp
@@ -236,10 +236,9 @@ AttachmentInterval ScrollTimeline::interval_for_attachment_range(AnimationAttach
// 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 };
+ if (max_scroll_offset == 0)
+ return TimeValue { TimeValue::Type::Percentage, edge.offset_percentage };
+ return TimeValue { TimeValue::Type::Percentage, edge.offset_along(max_scroll_offset) / max_scroll_offset * 100 };
};
return { time_of(range.start), time_of(range.end) };
}
diff --git a/Libraries/LibWeb/Animations/TimelineRange.cpp b/Libraries/LibWeb/Animations/TimelineRange.cpp
new file mode 100644
index 00000000000..7c7db4f6e7b
--- /dev/null
+++ b/Libraries/LibWeb/Animations/TimelineRange.cpp
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2026-present, the Ladybird developers.
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#include <LibWeb/Animations/TimelineRange.h>
+#include <LibWeb/ComputedValuesRustFFI.h>
+
+namespace Web::Animations {
+
+static double length_percentage_px(CSS::RustStyleValueHandle const& calculated, double px, double percentage, double basis)
+{
+ if (calculated)
+ return CSS::ComputedValuesFFI::rust_length_percentage_px(calculated.data(), basis);
+ return px + percentage / 100 * basis;
+}
+
+CSS::RustStyleValueHandle retain_calculated_offset(void const* value)
+{
+ if (!value)
+ return {};
+ return CSS::RustStyleValueHandle::retained(static_cast<CSS::StyleValueFFI::StyleValueData const*>(value));
+}
+
+double TimelineRangeEdge::offset_along(double range_size) const
+{
+ return length_percentage_px(calculated_offset, offset_px, offset_percentage, range_size);
+}
+
+double ViewTimelineInsetEdge::resolve(double scrollport_size) const
+{
+ VERIFY(!is_auto);
+ return length_percentage_px(calculated, px, percentage, scrollport_size);
+}
+
+}
diff --git a/Libraries/LibWeb/Animations/TimelineRange.h b/Libraries/LibWeb/Animations/TimelineRange.h
index ed3763db154..5ec99b738c6 100644
--- a/Libraries/LibWeb/Animations/TimelineRange.h
+++ b/Libraries/LibWeb/Animations/TimelineRange.h
@@ -9,6 +9,7 @@
#include <AK/StringView.h>
#include <AK/Types.h>
#include <LibWeb/Animations/TimeValue.h>
+#include <LibWeb/CSS/StyleValues/RustStyleValueHandle.h>
namespace Web::Animations {
@@ -56,6 +57,12 @@ struct TimelineRangeEdge {
TimelineRangeName name { TimelineRangeName::None };
double offset_px { 0 };
double offset_percentage { 0 };
+ // NB: An offset only a calculation can describe, such as min(50%, 10px), resolves against the size of its range once
+ // that is known. offset_px and offset_percentage then describe it as it resolves against 0px and 100px.
+ CSS::RustStyleValueHandle calculated_offset {};
+
+ // The offset, in pixels, along a range of the given size.
+ double offset_along(double range_size) const;
bool operator==(TimelineRangeEdge const&) const = default;
};
@@ -88,10 +95,18 @@ struct ViewTimelineInsetEdge {
bool is_auto { true };
double px { 0 };
double percentage { 0 };
+ // NB: An inset only a calculation can describe, such as min(50%, 10px), resolves against the scrollport size.
+ CSS::RustStyleValueHandle calculated {};
+
+ // The inset, in pixels, of a side that is not auto, in a scrollport of the given size.
+ double resolve(double scrollport_size) const;
bool operator==(ViewTimelineInsetEdge const&) const = default;
};
+// Takes a reference to a calculated offset or inset the style engine hands over, which may be null.
+CSS::RustStyleValueHandle retain_calculated_offset(void const*);
+
struct ViewTimelineInset {
ViewTimelineInsetEdge start;
ViewTimelineInsetEdge end;
diff --git a/Libraries/LibWeb/Animations/ViewTimeline.cpp b/Libraries/LibWeb/Animations/ViewTimeline.cpp
index 466586c4b3b..00e22e989f9 100644
--- a/Libraries/LibWeb/Animations/ViewTimeline.cpp
+++ b/Libraries/LibWeb/Animations/ViewTimeline.cpp
@@ -23,8 +23,8 @@ GC_DEFINE_ALLOCATOR(ViewTimeline);
ViewTimelineInset view_timeline_inset_from_ffi(CSS::ComputedValuesFFI::FfiViewTimelineInset const& inset)
{
return {
- .start = { inset.start_is_auto, inset.start_px, inset.start_percentage },
- .end = { inset.end_is_auto, inset.end_px, inset.end_percentage },
+ .start = { inset.start_is_auto, inset.start_px, inset.start_percentage, retain_calculated_offset(inset.start_calculated) },
+ .end = { inset.end_is_auto, inset.end_px, inset.end_percentage, retain_calculated_offset(inset.end_calculated) },
};
}
@@ -164,7 +164,7 @@ Optional<ViewTimeline::Metrics> ViewTimeline::compute_metrics() const
auto inset_of = [&](InsetEdge const& edge, double scroll_padding) {
if (edge.is_auto)
return scroll_padding;
- return edge.px + edge.percentage / 100 * scroller->scrollport_size;
+ return edge.resolve(scroller->scrollport_size);
};
auto inset_start = inset_of(m_inset.start, scroller->scroll_padding_start);
auto inset_end = inset_of(m_inset.end, scroller->scroll_padding_end);
@@ -272,7 +272,7 @@ AttachmentInterval ViewTimeline::interval_for_attachment_range(AnimationAttachme
// proportion of the cover range, which spans the entire timeline.
auto time_of = [&](TimelineRangeEdge const& edge) {
auto named_range = interval_for_range_name(*m_last_metrics, edge.name);
- auto position = named_range.start + edge.offset_px + edge.offset_percentage / 100 * (named_range.end - named_range.start);
+ auto position = named_range.start + edge.offset_along(named_range.end - named_range.start);
return TimeValue { TimeValue::Type::Percentage, (position - m_last_metrics->cover_start) / cover_length * 100 };
};
return { time_of(range.start), time_of(range.end) };
diff --git a/Libraries/LibWeb/CMakeLists.txt b/Libraries/LibWeb/CMakeLists.txt
index 86702af189a..8a34d878912 100644
--- a/Libraries/LibWeb/CMakeLists.txt
+++ b/Libraries/LibWeb/CMakeLists.txt
@@ -12,6 +12,7 @@ set(SOURCES
Animations/NamedTimelines.cpp
Animations/PseudoElementParsing.cpp
Animations/ScrollTimeline.cpp
+ Animations/TimelineRange.cpp
Animations/ViewTimeline.cpp
ARIA/AriaData.cpp
ARIA/ARIAMixin.cpp
diff --git a/Libraries/LibWeb/CSS/CSSAnimation.cpp b/Libraries/LibWeb/CSS/CSSAnimation.cpp
index 654e859b877..67c2449ee6e 100644
--- a/Libraries/LibWeb/CSS/CSSAnimation.cpp
+++ b/Libraries/LibWeb/CSS/CSSAnimation.cpp
@@ -158,6 +158,7 @@ void CSSAnimation::apply_css_properties(AnimationProperties const& animation_pro
// computation last computed.
m_applied_keyframe_set = keyframe_set;
m_applied_timing_function_value = animation_properties.timing_function_value;
+ m_applied_definition_range = animation_properties.range;
m_applied_definition = {
.values = {
.duration_is_auto = animation_properties.duration.has<Utf16String>(),
@@ -182,6 +183,8 @@ void CSSAnimation::apply_css_properties(AnimationProperties const& animation_pro
},
.keyframe_set = m_applied_keyframe_set.ptr(),
.timing_function = m_applied_timing_function_value.data(),
+ .range_start_calculated = m_applied_definition_range.start.calculated_offset.data(),
+ .range_end_calculated = m_applied_definition_range.end.calculated_offset.data(),
};
auto const update_timeline = !m_ignored_css_properties.contains(PropertyID::AnimationTimeline)
diff --git a/Libraries/LibWeb/CSS/CSSAnimation.h b/Libraries/LibWeb/CSS/CSSAnimation.h
index c1222a042c8..b7672585a2c 100644
--- a/Libraries/LibWeb/CSS/CSSAnimation.h
+++ b/Libraries/LibWeb/CSS/CSSAnimation.h
@@ -95,9 +95,10 @@ private:
// What the style computation last computed for this animation, as computed values rather than
// the easings and enums `m_applied_css_properties` holds, with the keyframe set and the timing
- // function it names, which the animation retains for as long as it names them.
+ // function and range calculations it names, which the animation retains for as long as it names them.
StyleEngineFFI::FfiAppliedAnimationDefinition m_applied_definition {};
RefPtr<Animations::KeyframeEffect::KeyFrameSet const> m_applied_keyframe_set;
+ Animations::AnimationAttachmentRange m_applied_definition_range;
RustStyleValueHandle m_applied_timing_function_value;
bool m_script_overrode_play_state { false };
diff --git a/Libraries/LibWeb/CSS/StyleComputer.cpp b/Libraries/LibWeb/CSS/StyleComputer.cpp
index 8c2e35a906e..70db285064d 100644
--- a/Libraries/LibWeb/CSS/StyleComputer.cpp
+++ b/Libraries/LibWeb/CSS/StyleComputer.cpp
@@ -956,8 +956,8 @@ static AnimationProperties animation_properties_from_ffi(ComputedValuesFFI::FfiC
.name = animation.timeline_name ? css_string_from_rust(animation.timeline_name) : Utf16FlyString {},
},
.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 },
+ .start = { static_cast<Animations::TimelineRangeName>(animation.range_start_name), animation.range_start_px, animation.range_start_percentage, Animations::retain_calculated_offset(animation.range_start_calculated) },
+ .end = { static_cast<Animations::TimelineRangeName>(animation.range_end_name), animation.range_end_px, animation.range_end_percentage, Animations::retain_calculated_offset(animation.range_end_calculated) },
},
.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 2f84fc4afe9..a0117f6be16 100644
--- a/Libraries/LibWeb/Rust/src/css/style/animations.rs
+++ b/Libraries/LibWeb/Rust/src/css/style/animations.rs
@@ -59,6 +59,8 @@ impl FfiAppliedAnimationDefinition {
},
keyframe_set: animation.keyframe_set,
timing_function: animation.timing_function,
+ range_start_calculated: animation.range_start_calculated,
+ range_end_calculated: animation.range_end_calculated,
}
}
@@ -66,7 +68,7 @@ impl FfiAppliedAnimationDefinition {
/// exactly as it is. A scroll, view or named timeline is found from the element's surroundings
/// every time it is applied, so a definition that names one is never called unchanged, and an animation no
/// plan has described yet publishes a null timing function, which no computed definition has.
- /// The timing function is compared by value: a recomputed style builds a fresh allocation for
+ /// The timing function and range calculations are compared by value: a recomputed style builds a fresh allocation for
/// a declaration that has not changed.
#[must_use]
fn would_change_nothing(&self, published: &Self) -> bool {
@@ -80,12 +82,15 @@ impl FfiAppliedAnimationDefinition {
&& !published.timing_function.is_null()
&& self.values == published.values
&& self.keyframe_set == published.keyframe_set
- && unsafe {
- crate::css::style_value::rust_style_value_equals(
- self.timing_function.cast(),
- published.timing_function.cast(),
- )
- }
+ && [
+ (self.timing_function, published.timing_function),
+ (self.range_start_calculated, published.range_start_calculated),
+ (self.range_end_calculated, published.range_end_calculated),
+ ]
+ .into_iter()
+ .all(|(value, published_value)| unsafe {
+ crate::css::style_value::rust_style_value_equals(value.cast(), published_value.cast())
+ })
}
}
@@ -655,6 +660,8 @@ mod tests {
},
keyframe_set: std::ptr::null(),
timing_function: std::ptr::null(),
+ range_start_calculated: std::ptr::null(),
+ range_end_calculated: std::ptr::null(),
};
animations.set(node, slot, self::names(names), &vec![undescribed; names.len()]);
}
diff --git a/Libraries/LibWeb/Rust/src/css/style/bridge.rs b/Libraries/LibWeb/Rust/src/css/style/bridge.rs
index 014d02ea914..111ba840f9b 100644
--- a/Libraries/LibWeb/Rust/src/css/style/bridge.rs
+++ b/Libraries/LibWeb/Rust/src/css/style/bridge.rs
@@ -1176,6 +1176,9 @@ pub struct FfiAppliedAnimationDefinition {
/// The computed `animation-timing-function`, which the animation retains, or null where no plan
/// has described the animation yet.
pub timing_function: *const c_void,
+ /// The calculations the edges of the attachment range resolve, which the animation retains, or null.
+ pub range_start_calculated: *const c_void,
+ pub range_end_calculated: *const c_void,
}
/// What an applied animation definition holds by value.
diff --git a/Libraries/LibWeb/Rust/src/css/style_compute.rs b/Libraries/LibWeb/Rust/src/css/style_compute.rs
index 48ebfeed1aa..1a0dc576bbe 100644
--- a/Libraries/LibWeb/Rust/src/css/style_compute.rs
+++ b/Libraries/LibWeb/Rust/src/css/style_compute.rs
@@ -2825,14 +2825,17 @@ pub enum FfiAnimationTimelineKind {
/// takes the scroll container's scroll padding, or a length plus a percentage of the scrollport.
/// https://drafts.csswg.org/scroll-animations-1/#view-timeline-inset
#[repr(C)]
-#[derive(Clone, Copy, Default, PartialEq)]
+#[derive(Clone, Copy)]
pub struct FfiViewTimelineInset {
pub start_is_auto: bool,
pub start_px: f64,
pub start_percentage: f64,
+ /// A calculation the start inset resolves against the scrollport size, or null. See `calculated_offset`.
+ pub start_calculated: *const c_void,
pub end_is_auto: bool,
pub end_px: f64,
pub end_percentage: f64,
+ pub end_calculated: *const c_void,
}
#[repr(C)]
@@ -2859,9 +2862,12 @@ pub struct FfiComputedAnimation {
pub range_start_name: u8,
pub range_start_px: f64,
pub range_start_percentage: f64,
+ /// A calculation the start offset resolves against the size of its range, or null. See `calculated_offset`.
+ pub range_start_calculated: *const c_void,
pub range_end_name: u8,
pub range_end_px: f64,
pub range_end_percentage: f64,
+ pub range_end_calculated: *const c_void,
/// 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,
@@ -4828,6 +4834,28 @@ fn fly_string_is_ascii(string: &crate::css::css_string::CssString, expected: &[u
.eq(expected.iter().copied().map(u16::from))
}
+/// The computed value of a length-percentage that only a calculation can describe, such as `min(50%, 10px)`, which the
+/// host retains and resolves once it knows the size the percentages are of, or null for any other value.
+fn calculated_offset(value: &StyleValueData) -> *const c_void {
+ match value {
+ StyleValueData::Calculated { .. } => std::ptr::from_ref(value).cast(),
+ _ => std::ptr::null(),
+ }
+}
+
+/// The pixels of a computed length-percentage, resolving its percentages against `basis`.
+///
+/// # Safety
+/// `value` must point at live style value data.
+#[unsafe(no_mangle)]
+pub unsafe extern "C" fn rust_length_percentage_px(value: *const c_void, basis: f64) -> f64 {
+ // SAFETY: The caller passes a live style value.
+ let value = unsafe { &*value.cast::<StyleValueData>() };
+ crate::css::computed_value_views::LengthPercentageRef::over(value)
+ .to_px(CssPixels::nearest_value_for(basis))
+ .to_double()
+}
+
/// A length-percentage computed value as a length plus a percentage of what it resolves against.
fn length_plus_percentage(value: &StyleValueData) -> (f64, f64) {
match value {
@@ -4843,14 +4871,14 @@ fn length_plus_percentage(value: &StyleValueData) -> (f64, f64) {
/// The insets a computed `[ auto | <length-percentage> ]{1,2}` describes, or both auto where there is none.
fn view_timeline_inset(value: Option<&StyleValueData>) -> FfiViewTimelineInset {
let side = |value: &StyleValueData| match value {
- StyleValueData::Keyword { keyword } if *keyword == keyword::AUTO => (true, 0.0, 0.0),
+ StyleValueData::Keyword { keyword } if *keyword == keyword::AUTO => (true, 0.0, 0.0, std::ptr::null()),
value => {
let (px, percentage) = length_plus_percentage(value);
- (false, px, percentage)
+ (false, px, percentage, calculated_offset(value))
}
};
let (start, end) = match value {
- None => ((true, 0.0, 0.0), (true, 0.0, 0.0)),
+ None => ((true, 0.0, 0.0, std::ptr::null()), (true, 0.0, 0.0, std::ptr::null())),
Some(StyleValueData::ValueList { values, .. }) => match values.as_slice() {
[start, end] => (side(start.data()), side(end.data())),
[both] => (side(both.data()), side(both.data())),
@@ -4862,9 +4890,11 @@ fn view_timeline_inset(value: Option<&StyleValueData>) -> FfiViewTimelineInset {
start_is_auto: start.0,
start_px: start.1,
start_percentage: start.2,
+ start_calculated: start.3,
end_is_auto: end.0,
end_px: end.1,
end_percentage: end.2,
+ end_calculated: end.3,
}
}
@@ -5137,7 +5167,7 @@ fn animation_timeline_descriptor(value: &StyleValueData) -> AnimationTimelineDes
/// 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) {
+fn animation_range_edge(value: &StyleValueData, default_percentage: f64) -> (u8, f64, f64, *const c_void) {
let range_name = |keyword: u16| match keyword {
keyword::COVER => 1,
keyword::CONTAIN => 2,
@@ -5148,9 +5178,12 @@ fn animation_range_edge(value: &StyleValueData, default_percentage: f64) -> (u8,
keyword::SCROLL => 7,
_ => 0,
};
- let offset = length_plus_percentage;
+ let offset = |value: &StyleValueData| {
+ let (px, percentage) = length_plus_percentage(value);
+ (px, percentage, calculated_offset(value))
+ };
match value {
- StyleValueData::Keyword { keyword } => (range_name(*keyword), 0.0, default_percentage),
+ StyleValueData::Keyword { keyword } => (range_name(*keyword), 0.0, default_percentage, std::ptr::null()),
StyleValueData::ValueList { values, .. } => {
let [name, length_percentage] = values.as_slice() else {
unreachable!("computed animation range edge must be a range name and an offset")
@@ -5158,12 +5191,12 @@ fn animation_range_edge(value: &StyleValueData, default_percentage: f64) -> (u8,
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)
+ let (px, percentage, calculated) = offset(length_percentage.data());
+ (range_name(*keyword), px, percentage, calculated)
}
value => {
- let (px, percentage) = offset(value);
- (0, px, percentage)
+ let (px, percentage, calculated) = offset(value);
+ (0, px, percentage, calculated)
}
}
}
@@ -5174,6 +5207,8 @@ pub struct FfiAnimationRangeEdge {
pub name: u8,
pub offset_px: f64,
pub offset_percentage: f64,
+ /// A calculation the offset resolves against the size of its range, or null. See `calculated_offset`.
+ pub offset_calculated: *const c_void,
}
/// The edge a computed `animation-range-start` or `animation-range-end` value with a single item describes, for a range
@@ -5196,11 +5231,13 @@ pub unsafe extern "C" fn rust_animation_range_edge(
},
value => value,
};
- let (name, offset_px, offset_percentage) = animation_range_edge(item, if is_end { 100.0 } else { 0.0 });
+ let (name, offset_px, offset_percentage, offset_calculated) =
+ animation_range_edge(item, if is_end { 100.0 } else { 0.0 });
*out = FfiAnimationRangeEdge {
name,
offset_px,
offset_percentage,
+ offset_calculated,
};
true
}
@@ -5393,9 +5430,9 @@ fn build_computed_animation_list(
_ => unreachable!("computed animation enum must be a keyword"),
};
let timeline = animation_timeline_descriptor(timeline_values[index % timeline_values.len()].data());
- let (range_start_name, range_start_px, range_start_percentage) =
+ let (range_start_name, range_start_px, range_start_percentage, range_start_calculated) =
animation_range_edge(range_start_values[index % range_start_values.len()].data(), 0.0);
- let (range_end_name, range_end_px, range_end_percentage) =
+ let (range_end_name, range_end_px, range_end_percentage, range_end_calculated) =
animation_range_edge(range_end_values[index % range_end_values.len()].data(), 100.0);
animations.push(FfiComputedAnimation {
duration_is_auto,
@@ -5418,9 +5455,11 @@ fn build_computed_animation_list(
range_start_name,
range_start_px,
range_start_percentage,
+ range_start_calculated,
range_end_name,
range_end_px,
range_end_percentage,
+ range_end_calculated,
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/animation-range-and-view-inset-calculations.txt b/Tests/LibWeb/Text/expected/animation-range-and-view-inset-calculations.txt
new file mode 100644
index 00000000000..f2e27391a94
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/animation-range-and-view-inset-calculations.txt
@@ -0,0 +1,3 @@
+scroll range: 5% 90%
+rangeStart: min(50%, 10px)
+view progress: 0.1739
diff --git a/Tests/LibWeb/Text/input/animation-range-and-view-inset-calculations.html b/Tests/LibWeb/Text/input/animation-range-and-view-inset-calculations.html
new file mode 100644
index 00000000000..7f2c8b829d8
--- /dev/null
+++ b/Tests/LibWeb/Text/input/animation-range-and-view-inset-calculations.html
@@ -0,0 +1,29 @@
+<!DOCTYPE html>
+<script src="include.js"></script>
+<style>
+ @keyframes grow { from { width: 0px; } to { width: 100px; } }
+ .scroller { overflow: scroll; width: 100px; height: 100px; }
+ .content { height: 300px; }
+ #scroll-target { animation: grow 1s linear; animation-timeline: scroll(nearest); animation-range: min(50%, 10px) max(50%, 190px); }
+ #view-scroller { height: 200px; }
+ #view-scroller .content { height: 600px; }
+ #view-target { height: 50px; margin-top: 350px; animation: grow 1s linear; animation-timeline: view(min(50%, 10px)); }
+</style>
+<div class="scroller"><div class="content"><div id="scroll-target"></div></div></div>
+<div class="scroller" id="view-scroller"><div class="content"><div id="view-target"></div></div></div>
+<script>
+ // A calculation in an attachment range or a view timeline inset resolves against its range or scrollport size.
+ function nextFrames() {
+ return new Promise(resolve => requestAnimationFrame(() => requestAnimationFrame(resolve)));
+ }
+ promiseTest(async () => {
+ await nextFrames();
+ const scrollAnimation = document.getElementById("scroll-target").getAnimations()[0];
+ println(`scroll range: ${scrollAnimation.startTime} ${scrollAnimation.effect.getComputedTiming().endTime}`);
+ println(`rangeStart: ${scrollAnimation.rangeStart.offset}`);
+ document.getElementById("view-scroller").scrollTop = 200;
+ await nextFrames();
+ const viewAnimation = document.getElementById("view-target").getAnimations()[0];
+ println(`view progress: ${viewAnimation.effect.getComputedTiming().progress.toFixed(4)}`);
+ });
+</script>