diff --git a/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp b/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp index 85d30d7589..f1b572b1f8 100644 --- a/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp +++ b/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp @@ -3319,6 +3319,7 @@ void generate_namespace_implementation(IDL::Interface const& interface, StringBu generator.append(R"~~~( // FIXME: This is a total hack until we can figure out the namespace for a given type somehow. +using namespace Web::Animations; using namespace Web::CSS; using namespace Web::DOM; using namespace Web::DOMParsing; @@ -3537,6 +3538,7 @@ void generate_constructor_implementation(IDL::Interface const& interface, String generator.append(R"~~~( // FIXME: This is a total hack until we can figure out the namespace for a given type somehow. +using namespace Web::Animations; using namespace Web::CSS; using namespace Web::DOM; using namespace Web::DOMParsing; @@ -3922,6 +3924,7 @@ void generate_prototype_implementation(IDL::Interface const& interface, StringBu generator.append(R"~~~( // FIXME: This is a total hack until we can figure out the namespace for a given type somehow. +using namespace Web::Animations; using namespace Web::Crypto; using namespace Web::CSS; using namespace Web::DOM; @@ -4071,6 +4074,7 @@ void generate_iterator_prototype_implementation(IDL::Interface const& interface, generator.append(R"~~~( // FIXME: This is a total hack until we can figure out the namespace for a given type somehow. +using namespace Web::Animations; using namespace Web::CSS; using namespace Web::DOM; using namespace Web::DOMParsing; @@ -4203,6 +4207,7 @@ void generate_global_mixin_implementation(IDL::Interface const& interface, Strin generator.append(R"~~~( // FIXME: This is a total hack until we can figure out the namespace for a given type somehow. +using namespace Web::Animations; using namespace Web::Crypto; using namespace Web::CSS; using namespace Web::DOM; diff --git a/Userland/Libraries/LibWeb/Animations/AnimationTimeline.cpp b/Userland/Libraries/LibWeb/Animations/AnimationTimeline.cpp new file mode 100644 index 0000000000..3f5b2586b5 --- /dev/null +++ b/Userland/Libraries/LibWeb/Animations/AnimationTimeline.cpp @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2023, Matthew Olsson . + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include +#include + +namespace Web::Animations { + +WebIDL::ExceptionOr AnimationTimeline::set_current_time(Optional value) +{ + if (value == m_current_time) + return {}; + + if (m_is_monotonically_increasing && m_current_time.has_value()) { + if (!value.has_value() || value.value() < m_current_time.value()) + m_is_monotonically_increasing = false; + } + + m_current_time = value; + + return {}; +} + +void AnimationTimeline::set_associated_document(JS::GCPtr document) +{ + m_associated_document = document; +} + +// https://www.w3.org/TR/web-animations-1/#inactive-timeline +bool AnimationTimeline::is_inactive() const +{ + // A timeline is considered to be inactive when its time value is unresolved. + return !m_current_time.has_value(); +} + +AnimationTimeline::AnimationTimeline(JS::Realm& realm) + : Bindings::PlatformObject(realm) +{ +} + +void AnimationTimeline::initialize(JS::Realm& realm) +{ + Base::initialize(realm); + set_prototype(&Bindings::ensure_web_prototype(realm, "AnimationTimeline")); +} + +void AnimationTimeline::visit_edges(Cell::Visitor& visitor) +{ + Base::visit_edges(visitor); + visitor.visit(m_associated_document); +} + +} diff --git a/Userland/Libraries/LibWeb/Animations/AnimationTimeline.h b/Userland/Libraries/LibWeb/Animations/AnimationTimeline.h new file mode 100644 index 0000000000..5d7a3d7bc4 --- /dev/null +++ b/Userland/Libraries/LibWeb/Animations/AnimationTimeline.h @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2023, Matthew Olsson . + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include + +namespace Web::Animations { + +// https://www.w3.org/TR/web-animations-1/#animationtimeline +class AnimationTimeline : public Bindings::PlatformObject { + WEB_PLATFORM_OBJECT(AnimationTimeline, Bindings::PlatformObject); + +public: + Optional current_time() const { return m_current_time; } + virtual WebIDL::ExceptionOr set_current_time(Optional); + + JS::GCPtr associated_document() const { return m_associated_document; } + void set_associated_document(JS::GCPtr); + + virtual bool is_inactive() const; + bool is_monotonically_increasing() const { return m_is_monotonically_increasing; } + + // https://www.w3.org/TR/web-animations-1/#timeline-time-to-origin-relative-time + virtual Optional convert_a_timeline_time_to_an_original_relative_time(Optional) { VERIFY_NOT_REACHED(); } + virtual bool can_convert_a_timeline_time_to_an_original_relative_time() const { return false; } + +protected: + AnimationTimeline(JS::Realm&); + + virtual void initialize(JS::Realm&) override; + virtual void visit_edges(Cell::Visitor&) override; + + // https://www.w3.org/TR/web-animations-1/#dom-animationtimeline-currenttime + Optional m_current_time {}; + + // https://www.w3.org/TR/web-animations-1/#monotonically-increasing-timeline + bool m_is_monotonically_increasing { true }; + + // https://www.w3.org/TR/web-animations-1/#timeline-associated-with-a-document + JS::GCPtr m_associated_document {}; +}; + +} diff --git a/Userland/Libraries/LibWeb/Animations/AnimationTimeline.idl b/Userland/Libraries/LibWeb/Animations/AnimationTimeline.idl new file mode 100644 index 0000000000..e4bb8a06ba --- /dev/null +++ b/Userland/Libraries/LibWeb/Animations/AnimationTimeline.idl @@ -0,0 +1,5 @@ +// https://www.w3.org/TR/web-animations-1/#animationtimeline +[Exposed=Window] +interface AnimationTimeline { + readonly attribute double? currentTime; +}; diff --git a/Userland/Libraries/LibWeb/CMakeLists.txt b/Userland/Libraries/LibWeb/CMakeLists.txt index 6f9e6aeb9f..d7140cec90 100644 --- a/Userland/Libraries/LibWeb/CMakeLists.txt +++ b/Userland/Libraries/LibWeb/CMakeLists.txt @@ -2,6 +2,7 @@ include(libweb_generators) include(accelerated_graphics) set(SOURCES + Animations/AnimationTimeline.cpp ARIA/AriaData.cpp ARIA/ARIAMixin.cpp ARIA/Roles.cpp diff --git a/Userland/Libraries/LibWeb/Forward.h b/Userland/Libraries/LibWeb/Forward.h index 69c2a1e7f6..01923d8d92 100644 --- a/Userland/Libraries/LibWeb/Forward.h +++ b/Userland/Libraries/LibWeb/Forward.h @@ -26,6 +26,10 @@ namespace Web::Painting { class RecordingPainter; } +namespace Web::Animations { +class AnimationTimeline; +} + namespace Web::ARIA { class AriaData; class ARIAMixin; diff --git a/Userland/Libraries/LibWeb/idl_files.cmake b/Userland/Libraries/LibWeb/idl_files.cmake index b32e0d1d03..73b439b3d0 100644 --- a/Userland/Libraries/LibWeb/idl_files.cmake +++ b/Userland/Libraries/LibWeb/idl_files.cmake @@ -1,6 +1,7 @@ # This file is included from "Meta/CMake/libweb_data.cmake" # It is defined here so that there is no need to go to the Meta directory when adding new idl files +libweb_js_bindings(Animations/AnimationTimeline) libweb_js_bindings(Crypto/Crypto) libweb_js_bindings(Crypto/SubtleCrypto) libweb_js_bindings(CSS/CSSConditionRule)