diff options
author | Timothy Flynn <trflynn89@pm.me> | 2023-05-12 15:04:58 -0400 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2023-05-13 15:51:44 +0200 |
commit | 05019746d2c09dd76b0925ca74b2f507959f515d (patch) | |
tree | 945733654472f4c897d8a012ba9d9aa02b1f166d | |
parent | c161a0fc49fa102971b95749280c1dc2c44dc851 (diff) | |
download | serenity-05019746d2c09dd76b0925ca74b2f507959f515d.zip |
LibWeb: Partially implement HTMLSourceElement's insertion/removal steps
This implements the substeps which concern HTMLMediaElement parents.
-rw-r--r-- | Userland/Libraries/LibWeb/HTML/HTMLMediaElement.h | 2 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/HTML/HTMLSourceElement.cpp | 31 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/HTML/HTMLSourceElement.h | 3 |
3 files changed, 35 insertions, 1 deletions
diff --git a/Userland/Libraries/LibWeb/HTML/HTMLMediaElement.h b/Userland/Libraries/LibWeb/HTML/HTMLMediaElement.h index 766d77e3f0..3f5b0c7d06 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLMediaElement.h +++ b/Userland/Libraries/LibWeb/HTML/HTMLMediaElement.h @@ -40,6 +40,7 @@ public: WebIDL::ExceptionOr<void> set_decoder_error(String error_message); String const& current_src() const { return m_current_src; } + WebIDL::ExceptionOr<void> select_resource(); enum class NetworkState : u16 { Empty, @@ -111,7 +112,6 @@ private: Task::Source media_element_event_task_source() const { return m_media_element_event_task_source.source; } WebIDL::ExceptionOr<void> load_element(); - WebIDL::ExceptionOr<void> select_resource(); WebIDL::ExceptionOr<void> fetch_resource(AK::URL const&, Function<void(String)> failure_callback); static bool verify_response(JS::NonnullGCPtr<Fetch::Infrastructure::Response>, ByteRange const&); WebIDL::ExceptionOr<void> process_media_data(Function<void(String)> failure_callback); diff --git a/Userland/Libraries/LibWeb/HTML/HTMLSourceElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLSourceElement.cpp index afb877a308..ef1674647c 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLSourceElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLSourceElement.cpp @@ -5,6 +5,8 @@ */ #include <LibWeb/Bindings/Intrinsics.h> +#include <LibWeb/HTML/AttributeNames.h> +#include <LibWeb/HTML/HTMLMediaElement.h> #include <LibWeb/HTML/HTMLSourceElement.h> namespace Web::HTML { @@ -24,4 +26,33 @@ JS::ThrowCompletionOr<void> HTMLSourceElement::initialize(JS::Realm& realm) return {}; } +// https://html.spec.whatwg.org/multipage/embedded-content.html#the-source-element:the-source-element-15 +void HTMLSourceElement::inserted() +{ + // The source HTML element insertion steps, given insertedNode, are: + Base::inserted(); + + // 1. If insertedNode's parent is a media element that has no src attribute and whose networkState has the value + // NETWORK_EMPTY, then invoke that media element's resource selection algorithm. + if (is<HTMLMediaElement>(parent())) { + auto& media_element = static_cast<HTMLMediaElement&>(*parent()); + + if (!media_element.has_attribute(HTML::AttributeNames::src) && media_element.network_state() == HTMLMediaElement::NetworkState::Empty) + media_element.select_resource().release_value_but_fixme_should_propagate_errors(); + } + + // FIXME: 2. If insertedNode's next sibling is an img element and its parent is a picture element, then, count this as a + // relevant mutation for the img element. +} + +// https://html.spec.whatwg.org/multipage/embedded-content.html#the-source-element:the-source-element-16 +void HTMLSourceElement::removed_from(DOM::Node* old_parent) +{ + // The source HTML element removing steps, given removedNode and oldParent, are: + Base::removed_from(old_parent); + + // FIXME: 1. If removedNode's next sibling was an img element and oldParent is a picture element, then, count this as a + // relevant mutation for the img element. +} + } diff --git a/Userland/Libraries/LibWeb/HTML/HTMLSourceElement.h b/Userland/Libraries/LibWeb/HTML/HTMLSourceElement.h index d3673f6a68..5b57dc540f 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLSourceElement.h +++ b/Userland/Libraries/LibWeb/HTML/HTMLSourceElement.h @@ -20,6 +20,9 @@ private: HTMLSourceElement(DOM::Document&, DOM::QualifiedName); virtual JS::ThrowCompletionOr<void> initialize(JS::Realm&) override; + + virtual void inserted() override; + virtual void removed_from(DOM::Node*) override; }; } |