/src/serenity/Userland/Libraries/LibWeb/HTML/TextTrackCue.cpp
Line | Count | Source |
1 | | /* |
2 | | * Copyright (c) 2024, Jamie Mansfield <jmansfield@cadixdev.org> |
3 | | * |
4 | | * SPDX-License-Identifier: BSD-2-Clause |
5 | | */ |
6 | | |
7 | | #include <AK/Math/Constants.h> |
8 | | #include <LibJS/Runtime/Realm.h> |
9 | | #include <LibWeb/Bindings/Intrinsics.h> |
10 | | #include <LibWeb/Bindings/TextTrackCuePrototype.h> |
11 | | #include <LibWeb/HTML/EventNames.h> |
12 | | #include <LibWeb/HTML/TextTrackCue.h> |
13 | | |
14 | | namespace Web::HTML { |
15 | | |
16 | | JS_DEFINE_ALLOCATOR(TextTrackCue); |
17 | | |
18 | | TextTrackCue::TextTrackCue(JS::Realm& realm, JS::GCPtr<TextTrack> track) |
19 | 0 | : DOM::EventTarget(realm) |
20 | 0 | , m_track(track) |
21 | 0 | { |
22 | 0 | } |
23 | | |
24 | 0 | TextTrackCue::~TextTrackCue() = default; |
25 | | |
26 | | void TextTrackCue::initialize(JS::Realm& realm) |
27 | 0 | { |
28 | 0 | Base::initialize(realm); |
29 | 0 | WEB_SET_PROTOTYPE_FOR_INTERFACE(TextTrackCue); |
30 | 0 | } |
31 | | |
32 | | void TextTrackCue::visit_edges(JS::Cell::Visitor& visitor) |
33 | 0 | { |
34 | 0 | Base::visit_edges(visitor); |
35 | 0 | visitor.visit(m_track); |
36 | 0 | } |
37 | | |
38 | | // https://html.spec.whatwg.org/multipage/media.html#dom-texttrackcue-starttime |
39 | | void TextTrackCue::set_start_time(double start_time) |
40 | 0 | { |
41 | | // On setting, the text track cue start time must be set to the new value, interpreted in seconds; |
42 | 0 | m_start_time = start_time; |
43 | | |
44 | | // 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 |
45 | | // element's list of text tracks, and the media element's show poster flag is not set, then run the time marches on steps |
46 | | // for that media element. |
47 | 0 | } |
48 | | |
49 | | // https://html.spec.whatwg.org/multipage/media.html#dom-texttrackcue-endtime |
50 | | WebIDL::ExceptionOr<void> TextTrackCue::set_end_time(double end_time) |
51 | 0 | { |
52 | | // On setting, if the new value is negative Infinity or a Not-a-Number (NaN) value, then throw a TypeError exception. |
53 | 0 | if (end_time == -AK::Infinity<double> || isnan(end_time)) |
54 | 0 | return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, "Value is negative infinity or NaN"_string }; |
55 | | |
56 | | // Otherwise, the text track cue end time must be set to the new value. |
57 | 0 | m_end_time = end_time; |
58 | | |
59 | | // 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 |
60 | | // element's list of text tracks, and the media element's show poster flag is not set, then run the time marches on steps |
61 | | // for that media element. |
62 | 0 | return {}; |
63 | 0 | } |
64 | | |
65 | | // https://html.spec.whatwg.org/multipage/media.html#handler-texttrackcue-onenter |
66 | | WebIDL::CallbackType* TextTrackCue::onenter() |
67 | 0 | { |
68 | 0 | return event_handler_attribute(HTML::EventNames::enter); |
69 | 0 | } |
70 | | |
71 | | // https://html.spec.whatwg.org/multipage/media.html#handler-texttrackcue-onenter |
72 | | void TextTrackCue::set_onenter(WebIDL::CallbackType* event_handler) |
73 | 0 | { |
74 | 0 | set_event_handler_attribute(HTML::EventNames::enter, event_handler); |
75 | 0 | } |
76 | | |
77 | | // https://html.spec.whatwg.org/multipage/media.html#handler-texttrackcue-onexit |
78 | | WebIDL::CallbackType* TextTrackCue::onexit() |
79 | 0 | { |
80 | 0 | return event_handler_attribute(HTML::EventNames::exit); |
81 | 0 | } |
82 | | |
83 | | // https://html.spec.whatwg.org/multipage/media.html#handler-texttrackcue-onexit |
84 | | void TextTrackCue::set_onexit(WebIDL::CallbackType* event_handler) |
85 | 0 | { |
86 | 0 | set_event_handler_attribute(HTML::EventNames::exit, event_handler); |
87 | 0 | } |
88 | | |
89 | | } |