2023-06-12 13:52:30 -04:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2023, Tim Flynn <trflynn89@serenityos.org>
|
2025-09-30 17:18:32 -05:00
|
|
|
* Copyright (c) 2025, Gregory Bertilson <gregory@ladybird.org>
|
2023-06-12 13:52:30 -04:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <LibJS/Runtime/Realm.h>
|
|
|
|
|
#include <LibJS/Runtime/VM.h>
|
|
|
|
|
#include <LibWeb/Bindings/AudioTrackPrototype.h>
|
|
|
|
|
#include <LibWeb/Bindings/Intrinsics.h>
|
|
|
|
|
#include <LibWeb/DOM/Event.h>
|
|
|
|
|
#include <LibWeb/HTML/AudioTrack.h>
|
|
|
|
|
#include <LibWeb/HTML/AudioTrackList.h>
|
|
|
|
|
#include <LibWeb/HTML/EventNames.h>
|
|
|
|
|
#include <LibWeb/HTML/HTMLMediaElement.h>
|
|
|
|
|
#include <LibWeb/Layout/Node.h>
|
|
|
|
|
|
|
|
|
|
namespace Web::HTML {
|
|
|
|
|
|
2024-11-15 04:01:23 +13:00
|
|
|
GC_DEFINE_ALLOCATOR(AudioTrack);
|
2023-11-19 19:47:52 +01:00
|
|
|
|
2025-09-24 14:08:34 -05:00
|
|
|
AudioTrack::AudioTrack(JS::Realm& realm, GC::Ref<HTMLMediaElement> media_element, Media::Track const& track)
|
2025-09-30 17:18:32 -05:00
|
|
|
: MediaTrackBase(realm, media_element, track)
|
2023-06-12 13:52:30 -04:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-30 17:18:32 -05:00
|
|
|
AudioTrack::~AudioTrack() = default;
|
2023-06-12 13:52:30 -04:00
|
|
|
|
2023-08-07 08:41:28 +02:00
|
|
|
void AudioTrack::initialize(JS::Realm& realm)
|
2023-06-12 13:52:30 -04:00
|
|
|
{
|
2024-03-16 13:13:08 +01:00
|
|
|
WEB_SET_PROTOTYPE_FOR_INTERFACE(AudioTrack);
|
2025-04-20 16:22:57 +02:00
|
|
|
Base::initialize(realm);
|
2023-06-12 13:52:30 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AudioTrack::visit_edges(Cell::Visitor& visitor)
|
|
|
|
|
{
|
|
|
|
|
Base::visit_edges(visitor);
|
|
|
|
|
visitor.visit(m_audio_track_list);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// https://html.spec.whatwg.org/multipage/media.html#dom-audiotrack-enabled
|
|
|
|
|
void AudioTrack::set_enabled(bool enabled)
|
|
|
|
|
{
|
|
|
|
|
// On setting, it must enable the track if the new value is true, and disable it otherwise. (If the track is no
|
|
|
|
|
// longer in an AudioTrackList object, then the track being enabled or disabled has no effect beyond changing the
|
|
|
|
|
// value of the attribute on the AudioTrack object.)
|
|
|
|
|
if (m_enabled == enabled)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (m_audio_track_list) {
|
|
|
|
|
// Whenever an audio track in an AudioTrackList that was disabled is enabled, and whenever one that was enabled
|
|
|
|
|
// is disabled, the user agent must queue a media element task given the media element to fire an event named
|
|
|
|
|
// change at the AudioTrackList object.
|
2025-09-30 17:18:32 -05:00
|
|
|
media_element().queue_a_media_element_task([this]() {
|
2023-08-13 13:05:26 +02:00
|
|
|
m_audio_track_list->dispatch_event(DOM::Event::create(realm(), HTML::EventNames::change));
|
2023-06-12 13:52:30 -04:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_enabled = enabled;
|
2025-09-30 17:18:32 -05:00
|
|
|
media_element().set_audio_track_enabled({}, this, enabled);
|
2023-06-12 13:52:30 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|