diff options
author | Timothy Flynn <trflynn89@pm.me> | 2023-04-10 11:52:44 -0400 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2023-04-11 19:27:55 +0200 |
commit | d5412f4e780430c95e1555f1caf07d434b28b9b5 (patch) | |
tree | 2bb00bcc2884380f62ebbf218001d147b673ba50 | |
parent | cdf4c410bf00edb9604521ab282705f79eb5400f (diff) | |
download | serenity-d5412f4e780430c95e1555f1caf07d434b28b9b5.zip |
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.
-rw-r--r-- | Userland/Libraries/LibWeb/HTML/HTMLVideoElement.h | 7 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/Painting/VideoPaintable.cpp | 14 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/Painting/VideoPaintable.h | 3 |
3 files changed, 16 insertions, 8 deletions
diff --git a/Userland/Libraries/LibWeb/HTML/HTMLVideoElement.h b/Userland/Libraries/LibWeb/HTML/HTMLVideoElement.h index 2c1c82cb47..0a268189fd 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLVideoElement.h +++ b/Userland/Libraries/LibWeb/HTML/HTMLVideoElement.h @@ -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; }; } diff --git a/Userland/Libraries/LibWeb/Painting/VideoPaintable.cpp b/Userland/Libraries/LibWeb/Painting/VideoPaintable.cpp index 3db544eee5..4b2c3e2058 100644 --- a/Userland/Libraries/LibWeb/Painting/VideoPaintable.cpp +++ b/Userland/Libraries/LibWeb/Painting/VideoPaintable.cpp @@ -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) }; + auto const& video_element = layout_box().dom_node(); + auto const& layout_mouse_position = video_element.layout_mouse_position({}); + Optional<DevicePixelPoint> mouse_position; - if (m_mouse_position.has_value()) - mouse_position = context.rounded_device_point(*m_mouse_position); + if (layout_mouse_position.has_value() && document().hovered_node() == &video_element) + mouse_position = context.rounded_device_point(*layout_mouse_position); - auto const& video_element = layout_box().dom_node(); 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; } diff --git a/Userland/Libraries/LibWeb/Painting/VideoPaintable.h b/Userland/Libraries/LibWeb/Painting/VideoPaintable.h index 1d7204f0a6..ac4e1fa09e 100644 --- a/Userland/Libraries/LibWeb/Painting/VideoPaintable.h +++ b/Userland/Libraries/LibWeb/Painting/VideoPaintable.h @@ -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; }; } |