/src/serenity/Userland/Libraries/LibWeb/Painting/AudioPaintable.cpp
Line | Count | Source |
1 | | /* |
2 | | * Copyright (c) 2023, Tim Flynn <trflynn89@serenityos.org> |
3 | | * |
4 | | * SPDX-License-Identifier: BSD-2-Clause |
5 | | */ |
6 | | |
7 | | #include <AK/Array.h> |
8 | | #include <AK/NumberFormat.h> |
9 | | #include <LibGfx/AntiAliasingPainter.h> |
10 | | #include <LibWeb/DOM/Document.h> |
11 | | #include <LibWeb/HTML/AudioTrackList.h> |
12 | | #include <LibWeb/HTML/HTMLAudioElement.h> |
13 | | #include <LibWeb/HTML/HTMLMediaElement.h> |
14 | | #include <LibWeb/Layout/AudioBox.h> |
15 | | #include <LibWeb/Painting/AudioPaintable.h> |
16 | | #include <LibWeb/Painting/BorderRadiusCornerClipper.h> |
17 | | |
18 | | namespace Web::Painting { |
19 | | |
20 | | JS_DEFINE_ALLOCATOR(AudioPaintable); |
21 | | |
22 | | JS::NonnullGCPtr<AudioPaintable> AudioPaintable::create(Layout::AudioBox const& layout_box) |
23 | 0 | { |
24 | 0 | return layout_box.heap().allocate_without_realm<AudioPaintable>(layout_box); |
25 | 0 | } |
26 | | |
27 | | AudioPaintable::AudioPaintable(Layout::AudioBox const& layout_box) |
28 | 0 | : MediaPaintable(layout_box) |
29 | 0 | { |
30 | 0 | } |
31 | | |
32 | | Layout::AudioBox& AudioPaintable::layout_box() |
33 | 0 | { |
34 | 0 | return static_cast<Layout::AudioBox&>(layout_node()); |
35 | 0 | } |
36 | | |
37 | | Layout::AudioBox const& AudioPaintable::layout_box() const |
38 | 0 | { |
39 | 0 | return static_cast<Layout::AudioBox const&>(layout_node()); |
40 | 0 | } |
41 | | |
42 | | void AudioPaintable::paint(PaintContext& context, PaintPhase phase) const |
43 | 0 | { |
44 | 0 | if (!is_visible()) |
45 | 0 | return; |
46 | | |
47 | 0 | Base::paint(context, phase); |
48 | |
|
49 | 0 | if (phase != PaintPhase::Foreground) |
50 | 0 | return; |
51 | | |
52 | 0 | DisplayListRecorderStateSaver saver { context.display_list_recorder() }; |
53 | |
|
54 | 0 | auto audio_rect = context.rounded_device_rect(absolute_rect()); |
55 | 0 | context.display_list_recorder().add_clip_rect(audio_rect.to_type<int>()); |
56 | |
|
57 | 0 | ScopedCornerRadiusClip corner_clip { context, audio_rect, normalized_border_radii_data(ShrinkRadiiForBorders::Yes) }; |
58 | |
|
59 | 0 | auto const& audio_element = layout_box().dom_node(); |
60 | 0 | auto mouse_position = MediaPaintable::mouse_position(context, audio_element); |
61 | |
|
62 | 0 | auto paint_user_agent_controls = audio_element.has_attribute(HTML::AttributeNames::controls) || audio_element.is_scripting_disabled(); |
63 | |
|
64 | 0 | if (paint_user_agent_controls) |
65 | 0 | paint_media_controls(context, audio_element, audio_rect, mouse_position); |
66 | 0 | } |
67 | | |
68 | | } |