Files
ladybird/Libraries/LibWeb/Animations/DocumentTimeline.h
Callum Law 69f05bd45d LibWeb: Store animation time values in abstract type
In level 2 of the web animations spec, times are no longer always
measures in milliseconds, they can also be percents when dealing with
progress-based (i.e. scroll-based) timelines.

We don't actually support percent times yet but this change will make it
easier to implement when we do.
2025-12-12 10:49:18 +00:00

47 lines
1.6 KiB
C++

/*
* Copyright (c) 2023, Matthew Olsson <mattco@serenityos.org>.
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <LibWeb/Animations/AnimationTimeline.h>
#include <LibWeb/HighResolutionTime/DOMHighResTimeStamp.h>
#include <LibWeb/WebIDL/ExceptionOr.h>
namespace Web::Animations {
// https://www.w3.org/TR/web-animations-1/#dictdef-documenttimelineoptions
struct DocumentTimelineOptions {
HighResolutionTime::DOMHighResTimeStamp origin_time { 0.0 };
};
// https://www.w3.org/TR/web-animations-1/#the-documenttimeline-interface
class DocumentTimeline : public AnimationTimeline {
WEB_PLATFORM_OBJECT(DocumentTimeline, AnimationTimeline);
GC_DECLARE_ALLOCATOR(DocumentTimeline);
public:
static GC::Ref<DocumentTimeline> create(JS::Realm&, DOM::Document&, HighResolutionTime::DOMHighResTimeStamp origin_time);
static WebIDL::ExceptionOr<GC::Ref<DocumentTimeline>> construct_impl(JS::Realm&, DocumentTimelineOptions options = {});
virtual Optional<TimeValue> duration() const override { return {}; }
virtual void update_current_time(double timestamp) override;
virtual bool is_inactive() const override;
virtual Optional<double> convert_a_timeline_time_to_an_origin_relative_time(Optional<TimeValue>) override;
virtual bool can_convert_a_timeline_time_to_an_origin_relative_time() const override { return true; }
private:
DocumentTimeline(JS::Realm&, DOM::Document&, HighResolutionTime::DOMHighResTimeStamp origin_time);
virtual ~DocumentTimeline() override = default;
virtual void initialize(JS::Realm&) override;
HighResolutionTime::DOMHighResTimeStamp m_origin_time;
};
}