Jelajahi Sumber

LibWeb: Implement HTMLMediaElement's networkState attribute

Timothy Flynn 2 tahun lalu
induk
melakukan
6d5893a121

+ 12 - 0
Userland/Libraries/LibWeb/HTML/HTMLMediaElement.h

@@ -16,6 +16,14 @@ class HTMLMediaElement : public HTMLElement {
 public:
 public:
     virtual ~HTMLMediaElement() override;
     virtual ~HTMLMediaElement() override;
 
 
+    enum class NetworkState : u16 {
+        Empty,
+        Idle,
+        Loading,
+        NoSource,
+    };
+    NetworkState network_state() const { return m_network_state; }
+
     Bindings::CanPlayTypeResult can_play_type(DeprecatedString const& type) const;
     Bindings::CanPlayTypeResult can_play_type(DeprecatedString const& type) const;
 
 
     void load() const;
     void load() const;
@@ -25,6 +33,10 @@ protected:
     HTMLMediaElement(DOM::Document&, DOM::QualifiedName);
     HTMLMediaElement(DOM::Document&, DOM::QualifiedName);
 
 
     virtual JS::ThrowCompletionOr<void> initialize(JS::Realm&) override;
     virtual JS::ThrowCompletionOr<void> initialize(JS::Realm&) override;
+
+private:
+    // https://html.spec.whatwg.org/multipage/media.html#dom-media-networkstate
+    NetworkState m_network_state { NetworkState::Empty };
 };
 };
 
 
 }
 }

+ 6 - 0
Userland/Libraries/LibWeb/HTML/HTMLMediaElement.idl

@@ -10,7 +10,13 @@ enum CanPlayTypeResult {
 [Exposed=Window]
 [Exposed=Window]
 interface HTMLMediaElement : HTMLElement {
 interface HTMLMediaElement : HTMLElement {
 
 
+    // network state
     [Reflect, CEReactions] attribute DOMString src;
     [Reflect, CEReactions] attribute DOMString src;
+    const unsigned short NETWORK_EMPTY = 0;
+    const unsigned short NETWORK_IDLE = 1;
+    const unsigned short NETWORK_LOADING = 2;
+    const unsigned short NETWORK_NO_SOURCE = 3;
+    readonly attribute unsigned short networkState;
 
 
     [Reflect, CEReactions] attribute boolean autoplay;
     [Reflect, CEReactions] attribute boolean autoplay;
     [Reflect, CEReactions] attribute boolean loop;
     [Reflect, CEReactions] attribute boolean loop;