mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 21:07:35 +00:00
LibWeb: Support TrackEvent instances with an AudioTrack track type
This commit is contained in:
parent
11af5119b6
commit
6520a9a849
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 = {
|
static constexpr Array types = {
|
||||||
"AbortSignal"sv,
|
"AbortSignal"sv,
|
||||||
"Attr"sv,
|
"Attr"sv,
|
||||||
|
"AudioTrack"sv,
|
||||||
"Blob"sv,
|
"Blob"sv,
|
||||||
"CanvasGradient"sv,
|
"CanvasGradient"sv,
|
||||||
"CanvasPattern"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.
|
// 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 {};
|
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);
|
m_video_tracks->dispatch_event(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,19 +10,19 @@
|
||||||
|
|
||||||
namespace Web::HTML {
|
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)
|
: 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 {};
|
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
|
#pragma once
|
||||||
|
|
||||||
#include <AK/FlyString.h>
|
#include <AK/FlyString.h>
|
||||||
|
#include <AK/Optional.h>
|
||||||
|
#include <AK/Variant.h>
|
||||||
|
#include <LibJS/Heap/Handle.h>
|
||||||
#include <LibWeb/DOM/Event.h>
|
#include <LibWeb/DOM/Event.h>
|
||||||
|
|
||||||
namespace Web::HTML {
|
namespace Web::HTML {
|
||||||
|
|
||||||
struct TrackEventInit : public DOM::EventInit {
|
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 {
|
class TrackEvent : public DOM::Event {
|
||||||
WEB_PLATFORM_OBJECT(TrackEvent, DOM::Event);
|
WEB_PLATFORM_OBJECT(TrackEvent, DOM::Event);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static WebIDL::ExceptionOr<JS::NonnullGCPtr<TrackEvent>> create(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 const& 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
|
// 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:
|
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;
|
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 <DOM/Event.idl>
|
||||||
|
#import <HTML/AudioTrack.idl>
|
||||||
#import <HTML/VideoTrack.idl>
|
#import <HTML/VideoTrack.idl>
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/media.html#trackevent
|
// https://html.spec.whatwg.org/multipage/media.html#trackevent
|
||||||
|
@ -7,10 +8,10 @@ interface TrackEvent : Event {
|
||||||
constructor(DOMString type, optional TrackEventInit eventInitDict = {});
|
constructor(DOMString type, optional TrackEventInit eventInitDict = {});
|
||||||
|
|
||||||
// FIXME: Should be: (VideoTrack or AudioTrack or TextTrack)?
|
// FIXME: Should be: (VideoTrack or AudioTrack or TextTrack)?
|
||||||
readonly attribute VideoTrack? track;
|
readonly attribute (VideoTrack or AudioTrack)? track;
|
||||||
};
|
};
|
||||||
|
|
||||||
dictionary TrackEventInit : EventInit {
|
dictionary TrackEventInit : EventInit {
|
||||||
// FIXME: Should be: (VideoTrack or AudioTrack or TextTrack)?
|
// FIXME: Should be: (VideoTrack or AudioTrack or TextTrack)?
|
||||||
VideoTrack? track = null;
|
(VideoTrack or AudioTrack)? track = null;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue