Luce packages
LuceLuce BaseLuciaOS

dymokomi/luce-browser-engine

Source of release 0.6.0

0.6.0 / src / web / animations / animation_timeline.lucb

#==============================================================================================
#
#   animation_timeline - Animations::AnimationTimeline: a timeline's current time, its
#   document and its animations
#
#   DESCRIPTION:
#       Port of Libraries/LibWeb/Animations/AnimationTimeline.cpp (lines 1-93) with the inline
#       members of AnimationTimeline.h, by region p2c: a restyle reads the document timeline's
#       current time (StyleComputer::start_needed_transitions), and resources that arrive
#       after the first rendering restyle their elements (Animations is phase 4 otherwise).
#
#       Copyright (c) 2023-2024, Matthew Olsson <mattco@serenityos.org>.
#       SPDX-License-Identifier: BSD-2-Clause
#
#==============================================================================================

## Ported from Libraries/LibWeb/Animations/AnimationTimeline.cpp:17 Web::Animations::AnimationTimeline::current_time.
# https://drafts.csswg.org/web-animations-1/#dom-animationtimeline-currenttime
pub func animations_animation_timeline_current_time(this: AnimationsAnimationTimeline*) -> AnimationsTimeValue?:
    # Returns the current time for this timeline or null if this timeline is inactive.
    if animations_animation_timeline_is_inactive(this):
        return none
    return this.m_current_time

## Ported from Libraries/LibWeb/Animations/AnimationTimeline.cpp:25 Web::Animations::AnimationTimeline::set_current_time (protected).
pub func animations_animation_timeline_set_current_time(this: AnimationsAnimationTimeline*, value: AnimationsTimeValue?):
    if value == this.m_current_time:
        return

    if this.m_is_monotonically_increasing:
        if let current = this.m_current_time:
            var goes_back = true
            if let new_value = value:
                assert(new_value.type_ == current.type_)
                goes_back = new_value.value < current.value
            if goes_back:
                ak.dbgln("AnimationTimeline::set_current_time: monotonically increasing timeline can only move forward")
                return

    this.m_current_time = value

## Ported from Libraries/LibWeb/Animations/AnimationTimeline.h:35 Web::Animations::AnimationTimeline::associated_document.
pub func animations_animation_timeline_associated_document(this: AnimationsAnimationTimeline*) -> DomDocument*?:
    return this.m_associated_document

## Ported from Libraries/LibWeb/Animations/AnimationTimeline.cpp:38 Web::Animations::AnimationTimeline::duration_for_bindings.
# https://drafts.csswg.org/web-animations-2/#timeline-duration
pub func animations_animation_timeline_duration_for_bindings(this: AnimationsAnimationTimeline*) -> AnimationsNullableCssNumberish:
    # The duration of a timeline gives the maximum value a timeline may generate for its current time. This value is
    # used to calculate the intrinsic iteration duration for the target effect of an animation that is associated with
    # the timeline when the effect’s iteration duration is "auto". The value is computed such that the effect fills the
    # available time. For a monotonic timeline, there is no upper bound on current time, and timeline duration is
    # unresolved. For a non-monotonic (e.g. scroll) timeline, the duration has a fixed upper bound. In this case, the
    # timeline is a progress-based timeline, and its timeline duration is 100%.
    return animations_nullable_css_numberish_from_optional_css_numberish_time(bind_platform_object_realm(this.bind_platform_object()), animations_animation_timeline_duration(this))

## Ported from Libraries/LibWeb/Animations/AnimationTimeline.cpp:50 Web::Animations::AnimationTimeline::set_associated_document.
pub func animations_animation_timeline_set_associated_document(this: AnimationsAnimationTimeline*, document: DomDocument*?):
    if let new_document = document:
        dom_document_associate_with_timeline(new_document, this)
    if let old_document = this.m_associated_document:
        dom_document_disassociate_with_timeline(old_document, this)
    this.m_associated_document = document

## Ported from Libraries/LibWeb/Animations/AnimationTimeline.cpp:60 Web::Animations::AnimationTimeline::is_inactive (virtual).
# https://drafts.csswg.org/web-animations-1/#timeline
pub func animations_animation_timeline_is_inactive_impl(this: AnimationsAnimationTimeline*) -> bool:
    # A timeline is considered to be inactive when its time value is unresolved, and active otherwise.
    return this.m_current_time == none

