mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-29 08:11:13 +00:00
LibWeb/HTML: Implement TextTrackCue idl interface
This commit is contained in:
parent
e5877cda61
commit
0b2449d8d2
Notes:
github-actions[bot]
2024-09-24 22:50:09 +00:00
Author: https://github.com/jamierocks Commit: https://github.com/LadybirdBrowser/ladybird/commit/0b2449d8d26 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/1494 Reviewed-by: https://github.com/AtkinsSJ Reviewed-by: https://github.com/tcl3 ✅
|
@ -344,6 +344,7 @@ TextDecoder
|
|||
TextEncoder
|
||||
TextMetrics
|
||||
TextTrack
|
||||
TextTrackCue
|
||||
TextTrackList
|
||||
TimeRanges
|
||||
ToggleEvent
|
||||
|
|
|
@ -462,6 +462,7 @@ set(SOURCES
|
|||
HTML/TagNames.cpp
|
||||
HTML/TextMetrics.cpp
|
||||
HTML/TextTrack.cpp
|
||||
HTML/TextTrackCue.cpp
|
||||
HTML/TextTrackList.cpp
|
||||
HTML/Timer.cpp
|
||||
HTML/TimeRanges.cpp
|
||||
|
|
|
@ -496,6 +496,7 @@ class Storage;
|
|||
class SubmitEvent;
|
||||
class TextMetrics;
|
||||
class TextTrack;
|
||||
class TextTrackCue;
|
||||
class TextTrackList;
|
||||
class Timer;
|
||||
class TimeRanges;
|
||||
|
|
|
@ -52,7 +52,9 @@ namespace Web::HTML::EventNames {
|
|||
__ENUMERATE_HTML_EVENT(durationchange) \
|
||||
__ENUMERATE_HTML_EVENT(emptied) \
|
||||
__ENUMERATE_HTML_EVENT(ended) \
|
||||
__ENUMERATE_HTML_EVENT(enter) \
|
||||
__ENUMERATE_HTML_EVENT(error) \
|
||||
__ENUMERATE_HTML_EVENT(exit) \
|
||||
__ENUMERATE_HTML_EVENT(finish) \
|
||||
__ENUMERATE_HTML_EVENT(focus) \
|
||||
__ENUMERATE_HTML_EVENT(focusin) \
|
||||
|
|
89
Userland/Libraries/LibWeb/HTML/TextTrackCue.cpp
Normal file
89
Userland/Libraries/LibWeb/HTML/TextTrackCue.cpp
Normal file
|
@ -0,0 +1,89 @@
|
|||
/*
|
||||
* Copyright (c) 2024, Jamie Mansfield <jmansfield@cadixdev.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <AK/Math.h>
|
||||
#include <LibJS/Runtime/Realm.h>
|
||||
#include <LibWeb/Bindings/Intrinsics.h>
|
||||
#include <LibWeb/Bindings/TextTrackCuePrototype.h>
|
||||
#include <LibWeb/HTML/EventNames.h>
|
||||
#include <LibWeb/HTML/TextTrackCue.h>
|
||||
|
||||
namespace Web::HTML {
|
||||
|
||||
JS_DEFINE_ALLOCATOR(TextTrackCue);
|
||||
|
||||
TextTrackCue::TextTrackCue(JS::Realm& realm, JS::GCPtr<TextTrack> track)
|
||||
: DOM::EventTarget(realm)
|
||||
, m_track(track)
|
||||
{
|
||||
}
|
||||
|
||||
TextTrackCue::~TextTrackCue() = default;
|
||||
|
||||
void TextTrackCue::initialize(JS::Realm& realm)
|
||||
{
|
||||
Base::initialize(realm);
|
||||
WEB_SET_PROTOTYPE_FOR_INTERFACE(TextTrackCue);
|
||||
}
|
||||
|
||||
void TextTrackCue::visit_edges(JS::Cell::Visitor& visitor)
|
||||
{
|
||||
Base::visit_edges(visitor);
|
||||
visitor.visit(m_track);
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/media.html#dom-texttrackcue-starttime
|
||||
void TextTrackCue::set_start_time(double start_time)
|
||||
{
|
||||
// On setting, the text track cue start time must be set to the new value, interpreted in seconds;
|
||||
m_start_time = start_time;
|
||||
|
||||
// FIXME: then, if the TextTrackCue object's text track cue is in a text track's list of cues, and that text track is in a media
|
||||
// element's list of text tracks, and the media element's show poster flag is not set, then run the time marches on steps
|
||||
// for that media element.
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/media.html#dom-texttrackcue-endtime
|
||||
WebIDL::ExceptionOr<void> TextTrackCue::set_end_time(double end_time)
|
||||
{
|
||||
// On setting, if the new value is negative Infinity or a Not-a-Number (NaN) value, then throw a TypeError exception.
|
||||
if (end_time == -AK::Infinity<double> || isnan(end_time))
|
||||
return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, "Value is negative infinity or NaN"_string };
|
||||
|
||||
// Otherwise, the text track cue end time must be set to the new value.
|
||||
m_end_time = end_time;
|
||||
|
||||
// FIXME: Then, if the TextTrackCue object's text track cue is in a text track's list of cues, and that text track is in a media
|
||||
// element's list of text tracks, and the media element's show poster flag is not set, then run the time marches on steps
|
||||
// for that media element.
|
||||
return {};
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/media.html#handler-texttrackcue-onenter
|
||||
WebIDL::CallbackType* TextTrackCue::onenter()
|
||||
{
|
||||
return event_handler_attribute(HTML::EventNames::enter);
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/media.html#handler-texttrackcue-onenter
|
||||
void TextTrackCue::set_onenter(WebIDL::CallbackType* event_handler)
|
||||
{
|
||||
set_event_handler_attribute(HTML::EventNames::enter, event_handler);
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/media.html#handler-texttrackcue-onexit
|
||||
WebIDL::CallbackType* TextTrackCue::onexit()
|
||||
{
|
||||
return event_handler_attribute(HTML::EventNames::exit);
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/media.html#handler-texttrackcue-onexit
|
||||
void TextTrackCue::set_onexit(WebIDL::CallbackType* event_handler)
|
||||
{
|
||||
set_event_handler_attribute(HTML::EventNames::exit, event_handler);
|
||||
}
|
||||
|
||||
}
|
64
Userland/Libraries/LibWeb/HTML/TextTrackCue.h
Normal file
64
Userland/Libraries/LibWeb/HTML/TextTrackCue.h
Normal file
|
@ -0,0 +1,64 @@
|
|||
/*
|
||||
* Copyright (c) 2024, Jamie Mansfield <jmansfield@cadixdev.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <LibJS/Heap/MarkedVector.h>
|
||||
#include <LibWeb/DOM/EventTarget.h>
|
||||
#include <LibWeb/HTML/TextTrack.h>
|
||||
|
||||
namespace Web::HTML {
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/media.html#texttrackcue
|
||||
class TextTrackCue : public DOM::EventTarget {
|
||||
WEB_PLATFORM_OBJECT(TextTrackCue, DOM::EventTarget);
|
||||
JS_DECLARE_ALLOCATOR(TextTrackCue);
|
||||
|
||||
public:
|
||||
virtual ~TextTrackCue() override;
|
||||
|
||||
JS::GCPtr<TextTrack> track() { return m_track; }
|
||||
|
||||
String const& id() const { return m_identifier; }
|
||||
void set_id(String const& id) { m_identifier = id; }
|
||||
|
||||
double start_time() const { return m_start_time; }
|
||||
void set_start_time(double start_time);
|
||||
|
||||
double end_time() const { return m_end_time; }
|
||||
WebIDL::ExceptionOr<void> set_end_time(double end_time);
|
||||
|
||||
bool pause_on_exit() const { return m_pause_on_exit; }
|
||||
void set_pause_on_exit(bool pause_on_exit) { m_pause_on_exit = pause_on_exit; }
|
||||
|
||||
WebIDL::CallbackType* onenter();
|
||||
void set_onenter(WebIDL::CallbackType*);
|
||||
|
||||
WebIDL::CallbackType* onexit();
|
||||
void set_onexit(WebIDL::CallbackType*);
|
||||
|
||||
protected:
|
||||
TextTrackCue(JS::Realm&, JS::GCPtr<TextTrack>);
|
||||
|
||||
virtual void initialize(JS::Realm&) override;
|
||||
virtual void visit_edges(Visitor&) override;
|
||||
|
||||
JS::GCPtr<TextTrack> m_track;
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/media.html#text-track-cue-identifier
|
||||
String m_identifier;
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/media.html#text-track-cue-start-time
|
||||
double m_start_time;
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/media.html#text-track-cue-end-time
|
||||
double m_end_time;
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/media.html#text-track-cue-pause-on-exit-flag
|
||||
bool m_pause_on_exit;
|
||||
};
|
||||
|
||||
}
|
15
Userland/Libraries/LibWeb/HTML/TextTrackCue.idl
Normal file
15
Userland/Libraries/LibWeb/HTML/TextTrackCue.idl
Normal file
|
@ -0,0 +1,15 @@
|
|||
#import <DOM/EventTarget.idl>
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/media.html#texttrackcue
|
||||
[Exposed=Window]
|
||||
interface TextTrackCue : EventTarget {
|
||||
readonly attribute TextTrack? track;
|
||||
|
||||
attribute DOMString id;
|
||||
attribute double startTime;
|
||||
attribute unrestricted double endTime;
|
||||
attribute boolean pauseOnExit;
|
||||
|
||||
attribute EventHandler onenter;
|
||||
attribute EventHandler onexit;
|
||||
};
|
|
@ -222,6 +222,7 @@ libweb_js_bindings(HTML/Storage)
|
|||
libweb_js_bindings(HTML/SubmitEvent)
|
||||
libweb_js_bindings(HTML/TextMetrics)
|
||||
libweb_js_bindings(HTML/TextTrack)
|
||||
libweb_js_bindings(HTML/TextTrackCue)
|
||||
libweb_js_bindings(HTML/TextTrackList)
|
||||
libweb_js_bindings(HTML/TimeRanges)
|
||||
libweb_js_bindings(HTML/ToggleEvent)
|
||||
|
|
Loading…
Reference in a new issue