HTMLAudioElement.cpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. HTMLAudioElement::HTMLAudioElement(DOM::Document& document, DOM::QualifiedName qualified_name)
  13. : HTMLMediaElement(document, move(qualified_name))
  14. {
  15. }
  16. HTMLAudioElement::~HTMLAudioElement() = default;
  17. void HTMLAudioElement::initialize(JS::Realm& realm)
  18. {
  19. Base::initialize(realm);
  20. set_prototype(&Bindings::ensure_web_prototype<Bindings::HTMLAudioElementPrototype>(realm, "HTMLAudioElement"));
  21. }
  22. JS::GCPtr<Layout::Node> HTMLAudioElement::create_layout_node(NonnullRefPtr<CSS::StyleProperties> style)
  23. {
  24. return heap().allocate_without_realm<Layout::AudioBox>(document(), *this, move(style));
  25. }
  26. Layout::AudioBox* HTMLAudioElement::layout_node()
  27. {
  28. return static_cast<Layout::AudioBox*>(Node::layout_node());
  29. }
  30. Layout::AudioBox const* HTMLAudioElement::layout_node() const
  31. {
  32. return static_cast<Layout::AudioBox const*>(Node::layout_node());
  33. }
  34. void HTMLAudioElement::on_playing()
  35. {
  36. audio_tracks()->for_each_enabled_track([](auto& audio_track) {
  37. audio_track.play({});
  38. });
  39. }
  40. void HTMLAudioElement::on_paused()
  41. {
  42. audio_tracks()->for_each_enabled_track([](auto& audio_track) {
  43. audio_track.pause({});
  44. });
  45. }
  46. void HTMLAudioElement::on_seek(double position, MediaSeekMode seek_mode)
  47. {
  48. audio_tracks()->for_each_enabled_track([&](auto& audio_track) {
  49. audio_track.seek(position, seek_mode);
  50. });
  51. }
  52. void HTMLAudioElement::on_volume_change()
  53. {
  54. audio_tracks()->for_each_enabled_track([&](auto& audio_track) {
  55. audio_track.update_volume();
  56. });
  57. }
  58. }