/src/serenity/Userland/Libraries/LibWeb/Painting/MediaPaintable.h
Line | Count | Source |
1 | | /* |
2 | | * Copyright (c) 2023, Tim Flynn <trflynn89@serenityos.org> |
3 | | * |
4 | | * SPDX-License-Identifier: BSD-2-Clause |
5 | | */ |
6 | | |
7 | | #pragma once |
8 | | |
9 | | #include <LibWeb/Forward.h> |
10 | | #include <LibWeb/HTML/HTMLMediaElement.h> |
11 | | #include <LibWeb/Painting/PaintableBox.h> |
12 | | #include <LibWeb/PixelUnits.h> |
13 | | |
14 | | namespace Web::Painting { |
15 | | |
16 | | class MediaPaintable : public PaintableBox { |
17 | | JS_CELL(MediaPaintable, PaintableBox); |
18 | | |
19 | | protected: |
20 | | explicit MediaPaintable(Layout::ReplacedBox const&); |
21 | | |
22 | | static Optional<DevicePixelPoint> mouse_position(PaintContext&, HTML::HTMLMediaElement const&); |
23 | | static void fill_triangle(DisplayListRecorder& painter, Gfx::IntPoint location, Array<Gfx::IntPoint, 3> coordinates, Color color); |
24 | | |
25 | | void paint_media_controls(PaintContext&, HTML::HTMLMediaElement const&, DevicePixelRect media_rect, Optional<DevicePixelPoint> const& mouse_position) const; |
26 | | |
27 | | private: |
28 | | struct Components { |
29 | | DevicePixelRect control_box_rect; |
30 | | DevicePixelRect playback_button_rect; |
31 | | DevicePixelRect timeline_rect; |
32 | | |
33 | | String timestamp; |
34 | | RefPtr<Gfx::Font> timestamp_font; |
35 | | DevicePixelRect timestamp_rect; |
36 | | |
37 | | DevicePixelRect speaker_button_rect; |
38 | | DevicePixels speaker_button_size; |
39 | | |
40 | | DevicePixelRect volume_rect; |
41 | | DevicePixelRect volume_scrub_rect; |
42 | | DevicePixels volume_button_size; |
43 | | }; |
44 | | |
45 | 0 | virtual bool wants_mouse_events() const override { return true; } |
46 | | virtual DispatchEventOfSameName handle_mousedown(Badge<EventHandler>, CSSPixelPoint, unsigned button, unsigned modifiers) override; |
47 | | virtual DispatchEventOfSameName handle_mouseup(Badge<EventHandler>, CSSPixelPoint, unsigned button, unsigned modifiers) override; |
48 | | virtual DispatchEventOfSameName handle_mousemove(Badge<EventHandler>, CSSPixelPoint, unsigned buttons, unsigned modifiers) override; |
49 | | |
50 | | Components compute_control_bar_components(PaintContext&, HTML::HTMLMediaElement const&, DevicePixelRect media_rect) const; |
51 | | static void paint_control_bar_playback_button(PaintContext&, HTML::HTMLMediaElement const&, Components const&, Optional<DevicePixelPoint> const& mouse_position); |
52 | | static void paint_control_bar_timeline(PaintContext&, HTML::HTMLMediaElement const&, Components const&); |
53 | | static void paint_control_bar_timestamp(PaintContext&, Components const&); |
54 | | static void paint_control_bar_speaker(PaintContext&, HTML::HTMLMediaElement const&, Components const& components, Optional<DevicePixelPoint> const& mouse_position); |
55 | | static void paint_control_bar_volume(PaintContext&, HTML::HTMLMediaElement const&, Components const&, Optional<DevicePixelPoint> const& mouse_position); |
56 | | |
57 | | enum class Temporary { |
58 | | Yes, |
59 | | No, |
60 | | }; |
61 | | static void set_current_time(HTML::HTMLMediaElement& media_element, CSSPixelRect timeline_rect, CSSPixelPoint mouse_position, Temporary); |
62 | | static void set_volume(HTML::HTMLMediaElement& media_element, CSSPixelRect volume_rect, CSSPixelPoint mouse_position); |
63 | | |
64 | | static bool rect_is_hovered(HTML::HTMLMediaElement const& media_element, Optional<DevicePixelRect> const& rect, Optional<DevicePixelPoint> const& mouse_position, Optional<HTML::HTMLMediaElement::MouseTrackingComponent> const& allowed_mouse_tracking_component = {}); |
65 | | }; |
66 | | |
67 | | } |