Skip to content

Truly independent web browser

LibWeb: Implement view progress timelines and named timelines

Andreas Klingaf77935d01c0
diff --git a/Libraries/LibWeb/Animations/NamedTimelines.cpp b/Libraries/LibWeb/Animations/NamedTimelines.cpp
new file mode 100644
index 00000000000..7eb8b215962
--- /dev/null
+++ b/Libraries/LibWeb/Animations/NamedTimelines.cpp
@@ -0,0 +1,239 @@
+/*
+ * Copyright (c) 2026-present, the Ladybird developers.
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#include <LibGC/Heap.h>
+#include <LibWeb/Animations/NamedTimelines.h>
+#include <LibWeb/CSS/CSSAnimation.h>
+#include <LibWeb/CSS/ComputedValues.h>
+#include <LibWeb/CSS/StyleValues/StyleValue.h>
+#include <LibWeb/DOM/Document.h>
+#include <LibWeb/DOM/Element.h>
+#include <LibWeb/DOM/ShadowRoot.h>
+#include <LibWeb/DOM/Text.h>
+#include <LibWeb/HTML/HTMLSlotElement.h>
+#include <LibWeb/HTML/Scripting/TemporaryExecutionContext.h>
+
+namespace Web::Animations {
+
+GC_DEFINE_ALLOCATOR(NamedTimelines);
+
+GC::Ref<NamedTimelines> NamedTimelines::create(DOM::Document& document)
+{
+ return GC::Heap::the().allocate<NamedTimelines>(document);
+}
+
+NamedTimelines::NamedTimelines(DOM::Document& document)
+ : m_document(document)
+{
+}
+
+void NamedTimelines::visit_edges(GC::Cell::Visitor& visitor)
+{
+ Base::visit_edges(visitor);
+ visitor.visit(m_document);
+ for (auto& declaring_element : m_declaring_elements)
+ visitor.visit(declaring_element.element);
+ for (auto& [key, timeline] : m_timelines) {
+ visitor.visit(key.element);
+ visitor.visit(timeline);
+ }
+}
+
+NamedTimelines::Declaration const* NamedTimelines::DeclaringElement::declaration_named(Utf16FlyString const& name) const
+{
+ // NB: Of the declarations that share a name, the last one is the one the element defines.
+ for (size_t i = declarations.size(); i-- > 0;) {
+ if (declarations[i].name == name)
+ return &declarations[i];
+ }
+ return nullptr;
+}
+
+// https://drafts.csswg.org/css-scoping-1/#flat-tree
+// NB: Visits |node| and its flat tree descendants in flat tree order: a shadow host's shadow tree takes the place of
+// its children, and a slot's assigned nodes take the place of its children when it has any.
+template<typename Callback>
+static void for_each_flat_tree_inclusive_descendant(DOM::Node& node, Callback const& callback)
+{
+ callback(node);
+ auto visit_children_of = [&](DOM::Node& parent) {
+ for (auto* child = parent.first_child(); child; child = child->next_sibling())
+ for_each_flat_tree_inclusive_descendant(*child, callback);
+ };
+ if (auto* element = as_if<DOM::Element>(node); element && element->shadow_root()) {
+ visit_children_of(*element->shadow_root());
+ return;
+ }
+ if (auto* slot = as_if<HTML::HTMLSlotElement>(node); slot && !slot->assigned_nodes_internal().is_empty()) {
+ for (auto const& slottable : slot->assigned_nodes_internal())
+ slottable.visit([&](auto const& assigned) { for_each_flat_tree_inclusive_descendant(static_cast<DOM::Node&>(*assigned), callback); });
+ return;
+ }
+ visit_children_of(node);
+}
+
+void NamedTimelines::refresh_declarations()
+{
+ // NB: An element that comes to declare timelines changes its style, which moves the declarations generation. A change
+ // to the tree can only take declarations away, which matters where any were collected.
+ auto dom_tree_version = m_document->dom_tree_version();
+ auto declarations_generation = m_document->timeline_declarations_generation();
+ bool const tree_changed = m_collected_dom_tree_version != dom_tree_version && !m_declaring_elements.is_empty();
+ if (m_collected_declarations_generation.has_value() && m_collected_declarations_generation == declarations_generation && !tree_changed)
+ return;
+ m_collected_dom_tree_version = dom_tree_version;
+ m_collected_declarations_generation = declarations_generation;
+ m_tracked_animations_need_update = true;
+
+ m_declaring_elements.clear();
+ m_declaring_element_indices.clear();
+
+ // NB: The declarations are collected in flat tree order, which the lookup of the last defined timeline uses.
+ for_each_flat_tree_inclusive_descendant(*m_document, [&](DOM::Node& node) {
+ auto* element = as_if<DOM::Element>(node);
+ if (!element)
+ return;
+ auto const* values_pointer = element->style_group<CSS::ComputedValues::AnimationValues>();
+ if (!values_pointer || !CSS::ComputedValuesFFI::rust_animation_values_declare_timelines(values_pointer))
+ return;
+ auto const& values = *values_pointer;
+
+ DeclaringElement declaring_element { .element = *element, .declarations = {}, .scopes_all_names = false, .scoped_names = {} };
+ CSS::ComputedValuesFFI::rust_animation_values_timeline_declarations(&values, &declaring_element, [](void* context, CSS::ComputedValuesFFI::FfiTimelineDeclaration const* declaration) {
+ static_cast<DeclaringElement*>(context)->declarations.append({
+ .name = CSS::css_string_from_rust(declaration->name),
+ .is_view = declaration->is_view,
+ .axis = scroll_axis_from_css_axis(static_cast<CSS::Axis>(declaration->axis)),
+ .view_inset = view_timeline_inset_from_ffi(declaration->view_inset),
+ });
+ });
+ auto scope = CSS::ComputedValuesFFI::rust_animation_values_timeline_scope(&values, &declaring_element, [](void* context, void const* name) {
+ static_cast<DeclaringElement*>(context)->scoped_names.append(CSS::css_string_from_rust(name));
+ });
+ declaring_element.scopes_all_names = scope == CSS::ComputedValuesFFI::FfiTimelineScope::All;
+
+ m_declaring_element_indices.set(element, m_declaring_elements.size());
+ m_declaring_elements.append(move(declaring_element));
+ });
+
+ // NB: A timeline whose element no longer declares it is dropped. The animations that follow it look their
+ // timeline up again.
+ m_timelines.remove_all_matching([&](TimelineKey const& key, auto const&) {
+ auto const* declaring_element = this->declaring_element(*key.element);
+ return !declaring_element || !declaring_element->declaration_named(key.name);
+ });
+}
+
+NamedTimelines::DeclaringElement const* NamedTimelines::declaring_element(DOM::Element const& element) const
+{
+ auto index = m_declaring_element_indices.get(&element);
+ if (!index.has_value())
+ return nullptr;
+ return &m_declaring_elements[*index];
+}
+
+GC::Ref<ScrollTimeline> NamedTimelines::timeline_for(DOM::Element& element, Declaration const& declaration)
+{
+ TimelineKey key { element, declaration.name };
+ if (auto existing = m_timelines.get(key); existing.has_value()) {
+ // An element may only define one timeline per name, which keeps its identity while its axis and inset change.
+ if (auto* view_timeline = as_if<ViewTimeline>(*existing.value()); view_timeline && declaration.is_view) {
+ view_timeline->set_axis_and_inset(declaration.axis, declaration.view_inset);
+ return *existing;
+ }
+ if (!is<ViewTimeline>(*existing.value()) && !declaration.is_view) {
+ existing.value()->set_axis(declaration.axis);
+ return *existing;
+ }
+ }
+
+ HTML::TemporaryExecutionContext context { m_document->relevant_settings_object() };
+ GC::Ref<ScrollTimeline> timeline = declaration.is_view
+ ? GC::Ref<ScrollTimeline> { ViewTimeline::create(m_document, DOM::AbstractElement { element }, declaration.axis, declaration.view_inset) }
+ : ScrollTimeline::create(m_document, GC::Ptr<DOM::Element const> { &element }, declaration.axis);
+ m_timelines.set(key, timeline);
+ return timeline;
+}
+
+// https://drafts.csswg.org/scroll-animations-1/#target-timeline
+GC::Ptr<ScrollTimeline> NamedTimelines::target_timeline(DOM::AbstractElement const& element, Utf16FlyString const& name)
+{
+ refresh_declarations();
+
+ // Whether |descendant| is a flat tree descendant of |ancestor| that a timeline name it defines is in scope for:
+ // no element between them limits the scope of |name| to its own descendants.
+ // INTEROP: The spec looks at all flat tree descendants, but like Chrome, a timeline inside an element that scopes
+ // its name, including the element itself, is only found by lookups within that element.
+ auto is_in_scope_of = [&](DOM::Element const& descendant, DOM::Element const& ancestor) {
+ for (auto const* element = &descendant; element; element = element->flat_tree_parent_element()) {
+ if (element == &ancestor)
+ return element != &descendant;
+ if (auto const* declaring_element = this->declaring_element(*element); declaring_element && declaring_element->scopes(name))
+ return false;
+ }
+ return false;
+ };
+
+ // The target timeline for a given element element referencing a timeline name name is:
+ for (Optional<DOM::AbstractElement> current = element; current.has_value();) {
+ auto& current_element = current->element();
+ auto const* declaring_element = current->pseudo_element().has_value() ? nullptr : this->declaring_element(current_element);
+
+ // If element defines a timeline matching name,
+ if (declaring_element) {
+ if (auto const* declaration = declaring_element->declaration_named(name)) {
+ // That timeline.
+ return timeline_for(current_element, *declaration);
+ }
+ }
+
+ // Otherwise, if name is scoped by element, or if element is the document element,
+ if ((declaring_element && declaring_element->scopes(name)) || (!current->pseudo_element().has_value() && &current_element == m_document->document_element())) {
+ // The last defined timeline matching name among element's flat tree descendants in flat tree order, or,
+ // if no such timeline exists, an inactive timeline.
+ for (size_t i = m_declaring_elements.size(); i-- > 0;) {
+ auto const& candidate = m_declaring_elements[i];
+ auto const* declaration = candidate.declaration_named(name);
+ if (declaration && is_in_scope_of(candidate.element, current_element))
+ return timeline_for(candidate.element, *declaration);
+ }
+ return nullptr;
+ }
+
+ // Otherwise, the target timeline for element's flat tree parent referencing name.
+ auto* parent = current->flat_tree_parent_element();
+ if (!parent)
+ break;
+ current = DOM::AbstractElement { *parent };
+ }
+ return nullptr;
+}
+
+void NamedTimelines::track_animation(CSS::CSSAnimation& animation)
+{
+ m_tracked_animations.set(animation);
+}
+
+bool NamedTimelines::update_tracked_animations()
+{
+ refresh_declarations();
+ if (!m_tracked_animations_need_update)
+ return false;
+ m_tracked_animations_need_update = false;
+ Vector<GC::Ref<CSS::CSSAnimation>> animations;
+ for (auto& animation : m_tracked_animations)
+ animations.append(animation);
+ bool any_timeline_changed = false;
+ for (auto& animation : animations) {
+ auto previous_timeline = animation->timeline();
+ animation->update_named_timeline();
+ if (animation->timeline() != previous_timeline)
+ any_timeline_changed = true;
+ }
+ return any_timeline_changed;
+}
+
+}
diff --git a/Libraries/LibWeb/Animations/NamedTimelines.h b/Libraries/LibWeb/Animations/NamedTimelines.h
new file mode 100644
index 00000000000..934a61ddbc7
--- /dev/null
+++ b/Libraries/LibWeb/Animations/NamedTimelines.h
@@ -0,0 +1,93 @@
+/*
+ * Copyright (c) 2026-present, the Ladybird developers.
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#pragma once
+
+#include <AK/HashMap.h>
+#include <AK/Utf16FlyString.h>
+#include <AK/Vector.h>
+#include <LibGC/Cell.h>
+#include <LibGC/CellAllocator.h>
+#include <LibGC/Ptr.h>
+#include <LibGC/WeakHashSet.h>
+#include <LibWeb/Animations/ViewTimeline.h>
+#include <LibWeb/Forward.h>
+
+namespace Web::Animations {
+
+// The scroll progress timelines and view progress timelines that elements of a document declare by name with the
+// 'scroll-timeline' and 'view-timeline' properties, and the animations that look them up by name.
+// https://drafts.csswg.org/scroll-animations-1/#timeline-scoping
+class NamedTimelines final : public GC::Cell {
+ GC_CELL(NamedTimelines, GC::Cell);
+ GC_DECLARE_ALLOCATOR(NamedTimelines);
+
+public:
+ [[nodiscard]] static GC::Ref<NamedTimelines> create(DOM::Document&);
+
+ // https://drafts.csswg.org/scroll-animations-1/#target-timeline
+ GC::Ptr<ScrollTimeline> target_timeline(DOM::AbstractElement const&, Utf16FlyString const& name);
+
+ // Tracks an animation whose timeline is a named timeline, so that it follows the timeline its name finds as the
+ // declarations of the document change.
+ void track_animation(CSS::CSSAnimation&);
+
+ // Looks the timelines of the tracked animations up again, where the declarations of the document have changed.
+ // Returns whether any animation changed its timeline.
+ bool update_tracked_animations();
+
+private:
+ explicit NamedTimelines(DOM::Document&);
+
+ virtual void visit_edges(GC::Cell::Visitor&) override;
+
+ struct Declaration {
+ Utf16FlyString name;
+ bool is_view { false };
+ ScrollAxis axis { ScrollAxis::Block };
+ ViewTimeline::Inset view_inset;
+ };
+ struct DeclaringElement {
+ GC::Ref<DOM::Element> element;
+ Vector<Declaration> declarations;
+ bool scopes_all_names { false };
+ Vector<Utf16FlyString> scoped_names;
+
+ Declaration const* declaration_named(Utf16FlyString const&) const;
+ bool scopes(Utf16FlyString const& name) const { return scopes_all_names || scoped_names.contains_slow(name); }
+ };
+
+ // Collects the declarations of the document again, when its tree or the timeline declarations of its elements
+ // have changed since they were last collected.
+ void refresh_declarations();
+
+ DeclaringElement const* declaring_element(DOM::Element const&) const;
+ GC::Ref<ScrollTimeline> timeline_for(DOM::Element&, Declaration const&);
+
+ GC::Ref<DOM::Document> m_document;
+
+ // The elements that declare timelines or scope timeline names, in tree order.
+ Vector<DeclaringElement> m_declaring_elements;
+ HashMap<GC::RawPtr<DOM::Element const>, size_t> m_declaring_element_indices;
+ Optional<u64> m_collected_dom_tree_version;
+ Optional<u64> m_collected_declarations_generation;
+
+ struct TimelineKey {
+ GC::Ref<DOM::Element> element;
+ Utf16FlyString name;
+
+ bool operator==(TimelineKey const&) const = default;
+ };
+ struct TimelineKeyTraits : public DefaultTraits<TimelineKey> {
+ static unsigned hash(TimelineKey const& key) { return pair_int_hash(ptr_hash(key.element.ptr()), key.name.hash()); }
+ };
+ HashMap<TimelineKey, GC::Ref<ScrollTimeline>, TimelineKeyTraits> m_timelines;
+
+ GC::WeakHashSet<CSS::CSSAnimation> m_tracked_animations;
+ bool m_tracked_animations_need_update { false };
+};
+
+}
diff --git a/Libraries/LibWeb/Animations/ScrollTimeline.cpp b/Libraries/LibWeb/Animations/ScrollTimeline.cpp
index de94617e3ec..9a880e26917 100644
--- a/Libraries/LibWeb/Animations/ScrollTimeline.cpp
+++ b/Libraries/LibWeb/Animations/ScrollTimeline.cpp
@@ -7,6 +7,7 @@
#include "ScrollTimeline.h"
#include <LibGC/Heap.h>
#include <LibWeb/Animations/Animation.h>
+#include <LibWeb/Animations/ViewTimeline.h>
#include <LibWeb/Bindings/ScrollTimeline.h>
#include <LibWeb/DOM/Document.h>
#include <LibWeb/HTML/Scripting/Environments.h>
@@ -114,14 +115,9 @@ static ComputedScrollAxis computed_scroll_axis(ScrollAxis axis, CSS::WritingMode
VERIFY_NOT_REACHED();
}
-struct ScrollOffsetData {
- Optional<AsyncScrollNodeStableID> scroll_node;
- bool is_vertical;
- double scroll_offset;
- double max_scroll_offset;
-};
-static Optional<ScrollOffsetData> compute_scroll_offset_data(Variant<GC::Ptr<DOM::Element const>, GC::Ptr<DOM::Document>> propagated_source, ScrollAxis axis)
+Optional<ScrollTimeline::ScrollerMetrics> ScrollTimeline::scroller_metrics() const
{
+ auto propagated_source = get_propagated_source();
if (propagated_source.visit([](auto const& source) { return source == nullptr; }))
return {};
@@ -136,14 +132,18 @@ static Optional<ScrollOffsetData> compute_scroll_offset_data(Variant<GC::Ptr<DOM
return {};
auto const& scrollable_overflow_rect = Painting::scrollable_overflow_rect(*layout_node).value();
- auto const& computed_axis = computed_scroll_axis(axis, layout_node->writing_mode(), layout_node->direction());
+ auto const& computed_axis = computed_scroll_axis(m_axis, layout_node->writing_mode(), layout_node->direction());
+ auto scrollport = Painting::absolute_padding_box_rect(*layout_node);
+ // NB: Only a view progress timeline measures its subject against the scroll padding, so a scroll progress timeline
+ // does not resolve it on every update.
+ auto snapport = is<ViewTimeline>(*this) ? Painting::scroll_snapport_rect(*layout_node, scrollport) : scrollport;
// FIXME: Scroll offset is currently incorrect as it is always relative to the top left of the scrollable overflow
// rect when it should instead be relative to the scroll origin.
// FIXME: Support the case where the computed scroll axis is reversed
- return ScrollOffsetData {
+ return ScrollerMetrics {
.scroll_node = Painting::async_scroll_node_stable_id(*layout_node),
.is_vertical = computed_axis.is_vertical,
.scroll_offset = computed_axis.is_vertical
@@ -152,9 +152,25 @@ static Optional<ScrollOffsetData> compute_scroll_offset_data(Variant<GC::Ptr<DOM
.max_scroll_offset = computed_axis.is_vertical
? scrollable_overflow_rect.height().to_double() - Painting::content_height(*layout_node).to_double()
: scrollable_overflow_rect.width().to_double() - Painting::content_width(*layout_node).to_double(),
+ .scrollport_start = (computed_axis.is_vertical ? scrollport.y() : scrollport.x()).to_double(),
+ .scrollport_size = (computed_axis.is_vertical ? scrollport.height() : scrollport.width()).to_double(),
+ .scroll_padding_start = computed_axis.is_vertical
+ ? (snapport.y() - scrollport.y()).to_double()
+ : (snapport.x() - scrollport.x()).to_double(),
+ .scroll_padding_end = computed_axis.is_vertical
+ ? (scrollport.bottom() - snapport.bottom()).to_double()
+ : (scrollport.right() - snapport.right()).to_double(),
};
}
+void ScrollTimeline::set_axis(ScrollAxis axis)
+{
+ if (m_axis == axis)
+ return;
+ m_axis = axis;
+ update_current_time(0);
+}
+
bool ScrollTimeline::is_stale() const
{
// FIXME: This should probably be a spec bug
@@ -168,7 +184,7 @@ bool ScrollTimeline::is_stale() const
// narrow) tests in WPT and is the same behavior as is implemented by WebKit.
// FIXME: Account for the named timeline ranges of view progress timelines once they are implemented.
- auto scroll_offset_data = compute_scroll_offset_data(get_propagated_source(), m_axis);
+ auto scroll_offset_data = scroller_metrics();
return scroll_offset_data.map([](auto const& data) { return data.max_scroll_offset; }) != m_last_max_scroll_offset;
}
@@ -180,7 +196,7 @@ void ScrollTimeline::update_current_time(double)
// representing its startmost scroll position (in the writing mode of the scroll container). Null when the timeline
// is inactive.
- auto scroll_offset_data = compute_scroll_offset_data(get_propagated_source(), m_axis);
+ auto scroll_offset_data = scroller_metrics();
m_last_max_scroll_offset = scroll_offset_data.map([](auto const& data) { return data.max_scroll_offset; });
m_followed_scroller.clear();
diff --git a/Libraries/LibWeb/Animations/ScrollTimeline.h b/Libraries/LibWeb/Animations/ScrollTimeline.h
index ffa2a437881..e712d0330da 100644
--- a/Libraries/LibWeb/Animations/ScrollTimeline.h
+++ b/Libraries/LibWeb/Animations/ScrollTimeline.h
@@ -43,11 +43,13 @@ public:
virtual Optional<TimeValue> duration() const override { return TimeValue { TimeValue::Type::Percentage, 100 }; }
GC::Ptr<DOM::Element const> source() const;
+ virtual GC::Ptr<DOM::Element const> source_for_bindings() const { return source(); }
ScrollAxis axis() const { return m_axis; }
+ void set_axis(ScrollAxis);
Source source_internal() const { return m_source; }
- bool is_stale() const;
+ virtual bool is_stale() const;
virtual void update_current_time(double timestamp) override;
// The scroll node the timeline followed at its last update, and the scroll offset at 100% progress there, in CSS
@@ -67,12 +69,29 @@ public:
virtual Optional<TimeValue> maximum_timeline_time() const override { return TimeValue { TimeValue::Type::Percentage, 100 }; }
virtual bool can_convert_a_timeline_time_to_an_origin_relative_time() const override { return false; }
-private:
+protected:
ScrollTimeline(DOM::Document&, Source source, ScrollAxis axis);
virtual ~ScrollTimeline() override = default;
virtual void visit_edges(GC::Cell::Visitor&) override;
+ // The scroll container the timeline follows, along the timeline's axis, in CSS pixels.
+ struct ScrollerMetrics {
+ Optional<AsyncScrollNodeStableID> scroll_node;
+ bool is_vertical { true };
+ double scroll_offset { 0 };
+ double max_scroll_offset { 0 };
+ // Where the scrollport starts in the coordinates the boxes inside it are laid out in, and its size.
+ double scrollport_start { 0 };
+ double scrollport_size { 0 };
+ // The scroll padding at the start and at the end of the scrollport.
+ double scroll_padding_start { 0 };
+ double scroll_padding_end { 0 };
+ };
+ // Empty while the source has no box, is not a scroll container or has no scrollable overflow.
+ Optional<ScrollerMetrics> scroller_metrics() const;
+
+private:
Variant<GC::Ptr<DOM::Element const>, GC::Ptr<DOM::Document>> get_propagated_source() const;
// https://drafts.csswg.org/scroll-animations-1/#dom-scrolltimeline-source
diff --git a/Libraries/LibWeb/Animations/ScrollTimeline.idl b/Libraries/LibWeb/Animations/ScrollTimeline.idl
index 35f25d81a78..939c286df27 100644
--- a/Libraries/LibWeb/Animations/ScrollTimeline.idl
+++ b/Libraries/LibWeb/Animations/ScrollTimeline.idl
@@ -2,7 +2,7 @@
[Exposed=Window]
interface ScrollTimeline : AnimationTimeline {
constructor(optional ScrollTimelineOptions options = {});
- readonly attribute Element? source;
+ [ImplementedAs=source_for_bindings] readonly attribute Element? source;
readonly attribute ScrollAxis axis;
};
diff --git a/Libraries/LibWeb/Animations/TimelineRange.h b/Libraries/LibWeb/Animations/TimelineRange.h
index 8559c362bd4..ed3763db154 100644
--- a/Libraries/LibWeb/Animations/TimelineRange.h
+++ b/Libraries/LibWeb/Animations/TimelineRange.h
@@ -81,4 +81,22 @@ struct AttachmentInterval {
bool operator==(AttachmentInterval const&) const = default;
};
+// One side of the view progress visibility range: auto takes the scroll container's scroll padding, otherwise a length
+// plus a percentage of the scrollport.
+// https://drafts.csswg.org/scroll-animations-1/#view-timeline-inset
+struct ViewTimelineInsetEdge {
+ bool is_auto { true };
+ double px { 0 };
+ double percentage { 0 };
+
+ bool operator==(ViewTimelineInsetEdge const&) const = default;
+};
+
+struct ViewTimelineInset {
+ ViewTimelineInsetEdge start;
+ ViewTimelineInsetEdge end;
+
+ bool operator==(ViewTimelineInset const&) const = default;
+};
+
}
diff --git a/Libraries/LibWeb/Animations/ViewTimeline.cpp b/Libraries/LibWeb/Animations/ViewTimeline.cpp
new file mode 100644
index 00000000000..466586c4b3b
--- /dev/null
+++ b/Libraries/LibWeb/Animations/ViewTimeline.cpp
@@ -0,0 +1,310 @@
+/*
+ * Copyright (c) 2026-present, the Ladybird developers.
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#include <LibGC/Heap.h>
+#include <LibWeb/Animations/ViewTimeline.h>
+#include <LibWeb/CSS/CSSKeywordValue.h>
+#include <LibWeb/CSS/CSSUnitValue.h>
+#include <LibWeb/CSS/Parser/Parser.h>
+#include <LibWeb/DOM/Document.h>
+#include <LibWeb/DOM/Element.h>
+#include <LibWeb/HTML/Window.h>
+#include <LibWeb/Layout/Node.h>
+#include <LibWeb/Layout/RenderDocument.h>
+#include <LibWeb/Painting/BoxViews.h>
+
+namespace Web::Animations {
+
+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 },
+ };
+}
+
+// The insets a computed 'view-timeline-inset' value describes.
+static ViewTimelineInset view_timeline_inset_from_style_value(CSS::StyleValue const& value)
+{
+ return view_timeline_inset_from_ffi(CSS::ComputedValuesFFI::rust_view_timeline_inset(value.rust_style_value_data()));
+}
+
+GC::Ref<ViewTimeline> ViewTimeline::create(DOM::Document& document, DOM::AbstractElement subject, ScrollAxis axis, Inset inset)
+{
+ auto timeline = GC::Heap::the().allocate<ViewTimeline>(document, subject, axis, inset);
+
+ // NB: The passed timestamp is ignored for ViewTimelines so we can just pass 0 here.
+ timeline->update_current_time(0);
+
+ return timeline;
+}
+
+// https://drafts.csswg.org/scroll-animations-1/#dom-viewtimeline-viewtimeline
+WebIDL::ExceptionOr<GC::Ref<ViewTimeline>> ViewTimeline::create_for_constructor(JS::Object& relevant_global_object, Bindings::ViewTimelineOptions const& options)
+{
+ auto& document = HTML::relevant_window(relevant_global_object).associated_document();
+
+ // 1. Let timeline be the new ViewTimeline object.
+ // 2. Set the subject and axis properties of timeline to the corresponding values from options.
+ // 3. Set the source of timeline to the subject’s nearest ancestor scroll container element that's scrollable in
+ // the specified axis.
+ // NB: The source is found from the subject whenever it is asked for.
+
+ // 4. If a DOMString value is provided as an inset, parse it as a <'view-timeline-inset'> value; if a sequence is
+ // provided, the first value represents the start inset and the second value represents the end inset. If the
+ // sequence has only one value, it is duplicated. If it has zero values or more than two values, or if it
+ // contains a CSSKeywordValue whose value is not "auto", throw a TypeError.
+ // AD-HOC: Relative lengths are not allowed, see https://github.com/w3c/csswg-drafts/issues/13852
+ auto parse_inset = [&](Utf16String const& string) -> WebIDL::ExceptionOr<Inset> {
+ auto value = parse_css_value(CSS::Parser::ParsingParams { document }, string, CSS::PropertyID::ViewTimelineInset);
+ // NB: Arbitrary substitution functions and CSS-wide keywords have nothing to substitute or inherit from here.
+ if (!value || value->is_css_wide_keyword() || value->is_unresolved() || value->is_pending_substitution()
+ || CSS::ComputedValuesFFI::rust_view_timeline_inset_has_relative_length(value->rust_style_value_data()))
+ return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, "Invalid view timeline inset"_utf16 };
+ auto computed = value->absolutized(CSS::ComputationContext { .length_resolution_context = CSS::Length::ResolutionContext::for_document(document) });
+ return view_timeline_inset_from_style_value(*computed);
+ };
+ auto parse_auto = [&](Utf16View const& keyword) -> WebIDL::ExceptionOr<InsetEdge> {
+ if (!keyword.equals_ignoring_ascii_case("auto"sv))
+ return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, "A view timeline inset keyword must be auto"_utf16 };
+ return InsetEdge {};
+ };
+ auto inset = TRY(options.inset.visit(
+ [&](Utf16String const& string) { return parse_inset(string); },
+ [&](auto const& values) -> WebIDL::ExceptionOr<Inset> {
+ if (values.is_empty() || values.size() > 2)
+ return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, "A view timeline inset takes one or two values"_utf16 };
+ Vector<InsetEdge, 2> edges;
+ for (auto const& value : values) {
+ auto edge = TRY(value.visit(
+ [&](GC::Ref<CSS::CSSNumericValue> const& numeric) -> WebIDL::ExceptionOr<InsetEdge> {
+ return TRY(parse_inset(numeric->to_string({}))).start;
+ },
+ [&](GC::Ref<CSS::CSSKeywordValue> const& keyword) { return parse_auto(keyword->value()); },
+ // INTEROP: Blink takes "auto" as a string in the sequence too.
+ [&](Utf16String const& keyword) { return parse_auto(keyword); }));
+ edges.append(edge);
+ }
+ return Inset { edges[0], edges.size() > 1 ? edges[1] : edges[0] };
+ }));
+
+ return create(document, DOM::AbstractElement { *options.subject }, options.axis, inset);
+}
+
+ViewTimeline::ViewTimeline(DOM::Document& document, DOM::AbstractElement subject, ScrollAxis axis, Inset inset)
+ : ScrollTimeline(document, AnonymousSource { .scroller = CSS::Scroller::Nearest, .target = subject }, axis)
+ , m_inset(inset)
+{
+}
+
+DOM::AbstractElement ViewTimeline::subject_internal() const
+{
+ return source_internal().get<AnonymousSource>().target;
+}
+
+GC::Ref<DOM::Element const> ViewTimeline::subject() const
+{
+ return subject_internal().element();
+}
+
+GC::Ptr<DOM::Element const> ViewTimeline::source_for_bindings() const
+{
+ // The values of subject, source, and currentTime are all computed when any of them is requested or updated.
+ auto subject = subject_internal();
+ subject.document().update_style_for_element(subject, DOM::Document::StyleUpdateMode::OnlyIfNeeded);
+
+ // If the source or subject of a ViewTimeline is an element whose principal box does not exist, [...] then the
+ // ViewTimeline is inactive.
+ // INTEROP: Its source is then null, as WebKit and Blink have it.
+ for (GC::Ptr<DOM::Element const> element = &subject.element(); element; element = element->flat_tree_parent_element()) {
+ if (!element->has_style() || element->installed_style().display_is_none())
+ return nullptr;
+ }
+ return source();
+}
+
+void ViewTimeline::set_axis_and_inset(ScrollAxis axis, Inset inset)
+{
+ if (this->axis() == axis && m_inset == inset)
+ return;
+ m_inset = inset;
+ if (this->axis() != axis)
+ set_axis(axis);
+ else
+ update_current_time(0);
+}
+
+Optional<ViewTimeline::Metrics> ViewTimeline::compute_metrics() const
+{
+ // If the source or subject of a ViewTimeline is an element whose principal box does not exist, or if its nearest
+ // ancestor scroll container has no scrollable overflow or is not scrollable in the specified axis (or if there is no
+ // such ancestor, e.g. in print media), then the ViewTimeline is inactive.
+ auto scroller = scroller_metrics();
+ if (!scroller.has_value())
+ return {};
+
+ auto subject = subject_internal();
+ Layout::ForcedReadScope read { subject.document() };
+ auto const* subject_layout_node = subject.unsafe_layout_node(read);
+ if (!subject_layout_node || !Painting::has_committed_box(*subject_layout_node))
+ return {};
+
+ // NB: The border box is laid out where the scroll container's scrolled content is at its scroll origin, with
+ // transforms ignored and relative positioning accounted for, as the view progress timeline ranges ask.
+ auto subject_border_box = Painting::absolute_border_box_rect(*subject_layout_node);
+ auto subject_start = (scroller->is_vertical ? subject_border_box.y() : subject_border_box.x()).to_double();
+ auto subject_size = (scroller->is_vertical ? subject_border_box.height() : subject_border_box.width()).to_double();
+ auto subject_offset = subject_start - scroller->scrollport_start;
+
+ 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;
+ };
+ auto inset_start = inset_of(m_inset.start, scroller->scroll_padding_start);
+ auto inset_end = inset_of(m_inset.end, scroller->scroll_padding_end);
+
+ // https://drafts.csswg.org/scroll-animations-1/#valdef-animation-timeline-range-cover
+ // 0% progress represents the latest position at which the start border edge of the element’s principal box
+ // coincides with the end edge of its view progress visibility range.
+ // 100% progress represents the earliest position at which the end border edge of the element’s principal box
+ // coincides with the start edge of its view progress visibility range.
+ return Metrics {
+ .scroll_offset = scroller->scroll_offset,
+ .max_scroll_offset = scroller->max_scroll_offset,
+ .cover_start = subject_offset - (scroller->scrollport_size - inset_end),
+ .cover_end = subject_offset + subject_size - inset_start,
+ .subject_size = subject_size,
+ };
+}
+
+bool ViewTimeline::is_stale() const
+{
+ // NB: See ScrollTimeline::is_stale(). A view progress timeline's named timeline ranges move with its subject too.
+ return compute_metrics() != m_last_metrics;
+}
+
+void ViewTimeline::update_current_time(double)
+{
+ m_last_metrics = compute_metrics();
+
+ if (!m_last_metrics.has_value()) {
+ set_current_time({});
+ return;
+ }
+
+ // https://drafts.csswg.org/scroll-animations-1/#view-timeline-progress
+ // Progress (the current time) in a view progress timeline is calculated as: distance ÷ range where:
+ // - distance is the current scroll offset minus the scroll offset corresponding to the start of the cover range
+ // - range is the scroll offset corresponding to the end of the cover range minus the scroll offset corresponding
+ // to the start of the cover range
+ auto distance = m_last_metrics->scroll_offset - m_last_metrics->cover_start;
+ auto range = m_last_metrics->cover_end - m_last_metrics->cover_start;
+
+ // If the 0% position and 100% position coincide (i.e. the denominator in the current time formula is zero), the
+ // timeline is inactive.
+ if (range == 0) {
+ set_current_time({});
+ return;
+ }
+
+ // FIXME: In paged media, view progress timelines that would otherwise reference the document viewport are also
+ // inactive.
+
+ set_current_time(TimeValue { TimeValue::Type::Percentage, distance / range * 100 });
+}
+
+// https://drafts.csswg.org/scroll-animations-1/#view-timelines-ranges
+ViewTimeline::ScrollOffsetInterval ViewTimeline::interval_for_range_name(Metrics const& metrics, TimelineRangeName name) const
+{
+ auto sorted = [](double start, double end) {
+ if (end < start)
+ swap(start, end);
+ return ScrollOffsetInterval { start, end };
+ };
+
+ switch (name) {
+ case TimelineRangeName::None:
+ case TimelineRangeName::Cover:
+ // Represents the full range of the view progress timeline.
+ return { metrics.cover_start, metrics.cover_end };
+ case TimelineRangeName::Contain:
+ // Represents the range during which the principal box is either fully contained by, or fully covers, its view
+ // progress visibility range within the scrollport.
+ return sorted(metrics.cover_start + metrics.subject_size, metrics.cover_end - metrics.subject_size);
+ case TimelineRangeName::Entry: {
+ // 0% is equivalent to 0% of the cover range.
+ // 100% is equivalent to 0% of the contain range.
+ auto contain = interval_for_range_name(metrics, TimelineRangeName::Contain);
+ return sorted(metrics.cover_start, contain.start);
+ }
+ case TimelineRangeName::Exit: {
+ // 0% is equivalent to 100% of the contain range.
+ // 100% is equivalent to 100% of the cover range.
+ auto contain = interval_for_range_name(metrics, TimelineRangeName::Contain);
+ return sorted(contain.end, metrics.cover_end);
+ }
+ case TimelineRangeName::EntryCrossing:
+ // Represents the range during which the principal box crosses the end border edge.
+ return sorted(metrics.cover_start, metrics.cover_start + metrics.subject_size);
+ case TimelineRangeName::ExitCrossing:
+ // Represents the range during which the principal box crosses the start border edge.
+ return sorted(metrics.cover_end - metrics.subject_size, metrics.cover_end);
+ case TimelineRangeName::Scroll:
+ // Represents the full range of the scroll container on which the view progress timeline is defined.
+ return { 0, metrics.max_scroll_offset };
+ }
+ VERIFY_NOT_REACHED();
+}
+
+AttachmentInterval ViewTimeline::interval_for_attachment_range(AnimationAttachmentRange const& range) const
+{
+ auto cover_length = m_last_metrics.has_value() ? m_last_metrics->cover_end - m_last_metrics->cover_start : 0;
+ if (cover_length == 0)
+ return ScrollTimeline::interval_for_attachment_range(range);
+
+ // Each edge is measured from the start of its named timeline range, along that range, and is then placed as a
+ // 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);
+ return TimeValue { TimeValue::Type::Percentage, (position - m_last_metrics->cover_start) / cover_length * 100 };
+ };
+ return { time_of(range.start), time_of(range.end) };
+}
+
+// NB: The timeline times at the minimum and the maximum scroll offsets, which need not be 0% and 100%.
+Optional<TimeValue> ViewTimeline::minimum_timeline_time() const
+{
+ if (!m_last_metrics.has_value() || m_last_metrics->cover_end == m_last_metrics->cover_start)
+ return {};
+ return TimeValue { TimeValue::Type::Percentage, (0 - m_last_metrics->cover_start) / (m_last_metrics->cover_end - m_last_metrics->cover_start) * 100 };
+}
+
+Optional<TimeValue> ViewTimeline::maximum_timeline_time() const
+{
+ if (!m_last_metrics.has_value() || m_last_metrics->cover_end == m_last_metrics->cover_start)
+ return {};
+ return TimeValue { TimeValue::Type::Percentage, (m_last_metrics->max_scroll_offset - m_last_metrics->cover_start) / (m_last_metrics->cover_end - m_last_metrics->cover_start) * 100 };
+}
+
+GC::Ref<CSS::CSSNumericValue> ViewTimeline::start_offset() const
+{
+ // Represents the starting (0% progress) scroll position of the view progress timeline as a length offset (in px)
+ // from the scroll origin.
+ return CSS::CSSUnitValue::create(m_last_metrics.has_value() ? m_last_metrics->cover_start : 0, "px"_utf16_fly_string);
+}
+
+GC::Ref<CSS::CSSNumericValue> ViewTimeline::end_offset() const
+{
+ // Represents the ending (100% progress) scroll position of the view progress timeline as a length offset (in px)
+ // from the scroll origin.
+ return CSS::CSSUnitValue::create(m_last_metrics.has_value() ? m_last_metrics->cover_end : 0, "px"_utf16_fly_string);
+}
+
+}
diff --git a/Libraries/LibWeb/Animations/ViewTimeline.h b/Libraries/LibWeb/Animations/ViewTimeline.h
new file mode 100644
index 00000000000..5cfed257180
--- /dev/null
+++ b/Libraries/LibWeb/Animations/ViewTimeline.h
@@ -0,0 +1,79 @@
+/*
+ * Copyright (c) 2026-present, the Ladybird developers.
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#pragma once
+
+#include <LibWeb/Animations/ScrollTimeline.h>
+#include <LibWeb/Bindings/ViewTimeline.h>
+#include <LibWeb/ComputedValuesRustFFI.h>
+
+namespace Web::Animations {
+
+// https://drafts.csswg.org/scroll-animations-1/#viewtimeline
+class ViewTimeline final : public ScrollTimeline {
+ WEB_WRAPPABLE(ViewTimeline, ScrollTimeline);
+ GC_DECLARE_ALLOCATOR(ViewTimeline);
+
+public:
+ using InsetEdge = ViewTimelineInsetEdge;
+ using Inset = ViewTimelineInset;
+
+ static GC::Ref<ViewTimeline> create(DOM::Document&, DOM::AbstractElement subject, ScrollAxis, Inset);
+ static WebIDL::ExceptionOr<GC::Ref<ViewTimeline>> create_for_constructor(JS::Object&, Bindings::ViewTimelineOptions const&);
+
+ // https://drafts.csswg.org/scroll-animations-1/#dom-viewtimeline-subject
+ GC::Ref<DOM::Element const> subject() const;
+ DOM::AbstractElement subject_internal() const;
+
+ // https://drafts.csswg.org/scroll-animations-1/#dom-scrolltimeline-source
+ virtual GC::Ptr<DOM::Element const> source_for_bindings() const override;
+
+ Inset const& inset() const { return m_inset; }
+ void set_axis_and_inset(ScrollAxis, Inset);
+
+ // https://drafts.csswg.org/scroll-animations-1/#dom-viewtimeline-startoffset
+ GC::Ref<CSS::CSSNumericValue> start_offset() const;
+ // https://drafts.csswg.org/scroll-animations-1/#dom-viewtimeline-endoffset
+ GC::Ref<CSS::CSSNumericValue> end_offset() const;
+
+ virtual bool is_stale() const override;
+ virtual void update_current_time(double timestamp) override;
+ virtual AttachmentInterval interval_for_attachment_range(AnimationAttachmentRange const&) const override;
+ virtual Optional<TimeValue> minimum_timeline_time() const override;
+ virtual Optional<TimeValue> maximum_timeline_time() const override;
+
+private:
+ // The scroll offsets at the start and at the end of a named timeline range, in CSS pixels.
+ struct ScrollOffsetInterval {
+ double start { 0 };
+ double end { 0 };
+ };
+
+ ViewTimeline(DOM::Document&, DOM::AbstractElement subject, ScrollAxis, Inset);
+ virtual ~ViewTimeline() override = default;
+
+ // What decides the progress of the timeline, along its axis, in CSS pixels.
+ struct Metrics {
+ double scroll_offset { 0 };
+ double max_scroll_offset { 0 };
+ // The start and the end of the cover range.
+ double cover_start { 0 };
+ double cover_end { 0 };
+ double subject_size { 0 };
+
+ bool operator==(Metrics const&) const = default;
+ };
+ Optional<Metrics> compute_metrics() const;
+
+ ScrollOffsetInterval interval_for_range_name(Metrics const&, TimelineRangeName) const;
+
+ Inset m_inset;
+ Optional<Metrics> m_last_metrics;
+};
+
+ViewTimelineInset view_timeline_inset_from_ffi(CSS::ComputedValuesFFI::FfiViewTimelineInset const&);
+
+}
diff --git a/Libraries/LibWeb/Animations/ViewTimeline.idl b/Libraries/LibWeb/Animations/ViewTimeline.idl
new file mode 100644
index 00000000000..91449726045
--- /dev/null
+++ b/Libraries/LibWeb/Animations/ViewTimeline.idl
@@ -0,0 +1,16 @@
+// https://drafts.csswg.org/scroll-animations-1/#dictdef-viewtimelineoptions
+dictionary ViewTimelineOptions {
+ required Element subject;
+ ScrollAxis axis = "block";
+ // INTEROP: Blink takes "auto" as a DOMString in the sequence too.
+ (DOMString or sequence<(CSSNumericValue or CSSKeywordValue or DOMString)>) inset = "auto";
+};
+
+// https://drafts.csswg.org/scroll-animations-1/#viewtimeline
+[Exposed=Window]
+interface ViewTimeline : ScrollTimeline {
+ constructor(ViewTimelineOptions options);
+ readonly attribute Element subject;
+ readonly attribute CSSNumericValue startOffset;
+ readonly attribute CSSNumericValue endOffset;
+};
diff --git a/Libraries/LibWeb/CMakeLists.txt b/Libraries/LibWeb/CMakeLists.txt
index 93185c3acd7..86702af189a 100644
--- a/Libraries/LibWeb/CMakeLists.txt
+++ b/Libraries/LibWeb/CMakeLists.txt
@@ -9,8 +9,10 @@ set(SOURCES
Animations/TimeValue.cpp
Animations/DocumentTimeline.cpp
Animations/KeyframeEffect.cpp
+ Animations/NamedTimelines.cpp
Animations/PseudoElementParsing.cpp
Animations/ScrollTimeline.cpp
+ Animations/ViewTimeline.cpp
ARIA/AriaData.cpp
ARIA/ARIAMixin.cpp
ARIA/AttributeNames.cpp
diff --git a/Libraries/LibWeb/CSS/CSSAnimation.cpp b/Libraries/LibWeb/CSS/CSSAnimation.cpp
index 838396f75ea..654e859b877 100644
--- a/Libraries/LibWeb/CSS/CSSAnimation.cpp
+++ b/Libraries/LibWeb/CSS/CSSAnimation.cpp
@@ -7,7 +7,9 @@
#include <LibGC/Heap.h>
#include <LibWeb/Animations/DocumentTimeline.h>
#include <LibWeb/Animations/KeyframeEffect.h>
+#include <LibWeb/Animations/NamedTimelines.h>
#include <LibWeb/Animations/ScrollTimeline.h>
+#include <LibWeb/Animations/ViewTimeline.h>
#include <LibWeb/CSS/CSSAnimation.h>
#include <LibWeb/CSS/PropertyID.h>
#include <LibWeb/DOM/Document.h>
@@ -97,12 +99,21 @@ static bool should_update_timeline(GC::Ptr<Animations::AnimationTimeline> old_ti
GC::Ptr<Animations::AnimationTimeline> const document_timeline = target.document().timeline();
return old_timeline != document_timeline;
}
+ case AnimationTimelineSource::Kind::Named:
+ return old_timeline != target.document().named_timelines().target_timeline(target, requested.name);
+ case AnimationTimelineSource::Kind::View: {
+ auto const* old_view_timeline = as_if<Animations::ViewTimeline>(old_timeline.ptr());
+ return !old_view_timeline
+ || old_view_timeline->subject_internal() != target
+ || old_view_timeline->axis() != Animations::scroll_axis_from_css_axis(requested.axis)
+ || old_view_timeline->inset() != requested.view_inset;
+ }
case AnimationTimelineSource::Kind::Scroll:
break;
}
auto const* old_scroll_timeline = as_if<Animations::ScrollTimeline>(old_timeline.ptr());
- if (!old_scroll_timeline)
+ if (!old_scroll_timeline || is<Animations::ViewTimeline>(*old_scroll_timeline))
return true;
if (old_scroll_timeline->axis() != Animations::scroll_axis_from_css_axis(requested.axis))
@@ -127,6 +138,10 @@ static GC::Ptr<Animations::AnimationTimeline> materialize_timeline(AnimationTime
target.document(),
anonymous_scroll_source(requested, target),
Animations::scroll_axis_from_css_axis(requested.axis));
+ case AnimationTimelineSource::Kind::View:
+ return Animations::ViewTimeline::create(target.document(), target, Animations::scroll_axis_from_css_axis(requested.axis), requested.view_inset);
+ case AnimationTimelineSource::Kind::Named:
+ return target.document().named_timelines().target_timeline(target, requested.name);
}
VERIFY_NOT_REACHED();
}
@@ -182,6 +197,15 @@ void CSSAnimation::apply_css_properties(AnimationProperties const& animation_pro
.composition = animation_properties.composition,
.range = animation_properties.range,
};
+ // NB: An animation that names its timeline looks it up again as the timelines its document declares change, also
+ // while the name finds no timeline.
+ if (animation_properties.timeline.kind == AnimationTimelineSource::Kind::Named) {
+ m_named_timeline_source = NamedTimelineSource { animation_properties.timeline.name, timeline_target };
+ timeline_target.document().named_timelines().track_animation(*this);
+ } else {
+ m_named_timeline_source.clear();
+ }
+
// 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.
if (!update_timeline && m_applied_css_properties == applied_properties)
@@ -329,6 +353,25 @@ WebIDL::ExceptionOr<void> CSSAnimation::set_range_end_for_bindings(Animations::T
return {};
}
+void CSSAnimation::update_named_timeline()
+{
+ if (!m_named_timeline_source.has_value() || m_ignored_css_properties.contains(PropertyID::AnimationTimeline))
+ return;
+ auto const& [name, target] = *m_named_timeline_source;
+ GC::Ptr<Animations::AnimationTimeline> timeline = target.document().named_timelines().target_timeline(target, name);
+ if (timeline == this->timeline())
+ return;
+ HTML::TemporaryExecutionContext context(relevant_settings_object());
+ set_timeline(timeline);
+}
+
+void CSSAnimation::visit_edges(Cell::Visitor& visitor)
+{
+ Base::visit_edges(visitor);
+ if (m_named_timeline_source.has_value())
+ m_named_timeline_source->target.visit(visitor);
+}
+
void CSSAnimation::set_timeline_for_bindings(GC::Ptr<Animations::AnimationTimeline> timeline)
{
// AD-HOC: When the timeline of a CSS animation is modified by the author from JS we should no longer apply changes
diff --git a/Libraries/LibWeb/CSS/CSSAnimation.h b/Libraries/LibWeb/CSS/CSSAnimation.h
index edbe2e0a873..c1222a042c8 100644
--- a/Libraries/LibWeb/CSS/CSSAnimation.h
+++ b/Libraries/LibWeb/CSS/CSSAnimation.h
@@ -39,6 +39,11 @@ public:
virtual WebIDL::ExceptionOr<void> set_range_start_for_bindings(Animations::TimelineRangeBindingValue const&) override;
virtual WebIDL::ExceptionOr<void> set_range_end_for_bindings(Animations::TimelineRangeBindingValue const&) override;
+ // Looks the named timeline the animation follows up again.
+ void update_named_timeline();
+ // A removed animation no longer follows its named timeline.
+ void stop_following_named_timeline() { m_named_timeline_source.clear(); }
+
virtual WebIDL::ExceptionOr<void> set_start_time_for_bindings(Animations::NullableCSSNumberish const&) override;
virtual WebIDL::ExceptionOr<void> set_current_time_for_bindings(Animations::NullableCSSNumberish const&) override;
virtual WebIDL::ExceptionOr<void> set_playback_rate(double) override;
@@ -101,6 +106,14 @@ private:
size_t m_animation_name_index { 0 };
void mark_script_play_state_override();
+
+ virtual void visit_edges(Cell::Visitor&) override;
+
+ struct NamedTimelineSource {
+ Utf16FlyString name;
+ DOM::AbstractElement target;
+ };
+ Optional<NamedTimelineSource> m_named_timeline_source;
};
}
diff --git a/Libraries/LibWeb/CSS/CSSAnimationProperties.h b/Libraries/LibWeb/CSS/CSSAnimationProperties.h
index da192832cc5..2274b35f22a 100644
--- a/Libraries/LibWeb/CSS/CSSAnimationProperties.h
+++ b/Libraries/LibWeb/CSS/CSSAnimationProperties.h
@@ -27,11 +27,15 @@ struct AnimationTimelineSource {
Document,
None,
Scroll,
+ View,
+ Named,
};
Kind kind { Kind::Document };
Scroller scroller {};
Axis axis {};
+ Animations::ViewTimelineInset view_inset {};
+ Utf16FlyString name {};
bool operator==(AnimationTimelineSource const&) const = default;
};
diff --git a/Libraries/LibWeb/CSS/StyleComputer.cpp b/Libraries/LibWeb/CSS/StyleComputer.cpp
index 2f44844032e..8c2e35a906e 100644
--- a/Libraries/LibWeb/CSS/StyleComputer.cpp
+++ b/Libraries/LibWeb/CSS/StyleComputer.cpp
@@ -30,6 +30,7 @@
#include <LibWeb/Animations/AnimationEffect.h>
#include <LibWeb/Animations/DocumentTimeline.h>
#include <LibWeb/Animations/ScrollTimeline.h>
+#include <LibWeb/Animations/ViewTimeline.h>
#include <LibWeb/Bindings/PrincipalHostDefined.h>
#include <LibWeb/CSS/AnimationEvent.h>
#include <LibWeb/CSS/CSSAnimation.h>
@@ -935,6 +936,8 @@ static AnimationProperties animation_properties_from_ffi(ComputedValuesFFI::FfiC
static_assert(to_underlying(AnimationTimelineSource::Kind::Document) == to_underlying(ComputedValuesFFI::FfiAnimationTimelineKind::Document));
static_assert(to_underlying(AnimationTimelineSource::Kind::None) == to_underlying(ComputedValuesFFI::FfiAnimationTimelineKind::None));
static_assert(to_underlying(AnimationTimelineSource::Kind::Scroll) == to_underlying(ComputedValuesFFI::FfiAnimationTimelineKind::Scroll));
+ static_assert(to_underlying(AnimationTimelineSource::Kind::View) == to_underlying(ComputedValuesFFI::FfiAnimationTimelineKind::View));
+ static_assert(to_underlying(AnimationTimelineSource::Kind::Named) == to_underlying(ComputedValuesFFI::FfiAnimationTimelineKind::Named));
return {
.duration = move(duration),
.timing_function = EasingFunction::from_style_value(timing_function),
@@ -949,6 +952,8 @@ static AnimationProperties animation_properties_from_ffi(ComputedValuesFFI::FfiC
.kind = static_cast<AnimationTimelineSource::Kind>(animation.timeline_kind),
.scroller = static_cast<Scroller>(animation.scroll_scroller),
.axis = static_cast<Axis>(animation.scroll_axis),
+ .view_inset = Animations::view_timeline_inset_from_ffi(animation.view_inset),
+ .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 },
@@ -1035,8 +1040,10 @@ void StyleComputer::apply_animation_definitions(DOM::AbstractElement& abstract_e
// Once an animation has started it continues until it ends or the animation-name is removed
// NB: An animation no definition claimed is one whose animation-name entry has gone.
for (size_t i = 0; i < existing_animations.size(); ++i) {
- if (!existing_animation_was_claimed[i])
+ if (!existing_animation_was_claimed[i]) {
existing_animations[i]->cancel(Animations::Animation::ShouldInvalidate::No);
+ existing_animations[i]->stop_following_named_timeline();
+ }
}
// NB: We create animations in reverse definition order so flip it back.
diff --git a/Libraries/LibWeb/DOM/Document.cpp b/Libraries/LibWeb/DOM/Document.cpp
index da62ad26e3f..402b9db75d5 100644
--- a/Libraries/LibWeb/DOM/Document.cpp
+++ b/Libraries/LibWeb/DOM/Document.cpp
@@ -44,6 +44,7 @@
#include <LibWeb/Animations/AnimationPlaybackEvent.h>
#include <LibWeb/Animations/AnimationTimeline.h>
#include <LibWeb/Animations/DocumentTimeline.h>
+#include <LibWeb/Animations/NamedTimelines.h>
#include <LibWeb/Animations/TimeValue.h>
#include <LibWeb/Bindings/CSS.h>
#include <LibWeb/Bindings/Document.h>
@@ -981,6 +982,7 @@ void Document::visit_edges(Cell::Visitor& visitor)
visitor.visit(m_lazy_load_intersection_observer);
visitor.visit(m_visual_viewport);
visitor.visit(m_default_timeline);
+ visitor.visit(m_named_timelines);
visitor.visit(m_scripts_to_execute_when_parsing_has_finished);
visitor.visit(m_scripts_to_execute_in_order_as_soon_as_possible);
visitor.visit(m_scripts_to_execute_as_soon_as_possible);
@@ -8051,6 +8053,13 @@ GC::Ref<Animations::DocumentTimeline> Document::timeline()
return *m_default_timeline;
}
+Animations::NamedTimelines& Document::named_timelines()
+{
+ if (!m_named_timelines)
+ m_named_timelines = Animations::NamedTimelines::create(*this);
+ return *m_named_timelines;
+}
+
void Document::associate_with_timeline(GC::Ref<Animations::AnimationTimeline> timeline)
{
m_associated_animation_timelines.set(timeline);
diff --git a/Libraries/LibWeb/DOM/Document.h b/Libraries/LibWeb/DOM/Document.h
index e226a06a60a..1bb8d835301 100644
--- a/Libraries/LibWeb/DOM/Document.h
+++ b/Libraries/LibWeb/DOM/Document.h
@@ -1201,6 +1201,13 @@ public:
void restore_the_history_object_state(NonnullRefPtr<HTML::SessionHistoryEntry> entry);
GC::Ref<Animations::DocumentTimeline> timeline();
+
+ // The scroll progress timelines and view progress timelines the elements of the document declare by name.
+ Animations::NamedTimelines& named_timelines();
+ bool has_named_timelines() const { return m_named_timelines != nullptr; }
+ // Moves on whenever the timelines an element declares by name, or the timeline names it scopes, may have changed.
+ u64 timeline_declarations_generation() const { return m_timeline_declarations_generation; }
+ void did_change_timeline_declarations() { ++m_timeline_declarations_generation; }
auto const& last_animation_frame_timestamp() const { return m_last_animation_frame_timestamp; }
void associate_with_timeline(GC::Ref<Animations::AnimationTimeline>);
@@ -2204,6 +2211,8 @@ private:
// https://www.w3.org/TR/web-animations-1/#document-default-document-timeline
GC::Ptr<Animations::DocumentTimeline> m_default_timeline;
+ GC::Ptr<Animations::NamedTimelines> m_named_timelines;
+ u64 m_timeline_declarations_generation { 0 };
Optional<double> m_last_animation_frame_timestamp;
// https://www.w3.org/TR/web-animations-1/#pending-animation-event-queue
diff --git a/Libraries/LibWeb/DOM/Element.cpp b/Libraries/LibWeb/DOM/Element.cpp
index 8680a4d01a5..87dba06b9ee 100644
--- a/Libraries/LibWeb/DOM/Element.cpp
+++ b/Libraries/LibWeb/DOM/Element.cpp
@@ -5368,6 +5368,29 @@ void Element::update_animated_properties_for_abstract_element(Badge<Web::Animati
effect.update_computed_properties_for_style(context, abstract_element);
}
+// The animation style group of an installed style, which holds the timelines it declares by name.
+static CSS::ComputedValues::AnimationValues const* installed_animation_values(CSS::InstalledStyle const& style)
+{
+ auto const* payloads = static_cast<void const* const*>(style.payloads());
+ if (!payloads)
+ return nullptr;
+ return static_cast<CSS::ComputedValues::AnimationValues const*>(payloads[CSS::ComputedValues::AnimationValues::style_group_index]);
+}
+
+// Whether two installed styles differ in the timelines they declare by name, or the timeline names they scope.
+static bool timeline_declarations_differ(CSS::InstalledStyle const& old_style, CSS::InstalledStyle const& new_style)
+{
+ auto const* old_values = installed_animation_values(old_style);
+ auto const* new_values = installed_animation_values(new_style);
+ bool const old_declares = old_values && CSS::ComputedValuesFFI::rust_animation_values_declare_timelines(old_values);
+ bool const new_declares = new_values && CSS::ComputedValuesFFI::rust_animation_values_declare_timelines(new_values);
+ if (!old_declares && !new_declares)
+ return false;
+ if (old_declares != new_declares)
+ return true;
+ return old_values != new_values && !CSS::ComputedValuesFFI::rust_animation_values_timeline_declarations_equal(old_values, new_values);
+}
+
void Element::replace_style_record(CSS::StyleRecordID style_record_identity)
{
VERIFY(!style_record_identity || style_node_id() != 0);
@@ -5390,6 +5413,9 @@ void Element::replace_style_record(CSS::StyleRecordID style_record_identity)
// attributes for the layout tree build to resolve, so they follow every record the element takes.
if (is<SVG::SVGGraphicsElement>(*this) && !!style_record_identity)
Layout::publish_svg_style_references(*this);
+ // https://drafts.csswg.org/scroll-animations-1/#timeline-scoping
+ if (timeline_declarations_differ(held_before, m_installed_style))
+ document().did_change_timeline_declarations();
}
// What C++ installs beside a pseudo-element it computes: its element's inheritable environment, or the one its own
diff --git a/Libraries/LibWeb/Forward.h b/Libraries/LibWeb/Forward.h
index 6205d19aa65..cfedd36d3b2 100644
--- a/Libraries/LibWeb/Forward.h
+++ b/Libraries/LibWeb/Forward.h
@@ -74,7 +74,9 @@ class AnimationPlaybackEvent;
class AnimationTimeline;
class DocumentTimeline;
class KeyframeEffect;
+class NamedTimelines;
class ScrollTimeline;
+class ViewTimeline;
}
diff --git a/Libraries/LibWeb/HTML/EventLoop/EventLoop.cpp b/Libraries/LibWeb/HTML/EventLoop/EventLoop.cpp
index 1575330467f..dfded7a4465 100644
--- a/Libraries/LibWeb/HTML/EventLoop/EventLoop.cpp
+++ b/Libraries/LibWeb/HTML/EventLoop/EventLoop.cpp
@@ -13,6 +13,7 @@
#include <LibGC/Heap.h>
#include <LibGC/HeapAccess.h>
#include <LibJS/Runtime/VM.h>
+#include <LibWeb/Animations/NamedTimelines.h>
#include <LibWeb/Animations/ScrollTimeline.h>
#include <LibWeb/Bindings/MainThreadVM.h>
#include <LibWeb/CSS/CSSTransition.h>
@@ -1116,13 +1117,22 @@ static void update_style_and_layout_for_rendering(DOM::Document& document)
TemporaryExecutionContext context { document.relevant_settings_object() };
+ // NB: The animations that name their timeline find the timelines that style update and layout declared. An
+ // animation that moved to another timeline takes its time from it in this frame, so the timelines update their
+ // current time and style and layout run again.
+ bool animations_changed_timeline = false;
+ if (document.has_named_timelines())
+ animations_changed_timeline = document.named_timelines().update_tracked_animations();
+ if (animations_changed_timeline)
+ requires_style_and_layout_update = true;
+
for (auto const& timeline : document.associated_animation_timelines()) {
auto* scroll_timeline = as_if<Animations::ScrollTimeline>(*timeline);
if (!scroll_timeline)
continue;
- if (!scroll_timeline->is_stale())
+ if (!animations_changed_timeline && !scroll_timeline->is_stale())
continue;
// NB: The passed timestamp is ignored for ScrollTimelines so we can just use 0.
@@ -1273,8 +1283,6 @@ void EventLoop::update_the_rendering_after_style_and_layout(Vector<GC::Root<DOM:
}
}
-// Whether the style transaction of `document` in a rendering update may fly beside the event loop, or what keeps it in
-// step.
Layout::RustFFI::FfiFlightBlocker EventLoop::style_flight_blocker(DOM::Document& document) const
{
using Blocker = Layout::RustFFI::FfiFlightBlocker;
@@ -1291,6 +1299,9 @@ Layout::RustFFI::FfiFlightBlocker EventLoop::style_flight_blocker(DOM::Document&
if (is<Animations::ScrollTimeline>(*timeline))
return Blocker::ScrollTimeline;
}
+ // The animations that name their timeline look it up again after style and layout.
+ if (document.has_named_timelines())
+ return Blocker::ScrollTimeline;
return Blocker::None;
}
diff --git a/Libraries/LibWeb/HTML/EventLoop/EventLoop.h b/Libraries/LibWeb/HTML/EventLoop/EventLoop.h
index eb83ef14266..e3674e96eda 100644
--- a/Libraries/LibWeb/HTML/EventLoop/EventLoop.h
+++ b/Libraries/LibWeb/HTML/EventLoop/EventLoop.h
@@ -58,6 +58,10 @@ class WEB_API EventLoop : public JS::Cell {
};
public:
+ // Whether the style transaction of a document in a rendering update may fly beside the event loop, or what keeps it
+ // in step.
+ Layout::RustFFI::FfiFlightBlocker style_flight_blocker(DOM::Document&) const;
+
struct RenderingSchedulerCounters {
u64 update_requests { 0 };
u64 coalesced_update_requests { 0 };
@@ -211,7 +215,6 @@ private:
};
void update_the_rendering_after_style_and_layout(Vector<GC::Root<DOM::Document>> const& docs, double frame_timestamp, u64 update_serial, TakenLayout = TakenLayout::UpToDate);
void finish_rendering_update(double update_start_time);
- Layout::RustFFI::FfiFlightBlocker style_flight_blocker(DOM::Document&) const;
void resume_rendering_update_in_flight();
void finish_ended_rendering_update_in_flight();
bool finish_ended_rendering_update_as_its_layout_flew();
diff --git a/Libraries/LibWeb/Layout/UpdateLayout.cpp b/Libraries/LibWeb/Layout/UpdateLayout.cpp
index 4b84ebc9831..bc4ff97adff 100644
--- a/Libraries/LibWeb/Layout/UpdateLayout.cpp
+++ b/Libraries/LibWeb/Layout/UpdateLayout.cpp
@@ -15,6 +15,7 @@
#include <LibWeb/DOM/Element.h>
#include <LibWeb/DOM/ShadowRoot.h>
#include <LibWeb/HTML/AttributeNames.h>
+#include <LibWeb/HTML/EventLoop/EventLoop.h>
#include <LibWeb/HTML/HTMLObjectElement.h>
#include <LibWeb/HTML/LocalNavigable.h>
#include <LibWeb/Layout/LayoutRustFFI.h>
@@ -321,6 +322,11 @@ bool Document::let_layout_fly(Layout::RustFFI::FfiFlightBlocker blocker)
auto navigable = this->navigable();
if (!navigable || navigable->active_document().ptr() != this || !m_layout_node_arena)
return false;
+ // The style update may have given the document what keeps its layout in step, such as the first animation that
+ // names its timeline.
+ blocker = HTML::main_thread_event_loop().style_flight_blocker(*this);
+ if (blocker != Layout::RustFFI::FfiFlightBlocker::None)
+ return false;
Layout::ForcedReadScope read { *this };
update_highlight_states_if_needed(read);
auto inputs = first_layout_round_inputs();
diff --git a/Libraries/LibWeb/Rust/src/css/style/animations.rs b/Libraries/LibWeb/Rust/src/css/style/animations.rs
index 2cf415ddd49..2f84fc4afe9 100644
--- a/Libraries/LibWeb/Rust/src/css/style/animations.rs
+++ b/Libraries/LibWeb/Rust/src/css/style/animations.rs
@@ -63,14 +63,20 @@ impl FfiAppliedAnimationDefinition {
}
/// Whether applying `self` to an animation that last had `published` applied would leave it
- /// exactly as it is. A scroll timeline is rebuilt from the element's surroundings every time it
- /// is applied, so a definition that names one is never called unchanged, and an animation no
+ /// 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
/// a declaration that has not changed.
#[must_use]
fn would_change_nothing(&self, published: &Self) -> bool {
- self.values.timeline_kind != crate::css::style_compute::FfiAnimationTimelineKind::Scroll as u8
+ use crate::css::style_compute::FfiAnimationTimelineKind;
+ ![
+ FfiAnimationTimelineKind::Scroll as u8,
+ FfiAnimationTimelineKind::View as u8,
+ FfiAnimationTimelineKind::Named as u8,
+ ]
+ .contains(&self.values.timeline_kind)
&& !published.timing_function.is_null()
&& self.values == published.values
&& self.keyframe_set == published.keyframe_set
diff --git a/Libraries/LibWeb/Rust/src/css/style_compute.rs b/Libraries/LibWeb/Rust/src/css/style_compute.rs
index 5d2fbafb006..48ebfeed1aa 100644
--- a/Libraries/LibWeb/Rust/src/css/style_compute.rs
+++ b/Libraries/LibWeb/Rust/src/css/style_compute.rs
@@ -2817,6 +2817,22 @@ pub enum FfiAnimationTimelineKind {
Document,
None,
Scroll,
+ View,
+ Named,
+}
+
+/// The insets of a view progress timeline's visibility range, as the host takes them: each side either auto, which
+/// 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)]
+pub struct FfiViewTimelineInset {
+ pub start_is_auto: bool,
+ pub start_px: f64,
+ pub start_percentage: f64,
+ pub end_is_auto: bool,
+ pub end_px: f64,
+ pub end_percentage: f64,
}
#[repr(C)]
@@ -2834,6 +2850,10 @@ pub struct FfiComputedAnimation {
pub timeline_kind: FfiAnimationTimelineKind,
pub scroll_scroller: u8,
pub scroll_axis: u8,
+ /// The insets of a view() timeline.
+ pub view_inset: FfiViewTimelineInset,
+ /// The name of a named timeline, as a CSS string, or null.
+ pub timeline_name: *const c_void,
/// 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,
@@ -4808,12 +4828,273 @@ fn fly_string_is_ascii(string: &crate::css::css_string::CssString, expected: &[u
.eq(expected.iter().copied().map(u16::from))
}
-fn animation_timeline_descriptor(value: &StyleValueData) -> (FfiAnimationTimelineKind, u8, u8) {
- let default = (FfiAnimationTimelineKind::Document, scroller::NEAREST, axis::BLOCK);
+/// 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 {
+ StyleValueData::Percentage { value } => (0.0, *value),
+ value => {
+ let value = crate::css::computed_value_views::LengthPercentageRef::over(value);
+ let px = value.to_px(CssPixels::default()).to_double();
+ (px, value.to_px(CssPixels::from_integer(100)).to_double() - px)
+ }
+ }
+}
+
+/// 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),
+ value => {
+ let (px, percentage) = length_plus_percentage(value);
+ (false, px, percentage)
+ }
+ };
+ let (start, end) = match value {
+ None => ((true, 0.0, 0.0), (true, 0.0, 0.0)),
+ Some(StyleValueData::ValueList { values, .. }) => match values.as_slice() {
+ [start, end] => (side(start.data()), side(end.data())),
+ [both] => (side(both.data()), side(both.data())),
+ _ => unreachable!("computed view timeline inset must have one or two sides"),
+ },
+ Some(value) => (side(value), side(value)),
+ };
+ FfiViewTimelineInset {
+ start_is_auto: start.0,
+ start_px: start.1,
+ start_percentage: start.2,
+ end_is_auto: end.0,
+ end_px: end.1,
+ end_percentage: end.2,
+ }
+}
+
+/// The insets a computed `view-timeline-inset` item describes, for a timeline the host builds from script.
+///
+/// # Safety
+/// `value` must point at live style value data.
+#[unsafe(no_mangle)]
+pub unsafe extern "C" fn rust_view_timeline_inset(value: *const c_void) -> FfiViewTimelineInset {
+ // SAFETY: Guaranteed by the caller.
+ let value = unsafe { &*value.cast::<StyleValueData>() };
+ let value = match value {
+ StyleValueData::ValueList { values, separator, .. } if *separator == 1 => values.as_slice()[0].data(),
+ value => value,
+ };
+ view_timeline_inset(Some(value))
+}
+
+/// One named timeline an element declares with `scroll-timeline` or `view-timeline`.
+/// https://drafts.csswg.org/scroll-animations-1/#timeline-scoping
+#[repr(C)]
+pub struct FfiTimelineDeclaration {
+ /// The name, as a CSS string.
+ pub name: *const c_void,
+ pub is_view: bool,
+ pub axis: u8,
+ pub view_inset: FfiViewTimelineInset,
+}
+
+/// Hands `declare` the named timelines `values` declares. Of the timelines that share a name, the one handed last is
+/// the one the element defines: names declared later in the naming property take precedence, and scroll progress
+/// timelines take precedence over view progress timelines.
+///
+/// # Safety
+/// `values` must point at a live animation style group, and `declare` must be safe to call with `context`.
+#[unsafe(no_mangle)]
+pub unsafe extern "C" fn rust_animation_values_timeline_declarations(
+ values: &crate::css::computed_value_types::AnimationValues,
+ context: *mut c_void,
+ declare: unsafe extern "C" fn(*mut c_void, *const FfiTimelineDeclaration),
+) {
+ let items = |handle: &crate::css::computed_value_types::ComputedStyleValueHandle| -> Vec<&StyleValueData> {
+ // SAFETY: A computed style group's handles point at retained style values it owns.
+ match unsafe { handle.pointer.cast::<StyleValueData>().as_ref() } {
+ None => Vec::new(),
+ Some(StyleValueData::ValueList { values, separator, .. }) if *separator == 1 => {
+ values.as_slice().iter().map(|value| value.data()).collect()
+ }
+ Some(value) => vec![value],
+ }
+ };
+ let axis_of = |values: &[&StyleValueData], index: usize| match values.get(index % values.len().max(1)) {
+ Some(StyleValueData::Keyword { keyword }) => keyword_to_axis(*keyword).unwrap_or(axis::BLOCK),
+ _ => axis::BLOCK,
+ };
+ let declare_names =
+ |names: Vec<&StyleValueData>, is_view: bool, axes: Vec<&StyleValueData>, insets: Vec<&StyleValueData>| {
+ for (index, name) in names.iter().enumerate() {
+ let StyleValueData::CustomIdent { custom_ident } = name else {
+ continue;
+ };
+ let declaration = FfiTimelineDeclaration {
+ name: custom_ident.as_ptr(),
+ is_view,
+ axis: axis_of(&axes, index),
+ view_inset: view_timeline_inset(insets.get(index % insets.len().max(1)).copied()),
+ };
+ // SAFETY: Guaranteed by the caller.
+ unsafe { declare(context, &raw const declaration) };
+ }
+ };
+ declare_names(
+ items(&values.view_timeline_name),
+ true,
+ items(&values.view_timeline_axis),
+ items(&values.view_timeline_inset),
+ );
+ declare_names(
+ items(&values.scroll_timeline_name),
+ false,
+ items(&values.scroll_timeline_axis),
+ Vec::new(),
+ );
+}
+
+/// The names `timeline-scope` in `values` scopes: none, all of them, or those handed to `scope`.
+/// https://drafts.csswg.org/scroll-animations-1/#timeline-scope
+///
+/// # Safety
+/// `values` must point at a live animation style group, and `scope` must be safe to call with `context`.
+#[unsafe(no_mangle)]
+pub unsafe extern "C" fn rust_animation_values_timeline_scope(
+ values: &crate::css::computed_value_types::AnimationValues,
+ context: *mut c_void,
+ scope: unsafe extern "C" fn(*mut c_void, *const c_void),
+) -> FfiTimelineScope {
+ // SAFETY: A computed style group's handles point at retained style values it owns.
+ let Some(value) = (unsafe { values.timeline_scope.pointer.cast::<StyleValueData>().as_ref() }) else {
+ return FfiTimelineScope::None;
+ };
+ let names: Vec<&StyleValueData> = match value {
+ StyleValueData::Keyword { keyword } if *keyword == keyword::ALL => return FfiTimelineScope::All,
+ StyleValueData::Keyword { .. } => return FfiTimelineScope::None,
+ StyleValueData::ValueList { values, .. } => values.as_slice().iter().map(|value| value.data()).collect(),
+ value => vec![value],
+ };
+ for name in names {
+ if let StyleValueData::CustomIdent { custom_ident } = name {
+ // SAFETY: Guaranteed by the caller.
+ unsafe { scope(context, custom_ident.as_ptr()) };
+ }
+ }
+ FfiTimelineScope::Names
+}
+
+#[repr(u8)]
+#[derive(Clone, Copy, PartialEq)]
+pub enum FfiTimelineScope {
+ None,
+ All,
+ Names,
+}
+
+/// Whether `a` and `b` declare the same named timelines, and scope the same timeline names.
+#[unsafe(no_mangle)]
+pub extern "C" fn rust_animation_values_timeline_declarations_equal(
+ a: &crate::css::computed_value_types::AnimationValues,
+ b: &crate::css::computed_value_types::AnimationValues,
+) -> bool {
+ let same = |a: &crate::css::computed_value_types::ComputedStyleValueHandle,
+ b: &crate::css::computed_value_types::ComputedStyleValueHandle| {
+ // SAFETY: A computed style group's handles point at retained style values it owns.
+ let (a, b) = unsafe {
+ (
+ a.pointer.cast::<StyleValueData>().as_ref(),
+ b.pointer.cast::<StyleValueData>().as_ref(),
+ )
+ };
+ a == b
+ };
+ same(&a.scroll_timeline_name, &b.scroll_timeline_name)
+ && same(&a.scroll_timeline_axis, &b.scroll_timeline_axis)
+ && same(&a.view_timeline_name, &b.view_timeline_name)
+ && same(&a.view_timeline_axis, &b.view_timeline_axis)
+ && same(&a.view_timeline_inset, &b.view_timeline_inset)
+ && same(&a.timeline_scope, &b.timeline_scope)
+}
+
+/// Whether `values` declares a named timeline, or scopes timeline names.
+#[unsafe(no_mangle)]
+pub extern "C" fn rust_animation_values_declare_timelines(
+ values: &crate::css::computed_value_types::AnimationValues,
+) -> bool {
+ fn declares_name(value: &StyleValueData) -> bool {
+ match value {
+ StyleValueData::Keyword { keyword } => *keyword != keyword::NONE,
+ StyleValueData::ValueList { values, .. } => values.as_slice().iter().any(|item| declares_name(item.data())),
+ _ => true,
+ }
+ }
+ let is_declared = |handle: &crate::css::computed_value_types::ComputedStyleValueHandle| {
+ // SAFETY: A computed style group's handles point at retained style values it owns.
+ unsafe { handle.pointer.cast::<StyleValueData>().as_ref() }.is_some_and(declares_name)
+ };
+ is_declared(&values.scroll_timeline_name)
+ || is_declared(&values.view_timeline_name)
+ || is_declared(&values.timeline_scope)
+}
+
+/// Whether a parsed `view-timeline-inset` value has a length in a unit that is not absolute.
+///
+/// # Safety
+/// `value` must point at live style value data.
+#[unsafe(no_mangle)]
+pub unsafe extern "C" fn rust_view_timeline_inset_has_relative_length(value: *const c_void) -> bool {
+ let is_absolute = |unit: u8| {
+ matches!(
+ length_unit_kinds().get(unit as usize),
+ Some(LengthUnitKind::Px | LengthUnitKind::Absolute { .. })
+ )
+ };
+ fn has_relative_length(value: &StyleValueData, is_absolute: &dyn Fn(u8) -> bool) -> bool {
+ match value {
+ StyleValueData::Length { unit, .. } => !is_absolute(*unit),
+ StyleValueData::Calculated { rust_calculation, .. } => !rust_calculation
+ .node()
+ .is_computationally_independent(&|unit| is_absolute(unit), &|_| false),
+ StyleValueData::ValueList { values, .. } => values
+ .as_slice()
+ .iter()
+ .any(|value| has_relative_length(value.data(), is_absolute)),
+ _ => false,
+ }
+ }
+ // SAFETY: Guaranteed by the caller.
+ has_relative_length(unsafe { &*value.cast::<StyleValueData>() }, &is_absolute)
+}
+
+/// The timeline a computed `animation-timeline` item asks for.
+struct AnimationTimelineDescriptor {
+ kind: FfiAnimationTimelineKind,
+ scroller: u8,
+ axis: u8,
+ view_inset: FfiViewTimelineInset,
+ name: *const c_void,
+}
+
+fn animation_timeline_descriptor(value: &StyleValueData) -> AnimationTimelineDescriptor {
+ let descriptor = |kind, scroller, axis| AnimationTimelineDescriptor {
+ kind,
+ scroller,
+ axis,
+ view_inset: view_timeline_inset(None),
+ name: std::ptr::null(),
+ };
+ let optional_axis = |value: &RetainedStyleValueData| {
+ value
+ .optional_data()
+ .map(|value| match value {
+ StyleValueData::Keyword { keyword } => keyword_to_axis(*keyword).unwrap(),
+ _ => unreachable!("computed timeline axis must be a keyword"),
+ })
+ .unwrap_or(axis::BLOCK)
+ };
match value {
- StyleValueData::Keyword { keyword } if *keyword == keyword::AUTO => default,
+ StyleValueData::Keyword { keyword } if *keyword == keyword::AUTO => {
+ descriptor(FfiAnimationTimelineKind::Document, scroller::NEAREST, axis::BLOCK)
+ }
StyleValueData::Keyword { keyword } if *keyword == keyword::NONE => {
- (FfiAnimationTimelineKind::None, scroller::NEAREST, axis::BLOCK)
+ descriptor(FfiAnimationTimelineKind::None, scroller::NEAREST, axis::BLOCK)
}
StyleValueData::Function { name, value } if fly_string_is_ascii(name, b"scroll") => {
let StyleValueData::Tuple { values } = value.data() else {
@@ -4827,16 +5108,28 @@ fn animation_timeline_descriptor(value: &StyleValueData) -> (FfiAnimationTimelin
_ => unreachable!("computed scroll() scroller must be a keyword"),
})
.unwrap_or(scroller::NEAREST);
- let axis = arguments[1]
- .optional_data()
- .map(|value| match value {
- StyleValueData::Keyword { keyword } => keyword_to_axis(*keyword).unwrap(),
- _ => unreachable!("computed scroll() axis must be a keyword"),
- })
- .unwrap_or(axis::BLOCK);
- (FfiAnimationTimelineKind::Scroll, scroller, axis)
+ descriptor(FfiAnimationTimelineKind::Scroll, scroller, optional_axis(&arguments[1]))
+ }
+ // https://drafts.csswg.org/scroll-animations-1/#view-notation
+ StyleValueData::Function { name, value } if fly_string_is_ascii(name, b"view") => {
+ let StyleValueData::Tuple { values } = value.data() else {
+ unreachable!("computed view() timeline must contain a tuple")
+ };
+ let arguments = values.as_slice();
+ AnimationTimelineDescriptor {
+ view_inset: view_timeline_inset(arguments[1].optional_data()),
+ ..descriptor(
+ FfiAnimationTimelineKind::View,
+ scroller::NEAREST,
+ optional_axis(&arguments[0]),
+ )
+ }
}
- _ => default,
+ StyleValueData::CustomIdent { custom_ident } => AnimationTimelineDescriptor {
+ name: custom_ident.as_ptr(),
+ ..descriptor(FfiAnimationTimelineKind::Named, scroller::NEAREST, axis::BLOCK)
+ },
+ _ => descriptor(FfiAnimationTimelineKind::Document, scroller::NEAREST, axis::BLOCK),
}
}
@@ -4855,14 +5148,7 @@ fn animation_range_edge(value: &StyleValueData, default_percentage: f64) -> (u8,
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)
- }
- };
+ let offset = length_plus_percentage;
match value {
StyleValueData::Keyword { keyword } => (range_name(*keyword), 0.0, default_percentage),
StyleValueData::ValueList { values, .. } => {
@@ -5106,8 +5392,7 @@ fn build_computed_animation_list(
StyleValueData::Keyword { keyword } => *keyword,
_ => unreachable!("computed animation enum must be a keyword"),
};
- let (timeline_kind, scroll_scroller, scroll_axis) =
- animation_timeline_descriptor(timeline_values[index % timeline_values.len()].data());
+ let timeline = 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) =
@@ -5125,9 +5410,11 @@ fn build_computed_animation_list(
fill_mode: keyword_to_animation_fill_mode(keyword_value(fill_mode_values)).unwrap(),
composition: keyword_to_animation_composition(keyword_value(composition_values)).unwrap(),
name: name.as_ptr(),
- timeline_kind,
- scroll_scroller,
- scroll_axis,
+ timeline_kind: timeline.kind,
+ scroll_scroller: timeline.scroller,
+ scroll_axis: timeline.axis,
+ view_inset: timeline.view_inset,
+ timeline_name: timeline.name,
range_start_name,
range_start_px,
range_start_percentage,
diff --git a/Libraries/LibWeb/idl_files.cmake b/Libraries/LibWeb/idl_files.cmake
index 05be954340f..b58ee528b68 100644
--- a/Libraries/LibWeb/idl_files.cmake
+++ b/Libraries/LibWeb/idl_files.cmake
@@ -9,6 +9,7 @@ libweb_js_bindings(Animations/AnimationTimeline)
libweb_js_bindings(Animations/DocumentTimeline)
libweb_js_bindings(Animations/KeyframeEffect)
libweb_js_bindings(Animations/ScrollTimeline)
+libweb_js_bindings(Animations/ViewTimeline)
libweb_js_bindings(ARIA/ARIAMixin)
libweb_js_bindings(Clipboard/Clipboard)
libweb_js_bindings(Clipboard/ClipboardEvent)
diff --git a/Tests/LibWeb/Text/expected/all-window-properties.txt b/Tests/LibWeb/Text/expected/all-window-properties.txt
index 5aeac8af90a..c12f67404c9 100644
--- a/Tests/LibWeb/Text/expected/all-window-properties.txt
+++ b/Tests/LibWeb/Text/expected/all-window-properties.txt
@@ -560,6 +560,7 @@ ValidityState
VideoPlaybackQuality
VideoTrack
VideoTrackList
+ViewTimeline
ViewTransition
VisualViewport
WeakMap
diff --git a/Tests/LibWeb/Text/expected/named-timeline-flat-tree-order.txt b/Tests/LibWeb/Text/expected/named-timeline-flat-tree-order.txt
new file mode 100644
index 00000000000..807330b39c7
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/named-timeline-flat-tree-order.txt
@@ -0,0 +1 @@
+source: in-shadow
diff --git a/Tests/LibWeb/Text/expected/scroll-timeline-script-values-without-substitution.txt b/Tests/LibWeb/Text/expected/scroll-timeline-script-values-without-substitution.txt
new file mode 100644
index 00000000000..51b5f1d7fa3
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/scroll-timeline-script-values-without-substitution.txt
@@ -0,0 +1,6 @@
+rangeStart var(--x): TypeError
+rangeStart inherit: TypeError
+rangeStart entry var(--x): TypeError
+rangeStart {}: normal
+inset var(--x): TypeError
+inset inherit: TypeError
diff --git a/Tests/LibWeb/Text/expected/wpt-import/scroll-animations/css/animation-range-ignored.txt b/Tests/LibWeb/Text/expected/wpt-import/scroll-animations/css/animation-range-ignored.txt
new file mode 100644
index 00000000000..f748f01c6c7
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/scroll-animations/css/animation-range-ignored.txt
@@ -0,0 +1,7 @@
+Harness status: OK
+
+Found 2 tests
+
+2 Pass
+Pass Animation API call rangeStart overrides animation-range-start
+Pass Animation API call rangeEnd overrides animation-range-end
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/scroll-animations/css/animation-range-normal-matches-cover.txt b/Tests/LibWeb/Text/expected/wpt-import/scroll-animations/css/animation-range-normal-matches-cover.txt
new file mode 100644
index 00000000000..c7f54576bdd
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/scroll-animations/css/animation-range-normal-matches-cover.txt
@@ -0,0 +1,6 @@
+Harness status: OK
+
+Found 1 tests
+
+1 Pass
+Pass Changing the animation range updates the play state
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/scroll-animations/css/animation-timeline-named-scroll-progress-timeline.tentative.txt b/Tests/LibWeb/Text/expected/wpt-import/scroll-animations/css/animation-timeline-named-scroll-progress-timeline.tentative.txt
new file mode 100644
index 00000000000..dba1d8e63de
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/scroll-animations/css/animation-timeline-named-scroll-progress-timeline.tentative.txt
@@ -0,0 +1,18 @@
+Harness status: OK
+
+Found 12 tests
+
+9 Pass
+3 Fail
+Pass scroll-timeline-name is referenceable in animation-timeline on the declaring element itself
+Pass scroll-timeline-name is referenceable in animation-timeline on that element's descendants
+Pass scroll-timeline-name on an element which is not a scroll-container
+Fail Change in scroll-timeline-name to match animation timeline updates animation.
+Fail Change in scroll-timeline-name to no longer match animation timeline updates animation.
+Pass Timeline lookup updates candidate when closer match available.
+Fail Timeline lookup updates candidate when match becomes available.
+Pass scroll-timeline-axis is block
+Pass scroll-timeline-axis is inline
+Pass scroll-timeline-axis is x
+Pass scroll-timeline-axis is y
+Pass scroll-timeline-axis is mutated
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/scroll-animations/css/animation-timeline-none.txt b/Tests/LibWeb/Text/expected/wpt-import/scroll-animations/css/animation-timeline-none.txt
index 5d95459f25e..8fc72c27059 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/scroll-animations/css/animation-timeline-none.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/scroll-animations/css/animation-timeline-none.txt
@@ -2,7 +2,6 @@ Harness status: OK
Found 2 tests
-1 Pass
-1 Fail
+2 Pass
Pass Animation with animation-timeline:none holds current time at zero
-Fail Animation with unknown timeline name holds current time at zero
\ No newline at end of file
+Pass Animation with unknown timeline name holds current time at zero
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/scroll-animations/css/animation-timeline-view-functional-notation.tentative.txt b/Tests/LibWeb/Text/expected/wpt-import/scroll-animations/css/animation-timeline-view-functional-notation.tentative.txt
new file mode 100644
index 00000000000..03bb703cebd
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/scroll-animations/css/animation-timeline-view-functional-notation.tentative.txt
@@ -0,0 +1,24 @@
+Harness status: OK
+
+Found 18 tests
+
+9 Pass
+9 Fail
+Pass animation-timeline: view() without timeline range name
+Pass animation-timeline: view(50px) without timeline range name
+Pass animation-timeline: view(auto 50px) without timeline range name
+Pass animation-timeline: view(inline) without timeline range name
+Pass animation-timeline: view(x) without timeline range name
+Pass animation-timeline: view(y) without timeline range name
+Pass animation-timeline: view(x 50px) without timeline range name
+Pass animation-timeline: view(50px), view(inline 50px) without timeline range name
+Pass animation-timeline: view(inline) changes to view(inline 50px), withouttimeline range name
+Fail animation-timeline: view()
+Fail animation-timeline: view(50px)
+Fail animation-timeline: view(auto 50px)
+Fail animation-timeline: view(inline)
+Fail animation-timeline: view(x)
+Fail animation-timeline: view(y)
+Fail animation-timeline: view(x 50px)
+Fail animation-timeline: view(), view(inline)
+Fail animation-timeline: view(inline) changes to view(inline 50px)
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/scroll-animations/css/scroll-timeline-range-animation.txt b/Tests/LibWeb/Text/expected/wpt-import/scroll-animations/css/scroll-timeline-range-animation.txt
new file mode 100644
index 00000000000..a4219849ebe
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/scroll-animations/css/scroll-timeline-range-animation.txt
@@ -0,0 +1,13 @@
+Harness status: OK
+
+Found 8 tests
+
+8 Pass
+Pass Animation with ranges [initial, initial]
+Pass Animation with ranges [0%, 100%]
+Pass Animation with ranges [10%, 100%]
+Pass Animation with ranges [0%, 50%]
+Pass Animation with ranges [10%, 50%]
+Pass Animation with ranges [150px, 75em]
+Pass Animation with ranges [calc(1% + 135px), calc(70em + 50px)]
+Pass Animation with ranges [calc(1% + 135px), calc(70em + 50px)] (scoped)
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/scroll-animations/css/timeline-scope-all.txt b/Tests/LibWeb/Text/expected/wpt-import/scroll-animations/css/timeline-scope-all.txt
new file mode 100644
index 00000000000..a8108a9a1e3
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/scroll-animations/css/timeline-scope-all.txt
@@ -0,0 +1,9 @@
+Harness status: OK
+
+Found 3 tests
+
+1 Pass
+2 Fail
+Fail timeline-scope:all scopes all names (basic)
+Fail timeline-scope:all scopes all names (multiple)
+Pass Inner scope is isolated from outer scope
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/scroll-animations/css/timeline-scope.txt b/Tests/LibWeb/Text/expected/wpt-import/scroll-animations/css/timeline-scope.txt
new file mode 100644
index 00000000000..ecbad9a19e6
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/scroll-animations/css/timeline-scope.txt
@@ -0,0 +1,18 @@
+Harness status: OK
+
+Found 12 tests
+
+11 Pass
+1 Fail
+Pass Timelines are visible by default
+Pass Descendant can attach to a timeline under the same timeline-scope
+Pass Timeline outside of the target's scope subtree is inaccessible
+Pass Timeline lookups isn't stopped by timeline-scope if the name doesn't match
+Pass Timeline under a different timeline-scope subtree is not visible to the target.
+Pass Timeline with a different timeline-scope is not visible to the target.
+Pass Dynamically re-attaching
+Pass Dynamically detaching
+Fail Removing/inserting element with attaching timeline
+Pass Ancestor attached element becoming display:none/block
+Pass A timline scope in the ancestor chain
+Pass Timeline search prioritizes ancestors
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/scroll-animations/css/view-timeline-animation.txt b/Tests/LibWeb/Text/expected/wpt-import/scroll-animations/css/view-timeline-animation.txt
new file mode 100644
index 00000000000..6cc5c22e2a4
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/scroll-animations/css/view-timeline-animation.txt
@@ -0,0 +1,8 @@
+Harness status: OK
+
+Found 3 tests
+
+3 Fail
+Fail Default view-timeline
+Fail Horizontal view-timeline
+Fail Multiple view-timelines on the same element
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/scroll-animations/css/view-timeline-dynamic.txt b/Tests/LibWeb/Text/expected/wpt-import/scroll-animations/css/view-timeline-dynamic.txt
new file mode 100644
index 00000000000..8fed78b1c8c
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/scroll-animations/css/view-timeline-dynamic.txt
@@ -0,0 +1,9 @@
+Harness status: OK
+
+Found 4 tests
+
+4 Pass
+Pass Dynamically changing view-timeline attachment
+Pass Dynamically changing view-timeline-axis
+Pass Dynamically changing view-timeline-inset
+Pass Element with scoped view-timeline becoming display:none
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/scroll-animations/css/view-timeline-inset-animation.txt b/Tests/LibWeb/Text/expected/wpt-import/scroll-animations/css/view-timeline-inset-animation.txt
new file mode 100644
index 00000000000..7397482c556
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/scroll-animations/css/view-timeline-inset-animation.txt
@@ -0,0 +1,31 @@
+Harness status: OK
+
+Found 25 tests
+
+18 Pass
+7 Fail
+Pass view-timeline-inset with one value
+Pass view-timeline-inset with two values
+Pass view-timeline-inset with em values
+Pass view-timeline-inset with percentage values
+Pass view-timeline-inset with negative values
+Pass view-timeline-inset with horizontal scroller
+Pass view-timeline-inset with block scroller
+Pass view-timeline-inset with inline scroller
+Pass view-timeline-inset:auto, block
+Pass view-timeline-inset:auto, block, vertical-lr
+Fail view-timeline-inset:auto, block, vertical-rl
+Pass view-timeline-inset:auto, inline
+Pass view-timeline-inset:auto, inline, vertical-rl
+Pass view-timeline-inset:auto, inline, vertical-lr
+Fail view-timeline-inset:auto, inline, rtl
+Fail view-timeline-inset:auto, inline, vertical-rl, rtl
+Fail view-timeline-inset:auto, inline, vertical-lr, rtl
+Pass view-timeline-inset:auto, y
+Pass view-timeline-inset:auto, y, vertical-rl
+Fail view-timeline-inset:auto, y, vertical-rl, rtl
+Pass view-timeline-inset:auto, x
+Fail view-timeline-inset:auto, x, rtl
+Pass view-timeline-inset:auto, x, vertical-lr
+Fail view-timeline-inset:auto, x, vertical-rl
+Pass view-timeline-inset:auto, mix
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/scroll-animations/scroll-timelines/idlharness.window.txt b/Tests/LibWeb/Text/expected/wpt-import/scroll-animations/scroll-timelines/idlharness.window.txt
index 43f2ec02dc9..fe04c22d42e 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/scroll-animations/scroll-timelines/idlharness.window.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/scroll-animations/scroll-timelines/idlharness.window.txt
@@ -2,8 +2,8 @@ Harness status: OK
Found 29 tests
-20 Pass
-9 Fail
+28 Pass
+1 Fail
Pass idl_test setup
Pass idl_test validation
Pass Partial interface Element: member names are unique
@@ -24,12 +24,12 @@ Pass ScrollTimeline must be primary interface of new ScrollTimeline()
Pass Stringification of new ScrollTimeline()
Pass ScrollTimeline interface: new ScrollTimeline() must inherit property "source" with the proper type
Pass ScrollTimeline interface: new ScrollTimeline() must inherit property "axis" with the proper type
-Fail ViewTimeline interface: existence and properties of interface object
+Pass ViewTimeline interface: existence and properties of interface object
Fail ViewTimeline interface object length
-Fail ViewTimeline interface object name
-Fail ViewTimeline interface: existence and properties of interface prototype object
-Fail ViewTimeline interface: existence and properties of interface prototype object's "constructor" property
-Fail ViewTimeline interface: existence and properties of interface prototype object's @@unscopables property
-Fail ViewTimeline interface: attribute subject
-Fail ViewTimeline interface: attribute startOffset
-Fail ViewTimeline interface: attribute endOffset
\ No newline at end of file
+Pass ViewTimeline interface object name
+Pass ViewTimeline interface: existence and properties of interface prototype object
+Pass ViewTimeline interface: existence and properties of interface prototype object's "constructor" property
+Pass ViewTimeline interface: existence and properties of interface prototype object's @@unscopables property
+Pass ViewTimeline interface: attribute subject
+Pass ViewTimeline interface: attribute startOffset
+Pass ViewTimeline interface: attribute endOffset
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/scroll-animations/scroll-timelines/intrinsic-iteration-duration.tentative.txt b/Tests/LibWeb/Text/expected/wpt-import/scroll-animations/scroll-timelines/intrinsic-iteration-duration.tentative.txt
index 611841b5dee..8783fe8179b 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/scroll-animations/scroll-timelines/intrinsic-iteration-duration.tentative.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/scroll-animations/scroll-timelines/intrinsic-iteration-duration.tentative.txt
@@ -2,11 +2,10 @@ Harness status: OK
Found 6 tests
-4 Pass
-2 Fail
+6 Pass
Pass Computed duration in percent even when specified in ms
-Fail Time-based duration normalized to fill animation range.
+Pass Time-based duration normalized to fill animation range.
Pass Time-based duration normalized to preserve proportional delays.
Pass Intrinsic iteration duration fills timeline.
-Fail Intrinsic iteration duration accounts for animation range.
+Pass Intrinsic iteration duration accounts for animation range.
Pass Intrinsic iteration duration accounts for number of iterations
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/scroll-animations/view-timelines/block-view-timeline-current-time.tentative.txt b/Tests/LibWeb/Text/expected/wpt-import/scroll-animations/view-timelines/block-view-timeline-current-time.tentative.txt
new file mode 100644
index 00000000000..dc4266c2a1e
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/scroll-animations/view-timelines/block-view-timeline-current-time.tentative.txt
@@ -0,0 +1,8 @@
+Harness status: OK
+
+Found 3 tests
+
+3 Pass
+Pass View timeline with start and end scroll offsets that do not align with the scroll boundaries
+Pass View timeline does not clamp starting scroll offset at 0
+Pass View timeline does not clamp end scroll offset at max scroll
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/scroll-animations/view-timelines/duration.txt b/Tests/LibWeb/Text/expected/wpt-import/scroll-animations/view-timelines/duration.txt
new file mode 100644
index 00000000000..b43e69e78bb
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/scroll-animations/view-timelines/duration.txt
@@ -0,0 +1,6 @@
+Harness status: OK
+
+Found 1 tests
+
+1 Pass
+Pass The duration of a view timeline is 100%
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/scroll-animations/view-timelines/inline-view-timeline-current-time.tentative.txt b/Tests/LibWeb/Text/expected/wpt-import/scroll-animations/view-timelines/inline-view-timeline-current-time.tentative.txt
new file mode 100644
index 00000000000..d6feb777f6b
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/scroll-animations/view-timelines/inline-view-timeline-current-time.tentative.txt
@@ -0,0 +1,10 @@
+Harness status: OK
+
+Found 4 tests
+
+3 Pass
+1 Fail
+Pass View timeline with start and end scroll offsets that do not align with the scroll boundaries
+Pass View timeline does not clamp starting scroll offset at 0
+Pass View timeline does not clamp end scroll offset at max scroll
+Fail View timeline with container having RTL layout
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/scroll-animations/view-timelines/view-timeline-inset.txt b/Tests/LibWeb/Text/expected/wpt-import/scroll-animations/view-timelines/view-timeline-inset.txt
new file mode 100644
index 00000000000..943e88ea1e0
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/scroll-animations/view-timelines/view-timeline-inset.txt
@@ -0,0 +1,10 @@
+Harness status: OK
+
+Found 5 tests
+
+5 Pass
+Pass View timeline with px based inset.
+Pass View timeline with percent based inset.
+Pass view timeline with inset auto.
+Pass view timeline inset as string
+Pass view timeline with invalid inset
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/scroll-animations/view-timelines/view-timeline-on-display-none-element.txt b/Tests/LibWeb/Text/expected/wpt-import/scroll-animations/view-timelines/view-timeline-on-display-none-element.txt
new file mode 100644
index 00000000000..36f4a58f994
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/scroll-animations/view-timelines/view-timeline-on-display-none-element.txt
@@ -0,0 +1,6 @@
+Harness status: OK
+
+Found 1 tests
+
+1 Pass
+Pass element with display: none should have inactive viewtimeline
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/scroll-animations/view-timelines/view-timeline-range.txt b/Tests/LibWeb/Text/expected/wpt-import/scroll-animations/view-timelines/view-timeline-range.txt
new file mode 100644
index 00000000000..2678ac59283
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/scroll-animations/view-timelines/view-timeline-range.txt
@@ -0,0 +1,13 @@
+Harness status: OK
+
+Found 7 tests
+
+6 Pass
+1 Fail
+Pass View timeline with range as <name> <percent> pair.
+Pass View timeline with range and inferred name or offset.
+Pass View timeline with range as <name> <px> pair.
+Pass View timeline range accepts absolute units.
+Pass View timeline with range as <name> <percent+px> pair.
+Pass View timeline with range as strings.
+Fail View timeline with range using relative units.
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/scroll-animations/view-timelines/view-timeline-source.tentative.txt b/Tests/LibWeb/Text/expected/wpt-import/scroll-animations/view-timelines/view-timeline-source.tentative.txt
new file mode 100644
index 00000000000..04837888302
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/scroll-animations/view-timelines/view-timeline-source.tentative.txt
@@ -0,0 +1,8 @@
+Harness status: OK
+
+Found 3 tests
+
+3 Pass
+Pass Default source for a View timeline is the nearest scroll ancestor to the subject
+Pass View timeline ignores explicitly set source
+Pass View timeline source is null when display:none
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/scroll-animations/view-timelines/view-timeline-subject-size-changes.txt b/Tests/LibWeb/Text/expected/wpt-import/scroll-animations/view-timelines/view-timeline-subject-size-changes.txt
new file mode 100644
index 00000000000..3e78004e545
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/scroll-animations/view-timelines/view-timeline-subject-size-changes.txt
@@ -0,0 +1,6 @@
+Harness status: OK
+
+Found 1 tests
+
+1 Pass
+Pass View timeline with subject size change after the creation of the animation
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/input/named-timeline-flat-tree-order.html b/Tests/LibWeb/Text/input/named-timeline-flat-tree-order.html
new file mode 100644
index 00000000000..45d45b850e6
--- /dev/null
+++ b/Tests/LibWeb/Text/input/named-timeline-flat-tree-order.html
@@ -0,0 +1,24 @@
+<!DOCTYPE html>
+<script src="include.js"></script>
+<style>
+ @keyframes anim { from { translate: 0px; } to { translate: 100px; } }
+ .scroller { overflow: scroll; width: 100px; height: 100px; }
+ .content { height: 300px; }
+ #target { animation: anim 1s linear; animation-timeline: --t; }
+</style>
+<div id="host"><div id="slotted" class="scroller" style="scroll-timeline: --t"><div class="content"></div></div></div>
+<div id="target"></div>
+<script>
+ // The last timeline defined in flat tree order wins, as the spec says. The slotted child comes after the shadow tree's scroller
+ // in shadow-including order, but before it in flat tree order, where it takes the slot's place.
+ asyncTest(async done => {
+ const shadow = document.getElementById("host").attachShadow({ mode: "open" });
+ shadow.innerHTML = `<style>.scroller { overflow: scroll; width: 100px; height: 100px; } .content { height: 300px; }</style>
+ <slot></slot>
+ <div id="in-shadow" class="scroller" style="scroll-timeline: --t"><div class="content"></div></div>`;
+ await new Promise(resolve => requestAnimationFrame(() => requestAnimationFrame(resolve)));
+ const source = document.getElementById("target").getAnimations()[0].timeline.source;
+ println(`source: ${source === shadow.getElementById("in-shadow") ? "in-shadow" : source && source.id}`);
+ done();
+ });
+</script>
diff --git a/Tests/LibWeb/Text/input/scroll-timeline-script-values-without-substitution.html b/Tests/LibWeb/Text/input/scroll-timeline-script-values-without-substitution.html
new file mode 100644
index 00000000000..c768a6811d2
--- /dev/null
+++ b/Tests/LibWeb/Text/input/scroll-timeline-script-values-without-substitution.html
@@ -0,0 +1,28 @@
+<!DOCTYPE html>
+<script src="include.js"></script>
+<div id="scroller" style="overflow: scroll; width: 100px; height: 100px"><div id="target" style="height: 300px"></div></div>
+<script>
+ // Values that script gives a timeline range or a view timeline inset have nothing to substitute var() against or
+ // inherit from, so they are rejected rather than taken as computed values.
+ test(() => {
+ const animation = target.animate({ opacity: [0, 1] }, { timeline: new ScrollTimeline({ source: scroller }) });
+ for (const value of ["var(--x)", "inherit", "entry var(--x)"]) {
+ try {
+ animation.rangeStart = value;
+ println(`rangeStart ${value}: accepted`);
+ } catch (error) {
+ println(`rangeStart ${value}: ${error.name}`);
+ }
+ }
+ animation.rangeStart = {};
+ println(`rangeStart {}: ${animation.rangeStart}`);
+ for (const inset of ["var(--x)", "inherit"]) {
+ try {
+ new ViewTimeline({ subject: target, inset });
+ println(`inset ${inset}: accepted`);
+ } catch (error) {
+ println(`inset ${inset}: ${error.name}`);
+ }
+ }
+ });
+</script>
diff --git a/Tests/LibWeb/Text/input/wpt-import/scroll-animations/css/animation-range-ignored.html b/Tests/LibWeb/Text/input/wpt-import/scroll-animations/css/animation-range-ignored.html
new file mode 100644
index 00000000000..72d044f250c
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/scroll-animations/css/animation-range-ignored.html
@@ -0,0 +1,234 @@
+<!DOCTYPE html>
+<html>
+<head>
+<meta charset="utf-8">
+<link rel="help" src="https://www.w3.org/TR/scroll-animations-1/#named-range-animation-declaration">
+<script src="../../resources/testharness.js"></script>
+<script src="../../resources/testharnessreport.js"></script>
+<script src="../../web-animations/testcommon.js"></script>
+<script src="../../web-animations/resources/keyframe-utils.js"></script>
+<script src="support/testcommon.js"></script>
+<script src="../../scroll-animations/scroll-timelines/testcommon.js"></script>
+<title>Programmatic API overrides animation-range-*</title>
+</head>
+<style type="text/css">
+ #scroller {
+ border: 10px solid lightgray;
+ overflow-y: scroll;
+ overflow-x: hidden;
+ width: 300px;
+ height: 200px;
+ }
+ @keyframes anim {
+ from { margin-left: 0px; }
+ to { margin-left: 100px; }
+ }
+ #target {
+ margin: 800px 0px;
+ width: 100px;
+ height: 100px;
+ z-index: -1;
+ background-color: green;
+ }
+ .animate {
+ animation: anim auto linear;
+ view-timeline: --timeline;
+ animation-timeline: --timeline;
+ animation-range-start: entry 0%;
+ animation-range-end: entry 100%;
+ }
+</style>
+<body>
+ <div id=scroller>
+ <div id=target></div>
+ </div>
+</body>
+<script type="text/javascript">
+ async function runTest() {
+ function startAnimation(t) {
+ target.classList.add('animate');
+ t.add_cleanup(async () => {
+ target.classList.remove('animate');
+ await waitForNextFrame();
+ });
+ return target.getAnimations()[0];
+ }
+
+ promise_test(async t => {
+ // Points of interest:
+ // entry 0% @ 600
+ // entry 100% / contain 0% @ 700
+ // exit 0% / contain 100% @ 800
+ // exit 100% @ 900
+ const anim = startAnimation(t);
+ await anim.ready;
+
+ await runAndWaitForFrameUpdate(() => {
+ scroller.scrollTop = 650;
+ });
+
+ // Timline time = (scroll pos - cover 0%) / (cover 100% - cover 0%) * 100%
+ // = (650 - 600)/(900 - 600) * 100% = 100/6%
+ assert_percents_equal(anim.timeline.currentTime, 100/6,
+ 'timeline\'s current time before style change');
+ assert_percents_equal(anim.startTime, 0,
+ 'animation\'s start time before style change');
+ // Range start of entry 0% aligns with timeline start. Thus, animation's
+ // and timeline's current time are equal.
+ assert_percents_equal(anim.currentTime, 100/6,
+ 'animation\'s current time before style change');
+ // Iteration duration =
+ // (range end - range start) / (cover 100% - cover 0%) * 100%
+ // = (700 - 600) / (900 - 600) = 33.3333%
+ assert_percents_equal(anim.effect.getComputedTiming().duration,
+ 100/3,
+ 'iteration duration before first style change');
+ assert_equals(getComputedStyle(target).marginLeft, '50px',
+ 'margin-left before style change');
+
+ // Step 1: Set the range end programmatically and range start via CSS.
+ // The start time will be respected since not previously set via the
+ // animation API.
+ await runAndWaitForFrameUpdate(() => {
+ anim.rangeEnd = 'contain 100%';
+ target.style.animationRangeStart = 'entry 50%';
+ });
+
+ // Animation range does not affect timeline's currentTime.
+ assert_percents_equal(
+ anim.timeline.currentTime, 100/6,
+ 'timeline\'s current time after first set of range updates');
+ assert_percents_equal(
+ anim.startTime, 100/6,
+ 'animation\'s start time after first set of range updates');
+ // Scroll position aligns with range start.
+ assert_percents_equal(
+ anim.currentTime, 0,
+ 'animation\'s current time after first set of range updates');
+ // Iteration duration =
+ // (range end - range start) / (cover 100% - cover 0%) * 100%
+ // = (800 - 650) / (900 - 600) = 50%
+ assert_percents_equal(
+ anim.effect.getComputedTiming().duration, 50,
+ 'iteration duration after first style change');
+ assert_equals(getComputedStyle(target).marginLeft, '0px',
+ 'margin-left after first set of range updates');
+
+ // Step 2: Programmatically set the range start.
+ // Scroll position is current at entry 50%, thus the animation's current
+ // time is negative.
+ await runAndWaitForFrameUpdate(() => {
+ anim.rangeStart = 'contain 0%';
+ });
+ // animation current time =
+ // (scroll pos - range start) / (cover 100% - cover 0%) * 100%
+ // = (650 - 700) / (900 - 600) * 100% = -100/6%
+ assert_percents_equal(
+ anim.currentTime, -100/6,
+ 'animation\'s current time after second set of range updates');
+ // Iteration duration =
+ // (range end - range start) / (cover 100% - cover 0%) * 100%
+ // = (800 - 700) / (900 - 600) = 33.3333%
+ assert_percents_equal(
+ anim.effect.getComputedTiming().duration, 100/3,
+ 'iteration duration after second style change');
+ assert_equals(getComputedStyle(target).marginLeft, '0px',
+ 'margin-left after second set of range updates');
+
+ // Jump to contain / cover 50%
+ scroller.scrollTop = 750;
+ await waitForNextFrame();
+
+ // animation current time =
+ // (scroll pos - range start) / (cover 100% - cover 0%) * 100%
+ // = (750 - 700) / (900 - 600) * 100% = 100/6%
+ assert_percents_equal(
+ anim.currentTime, 100/6,
+ 'animation\'s current time after bumping scroll position');
+ assert_approx_equals(parseFloat(getComputedStyle(target).marginLeft), 50, 0.125);
+
+ // Step 3: Try to update the range start via CSS. This change must be
+ // ignored since previously set programmatically.
+ await runAndWaitForFrameUpdate(() => {
+ target.style.animationRangeStart = "entry 50%";
+ });
+ assert_percents_equal(
+ anim.currentTime, 100/6,
+ 'Current time unchanged after change to ignored CSS property');
+ assert_approx_equals(parseFloat(getComputedStyle(target).marginLeft), 50, 0.125,
+ 'Margin-left unaffected by change to ignored CSS property');
+
+ }, 'Animation API call rangeStart overrides animation-range-start');
+
+ promise_test(async t => {
+ const anim = startAnimation(t);
+ await anim.ready;
+
+ scroller.scrollTop = 650;
+ await waitForNextFrame();
+
+ // Step 1: Set the range start programmatically and range end via CSS.
+ // The start time will be respected since not previously set via the
+ // animation API.
+ await runAndWaitForFrameUpdate(() => {
+ anim.rangeStart = "entry 50%";
+ target.style.animationRangeEnd = "contain 100%";
+ });
+
+ assert_percents_equal(
+ anim.timeline.currentTime, 100/6,
+ 'timeline\'s current time after first set of range updates');
+ assert_percents_equal(
+ anim.startTime, 100/6,
+ 'animation\'s start time after first set of range updates');
+ assert_percents_equal(
+ anim.currentTime, 0,
+ 'animation\'s current time after first set of range updates');
+ assert_percents_equal(
+ anim.effect.getComputedTiming().duration, 50,
+ 'iteration duration after first style change');
+ assert_equals(getComputedStyle(target).marginLeft, "0px",
+ 'margin-left after first set of range updates');
+
+ // Step 2: Programmatically set the range.
+ // Scroll position is current at entry 50%, thus the animation's current
+ // time is negative.
+ await runAndWaitForFrameUpdate(() => {
+ anim.rangeStart = "contain 0%";
+ anim.rangeEnd = "contain 100%";
+ });
+
+ assert_percents_equal(
+ anim.currentTime, -100/6,
+ 'animation\'s current time after second set of range updates');
+ assert_percents_equal(
+ anim.effect.getComputedTiming().duration, 100/3,
+ 'iteration duration after second style change');
+ assert_equals(getComputedStyle(target).marginLeft, "0px",
+ 'margin-left after second set of range updates');
+
+ // Jump to contain / cover 50%
+ scroller.scrollTop = 750;
+ await waitForNextFrame();
+
+ assert_percents_equal(
+ anim.currentTime, 100/6,
+ 'animation\'s current time after bumping scroll position');
+ assert_approx_equals(parseFloat(getComputedStyle(target).marginLeft), 50, 0.125);
+
+ // Step 3: Try to update the range end via CSS. This change must be
+ // ignored since previously set programmatically.
+ await runAndWaitForFrameUpdate(() => {
+ target.style.animationRangeEnd = "cover 100%";
+ });
+ assert_percents_equal(
+ anim.currentTime, 100/6,
+ 'Current time unchanged after change to ignored CSS property');
+ assert_approx_equals(parseFloat(getComputedStyle(target).marginLeft), 50, 0.125,
+ 'Margin-left unaffected by change to ignored CSS property');
+
+ }, 'Animation API call rangeEnd overrides animation-range-end');
+ }
+
+ window.onload = runTest;
+</script>
diff --git a/Tests/LibWeb/Text/input/wpt-import/scroll-animations/css/animation-range-normal-matches-cover.html b/Tests/LibWeb/Text/input/wpt-import/scroll-animations/css/animation-range-normal-matches-cover.html
new file mode 100644
index 00000000000..1f8508fb26d
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/scroll-animations/css/animation-range-normal-matches-cover.html
@@ -0,0 +1,93 @@
+<!DOCTYPE html>
+<html>
+<head>
+<meta charset="utf-8">
+<link rel="help" src="https://drafts.csswg.org/scroll-animations-1/#named-timeline-range">
+<script src="../../resources/testharness.js"></script>
+<script src="../../resources/testharnessreport.js"></script>
+<script src="../../web-animations/testcommon.js"></script>
+<script src="support/testcommon.js"></script>
+<script src="../../scroll-animations/scroll-timelines/testcommon.js"></script>
+<title>Animation range 'normal' is equivalent to animation range 'cover'</title>
+</head>
+<style type="text/css">
+ @keyframes anim-1 {
+ from { background-color: blue; }
+ to { background-color: white; }
+ }
+ @keyframes anim-2 {
+ from { opacity: 0.3; }
+ to { opacity: 1; }
+ }
+ #scroller {
+ border: 10px solid lightgray;
+ overflow-y: scroll;
+ overflow-x: hidden;
+ width: 300px;
+ height: 200px;
+ }
+ #target {
+ margin-top: 800px;
+ margin-bottom: 800px;
+ margin-left: 10px;
+ margin-right: 10px;
+ width: 100px;
+ height: 100px;
+ z-index: -1;
+ background-color: green;
+ animation: anim-1 auto linear, anim-2 auto linear;
+ animation-range: normal, cover;
+ view-timeline: --t1;
+ animation-timeline: --t1, --t1;
+ }
+</style>
+<body>
+ <div id="scroller">
+ <div id="target"></div>
+ </div>
+</body>
+<script type="text/javascript">
+ async function runTest() {
+ function assert_range_equals(actual, expected) {
+ if (typeof expected == 'string') {
+ assert_equals(actual, expected);
+ } else {
+ assert_equals(actual.rangeName, expected.rangeName);
+ assert_equals(actual.offset.value, expected.offset.value);
+ }
+ }
+
+ promise_test(async t => {
+ anims = target.getAnimations();
+ assert_equals(anims.length, 2, "Expecting 2 animations");
+ await anims[0].ready;
+ await anims[1].ready;
+
+ assert_range_equals(anims[0].rangeStart, "normal");
+ assert_range_equals(anims[0].rangeEnd, "normal");
+ assert_range_equals(anims[1].rangeStart,
+ { rangeName: 'cover', offset: CSS.percent(0) });
+ assert_range_equals(anims[1].rangeEnd,
+ { rangeName: 'cover', offset: CSS.percent(100) });
+
+ await runAndWaitForFrameUpdate(() => {
+ scroller.scrollTop = 600; // Start boundary for cover range.
+ });
+
+ assert_percents_equal(anims[0].currentTime, 0,
+ 'currentTime at start of normal range');
+ assert_percents_equal(anims[1].currentTime, 0,
+ 'currentTime at cover 0%');
+
+ scroller.scrollTop = 900; // End boundary for cover range.
+ await waitForNextFrame();
+
+ assert_percents_equal(anims[0].currentTime, 100,
+ 'currentTime at end of normal range');
+ assert_percents_equal(anims[1].currentTime, 100,
+ 'currentTime at cover 100%');
+ }, 'Changing the animation range updates the play state');
+ }
+
+ window.onload = runTest;
+</script>
diff --git a/Tests/LibWeb/Text/input/wpt-import/scroll-animations/css/animation-timeline-named-scroll-progress-timeline.tentative.html b/Tests/LibWeb/Text/input/wpt-import/scroll-animations/css/animation-timeline-named-scroll-progress-timeline.tentative.html
new file mode 100644
index 00000000000..f6f0dfd8787
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/scroll-animations/css/animation-timeline-named-scroll-progress-timeline.tentative.html
@@ -0,0 +1,421 @@
+<!DOCTYPE html>
+<title>The animation-timeline: scroll-timeline-name</title>
+<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1">
+<link rel="help" src="https://drafts.csswg.org/scroll-animations-1/rewrite#scroll-timelines-named">
+<link rel="help" src="https://github.com/w3c/csswg-drafts/issues/6674">
+<script src="../../resources/testharness.js"></script>
+<script src="../../resources/testharnessreport.js"></script>
+<script src="../../web-animations/testcommon.js"></script>
+<script src="support/testcommon.js"></script>
+<script src="../../scroll-animations/scroll-timelines/testcommon.js"></script>
+<style>
+ @keyframes anim {
+ from { translate: 50px; }
+ to { translate: 150px; }
+ }
+ @keyframes anim-2 {
+ from { z-index: 0; }
+ to { z-index: 100; }
+ }
+
+ #target {
+ width: 100px;
+ height: 100px;
+ }
+ .square {
+ width: 100px;
+ height: 100px;
+ }
+ .square-container {
+ width: 300px;
+ height: 300px;
+ }
+ .scroller {
+ overflow: scroll;
+ }
+ .content {
+ inline-size: 100%;
+ block-size: 100%;
+ padding-inline-end: 100px;
+ padding-block-end: 100px;
+ }
+</style>
+<body>
+<div id="log"></div>
+<script>
+"use strict";
+
+setup(assert_implements_animation_timeline);
+
+function createScroller(t, scrollerSizeClass) {
+ let scroller = document.createElement('div');
+ let className = scrollerSizeClass || 'square';
+ scroller.className = `scroller ${className}`;
+ let content = document.createElement('div');
+ content.className = 'content';
+
+ scroller.appendChild(content);
+
+ t.add_cleanup(function() {
+ content.remove();
+ scroller.remove();
+ });
+
+ return scroller;
+}
+
+function createTarget(t) {
+ let target = document.createElement('div');
+ target.id = 'target';
+
+ t.add_cleanup(function() {
+ target.remove();
+ });
+
+ return target;
+}
+
+function createScrollerAndTarget(t, scrollerSizeClass) {
+ return [createScroller(t, scrollerSizeClass), createTarget(t)];
+}
+
+async function waitForScrollTop(scroller, percentage) {
+ const maxScroll = scroller.scrollHeight - scroller.clientHeight;
+ scroller.scrollTop = maxScroll * percentage / 100;
+ return waitForNextFrame();
+}
+
+async function waitForScrollLeft(scroller, percentage) {
+ const maxScroll = scroller.scrollWidth - scroller.clientWidth;
+ scroller.scrollLeft = maxScroll * percentage / 100;
+ return waitForNextFrame();
+}
+
+// -------------------------
+// Test scroll-timeline-name
+// -------------------------
+
+promise_test(async t => {
+ let target = document.createElement('div');
+ target.id = 'target';
+ target.className = 'scroller';
+ let content = document.createElement('div');
+ content.className = 'content';
+
+ await runAndWaitForFrameUpdate(() => {
+ // <div id='target' class='scroller'>
+ // <div id='content'></div>
+ // </div>
+ document.body.appendChild(target);
+ target.appendChild(content);
+
+ target.style.scrollTimelineName = '--timeline';
+ target.style.animation = "anim 10s linear";
+ target.style.animationTimeline = '--timeline';
+ target.scrollTop = 50; // 50%
+ });
+
+ assert_equals(getComputedStyle(target).translate, '100px');
+
+ content.remove();
+ target.remove();
+}, 'scroll-timeline-name is referenceable in animation-timeline on the ' +
+ 'declaring element itself');
+
+promise_test(async t => {
+ let [parent, target] = createScrollerAndTarget(t, 'square-container');
+
+ await runAndWaitForFrameUpdate(() => {
+ // <div id='parent' class='scroller'>
+ // <div id='target'></div>
+ // <div id='content'></div>
+ // </div>
+ document.body.appendChild(parent);
+ parent.insertBefore(target, parent.firstElementChild);
+
+ parent.style.scrollTimelineName = '--timeline';
+ target.style.animation = "anim 10s linear";
+ target.style.animationTimeline = '--timeline';
+
+ parent.scrollTop = 100; // 50%
+ });
+
+ assert_equals(getComputedStyle(target).translate, '100px');
+}, "scroll-timeline-name is referenceable in animation-timeline on that " +
+ "element's descendants");
+
+promise_test(async t => {
+ let parent = document.createElement('div');
+ parent.className = 'square';
+ parent.style.overflowX = 'clip'; // This makes overflow-y be clip as well.
+ let target = document.createElement('div');
+ target.id = 'target';
+
+ await runAndWaitForFrameUpdate(() => {
+ // <div id='parent' style='overflow-x: clip'>...
+ // <div id='target'></div>
+ // </div>
+ document.body.appendChild(parent);
+ parent.appendChild(target);
+
+ parent.style.scrollTimelineName = '--timeline';
+ target.style.animation = "anim 10s linear";
+ target.style.animationTimeline = '--timeline';
+ });
+
+ assert_equals(getComputedStyle(target).translate, 'none',
+ 'Animation with an unresolved current time');
+
+ target.remove();
+ parent.remove();
+}, 'scroll-timeline-name on an element which is not a scroll-container');
+
+promise_test(async t => {
+ let [scroller, target] = createScrollerAndTarget(t);
+
+ await runAndWaitForFrameUpdate(() => {
+ // <div id='scroller' class='scroller'> ...
+ // <div id='target'></div>
+ // </div>
+
+ document.body.appendChild(scroller);
+ scroller.appendChild(target);
+
+ scroller.style.scrollTimelineName = '--timeline-A';
+ scroller.scrollTop = 50; // 25%
+ target.style.animation = "anim 10s linear";
+ target.style.animationTimeline = '--timeline-B';
+ });
+
+ const anim = target.getAnimations()[0];
+ assert_true(!!anim, 'Failed to create animation');
+ // https://github.com/w3c/csswg-drafts/issues/9256
+ // Animation with unresolved timeline produces no effect.
+ assert_equals(getComputedStyle(target).translate, 'none');
+
+ scroller.style.scrollTimelineName = '--timeline-B';
+ await waitForNextFrame();
+
+ assert_true(!!anim.timeline, 'Failed to create timeline');
+ assert_equals(getComputedStyle(target).translate, '75px');
+}, 'Change in scroll-timeline-name to match animation timeline updates animation.');
+
+promise_test(async t => {
+ let [scroller, target] = createScrollerAndTarget(t);
+
+ await runAndWaitForFrameUpdate(() => {
+ // <div id='scroller' class='scroller'> ...
+ // <div id='target'></div>
+ // </div>
+
+ document.body.appendChild(scroller);
+ scroller.appendChild(target);
+
+ scroller.style.scrollTimelineName = '--timeline-A';
+ scroller.scrollTop = 50; // 25%
+ target.style.animation = "anim 10s linear";
+ target.style.animationTimeline = '--timeline-A';
+ });
+
+ const anim = target.getAnimations()[0];
+ assert_true(!!anim, 'Failed to create animation');
+ assert_true(!!anim.timeline, 'Failed to create timeline');
+ assert_equals(getComputedStyle(target).translate, '75px');
+ assert_percents_equal(anim.startTime, 0);
+ assert_percents_equal(anim.currentTime, 25);
+
+ scroller.style.scrollTimelineName = '--timeline-B';
+ await waitForNextFrame();
+
+ // Switching to an unknown timeline causes the animation to
+ // stop producing the effect.
+ assert_equals(anim.timeline, null, 'Failed to remove timeline');
+ assert_equals(getComputedStyle(target).translate, 'none');
+ assert_equals(anim.startTime, null);
+ assert_equals(anim.currentTime, null);
+}, 'Change in scroll-timeline-name to no longer match animation timeline updates animation.');
+
+promise_test(async t => {
+ let target = createTarget(t);
+ let scroller1 = createScroller(t);
+ let scroller2 = createScroller(t);
+
+ target.style.animation = 'anim 10s linear';
+ target.style.animationTimeline = '--timeline';
+ scroller1.style.scrollTimelineName = '--timeline';
+ scroller1.id = 'A';
+ scroller2.id = 'B';
+
+ await runAndWaitForFrameUpdate(() => {
+ // <div class='scroller' id='A'> ...
+ // <div class='scroller' id='B'> ...
+ // <div id='target'></div>
+ // </div>
+ // </div>
+ document.body.appendChild(scroller1);
+ scroller1.appendChild(scroller2);
+ scroller2.appendChild(target);
+
+ scroller1.style.scrollTimelineName = '--timeline';
+ scroller1.scrollTop = 50; // 25%
+ scroller2.scrollTop = 100; // 50%
+ });
+
+ const anim = target.getAnimations()[0];
+ assert_true(!!anim.timeline, 'Failed to retrieve animation');
+ assert_equals(anim.timeline.source.id, 'A');
+ assert_equals(getComputedStyle(target).translate, '75px');
+
+ scroller2.style.scrollTimelineName = '--timeline';
+ await waitForNextFrame();
+
+ // The timeline should be updated to scroller2.
+ assert_true(!!anim.timeline, 'Animation no longer has a timeline');
+ assert_equals(anim.timeline.source.id, 'B', 'Timeline not updated');
+ assert_equals(getComputedStyle(target).translate, '100px');
+}, 'Timeline lookup updates candidate when closer match available.');
+
+promise_test(async t => {
+ let wrapper = createScroller(t);
+ wrapper.classList.remove('scroller');
+ let target = createTarget(t);
+
+ await runAndWaitForFrameUpdate(() => {
+ // <div id='wrapper'> ...
+ // <div id='target'></div>
+ // </div>
+ document.body.appendChild(wrapper);
+ wrapper.appendChild(target);
+ target.style.animation = "anim 10s linear";
+ target.style.animationTimeline = '--timeline';
+ });
+
+ // Timeline initially cannot be resolved, resulting in an unknown
+ // timeline. The animation produces no effect.
+ // let anim = document.getAnimations()[0];
+ assert_equals(getComputedStyle(target).translate, 'none');
+
+ await runAndWaitForFrameUpdate(() => {
+ // <div id='wrapper' class="scroller"> ...
+ // <div id='target'></div>
+ // </div>
+ wrapper.classList.add('scroller');
+ wrapper.style.scrollTimelineName = '--timeline';
+ wrapper.scrollTop = 50; // 25%
+ });
+
+ // The timeline should be updated to scroller.
+ assert_equals(getComputedStyle(target).translate, '75px');
+}, 'Timeline lookup updates candidate when match becomes available.');
+
+
+// -------------------------
+// Test scroll-timeline-axis
+// -------------------------
+
+promise_test(async t => {
+ let [scroller, target] = createScrollerAndTarget(t);
+ scroller.style.writingMode = 'vertical-lr';
+
+ await runAndWaitForFrameUpdate(() => {
+ // <div id='scroller' class='scroller'> ...
+ // <div id='target'></div>
+ // </div>
+ document.body.appendChild(scroller);
+ scroller.appendChild(target);
+
+ scroller.style.scrollTimeline = '--timeline block';
+ target.style.animation = "anim-2 10s linear";
+ target.style.animationTimeline = '--timeline';
+ });
+
+ await waitForScrollLeft(scroller, 50);
+ assert_equals(getComputedStyle(target).zIndex, '50');
+}, 'scroll-timeline-axis is block');
+
+promise_test(async t => {
+ let [scroller, target] = createScrollerAndTarget(t);
+ scroller.style.writingMode = 'vertical-lr';
+
+ await runAndWaitForFrameUpdate(() => {
+ // <div id='scroller' class='scroller'> ...
+ // <div id='target'></div>
+ // </div>
+ document.body.appendChild(scroller);
+ scroller.appendChild(target);
+
+ scroller.style.scrollTimeline = '--timeline inline';
+ target.style.animation = "anim-2 10s linear";
+ target.style.animationTimeline = '--timeline';
+ });
+
+ await waitForScrollTop(scroller, 50);
+ assert_equals(getComputedStyle(target).zIndex, '50');
+}, 'scroll-timeline-axis is inline');
+
+promise_test(async t => {
+ let [scroller, target] = createScrollerAndTarget(t);
+ scroller.style.writingMode = 'vertical-lr';
+
+ await runAndWaitForFrameUpdate(() => {
+ // <div id='scroller' class='scroller'> ...
+ // <div id='target'></div>
+ // </div>
+ document.body.appendChild(scroller);
+ scroller.appendChild(target);
+
+ scroller.style.scrollTimeline = '--timeline x';
+ target.style.animation = "anim-2 10s linear";
+ target.style.animationTimeline = '--timeline';
+ });
+
+ await waitForScrollLeft(scroller, 50);
+ assert_equals(getComputedStyle(target).zIndex, '50');
+}, 'scroll-timeline-axis is x');
+
+promise_test(async t => {
+ let [scroller, target] = createScrollerAndTarget(t);
+ scroller.style.writingMode = 'vertical-lr';
+
+ await runAndWaitForFrameUpdate(() => {
+ // <div id='scroller' class='scroller'> ...
+ // <div id='target'></div>
+ // </div>
+ document.body.appendChild(scroller);
+ scroller.appendChild(target);
+
+ scroller.style.scrollTimeline = '--timeline y';
+ target.style.animation = "anim-2 10s linear";
+ target.style.animationTimeline = '--timeline';
+ });
+
+ await waitForScrollTop(scroller, 50);
+ assert_equals(getComputedStyle(target).zIndex, '50');
+}, 'scroll-timeline-axis is y');
+
+promise_test(async t => {
+ let [scroller, target] = createScrollerAndTarget(t);
+
+ await runAndWaitForFrameUpdate(() => {
+ // <div id='scroller' class='scroller'> ...
+ // <div id='target'></div>
+ // </div>
+ document.body.appendChild(scroller);
+ scroller.appendChild(target);
+
+ scroller.style.scrollTimeline = '--timeline block';
+ target.style.animation = "anim-2 10s linear";
+ target.style.animationTimeline = '--timeline';
+ });
+
+ await waitForScrollTop(scroller, 25);
+ await waitForScrollLeft(scroller, 75);
+ assert_equals(getComputedStyle(target).zIndex, '25');
+
+ scroller.style.scrollTimelineAxis = 'inline';
+ await waitForNextFrame();
+ assert_equals(getComputedStyle(target).zIndex, '75');
+}, 'scroll-timeline-axis is mutated');
+
+</script>
+</body>
diff --git a/Tests/LibWeb/Text/input/wpt-import/scroll-animations/css/animation-timeline-view-functional-notation.tentative.html b/Tests/LibWeb/Text/input/wpt-import/scroll-animations/css/animation-timeline-view-functional-notation.tentative.html
new file mode 100644
index 00000000000..474aec25a68
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/scroll-animations/css/animation-timeline-view-functional-notation.tentative.html
@@ -0,0 +1,515 @@
+<!DOCTYPE html>
+<title>The animation-timeline: view() notation</title>
+<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1">
+<link rel="help" src="https://drafts.csswg.org/scroll-animations-1/#view-notation">
+<link rel="help" src="https://github.com/w3c/csswg-drafts/issues/7587">
+<script src="../../resources/testharness.js"></script>
+<script src="../../resources/testharnessreport.js"></script>
+<script src="../../web-animations/testcommon.js"></script>
+<script src="support/testcommon.js"></script>
+<style>
+ @keyframes fade-in-out-without-timeline-range {
+ 0% { opacity: 0; }
+ 40% { opacity: 1; }
+ 60% { opacity: 1; }
+ 100% { opacity: 0; }
+ }
+ @keyframes fade-out-without-timeline-range {
+ 0% { opacity: 1; }
+ 100% { opacity: 0; }
+ }
+ @keyframes change-font-size-without-timeline-range {
+ 0% { font-size: 10px; }
+ 100% { font-size: 30px; }
+ }
+ @keyframes fade-in-out {
+ entry 0% { opacity: 0; }
+ entry 100% { opacity: 1; }
+ exit 0% { opacity: 1; }
+ exit 100% { opacity: 0; }
+ }
+ @keyframes fade-out {
+ exit 0% { opacity: 1; }
+ exit 100% { opacity: 0; }
+ }
+ @keyframes change-font-size {
+ exit 0% { font-size: 10px; }
+ exit 100% { font-size: 20px; }
+ }
+ #container {
+ width: 200px;
+ height: 200px;
+ overflow-y: scroll;
+ overflow-x: hidden;
+ }
+ .target {
+ width: 100px;
+ height: 100px;
+ background-color: red;
+ }
+ .content {
+ width: 400px;
+ height: 400px;
+ background-color: blue;
+ }
+</style>
+
+<body>
+<script>
+"use strict";
+
+setup(assert_implements_animation_timeline);
+
+const createTargetWithStuff = function(t, divClasses) {
+ let container = document.createElement('div');
+ container.id = 'container';
+ document.body.appendChild(container);
+
+ // *** When testing inset
+ // <div id='container'>
+ // <div class='content'></div>
+ // <div class='target'></div>
+ // <div class='content'></div>
+ // </div>
+ // *** When testing axis
+ // <div id='container'>
+ // <div class='target'></div>
+ // <div class='content'></div>
+ // </div>
+
+ let divs = [];
+ let target;
+ for(let className of divClasses) {
+ let div = document.createElement('div');
+ div.className = className;
+ container.appendChild(div);
+
+ divs.push(div);
+ if(className === 'target')
+ target = div;
+ }
+
+ if (t && typeof t.add_cleanup === 'function') {
+ t.add_cleanup(() => {
+ for(let div of divs)
+ div.remove();
+ container.remove();
+ });
+ }
+
+ return [container, target];
+};
+
+async function scrollLeft(element, value) {
+ element.scrollLeft = value;
+ await waitForNextFrame();
+}
+
+async function scrollTop(element, value) {
+ element.scrollTop = value;
+ await waitForNextFrame();
+}
+
+// ---------------------------------
+// Tests without timeline range name
+// ---------------------------------
+
+promise_test(async t => {
+ let [container, div] = createTargetWithStuff(t, ['content', 'target', 'content']);
+ await runAndWaitForFrameUpdate(() => {
+ container.style.overflow = 'hidden';
+ div.style.animation = "fade-in-out-without-timeline-range 1s linear forwards";
+ div.style.animationTimeline = "view()";
+
+ });
+ // So the range is [200px, 500px].
+ await scrollTop(container, 200);
+ assert_equals(getComputedStyle(div).opacity, '0', 'At 0%');
+ await scrollTop(container, 260);
+ assert_equals(getComputedStyle(div).opacity, '0.5', 'At 20%');
+ await scrollTop(container, 320);
+ assert_equals(getComputedStyle(div).opacity, '1', 'At 40%');
+
+ await scrollTop(container, 380);
+ assert_equals(getComputedStyle(div).opacity, '1', 'At 60%');
+ await scrollTop(container, 440);
+ assert_equals(getComputedStyle(div).opacity, '0.5', 'At 80%');
+ await scrollTop(container, 500);
+ assert_equals(getComputedStyle(div).opacity, '0', 'At 100%');
+}, 'animation-timeline: view() without timeline range name');
+
+promise_test(async t => {
+ let [container, div] = createTargetWithStuff(t, ['content', 'target', 'content']);
+ await runAndWaitForFrameUpdate(() => {
+ container.style.overflow = 'hidden';
+ div.style.animation = "fade-in-out-without-timeline-range 1s linear forwards";
+ div.style.animationTimeline = "view(50px)";
+ });
+ // So the range is [250px, 450px].
+
+ await scrollTop(container, 250);
+ assert_equals(getComputedStyle(div).opacity, '0', 'At 0%');
+ await scrollTop(container, 290);
+ assert_equals(getComputedStyle(div).opacity, '0.5', 'At 20%');
+ await scrollTop(container, 330);
+ assert_equals(getComputedStyle(div).opacity, '1', 'At 40%');
+
+ await scrollTop(container, 370);
+ assert_equals(getComputedStyle(div).opacity, '1', 'At 60%');
+ await scrollTop(container, 410);
+ assert_equals(getComputedStyle(div).opacity, '0.5', 'At 80%');
+ await scrollTop(container, 450);
+ assert_equals(getComputedStyle(div).opacity, '0', 'At 100%');
+}, 'animation-timeline: view(50px) without timeline range name');
+
+promise_test(async t => {
+ let [container, div] = createTargetWithStuff(t, ['content', 'target', 'content']);
+ await runAndWaitForFrameUpdate(() => {
+ container.style.overflow = 'hidden';
+ div.style.animation = "fade-in-out-without-timeline-range 1s linear forwards";
+ div.style.animationTimeline = "view(auto 50px)";
+ });
+ // So the range is [250px, 500px].
+
+ await scrollTop(container, 250);
+ assert_equals(getComputedStyle(div).opacity, '0', 'At 0%');
+ await scrollTop(container, 300);
+ assert_equals(getComputedStyle(div).opacity, '0.5', 'At 20%');
+ await scrollTop(container, 350);
+ assert_equals(getComputedStyle(div).opacity, '1', 'At 40%');
+
+ await scrollTop(container, 400);
+ assert_equals(getComputedStyle(div).opacity, '1', 'At 60%');
+ await scrollTop(container, 450);
+ assert_equals(getComputedStyle(div).opacity, '0.5', 'At 80%');
+ await scrollTop(container, 500);
+ assert_equals(getComputedStyle(div).opacity, '0', 'At 100%');
+}, 'animation-timeline: view(auto 50px) without timeline range name');
+
+promise_test(async t => {
+ let [container, div] = createTargetWithStuff(t, ['target', 'content']);
+ await runAndWaitForFrameUpdate(() => {
+ container.style.overflow = 'hidden';
+ div.style.animation = "fade-out-without-timeline-range 1s linear forwards";
+ div.style.animationTimeline = "view(inline)";
+ });
+ // So the range is [-200px, 100px], but it is impossible to scroll to the
+ // negative part.
+
+ await scrollLeft(container, 0);
+ assert_approx_equals(parseFloat(getComputedStyle(div).opacity), 0.33333,
+ 0.00001, 'At 66.7%');
+ // Note: 20% for each 60px.
+ await scrollLeft(container, 40);
+ assert_equals(getComputedStyle(div).opacity, '0.2', 'At 80%');
+ await scrollLeft(container, 100);
+ assert_equals(getComputedStyle(div).opacity, '0', 'At 100%');
+}, 'animation-timeline: view(inline) without timeline range name');
+
+promise_test(async t => {
+ let [container, div] = createTargetWithStuff(t, ['target', 'content']);
+ await runAndWaitForFrameUpdate(() => {
+ container.style.overflow = 'hidden';
+ div.style.animation = "fade-out-without-timeline-range 1s linear forwards";
+ div.style.animationTimeline = "view(x)";
+ });
+ // So the range is [-200px, 100px], but it is impossible to scroll to the
+ // negative part.
+
+ await scrollLeft(container, 0);
+ assert_approx_equals(parseFloat(getComputedStyle(div).opacity), 0.33333,
+ 0.00001, 'At 66.7%');
+ // Note: 20% for each 60px.
+ await scrollLeft(container, 40);
+ assert_equals(getComputedStyle(div).opacity, '0.2', 'At 80%');
+ await scrollLeft(container, 100);
+ assert_equals(getComputedStyle(div).opacity, '0', 'At 100%');
+}, 'animation-timeline: view(x) without timeline range name');
+
+promise_test(async t => {
+ let [container, div] = createTargetWithStuff(t, ['target', 'content']);
+ await runAndWaitForFrameUpdate(() => {
+ div.style.animation = "fade-out-without-timeline-range 1s linear forwards";
+ div.style.animationTimeline = "view(y)";
+ });
+ // So the range is [-200px, 100px], but it is impossible to scroll to the
+ // negative part.
+
+ await scrollTop(container, 0);
+ assert_approx_equals(parseFloat(getComputedStyle(div).opacity), 0.33333,
+ 0.00001, 'At 66.7%');
+ // Note: 20% for each 60px.
+ await scrollTop(container, 40);
+ assert_equals(getComputedStyle(div).opacity, '0.2', 'At 80%');
+ await scrollTop(container, 100);
+ assert_equals(getComputedStyle(div).opacity, '0', 'At 100%');
+}, 'animation-timeline: view(y) without timeline range name');
+
+promise_test(async t => {
+ let [container, div] = createTargetWithStuff(t, ['target', 'content']);
+ await runAndWaitForFrameUpdate(() => {
+ container.style.overflow = 'hidden';
+ div.style.animation = "fade-out-without-timeline-range 1s linear forwards";
+ div.style.animationTimeline = "view(x 50px)";
+ });
+ // So the range is [-150px, 50px], but it is impossible to scroll to the
+ // negative part.
+
+ // Note: 25% for each 50px.
+ await scrollLeft(container, 0);
+ assert_equals(getComputedStyle(div).opacity, '0.25', 'At 75%');
+ await scrollLeft(container, 10);
+ assert_equals(getComputedStyle(div).opacity, '0.2', 'At 80%');
+ await scrollLeft(container, 50);
+ assert_equals(getComputedStyle(div).opacity, '0', 'At 100%');
+}, 'animation-timeline: view(x 50px) without timeline range name');
+
+promise_test(async t => {
+ let [container, div] = createTargetWithStuff(t, ['target', 'content']);
+ await runAndWaitForFrameUpdate(() => {
+ container.style.overflow = 'hidden';
+ div.style.animation
+ = "fade-out-without-timeline-range 1s linear forwards, " +
+ "change-font-size-without-timeline-range 1s linear forwards";
+ div.style.animationTimeline = "view(50px), view(inline 50px)";
+ });
+
+ await scrollLeft(container, 0);
+ assert_equals(getComputedStyle(div).fontSize, '25px', 'At 75% inline');
+ await scrollLeft(container, 10);
+ assert_equals(getComputedStyle(div).fontSize, '26px', 'At 80% inline');
+ await scrollLeft(container, 50);
+ assert_equals(getComputedStyle(div).fontSize, '30px', 'At 100% inline');
+
+ await scrollLeft(container, 0);
+
+ await scrollTop(container, 0);
+ assert_equals(getComputedStyle(div).opacity, '0.25', 'At 75% block');
+ await scrollTop(container, 10);
+ assert_equals(getComputedStyle(div).opacity, '0.2', 'At 80% block');
+ await scrollTop(container, 50);
+ assert_equals(getComputedStyle(div).opacity, '0', 'At 100% block');
+
+ await scrollLeft(container, 10);
+ await scrollTop(container, 10);
+ assert_equals(getComputedStyle(div).fontSize, '26px', 'At 80% inline');
+ assert_equals(getComputedStyle(div).opacity, '0.2', 'At 80% block');
+}, 'animation-timeline: view(50px), view(inline 50px) without timeline range ' +
+ 'name');
+
+promise_test(async t => {
+ let [container, div] = createTargetWithStuff(t, ['target', 'content']);
+ await runAndWaitForFrameUpdate(() => {
+ container.style.overflow = 'hidden';
+ div.style.animation = "fade-out-without-timeline-range 1s linear forwards";
+ div.style.animationTimeline = "view(inline)";
+ });
+ await scrollLeft(container, 0);
+ assert_approx_equals(parseFloat(getComputedStyle(div).opacity), 0.33333,
+ 0.00001, 'At 66.7%');
+ await scrollLeft(container, 40);
+ assert_equals(getComputedStyle(div).opacity, '0.2', 'At 80%');
+ await scrollLeft(container, 100);
+ assert_equals(getComputedStyle(div).opacity, '0', 'At 100%');
+
+ div.style.animationTimeline = "view(inline 50px)";
+ await scrollLeft(container, 0);
+ assert_equals(getComputedStyle(div).opacity, '0.25', 'At 75%');
+ await scrollLeft(container, 50);
+ assert_equals(getComputedStyle(div).opacity, '0', 'At 100%');
+}, 'animation-timeline: view(inline) changes to view(inline 50px), without' +
+ 'timeline range name');
+
+
+// ---------------------------------
+// Tests with timeline range name
+// ---------------------------------
+
+promise_test(async t => {
+ let [container, div] = createTargetWithStuff(t, ['content', 'target', 'content']);
+ await runAndWaitForFrameUpdate(() => {
+ div.style.animation = "fade-in-out 1s linear forwards";
+ div.style.animationTimeline = "view()";
+ });
+
+ await scrollTop(container, 200);
+ assert_equals(getComputedStyle(div).opacity, '0', 'At entry 0%');
+ await scrollTop(container, 250);
+ assert_equals(getComputedStyle(div).opacity, '0.5', 'At entry 50%');
+ await scrollTop(container, 300);
+ assert_equals(getComputedStyle(div).opacity, '1', 'At entry 100%');
+
+ await scrollTop(container, 400);
+ assert_equals(getComputedStyle(div).opacity, '1', 'At exit 0%');
+ await scrollTop(container, 450);
+ assert_equals(getComputedStyle(div).opacity, '0.5', 'At exit 50%');
+ await scrollTop(container, 500);
+ assert_equals(getComputedStyle(div).opacity, '0', 'At exit 100%');
+}, 'animation-timeline: view()');
+
+promise_test(async t => {
+ let [container, div] = createTargetWithStuff(t, ['content', 'target', 'content']);
+ await runAndWaitForFrameUpdate(() => {
+ div.style.animation = "fade-in-out 1s linear forwards";
+ div.style.animationTimeline = "view(50px)";
+ });
+
+ await scrollTop(container, 250);
+ assert_equals(getComputedStyle(div).opacity, '0', 'At entry 0%');
+ await scrollTop(container, 300);
+ assert_equals(getComputedStyle(div).opacity, '0.5', 'At entry 50%');
+
+ await scrollTop(container, 350);
+ assert_equals(getComputedStyle(div).opacity, '1', 'At entry 100% & exit 0%');
+
+ await scrollTop(container, 400);
+ assert_equals(getComputedStyle(div).opacity, '0.5', 'At exit 50%');
+ await scrollTop(container, 450);
+ assert_equals(getComputedStyle(div).opacity, '0', 'At exit 100%');
+}, 'animation-timeline: view(50px)');
+
+promise_test(async t => {
+ let [container, div] = createTargetWithStuff(t, ['content', 'target', 'content']);
+ await runAndWaitForFrameUpdate(() => {
+ div.style.animation = "fade-in-out 1s linear forwards";
+ div.style.animationTimeline = "view(auto 50px)";
+ });
+
+ await scrollTop(container, 250);
+ assert_equals(getComputedStyle(div).opacity, '0', 'At entry 0%');
+ await scrollTop(container, 300);
+ assert_equals(getComputedStyle(div).opacity, '0.5', 'At entry 50%');
+ await scrollTop(container, 350);
+ assert_equals(getComputedStyle(div).opacity, '1', 'At entry 100%');
+
+ await scrollTop(container, 400);
+ assert_equals(getComputedStyle(div).opacity, '1', 'At exit 0%');
+ await scrollTop(container, 450);
+ assert_equals(getComputedStyle(div).opacity, '0.5', 'At exit 50%');
+ await scrollTop(container, 500);
+ assert_equals(getComputedStyle(div).opacity, '0', 'At exit 100%');
+}, 'animation-timeline: view(auto 50px)');
+
+promise_test(async t => {
+ let [container, div] = createTargetWithStuff(t, ['target', 'content']);
+ await runAndWaitForFrameUpdate(() => {
+ container.style.overflow = 'scroll';
+ div.style.animation = "fade-out 1s linear forwards";
+ div.style.animationTimeline = "view(inline)";
+ });
+
+ await scrollLeft(container, 0);
+ assert_equals(getComputedStyle(div).opacity, '1', 'At exit 0%');
+ await scrollLeft(container, 50);
+ assert_equals(getComputedStyle(div).opacity, '0.5', 'At exit 50%');
+ await scrollLeft(container, 100);
+ assert_equals(getComputedStyle(div).opacity, '0', 'At exit 100%');
+}, 'animation-timeline: view(inline)');
+
+promise_test(async t => {
+ let [container, div] = createTargetWithStuff(t, ['target', 'content']);
+ await runAndWaitForFrameUpdate(() => {
+ container.style.overflow = 'scroll';
+ div.style.animation = "fade-out 1s linear forwards";
+ div.style.animationTimeline = "view(x)";
+ });
+
+ await scrollLeft(container, 0);
+ assert_equals(getComputedStyle(div).opacity, '1', 'At exit 0%');
+ await scrollLeft(container, 50);
+ assert_equals(getComputedStyle(div).opacity, '0.5', 'At exit 50%');
+ await scrollLeft(container, 100);
+ assert_equals(getComputedStyle(div).opacity, '0', 'At exit 100%');
+}, 'animation-timeline: view(x)');
+
+promise_test(async t => {
+ let [container, div] = createTargetWithStuff(t, ['target', 'content']);
+ await runAndWaitForFrameUpdate(() => {
+ container.style.overflow = 'scroll';
+ div.style.animation = "fade-out 1s linear forwards";
+ div.style.animationTimeline = "view(y)";
+ });
+
+ await scrollTop(container, 0);
+ assert_equals(getComputedStyle(div).opacity, '1', 'At exit 0%');
+ await scrollTop(container, 50);
+ assert_equals(getComputedStyle(div).opacity, '0.5', 'At exit 50%');
+ await scrollTop(container, 100);
+ assert_equals(getComputedStyle(div).opacity, '0', 'At exit 100%');
+}, 'animation-timeline: view(y)');
+
+promise_test(async t => {
+ let [container, div] = createTargetWithStuff(t, ['target', 'content']);
+ await runAndWaitForFrameUpdate(() => {
+ container.style.overflowY = 'hidden';
+ container.style.overflowX = 'scroll';
+ div.style.animation = "fade-out 1s linear forwards";
+ div.style.animationTimeline = "view(x 50px)";
+ });
+
+ await scrollLeft(container, 0);
+ assert_equals(getComputedStyle(div).opacity, '0.5', 'At exit 50%');
+ await scrollLeft(container, 50);
+ assert_equals(getComputedStyle(div).opacity, '0', 'At exit 100%');
+}, 'animation-timeline: view(x 50px)');
+
+promise_test(async t => {
+ let [container, div] = createTargetWithStuff(t, ['target', 'content']);
+ await runAndWaitForFrameUpdate(() => {
+ container.style.overflow = 'scroll';
+ div.style.animation
+ = "fade-out 1s linear forwards, change-font-size 1s linear forwards";
+ div.style.animationTimeline = "view(), view(inline)";
+ });
+
+ const assert_font_size_equals = (expected, description) => {
+ assert_approx_equals(parseFloat(getComputedStyle(div).fontSize), parseFloat(expected), 0.0001, 'At exit 0% inline');
+ };
+
+ await scrollLeft(container, 0);
+ assert_font_size_equals('10px', 'At exit 0% inline');
+ await scrollLeft(container, 50);
+ assert_font_size_equals('15px', 'At exit 50% inline');
+ await scrollLeft(container, 100);
+ assert_font_size_equals('20px', 'At exit 100% inline');
+
+ await scrollLeft(container, 0);
+
+ await scrollTop(container, 0);
+ assert_equals(getComputedStyle(div).opacity, '1', 'At exit 0% block');
+ await scrollTop(container, 50);
+ assert_equals(getComputedStyle(div).opacity, '0.5', 'At exit 50% block');
+ await scrollTop(container, 100);
+ assert_equals(getComputedStyle(div).opacity, '0', 'At exit 100% block');
+
+ await scrollLeft(container, 50);
+ await scrollTop(container, 50);
+ assert_font_size_equals('15px', 'At exit 50% inline');
+ assert_equals(getComputedStyle(div).opacity, '0.5', 'At exit 50% block');
+}, 'animation-timeline: view(), view(inline)');
+
+promise_test(async t => {
+ let [container, div] = createTargetWithStuff(t, ['target', 'content']);
+ await runAndWaitForFrameUpdate(() => {
+ container.style.overflowY = 'hidden';
+ container.style.overflowX = 'scroll';
+ div.style.animation = "fade-out 1s linear forwards";
+ });
+
+ div.style.animationTimeline = "view(inline)";
+ await scrollLeft(container, 0);
+ assert_equals(getComputedStyle(div).opacity, '1', 'At exit 0%');
+ await scrollLeft(container, 50);
+ assert_equals(getComputedStyle(div).opacity, '0.5', 'At exit 50%');
+ await scrollLeft(container, 100);
+ assert_equals(getComputedStyle(div).opacity, '0', 'At exit 100%');
+
+ div.style.animationTimeline = "view(inline 50px)";
+ await scrollLeft(container, 0);
+ assert_equals(getComputedStyle(div).opacity, '0.5', 'At exit 50%');
+ await scrollLeft(container, 50);
+ assert_equals(getComputedStyle(div).opacity, '0', 'At exit 100%');
+}, 'animation-timeline: view(inline) changes to view(inline 50px)');
+
+</script>
+</body>
diff --git a/Tests/LibWeb/Text/input/wpt-import/scroll-animations/css/scroll-timeline-range-animation.html b/Tests/LibWeb/Text/input/wpt-import/scroll-animations/css/scroll-timeline-range-animation.html
new file mode 100644
index 00000000000..078f2f7dac9
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/scroll-animations/css/scroll-timeline-range-animation.html
@@ -0,0 +1,182 @@
+<!DOCTYPE html>
+<title>Scroll timelines and animation attachment ranges</title>
+<link rel="help" src="https://drafts.csswg.org/scroll-animations-1/#named-timeline-range">
+<link rel="help" src="https://drafts.csswg.org/scroll-animations-1/#animation-range">
+<script src="../../resources/testharness.js"></script>
+<script src="../../resources/testharnessreport.js"></script>
+<script src="../../web-animations/testcommon.js"></script>
+<script src="support/testcommon.js"></script>
+<style>
+ @keyframes anim {
+ from { z-index: 0; background-color: skyblue;}
+ to { z-index: 100; background-color: coral; }
+ }
+ #scroller {
+ border: 10px solid lightgray;
+ overflow-y: scroll;
+ width: 200px;
+ height: 200px;
+ }
+ #scroller > div {
+ margin: 800px 0px;
+ width: 100px;
+ height: 100px;
+ }
+ #target {
+ font-size: 10px;
+ background-color: green;
+ z-index: -1;
+ }
+</style>
+<main id=main>
+</main>
+
+<template id=template_without_scope>
+ <div id=scroller class=timeline>
+ <div id=target></div>
+ </div>
+</template>
+
+<template id=template_with_scope>
+ <div id=scope>
+ <div id=target></div>
+ <div id=scroller class=timeline>
+ <div></div>
+ </div>
+ </div>
+</template>
+
+<script>
+ setup(assert_implements_animation_timeline);
+
+ function inflate(t, template) {
+ t.add_cleanup(() => main.replaceChildren());
+ main.append(template.content.cloneNode(true));
+ }
+ async function scrollTop(e, value) {
+ e.scrollTop = value;
+ await waitForNextFrame();
+ }
+ async function waitForAnimationReady(target) {
+ await waitForNextFrame();
+ await Promise.all(target.getAnimations().map(x => x.ready));
+ }
+ async function assertValueAt(scroller, target, args) {
+ await waitForAnimationReady(target);
+ await scrollTop(scroller, args.scrollTop);
+ assert_equals(getComputedStyle(target).zIndex, args.expected.toString());
+ }
+ function test_animation_range(options, template, desc_suffix) {
+ if (template === undefined)
+ template = template_without_scope;
+ if (desc_suffix === undefined)
+ desc_suffix = '';
+
+ promise_test(async (t) => {
+ inflate(t, template);
+ let scroller = main.querySelector('#scroller');
+ let target = main.querySelector('#target');
+ let timeline = main.querySelector('.timeline');
+ let scope = main.querySelector('#scope');
+ let maxScroll = scroller.scrollHeight - scroller.clientHeight;
+
+ if (scope != null) {
+ scope.style.timelineScope = '--t1';
+ }
+
+ timeline.style.scrollTimeline = '--t1';
+ target.style.animation = 'anim auto linear';
+ target.style.animationTimeline = '--t1';
+ target.style.animationRangeStart = options.rangeStart;
+ target.style.animationRangeEnd = options.rangeEnd;
+
+ // Accommodates floating point precision errors at the endpoints.
+ target.style.animationFillMode = 'both';
+
+ // 0%
+ await assertValueAt(scroller, target,
+ { scrollTop: options.startOffset, expected: 0 });
+ // 50%
+ await assertValueAt(scroller, target,
+ { scrollTop: (options.startOffset + options.endOffset) / 2, expected: 50 });
+ // 100%
+ await assertValueAt(scroller, target,
+ { scrollTop: options.endOffset, expected: 100 });
+
+ // Test before/after phases (need to clear the fill mode for that).
+ target.style.animationFillMode = 'initial';
+ let before_scroll = options.startOffset - 10;
+ if (before_scroll >= 0) {
+ await assertValueAt(scroller, target,
+ { scrollTop: options.startOffset - 10, expected: -1 });
+ }
+ let after_scroll = options.startOffset + 10;
+ if (after_scroll <= scroller.maxmum) {
+ await assertValueAt(scroller, target,
+ { scrollTop: options.endOffset + 10, expected: -1 });
+ }
+ // Check 50% again without fill mode.
+ await assertValueAt(scroller, target,
+ { scrollTop: (options.startOffset + options.endOffset) / 2, expected: 50 });
+
+ }, `Animation with ranges [${options.rangeStart}, ${options.rangeEnd}] ${desc_suffix}`.trim());
+ }
+
+ test_animation_range({
+ rangeStart: 'initial',
+ rangeEnd: 'initial',
+ startOffset: 0,
+ endOffset: 1500
+ });
+
+ test_animation_range({
+ rangeStart: '0%',
+ rangeEnd: '100%',
+ startOffset: 0,
+ endOffset: 1500
+ });
+
+ test_animation_range({
+ rangeStart: '10%',
+ rangeEnd: '100%',
+ startOffset: 150,
+ endOffset: 1500
+ });
+
+ test_animation_range({
+ rangeStart: '0%',
+ rangeEnd: '50%',
+ startOffset: 0,
+ endOffset: 750
+ });
+
+ test_animation_range({
+ rangeStart: '10%',
+ rangeEnd: '50%',
+ startOffset: 150,
+ endOffset: 750
+ });
+
+ test_animation_range({
+ rangeStart: '150px',
+ rangeEnd: '75em',
+ startOffset: 150,
+ endOffset: 750
+ });
+
+ test_animation_range({
+ rangeStart: 'calc(1% + 135px)',
+ rangeEnd: 'calc(70em + 50px)',
+ startOffset: 150,
+ endOffset: 750
+ });
+
+ // Test animation-range via timeline-scope.
+ test_animation_range({
+ rangeStart: 'calc(1% + 135px)',
+ rangeEnd: 'calc(70em + 50px)',
+ startOffset: 150,
+ endOffset: 750
+ }, template_with_scope, '(scoped)');
+
+</script>
diff --git a/Tests/LibWeb/Text/input/wpt-import/scroll-animations/css/timeline-scope-all.html b/Tests/LibWeb/Text/input/wpt-import/scroll-animations/css/timeline-scope-all.html
new file mode 100644
index 00000000000..326ade65287
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/scroll-animations/css/timeline-scope-all.html
@@ -0,0 +1,124 @@
+<!DOCTYPE html>
+<title>Behavior of timeline-scope:all</title>
+<link rel="help" src="https://github.com/w3c/csswg-drafts/issues/7759">
+<script src="../../resources/testharness.js"></script>
+<script src="../../resources/testharnessreport.js"></script>
+<script src="../../web-animations/testcommon.js"></script>
+
+<main id=main></main>
+<script>
+ async function inflate(t, template) {
+ t.add_cleanup(() => main.replaceChildren());
+ return runAndWaitForFrameUpdate(() => {
+ main.append(template.content.cloneNode(true));
+ });
+ }
+ async function scrollTop(e, value) {
+ e.scrollTop = value;
+ await waitForNextFrame();
+ }
+</script>
+<style>
+ @keyframes anim {
+ from { width: 0px; }
+ to { width: 200px; }
+ }
+ .scroller {
+ overflow-y: hidden;
+ width: 200px;
+ height: 200px;
+ }
+ .scroller > .content {
+ margin: 400px 0px;
+ width: 100px;
+ height: 100px;
+ background-color: green;
+ }
+ .target {
+ background-color: coral;
+ width: 0px;
+ animation: anim auto linear;
+ }
+ .scope-all {
+ timeline-scope: all;
+ }
+</style>
+
+<template id=timeline_scope_all_basic>
+ <div class="scope-all">
+ <div class=target style="animation-timeline:--mytimeline">Test</div>
+ </div>
+ <div class=scroller style="scroll-timeline-name:--mytimeline">
+ <div class=content></div>
+ </div>
+</template>
+<script>
+ promise_test(async (t) => {
+ await inflate(t, timeline_scope_all_basic);
+ let target = main.querySelector('.target');
+
+ const anim = target.getAnimations()[0];
+ assert_false(!!anim.timeline);
+ }, 'timeline-scope:all scopes all names (basic)');
+</script>
+
+
+<template id=timeline_scope_all_multiple>
+ <div class="scope-all">
+ <div class=target style="animation-timeline:--t1">Test</div>
+ <div class=target style="animation-timeline:--t2">Test</div>
+ </div>
+ <div class=scroller style="scroll-timeline-name:--t1, --t2">
+ <div class=content></div>
+ </div>
+</template>
+<script>
+ promise_test(async (t) => {
+ await inflate(t, timeline_scope_all_multiple);
+ let scroller = main.querySelector('.scroller');
+ let target1 = main.querySelector('.target:nth-child(1)');
+ let target2 = main.querySelector('.target:nth-child(2)');
+
+ const anim1 = target1.getAnimations()[0];
+ assert_false(!!anim1.timeline);
+ const anim2 = target2.getAnimations()[0];
+ assert_false(!!anim2.timeline);
+ }, 'timeline-scope:all scopes all names (multiple)');
+</script>
+
+
+<!--
+ This test has one element with timeline-scope:all inside another
+ element with timeline-scope:all, each associated with different scrollers
+ (at different scroll offsets).
+-->
+<template id=inner_scope_isolation>
+ <div class=scope-all>
+ <div class=target style="animation-timeline:--t1">Test</div>
+ <div class=scroller style="scroll-timeline: --t1">
+ <div class=content>
+ <!-- Inner scope -->
+ <div class=scope-all>
+ <div class=target style="animation-timeline:--t1">Test</div>
+ <div class=scroller style="scroll-timeline: --t1">
+ <div class=content></div>
+ </div>
+ </div>
+ </div>
+ </div>
+ </div>
+</template>
+<script>
+ promise_test(async (t) => {
+ await inflate(t, inner_scope_isolation);
+ let outer_scroller = main.querySelector('.scroller');
+ let inner_scroller = main.querySelector('.scroller .scroller');
+ let outer_target = main.querySelector('.target');
+ let inner_target = main.querySelector('.scroller .target');
+ await scrollTop(outer_scroller, 350); // 50%
+ await scrollTop(inner_scroller, 140); // 20%
+ assert_equals(getComputedStyle(outer_target).width, '100px'); // 0px => 200px, 50%
+ // Timeline lookup stopped by the inner scope.
+ assert_equals(getComputedStyle(inner_target).width, '40px'); // 0px => 200px, 20%
+ }, 'Inner scope is isolated from outer scope');
+</script>
diff --git a/Tests/LibWeb/Text/input/wpt-import/scroll-animations/css/timeline-scope.html b/Tests/LibWeb/Text/input/wpt-import/scroll-animations/css/timeline-scope.html
new file mode 100644
index 00000000000..97fc81df31a
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/scroll-animations/css/timeline-scope.html
@@ -0,0 +1,361 @@
+<!DOCTYPE html>
+<title>Behavior of the timeline-scope property</title>
+<link rel="help" src="https://github.com/w3c/csswg-drafts/issues/7759">
+<script src="../../resources/testharness.js"></script>
+<script src="../../resources/testharnessreport.js"></script>
+<script src="../../web-animations/testcommon.js"></script>
+
+<main id=main></main>
+<script>
+ async function inflate(t, template) {
+ t.add_cleanup(() => main.replaceChildren());
+ return runAndWaitForFrameUpdate(() => {
+ main.append(template.content.cloneNode(true));
+ });
+ }
+
+ async function scrollTop(e, value) {
+ e.scrollTop = value;
+ await waitForNextFrame();
+ }
+</script>
+<style>
+ @keyframes anim {
+ from { width: 0px; }
+ to { width: 200px; }
+ }
+
+ .scroller {
+ overflow-y: hidden;
+ width: 200px;
+ height: 200px;
+ }
+ .scroller > .content {
+ margin: 400px 0px;
+ width: 100px;
+ height: 100px;
+ background-color: green;
+ }
+ .target {
+ background-color: coral;
+ width: 0px;
+ animation: anim auto linear;
+ animation-timeline: --t1;
+ }
+ .timeline {
+ scroll-timeline-name: --t1;
+ }
+ .scope {
+ timeline-scope: --t1;
+ }
+
+</style>
+
+<!-- Basic Behavior -->
+
+<template id=default_visible>
+ <div class=target>Test</div>
+ <div class="scroller timeline">
+ <div class=content></div>
+ </div>
+</template>
+<script>
+ promise_test(async (t) => {
+ await inflate(t, default_visible);
+ let scroller = main.querySelector('.scroller');
+ let target = main.querySelector('.target');
+
+ const anim = target.getAnimations()[0];
+ await anim.ready;
+
+ await scrollTop(scroller, 350); // 50%
+ assert_equals(getComputedStyle(target).width, '100px'); // 0px => 200px, 50%
+ }, 'Timelines are visible by default');
+</script>
+
+<template id=visible_in_scope_subtree>
+ <div class="scope">
+ <div class=target>Test</div>
+ <div class="scroller timeline">
+ <div class=content></div>
+ </div>
+ </div>
+</template>
+<script>
+ promise_test(async (t) => {
+ await inflate(t, visible_in_scope_subtree);
+ let scroller = main.querySelector('.scroller');
+ let target = main.querySelector('.target');
+
+ const anim = target.getAnimations()[0];
+ await anim.ready;
+
+ await scrollTop(scroller, 350); // 50%
+ assert_equals(getComputedStyle(target).width, '100px'); // 0px => 200px, 50%
+ }, 'Descendant can attach to a timeline under the same timeline-scope');
+</script>
+
+<template id=out_of_scope_subtree>
+ <div class="scope">
+ <div class=target>Test</div>
+ </div>
+ <div class="scroller timeline">
+ <div class=content></div>
+ </div>
+</template>
+<script>
+ promise_test(async (t) => {
+ await inflate(t, out_of_scope_subtree);
+ let scroller = main.querySelector('.scroller');
+ let target = main.querySelector('.target');
+ await scrollTop(scroller, 350); // 50%
+ assert_equals(getComputedStyle(target).width, '0px');
+ }, 'Timeline outside of the target\'s scope subtree is inaccessible');
+</script>
+
+<template id=out_of_scope_subtree_different_name>
+ <div style="timeline-scope: --t2;">
+ <div class=target>Test</div>
+ </div>
+ <div class="scroller timeline">
+ <div class=content></div>
+ </div>
+</template>
+<script>
+ promise_test(async (t) => {
+ await inflate(t, out_of_scope_subtree_different_name);
+ let scroller = main.querySelector('.scroller');
+ let target = main.querySelector('.target');
+ await scrollTop(scroller, 350); // 50%
+ assert_equals(getComputedStyle(target).width, '100px');
+ }, 'Timeline lookups isn\'t stopped by timeline-scope if the name doesn\'t match');
+</script>
+
+<template id=tree_order_out_of_scope>
+ <div class=target>Test</div>
+ <div>
+ <div class="scroller timeline">
+ <div class=content></div>
+ </div>
+ </div>
+ <div class=scope>
+ <div class="scroller timeline">
+ <div class=content></div>
+ </div>
+ </div>
+</template>
+<script>
+ promise_test(async (t) => {
+ await inflate(t, tree_order_out_of_scope);
+ let scrollers = main.querySelectorAll('.scroller');
+ assert_equals(scrollers.length, 2);
+ let target = main.querySelector('.target');
+ await scrollTop(scrollers[0], 350); // 50%
+ await scrollTop(scrollers[1], 175); // 25%
+ // scrollers[1] is later in tree order, but should not be visible.
+ assert_equals(getComputedStyle(target).width, '100px');
+ }, 'Timeline under a different timeline-scope subtree is not visible to the target.');
+</script>
+
+<template id=tree_order_out_of_scope_self>
+ <div class=target>Test</div>
+ <div class="scroller timeline">
+ <div class=content></div>
+ </div>
+ <div class="scope scroller timeline">
+ <div class=content></div>
+ </div>
+</template>
+<script>
+ promise_test(async (t) => {
+ await inflate(t, tree_order_out_of_scope_self);
+ let scrollers = main.querySelectorAll('.scroller');
+ assert_equals(scrollers.length, 2);
+ let target = main.querySelector('.target');
+ await scrollTop(scrollers[0], 350); // 50%
+ await scrollTop(scrollers[1], 175); // 25%
+ // scrollers[1] is later in tree order, but should not be visible.
+ assert_equals(getComputedStyle(target).width, '100px');
+ }, 'Timeline with a different timeline-scope is not visible to the target.');
+</script>
+
+<!-- Dynamic Reattachment -->
+
+<template id=scoped_timeline_reattach>
+ <div class="scope">
+ <div class=target>Test</div>
+ <div class="scroller timeline">
+ <div class=content></div>
+ </div>
+ <div class="scroller">
+ <div class=content></div>
+ </div>
+ </div>
+</template>
+<script>
+ promise_test(async (t) => {
+ await inflate(t, scoped_timeline_reattach);
+ let scrollers = main.querySelectorAll('.scroller');
+ assert_equals(scrollers.length, 2);
+ let target = main.querySelector('.target');
+ await scrollTop(scrollers[0], 350); // 50%
+ await scrollTop(scrollers[1], 175); // 25%
+
+ // Attached to scrollers[0].
+ assert_equals(getComputedStyle(target).width, '100px'); // 0px => 200px, 50%
+
+ // Reattach to scrollers[1].
+ await runAndWaitForFrameUpdate(() => {
+ scrollers[0].classList.remove('timeline');
+ scrollers[1].classList.add('timeline');
+ });
+
+ assert_equals(getComputedStyle(target).width, '50px'); // 0px => 200px, 25%
+ }, 'Dynamically re-attaching');
+</script>
+
+<template id=scoped_timeline_dynamic_detach>
+ <div class="scope">
+ <div class=target>Test</div>
+ <div class="scroller timeline">
+ <div class=content></div>
+ </div>
+ <div class="scroller timeline">
+ <div class=content></div>
+ </div>
+ </div>
+</template>
+<script>
+ promise_test(async (t) => {
+ await inflate(t, scoped_timeline_dynamic_detach);
+ let scrollers = main.querySelectorAll('.scroller');
+ assert_equals(scrollers.length, 2);
+ let target = main.querySelector('.target');
+ await scrollTop(scrollers[0], 350); // 50%
+ await scrollTop(scrollers[1], 175); // 25%
+
+ // Attached to two timelines initially:
+ // Resolve conflict by selecting last match in flat tree order.
+ assert_equals(getComputedStyle(target).width, '50px');
+
+ // Detach scrollers[1].
+ await runAndWaitForFrameUpdate(() => {
+ scrollers[1].classList.remove('timeline');
+ });
+
+ assert_equals(getComputedStyle(target).width, '100px'); // 0px => 200px, 50%
+
+ // Also detach scrollers[0].
+ scrollers[0].classList.remove('timeline');
+
+ await waitForNextFrame();
+ assert_equals(getComputedStyle(target).width, '0px');
+ }, 'Dynamically detaching');
+</script>
+
+<template id=scoped_timeline_attached_removed>
+ <div class="scope">
+ <div class=target>Test</div>
+ <div class="scroller timeline">
+ <div class=content></div>
+ </div>
+ </div>
+</template>
+<script>
+ promise_test(async (t) => {
+ await inflate(t, scoped_timeline_attached_removed);
+ let scroller = main.querySelector('.scroller');
+ let target = main.querySelector('.target');
+ await scrollTop(scroller, 350); // 50%
+ assert_equals(getComputedStyle(target).width, '100px'); // 0px => 200px, 50%
+
+ let scroller_parent = scroller.parentElement;
+ scroller.remove();
+ await waitForNextFrame();
+ assert_equals(getComputedStyle(target).width, '0px');
+
+ scroller_parent.append(scroller);
+ await scrollTop(scroller, 350); // 50%
+ assert_equals(getComputedStyle(target).width, '100px'); // 0px => 200px, 50%
+ }, 'Removing/inserting element with attaching timeline');
+</script>
+
+<template id=scoped_timeline_attached_display_none>
+ <div class="scope">
+ <div class=target>Test</div>
+ <div class="scroller timeline">
+ <div class=content></div>
+ </div>
+ </div>
+</template>
+<script>
+ promise_test(async (t) => {
+ await inflate(t, scoped_timeline_attached_display_none);
+ let scroller = main.querySelector('.scroller');
+ let target = main.querySelector('.target');
+ await scrollTop(scroller, 350); // 50%
+ assert_equals(getComputedStyle(target).width, '100px'); // 0px => 200px, 50%
+
+ scroller.style.display = 'none';
+ await waitForNextFrame();
+ assert_equals(getComputedStyle(target).width, '0px');
+
+ scroller.style.display = 'block';
+ await scrollTop(scroller, 350); // 50%
+ assert_equals(getComputedStyle(target).width, '100px'); // 0px => 200px, 50%
+ }, 'Ancestor attached element becoming display:none/block');
+</script>
+
+<template id=scoped_timeline_appearing>
+ <div class=target>Test</div>
+ <div class="container scope">
+ <div class="scroller timeline">
+ <div class=content></div>
+ </div>
+ </div>
+</template>
+<script>
+ promise_test(async (t) => {
+ await inflate(t, scoped_timeline_appearing);
+ let container = main.querySelector('.container');
+ let scroller = main.querySelector('.scroller');
+ let target = main.querySelector('.target');
+
+ await scrollTop(scroller, 350); // 50%
+
+ // Not attached to any timeline initially.
+ assert_equals(getComputedStyle(target).width, '0px');
+
+ // Remove the scoping.
+ container.classList.remove('scope');
+ await waitForNextFrame();
+ assert_equals(getComputedStyle(target).width, '100px'); // 0px => 200px, 50%
+
+ // Add back the scoping.
+ container.classList.add('scope');
+ await waitForNextFrame();
+ assert_equals(getComputedStyle(target).width, '0px');
+ }, 'A timline scope in the ancestor chain');
+</script>
+
+<template id=scroll_timeline_prioritize_ancestor>
+ <div class=scope>
+ <div class="scroller timeline">
+ <div class=content>
+ <div class=target>Test</div>
+ <div class="scroller timeline">
+ <div class=content></div>
+ </div>
+ </div>
+ </div>
+ </div>
+</template>
+<script>
+ promise_test(async (t) => {
+ await inflate(t, scroll_timeline_prioritize_ancestor);
+ let scroller = main.querySelector('.scroller');
+ let target = main.querySelector('.target');
+ await scrollTop(scroller, 350); // 50%
+ assert_equals(getComputedStyle(target).width, '100px'); // 0px => 200px, 50%
+ }, 'Timeline search prioritizes ancestors');
+</script>
diff --git a/Tests/LibWeb/Text/input/wpt-import/scroll-animations/css/view-timeline-animation.html b/Tests/LibWeb/Text/input/wpt-import/scroll-animations/css/view-timeline-animation.html
new file mode 100644
index 00000000000..0c2bcc29d83
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/scroll-animations/css/view-timeline-animation.html
@@ -0,0 +1,242 @@
+<!DOCTYPE html>
+<title>Animations using view-timeline</title>
+<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1">
+<link rel="help" src="https://drafts.csswg.org/scroll-animations-1/#view-timelines-named">
+<script src="../../resources/testharness.js"></script>
+<script src="../../resources/testharnessreport.js"></script>
+<script src="../../web-animations/testcommon.js"></script>
+<script src="support/testcommon.js"></script>
+<style>
+ @keyframes anim {
+ from { z-index: 0; }
+ to { z-index: 100; }
+ }
+ .vertical-scroller {
+ overflow: auto;
+ width: 100px;
+ height: 100px;
+ }
+ .vertical-scroller > div {
+ height: 50px;
+ z-index: -1;
+ }
+ .horizontal-scroller {
+ overflow: auto;
+ width: 100px;
+ height: 100px;
+ writing-mode: vertical-lr;
+ }
+ .horizontal-scroller > div {
+ width: 50px;
+ z-index: -1;
+ }
+</style>
+<main id=main></main>
+<script>
+ setup(assert_implements_animation_timeline);
+
+ function inflate(t, template) {
+ t.add_cleanup(() => main.replaceChildren());
+ main.append(template.content.cloneNode(true));
+ }
+ async function scrollTop(e, value) {
+ e.scrollTop = value;
+ await waitForNextFrame();
+ }
+ async function scrollLeft(e, value) {
+ e.scrollLeft = value;
+ await waitForNextFrame();
+ }
+</script>
+
+<template id=default_view_timeline>
+ <style>
+ #target {
+ view-timeline: --t1;
+ animation: anim 1s linear forwards;
+ animation-timeline: --t1;
+ }
+ </style>
+ <div id=scroller class=vertical-scroller>
+ <div></div> <!-- [0px, 50px] -->
+ <div></div> <!-- [50px, 100px] -->
+ <div></div> <!-- [100px, 150px] -->
+ <div id=target></div> <!-- [150px, 200px] -->
+ <div></div> <!-- [200px, 250px] -->
+ <div></div> <!-- [250px, 300px] -->
+ <div></div> <!-- [300px, 350px] -->
+ </div>
+</template>
+<script>
+ promise_test(async (t) => {
+ inflate(t, default_view_timeline);
+ assert_equals(getComputedStyle(target).zIndex, '-1');
+ await scrollTop(scroller, 25);
+ assert_equals(getComputedStyle(target).zIndex, '-1');
+ await scrollTop(scroller, 50); // 0% (enter 0%)
+ assert_equals(getComputedStyle(target).zIndex, '0');
+ await scrollTop(scroller, 125); // 50%
+ assert_equals(getComputedStyle(target).zIndex, '50');
+ await scrollTop(scroller, 200); // 100% (exit 100%)
+ assert_equals(getComputedStyle(target).zIndex, '100');
+ await scrollTop(scroller, 201); // now over the 100% scroll offset, but "fill: forwards" lets the animation apply.
+ assert_equals(getComputedStyle(target).zIndex, '100');
+ document.getAnimations()[0].effect.updateTiming( { fill: 'none' });
+ assert_equals(getComputedStyle(target).zIndex, '-1');
+ await scrollTop(scroller, 200); // now back to the 100% scroll offset.
+ assert_equals(getComputedStyle(target).zIndex, '100');
+ }, 'Default view-timeline');
+</script>
+
+<template id=horizontal_timeline>
+ <style>
+ #target {
+ view-timeline: --t1 x;
+ animation: anim 1s linear forwards;
+ animation-timeline: --t1;
+ }
+ </style>
+ <div id=scroller class=horizontal-scroller>
+ <div></div> <!-- [0px, 50px] -->
+ <div></div> <!-- [50px, 100px] -->
+ <div></div> <!-- [100px, 150px] -->
+ <div id=target></div> <!-- [150px, 200px] -->
+ <div></div> <!-- [200px, 250px] -->
+ <div></div> <!-- [250px, 300px] -->
+ <div></div> <!-- [300px, 350px] -->
+ </div>
+</template>
+<script>
+ promise_test(async (t) => {
+ inflate(t, horizontal_timeline);
+ assert_equals(getComputedStyle(target).zIndex, '-1');
+ await scrollLeft(scroller, 25);
+ assert_equals(getComputedStyle(target).zIndex, '-1');
+ await scrollLeft(scroller, 50); // 0% (enter 0%)
+ assert_equals(getComputedStyle(target).zIndex, '0');
+ await scrollLeft(scroller, 125); // 50%
+ assert_equals(getComputedStyle(target).zIndex, '50');
+ await scrollLeft(scroller, 200); // 100% (exit 100%)
+ assert_equals(getComputedStyle(target).zIndex, '100');
+ await scrollLeft(scroller, 201); // now over the 100% scroll offset, but "fill: forwards" lets the animation apply.
+ assert_equals(getComputedStyle(target).zIndex, '100');
+ document.getAnimations()[0].effect.updateTiming( { fill: 'none' });
+ assert_equals(getComputedStyle(target).zIndex, '-1');
+ await scrollLeft(scroller, 200); // now back to the 100% scroll offset.
+ assert_equals(getComputedStyle(target).zIndex, '100');
+ }, 'Horizontal view-timeline');
+</script>
+
+<template id=multiple_timelines>
+ <style>
+ #timelines {
+ view-timeline: --tv y, --th x;
+ background-color: red;
+ }
+ #scroller {
+ width: 100px;
+ height: 100px;
+ overflow: hidden;
+ display: grid;
+ grid-template-columns: 50px 50px 50px 50px 50px 50px 50px;
+ grid-template-row: 50px 50px 50px 50px 50px 50px 50px;
+ timeline-scope: --tv, --th;
+ }
+ #scroller > div {
+ z-index: -1;
+ width: 50px;
+ height: 50px;
+ }
+ #target_v {
+ animation: anim 1s linear forwards;
+ animation-timeline: --tv;
+ }
+ #target_h {
+ animation: anim 1s linear forwards;
+ animation-timeline: --th;
+ }
+ </style>
+ <div id=scroller>
+ <!-- Created dynamically -->
+ </div>
+</template>
+<script>
+ promise_test(async (t) => {
+ inflate(t, multiple_timelines);
+
+ // Create a 350px x 350px grid (7x7 items of 50x50px each), with the
+ // timelines at item [3,3], an element attached to the horizontal timeline
+ // at [4,3], and an element attached to the vertical timeline at [3,4].
+
+ // x x x x x x x
+ // x x x x x x x
+ // x x x x x x x
+ // x x x T H x x
+ // x x x V x x x
+ // x x x x x x x
+ // x x x x x x x
+ // x x x x x x x
+
+ let grid_size = 7;
+ for (let i = 0; i < (grid_size*grid_size); ++i) {
+ let div = document.createElement('div');
+ if (i == (3 * grid_size + 3))
+ div.id = 'timelines';
+ if (i == (3 * grid_size + 4))
+ div.id = 'target_h';
+ if (i == (4 * grid_size + 3))
+ div.id = 'target_v';
+ scroller.append(div);
+ }
+
+ assert_equals(getComputedStyle(target_v).zIndex, '-1');
+ assert_equals(getComputedStyle(target_h).zIndex, '-1');
+
+ // First scroll vertically.
+ await scrollTop(scroller, 25);
+ assert_equals(getComputedStyle(target_v).zIndex, '-1');
+ assert_equals(getComputedStyle(target_h).zIndex, '-1');
+ await scrollTop(scroller, 50); // 0% (enter 0%)
+ assert_equals(getComputedStyle(target_v).zIndex, '0');
+ assert_equals(getComputedStyle(target_h).zIndex, '-1');
+ await scrollTop(scroller, 125); // 50%
+ assert_equals(getComputedStyle(target_v).zIndex, '50');
+ assert_equals(getComputedStyle(target_h).zIndex, '-1');
+ await scrollTop(scroller, 200); // 100% (exit 100%)
+ assert_equals(getComputedStyle(target_v).zIndex, '100');
+ assert_equals(getComputedStyle(target_h).zIndex, '-1');
+ await scrollTop(scroller, 201); // now over the 100% scroll offset, but "fill: forwards" lets the animation apply.
+ assert_equals(getComputedStyle(target_v).zIndex, '100');
+ assert_equals(getComputedStyle(target_h).zIndex, '-1');
+ document.getElementById('target_v').getAnimations()[0].
+ effect.updateTiming({ fill: 'none' });
+ assert_equals(getComputedStyle(target_v).zIndex, '-1');
+ assert_equals(getComputedStyle(target_h).zIndex, '-1');
+
+ // Then horizontally.
+ await scrollLeft(scroller, 25);
+ assert_equals(getComputedStyle(target_v).zIndex, '-1');
+ assert_equals(getComputedStyle(target_h).zIndex, '-1');
+ await scrollLeft(scroller, 50); // 0% (enter 0%)
+ assert_equals(getComputedStyle(target_v).zIndex, '-1');
+ assert_equals(getComputedStyle(target_h).zIndex, '0');
+ await scrollLeft(scroller, 125); // 50%
+ assert_equals(getComputedStyle(target_v).zIndex, '-1');
+ assert_equals(getComputedStyle(target_h).zIndex, '50');
+ await scrollLeft(scroller, 200); // 100% (exit 100%)
+ assert_equals(getComputedStyle(target_v).zIndex, '-1');
+ assert_equals(getComputedStyle(target_h).zIndex, '100');
+ await scrollLeft(scroller, 201); // now over the 100% scroll offset, but "fill: forwards" lets the animation apply.
+ assert_equals(getComputedStyle(target_v).zIndex, '-1');
+ assert_equals(getComputedStyle(target_h).zIndex, '100');
+ document.getElementById('target_h').getAnimations()[0].
+ effect.updateTiming({ fill: 'none' });
+ assert_equals(getComputedStyle(target_v).zIndex, '-1');
+ assert_equals(getComputedStyle(target_h).zIndex, '-1');
+
+ await scrollTop(scroller, 200); // now back to the 100% scroll offset.
+ await scrollLeft(scroller, 200); // now back to the 100% scroll offset.
+ assert_equals(getComputedStyle(target_v).zIndex, '100');
+ assert_equals(getComputedStyle(target_h).zIndex, '100');
+ }, 'Multiple view-timelines on the same element');
+</script>
diff --git a/Tests/LibWeb/Text/input/wpt-import/scroll-animations/css/view-timeline-dynamic.html b/Tests/LibWeb/Text/input/wpt-import/scroll-animations/css/view-timeline-dynamic.html
new file mode 100644
index 00000000000..d10ec6983e6
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/scroll-animations/css/view-timeline-dynamic.html
@@ -0,0 +1,200 @@
+<!DOCTYPE html>
+<title>Changes to view-timeline are reflected in dependent elements</title>
+<link rel="help" src="https://drafts.csswg.org/scroll-animations-1/#view-timeline-shorthand">
+<script src="../../resources/testharness.js"></script>
+<script src="../../resources/testharnessreport.js"></script>
+<script src="../../web-animations/testcommon.js"></script>
+<script src="support/testcommon.js"></script>
+<style>
+ @keyframes anim {
+ from { z-index: 0; }
+ to { z-index: 100; }
+ }
+ .scroller {
+ overflow: hidden;
+ width: 100px;
+ height: 100px;
+ }
+ .scroller > div {
+ height: 100px;
+ }
+ #target {
+ height: 0px;
+ z-index: -1;
+ }
+</style>
+<main id=main></main>
+<script>
+ setup(assert_implements_animation_timeline);
+
+ function inflate(t, template) {
+ t.add_cleanup(() => main.replaceChildren());
+ main.append(template.content.cloneNode(true));
+ main.offsetTop;
+ }
+ async function scrollTop(e, value) {
+ e.scrollTop = value;
+ await waitForNextFrame();
+ }
+ async function scrollLeft(e, value) {
+ e.scrollLeft = value;
+ await waitForNextFrame();
+ }
+</script>
+
+<template id=dynamic_view_timeline_attachment>
+ <style>
+ #scroller {
+ timeline-scope: --t1;
+ }
+ .timeline {
+ view-timeline: --t1;
+ }
+ #target {
+ animation: anim 1s linear;
+ animation-timeline: --t1;
+ }
+ </style>
+ <div id=scroller class=scroller>
+ <div id=div75></div>
+ <div id=div25></div>
+ <div id=div_before></div>
+ <div id=target></div>
+ </div>
+</template>
+<script>
+ promise_test(async (t) => {
+ inflate(t, dynamic_view_timeline_attachment);
+
+ await scrollTop(scroller, 50);
+
+ // scrollTop=50 is 75% for div75.
+ div75.classList.add('timeline');
+ await waitForCSSScrollTimelineStyle();
+ assert_equals(getComputedStyle(target).zIndex, '75', 'div75');
+
+ // Identical timelines in div75 and div25 creates a naming conflict that is
+ // resolved to the last match in tree order.
+ div25.classList.add('timeline');
+ await waitForCSSScrollTimelineStyle();
+ assert_equals(getComputedStyle(target).zIndex, '25', 'div25');
+ // Removing the timeline from div75 removes the conflict resolution.
+ div75.classList.remove('timeline');
+ await waitForCSSScrollTimelineStyle();
+ assert_equals(getComputedStyle(target).zIndex, '25', 'div25');
+
+ // scrollTop=50 is before the timeline start for div_before.
+ div25.classList.remove('timeline');
+ div_before.classList.add('timeline');
+ await waitForCSSScrollTimelineStyle();
+ assert_equals(getComputedStyle(target).zIndex, '-1', 'ahead of div_before');
+ // Scroll to 25% (for div_before) to verify that we're linked to that
+ // timeline.
+ await scrollTop(scroller, 150);
+ assert_equals(getComputedStyle(target).zIndex, '25', 'div_before');
+
+ // Linking the timeline back to div25 verifies that the new scrollTop=150 is
+ // actually at 75%.
+ div_before.classList.remove('timeline');
+ div25.classList.add('timeline');
+ await waitForCSSScrollTimelineStyle();
+ assert_equals(getComputedStyle(target).zIndex, '75', 'div25 again');
+ }, 'Dynamically changing view-timeline attachment');
+</script>
+
+<template id=dynamic_view_timeline_axis>
+ <style>
+ #timeline {
+ view-timeline: --t1;
+ width: 100px;
+ height: 100px;
+ margin: 100px;
+ }
+ #target {
+ animation: anim 1s linear;
+ animation-timeline: --t1;
+ }
+ </style>
+ <div id=scroller class=scroller>
+ <div id=timeline style="background: red;">
+ <div id=target></div>
+ </div>
+ </div>
+</template>
+<script>
+ promise_test(async (t) => {
+ inflate(t, dynamic_view_timeline_axis);
+
+ await scrollTop(scroller, 50); // 25% (vertical)
+ await scrollLeft(scroller, 20); // 10% (horizontal)
+
+ assert_equals(getComputedStyle(target).zIndex, '25', 'vertical');
+ timeline.style.viewTimelineAxis = 'x';
+ await waitForCSSScrollTimelineStyle();
+ assert_equals(getComputedStyle(target).zIndex, '10', 'horizontal');
+ }, 'Dynamically changing view-timeline-axis');
+</script>
+
+<template id=dynamic_view_timeline_inset>
+ <style>
+ #timeline {
+ width: 100px;
+ height: 100px;
+ margin: 100px;
+ view-timeline: --t1;
+ }
+ #target {
+ animation: anim 1s linear;
+ animation-timeline: --t1;
+ }
+ </style>
+ <div id=scroller class=scroller>
+ <div id=timeline style="background: red;">
+ <div id=target></div>
+ </div>
+ </div>
+</template>
+<script>
+ promise_test(async (t) => {
+ inflate(t, dynamic_view_timeline_inset);
+
+ await scrollTop(scroller, 50); // 25% (without inset).
+
+ assert_equals(getComputedStyle(target).zIndex, '25', 'without inset');
+ timeline.style.viewTimelineInset = '0px 50px';
+ await waitForCSSScrollTimelineStyle();
+ assert_equals(getComputedStyle(target).zIndex, '0', 'with inset');
+ }, 'Dynamically changing view-timeline-inset');
+</script>
+
+<template id=timeline_display_none>
+ <style>
+ #scroller {
+ timeline-scope: --t1;
+ }
+ #timeline {
+ view-timeline: --t1;
+ }
+ #target {
+ animation: anim 1s linear;
+ animation-timeline: --t1;
+ }
+ </style>
+ <div id=scroller class=scroller>
+ <div></div>
+ <div id=timeline></div>
+ <div id=target></div>
+ </div>
+</template>
+<script>
+ promise_test(async (t) => {
+ inflate(t, timeline_display_none);
+
+ await scrollTop(scroller, 50);
+ assert_equals(getComputedStyle(target).zIndex, '25', 'display:block');
+ timeline.style.display = 'none';
+ await waitForNextFrame();
+ // The timeline became inactive.
+ assert_equals(getComputedStyle(target).zIndex, '-1', 'display:none');
+ }, 'Element with scoped view-timeline becoming display:none');
+</script>
diff --git a/Tests/LibWeb/Text/input/wpt-import/scroll-animations/css/view-timeline-inset-animation.html b/Tests/LibWeb/Text/input/wpt-import/scroll-animations/css/view-timeline-inset-animation.html
new file mode 100644
index 00000000000..3cdb923f10b
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/scroll-animations/css/view-timeline-inset-animation.html
@@ -0,0 +1,802 @@
+<!DOCTYPE html>
+<title>Animations using view-timeline-inset</title>
+<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1">
+<link rel="help" src="https://drafts.csswg.org/scroll-animations-1/#propdef-view-timeline-inset">
+<script src="../../resources/testharness.js"></script>
+<script src="../../resources/testharnessreport.js"></script>
+<script src="../../web-animations/testcommon.js"></script>
+<script src="support/testcommon.js"></script>
+<style>
+ @keyframes anim {
+ from { z-index: 0; }
+ to { z-index: 100; }
+ }
+ #scroller {
+ overflow: hidden;
+ width: 80px;
+ height: 100px;
+ }
+
+ #container {
+ position: relative;
+ width: 350px;
+ height: 350px;
+ }
+
+ #target {
+ position: absolute;
+ left: 150px;
+ top: 150px;
+ width: 50px;
+ height: 50px;
+ z-index: -1;
+ }
+</style>
+<main id=main></main>
+<script>
+ setup(assert_implements_animation_timeline);
+
+ function inflate(t, template) {
+ t.add_cleanup(() => main.replaceChildren());
+ main.append(template.content.cloneNode(true));
+ }
+ async function scrollTop(e, value) {
+ e.scrollTop = value;
+ await waitForNextFrame();
+ }
+ async function scrollLeft(e, value) {
+ e.scrollLeft = value;
+ await waitForNextFrame();
+ }
+ async function assertValueAt(scroller, target, args) {
+ if (args.scrollTop !== undefined)
+ await scrollTop(scroller, args.scrollTop);
+ if (args.scrollLeft !== undefined)
+ await scrollLeft(scroller, args.scrollLeft);
+ assert_equals(getComputedStyle(target).zIndex, args.expected.toString());
+ }
+</script>
+
+<!--
+ Explanation of scroll positions
+ ===============================
+
+ Please note the following:
+
+ - The scroller has a width x height of 80x100px.
+ - The content is 350x350px
+ - The subject is 50x50px centered within the content.
+
+ This means that, for vertical direction scrolling, assuming no insets:
+
+ - The start offset is 50px (scroller height + 50px is 150px, which consumes
+ exactly the white space of the content).
+ - The end offset is 200px (this is where the bottom edge of the scroller has
+ just cleared the content).
+ - The halfway point is (50px + 200px) / 2 = 125px.
+
+ For horizontal direction scrolling, assuming no insets:
+
+ - The start offset is 70px (scroller width + 70px is 150px, which consumes
+ exactly the white space of the content).
+ - The end offset is 200px (this is where the left edge of the scroller has
+ just cleared the content).
+ - The halfway point is (70px + 200px) / 2 = 135px.
+
+ The start and end insets will adjust the start and end offsets accordingly,
+ and the expectations in this file explicitly write out those adjustments.
+ For example, if the start offset is normally 50px, but there's an inset of
+ 10px, we'll expect 50px + 10px rather than 60px.
+
+ Halfway-point expectations write out the adjustment from the "normal"
+ halfway-point, e.g. for start-inset:10px and end-inset:20px, we expect
+ "125px + 5px" since (20-10)/2 == 5.
+
+ Finally, note that for right-to-left and bottom-to-top scrolling directions
+ scroll offsets go the in the negative direction. This is why some expectations
+ negate all the offsets.
+-->
+
+<template id=test_one_value>
+ <style>
+ #target {
+ view-timeline: --t1;
+ view-timeline-inset: 10px;
+ animation: anim 1s linear forwards;
+ animation-timeline: --t1;
+ }
+ </style>
+ <div id=scroller class=vertical>
+ <div id="container">
+ <div id=target></div>
+ </div>
+ </div>
+</template>
+<script>
+ promise_test(async (t) => {
+ inflate(t, test_one_value);
+ await assertValueAt(scroller, target, { scrollTop:50, expected:-1 });
+ await assertValueAt(scroller, target, { scrollTop:50 + 10, expected:0 }); // 0%
+ await assertValueAt(scroller, target, { scrollTop:125 + 0, expected:50 }); // 50%
+ await assertValueAt(scroller, target, { scrollTop:200 - 10, expected:100 }); // 100%
+ }, 'view-timeline-inset with one value');
+</script>
+<template id=test_two_values>
+ <style>
+ #target {
+ view-timeline: --t1;
+ view-timeline-inset: 10px 20px;
+ animation: anim 1s linear forwards;
+ animation-timeline: --t1;
+ }
+ </style>
+ <div id=scroller class=vertical>
+ <div id="container">
+ <div id=target></div>
+ </div>
+ </div>
+</template>
+<script>
+ promise_test(async (t) => {
+ inflate(t, test_two_values);
+ await assertValueAt(scroller, target, { scrollTop:50, expected:-1 });
+ await assertValueAt(scroller, target, { scrollTop:50 + 20, expected:0 }); // 0%
+ await assertValueAt(scroller, target, { scrollTop:125 + 5, expected:50 }); // 50%
+ await assertValueAt(scroller, target, { scrollTop:200 - 10, expected:100 }); // 100%
+ }, 'view-timeline-inset with two values');
+</script>
+
+<template id=test_em_values>
+ <style>
+ #target {
+ font-size: 10px;
+ view-timeline: --t1;
+ view-timeline-inset: 10px 2em;
+ animation: anim 1s linear forwards;
+ animation-timeline: --t1;
+ }
+ </style>
+ <div id=scroller class=vertical>
+ <div id="container">
+ <div id=target></div>
+ </div>
+ </div>
+</template>
+<script>
+ promise_test(async (t) => {
+ inflate(t, test_em_values);
+ await assertValueAt(scroller, target, { scrollTop:50, expected:-1 });
+ await assertValueAt(scroller, target, { scrollTop:50 + 20, expected:0 }); // 0%
+ await assertValueAt(scroller, target, { scrollTop:125 + 5, expected:50 }); // 50%
+ await assertValueAt(scroller, target, { scrollTop:200 - 10, expected:100 }); // 100%
+ }, 'view-timeline-inset with em values');
+</script>
+
+<template id=test_percentage_values>
+ <style>
+ #target {
+ font-size: 10px;
+ view-timeline: --t1;
+ view-timeline-inset: calc(5px + max(1%, 5%)) 20%;
+ animation: anim 1s linear forwards;
+ animation-timeline: --t1;
+ }
+ </style>
+ <div id=scroller class=vertical>
+ <div id="container">
+ <div id=target></div>
+ </div>
+ </div>
+</template>
+<script>
+ promise_test(async (t) => {
+ inflate(t, test_percentage_values);
+ await assertValueAt(scroller, target, { scrollTop:50, expected:-1 });
+ await assertValueAt(scroller, target, { scrollTop:50 + 20, expected:0 }); // 0%
+ await assertValueAt(scroller, target, { scrollTop:125 + 5, expected:50 }); // 50%
+ await assertValueAt(scroller, target, { scrollTop:200 - 10, expected:100 }); // 100%
+ }, 'view-timeline-inset with percentage values');
+</script>
+
+<template id=test_outset>
+ <style>
+ #target {
+ view-timeline: --t1;
+ view-timeline-inset: -10px -20px;
+ animation: anim 1s linear forwards;
+ animation-timeline: --t1;
+ }
+ </style>
+ <div id=scroller class=vertical>
+ <div id="container">
+ <div id=target></div>
+ </div>
+ </div>
+</template>
+<script>
+ promise_test(async (t) => {
+ inflate(t, test_outset);
+ await assertValueAt(scroller, target, { scrollTop:20, expected:-1 });
+ await assertValueAt(scroller, target, { scrollTop:50 - 20, expected:0 }); // 0%
+ await assertValueAt(scroller, target, { scrollTop:125 - 5, expected:50 }); // 50%
+ await assertValueAt(scroller, target, { scrollTop:200 + 10, expected:100 }); // 100%
+ }, 'view-timeline-inset with negative values');
+</script>
+
+<template id=test_horizontal>
+ <style>
+ #target {
+ view-timeline: --t1 x;
+ view-timeline-inset: 10px 20px;
+ animation: anim 1s linear forwards;
+ animation-timeline: --t1;
+ }
+ </style>
+ <div id=scroller>
+ <div id="container">
+ <div id=target></div>
+ </div>
+ </div>
+</template>
+<script>
+ promise_test(async (t) => {
+ inflate(t, test_horizontal);
+ await assertValueAt(scroller, target, { scrollLeft:20, expected:-1 });
+ await assertValueAt(scroller, target, { scrollLeft:70 + 20, expected:0 }); // 0%
+ await assertValueAt(scroller, target, { scrollLeft:135 + 5, expected:50 }); // 50%
+ await assertValueAt(scroller, target, { scrollLeft:200 - 10, expected:100 }); // 100%
+ }, 'view-timeline-inset with horizontal scroller');
+</script>
+
+<template id=test_block>
+ <style>
+ #target {
+ view-timeline: --t1 block;
+ view-timeline-inset: 10px 20px;
+ animation: anim 1s linear forwards;
+ animation-timeline: --t1;
+ }
+ </style>
+ <div id=scroller>
+ <div id="container">
+ <div id=target></div>
+ </div>
+ </div>
+</template>
+<script>
+ promise_test(async (t) => {
+ inflate(t, test_block);
+ await assertValueAt(scroller, target, { scrollTop:50, expected:-1 });
+ await assertValueAt(scroller, target, { scrollTop:50 + 20, expected:0 }); // 0%
+ await assertValueAt(scroller, target, { scrollTop:125 + 5, expected:50 }); // 50%
+ await assertValueAt(scroller, target, { scrollTop:200 - 10, expected:100 }); // 100%
+ }, 'view-timeline-inset with block scroller');
+</script>
+
+<template id=test_inline>
+ <style>
+ #target {
+ view-timeline: --t1 inline;
+ view-timeline-inset: 10px 20px;
+ animation: anim 1s linear forwards;
+ animation-timeline: --t1;
+ }
+ </style>
+ <div id=scroller>
+ <div id="container">
+ <div id=target></div>
+ </div>
+ </div>
+</template>
+<script>
+ promise_test(async (t) => {
+ inflate(t, test_inline);
+ await assertValueAt(scroller, target, { scrollLeft:20, expected:-1 });
+ await assertValueAt(scroller, target, { scrollLeft:70 + 20, expected:0 }); // 0%
+ await assertValueAt(scroller, target, { scrollLeft:135 + 5, expected:50 }); // 50%
+ await assertValueAt(scroller, target, { scrollLeft:200 - 10, expected:100 }); // 100%
+ }, 'view-timeline-inset with inline scroller');
+</script>
+
+<template id=test_auto_block>
+ <style>
+ #scroller {
+ scroll-padding-block: 10px 20px;
+ }
+ #target {
+ view-timeline: --t1 block;
+ view-timeline-inset: auto auto;
+ animation: anim 1s linear forwards;
+ animation-timeline: --t1;
+ }
+ </style>
+ <div id=scroller>
+ <div id="container">
+ <div id=target></div>
+ </div>
+ </div>
+</template>
+<script>
+ promise_test(async (t) => {
+ inflate(t, test_auto_block);
+ await assertValueAt(scroller, target, { scrollTop:50, expected:-1 });
+ await assertValueAt(scroller, target, { scrollTop:50 + 20, expected:0 }); // 0%
+ await assertValueAt(scroller, target, { scrollTop:125 + 5, expected:50 }); // 50%
+ await assertValueAt(scroller, target, { scrollTop:200 - 10, expected:100 }); // 100%
+ }, 'view-timeline-inset:auto, block');
+</script>
+
+<template id=test_auto_block_vertical_lr>
+ <style>
+ #scroller {
+ scroll-padding-block: 10px 20px;
+ writing-mode: vertical-lr;
+ }
+ #target {
+ view-timeline: --t1 block;
+ view-timeline-inset: auto auto;
+ animation: anim 1s linear forwards;
+ animation-timeline: --t1;
+ }
+ </style>
+ <div id=scroller>
+ <div id="container">
+ <div id=target></div>
+ </div>
+ </div>
+</template>
+<script>
+ promise_test(async (t) => {
+ inflate(t, test_auto_block_vertical_lr);
+ await assertValueAt(scroller, target, { scrollLeft:20, expected:-1 });
+ await assertValueAt(scroller, target, { scrollLeft:70 + 20, expected:0 }); // 0%
+ await assertValueAt(scroller, target, { scrollLeft:135 + 5, expected:50 }); // 50%
+ await assertValueAt(scroller, target, { scrollLeft:200 - 10, expected:100 }); // 100%
+ }, 'view-timeline-inset:auto, block, vertical-lr');
+</script>
+
+<template id=test_auto_block_vertical_rl>
+ <style>
+ #scroller {
+ scroll-padding-block: 10px 20px;
+ writing-mode: vertical-rl;
+ }
+ #target {
+ view-timeline: --t1 block;
+ view-timeline-inset: auto auto;
+ animation: anim 1s linear forwards;
+ animation-timeline: --t1;
+ }
+ </style>
+ <div id=scroller>
+ <div id="container">
+ <div id=target></div>
+ </div>
+ </div>
+</template>
+<script>
+ promise_test(async (t) => {
+ inflate(t, test_auto_block_vertical_rl);
+ // Note: this represents horizontal scrolling from right to left.
+ await assertValueAt(scroller, target, { scrollLeft:-20, expected:-1 });
+ await assertValueAt(scroller, target, { scrollLeft:-(70 + 20), expected:0 }); // 0%
+ await assertValueAt(scroller, target, { scrollLeft:-(135 + 5), expected:50 }); // 50%
+ await assertValueAt(scroller, target, { scrollLeft:-(200 - 10), expected:100 }); // 100%
+ }, 'view-timeline-inset:auto, block, vertical-rl');
+</script>
+
+<template id=test_auto_inline>
+ <style>
+ #scroller {
+ scroll-padding-inline: 10px 20px;
+ }
+ #target {
+ view-timeline: --t1 inline;
+ view-timeline-inset: auto auto;
+ animation: anim 1s linear forwards;
+ animation-timeline: --t1;
+ }
+ </style>
+ <div id=scroller>
+ <div id="container">
+ <div id=target></div>
+ </div>
+ </div>
+</template>
+<script>
+ promise_test(async (t) => {
+ inflate(t, test_auto_inline);
+ await assertValueAt(scroller, target, { scrollLeft:20, expected:-1 });
+ await assertValueAt(scroller, target, { scrollLeft:70 + 20, expected:0 }); // 0%
+ await assertValueAt(scroller, target, { scrollLeft:135 + 5, expected:50 }); // 50%
+ await assertValueAt(scroller, target, { scrollLeft:200 - 10, expected:100 }); // 100%
+ }, 'view-timeline-inset:auto, inline');
+</script>
+
+<template id=test_auto_inline_vertical_rl>
+ <style>
+ #scroller {
+ scroll-padding-inline: 10px 20px;
+ writing-mode: vertical-rl;
+ }
+ #target {
+ view-timeline: --t1 inline;
+ view-timeline-inset: auto auto;
+ animation: anim 1s linear forwards;
+ animation-timeline: --t1;
+ }
+ </style>
+ <div id=scroller>
+ <div id="container">
+ <div id=target></div>
+ </div>
+ </div>
+</template>
+<script>
+ promise_test(async (t) => {
+ inflate(t, test_auto_inline_vertical_rl);
+ await assertValueAt(scroller, target, { scrollTop:50, expected:-1 });
+ await assertValueAt(scroller, target, { scrollTop:50 + 20, expected:0 }); // 0%
+ await assertValueAt(scroller, target, { scrollTop:125 + 5, expected:50 }); // 50%
+ await assertValueAt(scroller, target, { scrollTop:200 - 10, expected:100 }); // 100%
+ }, 'view-timeline-inset:auto, inline, vertical-rl');
+</script>
+
+<template id=test_auto_inline_vertical_lr>
+ <style>
+ #scroller {
+ scroll-padding-inline: 10px 20px;
+ writing-mode: vertical-lr;
+ }
+ #target {
+ view-timeline: --t1 inline;
+ view-timeline-inset: auto auto;
+ animation: anim 1s linear forwards;
+ animation-timeline: --t1;
+ }
+ </style>
+ <div id=scroller>
+ <div id="container">
+ <div id=target></div>
+ </div>
+ </div>
+</template>
+<script>
+ promise_test(async (t) => {
+ inflate(t, test_auto_inline_vertical_lr);
+ await assertValueAt(scroller, target, { scrollTop:50, expected:-1 });
+ await assertValueAt(scroller, target, { scrollTop:50 + 20, expected:0 }); // 0%
+ await assertValueAt(scroller, target, { scrollTop:125 + 5, expected:50 }); // 50%
+ await assertValueAt(scroller, target, { scrollTop:200 - 10, expected:100 }); // 100%
+ }, 'view-timeline-inset:auto, inline, vertical-lr');
+</script>
+
+<template id=test_auto_inline_rtl>
+ <style>
+ #scroller {
+ scroll-padding-inline: 10px 20px;
+ direction: rtl;
+ }
+ #target {
+ view-timeline: --t1 inline;
+ view-timeline-inset: auto auto;
+ animation: anim 1s linear forwards;
+ animation-timeline: --t1;
+ }
+ </style>
+ <div id=scroller>
+ <div id="container">
+ <div id=target></div>
+ </div>
+ </div>
+</template>
+<script>
+ promise_test(async (t) => {
+ inflate(t, test_auto_inline_rtl);
+ await assertValueAt(scroller, target, { scrollLeft:-20, expected:-1 });
+ await assertValueAt(scroller, target, { scrollLeft:-(70 + 20), expected:0 }); // 0%
+ await assertValueAt(scroller, target, { scrollLeft:-(135 + 5), expected:50 }); // 50%
+ await assertValueAt(scroller, target, { scrollLeft:-(200 - 10), expected:100 }); // 100%
+ }, 'view-timeline-inset:auto, inline, rtl');
+</script>
+
+<template id=test_auto_inline_vertical_rl_rtl>
+ <style>
+ #scroller {
+ scroll-padding-inline: 10px 20px;
+ writing-mode: vertical-rl;
+ direction: rtl;
+ }
+ #target {
+ view-timeline: --t1 inline;
+ view-timeline-inset: auto auto;
+ animation: anim 1s linear forwards;
+ animation-timeline: --t1;
+ }
+ </style>
+ <div id=scroller>
+ <div id="container">
+ <div id=target></div>
+ </div>
+ </div>
+</template>
+<script>
+ promise_test(async (t) => {
+ inflate(t, test_auto_inline_vertical_rl_rtl);
+ await assertValueAt(scroller, target, { scrollTop:-50, expected:-1 });
+ await assertValueAt(scroller, target, { scrollTop:-(50 + 20), expected:0 }); // 0%
+ await assertValueAt(scroller, target, { scrollTop:-(125 + 5), expected:50 }); // 50%
+ await assertValueAt(scroller, target, { scrollTop:-(200 - 10), expected:100 }); // 100%
+ }, 'view-timeline-inset:auto, inline, vertical-rl, rtl');
+</script>
+
+<template id=test_auto_inline_vertical_lr_rtl>
+ <style>
+ #scroller {
+ scroll-padding-inline: 10px 20px;
+ writing-mode: vertical-lr;
+ direction: rtl;
+ }
+ #target {
+ view-timeline: --t1 inline;
+ view-timeline-inset: auto auto;
+ animation: anim 1s linear forwards;
+ animation-timeline: --t1;
+ }
+ </style>
+ <div id=scroller>
+ <div id="container">
+ <div id=target></div>
+ </div>
+ </div>
+</template>
+<script>
+ promise_test(async (t) => {
+ inflate(t, test_auto_inline_vertical_lr_rtl);
+ await assertValueAt(scroller, target, { scrollTop:-50, expected:-1 });
+ await assertValueAt(scroller, target, { scrollTop:-(50 + 20), expected:0 }); // 0%
+ await assertValueAt(scroller, target, { scrollTop:-(125 + 5), expected:50 }); // 50%
+ await assertValueAt(scroller, target, { scrollTop:-(200 - 10), expected:100 }); // 100%
+ }, 'view-timeline-inset:auto, inline, vertical-lr, rtl');
+</script>
+
+<template id=test_auto_vertical>
+ <style>
+ #scroller {
+ scroll-padding-block: 10px 20px;
+ }
+ #target {
+ view-timeline: --t1 y;
+ view-timeline-inset: auto auto;
+ animation: anim 1s linear forwards;
+ animation-timeline: --t1;
+ }
+ </style>
+ <div id=scroller>
+ <div id="container">
+ <div id=target></div>
+ </div>
+ </div>
+</template>
+<script>
+ promise_test(async (t) => {
+ inflate(t, test_auto_vertical);
+ await assertValueAt(scroller, target, { scrollTop:50, expected:-1 });
+ await assertValueAt(scroller, target, { scrollTop:50 + 20, expected:0 }); // 0%
+ await assertValueAt(scroller, target, { scrollTop:125 + 5, expected:50 }); // 50%
+ await assertValueAt(scroller, target, { scrollTop:200 - 10, expected:100 }); // 100%
+ }, 'view-timeline-inset:auto, y');
+</script>
+
+<template id=test_auto_vertical_vertical_rl>
+ <style>
+ #scroller {
+ scroll-padding-inline: 10px 20px;
+ writing-mode: vertical-rl;
+ }
+ #target {
+ view-timeline: --t1 y;
+ view-timeline-inset: auto auto;
+ animation: anim 1s linear forwards;
+ animation-timeline: --t1;
+ }
+ </style>
+ <div id=scroller>
+ <div id="container">
+ <div id=target></div>
+ </div>
+ </div>
+</template>
+<script>
+ promise_test(async (t) => {
+ inflate(t, test_auto_vertical_vertical_rl);
+ await assertValueAt(scroller, target, { scrollTop:50, expected:-1 });
+ await assertValueAt(scroller, target, { scrollTop:50 + 20, expected:0 }); // 0%
+ await assertValueAt(scroller, target, { scrollTop:125 + 5, expected:50 }); // 50%
+ await assertValueAt(scroller, target, { scrollTop:200 - 10, expected:100 }); // 100%
+ }, 'view-timeline-inset:auto, y, vertical-rl');
+</script>
+
+<template id=test_auto_vertical_vertical_rl_rtl>
+ <style>
+ #scroller {
+ scroll-padding-inline: 10px 20px;
+ writing-mode: vertical-rl;
+ direction: rtl;
+ }
+ #target {
+ view-timeline: --t1 y;
+ view-timeline-inset: auto auto;
+ animation: anim 1s linear forwards;
+ animation-timeline: --t1;
+ }
+ </style>
+ <div id=scroller>
+ <div id="container">
+ <div id=target></div>
+ </div>
+ </div>
+</template>
+<script>
+ promise_test(async (t) => {
+ inflate(t, test_auto_vertical_vertical_rl_rtl);
+ await assertValueAt(scroller, target, { scrollTop:-50, expected:-1 });
+ await assertValueAt(scroller, target, { scrollTop:-(50 + 20), expected:0 }); // 0%
+ await assertValueAt(scroller, target, { scrollTop:-(125 + 5), expected:50 }); // 50%
+ await assertValueAt(scroller, target, { scrollTop:-(200 - 10), expected:100 }); // 100%
+ }, 'view-timeline-inset:auto, y, vertical-rl, rtl');
+</script>
+
+<template id=test_auto_horizontal>
+ <style>
+ #scroller {
+ scroll-padding-inline: 10px 20px;
+ }
+ #target {
+ view-timeline: --t1 x;
+ view-timeline-inset: auto auto;
+ animation: anim 1s linear forwards;
+ animation-timeline: --t1;
+ }
+ </style>
+ <div id=scroller>
+ <div id="container">
+ <div id=target></div>
+ </div>
+ </div>
+</template>
+<script>
+ promise_test(async (t) => {
+ inflate(t, test_auto_horizontal);
+ await assertValueAt(scroller, target, { scrollLeft:20, expected:-1 });
+ await assertValueAt(scroller, target, { scrollLeft:70 + 20, expected:0 }); // 0%
+ await assertValueAt(scroller, target, { scrollLeft:135 + 5, expected:50 }); // 50%
+ await assertValueAt(scroller, target, { scrollLeft:200 - 10, expected:100 }); // 100%
+ }, 'view-timeline-inset:auto, x');
+</script>
+
+<template id=test_auto_horizontal_rtl>
+ <style>
+ #scroller {
+ scroll-padding-inline: 10px 20px;
+ direction: rtl;
+ }
+ #target {
+ view-timeline: --t1 x;
+ view-timeline-inset: auto auto;
+ animation: anim 1s linear forwards;
+ animation-timeline: --t1;
+ }
+ </style>
+ <div id=scroller>
+ <div id="container">
+ <div id=target></div>
+ </div>
+ </div>
+</template>
+<script>
+ promise_test(async (t) => {
+ inflate(t, test_auto_horizontal_rtl);
+ await assertValueAt(scroller, target, { scrollLeft:-20, expected:-1 });
+ await assertValueAt(scroller, target, { scrollLeft:-(70 + 20), expected:0 }); // 0%
+ await assertValueAt(scroller, target, { scrollLeft:-(135 + 5), expected:50 }); // 50%
+ await assertValueAt(scroller, target, { scrollLeft:-(200 - 10), expected:100 }); // 100%
+ }, 'view-timeline-inset:auto, x, rtl');
+</script>
+
+<template id=test_auto_horizontal_vertical_lr>
+ <style>
+ #scroller {
+ scroll-padding-block: 10px 20px;
+ writing-mode: vertical-lr;
+ }
+ #target {
+ view-timeline: --t1 x;
+ view-timeline-inset: auto auto;
+ animation: anim 1s linear forwards;
+ animation-timeline: --t1;
+ }
+ </style>
+ <div id=scroller>
+ <div id="container">
+ <div id=target></div>
+ </div>
+ </div>
+</template>
+<script>
+ promise_test(async (t) => {
+ inflate(t, test_auto_horizontal_vertical_lr);
+ await assertValueAt(scroller, target, { scrollLeft:20, expected:-1 });
+ await assertValueAt(scroller, target, { scrollLeft:70 + 20, expected:0 }); // 0%
+ await assertValueAt(scroller, target, { scrollLeft:135 + 5, expected:50 }); // 50%
+ await assertValueAt(scroller, target, { scrollLeft:200 - 10, expected:100 }); // 100%
+ }, 'view-timeline-inset:auto, x, vertical-lr');
+</script>
+
+<template id=test_auto_horizontal_vertical_rl>
+ <style>
+ #scroller {
+ scroll-padding-block: 10px 20px;
+ writing-mode: vertical-rl;
+ }
+ #target {
+ view-timeline: --t1 x;
+ view-timeline-inset: auto auto;
+ animation: anim 1s linear forwards;
+ animation-timeline: --t1;
+ }
+ </style>
+ <div id=scroller>
+ <div id="container">
+ <div id=target></div>
+ </div>
+ </div>
+</template>
+<script>
+ promise_test(async (t) => {
+ inflate(t, test_auto_horizontal_vertical_rl);
+ await assertValueAt(scroller, target, { scrollLeft:-20, expected:-1 });
+ await assertValueAt(scroller, target, { scrollLeft:-(70 + 20), expected:0 }); // 0%
+ await assertValueAt(scroller, target, { scrollLeft:-(135 + 5), expected:50 }); // 50%
+ await assertValueAt(scroller, target, { scrollLeft:-(200 - 10), expected:100 }); // 100%
+ }, 'view-timeline-inset:auto, x, vertical-rl');
+</script>
+
+<template id=test_auto_mix>
+ <style>
+ #scroller {
+ font-size: 10px;
+ scroll-padding-block: 50px calc(10% + 1em);
+ }
+ #target {
+ view-timeline: --t1;
+ view-timeline-inset: 10% auto;
+ animation: anim 1s linear forwards;
+ animation-timeline: --t1;
+ }
+ </style>
+ <div id=scroller>
+ <div id="container">
+ <div id=target></div>
+ </div>
+ </div>
+</template>
+<script>
+ promise_test(async (t) => {
+ inflate(t, test_auto_mix);
+ // Note: 10% of scroller height 100px is 10px, and 1em with font-size:10px
+ // is also 10px. Hence we expect the end inset specified as calc(10% + 1em)
+ // to be 20px.
+ await assertValueAt(scroller, target, { scrollTop:50, expected:-1 });
+ await assertValueAt(scroller, target, { scrollTop:50 + 20, expected:0 }); // 0%
+ await assertValueAt(scroller, target, { scrollTop:125 + 5, expected:50 }); // 50%
+ await assertValueAt(scroller, target, { scrollTop:200 - 10, expected:100 }); // 100%
+ }, 'view-timeline-inset:auto, mix');
+</script>
+
+<!--
+ TODO: How to test view-timeline:auto + scroll-padding:auto? The UA may
+ in theory use any value in that case.
+
+ https://drafts.csswg.org/css-scroll-snap-1/#valdef-scroll-padding-auto
+-->
diff --git a/Tests/LibWeb/Text/input/wpt-import/scroll-animations/view-timelines/block-view-timeline-current-time.tentative.html b/Tests/LibWeb/Text/input/wpt-import/scroll-animations/view-timelines/block-view-timeline-current-time.tentative.html
new file mode 100644
index 00000000000..1b9cc24b77d
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/scroll-animations/view-timelines/block-view-timeline-current-time.tentative.html
@@ -0,0 +1,218 @@
+<!DOCTYPE html>
+<html id="top">
+<meta charset="utf-8">
+<title>View timeline current-time</title>
+<link rel="help" href="https://drafts.csswg.org/scroll-animations-1/#viewtimeline-interface">
+<script src="../../resources/testharness.js"></script>
+<script src="../../resources/testharnessreport.js"></script>
+<script src="../../web-animations/testcommon.js"></script>
+<script src="../../scroll-animations/scroll-timelines/testcommon.js"></script>
+<script src="../../scroll-animations/view-timelines/testcommon.js"></script>
+<style>
+ #container {
+ border: 10px solid lightgray;
+ overflow-y: scroll;
+ height: 200px;
+ width: 200px;
+ }
+ .spacer {
+ height: 800px;
+ }
+ #target {
+ background-color: green;
+ height: 200px;
+ width: 100px;
+ }
+</style>
+<body>
+ <div id="container">
+ <div id="leading-space" class="spacer"></div>
+ <div id="target"></div>
+ <div id="trailing-space" class="spacer"></div>
+ </div>
+</body>
+<script type="text/javascript">
+ promise_test(async t => {
+ container.scrollTop = 0;
+ await waitForNextFrame();
+
+ const anim = CreateViewTimelineOpacityAnimation(t, target);
+ const timeline = anim.timeline;
+ await anim.ready;
+
+ // Initially before start-offset and animation effect is in the before
+ // phase.
+ assert_percents_equal(timeline.currentTime, -150,
+ "Timeline's currentTime at container start boundary");
+ assert_percents_equal(anim.currentTime, -150,
+ "Animation's currentTime at container start boundary");
+ assert_equals(getComputedStyle(target).opacity, "1",
+ 'Effect is inactive in the before phase');
+
+ // Advance to the start offset, which triggers entry to the active phase.
+ await runAndWaitForFrameUpdate(() => {
+ container.scrollTop = 600;
+ });
+ assert_percents_equal(timeline.currentTime, 0,
+ "Timeline's current time at start offset");
+ assert_percents_equal(anim.currentTime, 0,
+ "Animation's current time at start offset");
+ assert_equals(getComputedStyle(target).opacity, '0.3',
+ 'Effect at the start of the active phase');
+
+ // Advance to the midpoint of the animation.
+ await runAndWaitForFrameUpdate(() => {
+ container.scrollTop = 800;
+ });
+ assert_percents_equal(timeline.currentTime, 50,
+ "Timeline's currentTime at midpoint");
+ assert_percents_equal(anim.currentTime, 50,
+ "Animation's currentTime at midpoint");
+ assert_equals(getComputedStyle(target).opacity,'0.5',
+ 'Effect at the midpoint of the active range');
+
+ // Advance to the end of the animation.
+ await runAndWaitForFrameUpdate(() => {
+ container.scrollTop = 1000;
+ });
+ assert_percents_equal(timeline.currentTime, 100,
+ "Timeline's currentTime at end offset");
+ assert_percents_equal(anim.currentTime, 100,
+ "Animation's currentTime at end offset");
+ assert_equals(getComputedStyle(target).opacity, '1',
+ 'Effect is in the after phase at effect end time');
+
+ // Advance to the scroll limit.
+ await runAndWaitForFrameUpdate(() => {
+ container.scrollTop = 1600;
+ });
+ assert_percents_equal(timeline.currentTime, 250,
+ "Timeline's currentTime at scroll limit");
+ // Hold time set when the animation finishes, which clamps the value of
+ // the animation's currentTime.
+ assert_percents_equal(anim.currentTime, 100,
+ "Animation's currentTime at scroll limit");
+ // In the after phase, so the effect should not be applied.
+ assert_equals(getComputedStyle(target).opacity, '1',
+ 'After phase at scroll limit');
+ }, 'View timeline with start and end scroll offsets that do not align with ' +
+ 'the scroll boundaries' );
+
+ promise_test(async t => {
+ const leading = document.getElementById('leading-space');
+ leading.style = 'display: none';
+ t.add_cleanup(() => {
+ leading.style = null;
+ });
+
+ await runAndWaitForFrameUpdate(() => {
+ container.scrollTop = 0;
+ });
+
+ const anim = CreateViewTimelineOpacityAnimation(t, target);
+ const timeline = anim.timeline;
+ await anim.ready;
+
+ assert_percents_equal(timeline.currentTime, 50,
+ "Timeline's currentTime at container start boundary");
+ assert_percents_equal(anim.currentTime, 50,
+ "Animation's currentTime at container start boundary");
+ assert_equals(getComputedStyle(target).opacity, "0.5",
+ 'Effect enters active phase at container start boundary');
+
+
+ // Advance to midpoint
+ await runAndWaitForFrameUpdate(() => {
+ container.scrollTop = 100;
+ });
+ assert_percents_equal(timeline.currentTime, 75,
+ "Timeline's current time at midpoint");
+ assert_percents_equal(anim.currentTime, 75,
+ "Animation's current time at midpoint");
+ assert_equals(getComputedStyle(target).opacity, '0.6',
+ 'Effect at the middle of the active phase');
+
+ // Advance to end-offset
+ await runAndWaitForFrameUpdate(() => {
+ container.scrollTop = 200;
+ });
+ assert_percents_equal(timeline.currentTime, 100,
+ "Timeline's current time at end offset");
+ assert_percents_equal(anim.currentTime, 100,
+ "Animation's current time at end offset");
+ assert_equals(getComputedStyle(target).opacity, '1',
+ 'Effect inactive at the end offset');
+
+ // Advance to scroll limit.
+ await runAndWaitForFrameUpdate(() => {
+ container.scrollTop = 800;
+ });
+ assert_percents_equal(timeline.currentTime, 250,
+ "Timeline's current time at scroll limit");
+ assert_percents_equal(anim.currentTime, 100,
+ "Animation's current time at scroll limit");
+ assert_equals(getComputedStyle(target).opacity, '1',
+ 'Effect inactive in the after phase');
+
+ }, 'View timeline does not clamp starting scroll offset at 0');
+
+ promise_test(async t => {
+ const trailing = document.getElementById('trailing-space');
+ trailing.style = 'display: none';
+ t.add_cleanup(() => {
+ trailing.style = null;
+ });
+
+ await runAndWaitForFrameUpdate(() => {
+ container.scrollTop = 0;
+ });
+
+ const anim = CreateViewTimelineOpacityAnimation(t, target);
+ const timeline = anim.timeline;
+ await anim.ready;
+
+ // Initially in before phase.
+ assert_percents_equal(timeline.currentTime, -150,
+ "Timeline's currentTime at container start boundary");
+ assert_percents_equal(anim.currentTime, -150,
+ "Animation's currentTime at container start boundary");
+ assert_equals(getComputedStyle(target).opacity, "1",
+ 'Effect enters active phase at container start boundary');
+
+ // Advance to start offset.
+ await runAndWaitForFrameUpdate(() => {
+ container.scrollTop = 600;
+ });
+ assert_percents_equal(timeline.currentTime, 0,
+ "Timeline's current time at start offset");
+ assert_percents_equal(anim.currentTime, 0,
+ "Animation's current time at start offset");
+ assert_equals(getComputedStyle(target).opacity, '0.3',
+ 'Effect at the start of the active phase');
+
+ // Advance to midpoint.
+ await runAndWaitForFrameUpdate(() => {
+ container.scrollTop = 700;
+ });
+ assert_percents_equal(timeline.currentTime, 25,
+ "Timeline's current time at the midpoint");
+ assert_percents_equal(anim.currentTime, 25,
+ "Animation's current time at the midpoint");
+ assert_equals(getComputedStyle(target).opacity, '0.4',
+ 'Effect at the midpoint of the active phase');
+
+ // Advance to end offset.
+ await runAndWaitForFrameUpdate(() => {
+ container.scrollTop = 800;
+ });
+ assert_percents_equal(timeline.currentTime, 50,
+ "Timeline's currentTime at max scroll offset");
+ assert_percents_equal(anim.currentTime, 50,
+ "Animation's currentTime at max scroll offset");
+ // The active-after boundary is inclusive since at the maximum scroll
+ // position.
+ assert_equals(getComputedStyle(target).opacity, "0.5",
+ 'Effect at end of active phase');
+ }, 'View timeline does not clamp end scroll offset at max scroll');
+</script>
+</html>
diff --git a/Tests/LibWeb/Text/input/wpt-import/scroll-animations/view-timelines/duration.html b/Tests/LibWeb/Text/input/wpt-import/scroll-animations/view-timelines/duration.html
new file mode 100644
index 00000000000..7d119b0b53e
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/scroll-animations/view-timelines/duration.html
@@ -0,0 +1,17 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>ViewTimeline.duration</title>
+<link rel="help" href="https://drafts.csswg.org/web-animations-2/#dom-animationtimeline-duration">
+<script src="../../resources/testharness.js"></script>
+<script src="../../resources/testharnessreport.js"></script>
+
+<div id=subject></div>
+<script>
+'use strict';
+
+test(t => {
+ const timeline = new ViewTimeline({subject: subject});
+ assert_equals(timeline.duration.toString(), '100%');
+}, 'The duration of a view timeline is 100%');
+
+</script>
diff --git a/Tests/LibWeb/Text/input/wpt-import/scroll-animations/view-timelines/inline-view-timeline-current-time.tentative.html b/Tests/LibWeb/Text/input/wpt-import/scroll-animations/view-timelines/inline-view-timeline-current-time.tentative.html
new file mode 100644
index 00000000000..c76ea664406
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/scroll-animations/view-timelines/inline-view-timeline-current-time.tentative.html
@@ -0,0 +1,318 @@
+<!DOCTYPE html>
+<html id="top">
+<meta charset="utf-8">
+<title>View timeline current-time</title>
+<link rel="help" href="https://drafts.csswg.org/scroll-animations-1/#viewtimeline-interface">
+<script src="../../resources/testharness.js"></script>
+<script src="../../resources/testharnessreport.js"></script>
+<script src="../../web-animations/testcommon.js"></script>
+<script src="../../scroll-animations/scroll-timelines/testcommon.js"></script>
+<script src="../../scroll-animations/view-timelines/testcommon.js"></script>
+<style>
+ #container {
+ border: 10px solid lightgray;
+ overflow-x: scroll;
+ height: 200px;
+ width: 200px;
+ }
+ #content {
+ display: flex;
+ flex-flow: row nowrap;
+ justify-content: flex-start;
+ width: 1800px;
+ margin: 0;
+ }
+ .spacer {
+ width: 800px;
+ display: inline-block;
+ }
+ #target {
+ background-color: green;
+ height: 100px;
+ width: 200px;
+ display: inline-block;
+ }
+</style>
+<body>
+ <div id="container">
+ <div id="content">
+ <div id="leading-space" class="spacer"></div>
+ <div id="target"></div>
+ <div id="trailing-space" class="spacer"></div>
+ </div>
+ </div>
+</body>
+<script type="text/javascript">
+ promise_test(async t => {
+ await runAndWaitForFrameUpdate(() => {
+ container.scrollLeft = 0;
+ });
+
+ const anim = CreateViewTimelineOpacityAnimation(t, target,
+ {
+ timeline:
+ {axis: 'inline'}
+ });
+ const timeline = anim.timeline;
+ await anim.ready;
+
+ // Initially before start-offset and animation effect is in the before
+ // phase.
+ assert_percents_equal(timeline.currentTime, -150,
+ "Timeline's currentTime at container start boundary");
+ assert_percents_equal(anim.currentTime, -150,
+ "Animation's currentTime at container start boundary");
+ assert_equals(getComputedStyle(target).opacity, "1",
+ 'Effect is inactive in the before phase');
+
+ // Advance to the start offset, which triggers entry to the active phase.
+ await runAndWaitForFrameUpdate(() => {
+ container.scrollLeft = 600;
+ });
+ assert_percents_equal(timeline.currentTime, 0,
+ "Timeline's current time at start offset");
+ assert_percents_equal(anim.currentTime, 0,
+ "Animation's current time at start offset");
+ assert_equals(getComputedStyle(target).opacity, '0.3',
+ 'Effect at the start of the active phase');
+
+ // Advance to the midpoint of the animation.
+ await runAndWaitForFrameUpdate(() => {
+ container.scrollLeft = 800;
+ });
+ assert_percents_equal(timeline.currentTime, 50,
+ "Timeline's currentTime at midpoint");
+ assert_percents_equal(anim.currentTime, 50,
+ "Animation's currentTime at midpoint");
+ assert_equals(getComputedStyle(target).opacity,'0.5',
+ 'Effect at the midpoint of the active range');
+
+ // Advance to the end of the animation.
+ await runAndWaitForFrameUpdate(() => {
+ container.scrollLeft = 1000;
+ });
+ assert_percents_equal(timeline.currentTime, 100,
+ "Timeline's currentTime at end offset");
+ assert_percents_equal(anim.currentTime, 100,
+ "Animation's currentTime at end offset");
+ assert_equals(getComputedStyle(target).opacity, '1',
+ 'Effect is in the after phase at effect end time');
+
+ // Advance to the scroll limit.
+ await runAndWaitForFrameUpdate(() => {
+ container.scrollLeft = 1600;
+ });
+ assert_percents_equal(timeline.currentTime, 250,
+ "Timeline's currentTime at scroll limit");
+ // Hold time set when the animation finishes, which clamps the value of
+ // the animation's currentTime.
+ assert_percents_equal(anim.currentTime, 100,
+ "Animation's currentTime at scroll limit");
+ // In the after phase, so the effect should not be applied.
+ assert_equals(getComputedStyle(target).opacity, '1',
+ 'After phase at scroll limit');
+ }, 'View timeline with start and end scroll offsets that do not align with ' +
+ 'the scroll boundaries' );
+
+ promise_test(async t => {
+ const leading = document.getElementById('leading-space');
+ leading.style = 'display: none';
+ content.style = 'width: 1000px';
+ t.add_cleanup(() => {
+ leading.style = null;
+ content.style = null;
+ });
+
+ await runAndWaitForFrameUpdate(() => {
+ container.scrollLeft = 0;
+ });
+
+ const anim = CreateViewTimelineOpacityAnimation(t, target,
+ {
+ timeline:
+ {axis: 'inline'}
+ });
+ const timeline = anim.timeline;
+ await anim.ready;
+
+ assert_percents_equal(timeline.currentTime, 50,
+ "Timeline's currentTime at container start boundary");
+ assert_percents_equal(anim.currentTime, 50,
+ "Animation's currentTime at container start boundary");
+ assert_equals(getComputedStyle(target).opacity, "0.5",
+ 'Effect enters active phase at container start boundary');
+
+ // Advance to midpoint
+ await runAndWaitForFrameUpdate(() => {
+ container.scrollLeft = 100;
+ });
+ assert_percents_equal(timeline.currentTime, 75,
+ "Timeline's current time at the midpoint");
+ assert_percents_equal(anim.currentTime, 75,
+ "Animation's current time at the midpoint");
+ assert_equals(getComputedStyle(target).opacity, '0.6',
+ 'Effect at the midpoint of the active phase');
+
+ // Advance to end-offset
+ await runAndWaitForFrameUpdate(() => {
+ container.scrollLeft = 200;
+ });
+ assert_percents_equal(timeline.currentTime, 100,
+ "Timeline's current time at end offset");
+ assert_percents_equal(anim.currentTime, 100,
+ "Animation's current time at end offset");
+ assert_equals(getComputedStyle(target).opacity, '1',
+ 'Effect at the end of the active phase');
+
+ // Advance to scroll limit.
+ await runAndWaitForFrameUpdate(() => {
+ container.scrollLeft = 800;
+ });
+ assert_percents_equal(timeline.currentTime, 250,
+ "Timeline's current time at the scroll limit");
+ assert_percents_equal(anim.currentTime, 100,
+ "Animation's current time at the scroll limit");
+ assert_equals(getComputedStyle(target).opacity, '1',
+ 'Effect at the scroll limit');
+
+ }, 'View timeline does not clamp starting scroll offset at 0');
+
+ promise_test(async t => {
+ const trailing = document.getElementById('trailing-space');
+ trailing.style = 'display: none';
+ content.style = 'width: 1000px';
+ t.add_cleanup(() => {
+ trailing.style = null;
+ content.style = null;
+ });
+
+ await runAndWaitForFrameUpdate(() => {
+ container.scrollLeft = 0;
+ });
+
+ const anim = CreateViewTimelineOpacityAnimation(t, target,
+ {
+ timeline:
+ {axis: 'inline'}
+ });
+ const timeline = anim.timeline;
+ await anim.ready;
+
+ // Initially in before phase.
+ assert_percents_equal(timeline.currentTime, -150,
+ "Timeline's currentTime at container start boundary");
+ assert_percents_equal(anim.currentTime, -150,
+ "Animation's currentTime at container start boundary");
+ assert_equals(getComputedStyle(target).opacity, "1",
+ 'Effect enters active phase at container start boundary');
+
+ // Advance to start offset.
+ await runAndWaitForFrameUpdate(() => {
+ container.scrollLeft = 600;
+ });
+ assert_percents_equal(timeline.currentTime, 0,
+ "Timeline's current time at start offset");
+ assert_percents_equal(anim.currentTime, 0,
+ "Animation's current time at start offset");
+ assert_equals(getComputedStyle(target).opacity, '0.3',
+ 'Effect at the start of the active phase');
+
+ // Advance to midpoint
+ await runAndWaitForFrameUpdate(() => {
+ container.scrollLeft = 700;
+ });
+ assert_percents_equal(timeline.currentTime, 25,
+ "Timeline's current time at midpoint");
+ assert_percents_equal(anim.currentTime, 25,
+ "Animation's current time at midpoint");
+ assert_equals(getComputedStyle(target).opacity, '0.4',
+ 'Effect at the midpoint of the active phase');
+
+ // Advance to end offset.
+ await runAndWaitForFrameUpdate(() => {
+ container.scrollLeft = 800;
+ });
+ assert_percents_equal(timeline.currentTime, 50,
+ "Timeline's currentTime at max scroll offset");
+ assert_percents_equal(anim.currentTime, 50,
+ "Animation's currentTime at max scroll offset");
+ // The active-after boundary is inclusive since at the scroll-limit.
+ assert_equals(getComputedStyle(target).opacity, "0.5",
+ 'Effect at end of active phase');
+ }, 'View timeline does not clamp end scroll offset at max scroll');
+
+
+ promise_test(async t => {
+ container.style = "direction: rtl";
+ container.scrollLeft = 0;
+ t.add_cleanup(() => {
+ content.style = null;
+ });
+ await waitForNextFrame();
+
+ const anim = CreateViewTimelineOpacityAnimation(t, target,
+ {
+ timeline:
+ {axis: 'inline'}
+ });
+ const timeline = anim.timeline;
+ await anim.ready;
+
+ // Initially before start-offset and animation effect is in the before
+ // phase.
+ assert_percents_equal(timeline.currentTime, -150,
+ "Timeline's currentTime at container start boundary");
+ assert_percents_equal(anim.currentTime, -150,
+ "Animation's currentTime at container start boundary");
+ assert_equals(getComputedStyle(target).opacity, "1",
+ 'Effect is inactive in the before phase');
+
+ // Advance to the start offset, which triggers entry to the active phase.
+ await runAndWaitForFrameUpdate(() => {
+ container.scrollLeft = -600;
+ });
+ assert_percents_equal(timeline.currentTime, 0,
+ "Timeline's current time at start offset");
+ assert_percents_equal(anim.currentTime, 0,
+ "Animation's current time at start offset");
+ assert_equals(getComputedStyle(target).opacity, '0.3',
+ 'Effect at the start of the active phase');
+
+ // Advance to the midpoint of the animation.
+ await runAndWaitForFrameUpdate(() => {
+ container.scrollLeft = -800;
+ });
+ assert_percents_equal(timeline.currentTime, 50,
+ "Timeline's currentTime at midpoint");
+ assert_percents_equal(anim.currentTime, 50,
+ "Animation's currentTime at midpoint");
+ assert_equals(getComputedStyle(target).opacity,'0.5',
+ 'Effect at the midpoint of the active range');
+
+ // Advance to the end of the animation.
+ await runAndWaitForFrameUpdate(() => {
+ container.scrollLeft = -1000;
+ });
+ assert_percents_equal(timeline.currentTime, 100,
+ "Timeline's currentTime at end offset");
+ assert_percents_equal(anim.currentTime, 100,
+ "Animation's currentTime at end offset");
+ assert_equals(getComputedStyle(target).opacity, '1',
+ 'Effect is in the after phase at effect end time');
+
+ // Advance to the scroll limit.
+ await runAndWaitForFrameUpdate(() => {
+ container.scrollLeft = -1600;
+ });
+ assert_percents_equal(timeline.currentTime, 250,
+ "Timeline's currentTime at scroll limit");
+ // Hold time set when the animation finishes, which clamps the value of
+ // the animation's currentTime.
+ assert_percents_equal(anim.currentTime, 100,
+ "Animation's currentTime at scroll limit");
+ // In the after phase, so the effect should not be applied.
+ assert_equals(getComputedStyle(target).opacity, '1',
+ 'After phase at scroll limit');
+ }, 'View timeline with container having RTL layout' );
+</script>
+</html>
diff --git a/Tests/LibWeb/Text/input/wpt-import/scroll-animations/view-timelines/testcommon.js b/Tests/LibWeb/Text/input/wpt-import/scroll-animations/view-timelines/testcommon.js
new file mode 100644
index 00000000000..32106d4f68c
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/scroll-animations/view-timelines/testcommon.js
@@ -0,0 +1,152 @@
+'use strict';
+
+function assert_px_equals(observed, expected, description) {
+ assert_equals(observed.unit, 'px',
+ `Unexpected unit type for '${description}'`);
+ assert_approx_equals(observed.value, expected, 0.0001,
+ `Unexpected value for ${description}`);
+}
+
+function CreateViewTimelineOpacityAnimation(test, target, options) {
+ const timeline_options = {
+ subject: target,
+ axis: 'block'
+ };
+ if (options && 'timeline' in options) {
+ for (let key in options.timeline) {
+ timeline_options[key] = options.timeline[key];
+ }
+ }
+ const animation_options = {
+ timeline: new ViewTimeline(timeline_options)
+ };
+ if (options && 'animation' in options) {
+ for (let key in options.animation) {
+ animation_options[key] = options.animation[key];
+ }
+ }
+
+ const anim =
+ target.animate({ opacity: [0.3, 0.7] }, animation_options);
+ test.add_cleanup(() => {
+ anim.cancel();
+ });
+ return anim;
+}
+
+// Verify that range specified in the options aligns with the active range of
+// the animation.
+//
+// Sample call:
+// await runTimelineBoundsTest(t, {
+// timeline: { inset: [ CSS.percent(0), CSS.percent(20)] },
+// timing: { fill: 'both' }
+// startOffset: 600,
+// endOffset: 900
+// });
+async function runTimelineBoundsTest(t, options, message) {
+ // Allow tiny sampling differences from subpixel scroll positions on
+ // highdpi configurations.
+ const opacityEpsilon = 0.001;
+ const scrollOffsetProp = options.axis == 'block' ? 'scrollTop' : 'scrollLeft';
+ container[scrollOffsetProp] = 0;
+ await waitForNextFrame();
+
+ const anim =
+ options.anim ||
+ CreateViewTimelineOpacityAnimation(t, target, options);
+ if (options.timing)
+ anim.effect.updateTiming(options.timing);
+
+ const timeline = anim.timeline;
+ await anim.ready;
+
+ // Advance to the start offset, which triggers entry to the active phase.
+ container[scrollOffsetProp] = options.startOffset;
+ await waitForNextFrame();
+ assert_approx_equals(Number(getComputedStyle(target).opacity), 0.3,
+ opacityEpsilon,
+ `Effect at the start of the active phase: ${message}`);
+
+ // Advance to the midpoint of the animation.
+ container[scrollOffsetProp] = (options.startOffset + options.endOffset) / 2;
+ await waitForNextFrame();
+ assert_approx_equals(Number(getComputedStyle(target).opacity), 0.5,
+ opacityEpsilon,
+ `Effect at the midpoint of the active range: ${message}`);
+
+ // Advance to the end of the animation.
+ container[scrollOffsetProp] = options.endOffset;
+ await waitForNextFrame();
+ assert_approx_equals(Number(getComputedStyle(target).opacity), 0.7,
+ opacityEpsilon,
+ `Effect is in the active phase at effect end time: ${message}`);
+
+ // Return the animation so that we can continue testing with the same object.
+ return anim;
+}
+
+// Sets the start and end range for a view timeline and ensures that the
+// range aligns with expected values.
+//
+// Sample call:
+// await runTimelineRangeTest(t, {
+// rangeStart: { rangeName: 'cover', offset: CSS.percent(0) } ,
+// rangeEnd: { rangeName: 'cover', offset: CSS.percent(100) },
+// startOffset: 600,
+// endOffset: 900
+// });
+async function runTimelineRangeTest(t, options) {
+ const rangeToString = range => {
+ const parts = [];
+ if (range.rangeName)
+ parts.push(range.rangeName);
+ if (range.offset)
+ parts.push(`${range.offset.value}%`);
+ return parts.join(' ');
+ };
+ const range =
+ `${rangeToString(options.rangeStart)} to ` +
+ `${rangeToString(options.rangeEnd)}`;
+
+ options.timeline = {
+ axis: options.axis || 'inline'
+ };
+ options.animation = {
+ rangeStart: options.rangeStart,
+ rangeEnd: options.rangeEnd,
+ };
+ options.timing = {
+ // Set fill to accommodate floating point precision errors at the
+ // endpoints.
+ fill: 'both'
+ };
+
+ return runTimelineBoundsTest(t, options, range);
+}
+
+// Sets the Inset for a view timeline and ensures that the range aligns with
+// expected values.
+//
+// Sample call:
+// await runTimelineInsetTest(t, {
+// inset: [ CSS.px(20), CSS.px(40) ]
+// startOffset: 600,
+// endOffset: 900
+// });
+async function runTimelineInsetTest(t, options) {
+ options.timeline = {
+ axis: 'inline',
+ inset: options.inset
+ };
+ options.timing = {
+ // Set fill to accommodate floating point precision errors at the
+ // endpoints.
+ fill: 'both'
+ }
+ const length = options.inset.length;
+ const range =
+ (options.inset instanceof Array) ? options.inset.join(' ')
+ : options.inset;
+ return runTimelineBoundsTest(t, options, range);
+}
diff --git a/Tests/LibWeb/Text/input/wpt-import/scroll-animations/view-timelines/view-timeline-inset.html b/Tests/LibWeb/Text/input/wpt-import/scroll-animations/view-timelines/view-timeline-inset.html
new file mode 100644
index 00000000000..3592498dc62
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/scroll-animations/view-timelines/view-timeline-inset.html
@@ -0,0 +1,205 @@
+<!DOCTYPE html>
+<html id="top">
+<meta charset="utf-8">
+<title>View timeline delay</title>
+<link rel="help" href="https://drafts.csswg.org/scroll-animations-1/#viewtimeline-interface">
+<script src="../../resources/testharness.js"></script>
+<script src="../../resources/testharnessreport.js"></script>
+<script src="../../web-animations/testcommon.js"></script>
+<script src="../../scroll-animations/scroll-timelines/testcommon.js"></script>
+<script src="../../scroll-animations/view-timelines/testcommon.js"></script>
+<style>
+ #container {
+ border: 10px solid lightgray;
+ overflow-x: scroll;
+ height: 200px;
+ width: 200px;
+ }
+ #content {
+ display: flex;
+ flex-flow: row nowrap;
+ justify-content: flex-start;
+ width: 1800px;
+ margin: 0;
+ }
+ .spacer {
+ width: 800px;
+ display: inline-block;
+ }
+ #target {
+ background-color: green;
+ height: 100px;
+ width: 100px;
+ display: inline-block;
+ font-size: 16px;
+ }
+ #target.big-font {
+ font-size: 20px;
+ }
+ #container.scroll-padded {
+ scroll-padding-inline: 10px 20px;
+ }
+</style>
+<body>
+ <div id="container">
+ <div id="content">
+ <div class="spacer"></div>
+ <div id="target"></div>
+ <div class="spacer"></div>
+ </div>
+ </div>
+</body>
+<script type="text/javascript">
+
+ function verifyTimelineOffsets(anim, start, end) {
+ const timeline = anim.timeline;
+ assert_px_equals(timeline.startOffset, start, 'startOffset');
+ assert_px_equals(timeline.endOffset, end, 'endOffset');
+ };
+
+ promise_test(async t => {
+ // These tests are all based on the cover range, which has bounds
+ // [600, 900] if there are no insets.
+ // startOffset = target_pos - viewport_size + end_side_inset
+ // = 600 + end_side_inset
+ // endOffset = target_pos + target_size - start_side_inset
+ // = 900 - start_side_inset
+ await runTimelineInsetTest(t, {
+ inset: [ CSS.px(0), CSS.px(0) ],
+ startOffset: 600,
+ endOffset: 900
+ }).then(anim => verifyTimelineOffsets(anim, 600, 900));
+ await runTimelineInsetTest(t, {
+ inset: [ CSS.px(10), CSS.px(20) ],
+ startOffset: 620,
+ endOffset: 890
+ }).then(anim => verifyTimelineOffsets(anim, 620, 890));
+ await runTimelineInsetTest(t, {
+ inset: [ CSS.px(10) ],
+ startOffset: 610,
+ endOffset: 890
+ }).then(anim => verifyTimelineOffsets(anim, 610, 890));
+ }, 'View timeline with px based inset.');
+
+ promise_test(async t => {
+ // These tests are all based on the cover range, which has bounds
+ // [600, 900].
+ // Percentages are relative to the viewport size, which is 200 for this
+ // test.
+ await runTimelineInsetTest(t, {
+ inset: [ CSS.percent(0), CSS.percent(0) ],
+ startOffset: 600,
+ endOffset: 900
+ }).then(anim => verifyTimelineOffsets(anim, 600, 900));
+ await runTimelineInsetTest(t, {
+ inset: [ CSS.percent(10), CSS.percent(20) ],
+ startOffset: 640,
+ endOffset: 880
+ }).then(anim => verifyTimelineOffsets(anim, 640, 880));
+ await runTimelineInsetTest(t, {
+ inset: [ CSS.percent(10) ],
+ startOffset: 620,
+ endOffset: 880
+ }).then(anim => verifyTimelineOffsets(anim, 620, 880));
+ }, 'View timeline with percent based inset.');
+
+ promise_test(async t => {
+ t.add_cleanup(() => {
+ container.classList.remove('scroll-padded');
+ });
+ const anim = await runTimelineInsetTest(t, {
+ inset: [ "auto", "auto" ],
+ startOffset: 600,
+ endOffset: 900
+ });
+ verifyTimelineOffsets(anim, 600, 900);
+ container.classList.add('scroll-padded');
+ await runTimelineBoundsTest(t, {
+ anim: anim,
+ startOffset: 620,
+ endOffset: 890,
+ }, 'Adjust for scroll-padding')
+ .then(anim => verifyTimelineOffsets(anim, 620, 890));
+ }, 'view timeline with inset auto.');
+
+promise_test(async t => {
+ await runTimelineInsetTest(t, {
+ inset: "10px",
+ startOffset: 610,
+ endOffset: 890
+ });
+ await runTimelineInsetTest(t, {
+ inset: "10px 20px",
+ startOffset: 620,
+ endOffset: 890
+ });
+ await runTimelineInsetTest(t, {
+ inset: "10%",
+ startOffset: 620,
+ endOffset: 880
+ });
+ await runTimelineInsetTest(t, {
+ inset: "10% 20%",
+ startOffset: 640,
+ endOffset: 880
+ });
+ await runTimelineInsetTest(t, {
+ inset: "auto",
+ startOffset: 600,
+ endOffset: 900
+ });
+
+ // Relative units are not allowed.
+ // https://github.com/w3c/csswg-drafts/issues/13852
+ assert_throws_js(TypeError, () => {
+ new ViewTimeline({
+ subject: target,
+ inset: "1em 2em"
+ });
+ });
+ assert_throws_js(TypeError, () => {
+ new ViewTimeline({
+ subject: target,
+ inset: "1vw 2vh"
+ });
+ });
+
+ assert_throws_js(TypeError, () => {
+ new ViewTimeline({
+ subject: target,
+ inset: "go fish"
+ });
+ });
+
+ assert_throws_js(TypeError, () => {
+ new ViewTimeline({
+ subject: target,
+ inset: "1 2"
+ });
+ });
+}, 'view timeline inset as string');
+
+promise_test(async t => {
+ assert_throws_js(TypeError, () => {
+ new ViewTimeline({
+ subject: target,
+ inset: []
+ });
+ });
+
+ assert_throws_js(TypeError, () => {
+ new ViewTimeline({
+ subject: target,
+ inset: [ CSS.rad(1) ]
+ });
+ });
+
+ assert_throws_js(TypeError, () => {
+ new ViewTimeline({
+ subject: target,
+ inset: [ CSS.px(10), CSS.px(10), CSS.px(10) ]
+ });
+ });
+}, 'view timeline with invalid inset');
+
+</script>
diff --git a/Tests/LibWeb/Text/input/wpt-import/scroll-animations/view-timelines/view-timeline-on-display-none-element.html b/Tests/LibWeb/Text/input/wpt-import/scroll-animations/view-timelines/view-timeline-on-display-none-element.html
new file mode 100644
index 00000000000..7207cd580c4
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/scroll-animations/view-timelines/view-timeline-on-display-none-element.html
@@ -0,0 +1,61 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>View timeline on element with display:none</title>
+<link rel="help" href="https://drafts.csswg.org/scroll-animations-1/#scroll-timelines">
+<script src="../../resources/testharness.js"></script>
+<script src="../../resources/testharnessreport.js"></script>
+<script src="../../web-animations/testcommon.js"></script>
+<script src="../../scroll-animations/scroll-timelines/testcommon.js"></script>
+<script src="../../scroll-animations/view-timelines/testcommon.js"></script>
+<script src="../../css/css-typed-om/resources/testhelper.js"></script>
+
+<style>
+ #container {
+ border: 10px solid lightgray;
+ overflow-x: scroll;
+ height: 200px;
+ width: 200px;
+ }
+ #content {
+ display: flex;
+ flex-flow: row nowrap;
+ justify-content: flex-start;
+ width: 1800px;
+ margin: 0;
+ }
+ .spacer {
+ width: 800px;
+ display: inline-block;
+ }
+ #target {
+ background-color: green;
+ height: 100px;
+ width: 100px;
+ display: none;
+ }
+</style>
+
+<div id="container">
+ <div id="content">
+ <div class="spacer"></div>
+ <div id="target"></div>
+ <div class="spacer"></div>
+ </div>
+</div>
+
+<script>
+promise_test(async t => {
+ const timeline = new ViewTimeline({ subject: target });
+ const anim = target.animate({ opacity: [0, 0.5] }, { timeline: timeline });
+ t.add_cleanup(() => {
+ anim.cancel();
+ });
+ // We use a unit that does not require an element to resolve given:
+ // https://github.com/web-platform-tests/interop/issues/1309
+ anim.rangeStart = "10px";
+ container.scrollLeft = 750;
+ await waitForNextFrame();
+ assert_equals(getComputedStyle(target).opacity, "1",
+ "Opacity with inactive timeline");
+}, "element with display: none should have inactive viewtimeline");
+</script>
diff --git a/Tests/LibWeb/Text/input/wpt-import/scroll-animations/view-timelines/view-timeline-range.html b/Tests/LibWeb/Text/input/wpt-import/scroll-animations/view-timelines/view-timeline-range.html
new file mode 100644
index 00000000000..7e14b48b807
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/scroll-animations/view-timelines/view-timeline-range.html
@@ -0,0 +1,257 @@
+<!DOCTYPE html>
+<html id="top">
+<meta charset="utf-8">
+<title>View timeline delay</title>
+<link rel="help" href="https://drafts.csswg.org/scroll-animations-1/#viewtimeline-interface">
+<script src="../../resources/testharness.js"></script>
+<script src="../../resources/testharnessreport.js"></script>
+<script src="../../web-animations/testcommon.js"></script>
+<script src="../../scroll-animations/scroll-timelines/testcommon.js"></script>
+<script src="../../scroll-animations/view-timelines/testcommon.js"></script>
+<style>
+ #container {
+ border: 10px solid lightgray;
+ overflow-x: scroll;
+ height: 200px;
+ width: 200px;
+ }
+ #content {
+ display: flex;
+ flex-flow: row nowrap;
+ justify-content: flex-start;
+ width: 1800px;
+ margin: 0;
+ }
+ .spacer {
+ width: 800px;
+ display: inline-block;
+ }
+ #target {
+ background-color: green;
+ height: 100px;
+ width: 100px;
+ display: inline-block;
+ font-size: 10px;
+ }
+</style>
+<body>
+ <div id="container">
+ <div id="content">
+ <div class="spacer"></div>
+ <div id="target"></div>
+ <div class="spacer"></div>
+ </div>
+ </div>
+</body>
+<script type="text/javascript">
+ promise_test(async t => {
+ // Delays are associated with the animation and not with the timeline.
+ // Thus adjusting the delays has no effect on the timeline offsets. The
+ // offsets always correspond to the 'cover' range.
+ const verifyTimelineOffsets = anim => {
+ const timeline = anim.timeline;
+ assert_px_equals(timeline.startOffset, 600, 'startOffset');
+ assert_px_equals(timeline.endOffset, 900, 'endOffset');
+ };
+ await runTimelineRangeTest(t, {
+ rangeStart: { rangeName: 'cover', offset: CSS.percent(0) } ,
+ rangeEnd: { rangeName: 'cover', offset: CSS.percent(100) },
+ startOffset: 600,
+ endOffset: 900
+ }).then(anim => {
+ verifyTimelineOffsets(anim);
+ });
+ await runTimelineRangeTest(t, {
+ rangeStart: { rangeName: 'contain', offset: CSS.percent(0) } ,
+ rangeEnd: { rangeName: 'contain', offset: CSS.percent(100) },
+ startOffset: 700,
+ endOffset: 800
+ }).then(anim => {
+ verifyTimelineOffsets(anim);
+ });
+ await runTimelineRangeTest(t, {
+ rangeStart: { rangeName: 'entry', offset: CSS.percent(0) },
+ rangeEnd: { rangeName: 'entry', offset: CSS.percent(100) },
+ startOffset: 600,
+ endOffset: 700
+ });
+ await runTimelineRangeTest(t, {
+ rangeStart: { rangeName: 'entry-crossing', offset: CSS.percent(0) },
+ rangeEnd: { rangeName: 'entry-crossing', offset: CSS.percent(100) },
+ startOffset: 600,
+ endOffset: 700
+ });
+ await runTimelineRangeTest(t, {
+ rangeStart: { rangeName: 'exit', offset: CSS.percent(0) },
+ rangeEnd: { rangeName: 'exit', offset: CSS.percent(100) },
+ startOffset: 800,
+ endOffset: 900
+ });
+ await runTimelineRangeTest(t, {
+ rangeStart: { rangeName: 'exit-crossing', offset: CSS.percent(0) },
+ rangeEnd: { rangeName: 'exit-crossing', offset: CSS.percent(100) },
+ startOffset: 800,
+ endOffset: 900
+ });
+ await runTimelineRangeTest(t, {
+ rangeStart: { rangeName: 'contain', offset: CSS.percent(-50) },
+ rangeEnd: { rangeName: 'entry', offset: CSS.percent(200) },
+ startOffset: 650,
+ endOffset: 800
+ });
+ }, 'View timeline with range as <name> <percent> pair.' );
+
+ promise_test(async t => {
+ await runTimelineRangeTest(t, {
+ rangeStart: { rangeName: 'entry' },
+ rangeEnd: { rangeName: 'exit' },
+ startOffset: 600,
+ endOffset: 900
+ });
+ await runTimelineRangeTest(t, {
+ rangeStart: { offset: CSS.percent(0) },
+ rangeEnd: { offset: CSS.percent(100) },
+ startOffset: 600,
+ endOffset: 900
+ });
+ }, 'View timeline with range and inferred name or offset.' );
+
+ promise_test(async t => {
+ await runTimelineRangeTest(t, {
+ rangeStart: { rangeName: 'cover', offset: CSS.px(20) } ,
+ rangeEnd: { rangeName: 'cover', offset: CSS.px(100) },
+ startOffset: 620,
+ endOffset: 700
+ });
+
+ await runTimelineRangeTest(t, {
+ rangeStart: { rangeName: 'contain', offset: CSS.px(20) } ,
+ rangeEnd: { rangeName: 'contain', offset: CSS.px(100) },
+ startOffset: 720,
+ endOffset: 800
+ });
+
+ await runTimelineRangeTest(t, {
+ rangeStart: { rangeName: 'entry', offset: CSS.px(20) } ,
+ rangeEnd: { rangeName: 'entry', offset: CSS.px(100) },
+ startOffset: 620,
+ endOffset: 700
+ });
+
+ await runTimelineRangeTest(t, {
+ rangeStart: { rangeName: 'exit', offset: CSS.px(20) } ,
+ rangeEnd: { rangeName: 'exit', offset: CSS.px(80) },
+ startOffset: 820,
+ endOffset: 880
+ });
+
+ }, 'View timeline with range as <name> <px> pair.' );
+
+ test(t => {
+ const timeline = new ViewTimeline({subject: target, axis: 'block'});
+ const anim = target.animate(
+ null,
+ {
+ timeline: timeline,
+ rangeStart: {
+ rangeName: 'cover',
+ offset: new CSSUnitValue(1, 'in'),
+ },
+ },
+ );
+ t.add_cleanup(() => { anim.cancel(); });
+
+ assert_equals(anim.rangeStart.offset.unit, 'px');
+ assert_equals(anim.rangeStart.offset.value, 96);
+ }, 'View timeline range accepts absolute units.');
+
+ promise_test(async t => {
+ await runTimelineRangeTest(t, {
+ rangeStart: {
+ rangeName: 'contain',
+ offset: new CSSMathSum(CSS.percent(0), CSS.px(20))
+ },
+ rangeEnd: {
+ rangeName: 'contain',
+ offset: new CSSMathSum(CSS.percent(100), CSS.px(-10))
+ },
+ startOffset: 720,
+ endOffset: 790
+ });
+
+ }, 'View timeline with range as <name> <percent+px> pair.' );
+
+ promise_test(async t => {
+ await runTimelineRangeTest(t, {
+ rangeStart: "contain -50%",
+ rangeEnd: "entry 200%",
+ startOffset: 650,
+ endOffset: 800
+ });
+
+ await runTimelineRangeTest(t, {
+ rangeStart: "contain 20px",
+ rangeEnd: "contain 100px",
+ startOffset: 720,
+ endOffset: 800
+ });
+
+ await runTimelineRangeTest(t, {
+ rangeStart: "contain calc(sign(1000px - 1px) * 20px)",
+ rangeEnd: "contain calc(100%)",
+ startOffset: 720,
+ endOffset: 800
+ });
+
+ await runTimelineRangeTest(t, {
+ rangeStart: "contain calc(0% + 20px)",
+ rangeEnd: "contain calc(100% - 10px)",
+ startOffset: 720,
+ endOffset: 790
+ });
+
+ await runTimelineRangeTest(t, {
+ rangeStart: "exit 20px",
+ rangeEnd: "exit 80px",
+ startOffset: 820,
+ endOffset: 880
+ });
+ }, 'View timeline with range as strings.');
+
+ promise_test(async t => {
+ const timeline = new ViewTimeline({subject: target, axis: 'block'});
+ assert_throws_js(TypeError, () => {
+ let anim = target.animate(
+ null,
+ {
+ timeline: timeline,
+ rangeStart: "exit 2em",
+ rangeEnd: "exit 8em",
+ },
+ );
+ t.add_cleanup(() => { anim?.cancel(); });
+ }, 'Invalid font-relative units');
+
+ assert_throws_js(TypeError, () => {
+ let anim = target.animate(
+ null,
+ {
+ timeline: timeline,
+ rangeStart: "cover 2vh",
+ rangeEnd: "cover calc(100% - 2vw)",
+ },
+ );
+ t.add_cleanup(() => { anim?.cancel(); });
+ }, 'Invalid viewport units');
+
+ for (const [offset, description] of [
+ [new CSSMathSum(CSS.percent(0), CSS.em(2)), 'font-relative'],
+ [new CSSMathSum(CSS.percent(0), CSS.vw(2)), 'viewport'],
+ ]) {
+ assert_throws_js(TypeError, () => {
+ target.animate(null, {timeline: timeline, rangeStart: {offset}});
+ }, `Invalid CSSNumericValue with ${description} units`);
+ }
+ }, 'View timeline with range using relative units.');
+
+</script>
diff --git a/Tests/LibWeb/Text/input/wpt-import/scroll-animations/view-timelines/view-timeline-source.tentative.html b/Tests/LibWeb/Text/input/wpt-import/scroll-animations/view-timelines/view-timeline-source.tentative.html
new file mode 100644
index 00000000000..d6dce8a60d5
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/scroll-animations/view-timelines/view-timeline-source.tentative.html
@@ -0,0 +1,94 @@
+<!DOCTYPE html>
+<html id="top">
+<meta charset="utf-8">
+<title>View timeline source</title>
+<link rel="help" href="https://drafts.csswg.org/scroll-animations-1/#viewtimeline-interface">
+<script src="../../resources/testharness.js"></script>
+<script src="../../resources/testharnessreport.js"></script>
+<script src="../../web-animations/testcommon.js"></script>
+<style>
+#outer {
+ height: 400px;
+ width: 400px;
+ overflow: clip;
+}
+
+#inner {
+ height: 300px;
+ width: 300px;
+ overflow: clip;
+}
+
+#outer.scroller,
+#inner.scroller {
+ overflow: scroll;
+}
+
+#spacer {
+ height: 1000px;
+}
+
+#target {
+ background: green;
+ height: 40px;
+ width: 40px;
+}
+</style>
+<body>
+ <div id="outer" class="scroller">
+ <div id="inner" class="scroller">
+ <div id="target"></div>
+ <div id="spacer"></div>
+ </div>
+ </div>
+</body>
+<script>
+'use strict';
+
+function resetScrollers() {
+ inner.classList.add('scroller');
+ outer.classList.add('scroller');
+}
+
+function assert_source_id(viewTimeline, expected) {
+ const source = viewTimeline.source;
+ assert_true(!!source, 'No source');
+ assert_equals(source.id, expected);
+}
+
+promise_test(async t => {
+ t.add_cleanup(resetScrollers);
+ const viewTimeline = new ViewTimeline({ subject: target });
+ assert_equals(viewTimeline.subject, target);
+ assert_source_id(viewTimeline, 'inner');
+
+ inner.classList.remove('scroller');
+ assert_source_id(viewTimeline, 'outer');
+
+ outer.classList.remove('scroller');
+ assert_source_id(viewTimeline, 'top');
+}, 'Default source for a View timeline is the nearest scroll ' +
+ 'ancestor to the subject');
+
+promise_test(async t => {
+ t.add_cleanup(resetScrollers);
+ const viewTimeline =
+ new ViewTimeline({ source: outer, subject: target });
+ assert_equals(viewTimeline.subject, target);
+ assert_source_id(viewTimeline, 'inner');
+}, 'View timeline ignores explicitly set source');
+
+promise_test(async t => {
+ t.add_cleanup(resetScrollers);
+ const viewTimeline =
+ new ViewTimeline({ subject: target });
+ assert_equals(viewTimeline.subject, target);
+ assert_source_id(viewTimeline, 'inner');
+
+ target.style = "display: none";
+ assert_equals(viewTimeline.source, null);
+
+}, 'View timeline source is null when display:none');
+
+</script>
+</html>
diff --git a/Tests/LibWeb/Text/input/wpt-import/scroll-animations/view-timelines/view-timeline-subject-size-changes.html b/Tests/LibWeb/Text/input/wpt-import/scroll-animations/view-timelines/view-timeline-subject-size-changes.html
new file mode 100644
index 00000000000..6c99b9cb914
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/scroll-animations/view-timelines/view-timeline-subject-size-changes.html
@@ -0,0 +1,81 @@
+<!DOCTYPE html>
+<html id="top">
+<meta charset="utf-8">
+<title>View timeline Subject size changes after creation of Animation</title>
+<link rel="help" href="https://drafts.csswg.org/scroll-animations-1/#viewtimeline-interface">
+<script src="../../resources/testharness.js"></script>
+<script src="../../resources/testharnessreport.js"></script>
+<script src="../../web-animations/testcommon.js"></script>
+<script src="../../scroll-animations/scroll-timelines/testcommon.js"></script>
+<script src="../../scroll-animations/view-timelines/testcommon.js"></script>
+<style>
+ #container {
+ border: 10px solid lightgray;
+ overflow-y: scroll;
+ height: 400px;
+ width: 400px;
+ }
+ .spacer {
+ height: 500px;
+ }
+ #target {
+ background-color: green;
+ height: 100px;
+ width: 100px;
+ }
+</style>
+<body>
+ <div id="container">
+ <div class="spacer"></div>
+ <div id="target"></div>
+ <div class="spacer"></div>
+ </div>
+</body>
+
+<script type="text/javascript">
+promise_test(async t => {
+ const options = {
+ timeline: { axis: 'y' },
+ animation: {
+ rangeStart: { rangeName: 'entry', offset: CSS.percent(0) },
+ rangeEnd: { rangeName: 'entry', offset: CSS.percent(100) },
+ // Set fill to accommodate floating point precision errors at the
+ // endpoints.
+ fill: 'both'
+ }
+ };
+
+ container.scrollTop = 0;
+ await waitForNextFrame();
+
+ const anim = CreateViewTimelineOpacityAnimation(t, target, options);
+ const timeline = anim.timeline;
+ anim.effect.updateTiming(options.timing);
+ await anim.ready;
+
+ // Advance to the start offset, which triggers entry to the active phase.
+ container.scrollTop = 100;
+ await waitForNextFrame();
+ assert_equals(getComputedStyle(target).opacity, '0.3',
+ `Effect at the start of the active phase`);
+
+ // Advance to the midpoint of the animation.
+ container.scrollTop = 150;
+ await waitForNextFrame();
+ assert_equals(getComputedStyle(target).opacity,'0.5',
+ `Effect at the midpoint of the active range`);
+
+ // Since the height of the target is cut in half, the animation should be at the end now.
+ target.style.height = '50px';
+ await waitForNextFrame();
+ assert_equals(getComputedStyle(target).opacity, '0.7',
+ `Effect at the end of the active range`);
+
+ // Advance to the midpoint of the animation again.
+ container.scrollTop = 125;
+ await waitForNextFrame();
+ assert_equals(getComputedStyle(target).opacity,'0.5',
+ `Effect at the midpoint of the active range again`);
+
+ }, 'View timeline with subject size change after the creation of the animation');
+</script>