mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-05 01:42:54 +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: 0b2449d8d2
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/1494
Reviewed-by: https://github.com/AtkinsSJ
Reviewed-by: https://github.com/tcl3 ✅
8 changed files with 174 additions and 0 deletions
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);
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue