2023-06-12 08:21:35 -04:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2023, Tim Flynn <trflynn89@serenityos.org>
|
|
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <LibWeb/Forward.h>
|
2023-06-21 17:08:50 -04:00
|
|
|
#include <LibWeb/HTML/HTMLMediaElement.h>
|
2023-06-12 08:21:35 -04:00
|
|
|
#include <LibWeb/Painting/PaintableBox.h>
|
2023-06-15 14:28:32 -04:00
|
|
|
#include <LibWeb/PixelUnits.h>
|
2023-06-12 08:21:35 -04:00
|
|
|
|
|
|
|
|
namespace Web::Painting {
|
|
|
|
|
|
|
|
|
|
class MediaPaintable : public PaintableBox {
|
2024-11-15 04:01:23 +13:00
|
|
|
GC_CELL(MediaPaintable, PaintableBox);
|
2023-06-12 08:21:35 -04:00
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
explicit MediaPaintable(Layout::ReplacedBox const&);
|
|
|
|
|
|
|
|
|
|
static Optional<DevicePixelPoint> mouse_position(PaintContext&, HTML::HTMLMediaElement const&);
|
2024-06-23 18:40:10 +02:00
|
|
|
static void fill_triangle(DisplayListRecorder& painter, Gfx::IntPoint location, Array<Gfx::IntPoint, 3> coordinates, Color color);
|
2023-06-12 08:21:35 -04:00
|
|
|
|
|
|
|
|
void paint_media_controls(PaintContext&, HTML::HTMLMediaElement const&, DevicePixelRect media_rect, Optional<DevicePixelPoint> const& mouse_position) const;
|
|
|
|
|
|
|
|
|
|
private:
|
2023-06-15 14:28:32 -04:00
|
|
|
struct Components {
|
|
|
|
|
DevicePixelRect control_box_rect;
|
|
|
|
|
DevicePixelRect playback_button_rect;
|
|
|
|
|
DevicePixelRect timeline_rect;
|
|
|
|
|
|
|
|
|
|
String timestamp;
|
|
|
|
|
RefPtr<Gfx::Font> timestamp_font;
|
|
|
|
|
DevicePixelRect timestamp_rect;
|
2023-06-15 15:09:47 -04:00
|
|
|
|
|
|
|
|
DevicePixelRect speaker_button_rect;
|
|
|
|
|
DevicePixels speaker_button_size;
|
2023-06-15 15:46:37 -04:00
|
|
|
|
|
|
|
|
DevicePixelRect volume_rect;
|
2023-08-03 17:53:35 -05:00
|
|
|
DevicePixelRect volume_scrub_rect;
|
2023-06-15 15:46:37 -04:00
|
|
|
DevicePixels volume_button_size;
|
2023-06-15 14:28:32 -04:00
|
|
|
};
|
|
|
|
|
|
2023-06-12 08:21:35 -04:00
|
|
|
virtual bool wants_mouse_events() const override { return true; }
|
2023-06-21 17:08:50 -04:00
|
|
|
virtual DispatchEventOfSameName handle_mousedown(Badge<EventHandler>, CSSPixelPoint, unsigned button, unsigned modifiers) override;
|
2023-06-12 08:21:35 -04:00
|
|
|
virtual DispatchEventOfSameName handle_mouseup(Badge<EventHandler>, CSSPixelPoint, unsigned button, unsigned modifiers) override;
|
|
|
|
|
virtual DispatchEventOfSameName handle_mousemove(Badge<EventHandler>, CSSPixelPoint, unsigned buttons, unsigned modifiers) override;
|
|
|
|
|
|
2023-06-15 14:28:32 -04:00
|
|
|
Components compute_control_bar_components(PaintContext&, HTML::HTMLMediaElement const&, DevicePixelRect media_rect) const;
|
|
|
|
|
static void paint_control_bar_playback_button(PaintContext&, HTML::HTMLMediaElement const&, Components const&, Optional<DevicePixelPoint> const& mouse_position);
|
2023-06-22 13:25:17 -04:00
|
|
|
static void paint_control_bar_timeline(PaintContext&, HTML::HTMLMediaElement const&, Components const&);
|
2023-06-15 14:28:32 -04:00
|
|
|
static void paint_control_bar_timestamp(PaintContext&, Components const&);
|
2023-06-15 15:09:47 -04:00
|
|
|
static void paint_control_bar_speaker(PaintContext&, HTML::HTMLMediaElement const&, Components const& components, Optional<DevicePixelPoint> const& mouse_position);
|
2023-06-15 15:46:37 -04:00
|
|
|
static void paint_control_bar_volume(PaintContext&, HTML::HTMLMediaElement const&, Components const&, Optional<DevicePixelPoint> const& mouse_position);
|
2023-06-21 17:08:50 -04:00
|
|
|
|
|
|
|
|
enum class Temporary {
|
|
|
|
|
Yes,
|
|
|
|
|
No,
|
|
|
|
|
};
|
|
|
|
|
static void set_current_time(HTML::HTMLMediaElement& media_element, CSSPixelRect timeline_rect, CSSPixelPoint mouse_position, Temporary);
|
|
|
|
|
static void set_volume(HTML::HTMLMediaElement& media_element, CSSPixelRect volume_rect, CSSPixelPoint mouse_position);
|
|
|
|
|
|
|
|
|
|
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 = {});
|
2023-06-12 08:21:35 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|