Luce packages
LuceLuce BaseLuciaOS

dymokomi/luce-browser-engine

Source of release 0.6.0

0.6.0 / src / web / html / animation_frame_callback_driver.lucb

#==============================================================================================
#
#   animation_frame_callback_driver - HTML::AnimationFrameCallbackDriver: a window's map of
#   animation frame callbacks
#
#   DESCRIPTION:
#       Port of Libraries/LibWeb/HTML/AnimationFrameCallbackDriver.cpp (lines 1-49) and
#       AnimationFrameCallbackDriver.h (lines 1-42). Callbacks are kept in insertion order
#       under increasing identifiers; run() moves the map aside first, so callbacks added while
#       it runs wait for the next frame.
#
#       Copyright (c) 2022, the SerenityOS developers.
#       Copyright (c) 2024, Andreas Kling <andreas@ladybird.org>
#       Copyright (c) 2024, Tim Flynn <trflynn89@ladybird.org>
#       SPDX-License-Identifier: BSD-2-Clause
#
#==============================================================================================

## Ported from Libraries/LibWeb/HTML/AnimationFrameCallbackDriver.cpp:16 Web::HTML::AnimationFrameCallbackDriver::visit_edges (override).
pub func html_animation_frame_callback_driver_visit_edges_impl(base: gc.Cell*, visitor: gc.CellVisitor*):
    let this = (HtmlAnimationFrameCallbackDriver*)base
    gc.cell_visit_edges_impl(base, visitor)
    gc.cell_visitor_visit_opaque_3(visitor, &this.m_callbacks)
    gc.cell_visitor_visit_opaque_3(visitor, &this.m_executing_callbacks)

## Ported from Libraries/LibWeb/HTML/AnimationFrameCallbackDriver.cpp:23 Web::HTML::AnimationFrameCallbackDriver::add.
pub func html_animation_frame_callback_driver_add(this: HtmlAnimationFrameCallbackDriver*, handler: gc.Function1[f64, unit]*) -> u32:
    this.m_animation_frame_callback_identifier +%= 1
    let id = this.m_animation_frame_callback_identifier
    _ = ak.ordered_hash_map_set(&this.m_callbacks, id, handler)
    return id

## Ported from Libraries/LibWeb/HTML/AnimationFrameCallbackDriver.cpp:30 Web::HTML::AnimationFrameCallbackDriver::remove.
pub func html_animation_frame_callback_driver_remove(this: HtmlAnimationFrameCallbackDriver*, id: u32) -> bool:
    return ak.ordered_hash_map_remove_k(&this.m_callbacks, id)

## Ported from Libraries/LibWeb/HTML/AnimationFrameCallbackDriver.cpp:35 Web::HTML::AnimationFrameCallbackDriver::has_callbacks.
pub func html_animation_frame_callback_driver_has_callbacks(this: HtmlAnimationFrameCallbackDriver*) -> bool:
    return not ak.ordered_hash_map_is_empty(&this.m_callbacks)

## Ported from Libraries/LibWeb/HTML/AnimationFrameCallbackDriver.cpp:40 Web::HTML::AnimationFrameCallbackDriver::run.
pub func html_animation_frame_callback_driver_run(this: HtmlAnimationFrameCallbackDriver*, now: f64):
    defer ak.ordered_hash_map_clear(&this.m_executing_callbacks)
    this.m_executing_callbacks = this.m_callbacks
    this.m_callbacks = ak.OrderedHashMap[u32, gc.Function1[f64, unit]*, ak.U32Traits]()

    for entry in ak.ordered_hash_map_begin(&this.m_executing_callbacks):
        ak.function1_call(&entry.value.function, now)