2023-04-04 09:28:59 -04:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2023, Tim Flynn <trflynn89@serenityos.org>
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <LibWeb/Bindings/Intrinsics.h>
|
|
|
|
#include <LibWeb/Bindings/TrackEventPrototype.h>
|
|
|
|
#include <LibWeb/HTML/TrackEvent.h>
|
|
|
|
|
|
|
|
namespace Web::HTML {
|
|
|
|
|
2024-11-14 10:01:23 -05:00
|
|
|
GC_DEFINE_ALLOCATOR(TrackEvent);
|
2023-12-23 09:15:27 -05:00
|
|
|
|
2024-11-14 10:01:23 -05: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-13 11:50:17 -05:00
|
|
|
return realm.create<TrackEvent>(realm, event_name, move(event_init));
|
2023-04-04 09:28:59 -04:00
|
|
|
}
|
|
|
|
|
2024-11-14 10:01:23 -05: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
|
|
|
}
|
|
|
|
|
2023-06-13 10:55:03 -04:00
|
|
|
TrackEvent::TrackEvent(JS::Realm& realm, FlyString const& event_name, TrackEventInit event_init)
|
2023-04-06 10:12:33 -04:00
|
|
|
: DOM::Event(realm, event_name, event_init)
|
2023-06-13 10:55:03 -04:00
|
|
|
, m_track(move(event_init.track))
|
2023-04-04 09:28:59 -04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2023-08-07 02:41:28 -04:00
|
|
|
void TrackEvent::initialize(JS::Realm& realm)
|
2023-04-04 09:28:59 -04:00
|
|
|
{
|
2023-08-07 02:41:28 -04:00
|
|
|
Base::initialize(realm);
|
2024-03-16 08:13:08 -04:00
|
|
|
WEB_SET_PROTOTYPE_FOR_INTERFACE(TrackEvent);
|
2023-04-04 09:28:59 -04:00
|
|
|
}
|
|
|
|
|
2024-11-14 10:01:23 -05:00
|
|
|
Variant<Empty, GC::Root<VideoTrack>, GC::Root<AudioTrack>, GC::Root<TextTrack>> TrackEvent::track() const
|
2023-06-13 10:55:03 -04:00
|
|
|
{
|
|
|
|
// FIXME: This is a bit awkward. When creating a nullable union, our IDL generator creates a type of
|
|
|
|
// Optional<Variant<...>>, using an empty Optional to represent null. But when retrieving the
|
|
|
|
// attribute, it expects a type of Variant<Empty, ...>, using Empty to represent null.
|
|
|
|
if (!m_track.has_value())
|
|
|
|
return Empty {};
|
|
|
|
|
|
|
|
return *m_track;
|
|
|
|
}
|
|
|
|
|
2023-04-04 09:28:59 -04:00
|
|
|
}
|