HTMLAudioElement.cpp 1.8 KB

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