1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 11:28:12 +00:00

LibWeb: Implement the HTMLMediaElement show-poster flag

Note that this doesn't do much yet, as the HTMLVideoElement does not
handle its poster attribute as of this commit.
This commit is contained in:
Timothy Flynn 2023-04-20 06:49:06 -04:00 committed by Andreas Kling
parent 12c15641c1
commit b384f2009d
2 changed files with 32 additions and 5 deletions

View file

@ -385,7 +385,8 @@ WebIDL::ExceptionOr<void> HTMLMediaElement::select_resource()
// 1. Set the element's networkState attribute to the NETWORK_NO_SOURCE value. // 1. Set the element's networkState attribute to the NETWORK_NO_SOURCE value.
m_network_state = NetworkState::NoSource; m_network_state = NetworkState::NoSource;
// FIXME: 2. Set the element's show poster flag to true. // 2. Set the element's show poster flag to true.
set_show_poster(true);
// 3. Set the media element's delaying-the-load-event flag to true (this delays the load event). // 3. Set the media element's delaying-the-load-event flag to true (this delays the load event).
m_delaying_the_load_event.emplace(document()); m_delaying_the_load_event.emplace(document());
@ -877,7 +878,8 @@ WebIDL::ExceptionOr<void> HTMLMediaElement::handle_media_source_failure(Span<JS:
// 3. Set the element's networkState attribute to the NETWORK_NO_SOURCE value. // 3. Set the element's networkState attribute to the NETWORK_NO_SOURCE value.
m_network_state = NetworkState::NoSource; m_network_state = NetworkState::NoSource;
// FIXME: 4. Set the element's show poster flag to true. // 4. Set the element's show poster flag to true.
set_show_poster(true);
// 5. Fire an event named error at the media element. // 5. Fire an event named error at the media element.
dispatch_event(TRY(DOM::Event::create(realm(), HTML::EventNames::error))); dispatch_event(TRY(DOM::Event::create(realm(), HTML::EventNames::error)));
@ -994,7 +996,11 @@ void HTMLMediaElement::set_ready_state(ReadyState ready_state)
// Set the paused attribute to false. // Set the paused attribute to false.
set_paused(false); set_paused(false);
// FIXME: If the element's show poster flag is true, set it to false and run the time marches on steps. // If the element's show poster flag is true, set it to false and run the time marches on steps.
if (m_show_poster) {
set_show_poster(false);
time_marches_on();
}
// Queue a media element task given the element to fire an event named play at the element. // Queue a media element task given the element to fire an event named play at the element.
queue_a_media_element_task([this]() { queue_a_media_element_task([this]() {
@ -1034,7 +1040,11 @@ WebIDL::ExceptionOr<void> HTMLMediaElement::play_element()
// 1. Change the value of paused to false. // 1. Change the value of paused to false.
set_paused(false); set_paused(false);
// FIXME: 2. If the show poster flag is true, set the element's show poster flag to false and run the time marches on steps. // 2. If the show poster flag is true, set the element's show poster flag to false and run the time marches on steps.
if (m_show_poster) {
set_show_poster(false);
time_marches_on();
}
// 3. Queue a media element task given the media element to fire an event named play at the element. // 3. Queue a media element task given the media element to fire an event named play at the element.
queue_a_media_element_task([this]() { queue_a_media_element_task([this]() {
@ -1110,7 +1120,8 @@ WebIDL::ExceptionOr<void> HTMLMediaElement::pause_element()
// https://html.spec.whatwg.org/multipage/media.html#dom-media-seek // https://html.spec.whatwg.org/multipage/media.html#dom-media-seek
void HTMLMediaElement::seek_element(double playback_position, MediaSeekMode seek_mode) void HTMLMediaElement::seek_element(double playback_position, MediaSeekMode seek_mode)
{ {
// FIXME: 1. Set the media element's show poster flag to false. // 1. Set the media element's show poster flag to false.
set_show_poster(false);
// 2. If the media element's readyState is HAVE_NOTHING, return. // 2. If the media element's readyState is HAVE_NOTHING, return.
if (m_ready_state == ReadyState::HaveNothing) if (m_ready_state == ReadyState::HaveNothing)
@ -1200,6 +1211,17 @@ void HTMLMediaElement::notify_about_playing()
on_playing(); on_playing();
} }
void HTMLMediaElement::set_show_poster(bool show_poster)
{
if (m_show_poster == show_poster)
return;
m_show_poster = show_poster;
if (auto* layout_node = this->layout_node())
layout_node->set_needs_display();
}
void HTMLMediaElement::set_paused(bool paused) void HTMLMediaElement::set_paused(bool paused)
{ {
if (m_paused == paused) if (m_paused == paused)

View file

@ -68,6 +68,7 @@ public:
void set_current_playback_position(double); void set_current_playback_position(double);
double duration() const; double duration() const;
bool show_poster() const { return m_show_poster; }
bool paused() const { return m_paused; } bool paused() const { return m_paused; }
bool ended() const; bool ended() const;
bool potentially_playing() const; bool potentially_playing() const;
@ -113,6 +114,7 @@ private:
WebIDL::ExceptionOr<void> pause_element(); WebIDL::ExceptionOr<void> pause_element();
void seek_element(double playback_position, MediaSeekMode = MediaSeekMode::Accurate); void seek_element(double playback_position, MediaSeekMode = MediaSeekMode::Accurate);
void notify_about_playing(); void notify_about_playing();
void set_show_poster(bool);
void set_paused(bool); void set_paused(bool);
void set_duration(double); void set_duration(double);
@ -171,6 +173,9 @@ private:
// https://html.spec.whatwg.org/multipage/media.html#default-playback-start-position // https://html.spec.whatwg.org/multipage/media.html#default-playback-start-position
double m_default_playback_start_position { 0 }; double m_default_playback_start_position { 0 };
// https://html.spec.whatwg.org/multipage/media.html#show-poster-flag
bool m_show_poster { true };
// https://html.spec.whatwg.org/multipage/media.html#dom-media-duration // https://html.spec.whatwg.org/multipage/media.html#dom-media-duration
double m_duration { NAN }; double m_duration { NAN };