mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 22:17:42 +00:00
LibWeb: Move VideoPaintable's cached mouse position to HTMLVideoElement
The layout node, and therefore the painting box, is frequently destroyed and recreated. This causes us to forget the cached mouse position we use to highlight media controls. Move this cached position to the DOM node instead, which survives relayout.
This commit is contained in:
parent
cdf4c410bf
commit
d5412f4e78
3 changed files with 17 additions and 9 deletions
|
@ -6,6 +6,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <AK/Optional.h>
|
||||
#include <LibGfx/Forward.h>
|
||||
#include <LibWeb/Forward.h>
|
||||
#include <LibWeb/HTML/HTMLMediaElement.h>
|
||||
|
@ -32,6 +33,9 @@ public:
|
|||
void set_current_frame(Badge<VideoTrack>, RefPtr<Gfx::Bitmap> frame);
|
||||
RefPtr<Gfx::Bitmap> const& current_frame() const { return m_current_frame; }
|
||||
|
||||
void set_layout_mouse_position(Badge<Painting::VideoPaintable>, Optional<CSSPixelPoint> mouse_position) { m_mouse_position = move(mouse_position); }
|
||||
Optional<CSSPixelPoint> const& layout_mouse_position(Badge<Painting::VideoPaintable>) const { return m_mouse_position; }
|
||||
|
||||
private:
|
||||
HTMLVideoElement(DOM::Document&, DOM::QualifiedName);
|
||||
|
||||
|
@ -48,6 +52,9 @@ private:
|
|||
|
||||
u32 m_video_width { 0 };
|
||||
u32 m_video_height { 0 };
|
||||
|
||||
// Cached state for layout
|
||||
Optional<CSSPixelPoint> m_mouse_position;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -64,11 +64,13 @@ void VideoPaintable::paint(PaintContext& context, PaintPhase phase) const
|
|||
auto video_rect = context.rounded_device_rect(absolute_rect());
|
||||
ScopedCornerRadiusClip corner_clip { context, context.painter(), video_rect, normalized_border_radii_data(ShrinkRadiiForBorders::Yes) };
|
||||
|
||||
Optional<DevicePixelPoint> mouse_position;
|
||||
if (m_mouse_position.has_value())
|
||||
mouse_position = context.rounded_device_point(*m_mouse_position);
|
||||
|
||||
auto const& video_element = layout_box().dom_node();
|
||||
auto const& layout_mouse_position = video_element.layout_mouse_position({});
|
||||
|
||||
Optional<DevicePixelPoint> mouse_position;
|
||||
if (layout_mouse_position.has_value() && document().hovered_node() == &video_element)
|
||||
mouse_position = context.rounded_device_point(*layout_mouse_position);
|
||||
|
||||
auto paint_user_agent_controls = video_element.has_attribute(HTML::AttributeNames::controls);
|
||||
|
||||
if (auto const& bitmap = layout_box().dom_node().current_frame()) {
|
||||
|
@ -201,12 +203,14 @@ VideoPaintable::DispatchEventOfSameName VideoPaintable::handle_mouseup(Badge<Eve
|
|||
|
||||
VideoPaintable::DispatchEventOfSameName VideoPaintable::handle_mousemove(Badge<EventHandler>, CSSPixelPoint position, unsigned, unsigned)
|
||||
{
|
||||
auto& video_element = layout_box().dom_node();
|
||||
|
||||
if (absolute_rect().contains(position)) {
|
||||
m_mouse_position = position;
|
||||
video_element.set_layout_mouse_position({}, position);
|
||||
return DispatchEventOfSameName::Yes;
|
||||
}
|
||||
|
||||
m_mouse_position.clear();
|
||||
video_element.set_layout_mouse_position({}, {});
|
||||
return DispatchEventOfSameName::No;
|
||||
}
|
||||
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <AK/Optional.h>
|
||||
#include <LibWeb/Forward.h>
|
||||
#include <LibWeb/Painting/PaintableBox.h>
|
||||
|
||||
|
@ -32,8 +31,6 @@ private:
|
|||
|
||||
void paint_loaded_video_controls(PaintContext&, HTML::HTMLVideoElement const&, DevicePixelRect video_rect, Optional<DevicePixelPoint> const& mouse_position) const;
|
||||
void paint_placeholder_video_controls(PaintContext&, DevicePixelRect video_rect, Optional<DevicePixelPoint> const& mouse_position) const;
|
||||
|
||||
Optional<CSSPixelPoint> m_mouse_position;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue