LibWeb: Partially implement HTMLSourceElement's insertion/removal steps

This implements the substeps which concern HTMLMediaElement parents.
This commit is contained in:
Timothy Flynn 2023-05-12 15:04:58 -04:00 committed by Andreas Kling
parent c161a0fc49
commit 05019746d2
Notes: sideshowbarker 2024-07-18 05:37:06 +09:00
3 changed files with 35 additions and 1 deletions

View file

@ -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.
}
}