summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb/HTML/HTMLMediaElement.cpp
diff options
context:
space:
mode:
authorTimothy Flynn <trflynn89@pm.me>2023-04-07 11:35:11 -0400
committerLinus Groh <mail@linusgroh.de>2023-04-08 22:04:14 +0200
commitb8a37ef809438a3e995451190c85b339c83f1c12 (patch)
tree7e09943113fce2fa5b90404574d9cf4e8d2d0328 /Userland/Libraries/LibWeb/HTML/HTMLMediaElement.cpp
parent90921a4f1621f3b068d2a7c47a5eac924778c20e (diff)
downloadserenity-b8a37ef809438a3e995451190c85b339c83f1c12.zip
LibWeb: Implement HTMLMediaElement.pause
Diffstat (limited to 'Userland/Libraries/LibWeb/HTML/HTMLMediaElement.cpp')
-rw-r--r--Userland/Libraries/LibWeb/HTML/HTMLMediaElement.cpp43
1 files changed, 41 insertions, 2 deletions
diff --git a/Userland/Libraries/LibWeb/HTML/HTMLMediaElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLMediaElement.cpp
index 036376ebb8..d71996360a 100644
--- a/Userland/Libraries/LibWeb/HTML/HTMLMediaElement.cpp
+++ b/Userland/Libraries/LibWeb/HTML/HTMLMediaElement.cpp
@@ -128,9 +128,17 @@ void HTMLMediaElement::set_duration(double duration)
}
// https://html.spec.whatwg.org/multipage/media.html#dom-media-pause
-void HTMLMediaElement::pause() const
+WebIDL::ExceptionOr<void> HTMLMediaElement::pause()
{
- dbgln("(STUBBED) HTMLMediaElement::pause()");
+ // 1. If the media element's networkState attribute has the value NETWORK_EMPTY, invoke the media element's resource
+ // selection algorithm.
+ if (m_network_state == NetworkState::Empty)
+ TRY(select_resource());
+
+ // 2. Run the internal pause steps for the media element.
+ TRY(pause_element());
+
+ return {};
}
// https://html.spec.whatwg.org/multipage/media.html#media-element-load-algorithm
@@ -784,6 +792,37 @@ void HTMLMediaElement::set_ready_state(ReadyState ready_state)
}
}
+// https://html.spec.whatwg.org/multipage/media.html#internal-pause-steps
+WebIDL::ExceptionOr<void> HTMLMediaElement::pause_element()
+{
+ // FIXME: 1. Set the media element's can autoplay flag to false.
+
+ // 2. If the media element's paused attribute is false, run the following steps:
+ if (!paused()) {
+ // 1. Change the value of paused to true.
+ set_paused(true);
+
+ // FIXME: 2. Take pending play promises and let promises be the result.
+
+ // 3. Queue a media element task given the media element and the following steps:
+ queue_a_media_element_task([this]() {
+ auto& realm = this->realm();
+
+ // 1. Fire an event named timeupdate at the element.
+ dispatch_event(DOM::Event::create(realm, HTML::EventNames::timeupdate).release_value_but_fixme_should_propagate_errors());
+
+ // 2. Fire an event named pause at the element.
+ dispatch_event(DOM::Event::create(realm, HTML::EventNames::pause).release_value_but_fixme_should_propagate_errors());
+
+ // FIXME: 3. Reject pending play promises with promises and an "AbortError" DOMException.
+ });
+
+ // FIXME: 4. Set the official playback position to the current playback position.
+ }
+
+ return {};
+}
+
// https://html.spec.whatwg.org/multipage/media.html#notify-about-playing
void HTMLMediaElement::notify_about_playing()
{