summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb
diff options
context:
space:
mode:
authorTimothy Flynn <trflynn89@pm.me>2023-04-20 07:20:42 -0400
committerAndreas Kling <kling@serenityos.org>2023-04-21 07:54:36 +0200
commit12c15641c1986788c717d37923b8046df8ba430e (patch)
tree03dc5365794484b398b52b896ce3fd6b568d6c0f /Userland/Libraries/LibWeb
parent9f71799456da13024dc0af5305fb8d87e0d1e19f (diff)
downloadserenity-12c15641c1986788c717d37923b8046df8ba430e.zip
LibWeb: Implement the HTMLMediaElement "potentially playing" concept
Diffstat (limited to 'Userland/Libraries/LibWeb')
-rw-r--r--Userland/Libraries/LibWeb/HTML/HTMLMediaElement.cpp29
-rw-r--r--Userland/Libraries/LibWeb/HTML/HTMLMediaElement.h2
2 files changed, 31 insertions, 0 deletions
diff --git a/Userland/Libraries/LibWeb/HTML/HTMLMediaElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLMediaElement.cpp
index 73eed82b27..9fec1596ba 100644
--- a/Userland/Libraries/LibWeb/HTML/HTMLMediaElement.cpp
+++ b/Userland/Libraries/LibWeb/HTML/HTMLMediaElement.cpp
@@ -1211,6 +1211,35 @@ void HTMLMediaElement::set_paused(bool paused)
on_paused();
}
+// https://html.spec.whatwg.org/multipage/media.html#blocked-media-element
+bool HTMLMediaElement::blocked() const
+{
+ // A media element is a blocked media element if its readyState attribute is in the HAVE_NOTHING state, the HAVE_METADATA
+ // state, or the HAVE_CURRENT_DATA state, or if the element has paused for user interaction or paused for in-band content.
+ switch (m_ready_state) {
+ case ReadyState::HaveNothing:
+ case ReadyState::HaveMetadata:
+ case ReadyState::HaveCurrentData:
+ return true;
+ default:
+ break;
+ }
+
+ // FIXME: Implement "paused for user interaction" (namely "the user agent has reached a point in the media resource
+ // where the user has to make a selection for the resource to continue").
+ // FIXME: Implement "paused for in-band content".
+ return false;
+}
+
+// https://html.spec.whatwg.org/multipage/media.html#potentially-playing
+bool HTMLMediaElement::potentially_playing() const
+{
+ // A media element is said to be potentially playing when its paused attribute is false, the element has not ended
+ // playback, playback has not stopped due to errors, and the element is not a blocked media element.
+ // FIXME: Implement "stopped due to errors".
+ return !paused() && !ended() && !blocked();
+}
+
// https://html.spec.whatwg.org/multipage/media.html#eligible-for-autoplay
bool HTMLMediaElement::is_eligible_for_autoplay() const
{
diff --git a/Userland/Libraries/LibWeb/HTML/HTMLMediaElement.h b/Userland/Libraries/LibWeb/HTML/HTMLMediaElement.h
index c5af05622c..307402b13b 100644
--- a/Userland/Libraries/LibWeb/HTML/HTMLMediaElement.h
+++ b/Userland/Libraries/LibWeb/HTML/HTMLMediaElement.h
@@ -70,6 +70,7 @@ public:
double duration() const;
bool paused() const { return m_paused; }
bool ended() const;
+ bool potentially_playing() const;
WebIDL::ExceptionOr<JS::NonnullGCPtr<JS::Promise>> play();
WebIDL::ExceptionOr<void> pause();
@@ -115,6 +116,7 @@ private:
void set_paused(bool);
void set_duration(double);
+ bool blocked() const;
bool is_eligible_for_autoplay() const;
bool has_ended_playback() const;
WebIDL::ExceptionOr<void> reached_end_of_media_playback();