## Ported from Libraries/LibWeb/Animations/AnimationTimeline.h:40 Web::Animations::AnimationTimeline::is_progress_based (virtual).
pub func animations_animation_timeline_is_progress_based_impl(this: AnimationsAnimationTimeline*) -> bool:
    return false

## Ported from Libraries/LibWeb/Animations/AnimationTimeline.h:41 Web::Animations::AnimationTimeline::is_monotonically_increasing.
pub func animations_animation_timeline_is_monotonically_increasing(this: AnimationsAnimationTimeline*) -> bool:
    return this.m_is_monotonically_increasing

## Ported from Libraries/LibWeb/Animations/AnimationTimeline.h:44 Web::Animations::AnimationTimeline::convert_a_timeline_time_to_an_origin_relative_time (virtual).
# https://www.w3.org/TR/web-animations-1/#timeline-time-to-origin-relative-time
pub func animations_animation_timeline_convert_a_timeline_time_to_an_origin_relative_time_impl(this: AnimationsAnimationTimeline*, timeline_time: AnimationsTimeValue?) -> f64?:
    trap("VERIFY_NOT_REACHED")

## Ported from Libraries/LibWeb/Animations/AnimationTimeline.h:45 Web::Animations::AnimationTimeline::can_convert_a_timeline_time_to_an_origin_relative_time (virtual).
pub func animations_animation_timeline_can_convert_a_timeline_time_to_an_origin_relative_time_impl(this: AnimationsAnimationTimeline*) -> bool:
    return false

## Ported from Libraries/LibWeb/Animations/AnimationTimeline.h:47 Web::Animations::AnimationTimeline::associate_with_animation.
pub func animations_animation_timeline_associate_with_animation(this: AnimationsAnimationTimeline*, value: AnimationsAnimation*):
    gc.weak_hash_set_set(&this.m_associated_animations, value)

## Ported from Libraries/LibWeb/Animations/AnimationTimeline.h:48 Web::Animations::AnimationTimeline::disassociate_with_animation.
pub func animations_animation_timeline_disassociate_with_animation(this: AnimationsAnimationTimeline*, value: AnimationsAnimation*):
    _ = gc.weak_hash_set_remove(&this.m_associated_animations, value)

## Ported from Libraries/LibWeb/Animations/AnimationTimeline.h:49 Web::Animations::AnimationTimeline::associated_animations: the
## animations of the weak set that live.
pub func animations_animation_timeline_associated_animations(this: AnimationsAnimationTimeline*) -> ak.Vector[AnimationsAnimation*]:
    var animations: ak.Vector[AnimationsAnimation*]
    for animation in gc.weak_hash_set_begin(&this.m_associated_animations):
        ak.vector_append_t(&animations, animation)
    return animations

## Ported from Libraries/LibWeb/Animations/AnimationTimeline.cpp:66 Web::Animations::AnimationTimeline::AnimationTimeline (protected).
pub func animations_animation_timeline_construct(this: AnimationsAnimationTimeline*, realm: Realm*):
    bind_platform_object_construct_realm(this.bind_platform_object(), realm)

## Ported from Libraries/LibWeb/Animations/AnimationTimeline.cpp:71 Web::Animations::AnimationTimeline::finalize (override).
pub func animations_animation_timeline_finalize_impl(base: gc.Cell*):
    let this = (AnimationsAnimationTimeline*)base
    gc.cell_finalize_impl(base)
    if let document = this.m_associated_document:
        dom_document_disassociate_with_timeline(document, this)

## Ported from Libraries/LibWeb/Animations/AnimationTimeline.cpp:78 Web::Animations::AnimationTimeline::initialize (override).
pub func animations_animation_timeline_initialize_impl(base: JsCell*, realm: Realm*):
    web_set_prototype_for_interface(base, realm, BindInterfaceName.animation_timeline)
    js_cell_initialize_impl(base, realm)

## Ported from Libraries/LibWeb/Animations/AnimationTimeline.cpp:84 Web::Animations::AnimationTimeline::visit_edges (override).
pub func animations_animation_timeline_visit_edges_impl(base: gc.Cell*, visitor: gc.CellVisitor*):
    let this = (AnimationsAnimationTimeline*)base
    bind_platform_object_visit_edges_impl(base, visitor)
    gc.cell_visitor_visit_t(visitor, this.m_associated_document)
    # We intentionally don't visit m_associated_animations here to avoid keeping Animations alive solely because they
    # are associated with a timeline. Animations are disassociated from timelines in Animation::finalize() so we don't
    # need to worry about dangling references.