1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-01 14:42:07 +00:00

LibWeb: Implement the HTMLMediaElement paused attribute

Note that the default value of the attribute is true. We were previously
autoplaying videos as soon as they loaded - this will prevent that from
happening until the paused attribute is set to false.
This commit is contained in:
Timothy Flynn 2023-04-07 11:10:57 -04:00 committed by Linus Groh
parent e130525c24
commit 90921a4f16
5 changed files with 68 additions and 7 deletions

View file

@ -179,9 +179,14 @@ WebIDL::ExceptionOr<void> HTMLMediaElement::load_element()
if (m_ready_state != ReadyState::HaveNothing)
set_ready_state(ReadyState::HaveNothing);
// FIXME: 6. If the paused attribute is false, then:
// 1. Set the paused attribute to true.
// 2. Take pending play promises and reject pending play promises with the result and an "AbortError" DOMException.
// 6. If the paused attribute is false, then:
if (!paused()) {
// 1. Set the paused attribute to true.
set_paused(true);
// FIXME 2. Take pending play promises and reject pending play promises with the result and an "AbortError" DOMException.
}
// FIXME: 7. If seeking is true, set it to false.
// FIXME: 8. Set the current playback position to 0.
// Set the official playback position to 0.
@ -737,7 +742,10 @@ void HTMLMediaElement::set_ready_state(ReadyState ready_state)
dispatch_event(DOM::Event::create(this->realm(), HTML::EventNames::canplay).release_value_but_fixme_should_propagate_errors());
});
// FIXME: If the element's paused attribute is false, the user agent must notify about playing for the element.
// If the element's paused attribute is false, the user agent must notify about playing for the element.
if (!paused())
notify_about_playing();
return;
}
@ -746,10 +754,12 @@ void HTMLMediaElement::set_ready_state(ReadyState ready_state)
// If the previous ready state was HAVE_CURRENT_DATA or less, the user agent must queue a media element task given the media element to fire an event
// named canplay at the element, and, if the element's paused attribute is false, notify about playing for the element.
if (m_ready_state <= ReadyState::HaveCurrentData) {
// FIXME: Handle the paused attribute.
queue_a_media_element_task([this] {
dispatch_event(DOM::Event::create(this->realm(), HTML::EventNames::canplay).release_value_but_fixme_should_propagate_errors());
});
if (!paused())
notify_about_playing();
}
// The user agent must queue a media element task given the media element to fire an event named canplaythrough at the element.
@ -774,4 +784,31 @@ void HTMLMediaElement::set_ready_state(ReadyState ready_state)
}
}
// https://html.spec.whatwg.org/multipage/media.html#notify-about-playing
void HTMLMediaElement::notify_about_playing()
{
// FIXME: 1. Take pending play promises and let promises be the result.
// 2. Queue a media element task given the element and the following steps:
queue_a_media_element_task([this]() {
// 1. Fire an event named playing at the element.
dispatch_event(DOM::Event::create(realm(), HTML::EventNames::playing).release_value_but_fixme_should_propagate_errors());
// FIXME: 2. Resolve pending play promises with promises.
});
on_playing();
}
void HTMLMediaElement::set_paused(bool paused)
{
if (m_paused == paused)
return;
m_paused = paused;
if (m_paused)
on_paused();
}
}