2020-08-01 03:07:00 +01:00
|
|
|
/*
|
2021-04-28 22:46:44 +02:00
|
|
|
* Copyright (c) 2020, the SerenityOS developers.
|
2020-08-01 03:07:00 +01:00
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-08-01 03:07:00 +01:00
|
|
|
*/
|
|
|
|
|
2024-04-27 12:09:58 +12:00
|
|
|
#include <LibWeb/Bindings/HTMLSourceElementPrototype.h>
|
2022-09-30 17:16:16 -06:00
|
|
|
#include <LibWeb/Bindings/Intrinsics.h>
|
2023-05-12 15:04:58 -04:00
|
|
|
#include <LibWeb/HTML/AttributeNames.h>
|
|
|
|
#include <LibWeb/HTML/HTMLMediaElement.h>
|
2020-08-01 03:07:00 +01:00
|
|
|
#include <LibWeb/HTML/HTMLSourceElement.h>
|
|
|
|
|
|
|
|
namespace Web::HTML {
|
|
|
|
|
2024-11-15 04:01:23 +13:00
|
|
|
GC_DEFINE_ALLOCATOR(HTMLSourceElement);
|
2023-11-19 19:47:52 +01:00
|
|
|
|
2022-02-18 21:00:52 +01:00
|
|
|
HTMLSourceElement::HTMLSourceElement(DOM::Document& document, DOM::QualifiedName qualified_name)
|
2021-02-07 11:20:15 +01:00
|
|
|
: HTMLElement(document, move(qualified_name))
|
2020-08-01 03:07:00 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-03-14 13:21:51 -06:00
|
|
|
HTMLSourceElement::~HTMLSourceElement() = default;
|
2020-08-01 03:07:00 +01:00
|
|
|
|
2023-08-07 08:41:28 +02:00
|
|
|
void HTMLSourceElement::initialize(JS::Realm& realm)
|
2023-01-10 06:28:20 -05:00
|
|
|
{
|
2023-08-07 08:41:28 +02:00
|
|
|
Base::initialize(realm);
|
2024-03-16 13:13:08 +01:00
|
|
|
WEB_SET_PROTOTYPE_FOR_INTERFACE(HTMLSourceElement);
|
2023-01-10 06:28:20 -05:00
|
|
|
}
|
|
|
|
|
2025-03-19 11:24:58 +00:00
|
|
|
// https://html.spec.whatwg.org/multipage/embedded-content.html#the-source-element:html-element-insertion-steps
|
2023-05-12 15:04:58 -04:00
|
|
|
void HTMLSourceElement::inserted()
|
|
|
|
{
|
|
|
|
// The source HTML element insertion steps, given insertedNode, are:
|
|
|
|
Base::inserted();
|
|
|
|
|
2025-03-19 11:24:58 +00:00
|
|
|
// 1. Let parent be insertedNode's parent.
|
|
|
|
auto* parent = this->parent();
|
2023-05-12 15:04:58 -04:00
|
|
|
|
2025-03-19 11:24:58 +00:00
|
|
|
// 2. If 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 (auto* media_element = as_if<HTMLMediaElement>(parent); media_element
|
|
|
|
&& !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();
|
2023-05-12 15:04:58 -04:00
|
|
|
}
|
|
|
|
|
2025-03-19 11:24:58 +00:00
|
|
|
// FIXME: 3. If parent is a picture element, then for each child of parent's children, if child is an img element, then
|
|
|
|
// count this as a relevant mutation for child.
|
2023-05-12 15:04:58 -04:00
|
|
|
}
|
|
|
|
|
2025-03-19 11:24:58 +00:00
|
|
|
// https://html.spec.whatwg.org/multipage/embedded-content.html#the-source-element:html-element-removing-steps
|
2025-01-23 17:37:18 +01:00
|
|
|
void HTMLSourceElement::removed_from(DOM::Node* old_parent, DOM::Node& old_root)
|
2023-05-12 15:04:58 -04:00
|
|
|
{
|
|
|
|
// The source HTML element removing steps, given removedNode and oldParent, are:
|
2025-01-23 17:37:18 +01:00
|
|
|
Base::removed_from(old_parent, old_root);
|
2023-05-12 15:04:58 -04:00
|
|
|
|
2025-03-19 11:24:58 +00:00
|
|
|
// FIXME: 1. If oldParent is a picture element, then for each child of oldParent's children, if child is an img
|
|
|
|
// element, then count this as a relevant mutation for child.
|
2023-05-12 15:04:58 -04:00
|
|
|
}
|
|
|
|
|
2020-08-01 03:07:00 +01:00
|
|
|
}
|