HTMLAudioElement.cpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. * Copyright (c) 2020, the SerenityOS developers.
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibWeb/Bindings/HTMLAudioElementPrototype.h>
  7. #include <LibWeb/HTML/AudioTrack.h>
  8. #include <LibWeb/HTML/AudioTrackList.h>
  9. #include <LibWeb/HTML/HTMLAudioElement.h>
  10. #include <LibWeb/HTML/Window.h>
  11. #include <LibWeb/Layout/AudioBox.h>
  12. namespace Web::HTML {
  13. JS_DEFINE_ALLOCATOR(HTMLAudioElement);
  14. HTMLAudioElement::HTMLAudioElement(DOM::Document& document, DOM::QualifiedName qualified_name)
  15. : HTMLMediaElement(document, move(qualified_name))
  16. {
  17. }
  18. HTMLAudioElement::~HTMLAudioElement() = default;
  19. void HTMLAudioElement::initialize(JS::Realm& realm)
  20. {
  21. Base::initialize(realm);
  22. WEB_SET_PROTOTYPE_FOR_INTERFACE(HTMLAudioElement);
  23. }
  24. JS::GCPtr<Layout::Node> HTMLAudioElement::create_layout_node(CSS::StyleProperties style)
  25. {
  26. return heap().allocate_without_realm<Layout::AudioBox>(document(), *this, move(style));
  27. }
  28. Layout::AudioBox* HTMLAudioElement::layout_node()
  29. {
  30. return static_cast<Layout::AudioBox*>(Node::layout_node());
  31. }
  32. Layout::AudioBox const* HTMLAudioElement::layout_node() const
  33. {
  34. return static_cast<Layout::AudioBox const*>(Node::layout_node());
  35. }
  36. void HTMLAudioElement::on_playing()
  37. {
  38. audio_tracks()->for_each_enabled_track([](auto& audio_track) {
  39. audio_track.play({});
  40. });
  41. }
  42. void HTMLAudioElement::on_paused()
  43. {
  44. audio_tracks()->for_each_enabled_track([](auto& audio_track) {
  45. audio_track.pause({});
  46. });
  47. }
  48. void HTMLAudioElement::on_seek(double position, MediaSeekMode seek_mode)
  49. {
  50. audio_tracks()->for_each_enabled_track([&](auto& audio_track) {
  51. audio_track.seek(position, seek_mode);
  52. });
  53. }
  54. void HTMLAudioElement::on_volume_change()
  55. {
  56. audio_tracks()->for_each_enabled_track([&](auto& audio_track) {
  57. audio_track.update_volume();
  58. });
  59. }
  60. }