mirror of
https://github.com/RGBCube/serenity
synced 2025-05-25 21:05:07 +00:00

The volume control's slider is drawn in a rectangle shrunken by its slider handle's size, so the handle did not move 1:1 with the user's mouse movement. To fix this, it will now check for a mousedown in the volume control with a rectangle sized to fit any possible position of the handle, but the volume value result will be calculated based on the center of the handle instead. This allows it to move 1:1 with the mouse cursor. Co-authored-by: trflynn89 <trflynn89@serenityos.org>
67 lines
3.1 KiB
C++
67 lines
3.1 KiB
C++
/*
|
|
* Copyright (c) 2023, Tim Flynn <trflynn89@serenityos.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <LibWeb/Forward.h>
|
|
#include <LibWeb/HTML/HTMLMediaElement.h>
|
|
#include <LibWeb/Painting/PaintableBox.h>
|
|
#include <LibWeb/PixelUnits.h>
|
|
|
|
namespace Web::Painting {
|
|
|
|
class MediaPaintable : public PaintableBox {
|
|
JS_CELL(MediaPaintable, PaintableBox);
|
|
|
|
protected:
|
|
explicit MediaPaintable(Layout::ReplacedBox const&);
|
|
|
|
static Optional<DevicePixelPoint> mouse_position(PaintContext&, HTML::HTMLMediaElement const&);
|
|
static void fill_triangle(Gfx::Painter& painter, Gfx::IntPoint location, Array<Gfx::IntPoint, 3> coordinates, Color color);
|
|
|
|
void paint_media_controls(PaintContext&, HTML::HTMLMediaElement const&, DevicePixelRect media_rect, Optional<DevicePixelPoint> const& mouse_position) const;
|
|
|
|
private:
|
|
struct Components {
|
|
DevicePixelRect control_box_rect;
|
|
DevicePixelRect playback_button_rect;
|
|
DevicePixelRect timeline_rect;
|
|
|
|
String timestamp;
|
|
RefPtr<Gfx::Font> timestamp_font;
|
|
DevicePixelRect timestamp_rect;
|
|
|
|
DevicePixelRect speaker_button_rect;
|
|
DevicePixels speaker_button_size;
|
|
|
|
DevicePixelRect volume_rect;
|
|
DevicePixelRect volume_scrub_rect;
|
|
DevicePixels volume_button_size;
|
|
};
|
|
|
|
virtual bool wants_mouse_events() const override { return true; }
|
|
virtual DispatchEventOfSameName handle_mousedown(Badge<EventHandler>, CSSPixelPoint, unsigned button, unsigned modifiers) override;
|
|
virtual DispatchEventOfSameName handle_mouseup(Badge<EventHandler>, CSSPixelPoint, unsigned button, unsigned modifiers) override;
|
|
virtual DispatchEventOfSameName handle_mousemove(Badge<EventHandler>, CSSPixelPoint, unsigned buttons, unsigned modifiers) override;
|
|
|
|
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);
|
|
static void paint_control_bar_timeline(PaintContext&, HTML::HTMLMediaElement const&, Components const&);
|
|
static void paint_control_bar_timestamp(PaintContext&, Components const&);
|
|
static void paint_control_bar_speaker(PaintContext&, HTML::HTMLMediaElement const&, Components const& components, Optional<DevicePixelPoint> const& mouse_position);
|
|
static void paint_control_bar_volume(PaintContext&, HTML::HTMLMediaElement const&, Components const&, Optional<DevicePixelPoint> const& mouse_position);
|
|
|
|
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 = {});
|
|
};
|
|
|
|
}
|