2023-04-04 09:28:59 -04:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2023, Tim Flynn <trflynn89@serenityos.org>
|
2026-02-16 14:26:27 +00:00
|
|
|
* Copyright (c) 2026, Sam Atkins <sam@ladybird.org>
|
2023-04-04 09:28:59 -04:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <LibWeb/Bindings/Intrinsics.h>
|
|
|
|
|
#include <LibWeb/Bindings/TrackEventPrototype.h>
|
2026-02-16 14:26:27 +00:00
|
|
|
#include <LibWeb/HTML/AudioTrack.h>
|
|
|
|
|
#include <LibWeb/HTML/TextTrack.h>
|
2023-04-04 09:28:59 -04:00
|
|
|
#include <LibWeb/HTML/TrackEvent.h>
|
2026-02-16 14:26:27 +00:00
|
|
|
#include <LibWeb/HTML/VideoTrack.h>
|
2023-04-04 09:28:59 -04:00
|
|
|
|
|
|
|
|
namespace Web::HTML {
|
|
|
|
|
|
2024-11-15 04:01:23 +13:00
|
|
|
GC_DEFINE_ALLOCATOR(TrackEvent);
|
2023-12-23 15:15:27 +01:00
|
|
|
|
2024-11-15 04:01:23 +13:00
|
|
|
GC::Ref<TrackEvent> TrackEvent::create(JS::Realm& realm, FlyString const& event_name, TrackEventInit event_init)
|
2023-04-04 09:28:59 -04:00
|
|
|
{
|
2024-11-14 05:50:17 +13:00
|
|
|
return realm.create<TrackEvent>(realm, event_name, move(event_init));
|
2023-04-04 09:28:59 -04:00
|
|
|
}
|
|
|
|
|
|
2024-11-15 04:01:23 +13:00
|
|
|
WebIDL::ExceptionOr<GC::Ref<TrackEvent>> TrackEvent::construct_impl(JS::Realm& realm, FlyString const& event_name, TrackEventInit event_init)
|
2023-04-04 09:28:59 -04:00
|
|
|
{
|
2023-06-13 10:55:03 -04:00
|
|
|
return create(realm, event_name, move(event_init));
|
2023-04-04 09:28:59 -04:00
|
|
|
}
|
|
|
|
|
|
2026-02-16 14:26:27 +00:00
|
|
|
TrackEvent::TrackTypeInternal TrackEvent::to_track_type_internal(TrackEventInit::TrackType const& track_type)
|
|
|
|
|
{
|
|
|
|
|
if (!track_type.has_value())
|
|
|
|
|
return Empty {};
|
|
|
|
|
|
|
|
|
|
return track_type->visit(
|
|
|
|
|
[](GC::Root<VideoTrack> const& root) -> TrackTypeInternal { return GC::Ref { *root }; },
|
|
|
|
|
[](GC::Root<AudioTrack> const& root) -> TrackTypeInternal { return GC::Ref { *root }; },
|
|
|
|
|
[](GC::Root<TextTrack> const& root) -> TrackTypeInternal { return GC::Ref { *root }; });
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-13 10:55:03 -04:00
|
|
|
TrackEvent::TrackEvent(JS::Realm& realm, FlyString const& event_name, TrackEventInit event_init)
|
2023-04-06 16:12:33 +02:00
|
|
|
: DOM::Event(realm, event_name, event_init)
|
2026-02-16 14:26:27 +00:00
|
|
|
, m_track(to_track_type_internal(event_init.track))
|
2023-04-04 09:28:59 -04:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-07 08:41:28 +02:00
|
|
|
void TrackEvent::initialize(JS::Realm& realm)
|
2023-04-04 09:28:59 -04:00
|
|
|
{
|
2024-03-16 13:13:08 +01:00
|
|
|
WEB_SET_PROTOTYPE_FOR_INTERFACE(TrackEvent);
|
2025-04-20 16:22:57 +02:00
|
|
|
Base::initialize(realm);
|
2023-04-04 09:28:59 -04:00
|
|
|
}
|
|
|
|
|
|
2026-02-16 14:26:27 +00:00
|
|
|
void TrackEvent::visit_edges(Visitor& visitor)
|
2023-06-13 10:55:03 -04:00
|
|
|
{
|
2026-02-16 14:26:27 +00:00
|
|
|
Base::visit_edges(visitor);
|
|
|
|
|
m_track.visit(
|
|
|
|
|
[](Empty) {},
|
|
|
|
|
[&](auto const& ref) { visitor.visit(ref); });
|
|
|
|
|
}
|
2023-06-13 10:55:03 -04:00
|
|
|
|
2026-02-16 14:26:27 +00:00
|
|
|
TrackEvent::TrackReturnType TrackEvent::track() const
|
|
|
|
|
{
|
|
|
|
|
return m_track.visit(
|
|
|
|
|
[](Empty) -> TrackReturnType { return Empty {}; },
|
|
|
|
|
[](auto const& ref) -> TrackReturnType { return GC::Root { *ref }; });
|
2023-06-13 10:55:03 -04:00
|
|
|
}
|
|
|
|
|
|
2023-04-04 09:28:59 -04:00
|
|
|
}
|