Luce packages
LuceLuce BaseLuciaOS

dymokomi/luce-browser-engine

Source of release 0.6.0

0.6.0 / src / web / html / audio_track_list.lucb

#==============================================================================================
#
#   audio_track_list - HTML::AudioTrackList, a media element's audio tracks
#
#   DESCRIPTION:
#       Port of Libraries/LibWeb/HTML/AudioTrackList.cpp (lines 1-128) and the inline functions
#       of AudioTrackList.h (length, for_each_track). The indexed property getter
#       (internal_get_own_property) answers JS property keys (phase 3).
#
#       Copyright (c) 2023, Tim Flynn <trflynn89@serenityos.org>
#       Copyright (c) 2026 the luce-browser authors.
#       SPDX-License-Identifier: BSD-2-Clause
#
#==============================================================================================

## Ported from AudioTrackList.cpp:18 Web::HTML::AudioTrackList::AudioTrackList.
pub func html_audio_track_list_construct(this: HtmlAudioTrackList*, realm: Realm*):
    dom_event_target_construct(this.dom_event_target(), realm, JsObjectMayInterfereWithIndexedPropertyAccess.yes)

## Ported from AudioTrackList.cpp:23 Web::HTML::AudioTrackList::initialize (override).
pub func html_audio_track_list_initialize_impl(base: JsCell*, realm: Realm*):
    web_set_prototype_for_interface(base, realm, BindInterfaceName.audio_track_list)
    dom_event_target_initialize_impl(base, realm)

## Ported from AudioTrackList.cpp:30 Web::HTML::AudioTrackList::internal_get_own_property (override).
# https://html.spec.whatwg.org/multipage/media.html#dom-tracklist-item
pub func html_audio_track_list_internal_get_own_property_impl(base: BindPlatformObject*, property_name: JsPropertyKey) -> (JsPropertyDescriptor?)!:
    # To determine the value of an indexed property for a given index index in an AudioTrackList or VideoTrackList
    # object list, the user agent must return the AudioTrack or VideoTrack object that represents the indexth track
    # in list. (JS property keys and descriptors.)
    trap("unported (P3): Web::HTML::AudioTrackList::internal_get_own_property")

## Ported from AudioTrackList.cpp:47 Web::HTML::AudioTrackList::add_track.
pub func html_audio_track_list_add_track(this: HtmlAudioTrackList*, audio_track: HtmlAudioTrack*):
    ak.vector_append_t(&this.m_audio_tracks, audio_track)
    html_audio_track_set_audio_track_list(audio_track, this)

## Ported from AudioTrackList.cpp:53 Web::HTML::AudioTrackList::remove_all_tracks.
pub func html_audio_track_list_remove_all_tracks(this: HtmlAudioTrackList*):
    for audio_track in ak.vector_span(&this.m_audio_tracks):
        html_audio_track_set_enabled(audio_track, false)
    ak.vector_clear(&this.m_audio_tracks)

## Ported from AudioTrackList.h:25 Web::HTML::AudioTrackList::length.
# https://html.spec.whatwg.org/multipage/media.html#dom-audiotracklist-length
pub func html_audio_track_list_length(this: HtmlAudioTrackList*) -> usize:
    return ak.vector_size(&this.m_audio_tracks)

## The tracks AudioTrackList::for_each_track (AudioTrackList.h:30) visits, in order: a copy, so a
## loop over it may change the list.
pub func html_audio_track_list_tracks(this: HtmlAudioTrackList*) -> ak.Vector[HtmlAudioTrack*]:
    return ak.vector_clone(&this.m_audio_tracks)

## Ported from AudioTrackList.cpp:61 Web::HTML::AudioTrackList::get_track_by_id.
# https://html.spec.whatwg.org/multipage/media.html#dom-audiotracklist-gettrackbyid
pub func html_audio_track_list_get_track_by_id(this: HtmlAudioTrackList*, id: ak.StringView) -> HtmlAudioTrack*?:
    # The AudioTrackList getTrackById(id) and VideoTrackList getTrackById(id) methods must return the first AudioTrack
    # or VideoTrack object (respectively) in the AudioTrackList or VideoTrackList object (respectively) whose identifier
    # is equal to the value of the id argument (in the natural order of the list, as defined above).
    for audio_track in ak.vector_span(&this.m_audio_tracks):
        if ak.utf16_string_base_eq_string_view(&audio_track.media_track_base.m_id.utf16_string_base, id):
            return audio_track

    # When no tracks match the given argument, the methods must return null.
    return none

## Ported from AudioTrackList.cpp:77 Web::HTML::AudioTrackList::has_enabled_track.
pub func html_audio_track_list_has_enabled_track(this: HtmlAudioTrackList*) -> bool:
    for audio_track in ak.vector_span(&this.m_audio_tracks):
        if html_audio_track_enabled(audio_track):
            return true
    return false

## Ported from AudioTrackList.cpp:87 Web::HTML::AudioTrackList::set_onchange.
# https://html.spec.whatwg.org/multipage/media.html#handler-tracklist-onchange
pub func html_audio_track_list_set_onchange(this: HtmlAudioTrackList*, event_handler: IdlCallbackType*?):
    dom_event_target_set_event_handler_attribute(this.dom_event_target(), html_event_names_change, event_handler)

## Ported from AudioTrackList.cpp:93 Web::HTML::AudioTrackList::onchange.
pub func html_audio_track_list_onchange(this: HtmlAudioTrackList*) -> IdlCallbackType*?:
    return dom_event_target_event_handler_attribute(this.dom_event_target(), html_event_names_change)

## Ported from AudioTrackList.cpp:99 Web::HTML::AudioTrackList::set_onaddtrack.
# https://html.spec.whatwg.org/multipage/media.html#handler-tracklist-onaddtrack
pub func html_audio_track_list_set_onaddtrack(this: HtmlAudioTrackList*, event_handler: IdlCallbackType*?):
    dom_event_target_set_event_handler_attribute(this.dom_event_target(), html_event_names_addtrack, event_handler)

## Ported from AudioTrackList.cpp:105 Web::HTML::AudioTrackList::onaddtrack.
pub func html_audio_track_list_onaddtrack(this: HtmlAudioTrackList*) -> IdlCallbackType*?:
    return dom_event_target_event_handler_attribute(this.dom_event_target(), html_event_names_addtrack)

## Ported from AudioTrackList.cpp:111 Web::HTML::AudioTrackList::set_onremovetrack.
# https://html.spec.whatwg.org/multipage/media.html#handler-tracklist-onremovetrack
pub func html_audio_track_list_set_onremovetrack(this: HtmlAudioTrackList*, event_handler: IdlCallbackType*?):
    dom_event_target_set_event_handler_attribute(this.dom_event_target(), html_event_names_removetrack, event_handler)

## Ported from AudioTrackList.cpp:117 Web::HTML::AudioTrackList::onremovetrack.
pub func html_audio_track_list_onremovetrack(this: HtmlAudioTrackList*) -> IdlCallbackType*?:
    return dom_event_target_event_handler_attribute(this.dom_event_target(), html_event_names_removetrack)

## Ported from AudioTrackList.cpp:122 Web::HTML::AudioTrackList::visit_edges (override).
pub func html_audio_track_list_visit_edges_impl(base: gc.Cell*, visitor: gc.CellVisitor*):
    let this = (HtmlAudioTrackList*)base
    dom_event_target_visit_edges_impl(base, visitor)
    for audio_track in ak.vector_span(&this.m_audio_tracks):
        gc.cell_visitor_visit_t(visitor, audio_track)