dymokomi/luce-browser-engine
Source of release 0.6.0
0.6.0 / src / web / html / video_track_list.lucb
#==============================================================================================
#
# video_track_list - HTML::VideoTrackList, a media element's video tracks
#
# DESCRIPTION:
# Port of Libraries/LibWeb/HTML/VideoTrackList.cpp (lines 1-144) and the inline functions
# of VideoTrackList.h (video_tracks, 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 VideoTrackList.cpp:19 Web::HTML::VideoTrackList::VideoTrackList.
pub func html_video_track_list_construct(this: HtmlVideoTrackList*, realm: Realm*, media_element: HtmlMediaElement*?):
dom_event_target_construct(this.dom_event_target(), realm, JsObjectMayInterfereWithIndexedPropertyAccess.yes)
this.m_media_element = media_element
## Ported from VideoTrackList.cpp:25 Web::HTML::VideoTrackList::initialize (override).
pub func html_video_track_list_initialize_impl(base: JsCell*, realm: Realm*):
web_set_prototype_for_interface(base, realm, BindInterfaceName.video_track_list)
dom_event_target_initialize_impl(base, realm)
## Ported from VideoTrackList.cpp:32 Web::HTML::VideoTrackList::internal_get_own_property (override).
# https://html.spec.whatwg.org/multipage/media.html#dom-tracklist-item
pub func html_video_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::VideoTrackList::internal_get_own_property")
## Ported from VideoTrackList.cpp:49 Web::HTML::VideoTrackList::add_track.
pub func html_video_track_list_add_track(this: HtmlVideoTrackList*, video_track: HtmlVideoTrack*):
ak.vector_append_t(&this.m_video_tracks, video_track)
html_video_track_set_video_track_list(video_track, this)
if let media_element = this.m_media_element:
html_media_element_update_natural_dimensions(media_element)
## Ported from VideoTrackList.cpp:57 Web::HTML::VideoTrackList::remove_all_tracks.
pub func html_video_track_list_remove_all_tracks(this: HtmlVideoTrackList*):
for video_track in ak.vector_span(&this.m_video_tracks):
html_video_track_set_video_track_list(video_track, none)
html_video_track_set_selected(video_track, false)
ak.vector_clear(&this.m_video_tracks)
if let media_element = this.m_media_element:
html_media_element_update_natural_dimensions(media_element)
## Ported from VideoTrackList.h:25 Web::HTML::VideoTrackList::video_tracks.
pub func html_video_track_list_video_tracks(this: HtmlVideoTrackList*) -> HtmlVideoTrack*[]:
return ak.vector_span(&this.m_video_tracks)
## Ported from VideoTrackList.h:28 Web::HTML::VideoTrackList::length.
# https://html.spec.whatwg.org/multipage/media.html#dom-videotracklist-length
pub func html_video_track_list_length(this: HtmlVideoTrackList*) -> usize:
return ak.vector_size(&this.m_video_tracks)
## The tracks VideoTrackList::for_each_track (VideoTrackList.h:33) visits, in order: a copy, so a
## loop over it may change the list.
pub func html_video_track_list_tracks(this: HtmlVideoTrackList*) -> ak.Vector[HtmlVideoTrack*]:
return ak.vector_clone(&this.m_video_tracks)
## Ported from VideoTrackList.cpp:69 Web::HTML::VideoTrackList::get_track_by_id.
# https://html.spec.whatwg.org/multipage/media.html#dom-videotracklist-gettrackbyid
pub func html_video_track_list_get_track_by_id(this: HtmlVideoTrackList*, id: ak.StringView) -> HtmlVideoTrack*?:
# 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 video_track in ak.vector_span(&this.m_video_tracks):
if ak.utf16_string_base_eq_string_view(&video_track.media_track_base.m_id.utf16_string_base, id):
return video_track
# When no tracks match the given argument, the methods must return null.
return none
## Ported from VideoTrackList.cpp:86 Web::HTML::VideoTrackList::selected_index.
# https://html.spec.whatwg.org/multipage/media.html#dom-videotracklist-selectedindex
pub func html_video_track_list_selected_index(this: HtmlVideoTrackList*) -> i32:
# The VideoTrackList selectedIndex attribute must return the index of the currently selected track, if any.
let tracks = ak.vector_span(&this.m_video_tracks)
for index in 0..<tracks.length:
if html_video_track_selected(tracks[index]):
return (i32)index
# If the VideoTrackList object does not currently represent any tracks, or if none of the tracks are selected,
# it must instead return −1.
return -1
## Ported from VideoTrackList.cpp:102 Web::HTML::VideoTrackList::set_onchange.
# https://html.spec.whatwg.org/multipage/media.html#handler-tracklist-onchange
pub func html_video_track_list_set_onchange(this: HtmlVideoTrackList*, event_handler: IdlCallbackType*?):
dom_event_target_set_event_handler_attribute(this.dom_event_target(), html_event_names_change, event_handler)
## Ported from VideoTrackList.cpp:108 Web::HTML::VideoTrackList::onchange.
pub func html_video_track_list_onchange(this: HtmlVideoTrackList*) -> IdlCallbackType*?:
return dom_event_target_event_handler_attribute(this.dom_event_target(), html_event_names_change)
## Ported from VideoTrackList.cpp:114 Web::HTML::VideoTrackList::set_onaddtrack.
# https://html.spec.whatwg.org/multipage/media.html#handler-tracklist-onaddtrack
pub func html_video_track_list_set_onaddtrack(this: HtmlVideoTrackList*, event_handler: IdlCallbackType*?):
dom_event_target_set_event_handler_attribute(this.dom_event_target(), html_event_names_addtrack, event_handler)
## Ported from VideoTrackList.cpp:120 Web::HTML::VideoTrackList::onaddtrack.
pub func html_video_track_list_onaddtrack(this: HtmlVideoTrackList*) -> IdlCallbackType*?:
return dom_event_target_event_handler_attribute(this.dom_event_target(), html_event_names_addtrack)
## Ported from VideoTrackList.cpp:126 Web::HTML::VideoTrackList::set_onremovetrack.
# https://html.spec.whatwg.org/multipage/media.html#handler-tracklist-onremovetrack
pub func html_video_track_list_set_onremovetrack(this: HtmlVideoTrackList*, event_handler: IdlCallbackType*?):
dom_event_target_set_event_handler_attribute(this.dom_event_target(), html_event_names_removetrack, event_handler)
## Ported from VideoTrackList.cpp:132 Web::HTML::VideoTrackList::onremovetrack.
pub func html_video_track_list_onremovetrack(this: HtmlVideoTrackList*) -> IdlCallbackType*?:
return dom_event_target_event_handler_attribute(this.dom_event_target(), html_event_names_removetrack)
## Ported from VideoTrackList.cpp:137 Web::HTML::VideoTrackList::visit_edges (override).
pub func html_video_track_list_visit_edges_impl(base: gc.Cell*, visitor: gc.CellVisitor*):
let this = (HtmlVideoTrackList*)base
dom_event_target_visit_edges_impl(base, visitor)
gc.cell_visitor_visit_cell(visitor, (gc.Cell*?)this.m_media_element)
for video_track in ak.vector_span(&this.m_video_tracks):
gc.cell_visitor_visit_t(visitor, video_track)