mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 15:40:19 +00:00
LibWeb: Support TrackEvent instances with an AudioTrack track type
This commit is contained in:
parent
11af5119b6
commit
6520a9a849
Notes:
sideshowbarker
2024-07-17 05:58:46 +09:00
Author: https://github.com/trflynn89 Commit: https://github.com/SerenityOS/serenity/commit/6520a9a849 Pull-request: https://github.com/SerenityOS/serenity/pull/19397
5 changed files with 33 additions and 16 deletions
|
@ -27,6 +27,7 @@ static bool is_platform_object(Type const& type)
|
|||
static constexpr Array types = {
|
||||
"AbortSignal"sv,
|
||||
"Attr"sv,
|
||||
"AudioTrack"sv,
|
||||
"Blob"sv,
|
||||
"CanvasGradient"sv,
|
||||
"CanvasPattern"sv,
|
||||
|
|
|
@ -1020,9 +1020,9 @@ WebIDL::ExceptionOr<void> HTMLMediaElement::process_media_data(Function<void(Str
|
|||
|
||||
// 7. Fire an event named addtrack at this VideoTrackList object, using TrackEvent, with the track attribute initialized to the new VideoTrack object.
|
||||
TrackEventInit event_init {};
|
||||
event_init.track = video_track;
|
||||
event_init.track = JS::make_handle(video_track);
|
||||
|
||||
auto event = TRY(TrackEvent::create(realm, HTML::EventNames::addtrack, event_init));
|
||||
auto event = TRY(TrackEvent::create(realm, HTML::EventNames::addtrack, move(event_init)));
|
||||
m_video_tracks->dispatch_event(event);
|
||||
}
|
||||
|
||||
|
|
|
@ -10,19 +10,19 @@
|
|||
|
||||
namespace Web::HTML {
|
||||
|
||||
WebIDL::ExceptionOr<JS::NonnullGCPtr<TrackEvent>> TrackEvent::create(JS::Realm& realm, FlyString const& event_name, TrackEventInit const& event_init)
|
||||
WebIDL::ExceptionOr<JS::NonnullGCPtr<TrackEvent>> TrackEvent::create(JS::Realm& realm, FlyString const& event_name, TrackEventInit event_init)
|
||||
{
|
||||
return MUST_OR_THROW_OOM(realm.heap().allocate<TrackEvent>(realm, realm, event_name, event_init));
|
||||
return MUST_OR_THROW_OOM(realm.heap().allocate<TrackEvent>(realm, realm, event_name, move(event_init)));
|
||||
}
|
||||
|
||||
WebIDL::ExceptionOr<JS::NonnullGCPtr<TrackEvent>> TrackEvent::construct_impl(JS::Realm& realm, FlyString const& event_name, TrackEventInit const& event_init)
|
||||
WebIDL::ExceptionOr<JS::NonnullGCPtr<TrackEvent>> TrackEvent::construct_impl(JS::Realm& realm, FlyString const& event_name, TrackEventInit event_init)
|
||||
{
|
||||
return create(realm, event_name, event_init);
|
||||
return create(realm, event_name, move(event_init));
|
||||
}
|
||||
|
||||
TrackEvent::TrackEvent(JS::Realm& realm, FlyString const& event_name, TrackEventInit const& event_init)
|
||||
TrackEvent::TrackEvent(JS::Realm& realm, FlyString const& event_name, TrackEventInit event_init)
|
||||
: DOM::Event(realm, event_name, event_init)
|
||||
, m_track(event_init.track)
|
||||
, m_track(move(event_init.track))
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -34,4 +34,15 @@ JS::ThrowCompletionOr<void> TrackEvent::initialize(JS::Realm& realm)
|
|||
return {};
|
||||
}
|
||||
|
||||
Variant<Empty, JS::Handle<VideoTrack>, JS::Handle<AudioTrack>> TrackEvent::track() const
|
||||
{
|
||||
// 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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -7,30 +7,34 @@
|
|||
#pragma once
|
||||
|
||||
#include <AK/FlyString.h>
|
||||
#include <AK/Optional.h>
|
||||
#include <AK/Variant.h>
|
||||
#include <LibJS/Heap/Handle.h>
|
||||
#include <LibWeb/DOM/Event.h>
|
||||
|
||||
namespace Web::HTML {
|
||||
|
||||
struct TrackEventInit : public DOM::EventInit {
|
||||
JS::GCPtr<VideoTrack> track;
|
||||
using TrackType = Optional<Variant<JS::Handle<VideoTrack>, JS::Handle<AudioTrack>>>;
|
||||
TrackType track;
|
||||
};
|
||||
|
||||
class TrackEvent : public DOM::Event {
|
||||
WEB_PLATFORM_OBJECT(TrackEvent, DOM::Event);
|
||||
|
||||
public:
|
||||
static WebIDL::ExceptionOr<JS::NonnullGCPtr<TrackEvent>> create(JS::Realm&, FlyString const& event_name, TrackEventInit const& event_init = {});
|
||||
static WebIDL::ExceptionOr<JS::NonnullGCPtr<TrackEvent>> construct_impl(JS::Realm&, FlyString const& event_name, TrackEventInit const& event_init);
|
||||
static WebIDL::ExceptionOr<JS::NonnullGCPtr<TrackEvent>> create(JS::Realm&, FlyString const& event_name, TrackEventInit event_init = {});
|
||||
static WebIDL::ExceptionOr<JS::NonnullGCPtr<TrackEvent>> construct_impl(JS::Realm&, FlyString const& event_name, TrackEventInit event_init);
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/media.html#dom-trackevent-track
|
||||
JS::GCPtr<VideoTrack> track() const { return m_track; }
|
||||
Variant<Empty, JS::Handle<VideoTrack>, JS::Handle<AudioTrack>> track() const;
|
||||
|
||||
private:
|
||||
TrackEvent(JS::Realm&, FlyString const& event_name, TrackEventInit const& event_init);
|
||||
TrackEvent(JS::Realm&, FlyString const& event_name, TrackEventInit event_init);
|
||||
|
||||
virtual JS::ThrowCompletionOr<void> initialize(JS::Realm&) override;
|
||||
|
||||
JS::GCPtr<VideoTrack> m_track;
|
||||
TrackEventInit::TrackType m_track;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#import <DOM/Event.idl>
|
||||
#import <HTML/AudioTrack.idl>
|
||||
#import <HTML/VideoTrack.idl>
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/media.html#trackevent
|
||||
|
@ -7,10 +8,10 @@ interface TrackEvent : Event {
|
|||
constructor(DOMString type, optional TrackEventInit eventInitDict = {});
|
||||
|
||||
// FIXME: Should be: (VideoTrack or AudioTrack or TextTrack)?
|
||||
readonly attribute VideoTrack? track;
|
||||
readonly attribute (VideoTrack or AudioTrack)? track;
|
||||
};
|
||||
|
||||
dictionary TrackEventInit : EventInit {
|
||||
// FIXME: Should be: (VideoTrack or AudioTrack or TextTrack)?
|
||||
VideoTrack? track = null;
|
||||
(VideoTrack or AudioTrack)? track = null;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue