LibWeb: Use an IIFE to determine a VideoPaintable's representation

This commit is contained in:
Zaggy1024 2025-09-12 17:36:33 -05:00 committed by Jelle Raaijmakers
commit 861c10f37f
Notes: github-actions[bot] 2025-09-16 08:27:25 +00:00

View file

@ -74,8 +74,7 @@ void VideoPaintable::paint(DisplayListRecordingContext& context, PaintPhase phas
auto current_playback_position = video_element.current_playback_position(); auto current_playback_position = video_element.current_playback_position();
auto ready_state = video_element.ready_state(); auto ready_state = video_element.ready_state();
enum class Representation { enum class Representation : u8 {
Unknown,
FirstVideoFrame, FirstVideoFrame,
CurrentVideoFrame, CurrentVideoFrame,
LastRenderedVideoFrame, LastRenderedVideoFrame,
@ -83,8 +82,7 @@ void VideoPaintable::paint(DisplayListRecordingContext& context, PaintPhase phas
TransparentBlack, TransparentBlack,
}; };
auto representation = Representation::Unknown; auto representation = [&]() {
// https://html.spec.whatwg.org/multipage/media.html#the-video-element:the-video-element-7 // https://html.spec.whatwg.org/multipage/media.html#the-video-element:the-video-element-7
// A video element represents what is given for the first matching condition in the list below: // A video element represents what is given for the first matching condition in the list below:
@ -94,39 +92,39 @@ void VideoPaintable::paint(DisplayListRecordingContext& context, PaintPhase phas
if (ready_state == HTML::HTMLMediaElement::ReadyState::HaveNothing if (ready_state == HTML::HTMLMediaElement::ReadyState::HaveNothing
|| (ready_state >= HTML::HTMLMediaElement::ReadyState::HaveMetadata && video_element.video_tracks()->length() == 0)) { || (ready_state >= HTML::HTMLMediaElement::ReadyState::HaveMetadata && video_element.video_tracks()->length() == 0)) {
// The video element represents its poster frame, if any, or else transparent black with no intrinsic dimensions. // The video element represents its poster frame, if any, or else transparent black with no intrinsic dimensions.
representation = poster_frame ? Representation::PosterFrame : Representation::TransparentBlack; return poster_frame ? Representation::PosterFrame : Representation::TransparentBlack;
} }
// -> When the video element is paused, the current playback position is the first frame of video, and the element's // -> When the video element is paused, the current playback position is the first frame of video, and the element's
// show poster flag is set // show poster flag is set
else if (video_element.paused() && current_playback_position == 0 && video_element.show_poster()) { if (video_element.paused() && current_playback_position == 0 && video_element.show_poster()) {
// The video element represents its poster frame, if any, or else the first frame of the video. // The video element represents its poster frame, if any, or else the first frame of the video.
representation = poster_frame ? Representation::PosterFrame : Representation::FirstVideoFrame; return poster_frame ? Representation::PosterFrame : Representation::FirstVideoFrame;
} }
// -> When the video element is paused, and the frame of video corresponding to the current playback position // -> When the video element is paused, and the frame of video corresponding to the current playback position
// is not available (e.g. because the video is seeking or buffering) // is not available (e.g. because the video is seeking or buffering)
// -> When the video element is neither potentially playing nor paused (e.g. when seeking or stalled) // -> When the video element is neither potentially playing nor paused (e.g. when seeking or stalled)
else if ( if (
(video_element.paused() && current_playback_position != current_frame.position) (video_element.paused() && current_playback_position != current_frame.position)
|| (!video_element.potentially_playing() && !video_element.paused())) { || (!video_element.potentially_playing() && !video_element.paused())) {
// The video element represents the last frame of the video to have been rendered. // The video element represents the last frame of the video to have been rendered.
representation = Representation::LastRenderedVideoFrame; return Representation::LastRenderedVideoFrame;
} }
// -> When the video element is paused // -> When the video element is paused
else if (video_element.paused()) { if (video_element.paused()) {
// The video element represents the frame of video corresponding to the current playback position. // The video element represents the frame of video corresponding to the current playback position.
representation = Representation::CurrentVideoFrame; return Representation::CurrentVideoFrame;
} }
// -> Otherwise (the video element has a video channel and is potentially playing) // -> Otherwise (the video element has a video channel and is potentially playing)
else { //
// The video element represents the frame of video at the continuously increasing "current" position. When the // The video element represents the frame of video at the continuously increasing "current" position. When the
// current playback position changes such that the last frame rendered is no longer the frame corresponding to // current playback position changes such that the last frame rendered is no longer the frame corresponding to
// the current playback position in the video, the new frame must be rendered. // the current playback position in the video, the new frame must be rendered.
representation = Representation::CurrentVideoFrame; return Representation::CurrentVideoFrame;
} }();
auto paint_frame = [&](auto const& frame) { auto paint_frame = [&](auto const& frame) {
auto scaling_mode = to_gfx_scaling_mode(computed_values().image_rendering(), frame->rect(), video_rect.to_type<int>()); auto scaling_mode = to_gfx_scaling_mode(computed_values().image_rendering(), frame->rect(), video_rect.to_type<int>());
@ -173,9 +171,6 @@ void VideoPaintable::paint(DisplayListRecordingContext& context, PaintPhase phas
if (paint_user_agent_controls) if (paint_user_agent_controls)
paint_placeholder_video_controls(context, video_rect, mouse_position); paint_placeholder_video_controls(context, video_rect, mouse_position);
break; break;
case Representation::Unknown:
VERIFY_NOT_REACHED();
} }
} }