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