TextTrackCue.cpp 3.1 KB

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